@platforma-sdk/workflow-tengo 2.8.1 → 2.8.2
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/dist/tengo/lib/assets.lib.tengo +76 -82
- package/dist/tengo/lib/constants.lib.tengo +28 -31
- package/dist/tengo/lib/exec.R.internal.lib.tengo +14 -14
- package/dist/tengo/lib/exec.R.lib.tengo +158 -167
- package/dist/tengo/lib/exec.internal.lib.tengo +222 -234
- package/dist/tengo/lib/exec.lib.tengo +647 -714
- package/dist/tengo/lib/exec.package.lib.tengo +229 -238
- package/dist/tengo/lib/exec.python.internal.lib.tengo +5 -6
- package/dist/tengo/lib/exec.python.lib.tengo +138 -146
- package/dist/tengo/lib/exec.runcmd.lib.tengo +234 -253
- package/dist/tengo/lib/exec.runenv.lib.tengo +88 -92
- package/dist/tengo/lib/exec.stream.lib.tengo +36 -40
- package/dist/tengo/lib/file.internal.lib.tengo +70 -77
- package/dist/tengo/lib/file.lib.tengo +54 -57
- package/dist/tengo/lib/ll.lib.tengo +217 -241
- package/dist/tengo/lib/maps.lib.tengo +98 -106
- package/dist/tengo/lib/objects.lib.tengo +11 -13
- package/dist/tengo/lib/oop.lib.tengo +16 -19
- package/dist/tengo/lib/path.lib.tengo +116 -125
- package/dist/tengo/lib/pframes.constants.lib.tengo +25 -28
- package/dist/tengo/lib/pframes.export-pcolumn.lib.tengo +28 -33
- package/dist/tengo/lib/pframes.lib.tengo +38 -43
- package/dist/tengo/lib/pframes.ll.lib.tengo +70 -73
- package/dist/tengo/lib/pframes.pcolumn.lib.tengo +45 -51
- package/dist/tengo/lib/pframes.spec.lib.tengo +70 -96
- package/dist/tengo/lib/pframes.util.lib.tengo +154 -289
- package/dist/tengo/lib/pframes.xsv.lib.tengo +260 -273
- package/dist/tengo/lib/render.lib.tengo +65 -76
- package/dist/tengo/lib/sets.lib.tengo +61 -68
- package/dist/tengo/lib/slices.lib.tengo +169 -180
- package/dist/tengo/lib/smart.lib.tengo +956 -1069
- package/dist/tengo/lib/test.lib.tengo +129 -161
- package/dist/tengo/lib/tpl.lib.tengo +448 -516
- package/dist/tengo/lib/tpl.state-await.lib.tengo +226 -241
- package/dist/tengo/lib/tpl.util.lib.tengo +4 -9
- package/dist/tengo/lib/validation.lib.tengo +334 -379
- package/dist/tengo/lib/workdir.lib.tengo +309 -332
- package/dist/tengo/lib/workdir.proc.lib.tengo +126 -144
- package/dist/tengo/lib/workdir.save.lib.tengo +113 -130
- package/dist/tengo/lib/workflow.bobject.lib.tengo +21 -26
- package/dist/tengo/lib/workflow.bquery.lib.tengo +140 -166
- package/dist/tengo/lib/workflow.constants.lib.tengo +1 -2
- package/dist/tengo/lib/workflow.context.lib.tengo +27 -32
- package/dist/tengo/lib/workflow.lib.tengo +167 -207
- package/dist/tengo/tpl/exec.R.create-renv.plj.gz +0 -0
- package/dist/tengo/tpl/exec.exec.plj.gz +0 -0
- package/dist/tengo/tpl/exec.python.create-venv.plj.gz +0 -0
- package/dist/tengo/tpl/exec.python.install-deps.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.aggregate.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-multiple-pcolumns.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-single-pcolumn.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.import-dir.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.map-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.xsv-export-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.xsv-import-map.plj.gz +0 -0
- package/dist/tengo/tpl/workdir.save.plj.gz +0 -0
- package/dist/tengo/tpl/workflow.build-ctx.plj.gz +0 -0
- package/package.json +5 -5
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
ll := import("@platforma-sdk/workflow-tengo:ll")
|
|
2
|
-
sets := import("@platforma-sdk/workflow-tengo:sets")
|
|
3
2
|
fmt := import("fmt")
|
|
4
3
|
text := import("text")
|
|
5
4
|
maps := import("@platforma-sdk/workflow-tengo:maps")
|
|
@@ -8,443 +7,399 @@ smart := import("@platforma-sdk/workflow-tengo:smart")
|
|
|
8
7
|
|
|
9
8
|
json := import("json")
|
|
10
9
|
|
|
11
|
-
//
|
|
12
|
-
// Tools for implementing your own checks:
|
|
13
|
-
//
|
|
14
10
|
|
|
15
11
|
_formatKeyPath := func(current, format, key) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
if current == "" {
|
|
13
|
+
if !is_string(key) {
|
|
14
|
+
return fmt.sprintf("[%d]", key)
|
|
15
|
+
}
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
return key
|
|
18
|
+
}
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
return fmt.sprintf(format, current, key)
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
23
|
+
|
|
24
|
+
|
|
30
25
|
success := { result: true }
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
39
33
|
fail := func(keyPath, msg, ...args) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
return {
|
|
35
|
+
result: false,
|
|
36
|
+
message: keyPath + ": " + fmt.sprintf(msg, args...)
|
|
37
|
+
}
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
isSuccess := func(r) {
|
|
47
|
-
|
|
41
|
+
return r.result == true
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
55
48
|
isFail := func(r) {
|
|
56
|
-
|
|
49
|
+
return r.result == false
|
|
57
50
|
}
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
67
59
|
check := func(condition, keyPath, msg, ...args) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
if condition {
|
|
61
|
+
return success
|
|
62
|
+
}
|
|
71
63
|
|
|
72
|
-
|
|
64
|
+
return fail(keyPath, msg, args...)
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
//
|
|
76
|
-
// Validation:
|
|
77
|
-
//
|
|
78
67
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
*/
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
86
74
|
_validateTypes := func(js, tags, keyPath, ...stack) {
|
|
87
|
-
|
|
75
|
+
k := tags.key
|
|
88
76
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
77
|
+
if k == "any" {
|
|
78
|
+
return success
|
|
79
|
+
}
|
|
92
80
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
if k == "alphanumeric" && ((is_string(js) && text.re_match("^[[:alnum:]]*$", js)) || is_int(js)) {
|
|
82
|
+
return success
|
|
83
|
+
}
|
|
96
84
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
if k == "string" && is_string(js) {
|
|
86
|
+
regex := tags.tags["regex"]
|
|
87
|
+
if !is_undefined(regex) && !text.re_match(regex, js) {
|
|
88
|
+
return fail(keyPath, "value %q does not conform regex %q", js, regex)
|
|
89
|
+
}
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
return success
|
|
92
|
+
}
|
|
105
93
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
if k == "char" && is_char(js) {
|
|
95
|
+
return success
|
|
96
|
+
}
|
|
109
97
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
if k == "bytes" && is_bytes(js) {
|
|
99
|
+
return success
|
|
100
|
+
}
|
|
113
101
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
if k == "null" && is_undefined(js) {
|
|
103
|
+
return success
|
|
104
|
+
}
|
|
117
105
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
if k == "number" && (is_int(js) || is_float(js)) {
|
|
107
|
+
return success
|
|
108
|
+
}
|
|
121
109
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
110
|
+
if k == "bool" && is_bool(js) {
|
|
111
|
+
return success
|
|
112
|
+
}
|
|
125
113
|
|
|
126
|
-
|
|
114
|
+
return fail(keyPath, "js %q is not one of a type: %s", js, tags.key)
|
|
127
115
|
}
|
|
128
116
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
135
122
|
_parseTags := func(rule) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
*/
|
|
123
|
+
tagsKV := text.split(rule, ",")
|
|
124
|
+
key := tagsKV[0]
|
|
125
|
+
tagsKV = tagsKV[1:]
|
|
126
|
+
|
|
127
|
+
tags := {}
|
|
128
|
+
for _, kv in tagsKV {
|
|
129
|
+
kAndV := text.split(kv, "=")
|
|
130
|
+
k := kAndV[0]
|
|
131
|
+
if len(kAndV) == 1 {
|
|
132
|
+
tags[k] = true
|
|
133
|
+
} else {
|
|
134
|
+
tags[k] = kAndV[1]
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return ll.toStrict({
|
|
139
|
+
key: key,
|
|
140
|
+
tags: tags
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
165
151
|
_validateJson := func(js, schema, keyPath, ...stack) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if key.tags["omitempty"] || key.tags["optional"] || key.tags["?"] {
|
|
308
|
-
continue
|
|
309
|
-
}
|
|
310
|
-
return fail(keyPath, "value %q does not contain key %q", js, _key)
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
r := _validateJson(elem, schemaRules[_key], _formatKeyPath(keyPath, "%s.%s", _key), js, stack...)
|
|
314
|
-
if isFail(r) {
|
|
315
|
-
return r
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return success
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Checks if the given JSON conforms to the given schema.
|
|
324
|
-
*
|
|
325
|
-
* @param js: any - the JSON to check.
|
|
326
|
-
* @param schema: any - the schema to check against.
|
|
327
|
-
* @return either fail or success
|
|
328
|
-
*/
|
|
152
|
+
if is_undefined(schema) {
|
|
153
|
+
if len(stack) == 0 {
|
|
154
|
+
return fail(keyPath, "key is not defined by schema, but exists in the JSON")
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return fail(keyPath, "key is not defined by schema, but exists in the JSON. Validated item: %#v", stack[0])
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if is_string(schema) {
|
|
161
|
+
if schema == "any" {
|
|
162
|
+
return success
|
|
163
|
+
}
|
|
164
|
+
tags := _parseTags(schema)
|
|
165
|
+
|
|
166
|
+
return _validateTypes(js, tags, keyPath, stack...)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if is_callable(schema) {
|
|
170
|
+
return schema(js, keyPath, stack)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if is_array(schema) && len(schema) > 0 && schema[0] == "or" {
|
|
174
|
+
for i, elem in schema[1:] {
|
|
175
|
+
r := _validateJson(js, elem, keyPath, stack...)
|
|
176
|
+
if isSuccess(r) {
|
|
177
|
+
return r
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return fail(keyPath, "js %q does not fit any of the following rules: %q", js, schema)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if is_array(schema) {
|
|
185
|
+
if !is_array(js) {
|
|
186
|
+
return fail(keyPath, "js %q must be array", js)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
schema = schema[0]
|
|
190
|
+
for i, elem in js {
|
|
191
|
+
r := _validateJson(elem, schema, _formatKeyPath(keyPath, "%s[%d]", i), js, stack...)
|
|
192
|
+
if isFail(r) {
|
|
193
|
+
return r
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return success
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if !ll.isMap(js) {
|
|
201
|
+
return fail(keyPath, "js %#v must be map", js)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
schemaTags := {}
|
|
205
|
+
schemaRules := {}
|
|
206
|
+
jsFull := {}
|
|
207
|
+
|
|
208
|
+
for k, v in schema {
|
|
209
|
+
p := _parseTags(k)
|
|
210
|
+
schemaTags[p.key] = p
|
|
211
|
+
schemaRules[p.key] = v
|
|
212
|
+
jsFull[p.key] = undefined
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
any := schemaTags["any"]
|
|
216
|
+
if !is_undefined(any) {
|
|
217
|
+
if is_undefined(jsFull["any"]) { // in case actual object has field named "any"
|
|
218
|
+
delete(jsFull, "any")
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
options := schemaTags["__options__"]
|
|
223
|
+
if is_undefined(options) {
|
|
224
|
+
options = {}
|
|
225
|
+
} else {
|
|
226
|
+
delete(schemaTags, "__options__")
|
|
227
|
+
delete(schemaRules, "__options__")
|
|
228
|
+
if is_undefined(jsFull["__options__"]) { // in case actual object has field named "__options__"
|
|
229
|
+
delete(jsFull, "__options__")
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
for k, v in js {
|
|
234
|
+
jsFull[k] = v
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
for _key, elem in jsFull {
|
|
238
|
+
if any {
|
|
239
|
+
r := _validateJson(elem, schemaRules["any"], _formatKeyPath(keyPath, "%s.%s", _key), js, stack...)
|
|
240
|
+
if isFail(r) {
|
|
241
|
+
return r
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if !is_undefined(any.tags["type"]) {
|
|
245
|
+
r := _validateJson(_key, any.tags["type"], keyPath, stack...)
|
|
246
|
+
if isFail(r) {
|
|
247
|
+
return r
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
continue
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
key := schemaTags[_key]
|
|
255
|
+
|
|
256
|
+
if is_undefined(key) {
|
|
257
|
+
if options.tags["closed"] == true {
|
|
258
|
+
return fail(keyPath, "only keys %v from the schema must be set, found %q", maps.getKeys(schema), _key)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
continue
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if key.tags["type"] {
|
|
265
|
+
r := _validateJson(_key, key.tags["type"], keyPath, stack...)
|
|
266
|
+
if isFail(r) {
|
|
267
|
+
return r
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if is_undefined(elem) {
|
|
272
|
+
if key.tags["omitempty"] || key.tags["optional"] || key.tags["?"] {
|
|
273
|
+
continue
|
|
274
|
+
}
|
|
275
|
+
return fail(keyPath, "value %q does not contain key %q", js, _key)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
r := _validateJson(elem, schemaRules[_key], _formatKeyPath(keyPath, "%s.%s", _key), js, stack...)
|
|
279
|
+
if isFail(r) {
|
|
280
|
+
return r
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return success
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
329
293
|
checkJson := func(js, schema) {
|
|
330
|
-
|
|
294
|
+
return _validateJson(js, schema, "")
|
|
331
295
|
}
|
|
332
296
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
*/
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
340
303
|
isValid := func(js, schema) {
|
|
341
|
-
|
|
304
|
+
return _validateJson(js, schema, "").result
|
|
342
305
|
}
|
|
343
306
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
*/
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
351
313
|
assertJsonSchema := func(js, schema, ...failMsg) {
|
|
352
|
-
|
|
314
|
+
r := _validateJson(js, schema, "")
|
|
353
315
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
316
|
+
msg := "JSON validation error"
|
|
317
|
+
if len(failMsg) > 0 {
|
|
318
|
+
msg = failMsg[0]
|
|
319
|
+
}
|
|
358
320
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
321
|
+
if isFail(r) {
|
|
322
|
+
ll.panic("%s: %s", msg, r.message)
|
|
362
323
|
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
363
329
|
|
|
364
|
-
//
|
|
365
|
-
// Domain-specific schemas and checks:
|
|
366
|
-
//
|
|
367
330
|
|
|
368
|
-
/**
|
|
369
|
-
* Checks if the given element is a resource.
|
|
370
|
-
*
|
|
371
|
-
* @param options: object - resource validation options
|
|
372
|
-
*/
|
|
373
331
|
resource := func(...args) {
|
|
374
332
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
*/
|
|
333
|
+
ops := {}
|
|
334
|
+
if len(args) > 0 {
|
|
335
|
+
ops = args[0]
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
assertJsonSchema(ops, {
|
|
339
|
+
`type,?`: {
|
|
340
|
+
Name: `string`,
|
|
341
|
+
Version: `string`
|
|
342
|
+
}
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
checker := func(elem, keyPath, stack) {
|
|
346
|
+
c := undefined
|
|
347
|
+
|
|
348
|
+
c = check(smart.isResource(elem), keyPath, "the element " + elem + " must be a resource")
|
|
349
|
+
if isFail(c) {
|
|
350
|
+
return c
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if !is_undefined(ops.type) {
|
|
354
|
+
c = check(elem.info().Type.Name == ops.type.Name && elem.info().Type.Version == ops.type.Version, keyPath,
|
|
355
|
+
"the element " + elem + " must have the following type: ", ops.type, " found: ", elem.info().Type)
|
|
356
|
+
if isFail(c) {
|
|
357
|
+
return c
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return c
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return checker
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
414
371
|
resourceType := func(rt) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
372
|
+
return func(elem, keyPath, stack) {
|
|
373
|
+
return check(smart.isResource(elem) && elem.info().Type.Name == rt.Name, keyPath, "the element " + elem + " must be a resource")
|
|
374
|
+
}
|
|
418
375
|
}
|
|
419
376
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
*/
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
426
382
|
reference := func(elem, keyPath, stack) {
|
|
427
|
-
|
|
383
|
+
return check(smart.isReference(elem), keyPath, "the element " + elem + " must be a resource or a field")
|
|
428
384
|
}
|
|
429
385
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
*/
|
|
386
|
+
|
|
387
|
+
|
|
433
388
|
refSchema := {
|
|
434
|
-
|
|
435
|
-
|
|
389
|
+
blockId: `string`,
|
|
390
|
+
name: `string`
|
|
436
391
|
}
|
|
437
392
|
|
|
438
393
|
export ll.toStrict({
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
394
|
+
success: success,
|
|
395
|
+
fail: fail,
|
|
396
|
+
isSuccess: isSuccess,
|
|
397
|
+
isFail: isFail,
|
|
398
|
+
checkJson: checkJson,
|
|
399
|
+
isValid: isValid,
|
|
400
|
+
assertJsonSchema: assertJsonSchema,
|
|
401
|
+
resource: resource,
|
|
402
|
+
reference: reference,
|
|
403
|
+
resourceType: resourceType,
|
|
404
|
+
ref: refSchema
|
|
450
405
|
})
|