@platforma-sdk/workflow-tengo 2.8.1 → 2.8.3

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 +8 -8
@@ -1,6 +1,5 @@
1
- /*
2
- * Create renderer objects to render templates from the code
3
- */
1
+
2
+
4
3
 
5
4
  ll := import("@platforma-sdk/workflow-tengo:ll")
6
5
  assets := import("@platforma-sdk/workflow-tengo:assets")
@@ -8,94 +7,84 @@ smart := import("@platforma-sdk/workflow-tengo:smart")
8
7
  tplutil := import("@platforma-sdk/workflow-tengo:tpl.util")
9
8
  constants := import("@platforma-sdk/workflow-tengo:constants")
10
9
  oop := import("@platforma-sdk/workflow-tengo:oop")
11
- validation := import("@platforma-sdk/workflow-tengo:validation")
12
10
  tx := import("tx")
13
11
  times := import("times")
14
12
 
15
13
 
16
14
  _SUBSCRIPTION_FIELD := "subscription"
17
15
 
18
- /**
19
- * Creates a render template resource.
20
- *
21
- * @param tpl: template resource (see assets.importTemplate())
22
- * @param isEph: whether template is ephemeral
23
- * @param inputs: a map of inputs to be passed to the template
24
- * @return renderer: a smart resource with additional output("name") method
25
- */
16
+
17
+
18
+
19
+
20
+
21
+
22
+
26
23
  createUniversal := func(tpl, isEph, inputs) {
27
24
 
28
- // build renderer resource
29
- rbuilder := undefined
30
- if isEph {
31
- rbuilder = smart.ephemeralBuilder(constants.RTYPE_RENDER_EPH_TEMPLATE)
32
- } else {
33
- rbuilder = smart.structBuilder(constants.RTYPE_RENDER_TEMPLATE)
34
- }
35
-
36
- if isEph {
37
- // create internal subscription field
38
- rbuilder.createField(_SUBSCRIPTION_FIELD, "OTW")
39
- }
40
-
41
- // template input
42
- rbuilder.createInputField(tplutil.TEMPLATE_FIELD).set(tpl)
43
-
44
- // inputs input
45
- inputsMap := isEph ? smart.ephemeralMapBuilder() : smart.mapBuilder()
46
- for name, value in inputs {
47
- inputsMap.add(name, value)
48
- }
49
-
50
- rbuilder.createInputField(tplutil.INPUTS_MAP_FIELD).set(inputsMap.build())
51
- // build
52
- renderer := rbuilder.lockInputsAndBuild()
53
-
54
- self := undefined
55
- self = ll.toStrict(oop.inherit(renderer, {
56
-
57
- /**
58
- * Returns an output field with a given name
59
- */
60
- output: func(name, ...cache) {
61
- ll.assert(len(cache) == 0 || is_int(cache[0]), "cache should be a number (use 'times' tengo library), got: %v", cache)
62
- out := renderer.getFutureOutputField(tplutil.TEMPLATE_OUTPUT_PREFIX + name, isEph)
63
- if len(cache) > 0 && cache[0] > 0 {
64
- cache = cache[0]
65
- tx.cacheSetToField(out.id, cache)
66
- }
67
-
68
- return out
69
- }
70
- }))
71
-
72
- return self
25
+ rbuilder := undefined
26
+ if isEph {
27
+ rbuilder = smart.ephemeralBuilder(constants.RTYPE_RENDER_EPH_TEMPLATE)
28
+ } else {
29
+ rbuilder = smart.structBuilder(constants.RTYPE_RENDER_TEMPLATE)
30
+ }
31
+
32
+ if isEph {
33
+ rbuilder.createField(_SUBSCRIPTION_FIELD, "OTW")
34
+ }
35
+
36
+ rbuilder.createInputField(tplutil.TEMPLATE_FIELD).set(tpl)
37
+
38
+ inputsMap := isEph ? smart.ephemeralMapBuilder() : smart.mapBuilder()
39
+ for name, value in inputs {
40
+ inputsMap.add(name, value)
41
+ }
42
+
43
+ rbuilder.createInputField(tplutil.INPUTS_MAP_FIELD).set(inputsMap.build())
44
+ renderer := rbuilder.lockInputsAndBuild()
45
+
46
+ self := undefined
47
+ self = ll.toStrict(oop.inherit(renderer, {
48
+
49
+
50
+
51
+ output: func(name, ...cache) {
52
+ ll.assert(len(cache) == 0 || is_int(cache[0]), "cache should be a number (use 'times' tengo library), got: %v", cache)
53
+ out := renderer.getFutureOutputField(tplutil.TEMPLATE_OUTPUT_PREFIX + name, isEph)
54
+ if len(cache) > 0 && cache[0] > 0 {
55
+ cache = cache[0]
56
+ tx.cacheSetToField(out.id, cache)
73
57
  }
74
58
 
75
- /**
76
- * Creates a render template resource.
77
- *
78
- * @param tpl: template resource (see assets.importTemplate())
79
- * @param inputs: a map of inputs to be passed to the template
80
- * @return renderer: a smart resource with additional output("name") method
81
- */
59
+ return out
60
+ }
61
+ }))
62
+
63
+ return self
64
+ }
65
+
66
+
67
+
68
+
69
+
70
+
71
+
82
72
  create := func(tpl, inputs) {
83
- return createUniversal(tpl, false, inputs)
73
+ return createUniversal(tpl, false, inputs)
84
74
  }
