{"version":3,"file":"bridgeAmplifyClass.mjs","sources":["../../../src/context/bridgeAmplifyClass.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AMPLIFY_CONTEXT_BRAND } from './contextBrand';\nimport { createAmplifyContextToken } from './contextToken';\n/**\n * Bridges an {@link AmplifyClass} (a.k.a. `AmplifyClassV6`) instance to the\n * {@link AmplifyContext} shape.\n *\n * `AmplifyClass` exposes `resourcesConfig` / `libraryOptions` directly but does\n * NOT surface the top-level context methods (`fetchAuthSession` /\n * `clearCredentials` / `getTokens`). Those live under its cross-category `Auth`\n * utility, so this helper maps them through.\n *\n * This is the single shared implementation promoted into core (Phase C1). It is\n * consumed by:\n * - The server wrapper where a legacy `ContextSpec` provides an `AmplifyClass` instance.\n * - The category internals (e.g. api-graphql / api-rest) that still receive an\n *   `AmplifyClassV6` until they migrate fully to `AmplifyContext`.\n *\n * @internal\n */\nexport const bridgeAmplifyClass = (amplify) => {\n    const resolved = {\n        get resourcesConfig() {\n            return amplify.getConfig();\n        },\n        // Live getter: AmplifyClass.libraryOptions is REASSIGNED wholesale on\n        // configure(), so a snapshot would go stale.\n        get libraryOptions() {\n            return amplify.libraryOptions;\n        },\n        // Unique, frozen per-context identity handle (see AmplifyContextToken).\n        // Attached before the brand/freeze below so the frozen bridge carries it.\n        token: createAmplifyContextToken(),\n        // AmplifyContext.fetchAuthSession has OPTIONAL options while\n        // AuthClass.Auth.fetchAuthSession requires it, hence the `?? {}` default.\n        fetchAuthSession: options => amplify.Auth.fetchAuthSession(options ?? {}),\n        clearCredentials: () => amplify.Auth.clearCredentials(),\n        // getTokens needs no default — options is required on both interfaces.\n        getTokens: options => amplify.Auth.getTokens(options),\n    };\n    // Branding makes downstream isAmplifyContext checks (e.g. internalPost)\n    // recognize an already-bridged context, preventing double-bridging which\n    // would break the Auth.* closures. Explicit descriptor (non-writable /\n    // non-configurable) mirrors the other AmplifyContext producers.\n    Object.defineProperty(resolved, AMPLIFY_CONTEXT_BRAND, {\n        value: true,\n        enumerable: false,\n        configurable: false,\n        writable: false,\n    });\n    // Freeze for parity with the other producers (createAmplifyContext, singleton\n    // Amplify.ts) so the method closures cannot be reassigned downstream. Frozen\n    // AFTER defining the getters/brand: the `resourcesConfig` / `libraryOptions`\n    // accessors remain live (getters still evaluate on a frozen object), while\n    // the data-valued method properties become non-writable.\n    Object.freeze(resolved);\n    return resolved;\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,CAAC,OAAO,KAAK;AAC/C,IAAI,MAAM,QAAQ,GAAG;AACrB,QAAQ,IAAI,eAAe,GAAG;AAC9B,YAAY,OAAO,OAAO,CAAC,SAAS,EAAE;AACtC,QAAQ,CAAC;AACT;AACA;AACA,QAAQ,IAAI,cAAc,GAAG;AAC7B,YAAY,OAAO,OAAO,CAAC,cAAc;AACzC,QAAQ,CAAC;AACT;AACA;AACA,QAAQ,KAAK,EAAE,yBAAyB,EAAE;AAC1C;AACA;AACA,QAAQ,gBAAgB,EAAE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,IAAI,EAAE,CAAC;AACjF,QAAQ,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;AAC/D;AACA,QAAQ,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;AAC7D,KAAK;AACL;AACA;AACA;AACA;AACA,IAAI,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,qBAAqB,EAAE;AAC3D,QAAQ,KAAK,EAAE,IAAI;AACnB,QAAQ,UAAU,EAAE,KAAK;AACzB,QAAQ,YAAY,EAAE,KAAK;AAC3B,QAAQ,QAAQ,EAAE,KAAK;AACvB,KAAK,CAAC;AACN;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;AAC3B,IAAI,OAAO,QAAQ;AACnB;;;;"}