@aws-amplify/core
Version:
Core category of aws-amplify
43 lines (41 loc) • 1.7 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.getContextTokenOrchestrator = exports.registerContextTokenOrchestrator = void 0;
/**
* Maps a per-context token provider object to its write-capable orchestrator.
*
* The public `TokenProvider` contract is read-only (`getTokens` only), so the
* write side of a per-context provider cannot be hung off the provider itself
* without expanding the public surface. This registry keeps that association
* Amplify-owned and out of any public type.
*
* Weak keys so entries are GC'd with the context/provider. Values are kept
* opaque (`unknown`) so core carries no dependency on auth's orchestrator type;
* the reader supplies the concrete type at the call site.
*
* @internal
*/
const contextTokenOrchestrators = new WeakMap();
/**
* Associates a per-context token provider with its write-capable orchestrator.
*
* @internal
*/
const registerContextTokenOrchestrator = (provider, orchestrator) => {
contextTokenOrchestrators.set(provider, orchestrator);
};
exports.registerContextTokenOrchestrator = registerContextTokenOrchestrator;
/**
* Returns the orchestrator registered for the given token provider, or
* `undefined` when the provider is absent or was never registered (the global
* `Amplify.configure()` path).
*
* @internal
*/
const getContextTokenOrchestrator = (provider) => provider
? contextTokenOrchestrators.get(provider)
: undefined;
exports.getContextTokenOrchestrator = getContextTokenOrchestrator;
//# sourceMappingURL=contextTokenOrchestrators.js.map