@salesforce/core 8.15.0 → 8.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -54,8 +54,9 @@ export type ConfigInfo = {
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Options> {
|
|
57
|
-
protected static instance: AsyncOptionalCreatable;
|
|
58
57
|
protected static encrypted: boolean;
|
|
58
|
+
protected static instance: AsyncOptionalCreatable | undefined;
|
|
59
|
+
private static readonly mutex;
|
|
59
60
|
private allowedProperties;
|
|
60
61
|
private readonly localConfig?;
|
|
61
62
|
private readonly globalConfig;
|
|
@@ -68,6 +69,12 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggre
|
|
|
68
69
|
constructor(options?: ConfigAggregator.Options);
|
|
69
70
|
private get config();
|
|
70
71
|
static create<P extends ConfigAggregator.Options, T extends AsyncOptionalCreatable<P>>(this: new (options?: P) => T, options?: P): Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Clear the cache to force reading from disk.
|
|
74
|
+
*
|
|
75
|
+
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
76
|
+
*/
|
|
77
|
+
static clearInstance(): Promise<void>;
|
|
71
78
|
/**
|
|
72
79
|
* Get the info for a given key. If the ConfigAggregator was not asynchronously created OR
|
|
73
80
|
* the {@link ConfigAggregator.reload} was not called, the config value may be encrypted.
|
|
@@ -11,6 +11,7 @@ const kit_1 = require("@salesforce/kit");
|
|
|
11
11
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
12
|
const messages_1 = require("../messages");
|
|
13
13
|
const lifecycleEvents_1 = require("../lifecycleEvents");
|
|
14
|
+
const mutex_1 = require("../util/mutex");
|
|
14
15
|
const envVars_1 = require("./envVars");
|
|
15
16
|
const config_1 = require("./config");
|
|
16
17
|
;
|
|
@@ -31,8 +32,9 @@ const messages = new messages_1.Messages('@salesforce/core', 'config', new Map([
|
|
|
31
32
|
* ```
|
|
32
33
|
*/
|
|
33
34
|
class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
34
|
-
static instance;
|
|
35
35
|
static encrypted = true;
|
|
36
|
+
static instance;
|
|
37
|
+
static mutex = new mutex_1.Mutex();
|
|
36
38
|
// Initialized in loadProperties
|
|
37
39
|
allowedProperties;
|
|
38
40
|
localConfig;
|
|
@@ -64,18 +66,32 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
64
66
|
// Use typing from AsyncOptionalCreatable to support extending ConfigAggregator.
|
|
65
67
|
// We really don't want ConfigAggregator extended but typescript doesn't support a final.
|
|
66
68
|
static async create(options) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
return ConfigAggregator.mutex.lock(async () => {
|
|
70
|
+
let config = ConfigAggregator.instance;
|
|
71
|
+
if (!config) {
|
|
72
|
+
config = ConfigAggregator.instance = new this(options);
|
|
73
|
+
await config.init();
|
|
74
|
+
}
|
|
75
|
+
if (ConfigAggregator.encrypted) {
|
|
76
|
+
await config.loadProperties();
|
|
77
|
+
}
|
|
78
|
+
if (options?.customConfigMeta) {
|
|
79
|
+
config_1.Config.addAllowedProperties(options.customConfigMeta);
|
|
80
|
+
}
|
|
81
|
+
// console.log(ConfigAggregator.instance);
|
|
82
|
+
return ConfigAggregator.instance;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Clear the cache to force reading from disk.
|
|
87
|
+
*
|
|
88
|
+
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
89
|
+
*/
|
|
90
|
+
static async clearInstance() {
|
|
91
|
+
return ConfigAggregator.mutex.lock(() => {
|
|
92
|
+
ConfigAggregator.instance = undefined;
|
|
93
|
+
ConfigAggregator.encrypted = true; // Reset encryption flag as well
|
|
94
|
+
});
|
|
79
95
|
}
|
|
80
96
|
/**
|
|
81
97
|
* Get the info for a given key. If the ConfigAggregator was not asynchronously created OR
|
|
@@ -4,6 +4,7 @@ import { OrgAccessor } from './accessors/orgAccessor';
|
|
|
4
4
|
import { SandboxAccessor } from './accessors/sandboxAccessor';
|
|
5
5
|
export declare class StateAggregator extends AsyncOptionalCreatable {
|
|
6
6
|
private static instanceMap;
|
|
7
|
+
private static readonly mutex;
|
|
7
8
|
aliases: AliasAccessor;
|
|
8
9
|
orgs: OrgAccessor;
|
|
9
10
|
sandboxes: SandboxAccessor;
|
|
@@ -17,7 +18,14 @@ export declare class StateAggregator extends AsyncOptionalCreatable {
|
|
|
17
18
|
* Clear the cache to force reading from disk.
|
|
18
19
|
*
|
|
19
20
|
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
21
|
+
* *NOTE: This call is NOT thread-safe, so it should only be called when no other threads are using the StateAggregator.*
|
|
20
22
|
*/
|
|
21
23
|
static clearInstance(path?: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Clear the cache to force reading from disk in a thread-safe manner.
|
|
26
|
+
*
|
|
27
|
+
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
28
|
+
*/
|
|
29
|
+
static clearInstanceAsync(path?: string): Promise<void>;
|
|
22
30
|
protected init(): Promise<void>;
|
|
23
31
|
}
|
|
@@ -9,11 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.StateAggregator = void 0;
|
|
10
10
|
const kit_1 = require("@salesforce/kit");
|
|
11
11
|
const global_1 = require("../global");
|
|
12
|
+
const mutex_1 = require("../util/mutex");
|
|
12
13
|
const aliasAccessor_1 = require("./accessors/aliasAccessor");
|
|
13
14
|
const orgAccessor_1 = require("./accessors/orgAccessor");
|
|
14
15
|
const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
|
|
15
16
|
class StateAggregator extends kit_1.AsyncOptionalCreatable {
|
|
16
17
|
static instanceMap = new Map();
|
|
18
|
+
static mutex = new mutex_1.Mutex();
|
|
17
19
|
aliases;
|
|
18
20
|
orgs;
|
|
19
21
|
sandboxes;
|
|
@@ -23,20 +25,33 @@ class StateAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
23
25
|
* HomeDir might be stubbed in tests
|
|
24
26
|
*/
|
|
25
27
|
static async getInstance() {
|
|
26
|
-
|
|
27
|
-
StateAggregator.instanceMap.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
return StateAggregator.mutex.lock(async () => {
|
|
29
|
+
if (!StateAggregator.instanceMap.has(global_1.Global.DIR)) {
|
|
30
|
+
StateAggregator.instanceMap.set(global_1.Global.DIR, await StateAggregator.create());
|
|
31
|
+
}
|
|
32
|
+
// TS assertion is valid because there either was one OR it was just now instantiated
|
|
33
|
+
return StateAggregator.instanceMap.get(global_1.Global.DIR);
|
|
34
|
+
});
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Clear the cache to force reading from disk.
|
|
34
38
|
*
|
|
35
39
|
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
40
|
+
* *NOTE: This call is NOT thread-safe, so it should only be called when no other threads are using the StateAggregator.*
|
|
36
41
|
*/
|
|
37
42
|
static clearInstance(path = global_1.Global.DIR) {
|
|
38
43
|
StateAggregator.instanceMap.delete(path);
|
|
39
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Clear the cache to force reading from disk in a thread-safe manner.
|
|
47
|
+
*
|
|
48
|
+
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
49
|
+
*/
|
|
50
|
+
static async clearInstanceAsync(path = global_1.Global.DIR) {
|
|
51
|
+
return StateAggregator.mutex.lock(() => {
|
|
52
|
+
StateAggregator.clearInstance(path);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
40
55
|
async init() {
|
|
41
56
|
this.orgs = await orgAccessor_1.OrgAccessor.create();
|
|
42
57
|
this.sandboxes = await sandboxAccessor_1.SandboxAccessor.create();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Mutex = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Simple mutex implementation using promises
|
|
12
|
+
*/
|
|
13
|
+
class Mutex {
|
|
14
|
+
mutex = Promise.resolve();
|
|
15
|
+
async lock(fn) {
|
|
16
|
+
const unlock = await this.acquire();
|
|
17
|
+
try {
|
|
18
|
+
return await fn();
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
unlock();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async acquire() {
|
|
25
|
+
let release;
|
|
26
|
+
const promise = new Promise((resolve) => {
|
|
27
|
+
release = resolve;
|
|
28
|
+
});
|
|
29
|
+
const currentMutex = this.mutex;
|
|
30
|
+
this.mutex = this.mutex.then(() => promise);
|
|
31
|
+
await currentMutex;
|
|
32
|
+
return release;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Mutex = Mutex;
|
|
36
|
+
//# sourceMappingURL=mutex.js.map
|