@platforma-sdk/workflow-tengo 2.9.5 → 2.9.7

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 (64) hide show
  1. package/dist/tengo/lib/assets.lib.tengo +52 -52
  2. package/dist/tengo/lib/assets.swinfo.lib.tengo +45 -45
  3. package/dist/tengo/lib/constants.lib.tengo +32 -32
  4. package/dist/tengo/lib/exec.R.internal.lib.tengo +29 -29
  5. package/dist/tengo/lib/exec.R.lib.tengo +166 -166
  6. package/dist/tengo/lib/exec.constants.lib.tengo +4 -4
  7. package/dist/tengo/lib/exec.descriptor.lib.tengo +31 -31
  8. package/dist/tengo/lib/exec.internal.lib.tengo +297 -297
  9. package/dist/tengo/lib/exec.lib.tengo +815 -815
  10. package/dist/tengo/lib/exec.monetization.lib.tengo +130 -130
  11. package/dist/tengo/lib/exec.package.lib.tengo +212 -212
  12. package/dist/tengo/lib/exec.python.internal.lib.tengo +6 -6
  13. package/dist/tengo/lib/exec.python.lib.tengo +146 -146
  14. package/dist/tengo/lib/exec.runcmd.lib.tengo +371 -371
  15. package/dist/tengo/lib/exec.runenv.lib.tengo +92 -92
  16. package/dist/tengo/lib/exec.stream.lib.tengo +40 -40
  17. package/dist/tengo/lib/file.internal.lib.tengo +77 -77
  18. package/dist/tengo/lib/file.lib.tengo +57 -57
  19. package/dist/tengo/lib/ll.lib.tengo +244 -244
  20. package/dist/tengo/lib/maps.lib.tengo +152 -152
  21. package/dist/tengo/lib/objects.lib.tengo +13 -13
  22. package/dist/tengo/lib/oop.lib.tengo +19 -19
  23. package/dist/tengo/lib/path.lib.tengo +125 -125
  24. package/dist/tengo/lib/pframes.constants.lib.tengo +28 -28
  25. package/dist/tengo/lib/pframes.export-pcolumn.lib.tengo +33 -33
  26. package/dist/tengo/lib/pframes.lib.tengo +43 -43
  27. package/dist/tengo/lib/pframes.ll.lib.tengo +72 -72
  28. package/dist/tengo/lib/pframes.pcolumn.lib.tengo +49 -49
  29. package/dist/tengo/lib/pframes.spec.lib.tengo +96 -96
  30. package/dist/tengo/lib/pframes.util.lib.tengo +288 -288
  31. package/dist/tengo/lib/pframes.xsv.lib.tengo +272 -272
  32. package/dist/tengo/lib/render.lib.tengo +75 -75
  33. package/dist/tengo/lib/sets.lib.tengo +68 -68
  34. package/dist/tengo/lib/slices.lib.tengo +258 -155
  35. package/dist/tengo/lib/smart.lib.tengo +1069 -1069
  36. package/dist/tengo/lib/test.lib.tengo +161 -161
  37. package/dist/tengo/lib/tpl.lib.tengo +515 -515
  38. package/dist/tengo/lib/tpl.state-await.lib.tengo +240 -240
  39. package/dist/tengo/lib/tpl.util.lib.tengo +9 -9
  40. package/dist/tengo/lib/validation.lib.tengo +378 -378
  41. package/dist/tengo/lib/workdir.lib.tengo +331 -331
  42. package/dist/tengo/lib/workdir.proc.lib.tengo +144 -144
  43. package/dist/tengo/lib/workdir.save.lib.tengo +130 -130
  44. package/dist/tengo/lib/workflow.bobject.lib.tengo +26 -26
  45. package/dist/tengo/lib/workflow.bquery.lib.tengo +165 -165
  46. package/dist/tengo/lib/workflow.constants.lib.tengo +2 -2
  47. package/dist/tengo/lib/workflow.context.lib.tengo +32 -32
  48. package/dist/tengo/lib/workflow.lib.tengo +206 -206
  49. package/dist/tengo/tpl/exec.R.create-renv.plj.gz +0 -0
  50. package/dist/tengo/tpl/exec.exec.plj.gz +0 -0
  51. package/dist/tengo/tpl/exec.monetization_to_json.plj.gz +0 -0
  52. package/dist/tengo/tpl/exec.python.create-venv.plj.gz +0 -0
  53. package/dist/tengo/tpl/exec.python.install-deps.plj.gz +0 -0
  54. package/dist/tengo/tpl/pframes.aggregate.plj.gz +0 -0
  55. package/dist/tengo/tpl/pframes.export-multiple-pcolumns.plj.gz +0 -0
  56. package/dist/tengo/tpl/pframes.export-pframe.plj.gz +0 -0
  57. package/dist/tengo/tpl/pframes.export-single-pcolumn.plj.gz +0 -0
  58. package/dist/tengo/tpl/pframes.import-dir.plj.gz +0 -0
  59. package/dist/tengo/tpl/pframes.map-pframe.plj.gz +0 -0
  60. package/dist/tengo/tpl/pframes.xsv-export-pframe.plj.gz +0 -0
  61. package/dist/tengo/tpl/pframes.xsv-import-map.plj.gz +0 -0
  62. package/dist/tengo/tpl/workdir.save.plj.gz +0 -0
  63. package/dist/tengo/tpl/workflow.build-ctx.plj.gz +0 -0
  64. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
