@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,107 +1,101 @@
1
- /** API to retrieve assets packed with template code (like other templates). */
2
1
 
3
2
  plapi := import("plapi")
4
3
  json := import("json")
5
4
  ll := import("@platforma-sdk/workflow-tengo:ll")
6
5
  smart := import("@platforma-sdk/workflow-tengo:smart")
7
6
 
8
- /**
9
- * Returns internal template identifier for loaded templates
10
- *
11
- * @param tplName: string - full name of a template, including namespace (package name).
12
- * Local templates (within the same package) can omit namespace part and start the name with colon:
13
- * - "@company/package:someTemplateName"
14
- * - ":myLocalTemplate"
15
- *
16
- * @return template: smart.resource - resource of tengo template with given name.
17
- */
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
18
16
  importTemplate := func(tplName) {
19
- return smart.resource(plapi.getTemplateId(tplName))
17
+ return smart.resource(plapi.getTemplateId(tplName))
20
18
  }
21
19
 
22
- /**
23
- * Returns software description suitable for 'exec' operations.
24
- *
25
- * @param swName: string - full name of the software entrypoint, including namespace (NPM package name).
26
- * Local software entrypoints (within the same package) can omit namespace part
27
- * and start the name with colon:
28
- * - "@company/package:some-oftware"
29
- * - ":my-local-software"
30
- *
31
- * @return softwareInfo: softwareInfo - structure with software info.
32
- */
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
33
30
  importSoftware := func(swName) {
34
- sw := plapi.getSoftwareInfo(swName)
35
- return ll.toStrict({
36
- _type: "softwareDescriptor",
37
- _id: sw.id,
38
-
39
- resource: smart.resource(sw.id),
40
- name: sw.name,
41
- version: sw.version,
42
- blobRef: sw.blobRef,
43
- descriptor: ll.toStrict(json.decode(sw.descriptor)) // raw sw.json data with software entrypoint descriptor
44
- })
31
+ sw := plapi.getSoftwareInfo(swName)
32
+ return ll.toStrict({
33
+ _type: "softwareDescriptor",
34
+ _id: sw.id,
35
+
36
+ resource: smart.resource(sw.id),
37
+ name: sw.name,
38
+ version: sw.version,
39
+ blobRef: sw.blobRef,
40
+ descriptor: ll.toStrict(json.decode(sw.descriptor)) // raw sw.json data with software entrypoint descriptor
41
+ })
45
42
  }
46
43
 
47
- /**
48
- * Checks if given item is a software info
49
- *
50
- * @param toCheck: any - item to check
51
- *
52
- * @return isSoftware: boolean - true for software info, loaded with importSoftware()
53
- */
44
+
45
+
46
+
47
+
48
+
49
+
54
50
  isSoftwareInfo := func(toCheck) {
55
- if !ll.isMap(toCheck) {
56
- return false
57
- }
51
+ if !ll.isMap(toCheck) {
52
+ return false
53
+ }
58
54
 
59
- return (ll.fromStrict(toCheck)._type) == "softwareDescriptor"
55
+ return (ll.fromStrict(toCheck)._type) == "softwareDescriptor"
60
56
  }
61
57
 
62
- /**
63
- * Returns asset description suitable for 'exec' operations.
64
- * Asset is the way to put static files into working directory before execution of the command.
65
- *
66
- * @param assetName: string - full name of asset entrypoint, including namespace (NPM package name).
67
- * Local software entrypoints (within the same package) can omit namespace
68
- * part and start the name with colon:
69
- * - "@company/package:some-software"
70
- * - ":my-local-software"
71
- */
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
72
67
  importAsset := func(assetName) {
73
- asset := plapi.getSoftwareInfo(assetName)
74
- return ll.toStrict({
75
- _type: "assetDescriptor",
76
- _id: asset.id,
77
-
78
- resource: smart.resource(asset.id),
79
- name: asset.name,
80
- version: asset.version,
81
- blobRef: asset.blobRef,
82
- descriptor: ll.toStrict(json.decode(asset.descriptor)) // raw sw.json data with asset entrypoint descriptor
83
- })
68
+ asset := plapi.getSoftwareInfo(assetName)
69
+ return ll.toStrict({
70
+ _type: "assetDescriptor",
71
+ _id: asset.id,
72
+
73
+ resource: smart.resource(asset.id),
74
+ name: asset.name,
75
+ version: asset.version,
76
+ blobRef: asset.blobRef,
77
+ descriptor: ll.toStrict(json.decode(asset.descriptor)) // raw sw.json data with asset entrypoint descriptor
78
+ })
84
79
  }
