@platforma-sdk/workflow-tengo 2.14.0 → 2.15.1

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,24 +1,22 @@
1
- /**
2
- * Library providing xsv <> p-frames conversion utils.
3
- */
1
+
2
+
3
+
4
4
 
5
5
  validation := import("@platforma-sdk/workflow-tengo:validation")
6
6
  constants := import("@platforma-sdk/workflow-tengo:pframes.constants")
7
7
  objects := import("@platforma-sdk/workflow-tengo:objects")
8
8
  render := import("@platforma-sdk/workflow-tengo:render")
9
- exec := import("@platforma-sdk/workflow-tengo:exec")
10
- json := import("json")
11
- text := import("text")
9
+ maps := import("@platforma-sdk/workflow-tengo:maps")
12
10
  util := import("@platforma-sdk/workflow-tengo:pframes.util")
13
11
  ll := import("@platforma-sdk/workflow-tengo:ll")
14
12
  assets := import("@platforma-sdk/workflow-tengo:assets")
13
+ xsvIF := import("@platforma-sdk/workflow-tengo:pframes.xsv-import-file")
14
+
15
+ importXsvIfNullTpl := assets.importTemplate("@platforma-sdk/workflow-tengo:pframes.xsv-import-if-not-null")
16
+
17
+
15
18
 
16
- transposeXsvSw := assets.importSoftware("@platforma-open/milaboratories.software-small-binaries:table-converter")
17
- pfconvSw := assets.importSoftware("@milaboratories/software-pframes-conv:main")
18
19
 