-
2
-
3
-
1
+ /*
2
+ * Library provides development kit for workflows
3
+ */
4
4
 
5
5
  tx := import("tx")
6
6
  ll := import("@platforma-sdk/workflow-tengo:ll")
@@ -17,281 +17,281 @@ bobject := import("@platforma-sdk/workflow-tengo:workflow.bobject")
17
17
  bquery := import("@platforma-sdk/workflow-tengo:workflow.bquery")
18
18
 
19
19
 
20
-
20
+ // instance of this
21
21
  self := import("@platforma-sdk/workflow-tengo:tpl")
22
22
 
23
-
23
+ // renderer's output field storing a map with the results
24
24
  _RESULTS_FIELD_NAME := "result"
25
25
 
26
-
26
+ // renderer's inputs map field with the context resource
27
27
  _INPUT_CONTEXT_FIELD_NAME := "context"
28
28
 
29
-
29
+ // renderer's output field with the context resource
30
30
  _OUTPUT_CONTEXT_FIELD_NAME := "context"
31
31
 
32
-
33
-
32
+ // a field name prefix used in the renderer's inputs map fields
33
+ // that store prepared resources (aka requested in the 'prepare()' method)
34
34
  _PREPARED_INPUTS_PREFIX := "prepared/"
35
35
 
36
36
 
37
-
38
-
39
-
37
+ // define outputs as we know them
38
+ // this is important to unlock 'prepare' functionality
39
+ // as workflow is an eph template
40
40
  self.defineOutputs([_RESULTS_FIELD_NAME, _OUTPUT_CONTEXT_FIELD_NAME])
41
41
 
42
42
  _isProduction := func() {
43
-
44
- return self.rawInputs().isProduction.getValueAsJson() == true
43
+ // using low level api to avoid unnecessary unmarshalling etc
44
+ return self.rawInputs().isProduction.getValueAsJson() == true
45
45
  }
46
46
 
47
47
  _isStaging := func() {
48
- return !_isProduction()
48
+ return !_isProduction()
49
49
  }
50
50
 
51
-
52
-
51
+ // register standard inputs preprocessors [now added by default for all templates]
52
+ // self.registerUnmarshaller(bquery.resultUnmarshaller())
53
53
 
54
54
  _args := undefined
55
55
 
56
-
57
-
58
-
56
+ /**
57
+ * Block arguments map
58
+ */
59
59
  args := func() {
60
- if is_undefined(_args) {
61
-
62
- inputs := self.inputs()
63
-
64
-
65
- _args = inputs.args
66
- if is_undefined(_args) || smart.isReference(_args) {
67
- ll.panic("Unexpected args type: %v", _args)
68
- }
69
-
70
-
71
- for k, v in inputs {
72
-
73
- if text.has_prefix(k, _PREPARED_INPUTS_PREFIX) {
74
-
75
- name := text.trim_prefix(k, _PREPARED_INPUTS_PREFIX)
76
-
77
- ll.assert(is_undefined(_args[name]), "prepare name is already in use in inputs: ", name)
78
-
79
- _args[name] = v
80
- }
81
- }
82
- }
83
- return _args
60
+ if is_undefined(_args) {
61
+ // template inputs
62
+ inputs := self.inputs()
63
+
64
+ // original args from inputs
65
+ _args = inputs.args
66
+ if is_undefined(_args) || smart.isReference(_args) {
67
+ ll.panic("Unexpected args type: %v", _args)
68
+ }
69
+
70
+ // add all prepared 'extra' inputs to the args
71
+ for k, v in inputs {
72
+ // those extra inputs are prefixed
73
+ if text.has_prefix(k, _PREPARED_INPUTS_PREFIX) {
74
+
75
+ name := text.trim_prefix(k, _PREPARED_INPUTS_PREFIX)
76
+
77
+ ll.assert(is_undefined(_args[name]), "prepare name is already in use in inputs: ", name)
78
+
79
+ _args[name] = v
80
+ }
81
+ }
82
+ }
83
+ return _args
84
84
  }
