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