{"version":3,"file":"API.mjs","sources":["../../src/API.ts"],"sourcesContent":["import { generateClient as internalGenerateClient, } from '@aws-amplify/api-graphql/internals';\nimport { AMPLIFY_CONTEXT_BRAND, createAmplifyContextToken, getGlobalContext, hasGlobalContext, isAmplifyContext, } from '@aws-amplify/core';\n// Empty config returned by the lazy global-context fallback before\n// `Amplify.configure()` has run. Mirrors the previous `Amplify` singleton\n// fallback whose `getConfig()` returned `{}` pre-configure, so `generateClient()`\n// called before configuration still yields a client whose `models` rebuild on\n// the subsequent configure Hub event (rather than throwing).\nconst EMPTY_RESOURCES_CONFIG = {};\n/**\n * A lazy {@link AmplifyContext} that resolves the *current* global context on\n * every access instead of capturing a snapshot at client-generation time.\n *\n * `generateClient()` returns a long-lived client whose `graphql()` operations\n * read config/auth off the stored context per call. Binding a snapshot of\n * `getGlobalContext()` at generation time would go stale if the app calls\n * `Amplify.configure()` again — each configure installs a NEW frozen global\n * context. Delegating through getters keeps reconfiguration honored, preserving\n * the live-read behavior the previous `Amplify` singleton fallback provided via\n * `bridgeAmplifyClass`'s getters. Reads before configuration degrade to an empty\n * config instead of throwing (see {@link EMPTY_RESOURCES_CONFIG}).\n */\nconst lazyGlobalContext = {\n    get resourcesConfig() {\n        return hasGlobalContext()\n            ? getGlobalContext().resourcesConfig\n            : EMPTY_RESOURCES_CONFIG;\n    },\n    get libraryOptions() {\n        return hasGlobalContext() ? getGlobalContext().libraryOptions : {};\n    },\n    // Stable identity handle for this lazy handle itself (see\n    // AmplifyContextToken). Deliberately NOT delegated to the global context:\n    // the token identifies this long-lived wrapper, and reading it must not\n    // throw pre-configure.\n    token: createAmplifyContextToken(),\n    fetchAuthSession: options => getGlobalContext().fetchAuthSession(options),\n    clearCredentials: () => getGlobalContext().clearCredentials(),\n    getTokens: options => getGlobalContext().getTokens(options),\n};\n// Brand the lazy context so `internalGenerateClient` recognizes it as an\n// AmplifyContext (via `isAmplifyContext`) and does NOT attempt to bridge it as\n// an `AmplifyClass` instance.\nObject.defineProperty(lazyGlobalContext, AMPLIFY_CONTEXT_BRAND, {\n    value: true,\n    enumerable: false,\n    configurable: false,\n    writable: false,\n});\nObject.freeze(lazyGlobalContext);\nexport function generateClient(ctxOrOptions, maybeOptions) {\n    // When the first argument is a branded AmplifyContext, bind the client to it\n    // and treat the second argument as the options. Otherwise fall back to the\n    // lazy global context (resolved fresh per operation, honoring reconfigure)\n    // and treat the first argument as the options. `isAmplifyContext` is inlined\n    // in each ternary so its type guard narrows `ctxOrOptions` in place.\n    const amplify = isAmplifyContext(ctxOrOptions)\n        ? ctxOrOptions\n        : lazyGlobalContext;\n    const options = isAmplifyContext(ctxOrOptions) ? maybeOptions : ctxOrOptions;\n    return internalGenerateClient({\n        ...(options ?? {}),\n        amplify,\n    });\n}\n"],"names":["internalGenerateClient"],"mappings":";;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM,sBAAsB,GAAG,EAAE;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,iBAAiB,GAAG;AAC1B,IAAI,IAAI,eAAe,GAAG;AAC1B,QAAQ,OAAO,gBAAgB;AAC/B,cAAc,gBAAgB,EAAE,CAAC;AACjC,cAAc,sBAAsB;AACpC,IAAI,CAAC;AACL,IAAI,IAAI,cAAc,GAAG;AACzB,QAAQ,OAAO,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAAC,cAAc,GAAG,EAAE;AAC1E,IAAI,CAAC;AACL;AACA;AACA;AACA;AACA,IAAI,KAAK,EAAE,yBAAyB,EAAE;AACtC,IAAI,gBAAgB,EAAE,OAAO,IAAI,gBAAgB,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC;AAC7E,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,EAAE,CAAC,gBAAgB,EAAE;AACjE,IAAI,SAAS,EAAE,OAAO,IAAI,gBAAgB,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;AAC/D,CAAC;AACD;AACA;AACA;AACA,M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