85
80
 
86
- /**
87
- * Checks if given item is an asset info
88
- *
89
- * @param toCheck: any - item to check
90
- *
91
- * @return isAsset: boolean - true for asset info, loaded with importAsset()
92
- */
81
+
82
+
83
+
84
+
85
+
86
+
93
87
  isAssetInfo := func(toCheck) {
94
- if !ll.isMap(toCheck) {
95
- return false
96
- }
88
+ if !ll.isMap(toCheck) {
89
+ return false
90
+ }
97
91
 
98
- return (ll.fromStrict(toCheck)._type) == "assetDescriptor"
92
+ return (ll.fromStrict(toCheck)._type) == "assetDescriptor"
99
93
  }
100
94
 
101
95
  export ll.toStrict({
102
- importTemplate: importTemplate,
103
- importSoftware: importSoftware,
104
- isSoftwareInfo: isSoftwareInfo,
105
- importAsset: importAsset,
106
- isAssetInfo: isAssetInfo
96
+ importTemplate: importTemplate,
97
+ importSoftware: importSoftware,
98
+ isSoftwareInfo: isSoftwareInfo,
99
+ importAsset: importAsset,
100
+ isAssetInfo: isAssetInfo
107
101
  })
@@ -1,11 +1,9 @@
1
- // constants
2
1
 
3
2
  ll := import("@platforma-sdk/workflow-tengo:ll")
4
3
 
5
4
  RTYPE_JSON := { Name: "json/object", Version: "1" }
6
5
 
7
6
  RTYPE_MAP := { Name: "std/map", Version: "1" }
8
- // @TODO this should be deleted once we align on map type name
9
7
  RTYPE_MAP_ALT := { Name: "StdMap", Version: "1" }
10
8
  RTYPE_MAP_EPH := { Name: "EphStdMap", Version: "1" }
11
9
 
@@ -33,7 +31,6 @@ RTYPE_WORKDIR_FILL_RULES := { Name: "WorkdirFill/rules", Version: "1" }
33
31
  RTYPE_WORKDIR_SAVE := { Name: "WorkdirSave", Version: "1" }
34
32
  RTYPE_WORKDIR_SAVE_RULES := { Name: "WorkdirSave/rules", Version: "1" }
35
33
 
36
- /** Main resource type of representing a PL error */
37
34
  RTYPE_JSON_ERROR := { Name: "json/resourceError", Version: "1"}
38
35
 
39
36
  FTYPE_OTW := "OTW" // Generic one-time writable field. The value of this field can be set only once.
@@ -43,33 +40,33 @@ FTYPE_OUTPUT := "output"
43
40
  FTYPE_DYNAMIC := "dynamic"
44
41
 
