@sanity/blueprints-parser 0.3.0 → 0.3.1
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 +9 -0
- package/biome.jsonc +1 -1
- package/package.json +3 -3
- package/src/refs.js +20 -6
- package/src/validate.js +3 -3
- package/test/mocks/reference-errors.js +23 -2
- package/test/mocks/references.js +31 -3
- package/test/unit/index.test.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.1](https://github.com/sanity-io/blueprints-parser/compare/v0.3.0...v0.3.1) (2026-02-06)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* Handle duplicate unresolved references ([#12](https://github.com/sanity-io/blueprints-parser/issues/12)) ([910dafc](https://github.com/sanity-io/blueprints-parser/commit/910dafc9493d4e622de0c452799e6b0a861854fd))
|
|
9
|
+
* Return reference error if resource is missing ([#14](https://github.com/sanity-io/blueprints-parser/issues/14)) ([7a15103](https://github.com/sanity-io/blueprints-parser/commit/7a1510333998ffe0d216f1ca08d355811d34d532))
|
|
10
|
+
* Update dependencies ([#13](https://github.com/sanity-io/blueprints-parser/issues/13)) ([ad01057](https://github.com/sanity-io/blueprints-parser/commit/ad010574f2a6a2904303294efee0322a5e344283))
|
|
11
|
+
|
|
3
12
|
## [0.3.0](https://github.com/sanity-io/blueprints-parser/compare/v0.2.1...v0.3.0) (2025-10-17)
|
|
4
13
|
|
|
5
14
|
|
package/biome.jsonc
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/blueprints-parser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A parser and validator for Sanity Blueprint documents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
},
|
|
31
31
|
"author": "Sanity.io <hello@sanity.io>",
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@biomejs/biome": "^2.
|
|
33
|
+
"@biomejs/biome": "^2.3.14",
|
|
34
34
|
"@sanity/blueprints-jsonschemas": "^0.1.1",
|
|
35
35
|
"ajv": "^8.17.1",
|
|
36
|
-
"tap": "^21.1
|
|
36
|
+
"tap": "^21.5.1"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
package/src/refs.js
CHANGED
|
@@ -73,17 +73,23 @@ function resolve(blueprint, foundRefs, options) {
|
|
|
73
73
|
const refErrors = []
|
|
74
74
|
for (const foundRef of foundRefs) {
|
|
75
75
|
const {ref} = foundRef
|
|
76
|
+
const parts = ref.split('.')
|
|
77
|
+
const refType = parts[1]
|
|
78
|
+
const refName = parts[2]
|
|
79
|
+
|
|
76
80
|
// Early return from an already found reference
|
|
77
81
|
if (refs[ref]) {
|
|
78
|
-
|
|
82
|
+
if (refType === 'resources') {
|
|
83
|
+
// all resources references must be resolved during deployment
|
|
84
|
+
unresolvedRefs.push({path: foundRef.path, ref: foundRef.ref})
|
|
85
|
+
} else {
|
|
86
|
+
foundRef.container[foundRef.property] = refs[ref].container[refs[ref].property]
|
|
87
|
+
}
|
|
79
88
|
continue
|
|
80
89
|
}
|
|
81
90
|
|
|
82
91
|
refs[ref] = foundRef
|
|
83
92
|
|
|
84
|
-
const parts = ref.split('.')
|
|
85
|
-
const refType = parts[1]
|
|
86
|
-
const refName = parts[2]
|
|
87
93
|
if (refType === 'parameters' || refType === 'params') {
|
|
88
94
|
const param = parameters[refName]
|
|
89
95
|
if (is.scalar(param)) {
|
|
@@ -112,8 +118,16 @@ function resolve(blueprint, foundRefs, options) {
|
|
|
112
118
|
} else if (refType === 'blueprintVersion') {
|
|
113
119
|
foundRef.container[foundRef.property] = blueprint.blueprintVersion
|
|
114
120
|
} else if (refType === 'resources') {
|
|
115
|
-
//
|
|
116
|
-
|
|
121
|
+
// check that the resource is in the list
|
|
122
|
+
if (blueprint.resources?.some((resource) => resource.name === refName)) {
|
|
123
|
+
// all resources references must be resolved during deployment
|
|
124
|
+
unresolvedRefs.push({path: foundRef.path, ref: foundRef.ref})
|
|
125
|
+
} else {
|
|
126
|
+
refErrors.push({
|
|
127
|
+
message: `Reference error '${ref}': '${refName}' not found in blueprint resources`,
|
|
128
|
+
type: 'missing_resource',
|
|
129
|
+
})
|
|
130
|
+
}
|
|
117
131
|
} else {
|
|
118
132
|
refErrors.push({
|
|
119
133
|
message: `Reference error '${ref}': invalid reference type ${refType}`,
|
package/src/validate.js
CHANGED
|
@@ -71,7 +71,7 @@ function resources(resources) {
|
|
|
71
71
|
message: `Resources must be an object, found: ${JSON.stringify(resource)}`,
|
|
72
72
|
type: 'invalid_type',
|
|
73
73
|
})
|
|
74
|
-
return
|
|
74
|
+
return
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
const {name, type} = resource
|
|
@@ -187,7 +187,7 @@ function parameters(parameters) {
|
|
|
187
187
|
message: `Parameters must be an object, found: ${JSON.stringify(param)}`,
|
|
188
188
|
type: 'invalid_type',
|
|
189
189
|
})
|
|
190
|
-
return
|
|
190
|
+
return
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
const {name, type} = param
|
|
@@ -265,7 +265,7 @@ function outputs(outputs) {
|
|
|
265
265
|
message: `Outputs must be an object, found: ${JSON.stringify(output)}`,
|
|
266
266
|
type: 'invalid_type',
|
|
267
267
|
})
|
|
268
|
-
return
|
|
268
|
+
return
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
const {name, value} = output
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
2
|
+
missingParameterReference: {
|
|
3
3
|
input: {
|
|
4
4
|
resources: [
|
|
5
5
|
{
|
|
@@ -34,7 +34,28 @@ export default {
|
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
missingResourceReference: {
|
|
38
|
+
input: {
|
|
39
|
+
resources: [
|
|
40
|
+
{
|
|
41
|
+
name: 'a-function',
|
|
42
|
+
type: 'cloud-function',
|
|
43
|
+
config: {memory: '$.resources.another-function.memory'},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
expected: {
|
|
48
|
+
resources: [
|
|
49
|
+
{
|
|
50
|
+
name: 'a-function',
|
|
51
|
+
type: 'cloud-function',
|
|
52
|
+
config: {memory: '$.resources.another-function.memory'},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
missingValueReference: {
|
|
38
59
|
input: {
|
|
39
60
|
resources: [
|
|
40
61
|
{
|
package/test/mocks/references.js
CHANGED
|
@@ -319,7 +319,11 @@ export default {
|
|
|
319
319
|
],
|
|
320
320
|
outputs: [
|
|
321
321
|
{
|
|
322
|
-
name: 'configured-memory',
|
|
322
|
+
name: 'configured-memory-1',
|
|
323
|
+
value: '$.resources.another-function.config.memory',
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: 'configured-memory-2',
|
|
323
327
|
value: '$.resources.another-function.config.memory',
|
|
324
328
|
},
|
|
325
329
|
],
|
|
@@ -340,7 +344,11 @@ export default {
|
|
|
340
344
|
],
|
|
341
345
|
outputs: [
|
|
342
346
|
{
|
|
343
|
-
name: 'configured-memory',
|
|
347
|
+
name: 'configured-memory-1',
|
|
348
|
+
value: '$.resources.another-function.config.memory',
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
name: 'configured-memory-2',
|
|
344
352
|
value: '$.resources.another-function.config.memory',
|
|
345
353
|
},
|
|
346
354
|
],
|
|
@@ -352,7 +360,11 @@ export default {
|
|
|
352
360
|
ref: '$.resources.a-function.config.memory',
|
|
353
361
|
},
|
|
354
362
|
{
|
|
355
|
-
path: 'outputs.configured-memory.value',
|
|
363
|
+
path: 'outputs.configured-memory-1.value',
|
|
364
|
+
ref: '$.resources.another-function.config.memory',
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
path: 'outputs.configured-memory-2.value',
|
|
356
368
|
ref: '$.resources.another-function.config.memory',
|
|
357
369
|
},
|
|
358
370
|
],
|
|
@@ -361,6 +373,10 @@ export default {
|
|
|
361
373
|
unresolvedArrayReference: {
|
|
362
374
|
input: {
|
|
363
375
|
resources: [
|
|
376
|
+
{
|
|
377
|
+
name: 'a-project',
|
|
378
|
+
type: 'cloud-project',
|
|
379
|
+
},
|
|
364
380
|
{
|
|
365
381
|
name: 'a-function',
|
|
366
382
|
type: 'cloud-function',
|
|
@@ -371,6 +387,10 @@ export default {
|
|
|
371
387
|
|
|
372
388
|
expected: {
|
|
373
389
|
resources: [
|
|
390
|
+
{
|
|
391
|
+
name: 'a-project',
|
|
392
|
+
type: 'cloud-project',
|
|
393
|
+
},
|
|
374
394
|
{
|
|
375
395
|
name: 'a-function',
|
|
376
396
|
type: 'cloud-function',
|
|
@@ -390,6 +410,10 @@ export default {
|
|
|
390
410
|
unresolvedDeeplyNestedArrayReference: {
|
|
391
411
|
input: {
|
|
392
412
|
resources: [
|
|
413
|
+
{
|
|
414
|
+
name: 'a-project',
|
|
415
|
+
type: 'cloud-project',
|
|
416
|
+
},
|
|
393
417
|
{
|
|
394
418
|
name: 'a-function',
|
|
395
419
|
type: 'cloud-function',
|
|
@@ -406,6 +430,10 @@ export default {
|
|
|
406
430
|
|
|
407
431
|
expected: {
|
|
408
432
|
resources: [
|
|
433
|
+
{
|
|
434
|
+
name: 'a-project',
|
|
435
|
+
type: 'cloud-project',
|
|
436
|
+
},
|
|
409
437
|
{
|
|
410
438
|
name: 'a-function',
|
|
411
439
|
type: 'cloud-function',
|
package/test/unit/index.test.js
CHANGED
|
@@ -117,6 +117,8 @@ tap.test('Reference resolution', async (t) => {
|
|
|
117
117
|
t.same(blueprint, expected, `${name}: returned expected blueprint`)
|
|
118
118
|
t.same(unresolvedRefs, unresolved, `${name}: returned expected unresolved references`)
|
|
119
119
|
t.notOk('errors' in output, `${name}: found no issues`)
|
|
120
|
+
} else {
|
|
121
|
+
t.notOk(output.errors, `${name}: ${JSON.stringify(output.errors)}`)
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
|