@aws-amplify/analytics
Version:
Analytics category of aws-amplify
34 lines (32 loc) • 1.45 kB
JavaScript
;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.peekCtxArgs = peekCtxArgs;
const core_1 = require("@aws-amplify/core");
/**
* Non-destructively inspects a public-API arguments array and separates the
* optional leading {@link AmplifyContext} from the API input.
*
* Unlike core's `resolveCtxArgs`, this helper deliberately does NOT fall back
* to the global context — `ctx` stays `undefined` when no explicit context was
* supplied. Callers (e.g. `configureAutoTrack`) that only need the context at
* emit time use this so the global context is resolved lazily: resolving it
* eagerly would (a) throw when trackers are configured before
* `Amplify.configure()` and (b) pin auto-tracked events to the configuration
* snapshot captured at setup time after a later `configure()` call.
*
* @param args The raw arguments array of an overloaded public API.
*
* @returns `{ ctx?, input }` — `ctx` is set only when the first argument is a
* branded `AmplifyContext`; `input` is the argument that follows it (or the
* first argument when no context was passed).
*
* @internal
*/
function peekCtxArgs(args) {
return (0, core_1.isAmplifyContext)(args[0])
? { ctx: args[0], input: args[1] }
: { ctx: undefined, input: args[0] };
}
//# sourceMappingURL=peekCtxArgs.js.map