@salesforce/core 3.19.0 → 3.19.3
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/CHANGELOG.md +14 -0
- package/README.md +6 -18
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +27 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/configAggregator.d.ts +7 -5
- package/lib/config/configAggregator.js +25 -9
- package/lib/config/configFile.js +2 -2
- package/lib/config/configGroup.d.ts +141 -0
- package/lib/config/configGroup.js +224 -0
- package/lib/config/configStore.d.ts +2 -2
- package/lib/config/configStore.js +1 -2
- package/lib/config/envVars.d.ts +2 -3
- package/lib/config/envVars.js +8 -13
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +28 -0
- package/lib/crypto/keyChainImpl.js +1 -1
- package/lib/exported.d.ts +1 -1
- package/lib/exported.js +6 -5
- package/lib/global.d.ts +8 -0
- package/lib/global.js +10 -0
- package/lib/org/authInfo.d.ts +3 -2
- package/lib/org/authInfo.js +55 -37
- package/lib/org/authRemover.d.ts +6 -5
- package/lib/org/authRemover.js +22 -16
- package/lib/org/connection.js +3 -2
- package/lib/org/org.d.ts +12 -4
- package/lib/org/org.js +28 -26
- package/lib/org/scratchOrgCreate.js +5 -8
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +79 -1
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +119 -2
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +50 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +197 -0
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.d.ts +12 -1
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.js +22 -2
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +28 -0
- package/lib/{globalInfo → stateAggregator}/accessors/tokenAccessor.js +34 -2
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.d.ts +11 -8
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.js +7 -4
- package/lib/stateAggregator/index.d.ts +7 -0
- package/lib/{globalInfo → stateAggregator}/index.js +5 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.d.ts +7 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.js +25 -2
- package/lib/stateAggregator/stateAggregator.d.ts +20 -0
- package/lib/stateAggregator/stateAggregator.js +38 -0
- package/lib/{globalInfo → stateAggregator}/types.d.ts +25 -10
- package/lib/{globalInfo → stateAggregator}/types.js +3 -0
- package/lib/testSetup.d.ts +30 -6
- package/lib/testSetup.js +79 -11
- package/lib/util/sfdcUrl.d.ts +3 -9
- package/lib/util/sfdcUrl.js +29 -28
- package/messages/core.md +10 -0
- package/messages/scratchOrgCreate.md +0 -4
- package/messages/scratchOrgInfoApi.md +4 -0
- package/package.json +4 -4
- package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
- package/lib/globalInfo/accessors/orgAccessor.js +0 -45
- package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
- package/lib/globalInfo/index.d.ts +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [3.19.3](https://github.com/forcedotcom/sfdx-core/compare/v3.19.2...v3.19.3) (2022-06-06)
|
|
6
|
+
|
|
7
|
+
### [3.19.2](https://github.com/forcedotcom/sfdx-core/compare/v3.19.1...v3.19.2) (2022-06-02)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- loosen audience url determination ([#588](https://github.com/forcedotcom/sfdx-core/issues/588)) ([a58ab89](https://github.com/forcedotcom/sfdx-core/commit/a58ab89e2ada34fbdb6d8c72d88966a5281db60b))
|
|
12
|
+
|
|
13
|
+
### [3.19.1](https://github.com/forcedotcom/sfdx-core/compare/v3.19.0...v3.19.1) (2022-05-27)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- env var resolution in ConfigAggregator ([#590](https://github.com/forcedotcom/sfdx-core/issues/590)) ([a65cfbd](https://github.com/forcedotcom/sfdx-core/commit/a65cfbdd0e2a6c3806aa4da3270b237f68b37133))
|
|
18
|
+
|
|
5
19
|
## [3.19.0](https://github.com/forcedotcom/sfdx-core/compare/v3.18.3...v3.19.0) (2022-05-20)
|
|
6
20
|
|
|
7
21
|
### Features
|
package/README.md
CHANGED
|
@@ -36,14 +36,8 @@ const $$ = testSetup();
|
|
|
36
36
|
describe('Mocking Auth data', () => {
|
|
37
37
|
it('example', async () => {
|
|
38
38
|
const testData = new MockTestOrgData();
|
|
39
|
-
$$.
|
|
40
|
-
|
|
41
|
-
orgs: {
|
|
42
|
-
[testData.username]: await testData.getConfig(),
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
const auth: AuthInfo = await AuthInfo.create({ username: testData.username });
|
|
39
|
+
await $$.stubAuths(testData)
|
|
40
|
+
const auth = await AuthInfo.create({ username: testData.username });
|
|
47
41
|
strictEqual(auth.getUsername(), testData.username);
|
|
48
42
|
});
|
|
49
43
|
});
|
|
@@ -65,25 +59,19 @@ describe('Mocking a force server call', () => {
|
|
|
65
59
|
it('example', async () => {
|
|
66
60
|
const records: AnyJson = { records: ['123456', '234567'] };
|
|
67
61
|
const testData = new MockTestOrgData();
|
|
68
|
-
$$.
|
|
69
|
-
contents: {
|
|
70
|
-
orgs: {
|
|
71
|
-
[testData.username]: await testData.getConfig(),
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
});
|
|
62
|
+
await $$.stubAuths(testData);
|
|
75
63
|
$$.fakeConnectionRequest = (request: AnyJson): Promise<AnyJson> => {
|
|
76
|
-
const _request
|
|
64
|
+
const _request = ensureJsonMap(request);
|
|
77
65
|
if (request && ensureString(_request.url).includes('Account')) {
|
|
78
66
|
return Promise.resolve(records);
|
|
79
67
|
} else {
|
|
80
68
|
return Promise.reject(new SfError(`Unexpected request: ${_request.url}`));
|
|
81
69
|
}
|
|
82
70
|
};
|
|
83
|
-
const connection
|
|
71
|
+
const connection = await Connection.create({
|
|
84
72
|
authInfo: await AuthInfo.create({ username: testData.username }),
|
|
85
73
|
});
|
|
86
|
-
const result
|
|
74
|
+
const result = await connection.query('select Id From Account');
|
|
87
75
|
deepStrictEqual(result, records);
|
|
88
76
|
});
|
|
89
77
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConfigGroup } from './configGroup';
|
|
2
|
+
import { ConfigContents, ConfigValue } from './configStore';
|
|
3
|
+
/**
|
|
4
|
+
* Different groups of aliases. Currently only support orgs.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum AliasGroup {
|
|
7
|
+
ORGS = "orgs"
|
|
8
|
+
}
|
|
9
|
+
export declare class AliasesConfig extends ConfigGroup<ConfigGroup.Options> {
|
|
10
|
+
static getDefaultOptions(): ConfigGroup.Options;
|
|
11
|
+
protected setMethod(contents: ConfigContents, key: string, value?: ConfigValue): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, 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.AliasesConfig = exports.AliasGroup = void 0;
|
|
10
|
+
const configGroup_1 = require("./configGroup");
|
|
11
|
+
/**
|
|
12
|
+
* Different groups of aliases. Currently only support orgs.
|
|
13
|
+
*/
|
|
14
|
+
var AliasGroup;
|
|
15
|
+
(function (AliasGroup) {
|
|
16
|
+
AliasGroup["ORGS"] = "orgs";
|
|
17
|
+
})(AliasGroup = exports.AliasGroup || (exports.AliasGroup = {}));
|
|
18
|
+
class AliasesConfig extends configGroup_1.ConfigGroup {
|
|
19
|
+
static getDefaultOptions() {
|
|
20
|
+
return { ...configGroup_1.ConfigGroup.getOptions(AliasGroup.ORGS, 'alias.json'), isGlobal: true, isState: true };
|
|
21
|
+
}
|
|
22
|
+
setMethod(contents, key, value) {
|
|
23
|
+
contents[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AliasesConfig = AliasesConfig;
|
|
27
|
+
//# sourceMappingURL=aliasesConfig.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AuthFields } from '../org';
|
|
2
|
+
import { ConfigFile } from './configFile';
|
|
3
|
+
/**
|
|
4
|
+
* An auth config file that stores information such as access tokens, usernames, etc.,
|
|
5
|
+
* in the global sfdx directory (~/.sfdx).
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare class AuthInfoConfig extends ConfigFile<ConfigFile.Options, AuthFields> {
|
|
12
|
+
protected static encryptedKeys: RegExp[];
|
|
13
|
+
/**
|
|
14
|
+
* Gets the config options for a given org ID.
|
|
15
|
+
*
|
|
16
|
+
* @param username The username for the org.
|
|
17
|
+
*/
|
|
18
|
+
static getOptions(username: string): ConfigFile.Options;
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, 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.AuthInfoConfig = void 0;
|
|
10
|
+
const configFile_1 = require("./configFile");
|
|
11
|
+
/**
|
|
12
|
+
* An auth config file that stores information such as access tokens, usernames, etc.,
|
|
13
|
+
* in the global sfdx directory (~/.sfdx).
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
class AuthInfoConfig extends configFile_1.ConfigFile {
|
|
20
|
+
/**
|
|
21
|
+
* Gets the config options for a given org ID.
|
|
22
|
+
*
|
|
23
|
+
* @param username The username for the org.
|
|
24
|
+
*/
|
|
25
|
+
static getOptions(username) {
|
|
26
|
+
return {
|
|
27
|
+
isGlobal: true,
|
|
28
|
+
isState: true,
|
|
29
|
+
filename: `${username}.json`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.AuthInfoConfig = AuthInfoConfig;
|
|
34
|
+
AuthInfoConfig.encryptedKeys = [/token/gi, /password/gi, /secret/gi];
|
|
35
|
+
//# sourceMappingURL=authInfoConfig.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
2
|
-
import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
|
|
2
|
+
import { AnyJson, Dictionary, JsonMap, Optional } from '@salesforce/ts-types';
|
|
3
3
|
import { Config, ConfigPropertyMeta } from './config';
|
|
4
4
|
/**
|
|
5
5
|
* Information about a config property.
|
|
@@ -54,8 +54,8 @@ export interface ConfigInfo {
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Options> {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
protected static instance: AsyncOptionalCreatable;
|
|
58
|
+
protected static encrypted: boolean;
|
|
59
59
|
private allowedProperties;
|
|
60
60
|
private localConfig?;
|
|
61
61
|
private globalConfig;
|
|
@@ -161,7 +161,7 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggre
|
|
|
161
161
|
/**
|
|
162
162
|
* Get the config properties that are environment variables.
|
|
163
163
|
*/
|
|
164
|
-
getEnvVars():
|
|
164
|
+
getEnvVars(): Dictionary<string>;
|
|
165
165
|
/**
|
|
166
166
|
* Re-read all property configurations from disk.
|
|
167
167
|
*/
|
|
@@ -183,7 +183,7 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggre
|
|
|
183
183
|
/**
|
|
184
184
|
* Loads all the properties and aggregates them according to location.
|
|
185
185
|
*/
|
|
186
|
-
|
|
186
|
+
protected loadProperties(): Promise<void>;
|
|
187
187
|
/**
|
|
188
188
|
* Loads all the properties and aggregates them according to location.
|
|
189
189
|
*/
|
|
@@ -219,6 +219,8 @@ export declare namespace ConfigAggregator {
|
|
|
219
219
|
* @deprecated
|
|
220
220
|
*/
|
|
221
221
|
export declare class SfdxConfigAggregator extends ConfigAggregator {
|
|
222
|
+
protected static instance: AsyncOptionalCreatable;
|
|
223
|
+
protected static encrypted: boolean;
|
|
222
224
|
static create<P, T extends AsyncOptionalCreatable<P>>(this: new (options?: ConfigAggregator.Options) => T, options?: ConfigAggregator.Options): Promise<T>;
|
|
223
225
|
getPropertyMeta(key: string): ConfigPropertyMeta;
|
|
224
226
|
getPropertyValue<T extends AnyJson>(key: string): Optional<T>;
|
|
@@ -37,6 +37,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
37
37
|
*/
|
|
38
38
|
constructor(options) {
|
|
39
39
|
super(options || {});
|
|
40
|
+
this.envVars = {};
|
|
40
41
|
// Don't throw an project error with the aggregator, since it should resolve to global if
|
|
41
42
|
// there is no project.
|
|
42
43
|
try {
|
|
@@ -107,7 +108,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
107
108
|
*/
|
|
108
109
|
getPropertyValue(key) {
|
|
109
110
|
if (this.getAllowedProperties().some((element) => key === element.key)) {
|
|
110
|
-
return this.getConfig()[key]
|
|
111
|
+
return this.getConfig()[key];
|
|
111
112
|
}
|
|
112
113
|
else {
|
|
113
114
|
throw messages.createError('unknownConfigKey', [key]);
|
|
@@ -164,7 +165,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
164
165
|
* @param key The key of the property.
|
|
165
166
|
*/
|
|
166
167
|
getLocation(key) {
|
|
167
|
-
if (this.
|
|
168
|
+
if (this.envVars[key] != null) {
|
|
168
169
|
return "Environment" /* ENVIRONMENT */;
|
|
169
170
|
}
|
|
170
171
|
if (this.localConfig && this.localConfig.get(key)) {
|
|
@@ -189,8 +190,8 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
189
190
|
* @param key The key of the property.
|
|
190
191
|
*/
|
|
191
192
|
getPath(key) {
|
|
192
|
-
if (this.envVars
|
|
193
|
-
return `$${
|
|
193
|
+
if (this.envVars[key] != null) {
|
|
194
|
+
return `$${envVars_1.EnvVars.propertyToEnvName(key)}`;
|
|
194
195
|
}
|
|
195
196
|
if (this.localConfig && this.localConfig.getContents()[key] != null) {
|
|
196
197
|
return this.localConfig.getPath();
|
|
@@ -239,7 +240,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
239
240
|
* Get the config properties that are environment variables.
|
|
240
241
|
*/
|
|
241
242
|
getEnvVars() {
|
|
242
|
-
return this.envVars
|
|
243
|
+
return this.envVars;
|
|
243
244
|
}
|
|
244
245
|
/**
|
|
245
246
|
* Re-read all property configurations from disk.
|
|
@@ -287,9 +288,12 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
287
288
|
this.resolveProperties(this.globalConfig.readSync(), this.localConfig && this.localConfig.readSync());
|
|
288
289
|
}
|
|
289
290
|
resolveProperties(globalConfig, localConfig) {
|
|
290
|
-
|
|
291
|
+
const envVars = new envVars_1.EnvVars();
|
|
291
292
|
for (const property of this.getAllowedProperties()) {
|
|
292
|
-
|
|
293
|
+
const key = property.newKey ? property.newKey : property.key;
|
|
294
|
+
const value = envVars.getPropertyFromEnv(property.key);
|
|
295
|
+
if (value)
|
|
296
|
+
this.envVars[key] = value;
|
|
293
297
|
}
|
|
294
298
|
// Global config must be read first so it is on the left hand of the
|
|
295
299
|
// object assign and is overwritten by the local config.
|
|
@@ -298,7 +302,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
|
|
|
298
302
|
if (localConfig) {
|
|
299
303
|
configs.push(localConfig);
|
|
300
304
|
}
|
|
301
|
-
configs.push(this.envVars
|
|
305
|
+
configs.push(this.envVars);
|
|
302
306
|
const json = {};
|
|
303
307
|
const reduced = configs.filter(ts_types_1.isJsonMap).reduce((acc, el) => (0, kit_1.merge)(acc, el), json);
|
|
304
308
|
return reduced;
|
|
@@ -320,7 +324,18 @@ class SfdxConfigAggregator extends ConfigAggregator {
|
|
|
320
324
|
const restDeploy = config_1.SFDX_ALLOWED_PROPERTIES.find((p) => p.key === config_1.SfdxPropertyKeys.REST_DEPLOY);
|
|
321
325
|
const orgRestDeploy = Object.assign({}, restDeploy, { key: 'org-metadata-rest-deploy', deprecated: false });
|
|
322
326
|
options.customConfigMeta = [...customConfigMeta, orgRestDeploy];
|
|
323
|
-
|
|
327
|
+
let config = SfdxConfigAggregator.instance;
|
|
328
|
+
if (!config) {
|
|
329
|
+
config = SfdxConfigAggregator.instance = new this(options);
|
|
330
|
+
await config.init();
|
|
331
|
+
}
|
|
332
|
+
if (SfdxConfigAggregator.encrypted) {
|
|
333
|
+
await config.loadProperties();
|
|
334
|
+
}
|
|
335
|
+
if (options === null || options === void 0 ? void 0 : options.customConfigMeta) {
|
|
336
|
+
config_1.Config.addAllowedProperties(options.customConfigMeta);
|
|
337
|
+
}
|
|
338
|
+
return SfdxConfigAggregator.instance;
|
|
324
339
|
}
|
|
325
340
|
getPropertyMeta(key) {
|
|
326
341
|
const match = this.getAllowedProperties().find((element) => key === element.key);
|
|
@@ -363,4 +378,5 @@ class SfdxConfigAggregator extends ConfigAggregator {
|
|
|
363
378
|
}
|
|
364
379
|
}
|
|
365
380
|
exports.SfdxConfigAggregator = SfdxConfigAggregator;
|
|
381
|
+
SfdxConfigAggregator.encrypted = true;
|
|
366
382
|
//# sourceMappingURL=configAggregator.js.map
|
package/lib/config/configFile.js
CHANGED
|
@@ -80,7 +80,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
|
|
|
80
80
|
isGlobal,
|
|
81
81
|
isState: true,
|
|
82
82
|
filename: filename || this.getFileName(),
|
|
83
|
-
stateFolder: global_1.Global.
|
|
83
|
+
stateFolder: global_1.Global.SFDX_STATE_FOLDER,
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
@@ -306,7 +306,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
|
|
|
306
306
|
? this.options.rootFolder
|
|
307
307
|
: ConfigFile.resolveRootFolderSync(!!this.options.isGlobal);
|
|
308
308
|
if (_isGlobal || _isState) {
|
|
309
|
-
configRootFolder = (0, path_1.join)(configRootFolder, this.options.stateFolder || global_1.Global.
|
|
309
|
+
configRootFolder = (0, path_1.join)(configRootFolder, this.options.stateFolder || global_1.Global.SFDX_STATE_FOLDER);
|
|
310
310
|
}
|
|
311
311
|
this.path = (0, path_1.join)(configRootFolder, this.options.filePath ? this.options.filePath : '', this.options.filename);
|
|
312
312
|
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Dictionary, JsonMap, Optional } from '@salesforce/ts-types';
|
|
2
|
+
import { ConfigFile } from './configFile';
|
|
3
|
+
import { ConfigContents, ConfigEntry, ConfigValue } from './configStore';
|
|
4
|
+
/**
|
|
5
|
+
* A config file that stores config values in groups. e.g. to store different config
|
|
6
|
+
* values for different commands, without having manually manipulate the config.
|
|
7
|
+
*
|
|
8
|
+
* **Note:** All config methods are overwritten to use the {@link ConfigGroup.setDefaultGroup}.
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
11
|
+
* class MyPluginConfig extends ConfigGroup<ConfigGroup.Options> {
|
|
12
|
+
* public static getFileName(): string {
|
|
13
|
+
* return 'myPluginConfigFilename.json';
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* const myConfig = await MyPluginConfig.create(ConfigGroup.getOptions('all'));
|
|
17
|
+
* myConfig.setDefaultGroup('myCommand'); // Can be set in your command's init.
|
|
18
|
+
* myConfig.set('mykey', 'myvalue'); // Sets 'myKey' for the 'myCommand' group.
|
|
19
|
+
* myConfig.setInGroup('myKey', 'myvalue', 'all'); // Manually set in another group.
|
|
20
|
+
* await myConfig.write();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class ConfigGroup<T extends ConfigGroup.Options> extends ConfigFile<T> {
|
|
24
|
+
protected defaultGroup: string;
|
|
25
|
+
/**
|
|
26
|
+
* Get ConfigGroup specific options, such as the default group.
|
|
27
|
+
*
|
|
28
|
+
* @param defaultGroup The default group to use when creating the config.
|
|
29
|
+
* @param filename The filename of the config file. Uses the static {@link getFileName} by default.
|
|
30
|
+
*/
|
|
31
|
+
static getOptions(defaultGroup: string, filename?: string): ConfigGroup.Options;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the default group for all {@link BaseConfigStore} methods to use.
|
|
34
|
+
* **Throws** *{@link SfError}{ name: 'MissingGroupName' }* The group parameter is null or undefined.
|
|
35
|
+
*
|
|
36
|
+
* @param group The group.
|
|
37
|
+
*/
|
|
38
|
+
setDefaultGroup(group: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Set a group of entries in a bulk save. Returns The new properties that were saved.
|
|
41
|
+
*
|
|
42
|
+
* @param newEntries An object representing the aliases to set.
|
|
43
|
+
* @param group The group the property belongs to.
|
|
44
|
+
*/
|
|
45
|
+
updateValues(newEntries: Dictionary<ConfigValue>, group?: string): Promise<Dictionary<ConfigValue>>;
|
|
46
|
+
/**
|
|
47
|
+
* Set a value on a group. Returns the promise resolved when the value is set.
|
|
48
|
+
*
|
|
49
|
+
* @param key The key.
|
|
50
|
+
* @param value The value.
|
|
51
|
+
* @param group The group.
|
|
52
|
+
*/
|
|
53
|
+
updateValue(key: string, value: ConfigValue, group?: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Gets an array of key value pairs.
|
|
56
|
+
*/
|
|
57
|
+
entries(): ConfigEntry[];
|
|
58
|
+
/**
|
|
59
|
+
* Returns a specified element from ConfigGroup. Returns the associated value.
|
|
60
|
+
*
|
|
61
|
+
* @param key The key.
|
|
62
|
+
*/
|
|
63
|
+
get(key: string): Optional<ConfigValue>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a boolean if an element with the specified key exists in the default group.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} key The key.
|
|
68
|
+
*/
|
|
69
|
+
has(key: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Returns an array of the keys from the default group.
|
|
72
|
+
*/
|
|
73
|
+
keys(): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Returns an array of the values from the default group.
|
|
76
|
+
*/
|
|
77
|
+
values(): ConfigValue[];
|
|
78
|
+
/**
|
|
79
|
+
* Add or updates an element with the specified key in the default group.
|
|
80
|
+
*
|
|
81
|
+
* @param key The key.
|
|
82
|
+
* @param value The value.
|
|
83
|
+
*/
|
|
84
|
+
set(key: string, value: ConfigValue): ConfigContents;
|
|
85
|
+
/**
|
|
86
|
+
* Removes an element with the specified key from the default group. Returns `true` if the item was deleted.
|
|
87
|
+
*
|
|
88
|
+
* @param key The key.
|
|
89
|
+
*/
|
|
90
|
+
unset(key: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Remove all key value pairs from the default group.
|
|
93
|
+
*/
|
|
94
|
+
clear(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Get all config contents for a group.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} [group = 'default'] The group.
|
|
99
|
+
*/
|
|
100
|
+
getGroup(group?: string): Optional<ConfigContents>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the value associated to the key and group, or undefined if there is none.
|
|
103
|
+
*
|
|
104
|
+
* @param key The key.
|
|
105
|
+
* @param group The group. Defaults to the default group.
|
|
106
|
+
*/
|
|
107
|
+
getInGroup(key: string, group?: string): Optional<ConfigValue>;
|
|
108
|
+
/**
|
|
109
|
+
* Convert the config object to a json object.
|
|
110
|
+
*/
|
|
111
|
+
toObject(): JsonMap;
|
|
112
|
+
/**
|
|
113
|
+
* Convert an object to a {@link ConfigContents} and set it as the config contents.
|
|
114
|
+
*
|
|
115
|
+
* @param {object} obj The object.
|
|
116
|
+
*/
|
|
117
|
+
setContentsFromObject<U extends object>(obj: U): void;
|
|
118
|
+
/**
|
|
119
|
+
* Sets the value for the key and group in the config object.
|
|
120
|
+
*
|
|
121
|
+
* @param key The key.
|
|
122
|
+
* @param value The value.
|
|
123
|
+
* @param group The group. Uses the default group if not specified.
|
|
124
|
+
*/
|
|
125
|
+
setInGroup(key: string, value?: ConfigValue, group?: string): ConfigContents;
|
|
126
|
+
/**
|
|
127
|
+
* Initialize the asynchronous dependencies.
|
|
128
|
+
*/
|
|
129
|
+
init(): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
export declare namespace ConfigGroup {
|
|
132
|
+
/**
|
|
133
|
+
* Options when creating the config file.
|
|
134
|
+
*/
|
|
135
|
+
interface Options extends ConfigFile.Options {
|
|
136
|
+
/**
|
|
137
|
+
* The default group for properties to go into.
|
|
138
|
+
*/
|
|
139
|
+
defaultGroup?: string;
|
|
140
|
+
}
|
|
141
|
+
}
|