85
75
 
86
- /**
87
- * Creates ephemeral 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
- * @return renderer: a smart resource with additional output("name") method
92
- */
76
+
77
+
78
+
79
+
80
+
81
+
93
82
  createEphemeral := func(tpl, inputs) {
94
- return createUniversal(tpl, true, inputs)
83
+ return createUniversal(tpl, true, inputs)
95
84
  }
96
85
 
97
86
  export ll.toStrict({
98
- createUniversal: createUniversal,
99
- create: create,
100
- createEphemeral: createEphemeral
87
+ createUniversal: createUniversal,
88
+ create: create,
89
+ createEphemeral: createEphemeral
101
90
  })
@@ -1,93 +1,86 @@
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
+
6
5
 
7
6
  ll := import("@platforma-sdk/workflow-tengo:ll")
8
7
  maps := import("@platforma-sdk/workflow-tengo:maps")
9
8
 
10
- /**
11
- * Turns a slice to a set of values.
12
- *
13
- * @param slice: slice<string|number>
14
- * @return result: set<string|number>
15
- */
9
+
10
+
11
+
12
+
13
+
16
14
  fromSlice := func(slice) {
17
- set := {}
18
- for _, elem in slice {
19
- set[elem] = true
20
- }
21
- return set
15
+ set := {}
16
+ for _, elem in slice {
17
+ set[elem] = true
18
+ }
19
+ return set
22
20
  }
23
21
 
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
- */
22
+
23
+
24
+
25
+
26
+
30
27
  toSlice := func(set) {
31
- sl := []
32
- for v, _ in set {
33
- sl = append(sl, v)
34
- }
35
- return sl
28
+ sl := []
29
+ for v, _ in set {
30
+ sl = append(sl, v)
36
31
  }
32
+ return sl
33
+ }
34
+
35
+
36
+
37
+
38
+
39
+
37
40
 
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
- */
45
41
  hasElement := func(set, element) {
46
- return !is_undefined(set[element])
42
+ return !is_undefined(set[element])
47
43
  }
48
44
 
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
- */
45
+
46
+
47
+
48
+
49
+
50
+
56
51
  add := func(set, ...elements) {
57
- for _, elem in elements {
58
- set[elem] = true
59
- }
52
+ for _, elem in elements {
53
+ set[elem] = true
54
+ }
60
55
 
61
- return set
56
+ return set
62
57
  }
63
58
 
64
- /**
65
- * Returns a set of key of the map.
66
- *
67
- * @param map a map
68
- * @return result: set<string|number>
69
- */
59
+
60
+
61
+
62
+
63
+
70
64
  fromMapKeys := func(map) {
71
- keys := maps.getKeys(map)
72
- return fromSlice(keys)
65
+ keys := maps.getKeys(map)
66
+ return fromSlice(keys)
73
67
  }
74
68
 
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
- */
69
+
70
+
71
+
72
+
73
+
74
+
82
75
  map := func(set, fn) {
83
- return maps.mapKeys(set, fn)
76
+ return maps.mapKeys(set, fn)
84
77
  }
85
78
 
86
79
  export ll.toStrict({
87
- fromSlice: fromSlice,
88
- toSlice: toSlice,
89
- hasElement: hasElement,
90
- add: add,
91
- fromMapKeys: fromMapKeys,
92
- map: map
80
+ fromSlice: fromSlice,
81
+ toSlice: toSlice,
82
+ hasElement: hasElement,
83
+ add: add,
84
+ fromMapKeys: fromMapKeys,
85
+ map: map
93
86
  })
