UNPKG

@aws-amplify/core

Version:

Core category of aws-amplify

45 lines (42 loc) • 1.3 kB
import { NoAmplifyContextError } from '../errors/NoAmplifyContextError.mjs'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 let _globalContext = null; /** * Returns the global {@link AmplifyContext} set by `Amplify.configure()`. * * @throws {@link NoAmplifyContextError} If `Amplify.configure()` has not been * called yet and no context is available. */ function getGlobalContext() { if (!_globalContext) { // Typed error (stable name/code) so categories can catch the unconfigured // path uniformly. Message text is preserved for back-compat. throw new NoAmplifyContextError(); } return _globalContext; } /** * Stores the given context as the global {@link AmplifyContext}. * * @internal */ function setGlobalContext(ctx) { _globalContext = ctx; } /** * Returns `true` if a global {@link AmplifyContext} has been set. */ function hasGlobalContext() { return _globalContext !== null; } /** * Clears the global {@link AmplifyContext}. * * @internal — intended for testing and HMR. */ function clearGlobalContext() { _globalContext = null; } export { clearGlobalContext, getGlobalContext, hasGlobalContext, setGlobalContext }; //# sourceMappingURL=globalContext.mjs.map