@platforma-sdk/workflow-tengo 2.14.0 → 2.15.0

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,6 +1,6 @@
1
- /**
2
- * Gives an interface for working with workdirs.
3
- */
1
+
2
+
3
+
4
4
 
5
5
  json := import("json")
6
6
 
@@ -24,25 +24,25 @@ _WD_CREATE_FIELD_WORKDIR := "workdir"
24
24
  _WD_FILL_FIELD_WORKDIR_IN := "workdirIn"
25
25
  _WD_FILL_FIELD_WORKDIR_OUT := "workdirOut"
26
26
 
27
- /**
28
- * Create empty working directory
29
- *
30
- * @return smart.field - field where working directory will appear after creation
31
- */
27
+
28
+
29
+
30
+
31
+
32
32
  create := func() {
33
- // working directories without quotas (old-style)
33
+
34
34
  wdCreate := smart.ephemeralBuilder(constants.RTYPE_WORKDIR_CREATE).lockAndBuild()
35
35
  return wdCreate.getField(_WD_CREATE_FIELD_WORKDIR)
36
36
  }
37
37
 
38
- /**
39
- * Create empry working directory for given allocation. This means, the WD would actually be created only
40
- * when allocation is ready for usage.
41
- *
42
- * @param allocation: smart.reference - a reference to storage space allocation.
43
- * It is usually obtained from StorageSpaceRequest
44
- * (see exec.limits.storageSpaceRequestBuilder)
45
- */
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
46
  createV2 := func(allocation) {
47
47
  wdCreate := smart.ephemeralBuilder(constants.RTYPE_WORKDIR_CREATE_2).lockAndBuild()
48
48
  wdCreate.getField(_WD_CREATE_FIELD_ALLOCATION).set(allocation)
@@ -82,12 +82,12 @@ _getArchiveFillRule := func(dstDir, whatToExtract, archiveBlobKey) {
82
82
  }
83
83
  }
84
84
 
