@platforma-sdk/test 1.53.12 → 1.53.14
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/index.d.ts +5 -5
- package/dist/test-block.cjs +14 -15
- package/dist/test-block.cjs.map +1 -1
- package/dist/test-block.d.ts +2 -2
- package/dist/test-block.d.ts.map +1 -1
- package/dist/test-block.js +14 -15
- package/dist/test-block.js.map +1 -1
- package/dist/test-pl.cjs +2 -2
- package/dist/test-pl.cjs.map +1 -1
- package/dist/test-pl.d.ts +3 -3
- package/dist/test-pl.d.ts.map +1 -1
- package/dist/test-pl.js +2 -2
- package/dist/test-pl.js.map +1 -1
- package/dist/test-template.cjs +22 -22
- package/dist/test-template.cjs.map +1 -1
- package/dist/test-template.d.ts +7 -7
- package/dist/test-template.d.ts.map +1 -1
- package/dist/test-template.js +22 -22
- package/dist/test-template.js.map +1 -1
- package/dist/util.cjs +1 -1
- package/dist/util.cjs.map +1 -1
- package/dist/util.d.ts +2 -2
- package/dist/util.js +1 -1
- package/dist/util.js.map +1 -1
- package/package.json +22 -21
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export { awaitStableState } from
|
|
5
|
-
export * as ML from
|
|
1
|
+
export * from "./test-pl";
|
|
2
|
+
export * from "./test-template";
|
|
3
|
+
export * from "./test-block";
|
|
4
|
+
export { awaitStableState } from "./util";
|
|
5
|
+
export * as ML from "@milaboratories/pl-middle-layer";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/test-block.cjs
CHANGED
|
@@ -28,15 +28,14 @@ var fsp__namespace = /*#__PURE__*/_interopNamespaceDefault(fsp);
|
|
|
28
28
|
function normalizeABDOpts(timeoutOrOps) {
|
|
29
29
|
let ops = {};
|
|
30
30
|
if (timeoutOrOps !== undefined) {
|
|
31
|
-
if (typeof timeoutOrOps ===
|
|
32
|
-
&& !(timeoutOrOps instanceof AbortSignal))
|
|
31
|
+
if (typeof timeoutOrOps === "object" && !(timeoutOrOps instanceof AbortSignal))
|
|
33
32
|
ops = { ...ops, ...timeoutOrOps };
|
|
34
33
|
else
|
|
35
34
|
ops.timeout = timeoutOrOps;
|
|
36
35
|
}
|
|
37
|
-
const abortSignal = typeof ops.timeout ===
|
|
36
|
+
const abortSignal = typeof ops.timeout === "undefined"
|
|
38
37
|
? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT)
|
|
39
|
-
: typeof ops.timeout ===
|
|
38
|
+
: typeof ops.timeout === "number"
|
|
40
39
|
? AbortSignal.timeout(ops.timeout)
|
|
41
40
|
: ops.timeout;
|
|
42
41
|
return {
|
|
@@ -61,12 +60,12 @@ async function awaitBlockDone(prj, blockId, timeoutOrOps) {
|
|
|
61
60
|
let errorMessage = blockOverview.outputsError;
|
|
62
61
|
if (errorMessage === undefined)
|
|
63
62
|
errorMessage = blockOverview.exportsError;
|
|
64
|
-
throw new Error(
|
|
63
|
+
throw new Error("Block error: " + (errorMessage ?? "no message"));
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
|
-
if (blockOverview.calculationStatus ===
|
|
66
|
+
if (blockOverview.calculationStatus === "Done")
|
|
68
67
|
return;
|
|
69
|
-
if (blockOverview.calculationStatus !==
|
|
68
|
+
if (blockOverview.calculationStatus !== "Running")
|
|
70
69
|
throw new Error(`Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`);
|
|
71
70
|
try {
|
|
72
71
|
await overview.awaitChange(ops.timeout);
|
|
@@ -74,14 +73,14 @@ async function awaitBlockDone(prj, blockId, timeoutOrOps) {
|
|
|
74
73
|
catch (e) {
|
|
75
74
|
console.dir(blockOverview, { depth: 5 });
|
|
76
75
|
console.dir(await state.getValue(), { depth: 5 });
|
|
77
|
-
throw new Error(
|
|
76
|
+
throw new Error("Aborted while awaiting block done.", { cause: e });
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
const blockTest = testPl.plTest.extend({
|
|
82
81
|
ml: async ({ pl, tmpFolder }, use) => {
|
|
83
|
-
const frontendFolder = path.join(tmpFolder,
|
|
84
|
-
const downloadFolder = path.join(tmpFolder,
|
|
82
|
+
const frontendFolder = path.join(tmpFolder, "frontend");
|
|
83
|
+
const downloadFolder = path.join(tmpFolder, "download");
|
|
85
84
|
await fsp__namespace.mkdir(frontendFolder, { recursive: true });
|
|
86
85
|
await fsp__namespace.mkdir(downloadFolder, { recursive: true });
|
|
87
86
|
const ml = await plMiddleLayer.MiddleLayer.init(pl, tmpFolder, {
|
|
@@ -90,12 +89,12 @@ const blockTest = testPl.plTest.extend({
|
|
|
90
89
|
localSecret: plMiddleLayer.MiddleLayer.generateLocalSecret(),
|
|
91
90
|
localProjections: [], // TODO must be different with local pl
|
|
92
91
|
openFileDialogCallback: () => {
|
|
93
|
-
throw new Error(
|
|
92
|
+
throw new Error("Not implemented.");
|
|
94
93
|
},
|
|
95
94
|
});
|
|
96
|
-
ml.addRuntimeCapability(
|
|
97
|
-
ml.addRuntimeCapability(
|
|
98
|
-
ml.addRuntimeCapability(
|
|
95
|
+
ml.addRuntimeCapability("requiresUIAPIVersion", 1);
|
|
96
|
+
ml.addRuntimeCapability("requiresUIAPIVersion", 2);
|
|
97
|
+
ml.addRuntimeCapability("requiresUIAPIVersion", 3);
|
|
99
98
|
try {
|
|
100
99
|
await use(ml);
|
|
101
100
|
}
|
|
@@ -104,7 +103,7 @@ const blockTest = testPl.plTest.extend({
|
|
|
104
103
|
}
|
|
105
104
|
},
|
|
106
105
|
rawPrj: async ({ ml }, use) => {
|
|
107
|
-
const pRid1 = await ml.createProject({ label:
|
|
106
|
+
const pRid1 = await ml.createProject({ label: "Test Project" }, "test_project");
|
|
108
107
|
await ml.openProject(pRid1);
|
|
109
108
|
const prj = ml.getOpenedProject(pRid1);
|
|
110
109
|
try {
|
package/dist/test-block.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-block.cjs","sources":["../src/test-block.ts"],"sourcesContent":["import path from
|
|
1
|
+
{"version":3,"file":"test-block.cjs","sources":["../src/test-block.ts"],"sourcesContent":["import path from \"node:path\";\nimport * as fsp from \"node:fs/promises\";\nimport type {\n InferBlockState,\n LocalImportFileHandle,\n Platforma,\n Project,\n} from \"@milaboratories/pl-middle-layer\";\nimport { MiddleLayer } from \"@milaboratories/pl-middle-layer\";\nimport { plTest } from \"./test-pl\";\nimport { awaitStableState } from \"./util\";\n\nexport type AwaitBlockDoneOps = {\n timeout?: number | AbortSignal;\n ignoreBlockError?: boolean;\n};\n\nexport type AwaitBlockDoneNormalized = {\n timeout: AbortSignal;\n ignoreBlockError: boolean;\n};\n\nfunction normalizeABDOpts(timeoutOrOps?: number | AwaitBlockDoneOps): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (typeof timeoutOrOps === \"object\" && !(timeoutOrOps instanceof AbortSignal))\n ops = { ...ops, ...timeoutOrOps };\n else ops.timeout = timeoutOrOps;\n }\n const abortSignal =\n typeof ops.timeout === \"undefined\"\n ? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT)\n : typeof ops.timeout === \"number\"\n ? AbortSignal.timeout(ops.timeout)\n : ops.timeout;\n return {\n timeout: abortSignal,\n ignoreBlockError: Boolean(ops.ignoreBlockError),\n };\n}\n\nexport const DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT = 5000;\n\nasync function awaitBlockDone(\n prj: Project,\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n) {\n const ops = normalizeABDOpts(timeoutOrOps);\n const overview = prj.overview;\n const state = prj.getBlockState(blockId);\n while (true) {\n const overviewSnapshot = (await overview.getValue())!;\n const blockOverview = overviewSnapshot.blocks.find((b) => b.id == blockId);\n if (blockOverview === undefined) throw new Error(`Blocks not found: ${blockId}`);\n if (blockOverview.outputErrors) {\n if (ops.ignoreBlockError) return;\n else {\n let errorMessage = blockOverview.outputsError;\n if (errorMessage === undefined) errorMessage = blockOverview.exportsError;\n throw new Error(\"Block error: \" + (errorMessage ?? \"no message\"));\n }\n }\n if (blockOverview.calculationStatus === \"Done\") return;\n if (blockOverview.calculationStatus !== \"Running\")\n throw new Error(\n `Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`,\n );\n try {\n await overview.awaitChange(ops.timeout);\n } catch (e: any) {\n console.dir(blockOverview, { depth: 5 });\n console.dir(await state.getValue(), { depth: 5 });\n throw new Error(\"Aborted while awaiting block done.\", { cause: e });\n }\n }\n}\n\nexport interface RawHelpers {\n awaitBlockDone(blockId: string, timeoutOrOps?: number | AwaitBlockDoneOps): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<LocalImportFileHandle>;\n}\n\nexport const blockTest = plTest.extend<{\n ml: MiddleLayer;\n rawPrj: Project;\n helpers: RawHelpers;\n}>({\n ml: async ({ pl, tmpFolder }, use) => {\n const frontendFolder = path.join(tmpFolder, \"frontend\");\n const downloadFolder = path.join(tmpFolder, \"download\");\n await fsp.mkdir(frontendFolder, { recursive: true });\n await fsp.mkdir(downloadFolder, { recursive: true });\n\n const ml = await MiddleLayer.init(pl, tmpFolder, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n localSecret: MiddleLayer.generateLocalSecret(),\n localProjections: [], // TODO must be different with local pl\n openFileDialogCallback: () => {\n throw new Error(\"Not implemented.\");\n },\n });\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 1);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 2);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 3);\n\n try {\n await use(ml);\n } finally {\n await ml.close();\n }\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject({ label: \"Test Project\" }, \"test_project\");\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n try {\n await use(prj);\n } finally {\n ml.closeProject(pRid1);\n }\n },\n helpers: async ({ ml, rawPrj }, use) => {\n await use({\n async awaitBlockDone(blockId, timeout) {\n await awaitBlockDone(rawPrj, blockId, timeout);\n },\n awaitBlockDoneAndGetStableBlockState: async <Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ) => {\n const ops = normalizeABDOpts(timeoutOrOps);\n await awaitBlockDone(rawPrj, blockId, ops);\n return (await awaitStableState(\n rawPrj.getBlockState(blockId),\n ops.timeout,\n )) as InferBlockState<Pl>;\n },\n async getLocalFileHandle(localPath) {\n return await ml.internalDriverKit.lsDriver.getLocalFileHandle(path.resolve(localPath));\n },\n });\n },\n});\n"],"names":["plTest","fsp","MiddleLayer","awaitStableState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,CAAC,YAAyC,EAAA;IACjE,IAAI,GAAG,GAAsB,EAAE;AAC/B,IAAA,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,EAAE,YAAY,YAAY,WAAW,CAAC;YAC5E,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,YAAY,EAAE;;AAC9B,YAAA,GAAG,CAAC,OAAO,GAAG,YAAY;IACjC;AACA,IAAA,MAAM,WAAW,GACf,OAAO,GAAG,CAAC,OAAO,KAAK;AACrB,UAAE,WAAW,CAAC,OAAO,CAAC,gCAAgC;AACtD,UAAE,OAAO,GAAG,CAAC,OAAO,KAAK;cACrB,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO;AACjC,cAAE,GAAG,CAAC,OAAO;IACnB,OAAO;AACL,QAAA,OAAO,EAAE,WAAW;AACpB,QAAA,gBAAgB,EAAE,OAAO,CAA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kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACxF,CAAC;AACF,SAAA,CAAC;IACJ,CAAC;AACF,CAAA;;;;;"}
|
package/dist/test-block.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InferBlockState, LocalImportFileHandle, Platforma, Project } from
|
|
2
|
-
import { MiddleLayer } from
|
|
1
|
+
import type { InferBlockState, LocalImportFileHandle, Platforma, Project } from "@milaboratories/pl-middle-layer";
|
|
2
|
+
import { MiddleLayer } from "@milaboratories/pl-middle-layer";
|
|
3
3
|
export type AwaitBlockDoneOps = {
|
|
4
4
|
timeout?: number | AbortSignal;
|
|
5
5
|
ignoreBlockError?: boolean;
|
package/dist/test-block.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-block.d.ts","sourceRoot":"","sources":["../src/test-block.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,SAAS,EACT,OAAO,EACR,MAAM,iCAAiC,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"test-block.d.ts","sourceRoot":"","sources":["../src/test-block.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,SAAS,EACT,OAAO,EACR,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAI9D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAqBF,eAAO,MAAM,gCAAgC,OAAO,CAAC;AAqCrD,MAAM,WAAW,UAAU;IACzB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1F,oCAAoC,CAAC,EAAE,SAAS,SAAS,EACvD,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,MAAM,GAAG,iBAAiB,GACxC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACvE;AAED,eAAO,MAAM,SAAS;;;;;;;;EA6DpB,CAAC"}
|
package/dist/test-block.js
CHANGED
|
@@ -7,15 +7,14 @@ import { awaitStableState } from './util.js';
|
|
|
7
7
|
function normalizeABDOpts(timeoutOrOps) {
|
|
8
8
|
let ops = {};
|
|
9
9
|
if (timeoutOrOps !== undefined) {
|
|
10
|
-
if (typeof timeoutOrOps ===
|
|
11
|
-
&& !(timeoutOrOps instanceof AbortSignal))
|
|
10
|
+
if (typeof timeoutOrOps === "object" && !(timeoutOrOps instanceof AbortSignal))
|
|
12
11
|
ops = { ...ops, ...timeoutOrOps };
|
|
13
12
|
else
|
|
14
13
|
ops.timeout = timeoutOrOps;
|
|
15
14
|
}
|
|
16
|
-
const abortSignal = typeof ops.timeout ===
|
|
15
|
+
const abortSignal = typeof ops.timeout === "undefined"
|
|
17
16
|
? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT)
|
|
18
|
-
: typeof ops.timeout ===
|
|
17
|
+
: typeof ops.timeout === "number"
|
|
19
18
|
? AbortSignal.timeout(ops.timeout)
|
|
20
19
|
: ops.timeout;
|
|
21
20
|
return {
|
|
@@ -40,12 +39,12 @@ async function awaitBlockDone(prj, blockId, timeoutOrOps) {
|
|
|
40
39
|
let errorMessage = blockOverview.outputsError;
|
|
41
40
|
if (errorMessage === undefined)
|
|
42
41
|
errorMessage = blockOverview.exportsError;
|
|
43
|
-
throw new Error(
|
|
42
|
+
throw new Error("Block error: " + (errorMessage ?? "no message"));
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
if (blockOverview.calculationStatus ===
|
|
45
|
+
if (blockOverview.calculationStatus === "Done")
|
|
47
46
|
return;
|
|
48
|
-
if (blockOverview.calculationStatus !==
|
|
47
|
+
if (blockOverview.calculationStatus !== "Running")
|
|
49
48
|
throw new Error(`Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`);
|
|
50
49
|
try {
|
|
51
50
|
await overview.awaitChange(ops.timeout);
|
|
@@ -53,14 +52,14 @@ async function awaitBlockDone(prj, blockId, timeoutOrOps) {
|
|
|
53
52
|
catch (e) {
|
|
54
53
|
console.dir(blockOverview, { depth: 5 });
|
|
55
54
|
console.dir(await state.getValue(), { depth: 5 });
|
|
56
|
-
throw new Error(
|
|
55
|
+
throw new Error("Aborted while awaiting block done.", { cause: e });
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
const blockTest = plTest.extend({
|
|
61
60
|
ml: async ({ pl, tmpFolder }, use) => {
|
|
62
|
-
const frontendFolder = path.join(tmpFolder,
|
|
63
|
-
const downloadFolder = path.join(tmpFolder,
|
|
61
|
+
const frontendFolder = path.join(tmpFolder, "frontend");
|
|
62
|
+
const downloadFolder = path.join(tmpFolder, "download");
|
|
64
63
|
await fsp.mkdir(frontendFolder, { recursive: true });
|
|
65
64
|
await fsp.mkdir(downloadFolder, { recursive: true });
|
|
66
65
|
const ml = await MiddleLayer.init(pl, tmpFolder, {
|
|
@@ -69,12 +68,12 @@ const blockTest = plTest.extend({
|
|
|
69
68
|
localSecret: MiddleLayer.generateLocalSecret(),
|
|
70
69
|
localProjections: [], // TODO must be different with local pl
|
|
71
70
|
openFileDialogCallback: () => {
|
|
72
|
-
throw new Error(
|
|
71
|
+
throw new Error("Not implemented.");
|
|
73
72
|
},
|
|
74
73
|
});
|
|
75
|
-
ml.addRuntimeCapability(
|
|
76
|
-
ml.addRuntimeCapability(
|
|
77
|
-
ml.addRuntimeCapability(
|
|
74
|
+
ml.addRuntimeCapability("requiresUIAPIVersion", 1);
|
|
75
|
+
ml.addRuntimeCapability("requiresUIAPIVersion", 2);
|
|
76
|
+
ml.addRuntimeCapability("requiresUIAPIVersion", 3);
|
|
78
77
|
try {
|
|
79
78
|
await use(ml);
|
|
80
79
|
}
|
|
@@ -83,7 +82,7 @@ const blockTest = plTest.extend({
|
|
|
83
82
|
}
|
|
84
83
|
},
|
|
85
84
|
rawPrj: async ({ ml }, use) => {
|
|
86
|
-
const pRid1 = await ml.createProject({ label:
|
|
85
|
+
const pRid1 = await ml.createProject({ label: "Test Project" }, "test_project");
|
|
87
86
|
await ml.openProject(pRid1);
|
|
88
87
|
const prj = ml.getOpenedProject(pRid1);
|
|
89
88
|
try {
|
package/dist/test-block.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-block.js","sources":["../src/test-block.ts"],"sourcesContent":["import path from
|
|
1
|
+
{"version":3,"file":"test-block.js","sources":["../src/test-block.ts"],"sourcesContent":["import path from \"node:path\";\nimport * as fsp from \"node:fs/promises\";\nimport type {\n InferBlockState,\n LocalImportFileHandle,\n Platforma,\n Project,\n} from \"@milaboratories/pl-middle-layer\";\nimport { MiddleLayer } from \"@milaboratories/pl-middle-layer\";\nimport { plTest } from \"./test-pl\";\nimport { awaitStableState } from \"./util\";\n\nexport type AwaitBlockDoneOps = {\n timeout?: number | AbortSignal;\n ignoreBlockError?: boolean;\n};\n\nexport type AwaitBlockDoneNormalized = {\n timeout: AbortSignal;\n ignoreBlockError: boolean;\n};\n\nfunction normalizeABDOpts(timeoutOrOps?: number | AwaitBlockDoneOps): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (typeof timeoutOrOps === \"object\" && !(timeoutOrOps instanceof AbortSignal))\n ops = { ...ops, ...timeoutOrOps };\n else ops.timeout = timeoutOrOps;\n }\n const abortSignal =\n typeof ops.timeout === \"undefined\"\n ? AbortSignal.timeout(DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT)\n : typeof ops.timeout === \"number\"\n ? AbortSignal.timeout(ops.timeout)\n : ops.timeout;\n return {\n timeout: abortSignal,\n ignoreBlockError: Boolean(ops.ignoreBlockError),\n };\n}\n\nexport const DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT = 5000;\n\nasync function awaitBlockDone(\n prj: Project,\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n) {\n const ops = normalizeABDOpts(timeoutOrOps);\n const overview = prj.overview;\n const state = prj.getBlockState(blockId);\n while (true) {\n const overviewSnapshot = (await overview.getValue())!;\n const blockOverview = overviewSnapshot.blocks.find((b) => b.id == blockId);\n if (blockOverview === undefined) throw new Error(`Blocks not found: ${blockId}`);\n if (blockOverview.outputErrors) {\n if (ops.ignoreBlockError) return;\n else {\n let errorMessage = blockOverview.outputsError;\n if (errorMessage === undefined) errorMessage = blockOverview.exportsError;\n throw new Error(\"Block error: \" + (errorMessage ?? \"no message\"));\n }\n }\n if (blockOverview.calculationStatus === \"Done\") return;\n if (blockOverview.calculationStatus !== \"Running\")\n throw new Error(\n `Unexpected block status, block not calculating anything at the moment: ${blockOverview.calculationStatus}`,\n );\n try {\n await overview.awaitChange(ops.timeout);\n } catch (e: any) {\n console.dir(blockOverview, { depth: 5 });\n console.dir(await state.getValue(), { depth: 5 });\n throw new Error(\"Aborted while awaiting block done.\", { cause: e });\n }\n }\n}\n\nexport interface RawHelpers {\n awaitBlockDone(blockId: string, timeoutOrOps?: number | AwaitBlockDoneOps): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<LocalImportFileHandle>;\n}\n\nexport const blockTest = plTest.extend<{\n ml: MiddleLayer;\n rawPrj: Project;\n helpers: RawHelpers;\n}>({\n ml: async ({ pl, tmpFolder }, use) => {\n const frontendFolder = path.join(tmpFolder, \"frontend\");\n const downloadFolder = path.join(tmpFolder, \"download\");\n await fsp.mkdir(frontendFolder, { recursive: true });\n await fsp.mkdir(downloadFolder, { recursive: true });\n\n const ml = await MiddleLayer.init(pl, tmpFolder, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n localSecret: MiddleLayer.generateLocalSecret(),\n localProjections: [], // TODO must be different with local pl\n openFileDialogCallback: () => {\n throw new Error(\"Not implemented.\");\n },\n });\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 1);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 2);\n ml.addRuntimeCapability(\"requiresUIAPIVersion\", 3);\n\n try {\n await use(ml);\n } finally {\n await ml.close();\n }\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject({ label: \"Test Project\" }, \"test_project\");\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n try {\n await use(prj);\n } finally {\n ml.closeProject(pRid1);\n }\n },\n helpers: async ({ ml, rawPrj }, use) => {\n await use({\n async awaitBlockDone(blockId, timeout) {\n await awaitBlockDone(rawPrj, blockId, timeout);\n },\n awaitBlockDoneAndGetStableBlockState: async <Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps,\n ) => {\n const ops = normalizeABDOpts(timeoutOrOps);\n await awaitBlockDone(rawPrj, blockId, ops);\n return (await awaitStableState(\n rawPrj.getBlockState(blockId),\n ops.timeout,\n )) as InferBlockState<Pl>;\n },\n async getLocalFileHandle(localPath) {\n return await ml.internalDriverKit.lsDriver.getLocalFileHandle(path.resolve(localPath));\n },\n });\n },\n});\n"],"names":[],"mappings":";;;;;;AAsBA,SAAS,gBAAgB,CAAC,YAAyC,EAAA;IACjE,IAAI,GAAG,GAAsB,EAAE;AAC/B,IAAA,IAAI,YAAY,KAAK,SAAS,EAAE;QAC9B,I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nC,MAAM,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC;YAChD,CAAC;AACD,YAAA,oCAAoC,EAAE,OACpC,OAAe,EACf,YAAyC,KACvC;AACF,gBAAA,MAAM,GAAG,GAAG,gBAAgB,CAAC,YAAY,CAAC;gBAC1C,MAAM,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC;AAC1C,gBAAA,QAAQ,MAAM,gBAAgB,CAC5B,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,EAC7B,GAAG,CAAC,OAAO,CACZ;YACH,CAAC;YACD,MAAM,kBAAkB,CAAC,SAAS,EAAA;AAChC,gBAAA,OAAO,MAAM,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACxF,CAAC;AACF,SAAA,CAAC;IACJ,CAAC;AACF,CAAA;;;;"}
|
package/dist/test-pl.cjs
CHANGED
|
@@ -32,7 +32,7 @@ const plTest = vitest.test.extend({
|
|
|
32
32
|
await fsp__namespace.mkdir(workFolder, { recursive: true });
|
|
33
33
|
await use(workFolder);
|
|
34
34
|
onTestFinished(async (context) => {
|
|
35
|
-
if (context.task.result?.state ===
|
|
35
|
+
if (context.task.result?.state === "pass") {
|
|
36
36
|
await fsp__namespace.rm(workFolder, { recursive: true });
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
@@ -54,7 +54,7 @@ const plTest = vitest.test.extend({
|
|
|
54
54
|
await client.close();
|
|
55
55
|
}
|
|
56
56
|
onTestFinished(async (context) => {
|
|
57
|
-
if (context.task.result?.state ===
|
|
57
|
+
if (context.task.result?.state === "pass") {
|
|
58
58
|
const rawClient = await plMiddleLayer.TestHelpers.getTestClient();
|
|
59
59
|
try {
|
|
60
60
|
await rawClient.deleteAlternativeRoot(alternativeRoot);
|
package/dist/test-pl.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-pl.cjs","sources":["../src/test-pl.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"test-pl.cjs","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\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"],"names":["test","randomUUID","fsp","NullResourceId","TestHelpers","resourceIdToString","SynchronizedTreeState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,MAAM,MAAM,GAAGA,WAAI,CAAC,MAAM,CAK9B;IACD,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,GAAG,KAAI;QAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,CAAA,KAAA,EAAQC,sBAAU,EAAE,CAAA,CAAE,CAAC;AACvD,QAAA,MAAMC,cAAG,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAChD,QAAA,MAAM,GAAG,CAAC,UAAU,CAAC;AACrB,QAAA,cAAc,CAAC,OAAO,OAAO,KAAI;YAC/B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,KAAK,MAAM,EAAE;AACzC,gBAAA,MAAMA,cAAG,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YAC/C;iBAAO;AACL,gBAAA,OAAO,CAAC,GAAG,CAAC,wCAAwC,UAAU,CAAA,CAAE,CAAC;YACnE;AACF,QAAA,CAAC,CAAC;IACJ,CAAC;IAED,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,GAAG,KAAI;QACpC,MAAM,e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AAG,IAAI;AACL,wBAAA,eAAe,EAAE,GAAG;AACpB,wBAAA,gBAAgB,EAAE,GAAG;AACtB,qBAAA,CACF;AACD,oBAAA,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC;gBAC7B;AACA,gBAAA,OAAO,WAAW;AACpB,YAAA,CAAC,CAAC;QACJ;gBAAU;YACR,KAAK,MAAM,GAAG,WAAW,CAAC,IAAI,KAAK,EAAE;AACnC,gBAAA,MAAM,CAAC,MAAM,WAAW,EAAE,SAAS,EAAE;YACvC;QACF;IACF,CAAC;AAED,IAAA,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,KAAI;QAChD,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;AACF,CAAA;;;;"}
|
package/dist/test-pl.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PlClient, ResourceId } from
|
|
2
|
-
import type { SynchronizedTreeOps } from
|
|
3
|
-
import { SynchronizedTreeState } from
|
|
1
|
+
import type { PlClient, ResourceId } from "@milaboratories/pl-middle-layer";
|
|
2
|
+
import type { SynchronizedTreeOps } from "@milaboratories/pl-tree";
|
|
3
|
+
import { SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
4
4
|
export declare const plTest: import("vitest").TestAPI<{
|
|
5
5
|
pl: PlClient;
|
|
6
6
|
createTree: (res: ResourceId, ops?: SynchronizedTreeOps) => Promise<SynchronizedTreeState>;
|
package/dist/test-pl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-pl.d.ts","sourceRoot":"","sources":["../src/test-pl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"test-pl.d.ts","sourceRoot":"","sources":["../src/test-pl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,QAAQ,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAEhG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAMhE,eAAO,MAAM,MAAM;;sBAEC,UAAU,QAAQ,mBAAmB,KAAK,OAAO,CAAC,qBAAqB,CAAC;;;EA6E1F,CAAC"}
|
package/dist/test-pl.js
CHANGED
|
@@ -11,7 +11,7 @@ const plTest = test.extend({
|
|
|
11
11
|
await fsp.mkdir(workFolder, { recursive: true });
|
|
12
12
|
await use(workFolder);
|
|
13
13
|
onTestFinished(async (context) => {
|
|
14
|
-
if (context.task.result?.state ===
|
|
14
|
+
if (context.task.result?.state === "pass") {
|
|
15
15
|
await fsp.rm(workFolder, { recursive: true });
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
@@ -33,7 +33,7 @@ const plTest = test.extend({
|
|
|
33
33
|
await client.close();
|
|
34
34
|
}
|
|
35
35
|
onTestFinished(async (context) => {
|
|
36
|
-
if (context.task.result?.state ===
|
|
36
|
+
if (context.task.result?.state === "pass") {
|
|
37
37
|
const rawClient = await TestHelpers.getTestClient();
|
|
38
38
|
try {
|
|
39
39
|
await rawClient.deleteAlternativeRoot(alternativeRoot);
|
package/dist/test-pl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-pl.js","sources":["../src/test-pl.ts"],"sourcesContent":["import type {
|
|
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\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.cl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AC,MAAM,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;AACF,CAAA;;;;"}
|
package/dist/test-template.cjs
CHANGED
|
@@ -16,7 +16,7 @@ class TestRenderResults {
|
|
|
16
16
|
const outputAccessor = ctx
|
|
17
17
|
.accessor(this.resultEntry)
|
|
18
18
|
.node()
|
|
19
|
-
.traverse({ field: name, assertFieldType:
|
|
19
|
+
.traverse({ field: name, assertFieldType: "Input" });
|
|
20
20
|
return cb(outputAccessor, ctx);
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -34,27 +34,27 @@ class TestWorkflowResults {
|
|
|
34
34
|
* Returns context id of this workflow
|
|
35
35
|
* */
|
|
36
36
|
context() {
|
|
37
|
-
return this.renderResult.computeOutput(
|
|
37
|
+
return this.renderResult.computeOutput("context", (cb) => cb?.id).withStableType();
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Returns context id of this workflow
|
|
41
41
|
* */
|
|
42
42
|
result() {
|
|
43
|
-
return this.renderResult.computeOutput(
|
|
43
|
+
return this.renderResult.computeOutput("result", (cb) => cb?.id).withStableType();
|
|
44
44
|
}
|
|
45
45
|
export(name, cb) {
|
|
46
46
|
if (this.processedExportsResult !== undefined)
|
|
47
|
-
return this.processedExportsResult.computeOutput(
|
|
48
|
-
return cb(acc?.traverse({ field: name, assertFieldType:
|
|
47
|
+
return this.processedExportsResult.computeOutput("result", (acc, ctx) => {
|
|
48
|
+
return cb(acc?.traverse({ field: name, assertFieldType: "Input" }), ctx);
|
|
49
49
|
});
|
|
50
50
|
else
|
|
51
|
-
return this.renderResult.computeOutput(
|
|
52
|
-
return cb(acc?.traverse({ field: `values/${name}`, assertFieldType:
|
|
51
|
+
return this.renderResult.computeOutput("context", (acc, ctx) => {
|
|
52
|
+
return cb(acc?.traverse({ field: `values/${name}`, assertFieldType: "Input" }), ctx);
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
output(name, cb) {
|
|
56
|
-
return this.renderResult.computeOutput(
|
|
57
|
-
return cb(acc?.traverse({ field: name, assertFieldType:
|
|
56
|
+
return this.renderResult.computeOutput("result", (acc, ctx) => {
|
|
57
|
+
return cb(acc?.traverse({ field: name, assertFieldType: "Input" }), ctx);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -69,18 +69,18 @@ class TplTestHelpers {
|
|
|
69
69
|
}
|
|
70
70
|
async renderTemplate(ephemeral, template, outputs, inputs) {
|
|
71
71
|
const runId = node_crypto.randomUUID();
|
|
72
|
-
const spec = typeof template ===
|
|
72
|
+
const spec = typeof template === "string"
|
|
73
73
|
? await plMiddleLayer.prepareTemplateSpec({
|
|
74
|
-
type:
|
|
74
|
+
type: "from-file",
|
|
75
75
|
path: `./dist/tengo/tpl/${template}.plj.gz`,
|
|
76
76
|
})
|
|
77
77
|
: await plMiddleLayer.prepareTemplateSpec(template);
|
|
78
|
-
const { resultMapRid } = await this.pl.withWriteTx(
|
|
78
|
+
const { resultMapRid } = await this.pl.withWriteTx("TemplateRender", async (tx) => {
|
|
79
79
|
const tpl = plMiddleLayer.loadTemplate(tx, spec);
|
|
80
80
|
const renderedInputs = await inputs(tx);
|
|
81
81
|
const futureOutputs = await plMiddleLayer.createRenderTemplate(tx, tpl, ephemeral, renderedInputs, outputs);
|
|
82
82
|
const resultMap = plMiddleLayer.Pl.createPlMap(tx, futureOutputs, ephemeral);
|
|
83
|
-
tx.createField(plMiddleLayer.field(this.resultRootRid, runId),
|
|
83
|
+
tx.createField(plMiddleLayer.field(this.resultRootRid, runId), "Dynamic", resultMap);
|
|
84
84
|
const resultMapRid = await plMiddleLayer.toGlobalResourceId(resultMap);
|
|
85
85
|
await tx.commit();
|
|
86
86
|
return {
|
|
@@ -95,13 +95,13 @@ class TplTestHelpers {
|
|
|
95
95
|
}
|
|
96
96
|
async renderWorkflow(workflow, preRun, args, ops = {}) {
|
|
97
97
|
const blockId = ops.blockId ?? node_crypto.randomUUID();
|
|
98
|
-
const mainResult = await this.renderTemplate(true, workflow, [
|
|
98
|
+
const mainResult = await this.renderTemplate(true, workflow, ["result", "context"], (tx) => {
|
|
99
99
|
let ctx = undefined;
|
|
100
100
|
if (ops.parent) {
|
|
101
101
|
ctx = ops.parent;
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
|
-
ctx = tx.createEphemeral({ name:
|
|
104
|
+
ctx = tx.createEphemeral({ name: "BContextEnd", version: "1" });
|
|
105
105
|
tx.lock(ctx);
|
|
106
106
|
}
|
|
107
107
|
return {
|
|
@@ -113,8 +113,8 @@ class TplTestHelpers {
|
|
|
113
113
|
});
|
|
114
114
|
let exports = undefined;
|
|
115
115
|
if (ops.exportProcessor !== undefined) {
|
|
116
|
-
exports = await this.renderTemplate(true, ops.exportProcessor, [
|
|
117
|
-
pf: tx.getFutureFieldValue(mainResult.resultEntry.rid,
|
|
116
|
+
exports = await this.renderTemplate(true, ops.exportProcessor, ["result"], (tx) => ({
|
|
117
|
+
pf: tx.getFutureFieldValue(mainResult.resultEntry.rid, "context", "Input"),
|
|
118
118
|
}));
|
|
119
119
|
}
|
|
120
120
|
return new TestWorkflowResults(mainResult, exports, blockId);
|
|
@@ -122,10 +122,10 @@ class TplTestHelpers {
|
|
|
122
122
|
}
|
|
123
123
|
const tplTest = testPl.plTest.extend({
|
|
124
124
|
helper: async ({ pl, createTree }, use) => {
|
|
125
|
-
const resultMap = await pl.withWriteTx(
|
|
125
|
+
const resultMap = await pl.withWriteTx("CreatingHelpers", async (tx) => {
|
|
126
126
|
const map = tx.createEphemeral(plMiddleLayer.Pl.EphStdMap);
|
|
127
|
-
const rootField = plMiddleLayer.field(tx.clientRoot,
|
|
128
|
-
tx.createField(rootField,
|
|
127
|
+
const rootField = plMiddleLayer.field(tx.clientRoot, "templateTeste");
|
|
128
|
+
tx.createField(rootField, "Dynamic", map);
|
|
129
129
|
await tx.commit();
|
|
130
130
|
return await plMiddleLayer.toGlobalResourceId(map);
|
|
131
131
|
});
|
|
@@ -133,12 +133,12 @@ const tplTest = testPl.plTest.extend({
|
|
|
133
133
|
await use(new TplTestHelpers(pl, resultMap, resultMapTree));
|
|
134
134
|
},
|
|
135
135
|
driverKit: async ({ pl, tmpFolder }, use) => {
|
|
136
|
-
const frontendDownloadPath = path.join(tmpFolder,
|
|
136
|
+
const frontendDownloadPath = path.join(tmpFolder, "frontend");
|
|
137
137
|
const driverKit = await plMiddleLayer.initDriverKit(pl, tmpFolder, frontendDownloadPath, {
|
|
138
138
|
localSecret: plMiddleLayer.MiddleLayer.generateLocalSecret(),
|
|
139
139
|
localProjections: [], // TODO must be different with local pl
|
|
140
140
|
openFileDialogCallback: () => {
|
|
141
|
-
throw new Error(
|
|
141
|
+
throw new Error("Not implemented.");
|
|
142
142
|
},
|
|
143
143
|
});
|
|
144
144
|
await use(driverKit);
|
|
@@ -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 {\n Computable,\n} from '@milaboratories/computable';\nimport type {\n AnyRef,\n MiddleLayerDriverKit,\n PlClient,\n PlTransaction,\n ResourceId,\n TemplateSpecAny } 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 { PlTreeEntry, PlTreeNodeAccessor, SynchronizedTreeState } 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(\n 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":";;;;;;;;MAoCa,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,sB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AS,CAAC;AACjD,QAAA,MAAM,GAAG,CAAC,IAAI,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IAC7D,CAAC;IACD,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,KAAmB;QACzD,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;QAE7D,MAAM,SAAS,GAAG,MAAME,2BAAa,CAAC,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE;AACzE,YAAA,WAAW,EAAEC,yBAAW,CAAC,mBAAmB,EAAE;YAC9C,gBAAgB,EAAE,EAAE;YACpB,sBAAsB,EAAE,MAAK;AAC3B,gBAAA,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;YACrC,CAAC;AACF,SAAA,CAAC;AAEF,QAAA,MAAM,GAAG,CAAC,SAAS,CAAC;IACtB,CAAC;AACF,CAAA;;;;;;;"}
|
|
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,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ACzC,YAAA,MAAM,EAAE,CAAC,MAAM,EAAE;AACjB,YAAA,OAAO,MAAMC,gCAAkB,CAAC,GAAG,CAAC;AACtC,QAAA,CAAC,CAAC;AACF,QAAA,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC;AACjD,QAAA,MAAM,GAAG,CAAC,IAAI,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IAC7D,CAAC;IACD,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,KAAmB;QACzD,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;QAE7D,MAAM,SAAS,GAAG,MAAME,2BAAa,CAAC,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE;AACzE,YAAA,WAAW,EAAEC,yBAAW,CAAC,mBAAmB,EAAE;YAC9C,gBAAgB,EAAE,EAAE;YACpB,sBAAsB,EAAE,MAAK;AAC3B,gBAAA,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;YACrC,CAAC;AACF,SAAA,CAAC;AAEF,QAAA,MAAM,GAAG,CAAC,SAAS,CAAC;IACtB,CAAC;AACF,CAAA;;;;;;;"}
|
package/dist/test-template.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ComputableCtx, ComputableStableDefined, UnwrapComputables } from
|
|
2
|
-
import { Computable } from
|
|
3
|
-
import type { AnyRef, MiddleLayerDriverKit, PlClient, PlTransaction, ResourceId, TemplateSpecAny } from
|
|
4
|
-
import type { PlTreeEntry, PlTreeNodeAccessor, SynchronizedTreeState } from
|
|
1
|
+
import type { ComputableCtx, ComputableStableDefined, UnwrapComputables } from "@milaboratories/computable";
|
|
2
|
+
import { Computable } from "@milaboratories/computable";
|
|
3
|
+
import type { AnyRef, MiddleLayerDriverKit, PlClient, PlTransaction, ResourceId, TemplateSpecAny } from "@milaboratories/pl-middle-layer";
|
|
4
|
+
import type { PlTreeEntry, PlTreeNodeAccessor, SynchronizedTreeState } from "@milaboratories/pl-tree";
|
|
5
5
|
export type WorkflowRenderOps = {
|
|
6
6
|
parent?: ResourceId;
|
|
7
7
|
exportProcessor?: TemplateSpecAny;
|
|
@@ -13,10 +13,10 @@ export declare class TestRenderResults<O extends string> {
|
|
|
13
13
|
computeOutput<R>(name: O, cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R): Computable<UnwrapComputables<R> | undefined>;
|
|
14
14
|
}
|
|
15
15
|
export declare class TestWorkflowResults {
|
|
16
|
-
readonly renderResult: TestRenderResults<
|
|
17
|
-
readonly processedExportsResult: TestRenderResults<
|
|
16
|
+
readonly renderResult: TestRenderResults<"context" | "result">;
|
|
17
|
+
readonly processedExportsResult: TestRenderResults<"result"> | undefined;
|
|
18
18
|
readonly blockId: string;
|
|
19
|
-
constructor(renderResult: TestRenderResults<
|
|
19
|
+
constructor(renderResult: TestRenderResults<"context" | "result">, processedExportsResult: TestRenderResults<"result"> | undefined, blockId: string);
|
|
20
20
|
/**
|
|
21
21
|
* Returns context id of this workflow
|
|
22
22
|
* */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-template.d.ts","sourceRoot":"","sources":["../src/test-template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"test-template.d.ts","sourceRoot":"","sources":["../src/test-template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,EACV,MAAM,EACN,oBAAoB,EACpB,QAAQ,EACR,aAAa,EACb,UAAU,EACV,eAAe,EAChB,MAAM,iCAAiC,CAAC;AAWzC,O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AAC,GAAG,EAAE,kBAAkB,GAAG,SAAS,EAAE,GAAG,EAAE,aAAa,KAAK,CAAC,GACjE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CAKhD;AAED,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAFd,EAAE,EAAE,QAAQ,EACZ,aAAa,EAAE,UAAU,EACzB,cAAc,EAAE,qBAAqB;IAGlD,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EACzC,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,MAAM,GAAG,eAAe,EAClC,OAAO,EAAE,CAAC,EAAE,EACZ,MAAM,EAAE,CAAC,EAAE,EAAE,aAAa,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACtF,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAyBhC,YAAY,CAAC,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM;IAIjD,cAAc,CAClB,QAAQ,EAAE,MAAM,GAAG,eAAe,EAClC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAChE,GAAG,GAAE,iBAAsB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;CAiChC;AAED,eAAO,MAAM,OAAO;;;;;;;EA4BlB,CAAC"}
|
package/dist/test-template.js
CHANGED
|
@@ -14,7 +14,7 @@ class TestRenderResults {
|
|
|
14
14
|
const outputAccessor = ctx
|
|
15
15
|
.accessor(this.resultEntry)
|
|
16
16
|
.node()
|
|
17
|
-
.traverse({ field: name, assertFieldType:
|
|
17
|
+
.traverse({ field: name, assertFieldType: "Input" });
|
|
18
18
|
return cb(outputAccessor, ctx);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -32,27 +32,27 @@ class TestWorkflowResults {
|
|
|
32
32
|
* Returns context id of this workflow
|
|
33
33
|
* */
|
|
34
34
|
context() {
|
|
35
|
-
return this.renderResult.computeOutput(
|
|
35
|
+
return this.renderResult.computeOutput("context", (cb) => cb?.id).withStableType();
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Returns context id of this workflow
|
|
39
39
|
* */
|
|
40
40
|
result() {
|
|
41
|
-
return this.renderResult.computeOutput(
|
|
41
|
+
return this.renderResult.computeOutput("result", (cb) => cb?.id).withStableType();
|
|
42
42
|
}
|
|
43
43
|
export(name, cb) {
|
|
44
44
|
if (this.processedExportsResult !== undefined)
|
|
45
|
-
return this.processedExportsResult.computeOutput(
|
|
46
|
-
return cb(acc?.traverse({ field: name, assertFieldType:
|
|
45
|
+
return this.processedExportsResult.computeOutput("result", (acc, ctx) => {
|
|
46
|
+
return cb(acc?.traverse({ field: name, assertFieldType: "Input" }), ctx);
|
|
47
47
|
});
|
|
48
48
|
else
|
|
49
|
-
return this.renderResult.computeOutput(
|
|
50
|
-
return cb(acc?.traverse({ field: `values/${name}`, assertFieldType:
|
|
49
|
+
return this.renderResult.computeOutput("context", (acc, ctx) => {
|
|
50
|
+
return cb(acc?.traverse({ field: `values/${name}`, assertFieldType: "Input" }), ctx);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
output(name, cb) {
|
|
54
|
-
return this.renderResult.computeOutput(
|
|
55
|
-
return cb(acc?.traverse({ field: name, assertFieldType:
|
|
54
|
+
return this.renderResult.computeOutput("result", (acc, ctx) => {
|
|
55
|
+
return cb(acc?.traverse({ field: name, assertFieldType: "Input" }), ctx);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -67,18 +67,18 @@ class TplTestHelpers {
|
|
|
67
67
|
}
|
|
68
68
|
async renderTemplate(ephemeral, template, outputs, inputs) {
|
|
69
69
|
const runId = randomUUID();
|
|
70
|
-
const spec = typeof template ===
|
|
70
|
+
const spec = typeof template === "string"
|
|
71
71
|
? await prepareTemplateSpec({
|
|
72
|
-
type:
|
|
72
|
+
type: "from-file",
|
|
73
73
|
path: `./dist/tengo/tpl/${template}.plj.gz`,
|
|
74
74
|
})
|
|
75
75
|
: await prepareTemplateSpec(template);
|
|
76
|
-
const { resultMapRid } = await this.pl.withWriteTx(
|
|
76
|
+
const { resultMapRid } = await this.pl.withWriteTx("TemplateRender", async (tx) => {
|
|
77
77
|
const tpl = loadTemplate(tx, spec);
|
|
78
78
|
const renderedInputs = await inputs(tx);
|
|
79
79
|
const futureOutputs = await createRenderTemplate(tx, tpl, ephemeral, renderedInputs, outputs);
|
|
80
80
|
const resultMap = Pl.createPlMap(tx, futureOutputs, ephemeral);
|
|
81
|
-
tx.createField(field(this.resultRootRid, runId),
|
|
81
|
+
tx.createField(field(this.resultRootRid, runId), "Dynamic", resultMap);
|
|
82
82
|
const resultMapRid = await toGlobalResourceId(resultMap);
|
|
83
83
|
await tx.commit();
|
|
84
84
|
return {
|
|
@@ -93,13 +93,13 @@ class TplTestHelpers {
|
|
|
93
93
|
}
|
|
94
94
|
async renderWorkflow(workflow, preRun, args, ops = {}) {
|
|
95
95
|
const blockId = ops.blockId ?? randomUUID();
|
|
96
|
-
const mainResult = await this.renderTemplate(true, workflow, [
|
|
96
|
+
const mainResult = await this.renderTemplate(true, workflow, ["result", "context"], (tx) => {
|
|
97
97
|
let ctx = undefined;
|
|
98
98
|
if (ops.parent) {
|
|
99
99
|
ctx = ops.parent;
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
|
-
ctx = tx.createEphemeral({ name:
|
|
102
|
+
ctx = tx.createEphemeral({ name: "BContextEnd", version: "1" });
|
|
103
103
|
tx.lock(ctx);
|
|
104
104
|
}
|
|
105
105
|
return {
|
|
@@ -111,8 +111,8 @@ class TplTestHelpers {
|
|
|
111
111
|
});
|
|
112
112
|
let exports = undefined;
|
|
113
113
|
if (ops.exportProcessor !== undefined) {
|
|
114
|
-
exports = await this.renderTemplate(true, ops.exportProcessor, [
|
|
115
|
-
pf: tx.getFutureFieldValue(mainResult.resultEntry.rid,
|
|
114
|
+
exports = await this.renderTemplate(true, ops.exportProcessor, ["result"], (tx) => ({
|
|
115
|
+
pf: tx.getFutureFieldValue(mainResult.resultEntry.rid, "context", "Input"),
|
|
116
116
|
}));
|
|
117
117
|
}
|
|
118
118
|
return new TestWorkflowResults(mainResult, exports, blockId);
|
|
@@ -120,10 +120,10 @@ class TplTestHelpers {
|
|
|
120
120
|
}
|
|
121
121
|
const tplTest = plTest.extend({
|
|
122
122
|
helper: async ({ pl, createTree }, use) => {
|
|
123
|
-
const resultMap = await pl.withWriteTx(
|
|
123
|
+
const resultMap = await pl.withWriteTx("CreatingHelpers", async (tx) => {
|
|
124
124
|
const map = tx.createEphemeral(Pl.EphStdMap);
|
|
125
|
-
const rootField = field(tx.clientRoot,
|
|
126
|
-
tx.createField(rootField,
|
|
125
|
+
const rootField = field(tx.clientRoot, "templateTeste");
|
|
126
|
+
tx.createField(rootField, "Dynamic", map);
|
|
127
127
|
await tx.commit();
|
|
128
128
|
return await toGlobalResourceId(map);
|
|
129
129
|
});
|
|
@@ -131,12 +131,12 @@ const tplTest = plTest.extend({
|
|
|
131
131
|
await use(new TplTestHelpers(pl, resultMap, resultMapTree));
|
|
132
132
|
},
|
|
133
133
|
driverKit: async ({ pl, tmpFolder }, use) => {
|
|
134
|
-
const frontendDownloadPath = path.join(tmpFolder,
|
|
134
|
+
const frontendDownloadPath = path.join(tmpFolder, "frontend");
|
|
135
135
|
const driverKit = await initDriverKit(pl, tmpFolder, frontendDownloadPath, {
|
|
136
136
|
localSecret: MiddleLayer.generateLocalSecret(),
|
|
137
137
|
localProjections: [], // TODO must be different with local pl
|
|
138
138
|
openFileDialogCallback: () => {
|
|
139
|
-
throw new Error(
|
|
139
|
+
throw new Error("Not implemented.");
|
|
140
140
|
},
|
|
141
141
|
});
|
|
142
142
|
await use(driverKit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-template.js","sources":["../src/test-template.ts"],"sourcesContent":["import type {\n ComputableCtx,\n ComputableStableDefined,\n UnwrapComputables,\n} from '@milaboratories/computable';\nimport {\n Computable,\n} from '@milaboratories/computable';\nimport type {\n AnyRef,\n MiddleLayerDriverKit,\n PlClient,\n PlTransaction,\n ResourceId,\n TemplateSpecAny } 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 { PlTreeEntry, PlTreeNodeAccessor, SynchronizedTreeState } 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(\n 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":[],"mappings":";;;;;;MAoCa,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,OAAO,UAAU,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,IAAI,I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,GAAG,CAAC,SAAS,CAAC;IACtB,CAAC;AACF,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"test-template.js","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":[],"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,OAAO,UAAU,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,I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,CAAC;AACF,SAAA,CAAC;AAEF,QAAA,MAAM,GAAG,CAAC,SAAS,CAAC;IACtB,CAAC;AACF,CAAA;;;;"}
|
package/dist/util.cjs
CHANGED
|
@@ -4,7 +4,7 @@ var plClient = require('@milaboratories/pl-client');
|
|
|
4
4
|
|
|
5
5
|
async function awaitStableState(computable, timeout = 5000) {
|
|
6
6
|
try {
|
|
7
|
-
return await computable.awaitStableValue(typeof timeout ===
|
|
7
|
+
return await computable.awaitStableValue(typeof timeout === "number" ? AbortSignal.timeout(timeout) : timeout);
|
|
8
8
|
}
|
|
9
9
|
catch (e) {
|
|
10
10
|
if (plClient.isTimeoutOrCancelError(e)) {
|
package/dist/util.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.cjs","sources":["../src/util.ts"],"sourcesContent":["import type { Computable } from
|
|
1
|
+
{"version":3,"file":"util.cjs","sources":["../src/util.ts"],"sourcesContent":["import type { Computable } from \"@milaboratories/computable\";\nimport { isTimeoutOrCancelError } from \"@milaboratories/pl-client\";\nimport type { BigIntStats } from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\n\nexport async function tryStat(path: string): Promise<BigIntStats | undefined> {\n try {\n return await fsp.stat(path, { bigint: true });\n } catch (error: unknown) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return undefined;\n }\n throw error;\n }\n}\n\nexport async function awaitStableState<S>(\n computable: Computable<unknown, S>,\n timeout: number | AbortSignal = 5000,\n): Promise<S> {\n try {\n return await computable.awaitStableValue(\n typeof timeout === \"number\" ? AbortSignal.timeout(timeout) : timeout,\n );\n } catch (e: unknown) {\n if (isTimeoutOrCancelError(e)) {\n const fullValue = await computable.getFullValue();\n console.dir(fullValue, { depth: 5 });\n throw new Error(\n `Aborted while awaiting stable value. Unstable marker: ${fullValue.unstableMarker}`,\n { cause: e },\n );\n } else throw e;\n }\n}\n"],"names":["isTimeoutOrCancelError"],"mappings":";;;;AAgBO,eAAe,gBAAgB,CACpC,UAAkC,EAClC,UAAgC,IAAI,EAAA;AAEpC,IAAA,IAAI;QACF,OAAO,MAAM,UAAU,CAAC,gBAAgB,CACtC,OAAO,OAAO,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CACrE;IACH;IAAE,OAAO,CAAU,EAAE;AACnB,QAAA,IAAIA,+BAAsB,CAAC,CAAC,CAAC,EAAE;AAC7B,YAAA,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,YAAY,EAAE;YACjD,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AACpC,YAAA,MAAM,IAAI,KAAK,CACb,CAAA,sDAAA,EAAyD,SAAS,CAAC,cAAc,CAAA,CAAE,EACnF,EAAE,KAAK,EAAE,CAAC,EAAE,CACb;QACH;;AAAO,YAAA,MAAM,CAAC;IAChB;AACF;;;;"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Computable } from
|
|
2
|
-
import type { BigIntStats } from
|
|
1
|
+
import type { Computable } from "@milaboratories/computable";
|
|
2
|
+
import type { BigIntStats } from "node:fs";
|
|
3
3
|
export declare function tryStat(path: string): Promise<BigIntStats | undefined>;
|
|
4
4
|
export declare function awaitStableState<S>(computable: Computable<unknown, S>, timeout?: number | AbortSignal): Promise<S>;
|
|
5
5
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isTimeoutOrCancelError } from '@milaboratories/pl-client';
|
|
|
2
2
|
|
|
3
3
|
async function awaitStableState(computable, timeout = 5000) {
|
|
4
4
|
try {
|
|
5
|
-
return await computable.awaitStableValue(typeof timeout ===
|
|
5
|
+
return await computable.awaitStableValue(typeof timeout === "number" ? AbortSignal.timeout(timeout) : timeout);
|
|
6
6
|
}
|
|
7
7
|
catch (e) {
|
|
8
8
|
if (isTimeoutOrCancelError(e)) {
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sources":["../src/util.ts"],"sourcesContent":["import type { Computable } from
|
|
1
|
+
{"version":3,"file":"util.js","sources":["../src/util.ts"],"sourcesContent":["import type { Computable } from \"@milaboratories/computable\";\nimport { isTimeoutOrCancelError } from \"@milaboratories/pl-client\";\nimport type { BigIntStats } from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\n\nexport async function tryStat(path: string): Promise<BigIntStats | undefined> {\n try {\n return await fsp.stat(path, { bigint: true });\n } catch (error: unknown) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return undefined;\n }\n throw error;\n }\n}\n\nexport async function awaitStableState<S>(\n computable: Computable<unknown, S>,\n timeout: number | AbortSignal = 5000,\n): Promise<S> {\n try {\n return await computable.awaitStableValue(\n typeof timeout === \"number\" ? AbortSignal.timeout(timeout) : timeout,\n );\n } catch (e: unknown) {\n if (isTimeoutOrCancelError(e)) {\n const fullValue = await computable.getFullValue();\n console.dir(fullValue, { depth: 5 });\n throw new Error(\n `Aborted while awaiting stable value. Unstable marker: ${fullValue.unstableMarker}`,\n { cause: e },\n );\n } else throw e;\n }\n}\n"],"names":[],"mappings":";;AAgBO,eAAe,gBAAgB,CACpC,UAAkC,EAClC,UAAgC,IAAI,EAAA;AAEpC,IAAA,IAAI;QACF,OAAO,MAAM,UAAU,CAAC,gBAAgB,CACtC,OAAO,OAAO,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CACrE;IACH;IAAE,OAAO,CAAU,EAAE;AACnB,QAAA,IAAI,sBAAsB,CAAC,CAAC,CAAC,EAAE;AAC7B,YAAA,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,YAAY,EAAE;YACjD,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AACpC,YAAA,MAAM,IAAI,KAAK,CACb,CAAA,sDAAA,EAAyD,SAAS,CAAC,cAAc,CAAA,CAAE,EACnF,EAAE,KAAK,EAAE,CAAC,EAAE,CACb;QACH;;AAAO,YAAA,MAAM,CAAC;IAChB;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/test",
|
|
3
|
-
"version": "1.53.
|
|
3
|
+
"version": "1.53.14",
|
|
4
4
|
"description": "Typescript Block Test Helpers",
|
|
5
|
-
"
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/**/*"
|
|
8
|
+
],
|
|
6
9
|
"main": "./dist/index.cjs",
|
|
7
10
|
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
8
12
|
"exports": {
|
|
9
13
|
".": {
|
|
10
14
|
"types": "./dist/index.d.ts",
|
|
@@ -12,34 +16,31 @@
|
|
|
12
16
|
"import": "./dist/index.js"
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist/**/*"
|
|
17
|
-
],
|
|
18
|
-
"license": "UNLICENSED",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"vitest": "^4.0.16",
|
|
21
20
|
"@vitest/coverage-istanbul": "^4.0.16",
|
|
22
|
-
"
|
|
23
|
-
"@milaboratories/
|
|
24
|
-
"@
|
|
25
|
-
"@milaboratories/pl-
|
|
26
|
-
"@milaboratories/pl-
|
|
27
|
-
"@milaboratories/ts-helpers": "1.7.
|
|
28
|
-
"@
|
|
29
|
-
"@milaboratories/eslint-config": "1.0.5"
|
|
21
|
+
"vitest": "^4.0.16",
|
|
22
|
+
"@milaboratories/computable": "2.8.4",
|
|
23
|
+
"@milaboratories/pl-client": "2.16.28",
|
|
24
|
+
"@milaboratories/pl-tree": "1.8.36",
|
|
25
|
+
"@milaboratories/pl-middle-layer": "1.46.22",
|
|
26
|
+
"@milaboratories/ts-helpers": "1.7.2",
|
|
27
|
+
"@platforma-sdk/model": "1.53.14"
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
32
30
|
"@types/node": "~24.5.2",
|
|
33
31
|
"typescript": "~5.6.3",
|
|
34
|
-
"@milaboratories/
|
|
35
|
-
"@milaboratories/
|
|
36
|
-
"@milaboratories/ts-
|
|
32
|
+
"@milaboratories/ts-builder": "1.2.6",
|
|
33
|
+
"@milaboratories/build-configs": "1.4.2",
|
|
34
|
+
"@milaboratories/ts-configs": "1.2.1"
|
|
37
35
|
},
|
|
38
36
|
"scripts": {
|
|
39
|
-
"type-check": "ts-builder types --target node",
|
|
40
37
|
"build": "ts-builder build --target node",
|
|
41
38
|
"watch": "ts-builder build --target node --watch",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
39
|
+
"check": "ts-builder check --target node",
|
|
40
|
+
"formatter:check": "ts-builder formatter --check",
|
|
41
|
+
"linter:check": "ts-builder linter --check",
|
|
42
|
+
"types:check": "ts-builder type-check --target node",
|
|
43
|
+
"test": "vitest run --coverage",
|
|
44
|
+
"fmt": "ts-builder format"
|
|
44
45
|
}
|
|
45
46
|
}
|