@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
+ * A library that creates RunCommand resource.
3
+ */
4
4
 
5
5
  ll := import("@platforma-sdk/workflow-tengo:ll")
6
6
  maps := import("@platforma-sdk/workflow-tengo:maps")
@@ -17,385 +17,385 @@ _RTYPE_RUN_COMMAND_ARGS := { Name: "RunCommandArgs", Version: "1" }
17
17
  _RTYPE_RUN_COMMAND_OPTIONS := { Name: "run-command/options", Version: "1" }
18
18
  _RTYPE_RUN_COMMAND_REFS := { Name: "RunCommandRefs", Version: "1" }
19
19
 
20
-
21
-
22
-
23
-
24
-
20
+ /**
21
+ * Creates a simple argument for the command.
22
+ *
23
+ * @param argument: string - the argument to create.
24
+ */
25
25
  _createSimpleArg := func(argument) {
26
- return {
27
- type: constants.ARG_TYPE_STRING,
28
- value: argument
29
- }
26
+ return {
27
+ type: constants.ARG_TYPE_STRING,
28
+ value: argument
29
+ }
30
30
  }
31
31
 
32
-
33
-
34
-
35
-
36
-
32
+ /**
33
+ * @deprecated, use _createRenderedArg
34
+ * Creates 'variableRef' argument.
35
+ * @param argTpl: string - argument value in any form with variables inside (e.g. "file://{pkg}/some-file" or "o-{java}-o")
36
+ */
37
37
  _createVariableArg := func(argTpl) {
38
- return {
39
- type: constants.ARG_TYPE_VAR,
40
- value: argTpl
41
- }
38
+ return {
39
+ type: constants.ARG_TYPE_VAR,
40
+ value: argTpl
41
+ }
42
42
  }
43
43
 
44
-
45
-
46
-
47
-
48
-
49
-
50
-
44
+ /**
45
+ * Creates 'expressionRef' arguments
46
+ * @param argTpl: string - arguments value in any form with expressions inside, e.g.:
47
+ * - `–Xms{env.PL_EXEC_HARD_MEMORY_LIMIT_MB * 80 / 100}m`
48
+ * - `file://{pkg}/some-file`
49
+ * - `o-{java}-o`
50
+ */
51
51
  _createExpressionArg := func(argTpl) {
52
- return {
53
- type: constants.ARG_TYPE_EXPRESSION,
54
- value: argTpl
55
- }
52
+ return {
53
+ type: constants.ARG_TYPE_EXPRESSION,
54
+ value: argTpl
55
+ }
56
56
  }
57
57
 
