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