85
- /**
86
- * Generates a value fill rule for a given file path.
87
- *
88
- * @param filePath: string - the path of the file.
89
- * @return rule: map - the value fill rule.
90
- */
85
+
86
+
87
+
88
+
89
+
90
+
91
91
  _getValueFillRule := func(filePath) {
92
92
  return {
93
93
  type: "value",
@@ -98,12 +98,12 @@ _getValueFillRule := func(filePath) {
98
98
  }
99
99
  }
100
100
 
101
- /**
102
- * Generates a directory fill rule for a given directory.
103
- *
104
- * @param dir: string - the path of the directory.
105
- * @return rule: map - the directory fill rule.
106
- */
101
+
102
+
103
+
104
+
105
+
106
+
107
107
  _getDirFillRule := func(dir) {
108
108
  return {
109
109
  type: "dir",
@@ -113,14 +113,14 @@ _getDirFillRule := func(dir) {
113
113
  }
114
114
  }
115
115
 
116
- /**
117
- * Fills a workdir with files, values, and directories.
118
- *
119
- * @return self: builder - a builder that adds files and directories to the workdir. */
116
+
117
+
118
+
119
+
120
120
  _fill := func() {
121
121
  wd := smart.ephemeralBuilder(constants.RTYPE_WORKDIR_FILL)
122
122
 
123
- /** @type reference - space allocation to be used for WD */
123
+
124
124
  _allocation := undefined
125
125
  blobs := {}
126
126
  files := {}
@@ -140,28 +140,28 @@ _fill := func() {
140
140
  sets.add(dirs, newDirs...)
141
141
  },
142
142
 
143
- /**
144
- * Use given storage allocation for working directory.
145
- *
146
- * @param allocation: reference
147
- */
143
+
144
+
145
+
146
+
147
+
148
148
  allocation: func(allocation) {
149
149
  validation.assertType(allocation, validation.reference, "workdir.builder: allocation should be a valid reference")
150
150
  _allocation = allocation
151
151
  },
152
152
 
153
- /**
154
- * Adds files from given zip archive into working directory.
155
- *
156
- * @param zipResource: smart.reference - reference to zip archive to be extracted.
157
- * @param destinationDir: string - path inside working directory for files to be extracted from archive.
158
- * Consider it as 'cd' before extraction. It makes all extracted files to be
159
- * stored inside this directory.
160
- * @param pathsInArchive: string[] - paths inside the archive to be extracted into destinationDir.
161
- * Empty array means 'unpack full archive'.
162
- * Full file paths are preserved during extraction: the file 'a/b/file.txt' would
163
- * be extracted into '<destinationDir>/a/b/file.txt', NOT '<destinationDir>/file.txt',
164
- */
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
165
  addFromZip: func(zipResource, destinationDir, pathsInArchive) {
166
166
  validation.assertType(zipResource, validation.reference, "workdir.builder.addFromZip: <zipResource> is not smart.reference")
167
167
  validation.assertType(destinationDir, "string", "workdir.builder.addFromZip: <destinationDir> is not a string. It must be a path inside working directory")
@@ -193,12 +193,12 @@ _fill := func() {
193
193
  return self
194
194
  },
195
195
 
196
- /**
197
- * Adds a file to the workdir.
198
- *
199
- * @param fileName: string - the name of the file.
200
- * @param fileResource: reference - the file to add.
201
- */
196
+
197
+
198
+
199
+
200
+
201
+
202
202
  addFile: func(fileName, fileResource) {
203
203
  validation.assertType(fileName, "string")
204
204
  validation.assertType(fileResource, validation.reference)
@@ -210,22 +210,22 @@ _fill := func() {
210
210
  return self
211
211
  },
212
212
 
213
- /**
214
- * Adds multiple files to the workdir.
215
- *
216
- * @param fileMap: map[string]reference - a map of files.
217
- */
213
+
214
+
215
+
216
+
217
+
218
218
  addFiles: func(fileMap) {
219
219
  enum.each(fileMap, self.addFile)
220
220
  return self
221
221
  },
222
222
 
223
- /**
224
- * Adds a file with a content to the workdir.
225
- *
226
- * @param fileName: string - the name of the file.
227
- * @param contentRef: reference|any - the content as a reference to add or the content itself.
228
- */
223
+
224
+
225
+
226
+
227
+
228
+
229
229
  writeFile: func(fileName, contentRef) {
230
230
  validation.assertType(fileName, "string")
231
231
  values[fileName] = contentRef
@@ -234,27 +234,27 @@ _fill := func() {
234
234
  return self
235
235
  },
236
236
 
237
- /**
238
- * Adds multiple files with contents to the workdir.
239
- *
240
- * @param contentMap: map[string]any|reference - a map of references to a content or to a content itself.
241
- */
237
+
238
+
239
+
240
+
241
+
242
242
  writeFiles: func(contentRefMap) {
243
243
  enum.each(contentRefMap, self.writeFile)
244
244
  return self
245
245
  },
246
246
 
247
- /**
248
- * Creates a possibly nested directory in the workdir.
249
- *
250
- * @param dir: string - the path of the directory.
251
- */
247
+
248
+
249
+
250
+
251
+
252
252
  mkDir: func(dir) {
253
253
  sets.add(dirs, path.getBasenameDirs(dir))
254
254
  return self
255
255
  },
256
256
 
257
- /** Creates nested dirs. */
257
+
258
258
  mkDirs: func(dirs) {
259
259
  for _, dir in dirs {
260
260
  self.mkDir(dir)
@@ -263,11 +263,11 @@ _fill := func() {
263
263
  return self
264
264
  },
265
265
 
266
- /**
267
- * Builds the filled workdir.
268
- *
269
- * @return wd: reference - a reference to the filled workdir.
270
- */
266
+
267
+
268
+
269
+
270
+
271
271
  build: func() {
272
272
  emptyWorkdir := undefined
273
273
  if feats.workdirLimits && smart.isReference(_allocation) {
@@ -311,63 +311,63 @@ _fill := func() {
311
311
  return self
312
312
  }
313
313
 
314
- /**
315
- * Creates and fills a workdir with files, contents, and directories. See _fill for futher documentation.
316
- *
317
- * @return self: builder - a builder that adds files and directories to the workdir.
318
- */
314
+
315
+
316
+
317
+
318
+
319
319
  builder := func() {
320
320
  return _fill()
321
321
  }
322
322
 
323
- /**
324
- * Saves a workdir.
325
- *
326
- * @param workdir: reference - a reference to the workdir to save.
327
- * @return self: builder - the builder that helps adding save rules to the save workdir.
328
- */
323
+
324
+
325
+
326
+
327
+
328
+
329
329
  save := func(workdir) {
330
330
  ll.assert(smart.isReference(workdir), "workdir must be a reference to a resource or field")
331
331
 
332
- // files to save
332
+
333
333
  files := {}
334
- // files to save their content
334
+
335
335
  filesContent := {}
336
- // file sets to save by regex
336
+
337
337
  fileSets := {}
338
- // file sets to save their content by regex
338
+
339
339
  fileSetsContent := {}
340
340
 
341
341
  self := undefined
342
342
  self = ll.toStrict({
343
- /**
344
- * Saves a file from the workdir.
345
- *
346
- * @param fileName: string - the name of the file.
347
- */
343
+
344
+
345
+
346
+
347
+
348
348
  saveFile: func(fileName) {
349
349
  validation.assertType(fileName, "string")
350
350
  sets.add(files, fileName)
351
351
  return self
352
352
  },
353
353
 
354
- /**
355
- * Saves a file to a value resource from the workdir.
356
- *
357
- * @param fileName: string - the name of the file.
358
- */
354
+
355
+
356
+
357
+
358
+
359
359
  saveFileContent: func(fileName) {
360
360
  validation.assertType(fileName, "string")
361
361
  sets.add(filesContent, fileName)
362
362
  return self
363
363
  },
364
364
 
365
- /**
366
- * Save files which names satisfy given regex rule
367
- *
368
- * @param name: string - a name to refer this file set in the outputs
369
- * @param regex: string - regex
370
- */
365
+
366
+
367
+
368
+
369
+
370
+
371
371
  saveFileSet: func(name, regex) {
372
372
  validation.assertType(regex, "string")
373
373
  ll.assert(is_undefined(fileSets[name]), "file set with name '", name, "' is already in added")
@@ -375,12 +375,12 @@ save := func(workdir) {
375
375
  return self
376
376
  },
377
377
 
378
- /**
379
- * Save files content which names satisfy given regex rule
380
- *
381
- * @param name: string - a name to refer this file set in the outputs
382
- * @param regex: string - regex
383
- */
378
+
379
+
380
+
381
+
382
+
383
+
384
384
  saveFileSetContent: func(name, regex) {
385
385
  validation.assertType(regex, "string")
386
386
  ll.assert(is_undefined(fileSetsContent[name]), "file set content with name '", name, "' is already in added")
@@ -388,11 +388,11 @@ save := func(workdir) {
388
388
  return self
389
389
  },
390
390
 
391
- /**
392
- * Builds the saved workdir.
393
- *
394
- * @return wd: reference - the saved workdir with additional fields.
395
- */
391
+
392
+
393
+
394
+
395
+
396
396
  build: func() {
397
397
 
398
398
  tpl := assets.importTemplate("@platforma-sdk/workflow-tengo:workdir.save")
@@ -1,10 +1,10 @@
1
- /** Library for workdir processor templates */
1
+
2
2
 
3
3
  tpl := import("@platforma-sdk/workflow-tengo:tpl")
4
4
  ll := import("@platforma-sdk/workflow-tengo:ll")
5
5
  wdSave := import("@platforma-sdk/workflow-tengo:workdir.save")
6
6
 
7
- // the template has a defined outputs
7
+
8
8
  tpl.defineOutputs(["result", "workdir"])
9
9
 
10
10
  proc := func() {
@@ -13,9 +13,9 @@ proc := func() {
13
13
  self = {
14
14
 
15
15
  _wdBefore: undefined,
16
- /**
17
- * @return wd: resource - initial working directory resource
18
- */
16
+
17
+
18
+
19
19
  wdBefore: func() {
20
20
  if is_undefined(self._wdBefore) {
21
21
  self._wdBefore = tpl.inputs().workdir
@@ -24,9 +24,9 @@ proc := func() {
24
24
  },
25
25
 
26
26
  _filesInWd: undefined,
27
- /**
28
- * @return fileNames: string[] - list of file paths currently existing in the working directory
29
- */
27
+
28
+
29
+
30
30
  filesInWd: func() {
31
31
  if is_undefined(self._filesInWd) {
32
32
  self._filesInWd = self.wdBefore().getDataAsJson().files
@@ -36,22 +36,22 @@ proc := func() {
36
36
  },
37
37
 
38
38
  _wdAfterReadFiles: undefined,
39
- /**
40
- * @return wd: resource - working directory resource after "readFiles" is done
41
- */
39
+
40
+
41
+
42
42
  wdAfterReadFiles: func() {
43
43
  if is_undefined(self._wdAfterReadFiles) {
44
44
 
45
45
  if !is_undefined(tpl.inputs().wdAfterReadFiles) {
46
46
 
47
- //
48
- // this means readFiles was used and we are actually
49
- // in the 'prepare' render
50
- //
47
+
48
+
49
+
50
+
51
51
  self._wdAfterReadFiles = tpl.inputs().wdAfterReadFiles
52
52
  } else {
53
53
 
54
- // no readFiles
54
+
55
55
  self._wdAfterReadFiles = self.wdBefore()
56
56
  }
57
57
  }
@@ -59,17 +59,17 @@ proc := func() {
59
59
  return self._wdAfterReadFiles
60
60
  },
61
61
 
62
- /**
63
- * Select files to read their content and pass it to the body function
64
- *
65
- * @param cb: callback - a callback which takes a list of file names (paths) existing in the working directory and
66
- * returning a map of key -> file name containing files to get content from; each file content will be available in
67
- * the body inputs with the corresponding key
68
- */
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
69
  readFiles: func(cb) {
70
70
  tpl.prepare(func(inputs){
71
71
  inputs.files = self.filesInWd()
72
- // key -> file name
72
+
73
73
  files := cb(inputs)
74
74
 
75
75
  wdBuilder := wdSave.builder(self.wdBefore())
@@ -78,7 +78,7 @@ proc := func() {
78
78
  }
79
79
  wd := wdBuilder.build()
80
80
 
81
- // run prepare to get file contents in the inputs
81
+
82
82
  preps := {}
83
83
  for key, fName in files {
84
84
  preps[key] = wd.getSavedFileContent(fName)
@@ -91,9 +91,9 @@ proc := func() {
91
91
  },
92
92
 
93
93
  _wdFinalBuilder: undefined,
94
- /**
95
- * Final workdir builder, after prepare
96
- */
94
+
95
+
96
+
97
97
  wdFinalBuilder: func() {
98
98
  if is_undefined(self._wdFinalBuilder) {
99
99
  self._wdFinalBuilder = wdSave.builder(self.wdAfterReadFiles())
@@ -101,34 +101,34 @@ proc := func() {
101
101
  return self._wdFinalBuilder
102
102
  },
103
103
 
104
- /**
105
- * Save given file.
106
- *
107
- * @return ref: reference - a reference to saved file resource
108
- */
104
+
105
+
106
+
107
+
108
+
109
109
  saveFile: func(fName) {
110
110
  self.wdFinalBuilder().saveFile(fName)
111
111
  return self.wdFinalBuilder().getSavedFile(fName)
112
112
  },
113
113
 
114
- /**
115
- * Save content of a given file.
116
- *
117
- * @return ref: reference - a reference to saved file content value resource
118
- */
114
+
115
+
116
+
117
+
118
+
119
119
  saveFileContent: func(fName) {
120
120
  self.wdFinalBuilder().saveFileContent(fName)
121
121
  return self.wdFinalBuilder().getSavedFileContent(fName)
122
122
  },
123
123
 
124
- /**
125
- * Template body function
126
- *
127
- * @param cb: func - a callback function to run in template body; the inputs passed to the body will have the following fields:
128
- * files: string[] - list of files in workdir
129
- * args: map - additional arguments of the template processor
130
- * ...filesContent: resources - fields with the content of files specified in 'readFiles'
131
- */
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
132
  body: func(cb) {
133
133
  tpl.body(func(inputs) {
134
134
 
@@ -147,7 +147,7 @@ proc := func() {
147
147
  return ll.toStrict(self)
148
148
  }
149
149
 
150
- /** singleton instance */
150
+
151
151
  instance := proc()
152
152
 
153
153
  export ll.toStrict({