@sanity/blueprints-parser 0.1.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/.github/workflows/ci.yaml +54 -0
- package/.github/workflows/release-please.yaml +56 -0
- package/CHANGELOG.md +8 -0
- package/README.md +32 -0
- package/biome.jsonc +40 -0
- package/package.json +38 -0
- package/src/constants.js +16 -0
- package/src/index.js +91 -0
- package/src/is.js +20 -0
- package/src/refs.js +103 -0
- package/src/validate.js +326 -0
- package/test/mocks/all.js +6 -0
- package/test/mocks/basic-errors.js +274 -0
- package/test/mocks/basic.js +58 -0
- package/test/mocks/reference-errors.js +88 -0
- package/test/mocks/references.js +393 -0
- package/test/unit/index.test.js +131 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
unresolvedParameterReference: {
|
|
3
|
+
input: {
|
|
4
|
+
resources: [
|
|
5
|
+
{
|
|
6
|
+
name: 'a-function',
|
|
7
|
+
type: 'cloud-function',
|
|
8
|
+
config: {memory: '$.parameters.memory'},
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
parameters: [
|
|
12
|
+
{
|
|
13
|
+
name: 'memory',
|
|
14
|
+
type: 'env-var',
|
|
15
|
+
input: 'MEM',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
expected: {
|
|
20
|
+
resources: [
|
|
21
|
+
{
|
|
22
|
+
name: 'a-function',
|
|
23
|
+
type: 'cloud-function',
|
|
24
|
+
config: {memory: '$.parameters.memory'},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
parameters: [
|
|
28
|
+
{
|
|
29
|
+
name: 'memory',
|
|
30
|
+
type: 'env-var',
|
|
31
|
+
input: 'MEM',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
unresolvedParameterReferenceAndRegularReference: {
|
|
38
|
+
input: {
|
|
39
|
+
resources: [
|
|
40
|
+
{
|
|
41
|
+
name: 'a-function',
|
|
42
|
+
type: 'cloud-function',
|
|
43
|
+
config: {
|
|
44
|
+
memory: '$.parameters.memory',
|
|
45
|
+
disk: '$.values.disk',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
parameters: [
|
|
50
|
+
{
|
|
51
|
+
name: 'memory',
|
|
52
|
+
type: 'env-var',
|
|
53
|
+
input: 'MEM',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
expected: {
|
|
58
|
+
resources: [
|
|
59
|
+
{
|
|
60
|
+
name: 'a-function',
|
|
61
|
+
type: 'cloud-function',
|
|
62
|
+
config: {
|
|
63
|
+
memory: '$.parameters.memory',
|
|
64
|
+
disk: '$.values.disk',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
parameters: [
|
|
69
|
+
{
|
|
70
|
+
name: 'memory',
|
|
71
|
+
type: 'env-var',
|
|
72
|
+
input: 'MEM',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
unresolved: [
|
|
77
|
+
{
|
|
78
|
+
path: 'resources.a-function.config.disk',
|
|
79
|
+
property: 'disk',
|
|
80
|
+
ref: '$.values.disk',
|
|
81
|
+
item: {
|
|
82
|
+
memory: '$.parameters.memory',
|
|
83
|
+
disk: '$.values.disk',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
// Resolved reference cases
|
|
3
|
+
simpleReference: {
|
|
4
|
+
input: {
|
|
5
|
+
resources: [
|
|
6
|
+
{
|
|
7
|
+
name: 'a-function',
|
|
8
|
+
type: 'cloud-function',
|
|
9
|
+
config: {memory: '$.values.memory'},
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
values: {
|
|
13
|
+
memory: 1000,
|
|
14
|
+
},
|
|
15
|
+
outputs: [
|
|
16
|
+
{
|
|
17
|
+
name: 'configured-memory',
|
|
18
|
+
value: '$.values.memory',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
expected: {
|
|
24
|
+
resources: [
|
|
25
|
+
{
|
|
26
|
+
name: 'a-function',
|
|
27
|
+
type: 'cloud-function',
|
|
28
|
+
config: {memory: 1000},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
values: {
|
|
32
|
+
memory: 1000,
|
|
33
|
+
},
|
|
34
|
+
outputs: [
|
|
35
|
+
{
|
|
36
|
+
name: 'configured-memory',
|
|
37
|
+
value: 1000,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
unresolved: undefined,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
scalarReferences: {
|
|
46
|
+
input: {
|
|
47
|
+
resources: [
|
|
48
|
+
{
|
|
49
|
+
name: 'a-function',
|
|
50
|
+
type: 'cloud-function',
|
|
51
|
+
config: {
|
|
52
|
+
string: '$.values.string',
|
|
53
|
+
int: '$.values.int',
|
|
54
|
+
float: '$.values.float',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
values: {
|
|
59
|
+
string: 'string',
|
|
60
|
+
int: 1,
|
|
61
|
+
float: 1.2,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
expected: {
|
|
66
|
+
resources: [
|
|
67
|
+
{
|
|
68
|
+
name: 'a-function',
|
|
69
|
+
type: 'cloud-function',
|
|
70
|
+
config: {
|
|
71
|
+
string: 'string',
|
|
72
|
+
int: 1,
|
|
73
|
+
float: 1.2,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
values: {
|
|
78
|
+
string: 'string',
|
|
79
|
+
int: 1,
|
|
80
|
+
float: 1.2,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
unresolved: undefined,
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
deepyNestedObjectReference: {
|
|
88
|
+
input: {
|
|
89
|
+
resources: [
|
|
90
|
+
{
|
|
91
|
+
name: 'a-function',
|
|
92
|
+
type: 'cloud-function',
|
|
93
|
+
config: {memory: '$.resources.another-function.config.env.memory'},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'another-function',
|
|
97
|
+
type: 'cloud-function',
|
|
98
|
+
config: {env: {memory: 1000}},
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
expected: {
|
|
104
|
+
resources: [
|
|
105
|
+
{
|
|
106
|
+
name: 'a-function',
|
|
107
|
+
type: 'cloud-function',
|
|
108
|
+
config: {memory: 1000},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'another-function',
|
|
112
|
+
type: 'cloud-function',
|
|
113
|
+
config: {env: {memory: 1000}},
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
unresolved: undefined,
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
arrayReference: {
|
|
122
|
+
input: {
|
|
123
|
+
resources: [
|
|
124
|
+
{
|
|
125
|
+
name: 'a-project',
|
|
126
|
+
type: 'project',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'a-function',
|
|
130
|
+
type: 'cloud-function',
|
|
131
|
+
projects: ['project-1', '$.resources.a-project.name', 'project-2'],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
expected: {
|
|
137
|
+
resources: [
|
|
138
|
+
{
|
|
139
|
+
name: 'a-project',
|
|
140
|
+
type: 'project',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'a-function',
|
|
144
|
+
type: 'cloud-function',
|
|
145
|
+
projects: ['project-1', 'a-project', 'project-2'],
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
unresolved: undefined,
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
// This is so weird please don't do this omg
|
|
154
|
+
deeplyNestedArrayReference: {
|
|
155
|
+
input: {
|
|
156
|
+
resources: [
|
|
157
|
+
{
|
|
158
|
+
name: 'a-project',
|
|
159
|
+
type: 'project',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'a-function',
|
|
163
|
+
type: 'cloud-function',
|
|
164
|
+
config: {
|
|
165
|
+
settings: [
|
|
166
|
+
{
|
|
167
|
+
projects: ['project-1', 'project-2', '$.resources.a-project.name'],
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
expected: {
|
|
176
|
+
resources: [
|
|
177
|
+
{
|
|
178
|
+
name: 'a-project',
|
|
179
|
+
type: 'project',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: 'a-function',
|
|
183
|
+
type: 'cloud-function',
|
|
184
|
+
config: {
|
|
185
|
+
settings: [
|
|
186
|
+
{
|
|
187
|
+
projects: ['project-1', 'project-2', 'a-project'],
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
unresolved: undefined,
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
arrayReferenceToParams: {
|
|
199
|
+
input: {
|
|
200
|
+
resources: [
|
|
201
|
+
{
|
|
202
|
+
name: 'a-function',
|
|
203
|
+
type: 'cloud-function',
|
|
204
|
+
projects: ['project-1', 'project-2', '$.params.project'],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
expected: {
|
|
210
|
+
resources: [
|
|
211
|
+
{
|
|
212
|
+
name: 'a-function',
|
|
213
|
+
type: 'cloud-function',
|
|
214
|
+
projects: ['project-1', 'project-2', 'a-project'],
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
parameters: {
|
|
220
|
+
project: 'a-project',
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
unresolved: undefined,
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
parameterReference: {
|
|
227
|
+
input: {
|
|
228
|
+
resources: [
|
|
229
|
+
{
|
|
230
|
+
name: 'a-function',
|
|
231
|
+
type: 'cloud-function',
|
|
232
|
+
config: {memory: '$.parameters.memory'},
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
parameters: [
|
|
236
|
+
{
|
|
237
|
+
name: 'memory',
|
|
238
|
+
type: 'env-var',
|
|
239
|
+
input: 'MEM',
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
parameters: {
|
|
245
|
+
memory: 1000,
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
expected: {
|
|
249
|
+
resources: [
|
|
250
|
+
{
|
|
251
|
+
name: 'a-function',
|
|
252
|
+
type: 'cloud-function',
|
|
253
|
+
config: {memory: 1000},
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
parameters: [
|
|
257
|
+
{
|
|
258
|
+
name: 'memory',
|
|
259
|
+
type: 'env-var',
|
|
260
|
+
input: 'MEM',
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
unresolved: undefined,
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
// Unresolved reference cases
|
|
269
|
+
unresolvedReference: {
|
|
270
|
+
input: {
|
|
271
|
+
resources: [
|
|
272
|
+
{
|
|
273
|
+
name: 'a-function',
|
|
274
|
+
type: 'cloud-function',
|
|
275
|
+
config: {memory: '$.values.memory'},
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
outputs: [
|
|
279
|
+
{
|
|
280
|
+
name: 'configured-memory',
|
|
281
|
+
value: '$.values.memory',
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
expected: {
|
|
287
|
+
resources: [
|
|
288
|
+
{
|
|
289
|
+
name: 'a-function',
|
|
290
|
+
type: 'cloud-function',
|
|
291
|
+
config: {memory: '$.values.memory'},
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
outputs: [
|
|
295
|
+
{
|
|
296
|
+
name: 'configured-memory',
|
|
297
|
+
value: '$.values.memory',
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
unresolved: [
|
|
303
|
+
{
|
|
304
|
+
path: 'resources.a-function.config.memory',
|
|
305
|
+
property: 'memory',
|
|
306
|
+
ref: '$.values.memory',
|
|
307
|
+
item: {memory: '$.values.memory'},
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
path: 'outputs.configured-memory.value',
|
|
311
|
+
property: 'value',
|
|
312
|
+
ref: '$.values.memory',
|
|
313
|
+
item: {name: 'configured-memory', value: '$.values.memory'},
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
unresolvedArrayReference: {
|
|
319
|
+
input: {
|
|
320
|
+
resources: [
|
|
321
|
+
{
|
|
322
|
+
name: 'a-function',
|
|
323
|
+
type: 'cloud-function',
|
|
324
|
+
projects: ['project-1', 'project-2', '$.resources.a-project.name', 'project-4'],
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
expected: {
|
|
330
|
+
resources: [
|
|
331
|
+
{
|
|
332
|
+
name: 'a-function',
|
|
333
|
+
type: 'cloud-function',
|
|
334
|
+
projects: ['project-1', 'project-2', '$.resources.a-project.name', 'project-4'],
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
unresolved: [
|
|
340
|
+
{
|
|
341
|
+
path: 'resources.a-function.projects[2]',
|
|
342
|
+
property: '$.resources.a-project.name',
|
|
343
|
+
ref: '$.resources.a-project.name',
|
|
344
|
+
item: ['project-1', 'project-2', '$.resources.a-project.name', 'project-4'],
|
|
345
|
+
index: 2,
|
|
346
|
+
},
|
|
347
|
+
],
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
unresolvedDeeplyNestedArrayReference: {
|
|
351
|
+
input: {
|
|
352
|
+
resources: [
|
|
353
|
+
{
|
|
354
|
+
name: 'a-function',
|
|
355
|
+
type: 'cloud-function',
|
|
356
|
+
config: {
|
|
357
|
+
settings: [
|
|
358
|
+
{
|
|
359
|
+
projects: ['$.resources.a-project.name', 'project-2', 'project-3'],
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
expected: {
|
|
368
|
+
resources: [
|
|
369
|
+
{
|
|
370
|
+
name: 'a-function',
|
|
371
|
+
type: 'cloud-function',
|
|
372
|
+
config: {
|
|
373
|
+
settings: [
|
|
374
|
+
{
|
|
375
|
+
projects: ['$.resources.a-project.name', 'project-2', 'project-3'],
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
},
|
|
382
|
+
|
|
383
|
+
unresolved: [
|
|
384
|
+
{
|
|
385
|
+
path: 'resources.a-function.config.settings[0].projects[0]',
|
|
386
|
+
property: '$.resources.a-project.name',
|
|
387
|
+
ref: '$.resources.a-project.name',
|
|
388
|
+
item: ['$.resources.a-project.name', 'project-2', 'project-3'],
|
|
389
|
+
index: 0,
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
},
|
|
393
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {readFile} from 'node:fs/promises'
|
|
2
|
+
import {join} from 'node:path'
|
|
3
|
+
import schemas from '@sanity/blueprints-jsonschemas'
|
|
4
|
+
import Ajv from 'ajv/dist/2020.js'
|
|
5
|
+
import tap from 'tap'
|
|
6
|
+
import blueprintParserValidator from '../../src/index.js'
|
|
7
|
+
import mocks from '../mocks/all.js'
|
|
8
|
+
|
|
9
|
+
const cwd = process.cwd()
|
|
10
|
+
const ajv = new Ajv()
|
|
11
|
+
|
|
12
|
+
tap.test('Basic input', (t) => {
|
|
13
|
+
t.plan(8)
|
|
14
|
+
const input = {blueprintVersion: '2024-10-01'}
|
|
15
|
+
const inputJSON = JSON.stringify(input)
|
|
16
|
+
let result
|
|
17
|
+
|
|
18
|
+
result = blueprintParserValidator(input)
|
|
19
|
+
t.same(result.blueprint, input, 'Parser / validator accepted raw JS input')
|
|
20
|
+
t.notOk(result.errors, 'Parser / validator found no issues')
|
|
21
|
+
|
|
22
|
+
result = blueprintParserValidator(inputJSON)
|
|
23
|
+
t.same(result.blueprint, input, 'Parser / validator accepted JSON input')
|
|
24
|
+
t.notOk(result.errors, 'Parser / validator found no issues')
|
|
25
|
+
|
|
26
|
+
result = blueprintParserValidator(Buffer.from(inputJSON))
|
|
27
|
+
t.same(result.blueprint, input, 'Parser / validator accepted JSON buffer')
|
|
28
|
+
t.notOk(result.errors, 'Parser / validator found no issues')
|
|
29
|
+
|
|
30
|
+
result = blueprintParserValidator(input, {parameters: {ok: 'hello'}})
|
|
31
|
+
t.same(result.blueprint, input, 'Parser / validator accepted raw JS input and scalar params')
|
|
32
|
+
t.notOk(result.errors, 'Parser / validator found no issues')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
tap.test('Basic input: errors', (t) => {
|
|
36
|
+
t.plan(10)
|
|
37
|
+
const input = {blueprintVersion: 'nah'}
|
|
38
|
+
const invalidInput = '{'
|
|
39
|
+
const validInput = {}
|
|
40
|
+
let result
|
|
41
|
+
|
|
42
|
+
result = blueprintParserValidator(invalidInput)
|
|
43
|
+
t.same(
|
|
44
|
+
result.blueprint,
|
|
45
|
+
invalidInput,
|
|
46
|
+
'Parser / validator returned invalid input for user debugging',
|
|
47
|
+
)
|
|
48
|
+
t.same(result.errors.length, 1, 'Parser / validator returned error on invalid JSON')
|
|
49
|
+
|
|
50
|
+
result = blueprintParserValidator(undefined)
|
|
51
|
+
t.notOk(result.blueprint, 'Parser / validator had no input to return (undefined)')
|
|
52
|
+
t.same(result.errors.length, 1, 'Parser / validator returned error on invalid input (undefined)')
|
|
53
|
+
|
|
54
|
+
result = blueprintParserValidator(input)
|
|
55
|
+
t.same(result.blueprint, input, 'Parser / validator accepted raw JS input')
|
|
56
|
+
t.same(result.errors.length, 1, 'Parser / validator returned a basic format error')
|
|
57
|
+
|
|
58
|
+
result = blueprintParserValidator(validInput, {parameters: 'hi'})
|
|
59
|
+
t.same(result.blueprint, validInput, 'Parser / validator accepted valid input')
|
|
60
|
+
t.same(result.errors.length, 1, 'Parser / validator returned a basic format error')
|
|
61
|
+
|
|
62
|
+
result = blueprintParserValidator(validInput, {parameters: {ok: {}}})
|
|
63
|
+
t.same(result.blueprint, validInput, 'Parser / validator accepted valid input')
|
|
64
|
+
t.same(result.errors.length, 1, 'Parser / validator returned a basic format error')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
tap.test('Reference resolution', async (t) => {
|
|
68
|
+
const references = Object.entries(mocks.references)
|
|
69
|
+
const referenceErrors = Object.entries(mocks.referenceErrors)
|
|
70
|
+
const tests = references.length * 3 + referenceErrors.length * 3
|
|
71
|
+
t.plan(tests)
|
|
72
|
+
|
|
73
|
+
// Basic reference resolution
|
|
74
|
+
for (const [name, {input, parameters, expected, unresolved}] of references) {
|
|
75
|
+
const {blueprint, unresolvedRefs, errors} = blueprintParserValidator(input, {
|
|
76
|
+
debug: true,
|
|
77
|
+
parameters,
|
|
78
|
+
})
|
|
79
|
+
t.same(blueprint, expected, `${name}: returned expected blueprint`)
|
|
80
|
+
t.same(unresolvedRefs, unresolved, `${name}: returned expected unresolved references`)
|
|
81
|
+
t.notOk(errors, `${name}: found no issues`)
|
|
82
|
+
if (errors?.length) console.log(`${name} errors:`, errors)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Basic reference errors
|
|
86
|
+
for (const [name, {input, expected, unresolved}] of referenceErrors) {
|
|
87
|
+
const {blueprint, unresolvedRefs, errors} = blueprintParserValidator(input, {
|
|
88
|
+
debug: true,
|
|
89
|
+
parameters: {},
|
|
90
|
+
})
|
|
91
|
+
t.same(blueprint, expected, `${name}: returned expected blueprint`)
|
|
92
|
+
t.same(unresolvedRefs, unresolved, `${name}: returned expected unresolved references`)
|
|
93
|
+
t.ok(errors, `${name}: parser / validator found an error`)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
tap.test('2024-10-01', async (t) => {
|
|
98
|
+
const jsonSchema20241001 = schemas['2024-10-01'].sanity.blueprint
|
|
99
|
+
|
|
100
|
+
const basic = Object.entries(mocks.basic)
|
|
101
|
+
const basicErrors = Object.entries(mocks.basicErrors)
|
|
102
|
+
const tests =
|
|
103
|
+
basic.length * 3 +
|
|
104
|
+
// allow tests to opt out of JSON Schema validation, when it's not as flexible as regular logic
|
|
105
|
+
basicErrors.reduce((a, [, b]) => a + (b.metadata?.ignore ? 1 : 3), 0)
|
|
106
|
+
t.plan(tests)
|
|
107
|
+
|
|
108
|
+
// Check the basic structure of a document
|
|
109
|
+
for (const [name, input] of basic) {
|
|
110
|
+
const {errors} = blueprintParserValidator(input)
|
|
111
|
+
t.notOk(errors, `${name}: parser / validator found no issues`)
|
|
112
|
+
if (errors?.length) console.log(`${name} errors:`, errors)
|
|
113
|
+
|
|
114
|
+
const valid = ajv.validate(jsonSchema20241001, input)
|
|
115
|
+
t.ok(valid, `${name}: JSON Schema validator found no issues`)
|
|
116
|
+
t.notOk(ajv.errors, `${name}: JSON Schema validator found no issues`)
|
|
117
|
+
if (ajv.errors?.length) console.log(`${name} errors (AJV):`, ajv.errors)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Basic validation errors
|
|
121
|
+
for (const [name, input] of basicErrors) {
|
|
122
|
+
const {errors} = blueprintParserValidator(input)
|
|
123
|
+
t.ok(errors, `${name}: parser / validator found an error`)
|
|
124
|
+
|
|
125
|
+
if (!input.metadata?.ignore) {
|
|
126
|
+
const valid = ajv.validate(jsonSchema20241001, input)
|
|
127
|
+
t.notOk(valid, `${name}: JSON Schema validator found an error`)
|
|
128
|
+
t.ok(ajv.errors, `${name}: JSON Schema validator found an error`)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|