@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/schema/printer.js
CHANGED
|
@@ -1,261 +1,261 @@
|
|
|
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
|
-
/* eslint-disable class-methods-use-this */
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.SchemaPrinter = exports.SchemaPropertyRenderer = void 0;
|
|
11
|
-
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
|
-
const sfError_1 = require("../sfError");
|
|
13
|
-
/**
|
|
14
|
-
* Renders schema properties. By default, this is simply an identity transform. Subclasses may provide more
|
|
15
|
-
* interesting decorations of each values, such as ANSI coloring.
|
|
16
|
-
*
|
|
17
|
-
* @deprecated
|
|
18
|
-
*/
|
|
19
|
-
class SchemaPropertyRenderer {
|
|
20
|
-
/**
|
|
21
|
-
* Renders a name.
|
|
22
|
-
*
|
|
23
|
-
* @param name The name value to render.
|
|
24
|
-
*/
|
|
25
|
-
renderName(name) {
|
|
26
|
-
return name;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Renders a title.
|
|
30
|
-
*
|
|
31
|
-
* @param title The title value to render.
|
|
32
|
-
*/
|
|
33
|
-
renderTitle(title) {
|
|
34
|
-
return title;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Renders a description.
|
|
38
|
-
*
|
|
39
|
-
* @param description The description value to render.
|
|
40
|
-
*/
|
|
41
|
-
renderDescription(description) {
|
|
42
|
-
return description;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Renders a type.
|
|
46
|
-
*
|
|
47
|
-
* @param propertyType The type value to render.
|
|
48
|
-
*/
|
|
49
|
-
renderType(propertyType) {
|
|
50
|
-
return propertyType;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.SchemaPropertyRenderer = SchemaPropertyRenderer;
|
|
54
|
-
/**
|
|
55
|
-
* Prints a JSON schema in a human-friendly format.
|
|
56
|
-
*
|
|
57
|
-
* @deprecated
|
|
58
|
-
*
|
|
59
|
-
* ```
|
|
60
|
-
* import chalk from 'chalk';
|
|
61
|
-
* class MyPropertyRenderer extends SchemaPropertyRenderer {
|
|
62
|
-
* renderName(name) { return chalk.bold.blue(name); }
|
|
63
|
-
* }
|
|
64
|
-
*
|
|
65
|
-
* const printer = new SchemaPrinter(logger, schema, new MyPropertyRenderer());
|
|
66
|
-
* printer.getLines().forEach(console.log);
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
class SchemaPrinter {
|
|
70
|
-
/**
|
|
71
|
-
* Constructs a new `SchemaPrinter`.
|
|
72
|
-
*
|
|
73
|
-
* @param logger The logger to use when emitting the printed schema.
|
|
74
|
-
* @param schema The schema to print.
|
|
75
|
-
* @param propertyRenderer The property renderer.
|
|
76
|
-
*/
|
|
77
|
-
constructor(logger, schema, propertyRenderer = new SchemaPropertyRenderer()) {
|
|
78
|
-
this.schema = schema;
|
|
79
|
-
this.propertyRenderer = propertyRenderer;
|
|
80
|
-
this.lines = [];
|
|
81
|
-
this.logger = logger.child('SchemaPrinter');
|
|
82
|
-
if (!this.schema.properties && !this.schema.items) {
|
|
83
|
-
// No need to add to messages, since this should never happen. In fact,
|
|
84
|
-
// this will cause a test failure if there is a command that uses a schema
|
|
85
|
-
// with no properties defined.
|
|
86
|
-
throw new sfError_1.SfError('There is no purpose to print a schema with no properties or items');
|
|
87
|
-
}
|
|
88
|
-
const startLevel = 0;
|
|
89
|
-
const add = this.addFn(startLevel);
|
|
90
|
-
// For object schemas, print out the "header" and first level properties differently
|
|
91
|
-
if (this.schema.properties) {
|
|
92
|
-
if (typeof this.schema.description === 'string') {
|
|
93
|
-
// Output the overall schema description before printing the properties
|
|
94
|
-
add(this.schema.description);
|
|
95
|
-
add('');
|
|
96
|
-
}
|
|
97
|
-
Object.keys(this.schema.properties).forEach((key) => {
|
|
98
|
-
const properties = (0, ts_types_1.asJsonMap)(this.schema.properties);
|
|
99
|
-
if (!properties) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
this.parseProperty(key, (0, ts_types_1.asJsonMap)(properties[key]), startLevel);
|
|
103
|
-
add('');
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
this.parseProperty('schema', this.schema, startLevel);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Gets a read-only array of ready-to-display lines.
|
|
112
|
-
*/
|
|
113
|
-
getLines() {
|
|
114
|
-
return this.lines;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Gets a ready-to-display line by index.
|
|
118
|
-
*
|
|
119
|
-
* @param index The line index to get.
|
|
120
|
-
*/
|
|
121
|
-
getLine(index) {
|
|
122
|
-
return this.lines[index];
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Prints the accumulated set of schema lines as info log lines to the logger.
|
|
126
|
-
*/
|
|
127
|
-
print() {
|
|
128
|
-
this.lines.forEach((line) => this.logger.info(line));
|
|
129
|
-
}
|
|
130
|
-
addFn(level) {
|
|
131
|
-
const indent = ' '.repeat(level * 4);
|
|
132
|
-
return (line) => {
|
|
133
|
-
this.lines.push(`${indent}${line}`);
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
parseProperty(name, rawProperty, level = 0) {
|
|
137
|
-
if (!rawProperty) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const add = this.addFn(level);
|
|
141
|
-
const property = new SchemaProperty(this.logger, this.schema, name, rawProperty, this.propertyRenderer);
|
|
142
|
-
add(property.renderHeader());
|
|
143
|
-
if (property.type === 'object' && property.properties) {
|
|
144
|
-
Object.keys(property.properties).forEach((key) => {
|
|
145
|
-
this.parseProperty(key, property.getProperty(key), level + 1);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if (property.type === 'array') {
|
|
149
|
-
add(` ${property.renderArrayHeader()}`);
|
|
150
|
-
if (property.items && property.items.type === 'object' && property.items.properties) {
|
|
151
|
-
Object.keys(property.items.properties).forEach((key) => {
|
|
152
|
-
const items = (0, ts_types_1.asJsonMap)(property.items);
|
|
153
|
-
if (!items) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const properties = (0, ts_types_1.asJsonMap)(items.properties);
|
|
157
|
-
if (!properties) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
this.parseProperty(key, (0, ts_types_1.asJsonMap)(properties[key]), level + 2);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (property.required) {
|
|
165
|
-
add(`Required: ${property.required.join(', ')}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.SchemaPrinter = SchemaPrinter;
|
|
170
|
-
class SchemaProperty {
|
|
171
|
-
constructor(logger, schema, name, rawProperty, propertyRenderer) {
|
|
172
|
-
this.logger = logger;
|
|
173
|
-
this.schema = schema;
|
|
174
|
-
this.name = name;
|
|
175
|
-
this.rawProperty = rawProperty;
|
|
176
|
-
this.propertyRenderer = propertyRenderer;
|
|
177
|
-
this.name = name;
|
|
178
|
-
// Capture the referenced definition, if specified
|
|
179
|
-
if (typeof this.rawProperty.$ref === 'string') {
|
|
180
|
-
// Copy the referenced property while adding the original property's properties on top of that --
|
|
181
|
-
// if they are defined here, they take precedence over referenced definition properties.
|
|
182
|
-
this.rawProperty = Object.assign({}, resolveRef(this.schema, this.rawProperty), rawProperty);
|
|
183
|
-
}
|
|
184
|
-
const oneOfs = (0, ts_types_1.asJsonArray)(this.rawProperty.oneOf);
|
|
185
|
-
if (oneOfs && !this.rawProperty.type) {
|
|
186
|
-
this.rawProperty.type = oneOfs.map((value) => ((0, ts_types_1.isJsonMap)(value) ? value.type ?? value.$ref : value)).join('|');
|
|
187
|
-
}
|
|
188
|
-
// Handle items references
|
|
189
|
-
if ((0, ts_types_1.isJsonMap)(this.items) && this.items && this.items.$ref) {
|
|
190
|
-
Object.assign(this.items, resolveRef(this.schema, this.items));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
get title() {
|
|
194
|
-
return (0, ts_types_1.asString)(this.rawProperty.title);
|
|
195
|
-
}
|
|
196
|
-
get description() {
|
|
197
|
-
return (0, ts_types_1.asString)(this.rawProperty.description);
|
|
198
|
-
}
|
|
199
|
-
get type() {
|
|
200
|
-
return (0, ts_types_1.asString)(this.rawProperty.type);
|
|
201
|
-
}
|
|
202
|
-
get required() {
|
|
203
|
-
return (0, ts_types_1.asJsonArray)(this.rawProperty.required);
|
|
204
|
-
}
|
|
205
|
-
get properties() {
|
|
206
|
-
return (0, ts_types_1.asJsonMap)(this.rawProperty.properties);
|
|
207
|
-
}
|
|
208
|
-
get items() {
|
|
209
|
-
return (0, ts_types_1.asJsonMap)(this.rawProperty.items);
|
|
210
|
-
}
|
|
211
|
-
get minItems() {
|
|
212
|
-
return (0, ts_types_1.asNumber)(this.rawProperty.minItems);
|
|
213
|
-
}
|
|
214
|
-
getProperty(key) {
|
|
215
|
-
const properties = this.getProperties();
|
|
216
|
-
return (0, ts_types_1.asJsonMap)(properties?.[key]);
|
|
217
|
-
}
|
|
218
|
-
getProperties() {
|
|
219
|
-
return (0, ts_types_1.asJsonMap)(this.rawProperty.properties);
|
|
220
|
-
}
|
|
221
|
-
renderName() {
|
|
222
|
-
return this.propertyRenderer.renderName(this.name);
|
|
223
|
-
}
|
|
224
|
-
renderTitle() {
|
|
225
|
-
return this.propertyRenderer.renderTitle(this.title ?? '');
|
|
226
|
-
}
|
|
227
|
-
renderDescription() {
|
|
228
|
-
return this.propertyRenderer.renderDescription(this.description ?? '');
|
|
229
|
-
}
|
|
230
|
-
renderType() {
|
|
231
|
-
return this.propertyRenderer.renderType(this.type ?? '');
|
|
232
|
-
}
|
|
233
|
-
renderHeader() {
|
|
234
|
-
return `${this.renderName()}(${this.renderType()}) - ${this.renderTitle()}: ${this.renderDescription()}`;
|
|
235
|
-
}
|
|
236
|
-
renderArrayHeader() {
|
|
237
|
-
if (!this.items) {
|
|
238
|
-
return '';
|
|
239
|
-
}
|
|
240
|
-
const minItems = this.minItems ? ` - min ${this.minItems}` : '';
|
|
241
|
-
const prop = new SchemaProperty(this.logger, this.schema, 'items', this.items, this.propertyRenderer);
|
|
242
|
-
return `items(${prop.renderType()}${minItems}) - ${prop.renderTitle()}: ${prop.renderDescription()}`;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Get the referenced definition by following the reference path on the current schema.
|
|
247
|
-
*
|
|
248
|
-
* @param schema The source schema containing the property containing a `$ref` field.
|
|
249
|
-
* @param property The property that contains the `$ref` field.
|
|
250
|
-
*/
|
|
251
|
-
function resolveRef(schema, property) {
|
|
252
|
-
const ref = property.$ref;
|
|
253
|
-
if (!ref || typeof ref !== 'string') {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
return ref.split('/').reduce((prev, key) => {
|
|
257
|
-
const next = prev[key];
|
|
258
|
-
return key === '#' ? schema : (0, ts_types_1.isJsonMap)(next) ? next : {};
|
|
259
|
-
}, property);
|
|
260
|
-
}
|
|
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
|
+
/* eslint-disable class-methods-use-this */
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SchemaPrinter = exports.SchemaPropertyRenderer = void 0;
|
|
11
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
|
+
const sfError_1 = require("../sfError");
|
|
13
|
+
/**
|
|
14
|
+
* Renders schema properties. By default, this is simply an identity transform. Subclasses may provide more
|
|
15
|
+
* interesting decorations of each values, such as ANSI coloring.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated
|
|
18
|
+
*/
|
|
19
|
+
class SchemaPropertyRenderer {
|
|
20
|
+
/**
|
|
21
|
+
* Renders a name.
|
|
22
|
+
*
|
|
23
|
+
* @param name The name value to render.
|
|
24
|
+
*/
|
|
25
|
+
renderName(name) {
|
|
26
|
+
return name;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Renders a title.
|
|
30
|
+
*
|
|
31
|
+
* @param title The title value to render.
|
|
32
|
+
*/
|
|
33
|
+
renderTitle(title) {
|
|
34
|
+
return title;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Renders a description.
|
|
38
|
+
*
|
|
39
|
+
* @param description The description value to render.
|
|
40
|
+
*/
|
|
41
|
+
renderDescription(description) {
|
|
42
|
+
return description;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Renders a type.
|
|
46
|
+
*
|
|
47
|
+
* @param propertyType The type value to render.
|
|
48
|
+
*/
|
|
49
|
+
renderType(propertyType) {
|
|
50
|
+
return propertyType;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.SchemaPropertyRenderer = SchemaPropertyRenderer;
|
|
54
|
+
/**
|
|
55
|
+
* Prints a JSON schema in a human-friendly format.
|
|
56
|
+
*
|
|
57
|
+
* @deprecated
|
|
58
|
+
*
|
|
59
|
+
* ```
|
|
60
|
+
* import chalk from 'chalk';
|
|
61
|
+
* class MyPropertyRenderer extends SchemaPropertyRenderer {
|
|
62
|
+
* renderName(name) { return chalk.bold.blue(name); }
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* const printer = new SchemaPrinter(logger, schema, new MyPropertyRenderer());
|
|
66
|
+
* printer.getLines().forEach(console.log);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
class SchemaPrinter {
|
|
70
|
+
/**
|
|
71
|
+
* Constructs a new `SchemaPrinter`.
|
|
72
|
+
*
|
|
73
|
+
* @param logger The logger to use when emitting the printed schema.
|
|
74
|
+
* @param schema The schema to print.
|
|
75
|
+
* @param propertyRenderer The property renderer.
|
|
76
|
+
*/
|
|
77
|
+
constructor(logger, schema, propertyRenderer = new SchemaPropertyRenderer()) {
|
|
78
|
+
this.schema = schema;
|
|
79
|
+
this.propertyRenderer = propertyRenderer;
|
|
80
|
+
this.lines = [];
|
|
81
|
+
this.logger = logger.child('SchemaPrinter');
|
|
82
|
+
if (!this.schema.properties && !this.schema.items) {
|
|
83
|
+
// No need to add to messages, since this should never happen. In fact,
|
|
84
|
+
// this will cause a test failure if there is a command that uses a schema
|
|
85
|
+
// with no properties defined.
|
|
86
|
+
throw new sfError_1.SfError('There is no purpose to print a schema with no properties or items');
|
|
87
|
+
}
|
|
88
|
+
const startLevel = 0;
|
|
89
|
+
const add = this.addFn(startLevel);
|
|
90
|
+
// For object schemas, print out the "header" and first level properties differently
|
|
91
|
+
if (this.schema.properties) {
|
|
92
|
+
if (typeof this.schema.description === 'string') {
|
|
93
|
+
// Output the overall schema description before printing the properties
|
|
94
|
+
add(this.schema.description);
|
|
95
|
+
add('');
|
|
96
|
+
}
|
|
97
|
+
Object.keys(this.schema.properties).forEach((key) => {
|
|
98
|
+
const properties = (0, ts_types_1.asJsonMap)(this.schema.properties);
|
|
99
|
+
if (!properties) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.parseProperty(key, (0, ts_types_1.asJsonMap)(properties[key]), startLevel);
|
|
103
|
+
add('');
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.parseProperty('schema', this.schema, startLevel);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets a read-only array of ready-to-display lines.
|
|
112
|
+
*/
|
|
113
|
+
getLines() {
|
|
114
|
+
return this.lines;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Gets a ready-to-display line by index.
|
|
118
|
+
*
|
|
119
|
+
* @param index The line index to get.
|
|
120
|
+
*/
|
|
121
|
+
getLine(index) {
|
|
122
|
+
return this.lines[index];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Prints the accumulated set of schema lines as info log lines to the logger.
|
|
126
|
+
*/
|
|
127
|
+
print() {
|
|
128
|
+
this.lines.forEach((line) => this.logger.info(line));
|
|
129
|
+
}
|
|
130
|
+
addFn(level) {
|
|
131
|
+
const indent = ' '.repeat(level * 4);
|
|
132
|
+
return (line) => {
|
|
133
|
+
this.lines.push(`${indent}${line}`);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
parseProperty(name, rawProperty, level = 0) {
|
|
137
|
+
if (!rawProperty) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const add = this.addFn(level);
|
|
141
|
+
const property = new SchemaProperty(this.logger, this.schema, name, rawProperty, this.propertyRenderer);
|
|
142
|
+
add(property.renderHeader());
|
|
143
|
+
if (property.type === 'object' && property.properties) {
|
|
144
|
+
Object.keys(property.properties).forEach((key) => {
|
|
145
|
+
this.parseProperty(key, property.getProperty(key), level + 1);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (property.type === 'array') {
|
|
149
|
+
add(` ${property.renderArrayHeader()}`);
|
|
150
|
+
if (property.items && property.items.type === 'object' && property.items.properties) {
|
|
151
|
+
Object.keys(property.items.properties).forEach((key) => {
|
|
152
|
+
const items = (0, ts_types_1.asJsonMap)(property.items);
|
|
153
|
+
if (!items) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const properties = (0, ts_types_1.asJsonMap)(items.properties);
|
|
157
|
+
if (!properties) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.parseProperty(key, (0, ts_types_1.asJsonMap)(properties[key]), level + 2);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (property.required) {
|
|
165
|
+
add(`Required: ${property.required.join(', ')}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.SchemaPrinter = SchemaPrinter;
|
|
170
|
+
class SchemaProperty {
|
|
171
|
+
constructor(logger, schema, name, rawProperty, propertyRenderer) {
|
|
172
|
+
this.logger = logger;
|
|
173
|
+
this.schema = schema;
|
|
174
|
+
this.name = name;
|
|
175
|
+
this.rawProperty = rawProperty;
|
|
176
|
+
this.propertyRenderer = propertyRenderer;
|
|
177
|
+
this.name = name;
|
|
178
|
+
// Capture the referenced definition, if specified
|
|
179
|
+
if (typeof this.rawProperty.$ref === 'string') {
|
|
180
|
+
// Copy the referenced property while adding the original property's properties on top of that --
|
|
181
|
+
// if they are defined here, they take precedence over referenced definition properties.
|
|
182
|
+
this.rawProperty = Object.assign({}, resolveRef(this.schema, this.rawProperty), rawProperty);
|
|
183
|
+
}
|
|
184
|
+
const oneOfs = (0, ts_types_1.asJsonArray)(this.rawProperty.oneOf);
|
|
185
|
+
if (oneOfs && !this.rawProperty.type) {
|
|
186
|
+
this.rawProperty.type = oneOfs.map((value) => ((0, ts_types_1.isJsonMap)(value) ? value.type ?? value.$ref : value)).join('|');
|
|
187
|
+
}
|
|
188
|
+
// Handle items references
|
|
189
|
+
if ((0, ts_types_1.isJsonMap)(this.items) && this.items && this.items.$ref) {
|
|
190
|
+
Object.assign(this.items, resolveRef(this.schema, this.items));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
get title() {
|
|
194
|
+
return (0, ts_types_1.asString)(this.rawProperty.title);
|
|
195
|
+
}
|
|
196
|
+
get description() {
|
|
197
|
+
return (0, ts_types_1.asString)(this.rawProperty.description);
|
|
198
|
+
}
|
|
199
|
+
get type() {
|
|
200
|
+
return (0, ts_types_1.asString)(this.rawProperty.type);
|
|
201
|
+
}
|
|
202
|
+
get required() {
|
|
203
|
+
return (0, ts_types_1.asJsonArray)(this.rawProperty.required);
|
|
204
|
+
}
|
|
205
|
+
get properties() {
|
|
206
|
+
return (0, ts_types_1.asJsonMap)(this.rawProperty.properties);
|
|
207
|
+
}
|
|
208
|
+
get items() {
|
|
209
|
+
return (0, ts_types_1.asJsonMap)(this.rawProperty.items);
|
|
210
|
+
}
|
|
211
|
+
get minItems() {
|
|
212
|
+
return (0, ts_types_1.asNumber)(this.rawProperty.minItems);
|
|
213
|
+
}
|
|
214
|
+
getProperty(key) {
|
|
215
|
+
const properties = this.getProperties();
|
|
216
|
+
return (0, ts_types_1.asJsonMap)(properties?.[key]);
|
|
217
|
+
}
|
|
218
|
+
getProperties() {
|
|
219
|
+
return (0, ts_types_1.asJsonMap)(this.rawProperty.properties);
|
|
220
|
+
}
|
|
221
|
+
renderName() {
|
|
222
|
+
return this.propertyRenderer.renderName(this.name);
|
|
223
|
+
}
|
|
224
|
+
renderTitle() {
|
|
225
|
+
return this.propertyRenderer.renderTitle(this.title ?? '');
|
|
226
|
+
}
|
|
227
|
+
renderDescription() {
|
|
228
|
+
return this.propertyRenderer.renderDescription(this.description ?? '');
|
|
229
|
+
}
|
|
230
|
+
renderType() {
|
|
231
|
+
return this.propertyRenderer.renderType(this.type ?? '');
|
|
232
|
+
}
|
|
233
|
+
renderHeader() {
|
|
234
|
+
return `${this.renderName()}(${this.renderType()}) - ${this.renderTitle()}: ${this.renderDescription()}`;
|
|
235
|
+
}
|
|
236
|
+
renderArrayHeader() {
|
|
237
|
+
if (!this.items) {
|
|
238
|
+
return '';
|
|
239
|
+
}
|
|
240
|
+
const minItems = this.minItems ? ` - min ${this.minItems}` : '';
|
|
241
|
+
const prop = new SchemaProperty(this.logger, this.schema, 'items', this.items, this.propertyRenderer);
|
|
242
|
+
return `items(${prop.renderType()}${minItems}) - ${prop.renderTitle()}: ${prop.renderDescription()}`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get the referenced definition by following the reference path on the current schema.
|
|
247
|
+
*
|
|
248
|
+
* @param schema The source schema containing the property containing a `$ref` field.
|
|
249
|
+
* @param property The property that contains the `$ref` field.
|
|
250
|
+
*/
|
|
251
|
+
function resolveRef(schema, property) {
|
|
252
|
+
const ref = property.$ref;
|
|
253
|
+
if (!ref || typeof ref !== 'string') {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
return ref.split('/').reduce((prev, key) => {
|
|
257
|
+
const next = prev[key];
|
|
258
|
+
return key === '#' ? schema : (0, ts_types_1.isJsonMap)(next) ? next : {};
|
|
259
|
+
}, property);
|
|
260
|
+
}
|
|
261
261
|
//# sourceMappingURL=printer.js.map
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { AnyJson, JsonMap } from '@salesforce/ts-types';
|
|
2
|
-
import { Logger } from '../logger';
|
|
3
|
-
/**
|
|
4
|
-
* Loads a JSON schema and performs validations against JSON objects.
|
|
5
|
-
*/
|
|
6
|
-
export declare class SchemaValidator {
|
|
7
|
-
private schemaPath;
|
|
8
|
-
private readonly schemasDir;
|
|
9
|
-
private readonly logger;
|
|
10
|
-
private schema?;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new `SchemaValidator` instance given a logger and path to a schema file.
|
|
13
|
-
*
|
|
14
|
-
* @param logger An {@link Logger} instance on which to base this class's logger.
|
|
15
|
-
* @param schemaPath The path to the schema file to load and use for validation.
|
|
16
|
-
*/
|
|
17
|
-
constructor(logger: Logger, schemaPath: string);
|
|
18
|
-
/**
|
|
19
|
-
* Loads a JSON schema from the `schemaPath` parameter provided at instantiation.
|
|
20
|
-
*/
|
|
21
|
-
load(): Promise<JsonMap>;
|
|
22
|
-
/**
|
|
23
|
-
* Loads a JSON schema from the `schemaPath` parameter provided at instantiation.
|
|
24
|
-
*/
|
|
25
|
-
loadSync(): JsonMap;
|
|
26
|
-
/**
|
|
27
|
-
* Performs validation of JSON data against the schema located at the `schemaPath` value provided
|
|
28
|
-
* at instantiation.
|
|
29
|
-
*
|
|
30
|
-
* **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
|
|
31
|
-
* **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
|
|
32
|
-
*
|
|
33
|
-
* @param json A JSON value to validate against this instance's target schema.
|
|
34
|
-
* @returns The validated JSON data.
|
|
35
|
-
*/
|
|
36
|
-
validate(json: AnyJson): Promise<AnyJson>;
|
|
37
|
-
/**
|
|
38
|
-
* Performs validation of JSON data against the schema located at the `schemaPath` value provided
|
|
39
|
-
* at instantiation.
|
|
40
|
-
*
|
|
41
|
-
* **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
|
|
42
|
-
* **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
|
|
43
|
-
*
|
|
44
|
-
* @param json A JSON value to validate against this instance's target schema.
|
|
45
|
-
* @returns The validated JSON data.
|
|
46
|
-
*/
|
|
47
|
-
validateSync<T extends AnyJson>(json: T): T;
|
|
48
|
-
/**
|
|
49
|
-
* Loads local, external schemas from URIs in the same directory as the local schema file.
|
|
50
|
-
* Does not support loading from remote URIs.
|
|
51
|
-
* Returns a map of external schema local URIs to loaded schema JSON objects.
|
|
52
|
-
*
|
|
53
|
-
* @param schema The main schema to look up references ($ref) in.
|
|
54
|
-
* @returns An array of found referenced schemas.
|
|
55
|
-
*/
|
|
56
|
-
private loadExternalSchemas;
|
|
57
|
-
/**
|
|
58
|
-
* Load another schema relative to the primary schema when referenced. Only supports local schema URIs.
|
|
59
|
-
*
|
|
60
|
-
* @param uri The first segment of the $ref schema.
|
|
61
|
-
*/
|
|
62
|
-
private loadExternalSchema;
|
|
63
|
-
/**
|
|
64
|
-
* Get a string representation of the schema validation errors.
|
|
65
|
-
* Adds additional (human friendly) information to certain errors.
|
|
66
|
-
*
|
|
67
|
-
* @param errors An array of AJV (DefinedError) objects.
|
|
68
|
-
*/
|
|
69
|
-
private getErrorsText;
|
|
70
|
-
}
|
|
1
|
+
import { AnyJson, JsonMap } from '@salesforce/ts-types';
|
|
2
|
+
import { Logger } from '../logger';
|
|
3
|
+
/**
|
|
4
|
+
* Loads a JSON schema and performs validations against JSON objects.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SchemaValidator {
|
|
7
|
+
private schemaPath;
|
|
8
|
+
private readonly schemasDir;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private schema?;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new `SchemaValidator` instance given a logger and path to a schema file.
|
|
13
|
+
*
|
|
14
|
+
* @param logger An {@link Logger} instance on which to base this class's logger.
|
|
15
|
+
* @param schemaPath The path to the schema file to load and use for validation.
|
|
16
|
+
*/
|
|
17
|
+
constructor(logger: Logger, schemaPath: string);
|
|
18
|
+
/**
|
|
19
|
+
* Loads a JSON schema from the `schemaPath` parameter provided at instantiation.
|
|
20
|
+
*/
|
|
21
|
+
load(): Promise<JsonMap>;
|
|
22
|
+
/**
|
|
23
|
+
* Loads a JSON schema from the `schemaPath` parameter provided at instantiation.
|
|
24
|
+
*/
|
|
25
|
+
loadSync(): JsonMap;
|
|
26
|
+
/**
|
|
27
|
+
* Performs validation of JSON data against the schema located at the `schemaPath` value provided
|
|
28
|
+
* at instantiation.
|
|
29
|
+
*
|
|
30
|
+
* **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
|
|
31
|
+
* **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
|
|
32
|
+
*
|
|
33
|
+
* @param json A JSON value to validate against this instance's target schema.
|
|
34
|
+
* @returns The validated JSON data.
|
|
35
|
+
*/
|
|
36
|
+
validate(json: AnyJson): Promise<AnyJson>;
|
|
37
|
+
/**
|
|
38
|
+
* Performs validation of JSON data against the schema located at the `schemaPath` value provided
|
|
39
|
+
* at instantiation.
|
|
40
|
+
*
|
|
41
|
+
* **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
|
|
42
|
+
* **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
|
|
43
|
+
*
|
|
44
|
+
* @param json A JSON value to validate against this instance's target schema.
|
|
45
|
+
* @returns The validated JSON data.
|
|
46
|
+
*/
|
|
47
|
+
validateSync<T extends AnyJson>(json: T): T;
|
|
48
|
+
/**
|
|
49
|
+
* Loads local, external schemas from URIs in the same directory as the local schema file.
|
|
50
|
+
* Does not support loading from remote URIs.
|
|
51
|
+
* Returns a map of external schema local URIs to loaded schema JSON objects.
|
|
52
|
+
*
|
|
53
|
+
* @param schema The main schema to look up references ($ref) in.
|
|
54
|
+
* @returns An array of found referenced schemas.
|
|
55
|
+
*/
|
|
56
|
+
private loadExternalSchemas;
|
|
57
|
+
/**
|
|
58
|
+
* Load another schema relative to the primary schema when referenced. Only supports local schema URIs.
|
|
59
|
+
*
|
|
60
|
+
* @param uri The first segment of the $ref schema.
|
|
61
|
+
*/
|
|
62
|
+
private loadExternalSchema;
|
|
63
|
+
/**
|
|
64
|
+
* Get a string representation of the schema validation errors.
|
|
65
|
+
* Adds additional (human friendly) information to certain errors.
|
|
66
|
+
*
|
|
67
|
+
* @param errors An array of AJV (DefinedError) objects.
|
|
68
|
+
*/
|
|
69
|
+
private getErrorsText;
|
|
70
|
+
}
|