19
- /**
20
- * Calculate axes spec from pfconv spec
21
- */
22
20
  getAxesSpec := func(spec) {
23
21
  axes := []
24
22
  for ax in spec.axes {
@@ -55,168 +53,87 @@ getColumnSpec := func(axesSpec, col) {
55
53
  return objects.deleteUndefined(spec)
56
54
  }
57
55
 
58
- /**
59
- * Imports xsv data into p-frame. The resulting map resource contains all columns specified in the params (column identifiers as
60
- * provided by the spec used as map keys). Resulting p-columns will be always single-partitioned at most.
61
- *
62
- * @param xsvFile: reference - a reference to a file
63
- * @param xsvType: string - either csv or tsv
64
- * @param spec: object - xsv conversion specification
65
- * @param ops: object - additional options
66
- * {
67
- * dataOnly: boolean - set to true to completely skip creation of specs
68
- * splitDataAndSpec: boolean - if true, resulting map will have nested structures,
69
- * with "spec" + "data" fields in nested maps
70
- * transpose: object - if specified, then the input table will be transposed
71
- * {
72
- * separator: string - (optional) use separator instead of inferring from the file extension
73
- * pAxisIdx: index - (optional) the index of the primary axis (column in the input xsv); default 0
74
- * pAxisName: string - (optional) the name of the primary axis (column name in the input xsv); default undefined
75
- * pAxisSearch: regex - (optional) the regex pattern of the name of the primary axis (column name in the input xsv); default undefined
76
- * pAxisNameOverride: string - (optional) override primary axis header in the output; default undefined
77
- * sAxisSearch: string - (optional) regex to filter secondary axis columns in the input table;
78
- * sAxisName: string - (optional) the name of the secondary axis (column name in the output xsv); default "Metric"
79
- * valueName: string - (optional) the name of the value column; default "Value"
80
- * separatorOverride: string - (optional) specify separator in the output (optional)
81
- * }
82
- * }
83
- * @return map: reference - a reference to a map resource storing imported data.
84
- */
85
- importFile := func(xsvFile, xsvType, spec, ...ops) {
86
- ll.assert(xsvType == "csv" || xsvType == "tsv", "expected one of [tsv, csv] types, found: " + xsvType)
87
56
 
88
- validation.assertType(spec, util.PFCONV_IMPORT_CFG_SCHEMA)
89
57
 
90
- xsvFileName := "file." + xsvType
91
58
 
92
- ops := renderOps({ dataOnly: false, splitDataAndSpec: false }, ops...)
93
59
 
94
- if ops.transpose != undefined {
95
60
 
96
- tops := ops.transpose
97
61
 
98
- transposedFileName := "fileTransposed." + xsvType
99
62
 
100
- // convert csv to p-frame and read resulting data
101
- transposeXsv := exec.builder().
102
- software(transposeXsvSw).
103
- printErrStreamToStdout().
104
- inLightQueue()
105
63
 
106
- if (tops.separator != undefined) {
107
- transposeXsv = transposeXsv.arg("-input-separator").arg(tops.separator)
108
- }
109
- if (tops.pAxisIdx != undefined) {
110
- transposeXsv = transposeXsv.arg("-sample-column-i").arg("" + tops.pAxisIdx) // always convert to string
111
- }
112
- if (tops.pAxisName != undefined) {
113
- transposeXsv = transposeXsv.arg("-sample-column-name").arg(tops.pAxisName)
114
- }
115
- if (tops.pAxisSearch != undefined) {
116
- transposeXsv = transposeXsv.arg("-sample-column-search").arg(tops.pAxisSearch)
117
- }
118
- if (tops.pAxisNameOverride != undefined) {
119
- transposeXsv = transposeXsv.arg("-sample-label").arg(tops.pAxisNameOverride)
120
- }
121
- if (tops.sAxisSearch != undefined) {
122
- transposeXsv = transposeXsv.arg("-metric-columns-search").arg(tops.sAxisSearch)
123
- }
124
- if (tops.sAxisName != undefined) {
125
- transposeXsv = transposeXsv.arg("-metric-label").arg(tops.sAxisName)
126
- }
127
- if (tops.valueName != undefined) {
128
- transposeXsv = transposeXsv.arg("-value-label").arg(tops.valueName)
129
- }
130
- if (tops.separatorOverride != undefined) {
131
- transposeXsv = transposeXsv.arg("-separator").arg(tops.separatorOverride)
132
- }
133
64
 
134
- transposeXsv = transposeXsv.
135
- arg(xsvFileName).
136
- arg(transposedFileName).
137
- addFile(xsvFileName, xsvFile).
138
- saveFile(transposedFileName).
139
- run()
140
65
 
141
- xsvFile = transposeXsv.getFile(transposedFileName)
142
- }
143
66
 
144
- // import p-frame from directory tpl
145
- importDirTpl := assets.importTemplate("@platforma-sdk/workflow-tengo:pframes.import-dir")
146
-
147
- // spec without any metadata (for caching purposes)
148
- pureSpec := util.purifySpec(spec)
149
-
150
- // convert csv to p-frame and read resulting data
151
- pfconv := exec.builder().
152
- software(pfconvSw).
153
- printErrStreamToStdout().
154
- inLightQueue().
155
- arg("importCsv").
156
- arg(xsvFileName).
157
- arg("-p").arg("spec.json").
158
- arg("-o").arg("out").
159
- addFile(xsvFileName, xsvFile).
160
- writeFile("spec.json", json.encode(pureSpec)).
161
- processWorkdir("pf", importDirTpl, pureSpec).
162
- run()
163
-
164
- // p-columns data
165
- pf := pfconv.getProcessorResult("pf")
166
- if ops.dataOnly {
167
- // @TODO discuss, as it changes the type of the return from map to object
168
- return pf
169
- }
170
67
 
171
- axesSpec := getAxesSpec(spec)
172
68
 
173
- result := {}
174
- for col in spec.columns {
175
- id := util.xsvColumnId(col)
176
69
 
177
- if ops.splitDataAndSpec {
178
- result[id] = {
179
- data: pf.getFutureInputField(id),
180
- spec: getColumnSpec(axesSpec, col)
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+ importFile := func(xsvFile, xsvType, spec, ...ops) {
85
+ ll.assert(xsvType == "csv" || xsvType == "tsv", "expected one of [tsv, csv] types, found: " + xsvType)
86
+
87
+ validation.assertType(spec, util.PFCONV_IMPORT_CFG_SCHEMA)
88
+
89
+ allowNullInput := false
90
+ if len(ops) > 0 {
91
+ allowNullInput = ops[0].allowNullInput
92
+ }
93
+
94
+ if allowNullInput {
95
+ return render.create(importXsvIfNullTpl, {
96
+ xsvFile: xsvFile,
97
+ params: {
98
+ xsvType: xsvType,
99
+ spec: spec,
100
+ ops: [maps.merge(ops[0], { allowNullInput: undefined })]
181
101
  }
182
- } else {
183
- result[id + ".data"] = pf.getFutureInputField(id)
184
- result[id + ".spec"] = getColumnSpec(axesSpec, col)
185
- }
102
+ }).output("result")
186
103
  }
187
104
 
188
- return result
105
+ return xsvIF.importFile(xsvFile, xsvType, spec, ops...)
189
106
  }
190
107
 
191
- /**
192
- * Imports a map with xsv files into a p-frame. The resulting map resource contains all columns specified in the params (column identifiers as
193
- * provided by the spec used as map keys). Resulting p-columns may be double-partitioned.
194
- *
195
- * @param xsvMap: reference - a reference to a p-column resource map with xsv files
196
- * @param xsvType: string - either csv or tsv
197
- * @param spec: object - xsv conversion specification
198
- * @param ops: object - additional options
199
- * {
200
- * dataOnly: boolean - set to true to completely skip creation of specs
201
- * splitDataAndSpec: boolean - if true, resulting map will have nested structures,
202
- * with "spec" + "data" fields in nested maps
203
- * additionalAxesSpec: AxisSpec[] - array of additional axes spec to prepend to
204
- * each column spec
205
- * transpose: object - if specified, then the input table will be transposed
206
- * {
207
- * separator: string - (optional) use separator instead of inferring from the file extension
208
- * pAxisIdx: index - (optional) the index of the primary axis (column in the input xsv); default 0
209
- * pAxisName: string - (optional) the name of the primary axis (column name in the input xsv); default undefined
210
- * pAxisSearch: regex - (optional) the regex pattern of the name of the primary axis (column name in the input xsv); default undefined
211
- * pAxisNameOverride: string - (optional) override primary axis header in the output; default undefined
212
- * sAxisSearch: string - (optional) regex to filter secondary axis columns in the input table;
213
- * sAxisName: string - (optional) the name of the secondary axis (column name in the output xsv); default "Metric"
214
- * valueName: string - (optional) the name of the value column; default "Value"
215
- * separatorOverride: string - (optional) specify separator in the output (optional)
216
- * }
217
- * }
218
- * @return map: reference - a reference to a map resource storing imported data.
219
- */
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
220
137
  importFileMap := func(xsvMap, xsvType, spec, ...ops) {
221
138
 
222
139
  importXsvMapTpl := assets.importTemplate("@platforma-sdk/workflow-tengo:pframes.xsv-import-map")
@@ -228,7 +145,7 @@ importFileMap := func(xsvMap, xsvType, spec, ...ops) {
228
145
  transpose: undefined
229
146
  }, ops...)
230
147
 
231
- // spec without any metadata (for caching purposes)
148
+
232
149
  decomposedSpec := util.decomposePfconvImportCfg(spec, { additionalAxesSpec: ops.additionalAxesSpec })
233
150
  pureSpec := decomposedSpec.purifiedCfg
234
151
  columnsSpec := decomposedSpec.columnsSpec
@@ -264,24 +181,24 @@ importFileMap := func(xsvMap, xsvType, spec, ...ops) {
264
181
  return result
265
182
  }
266
183
 
267
- /**
268
- * Export p-frame into xsv file
269
- *
270
- * @param pf: p-frame - a list of p-columns ({data, spec}) or a frame-like map of col.data col.spec entries
271
- * @param xsvType: string - "csv" or "tsv"
272
- * @param params: map - export params
273
- * @param ops: object - additional options
274
- * {
275
- * partitions: {axisIdx: [keys]} - map of partitions to export; if not specified, all data is exported
276
- * }
277
- */
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
278
195
  exportFrame := func(pf, xsvType, params, ...ops) {
279
196
  exportPfTpl := assets.importTemplate("@platforma-sdk/workflow-tengo:pframes.xsv-export-pframe")
280
197
 
281
198
  ops := renderOps({}, ops...)
282
199
 
283
200
  if is_array(pf) {
284
- // transform into .data .spec map
201
+
285
202
 
286
203
  pfm := {}
287
204
  i := 0
@@ -1,6 +1,6 @@
1
- /*
2
- * Create renderer objects to render templates from the code
3
- */
1
+
2
+
3
+
4
4
 
5
5
  ll := import("@platforma-sdk/workflow-tengo:ll")
6
6
  assets := import("@platforma-sdk/workflow-tengo:assets")
@@ -10,26 +10,27 @@ constants := import("@platforma-sdk/workflow-tengo:constants")
10
10
  oop := import("@platforma-sdk/workflow-tengo:oop")
11
11
  tx := import("tx")
12
12
  times := import("times")
13
+ maps := import("@platforma-sdk/workflow-tengo:maps")
13
14
 
14
15
 
15
16
  _SUBSCRIPTION_FIELD := "subscription"
16
17
 
17
- /**
18
- * Creates a render template resource.
19
- *
20
- * @param tpl: template resource (see assets.importTemplate())
21
- * @param isEph: whether template is ephemeral
22
- * @param inputs: a map of inputs to be passed to the template
23
- * @param serviceInputs: (optional) a map of service inputs to be passed to the template.
24
- * Service inputs are not accounted in dedupliation and recovering.
25
- * Two resources with the same <inputs> and different <serviceInputs>
26
- * would be considered as copies of each-other.
27
- * @return renderer: a smart resource with additional output("name") method
28
- */
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
29
30
  createUniversal := func(tpl, isEph, inputs, ...opts) {
30
31
  serviceInputs := opts[0]
31
32
 
32
- // build renderer resource
33
+
33
34
  rbuilder := undefined
34
35
  if isEph {
35
36
  rbuilder = smart.ephemeralBuilder(constants.RTYPE_RENDER_EPH_TEMPLATE)
@@ -38,14 +39,14 @@ createUniversal := func(tpl, isEph, inputs, ...opts) {
38
39
  }
39
40
 
40
41
  if isEph {
41
- // create internal subscription field
42
+
42
43
  rbuilder.createField(_SUBSCRIPTION_FIELD, "OTW")
43
44
  }
44
45
 
45
- // template input
46
+
46
47
  rbuilder.createInputField(tplutil.TEMPLATE_FIELD).set(tpl)
47
48
 
48
- // inputs input
49
+
49
50
  inputsMap := isEph ? smart.ephemeralMapBuilder() : smart.mapBuilder()
50
51
  for name, value in inputs {
51
52
  if !is_undefined(value) {
@@ -59,15 +60,15 @@ createUniversal := func(tpl, isEph, inputs, ...opts) {
59
60
  }
60
61
 
61
62
  rbuilder.createInputField(tplutil.INPUTS_MAP_FIELD).set(inputsMap.build())
62
- // build
63
+
63
64
  renderer := rbuilder.lockInputsAndBuild()
64
65
 
65
66
  self := undefined
66
67
  self = ll.toStrict(oop.inherit(renderer, {
67
68
 
68
- /**
69
- * Returns an output field with a given name
70
- */
69
+
70
+
71
+
71
72
  output: func(name, ...cache) {
72
73
  ll.assert(len(cache) == 0 || is_int(cache[0]), "cache should be a number (use 'times' tengo library), got: %v", cache)
73
74
  out := renderer.getFutureOutputField(tplutil.TEMPLATE_OUTPUT_PREFIX + name, isEph)
@@ -77,38 +78,92 @@ createUniversal := func(tpl, isEph, inputs, ...opts) {
77
78
  }
78
79
 
79
80
  return out
81
+ },
82
+
83
+
84
+
85
+
86
+ optionalOutput: func(name, ...cache) {
87
+ ll.assert(len(cache) == 0 || is_int(cache[0]), "cache should be a number (use 'times' tengo library), got: %v", cache)
88
+ out := renderer.getFutureFieldOptional(tplutil.TEMPLATE_OUTPUT_PREFIX + name, "output", isEph)
89
+ if len(cache) > 0 && cache[0] > 0 {
90
+ cache = cache[0]
91
+ tx.cacheSetToField(out.id, cache)
92
+ }
93
+
94
+ return out
95
+ },
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ resolveOutput: func(path) {
104
+ ll.assert(is_array(path), "path must be an array, got: %v", path)
105
+
106
+
107
+ pathCopy := []
108
+
109
+
110
+ if len(path) > 0 {
111
+ firstElem := path[0]
112
+
113
+
114
+ if is_string(firstElem) {
115
+ firstElem = { name: firstElem }
116
+ }
117
+
118
+
119
+ firstElemCopy := maps.clone(firstElem)
120
+ firstElemCopy.type = "output"
121
+
122
+
123
+ firstElemCopy.name = tplutil.TEMPLATE_OUTPUT_PREFIX + firstElemCopy.name
124
+
125
+ pathCopy = append(pathCopy, firstElemCopy)
126
+ }
127
+
128
+
129
+ for i := 1; i < len(path); i++ {
130
+ pathCopy = append(pathCopy, path[i])
131
+ }
132
+
133
+
134
+ return renderer.buildFutureField(pathCopy)
80
135
  }
81
136
  }))
82
137
 
83
138
  return self
84
139
  }
85
140
 
86
- /**
87
- * Creates a render template resource.
88
- *
89
- * @param tpl: template resource (see assets.importTemplate())
90
- * @param inputs: a map of inputs to be passed to the template
91
- * @param serviceInputs: (optional) a map of service inputs to be passed to the template.
92
- * Service inputs are not accounted in dedupliation and recovering.
93
- * Two resources with the same <inputs> and different <serviceInputs>
94
- * would be considered as copies of each-other.
95
- * @return renderer: a smart resource with additional output("name") method
96
- */
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
97
152
  create := func(tpl, inputs, ...opts) {
98
153
  return createUniversal(tpl, false, inputs, opts...)
99
154
  }
100
155
 
101
- /**
102
- * Creates ephemeral render template resource.
103
- *
104
- * @param tpl: template resource (see assets.importTemplate())
105
- * @param inputs: a map of inputs to be passed to the template
106
- * @param serviceInputs: (optional) a map of service inputs to be passed to the template.
107
- * The split into <inputs> and <serviceInputs> has no
108
- * effect on ephemeral templates, as they do not
109
- * have deduplication.
110
- * @return renderer: a smart resource with additional output("name") method
111
- */
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
112
167
  createEphemeral := func(tpl, inputs, ...opts) {
113
168
  return createUniversal(tpl, true, inputs, opts...)
114
169
  }
@@ -1,18 +1,18 @@
1
- /**
2
- * Functions for working with sets of elements,
3
- * in Tengo they are just maps with truthy values.
4
- * Keys of the map can be only either strings or numbers.
5
- */
1
+
2
+
3
+
4
+
5
+
6
6
 
7
7
  ll := import("@platforma-sdk/workflow-tengo:ll")
8
8
  maps := import("@platforma-sdk/workflow-tengo:maps")
9
9
 
10
- /**
11
- * Turns a slice to a set of values.
12
- *
13
- * @param slice: slice<string|number>
14
- * @return result: set<string|number>
15
- */
10
+
11
+
12
+
13
+
14
+
15
+
16
16
  fromSlice := func(slice) {
17
17
  set := {}
18
18
  for _, elem in slice {
@@ -21,12 +21,12 @@ fromSlice := func(slice) {
21
21
  return set
22
22
  }
23
23
 
24
- /**
25
- * Convert given set to slice
26
- *
27
- * @param set: set - a set of values to be converted to slice
28
- * @return slice: []<string|number>
29
- */
24
+
25
+
26
+
27
+
28
+
29
+
30
30
  toSlice := func(set) {
31
31
  sl := []
32
32
  for v, _ in set {
@@ -35,24 +35,24 @@ toSlice := func(set) {
35
35
  return sl
36
36
  }
37
37
 
38
- /**
39
- * Checks if a set has an element.
40
- *
41
- * @param set a set of any elements
42
- * @param element any
43
- * @return found: bool
44
- */
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
45
  hasElement := func(set, element) {
46
46
  return !is_undefined(set[element])
47
47
  }
48
48
 
49
- /**
50
- * Adds elements to the set.
51
- *
52
- * @param set a set
53
- * @param elements a slice of elements
54
- * @return: result: set<string|number> - a changed old set with all old and new elements.
55
- */
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
56
  add := func(set, ...elements) {
57
57
  for _, elem in elements {
58
58
  set[elem] = true
@@ -61,24 +61,24 @@ add := func(set, ...elements) {
61
61
  return set
62
62
  }
63
63
 
64
- /**
65
- * Returns a set of key of the map.
66
- *
67
- * @param map a map
68
- * @return result: set<string|number>
69
- */
64
+
65
+
66
+
67
+
68
+
69
+
70
70
  fromMapKeys := func(map) {
71
71
  keys := maps.getKeys(map)
72
72
  return fromSlice(keys)
73
73
  }
74
74
 
75
- /**
76
- * Transforms all keys of the map with a function and returns a new map with these keys.
77
- *
78
- * @param set: set
79
- * @param fn: func(elem): newElem - a function that gets an element and returns a new element.
80
- * @return new set: map[newElem]any - a transformed set
81
- */
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
82
  map := func(set, fn) {
83
83
  return maps.mapKeys(set, fn)
84
84
  }