{"version":3,"file":"resolveCtxArgs.mjs","sources":["../../../src/context/resolveCtxArgs.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { InvalidAmplifyContextError } from '../errors/InvalidAmplifyContextError';\nimport { NoAmplifyContextError } from '../errors/NoAmplifyContextError';\nimport { isAmplifyContext } from './contextBrand';\nimport { getGlobalContext } from './globalContext';\n/**\n * Resolves the optional leading `AmplifyContext` argument from a function's\n * arguments array. Used by category functions that accept an optional context\n * as their first positional parameter.\n *\n * @returns A tuple of `[AmplifyContext, ...T]` where `T` is the remaining args.\n *\n * @example\n * ```ts\n * export function signIn(...args: any[]) {\n *   const [ctx, input] = resolveCtxArgs<[SignInInput]>(args);\n *   // ctx is guaranteed to be a valid AmplifyContext\n * }\n * ```\n *\n * @internal\n */\nexport function resolveCtxArgs(args) {\n    if (isAmplifyContext(args[0])) {\n        return [args[0], ...args.slice(1)];\n    }\n    // Guard against mis-ordered calls (e.g. `send(input, ctx)` from untyped JS):\n    // a context anywhere but the first position would otherwise be silently\n    // treated as a regular argument while the call falls back to the global context.\n    // Checked before the undefined-first-arg guard so the more specific message\n    // wins whenever a context actually exists somewhere in `args`.\n    if (args.some(isAmplifyContext)) {\n        throw new InvalidAmplifyContextError('AmplifyContext must be passed as the first argument. ' +\n            'Found an AmplifyContext in a later position — check the argument order.');\n    }\n    if (args.length > 1 && args[0] === undefined) {\n        // Unconfigured/undefined leading context — throw the typed error (stable\n        // name/code) so categories can catch it uniformly. The fallback path\n        // below also throws NoAmplifyContextError via getGlobalContext().\n        throw new NoAmplifyContextError('Undefined AmplifyContext passed. Call configure() first or omit the parameter.');\n    }\n    return [getGlobalContext(), ...args];\n}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,IAAI,EAAE;AACrC,IAAI,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;AACnC,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1C,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE;AACrC,QAAQ,MAAM,IAAI,0BAA0B,CAAC,uDAAuD;AACpG,YAAY,yEAAyE,CAAC;AACtF,IAAI;AACJ,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;AAClD;AACA;AACA;AACA,QAAQ,MAAM,IAAI,qBAAqB,CAAC,gFAAgF,CAAC;AACzH,IAAI;AACJ,IAAI,OAAO,CAAC,gBAAgB,EAAE,EAAE,GAAG,IAAI,CAAC;AACxC;;;;"}