45
42
  export ll.toStrict({
46
- FTYPE_OTW : FTYPE_OTW,
47
- FTYPE_SERVICE : FTYPE_SERVICE,
48
- FTYPE_INPUT : FTYPE_INPUT,
49
- FTYPE_OUTPUT : FTYPE_OUTPUT,
50
- FTYPE_DYNAMIC : FTYPE_DYNAMIC,
43
+ FTYPE_OTW : FTYPE_OTW,
44
+ FTYPE_SERVICE : FTYPE_SERVICE,
45
+ FTYPE_INPUT : FTYPE_INPUT,
46
+ FTYPE_OUTPUT : FTYPE_OUTPUT,
47
+ FTYPE_DYNAMIC : FTYPE_DYNAMIC,
51
48
 
52
- RTYPE_BINARY_MAP : RTYPE_BINARY_MAP,
53
- RTYPE_BINARY_VALUE : RTYPE_BINARY_VALUE,
54
- RTYPE_BLOB_MAP : RTYPE_BLOB_MAP,
55
- RTYPE_BOBJECT_SPEC : RTYPE_BOBJECT_SPEC,
56
- RTYPE_BRESOLVE_CHOICE : RTYPE_BRESOLVE_CHOICE,
57
- RTYPE_BRESOLVE_FIRST : RTYPE_BRESOLVE_FIRST,
58
- RTYPE_BRESOLVE_NO_RESULT : RTYPE_BRESOLVE_NO_RESULT,
59
- RTYPE_CONTEXT : RTYPE_CONTEXT,
60
- RTYPE_CONTEXT_END : RTYPE_CONTEXT_END,
61
- RTYPE_JSON : RTYPE_JSON,
62
- RTYPE_MAP : RTYPE_MAP,
63
- RTYPE_MAP_ALT : RTYPE_MAP_ALT,
64
- RTYPE_MAP_EPH : RTYPE_MAP_EPH,
65
- RTYPE_QUERY_RESULT : RTYPE_QUERY_RESULT,
66
- RTYPE_OBJECT_SPEC : RTYPE_OBJECT_SPEC,
67
- RTYPE_RENDER_EPH_TEMPLATE : RTYPE_RENDER_EPH_TEMPLATE,
68
- RTYPE_RENDER_TEMPLATE : RTYPE_RENDER_TEMPLATE,
69
- RTYPE_WORKDIR_CREATE : RTYPE_WORKDIR_CREATE,
70
- RTYPE_WORKDIR_FILL : RTYPE_WORKDIR_FILL,
71
- RTYPE_WORKDIR_FILL_RULES : RTYPE_WORKDIR_FILL_RULES,
72
- RTYPE_WORKDIR_SAVE : RTYPE_WORKDIR_SAVE,
73
- RTYPE_WORKDIR_SAVE_RULES : RTYPE_WORKDIR_SAVE_RULES,
74
- RTYPE_JSON_ERROR : RTYPE_JSON_ERROR
49
+ RTYPE_BINARY_MAP : RTYPE_BINARY_MAP,
50
+ RTYPE_BINARY_VALUE : RTYPE_BINARY_VALUE,
51
+ RTYPE_BLOB_MAP : RTYPE_BLOB_MAP,
52
+ RTYPE_BOBJECT_SPEC : RTYPE_BOBJECT_SPEC,
53
+ RTYPE_BRESOLVE_CHOICE : RTYPE_BRESOLVE_CHOICE,
54
+ RTYPE_BRESOLVE_FIRST : RTYPE_BRESOLVE_FIRST,
55
+ RTYPE_BRESOLVE_NO_RESULT : RTYPE_BRESOLVE_NO_RESULT,
56
+ RTYPE_CONTEXT : RTYPE_CONTEXT,
57
+ RTYPE_CONTEXT_END : RTYPE_CONTEXT_END,
58
+ RTYPE_JSON : RTYPE_JSON,
59
+ RTYPE_MAP : RTYPE_MAP,
60
+ RTYPE_MAP_ALT : RTYPE_MAP_ALT,
61
+ RTYPE_MAP_EPH : RTYPE_MAP_EPH,
62
+ RTYPE_QUERY_RESULT : RTYPE_QUERY_RESULT,
63
+ RTYPE_OBJECT_SPEC : RTYPE_OBJECT_SPEC,
64
+ RTYPE_RENDER_EPH_TEMPLATE : RTYPE_RENDER_EPH_TEMPLATE,
65
+ RTYPE_RENDER_TEMPLATE : RTYPE_RENDER_TEMPLATE,
66
+ RTYPE_WORKDIR_CREATE : RTYPE_WORKDIR_CREATE,
67
+ RTYPE_WORKDIR_FILL : RTYPE_WORKDIR_FILL,
68
+ RTYPE_WORKDIR_FILL_RULES : RTYPE_WORKDIR_FILL_RULES,
69
+ RTYPE_WORKDIR_SAVE : RTYPE_WORKDIR_SAVE,
70
+ RTYPE_WORKDIR_SAVE_RULES : RTYPE_WORKDIR_SAVE_RULES,
71
+ RTYPE_JSON_ERROR : RTYPE_JSON_ERROR
75
72
  })
@@ -5,25 +5,25 @@ pkg := import("@platforma-sdk/workflow-tengo:exec.package")
5
5
  path := import("@platforma-sdk/workflow-tengo:path")
6
6
 
7
7
  rVenvInputSchema := {
8
- operationMode: "string",
9
- toolset: "string",
10
- dependencies: {"any": "string"},
11
- software: validation.reference,
8
+ operationMode: "string",
9
+ toolset: "string",
10
+ dependencies: {"any": "string"},
11
+ software: validation.reference,
12
12
 
13
- rDescriptor: pkg.runEnvDescriptorScheme,
14
- R: validation.reference
13
+ rDescriptor: pkg.runEnvDescriptorScheme,
14
+ R: validation.reference
15
15
  }
