@sanity/runtime-cli 10.4.0 → 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/dist/actions/blueprints/blueprint.d.ts +14 -24
- package/dist/actions/blueprints/blueprint.js +19 -43
- package/dist/actions/blueprints/index.d.ts +3 -4
- package/dist/actions/blueprints/index.js +0 -1
- package/dist/actions/blueprints/logs-streaming.d.ts +24 -0
- package/dist/actions/blueprints/logs-streaming.js +96 -0
- package/dist/actions/blueprints/logs.d.ts +0 -11
- package/dist/actions/blueprints/logs.js +0 -75
- package/dist/baseCommands.d.ts +2 -2
- package/dist/commands/blueprints/init.js +4 -4
- package/dist/cores/blueprints/add.js +1 -1
- package/dist/cores/blueprints/deploy.js +1 -1
- package/dist/cores/blueprints/destroy.js +1 -1
- package/dist/cores/blueprints/logs.js +1 -1
- package/dist/cores/index.js +2 -2
- package/dist/utils/display/blueprints-formatting.d.ts +4 -3
- package/dist/utils/display/index.d.ts +0 -1
- package/dist/utils/display/index.js +0 -1
- package/dist/utils/display/logs-formatting.d.ts +0 -1
- package/dist/utils/display/logs-formatting.js +0 -10
- package/dist/utils/find-function.d.ts +3 -3
- package/dist/utils/find-function.js +0 -18
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/types.d.ts +5 -42
- package/dist/utils/validated-token.d.ts +5 -10
- package/dist/utils/validated-token.js +6 -3
- package/oclif.manifest.json +1 -1
- package/package.json +2 -1
- package/dist/actions/blueprints/operations.d.ts +0 -19
- package/dist/actions/blueprints/operations.js +0 -46
- package/dist/utils/display/blueprints-logs-streaming.d.ts +0 -14
- package/dist/utils/display/blueprints-logs-streaming.js +0 -33
- package/dist/utils/display/colors.d.ts +0 -15
- package/dist/utils/display/colors.js +0 -30
- package/dist/utils/vendor/index.d.ts +0 -1
- package/dist/utils/vendor/index.js +0 -1
- package/dist/utils/vendor/parser-validator.d.ts +0 -7
- package/dist/utils/vendor/parser-validator.js +0 -514
|
@@ -1,514 +0,0 @@
|
|
|
1
|
-
const firstVersion = '2024-10-01';
|
|
2
|
-
const formatProperties = [
|
|
3
|
-
'$schema',
|
|
4
|
-
'blueprintVersion',
|
|
5
|
-
'resources',
|
|
6
|
-
'parameters',
|
|
7
|
-
'values',
|
|
8
|
-
'outputs',
|
|
9
|
-
'metadata',
|
|
10
|
-
];
|
|
11
|
-
const parameterTypes = ['arg', 'env-var', 'stdin', 'config'];
|
|
12
|
-
const versionFormat = /^\d{4}-\d{2}-\d{2}$/; // YYYY-MM-DD
|
|
13
|
-
const nameFormat = /^[a-zA-Z][a-zA-Z0-9-_]*(?<![-_])$/;
|
|
14
|
-
const typeFormat = /^[a-zA-Z]([a-zA-Z0-9-_]+\.?)*(?<![-_\.])$/;
|
|
15
|
-
// Types
|
|
16
|
-
const array = (item) => Array.isArray(item);
|
|
17
|
-
// const bool = (item) => typeof item === 'boolean'
|
|
18
|
-
const defined = (item) => typeof item !== 'undefined';
|
|
19
|
-
// const nullish = (item) => typeof item === 'undefined' || item === null
|
|
20
|
-
const number = (item) => Number.isInteger(item) || (typeof item === 'number' && !Number.isNaN(item));
|
|
21
|
-
const object = (item) => item && typeof item === 'object' && !Array.isArray(item);
|
|
22
|
-
const ref = (item) => string(item) && item.startsWith('$.');
|
|
23
|
-
const scalar = (item) => string(item) || number(item);
|
|
24
|
-
const string = (item) => typeof item === 'string';
|
|
25
|
-
var is = {
|
|
26
|
-
array,
|
|
27
|
-
defined,
|
|
28
|
-
number,
|
|
29
|
-
object,
|
|
30
|
-
ref,
|
|
31
|
-
scalar,
|
|
32
|
-
string,
|
|
33
|
-
};
|
|
34
|
-
var references = { find, resolve };
|
|
35
|
-
function find(rawBlueprint, options) {
|
|
36
|
-
const { resources, parameters, outputs } = rawBlueprint;
|
|
37
|
-
const { debug } = options;
|
|
38
|
-
const foundRefs = [];
|
|
39
|
-
function walk(item, path) {
|
|
40
|
-
if (is.object(item)) {
|
|
41
|
-
for (const [name, value] of Object.entries(item)) {
|
|
42
|
-
const cur = `${path}.${name}`;
|
|
43
|
-
if (is.ref(value))
|
|
44
|
-
foundRefs.push({ path: cur, property: name, ref: value, item });
|
|
45
|
-
else if (is.object(value) || is.array(value))
|
|
46
|
-
walk(value, cur);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (is.array(item)) {
|
|
50
|
-
item.forEach((value, index) => {
|
|
51
|
-
const cur = `${path}[${index}]`;
|
|
52
|
-
if (is.ref(value))
|
|
53
|
-
foundRefs.push({ path: cur, property: value, ref: value, item, index });
|
|
54
|
-
else if (is.object(value))
|
|
55
|
-
walk(value, cur);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// Top-level Blueprint properties that may contain a reference
|
|
60
|
-
const properties = ['resources', 'parameters', 'outputs'];
|
|
61
|
-
for (const property of properties) {
|
|
62
|
-
// Run over the list
|
|
63
|
-
if (rawBlueprint[property]?.length) {
|
|
64
|
-
// Inspect each property, or (recursively) walk if it's an object
|
|
65
|
-
for (const item of rawBlueprint[property]) {
|
|
66
|
-
const top = `${property}.${item.name}`;
|
|
67
|
-
walk(item, top);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/* c8 ignore next 4 */
|
|
72
|
-
if (debug) {
|
|
73
|
-
console.log(`[Debug] Found ${foundRefs.length} references:`, foundRefs.length ? foundRefs : '');
|
|
74
|
-
}
|
|
75
|
-
return foundRefs;
|
|
76
|
-
}
|
|
77
|
-
function resolve(rawBlueprint, foundRefs, options) {
|
|
78
|
-
const { parameters = {} } = options;
|
|
79
|
-
const refs = {};
|
|
80
|
-
const unresolvedRefs = [];
|
|
81
|
-
const refErrors = [];
|
|
82
|
-
for (const foundRef of foundRefs) {
|
|
83
|
-
const { path, property, ref, item } = foundRef;
|
|
84
|
-
const refPath = ref.replace(/^\$\./, '');
|
|
85
|
-
// Early return from an already found reference
|
|
86
|
-
if (refs[refPath]) {
|
|
87
|
-
item[property] = refs[refPath];
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
// Parameters are special, (try to) find them in options.parameters passed by the caller
|
|
91
|
-
const parts = refPath.split('.');
|
|
92
|
-
const param = parts[1];
|
|
93
|
-
if (['parameters', 'params'].includes(parts[0])) {
|
|
94
|
-
const found = parameters[param];
|
|
95
|
-
if (is.scalar(found)) {
|
|
96
|
-
refs[refPath] = found;
|
|
97
|
-
if (is.object(item))
|
|
98
|
-
item[property] = refs[refPath];
|
|
99
|
-
if (is.array(item)) {
|
|
100
|
-
const index = item.findIndex(i => i === property);
|
|
101
|
-
item[index] = refs[refPath];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
refErrors.push({
|
|
106
|
-
message: `Reference error '${ref}': '${param}' not found in passed parameters`,
|
|
107
|
-
type: 'missing_parameter',
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
// Will prob need to refactor the following to get a bit more readable, and introduce more subtle behavior
|
|
113
|
-
const found = parts.reduce((obj, i) => {
|
|
114
|
-
if (obj?.[i])
|
|
115
|
-
return obj[i];
|
|
116
|
-
if (is.array(obj))
|
|
117
|
-
return obj.find(({ name }) => name === i);
|
|
118
|
-
}, rawBlueprint);
|
|
119
|
-
if (is.scalar(found)) {
|
|
120
|
-
refs[refPath] = found;
|
|
121
|
-
if (is.object(item))
|
|
122
|
-
item[property] = refs[refPath];
|
|
123
|
-
if (is.array(item)) {
|
|
124
|
-
const index = item.findIndex(i => i === property);
|
|
125
|
-
item[index] = refs[refPath];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
unresolvedRefs.push(foundRef);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
resolvedBlueprint: rawBlueprint,
|
|
134
|
-
unresolvedRefs: unresolvedRefs.length ? unresolvedRefs : undefined,
|
|
135
|
-
refErrors,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
var validate = {
|
|
139
|
-
version: (blueprintVersion) => {
|
|
140
|
-
const errors = [];
|
|
141
|
-
const type = 'invalid_version';
|
|
142
|
-
if (!is.string(blueprintVersion) || !versionFormat.test(blueprintVersion)) {
|
|
143
|
-
return errors.push({ message: `Invalid version: ${blueprintVersion}`, type });
|
|
144
|
-
}
|
|
145
|
-
const [y, m, d] = blueprintVersion.split('-');
|
|
146
|
-
if (y < '2024') {
|
|
147
|
-
errors.push({ message: `Invalid version year: ${y}`, type });
|
|
148
|
-
}
|
|
149
|
-
if (m < '01' || m > '12') {
|
|
150
|
-
errors.push({ message: `Invalid version month: ${m}`, type });
|
|
151
|
-
}
|
|
152
|
-
if (d < '01' || d > '31') {
|
|
153
|
-
errors.push({ message: `Invalid version day: ${d}`, type });
|
|
154
|
-
}
|
|
155
|
-
if (errors.length)
|
|
156
|
-
return errors;
|
|
157
|
-
},
|
|
158
|
-
resources: (resources) => {
|
|
159
|
-
if (!is.defined(resources))
|
|
160
|
-
return;
|
|
161
|
-
if (!is.array(resources)) {
|
|
162
|
-
return [
|
|
163
|
-
{
|
|
164
|
-
message: 'Resources must be an array',
|
|
165
|
-
type: 'invalid_type',
|
|
166
|
-
},
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
|
-
const errors = [];
|
|
170
|
-
const names = [];
|
|
171
|
-
resources.forEach((resource) => {
|
|
172
|
-
if (!is.object(resource)) {
|
|
173
|
-
return errors.push({
|
|
174
|
-
// Maybe we should break out the stringified resource into a data field?
|
|
175
|
-
message: `Resources must be an object, found: ${JSON.stringify(resource)}`,
|
|
176
|
-
type: 'invalid_type',
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
const { name, type } = resource;
|
|
180
|
-
if (!is.defined(name)) {
|
|
181
|
-
errors.push({
|
|
182
|
-
message: `Resource must have a 'name' property`,
|
|
183
|
-
type: 'missing_required_property',
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
else if (!is.string(name)) {
|
|
187
|
-
errors.push({
|
|
188
|
-
message: `Resource 'name' property must be a string, found: ${name}`,
|
|
189
|
-
type: 'invalid_type',
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
if (names.includes(name)) {
|
|
194
|
-
errors.push({
|
|
195
|
-
message: `All resource 'name' properties must be unique, found: ${name}`,
|
|
196
|
-
type: 'duplicate_name',
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
if (!nameFormat.test(name)) {
|
|
200
|
-
errors.push({
|
|
201
|
-
message: `Resource 'name' property is invalid, must conform to '${nameFormat}', found: ${name}`,
|
|
202
|
-
type: 'invalid_format',
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
names.push(name);
|
|
206
|
-
}
|
|
207
|
-
if (!is.defined(type)) {
|
|
208
|
-
errors.push({
|
|
209
|
-
message: `Resource must have a 'type' property`,
|
|
210
|
-
type: 'missing_required_property',
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
else if (!is.string(type)) {
|
|
214
|
-
errors.push({
|
|
215
|
-
message: `Resource 'type' property must be a string, found: ${type}`,
|
|
216
|
-
type: 'invalid_type',
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
else if (!typeFormat.test(type)) {
|
|
220
|
-
errors.push({
|
|
221
|
-
message: `Resource 'type' property is invalid, must conform to '${typeFormat}', found: ${type}`,
|
|
222
|
-
type: 'invalid_format',
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
if (errors.length)
|
|
227
|
-
return errors;
|
|
228
|
-
},
|
|
229
|
-
values: (values) => {
|
|
230
|
-
if (!is.defined(values))
|
|
231
|
-
return;
|
|
232
|
-
if (!is.object(values)) {
|
|
233
|
-
return [
|
|
234
|
-
{
|
|
235
|
-
message: 'Values must be an object',
|
|
236
|
-
type: 'invalid_type',
|
|
237
|
-
},
|
|
238
|
-
];
|
|
239
|
-
}
|
|
240
|
-
const errors = [];
|
|
241
|
-
if (Object.keys(values).length) {
|
|
242
|
-
Object.entries(values).forEach(([name, value]) => {
|
|
243
|
-
if (!is.scalar(value)) {
|
|
244
|
-
errors.push({
|
|
245
|
-
message: `Values property '${name}' must be scalar (string or number)`,
|
|
246
|
-
type: 'invalid_type',
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
if (is.ref(value)) {
|
|
250
|
-
errors.push({
|
|
251
|
-
message: `Values property '${name}' cannot be a reference, found: ${value}`,
|
|
252
|
-
type: 'invalid_type',
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
if (errors.length)
|
|
258
|
-
return errors;
|
|
259
|
-
},
|
|
260
|
-
parameters: (parameters) => {
|
|
261
|
-
if (!is.defined(parameters))
|
|
262
|
-
return;
|
|
263
|
-
if (!is.array(parameters)) {
|
|
264
|
-
return [
|
|
265
|
-
{
|
|
266
|
-
message: 'Parameters must be an array',
|
|
267
|
-
type: 'invalid_type',
|
|
268
|
-
},
|
|
269
|
-
];
|
|
270
|
-
}
|
|
271
|
-
const errors = [];
|
|
272
|
-
const names = [];
|
|
273
|
-
if (parameters.length) {
|
|
274
|
-
parameters.forEach((param) => {
|
|
275
|
-
if (!is.object(param)) {
|
|
276
|
-
return errors.push({
|
|
277
|
-
// Maybe we should break out the stringified parameter into a data field?
|
|
278
|
-
message: `Parameters must be an object, found: ${JSON.stringify(param)}`,
|
|
279
|
-
type: 'invalid_type',
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
const { name, type } = param;
|
|
283
|
-
if (!is.defined(name)) {
|
|
284
|
-
errors.push({
|
|
285
|
-
message: `Parameter must have a 'name' property`,
|
|
286
|
-
type: 'missing_required_property',
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
else if (!is.string(name)) {
|
|
290
|
-
errors.push({
|
|
291
|
-
message: `Parameter 'name' property must be a string, found: ${name}`,
|
|
292
|
-
type: 'invalid_type',
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
if (names.includes(name)) {
|
|
297
|
-
errors.push({
|
|
298
|
-
message: `All parameter 'name' properties must be unique, found: ${name}`,
|
|
299
|
-
type: 'duplicate_name',
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
if (!nameFormat.test(name)) {
|
|
303
|
-
errors.push({
|
|
304
|
-
message: `Parameter 'name' property is invalid, must conform to '${nameFormat}', found: ${name}`,
|
|
305
|
-
type: 'invalid_format',
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
names.push(name);
|
|
309
|
-
}
|
|
310
|
-
if (!is.defined(type)) {
|
|
311
|
-
errors.push({
|
|
312
|
-
message: `Parameter must have a 'type' property`,
|
|
313
|
-
type: 'missing_required_property',
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
else if (!is.string(type)) {
|
|
317
|
-
errors.push({
|
|
318
|
-
message: `Parameter 'type' property must be a string, found: ${type}`,
|
|
319
|
-
type: 'invalid_type',
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
else if (!parameterTypes.includes(type)) {
|
|
323
|
-
errors.push({
|
|
324
|
-
message: `Unknown parameter 'type', found: ${type}`,
|
|
325
|
-
type: 'invalid_value',
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
if (errors.length)
|
|
331
|
-
return errors;
|
|
332
|
-
},
|
|
333
|
-
outputs: (outputs) => {
|
|
334
|
-
if (!is.defined(outputs))
|
|
335
|
-
return;
|
|
336
|
-
if (!is.array(outputs)) {
|
|
337
|
-
return [
|
|
338
|
-
{
|
|
339
|
-
message: 'Outputs must be an array',
|
|
340
|
-
type: 'invalid_type',
|
|
341
|
-
},
|
|
342
|
-
];
|
|
343
|
-
}
|
|
344
|
-
const errors = [];
|
|
345
|
-
const names = [];
|
|
346
|
-
outputs.forEach((output) => {
|
|
347
|
-
if (!is.object(output)) {
|
|
348
|
-
return errors.push({
|
|
349
|
-
// Maybe we should break out the stringified output into a data field?
|
|
350
|
-
message: `Outputs must be an object, found: ${JSON.stringify(output)}`,
|
|
351
|
-
type: 'invalid_type',
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
const { name, value } = output;
|
|
355
|
-
if (!is.defined(name)) {
|
|
356
|
-
errors.push({
|
|
357
|
-
message: `Output must have a 'name' property`,
|
|
358
|
-
type: 'missing_required_property',
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
else if (!is.string(name)) {
|
|
362
|
-
errors.push({
|
|
363
|
-
message: `Output 'name' property must be a string, found: ${name}`,
|
|
364
|
-
type: 'invalid_type',
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
if (names.includes(name)) {
|
|
369
|
-
errors.push({
|
|
370
|
-
message: `All output 'name' properties must be unique, found: ${name}`,
|
|
371
|
-
type: 'duplicate_name',
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
if (!nameFormat.test(name)) {
|
|
375
|
-
errors.push({
|
|
376
|
-
message: `Output 'name' property is invalid, must conform to '${nameFormat}', found: ${name}`,
|
|
377
|
-
type: 'invalid_format',
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
names.push(name);
|
|
381
|
-
}
|
|
382
|
-
if (!is.defined(value)) {
|
|
383
|
-
errors.push({
|
|
384
|
-
message: `Output must have a 'value' property`,
|
|
385
|
-
type: 'missing_required_property',
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
if (errors.length)
|
|
390
|
-
return errors;
|
|
391
|
-
},
|
|
392
|
-
metadata: (metadata) => {
|
|
393
|
-
if (!is.defined(metadata))
|
|
394
|
-
return;
|
|
395
|
-
if (!is.object(metadata)) {
|
|
396
|
-
return [
|
|
397
|
-
{
|
|
398
|
-
message: 'Metadata must be an object',
|
|
399
|
-
type: 'invalid_type',
|
|
400
|
-
},
|
|
401
|
-
];
|
|
402
|
-
}
|
|
403
|
-
},
|
|
404
|
-
else: (rawBlueprint) => {
|
|
405
|
-
const properties = Object.keys(rawBlueprint);
|
|
406
|
-
if (!properties.length)
|
|
407
|
-
return;
|
|
408
|
-
const errors = [];
|
|
409
|
-
for (const property of properties) {
|
|
410
|
-
if (!formatProperties.includes(property)) {
|
|
411
|
-
errors.push({
|
|
412
|
-
message: `Found invalid Blueprint property: ${property}`,
|
|
413
|
-
type: 'invalid_property',
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
if (errors.length)
|
|
418
|
-
return errors;
|
|
419
|
-
},
|
|
420
|
-
passedParameters: (options) => {
|
|
421
|
-
const { parameters } = options;
|
|
422
|
-
if (!is.defined(parameters))
|
|
423
|
-
return;
|
|
424
|
-
if (!is.object(parameters)) {
|
|
425
|
-
return [
|
|
426
|
-
{
|
|
427
|
-
message: 'Passed parameters must be an object',
|
|
428
|
-
type: 'invalid_type',
|
|
429
|
-
},
|
|
430
|
-
];
|
|
431
|
-
}
|
|
432
|
-
const errors = [];
|
|
433
|
-
for (const [name, value] of Object.entries(parameters)) {
|
|
434
|
-
if (!is.scalar(value)) {
|
|
435
|
-
errors.push({
|
|
436
|
-
message: `Passed parameter '${name}' must be scalar (string or number)`,
|
|
437
|
-
type: 'invalid_type',
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
if (errors.length)
|
|
442
|
-
return errors;
|
|
443
|
-
},
|
|
444
|
-
};
|
|
445
|
-
function blueprintParserValidator(input, options = {}) {
|
|
446
|
-
try {
|
|
447
|
-
const { rawBlueprint, parseErrors } = parse(input);
|
|
448
|
-
if (parseErrors?.length) {
|
|
449
|
-
return {
|
|
450
|
-
blueprint: rawBlueprint || input,
|
|
451
|
-
errors: parseErrors,
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
const version = rawBlueprint.blueprintVersion || firstVersion;
|
|
455
|
-
// Aggregate basic structural, spec violation, or input errors
|
|
456
|
-
const initialErrors = []
|
|
457
|
-
.concat(validate.version(version), validate.resources(rawBlueprint.resources), validate.values(rawBlueprint.values), validate.parameters(rawBlueprint.parameters), validate.outputs(rawBlueprint.outputs), validate.metadata(rawBlueprint.metadata), validate.else(rawBlueprint), validate.passedParameters(options))
|
|
458
|
-
.filter(Boolean);
|
|
459
|
-
if (initialErrors.length) {
|
|
460
|
-
return {
|
|
461
|
-
blueprint: rawBlueprint,
|
|
462
|
-
errors: initialErrors,
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
const foundRefs = references.find(rawBlueprint, options);
|
|
466
|
-
if (!foundRefs.length) {
|
|
467
|
-
return {
|
|
468
|
-
blueprint: rawBlueprint,
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
const { resolvedBlueprint, unresolvedRefs, refErrors } = references.resolve(rawBlueprint, foundRefs, options);
|
|
472
|
-
const output = { blueprint: resolvedBlueprint };
|
|
473
|
-
if (unresolvedRefs?.length)
|
|
474
|
-
output.unresolvedRefs = unresolvedRefs;
|
|
475
|
-
if (refErrors.length)
|
|
476
|
-
output.errors = refErrors;
|
|
477
|
-
return output;
|
|
478
|
-
/* c8 ignore next 4 */
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
console.log('Unknown Blueprint error', error);
|
|
482
|
-
throw error;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
function parse(input) {
|
|
486
|
-
if (is.string(input) || input instanceof Buffer) {
|
|
487
|
-
try {
|
|
488
|
-
return { rawBlueprint: JSON.parse(input) };
|
|
489
|
-
}
|
|
490
|
-
catch (error) {
|
|
491
|
-
return {
|
|
492
|
-
parseErrors: [
|
|
493
|
-
{
|
|
494
|
-
message: 'Invalid Blueprint JSON',
|
|
495
|
-
type: 'json_validation_error',
|
|
496
|
-
error,
|
|
497
|
-
},
|
|
498
|
-
],
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
else if (is.object(input)) {
|
|
503
|
-
return { rawBlueprint: structuredClone(input) };
|
|
504
|
-
}
|
|
505
|
-
return {
|
|
506
|
-
parseErrors: [
|
|
507
|
-
{
|
|
508
|
-
message: 'Invalid input',
|
|
509
|
-
type: 'invalid_input',
|
|
510
|
-
},
|
|
511
|
-
],
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
export { blueprintParserValidator };
|