@milaboratories/pl-middle-layer 1.36.4 → 1.37.1

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 (44) hide show
  1. package/dist/index.js +19 -19
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +2031 -1918
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/js_render/computable_context.d.ts +68 -0
  6. package/dist/js_render/computable_context.d.ts.map +1 -0
  7. package/dist/js_render/context.d.ts +22 -64
  8. package/dist/js_render/context.d.ts.map +1 -1
  9. package/dist/js_render/index.d.ts +2 -0
  10. package/dist/js_render/index.d.ts.map +1 -1
  11. package/dist/middle_layer/block.d.ts.map +1 -1
  12. package/dist/middle_layer/block_ctx.d.ts +5 -0
  13. package/dist/middle_layer/block_ctx.d.ts.map +1 -1
  14. package/dist/middle_layer/middle_layer.d.ts +2 -0
  15. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  16. package/dist/middle_layer/project.d.ts.map +1 -1
  17. package/dist/middle_layer/project_overview.d.ts.map +1 -1
  18. package/dist/middle_layer/util.d.ts +2 -0
  19. package/dist/middle_layer/util.d.ts.map +1 -1
  20. package/dist/model/args.d.ts +4 -2
  21. package/dist/model/args.d.ts.map +1 -1
  22. package/dist/model/project_helper.d.ts +14 -0
  23. package/dist/model/project_helper.d.ts.map +1 -0
  24. package/dist/model/project_model_util.d.ts +14 -4
  25. package/dist/model/project_model_util.d.ts.map +1 -1
  26. package/dist/mutator/project.d.ts +16 -10
  27. package/dist/mutator/project.d.ts.map +1 -1
  28. package/package.json +14 -14
  29. package/src/js_render/computable_context.ts +753 -0
  30. package/src/js_render/context.ts +32 -720
  31. package/src/js_render/index.ts +37 -3
  32. package/src/middle_layer/block.ts +2 -0
  33. package/src/middle_layer/block_ctx.ts +6 -0
  34. package/src/middle_layer/middle_layer.ts +7 -2
  35. package/src/middle_layer/project.ts +15 -17
  36. package/src/middle_layer/project_overview.ts +13 -4
  37. package/src/middle_layer/util.ts +3 -1
  38. package/src/model/args.ts +12 -6
  39. package/src/model/project_helper.ts +41 -0
  40. package/src/model/project_model_util.test.ts +13 -4
  41. package/src/model/project_model_util.ts +37 -12
  42. package/src/mutator/project.test.ts +18 -12
  43. package/src/mutator/project.ts +159 -61
  44. package/src/mutator/template/template_render.test.ts +2 -2