16
16
 
17
17
  runRBuilder := func(wd, rPackage, rDescriptor) {
18
- return runcmd.builder(wd).
19
- ref("r-run-environment", rPackage).
20
- substitutionRule("{R}", "r-run-environment").
21
- addToPath(path.join("{R}", rDescriptor.binDir), true).
22
- envVar("R_HOME_DIR", "{R}").
23
- envVar("RENV_PATHS_ROOT", path.join("{R}", "renv-root"))
18
+ return runcmd.builder(wd).
19
+ ref("r-run-environment", rPackage).
20
+ substitutionRule("{R}", "r-run-environment").
21
+ addToPath(path.join("{R}", rDescriptor.binDir), true).
22
+ envVar("R_HOME_DIR", "{R}").
23
+ envVar("RENV_PATHS_ROOT", path.join("{R}", "renv-root"))
24
24
  }
25
25
 
26
26
  export ll.toStrict({
27
- rVenvInputSchema : rVenvInputSchema,
28
- runRBuilder : runRBuilder
27
+ rVenvInputSchema : rVenvInputSchema,
28
+ runRBuilder : runRBuilder
29
29
  })
@@ -8,179 +8,170 @@ smart := import("@platforma-sdk/workflow-tengo:smart")
8
8
  render := import("@platforma-sdk/workflow-tengo:render")
9
9
  pkg := import("@platforma-sdk/workflow-tengo:exec.package")
10
10
  internal := import("@platforma-sdk/workflow-tengo:exec.R.internal")
11
- runenv := import("@platforma-sdk/workflow-tengo:exec.runenv")
12
11
 
13
12
  _OUTPUT_RUN_ENV := "runEnv"
14
13
 