85
85
 
86
86
  _blockId := undefined
87
87
 
88
-
89
-
90
-
88
+ /**
89
+ * Id of this block
90
+ */
91
91
  blockId := func() {
92
- if _blockId == undefined {
93
- _blockId = self.inputs().blockId
94
- ll.assert(!is_undefined(_blockId), "block id is not set in workflow inputs")
95
- }
92
+ if _blockId == undefined {
93
+ _blockId = self.inputs().blockId
94
+ ll.assert(!is_undefined(_blockId), "block id is not set in workflow inputs")
95
+ }
96
96
 
97
- return _blockId
97
+ return _blockId
98
98
  }
99
99
 
100
100
  __parentContext := undefined
101
101
 
102
-
103
-
104
-
102
+ /**
103
+ * Parent context
104
+ */
105
105
  _parentContext := func() {
106
- if __parentContext == undefined {
107
- __parentContext = self.inputs()[_INPUT_CONTEXT_FIELD_NAME]
108
- if __parentContext == undefined {
109
- ll.panic("parent context is not set in inputs")
110
- }
111
- }
112
- return __parentContext
106
+ if __parentContext == undefined {
107
+ __parentContext = self.inputs()[_INPUT_CONTEXT_FIELD_NAME]
108
+ if __parentContext == undefined {
109
+ ll.panic("parent context is not set in inputs")
110
+ }
111
+ }
112
+ return __parentContext
113
113
  }
114
114
 