@@ -1,202 +1,191 @@
1
1
  ll := import("@platforma-sdk/workflow-tengo:ll")
2
2
  enum := import("enum")
3
3
 
4
- /**
5
- * Returns length of the collection even if it's nil.
6
- * It's a one of rare differences of Tengo and Go.
7
- *
8
- * @param slice: []any | undefined - a slice
9
- * @return: length: int
10
- */
4
+
5
+
6
+
7
+
8
+
9
+
11
10
  length := func(slice) {
12
- if is_undefined(slice) {
13
- return 0
14
- }
15
- return len(slice)
16
- }
17
-
18
- /**
19
- * Returns a slice of the array, but you can give negative from and to,
20
- * in which case it slices from the end like in Python.
21
- * Example: slice([1, 2, 3], 0, -1) == [1, 2]
22
- *
23
- * @param array: []any - a slice
24
- * @param from: number - an index we starts from
25
- * @param to: number - an index the slice will end
26
- * @return slice: []any - a sliced array.
27
- */
11
+ if is_undefined(slice) {
12
+ return 0
13
+ }
14
+ return len(slice)
15
+ }
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
28
26
  slice := func(array, from, to) {
29
- len := length(array)
30
- if from < 0 {
31
- from = len + from
32
- }
33
- if to < 0 {
34
- to = len + to
35
- }
36
-
37
- return array[from:to]
38
- }
39
-
40
- /**
41
- * Appends slices safely even some of them are nil.
42
- * It's one of rare differences of Tengo and Go.
43
- *
44
- * @param slice: []any - a slice
45
- * @param toAppend: ...any - elements we'll append to the slice
46
- * @return new slice: []any - the same slice but with appended elements.
47
- */
27
+ len := length(array)
28
+ if from < 0 {
29
+ from = len + from
30
+ }
31
+ if to < 0 {
32
+ to = len + to
33
+ }
34
+
35
+ return array[from:to]
36
+ }
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
48
45
  safeAppend := func(slice, ...toAppend) {
49
- if is_undefined(slice) {
50
- slice = []
51
- }
52
- if length(toAppend) == 0 {
53
- return slice // slice is of any length here.
54
- }
55
-
56
- return append(slice, toAppend...)
57
- }
58
-
59
- /**
60
- * Returns an index of an element in the slice or -1 if it wasn't found.
61
- *
62
- * @param silce: []any
63
- * @param element: any
64
- * @return index: int - index of the element or -1
65
- */
46
+ if is_undefined(slice) {
47
+ slice = []
48
+ }
49
+ if length(toAppend) == 0 {
50
+ return slice // slice is of any length here.
51
+ }
52
+
53
+ return append(slice, toAppend...)
54
+ }
55
+
56
+
57
+
58
+
59
+
60
+
61
+
66
62
  findElement := func(slice, element) {
67
- for i, elem in slice {
68
- if elem == element {
69
- return i
70
- }
71
- }
72
-
73
- return -1
74
- }
75
-
76
- /**
77
- * Returns a boolean of whether an element is in a slice.
78
- *
79
- * @param slice: []any
80
- * @param element: any - an element the function searches for.
81
- * @return found: bool
82
- */
63
+ for i, elem in slice {
64
+ if elem == element {
65
+ return i
66
+ }
67
+ }
68
+
69
+ return -1
70
+ }
71
+
72
+
73
+
74
+
75
+
76
+
77
+
83
78
  hasElement := func(slice, element) {
84
- return findElement(slice, element) != -1
79
+ return findElement(slice, element) != -1
85
80
  }
86
81
 
87
- /**
88
- * Removes an element from the slice
89
- *
90
- * @param slice: []any
91
- * @param i: int - an index of the element to remove.
92
- * @return nothing
93
- */
82
+
83
+
84
+
85
+
86
+
87
+
94
88
  removeElement := func(slice, i) {
95
- return safeAppend(slice[:i], slice[i+1:]...)
89
+ return safeAppend(slice[:i], slice[i+1:]...)
96
90
  }
97
91
 
