@platforma-sdk/test 1.5.28 → 1.5.29
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.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -73
- package/dist/index.mjs.map +1 -1
- package/dist/test-template.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@milaboratories/pl-middle-layer"),I=require("@milaboratories/pl-tree"),w=require("node:crypto"),O=require("node:fs/promises"),u=require("node:path"),P=require("vitest"),M=require("@milaboratories/computable"),j=require("@milaboratories/
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@milaboratories/pl-middle-layer"),I=require("@milaboratories/pl-tree"),w=require("node:crypto"),O=require("node:fs/promises"),u=require("node:path"),P=require("vitest"),M=require("@milaboratories/computable"),j=require("@milaboratories/pl-client");function m(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const r in o)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(o,r);Object.defineProperty(e,r,t.get?t:{enumerable:!0,get:()=>o[r]})}}return e.default=o,Object.freeze(e)}const A=m(i),p=m(O),T=P.test.extend({tmpFolder:async({},o)=>{const e=u.resolve(`work/${w.randomUUID()}`);await p.mkdir(e,{recursive:!0}),await o(e),await p.rm(e,{recursive:!0})},pl:async({onTestFinished:o},e)=>{const r=`test_${Date.now()}_${w.randomUUID()}`;let t=i.NullResourceId;const a=await i.TestHelpers.getTestClient(r);t=a.clientRoot,await e(a),o(async n=>{n.errors!==void 0?console.log(`TEST FAILED SO ALTERNATIVE ROOT IS PRESETVED IN PL: ${r} (${i.resourceIdToString(t)})`):await(await i.TestHelpers.getTestClient()).deleteAlternativeRoot(r)})},createTree:async({pl:o},e)=>{const r=new Map;await e((t,a)=>{let n=r.get(t);return n===void 0&&(n=I.SynchronizedTreeState.init(o,t,a??{pollingInterval:200,stopPollingDelay:400}),r.set(t,n)),n});for(const[,t]of r)await(await t).terminate()},rootTree:async({pl:o,createTree:e},r)=>{await r(await e(o.clientRoot))}});class y{constructor(e){this.resultEntry=e}computeOutput(e,r){return M.Computable.make(t=>{const a=t.accessor(this.resultEntry).node().traverse({field:e,assertFieldType:"Input"});return r(a,t)})}}class g{constructor(e,r,t){this.renderResult=e,this.processedExportsResult=r,this.blockId=t}context(){return this.renderResult.computeOutput("context",e=>e==null?void 0:e.id).withStableType()}result(){return this.renderResult.computeOutput("result",e=>e==null?void 0:e.id).withStableType()}export(e,r){return this.processedExportsResult!==void 0?this.processedExportsResult.computeOutput("result",(t,a)=>r(t==null?void 0:t.traverse({field:e,assertFieldType:"Input"}),a)):this.renderResult.computeOutput("context",(t,a)=>r(t==null?void 0:t.traverse({field:`values/${e}`,assertFieldType:"Input"}),a))}output(e,r){return this.renderResult.computeOutput("result",(t,a)=>r(t==null?void 0:t.traverse({field:e,assertFieldType:"Input"}),a))}}class v{constructor(e,r,t){this.pl=e,this.resultRootRid=r,this.resultRootTree=t}async renderTemplate(e,r,t,a){const n=w.randomUUID(),c=typeof r=="string"?await i.prepareTemplateSpec({type:"from-file",path:`./dist/tengo/tpl/${r}.plj.gz`}):await i.prepareTemplateSpec(r),{resultMapRid:l}=await this.pl.withWriteTx("TemplateRender",async s=>{const d=i.loadTemplate(s,c),E=await a(s),k=await i.createRenderTemplate(s,d,e,E,t),f=i.Pl.createPlMap(s,k,e);s.createField(i.field(this.resultRootRid,n),"Dynamic",f);const D=await i.toGlobalResourceId(f);return await s.commit(),{resultMapRid:D}});return await this.resultRootTree.refreshState(),new y(this.resultRootTree.entry(l))}createObject(e,r){return e.createValue(i.Pl.JsonObject,JSON.stringify(r))}async renderWorkflow(e,r,t,a={}){const n=w.randomUUID(),c=await this.renderTemplate(!0,e,["result","context"],s=>{let d;return a.parent?d=a.parent:(d=s.createEphemeral({name:"BContextEnd",version:"1"}),s.lock(d)),{args:this.createObject(s,t),blockId:this.createObject(s,n),isProduction:this.createObject(s,!r),context:d}}),l=void 0;return a.exportProcessor!==void 0&&await this.renderTemplate(!0,a.exportProcessor,["result"],s=>({pf:s.getFutureFieldValue(c.resultEntry.rid,"context","Input")})),new g(c,l,n)}}const F=T.extend({helper:async({pl:o,createTree:e},r)=>{const t=await o.withWriteTx("CreatingHelpers",async n=>{const c=n.createEphemeral(i.Pl.EphStdMap),l=i.field(n.clientRoot,"templateTeste");return n.createField(l,"Dynamic",c),await n.commit(),await i.toGlobalResourceId(c)}),a=await e(t);await r(new v(o,t,a))},driverKit:async({pl:o,tmpFolder:e},r)=>{const t=u.join(e,"download");await p.mkdir(t,{recursive:!0});const a=await i.initDriverKit(o,{blobDownloadPath:t,localSecret:i.MiddleLayer.generateLocalSecret()});await r(a)}});async function S(o,e=2e3){try{return await o.awaitStableValue(typeof e=="number"?AbortSignal.timeout(e):e)}catch(r){if(j.isTimeoutOrCancelError(r)){const t=await o.getFullValue();throw console.dir(t,{depth:5}),new Error(`Aborted while awaiting stable value. Unstable marker: ${t.unstableMarker}`,{cause:r})}else throw r}}function R(o){let e={};return o!==void 0&&(typeof o=="object"&&!(o instanceof AbortSignal)?e={...e,...o}:e.timeout=o),{timeout:typeof e.timeout>"u"?AbortSignal.timeout(b):typeof e.timeout=="number"?AbortSignal.timeout(e.timeout):e.timeout,ignoreBlockError:!!e.ignoreBlockError}}const b=5e3;async function h(o,e,r){const t=R(r),a=o.overview,n=o.getBlockState(e);for(;;){const l=(await a.getValue()).blocks.find(s=>s.id==e);if(l===void 0)throw new Error(`Blocks not found: ${e}`);if(l.outputErrors){if(t.ignoreBlockError)return;{let s=l.outputsError;throw s===void 0&&(s=l.exportsError),new Error("Block error: "+(s??"no message"))}}if(l.calculationStatus==="Done")return;if(l.calculationStatus!=="Running")throw new Error(`Unexpected block status, block not calculating anything at the moment: ${l.calculationStatus}`);try{await a.awaitChange(t.timeout)}catch(s){throw console.dir(l,{depth:5}),console.dir(await n.getValue(),{depth:5}),new Error("Aborted while awaiting block done.",{cause:s})}}}const B=T.extend({ml:async({pl:o,tmpFolder:e},r)=>{const t=u.join(e,"frontend"),a=u.join(e,"download");await p.mkdir(t,{recursive:!0}),await p.mkdir(a,{recursive:!0});const n=await i.MiddleLayer.init(o,{defaultTreeOptions:{pollingInterval:250,stopPollingDelay:500},devBlockUpdateRecheckInterval:300,frontendDownloadPath:u.resolve(t),localSecret:i.MiddleLayer.generateLocalSecret(),blobDownloadPath:u.resolve(a),localStorageNameToPath:{local:""}});await r(n),await n.close()},rawPrj:async({ml:o},e)=>{const r=await o.createProject({label:"Test Project"},"test_project");await o.openProject(r);const t=o.getOpenedProject(r);await e(t),o.closeProject(r)},helpers:async({ml:o,rawPrj:e},r)=>{await r({async awaitBlockDone(t,a){await h(e,t,a)},awaitBlockDoneAndGetStableBlockState:async(t,a)=>{const n=R(a);return await h(e,t,n),await S(e.getBlockState(t),n.timeout)},async getLocalFileHandle(t){return await o.internalDriverKit.lsDriver.getLocalFileHandle(u.resolve(t))}})}});exports.ML=A;exports.DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT=b;exports.TestRenderResults=y;exports.TestWorkflowResults=g;exports.TplTestHelpers=v;exports.awaitStableState=S;exports.blockTest=B;exports.plTest=T;exports.tplTest=F;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/test-pl.ts","../src/test-template.ts","../src/util.ts","../src/test-block.ts"],"sourcesContent":["import {\n NullResourceId,\n OptionalResourceId,\n PlClient,\n ResourceId,\n resourceIdToString,\n TestHelpers\n} from '@milaboratories/pl-middle-layer';\nimport {\n SynchronizedTreeOps,\n SynchronizedTreeState\n} from '@milaboratories/pl-tree';\nimport { randomUUID } from 'crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'path';\nimport { test } from 'vitest';\n\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (\n res: ResourceId,\n ops?: SynchronizedTreeOps\n ) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({}, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n await fsp.rm(workFolder, { recursive: true });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const altRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(altRoot);\n altRootId = client.clientRoot;\n await use(client);\n onTestFinished(async (task) => {\n if (task.errors !== undefined) {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESETVED IN PL: ${altRoot} (${resourceIdToString(\n altRootId\n )})`\n );\n } else {\n const rawClient = await TestHelpers.getTestClient();\n await rawClient.deleteAlternativeRoot(altRoot);\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\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 for (const [, treePromise] of trees) {\n // TODO implement termination\n await (await treePromise).terminate();\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n }\n});\n","import {\n Computable,\n ComputableCtx,\n ComputableStableDefined,\n UnwrapComputables\n} from '@milaboratories/computable';\nimport {\n AnyRef,\n createRenderTemplate,\n field,\n FieldRef,\n initDriverKit,\n loadTemplate,\n MiddleLayer,\n MiddleLayerDriverKit,\n Pl,\n PlClient,\n PlTransaction,\n prepareTemplateSpec,\n ResourceId,\n TemplateSpecAny,\n toGlobalResourceId\n} from '@milaboratories/pl-middle-layer';\nimport {\n PlTreeEntry,\n PlTreeNodeAccessor,\n SynchronizedTreeState\n} from '@milaboratories/pl-tree';\nimport { ConsoleLoggerAdapter } from '@milaboratories/ts-helpers';\nimport { randomUUID } from 'node:crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'node:path';\nimport { plTest } from './test-pl';\n\nexport type WorkflowRenderOps = {\n parent?: ResourceId;\n exportProcessor?: TemplateSpecAny;\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:\n | TestRenderResults<'result'>\n | 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\n .computeOutput('context', (cb) => cb?.id)\n .withStableType();\n }\n\n /**\n * Returns context id of this workflow\n * */\n public result(): ComputableStableDefined<ResourceId> {\n return this.renderResult\n .computeOutput('result', (cb) => cb?.id)\n .withStableType();\n }\n\n public export<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R\n ) {\n if (this.processedExportsResult !== undefined)\n return this.processedExportsResult.computeOutput('result', (acc, ctx) => {\n return cb(\n acc?.traverse({ field: name, assertFieldType: 'Input' }),\n ctx\n );\n });\n else\n return this.renderResult.computeOutput('context', (acc, ctx) => {\n return cb(\n acc?.traverse({ field: `values/${name}`, assertFieldType: 'Input' }),\n ctx\n );\n });\n }\n\n public output<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R\n ) {\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: (\n tx: PlTransaction\n ) => 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(\n 'TemplateRender',\n async (tx) => {\n const tpl = loadTemplate(tx, spec);\n const renderedInputs = await inputs(tx);\n // prettier-ignore\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 );\n await this.resultRootTree.refreshState();\n return new TestRenderResults(this.resultRootTree.entry(resultMapRid));\n }\n\n createObject(tx: PlTransaction, value: any) {\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, any> | Promise<Record<string, any>>,\n ops: WorkflowRenderOps = {}\n ): Promise<TestWorkflowResults> {\n const blockId = randomUUID();\n const mainResult: TestRenderResults<'result' | 'context'> =\n await this.renderTemplate(true, workflow, ['result', 'context'], (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 const exports: TestRenderResults<'result'> | undefined = undefined;\n if (ops.exportProcessor !== undefined) {\n const exports = await this.renderTemplate(\n true,\n ops.exportProcessor,\n ['result'],\n (tx) => ({\n pf: tx.getFutureFieldValue(\n mainResult.resultEntry.rid,\n 'context',\n 'Input'\n )\n })\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) => {\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) => {\n const downloadFolder = path.join(tmpFolder, 'download');\n await fsp.mkdir(downloadFolder, { recursive: true });\n const driverKit = await initDriverKit(pl, new ConsoleLoggerAdapter(), {\n blobDownloadPath: downloadFolder,\n localSecret: MiddleLayer.generateLocalSecret()\n });\n\n await use(driverKit);\n }\n});\n","import { Computable } from '@milaboratories/computable';\nimport { isTimeoutOrCancelError } from '@milaboratories/pl-client';\nimport { 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: any) {\n if (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 = 2000\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","import path from 'path';\nimport * as fsp from 'node:fs/promises';\nimport {\n BlockModel,\n BlockState,\n ImportFileHandleUpload,\n InferBlockState,\n MiddleLayer,\n Platforma,\n Project\n} 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(\n timeoutOrOps?: number | AwaitBlockDoneOps\n): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (\n typeof timeoutOrOps === 'object' &&\n !(timeoutOrOps instanceof AbortSignal)\n )\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)\n 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)\n 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(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<ImportFileHandleUpload>;\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, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n frontendDownloadPath: path.resolve(frontendFolder),\n localSecret: MiddleLayer.generateLocalSecret(),\n blobDownloadPath: path.resolve(downloadFolder),\n localStorageNameToPath: { local: '' }\n });\n\n await use(ml);\n\n await ml.close();\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject(\n { label: 'Test Project' },\n 'test_project'\n );\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n await use(prj);\n ml.closeProject(pRid1);\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(\n path.resolve(localPath)\n );\n }\n });\n }\n});\n"],"names":["plTest","test","use","workFolder","path","randomUUID","fsp","onTestFinished","altRoot","altRootId","NullResourceId","client","TestHelpers","task","resourceIdToString","pl","trees","res","ops","treePromise","SynchronizedTreeState","tree","TestRenderResults","resultEntry","name","cb","Computable","ctx","outputAccessor","TestWorkflowResults","renderResult","processedExportsResult","blockId","acc","TplTestHelpers","resultRootRid","resultRootTree","ephemeral","template","outputs","inputs","runId","spec","prepareTemplateSpec","resultMapRid","tx","tpl","loadTemplate","renderedInputs","futureOutputs","createRenderTemplate","resultMap","Pl","field","toGlobalResourceId","value","workflow","preRun","args","mainResult","exports","tplTest","createTree","map","rootField","resultMapTree","tmpFolder","downloadFolder","driverKit","initDriverKit","ConsoleLoggerAdapter","MiddleLayer","awaitStableState","computable","timeout","e","isTimeoutOrCancelError","fullValue","normalizeABDOpts","timeoutOrOps","DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT","awaitBlockDone","prj","overview","state","blockOverview","b","errorMessage","blockTest","frontendFolder","ml","pRid1","rawPrj","localPath"],"mappings":"kqBAiBaA,EAASC,OAAK,OAQxB,CACD,UAAW,MAAO,CAAC,EAAGC,IAAQ,CAC5B,MAAMC,EAAaC,EAAK,QAAQ,QAAQC,EAAA,WAAA,CAAY,E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aAAAE,EAAeW,EAAQ5D,EAASd,CAAG,EACjC,MAAMsD,EACZoB,EAAO,cAAc5D,CAAO,EAC5Bd,EAAI,OAAA,CAER,EACA,MAAM,mBAAmB2E,EAAW,CAC3B,OAAA,MAAMH,EAAG,kBAAkB,SAAS,mBACzCtF,EAAK,QAAQyF,CAAS,CAAA,CAE1B,CAAA,CACD,CACH,CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/test-pl.ts","../src/test-template.ts","../src/util.ts","../src/test-block.ts"],"sourcesContent":["import {\n NullResourceId,\n OptionalResourceId,\n PlClient,\n ResourceId,\n resourceIdToString,\n TestHelpers\n} from '@milaboratories/pl-middle-layer';\nimport {\n SynchronizedTreeOps,\n SynchronizedTreeState\n} from '@milaboratories/pl-tree';\nimport { randomUUID } from 'crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'path';\nimport { test } from 'vitest';\n\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (\n res: ResourceId,\n ops?: SynchronizedTreeOps\n ) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({}, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n await fsp.rm(workFolder, { recursive: true });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const altRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(altRoot);\n altRootId = client.clientRoot;\n await use(client);\n onTestFinished(async (task) => {\n if (task.errors !== undefined) {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESETVED IN PL: ${altRoot} (${resourceIdToString(\n altRootId\n )})`\n );\n } else {\n const rawClient = await TestHelpers.getTestClient();\n await rawClient.deleteAlternativeRoot(altRoot);\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\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 for (const [, treePromise] of trees) {\n // TODO implement termination\n await (await treePromise).terminate();\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n }\n});\n","import {\n Computable,\n ComputableCtx,\n ComputableStableDefined,\n UnwrapComputables\n} from '@milaboratories/computable';\nimport {\n AnyRef,\n createRenderTemplate,\n field,\n FieldRef,\n initDriverKit,\n loadTemplate,\n MiddleLayer,\n MiddleLayerDriverKit,\n Pl,\n PlClient,\n PlTransaction,\n prepareTemplateSpec,\n ResourceId,\n TemplateSpecAny,\n toGlobalResourceId\n} from '@milaboratories/pl-middle-layer';\nimport { PlTreeEntry, PlTreeNodeAccessor, SynchronizedTreeState } from '@milaboratories/pl-tree';\nimport { ConsoleLoggerAdapter } from '@milaboratories/ts-helpers';\nimport { randomUUID } from 'node:crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'node:path';\nimport { plTest } from './test-pl';\n\nexport type WorkflowRenderOps = {\n parent?: ResourceId;\n exportProcessor?: TemplateSpecAny;\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 ) {\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 ) {\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 // prettier-ignore\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: any) {\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, any> | Promise<Record<string, any>>,\n ops: WorkflowRenderOps = {}\n ): Promise<TestWorkflowResults> {\n const 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 const exports: TestRenderResults<'result'> | undefined = undefined;\n if (ops.exportProcessor !== undefined) {\n const 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) => {\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) => {\n const downloadFolder = path.join(tmpFolder, 'download');\n await fsp.mkdir(downloadFolder, { recursive: true });\n const driverKit = await initDriverKit(pl, {\n blobDownloadPath: downloadFolder,\n localSecret: MiddleLayer.generateLocalSecret()\n });\n\n await use(driverKit);\n }\n});\n","import { Computable } from '@milaboratories/computable';\nimport { isTimeoutOrCancelError } from '@milaboratories/pl-client';\nimport { 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: any) {\n if (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 = 2000\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","import path from 'path';\nimport * as fsp from 'node:fs/promises';\nimport {\n BlockModel,\n BlockState,\n ImportFileHandleUpload,\n InferBlockState,\n MiddleLayer,\n Platforma,\n Project\n} 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(\n timeoutOrOps?: number | AwaitBlockDoneOps\n): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (\n typeof timeoutOrOps === 'object' &&\n !(timeoutOrOps instanceof AbortSignal)\n )\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)\n 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)\n 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(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<ImportFileHandleUpload>;\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, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n frontendDownloadPath: path.resolve(frontendFolder),\n localSecret: MiddleLayer.generateLocalSecret(),\n blobDownloadPath: path.resolve(downloadFolder),\n localStorageNameToPath: { local: '' }\n });\n\n await use(ml);\n\n await ml.close();\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject(\n { label: 'Test Project' },\n 'test_project'\n );\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n await use(prj);\n ml.closeProject(pRid1);\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(\n path.resolve(localPath)\n );\n }\n });\n }\n});\n"],"names":["plTest","test","use","workFolder","path","randomUUID","fsp","onTestFinished","altRoot","altRootId","NullResourceId","client","TestHelpers","task","resourceIdToString","pl","trees","res","ops","treePromise","SynchronizedTreeState","tree","TestRenderResults","resultEntry","name","cb","Computable","ctx","outputAccessor","TestWorkflowResults","renderResult","processedExportsResult","blockId","acc","TplTestHelpers","resultRootRid","resultRootTree","ephemeral","template","outputs","inputs","runId","spec","prepareTemplateSpec","resultMapRid","tx","tpl","loadTemplate","renderedInputs","futureOutputs","createRenderTemplate","resultMap","Pl","field","toGlobalResourceId","value","workflow","preRun","args","mainResult","exports","tplTest","createTree","map","rootField","resultMapTree","tmpFolder","downloadFolder","driverKit","initDriverKit","MiddleLayer","awaitStableState","computable","timeout","e","isTimeoutOrCancelError","fullValue","normalizeABDOpts","timeoutOrOps","DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT","awaitBlockDone","prj","overview","state","blockOverview","b","errorMessage","blockTest","frontendFolder","ml","pRid1","rawPrj","localPath"],"mappings":"0nBAiBaA,EAASC,OAAK,OAQxB,CACD,UAAW,MAAO,CAAC,EAAGC,IAAQ,CAC5B,MAAMC,EAAaC,EAAK,QAAQ,QAAQC,EAAA,WAAA,CAAY,EAAE,EACtD,MAAMC,EAAI,MAAMH,EAAY,CAAE,UAAW,GAAM,EAC/C,MAAMD,EAAIC,CAAU,EACpB,MAAMG,EAAI,GAAGH,EAAY,CAAE,UAAW,GAAM,CAC9C,EAEA,GAAI,MAAO,CAAE,eAAAI,GAAkBL,IAAQ,CACrC,MAAMM,EAAU,QAAQ,KAAK,KAAK,IAAIH,aAAY,CAAA,GAClD,IAAII,EAAgCC,EAAAA,eACpC,MAAMC,EAAS,MAAMC,EAAAA,YAAY,cAAcJ,CAAO,EACtDC,EAAYE,EAAO,WACnB,MAAMT,EAAIS,CAAM,EAChBJ,EAAe,MAAOM,GAAS,CACzBA,EAAK,SAAW,OACV,QAAA,IACN,uDAAuDL,CAAO,KAAKM,EAAA,mBACjEL,CACD,CAAA,GAAA,EAIG,MADY,MAAMG,cAAY,iBACpB,sBAAsBJ,CAAO,CAC/C,CACD,CACH,EAEA,WAAY,MAAO,CAAE,GAAAO,GAAMb,IAAQ,CAC3B,MAAAc,MAAY,IACZ,MAAAd,EAAI,CAACe,EAAKC,IAAQ,CAClB,IAAAC,EAAcH,EAAM,IAAIC,CAAG,EAC/B,OAAIE,IAAgB,SAClBA,EAAcC,EAAsB,sBAAA,KAClCL,EACAE,EACAC,GAAO,CACL,gB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,CACvB,MAAAwF,EAAQ,MAAMD,EAAG,cACrB,CAAE,MAAO,cAAe,EACxB,cAAA,EAEI,MAAAA,EAAG,YAAYC,CAAK,EACpB,MAAAT,EAAMQ,EAAG,iBAAiBC,CAAK,EACrC,MAAMxF,EAAI+E,CAAG,EACbQ,EAAG,aAAaC,CAAK,CACvB,EACA,QAAS,MAAO,CAAE,GAAAD,EAAI,OAAAE,CAAA,EAAUzF,IAAQ,CACtC,MAAMA,EAAI,CACR,MAAM,eAAe8B,EAASyC,EAAS,CAC/B,MAAAO,EAAeW,EAAQ3D,EAASyC,CAAO,CAC/C,EACA,qCAAsC,MACpCzC,EACA8C,IACG,CACG,MAAA5D,EAAM2D,EAAiBC,CAAY,EACnC,aAAAE,EAAeW,EAAQ3D,EAASd,CAAG,EACjC,MAAMqD,EACZoB,EAAO,cAAc3D,CAAO,EAC5Bd,EAAI,OAAA,CAER,EACA,MAAM,mBAAmB0E,EAAW,CAC3B,OAAA,MAAMH,EAAG,kBAAkB,SAAS,mBACzCrF,EAAK,QAAQwF,CAAS,CAAA,CAE1B,CAAA,CACD,CACH,CACF,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { TestHelpers as f, resourceIdToString as D, NullResourceId as I, Pl as w, field as
|
|
2
|
-
import * as
|
|
1
|
+
import { TestHelpers as f, resourceIdToString as D, NullResourceId as I, Pl as w, field as v, toGlobalResourceId as g, initDriverKit as P, MiddleLayer as m, prepareTemplateSpec as T, loadTemplate as F, createRenderTemplate as A } from "@milaboratories/pl-middle-layer";
|
|
2
|
+
import * as _ from "@milaboratories/pl-middle-layer";
|
|
3
3
|
import { SynchronizedTreeState as B } from "@milaboratories/pl-tree";
|
|
4
4
|
import { randomUUID as p } from "node:crypto";
|
|
5
5
|
import * as d from "node:fs/promises";
|
|
6
6
|
import c from "node:path";
|
|
7
7
|
import { test as O } from "vitest";
|
|
8
8
|
import { Computable as j } from "@milaboratories/computable";
|
|
9
|
-
import {
|
|
10
|
-
import { isTimeoutOrCancelError as L } from "@milaboratories/pl-client";
|
|
9
|
+
import { isTimeoutOrCancelError as M } from "@milaboratories/pl-client";
|
|
11
10
|
const R = O.extend({
|
|
12
11
|
tmpFolder: async ({}, o) => {
|
|
13
12
|
const e = c.resolve(`work/${p()}`);
|
|
@@ -45,7 +44,7 @@ const R = O.extend({
|
|
|
45
44
|
await r(await e(o.clientRoot));
|
|
46
45
|
}
|
|
47
46
|
});
|
|
48
|
-
class
|
|
47
|
+
class L {
|
|
49
48
|
constructor(e) {
|
|
50
49
|
this.resultEntry = e;
|
|
51
50
|
}
|
|
@@ -56,7 +55,7 @@ class x {
|
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
class
|
|
58
|
+
class x {
|
|
60
59
|
constructor(e, r, t) {
|
|
61
60
|
this.renderResult = e, this.processedExportsResult = r, this.blockId = t;
|
|
62
61
|
}
|
|
@@ -73,19 +72,13 @@ class C {
|
|
|
73
72
|
return this.renderResult.computeOutput("result", (e) => e == null ? void 0 : e.id).withStableType();
|
|
74
73
|
}
|
|
75
74
|
export(e, r) {
|
|
76
|
-
return this.processedExportsResult !== void 0 ? this.processedExportsResult.computeOutput("result", (t, a) => r(
|
|
77
|
-
t == null ? void 0 : t.traverse({ field: e, assertFieldType: "Input" }),
|
|
78
|
-
a
|
|
79
|
-
)) : this.renderResult.computeOutput("context", (t, a) => r(
|
|
80
|
-
t == null ? void 0 : t.traverse({ field: `values/${e}`, assertFieldType: "Input" }),
|
|
81
|
-
a
|
|
82
|
-
));
|
|
75
|
+
return this.processedExportsResult !== void 0 ? this.processedExportsResult.computeOutput("result", (t, a) => r(t == null ? void 0 : t.traverse({ field: e, assertFieldType: "Input" }), a)) : this.renderResult.computeOutput("context", (t, a) => r(t == null ? void 0 : t.traverse({ field: `values/${e}`, assertFieldType: "Input" }), a));
|
|
83
76
|
}
|
|
84
77
|
output(e, r) {
|
|
85
78
|
return this.renderResult.computeOutput("result", (t, a) => r(t == null ? void 0 : t.traverse({ field: e, assertFieldType: "Input" }), a));
|
|
86
79
|
}
|
|
87
80
|
}
|
|
88
|
-
class
|
|
81
|
+
class C {
|
|
89
82
|
constructor(e, r, t) {
|
|
90
83
|
this.pl = e, this.resultRootRid = r, this.resultRootTree = t;
|
|
91
84
|
}
|
|
@@ -93,77 +86,70 @@ class $ {
|
|
|
93
86
|
const n = p(), l = typeof r == "string" ? await T({
|
|
94
87
|
type: "from-file",
|
|
95
88
|
path: `./dist/tengo/tpl/${r}.plj.gz`
|
|
96
|
-
}) : await T(r), { resultMapRid: s } = await this.pl.withWriteTx(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
return await this.resultRootTree.refreshState(), new x(this.resultRootTree.entry(s));
|
|
89
|
+
}) : await T(r), { resultMapRid: s } = await this.pl.withWriteTx("TemplateRender", async (i) => {
|
|
90
|
+
const u = F(i, l), E = await a(i), k = await A(
|
|
91
|
+
i,
|
|
92
|
+
u,
|
|
93
|
+
e,
|
|
94
|
+
E,
|
|
95
|
+
t
|
|
96
|
+
), h = w.createPlMap(i, k, e);
|
|
97
|
+
i.createField(v(this.resultRootRid, n), "Dynamic", h);
|
|
98
|
+
const b = await g(h);
|
|
99
|
+
return await i.commit(), {
|
|
100
|
+
resultMapRid: b
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
return await this.resultRootTree.refreshState(), new L(this.resultRootTree.entry(s));
|
|
114
104
|
}
|
|
115
105
|
createObject(e, r) {
|
|
116
106
|
return e.createValue(w.JsonObject, JSON.stringify(r));
|
|
117
107
|
}
|
|
118
108
|
async renderWorkflow(e, r, t, a = {}) {
|
|
119
|
-
const n = p(), l = await this.renderTemplate(
|
|
120
|
-
let u;
|
|
121
|
-
return a.parent ? u = a.parent : (u = i.createEphemeral({ name: "BContextEnd", version: "1" }), i.lock(u)), {
|
|
122
|
-
args: this.createObject(i, t),
|
|
123
|
-
blockId: this.createObject(i, n),
|
|
124
|
-
isProduction: this.createObject(i, !r),
|
|
125
|
-
context: u
|
|
126
|
-
};
|
|
127
|
-
}), s = void 0;
|
|
128
|
-
return a.exportProcessor !== void 0 && await this.renderTemplate(
|
|
109
|
+
const n = p(), l = await this.renderTemplate(
|
|
129
110
|
!0,
|
|
130
|
-
|
|
131
|
-
["result"],
|
|
132
|
-
(i) =>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
111
|
+
e,
|
|
112
|
+
["result", "context"],
|
|
113
|
+
(i) => {
|
|
114
|
+
let u;
|
|
115
|
+
return a.parent ? u = a.parent : (u = i.createEphemeral({ name: "BContextEnd", version: "1" }), i.lock(u)), {
|
|
116
|
+
args: this.createObject(i, t),
|
|
117
|
+
blockId: this.createObject(i, n),
|
|
118
|
+
isProduction: this.createObject(i, !r),
|
|
119
|
+
context: u
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
), s = void 0;
|
|
123
|
+
return a.exportProcessor !== void 0 && await this.renderTemplate(!0, a.exportProcessor, ["result"], (i) => ({
|
|
124
|
+
pf: i.getFutureFieldValue(l.resultEntry.rid, "context", "Input")
|
|
125
|
+
})), new x(l, s, n);
|
|
140
126
|
}
|
|
141
127
|
}
|
|
142
|
-
const
|
|
128
|
+
const J = R.extend({
|
|
143
129
|
helper: async ({ pl: o, createTree: e }, r) => {
|
|
144
130
|
const t = await o.withWriteTx("CreatingHelpers", async (n) => {
|
|
145
|
-
const l = n.createEphemeral(w.EphStdMap), s =
|
|
146
|
-
return n.createField(s, "Dynamic", l), await n.commit(), await
|
|
131
|
+
const l = n.createEphemeral(w.EphStdMap), s = v(n.clientRoot, "templateTeste");
|
|
132
|
+
return n.createField(s, "Dynamic", l), await n.commit(), await g(l);
|
|
147
133
|
}), a = await e(t);
|
|
148
|
-
await r(new
|
|
134
|
+
await r(new C(o, t, a));
|
|
149
135
|
},
|
|
150
136
|
driverKit: async ({ pl: o, tmpFolder: e }, r) => {
|
|
151
137
|
const t = c.join(e, "download");
|
|
152
138
|
await d.mkdir(t, { recursive: !0 });
|
|
153
|
-
const a = await P(o,
|
|
139
|
+
const a = await P(o, {
|
|
154
140
|
blobDownloadPath: t,
|
|
155
141
|
localSecret: m.generateLocalSecret()
|
|
156
142
|
});
|
|
157
143
|
await r(a);
|
|
158
144
|
}
|
|
159
145
|
});
|
|
160
|
-
async function
|
|
146
|
+
async function $(o, e = 2e3) {
|
|
161
147
|
try {
|
|
162
148
|
return await o.awaitStableValue(
|
|
163
149
|
typeof e == "number" ? AbortSignal.timeout(e) : e
|
|
164
150
|
);
|
|
165
151
|
} catch (r) {
|
|
166
|
-
if (
|
|
152
|
+
if (M(r)) {
|
|
167
153
|
const t = await o.getFullValue();
|
|
168
154
|
throw console.dir(t, { depth: 5 }), new Error(
|
|
169
155
|
`Aborted while awaiting stable value. Unstable marker: ${t.unstableMarker}`,
|
|
@@ -175,12 +161,12 @@ async function V(o, e = 2e3) {
|
|
|
175
161
|
function S(o) {
|
|
176
162
|
let e = {};
|
|
177
163
|
return o !== void 0 && (typeof o == "object" && !(o instanceof AbortSignal) ? e = { ...e, ...o } : e.timeout = o), {
|
|
178
|
-
timeout: typeof e.timeout > "u" ? AbortSignal.timeout(
|
|
164
|
+
timeout: typeof e.timeout > "u" ? AbortSignal.timeout(V) : typeof e.timeout == "number" ? AbortSignal.timeout(e.timeout) : e.timeout,
|
|
179
165
|
ignoreBlockError: !!e.ignoreBlockError
|
|
180
166
|
};
|
|
181
167
|
}
|
|
182
|
-
const
|
|
183
|
-
async function
|
|
168
|
+
const V = 5e3;
|
|
169
|
+
async function y(o, e, r) {
|
|
184
170
|
const t = S(r), a = o.overview, n = o.getBlockState(e);
|
|
185
171
|
for (; ; ) {
|
|
186
172
|
const s = (await a.getValue()).blocks.find((i) => i.id == e);
|
|
@@ -205,7 +191,7 @@ async function g(o, e, r) {
|
|
|
205
191
|
}
|
|
206
192
|
}
|
|
207
193
|
}
|
|
208
|
-
const
|
|
194
|
+
const q = R.extend({
|
|
209
195
|
ml: async ({ pl: o, tmpFolder: e }, r) => {
|
|
210
196
|
const t = c.join(e, "frontend"), a = c.join(e, "download");
|
|
211
197
|
await d.mkdir(t, { recursive: !0 }), await d.mkdir(a, { recursive: !0 });
|
|
@@ -231,11 +217,11 @@ const X = R.extend({
|
|
|
231
217
|
helpers: async ({ ml: o, rawPrj: e }, r) => {
|
|
232
218
|
await r({
|
|
233
219
|
async awaitBlockDone(t, a) {
|
|
234
|
-
await
|
|
220
|
+
await y(e, t, a);
|
|
235
221
|
},
|
|
236
222
|
awaitBlockDoneAndGetStableBlockState: async (t, a) => {
|
|
237
223
|
const n = S(a);
|
|
238
|
-
return await
|
|
224
|
+
return await y(e, t, n), await $(
|
|
239
225
|
e.getBlockState(t),
|
|
240
226
|
n.timeout
|
|
241
227
|
);
|
|
@@ -249,14 +235,14 @@ const X = R.extend({
|
|
|
249
235
|
}
|
|
250
236
|
});
|
|
251
237
|
export {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
238
|
+
V as DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT,
|
|
239
|
+
_ as ML,
|
|
240
|
+
L as TestRenderResults,
|
|
241
|
+
x as TestWorkflowResults,
|
|
242
|
+
C as TplTestHelpers,
|
|
243
|
+
$ as awaitStableState,
|
|
244
|
+
q as blockTest,
|
|
259
245
|
R as plTest,
|
|
260
|
-
|
|
246
|
+
J as tplTest
|
|
261
247
|
};
|
|
262
248
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/test-pl.ts","../src/test-template.ts","../src/util.ts","../src/test-block.ts"],"sourcesContent":["import {\n NullResourceId,\n OptionalResourceId,\n PlClient,\n ResourceId,\n resourceIdToString,\n TestHelpers\n} from '@milaboratories/pl-middle-layer';\nimport {\n SynchronizedTreeOps,\n SynchronizedTreeState\n} from '@milaboratories/pl-tree';\nimport { randomUUID } from 'crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'path';\nimport { test } from 'vitest';\n\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (\n res: ResourceId,\n ops?: SynchronizedTreeOps\n ) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({}, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n await fsp.rm(workFolder, { recursive: true });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const altRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(altRoot);\n altRootId = client.clientRoot;\n await use(client);\n onTestFinished(async (task) => {\n if (task.errors !== undefined) {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESETVED IN PL: ${altRoot} (${resourceIdToString(\n altRootId\n )})`\n );\n } else {\n const rawClient = await TestHelpers.getTestClient();\n await rawClient.deleteAlternativeRoot(altRoot);\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\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 for (const [, treePromise] of trees) {\n // TODO implement termination\n await (await treePromise).terminate();\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n }\n});\n","import {\n Computable,\n ComputableCtx,\n ComputableStableDefined,\n UnwrapComputables\n} from '@milaboratories/computable';\nimport {\n AnyRef,\n createRenderTemplate,\n field,\n FieldRef,\n initDriverKit,\n loadTemplate,\n MiddleLayer,\n MiddleLayerDriverKit,\n Pl,\n PlClient,\n PlTransaction,\n prepareTemplateSpec,\n ResourceId,\n TemplateSpecAny,\n toGlobalResourceId\n} from '@milaboratories/pl-middle-layer';\nimport {\n PlTreeEntry,\n PlTreeNodeAccessor,\n SynchronizedTreeState\n} from '@milaboratories/pl-tree';\nimport { ConsoleLoggerAdapter } from '@milaboratories/ts-helpers';\nimport { randomUUID } from 'node:crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'node:path';\nimport { plTest } from './test-pl';\n\nexport type WorkflowRenderOps = {\n parent?: ResourceId;\n exportProcessor?: TemplateSpecAny;\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:\n | TestRenderResults<'result'>\n | 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\n .computeOutput('context', (cb) => cb?.id)\n .withStableType();\n }\n\n /**\n * Returns context id of this workflow\n * */\n public result(): ComputableStableDefined<ResourceId> {\n return this.renderResult\n .computeOutput('result', (cb) => cb?.id)\n .withStableType();\n }\n\n public export<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R\n ) {\n if (this.processedExportsResult !== undefined)\n return this.processedExportsResult.computeOutput('result', (acc, ctx) => {\n return cb(\n acc?.traverse({ field: name, assertFieldType: 'Input' }),\n ctx\n );\n });\n else\n return this.renderResult.computeOutput('context', (acc, ctx) => {\n return cb(\n acc?.traverse({ field: `values/${name}`, assertFieldType: 'Input' }),\n ctx\n );\n });\n }\n\n public output<R>(\n name: string,\n cb: (acc: PlTreeNodeAccessor | undefined, ctx: ComputableCtx) => R\n ) {\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: (\n tx: PlTransaction\n ) => 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(\n 'TemplateRender',\n async (tx) => {\n const tpl = loadTemplate(tx, spec);\n const renderedInputs = await inputs(tx);\n // prettier-ignore\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 );\n await this.resultRootTree.refreshState();\n return new TestRenderResults(this.resultRootTree.entry(resultMapRid));\n }\n\n createObject(tx: PlTransaction, value: any) {\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, any> | Promise<Record<string, any>>,\n ops: WorkflowRenderOps = {}\n ): Promise<TestWorkflowResults> {\n const blockId = randomUUID();\n const mainResult: TestRenderResults<'result' | 'context'> =\n await this.renderTemplate(true, workflow, ['result', 'context'], (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 const exports: TestRenderResults<'result'> | undefined = undefined;\n if (ops.exportProcessor !== undefined) {\n const exports = await this.renderTemplate(\n true,\n ops.exportProcessor,\n ['result'],\n (tx) => ({\n pf: tx.getFutureFieldValue(\n mainResult.resultEntry.rid,\n 'context',\n 'Input'\n )\n })\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) => {\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) => {\n const downloadFolder = path.join(tmpFolder, 'download');\n await fsp.mkdir(downloadFolder, { recursive: true });\n const driverKit = await initDriverKit(pl, new ConsoleLoggerAdapter(), {\n blobDownloadPath: downloadFolder,\n localSecret: MiddleLayer.generateLocalSecret()\n });\n\n await use(driverKit);\n }\n});\n","import { Computable } from '@milaboratories/computable';\nimport { isTimeoutOrCancelError } from '@milaboratories/pl-client';\nimport { 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: any) {\n if (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 = 2000\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","import path from 'path';\nimport * as fsp from 'node:fs/promises';\nimport {\n BlockModel,\n BlockState,\n ImportFileHandleUpload,\n InferBlockState,\n MiddleLayer,\n Platforma,\n Project\n} 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(\n timeoutOrOps?: number | AwaitBlockDoneOps\n): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (\n typeof timeoutOrOps === 'object' &&\n !(timeoutOrOps instanceof AbortSignal)\n )\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)\n 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)\n 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(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<ImportFileHandleUpload>;\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, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n frontendDownloadPath: path.resolve(frontendFolder),\n localSecret: MiddleLayer.generateLocalSecret(),\n blobDownloadPath: path.resolve(downloadFolder),\n localStorageNameToPath: { local: '' }\n });\n\n await use(ml);\n\n await ml.close();\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject(\n { label: 'Test Project' },\n 'test_project'\n );\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n await use(prj);\n ml.closeProject(pRid1);\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(\n path.resolve(localPath)\n );\n }\n });\n }\n});\n"],"names":["plTest","test","use","workFolder","path","randomUUID","fsp","onTestFinished","altRoot","altRootId","NullResourceId","client","TestHelpers","task","resourceIdToString","pl","trees","res","ops","treePromise","SynchronizedTreeState","tree","TestRenderResults","resultEntry","name","cb","Computable","ctx","outputAccessor","TestWorkflowResults","renderResult","processedExportsResult","blockId","acc","TplTestHelpers","resultRootRid","resultRootTree","ephemeral","template","outputs","inputs","runId","spec","prepareTemplateSpec","resultMapRid","tx","tpl","loadTemplate","renderedInputs","futureOutputs","createRenderTemplate","resultMap","Pl","field","toGlobalResourceId","value","workflow","preRun","args","mainResult","exports","tplTest","createTree","map","rootField","resultMapTree","tmpFolder","downloadFolder","driverKit","initDriverKit","ConsoleLoggerAdapter","MiddleLayer","awaitStableState","computable","timeout","e","isTimeoutOrCancelError","fullValue","normalizeABDOpts","timeoutOrOps","DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT","awaitBlockDone","prj","overview","state","blockOverview","b","errorMessage","blockTest","frontendFolder","ml","pRid1","rawPrj","localPath"],"mappings":";;;;;;;;;;AAiBa,MAAAA,IAASC,EAAK,OAQxB;AAAA,EACD,WAAW,OAAO,CAAC,GAAGC,MAAQ;AAC5B,UAAMC,IAAaC,EAAK,QAAQ,QAAQC,EAAA,CAAY,EAAE;AACtD,UAAMC,EAAI,MAAMH,GAAY,EAAE,WAAW,IAAM,GAC/C,MAAMD,EAAIC,CAAU,GACpB,MAAMG,EAAI,GAAGH,GAAY,EAAE,WAAW,IAAM;AAAA,EAC9C;AAAA,EAEA,IAAI,OAAO,EAAE,gBAAAI,KAAkBL,MAAQ;AACrC,UAAMM,IAAU,QAAQ,KAAK,KAAK,IAAIH,EAAY,CAAA;AAClD,QAAII,IAAgCC;AACpC,UAAMC,IAAS,MAAMC,EAAY,cAAcJ,CAAO;AACtD,IAAAC,IAAYE,EAAO,YACnB,MAAMT,EAAIS,CAAM,GAChBJ,EAAe,OAAOM,MAAS;AACzB,MAAAA,EAAK,WAAW,SACV,QAAA;AAAA,QACN,uDAAuDL,CAAO,KAAKM;AAAA,UACjEL;AAAA,QACD,CAAA;AAAA,MAAA,IAIG,OADY,MAAMG,EAAY,iBACpB,sBAAsBJ,CAAO;AAAA,IAC/C,CACD;AAAA,EACH;AAAA,EAEA,YAAY,OAAO,EAAE,IAAAO,KAAMb,MAAQ;AAC3B,UAAAc,wBAAY;AACZ,UAAAd,EAAI,CAACe,GAAKC,MAAQ;AAClB,UAAAC,IAAcH,EAAM,IAAIC,CAAG;AAC/B,aAAIE,MAAgB,WAClBA,IAAcC,EAAsB;AAAA,QAClCL;AAAA,QACAE;AAAA,QACAC,KAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,kBAAkB;AAAA,QACpB;AAAA,MAAA,GAEIF,EAAA,IAAIC,GAAK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AAA,QAAA;AAAA,MAE1B;AAAA,IAAA,CACD;AAAA,EACH;AACF,CAAC;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/test-pl.ts","../src/test-template.ts","../src/util.ts","../src/test-block.ts"],"sourcesContent":["import {\n NullResourceId,\n OptionalResourceId,\n PlClient,\n ResourceId,\n resourceIdToString,\n TestHelpers\n} from '@milaboratories/pl-middle-layer';\nimport {\n SynchronizedTreeOps,\n SynchronizedTreeState\n} from '@milaboratories/pl-tree';\nimport { randomUUID } from 'crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'path';\nimport { test } from 'vitest';\n\nexport const plTest = test.extend<{\n pl: PlClient;\n createTree: (\n res: ResourceId,\n ops?: SynchronizedTreeOps\n ) => Promise<SynchronizedTreeState>;\n rootTree: SynchronizedTreeState;\n tmpFolder: string;\n}>({\n tmpFolder: async ({}, use) => {\n const workFolder = path.resolve(`work/${randomUUID()}`);\n await fsp.mkdir(workFolder, { recursive: true });\n await use(workFolder);\n await fsp.rm(workFolder, { recursive: true });\n },\n\n pl: async ({ onTestFinished }, use) => {\n const altRoot = `test_${Date.now()}_${randomUUID()}`;\n let altRootId: OptionalResourceId = NullResourceId;\n const client = await TestHelpers.getTestClient(altRoot);\n altRootId = client.clientRoot;\n await use(client);\n onTestFinished(async (task) => {\n if (task.errors !== undefined) {\n console.log(\n `TEST FAILED SO ALTERNATIVE ROOT IS PRESETVED IN PL: ${altRoot} (${resourceIdToString(\n altRootId\n )})`\n );\n } else {\n const rawClient = await TestHelpers.getTestClient();\n await rawClient.deleteAlternativeRoot(altRoot);\n }\n });\n },\n\n createTree: async ({ pl }, use) => {\n const trees = new Map<ResourceId, Promise<SynchronizedTreeState>>();\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 for (const [, treePromise] of trees) {\n // TODO implement termination\n await (await treePromise).terminate();\n }\n },\n\n rootTree: async ({ pl, createTree: tree }, use) => {\n await use(await tree(pl.clientRoot));\n }\n});\n","import {\n Computable,\n ComputableCtx,\n ComputableStableDefined,\n UnwrapComputables\n} from '@milaboratories/computable';\nimport {\n AnyRef,\n createRenderTemplate,\n field,\n FieldRef,\n initDriverKit,\n loadTemplate,\n MiddleLayer,\n MiddleLayerDriverKit,\n Pl,\n PlClient,\n PlTransaction,\n prepareTemplateSpec,\n ResourceId,\n TemplateSpecAny,\n toGlobalResourceId\n} from '@milaboratories/pl-middle-layer';\nimport { PlTreeEntry, PlTreeNodeAccessor, SynchronizedTreeState } from '@milaboratories/pl-tree';\nimport { ConsoleLoggerAdapter } from '@milaboratories/ts-helpers';\nimport { randomUUID } from 'node:crypto';\nimport * as fsp from 'node:fs/promises';\nimport path from 'node:path';\nimport { plTest } from './test-pl';\n\nexport type WorkflowRenderOps = {\n parent?: ResourceId;\n exportProcessor?: TemplateSpecAny;\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 ) {\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 ) {\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 // prettier-ignore\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: any) {\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, any> | Promise<Record<string, any>>,\n ops: WorkflowRenderOps = {}\n ): Promise<TestWorkflowResults> {\n const 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 const exports: TestRenderResults<'result'> | undefined = undefined;\n if (ops.exportProcessor !== undefined) {\n const 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) => {\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) => {\n const downloadFolder = path.join(tmpFolder, 'download');\n await fsp.mkdir(downloadFolder, { recursive: true });\n const driverKit = await initDriverKit(pl, {\n blobDownloadPath: downloadFolder,\n localSecret: MiddleLayer.generateLocalSecret()\n });\n\n await use(driverKit);\n }\n});\n","import { Computable } from '@milaboratories/computable';\nimport { isTimeoutOrCancelError } from '@milaboratories/pl-client';\nimport { 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: any) {\n if (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 = 2000\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","import path from 'path';\nimport * as fsp from 'node:fs/promises';\nimport {\n BlockModel,\n BlockState,\n ImportFileHandleUpload,\n InferBlockState,\n MiddleLayer,\n Platforma,\n Project\n} 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(\n timeoutOrOps?: number | AwaitBlockDoneOps\n): AwaitBlockDoneNormalized {\n let ops: AwaitBlockDoneOps = {};\n if (timeoutOrOps !== undefined) {\n if (\n typeof timeoutOrOps === 'object' &&\n !(timeoutOrOps instanceof AbortSignal)\n )\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)\n 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)\n 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(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<void>;\n awaitBlockDoneAndGetStableBlockState<Pl extends Platforma>(\n blockId: string,\n timeoutOrOps?: number | AwaitBlockDoneOps\n ): Promise<InferBlockState<Pl>>;\n getLocalFileHandle(localPath: string): Promise<ImportFileHandleUpload>;\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, {\n defaultTreeOptions: { pollingInterval: 250, stopPollingDelay: 500 },\n devBlockUpdateRecheckInterval: 300,\n frontendDownloadPath: path.resolve(frontendFolder),\n localSecret: MiddleLayer.generateLocalSecret(),\n blobDownloadPath: path.resolve(downloadFolder),\n localStorageNameToPath: { local: '' }\n });\n\n await use(ml);\n\n await ml.close();\n },\n rawPrj: async ({ ml }, use) => {\n const pRid1 = await ml.createProject(\n { label: 'Test Project' },\n 'test_project'\n );\n await ml.openProject(pRid1);\n const prj = ml.getOpenedProject(pRid1);\n await use(prj);\n ml.closeProject(pRid1);\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(\n path.resolve(localPath)\n );\n }\n });\n }\n});\n"],"names":["plTest","test","use","workFolder","path","randomUUID","fsp","onTestFinished","altRoot","altRootId","NullResourceId","client","TestHelpers","task","resourceIdToString","pl","trees","res","ops","treePromise","SynchronizedTreeState","tree","TestRenderResults","resultEntry","name","cb","Computable","ctx","outputAccessor","TestWorkflowResults","renderResult","processedExportsResult","blockId","acc","TplTestHelpers","resultRootRid","resultRootTree","ephemeral","template","outputs","inputs","runId","spec","prepareTemplateSpec","resultMapRid","tx","tpl","loadTemplate","renderedInputs","futureOutputs","createRenderTemplate","resultMap","Pl","field","toGlobalResourceId","value","workflow","preRun","args","mainResult","exports","tplTest","createTree","map","rootField","resultMapTree","tmpFolder","downloadFolder","driverKit","initDriverKit","MiddleLayer","awaitStableState","computable","timeout","e","isTimeoutOrCancelError","fullValue","normalizeABDOpts","timeoutOrOps","DEFAULT_AWAIT_BLOCK_DONE_TIMEOUT","awaitBlockDone","prj","overview","state","blockOverview","b","errorMessage","blockTest","frontendFolder","ml","pRid1","rawPrj","localPath"],"mappings":";;;;;;;;;AAiBa,MAAAA,IAASC,EAAK,OAQxB;AAAA,EACD,WAAW,OAAO,CAAC,GAAGC,MAAQ;AAC5B,UAAMC,IAAaC,EAAK,QAAQ,QAAQC,EAAA,CAAY,EAAE;AACtD,UAAMC,EAAI,MAAMH,GAAY,EAAE,WAAW,IAAM,GAC/C,MAAMD,EAAIC,CAAU,GACpB,MAAMG,EAAI,GAAGH,GAAY,EAAE,WAAW,IAAM;AAAA,EAC9C;AAAA,EAEA,IAAI,OAAO,EAAE,gBAAAI,KAAkBL,MAAQ;AACrC,UAAMM,IAAU,QAAQ,KAAK,KAAK,IAAIH,EAAY,CAAA;AAClD,QAAII,IAAgCC;AACpC,UAAMC,IAAS,MAAMC,EAAY,cAAcJ,CAAO;AACtD,IAAAC,IAAYE,EAAO,YACnB,MAAMT,EAAIS,CAAM,GAChBJ,EAAe,OAAOM,MAAS;AACzB,MAAAA,EAAK,WAAW,SACV,QAAA;AAAA,QACN,uDAAuDL,CAAO,KAAKM;AAAA,UACjEL;AAAA,QACD,CAAA;AAAA,MAAA,IAIG,OADY,MAAMG,EAAY,iBACpB,sBAAsBJ,CAAO;AAAA,IAC/C,CACD;AAAA,EACH;AAAA,EAEA,YAAY,OAAO,EAAE,IAAAO,KAAMb,MAAQ;AAC3B,UAAAc,wBAAY;AACZ,UAAAd,EAAI,CAACe,GAAKC,MAAQ;AAClB,UAAAC,IAAcH,EAAM,IAAIC,CAAG;AAC/B,aAAIE,MAAgB,WAClBA,IAAcC,EAAsB;AAAA,QAClCL;AAAA,QACAE;AAAA,QACAC,KAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,kBAAkB;AAAA,QACpB;AAAA,MAAA,GAEIF,EAAA,IAAIC,GAAKE,CAAW,IAErBA;AAAA,IA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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-template.d.ts","sourceRoot":"","sources":["../src/test-template.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,MAAM,EAON,oBAAoB,EAEpB,QAAQ,EACR,aAAa,EAEb,UAAU,EACV,eAAe,EAEhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"test-template.d.ts","sourceRoot":"","sources":["../src/test-template.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,MAAM,EAON,oBAAoB,EAEpB,QAAQ,EACR,aAAa,EAEb,UAAU,EACV,eAAe,EAEhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAOjG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF,qBAAa,iBAAiB,CAAC,CAAC,SAAS,MAAM;aACjB,WAAW,EAAE,WAAW;gBAAxB,WAAW,EAAE,WAAW;IAE7C,aAAa,CAAC,CAAC,EACpB,IAAI,EAAE,CAAC,EACP,EAAE,EAAE,CAAC,GAAG,EAAE,kBAAkB,GAAG,SAAS,EAAE,GAAG,EAAE,aAAa,KAAK,CAAC,GACjE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CAShD;AAED,qBAAa,mBAAmB;aAEZ,YAAY,EAAE,iBAAiB,CAAC,SAAS,GAAG,QAAQ,CAAC;aACrD,sBAAsB,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAAG,SAAS;aAC/D,OAA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,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EACxD,GAAG,GAAE,iBAAsB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;CAiChC;AAED,eAAO,MAAM,OAAO;;;;;;;EAyBlB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/test",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.29",
|
|
4
4
|
"description": "Typescript Block Test Helpers",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"license": "UNLICENSED",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"vitest": "^2.1.1",
|
|
21
|
-
"@milaboratories/pl-middle-layer": "^1.10.
|
|
21
|
+
"@milaboratories/pl-middle-layer": "^1.10.34",
|
|
22
22
|
"@platforma-sdk/model": "^1.2.29",
|
|
23
23
|
"@milaboratories/pl-client": "^2.4.17",
|
|
24
|
-
"@milaboratories/pl-tree": "^1.3.
|
|
25
|
-
"@milaboratories/
|
|
26
|
-
"@milaboratories/
|
|
24
|
+
"@milaboratories/pl-tree": "^1.3.15",
|
|
25
|
+
"@milaboratories/computable": "^2.1.9",
|
|
26
|
+
"@milaboratories/ts-helpers": "^1.0.28"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "~20.16.5",
|