115
-
116
-
117
-
115
+ /**
116
+ * Utility function to build final template outputs given block results
117
+ */
118
118
  _buildOutputs := func(results) {
119
- ll.assert(ll.isMap(results), "expected to see map result from body function")
120
- ll.assert(
121
- sets.fromSlice(["outputs", "exports"]) == sets.fromMapKeys(results),
122
- "expected only results and exports in the returned map, found", sets.fromMapKeys(results)
123
- )
124
-
125
- ll.assert(!is_undefined(results.outputs), "outputs are not defined in the results")
126
- ll.assert(!is_undefined(results.exports), "exports are not defined in the results")
127
-
128
- ll.assert(ll.isMap(results.outputs), "expected a map in outputs returned from workflow.body")
129
- ll.assert(ll.isMap(results.exports), "expected a map in exports returned from workflow.body")
130
-
131
-
132
- o := results.outputs
133
-
134
- e := results.exports
135
-
136
-
137
- resBuilder := smart.mapBuilder()
138
- for name, value in o {
139
- ll.assert(!is_undefined(value), "value is undefined for output ", name)
140
- resBuilder.add(name, value)
141
- }
142
-
143
-
144
- eData := {}
145
- eData[constants.NO_PREFIX_EXPORT] = {}
146
-
147
- for name, value in e {
148
-
149
- if smart.isReference(value) {
150
- eData[name] = value
151
- continue
152
- }
153
-
154
-
155
- ll.assert(
156
- sets.fromSlice(["spec", "data"]) == sets.fromMapKeys(value),
157
- "expected spec and data export structure"
158
- )
159
-
160
- spec := value.spec
161
- ll.assert(!is_undefined(spec), "spec must be defined")
162
-
163
- if !smart.isReference(spec) {
164
- spec = bobject.createSpec(spec)
119
+ ll.assert(ll.isMap(results), "expected to see map result from body function")
120
+ ll.assert(
121
+ sets.fromSlice(["outputs", "exports"]) == sets.fromMapKeys(results),
122
+ "expected only results and exports in the returned map, found", sets.fromMapKeys(results)
123
+ )
124
+
125
+ ll.assert(!is_undefined(results.outputs), "outputs are not defined in the results")
126
+ ll.assert(!is_undefined(results.exports), "exports are not defined in the results")
127
+
128
+ ll.assert(ll.isMap(results.outputs), "expected a map in outputs returned from workflow.body")
129
+ ll.assert(ll.isMap(results.exports), "expected a map in exports returned from workflow.body")
130
+
131
+ // block outputs
132
+ o := results.outputs
133
+ // block exports
134
+ e := results.exports
135
+
136
+ // create results map
137
+ resBuilder := smart.mapBuilder()
138
+ for name, value in o {
139
+ ll.assert(!is_undefined(value), "value is undefined for output ", name)
140
+ resBuilder.add(name, value)
141
+ }
142
+
143
+ // data to pass to ctx builder template
144
+ eData := {}
145
+ eData[constants.NO_PREFIX_EXPORT] = {}
146
+
147
+ for name, value in e {
148
+ // pass resource to flatten in ctx builder
149
+ if smart.isReference(value) {
150
+ eData[name] = value
151
+ continue
152
+ }
153
+
154
+ // check that value has spec and data
155
+ ll.assert(
156
+ sets.fromSlice(["spec", "data"]) == sets.fromMapKeys(value),
157
+ "expected spec and data export structure"
158
+ )
159
+
160
+ spec := value.spec
161
+ ll.assert(!is_undefined(spec), "spec must be defined")
162
+
163
+ if !smart.isReference(spec) {
164
+ spec = bobject.createSpec(spec)
165
+ }
166
+ eData[constants.NO_PREFIX_EXPORT][name + ".spec"] = spec
167
+ eData[constants.NO_PREFIX_EXPORT][name + ".data"] = value.data
168
+ }
169
+
170
+ // create ctx and save exports
171
+ ctxBuilder := render.createEphemeral(
172
+ assets.importTemplate("@platforma-sdk/workflow-tengo:workflow.build-ctx"),
173
+ {
174
+ blockId: blockId(),
175
+ parentContext: _parentContext(),
176
+ data: eData
177
+ }
178
+ )
179
+
180
+ // final template outputs
181
+ tplOutputs := {}
182
+ tplOutputs[_RESULTS_FIELD_NAME] = resBuilder.build()
183
+ tplOutputs[_OUTPUT_CONTEXT_FIELD_NAME] = ctxBuilder.output("ctx")
184
+
185
+ return tplOutputs
165
186
  }
166
- eData[constants.NO_PREFIX_EXPORT][name + ".spec"] = spec
167
- eData[constants.NO_PREFIX_EXPORT][name + ".data"] = value.data
168
- }
169
-
170
-
171
- ctxBuilder := render.createEphemeral(
172
- assets.importTemplate("@platforma-sdk/workflow-tengo:workflow.build-ctx"),
173
- {
174
- blockId: blockId(),
175
- parentContext: _parentContext(),
176
- data: eData
177
- }
178
- )
179
-
180
-
181
- tplOutputs := {}
182
- tplOutputs[_RESULTS_FIELD_NAME] = resBuilder.build()
183
- tplOutputs[_OUTPUT_CONTEXT_FIELD_NAME] = ctxBuilder.output("ctx")
184
-
185
- return tplOutputs
186
- }
187
-
188
-
189
-
190
-
191
-
192
-
193
187
 
188
+ /**
189
+ * Query results pool.
190
+ *
191
+ * @param spec: query spec
192
+ * @return result: an array of {ref: spec: data:} objects (data will be absent if not requested)
193
+ */
194
194
  query := func(spec, ...options) {
195
- return bquery.create(spec, _parentContext(), options...)
195
+ return bquery.create(spec, _parentContext(), options...)
196
196
  }
197
197
 
198
-
199
-
200
-
201
-
202
-
203
-
198
+ /**
199
+ * Query results pool to find spec & data for a given ref.
200
+ *
201
+ * @param ref: a ref object ({blockId: name:})
202
+ * @return result: a {ref: spec: data:} object
203
+ */
204
204
  resolve := func(ref, ...options) {
205
- r := bquery.resolve(ref, _parentContext(), options...)
205
+ r := bquery.resolve(ref, _parentContext(), options...)
206
206
 
207
- return ll.toStrict(oop.inherit(r, {
208
- spec: r.getFutureInputField("spec"),
209
- data: r.getFutureInputField("data")
210
- }))
207
+ return ll.toStrict(oop.inherit(r, {
208
+ spec: r.getFutureInputField("spec"),
209
+ data: r.getFutureInputField("data")
210
+ }))
211
211
  }
212
212
 
213
213
 
214
-
214
+ // template for prerun
215
215
  _preRunTpl := undefined
216
216
 