@@ -0,0 +1,753 @@
1
+ import type { ComputableCtx } from '@milaboratories/computable';
2
+ import { Computable } from '@milaboratories/computable';
3
+ import type { PlTreeNodeAccessor } from '@milaboratories/pl-tree';
4
+ import type {
5
+ JsRenderInternal,
6
+ ArchiveFormat,
7
+ CommonFieldTraverseOps as CommonFieldTraverseOpsFromSDK,
8
+ DataInfo,
9
+ FieldTraversalStep as FieldTraversalStepFromSDK,
10
+ Option,
11
+ PColumn,
12
+ PColumnValues,
13
+ PFrameDef,
14
+ PFrameHandle,
15
+ PObject,
16
+ PObjectSpec,
17
+ PSpecPredicate,
18
+ PTableDef,
19
+ PTableHandle,
20
+ ResourceType as ResourceTypeFromSDK,
21
+ ResultCollection,
22
+ ValueOrError,
23
+ } from '@platforma-sdk/model';
24
+ import {
25
+ isDataInfo,
26
+ mapDataInfo,
27
+ mapPObjectData,
28
+ mapPTableDef,
29
+ mapValueInVOE,
30
+ } from '@platforma-sdk/model';
31
+ import { notEmpty } from '@milaboratories/ts-helpers';
32
+ import { randomUUID } from 'node:crypto';
33
+ import type { Optional } from 'utility-types';
34
+ import type { BlockContextAny } from '../middle_layer/block_ctx';
35
+ import type { MiddleLayerEnvironment } from '../middle_layer/middle_layer';
36
+ import type { Block } from '../model/project_model';
37
+ import { parseFinalPObjectCollection } from '../pool/p_object_collection';
38
+ import type { ResultPool } from '../pool/result_pool';
39
+ import type { JsExecutionContext } from './context';
40
+ import type { VmFunctionImplementation } from 'quickjs-emscripten';
41
+ import { Scope, type QuickJSHandle } from 'quickjs-emscripten';
42
+
43
+ function bytesToBase64(data: Uint8Array | undefined): string | undefined {
44
+ return data !== undefined ? Buffer.from(data).toString('base64') : undefined;
45
+ }
46
+
47
+ export class ComputableContextHelper
48
+ implements JsRenderInternal.GlobalCfgRenderCtxMethods<string, string> {
49
+ public readonly computablesToResolve: Record<string, Computable<unknown>> = {};
50
+
51
+ private computableCtx: ComputableCtx | undefined;
52
+ private readonly accessors = new Map<string, PlTreeNodeAccessor | undefined>();
53
+
54
+ private readonly meta: Map<string, Block>;
55
+
56
+ constructor(
57
+ private readonly parent: JsExecutionContext,
58
+ private readonly blockCtx: BlockContextAny,
59
+ private readonly env: MiddleLayerEnvironment,
60
+ computableCtx: ComputableCtx,
61
+ ) {
62
+ this.computableCtx = computableCtx;
63
+ this.meta = blockCtx.blockMeta(computableCtx);
64
+ }
65
+
66
+ public resetComputableCtx() {
67
+ this.computableCtx = undefined;
68
+ this.accessors.clear();
69
+ }
70
+
71
+ //
72
+ // Methods for injected ctx object
73
+ //
74
+
75
+ getAccessorHandleByName(name: string): string | undefined {
76
+ if (this.computableCtx === undefined)
77
+ throw new Error('Accessors can\'t be used in this context');
78
+ const wellKnownAccessor = (name: string, ctxKey: 'staging' | 'prod'): string | undefined => {
79
+ if (!this.accessors.has(name)) {
80
+ const lambda = this.blockCtx[ctxKey];
81
+ if (lambda === undefined) throw new Error('Staging context not available');
82
+ const entry = lambda(this.computableCtx!);
83
+ if (!entry) this.accessors.set(name, undefined);
84
+ else
85
+ this.accessors.set(name, this.computableCtx!.accessor(entry).node({ ignoreError: true }));
86
+ }
87
+ return this.accessors.get(name) ? name : undefined;
88
+ };
89
+ if (name === 'staging') return wellKnownAccessor('staging', 'staging');
90
+ else if (name === 'main') return wellKnownAccessor('main', 'prod');
91
+ return undefined;
92
+ }
93
+
94
+ //
95
+ // Accessors
96
+ //
97
+
98
+ resolveWithCommon(
99
+ handle: string,
100
+ commonOptions: CommonFieldTraverseOpsFromSDK,
101
+ ...steps: (FieldTraversalStepFromSDK | string)[]
102
+ ): string | undefined {
103
+ return this.wrapAccessor(this.getAccessor(handle).traverseWithCommon(commonOptions, ...steps));
104
+ }
105
+
106
+ getResourceType(handle: string): ResourceTypeFromSDK {
107
+ return this.getAccessor(handle).resourceType;
108
+ }
109
+
110
+ getInputsLocked(handle: string): boolean {
111
+ return this.getAccessor(handle).getInputsLocked();
112
+ }
113
+
114
+ getOutputsLocked(handle: string): boolean {
115
+ return this.getAccessor(handle).getOutputsLocked();
116
+ }
117
+
118
+ getIsReadyOrError(handle: string): boolean {
119
+ return this.getAccessor(handle).getIsReadyOrError();
120
+ }
121
+
122
+ getIsFinal(handle: string): boolean {
123
+ return this.getAccessor(handle).getIsFinal();
124
+ }
125
+
126
+ getError(handle: string): string | undefined {
127
+ return this.wrapAccessor(this.getAccessor(handle).getError());
128
+ }
129
+
130
+ listInputFields(handle: string): string[] {
131
+ return this.getAccessor(handle).listInputFields();
132
+ }
133
+
134
+ listOutputFields(handle: string): string[] {
135
+ return this.getAccessor(handle).listOutputFields();
136
+ }
137
+
138
+ listDynamicFields(handle: string): string[] {
139
+ return this.getAccessor(handle).listDynamicFields();
140
+ }
141
+
142
+ getKeyValueBase64(handle: string, key: string): string | undefined {
143
+ return bytesToBase64(this.getAccessor(handle).getKeyValue(key));
144
+ }
145
+
146
+ getKeyValueAsString(handle: string, key: string): string | undefined {
147
+ return this.getAccessor(handle).getKeyValueAsString(key);
148
+ }
149
+
150
+ getDataBase64(handle: string): string | undefined {
151
+ return bytesToBase64(this.getAccessor(handle).getData());
152
+ }
153
+
154
+ getDataAsString(handle: string): string | undefined {
155
+ return this.getAccessor(handle).getDataAsString();
156
+ }
157
+
158
+ //
159
+ // Accessor helpers
160
+ //
161
+
162
+ parsePObjectCollection(
163
+ handle: string,
164
+ errorOnUnknownField: boolean,
165
+ prefix: string,
166
+ ...resolveSteps: string[]
167
+ ): Record<string, PObject<string>> | undefined {
168
+ const acc = this.getAccessor(handle);
169
+ if (!acc.getIsReadyOrError()) return undefined;
170
+ const accResult = parseFinalPObjectCollection(acc, errorOnUnknownField, prefix, resolveSteps);
171
+ const result: Record<string, PObject<string>> = {};
172
+ for (const [key, obj] of Object.entries(accResult)) {
173
+ result[key] = mapPObjectData(obj, (d) => this.wrapAccessor(d));
174
+ }
175
+ return result;
176
+ }
177
+
178
+ //
179
+ // Blobs
180
+ //
181
+
182
+ private registerComputable(hPrefix: string, computable: Computable<unknown>): string {
183
+ const fHandle = `${hPrefix}_${randomUUID()}`;
184
+ this.computablesToResolve[fHandle] = computable;
185
+ return fHandle;
186
+ }
187
+
188
+ public getBlobContentAsString(handle: string): string {
189
+ const resourceInfo = this.getAccessor(handle).resourceInfo;
190
+ return this.registerComputable(
191
+ 'getBlobContentAsString',
192
+ Computable.make((ctx) => this.env.driverKit.blobDriver.getDownloadedBlob(resourceInfo, ctx), {
193
+ postprocessValue: async (value) => {
194
+ if (value === undefined) return undefined;
195
+ return Buffer.from(await this.env.driverKit.blobDriver.getContent(value.handle)).toString(
196
+ 'utf-8',
197
+ );
198
+ },
199
+ }),
200
+ );
201
+ }
202
+
203
+ public getBlobContentAsBase64(handle: string): string {
204
+ const resourceInfo = this.getAccessor(handle).resourceInfo;
205
+ return this.registerComputable(
206
+ 'getBlobContentAsBase64',
207
+ Computable.make((ctx) => this.env.driverKit.blobDriver.getDownloadedBlob(resourceInfo, ctx), {
208
+ postprocessValue: async (value) => {
209
+ if (value === undefined) return undefined;
210
+ return Buffer.from(await this.env.driverKit.blobDriver.getContent(value.handle)).toString(
211
+ 'base64',
212
+ );
213
+ },
214
+ }),
215
+ );
216
+ }
217
+
218
+ public getDownloadedBlobContentHandle(handle: string): string {
219
+ const resourceInfo = this.getAccessor(handle).resourceInfo;
220
+ return this.registerComputable(
221
+ 'getDownloadedBlobContentHandle',
222
+ this.env.driverKit.blobDriver.getDownloadedBlob(resourceInfo),
223
+ );
224
+ }
225
+
226
+ public getOnDemandBlobContentHandle(handle: string): string {
227
+ const resource = this.getAccessor(handle).persist();
228
+ return this.registerComputable(
229
+ 'getOnDemandBlobContentHandle',
230
+ this.env.driverKit.blobDriver.getOnDemandBlob(resource),
231
+ );
232
+ }
233
+
234
+ //
235
+ // Blobs to URLs
236
+ //
237
+
238
+ public extractArchiveAndGetURL(handle: string, format: ArchiveFormat): string {
239
+ const resource = this.getAccessor(handle).persist();
240
+ return this.registerComputable(
241
+ 'extractArchiveAndGetURL',
242
+ this.env.driverKit.blobToURLDriver.extractArchiveAndGetURL(resource, format),
243
+ );
244
+ }
245
+
246
+ //
247
+ // Import progress
248
+ //
249
+
250
+ getImportProgress(handle: string): string {
251
+ const resource = this.getAccessor(handle).persist();
252
+ return this.registerComputable(
253
+ 'getImportProgress',
254
+ this.env.driverKit.uploadDriver.getProgressId(resource),
255
+ );
256
+ }
257
+
258
+ //
259
+ // Logs
260
+ //
261
+
262
+ getLastLogs(handle: string, nLines: number): string {
263
+ const resource = this.getAccessor(handle).persist();
264
+ return this.registerComputable(
265
+ 'getLastLogs',
266
+ this.env.driverKit.logDriver.getLastLogs(resource, nLines),
267
+ );
268
+ }
269
+
270
+ getProgressLog(handle: string, patternToSearch: string): string {
271
+ const resource = this.getAccessor(handle).persist();
272
+ return this.registerComputable(
273
+ 'getProgressLog',
274
+ this.env.driverKit.logDriver.getProgressLog(resource, patternToSearch),
275
+ );
276
+ }
277
+
278
+ getProgressLogWithInfo(handle: string, patternToSearch: string): string {
279
+ const resource = this.getAccessor(handle).persist();
280
+ return this.registerComputable(
281
+ 'getProgressLogWithInfo',
282
+ this.env.driverKit.logDriver.getProgressLogWithInfo(resource, patternToSearch),
283
+ );
284
+ }
285
+
286
+ getLogHandle(handle: string): string {
287
+ const resource = this.getAccessor(handle).persist();
288
+ return this.registerComputable(
289
+ 'getLogHandle',
290
+ this.env.driverKit.logDriver.getLogHandle(resource),
291
+ );
292
+ }
293
+
294
+ //
295
+ // Blocks
296
+ //
297
+
298
+ public getBlockLabel(blockId: string): string {
299
+ const b = this.meta.get(blockId);
300
+ if (b === undefined) throw new Error(`Block ${blockId} not found.`);
301
+ return b.label;
302
+ }
303
+
304
+ //
305
+ // Result Pool
306
+ //
307
+
308
+ private _resultPool: ResultPool | undefined = undefined;
309
+ private get resultPool(): ResultPool {
310
+ if (this._resultPool === undefined) {
311
+ if (this.computableCtx === undefined)
312
+ throw new Error(
313
+ 'can\'t use result pool in this context (most porbably called from the future mapper)',
314
+ );
315
+ this._resultPool = notEmpty(
316
+ this.blockCtx.getResultsPool,
317
+ 'getResultsPool',
318
+ )(this.computableCtx);
319
+ }
320
+ return this._resultPool;
321
+ }
322
+
323
+ public calculateOptions(predicate: PSpecPredicate): Option[] {
324
+ return this.resultPool.calculateOptions(predicate);
325
+ }
326
+
327
+ public getDataFromResultPool(): ResultCollection<PObject<string>> {
328
+ const collection = this.resultPool.getData();
329
+ if (collection.instabilityMarker !== undefined)
330
+ this.computableCtx!.markUnstable(`incomplete_result_pool:${collection.instabilityMarker}`);
331
+ return {
332
+ isComplete: collection.isComplete,
333
+ entries: collection.entries.map((e) => ({
334
+ ref: e.ref,
335
+ obj: mapPObjectData(e.obj, (d) => this.wrapAccessor(d)),
336
+ })),
337
+ };
338
+ }
339
+
340
+ public getDataWithErrorsFromResultPool(): ResultCollection<
341
+ Optional<PObject<ValueOrError<string, Error>>, 'id'>
342
+ > {
343
+ const collection = this.resultPool.getDataWithErrors();
344
+ if (collection.instabilityMarker !== undefined)
345
+ this.computableCtx!.markUnstable(`incomplete_result_pool:${collection.instabilityMarker}`);
346
+ return {
347
+ isComplete: collection.isComplete,
348
+ entries: collection.entries.map((e) => ({
349
+ ref: e.ref,
350
+ obj: {
351
+ id: e.obj.id,
352
+ spec: e.obj.spec,
353
+ data: mapValueInVOE(e.obj.data, (d) => this.wrapAccessor(d)),
354
+ },
355
+ })),
356
+ };
357
+ }
358
+
359
+ public getSpecsFromResultPool(): ResultCollection<PObjectSpec> {
360
+ const specs = this.resultPool.getSpecs();
361
+ if (specs.instabilityMarker !== undefined)
362
+ this.computableCtx!.markUnstable(`specs_from_pool_incomplete:${specs.instabilityMarker}`);
363
+ return specs;
364
+ }
365
+
366
+ getSpecFromResultPoolByRef(blockId: string, exportName: string): PObjectSpec | undefined {
367
+ return this.resultPool.getSpecByRef(blockId, exportName);
368
+ }
369
+
370
+ getDataFromResultPoolByRef(blockId: string, exportName: string): PObject<string> | undefined {
371
+ return mapPObjectData(this.resultPool.getDataByRef(blockId, exportName), (acc) =>
372
+ this.wrapAccessor(acc),
373
+ );
374
+ }
375
+
376
+ //
377
+ // PFrames / PTables
378
+ //
379
+
380
+ public createPFrame(def: PFrameDef<string | PColumnValues | DataInfo<string>>): PFrameHandle {
381
+ if (this.computableCtx === undefined)
382
+ throw new Error(
383
+ 'can\'t instantiate PFrames from this context (most porbably called from the future mapper)',
384
+ );
385
+ return this.env.driverKit.pFrameDriver.createPFrame(
386
+ def.map((c) => mapPObjectData(c, (d) => this.transformInputPData(d))),
387
+ this.computableCtx,
388
+ );
389
+ }
390
+
391
+ public createPTable(def: PTableDef<PColumn<string | PColumnValues | DataInfo<string>>>): PTableHandle {
392
+ if (this.computableCtx === undefined)
393
+ throw new Error(
394
+ 'can\'t instantiate PTable from this context (most porbably called from the future mapper)',
395
+ );
396
+ return this.env.driverKit.pFrameDriver.createPTable(
397
+ mapPTableDef(def, (c) =>
398
+ mapPObjectData(c, (d) => this.transformInputPData(d)),
399
+ ),
400
+ this.computableCtx,
401
+ );
402
+ }
403
+
404
+ /**
405
+ * Transforms input data for PFrame/PTable creation
406
+ * - Converts string handles to accessors
407
+ * - Maps accessors in DataInfo objects
408
+ * - Passes through other values
409
+ */
410
+ private transformInputPData(d: string | PColumnValues | DataInfo<string>): PlTreeNodeAccessor | PColumnValues | DataInfo<PlTreeNodeAccessor> {
411
+ if (typeof d === 'string') {
412
+ return this.getAccessor(d);
413
+ } else if (isDataInfo(d)) {
414
+ return mapDataInfo(d, (a) => this.getAccessor(a));
415
+ } else {
416
+ return d;
417
+ }
418
+ }
419
+
420
+ //
421
+ // Computable
422
+ //
423
+
424
+ public getCurrentUnstableMarker(): string | undefined {
425
+ return this.computableCtx?.unstableMarker;
426
+ }
427
+
428
+ //
429
+ // Helpers
430
+ //
431
+
432
+ private getAccessor(handle: string): PlTreeNodeAccessor {
433
+ const accessor = this.accessors.get(handle);
434
+ if (accessor === undefined) throw new Error('No such accessor');
435
+ return accessor;
436
+ }
437
+
438
+ private wrapAccessor(accessor: PlTreeNodeAccessor): string;
439
+ private wrapAccessor(accessor: PlTreeNodeAccessor | undefined): string | undefined;
440
+ private wrapAccessor(accessor: PlTreeNodeAccessor | undefined): string | undefined {
441
+ if (accessor === undefined) return undefined;
442
+ else {
443
+ const nextHandle = randomUUID();
444
+ this.accessors.set(nextHandle, accessor);
445
+ return nextHandle;
446
+ }
447
+ }
448
+
449
+ public injectCtx(configCtx: QuickJSHandle): void {
450
+ const parent = this.parent;
451
+ const vm = parent.vm;
452
+
453
+ Scope.withScope((localScope) => {
454
+ // Exporting props
455
+
456
+ const args = this.blockCtx.args(this.computableCtx!);
457
+ const activeArgs = this.blockCtx.activeArgs(this.computableCtx!);
458
+ const uiState = this.blockCtx.uiState(this.computableCtx!);
459
+ vm.setProp(configCtx, 'args', localScope.manage(vm.newString(args)));
460
+ if (uiState !== undefined)
461
+ vm.setProp(configCtx, 'uiState', localScope.manage(vm.newString(uiState)));
462
+ if (activeArgs !== undefined)
463
+ vm.setProp(configCtx, 'activeArgs', localScope.manage(vm.newString(activeArgs)));
464
+
465
+ // Exporting methods
466
+
467
+ const exportCtxFunction = (
468
+ name: string,
469
+ fn: VmFunctionImplementation<QuickJSHandle>,
470
+ ): void => {
471
+ const withCachedError: VmFunctionImplementation<QuickJSHandle> = (...args) => {
472
+ // QuickJS strips all fields from errors apart from 'name' and 'message'.
473
+ // That's why here we need to store them, and rethrow them when we exit
474
+ // from QuickJS code.
475
+ try {
476
+ return (fn as any)(...args);
477
+ } catch (e: unknown) {
478
+ const newErr = parent.errorRepo.setAndRecreateForQuickJS(e);
479
+
480
+ // eslint-disable-next-line @typescript-eslint/only-throw-error
481
+ throw vm.newError(newErr);
482
+ }
483
+ };
484
+
485
+ vm.newFunction(name, withCachedError).consume((fnh) => vm.setProp(configCtx, name, fnh));
486
+ vm.newFunction(name, fn).consume((fnh) => vm.setProp(configCtx, name + '__internal__', fnh));
487
+ };
488
+
489
+ //
490
+ // Methods for injected ctx object
491
+ //
492
+
493
+ exportCtxFunction('getAccessorHandleByName', (name) => {
494
+ return parent.exportSingleValue(
495
+ this.getAccessorHandleByName(vm.getString(name)),
496
+ undefined,
497
+ );
498
+ });
499
+
500
+ //
501
+ // Accessors
502
+ //
503
+
504
+ exportCtxFunction('resolveWithCommon', (handle, commonOptions, ...steps) => {
505
+ return parent.exportSingleValue(
506
+ this.resolveWithCommon(
507
+ vm.getString(handle),
508
+ parent.importObjectViaJson(commonOptions) as CommonFieldTraverseOpsFromSDK,
509
+ ...steps.map(
510
+ (step) => parent.importObjectViaJson(step) as FieldTraversalStepFromSDK | string,
511
+ ),
512
+ ),
513
+ undefined,
514
+ );
515
+ });
516
+
517
+ exportCtxFunction('getResourceType', (handle) => {
518
+ return parent.exportObjectViaJson(this.getResourceType(vm.getString(handle)), undefined);
519
+ });
520
+
521
+ exportCtxFunction('getInputsLocked', (handle) => {
522
+ return parent.exportSingleValue(this.getInputsLocked(vm.getString(handle)), undefined);
523
+ });
524
+
525
+ exportCtxFunction('getOutputsLocked', (handle) => {
526
+ return parent.exportSingleValue(this.getOutputsLocked(vm.getString(handle)), undefined);
527
+ });
528
+
529
+ exportCtxFunction('getIsReadyOrError', (handle) => {
530
+ return parent.exportSingleValue(this.getIsReadyOrError(vm.getString(handle)), undefined);
531
+ });
532
+
533
+ exportCtxFunction('getIsFinal', (handle) => {
534
+ return parent.exportSingleValue(this.getIsFinal(vm.getString(handle)), undefined);
535
+ });
536
+
537
+ exportCtxFunction('getError', (handle) => {
538
+ return parent.exportSingleValue(this.getError(vm.getString(handle)), undefined);
539
+ });
540
+
541
+ exportCtxFunction('listInputFields', (handle) => {
542
+ return parent.exportObjectViaJson(this.listInputFields(vm.getString(handle)), undefined);
543
+ });
544
+
545
+ exportCtxFunction('listOutputFields', (handle) => {
546
+ return parent.exportObjectViaJson(this.listInputFields(vm.getString(handle)), undefined);
547
+ });
548
+
549
+ exportCtxFunction('listDynamicFields', (handle) => {
550
+ return parent.exportObjectViaJson(this.listInputFields(vm.getString(handle)), undefined);
551
+ });
552
+
553
+ exportCtxFunction('getKeyValueBase64', (handle, key) => {
554
+ return parent.exportSingleValue(
555
+ this.getKeyValueBase64(vm.getString(handle), vm.getString(key)),
556
+ undefined,
557
+ );
558
+ });
559
+
560
+ exportCtxFunction('getKeyValueAsString', (handle, key) => {
561
+ return parent.exportSingleValue(
562
+ this.getKeyValueAsString(vm.getString(handle), vm.getString(key)),
563
+ undefined,
564
+ );
565
+ });
566
+
567
+ exportCtxFunction('getDataBase64', (handle) => {
568
+ return parent.exportSingleValue(this.getDataBase64(vm.getString(handle)), undefined);
569
+ });
570
+
571
+ exportCtxFunction('getDataAsString', (handle) => {
572
+ return parent.exportSingleValue(this.getDataAsString(vm.getString(handle)), undefined);
573
+ });
574
+
575
+ //
576
+ // Accessor helpers
577
+ //
578
+
579
+ exportCtxFunction(
580
+ 'parsePObjectCollection',
581
+ (handle, errorOnUnknownField, prefix, ...resolveSteps) => {
582
+ return parent.exportObjectUniversal(
583
+ this.parsePObjectCollection(
584
+ vm.getString(handle),
585
+ vm.dump(errorOnUnknownField) as boolean,
586
+ vm.getString(prefix),
587
+ ...resolveSteps.map((stepHandle) => vm.getString(stepHandle)),
588
+ ),
589
+ undefined,
590
+ );
591
+ },
592
+ );
593
+
594
+ //
595
+ // Blobs
596
+ //
597
+
598
+ exportCtxFunction('getBlobContentAsBase64', (handle) => {
599
+ return parent.exportSingleValue(
600
+ this.getBlobContentAsBase64(vm.getString(handle)),
601
+ undefined,
602
+ );
603
+ });
604
+
605
+ exportCtxFunction('getBlobContentAsString', (handle) => {
606
+ return parent.exportSingleValue(
607
+ this.getBlobContentAsString(vm.getString(handle)),
608
+ undefined,
609
+ );
610
+ });
611
+
612
+ exportCtxFunction('getDownloadedBlobContentHandle', (handle) => {
613
+ return parent.exportSingleValue(
614
+ this.getDownloadedBlobContentHandle(vm.getString(handle)),
615
+ undefined,
616
+ );
617
+ });
618
+
619
+ exportCtxFunction('getOnDemandBlobContentHandle', (handle) => {
620
+ return parent.exportSingleValue(
621
+ this.getOnDemandBlobContentHandle(vm.getString(handle)),
622
+ undefined,
623
+ );
624
+ });
625
+
626
+ //
627
+ // Blobs to URLs
628
+ //
629
+
630
+ exportCtxFunction('extractArchiveAndGetURL', (handle, format) => {
631
+ return parent.exportSingleValue(
632
+ this.extractArchiveAndGetURL(vm.getString(handle), vm.getString(format) as ArchiveFormat),
633
+ undefined);
634
+ });
635
+
636
+ //
637
+ // ImportProgress
638
+ //
639
+
640
+ exportCtxFunction('getImportProgress', (handle) => {
641
+ return parent.exportSingleValue(this.getImportProgress(vm.getString(handle)), undefined);
642
+ });
643
+
644
+ //
645
+ // Logs
646
+ //
647
+
648
+ exportCtxFunction('getLastLogs', (handle, nLines) => {
649
+ return parent.exportSingleValue(
650
+ this.getLastLogs(vm.getString(handle), vm.getNumber(nLines)),
651
+ undefined,
652
+ );
653
+ });
654
+
655
+ exportCtxFunction('getProgressLog', (handle, patternToSearch) => {
656
+ return parent.exportSingleValue(
657
+ this.getProgressLog(vm.getString(handle), vm.getString(patternToSearch)),
658
+ undefined,
659
+ );
660
+ });
661
+
662
+ exportCtxFunction('getProgressLogWithInfo', (handle, patternToSearch) => {
663
+ return parent.exportSingleValue(
664
+ this.getProgressLogWithInfo(vm.getString(handle), vm.getString(patternToSearch)),
665
+ undefined,
666
+ );
667
+ });
668
+
669
+ exportCtxFunction('getLogHandle', (handle) => {
670
+ return parent.exportSingleValue(this.getLogHandle(vm.getString(handle)), undefined);
671
+ });
672
+
673
+ //
674
+ // Blocks
675
+ //
676
+
677
+ exportCtxFunction('getBlockLabel', (blockId) => {
678
+ return parent.exportSingleValue(this.getBlockLabel(vm.getString(blockId)), undefined);
679
+ });
680
+
681
+ //
682
+ // Result pool
683
+ //
684
+
685
+ exportCtxFunction('getDataFromResultPool', () => {
686
+ return parent.exportObjectUniversal(this.getDataFromResultPool(), undefined);
687
+ });
688
+
689
+ exportCtxFunction('getDataWithErrorsFromResultPool', () => {
690
+ return parent.exportObjectUniversal(this.getDataWithErrorsFromResultPool(), undefined);
691
+ });
692
+
693
+ exportCtxFunction('getSpecsFromResultPool', () => {
694
+ return parent.exportObjectUniversal(this.getSpecsFromResultPool(), undefined);
695
+ });
696
+
697
+ exportCtxFunction('calculateOptions', (predicate) => {
698
+ return parent.exportObjectUniversal(
699
+ this.calculateOptions(parent.importObjectViaJson(predicate) as PSpecPredicate),
700
+ undefined,
701
+ );
702
+ });
703
+
704
+ exportCtxFunction('getSpecFromResultPoolByRef', (blockId, exportName) => {
705
+ return parent.exportObjectUniversal(
706
+ this.getSpecFromResultPoolByRef(
707
+ vm.getString(blockId),
708
+ vm.getString(exportName),
709
+ ),
710
+ undefined,
711
+ );
712
+ });
713
+
714
+ exportCtxFunction('getDataFromResultPoolByRef', (blockId, exportName) => {
715
+ return parent.exportObjectUniversal(
716
+ this.getDataFromResultPoolByRef(
717
+ vm.getString(blockId),
718
+ vm.getString(exportName),
719
+ ),
720
+ undefined,
721
+ );
722
+ });
723
+
724
+ //
725
+ // PFrames / PTables
726
+ //
727
+
728
+ exportCtxFunction('createPFrame', (def) => {
729
+ return parent.exportSingleValue(
730
+ this.createPFrame(parent.importObjectViaJson(def) as PFrameDef<string | PColumnValues>),
731
+ undefined,
732
+ );
733
+ });
734
+
735
+ exportCtxFunction('createPTable', (def) => {
736
+ return parent.exportSingleValue(
737
+ this.createPTable(
738
+ parent.importObjectViaJson(def) as PTableDef<PColumn<string | PColumnValues>>,
739
+ ),
740
+ undefined,
741
+ );
742
+ });
743
+
744
+ //
745
+ // Computable
746
+ //
747
+
748
+ exportCtxFunction('getCurrentUnstableMarker', () => {
749
+ return parent.exportSingleValue(this.getCurrentUnstableMarker(), undefined);
750
+ });
751
+ });
752
+ }
753
+ }