58
-
59
-
60
-
61
-
62
-
63
-
58
+ /**
59
+ * Builder function for creating a RunCommand resource.
60
+ *
61
+ * @param workdir: string - the working directory for the command.
62
+ * @return builder - the builder object with methods for configuring and building the RunCommand resource.
63
+ */
64
64
  builder := func(workdir) {
65
- res := smart.ephemeralBuilder(_RTYPE_RUN_COMMAND)
66
- res.getField("workdirIn").set(workdir)
67
-
68
- self := undefined
69
-
70
- cmd := undefined
71
- args := []
72
- envs := {}
73
- queue := ""
74
- refs := {}
75
-
76
- substRules := {}
77
- hasPatternArgs := false // TODO: deprecated, remove after a month of expressionRefs in prod.
78
- hasExpressionArgs := false
79
- customPaths := []
80
-
81
- stdout := "stdout.txt"
82
- stderr := "stderr.txt"
83
- nErrorLines := 200
84
-
85
- self = ll.toStrict(oop.inherit(res, {
86
-
87
-
88
-
89
-
90
-
91
- cmd: func(commandName) {
92
- cmd = _createSimpleArg(commandName)
93
- return self
94
- },
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
- cmdVar: func(commandTpl) {
105
- cmd = _createVariableArg(commandTpl)
106
- hasPatternArgs = true
107
- return self
108
- },
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
- cmdExpression: func(commandTpl) {
119
- cmd = _createExpressionArg(commandTpl)
120
- hasExpressionArgs = true
121
- return self
122
- },
123
-
124
- cmdTyped: func(type, value) {
125
- ll.assert(slices.hasElement(constants.ARG_TYPES, type),
126
- "runcmd.builder().cmdTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
127
-
128
- if type == constants.ARG_TYPE_STRING {
129
- return self.cmd(value)
130
- } else if type == constants.ARG_TYPE_EXPRESSION {
131
- return self.cmdExpression(value)
132
- } else if type == constants.ARG_TYPE_VAR {
133
- return self.cmdVar(value)
134
- }
135
-
136
- ll.panic("runcmd.builder().cmdTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
137
- },
138
-
139
-
140
-
141
-
142
-
143
-
144
- arg: func(arg) {
145
- args = append(args, _createSimpleArg(arg))
146
- return self
147
- },
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
- argVar: func(argTpl) {
158
- args = append(args, _createVariableArg(argTpl))
159
- hasPatternArgs = true
160
- return self
161
- },
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
- argExpression: func(argTpl) {
172
- args = append(args, _createExpressionArg(argTpl))
173
- hasExpressionArgs = true
174
- return self
175
- },
176
-
177
- argTyped: func(type, value) {
178
- ll.assert(slices.hasElement(constants.ARG_TYPES, type),
179
- "runcmd.builder().argTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
180
-
181
- if type == constants.ARG_TYPE_STRING {
182
- return self.arg(value)
183
- } else if type == constants.ARG_TYPE_EXPRESSION {
184
- return self.argExpression(value)
185
- } else if type == constants.ARG_TYPE_VAR {
186
- return self.argVar(value)
187
- }
188
-
189
- ll.panic("runcmd.builder().argTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
190
- },
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
- ref: func(refKey, ref) {
199
- ll.assert(smart.isReference(ref),
200
- "runcmd.builder().ref() must be a reference (valid field or resource)")
201
-
202
- ll.assert(!maps.containsKey(refs, refKey),
203
- "attempt to override existing reference %q", refKey)
204
-
205
- refs[refKey] = ref
206
- return self
207
- },
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
- env: func(name, value) {
216
- envs[name] = value
217
- return self
218
- },
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
- envVar: func(name, valueTpl) {
228
- envs[name] = _createVariableArg(valueTpl)
229
- hasPatternArgs = true
230
- return self
231
- },
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
- envExpression: func(name, valueTpl) {
241
- envs[name] = _createExpressionArg(valueTpl)
242
- hasExpressionArgs = true
243
- return self
244
- },
245
-
246
- envTyped: func(name, type, value) {
247
- ll.assert(slices.hasElement(constants.ARG_TYPES, type),
248
- "runcmd.builder().envTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
249
-
250
- if type == constants.ARG_TYPE_STRING {
251
- return self.env(name, value)
252
- } else if type == constants.ARG_TYPE_EXPRESSION {
253
- return self.envExpression(name, value)
254
- } else if type == constants.ARG_TYPE_VAR {
255
- return self.envVar(name, value)
256
- }
257
-
258
- ll.panic("runcmd.builder().envTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
259
- },
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
- addToPath: func(type, value) {
268
- ll.assert(slices.hasElement(constants.ARG_TYPES, type),
269
- "runcmd.builder().addToPath: unknown type %s, expect: %v", type, constants.ARG_TYPES)
270
-
271
- if type == constants.ARG_TYPE_STRING {
272
- customPaths = append(customPaths, _createSimpleArg(value))
273
- } else if type == constants.ARG_TYPE_EXPRESSION {
274
- customPaths = append(customPaths, _createExpressionArg(value))
275
- hasExpressionArgs = true
276
- } else if type == constants.ARG_TYPE_VAR {
277
- customPaths = append(customPaths, _createVariableArg(value))
278
- hasPatternArgs = true
279
- } else {
280
- ll.panic("runcmd.builder().addToPath: unknown type %s, expect: %v", type, constants.ARG_TYPES)
281
- }
282
-
283
- return self
284
- },
285
-
286
-
287
-
288
-
289
-
290
-
291
-
292
-
293
- substitutionRule: func(varName, refKey) {
294
- substRules[varName] = refKey
295
- return self
296
- },
297
-
298
-
299
-
300
-
301
-
302
-
303
- substitutionRules: func(rules) {
304
- for k, v in rules {
305
- substRules[k] = v
306
- }
307
- return self
308
- },
309
-
310
-
311
-
312
-
313
-
314
-
315
- inQueue: func(queueName) {
316
- queue = queueName
317
- return self
318
- },
319
-
320
-
321
-
322
-
323
-
324
-
325
- stdout: func(fileName) {
326
- stdout = fileName
327
- return self
328
- },
329
-
330
-
331
-
332
-
333
-
334
-
335
- stderr: func(fileName) {
336
- stderr = fileName
337
- return self
338
- },
339
-
340
-
341
-
342
-
343
-
344
-
345
- nErrorLines: func(number) {
346
- nErrorLines = number
347
- return self
348
- },
349
-
350
-
351
-
352
-
353
-
354
-
355
- build: func() {
356
-
357
-
358
- ll.assert(!hasPatternArgs || len(substRules) != 0,
359
- "found pattern argument, but no substitution rules were set: hasPatternArgs: %v, substRules: %v, cmd: %v, args: %v, envs: %v",
360
- hasPatternArgs, substRules, cmd, args, envs)
361
- ll.assert(!hasExpressionArgs || desc.canBackendUseExpressions(),
362
- "runcmd.builder().build: expression arguments must be enabled only if platforma backend supports expressions, found: %v",
363
- hasExpressionArgs)
364
-
365
- refsRes := smart.createMapResourceWithType(_RTYPE_RUN_COMMAND_REFS, refs)
366
- self.getField("refs").set(refsRes)
367
-
368
- cmdRes := smart.createValueResource(_RTYPE_RUN_COMMAND_CMD, json.encode(cmd))
369
- self.getField("cmd").set(cmdRes)
370
-
371
- options := {
372
- queueName: queue,
373
- errorLines: nErrorLines,
374
- redirectStdout: stdout,
375
- redirectStderr: stderr,
376
- env: envs,
377
- additionalPaths: customPaths,
378
- substitutions: substRules
379
- }
380
-
381
- optionsRes := smart.createValueResource(_RTYPE_RUN_COMMAND_OPTIONS, json.encode(options))
382
- self.getField("options").set(optionsRes)
383
-
384
- argsRes := smart.createValueResource(_RTYPE_RUN_COMMAND_ARGS, json.encode(args))
385
- self.getField("args").set(argsRes)
386
-
387
- res := ll.toStrict(oop.inherit(self.lockAndBuild(), {
388
- "workdir": self.outputs().workdirOut,
389
- "options": options
390
- }))
391
-
392
- return res
393
- }
394
- }))
395
-
396
- return self
65
+ res := smart.ephemeralBuilder(_RTYPE_RUN_COMMAND)
66
+ res.getField("workdirIn").set(workdir)
67
+
68
+ self := undefined
69
+
70
+ cmd := undefined
71
+ args := []
72
+ envs := {}
73
+ queue := ""
74
+ refs := {}
75
+
76
+ substRules := {}
77
+ hasPatternArgs := false // TODO: deprecated, remove after a month of expressionRefs in prod.
78
+ hasExpressionArgs := false
79
+ customPaths := []
80
+
81
+ stdout := "stdout.txt"
82
+ stderr := "stderr.txt"
83
+ nErrorLines := 200
84
+
85
+ self = ll.toStrict(oop.inherit(res, {
86
+ /**
87
+ * Sets the command, e.g. /usr/bin/env or sh.
88
+ *
89
+ * @param commandName: string - the name of the command.
90
+ */
91
+ cmd: func(commandName) {
92
+ cmd = _createSimpleArg(commandName)
93
+ return self
94
+ },
95
+
96
+ /**
97
+ * Sets the command with variables inside to be rendered using rules
98
+ * from .substitutionRules().
99
+ *
100
+ * @param commandTpl: string - string with '{varName}' substitutions to be replaced with
101
+ * software paths. Replace rules are defined by .substitutionRule()
102
+ * and .substitutionRules(),
103
+ */
104
+ cmdVar: func(commandTpl) {
105
+ cmd = _createVariableArg(commandTpl)
106
+ hasPatternArgs = true
107
+ return self
108
+ },
109
+
110
+ /**
111
+ * Sets the command with expressions inside to be rendered using rules
112
+ * from .substitutionRules().
113
+ *
114
+ * @param commandTpl: string - string with '{any expression}' substitutions to be replaced with
115
+ * software paths. Replace rules are defined by .substitutionRule()
116
+ * and .substitutionRules(),
117
+ */
118
+ cmdExpression: func(commandTpl) {
119
+ cmd = _createExpressionArg(commandTpl)
120
+ hasExpressionArgs = true
121
+ return self
122
+ },
123
+
124
+ cmdTyped: func(type, value) {
125
+ ll.assert(slices.hasElement(constants.ARG_TYPES, type),
126
+ "runcmd.builder().cmdTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
127
+
128
+ if type == constants.ARG_TYPE_STRING {
129
+ return self.cmd(value)
130
+ } else if type == constants.ARG_TYPE_EXPRESSION {
131
+ return self.cmdExpression(value)
132
+ } else if type == constants.ARG_TYPE_VAR {
133
+ return self.cmdVar(value)
134
+ }
135
+
136
+ ll.panic("runcmd.builder().cmdTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
137
+ },
138
+
139
+ /**
140
+ * Adds an argument to the command.
141
+ *
142
+ * @param arg: string - the argument to add.
143
+ */
144
+ arg: func(arg) {
145
+ args = append(args, _createSimpleArg(arg))
146
+ return self
147
+ },
148
+
149
+ /**
150
+ * Adds an argument with variables inside to be rendered using rules
151
+ * from .substitutionRules().
152
+ *
153
+ * @param argTpl: string - string with '{varName}' substitutions to be replaced with
154
+ * software paths. Replace rules are defined by .substitutionRule()
155
+ * and .substitutionRules(),
156
+ */
157
+ argVar: func(argTpl) {
158
+ args = append(args, _createVariableArg(argTpl))
159
+ hasPatternArgs = true
160
+ return self
161
+ },
162
+
163
+ /**
164
+ * Adds an argument with variables inside to be rendered using rules
165
+ * from .substitutionRules().
166
+ *
167
+ * @param argTpl: string - string with '{expression}' substitutions to be replaced with
168
+ * expression value. Replace rules are defined by .substitutionRule()
169
+ * and .substitutionRules(),
170
+ */
171
+ argExpression: func(argTpl) {
172
+ args = append(args, _createExpressionArg(argTpl))
173
+ hasExpressionArgs = true
174
+ return self
175
+ },
176
+
177
+ argTyped: func(type, value) {
178
+ ll.assert(slices.hasElement(constants.ARG_TYPES, type),
179
+ "runcmd.builder().argTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
180
+
181
+ if type == constants.ARG_TYPE_STRING {
182
+ return self.arg(value)
183
+ } else if type == constants.ARG_TYPE_EXPRESSION {
184
+ return self.argExpression(value)
185
+ } else if type == constants.ARG_TYPE_VAR {
186
+ return self.argVar(value)
187
+ }
188
+
189
+ ll.panic("runcmd.builder().argTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
190
+ },
191
+
192
+ /**
193
+ * Adds a reference for using it in expressions next.
194
+ *
195
+ * @param refKey: string - the name of the ref
196
+ * @param ref: reference - a reference to the valid field or resource
197
+ */
198
+ ref: func(refKey, ref) {
199
+ ll.assert(smart.isReference(ref),
200
+ "runcmd.builder().ref() must be a reference (valid field or resource)")
201
+
202
+ ll.assert(!maps.containsKey(refs, refKey),
203
+ "attempt to override existing reference %q", refKey)
204
+
205
+ refs[refKey] = ref
206
+ return self
207
+ },
208
+
209
+ /**
210
+ * Sets an environment variable for the command.
211
+ *
212
+ * @param name: string - the name of the environment variable.
213
+ * @param value: string - the value of the environment variable.
214
+ */
215
+ env: func(name, value) {
216
+ envs[name] = value
217
+ return self
218
+ },
219
+
220
+ /**
221
+ * Sets environment variable with substitution inside value, to be rendered
222
+ * using rules from .substitutionRules().
223
+ *
224
+ * @param name: string - the name of the environment variable.
225
+ * @param valueTpl: string - the value of the environment variable.
226
+ */
227
+ envVar: func(name, valueTpl) {
228
+ envs[name] = _createVariableArg(valueTpl)
229
+ hasPatternArgs = true
230
+ return self
231
+ },
232
+
233
+ /**
234
+ * Sets environment variable with substitution inside value, to be rendered
235
+ * using rules from .substitutionRules().
236
+ *
237
+ * @param name: string - the name of the environment variable.
238
+ * @param valueTpl: string - the value of the environment variable.
239
+ */
240
+ envExpression: func(name, valueTpl) {
241
+ envs[name] = _createExpressionArg(valueTpl)
242
+ hasExpressionArgs = true
243
+ return self
244
+ },
245
+
246
+ envTyped: func(name, type, value) {
247
+ ll.assert(slices.hasElement(constants.ARG_TYPES, type),
248
+ "runcmd.builder().envTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
249
+
250
+ if type == constants.ARG_TYPE_STRING {
251
+ return self.env(name, value)
252
+ } else if type == constants.ARG_TYPE_EXPRESSION {
253
+ return self.envExpression(name, value)
254
+ } else if type == constants.ARG_TYPE_VAR {
255
+ return self.envVar(name, value)
256
+ }
257
+
258
+ ll.panic("runcmd.builder().envTyped: unknown type %s, expect: %v", type, constants.ARG_TYPES)
259
+ },
260
+
261
+ /*
262
+ * Patch 'PATH' environment variable, adding software path to it.
263
+ *
264
+ * @param type: constants.ARG_TYPES - whether Platforma Backend should try to substitute variables or expressions inside <value> on server side
265
+ * @param value: string - the value of the environment variable with variables to be replaced to software path.
266
+ */
267
+ addToPath: func(type, value) {
268
+ ll.assert(slices.hasElement(constants.ARG_TYPES, type),
269
+ "runcmd.builder().addToPath: unknown type %s, expect: %v", type, constants.ARG_TYPES)
270
+
271
+ if type == constants.ARG_TYPE_STRING {
272
+ customPaths = append(customPaths, _createSimpleArg(value))
273
+ } else if type == constants.ARG_TYPE_EXPRESSION {
274
+ customPaths = append(customPaths, _createExpressionArg(value))
275
+ hasExpressionArgs = true
276
+ } else if type == constants.ARG_TYPE_VAR {
277
+ customPaths = append(customPaths, _createVariableArg(value))
278
+ hasPatternArgs = true
279
+ } else {
280
+ ll.panic("runcmd.builder().addToPath: unknown type %s, expect: %v", type, constants.ARG_TYPES)
281
+ }
282
+
283
+ return self
284
+ },
285
+
286
+ /**
287
+ * Define substitution variable for software args.
288
+ *
289
+ * @param varName: string - variable to be substituted in arg value ("var1" would be
290
+ * substituted in place of {var1} of arg value)
291
+ * @param refKey: string - key of ref (added with .ref()) that points to installed software.
292
+ */
293
+ substitutionRule: func(varName, refKey) {
294
+ substRules[varName] = refKey
295
+ return self
296
+ },
297
+
298
+ /**
299
+ * Batched .substitutionRule() call (add several rules in single call)
300
+ *
301
+ * @param rules: map[string]string - <var name> -> <ref key> pairs to be added to substitution rules.
302
+ */
303
+ substitutionRules: func(rules) {
304
+ for k, v in rules {
305
+ substRules[k] = v
306
+ }
307
+ return self
308
+ },
309
+
310
+ /**
311
+ * Sets the queue name for the command.
312
+ *
313
+ * @param queueName: string - the name of the queue.
314
+ */
315
+ inQueue: func(queueName) {
316
+ queue = queueName
317
+ return self
318
+ },
319
+
320
+ /**
321
+ * Sets the stdout file name for the command.
322
+ *
323
+ * @param fileName: string - the name of the stdout file.
324
+ */
325
+ stdout: func(fileName) {
326
+ stdout = fileName
327
+ return self
328
+ },
329
+
330
+ /**
331
+ * Sets the stderr file name for the command.
332
+ *
333
+ * @param fileName: string - the name of the stderr file.
334
+ */
335
+ stderr: func(fileName) {
336
+ stderr = fileName
337
+ return self
338
+ },
339
+
340
+ /**
341
+ * Sets the number of error lines for the command.
342
+ *
343
+ * @param number: int - the number of error lines.
344
+ */
345
+ nErrorLines: func(number) {
346
+ nErrorLines = number
347
+ return self
348
+ },
349
+
350
+ /**
351
+ * Builds the RunCommand resource.
352
+ *
353
+ * @return object - the built RunCommand resource.
354
+ */
355
+ build: func() {
356
+ // TODO: add assertions about the state
357
+
358
+ ll.assert(!hasPatternArgs || len(substRules) != 0,
359
+ "found pattern argument, but no substitution rules were set: hasPatternArgs: %v, substRules: %v, cmd: %v, args: %v, envs: %v",
360
+ hasPatternArgs, substRules, cmd, args, envs)
361
+ ll.assert(!hasExpressionArgs || desc.canBackendUseExpressions(),
362
+ "runcmd.builder().build: expression arguments must be enabled only if platforma backend supports expressions, found: %v",
363
+ hasExpressionArgs)
364
+
365
+ refsRes := smart.createMapResourceWithType(_RTYPE_RUN_COMMAND_REFS, refs)
366
+ self.getField("refs").set(refsRes)
367
+
368
+ cmdRes := smart.createValueResource(_RTYPE_RUN_COMMAND_CMD, json.encode(cmd))
369
+ self.getField("cmd").set(cmdRes)
370
+
371
+ options := {
372
+ queueName: queue,
373
+ errorLines: nErrorLines,
374
+ redirectStdout: stdout,
375
+ redirectStderr: stderr,
376
+ env: envs,
377
+ additionalPaths: customPaths,
378
+ substitutions: substRules
379
+ }
380
+
381
+ optionsRes := smart.createValueResource(_RTYPE_RUN_COMMAND_OPTIONS, json.encode(options))
382
+ self.getField("options").set(optionsRes)
383
+
384
+ argsRes := smart.createValueResource(_RTYPE_RUN_COMMAND_ARGS, json.encode(args))
385
+ self.getField("args").set(argsRes)
386
+
387
+ res := ll.toStrict(oop.inherit(self.lockAndBuild(), {
388
+ "workdir": self.outputs().workdirOut,
389
+ "options": options
390
+ }))
391
+
392
+ return res
393
+ }
394
+ }))
395
+
396
+ return self
397
397
  }
398
398
 
399
399
  export ll.toStrict({
400
- builder: builder
400
+ builder: builder
401
401
  })