@platforma-sdk/test 1.58.6 → 1.58.9
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/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/index.cjs +22 -38
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -7
- package/dist/test-block.cjs +96 -126
- package/dist/test-block.cjs.map +1 -1
- package/dist/test-block.d.ts +27 -21
- package/dist/test-block.js +92 -104
- package/dist/test-block.js.map +1 -1
- package/dist/test-pl.cjs +63 -96
- package/dist/test-pl.cjs.map +1 -1
- package/dist/test-pl.d.ts +12 -8
- package/dist/test-pl.js +60 -75
- package/dist/test-pl.js.map +1 -1
- package/dist/test-template.cjs +134 -145
- package/dist/test-template.cjs.map +1 -1
- package/dist/test-template.d.ts +47 -42
- package/dist/test-template.js +131 -142
- package/dist/test-template.js.map +1 -1
- package/dist/util.cjs +17 -17
- package/dist/util.cjs.map +1 -1
- package/dist/util.d.ts +7 -4
- package/dist/util.js +15 -15
- package/dist/util.js.map +1 -1
- package/package.json +6 -6
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/simple.test.d.ts +0 -2
- package/dist/simple.test.d.ts.map +0 -1
- package/dist/test-block.d.ts.map +0 -1
- package/dist/test-pl.d.ts.map +0 -1
- package/dist/test-template.d.ts.map +0 -1
- package/dist/util.d.ts.map +0 -1
package/dist/test-pl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-pl.js","sources":["../src/test-pl.ts"],"sourcesContent":["import type { OptionalResourceId, PlClient, ResourceId } from \"@milaboratories/pl-middle-layer\";\nimport { NullResourceId, resourceIdToString, TestHelpers } from \"@milaboratories/pl-middle-layer\";\nimport type { SynchronizedTreeOps } from \"@milaboratories/pl-tree\";\nimport { SynchronizedTreeState } from \"@milaboratories/pl-tree\";\nimport { randomUUID } from \"node:crypto\";\nimport * as fsp from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { test } from \"vitest\";\n\n// oxlint-disable-next-line jest/expect-expect jest/no-disabled-tests\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (res: ResourceId, ops?: SynchronizedTreeOps) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({ onTestFinished }, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n await fsp.rm(workFolder, { recursive: true });\n } else {\n console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);\n }\n });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(alternativeRoot);\n altRootId = client.clientRoot;\n try {\n await use(client);\n } finally {\n // Close the test client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await client.close();\n }\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n const rawClient = await TestHelpers.getTestClient();\n try {\n await rawClient.deleteAlternativeRoot(alternativeRoot);\n } finally {\n // Close the cleanup client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await rawClient.close();\n }\n } else {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${resourceIdToString(\n altRootId,\n )})`,\n );\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\n try {\n await use((res, ops) => {\n let treePromise = trees.get(res);\n if (treePromise === undefined) {\n treePromise = SynchronizedTreeState.init(\n pl,\n res,\n ops ?? {\n pollingInterval: 200,\n stopPollingDelay: 400,\n },\n );\n trees.set(res, treePromise);\n }\n return treePromise;\n });\n } finally {\n for (const [, treePromise] of trees) {\n await (await treePromise).terminate();\n }\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n },\n});\n"],"
|
|
1
|
+
{"version":3,"file":"test-pl.js","names":[],"sources":["../src/test-pl.ts"],"sourcesContent":["import type { OptionalResourceId, PlClient, ResourceId } from \"@milaboratories/pl-middle-layer\";\nimport { NullResourceId, resourceIdToString, TestHelpers } from \"@milaboratories/pl-middle-layer\";\nimport type { SynchronizedTreeOps } from \"@milaboratories/pl-tree\";\nimport { SynchronizedTreeState } from \"@milaboratories/pl-tree\";\nimport { randomUUID } from \"node:crypto\";\nimport * as fsp from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { test } from \"vitest\";\n\n// oxlint-disable-next-line jest/expect-expect jest/no-disabled-tests\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (res: ResourceId, ops?: SynchronizedTreeOps) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({ onTestFinished }, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n await fsp.rm(workFolder, { recursive: true });\n } else {\n console.log(`TEST FAILED TMP FOLDER IS PRESERVED: ${workFolder}`);\n }\n });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const alternativeRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(alternativeRoot);\n altRootId = client.clientRoot;\n try {\n await use(client);\n } finally {\n // Close the test client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await client.close();\n }\n onTestFinished(async (context) => {\n if (context.task.result?.state === \"pass\") {\n const rawClient = await TestHelpers.getTestClient();\n try {\n await rawClient.deleteAlternativeRoot(alternativeRoot);\n } finally {\n // Close the cleanup client to avoid dangling gRPC channels\n // that can cause segfaults during process exit\n await rawClient.close();\n }\n } else {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESERVED IN PL: ${alternativeRoot} (${resourceIdToString(\n altRootId,\n )})`,\n );\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\n try {\n await use((res, ops) => {\n let treePromise = trees.get(res);\n if (treePromise === undefined) {\n treePromise = SynchronizedTreeState.init(\n pl,\n res,\n ops ?? {\n pollingInterval: 200,\n stopPollingDelay: 400,\n },\n );\n trees.set(res, treePromise);\n }\n return treePromise;\n });\n } finally {\n for (const [, treePromise] of trees) {\n await (await treePromise).terminate();\n }\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n },\n});\n"],"mappings":";;;;;;;;AAUA,MAAa,SAAS,KAAK,OAKxB;CACD,WAAW,OAAO,EAAE,kBAAkB,QAAQ;EAC5C,MAAM,aAAa,KAAK,QAAQ,QAAQ,YAAY,GAAG;AACvD,QAAM,IAAI,MAAM,YAAY,EAAE,WAAW,MAAM,CAAC;AAChD,QAAM,IAAI,WAAW;AACrB,iBAAe,OAAO,YAAY;AAChC,OAAI,QAAQ,KAAK,QAAQ,UAAU,OACjC,OAAM,IAAI,GAAG,YAAY,EAAE,WAAW,MAAM,CAAC;OAE7C,SAAQ,IAAI,wCAAwC,aAAa;IAEnE;;CAGJ,IAAI,OAAO,EAAE,kBAAkB,QAAQ;EACrC,MAAM,kBAAkB,QAAQ,KAAK,KAAK,CAAC,GAAG,YAAY;EAC1D,IAAI,YAAgC;EACpC,MAAM,SAAS,MAAM,YAAY,cAAc,gBAAgB;AAC/D,cAAY,OAAO;AACnB,MAAI;AACF,SAAM,IAAI,OAAO;YACT;AAGR,SAAM,OAAO,OAAO;;AAEtB,iBAAe,OAAO,YAAY;AAChC,OAAI,QAAQ,KAAK,QAAQ,UAAU,QAAQ;IACzC,MAAM,YAAY,MAAM,YAAY,eAAe;AACnD,QAAI;AACF,WAAM,UAAU,sBAAsB,gBAAgB;cAC9C;AAGR,WAAM,UAAU,OAAO;;SAGzB,SAAQ,IACN,uDAAuD,gBAAgB,IAAI,mBACzE,UACD,CAAC,GACH;IAEH;;CAGJ,YAAY,OAAO,EAAE,MAAM,QAAQ;EACjC,MAAM,wBAAQ,IAAI,KAAiD;AACnE,MAAI;AACF,SAAM,KAAK,KAAK,QAAQ;IACtB,IAAI,cAAc,MAAM,IAAI,IAAI;AAChC,QAAI,gBAAgB,QAAW;AAC7B,mBAAc,sBAAsB,KAClC,IACA,KACA,OAAO;MACL,iBAAiB;MACjB,kBAAkB;MACnB,CACF;AACD,WAAM,IAAI,KAAK,YAAY;;AAE7B,WAAO;KACP;YACM;AACR,QAAK,MAAM,GAAG,gBAAgB,MAC5B,QAAO,MAAM,aAAa,WAAW;;;CAK3C,UAAU,OAAO,EAAE,IAAI,YAAY,QAAQ,QAAQ;AACjD,QAAM,IAAI,MAAM,KAAK,GAAG,WAAW,CAAC;;CAEvC,CAAC"}
|
package/dist/test-template.cjs
CHANGED
|
@@ -1,152 +1,141 @@
|
|
|
1
|
-
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_test_pl = require('./test-pl.cjs');
|
|
3
|
+
let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
|
|
4
|
+
let node_crypto = require("node:crypto");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_runtime.__toESM(node_path);
|
|
7
|
+
let _milaboratories_computable = require("@milaboratories/computable");
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
tx.createField(rootField, "Dynamic", map);
|
|
129
|
-
await tx.commit();
|
|
130
|
-
return await plMiddleLayer.toGlobalResourceId(map);
|
|
131
|
-
});
|
|
132
|
-
const resultMapTree = await createTree(resultMap);
|
|
133
|
-
await use(new TplTestHelpers(pl, resultMap, resultMapTree));
|
|
134
|
-
},
|
|
135
|
-
driverKit: async ({ pl, tmpFolder }, use) => {
|
|
136
|
-
const frontendDownloadPath = path.join(tmpFolder, "frontend");
|
|
137
|
-
const driverKit = await plMiddleLayer.initDriverKit(pl, tmpFolder, frontendDownloadPath, {
|
|
138
|
-
localSecret: plMiddleLayer.MiddleLayer.generateLocalSecret(),
|
|
139
|
-
localProjections: [], // TODO must be different with local pl
|
|
140
|
-
openFileDialogCallback: () => {
|
|
141
|
-
throw new Error("Not implemented.");
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
await use(driverKit);
|
|
145
|
-
},
|
|
9
|
+
//#region src/test-template.ts
|
|
10
|
+
var TestRenderResults = class {
|
|
11
|
+
constructor(resultEntry) {
|
|
12
|
+
this.resultEntry = resultEntry;
|
|
13
|
+
}
|
|
14
|
+
computeOutput(name, cb) {
|
|
15
|
+
return _milaboratories_computable.Computable.make((ctx) => {
|
|
16
|
+
return cb(ctx.accessor(this.resultEntry).node().traverse({
|
|
17
|
+
field: name,
|
|
18
|
+
assertFieldType: "Input"
|
|
19
|
+
}), ctx);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var TestWorkflowResults = class {
|
|
24
|
+
constructor(renderResult, processedExportsResult, blockId) {
|
|
25
|
+
this.renderResult = renderResult;
|
|
26
|
+
this.processedExportsResult = processedExportsResult;
|
|
27
|
+
this.blockId = blockId;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns context id of this workflow
|
|
31
|
+
* */
|
|
32
|
+
context() {
|
|
33
|
+
return this.renderResult.computeOutput("context", (cb) => cb?.id).withStableType();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns context id of this workflow
|
|
37
|
+
* */
|
|
38
|
+
result() {
|
|
39
|
+
return this.renderResult.computeOutput("result", (cb) => cb?.id).withStableType();
|
|
40
|
+
}
|
|
41
|
+
export(name, cb) {
|
|
42
|
+
if (this.processedExportsResult !== void 0) return this.processedExportsResult.computeOutput("result", (acc, ctx) => {
|
|
43
|
+
return cb(acc?.traverse({
|
|
44
|
+
field: name,
|
|
45
|
+
assertFieldType: "Input"
|
|
46
|
+
}), ctx);
|
|
47
|
+
});
|
|
48
|
+
else return this.renderResult.computeOutput("context", (acc, ctx) => {
|
|
49
|
+
return cb(acc?.traverse({
|
|
50
|
+
field: `values/${name}`,
|
|
51
|
+
assertFieldType: "Input"
|
|
52
|
+
}), ctx);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
output(name, cb) {
|
|
56
|
+
return this.renderResult.computeOutput("result", (acc, ctx) => {
|
|
57
|
+
return cb(acc?.traverse({
|
|
58
|
+
field: name,
|
|
59
|
+
assertFieldType: "Input"
|
|
60
|
+
}), ctx);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var TplTestHelpers = class {
|
|
65
|
+
constructor(pl, resultRootRid, resultRootTree) {
|
|
66
|
+
this.pl = pl;
|
|
67
|
+
this.resultRootRid = resultRootRid;
|
|
68
|
+
this.resultRootTree = resultRootTree;
|
|
69
|
+
}
|
|
70
|
+
async renderTemplate(ephemeral, template, outputs, inputs) {
|
|
71
|
+
const runId = (0, node_crypto.randomUUID)();
|
|
72
|
+
const spec = typeof template === "string" ? await (0, _milaboratories_pl_middle_layer.prepareTemplateSpec)({
|
|
73
|
+
type: "from-file",
|
|
74
|
+
path: `./dist/tengo/tpl/${template}.plj.gz`
|
|
75
|
+
}) : await (0, _milaboratories_pl_middle_layer.prepareTemplateSpec)(template);
|
|
76
|
+
const { resultMapRid } = await this.pl.withWriteTx("TemplateRender", async (tx) => {
|
|
77
|
+
const futureOutputs = await (0, _milaboratories_pl_middle_layer.createRenderTemplate)(tx, (0, _milaboratories_pl_middle_layer.loadTemplate)(tx, spec), ephemeral, await inputs(tx), outputs);
|
|
78
|
+
const resultMap = _milaboratories_pl_middle_layer.Pl.createPlMap(tx, futureOutputs, ephemeral);
|
|
79
|
+
tx.createField((0, _milaboratories_pl_middle_layer.field)(this.resultRootRid, runId), "Dynamic", resultMap);
|
|
80
|
+
const resultMapRid = await (0, _milaboratories_pl_middle_layer.toGlobalResourceId)(resultMap);
|
|
81
|
+
await tx.commit();
|
|
82
|
+
return { resultMapRid };
|
|
83
|
+
});
|
|
84
|
+
await this.resultRootTree.refreshState();
|
|
85
|
+
return new TestRenderResults(this.resultRootTree.entry(resultMapRid));
|
|
86
|
+
}
|
|
87
|
+
createObject(tx, value) {
|
|
88
|
+
return tx.createValue(_milaboratories_pl_middle_layer.Pl.JsonObject, JSON.stringify(value));
|
|
89
|
+
}
|
|
90
|
+
async renderWorkflow(workflow, preRun, args, ops = {}) {
|
|
91
|
+
const blockId = ops.blockId ?? (0, node_crypto.randomUUID)();
|
|
92
|
+
const mainResult = await this.renderTemplate(true, workflow, ["result", "context"], (tx) => {
|
|
93
|
+
let ctx = void 0;
|
|
94
|
+
if (ops.parent) ctx = ops.parent;
|
|
95
|
+
else {
|
|
96
|
+
ctx = tx.createEphemeral({
|
|
97
|
+
name: "BContextEnd",
|
|
98
|
+
version: "1"
|
|
99
|
+
});
|
|
100
|
+
tx.lock(ctx);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
args: this.createObject(tx, args),
|
|
104
|
+
blockId: this.createObject(tx, blockId),
|
|
105
|
+
isProduction: this.createObject(tx, !preRun),
|
|
106
|
+
context: ctx
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
let exports = void 0;
|
|
110
|
+
if (ops.exportProcessor !== void 0) exports = await this.renderTemplate(true, ops.exportProcessor, ["result"], (tx) => ({ pf: tx.getFutureFieldValue(mainResult.resultEntry.rid, "context", "Input") }));
|
|
111
|
+
return new TestWorkflowResults(mainResult, exports, blockId);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const tplTest = require_test_pl.plTest.extend({
|
|
115
|
+
helper: async ({ pl, createTree }, use) => {
|
|
116
|
+
const resultMap = await pl.withWriteTx("CreatingHelpers", async (tx) => {
|
|
117
|
+
const map = tx.createEphemeral(_milaboratories_pl_middle_layer.Pl.EphStdMap);
|
|
118
|
+
const rootField = (0, _milaboratories_pl_middle_layer.field)(tx.clientRoot, "templateTeste");
|
|
119
|
+
tx.createField(rootField, "Dynamic", map);
|
|
120
|
+
await tx.commit();
|
|
121
|
+
return await (0, _milaboratories_pl_middle_layer.toGlobalResourceId)(map);
|
|
122
|
+
});
|
|
123
|
+
await use(new TplTestHelpers(pl, resultMap, await createTree(resultMap)));
|
|
124
|
+
},
|
|
125
|
+
driverKit: async ({ pl, tmpFolder }, use) => {
|
|
126
|
+
await use(await (0, _milaboratories_pl_middle_layer.initDriverKit)(pl, tmpFolder, node_path.default.join(tmpFolder, "frontend"), {
|
|
127
|
+
localSecret: _milaboratories_pl_middle_layer.MiddleLayer.generateLocalSecret(),
|
|
128
|
+
localProjections: [],
|
|
129
|
+
openFileDialogCallback: () => {
|
|
130
|
+
throw new Error("Not implemented.");
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
146
134
|
});
|
|
147
135
|
|
|
136
|
+
//#endregion
|
|
148
137
|
exports.TestRenderResults = TestRenderResults;
|
|
149
138
|
exports.TestWorkflowResults = TestWorkflowResults;
|
|
150
139
|
exports.TplTestHelpers = TplTestHelpers;
|
|
151
140
|
exports.tplTest = tplTest;
|
|
152
|
-
//# sourceMappingURL=test-template.cjs.map
|
|
141
|
+
//# sourceMappingURL=test-template.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-template.cjs","sources":["../src/test-template.ts"],"sourcesContent":["import type {\n ComputableCtx,\n ComputableStableDefined,\n UnwrapComputables,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type {\n AnyRef,\n MiddleLayerDriverKit,\n PlClient,\n PlTransaction,\n ResourceId,\n TemplateSpecAny,\n} from \"@milaboratories/pl-middle-layer\";\nimport {\n createRenderTemplate,\n field,\n initDriverKit,\n loadTemplate,\n MiddleLayer,\n Pl,\n prepareTemplateSpec,\n toGlobalResourceId,\n} from \"@milaboratories/pl-middle-layer\";\nimport type {\n PlTreeEntry,\n PlTreeNodeAccessor,\n SynchronizedTreeState,\n} from \"@milaboratories/pl-tree\";\nimport { randomUUID } from \"node:crypto\";\nimport path from \"node:path\";\nimport { plTest } from \"./test-pl\";\n\nexport type WorkflowRenderOps = {\n parent?: ResourceId;\n exportProcessor?: TemplateSpecAny;\n blockId?: string;\n};\n\nexport class TestRenderResults<O extends string> {\n constructor(public readonly resultEntry: PlTreeEntry) {}\n\n public computeOutput<R>(\n name: O,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R,\n ): Computable<UnwrapComputables<R> | undefined> {\n return Computable.make((ctx) => {\n const outputAccessor = ctx\n .accessor(this.resultEntry)\n .node()\n .traverse({ field: name, assertFieldType: \"Input\" });\n return cb(outputAccessor, ctx);\n });\n }\n}\n\nexport class TestWorkflowResults {\n constructor(\n public readonly renderResult: TestRenderResults<\"context\" | \"result\">,\n public readonly processedExportsResult: TestRenderResults<\"result\"> | undefined,\n public readonly blockId: string,\n ) {}\n\n /**\n * Returns context id of this workflow\n * */\n public context(): ComputableStableDefined<ResourceId> {\n return this.renderResult.computeOutput(\"context\", (cb) => cb?.id).withStableType();\n }\n\n /**\n * Returns context id of this workflow\n * */\n public result(): ComputableStableDefined<ResourceId> {\n return this.renderResult.computeOutput(\"result\", (cb) => cb?.id).withStableType();\n }\n\n public export<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R,\n ): Computable<UnwrapComputables<R> | undefined> {\n if (this.processedExportsResult !== undefined)\n return this.processedExportsResult.computeOutput(\"result\", (acc, ctx) => {\n return cb(acc?.traverse({ field: name, assertFieldType: \"Input\" }), ctx);\n });\n else\n return this.renderResult.computeOutput(\"context\", (acc, ctx) => {\n return cb(acc?.traverse({ field: `values/${name}`, assertFieldType: \"Input\" }), ctx);\n });\n }\n\n public output<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R,\n ): Computable<UnwrapComputables<R> | undefined> {\n return this.renderResult.computeOutput(\"result\", (acc, ctx) => {\n return cb(acc?.traverse({ field: name, assertFieldType: \"Input\" }), ctx);\n });\n }\n}\n\nexport class TplTestHelpers {\n constructor(\n private readonly pl: PlClient,\n private readonly resultRootRid: ResourceId,\n private readonly resultRootTree: SynchronizedTreeState,\n ) {}\n\n async renderTemplate<const O extends string>(\n ephemeral: boolean,\n template: string | TemplateSpecAny,\n outputs: O[],\n inputs: (tx: PlTransaction) => Record<string, AnyRef> | Promise<Record<string, AnyRef>>,\n ): Promise<TestRenderResults<O>> {\n const runId = randomUUID();\n const spec =\n typeof template === \"string\"\n ? await prepareTemplateSpec({\n type: \"from-file\",\n path: `./dist/tengo/tpl/${template}.plj.gz`,\n })\n : await prepareTemplateSpec(template);\n const { resultMapRid } = await this.pl.withWriteTx(\"TemplateRender\", async (tx) => {\n const tpl = loadTemplate(tx, spec);\n const renderedInputs = await inputs(tx);\n const futureOutputs = await createRenderTemplate(tx, tpl, ephemeral, renderedInputs, outputs);\n const resultMap = Pl.createPlMap(tx, futureOutputs, ephemeral);\n tx.createField(field(this.resultRootRid, runId), \"Dynamic\", resultMap);\n const resultMapRid = await toGlobalResourceId(resultMap);\n await tx.commit();\n return {\n resultMapRid,\n };\n });\n await this.resultRootTree.refreshState();\n return new TestRenderResults(this.resultRootTree.entry(resultMapRid));\n }\n\n createObject(tx: PlTransaction, value: unknown): AnyRef {\n return tx.createValue(Pl.JsonObject, JSON.stringify(value));\n }\n\n async renderWorkflow(\n workflow: string | TemplateSpecAny,\n preRun: boolean,\n args: Record<string, unknown> | Promise<Record<string, unknown>>,\n ops: WorkflowRenderOps = {},\n ): Promise<TestWorkflowResults> {\n const blockId = ops.blockId ?? randomUUID();\n const mainResult: TestRenderResults<\"result\" | \"context\"> = await this.renderTemplate(\n true,\n workflow,\n [\"result\", \"context\"],\n (tx) => {\n let ctx = undefined;\n if (ops.parent) {\n ctx = ops.parent;\n } else {\n ctx = tx.createEphemeral({ name: \"BContextEnd\", version: \"1\" });\n tx.lock(ctx);\n }\n\n return {\n args: this.createObject(tx, args),\n blockId: this.createObject(tx, blockId),\n isProduction: this.createObject(tx, !preRun),\n context: ctx,\n };\n },\n );\n\n let exports: TestRenderResults<\"result\"> | undefined = undefined;\n if (ops.exportProcessor !== undefined) {\n exports = await this.renderTemplate(true, ops.exportProcessor, [\"result\"], (tx) => ({\n pf: tx.getFutureFieldValue(mainResult.resultEntry.rid, \"context\", \"Input\"),\n }));\n }\n\n return new TestWorkflowResults(mainResult, exports, blockId);\n }\n}\n\nexport const tplTest = plTest.extend<{\n helper: TplTestHelpers;\n driverKit: MiddleLayerDriverKit;\n}>({\n helper: async ({ pl, createTree }, use): Promise<void> => {\n const resultMap = await pl.withWriteTx(\"CreatingHelpers\", async (tx) => {\n const map = tx.createEphemeral(Pl.EphStdMap);\n const rootField = field(tx.clientRoot, \"templateTeste\");\n tx.createField(rootField, \"Dynamic\", map);\n await tx.commit();\n return await toGlobalResourceId(map);\n });\n const resultMapTree = await createTree(resultMap);\n await use(new TplTestHelpers(pl, resultMap, resultMapTree));\n },\n driverKit: async ({ pl, tmpFolder }, use): Promise<void> => {\n const frontendDownloadPath = path.join(tmpFolder, \"frontend\");\n\n const driverKit = await initDriverKit(pl, tmpFolder, frontendDownloadPath, {\n localSecret: MiddleLayer.generateLocalSecret(),\n localProjections: [], // TODO must be different with local pl\n openFileDialogCallback: () => {\n throw new Error(\"Not implemented.\");\n },\n });\n\n await use(driverKit);\n },\n});\n"],"names":["Computable","randomUUID","prepareTemplateSpec","loadTemplate","createRenderTemplate","Pl","field","toGlobalResourceId","plTest","initDriverKit","MiddleLayer"],"mappings":";;;;;;;;MAuCa,iBAAiB,CAAA;AACA,IAAA,WAAA;AAA5B,IAAA,WAAA,CAA4B,WAAwB,EAAA;QAAxB,IAAA,CAAA,WAAW,GAAX,WAAW;IAAgB;IAEhD,aAAa,CAClB,IAAO,EACP,EAAkE,EAAA;AAElE,QAAA,OAAOA,qBAAU,CAAC,IAAI,CAAC,CAAC,GAAG,KAAI;YAC7B,MAAM,cAAc,GAAG;AACpB,iBAAA,QAAQ,CAAC,IAAI,CAAC,WAAW;AACzB,iBAAA,IAAI;iBACJ,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;AACtD,YAAA,OAAO,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC;AAChC,QAAA,CAAC,CAAC;IACJ;AACD;MAEY,mBAAmB,CAAA;AAEZ,IAAA,YAAA;AACA,IAAA,sBAAA;AACA,IAAA,OAAA;AAHlB,IAAA,WAAA,CACkB,YAAqD,EACrD,sBAA+D,EAC/D,OAAe,EAAA;QAFf,IAAA,CAAA,YAAY,GAAZ,YAAY;QACZ,IAAA,CAAA,sBAAsB,GAAtB,sBAAsB;QACtB,IAAA,CAAA,OAAO,GAAP,OAAO;IACtB;AAEH;;AAEK;IACE,OAAO,GAAA;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,cAAc,EAAE;IACpF;AAEA;;AAEK;IACE,MAAM,GAAA;QACX,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,cAAc,EAAE;IACnF;IAEO,MAAM,CACX,IAAY,EACZ,EAAkE,EAAA;AAElE,QAAA,IAA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SAAA,CAAC;AAEF,QAAA,MAAM,GAAG,CAAC,SAAS,CAAC;IACtB,CAAC;AACF,CAAA;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"test-template.cjs","names":["Computable","Pl","plTest","path","MiddleLayer"],"sources":["../src/test-template.ts"],"sourcesContent":["import type {\n ComputableCtx,\n ComputableStableDefined,\n UnwrapComputables,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type {\n AnyRef,\n MiddleLayerDriverKit,\n PlClient,\n PlTransaction,\n ResourceId,\n TemplateSpecAny,\n} from \"@milaboratories/pl-middle-layer\";\nimport {\n createRenderTemplate,\n field,\n initDriverKit,\n loadTemplate,\n MiddleLayer,\n Pl,\n prepareTemplateSpec,\n toGlobalResourceId,\n} from \"@milaboratories/pl-middle-layer\";\nimport type {\n PlTreeEntry,\n PlTreeNodeAccessor,\n SynchronizedTreeState,\n} from \"@milaboratories/pl-tree\";\nimport { randomUUID } from \"node:crypto\";\nimport path from \"node:path\";\nimport { plTest } from \"./test-pl\";\n\nexport type WorkflowRenderOps = {\n parent?: ResourceId;\n exportProcessor?: TemplateSpecAny;\n blockId?: string;\n};\n\nexport class TestRenderResults<O extends string> {\n constructor(public readonly resultEntry: PlTreeEntry) {}\n\n public computeOutput<R>(\n name: O,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R,\n ): Computable<UnwrapComputables<R> | undefined> {\n return Computable.make((ctx) => {\n const outputAccessor = ctx\n .accessor(this.resultEntry)\n .node()\n .traverse({ field: name, assertFieldType: \"Input\" });\n return cb(outputAccessor, ctx);\n });\n }\n}\n\nexport class TestWorkflowResults {\n constructor(\n public readonly renderResult: TestRenderResults<\"context\" | \"result\">,\n public readonly processedExportsResult: TestRenderResults<\"result\"> | undefined,\n public readonly blockId: string,\n ) {}\n\n /**\n * Returns context id of this workflow\n * */\n public context(): ComputableStableDefined<ResourceId> {\n return this.renderResult.computeOutput(\"context\", (cb) => cb?.id).withStableType();\n }\n\n /**\n * Returns context id of this workflow\n * */\n public result(): ComputableStableDefined<ResourceId> {\n return this.renderResult.computeOutput(\"result\", (cb) => cb?.id).withStableType();\n }\n\n public export<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R,\n ): Computable<UnwrapComputables<R> | undefined> {\n if (this.processedExportsResult !== undefined)\n return this.processedExportsResult.computeOutput(\"result\", (acc, ctx) => {\n return cb(acc?.traverse({ field: name, assertFieldType: \"Input\" }), ctx);\n });\n else\n return this.renderResult.computeOutput(\"context\", (acc, ctx) => {\n return cb(acc?.traverse({ field: `values/${name}`, assertFieldType: \"Input\" }), ctx);\n });\n }\n\n public output<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R,\n ): Computable<UnwrapComputables<R> | undefined> {\n return this.renderResult.computeOutput(\"result\", (acc, ctx) => {\n return cb(acc?.traverse({ field: name, assertFieldType: \"Input\" }), ctx);\n });\n }\n}\n\nexport class TplTestHelpers {\n constructor(\n private readonly pl: PlClient,\n private readonly resultRootRid: ResourceId,\n private readonly resultRootTree: SynchronizedTreeState,\n ) {}\n\n async renderTemplate<const O extends string>(\n ephemeral: boolean,\n template: string | TemplateSpecAny,\n outputs: O[],\n inputs: (tx: PlTransaction) => Record<string, AnyRef> | Promise<Record<string, AnyRef>>,\n ): Promise<TestRenderResults<O>> {\n const runId = randomUUID();\n const spec =\n typeof template === \"string\"\n ? await prepareTemplateSpec({\n type: \"from-file\",\n path: `./dist/tengo/tpl/${template}.plj.gz`,\n })\n : await prepareTemplateSpec(template);\n const { resultMapRid } = await this.pl.withWriteTx(\"TemplateRender\", async (tx) => {\n const tpl = loadTemplate(tx, spec);\n const renderedInputs = await inputs(tx);\n const futureOutputs = await createRenderTemplate(tx, tpl, ephemeral, renderedInputs, outputs);\n const resultMap = Pl.createPlMap(tx, futureOutputs, ephemeral);\n tx.createField(field(this.resultRootRid, runId), \"Dynamic\", resultMap);\n const resultMapRid = await toGlobalResourceId(resultMap);\n await tx.commit();\n return {\n resultMapRid,\n };\n });\n await this.resultRootTree.refreshState();\n return new TestRenderResults(this.resultRootTree.entry(resultMapRid));\n }\n\n createObject(tx: PlTransaction, value: unknown): AnyRef {\n return tx.createValue(Pl.JsonObject, JSON.stringify(value));\n }\n\n async renderWorkflow(\n workflow: string | TemplateSpecAny,\n preRun: boolean,\n args: Record<string, unknown> | Promise<Record<string, unknown>>,\n ops: WorkflowRenderOps = {},\n ): Promise<TestWorkflowResults> {\n const blockId = ops.blockId ?? randomUUID();\n const mainResult: TestRenderResults<\"result\" | \"context\"> = await this.renderTemplate(\n true,\n workflow,\n [\"result\", \"context\"],\n (tx) => {\n let ctx = undefined;\n if (ops.parent) {\n ctx = ops.parent;\n } else {\n ctx = tx.createEphemeral({ name: \"BContextEnd\", version: \"1\" });\n tx.lock(ctx);\n }\n\n return {\n args: this.createObject(tx, args),\n blockId: this.createObject(tx, blockId),\n isProduction: this.createObject(tx, !preRun),\n context: ctx,\n };\n },\n );\n\n let exports: TestRenderResults<\"result\"> | undefined = undefined;\n if (ops.exportProcessor !== undefined) {\n exports = await this.renderTemplate(true, ops.exportProcessor, [\"result\"], (tx) => ({\n pf: tx.getFutureFieldValue(mainResult.resultEntry.rid, \"context\", \"Input\"),\n }));\n }\n\n return new TestWorkflowResults(mainResult, exports, blockId);\n }\n}\n\nexport const tplTest = plTest.extend<{\n helper: TplTestHelpers;\n driverKit: MiddleLayerDriverKit;\n}>({\n helper: async ({ pl, createTree }, use): Promise<void> => {\n const resultMap = await pl.withWriteTx(\"CreatingHelpers\", async (tx) => {\n const map = tx.createEphemeral(Pl.EphStdMap);\n const rootField = field(tx.clientRoot, \"templateTeste\");\n tx.createField(rootField, \"Dynamic\", map);\n await tx.commit();\n return await toGlobalResourceId(map);\n });\n const resultMapTree = await createTree(resultMap);\n await use(new TplTestHelpers(pl, resultMap, resultMapTree));\n },\n driverKit: async ({ pl, tmpFolder }, use): Promise<void> => {\n const frontendDownloadPath = path.join(tmpFolder, \"frontend\");\n\n const driverKit = await initDriverKit(pl, tmpFolder, frontendDownloadPath, {\n localSecret: MiddleLayer.generateLocalSecret(),\n localProjections: [], // TODO must be different with local pl\n openFileDialogCallback: () => {\n throw new Error(\"Not implemented.\");\n },\n });\n\n await use(driverKit);\n },\n});\n"],"mappings":";;;;;;;;;AAuCA,IAAa,oBAAb,MAAiD;CAC/C,YAAY,AAAgB,aAA0B;EAA1B;;CAE5B,AAAO,cACL,MACA,IAC8C;AAC9C,SAAOA,sCAAW,MAAM,QAAQ;AAK9B,UAAO,GAJgB,IACpB,SAAS,KAAK,YAAY,CAC1B,MAAM,CACN,SAAS;IAAE,OAAO;IAAM,iBAAiB;IAAS,CAAC,EAC5B,IAAI;IAC9B;;;AAIN,IAAa,sBAAb,MAAiC;CAC/B,YACE,AAAgB,cAChB,AAAgB,wBAChB,AAAgB,SAChB;EAHgB;EACA;EACA;;;;;CAMlB,AAAO,UAA+C;AACpD,SAAO,KAAK,aAAa,cAAc,YAAY,OAAO,IAAI,GAAG,CAAC,gBAAgB;;;;;CAMpF,AAAO,SAA8C;AACnD,SAAO,KAAK,aAAa,cAAc,WAAW,OAAO,IAAI,GAAG,CAAC,gBAAgB;;CAGnF,AAAO,OACL,MACA,IAC8C;AAC9C,MAAI,KAAK,2BAA2B,OAClC,QAAO,KAAK,uBAAuB,cAAc,WAAW,KAAK,QAAQ;AACvE,UAAO,GAAG,KAAK,SAAS;IAAE,OAAO;IAAM,iBAAiB;IAAS,CAAC,EAAE,IAAI;IACxE;MAEF,QAAO,KAAK,aAAa,cAAc,YAAY,KAAK,QAAQ;AAC9D,UAAO,GAAG,KAAK,SAAS;IAAE,OAAO,UAAU;IAAQ,iBAAiB;IAAS,CAAC,EAAE,IAAI;IACpF;;CAGN,AAAO,OACL,MACA,IAC8C;AAC9C,SAAO,KAAK,aAAa,cAAc,WAAW,KAAK,QAAQ;AAC7D,UAAO,GAAG,KAAK,SAAS;IAAE,OAAO;IAAM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,IAAI,QAAQ;IACvC,cAAc,KAAK,aAAa,IAAI,CAAC,OAAO;IAC5C,SAAS;IACV;IAEJ;EAED,IAAI,UAAmD;AACvD,MAAI,IAAI,oBAAoB,OAC1B,WAAU,MAAM,KAAK,eAAe,MAAM,IAAI,iBAAiB,CAAC,SAAS,GAAG,QAAQ,EAClF,IAAI,GAAG,oBAAoB,WAAW,YAAY,KAAK,WAAW,QAAQ,EAC3E,EAAE;AAGL,SAAO,IAAI,oBAAoB,YAAY,SAAS,QAAQ;;;AAIhE,MAAa,UAAUC,uBAAO,OAG3B;CACD,QAAQ,OAAO,EAAE,IAAI,cAAc,QAAuB;EACxD,MAAM,YAAY,MAAM,GAAG,YAAY,mBAAmB,OAAO,OAAO;GACtE,MAAM,MAAM,GAAG,gBAAgBD,mCAAG,UAAU;GAC5C,MAAM,uDAAkB,GAAG,YAAY,gBAAgB;AACvD,MAAG,YAAY,WAAW,WAAW,IAAI;AACzC,SAAM,GAAG,QAAQ;AACjB,UAAO,8DAAyB,IAAI;IACpC;AAEF,QAAM,IAAI,IAAI,eAAe,IAAI,WADX,MAAM,WAAW,UAAU,CACS,CAAC;;CAE7D,WAAW,OAAO,EAAE,IAAI,aAAa,QAAuB;AAW1D,QAAM,IARY,yDAAoB,IAAI,WAFbE,kBAAK,KAAK,WAAW,WAAW,EAEc;GACzE,aAAaC,4CAAY,qBAAqB;GAC9C,kBAAkB,EAAE;GACpB,8BAA8B;AAC5B,UAAM,IAAI,MAAM,mBAAmB;;GAEtC,CAAC,CAEkB;;CAEvB,CAAC"}
|
package/dist/test-template.d.ts
CHANGED
|
@@ -1,48 +1,53 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { AnyRef, MiddleLayerDriverKit, PlClient, PlTransaction, ResourceId, TemplateSpecAny } from "@milaboratories/pl-middle-layer";
|
|
2
|
+
import * as _milaboratories_pl_tree0 from "@milaboratories/pl-tree";
|
|
3
|
+
import { PlTreeEntry, PlTreeNodeAccessor, SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
4
|
+
import * as vitest from "vitest";
|
|
5
|
+
import { Computable, ComputableCtx, ComputableStableDefined, UnwrapComputables } from "@milaboratories/computable";
|
|
6
|
+
|
|
7
|
+
//#region src/test-template.d.ts
|
|
8
|
+
type WorkflowRenderOps = {
|
|
9
|
+
parent?: ResourceId;
|
|
10
|
+
exportProcessor?: TemplateSpecAny;
|
|
11
|
+
blockId?: string;
|
|
9
12
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
declare class TestRenderResults<O extends string> {
|
|
14
|
+
readonly resultEntry: PlTreeEntry;
|
|
15
|
+
constructor(resultEntry: PlTreeEntry);
|
|
16
|
+
computeOutput<R>(name: O, cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R): Computable<UnwrapComputables<R> | undefined>;
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
declare class TestWorkflowResults {
|
|
19
|
+
readonly renderResult: TestRenderResults<"context" | "result">;
|
|
20
|
+
readonly processedExportsResult: TestRenderResults<"result"> | undefined;
|
|
21
|
+
readonly blockId: string;
|
|
22
|
+
constructor(renderResult: TestRenderResults<"context" | "result">, processedExportsResult: TestRenderResults<"result"> | undefined, blockId: string);
|
|
23
|
+
/**
|
|
24
|
+
* Returns context id of this workflow
|
|
25
|
+
* */
|
|
26
|
+
context(): ComputableStableDefined<ResourceId>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns context id of this workflow
|
|
29
|
+
* */
|
|
30
|
+
result(): ComputableStableDefined<ResourceId>;
|
|
31
|
+
export<R>(name: string, cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R): Computable<UnwrapComputables<R> | undefined>;
|
|
32
|
+
output<R>(name: string, cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R): Computable<UnwrapComputables<R> | undefined>;
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
declare class TplTestHelpers {
|
|
35
|
+
private readonly pl;
|
|
36
|
+
private readonly resultRootRid;
|
|
37
|
+
private readonly resultRootTree;
|
|
38
|
+
constructor(pl: PlClient, resultRootRid: ResourceId, resultRootTree: SynchronizedTreeState);
|
|
39
|
+
renderTemplate<const O extends string>(ephemeral: boolean, template: string | TemplateSpecAny, outputs: O[], inputs: (tx: PlTransaction) => Record<string, AnyRef> | Promise<Record<string, AnyRef>>): Promise<TestRenderResults<O>>;
|
|
40
|
+
createObject(tx: PlTransaction, value: unknown): AnyRef;
|
|
41
|
+
renderWorkflow(workflow: string | TemplateSpecAny, preRun: boolean, args: Record<string, unknown> | Promise<Record<string, unknown>>, ops?: WorkflowRenderOps): Promise<TestWorkflowResults>;
|
|
39
42
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
declare const tplTest: vitest.TestAPI<{
|
|
44
|
+
pl: PlClient;
|
|
45
|
+
createTree: (res: ResourceId, ops?: _milaboratories_pl_tree0.SynchronizedTreeOps) => Promise<SynchronizedTreeState>;
|
|
46
|
+
rootTree: SynchronizedTreeState;
|
|
47
|
+
tmpFolder: string;
|
|
48
|
+
helper: TplTestHelpers;
|
|
49
|
+
driverKit: MiddleLayerDriverKit;
|
|
47
50
|
}>;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { TestRenderResults, TestWorkflowResults, TplTestHelpers, WorkflowRenderOps, tplTest };
|
|
48
53
|
//# sourceMappingURL=test-template.d.ts.map
|