UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

46 lines 2.03 kB
"use strict"; /* * Copyright (c) 2022, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ Object.defineProperty(exports, "__esModule", { value: true }); exports.StateAggregator = void 0; const kit_1 = require("@salesforce/kit"); const global_1 = require("../global"); const aliasAccessor_1 = require("./accessors/aliasAccessor"); const orgAccessor_1 = require("./accessors/orgAccessor"); const sandboxAccessor_1 = require("./accessors/sandboxAccessor"); const tokenAccessor_1 = require("./accessors/tokenAccessor"); class StateAggregator extends kit_1.AsyncOptionalCreatable { /** * Reuse a StateAggregator if one was already created for the current global state directory * Otherwise, create one and adds it to map for future reuse. * HomeDir might be stubbed in tests */ static async getInstance() { if (!StateAggregator.instanceMap.has(global_1.Global.DIR)) { StateAggregator.instanceMap.set(global_1.Global.DIR, await StateAggregator.create()); } // TS assertion is valid because there either was one OR it was just now instantiated return StateAggregator.instanceMap.get(global_1.Global.DIR); } /** * Clear the cache to force reading from disk. * * *NOTE: Only call this method if you must and you know what you are doing.* */ static clearInstance(path = global_1.Global.DIR) { StateAggregator.instanceMap.delete(path); } async init() { this.orgs = await orgAccessor_1.OrgAccessor.create(); this.sandboxes = await sandboxAccessor_1.SandboxAccessor.create(); this.aliases = await aliasAccessor_1.AliasAccessor.create(); this.tokens = await tokenAccessor_1.TokenAccessor.create(); } } exports.StateAggregator = StateAggregator; StateAggregator.instanceMap = new Map(); //# sourceMappingURL=stateAggregator.js.map