@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.
- package/dist/tengo/lib/assets.lib.tengo +76 -82
- package/dist/tengo/lib/constants.lib.tengo +28 -31
- package/dist/tengo/lib/exec.R.internal.lib.tengo +14 -14
- package/dist/tengo/lib/exec.R.lib.tengo +158 -167
- package/dist/tengo/lib/exec.internal.lib.tengo +222 -234
- package/dist/tengo/lib/exec.lib.tengo +647 -714
- package/dist/tengo/lib/exec.package.lib.tengo +229 -238
- package/dist/tengo/lib/exec.python.internal.lib.tengo +5 -6
- package/dist/tengo/lib/exec.python.lib.tengo +138 -146
- package/dist/tengo/lib/exec.runcmd.lib.tengo +234 -253
- package/dist/tengo/lib/exec.runenv.lib.tengo +88 -92
- package/dist/tengo/lib/exec.stream.lib.tengo +36 -40
- package/dist/tengo/lib/file.internal.lib.tengo +70 -77
- package/dist/tengo/lib/file.lib.tengo +54 -57
- package/dist/tengo/lib/ll.lib.tengo +217 -241
- package/dist/tengo/lib/maps.lib.tengo +98 -106
- package/dist/tengo/lib/objects.lib.tengo +11 -13
- package/dist/tengo/lib/oop.lib.tengo +16 -19
- package/dist/tengo/lib/path.lib.tengo +116 -125
- package/dist/tengo/lib/pframes.constants.lib.tengo +25 -28
- package/dist/tengo/lib/pframes.export-pcolumn.lib.tengo +28 -33
- package/dist/tengo/lib/pframes.lib.tengo +38 -43
- package/dist/tengo/lib/pframes.ll.lib.tengo +70 -73
- package/dist/tengo/lib/pframes.pcolumn.lib.tengo +45 -51
- package/dist/tengo/lib/pframes.spec.lib.tengo +70 -96
- package/dist/tengo/lib/pframes.util.lib.tengo +154 -289
- package/dist/tengo/lib/pframes.xsv.lib.tengo +260 -273
- package/dist/tengo/lib/render.lib.tengo +65 -76
- package/dist/tengo/lib/sets.lib.tengo +61 -68
- package/dist/tengo/lib/slices.lib.tengo +169 -180
- package/dist/tengo/lib/smart.lib.tengo +956 -1069
- package/dist/tengo/lib/test.lib.tengo +129 -161
- package/dist/tengo/lib/tpl.lib.tengo +448 -516
- package/dist/tengo/lib/tpl.state-await.lib.tengo +226 -241
- package/dist/tengo/lib/tpl.util.lib.tengo +4 -9
- package/dist/tengo/lib/validation.lib.tengo +334 -379
- package/dist/tengo/lib/workdir.lib.tengo +309 -332
- package/dist/tengo/lib/workdir.proc.lib.tengo +126 -144
- package/dist/tengo/lib/workdir.save.lib.tengo +113 -130
- package/dist/tengo/lib/workflow.bobject.lib.tengo +21 -26
- package/dist/tengo/lib/workflow.bquery.lib.tengo +140 -166
- package/dist/tengo/lib/workflow.constants.lib.tengo +1 -2
- package/dist/tengo/lib/workflow.context.lib.tengo +27 -32
- package/dist/tengo/lib/workflow.lib.tengo +167 -207
- 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.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 +8 -8
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* A library exposing template functional components */
|
|
2
1
|
|
|
3
2
|
tx := import("tx")
|
|
4
3
|
ll := import("@platforma-sdk/workflow-tengo:ll")
|
|
@@ -13,524 +12,457 @@ validation := import("@platforma-sdk/workflow-tengo:validation")
|
|
|
13
12
|
|
|
14
13
|
bquery := import("@platforma-sdk/workflow-tengo:workflow.bquery")
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
25
23
|
_unmarshal := func(resource, preprocessors) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* A wrapper object around template functionality
|
|
69
|
-
*/
|
|
24
|
+
ll.assert(smart.isResource(resource), "expected resource, found ", resource)
|
|
25
|
+
|
|
26
|
+
self := func(resource) { return _unmarshal(resource, preprocessors) }
|
|
27
|
+
|
|
28
|
+
for preproc in preprocessors {
|
|
29
|
+
if preproc.canParse(resource) {
|
|
30
|
+
return preproc.parse(resource, self)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if smart.isReference(resource) && resource.hasError() {
|
|
35
|
+
ll.panic("input resource has errors: ", resource, resource.getError())
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if smart.isJsonResource(resource) || resource.checkResourceType(constants.RTYPE_BOBJECT_SPEC) {
|
|
39
|
+
|
|
40
|
+
return resource.getDataAsJson()
|
|
41
|
+
} else if smart.isMapResource(resource) || smart.isLockedEphMapResource(resource) {
|
|
42
|
+
|
|
43
|
+
result := {}
|
|
44
|
+
for field, value in resource.inputs() {
|
|
45
|
+
if value.isErrorSet() {
|
|
46
|
+
ll.panic("input %v field has error: %v", field, field.getError().getDataAsJson().message)
|
|
47
|
+
} else if value.isSet() {
|
|
48
|
+
result[field] = _unmarshal(value.getValue(), preprocessors)
|
|
49
|
+
} else {
|
|
50
|
+
result[field] = value
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
return result
|
|
55
|
+
} else {
|
|
56
|
+
return resource
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
70
62
|
tpl := func() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if len(self.prepareQueue) > 0 {
|
|
462
|
-
ll.assert(len(self.definedOutputs) > 0, "outputs should be defined prior to prepare")
|
|
463
|
-
|
|
464
|
-
self.createOutputsAndLock(self.definedOutputs)
|
|
465
|
-
|
|
466
|
-
self.renderPrepare()
|
|
467
|
-
} else {
|
|
468
|
-
|
|
469
|
-
// run body func
|
|
470
|
-
self._validateInputs()
|
|
471
|
-
result := bodyFn(self.inputs())
|
|
472
|
-
ll.assert(ll.isMap(result),
|
|
473
|
-
"expected map from tpl-eph.body() callback. Did you forget 'return' statement?")
|
|
474
|
-
|
|
475
|
-
self.createOutputsAndLock(maps.getKeys(result))
|
|
476
|
-
|
|
477
|
-
// set result to self outputs
|
|
478
|
-
self.setOutputs(result)
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
},
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* Delegates itself to the specified template, i.e. runs specified template and
|
|
485
|
-
* saves its outputs to this.
|
|
486
|
-
*
|
|
487
|
-
* @param tpl: template - specified template
|
|
488
|
-
* @param extraInputs: map - additional inputs to pass to the template
|
|
489
|
-
* @param outputs: array - array of expected outputs to save
|
|
490
|
-
*/
|
|
491
|
-
routeDelegate: func(tpl, extraInputs, outputs) {
|
|
492
|
-
_delegatedOutputs = outputs
|
|
493
|
-
|
|
494
|
-
inputs := self.rawInputs()
|
|
495
|
-
for k, v in extraInputs {
|
|
496
|
-
inputs[k] = v
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
renderer := undefined
|
|
500
|
-
if self.isEphemeral() {
|
|
501
|
-
renderer = render.createEphemeral(tpl, inputs)
|
|
502
|
-
} else {
|
|
503
|
-
renderer = render.create(tpl, inputs)
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
tplOutputs := {}
|
|
507
|
-
for o in outputs {
|
|
508
|
-
tplOutputs[o] = renderer.output(o)
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
self.createOutputsAndLock(outputs)
|
|
512
|
-
self.setOutputs(tplOutputs)
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
return ll.toStrict(self)
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* Singleton instance of this resource
|
|
520
|
-
*/
|
|
63
|
+
self := undefined
|
|
64
|
+
|
|
65
|
+
_renderer := smart.resourceBuilder(ll.getCurrentTemplateRenderer())
|
|
66
|
+
|
|
67
|
+
_rendererType := _renderer.info().Type
|
|
68
|
+
|
|
69
|
+
_isEphemeral := _rendererType.Name == constants.RTYPE_RENDER_EPH_TEMPLATE.Name
|
|
70
|
+
|
|
71
|
+
_hasPrepared := _renderer.get(tplutil.INPUTS_MAP_FIELD).hasField(tplutil.PREPARE_MAP_FIELD_NAME)
|
|
72
|
+
|
|
73
|
+
_preparedMap := _hasPrepared ? _renderer.get(tplutil.INPUTS_MAP_FIELD).get(tplutil.PREPARE_MAP_FIELD_NAME) : undefined
|
|
74
|
+
|
|
75
|
+
_templateId := _renderer.get(tplutil.TEMPLATE_FIELD).id
|
|
76
|
+
|
|
77
|
+
_stateRequests := []
|
|
78
|
+
_delegatedOutputs := []
|
|
79
|
+
|
|
80
|
+
self = {
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
renderer: func() {
|
|
85
|
+
return _renderer
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
isEphemeral: func() {
|
|
91
|
+
return _isEphemeral
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
template: func() {
|
|
97
|
+
return smart.resource(_templateId)
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
_unmarshallers: [bquery.resultUnmarshaller()],
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
registerUnmarshaller: func(preproc) {
|
|
107
|
+
ll.assert(is_undefined(self._inputs), "input preprocessors must be registered before getting inputs")
|
|
108
|
+
self._unmarshallers = append(self._unmarshallers, preproc)
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
rawInputs: func() {
|
|
114
|
+
return self.renderer().get(tplutil.INPUTS_MAP_FIELD).inputs()
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
_inputs: undefined,
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
inputs: func() {
|
|
122
|
+
if self._inputs == undefined {
|
|
123
|
+
inputs := _unmarshal(self.renderer().get(tplutil.INPUTS_MAP_FIELD), self._unmarshallers)
|
|
124
|
+
|
|
125
|
+
pp := inputs[tplutil.PREPARE_MAP_FIELD_NAME]
|
|
126
|
+
if !is_undefined(pp) {
|
|
127
|
+
delete(inputs, tplutil.PREPARE_MAP_FIELD_NAME)
|
|
128
|
+
for k, v in pp {
|
|
129
|
+
ll.assert(is_undefined(inputs[k]), k, " key already exists in inputs map")
|
|
130
|
+
inputs[k] = v
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
self._inputs = inputs
|
|
135
|
+
}
|
|
136
|
+
return self._inputs
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
hasInput: func(name) {
|
|
142
|
+
return self.renderer().get(tplutil.INPUTS_MAP_FIELD).hasField(name)
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
definedOutputs : [],
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
defineOutputs : func(...name) {
|
|
153
|
+
if len(name) == 1 && is_array(name[0]) {
|
|
154
|
+
for v in name[0] {
|
|
155
|
+
self.definedOutputs = append(self.definedOutputs, v)
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
self.definedOutputs = append(self.definedOutputs, name...)
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
awaitState: func(...pathAndState) {
|
|
195
|
+
if !self.isEphemeral() {
|
|
196
|
+
ll.panic("awaitState allowed only in ephemeral templates")
|
|
197
|
+
}
|
|
198
|
+
path := pathAndState[:len(pathAndState) - 1]
|
|
199
|
+
state := pathAndState[len(pathAndState) - 1]
|
|
200
|
+
_stateRequests = append(_stateRequests, {
|
|
201
|
+
path: path,
|
|
202
|
+
state: state
|
|
203
|
+
})
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
ignorePrepare: _hasPrepared,
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
preparedMapResource: func() {
|
|
214
|
+
return _preparedMap
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
prepareQueue : [],
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
prepare : func(codeFn) {
|
|
227
|
+
if self.ignorePrepare {
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
ll.assert(len(self.prepareQueue) == 0, "multiple prepare statements are not supported yet")
|
|
232
|
+
|
|
233
|
+
self.prepareQueue = append(self.prepareQueue, codeFn)
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
renderPrepare: func() {
|
|
240
|
+
ll.assert(!self.ignorePrepare, "expected !ignorePrepare")
|
|
241
|
+
|
|
242
|
+
inputs := self.inputs()
|
|
243
|
+
|
|
244
|
+
newInputs := copy(inputs)
|
|
245
|
+
|
|
246
|
+
builder := undefined
|
|
247
|
+
if self.isEphemeral() {
|
|
248
|
+
builder = smart.ephemeralMapBuilder()
|
|
249
|
+
} else {
|
|
250
|
+
builder = smart.mapBuilder()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
self._validateInputs()
|
|
254
|
+
for cb in self.prepareQueue {
|
|
255
|
+
r := cb(inputs)
|
|
256
|
+
|
|
257
|
+
ll.assert(is_map(r), "expected map, got ", r)
|
|
258
|
+
|
|
259
|
+
for name, ref in r {
|
|
260
|
+
ll.assert(is_undefined(newInputs[name]), "prepare name is already in use: %s", name)
|
|
261
|
+
|
|
262
|
+
builder.add(name, ref)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
newInputs[tplutil.PREPARE_MAP_FIELD_NAME] = builder.build()
|
|
266
|
+
|
|
267
|
+
renderer := undefined
|
|
268
|
+
if self.isEphemeral() {
|
|
269
|
+
renderer = render.createEphemeral(self.template(), newInputs)
|
|
270
|
+
} else {
|
|
271
|
+
renderer = render.create(self.template(), newInputs)
|
|
272
|
+
}
|
|
273
|
+
for output in self.definedOutputs {
|
|
274
|
+
self.getOutputField(output).set(renderer.output(output))
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
setOutputs : func(resultMap) {
|
|
282
|
+
ll.assert(ll.isMap(resultMap), "expected map, got ", resultMap)
|
|
283
|
+
|
|
284
|
+
for name, value in resultMap {
|
|
285
|
+
f := self.getOutputField(name)
|
|
286
|
+
if !f.isSet() {
|
|
287
|
+
f.setRefOrJson(value)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
getOutputField: func(name) {
|
|
295
|
+
return self.renderer().getField(tplutil.TEMPLATE_OUTPUT_PREFIX + name)
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
createOutputsAndLock: func(outputs) {
|
|
301
|
+
for name in outputs {
|
|
302
|
+
self.renderer().createOutputField(tplutil.TEMPLATE_OUTPUT_PREFIX + name)
|
|
303
|
+
}
|
|
304
|
+
self.renderer().lockOutputs()
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
_inputsSchema: undefined,
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
validateInputs: func(schema) {
|
|
312
|
+
ll.assert(is_undefined(self._inputsSchema), "validateInputs was already invoked")
|
|
313
|
+
self._inputsSchema = schema
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
_validateInputs: func() {
|
|
317
|
+
schema := self._inputsSchema
|
|
318
|
+
if is_undefined(schema) {
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
validation.assertJsonSchema(self.inputs(), schema)
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
body: func(bodyFn){
|
|
327
|
+
if self.isEphemeral() {
|
|
328
|
+
|
|
329
|
+
self.routeEph(bodyFn)
|
|
330
|
+
} else {
|
|
331
|
+
|
|
332
|
+
self.routePure(bodyFn)
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
routePure: func(bodyFn){
|
|
339
|
+
if len(self.definedOutputs) == 0 {
|
|
340
|
+
ll.panic("please define outputs before template body")
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
if ll.isInitializing() {
|
|
345
|
+
|
|
346
|
+
self.createOutputsAndLock(self.definedOutputs)
|
|
347
|
+
} else {
|
|
348
|
+
|
|
349
|
+
if len(self.prepareQueue) != 0 {
|
|
350
|
+
|
|
351
|
+
self.renderPrepare()
|
|
352
|
+
} else {
|
|
353
|
+
self._validateInputs()
|
|
354
|
+
result := bodyFn(self.inputs())
|
|
355
|
+
|
|
356
|
+
ll.assert(ll.isMap(result),
|
|
357
|
+
"expected map from tpl.body() callback. Did you forget 'return' statement?")
|
|
358
|
+
|
|
359
|
+
outputsWithValues := sets.fromMapKeys(result)
|
|
360
|
+
outputsWithValues = sets.add(outputsWithValues, _delegatedOutputs...)
|
|
361
|
+
|
|
362
|
+
ll.assert(sets.fromSlice(self.definedOutputs) == outputsWithValues,
|
|
363
|
+
"tpl.body() callback must return the same list of outputs as were given to 'defineOutputs()'. Want %s, got %s",
|
|
364
|
+
self.definedOutputs, sets.toSlice(outputsWithValues))
|
|
365
|
+
|
|
366
|
+
self.setOutputs(result)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
routeEph: func(bodyFn) {
|
|
374
|
+
|
|
375
|
+
if len(_stateRequests) == 0 {
|
|
376
|
+
_stateRequests = [{
|
|
377
|
+
path: [],
|
|
378
|
+
state: "AllInputsSet"
|
|
379
|
+
}]
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if _hasPrepared {
|
|
383
|
+
_stateRequests = append(_stateRequests, {
|
|
384
|
+
path: [tplutil.PREPARE_MAP_FIELD_NAME],
|
|
385
|
+
state: "ResourceReady"
|
|
386
|
+
})
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
stateReached := stateAwait.await(
|
|
390
|
+
_renderer.getField(tplutil.INPUTS_MAP_FIELD),
|
|
391
|
+
_renderer,
|
|
392
|
+
_stateRequests
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
if stateReached {
|
|
396
|
+
|
|
397
|
+
if len(self.prepareQueue) > 0 {
|
|
398
|
+
ll.assert(len(self.definedOutputs) > 0, "outputs should be defined prior to prepare")
|
|
399
|
+
|
|
400
|
+
self.createOutputsAndLock(self.definedOutputs)
|
|
401
|
+
|
|
402
|
+
self.renderPrepare()
|
|
403
|
+
} else {
|
|
404
|
+
|
|
405
|
+
self._validateInputs()
|
|
406
|
+
result := bodyFn(self.inputs())
|
|
407
|
+
ll.assert(ll.isMap(result),
|
|
408
|
+
"expected map from tpl-eph.body() callback. Did you forget 'return' statement?")
|
|
409
|
+
|
|
410
|
+
self.createOutputsAndLock(maps.getKeys(result))
|
|
411
|
+
|
|
412
|
+
self.setOutputs(result)
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
routeDelegate: func(tpl, extraInputs, outputs) {
|
|
425
|
+
_delegatedOutputs = outputs
|
|
426
|
+
|
|
427
|
+
inputs := self.rawInputs()
|
|
428
|
+
for k, v in extraInputs {
|
|
429
|
+
inputs[k] = v
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
renderer := undefined
|
|
433
|
+
if self.isEphemeral() {
|
|
434
|
+
renderer = render.createEphemeral(tpl, inputs)
|
|
435
|
+
} else {
|
|
436
|
+
renderer = render.create(tpl, inputs)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
tplOutputs := {}
|
|
440
|
+
for o in outputs {
|
|
441
|
+
tplOutputs[o] = renderer.output(o)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
self.createOutputsAndLock(outputs)
|
|
445
|
+
self.setOutputs(tplOutputs)
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return ll.toStrict(self)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
521
453
|
instance := tpl()
|
|
522
454
|
|
|
523
455
|
export ll.toStrict({
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
456
|
+
renderer : instance.renderer,
|
|
457
|
+
registerUnmarshaller : instance.registerUnmarshaller,
|
|
458
|
+
rawInputs : instance.rawInputs,
|
|
459
|
+
hasInput : instance.hasInput,
|
|
460
|
+
inputs : instance.inputs,
|
|
461
|
+
defineOutputs : instance.defineOutputs,
|
|
462
|
+
prepare : instance.prepare,
|
|
463
|
+
awaitState : instance.awaitState,
|
|
464
|
+
delegate : instance.routeDelegate,
|
|
465
|
+
validateInputs : instance.validateInputs,
|
|
466
|
+
body : instance.body,
|
|
467
|
+
template : instance.template
|
|
536
468
|
})
|