15
14
  rVenvBuilder := func() {
16
- self := undefined
17
-
18
- opMode := "remote"
19
- toolset := "renv"
20
- rDescriptor := undefined
21
- softwareRef := undefined
22
- dependencies := undefined
23
- cache := 0
24
-
25
- self = {
26
- operationMode: func(mode) {
27
- validation.assertJsonSchema(mode, "string",
28
- "exec.R.operationMode: <mode> must be string")
29
-
30
- ll.assert(mode == "remote" || mode == "dev-local",
31
- "exec.R.operationMode: unsupported operation mode: 'remote', 'dev-local' are valid in this version of workflow-tengo SDK")
32
-
33
- opMode = mode
34
- return self
35
- },
36
-
37
- useToolset: func(name) {
38
- validation.assertJsonSchema(name, "string",
39
- "exec.R.useToolset: <name> must be valid name of R packaging toolset (i.e. 'renv')")
40
- ll.assert(name != "", "exec.R.useToolset: toolset name must not be empty")
41
-
42
- toolset = name
43
- return self
44
- },
45
-
46
- runEnvDescriptor: func(descriptor) {
47
- validation.assertJsonSchema(descriptor, pkg.runEnvDescriptorScheme, "exec.R.runEnvDescriptor: <descriptor> must be run environment specification")
48
- ll.assert(descriptor.type == "R", "exec.R.runEnvDescriptor: not a 'R' run environment: %q", descriptor.type)
49
-
50
- rDescriptor = ll.fromStrict(descriptor)
51
- return self
52
- },
53
-
54
- software: func(pkgRef) {
55
- validation.assertJsonSchema(pkgRef, validation.reference, "exec.R.software: <pkgRef> must be a reference to software package")
56
-
57
- softwareRef = pkgRef
58
- return self
59
- },
60
-
61
- dependencies: func(deps) {
62
- validation.assertJsonSchema(deps, { "any": "string" }, "exec.R.dependencies: <deps> must be map of reference file paths")
63
-
64
- dependencies = deps
65
- return self
66
- },
67
-
68
- /**
69
- * Sets the cache time in milliseconds.
70
- *
71
- * @param millis: number
72
- */
73
- cacheMillis: func(millis) {
74
- ll.assert(is_int(millis) && millis > 0, "exec.R.cacheMillis: cache time must be a number of milliseconds")
75
- cache = millis * times.millisecond
76
- return self
77
- },
78
-
79
- /**
80
- * Sets the cache time in seconds.
81
- *
82
- * @param seconds: number
83
- */
84
- cacheSeconds: func(seconds) {
85
- ll.assert(is_int(seconds) && seconds > 0, "exec.R.cacheSeconds: cache time must be a number of seconds")
86
- cache = seconds * times.second
87
- return self
88
- },
89
-
90
- /**
91
- * Sets the cache time in minutes.
92
- *
93
- * @param minutes: number
94
- */
95
- cacheMinutes: func(minutes) {
96
- ll.assert(is_int(minutes) && minutes > 0, "exec.R.cacheMinutes: cache time must be a number of minutes")
97
- cache = minutes * times.minute
98
- return self
99
- },
100
-
101
- /**
102
- * Sets the cache time in hours.
103
- *
104
- * @param hours: number
105
- */
106
- cacheHours: func(hours) {
107
- ll.assert(is_int(hours) && hours > 0, "exec.R.cacheHours: cache time must be a number of hours")
108
- cache = hours * times.hour
109
- return self
110
- },
111
-
112
- /**
113
- * Sets the cache time in days
114
- *
115
- * @param days: number
116
- */
117
- cacheDays: func(days) {
118
- ll.assert(is_int(days) && days > 0, "exec.R.cacheDays: cache time must be a number of days")
119
- cache = days * times.hour * 24
120
- return self
121
- },
122
-
123
- /**
124
- * @deprecated, use cacheMillis, cacheSeconds, cacheMinutes, cacheHours and cacheDays instead.
125
- * Sets the cache time.
126
- *
127
- * @param time: duration - the cache time from 'times' library.
128
- */
129
- cache: func(time) {
130
- ll.assert(
131
- is_int(time) && time > times.millisecond,
132
- "exec.R.cache: cache time must be an integer. " +
133
- "Did you forget to import a standard tengo library 'times'?")
134
- cache = time
135
- return self
136
- },
137
-
138
- build: func() {
139
- archive := pkg.get(rDescriptor.registry, rDescriptor.package).archive()
140
- rPkg := pkg.install(archive).package()
141
-
142
- rVenvInputs := {
143
- operationMode: opMode,
144
- toolset: toolset,
145
- dependencies: dependencies,
146
- software: softwareRef,
147
- rDescriptor: rDescriptor,
148
- R: rPkg
149
- }
150
-
151
- validation.assertJsonSchema(rVenvInputs, internal.rVenvInputSchema, "incomplete R runenv configuration")
152
-
153
- tpl := render.create(assets.importTemplate("@platforma-sdk/workflow-tengo:exec.R.create-renv"), rVenvInputs)
154
-
155
- self := undefined
156
- self = ll.toStrict(oop.inherit(tpl, {
157
- /**
158
- * R virtual environment with all dependencies installed.
159
- *
160
- * @return renv: smart.field - a reference to the R portable run environment.
161
- */
162
- venv: func() {
163
- return tpl.output(_OUTPUT_RUN_ENV, cache)
164
- },
165
-
166
- /**
167
- * R runtime used for R virtual environment creation.
168
- *
169
- * @return R: smart.Field - a reference to the R runtime.
170
- */
171
- R: func() {
172
- return rPkg
173
- }
174
- }))
175
-
176
- return self
177
- }
178
- }
179
-
180
- return self
15
+ self := undefined
16
+
17
+ opMode := "remote"
18
+ toolset := "renv"
19
+ rDescriptor := undefined
20
+ softwareRef := undefined
21
+ dependencies := undefined
22
+ cache := 0
23
+
24
+ self = {
25
+ operationMode: func(mode) {
26
+ validation.assertJsonSchema(mode, "string",
27
+ "exec.R.operationMode: <mode> must be string")
28
+
29
+ ll.assert(mode == "remote" || mode == "dev-local",
30
+ "exec.R.operationMode: unsupported operation mode: 'remote', 'dev-local' are valid in this version of workflow-tengo SDK")
31
+
32
+ opMode = mode
33
+ return self
34
+ },
35
+
36
+ useToolset: func(name) {
37
+ validation.assertJsonSchema(name, "string",
38
+ "exec.R.useToolset: <name> must be valid name of R packaging toolset (i.e. 'renv')")
39
+ ll.assert(name != "", "exec.R.useToolset: toolset name must not be empty")
40
+
41
+ toolset = name
42
+ return self
43
+ },
44
+
45
+ runEnvDescriptor: func(descriptor) {
46
+ validation.assertJsonSchema(descriptor, pkg.runEnvDescriptorScheme, "exec.R.runEnvDescriptor: <descriptor> must be run environment specification")
47
+ ll.assert(descriptor.type == "R", "exec.R.runEnvDescriptor: not a 'R' run environment: %q", descriptor.type)
48
+
49
+ rDescriptor = ll.fromStrict(descriptor)
50
+ return self
51
+ },
52
+
53
+ software: func(pkgRef) {
54
+ validation.assertJsonSchema(pkgRef, validation.reference, "exec.R.software: <pkgRef> must be a reference to software package")
55
+
56
+ softwareRef = pkgRef
57
+ return self
58
+ },
59
+
60
+ dependencies: func(deps) {
61
+ validation.assertJsonSchema(deps, { "any": "string" }, "exec.R.dependencies: <deps> must be map of reference file paths")
62
+
63
+ dependencies = deps
64
+ return self
65
+ },
66
+
67
+
68
+
69
+
70
+
71
+ cacheMillis: func(millis) {
72
+ ll.assert(is_int(millis) && millis > 0, "exec.R.cacheMillis: cache time must be a number of milliseconds")
73
+ cache = millis * times.millisecond
74
+ return self
75
+ },
76
+
77
+
78
+
79
+
80
+
81
+ cacheSeconds: func(seconds) {
82
+ ll.assert(is_int(seconds) && seconds > 0, "exec.R.cacheSeconds: cache time must be a number of seconds")
83
+ cache = seconds * times.second
84
+ return self
85
+ },
86
+
87
+
88
+
89
+
90
+
91
+ cacheMinutes: func(minutes) {
92
+ ll.assert(is_int(minutes) && minutes > 0, "exec.R.cacheMinutes: cache time must be a number of minutes")
93
+ cache = minutes * times.minute
94
+ return self
95
+ },
96
+
97
+
98
+
99
+
100
+
101
+ cacheHours: func(hours) {
102
+ ll.assert(is_int(hours) && hours > 0, "exec.R.cacheHours: cache time must be a number of hours")
103
+ cache = hours * times.hour
104
+ return self
105
+ },
106
+
107
+
108
+
109
+
110
+
111
+ cacheDays: func(days) {
112
+ ll.assert(is_int(days) && days > 0, "exec.R.cacheDays: cache time must be a number of days")
113
+ cache = days * times.hour * 24
114
+ return self
115
+ },
116
+
117
+
118
+
119
+
120
+
121
+
122
+ cache: func(time) {
123
+ ll.assert(
124
+ is_int(time) && time > times.millisecond,
125
+ "exec.R.cache: cache time must be an integer. " +
126
+ "Did you forget to import a standard tengo library 'times'?")
127
+ cache = time
128
+ return self
129
+ },
130
+
131
+ build: func() {
132
+ archive := pkg.get(rDescriptor.registry, rDescriptor.package).archive()
133
+ rPkg := pkg.install(archive).package()
134
+
135
+ rVenvInputs := {
136
+ operationMode: opMode,
137
+ toolset: toolset,
138
+ dependencies: dependencies,
139
+ software: softwareRef,
140
+ rDescriptor: rDescriptor,
141
+ R: rPkg
142
+ }
143
+
144
+ validation.assertJsonSchema(rVenvInputs, internal.rVenvInputSchema, "incomplete R runenv configuration")
145
+
146
+ tpl := render.create(assets.importTemplate("@platforma-sdk/workflow-tengo:exec.R.create-renv"), rVenvInputs)
147
+
148
+ self := undefined
149
+ self = ll.toStrict(oop.inherit(tpl, {
150
+
151
+
152
+
153
+
154
+ venv: func() {
155
+ return tpl.output(_OUTPUT_RUN_ENV, cache)
156
+ },
157
+
158
+
159
+
160
+
161
+
162
+ R: func() {
163
+ return rPkg
164
+ }
165
+ }))
166
+
167
+ return self
168
+ }
169
+ }
170
+
171
+ return self
181
172
  }
182
173
 
183
174
 
184
175
  export ll.toStrict({
185
- rVenvBuilder : rVenvBuilder
176
+ rVenvBuilder : rVenvBuilder
186
177
  })