@sanity/blueprints-parser 0.2.1 → 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 +25 -0
- package/biome.jsonc +1 -1
- package/package.json +3 -3
- package/src/index.d.ts +17 -7
- package/src/refs.js +56 -35
- package/src/validate.js +3 -3
- package/test/mocks/reference-errors.js +103 -10
- package/test/mocks/references.js +91 -26
- package/test/unit/index.test.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
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
|
+
|
|
12
|
+
## [0.3.0](https://github.com/sanity-io/blueprints-parser/compare/v0.2.1...v0.3.0) (2025-10-17)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### ⚠ BREAKING CHANGES
|
|
16
|
+
|
|
17
|
+
* Make references work more consistently ([#9](https://github.com/sanity-io/blueprints-parser/issues/9))
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* Make references work more consistently ([#9](https://github.com/sanity-io/blueprints-parser/issues/9)) ([c2e7944](https://github.com/sanity-io/blueprints-parser/commit/c2e7944c88361fd6547db9b8932c4cab261c3b41))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* release 0.3.0 ([#11](https://github.com/sanity-io/blueprints-parser/issues/11)) ([e7971b1](https://github.com/sanity-io/blueprints-parser/commit/e7971b1c595b13cc83f754e5f39332e0cf528ba5))
|
|
27
|
+
|
|
3
28
|
## [0.2.1](https://github.com/sanity-io/blueprints-parser/compare/v0.2.0...v0.2.1) (2025-09-04)
|
|
4
29
|
|
|
5
30
|
|
package/biome.jsonc
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/blueprints-parser",
|
|
3
|
-
"version": "0.
|
|
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/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export type Scalar = string | number
|
|
2
|
+
|
|
1
3
|
export type BlueprintInput = string | Buffer | object
|
|
2
4
|
|
|
3
5
|
export type ParserOptions = {
|
|
4
6
|
debug?: boolean
|
|
5
|
-
parameters?: Record<string,
|
|
7
|
+
parameters?: Record<string, Scalar>
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export type Resource = {
|
|
@@ -32,7 +34,7 @@ export type Output = {
|
|
|
32
34
|
export type Blueprint = {
|
|
33
35
|
blueprintVersion?: string
|
|
34
36
|
resources?: Array<Resource>
|
|
35
|
-
values?: Record<string,
|
|
37
|
+
values?: Record<string, Scalar>
|
|
36
38
|
parameters?: Array<Parameter>
|
|
37
39
|
outputs?: Array<Output>
|
|
38
40
|
metadata?: Record<string, unknown>
|
|
@@ -64,11 +66,19 @@ export type ValidationError = {
|
|
|
64
66
|
message: string
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
export type
|
|
69
|
+
export type UnresolvedReference = {
|
|
70
|
+
/** The location where the reference was found */
|
|
68
71
|
path: string
|
|
69
|
-
|
|
72
|
+
/** The content of the reference (e.g. $.resources.project-1.id) */
|
|
70
73
|
ref: string
|
|
71
|
-
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type Reference = UnresolvedReference & {
|
|
77
|
+
/** The object or array containing the reference */
|
|
78
|
+
container: object | Array
|
|
79
|
+
/** The key or index of the reference in the container */
|
|
80
|
+
property: string | number
|
|
81
|
+
}
|
|
72
82
|
|
|
73
83
|
export type ReferenceError = {
|
|
74
84
|
type: string
|
|
@@ -81,12 +91,12 @@ export type BlueprintOutput =
|
|
|
81
91
|
| {
|
|
82
92
|
result: 'valid'
|
|
83
93
|
blueprint: Blueprint
|
|
84
|
-
unresolvedRefs?: Array<
|
|
94
|
+
unresolvedRefs?: Array<UnresolvedReference>
|
|
85
95
|
}
|
|
86
96
|
| {
|
|
87
97
|
result: 'reference_errors'
|
|
88
98
|
blueprint: Blueprint
|
|
89
|
-
unresolvedRefs?: Array<
|
|
99
|
+
unresolvedRefs?: Array<UnresolvedReference>
|
|
90
100
|
errors: Array<ReferenceError>
|
|
91
101
|
}
|
|
92
102
|
| {
|
package/src/refs.js
CHANGED
|
@@ -19,14 +19,14 @@ function find(validatedBlueprint, options) {
|
|
|
19
19
|
if (is.object(item)) {
|
|
20
20
|
for (const [name, value] of Object.entries(item)) {
|
|
21
21
|
const cur = `${path}.${name}`
|
|
22
|
-
if (is.ref(value)) foundRefs.push({path: cur,
|
|
22
|
+
if (is.ref(value)) foundRefs.push({path: cur, ref: value, container: item, property: name})
|
|
23
23
|
else if (is.object(value) || is.array(value)) walk(value, cur)
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
if (is.array(item)) {
|
|
27
27
|
item.forEach((value, index) => {
|
|
28
28
|
const cur = `${path}[${index}]`
|
|
29
|
-
if (is.ref(value)) foundRefs.push({path: cur,
|
|
29
|
+
if (is.ref(value)) foundRefs.push({path: cur, ref: value, container: item, property: index})
|
|
30
30
|
else if (is.object(value)) walk(value, cur)
|
|
31
31
|
})
|
|
32
32
|
}
|
|
@@ -59,59 +59,80 @@ function find(validatedBlueprint, options) {
|
|
|
59
59
|
* @param {import('.').ParserOptions} options
|
|
60
60
|
* @returns {{
|
|
61
61
|
* resolvedBlueprint: import('.').Blueprint
|
|
62
|
-
* unresolvedRefs: Array<import('.').
|
|
62
|
+
* unresolvedRefs: Array<import('.').UnresolvedReference> | undefined
|
|
63
63
|
* refErrors: Array<import('.').ReferenceError>
|
|
64
64
|
* }}
|
|
65
65
|
*/
|
|
66
66
|
function resolve(blueprint, foundRefs, options) {
|
|
67
67
|
const {parameters = {}} = options
|
|
68
|
+
|
|
69
|
+
/** @type {Record<string, import('.').Reference>} */
|
|
68
70
|
const refs = {}
|
|
71
|
+
/** @type {Array<import('.').UnresolvedReference>} */
|
|
69
72
|
const unresolvedRefs = []
|
|
70
73
|
const refErrors = []
|
|
71
74
|
for (const foundRef of foundRefs) {
|
|
72
|
-
const {
|
|
73
|
-
const
|
|
75
|
+
const {ref} = foundRef
|
|
76
|
+
const parts = ref.split('.')
|
|
77
|
+
const refType = parts[1]
|
|
78
|
+
const refName = parts[2]
|
|
79
|
+
|
|
74
80
|
// Early return from an already found reference
|
|
75
|
-
if (refs[
|
|
76
|
-
|
|
81
|
+
if (refs[ref]) {
|
|
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
|
+
}
|
|
77
88
|
continue
|
|
78
89
|
}
|
|
79
90
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
refs[refPath] = found
|
|
87
|
-
if (is.object(item)) item[property] = refs[refPath]
|
|
88
|
-
if (is.array(item)) {
|
|
89
|
-
const index = item.findIndex((i) => i === property)
|
|
90
|
-
item[index] = refs[refPath]
|
|
91
|
-
}
|
|
91
|
+
refs[ref] = foundRef
|
|
92
|
+
|
|
93
|
+
if (refType === 'parameters' || refType === 'params') {
|
|
94
|
+
const param = parameters[refName]
|
|
95
|
+
if (is.scalar(param)) {
|
|
96
|
+
foundRef.container[foundRef.property] = param
|
|
92
97
|
} else {
|
|
93
98
|
refErrors.push({
|
|
94
|
-
message: `Reference error '${ref}': '${
|
|
99
|
+
message: `Reference error '${ref}': '${refName}' not found in passed parameters`,
|
|
95
100
|
type: 'missing_parameter',
|
|
96
101
|
})
|
|
97
102
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
} else if (refType === 'values') {
|
|
104
|
+
const value = blueprint.values?.[refName]
|
|
105
|
+
if (is.scalar(value)) {
|
|
106
|
+
foundRef.container[foundRef.property] = value
|
|
107
|
+
} else {
|
|
108
|
+
refErrors.push({
|
|
109
|
+
message: `Reference error '${ref}': '${refName}' not found in blueprint values`,
|
|
110
|
+
type: 'missing_value',
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
} else if (refType === 'metadata' || refType === 'outputs') {
|
|
114
|
+
refErrors.push({
|
|
115
|
+
message: `Reference error '${ref}': invalid reference to ${refType}`,
|
|
116
|
+
type: 'invalid_reference',
|
|
117
|
+
})
|
|
118
|
+
} else if (refType === 'blueprintVersion') {
|
|
119
|
+
foundRef.container[foundRef.property] = blueprint.blueprintVersion
|
|
120
|
+
} else if (refType === 'resources') {
|
|
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
|
+
})
|
|
112
130
|
}
|
|
113
131
|
} else {
|
|
114
|
-
|
|
132
|
+
refErrors.push({
|
|
133
|
+
message: `Reference error '${ref}': invalid reference type ${refType}`,
|
|
134
|
+
type: 'invalid_reference',
|
|
135
|
+
})
|
|
115
136
|
}
|
|
116
137
|
}
|
|
117
138
|
|
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,6 +34,90 @@ export default {
|
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
|
|
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: {
|
|
59
|
+
input: {
|
|
60
|
+
resources: [
|
|
61
|
+
{
|
|
62
|
+
name: 'a-function',
|
|
63
|
+
type: 'cloud-function',
|
|
64
|
+
config: {memory: '$.values.memory'},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
expected: {
|
|
69
|
+
resources: [
|
|
70
|
+
{
|
|
71
|
+
name: 'a-function',
|
|
72
|
+
type: 'cloud-function',
|
|
73
|
+
config: {memory: '$.values.memory'},
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
invalidReferenceTypeMetadata: {
|
|
80
|
+
input: {
|
|
81
|
+
resources: [
|
|
82
|
+
{
|
|
83
|
+
name: 'a-function',
|
|
84
|
+
type: 'cloud-function',
|
|
85
|
+
config: {memory: '$.metadata.memory'},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
expected: {
|
|
90
|
+
resources: [
|
|
91
|
+
{
|
|
92
|
+
name: 'a-function',
|
|
93
|
+
type: 'cloud-function',
|
|
94
|
+
config: {memory: '$.metadata.memory'},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
invalidReferenceType: {
|
|
101
|
+
input: {
|
|
102
|
+
resources: [
|
|
103
|
+
{
|
|
104
|
+
name: 'a-function',
|
|
105
|
+
type: 'cloud-function',
|
|
106
|
+
config: {memory: '$.invalid.memory'},
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
expected: {
|
|
111
|
+
resources: [
|
|
112
|
+
{
|
|
113
|
+
name: 'a-function',
|
|
114
|
+
type: 'cloud-function',
|
|
115
|
+
config: {memory: '$.invalid.memory'},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
|
|
37
121
|
unresolvedParameterReferenceAndRegularReference: {
|
|
38
122
|
input: {
|
|
39
123
|
resources: [
|
|
@@ -42,7 +126,14 @@ export default {
|
|
|
42
126
|
type: 'cloud-function',
|
|
43
127
|
config: {
|
|
44
128
|
memory: '$.parameters.memory',
|
|
45
|
-
disk: '
|
|
129
|
+
disk: '20G',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'another-function',
|
|
134
|
+
type: 'cloud-function',
|
|
135
|
+
config: {
|
|
136
|
+
disk: '$.resources.a-function.config.disk',
|
|
46
137
|
},
|
|
47
138
|
},
|
|
48
139
|
],
|
|
@@ -61,7 +152,14 @@ export default {
|
|
|
61
152
|
type: 'cloud-function',
|
|
62
153
|
config: {
|
|
63
154
|
memory: '$.parameters.memory',
|
|
64
|
-
disk: '
|
|
155
|
+
disk: '20G',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: 'another-function',
|
|
160
|
+
type: 'cloud-function',
|
|
161
|
+
config: {
|
|
162
|
+
disk: '$.resources.a-function.config.disk',
|
|
65
163
|
},
|
|
66
164
|
},
|
|
67
165
|
],
|
|
@@ -75,13 +173,8 @@ export default {
|
|
|
75
173
|
},
|
|
76
174
|
unresolved: [
|
|
77
175
|
{
|
|
78
|
-
path: 'resources.
|
|
79
|
-
|
|
80
|
-
ref: '$.values.disk',
|
|
81
|
-
item: {
|
|
82
|
-
memory: '$.parameters.memory',
|
|
83
|
-
disk: '$.values.disk',
|
|
84
|
-
},
|
|
176
|
+
path: 'resources.another-function.config.disk',
|
|
177
|
+
ref: '$.resources.a-function.config.disk',
|
|
85
178
|
},
|
|
86
179
|
],
|
|
87
180
|
},
|
package/test/mocks/references.js
CHANGED
|
@@ -84,6 +84,28 @@ export default {
|
|
|
84
84
|
unresolved: undefined,
|
|
85
85
|
},
|
|
86
86
|
|
|
87
|
+
blueprintVersionReference: {
|
|
88
|
+
input: {
|
|
89
|
+
blueprintVersion: '2025-01-01',
|
|
90
|
+
outputs: [
|
|
91
|
+
{
|
|
92
|
+
name: 'version',
|
|
93
|
+
value: '$.blueprintVersion',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
expected: {
|
|
99
|
+
blueprintVersion: '2025-01-01',
|
|
100
|
+
outputs: [
|
|
101
|
+
{
|
|
102
|
+
name: 'version',
|
|
103
|
+
value: '2025-01-01',
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
|
|
87
109
|
deepyNestedObjectReference: {
|
|
88
110
|
input: {
|
|
89
111
|
resources: [
|
|
@@ -105,7 +127,7 @@ export default {
|
|
|
105
127
|
{
|
|
106
128
|
name: 'a-function',
|
|
107
129
|
type: 'cloud-function',
|
|
108
|
-
config: {memory:
|
|
130
|
+
config: {memory: '$.resources.another-function.config.env.memory'},
|
|
109
131
|
},
|
|
110
132
|
{
|
|
111
133
|
name: 'another-function',
|
|
@@ -115,7 +137,12 @@ export default {
|
|
|
115
137
|
],
|
|
116
138
|
},
|
|
117
139
|
|
|
118
|
-
unresolved:
|
|
140
|
+
unresolved: [
|
|
141
|
+
{
|
|
142
|
+
path: 'resources.a-function.config.memory',
|
|
143
|
+
ref: '$.resources.another-function.config.env.memory',
|
|
144
|
+
},
|
|
145
|
+
],
|
|
119
146
|
},
|
|
120
147
|
|
|
121
148
|
arrayReference: {
|
|
@@ -142,12 +169,17 @@ export default {
|
|
|
142
169
|
{
|
|
143
170
|
name: 'a-function',
|
|
144
171
|
type: 'cloud-function',
|
|
145
|
-
projects: ['project-1', 'a-project', 'project-2'],
|
|
172
|
+
projects: ['project-1', '$.resources.a-project.name', 'project-2'],
|
|
146
173
|
},
|
|
147
174
|
],
|
|
148
175
|
},
|
|
149
176
|
|
|
150
|
-
unresolved:
|
|
177
|
+
unresolved: [
|
|
178
|
+
{
|
|
179
|
+
path: 'resources.a-function.projects[1]',
|
|
180
|
+
ref: '$.resources.a-project.name',
|
|
181
|
+
},
|
|
182
|
+
],
|
|
151
183
|
},
|
|
152
184
|
|
|
153
185
|
// This is so weird please don't do this omg
|
|
@@ -184,7 +216,7 @@ export default {
|
|
|
184
216
|
config: {
|
|
185
217
|
settings: [
|
|
186
218
|
{
|
|
187
|
-
projects: ['project-1', 'project-2', 'a-project'],
|
|
219
|
+
projects: ['project-1', 'project-2', '$.resources.a-project.name'],
|
|
188
220
|
},
|
|
189
221
|
],
|
|
190
222
|
},
|
|
@@ -192,7 +224,12 @@ export default {
|
|
|
192
224
|
],
|
|
193
225
|
},
|
|
194
226
|
|
|
195
|
-
unresolved:
|
|
227
|
+
unresolved: [
|
|
228
|
+
{
|
|
229
|
+
path: 'resources.a-function.config.settings[0].projects[2]',
|
|
230
|
+
ref: '$.resources.a-project.name',
|
|
231
|
+
},
|
|
232
|
+
],
|
|
196
233
|
},
|
|
197
234
|
|
|
198
235
|
arrayReferenceToParams: {
|
|
@@ -272,13 +309,22 @@ export default {
|
|
|
272
309
|
{
|
|
273
310
|
name: 'a-function',
|
|
274
311
|
type: 'cloud-function',
|
|
275
|
-
config: {memory:
|
|
312
|
+
config: {memory: 1000},
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: 'another-function',
|
|
316
|
+
type: 'cloud-function',
|
|
317
|
+
config: {memory: '$.resources.a-function.config.memory'},
|
|
276
318
|
},
|
|
277
319
|
],
|
|
278
320
|
outputs: [
|
|
279
321
|
{
|
|
280
|
-
name: 'configured-memory',
|
|
281
|
-
value: '$.
|
|
322
|
+
name: 'configured-memory-1',
|
|
323
|
+
value: '$.resources.another-function.config.memory',
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: 'configured-memory-2',
|
|
327
|
+
value: '$.resources.another-function.config.memory',
|
|
282
328
|
},
|
|
283
329
|
],
|
|
284
330
|
},
|
|
@@ -288,29 +334,38 @@ export default {
|
|
|
288
334
|
{
|
|
289
335
|
name: 'a-function',
|
|
290
336
|
type: 'cloud-function',
|
|
291
|
-
config: {memory:
|
|
337
|
+
config: {memory: 1000},
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: 'another-function',
|
|
341
|
+
type: 'cloud-function',
|
|
342
|
+
config: {memory: '$.resources.a-function.config.memory'},
|
|
292
343
|
},
|
|
293
344
|
],
|
|
294
345
|
outputs: [
|
|
295
346
|
{
|
|
296
|
-
name: 'configured-memory',
|
|
297
|
-
value: '$.
|
|
347
|
+
name: 'configured-memory-1',
|
|
348
|
+
value: '$.resources.another-function.config.memory',
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
name: 'configured-memory-2',
|
|
352
|
+
value: '$.resources.another-function.config.memory',
|
|
298
353
|
},
|
|
299
354
|
],
|
|
300
355
|
},
|
|
301
356
|
|
|
302
357
|
unresolved: [
|
|
303
358
|
{
|
|
304
|
-
path: 'resources.
|
|
305
|
-
|
|
306
|
-
ref: '$.values.memory',
|
|
307
|
-
item: {memory: '$.values.memory'},
|
|
359
|
+
path: 'resources.another-function.config.memory',
|
|
360
|
+
ref: '$.resources.a-function.config.memory',
|
|
308
361
|
},
|
|
309
362
|
{
|
|
310
|
-
path: 'outputs.configured-memory.value',
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
363
|
+
path: 'outputs.configured-memory-1.value',
|
|
364
|
+
ref: '$.resources.another-function.config.memory',
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
path: 'outputs.configured-memory-2.value',
|
|
368
|
+
ref: '$.resources.another-function.config.memory',
|
|
314
369
|
},
|
|
315
370
|
],
|
|
316
371
|
},
|
|
@@ -318,6 +373,10 @@ export default {
|
|
|
318
373
|
unresolvedArrayReference: {
|
|
319
374
|
input: {
|
|
320
375
|
resources: [
|
|
376
|
+
{
|
|
377
|
+
name: 'a-project',
|
|
378
|
+
type: 'cloud-project',
|
|
379
|
+
},
|
|
321
380
|
{
|
|
322
381
|
name: 'a-function',
|
|
323
382
|
type: 'cloud-function',
|
|
@@ -328,6 +387,10 @@ export default {
|
|
|
328
387
|
|
|
329
388
|
expected: {
|
|
330
389
|
resources: [
|
|
390
|
+
{
|
|
391
|
+
name: 'a-project',
|
|
392
|
+
type: 'cloud-project',
|
|
393
|
+
},
|
|
331
394
|
{
|
|
332
395
|
name: 'a-function',
|
|
333
396
|
type: 'cloud-function',
|
|
@@ -339,10 +402,7 @@ export default {
|
|
|
339
402
|
unresolved: [
|
|
340
403
|
{
|
|
341
404
|
path: 'resources.a-function.projects[2]',
|
|
342
|
-
property: '$.resources.a-project.name',
|
|
343
405
|
ref: '$.resources.a-project.name',
|
|
344
|
-
item: ['project-1', 'project-2', '$.resources.a-project.name', 'project-4'],
|
|
345
|
-
index: 2,
|
|
346
406
|
},
|
|
347
407
|
],
|
|
348
408
|
},
|
|
@@ -350,6 +410,10 @@ export default {
|
|
|
350
410
|
unresolvedDeeplyNestedArrayReference: {
|
|
351
411
|
input: {
|
|
352
412
|
resources: [
|
|
413
|
+
{
|
|
414
|
+
name: 'a-project',
|
|
415
|
+
type: 'cloud-project',
|
|
416
|
+
},
|
|
353
417
|
{
|
|
354
418
|
name: 'a-function',
|
|
355
419
|
type: 'cloud-function',
|
|
@@ -366,6 +430,10 @@ export default {
|
|
|
366
430
|
|
|
367
431
|
expected: {
|
|
368
432
|
resources: [
|
|
433
|
+
{
|
|
434
|
+
name: 'a-project',
|
|
435
|
+
type: 'cloud-project',
|
|
436
|
+
},
|
|
369
437
|
{
|
|
370
438
|
name: 'a-function',
|
|
371
439
|
type: 'cloud-function',
|
|
@@ -383,10 +451,7 @@ export default {
|
|
|
383
451
|
unresolved: [
|
|
384
452
|
{
|
|
385
453
|
path: 'resources.a-function.config.settings[0].projects[0]',
|
|
386
|
-
property: '$.resources.a-project.name',
|
|
387
454
|
ref: '$.resources.a-project.name',
|
|
388
|
-
item: ['$.resources.a-project.name', 'project-2', 'project-3'],
|
|
389
|
-
index: 0,
|
|
390
455
|
},
|
|
391
456
|
],
|
|
392
457
|
},
|
package/test/unit/index.test.js
CHANGED
|
@@ -111,12 +111,14 @@ tap.test('Reference resolution', async (t) => {
|
|
|
111
111
|
debug: true,
|
|
112
112
|
parameters,
|
|
113
113
|
})
|
|
114
|
-
t.same(output.result, 'valid')
|
|
114
|
+
t.same(output.result, 'valid', `${name}: returned expected result`)
|
|
115
115
|
if (output.result === 'valid') {
|
|
116
116
|
const {blueprint, unresolvedRefs} = output
|
|
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
|
|