98
- /**
99
- * Returns a new slice with elements for which a predicate returned true.
100
- *
101
- * @param slice: []any
102
- * @param predicateFn: func(elem): bool - a function that gets an element and returns a truthy or falsy value.
103
- * @return new slice: []any - a slice with matched elements.
104
- */
92
+
93
+
94
+
95
+
96
+
97
+
105
98
  filter := func(slice, predicateFn) {
106
- newS := []
107
- for _, elem in slice {
108
- if predicateFn(elem) {
109
- newS = append(newS, elem)
110
- }
111
- }
112
-
113
- return newS
114
- }
115
-
116
- /**
117
- * Transforms each element of the slice to a new one and returns a new slice
118
- *
119
- * @param slice: []any
120
- * @param fn: func(elem): new elem - a function that gets an element and returns a transformed element.
121
- * @return new slice: []any - a new slice with transformed elements.
122
- */
99
+ newS := []
100
+ for _, elem in slice {
101
+ if predicateFn(elem) {
102
+ newS = append(newS, elem)
103
+ }
104
+ }
105
+
106
+ return newS
107
+ }
108
+
109
+
110
+
111
+
112
+
113
+
114
+
123
115
  map := func(slice, fn) {
124
- newS := []
125
- for _, elem in slice {
126
- newS = append(newS, fn(elem))
127
- }
128
-
129
- return newS
130
- }
131
-
132
- /**
133
- * Returns the result of applying fn to the first 2 items in the slice, then
134
- * applying fn to that result and the 3rd item, etc.
135
- * If coll has only 1 item, it is returned and fn is not called.
136
- *
137
- * @param slice: []any
138
- * @param fn: func(any, element): new result.
139
- * a function that gets a result got so far and an element and returns a new result.
140
- * @return final result: any - the final result
141
- */
116
+ newS := []
117
+ for _, elem in slice {
118
+ newS = append(newS, fn(elem))
119
+ }
120
+
121
+ return newS
122
+ }
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
142
133
  reduce := func(slice, fn) {
143
- result := undefined
144
- for i, elem in slice {
145
- if i == 0 {
146
- result = elem
147
- } else {
148
- result = fn(result, elem)
149
- }
150
- }
151
-
152
- return result
153
- }
154
-
155
- /**
156
- * Creates a copy of a slice and sorts it using a stable bubble sort.
157
- *
158
- * @param notSortedSlice: []any - a slice of elements of any type.
159
- * @param fn: func(elem): int - a function that transforms an element to a key.
160
- * @return sorted slice: []any
161
- *
162
- */
134
+ result := undefined
135
+ for i, elem in slice {
136
+ if i == 0 {
137
+ result = elem
138
+ } else {
139
+ result = fn(result, elem)
140
+ }
141
+ }
142
+
143
+ return result
144
+ }
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
163
153
  sortByFn := func(notSortedSlice, fn) {
164
- s := copy(notSortedSlice)
165
-
166
- for i := 0; i < length(s) - 1; i++ {
167
- for j := i+1; j < length(s); j++ {
168
- if fn(s[i]) > fn(s[j]) {
169
- tmp := s[i]
170
- s[i] = s[j]
171
- s[j] = tmp
172
- }
173
- }
174
- }
175
-
176
- return s
177
- }
178
-
179
- /**
180
- * Creates a slice from a set of elements
181
- *
182
- * @param set: map[element]any - a set
183
- * @return slice: []element - a slice of elements from the set, sorted by an element.
184
- */
154
+ s := copy(notSortedSlice)
155
+
156
+ for i := 0; i < length(s) - 1; i++ {
157
+ for j := i+1; j < length(s); j++ {
158
+ if fn(s[i]) > fn(s[j]) {
159
+ tmp := s[i]
160
+ s[i] = s[j]
161
+ s[j] = tmp
162
+ }
163
+ }
164
+ }
165
+
166
+ return s
167
+ }
168
+
169
+
170
+
171
+
172
+
173
+
185
174
  fromSet := func(set) {
186
- slice := enum.map(set, func(k, _) { return k })
187
- return sortByFn(slice, func(elem) { return elem })
175
+ slice := enum.map(set, func(k, _) { return k })
176
+ return sortByFn(slice, func(elem) { return elem })
188
177
  }
189
178
 
190
179
  export ll.toStrict({
191
- length: length,
192
- safeAppend: safeAppend,
193
- findElement: findElement,
194
- hasElement: hasElement,
195
- removeElement: removeElement,
196
- filter: filter,
197
- map: map,
198
- reduce: reduce,
199
- sortByFn: sortByFn,
200
- fromSet: fromSet,
201
- slice: slice
180
+ length: length,
181
+ safeAppend: safeAppend,
182
+ findElement: findElement,
183
+ hasElement: hasElement,
184
+ removeElement: removeElement,
185
+ filter: filter,
186
+ map: map,
187
+ reduce: reduce,
188
+ sortByFn: sortByFn,
189
+ fromSet: fromSet,
190
+ slice: slice
202
191
  })