@platforma-sdk/workflow-tengo 2.14.0 → 2.15.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.
Files changed (80) hide show
  1. package/README.md +17 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +3 -1
  4. package/dist/index.mjs +3 -1
  5. package/dist/tengo/lib/assets.lib.tengo +28 -28
  6. package/dist/tengo/lib/assets.swinfo.lib.tengo +24 -24
  7. package/dist/tengo/lib/constants.lib.tengo +6 -3
  8. package/dist/tengo/lib/exec.R.internal.lib.tengo +2 -2
  9. package/dist/tengo/lib/exec.R.lib.tengo +41 -41
  10. package/dist/tengo/lib/exec.descriptor.lib.tengo +3 -3
  11. package/dist/tengo/lib/exec.internal.lib.tengo +41 -41
  12. package/dist/tengo/lib/exec.lib.tengo +289 -289
  13. package/dist/tengo/lib/exec.limits.lib.tengo +49 -49
  14. package/dist/tengo/lib/exec.monetization.lib.tengo +1 -1
  15. package/dist/tengo/lib/exec.monetization_internal.lib.tengo +38 -38
  16. package/dist/tengo/lib/exec.package.lib.tengo +53 -53
  17. package/dist/tengo/lib/exec.python.internal.lib.tengo +1 -1
  18. package/dist/tengo/lib/exec.python.lib.tengo +37 -37
  19. package/dist/tengo/lib/exec.runcmd.lib.tengo +138 -138
  20. package/dist/tengo/lib/exec.runenv.lib.tengo +18 -18
  21. package/dist/tengo/lib/exec.stream.lib.tengo +25 -25
  22. package/dist/tengo/lib/feats.lib.tengo +3 -3
  23. package/dist/tengo/lib/file.internal.lib.tengo +31 -31
  24. package/dist/tengo/lib/file.lib.tengo +29 -29
  25. package/dist/tengo/lib/ll.get-future-field-default.lib.tengo +137 -0
  26. package/dist/tengo/lib/ll.lib.tengo +129 -129
  27. package/dist/tengo/lib/maps.lib.tengo +38 -38
  28. package/dist/tengo/lib/objects.lib.tengo +6 -6
  29. package/dist/tengo/lib/oop.lib.tengo +11 -11
  30. package/dist/tengo/lib/path.lib.tengo +60 -60
  31. package/dist/tengo/lib/pframes.builder.lib.tengo +3 -3
  32. package/dist/tengo/lib/pframes.constants.lib.tengo +20 -20
  33. package/dist/tengo/lib/pframes.export-pcolumn.lib.tengo +5 -5
  34. package/dist/tengo/lib/pframes.lib.tengo +206 -198
  35. package/dist/tengo/lib/pframes.ll.lib.tengo +59 -59
  36. package/dist/tengo/lib/pframes.pcolumn.lib.tengo +18 -18
  37. package/dist/tengo/lib/pframes.remove-nulls.lib.tengo +36 -0
  38. package/dist/tengo/lib/pframes.spec.lib.tengo +83 -83
  39. package/dist/tengo/lib/pframes.util.lib.tengo +176 -176
  40. package/dist/tengo/lib/pframes.xsv-import-file.lib.tengo +160 -0
  41. package/dist/tengo/lib/pframes.xsv.lib.tengo +84 -167
  42. package/dist/tengo/lib/render.lib.tengo +100 -45
  43. package/dist/tengo/lib/sets.lib.tengo +44 -44
  44. package/dist/tengo/lib/slices.lib.tengo +126 -126
  45. package/dist/tengo/lib/smart.lib.tengo +654 -507
  46. package/dist/tengo/lib/test.lib.tengo +120 -120
  47. package/dist/tengo/lib/tpl.lib.tengo +206 -170
  48. package/dist/tengo/lib/tpl.state-await.lib.tengo +17 -17
  49. package/dist/tengo/lib/tpl.util.lib.tengo +5 -5
  50. package/dist/tengo/lib/units.lib.tengo +2 -2
  51. package/dist/tengo/lib/validation.lib.tengo +130 -130
  52. package/dist/tengo/lib/waiter.lib.tengo +13 -13
  53. package/dist/tengo/lib/workdir.lib.tengo +126 -126
  54. package/dist/tengo/lib/workdir.proc.lib.tengo +47 -47
  55. package/dist/tengo/lib/workdir.save.lib.tengo +53 -53
  56. package/dist/tengo/lib/workflow.bobject.lib.tengo +11 -11
  57. package/dist/tengo/lib/workflow.bquery.lib.tengo +40 -40
  58. package/dist/tengo/lib/workflow.constants.lib.tengo +1 -1
  59. package/dist/tengo/lib/workflow.context.lib.tengo +16 -16
  60. package/dist/tengo/lib/workflow.lib.tengo +76 -76
  61. package/dist/tengo/tpl/exec.R.create-renv.plj.gz +0 -0
  62. package/dist/tengo/tpl/exec.exec.plj.gz +0 -0
  63. package/dist/tengo/tpl/exec.monetization_to_json.plj.gz +0 -0
  64. package/dist/tengo/tpl/exec.python.create-venv.plj.gz +0 -0
  65. package/dist/tengo/tpl/exec.python.install-deps.plj.gz +0 -0
  66. package/dist/tengo/tpl/ll.get-field.plj.gz +0 -0
  67. package/dist/tengo/tpl/pframes.export-multiple-pcolumns.plj.gz +0 -0
  68. package/dist/tengo/tpl/pframes.export-pframe.plj.gz +0 -0
  69. package/dist/tengo/tpl/pframes.export-single-pcolumn.plj.gz +0 -0
  70. package/dist/tengo/tpl/pframes.import-dir.plj.gz +0 -0
  71. package/dist/tengo/tpl/pframes.process-pcolumn-data.plj.gz +0 -0
  72. package/dist/tengo/tpl/pframes.remove-nulls.plj.gz +0 -0
  73. package/dist/tengo/tpl/pframes.xsv-export-pframe.plj.gz +0 -0
  74. package/dist/tengo/tpl/pframes.xsv-import-if-not-null.plj.gz +0 -0
  75. package/dist/tengo/tpl/pframes.xsv-import-map.plj.gz +0 -0
  76. package/dist/tengo/tpl/waiter.waiter.plj.gz +0 -0
  77. package/dist/tengo/tpl/workdir.save.plj.gz +0 -0
  78. package/dist/tengo/tpl/workflow.build-ctx.plj.gz +0 -0
  79. package/package.json +2 -2
  80. package/dist/tengo/tpl/pframes.map-pframe.plj.gz +0 -0
