@salesforce/core 3.31.4 → 3.31.7
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.
- package/LICENSE.txt +11 -11
- package/README.md +222 -222
- package/lib/config/aliasesConfig.d.ts +12 -12
- package/lib/config/aliasesConfig.js +27 -27
- package/lib/config/authInfoConfig.d.ts +19 -19
- package/lib/config/authInfoConfig.js +34 -34
- package/lib/config/config.d.ts +311 -311
- package/lib/config/config.js +574 -574
- package/lib/config/configAggregator.d.ts +232 -232
- package/lib/config/configAggregator.js +379 -379
- package/lib/config/configFile.d.ts +199 -199
- package/lib/config/configFile.js +340 -340
- package/lib/config/configGroup.d.ts +141 -141
- package/lib/config/configGroup.js +224 -224
- package/lib/config/configStore.d.ts +241 -241
- package/lib/config/configStore.js +352 -352
- package/lib/config/envVars.d.ts +101 -101
- package/lib/config/envVars.js +456 -456
- package/lib/config/orgUsersConfig.d.ts +31 -31
- package/lib/config/orgUsersConfig.js +41 -41
- package/lib/config/sandboxOrgConfig.d.ts +37 -37
- package/lib/config/sandboxOrgConfig.js +50 -50
- package/lib/config/sandboxProcessCache.d.ts +16 -16
- package/lib/config/sandboxProcessCache.js +37 -37
- package/lib/config/tokensConfig.d.ts +10 -10
- package/lib/config/tokensConfig.js +28 -28
- package/lib/config/ttlConfig.d.ts +34 -34
- package/lib/config/ttlConfig.js +54 -54
- package/lib/crypto/crypto.d.ts +54 -54
- package/lib/crypto/crypto.js +220 -220
- package/lib/crypto/keyChain.d.ts +8 -8
- package/lib/crypto/keyChain.js +61 -61
- package/lib/crypto/keyChainImpl.d.ts +116 -116
- package/lib/crypto/keyChainImpl.js +486 -486
- package/lib/crypto/secureBuffer.d.ts +46 -46
- package/lib/crypto/secureBuffer.js +82 -82
- package/lib/deviceOauthService.d.ts +71 -71
- package/lib/deviceOauthService.js +191 -191
- package/lib/exported.d.ts +38 -38
- package/lib/exported.js +118 -118
- package/lib/global.d.ts +70 -70
- package/lib/global.js +109 -109
- package/lib/lifecycleEvents.d.ts +93 -93
- package/lib/lifecycleEvents.js +188 -188
- package/lib/logger.d.ts +381 -381
- package/lib/logger.js +734 -734
- package/lib/messages.d.ts +291 -291
- package/lib/messages.js +543 -543
- package/lib/org/authInfo.d.ts +344 -344
- package/lib/org/authInfo.js +892 -892
- package/lib/org/authRemover.d.ts +88 -88
- package/lib/org/authRemover.js +182 -182
- package/lib/org/connection.d.ts +197 -197
- package/lib/org/connection.js +395 -395
- package/lib/org/index.d.ts +6 -6
- package/lib/org/index.js +28 -28
- package/lib/org/org.d.ts +558 -558
- package/lib/org/org.js +1267 -1267
- package/lib/org/orgConfigProperties.d.ts +69 -69
- package/lib/org/orgConfigProperties.js +136 -136
- package/lib/org/permissionSetAssignment.d.ts +35 -35
- package/lib/org/permissionSetAssignment.js +125 -125
- package/lib/org/scratchOrgCache.d.ts +20 -20
- package/lib/org/scratchOrgCache.js +32 -32
- package/lib/org/scratchOrgCreate.d.ts +54 -54
- package/lib/org/scratchOrgCreate.js +216 -216
- package/lib/org/scratchOrgErrorCodes.d.ts +10 -10
- package/lib/org/scratchOrgErrorCodes.js +88 -88
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -26
- package/lib/org/scratchOrgFeatureDeprecation.js +109 -109
- package/lib/org/scratchOrgInfoApi.d.ts +68 -68
- package/lib/org/scratchOrgInfoApi.js +413 -413
- package/lib/org/scratchOrgInfoGenerator.d.ts +64 -64
- package/lib/org/scratchOrgInfoGenerator.js +241 -241
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -10
- package/lib/org/scratchOrgLifecycleEvents.js +40 -40
- package/lib/org/scratchOrgSettingsGenerator.d.ts +78 -78
- package/lib/org/scratchOrgSettingsGenerator.js +276 -276
- package/lib/org/scratchOrgTypes.d.ts +43 -43
- package/lib/org/scratchOrgTypes.js +8 -8
- package/lib/org/user.d.ts +187 -187
- package/lib/org/user.js +448 -448
- package/lib/schema/printer.d.ts +79 -79
- package/lib/schema/printer.js +260 -260
- package/lib/schema/validator.d.ts +70 -70
- package/lib/schema/validator.js +169 -169
- package/lib/sfError.d.ts +73 -73
- package/lib/sfError.js +136 -136
- package/lib/sfProject.d.ts +357 -357
- package/lib/sfProject.js +671 -671
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -98
- package/lib/stateAggregator/accessors/aliasAccessor.js +145 -145
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -101
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -240
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -8
- package/lib/stateAggregator/accessors/sandboxAccessor.js +27 -27
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -63
- package/lib/stateAggregator/accessors/tokenAccessor.js +79 -79
- package/lib/stateAggregator/index.d.ts +4 -4
- package/lib/stateAggregator/index.js +26 -26
- package/lib/stateAggregator/stateAggregator.d.ts +25 -25
- package/lib/stateAggregator/stateAggregator.js +45 -45
- package/lib/status/myDomainResolver.d.ts +66 -66
- package/lib/status/myDomainResolver.js +124 -124
- package/lib/status/pollingClient.d.ts +85 -85
- package/lib/status/pollingClient.js +115 -115
- package/lib/status/streamingClient.d.ts +244 -244
- package/lib/status/streamingClient.js +436 -436
- package/lib/status/types.d.ts +89 -89
- package/lib/status/types.js +17 -17
- package/lib/testSetup.d.ts +553 -553
- package/lib/testSetup.js +871 -871
- package/lib/util/cache.d.ts +11 -11
- package/lib/util/cache.js +69 -69
- package/lib/util/checkLightningDomain.d.ts +1 -1
- package/lib/util/checkLightningDomain.js +28 -28
- package/lib/util/directoryWriter.d.ts +12 -12
- package/lib/util/directoryWriter.js +53 -53
- package/lib/util/getJwtAudienceUrl.d.ts +4 -4
- package/lib/util/getJwtAudienceUrl.js +18 -18
- package/lib/util/internal.d.ts +58 -58
- package/lib/util/internal.js +118 -118
- package/lib/util/jsonXmlTools.d.ts +14 -14
- package/lib/util/jsonXmlTools.js +38 -38
- package/lib/util/mapKeys.d.ts +14 -14
- package/lib/util/mapKeys.js +51 -51
- package/lib/util/sfdc.d.ts +52 -52
- package/lib/util/sfdc.js +85 -85
- package/lib/util/sfdcUrl.d.ts +72 -72
- package/lib/util/sfdcUrl.js +215 -215
- package/lib/util/structuredWriter.d.ts +9 -9
- package/lib/util/structuredWriter.js +2 -2
- package/lib/util/zipWriter.d.ts +16 -16
- package/lib/util/zipWriter.js +67 -67
- package/lib/webOAuthServer.d.ts +156 -156
- package/lib/webOAuthServer.js +388 -388
- package/messages/auth.md +37 -37
- package/messages/config.md +156 -156
- package/messages/connection.md +30 -30
- package/messages/core.json +20 -20
- package/messages/core.md +67 -67
- package/messages/encryption.md +85 -85
- package/messages/envVars.md +303 -303
- package/messages/org.md +63 -63
- package/messages/permissionSetAssignment.md +31 -31
- package/messages/scratchOrgCreate.md +23 -23
- package/messages/scratchOrgErrorCodes.md +115 -115
- package/messages/scratchOrgFeatureDeprecation.md +11 -11
- package/messages/scratchOrgInfoApi.md +15 -15
- package/messages/scratchOrgInfoGenerator.md +23 -23
- package/messages/streaming.md +23 -23
- package/messages/user.md +35 -35
- package/package.json +97 -97
package/lib/lifecycleEvents.d.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import { AnyJson } from '@salesforce/ts-types';
|
|
2
|
-
declare type callback = (data: any) => Promise<void>;
|
|
3
|
-
/**
|
|
4
|
-
* An asynchronous event listener and emitter that follows the singleton pattern. The singleton pattern allows lifecycle
|
|
5
|
-
* events to be emitted from deep within a library and still be consumed by any other library or tool. It allows other
|
|
6
|
-
* developers to react to certain situations or events in your library without them having to manually call the method themselves.
|
|
7
|
-
*
|
|
8
|
-
* An example might be transforming metadata before it is deployed to an environment. As long as an event was emitted from the
|
|
9
|
-
* deploy library and you were listening on that event in the same process, you could transform the metadata before the deploy
|
|
10
|
-
* regardless of where in the code that metadata was initiated.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```
|
|
14
|
-
* // Listen for an event in a plugin hook
|
|
15
|
-
* Lifecycle.getInstance().on('deploy-metadata', transformMetadata)
|
|
16
|
-
*
|
|
17
|
-
* // Deep in the deploy code, fire the event for all libraries and plugins to hear.
|
|
18
|
-
* Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed);
|
|
19
|
-
*
|
|
20
|
-
* // if you don't need to await anything
|
|
21
|
-
* use `void Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed)` ;
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare class Lifecycle {
|
|
25
|
-
private readonly listeners;
|
|
26
|
-
static readonly telemetryEventName = "telemetry";
|
|
27
|
-
static readonly warningEventName = "warning";
|
|
28
|
-
private debug;
|
|
29
|
-
private constructor();
|
|
30
|
-
/**
|
|
31
|
-
* return the package.json version of the sfdx-core library.
|
|
32
|
-
*/
|
|
33
|
-
static staticVersion(): string;
|
|
34
|
-
/**
|
|
35
|
-
* Retrieve the singleton instance of this class so that all listeners and emitters can interact from any library or tool
|
|
36
|
-
*/
|
|
37
|
-
static getInstance(): Lifecycle;
|
|
38
|
-
/**
|
|
39
|
-
* return the package.json version of the sfdx-core library.
|
|
40
|
-
*/
|
|
41
|
-
version(): string;
|
|
42
|
-
/**
|
|
43
|
-
* Remove all listeners for a given event
|
|
44
|
-
*
|
|
45
|
-
* @param eventName The name of the event to remove listeners of
|
|
46
|
-
*/
|
|
47
|
-
removeAllListeners(eventName: string): void;
|
|
48
|
-
/**
|
|
49
|
-
* Get an array of listeners (callback functions) for a given event
|
|
50
|
-
*
|
|
51
|
-
* @param eventName The name of the event to get listeners of
|
|
52
|
-
*/
|
|
53
|
-
getListeners(eventName: string): callback[];
|
|
54
|
-
/**
|
|
55
|
-
* Create a listener for the `telemetry` event
|
|
56
|
-
*
|
|
57
|
-
* @param cb The callback function to run when the event is emitted
|
|
58
|
-
*/
|
|
59
|
-
onTelemetry(cb: (data: Record<string, unknown>) => Promise<void>): void;
|
|
60
|
-
/**
|
|
61
|
-
* Create a listener for the `warning` event
|
|
62
|
-
*
|
|
63
|
-
* @param cb The callback function to run when the event is emitted
|
|
64
|
-
*/
|
|
65
|
-
onWarning(cb: (warning: string) => Promise<void>): void;
|
|
66
|
-
/**
|
|
67
|
-
* Create a new listener for a given event
|
|
68
|
-
*
|
|
69
|
-
* @param eventName The name of the event that is being listened for
|
|
70
|
-
* @param cb The callback function to run when the event is emitted
|
|
71
|
-
*/
|
|
72
|
-
on<T = AnyJson>(eventName: string, cb: (data: T) => Promise<void>): void;
|
|
73
|
-
/**
|
|
74
|
-
* Emit a `telemetry` event, causing all callback functions to be run in the order they were registered
|
|
75
|
-
*
|
|
76
|
-
* @param data The data to emit
|
|
77
|
-
*/
|
|
78
|
-
emitTelemetry(data: AnyJson): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Emit a `warning` event, causing all callback functions to be run in the order they were registered
|
|
81
|
-
*
|
|
82
|
-
* @param data The warning (string) to emit
|
|
83
|
-
*/
|
|
84
|
-
emitWarning(warning: string): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Emit a given event, causing all callback functions to be run in the order they were registered
|
|
87
|
-
*
|
|
88
|
-
* @param eventName The name of the event to emit
|
|
89
|
-
* @param data The argument to be passed to the callback function
|
|
90
|
-
*/
|
|
91
|
-
emit<T = AnyJson>(eventName: string, data: T): Promise<void>;
|
|
92
|
-
}
|
|
93
|
-
export {};
|
|
1
|
+
import { AnyJson } from '@salesforce/ts-types';
|
|
2
|
+
declare type callback = (data: any) => Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* An asynchronous event listener and emitter that follows the singleton pattern. The singleton pattern allows lifecycle
|
|
5
|
+
* events to be emitted from deep within a library and still be consumed by any other library or tool. It allows other
|
|
6
|
+
* developers to react to certain situations or events in your library without them having to manually call the method themselves.
|
|
7
|
+
*
|
|
8
|
+
* An example might be transforming metadata before it is deployed to an environment. As long as an event was emitted from the
|
|
9
|
+
* deploy library and you were listening on that event in the same process, you could transform the metadata before the deploy
|
|
10
|
+
* regardless of where in the code that metadata was initiated.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```
|
|
14
|
+
* // Listen for an event in a plugin hook
|
|
15
|
+
* Lifecycle.getInstance().on('deploy-metadata', transformMetadata)
|
|
16
|
+
*
|
|
17
|
+
* // Deep in the deploy code, fire the event for all libraries and plugins to hear.
|
|
18
|
+
* Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed);
|
|
19
|
+
*
|
|
20
|
+
* // if you don't need to await anything
|
|
21
|
+
* use `void Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed)` ;
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class Lifecycle {
|
|
25
|
+
private readonly listeners;
|
|
26
|
+
static readonly telemetryEventName = "telemetry";
|
|
27
|
+
static readonly warningEventName = "warning";
|
|
28
|
+
private debug;
|
|
29
|
+
private constructor();
|
|
30
|
+
/**
|
|
31
|
+
* return the package.json version of the sfdx-core library.
|
|
32
|
+
*/
|
|
33
|
+
static staticVersion(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve the singleton instance of this class so that all listeners and emitters can interact from any library or tool
|
|
36
|
+
*/
|
|
37
|
+
static getInstance(): Lifecycle;
|
|
38
|
+
/**
|
|
39
|
+
* return the package.json version of the sfdx-core library.
|
|
40
|
+
*/
|
|
41
|
+
version(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Remove all listeners for a given event
|
|
44
|
+
*
|
|
45
|
+
* @param eventName The name of the event to remove listeners of
|
|
46
|
+
*/
|
|
47
|
+
removeAllListeners(eventName: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get an array of listeners (callback functions) for a given event
|
|
50
|
+
*
|
|
51
|
+
* @param eventName The name of the event to get listeners of
|
|
52
|
+
*/
|
|
53
|
+
getListeners(eventName: string): callback[];
|
|
54
|
+
/**
|
|
55
|
+
* Create a listener for the `telemetry` event
|
|
56
|
+
*
|
|
57
|
+
* @param cb The callback function to run when the event is emitted
|
|
58
|
+
*/
|
|
59
|
+
onTelemetry(cb: (data: Record<string, unknown>) => Promise<void>): void;
|
|
60
|
+
/**
|
|
61
|
+
* Create a listener for the `warning` event
|
|
62
|
+
*
|
|
63
|
+
* @param cb The callback function to run when the event is emitted
|
|
64
|
+
*/
|
|
65
|
+
onWarning(cb: (warning: string) => Promise<void>): void;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new listener for a given event
|
|
68
|
+
*
|
|
69
|
+
* @param eventName The name of the event that is being listened for
|
|
70
|
+
* @param cb The callback function to run when the event is emitted
|
|
71
|
+
*/
|
|
72
|
+
on<T = AnyJson>(eventName: string, cb: (data: T) => Promise<void>): void;
|
|
73
|
+
/**
|
|
74
|
+
* Emit a `telemetry` event, causing all callback functions to be run in the order they were registered
|
|
75
|
+
*
|
|
76
|
+
* @param data The data to emit
|
|
77
|
+
*/
|
|
78
|
+
emitTelemetry(data: AnyJson): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Emit a `warning` event, causing all callback functions to be run in the order they were registered
|
|
81
|
+
*
|
|
82
|
+
* @param data The warning (string) to emit
|
|
83
|
+
*/
|
|
84
|
+
emitWarning(warning: string): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Emit a given event, causing all callback functions to be run in the order they were registered
|
|
87
|
+
*
|
|
88
|
+
* @param eventName The name of the event to emit
|
|
89
|
+
* @param data The argument to be passed to the callback function
|
|
90
|
+
*/
|
|
91
|
+
emit<T = AnyJson>(eventName: string, data: T): Promise<void>;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
package/lib/lifecycleEvents.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2020, 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.Lifecycle = void 0;
|
|
10
|
-
const Debug = require("debug");
|
|
11
|
-
const semver_1 = require("semver");
|
|
12
|
-
// needed for TS to not put everything inside /lib/src
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
const pjson = require("../package.json");
|
|
16
|
-
/**
|
|
17
|
-
* An asynchronous event listener and emitter that follows the singleton pattern. The singleton pattern allows lifecycle
|
|
18
|
-
* events to be emitted from deep within a library and still be consumed by any other library or tool. It allows other
|
|
19
|
-
* developers to react to certain situations or events in your library without them having to manually call the method themselves.
|
|
20
|
-
*
|
|
21
|
-
* An example might be transforming metadata before it is deployed to an environment. As long as an event was emitted from the
|
|
22
|
-
* deploy library and you were listening on that event in the same process, you could transform the metadata before the deploy
|
|
23
|
-
* regardless of where in the code that metadata was initiated.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```
|
|
27
|
-
* // Listen for an event in a plugin hook
|
|
28
|
-
* Lifecycle.getInstance().on('deploy-metadata', transformMetadata)
|
|
29
|
-
*
|
|
30
|
-
* // Deep in the deploy code, fire the event for all libraries and plugins to hear.
|
|
31
|
-
* Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed);
|
|
32
|
-
*
|
|
33
|
-
* // if you don't need to await anything
|
|
34
|
-
* use `void Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed)` ;
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
class Lifecycle {
|
|
38
|
-
constructor(listeners = {}) {
|
|
39
|
-
this.listeners = listeners;
|
|
40
|
-
this.debug = Debug(`sfdx:${this.constructor.name}`);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* return the package.json version of the sfdx-core library.
|
|
44
|
-
*/
|
|
45
|
-
static staticVersion() {
|
|
46
|
-
return pjson.version;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Retrieve the singleton instance of this class so that all listeners and emitters can interact from any library or tool
|
|
50
|
-
*/
|
|
51
|
-
static getInstance() {
|
|
52
|
-
// Across a npm dependency tree, there may be a LOT of versions of `@salesforce/core`. We want to ensure that consumers are notified when
|
|
53
|
-
// listening on a lifecycle event that is fired by a different version of `@salesforce/core`. Adding the instance on the global object will
|
|
54
|
-
// ensure this.
|
|
55
|
-
//
|
|
56
|
-
// For example, a consumer calls `Lifecycle.getInstance().on('myEvent', ...)` on version `@salesforce/core@2.12.2`, and another consumer calls
|
|
57
|
-
// `Lifecycle.getInstance().emit('myEvent', ...)` on version `@salesforce/core@2.13.0`, the on handler will never be called.
|
|
58
|
-
//
|
|
59
|
-
// Note: If ANYTHING is ever added to this class, it needs to check and update `global.salesforceCoreLifecycle` to the newer version.
|
|
60
|
-
// One way this can be done by adding a `version = require(../package.json).version` to the Lifecycle class, then checking if
|
|
61
|
-
// `global.salesforceCoreLifecycle` is greater or equal to that version.
|
|
62
|
-
//
|
|
63
|
-
// For example, let's say a new method is added in `@salesforce/core@3.0.0`. If `Lifecycle.getInstance()` is called fist by
|
|
64
|
-
// `@salesforce/core@2.12.2` then by someone who depends on version `@salesforce/core@3.0.0` (who depends on the new method)
|
|
65
|
-
// they will get a "method does not exist on object" error because the instance on the global object will be of `@salesforce/core@2.12.2`.
|
|
66
|
-
//
|
|
67
|
-
// Nothing should EVER be removed, even across major versions.
|
|
68
|
-
if (!global.salesforceCoreLifecycle) {
|
|
69
|
-
// it's not been loaded yet (basic singleton pattern)
|
|
70
|
-
global.salesforceCoreLifecycle = new Lifecycle();
|
|
71
|
-
}
|
|
72
|
-
else if (
|
|
73
|
-
// an older version was loaded that should be replaced
|
|
74
|
-
(0, semver_1.compare)(global.salesforceCoreLifecycle.version(), Lifecycle.staticVersion()) === -1) {
|
|
75
|
-
const oldInstance = global.salesforceCoreLifecycle;
|
|
76
|
-
// use the newer version and transfer any listeners from the old version
|
|
77
|
-
// object spread keeps them from being references
|
|
78
|
-
global.salesforceCoreLifecycle = new Lifecycle({ ...oldInstance.listeners });
|
|
79
|
-
// clean up any listeners on the old version
|
|
80
|
-
Object.keys(oldInstance.listeners).map((eventName) => {
|
|
81
|
-
oldInstance.removeAllListeners(eventName);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return global.salesforceCoreLifecycle;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* return the package.json version of the sfdx-core library.
|
|
88
|
-
*/
|
|
89
|
-
// eslint-disable-next-line class-methods-use-this
|
|
90
|
-
version() {
|
|
91
|
-
return pjson.version;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Remove all listeners for a given event
|
|
95
|
-
*
|
|
96
|
-
* @param eventName The name of the event to remove listeners of
|
|
97
|
-
*/
|
|
98
|
-
removeAllListeners(eventName) {
|
|
99
|
-
this.listeners[eventName] = [];
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Get an array of listeners (callback functions) for a given event
|
|
103
|
-
*
|
|
104
|
-
* @param eventName The name of the event to get listeners of
|
|
105
|
-
*/
|
|
106
|
-
getListeners(eventName) {
|
|
107
|
-
const listeners = this.listeners[eventName];
|
|
108
|
-
if (listeners) {
|
|
109
|
-
return listeners;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.listeners[eventName] = [];
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Create a listener for the `telemetry` event
|
|
118
|
-
*
|
|
119
|
-
* @param cb The callback function to run when the event is emitted
|
|
120
|
-
*/
|
|
121
|
-
onTelemetry(cb) {
|
|
122
|
-
this.on(Lifecycle.telemetryEventName, cb);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Create a listener for the `warning` event
|
|
126
|
-
*
|
|
127
|
-
* @param cb The callback function to run when the event is emitted
|
|
128
|
-
*/
|
|
129
|
-
onWarning(cb) {
|
|
130
|
-
this.on(Lifecycle.warningEventName, cb);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Create a new listener for a given event
|
|
134
|
-
*
|
|
135
|
-
* @param eventName The name of the event that is being listened for
|
|
136
|
-
* @param cb The callback function to run when the event is emitted
|
|
137
|
-
*/
|
|
138
|
-
on(eventName, cb) {
|
|
139
|
-
const listeners = this.getListeners(eventName);
|
|
140
|
-
if (listeners.length !== 0) {
|
|
141
|
-
this.debug(`${listeners.length + 1} lifecycle events with the name ${eventName} have now been registered. When this event is emitted all ${listeners.length + 1} listeners will fire.`);
|
|
142
|
-
}
|
|
143
|
-
listeners.push(cb);
|
|
144
|
-
this.listeners[eventName] = listeners;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Emit a `telemetry` event, causing all callback functions to be run in the order they were registered
|
|
148
|
-
*
|
|
149
|
-
* @param data The data to emit
|
|
150
|
-
*/
|
|
151
|
-
async emitTelemetry(data) {
|
|
152
|
-
return this.emit(Lifecycle.telemetryEventName, data);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Emit a `warning` event, causing all callback functions to be run in the order they were registered
|
|
156
|
-
*
|
|
157
|
-
* @param data The warning (string) to emit
|
|
158
|
-
*/
|
|
159
|
-
async emitWarning(warning) {
|
|
160
|
-
// if there are no listeners, warnings should go to the node process so they're not lost
|
|
161
|
-
// this also preserves behavior in UT where there's a spy on process.emitWarning
|
|
162
|
-
if (this.getListeners(Lifecycle.warningEventName).length === 0) {
|
|
163
|
-
process.emitWarning(warning);
|
|
164
|
-
}
|
|
165
|
-
return this.emit(Lifecycle.warningEventName, warning);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Emit a given event, causing all callback functions to be run in the order they were registered
|
|
169
|
-
*
|
|
170
|
-
* @param eventName The name of the event to emit
|
|
171
|
-
* @param data The argument to be passed to the callback function
|
|
172
|
-
*/
|
|
173
|
-
async emit(eventName, data) {
|
|
174
|
-
const listeners = this.getListeners(eventName);
|
|
175
|
-
if (listeners.length === 0 && eventName !== Lifecycle.warningEventName) {
|
|
176
|
-
this.debug(`A lifecycle event with the name ${eventName} does not exist. An event must be registered before it can be emitted.`);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
for (const cb of listeners) {
|
|
180
|
-
// eslint-disable-next-line no-await-in-loop
|
|
181
|
-
await cb(data);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
exports.Lifecycle = Lifecycle;
|
|
187
|
-
Lifecycle.telemetryEventName = 'telemetry';
|
|
188
|
-
Lifecycle.warningEventName = 'warning';
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020, 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.Lifecycle = void 0;
|
|
10
|
+
const Debug = require("debug");
|
|
11
|
+
const semver_1 = require("semver");
|
|
12
|
+
// needed for TS to not put everything inside /lib/src
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const pjson = require("../package.json");
|
|
16
|
+
/**
|
|
17
|
+
* An asynchronous event listener and emitter that follows the singleton pattern. The singleton pattern allows lifecycle
|
|
18
|
+
* events to be emitted from deep within a library and still be consumed by any other library or tool. It allows other
|
|
19
|
+
* developers to react to certain situations or events in your library without them having to manually call the method themselves.
|
|
20
|
+
*
|
|
21
|
+
* An example might be transforming metadata before it is deployed to an environment. As long as an event was emitted from the
|
|
22
|
+
* deploy library and you were listening on that event in the same process, you could transform the metadata before the deploy
|
|
23
|
+
* regardless of where in the code that metadata was initiated.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* // Listen for an event in a plugin hook
|
|
28
|
+
* Lifecycle.getInstance().on('deploy-metadata', transformMetadata)
|
|
29
|
+
*
|
|
30
|
+
* // Deep in the deploy code, fire the event for all libraries and plugins to hear.
|
|
31
|
+
* Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed);
|
|
32
|
+
*
|
|
33
|
+
* // if you don't need to await anything
|
|
34
|
+
* use `void Lifecycle.getInstance().emit('deploy-metadata', metadataToBeDeployed)` ;
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
class Lifecycle {
|
|
38
|
+
constructor(listeners = {}) {
|
|
39
|
+
this.listeners = listeners;
|
|
40
|
+
this.debug = Debug(`sfdx:${this.constructor.name}`);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* return the package.json version of the sfdx-core library.
|
|
44
|
+
*/
|
|
45
|
+
static staticVersion() {
|
|
46
|
+
return pjson.version;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Retrieve the singleton instance of this class so that all listeners and emitters can interact from any library or tool
|
|
50
|
+
*/
|
|
51
|
+
static getInstance() {
|
|
52
|
+
// Across a npm dependency tree, there may be a LOT of versions of `@salesforce/core`. We want to ensure that consumers are notified when
|
|
53
|
+
// listening on a lifecycle event that is fired by a different version of `@salesforce/core`. Adding the instance on the global object will
|
|
54
|
+
// ensure this.
|
|
55
|
+
//
|
|
56
|
+
// For example, a consumer calls `Lifecycle.getInstance().on('myEvent', ...)` on version `@salesforce/core@2.12.2`, and another consumer calls
|
|
57
|
+
// `Lifecycle.getInstance().emit('myEvent', ...)` on version `@salesforce/core@2.13.0`, the on handler will never be called.
|
|
58
|
+
//
|
|
59
|
+
// Note: If ANYTHING is ever added to this class, it needs to check and update `global.salesforceCoreLifecycle` to the newer version.
|
|
60
|
+
// One way this can be done by adding a `version = require(../package.json).version` to the Lifecycle class, then checking if
|
|
61
|
+
// `global.salesforceCoreLifecycle` is greater or equal to that version.
|
|
62
|
+
//
|
|
63
|
+
// For example, let's say a new method is added in `@salesforce/core@3.0.0`. If `Lifecycle.getInstance()` is called fist by
|
|
64
|
+
// `@salesforce/core@2.12.2` then by someone who depends on version `@salesforce/core@3.0.0` (who depends on the new method)
|
|
65
|
+
// they will get a "method does not exist on object" error because the instance on the global object will be of `@salesforce/core@2.12.2`.
|
|
66
|
+
//
|
|
67
|
+
// Nothing should EVER be removed, even across major versions.
|
|
68
|
+
if (!global.salesforceCoreLifecycle) {
|
|
69
|
+
// it's not been loaded yet (basic singleton pattern)
|
|
70
|
+
global.salesforceCoreLifecycle = new Lifecycle();
|
|
71
|
+
}
|
|
72
|
+
else if (
|
|
73
|
+
// an older version was loaded that should be replaced
|
|
74
|
+
(0, semver_1.compare)(global.salesforceCoreLifecycle.version(), Lifecycle.staticVersion()) === -1) {
|
|
75
|
+
const oldInstance = global.salesforceCoreLifecycle;
|
|
76
|
+
// use the newer version and transfer any listeners from the old version
|
|
77
|
+
// object spread keeps them from being references
|
|
78
|
+
global.salesforceCoreLifecycle = new Lifecycle({ ...oldInstance.listeners });
|
|
79
|
+
// clean up any listeners on the old version
|
|
80
|
+
Object.keys(oldInstance.listeners).map((eventName) => {
|
|
81
|
+
oldInstance.removeAllListeners(eventName);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return global.salesforceCoreLifecycle;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* return the package.json version of the sfdx-core library.
|
|
88
|
+
*/
|
|
89
|
+
// eslint-disable-next-line class-methods-use-this
|
|
90
|
+
version() {
|
|
91
|
+
return pjson.version;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Remove all listeners for a given event
|
|
95
|
+
*
|
|
96
|
+
* @param eventName The name of the event to remove listeners of
|
|
97
|
+
*/
|
|
98
|
+
removeAllListeners(eventName) {
|
|
99
|
+
this.listeners[eventName] = [];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get an array of listeners (callback functions) for a given event
|
|
103
|
+
*
|
|
104
|
+
* @param eventName The name of the event to get listeners of
|
|
105
|
+
*/
|
|
106
|
+
getListeners(eventName) {
|
|
107
|
+
const listeners = this.listeners[eventName];
|
|
108
|
+
if (listeners) {
|
|
109
|
+
return listeners;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.listeners[eventName] = [];
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create a listener for the `telemetry` event
|
|
118
|
+
*
|
|
119
|
+
* @param cb The callback function to run when the event is emitted
|
|
120
|
+
*/
|
|
121
|
+
onTelemetry(cb) {
|
|
122
|
+
this.on(Lifecycle.telemetryEventName, cb);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a listener for the `warning` event
|
|
126
|
+
*
|
|
127
|
+
* @param cb The callback function to run when the event is emitted
|
|
128
|
+
*/
|
|
129
|
+
onWarning(cb) {
|
|
130
|
+
this.on(Lifecycle.warningEventName, cb);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create a new listener for a given event
|
|
134
|
+
*
|
|
135
|
+
* @param eventName The name of the event that is being listened for
|
|
136
|
+
* @param cb The callback function to run when the event is emitted
|
|
137
|
+
*/
|
|
138
|
+
on(eventName, cb) {
|
|
139
|
+
const listeners = this.getListeners(eventName);
|
|
140
|
+
if (listeners.length !== 0) {
|
|
141
|
+
this.debug(`${listeners.length + 1} lifecycle events with the name ${eventName} have now been registered. When this event is emitted all ${listeners.length + 1} listeners will fire.`);
|
|
142
|
+
}
|
|
143
|
+
listeners.push(cb);
|
|
144
|
+
this.listeners[eventName] = listeners;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Emit a `telemetry` event, causing all callback functions to be run in the order they were registered
|
|
148
|
+
*
|
|
149
|
+
* @param data The data to emit
|
|
150
|
+
*/
|
|
151
|
+
async emitTelemetry(data) {
|
|
152
|
+
return this.emit(Lifecycle.telemetryEventName, data);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Emit a `warning` event, causing all callback functions to be run in the order they were registered
|
|
156
|
+
*
|
|
157
|
+
* @param data The warning (string) to emit
|
|
158
|
+
*/
|
|
159
|
+
async emitWarning(warning) {
|
|
160
|
+
// if there are no listeners, warnings should go to the node process so they're not lost
|
|
161
|
+
// this also preserves behavior in UT where there's a spy on process.emitWarning
|
|
162
|
+
if (this.getListeners(Lifecycle.warningEventName).length === 0) {
|
|
163
|
+
process.emitWarning(warning);
|
|
164
|
+
}
|
|
165
|
+
return this.emit(Lifecycle.warningEventName, warning);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Emit a given event, causing all callback functions to be run in the order they were registered
|
|
169
|
+
*
|
|
170
|
+
* @param eventName The name of the event to emit
|
|
171
|
+
* @param data The argument to be passed to the callback function
|
|
172
|
+
*/
|
|
173
|
+
async emit(eventName, data) {
|
|
174
|
+
const listeners = this.getListeners(eventName);
|
|
175
|
+
if (listeners.length === 0 && eventName !== Lifecycle.warningEventName) {
|
|
176
|
+
this.debug(`A lifecycle event with the name ${eventName} does not exist. An event must be registered before it can be emitted.`);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
for (const cb of listeners) {
|
|
180
|
+
// eslint-disable-next-line no-await-in-loop
|
|
181
|
+
await cb(data);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.Lifecycle = Lifecycle;
|
|
187
|
+
Lifecycle.telemetryEventName = 'telemetry';
|
|
188
|
+
Lifecycle.warningEventName = 'warning';
|
|
189
189
|
//# sourceMappingURL=lifecycleEvents.js.map
|