217
-
218
-
219
-
220
-
221
-
222
-
217
+ /**
218
+ * Prepare additional resources for the workflow body. The body function of the workflow will be executed only when the references will be
219
+ * returned by the prepare method will ve resolved into a ready resources. The resulting resources will be passed as an input to the body function.
220
+ *
221
+ * @param cb: a callback function returning a map of references to be resolved
222
+ */
223
223
  prepare := func(cb) {
224
- self.prepare(func(_){
225
- raw := cb(args())
226
- prefixed := {}
227
-
228
- for k, v in raw {
229
- prefixed[_PREPARED_INPUTS_PREFIX + k] = v
230
- }
231
- return prefixed
232
- })
224
+ self.prepare(func(_){
225
+ raw := cb(args())
226
+ prefixed := {}
227
+ // mark prepared inputs
228
+ for k, v in raw {
229
+ prefixed[_PREPARED_INPUTS_PREFIX + k] = v
230
+ }
231
+ return prefixed
232
+ })
233
233
  }
234
234
 
235
-
236
-
237
-
235
+ /**
236
+ * Defines a pre run entry point for a current workflow
237
+ */
238
238
  setPreRun := func(tplId) {
239
- ll.assert(is_undefined(_preRunTpl), "pre run template is already set")
239
+ ll.assert(is_undefined(_preRunTpl), "pre run template is already set")
240
240
 
241
- ll.assert(!is_undefined(tplId), "prerun template is undefined")
242
- _preRunTpl = tplId
241
+ ll.assert(!is_undefined(tplId), "prerun template is undefined")
242
+ _preRunTpl = tplId
243
243
  }
244
244
 
245
-
246
-
247
-
245
+ /**
246
+ * Validate that arguments fulfil the desired schema
247
+ */
248
248
  validateArgs := func(argsSchema) {
249
- self.validateInputs({
250
- args: argsSchema
251
- })
249
+ self.validateInputs({
250
+ args: argsSchema
251
+ })
252
252
  }
253
253
 
254
-
255
-
256
-
254
+ /**
255
+ * Defines main entry point for current workflow
256
+ */
257
257
  body := func(bodyFn) {
258
258
 
259
- if _isProduction() {
259
+ if _isProduction() {
260
260
 
261
- self.body(func(_) {
261
+ self.body(func(_) {
262
262
 
263
- workflowInputArgs := args()
264
- result := bodyFn(workflowInputArgs)
265
-
266
- return _buildOutputs(result)
267
- })
268
-
269
- } else if !is_undefined(_preRunTpl) {
263
+ workflowInputArgs := args()
264
+ result := bodyFn(workflowInputArgs)
270
265
 
266
+ return _buildOutputs(result)
267
+ })
271
268
 
269
+ } else if !is_undefined(_preRunTpl) {
272
270
 
273
- self.delegate(_preRunTpl, { isProduction: true }, [_RESULTS_FIELD_NAME, _OUTPUT_CONTEXT_FIELD_NAME])
271
+ // staging; render pre-run template
274
272
 
275
- } else {
273
+ self.delegate(_preRunTpl, { isProduction: true }, [_RESULTS_FIELD_NAME, _OUTPUT_CONTEXT_FIELD_NAME])
276
274
 
275
+ } else {
277
276
 
277
+ // staging; pre-run template not specified; noop
278
278
 
279
- self.body(func(_) {
280
- return _buildOutputs({
281
- outputs: {},
282
- exports: {}
283
- })
284
- })
279
+ self.body(func(_) {
280
+ return _buildOutputs({
281
+ outputs: {},
282
+ exports: {}
283
+ })
284
+ })
285
285
 
286
- }
286
+ }
287
287
  }
288
288
 
289
289
  export ll.toStrict({
290
- query: query,
291
- resolve: resolve,
292
- prepare: prepare,
293
- body: body,
294
- setPreRun: setPreRun,
295
- blockId: blockId,
296
- validateArgs: validateArgs
290
+ query: query,
291
+ resolve: resolve,
292
+ prepare: prepare,
293
+ body: body,
294
+ setPreRun: setPreRun,
295
+ blockId: blockId,
296
+ validateArgs: validateArgs
297
297
  })
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/workflow-tengo",
3
- "version": "2.9.5",
3
+ "version": "2.9.7",
4
4
  "description": "Tengo SDK library",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "./dist/**/*"
17
17
  ],
18
18
  "dependencies": {
19
- "@milaboratories/software-pframes-conv": "2.1.4",
19
+ "@milaboratories/software-pframes-conv": "2.1.5",
20
20
  "@platforma-open/milaboratories.software-small-binaries": "^1.15.6"
21
21
  },
22
22
  "devDependencies": {