@@ -1,14 +1,14 @@
1
- /* Templates/renderers utils */
1
+
2
2
 
3
3
  ll := import("@platforma-sdk/workflow-tengo:ll")
4
4
 
5
- // template field name in renderer resource
5
+
6
6
  TEMPLATE_FIELD := "template"
7
- // field name of a resource map with the inputs in renderer resource
7
+
8
8
  INPUTS_MAP_FIELD := "inputs"
9
- // prefix of output fields template results in renderer resource
9
+
10
10
  TEMPLATE_OUTPUT_PREFIX := "outputs/"
11
- // input field containing a map with resources to prepare for the body
11
+
12
12
  PREPARE_MAP_FIELD_NAME := "__prepare__"
13
13
 
14
14
  export ll.toStrict({
@@ -1,12 +1,12 @@
1
1
  ll := import("@platforma-sdk/workflow-tengo:ll")
2
2
 
3
3
  export ll.toStrict({
4
- // Base-2 size modifiers:
4
+
5
5
  KiB: 1024,
6
6
  MiB: 1024 * 1024,
7
7
  GiB: 1024 * 1024 * 1024,
8
8
 
9
- // Decimal modifiers:
9
+
10
10
  KB: 1000,
11
11
  MB: 1000000,
12
12
  GB: 1000000000
@@ -7,9 +7,9 @@ smart := import("@platforma-sdk/workflow-tengo:smart")
7
7
 
8
8
  json := import("json")
9
9
 
10
- //
11
- // Tools for implementing your own checks:
12
- //
10
+
11
+
12
+
13
13
 
14
14
  _formatKeyPath := func(current, format, key) {
15
15
  if current == "" {
@@ -23,18 +23,18 @@ _formatKeyPath := func(current, format, key) {
23
23
  return fmt.sprintf(format, current, key)
24
24
  }
25
25
 
26
- /**
27
- * Validation success result.
28
- */
26
+
27
+
28
+
29
29
  success := { result: true }
30
30
 
31
- /**
32
- * Validation failure result with a message.
33
- *
34
- * @param keyPath: string - the current stack state.
35
- * @param msg: string - the failure message.
36
- * @param args: ...any - additional arguments for the message.
37
- */
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
38
  fail := func(keyPath, msg, ...args) {
39
39
  return {
40
40
  result: false,
@@ -46,23 +46,23 @@ isSuccess := func(r) {
46
46
  return r.result == true
47
47
  }
48
48
 
49
- /**
50
- * Returns true if the validation failed.
51
- *
52
- * @param r: either fail or success.
53
- */
49
+
50
+
51
+
52
+
53
+
54
54
  isFail := func(r) {
55
55
  return r.result == false
56
56
  }
57
57
 
58
- /**
59
- * Checks a condition and returns success or failure.
60
- *
61
- * @param condition: bool - the condition to check.
62
- * @param stack: any - the current stack state.
63
- * @param msg: string - the failure message if the condition is false.
64
- * @param args: variadic any - additional arguments for the message.
65
- */
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
66
  check := func(condition, keyPath, msg, ...args) {
67
67
  if condition {
68
68
  return success
@@ -71,17 +71,17 @@ check := func(condition, keyPath, msg, ...args) {
71
71
  return fail(keyPath, msg, args...)
72
72
  }
73
73
 
74
- //
75
- // Validation:
76
- //
77
-
78
- /**
79
- * Validates JSON types based on tags when the schema is a string.
80
- *
81
- * @param js: any - the JSON to validate.
82
- * @param tags: { key: string, tags: []tag } - the tags to validate against.
83
- * @param stack: ...any - the current stack state.
84
- */
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
85
  _validateTypes := func(js, tags, keyPath, ...stack) {
86
86
  k := tags.key
87
87
 
@@ -125,12 +125,12 @@ _validateTypes := func(js, tags, keyPath, ...stack) {
125
125
  return fail(keyPath, "js %q is not one of a type: %s", js, tags.key)
126
126
  }
127
127
 
128
- /**
129
- * Parses JSON tags from a string rule.
130
- *
131
- * @param rule: string - a key with tags, e.g. "any,type=string,regex=abc.*"
132
- * @return parsedRule: { key: string, tags: map } - the key and tags parsed from the rule.
133
- */
128
+
129
+
130
+
131
+
132
+
133
+
134
134
  _parseTags := func(rule) {
135
135
  tagsKV := text.split(rule, ",")
136
136
  key := tagsKV[0]
@@ -153,14 +153,14 @@ _parseTags := func(rule) {
153
153
  })
154
154
  }
155
155
 
156
- /**
157
- * Validates JSON against a schema.
158
- *
159
- * @param js: any - the JSON to validate.
160
- * @param schema: any - the schema to validate against.
161
- * @param stack: ...any - the current stack state.
162
- * @return either fail or success
163
- */
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
164
  _validateJson := func(js, schema, keyPath, ...stack) {
165
165
  if is_undefined(schema) {
166
166
  if len(stack) == 0 {
@@ -170,8 +170,8 @@ _validateJson := func(js, schema, keyPath, ...stack) {
170
170
  return fail(keyPath, "key is not defined by schema, but exists in the JSON. Validated item: %#v", stack[0])
171
171
  }
172
172
 
173
- // if the schema is a string, then
174
- // we check the predefined type.
173
+
174
+
175
175
  if is_string(schema) {
176
176
  if schema == "any" {
177
177
  return success
@@ -181,16 +181,16 @@ _validateJson := func(js, schema, keyPath, ...stack) {
181
181
  return _validateTypes(js, tags, keyPath, stack...)
182
182
  }
183
183
 
184
- // if the schema is a function, call it
185
- // with the element and the path of how we
186
- // got this element, i.e. recursion history.
184
+
185
+
186
+
187
187
  if is_callable(schema) {
188
188
  return schema(js, keyPath, stack)
189
189
  }
190
190
 
191
- // if the schema is an array with "or" at the beginning,
192
- // we should check if the element is succeed with
193
- // any of the following elements.
191
+
192
+
193
+
194
194
  if is_array(schema) && len(schema) > 0 && schema[0] == "or" {
195
195
  for i, elem in schema[1:] {
196
196
  r := _validateJson(js, elem, keyPath, stack...)
@@ -202,9 +202,9 @@ _validateJson := func(js, schema, keyPath, ...stack) {
202
202
  return fail(keyPath, "js %q does not fit any of the following rules: %q", js, schema)
203
203
  }
204
204
 
205
- // if the schema is an array, then check that every
206
- // element of the json has the schema that is the first element
207
- // of the schema.
205
+
206
+
207
+
208
208
  if is_array(schema) {
209
209
  if !is_array(js) {
210
210
  return fail(keyPath, "js %q must be array", js)
@@ -221,19 +221,19 @@ _validateJson := func(js, schema, keyPath, ...stack) {
221
221
  return success
222
222
  }
223
223
 
224
- // only map left, since schema can't be undefined
225
- // if the schema is a map, check that every key
226
- // in json-object is in the schema and vice-versa,
227
- // unless there are tags "any" or "omitempty".
224
+
225
+
226
+
227
+
228
228
  if !ll.isMap(js) {
229
229
  return fail(keyPath, "js %#v must be map", js)
230
230
  }
231
231
 
232
- // schema.key -> tags
232
+
233
233
  schemaTags := {}
234
- // schema.key -> rule
234
+
235
235
  schemaRules := {}
236
- // js padded with all keys from schema
236
+
237
237
  jsFull := {}
238
238
 
239
239
  for k, v in schema {
@@ -243,7 +243,7 @@ _validateJson := func(js, schema, keyPath, ...stack) {
243
243
  jsFull[p.key] = undefined
244
244
  }
245
245
 
246
- // tags that should be applied to all elements
246
+
247
247
  any := schemaTags["any"]
248
248
  if !is_undefined(any) {
249
249
  if is_undefined(jsFull["any"]) { // in case actual object has field named "any"
@@ -262,7 +262,7 @@ _validateJson := func(js, schema, keyPath, ...stack) {
262
262
  }
263
263
  }
264
264
 
265
- // transferring fields from input map into padded map
265
+
266
266
  for k, v in js {
267
267
  jsFull[k] = v
268
268
  }
@@ -284,7 +284,7 @@ _validateJson := func(js, schema, keyPath, ...stack) {
284
284
  continue
285
285
  }
286
286
 
287
- // tags for the key
287
+
288
288
  key := schemaTags[_key]
289
289
 
290
290
  if is_undefined(key) {
@@ -318,51 +318,51 @@ _validateJson := func(js, schema, keyPath, ...stack) {
318
318
  return success
319
319
  }
320
320
 
321
- /**
322
- * Checks if the given JSON conforms to the given schema.
323
- *
324
- * @param js: any - the JSON to check.
325
- * @param schema: any - the schema to check against.
326
- * @return either fail or success
327
- */
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
328
  checkJson := func(js, schema) {
329
329
  return _validateJson(js, schema, "")
330
330
  }
331
331
 
332
- /**
333
- * Checks if the given JSON is valid according to the given schema.
334
- *
335
- * @param js: any - the JSON to check.
336
- * @param schema: any - the schema to check against.
337
- * @return result: bool - the result of the validation (true/false).
338
- */
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
339
  isValid := func(js, schema) {
340
340
  return _validateJson(js, schema, "").result
341
341
  }
342
342
 
343
- /**
344
- * Alias to ll.assert just for usage convenience
345
- */
343
+
344
+
345
+
346
346
  assert := func(condition, msg, ...args) {
347
347
  ll.assert(condition, msg, args...)
348
348
  }
349
349
 
350
- /**
351
- * Asserts that a given variable conforms to a given schema.
352
- *
353
- * Schema field value examples:
354
- * - for scalar type checks:
355
- * "string", "number", "char", "bytes", "bool" to check presence of value of given type
356
- * "null" - value must be undefined
357
- * "any" - any value is accepted (even undefined)
358
- * ["or", "string", "number"] - value must be string or number
359
- * - for arrays: ["string"], ["number"], ... (any valid scalar type)
360
- * - for maps: {"name": "string", "age": "number"} - make sure <value> is map with "name" and "age" keys with given value types.
361
- *
362
- * @param value: any - the value to check.
363
- * @param schema: any - the schema to assert against (see comments above)
364
- * @param failMsg: string - optional parameter with custom message to be printed on validation error
365
- */
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
366
  assertType := func(value, schema, ...failMsg) {
367
367
  r := _validateJson(value, schema, "")
368
368
 
@@ -376,22 +376,22 @@ assertType := func(value, schema, ...failMsg) {
376
376
  }
377
377
  }
378
378
 
379
- /**
380
- * Alias to 'assertType' for backward compatibility
381
- */
379
+
380
+
381
+
382
382
  assertJsonSchema := func(js, schema, ...failMsg) {
383
383
  assertType(js, schema, failMsg...)
384
384
  }
385
385
 
386
- //
387
- // Domain-specific schemas and checks:
388
- //
389
386
 
390
- /**
391
- * Checks if the given element is a resource.
392
- *
393
- * @param options: object - resource validation options
394
- */
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
395
  resource := func(...args) {
396
396
 
397
397
  ops := {}
@@ -428,30 +428,30 @@ resource := func(...args) {
428
428
  return checker
429
429
  }
430
430
 
431
- /**
432
- * Checks if the given element is a resource with specified type.
433
- *
434
- * @param rt: ResourceType - desired resource type
435
- */
431
+
432
+
433
+
434
+
435
+
436
436
  resourceType := func(rt) {
437
437
  return func(elem, keyPath, stack) {
438
438
  return check(smart.isResource(elem) && elem.info().Type.Name == rt.Name, keyPath, "the element " + elem + " must be a resource")
439
439
  }
440
440
  }
441
441
 
442
- /**
443
- * Checks if the given element is a reference.
444
- *
445
- * @param elem: any - the element to check.
446
- * @param stack: any - the current stack state.
447
- */
442
+
443
+
444
+
445
+
446
+
447
+
448
448
  reference := func(elem, keyPath, stack) {
449
449
  return check(smart.isReference(elem), keyPath, "the element " + elem + " must be a resource or a field")
450
450
  }
451
451
 
452
- /**
453
- * Schema for reference
454
- */
452
+
453
+
454
+
455
455
  refSchema := {
456
456
  blockId: `string`,
457
457
  name: `string`
@@ -6,25 +6,25 @@ assets := import("@platforma-sdk/workflow-tengo:assets")
6
6
 
7
7
  waiterTpl := assets.importTemplate("@platforma-sdk/workflow-tengo:waiter.waiter")
8
8
 
9
- /**
10
- * Create new waiter, that will wait for all resources given to wait() and pass <pass> to <output> afterwards.
11
- *
12
- * @param pass: smart.field | smart.resource - reference to something that should be passed to the output
13
- * once all waits get ready.
14
- */
9
+
10
+
11
+
12
+
13
+
14
+
15
15
  builder := func(pass) {
16
16
  self := undefined
17
17
 
18
- /** type: smart.reference[] */
18
+
19
19
  whatToWait := []
20
20
 
21
21
  self = ll.toStrict({
22
- /**
23
- * Wait for given reference to become ready.
24
- *
25
- * @param ref: smart.field | smart.resource - reference to resource to wait for ResourceReady
26
- * state before passing <pass> to the output of waiter
27
- */
22
+
23
+
24
+
25
+
26
+
27
+
28
28
  wait: func(ref) {
29
29
  validation.assertJsonSchema(ref, validation.reference, "waiter.builder.wait(ref): ref should be a reference to resource or field")
30
30
  whatToWait = append(whatToWait, ref)