@platforma-sdk/workflow-tengo 2.9.6 → 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.
- package/dist/tengo/lib/assets.lib.tengo +52 -52
- package/dist/tengo/lib/assets.swinfo.lib.tengo +45 -45
- package/dist/tengo/lib/constants.lib.tengo +32 -32
- package/dist/tengo/lib/exec.R.internal.lib.tengo +29 -29
- package/dist/tengo/lib/exec.R.lib.tengo +166 -166
- package/dist/tengo/lib/exec.constants.lib.tengo +4 -4
- package/dist/tengo/lib/exec.descriptor.lib.tengo +31 -31
- package/dist/tengo/lib/exec.internal.lib.tengo +297 -297
- package/dist/tengo/lib/exec.lib.tengo +815 -815
- package/dist/tengo/lib/exec.monetization.lib.tengo +130 -130
- package/dist/tengo/lib/exec.package.lib.tengo +212 -212
- package/dist/tengo/lib/exec.python.internal.lib.tengo +6 -6
- package/dist/tengo/lib/exec.python.lib.tengo +146 -146
- package/dist/tengo/lib/exec.runcmd.lib.tengo +371 -371
- package/dist/tengo/lib/exec.runenv.lib.tengo +92 -92
- package/dist/tengo/lib/exec.stream.lib.tengo +40 -40
- package/dist/tengo/lib/file.internal.lib.tengo +77 -77
- package/dist/tengo/lib/file.lib.tengo +57 -57
- package/dist/tengo/lib/ll.lib.tengo +244 -244
- package/dist/tengo/lib/maps.lib.tengo +152 -152
- package/dist/tengo/lib/objects.lib.tengo +13 -13
- package/dist/tengo/lib/oop.lib.tengo +19 -19
- package/dist/tengo/lib/path.lib.tengo +125 -125
- package/dist/tengo/lib/pframes.constants.lib.tengo +28 -28
- package/dist/tengo/lib/pframes.export-pcolumn.lib.tengo +33 -33
- package/dist/tengo/lib/pframes.lib.tengo +43 -43
- package/dist/tengo/lib/pframes.ll.lib.tengo +72 -72
- package/dist/tengo/lib/pframes.pcolumn.lib.tengo +49 -49
- package/dist/tengo/lib/pframes.spec.lib.tengo +96 -96
- package/dist/tengo/lib/pframes.util.lib.tengo +288 -288
- package/dist/tengo/lib/pframes.xsv.lib.tengo +272 -272
- package/dist/tengo/lib/render.lib.tengo +75 -75
- package/dist/tengo/lib/sets.lib.tengo +68 -68
- package/dist/tengo/lib/slices.lib.tengo +258 -155
- package/dist/tengo/lib/smart.lib.tengo +1069 -1069
- package/dist/tengo/lib/test.lib.tengo +161 -161
- package/dist/tengo/lib/tpl.lib.tengo +515 -515
- package/dist/tengo/lib/tpl.state-await.lib.tengo +240 -240
- package/dist/tengo/lib/tpl.util.lib.tengo +9 -9
- package/dist/tengo/lib/validation.lib.tengo +378 -378
- package/dist/tengo/lib/workdir.lib.tengo +331 -331
- package/dist/tengo/lib/workdir.proc.lib.tengo +144 -144
- package/dist/tengo/lib/workdir.save.lib.tengo +130 -130
- package/dist/tengo/lib/workflow.bobject.lib.tengo +26 -26
- package/dist/tengo/lib/workflow.bquery.lib.tengo +165 -165
- package/dist/tengo/lib/workflow.constants.lib.tengo +2 -2
- package/dist/tengo/lib/workflow.context.lib.tengo +32 -32
- package/dist/tengo/lib/workflow.lib.tengo +206 -206
- package/dist/tengo/tpl/exec.R.create-renv.plj.gz +0 -0
- package/dist/tengo/tpl/exec.exec.plj.gz +0 -0
- package/dist/tengo/tpl/exec.monetization_to_json.plj.gz +0 -0
- package/dist/tengo/tpl/exec.python.create-venv.plj.gz +0 -0
- package/dist/tengo/tpl/exec.python.install-deps.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.aggregate.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-multiple-pcolumns.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.export-single-pcolumn.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.import-dir.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.map-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.xsv-export-pframe.plj.gz +0 -0
- package/dist/tengo/tpl/pframes.xsv-import-map.plj.gz +0 -0
- package/dist/tengo/tpl/workdir.save.plj.gz +0 -0
- package/dist/tengo/tpl/workflow.build-ctx.plj.gz +0 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/** The library provides all things to work with a monetization. */
|
|
2
2
|
|
|
3
3
|
ll := import("@platforma-sdk/workflow-tengo:ll")
|
|
4
4
|
validation := import("@platforma-sdk/workflow-tengo:validation")
|
|
@@ -14,175 +14,175 @@ constants := import("@platforma-sdk/workflow-tengo:exec.constants")
|
|
|
14
14
|
|
|
15
15
|
_JWT_TOKEN_RESULT_ENV := "PLATFORMA_MNZ_JWT"
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/** Just creates a new monetization as a map of params. */
|
|
18
18
|
init := func() {
|
|
19
|
-
return ll.toStrict({
|
|
20
|
-
enabled: false,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
productName: "",
|
|
19
|
+
return ll.toStrict({
|
|
20
|
+
enabled: false,
|
|
24
21
|
|
|
22
|
+
// product name of monetization, e.g. "mixcr_analyze"
|
|
23
|
+
productName: "",
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
}
|
|
25
|
+
// file name to the param, e.g. {fileName: { arg: "dataset", collect: ["size", "lines", "sha256"] }}
|
|
26
|
+
fileParams: {}
|
|
27
|
+
})
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
fileParamsSchema := {
|
|
31
|
-
"arg": "string",
|
|
32
|
-
"collect": [`string,regex=size|lines|sha256`]
|
|
31
|
+
"arg": "string",
|
|
32
|
+
"collect": [`string,regex=size|lines|sha256`]
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
schema := {
|
|
36
|
-
"enabled": "bool",
|
|
37
|
-
"productName": "string",
|
|
38
|
-
"fileParams": {"any": fileParamsSchema}
|
|
36
|
+
"enabled": "bool",
|
|
37
|
+
"productName": "string",
|
|
38
|
+
"fileParams": {"any": fileParamsSchema}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
/** Same as validation.assertJsonSchema(params, fileParamsSchema, ...),
|
|
42
|
+
* but with prettier errors for clients. */
|
|
43
43
|
_validateParams := func(params) {
|
|
44
|
-
ll.assert(ll.isMap(params), "monetization.validateParams(): mnz params must be a map")
|
|
45
|
-
ll.assert(is_string(params.arg), "monetization.validateParams(): 'arg' in {\"mnz\": {...}} param must be a string")
|
|
46
|
-
ll.assert(is_array(params.collect) && len(params.collect) > 0, "monetization.validateParams(): 'collect' in {\"mnz\": {...}} param must be non-empty an array")
|
|
44
|
+
ll.assert(ll.isMap(params), "monetization.validateParams(): mnz params must be a map")
|
|
45
|
+
ll.assert(is_string(params.arg), "monetization.validateParams(): 'arg' in {\"mnz\": {...}} param must be a string")
|
|
46
|
+
ll.assert(is_array(params.collect) && len(params.collect) > 0, "monetization.validateParams(): 'collect' in {\"mnz\": {...}} param must be non-empty an array")
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
_validateIsReady := func(mnz) {
|
|
50
|
-
validation.assertJsonSchema(mnz, schema,
|
|
51
|
-
"monetization.assertIsReady(): monetization does not fit schema")
|
|
52
|
-
ll.assert(len(mnz.productName) > 0,
|
|
53
|
-
"monetization.assertIsReady(): product name must be set")
|
|
54
|
-
ll.assert(len(mnz.fileParams) > 0,
|
|
55
|
-
"monetization.assertIsReady(): at least 1 file param must be set")
|
|
50
|
+
validation.assertJsonSchema(mnz, schema,
|
|
51
|
+
"monetization.assertIsReady(): monetization does not fit schema")
|
|
52
|
+
ll.assert(len(mnz.productName) > 0,
|
|
53
|
+
"monetization.assertIsReady(): product name must be set")
|
|
54
|
+
ll.assert(len(mnz.fileParams) > 0,
|
|
55
|
+
"monetization.assertIsReady(): at least 1 file param must be set")
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
/** Enables the monetization for a product. */
|
|
59
59
|
enable := func(mnz, productName) {
|
|
60
|
-
ll.assert(is_string(productName),
|
|
61
|
-
"monetization.enable(): product name must be a string, got %v", productName)
|
|
60
|
+
ll.assert(is_string(productName),
|
|
61
|
+
"monetization.enable(): product name must be a string, got %v", productName)
|
|
62
62
|
|
|
63
|
-
validation.assertJsonSchema(mnz, schema,
|
|
64
|
-
"monetization.enable(): mnz object does not fit schema")
|
|
63
|
+
validation.assertJsonSchema(mnz, schema,
|
|
64
|
+
"monetization.enable(): mnz object does not fit schema")
|
|
65
65
|
|
|
66
|
-
mnz.enabled = true
|
|
67
|
-
mnz.productName = productName
|
|
66
|
+
mnz.enabled = true
|
|
67
|
+
mnz.productName = productName
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
/** Is this monetization enabled and should run? */
|
|
71
71
|
shouldRun := func(mnz) {
|
|
72
|
-
if mnz.enabled {
|
|
73
|
-
_validateIsReady(mnz)
|
|
74
|
-
return true
|
|
75
|
-
}
|
|
72
|
+
if mnz.enabled {
|
|
73
|
+
_validateIsReady(mnz)
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
76
|
|
|
77
|
-
return false
|
|
77
|
+
return false
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
toJson := func(mnz) {
|
|
81
|
-
validation.assertJsonSchema(mnz, schema,
|
|
82
|
-
"monetization.toJson(): monetization object does not fit json schema")
|
|
81
|
+
validation.assertJsonSchema(mnz, schema,
|
|
82
|
+
"monetization.toJson(): monetization object does not fit json schema")
|
|
83
83
|
|
|
84
|
-
return ll.fromStrict(mnz)
|
|
84
|
+
return ll.fromStrict(mnz)
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
/** Adds monetization parameters by a file. */
|
|
88
88
|
addFileParams := func(mnz, fileName, params) {
|
|
89
|
-
validation.assertJsonSchema(mnz, schema,
|
|
90
|
-
"monetization.addFileParams(): monetization object does not fit json schema")
|
|
89
|
+
validation.assertJsonSchema(mnz, schema,
|
|
90
|
+
"monetization.addFileParams(): monetization object does not fit json schema")
|
|
91
91
|
|
|
92
|
-
_validateParams(params)
|
|
92
|
+
_validateParams(params)
|
|
93
93
|
|
|
94
|
-
validation.assertJsonSchema(params, fileParamsSchema,
|
|
95
|
-
"monetization.addFileParams(): file params does not fit json schema")
|
|
94
|
+
validation.assertJsonSchema(params, fileParamsSchema,
|
|
95
|
+
"monetization.addFileParams(): file params does not fit json schema")
|
|
96
96
|
|
|
97
|
-
ll.assert(mnz.enabled,
|
|
98
|
-
"monetization.addFileParams(): monetization must be explicitly enabled by enableMnz(productName) function")
|
|
97
|
+
ll.assert(mnz.enabled,
|
|
98
|
+
"monetization.addFileParams(): monetization must be explicitly enabled by enableMnz(productName) function")
|
|
99
99
|
|
|
100
|
-
ll.assert(is_string(fileName),
|
|
101
|
-
"monetization.addFileParams(): file name must be a string.")
|
|
100
|
+
ll.assert(is_string(fileName),
|
|
101
|
+
"monetization.addFileParams(): file name must be a string.")
|
|
102
102
|
|
|
103
|
-
mnz.fileParams[fileName] = params
|
|
103
|
+
mnz.fileParams[fileName] = params
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Runs monetization binary on a workdir with all files, and returns a new workdir and a resulted jwt token.
|
|
108
|
+
* All resources are ephemeral,
|
|
109
|
+
* the deduplication should be above this level.
|
|
110
|
+
*
|
|
111
|
+
* @param: mnz: monetization -- see a beginning of this file.
|
|
112
|
+
* @param: wd: workdir -- workdir where all files from mnz.fileParams already exist. */
|
|
113
113
|
run := func(mnz, wd, queue) {
|
|
114
|
-
_validateIsReady(mnz)
|
|
115
|
-
|
|
116
|
-
mnzSw := assets.importSoftware("@platforma-open/milaboratories.software-small-binaries:mnz-client")
|
|
117
|
-
|
|
118
|
-
builder := runcmd.builder(wd)
|
|
119
|
-
|
|
120
|
-
exprType := desc.canBackendUseExpressions() ? constants.ARG_TYPE_EXPRESSION : constants.ARG_TYPE_VAR
|
|
121
|
-
|
|
122
|
-
builder.envTyped("MI_LICENSE", exprType, "{secrets.MI_LICENSE}")
|
|
123
|
-
|
|
124
|
-
opts := internal.swToRunCmdOptions(mnzSw.name, mnzSw.version, mnzSw.descriptor)
|
|
125
|
-
|
|
126
|
-
for _, varInfo in opts.variables {
|
|
127
|
-
builder.ref(varInfo.refName, varInfo.reference)
|
|
128
|
-
builder.substitutionRule(varInfo.varName, varInfo.refName)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
builder.cmdTyped(exprType, opts.cmd.value)
|
|
132
|
-
for _, arg in opts.args {
|
|
133
|
-
|
|
134
|
-
builder.argTyped(exprType, arg)
|
|
135
|
-
}
|
|
136
|
-
builder.arg("-productName").arg(mnz.productName)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
for fileName, param in mnz.fileParams {
|
|
140
|
-
|
|
141
|
-
toCollect := text.join(param.collect, ",")
|
|
142
|
-
arg := fmt.sprintf("%s:file:%s:%s", param.arg, fileName, toCollect)
|
|
143
|
-
builder.arg(arg)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
builder.inQueue(queue)
|
|
147
|
-
stdout := "mnz_stdout.txt"
|
|
148
|
-
builder.stdout(stdout)
|
|
149
|
-
run := builder.build()
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
savedWd := workdir.save(run.workdir).
|
|
153
|
-
saveFileContent(stdout).
|
|
154
|
-
build()
|
|
155
|
-
|
|
156
|
-
jwtResultAsBytes := savedWd.filesContent.getFutureInputField(stdout)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
jwtResultAsString := render.create(
|
|
162
|
-
assets.importTemplate("@platforma-sdk/workflow-tengo:exec.monetization_to_json"),
|
|
163
|
-
{ resource: jwtResultAsBytes }
|
|
164
|
-
).output("jsonedData")
|
|
165
|
-
|
|
166
|
-
return ll.toStrict({
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
wdAfter: savedWd.workdir,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
jwtEnvName: _JWT_TOKEN_RESULT_ENV,
|
|
176
|
-
jwtEnvValue: jwtResultAsString
|
|
177
|
-
})
|
|
114
|
+
_validateIsReady(mnz)
|
|
115
|
+
|
|
116
|
+
mnzSw := assets.importSoftware("@platforma-open/milaboratories.software-small-binaries:mnz-client")
|
|
117
|
+
|
|
118
|
+
builder := runcmd.builder(wd)
|
|
119
|
+
|
|
120
|
+
exprType := desc.canBackendUseExpressions() ? constants.ARG_TYPE_EXPRESSION : constants.ARG_TYPE_VAR
|
|
121
|
+
|
|
122
|
+
builder.envTyped("MI_LICENSE", exprType, "{secrets.MI_LICENSE}")
|
|
123
|
+
|
|
124
|
+
opts := internal.swToRunCmdOptions(mnzSw.name, mnzSw.version, mnzSw.descriptor)
|
|
125
|
+
// load pkg var that points to mnz-client location.
|
|
126
|
+
for _, varInfo in opts.variables {
|
|
127
|
+
builder.ref(varInfo.refName, varInfo.reference)
|
|
128
|
+
builder.substitutionRule(varInfo.varName, varInfo.refName)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
builder.cmdTyped(exprType, opts.cmd.value)
|
|
132
|
+
for _, arg in opts.args {
|
|
133
|
+
// now mnz-client doesn't have additional args; this line is just in case.
|
|
134
|
+
builder.argTyped(exprType, arg)
|
|
135
|
+
}
|
|
136
|
+
builder.arg("-productName").arg(mnz.productName)
|
|
137
|
+
|
|
138
|
+
// load file params
|
|
139
|
+
for fileName, param in mnz.fileParams {
|
|
140
|
+
// param is of fileParamsSchema type
|
|
141
|
+
toCollect := text.join(param.collect, ",")
|
|
142
|
+
arg := fmt.sprintf("%s:file:%s:%s", param.arg, fileName, toCollect)
|
|
143
|
+
builder.arg(arg)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
builder.inQueue(queue)
|
|
147
|
+
stdout := "mnz_stdout.txt"
|
|
148
|
+
builder.stdout(stdout)
|
|
149
|
+
run := builder.build()
|
|
150
|
+
|
|
151
|
+
// save mnz_stdout.txt
|
|
152
|
+
savedWd := workdir.save(run.workdir).
|
|
153
|
+
saveFileContent(stdout).
|
|
154
|
+
build()
|
|
155
|
+
|
|
156
|
+
jwtResultAsBytes := savedWd.filesContent.getFutureInputField(stdout)
|
|
157
|
+
|
|
158
|
+
// runcmd refs gets only json/objects as values,
|
|
159
|
+
// but workdir save returns binary:1 resource type.
|
|
160
|
+
// Hence here we have to convert it to the json's string.
|
|
161
|
+
jwtResultAsString := render.create(
|
|
162
|
+
assets.importTemplate("@platforma-sdk/workflow-tengo:exec.monetization_to_json"),
|
|
163
|
+
{ resource: jwtResultAsBytes }
|
|
164
|
+
).output("jsonedData")
|
|
165
|
+
|
|
166
|
+
return ll.toStrict({
|
|
167
|
+
// other commands should run on this wd,
|
|
168
|
+
// or else they will run concurrently
|
|
169
|
+
// with monetization.
|
|
170
|
+
wdAfter: savedWd.workdir,
|
|
171
|
+
|
|
172
|
+
// mnz-client returns jwt token
|
|
173
|
+
// that we will pass to the next command as env.
|
|
174
|
+
// If we need to change env to a file, that's the place.
|
|
175
|
+
jwtEnvName: _JWT_TOKEN_RESULT_ENV,
|
|
176
|
+
jwtEnvValue: jwtResultAsString
|
|
177
|
+
})
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
export ll.toStrict({
|
|
181
|
-
init: init,
|
|
182
|
-
schema: schema,
|
|
183
|
-
enable: enable,
|
|
184
|
-
shouldRun: shouldRun,
|
|
185
|
-
toJson: toJson,
|
|
186
|
-
addFileParams: addFileParams,
|
|
187
|
-
run: run
|
|
181
|
+
init: init,
|
|
182
|
+
schema: schema,
|
|
183
|
+
enable: enable,
|
|
184
|
+
shouldRun: shouldRun,
|
|
185
|
+
toJson: toJson,
|
|
186
|
+
addFileParams: addFileParams,
|
|
187
|
+
run: run
|
|
188
188
|
})
|