@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,15 +1,15 @@
1
- /**
2
- * Functions to work with blobs / files.
3
- *
4
- * Allowing to create resources to import files from configured storages
5
- * as well as creation of resources to facilitate file upload from the
6
- * users machine.
7
- *
8
- * This library exposes rather high level functions working with
9
- * ImportFileHandle, encoding user intent to import a file from a pl-wide
10
- * configured storage or to upload file from users side in a universal
11
- * string representation.
12
- */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
13
 
14
14
  ll := import("@platforma-sdk/workflow-tengo:ll")
15
15
  smart := import("@platforma-sdk/workflow-tengo:smart")
@@ -18,19 +18,19 @@ blobs := import("@platforma-sdk/workflow-tengo:file.internal")
18
18
 
19
19
  json := import("json")
20
20
 
21
- /**
22
- * Imports an external file into the workflow, either from pre-configured storage,
23
- * available from the pl instance, or from the client machine via upload.
24
- *
25
- * @param importFileHandle string a string file import handle, in most cases obtained via the
26
- * LS controller in UI
27
- *
28
- * @return a structure with two field references
29
- * {
30
- * file: field,
31
- * handle: field
32
- * }
33
- */
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
34
  importFile := func(importFileHandle) {
35
35
  validation.assertType(
36
36
  importFileHandle,
@@ -56,10 +56,10 @@ importFile := func(importFileHandle) {
56
56
  }
57
57
  }
58
58
 
59
- /**
60
- * Given a reference to the file, converts it into resource that can be
61
- * downloaded from the UI side.
62
- */
59
+
60
+
61
+
62
+
63
63
  exportFile := func(blob) {
64
64
  builder := smart.structBuilder(blobs.RTYPE_BLOB_DOWNLOAD)
65
65
 
@@ -0,0 +1,137 @@
1
+ tx := import("tx")
2
+ plapi := import("plapi")
3
+ fmt := import("fmt")
4
+ json := import("json")
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+ isResourceId := func(value) {
13
+ return is_int(value)
14
+ }
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+ isFieldId := func(value) {
23
+ return plapi.isStrictMap(value) &&
24
+ plapi.mapHasKey(value, "ResourceID") &&
25
+ plapi.mapHasKey(value, "Name")
26
+ }
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+ getFutureFieldWithDefault := func(from, name, fieldType, isEph, ...options) {
40
+
41
+ fromIsResourceId := isResourceId(from)
42
+ fromIsFieldId := isFieldId(from)
43
+
44
+ if !fromIsResourceId && !fromIsFieldId {
45
+ txt := fmt.sprintf("'from' must be either a resource ID or a field ID, got: %#v", from)
46
+ plapi.print(txt)
47
+ plapi.setTemplateError(txt)
48
+ return 0
49
+ }
50
+
51
+ if len(options) > 1 {
52
+ txt := fmt.sprintf("expected at most 1 option, got: %d", len(options))
53
+ plapi.print(txt)
54
+ plapi.setTemplateError(txt)
55
+ return 0
56
+ }
57
+
58
+
59
+ defaultValue := 0
60
+ if len(options) == 1 {
61
+ defaultValue = options[0]
62
+ } else {
63
+ defaultValue = tx.createValue("Null", "1", "")
64
+ }
65
+
66
+
67
+ tplId := plapi.getTemplateId("@platforma-sdk/workflow-tengo:ll.get-field")
68
+
69
+
70
+ tplResource := 0
71
+ if isEph {
72
+ tplResource = tx.createEphemeral("EphRenderTemplate", "1")
73
+ } else {
74
+ tplResource = tx.createStruct("RenderTemplate", "1")
75
+ }
76
+
77
+ templateFieldId := plapi.newFieldID(tplResource, "template")
78
+ tx.createField(templateFieldId, "input")
79
+ tx.setFieldToResource(templateFieldId, tplId)
80
+
81
+
82
+ inputsMapResource := 0
83
+ if isEph {
84
+ inputsMapResource = tx.createEphemeral("std/map", "1")
85
+ } else {
86
+ inputsMapResource = tx.createStruct("std/map", "1")
87
+ }
88
+
89
+ resourceFieldId := plapi.newFieldID(inputsMapResource, "resource")
90
+ tx.createField(resourceFieldId, "input")
91
+
92
+ fieldNameFieldId := plapi.newFieldID(inputsMapResource, "fieldName")
93
+ tx.createField(fieldNameFieldId, "input")
94
+
95
+ fieldTypeFieldId := plapi.newFieldID(inputsMapResource, "fieldType")
96
+ tx.createField(fieldTypeFieldId, "input")
97
+
98
+ defaultValueFieldId := plapi.newFieldID(inputsMapResource, "defaultValue")
99
+ tx.createField(defaultValueFieldId, "input")
100
+
101
+ if fromIsResourceId {
102
+ tx.setFieldToResource(resourceFieldId, from)
103
+ } else {
104
+ tx.setFieldToField(resourceFieldId, from)
105
+ }
106
+
107
+ fieldNameResource := tx.createValue("json/object", "1", json.encode(name))
108
+ tx.setFieldToResource(fieldNameFieldId, fieldNameResource)
109
+
110
+ fieldTypeResource := tx.createValue("json/object", "1", json.encode(fieldType))
111
+ tx.setFieldToResource(fieldTypeFieldId, fieldTypeResource)
112
+
113
+ if isResourceId(defaultValue) {
114
+ tx.setFieldToResource(defaultValueFieldId, defaultValue)
115
+ } else {
116
+ tx.setFieldToField(defaultValueFieldId, defaultValue)
117
+ }
118
+
119
+ tx.lockInputs(inputsMapResource)
120
+
121
+ inputsMapFieldId := plapi.newFieldID(tplResource, "inputs")
122
+ tx.createField(inputsMapFieldId, "input")
123
+ tx.setFieldToResource(inputsMapFieldId, inputsMapResource)
124
+
125
+ tx.lockInputs(tplResource)
126
+
127
+ resultFieldId := plapi.newFieldID(tplResource, "outputs/result")
128
+ tx.createField(resultFieldId, "output")
129
+
130
+ tx.lockOutputs(tplResource)
131
+
132
+ return resultFieldId
133
+ }
134
+
135
+ export {
136
+ getFutureFieldWithDefault: getFutureFieldWithDefault
137
+ }
@@ -1,66 +1,66 @@
1
- /* Low level pl API */
1
+
2
2
 
3
3
  plapi := import("plapi")
4
4
  fmt := import("fmt")
5
5
  log := import("log")
6
6
  text := import("text")
7
7
 
8
- /**
9
- * Prints message to the pl log
10
- */
8
+
9
+
10
+
11
11
  print := func(txt, ...args) {
12
12
  plapi.print(txt, args...)
13
13
  }
14
14
 
15
- /**
16
- * Panics in a template, prints the error and
17
- * stops the execution of the template.
18
- * After that, the controller will set errors to outputs.
19
- */
15
+
16
+
17
+
18
+
19
+
20
20
  panic := func(msg, ...args) {
21
21
  txt := fmt.sprintf(msg, args...)
22
22
  plapi.print(txt)
23
23
 
24
- // next statement actually terminates the execution
24
+
25
25
  plapi.setTemplateError(txt)
26
26
  }
27
27
 
28
- /**
29
- * Asserts a given condition and panics if it is not met
30
- */
28
+
29
+
30
+
31
31
  assert := func(condition, msg, ...args) {
32
32
  if !condition {
33
33
  panic("assertion error: condition failed: "+msg, args...)
34
34
  }
35
35
  }
36
36
 
37
- /**
38
- * Checks whether the given object is a strict map
39
- *
40
- * @param obj any
41
- * @return strict: bool - whether obj is a 'strict' map
42
- */
37
+
38
+
39
+
40
+
41
+
42
+
43
43
  isStrict := func(obj) {
44
44
  return plapi.isStrictMap(obj)
45
45
  }
46
46
 
47
- /**
48
- * Checks whether the given object is a map, a strict map or an immutable map.
49
- *
50
- * @param obj any
51
- * @return bool whether obj is any kind of map object (map/immutable map/strict map)
52
- */
47
+
48
+
49
+
50
+
51
+
52
+
53
53
  isMap := func(obj) {
54
54
  return is_map(obj) || is_immutable_map(obj) || isStrict(obj)
55
55
  }
56
56
 
57
- /**
58
- * Converts 'strict' map into a normal one
59
- *
60
- * @param r: map|strictMap (will panic if not)
61
- *
62
- * @return map: std map
63
- */
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
64
  fromStrict := func(r) {
65
65
  if is_map(r) {
66
66
  return r
@@ -73,12 +73,12 @@ fromStrict := func(r) {
73
73
  return plapi.strictToMap(r)
74
74
  }
75
75
 
76
- /**
77
- * If input is a strict map, converts it to a normal one, otherwise returns the object as is
78
- *
79
- * @param r: any object (possible strict map)
80
- * @return map: tengo object
81
- */
76
+
77
+
78
+
79
+
80
+
81
+
82
82
  ensureNonStrict := func(r) {
83
83
  if isStrict(r) {
84
84
  return fromStrict(r)
@@ -87,15 +87,15 @@ ensureNonStrict := func(r) {
87
87
  return r
88
88
  }
89
89
 
90
- /**
91
- * Converts map into a 'strict' map, which will panic on
92
- * access to non-existing elements.
93
- *
94
- * @param m: map|strictMap
95
- * @param recursive: boolean - convert also all child maps
96
- *
97
- * @return strict: strictMap
98
- */
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
99
  toStrict := func(v, ...recursive) {
100
100
  if len(recursive) > 0 && recursive[0] {
101
101
  if isMap(v) {
@@ -125,14 +125,14 @@ toStrict := func(v, ...recursive) {
125
125
  return plapi.mapToStrict(v)
126
126
  }
127
127
 
128
- /**
129
- * Safe way to check if method exists in a builtin module or a library
130
- *
131
- * @param module: module - builtin module or tengo library
132
- * @param methodName: string - name of a method to be checked
133
- *
134
- * @return bool - true when method exists, false otherwise
135
- */
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
136
  methodExists := func(module, methodName) {
137
137
  if isStrict(module) {
138
138
  if !is_callable(plapi.mapHasKey) {
@@ -154,9 +154,9 @@ methodExists := func(module, methodName) {
154
154
  return true
155
155
  }
156
156
 
157
- /**
158
- * Provides current API version available at runtime
159
- */
157
+
158
+
159
+
160
160
  apiVersion := func() {
161
161
  if !methodExists(plapi, "apiVersion") {
162
162
  return 0 // before we introduced apiVersion
@@ -165,16 +165,16 @@ apiVersion := func() {
165
165
  return plapi.apiVersion
166
166
  }
167
167
 
168
- /**
169
- * Creates a field Id struct from given resource id and field name
170
- */
168
+
169
+
170
+
171
171
  fieldId := func(resourceId, fieldName) {
172
172
  return plapi.newFieldID(resourceId, fieldName)
173
173
  }
174
174
 
175
- /**
176
- * Checks if <val> can be used as field ID
177
- */
175
+
176
+
177
+
178
178
  isFieldId := func(val) {
179
179
  if !isStrict(val) {
180
180
  return false
@@ -183,9 +183,9 @@ isFieldId := func(val) {
183
183
  return v["ResourceID"] != undefined && v["Name"] != undefined
184
184
  }
185
185
 
186
- /**
187
- * Converts reference ID (resource ID or field ID) to stable string representation, suitable for use as map keys
188
- */
186
+
187
+
188
+
189
189
  idToString := func(referenceID) {
190
190
  if isFieldId(referenceID) {
191
191
  return fmt.sprintf("0x%X/%s", referenceID.ResourceID, referenceID.Name)
@@ -196,99 +196,99 @@ idToString := func(referenceID) {
196
196
  panic("ll.idToString: <referenceID> cannot be used as resource or field ID")
197
197
  }
198
198
 
199
- /**
200
- * Returns current template renderer
201
- */
199
+
200
+
201
+
202
202
  getCurrentTemplateRenderer := func() {
203
203
  return plapi.getTemplate()
204
204
  }
205
205
 
206
- /**
207
- * @return isInit: bool - true when current template is initializing (executed for the first time)
208
- */
206
+
207
+
208
+
209
209
  isInitializing := func() {
210
210
  return plapi.isInit
211
211
  }
212
212
 
213
- /**
214
- * Get the list of executors available in current Platforma installation.
215
- *
216
- * @return executors: []string - list of executors, say ['executor', 'docker', ...]
217
- */
213
+
214
+
215
+
216
+
217
+
218
218
  getExecutorsList := func() {
219
219
  return plapi.getExecutors()
220
220
  }
221
221
 
222
- /**
223
- * Joins path elements into a single path.
224
- *
225
- * @param elems: ...string - any number of elements.
226
- */
222
+
223
+
224
+
225
+
226
+
227
227
  filepathJoin := func(...elems) {
228
228
  return plapi.filepathJoin(elems...)
229
229
  }
230
230
 
231
- /**
232
- * Like filepathJoin, joins elements to a single path,
233
- * but can be used safely in regexps.
234
- *
235
- * @param elems: ...string - any number of elements.
236
- */
231
+
232
+
233
+
234
+
235
+
236
+
237
237
  filepathRegexpJoin := func(...elems) {
238
238
  escapedSeparator := plapi.regexpQuoteMeta(plapi.osSeparator)
239
239
  return text.join(elems, escapedSeparator)
240
240
  }
241
241
 
242
- /**
243
- * Joins elements of the filepath and canonizes it, i.e.
244
- * semantically resolves ../ and ./ and changes slash
245
- * to a pathSeparator.
246
- *
247
- * @param elems: ...string - any number of elements.
248
- */
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
249
  filepathCanonize := func(...elem) {
250
250
  return plapi.filepathCanonize(elem...)
251
251
  }
252
252
 
253
- /**
254
- * Returns a path separator. "/" on Unix-like systems, "\\" on Windows.
255
- *
256
- * @return separator: string
257
- */
253
+
254
+
255
+
256
+
257
+
258
258
  pathSeparator := plapi.osSeparator
259
259
 
260
- /**
261
- * Parses URL and returns a structure containing separe parts of the URL.
262
- *
263
- * The general form represented is:
264
- *
265
- * [scheme:][//[userinfo@]host][/]path[?query][#fragment]
266
- *
267
- * URLs that do not start with a slash after the scheme are interpreted as:
268
- *
269
- * scheme:opaque[?query][#fragment]
270
- *
271
- * Returns the floowing structure:
272
- *
273
- * {
274
- * Scheme: string,
275
- * Host: string,
276
- * Port: number,
277
- * Path: string,
278
- * RawPath: string,
279
- * Query: string
280
- * }
281
- *
282
- * @param url: string with the url
283
- * @return url structure: (see above)
284
- */
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
285
  parseUrl := func(url) {
286
286
  return plapi.urlParse(url)
287
287
  }
288
288
 
289
- /**
290
- * Returns current execution context, which cab be used is a simple kv-store associated with the renderer instance.
291
- */
289
+
290
+
291
+
292
292
  getCtx := func() {
293
293
  return plapi.getCtx()
294
294
  }