UNPKG

@aws-amplify/core

Version:

Core category of aws-amplify

35 lines (33 loc) • 1.55 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.assertOptionalCtxArg = assertOptionalCtxArg; const InvalidAmplifyContextError_1 = require("../errors/InvalidAmplifyContextError"); const contextBrand_1 = require("./contextBrand"); /** * Assertion guard for category class constructors (and other call sites) that * accept an **optional** leading {@link AmplifyContext} argument. * * - `undefined` is allowed (the caller will fall back to the global context * lazily — constructors MUST NOT capture `getGlobalContext()` eagerly). * - A branded {@link AmplifyContext} is allowed. * - Any other defined value (a plain options object, an `AmplifyClass` * instance, etc.) is rejected with a typed {@link InvalidAmplifyContextError}, * so an unbranded value passed in the context position fails loudly instead * of being silently treated as a valid context. * * This complements {@link resolveCtxArgs}, which handles the function-argument * (tuple) pattern, by covering the constructor / single-slot pattern. * * @throws {@link InvalidAmplifyContextError} when `ctx` is defined but is not a * branded {@link AmplifyContext}. * * @internal */ function assertOptionalCtxArg(ctx) { if (ctx !== undefined && !(0, contextBrand_1.isAmplifyContext)(ctx)) { throw new InvalidAmplifyContextError_1.InvalidAmplifyContextError(); } } //# sourceMappingURL=assertCtxArg.js.map