@milaboratories/pl-middle-layer 1.71.7 → 1.71.8
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/js_render/index.cjs +28 -5
- package/dist/js_render/index.cjs.map +1 -1
- package/dist/js_render/index.js +28 -5
- package/dist/js_render/index.js.map +1 -1
- package/dist/middle_layer/active_cfg.cjs +1 -1
- package/dist/middle_layer/active_cfg.cjs.map +1 -1
- package/dist/middle_layer/active_cfg.js +1 -1
- package/dist/middle_layer/active_cfg.js.map +1 -1
- package/dist/middle_layer/block.cjs +2 -2
- package/dist/middle_layer/block.cjs.map +1 -1
- package/dist/middle_layer/block.js +2 -2
- package/dist/middle_layer/block.js.map +1 -1
- package/dist/middle_layer/build_stamp.cjs +1 -1
- package/dist/middle_layer/build_stamp.js +1 -1
- package/dist/middle_layer/driver_kit.cjs +5 -5
- package/dist/middle_layer/driver_kit.cjs.map +1 -1
- package/dist/middle_layer/driver_kit.d.ts +3 -3
- package/dist/middle_layer/driver_kit.d.ts.map +1 -1
- package/dist/middle_layer/driver_kit.js +5 -5
- package/dist/middle_layer/driver_kit.js.map +1 -1
- package/dist/middle_layer/project_overview.cjs +5 -5
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.js +5 -5
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/dist/middle_layer/render.cjs +2 -2
- package/dist/middle_layer/render.cjs.map +1 -1
- package/dist/middle_layer/render.js +2 -2
- package/dist/middle_layer/render.js.map +1 -1
- package/package.json +10 -10
- package/src/js_render/index.ts +35 -4
- package/src/middle_layer/active_cfg.ts +9 -1
- package/src/middle_layer/block.ts +3 -1
- package/src/middle_layer/driver_kit.ts +12 -12
- package/src/middle_layer/project_overview.ts +41 -11
- package/src/middle_layer/render.ts +3 -1
package/dist/js_render/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ const require_index = require("../debug/index.cjs");
|
|
|
2
2
|
const require_context = require("./context.cjs");
|
|
3
3
|
let _milaboratories_computable = require("@milaboratories/computable");
|
|
4
4
|
let quickjs_emscripten = require("quickjs-emscripten");
|
|
5
|
-
let
|
|
5
|
+
let _milaboratories_pl_crash_recorder = require("@milaboratories/pl-crash-recorder");
|
|
6
6
|
//#region src/js_render/index.ts
|
|
7
7
|
/** Memory ceiling applied to every QuickJS runtime that evaluates model code. */
|
|
8
8
|
const QUICK_JS_MEMORY_LIMIT = 1024 * 1024 * 8;
|
|
@@ -58,7 +58,7 @@ function logOutputStatus(handle, renderedResult, stable, recalculationCounter, u
|
|
|
58
58
|
* @param ops Options for the computable.
|
|
59
59
|
* @returns A `Computable` that will resolve to the result of the lambda execution.
|
|
60
60
|
*/
|
|
61
|
-
function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}) {
|
|
61
|
+
function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}, blockPack) {
|
|
62
62
|
const key = `${ctx.blockId}#lambda#${configKey}#${fh.handle}`;
|
|
63
63
|
ops = {
|
|
64
64
|
...ops,
|
|
@@ -90,15 +90,17 @@ function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}) {
|
|
|
90
90
|
blockCtx: ctx,
|
|
91
91
|
mlEnv: env
|
|
92
92
|
});
|
|
93
|
-
const
|
|
93
|
+
const crashRecorder = env.driverKit.crashRecorder;
|
|
94
94
|
const renderInfo = {
|
|
95
95
|
blockId: ctx.blockId,
|
|
96
|
+
...describeBlockPack(blockPack),
|
|
97
|
+
sdkVersion: codeWithInfo.sdkVersion,
|
|
96
98
|
key,
|
|
97
99
|
lambda: fh.handle,
|
|
98
100
|
sandboxMemoryLimit: QUICK_JS_MEMORY_LIMIT,
|
|
99
101
|
getStats: () => ({ ...rCtx.stats })
|
|
100
102
|
};
|
|
101
|
-
return (0,
|
|
103
|
+
return (0, _milaboratories_pl_crash_recorder.recordModelRenderSync)(crashRecorder, renderInfo, () => {
|
|
102
104
|
rCtx.evaluateBundle(code.content);
|
|
103
105
|
const result = rCtx.runCallback(fh.handle);
|
|
104
106
|
rCtx.resetComputableCtx();
|
|
@@ -116,7 +118,7 @@ function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}) {
|
|
|
116
118
|
ir: toBeResolved,
|
|
117
119
|
postprocessValue: (resolved, { unstableMarker, stable }) => {
|
|
118
120
|
recalculationCounter++;
|
|
119
|
-
return (0,
|
|
121
|
+
return (0, _milaboratories_pl_crash_recorder.recordModelRenderSync)(crashRecorder, {
|
|
120
122
|
...renderInfo,
|
|
121
123
|
recalculation: recalculationCounter
|
|
122
124
|
}, () => {
|
|
@@ -161,6 +163,27 @@ function executeSingleLambda(quickJs, fh, codeWithInfo, ...args) {
|
|
|
161
163
|
scope.dispose();
|
|
162
164
|
}
|
|
163
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* The part of a block pack that names the code, and nothing else.
|
|
168
|
+
*
|
|
169
|
+
* Registry packs carry an organization, name and version, which is what a reader
|
|
170
|
+
* needs to open the right source. Local and development packs carry a filesystem
|
|
171
|
+
* path instead; the path is deliberately not recorded — it identifies the
|
|
172
|
+
* machine rather than the code, and its `type` already says that no published
|
|
173
|
+
* version exists to look up.
|
|
174
|
+
*/
|
|
175
|
+
function describeBlockPack(spec) {
|
|
176
|
+
if (spec === void 0) return {};
|
|
177
|
+
if (spec.type === "from-registry-v1" || spec.type === "from-registry-v2") return {
|
|
178
|
+
block: `${spec.id.organization}:${spec.id.name}`,
|
|
179
|
+
blockVersion: spec.id.version,
|
|
180
|
+
blockSource: spec.type
|
|
181
|
+
};
|
|
182
|
+
return {
|
|
183
|
+
block: "(unpublished)",
|
|
184
|
+
blockSource: spec.type
|
|
185
|
+
};
|
|
186
|
+
}
|
|
164
187
|
//#endregion
|
|
165
188
|
exports.computableFromRF = computableFromRF;
|
|
166
189
|
exports.executeSingleLambda = executeSingleLambda;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["getDebugFlags","Computable","Scope","JsExecutionContext"],"sources":["../../src/js_render/index.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from \"../middle_layer/middle_layer\";\nimport type { BlockCodeWithInfo, ConfigRenderLambda } from \"@platforma-sdk/model\";\nimport type { ComputableRenderingOps } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { QuickJSWASMModule } from \"quickjs-emscripten\";\nimport { Scope } from \"quickjs-emscripten\";\nimport type { DeadlineSettings } from \"./context\";\nimport { JsExecutionContext } from \"./context\";\nimport type { BlockContextAny } from \"../middle_layer/block_ctx\";\nimport { getDebugFlags } from \"../debug\";\nimport { recordModelRenderSync } from \"@milaboratories/pl-flight-recorder\";\n\n/** Memory ceiling applied to every QuickJS runtime that evaluates model code. */\nconst QUICK_JS_MEMORY_LIMIT = 1024 * 1024 * 8;\n\nfunction logOutputStatus(\n handle: string,\n renderedResult: unknown,\n stable: boolean,\n recalculationCounter: number,\n unstableMarker?: string,\n) {\n if (getDebugFlags().logOutputStatus && (getDebugFlags().logOutputStatus === \"any\" || !stable)) {\n if (stable)\n console.log(\n `Stable output ${handle} calculated ${renderedResult !== undefined ? \"defined\" : \"undefined\"}; (#${recalculationCounter})`,\n );\n else\n console.log(\n `Unstable output ${handle}; marker = ${unstableMarker}; ${renderedResult !== undefined ? \"defined\" : \"undefined\"} (#${recalculationCounter})`,\n );\n }\n}\n\n/**\n * Creates a Computable that executes a render function (`fh`) from a block's code in a QuickJS virtual machine.\n * This function handles both synchronous and asynchronous execution patterns of the sandboxed JS code.\n *\n * The overall data flow is as follows:\n * 1. A QuickJS VM is initialized.\n * 2. A `JsExecutionContext` is created to bridge the host (TypeScript) and guest (QuickJS) environments. It injects a\n * context object (`cfgRenderCtx`) into the VM, providing helper methods for the sandboxed code to interact with the\n * platform (e.g., to request data).\n * 3. The block's Javascript bundle is evaluated in the VM.\n * 4. The specified render function (`fh.handle`) is executed.\n *\n * Two execution paths are possible depending on the behavior of the render function:\n *\n * ### Synchronous Path\n * If the render function computes its result without requesting any external data requiring asynchronous calculations,\n * it executes synchronously.\n * - The `computablesToResolve` map in `JsExecutionContext` remains empty.\n * - The function returns an object with an `ir` field holding the result (`{ ir: importedResult }`).\n * Since `postprocessValue` is not specified, `ir` is treated as the final resolved value of the Computable.\n * - The QuickJS VM is disposed of immediately as it's no longer needed.\n *\n * ### Asynchronous Path (with `postprocessValue`)\n * If the render function needs external data requiring asynchronous calculations (e.g., fetching a file), it calls\n * one of the injected helper methods. These methods don't return data directly. Instead, they:\n * a. Create a new `Computable` for the data request (e.g., to fetch a blob).\n * b. Register this new `Computable` in the `computablesToResolve` map.\n * c. Return a handle (string) to the sandboxed code.\n *\n * In this case:\n * - The initial execution of the render function returns a scaffold of the final result, which depends on the pending\n * computables.\n * - The `computablesToResolve` map is passed as the `ir` (initial result) to `Computable.makeRaw`.\n * - The `postprocessValue` function is provided to handle the results once the computables are resolved.\n * - The QuickJS VM is kept alive (`keepVmAlive = true`) because its state is needed in `postprocessValue`.\n * - Once the `computable` framework resolves all dependencies, it calls `postprocessValue` with the resolved data.\n * - `postprocessValue` feeds the resolved data back into the VM, allowing the sandboxed code to compute the final\n * result.\n * - The VM is eventually disposed of when the host Computable is destroyed.\n *\n * @param env The middle layer environment.\n * @param ctx The block context.\n * @param fh The config render lambda to execute.\n * @param codeWithInfo The block's code and feature flags.\n * @param configKey A key for the configuration, used for cache busting.\n * @param ops Options for the computable.\n * @returns A `Computable` that will resolve to the result of the lambda execution.\n */\nexport function computableFromRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n): Computable<unknown> {\n // adding configKey to reload all outputs on block-pack update\n const key = `${ctx.blockId}#lambda#${configKey}#${fh.handle}`;\n ops = { ...ops, key };\n if (ops.mode === undefined && fh.retentive === true) ops.mode = \"StableOnlyRetentive\";\n return Computable.makeRaw((cCtx) => {\n const { code, featureFlags } = codeWithInfo;\n\n if (getDebugFlags().logOutputRecalculations)\n console.log(\n `Block lambda recalculation : ${key} (${cCtx.changeSourceMarker}; ${cCtx.bodyInvocations} invocations)`,\n );\n\n const scope = new Scope();\n let keepVmAlive = false;\n cCtx.addOnDestroy(() => {\n // If keepVmAlive is false, the scope will be disposed by the finally block,\n // no need to dispose it here.\n if (keepVmAlive) scope.dispose();\n });\n\n try {\n const runtime = scope.manage(env.quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n { computableCtx: cCtx, blockCtx: ctx, mlEnv: env },\n );\n\n const flightRecorder = env.driverKit.flightRecorder;\n const renderInfo = {\n blockId: ctx.blockId,\n key,\n lambda: fh.handle,\n // The sandbox has its own 8 MB ceiling, so the model's own objects can\n // never exhaust the host heap. What can is the volume crossing out of\n // it, which `stats` counts.\n sandboxMemoryLimit: QUICK_JS_MEMORY_LIMIT,\n getStats: () => ({ ...rCtx.stats }),\n };\n\n return recordModelRenderSync(flightRecorder, renderInfo, () => {\n rCtx.evaluateBundle(code.content);\n const result = rCtx.runCallback(fh.handle);\n\n rCtx.resetComputableCtx();\n\n const toBeResolved = rCtx.computableHelper!.computablesToResolve;\n\n if (Object.keys(toBeResolved).length === 0) {\n const importedResult = rCtx.importObjectUniversal(result);\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${key}: ${JSON.stringify(rCtx.stats)}`);\n logOutputStatus(\n fh.handle,\n importedResult,\n cCtx.unstableMarker === undefined,\n -1,\n cCtx.unstableMarker,\n );\n return { ir: importedResult };\n }\n\n let recalculationCounter = 0;\n if (getDebugFlags().logOutputStatus)\n console.log(\n `Output ${fh.handle} scaffold calculated (not all computables resolved yet).`,\n );\n keepVmAlive = true;\n\n return {\n ir: toBeResolved,\n postprocessValue: (resolved: Record<string, unknown>, { unstableMarker, stable }) => {\n recalculationCounter++;\n // A deferred render resumes here, potentially many times, and each\n // resumption can build joins of its own, so each gets its own span.\n return recordModelRenderSync(\n flightRecorder,\n { ...renderInfo, recalculation: recalculationCounter },\n () => {\n // resolving futures\n for (const [handle, value] of Object.entries(resolved))\n rCtx.runCallback(handle, value);\n\n // rendering result\n const renderedResult = rCtx.importObjectUniversal(result);\n\n // logging\n if (getDebugFlags().logJsExecStat)\n console.log(\n `[jsExec] ${key} #${recalculationCounter}: ${JSON.stringify(rCtx.stats)}`,\n );\n logOutputStatus(\n fh.handle,\n renderedResult,\n stable,\n recalculationCounter,\n unstableMarker,\n );\n\n return renderedResult;\n },\n );\n },\n };\n });\n } catch (e) {\n keepVmAlive = false;\n throw e;\n } finally {\n if (!keepVmAlive) scope.dispose();\n }\n }, ops);\n}\n\nexport function executeSingleLambda(\n quickJs: QuickJSWASMModule,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n ...args: unknown[]\n): unknown {\n const { code, featureFlags } = codeWithInfo;\n const scope = new Scope();\n try {\n const runtime = scope.manage(quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n );\n\n // Initializing the model\n rCtx.evaluateBundle(code.content);\n\n // Running the lambda with arguments (e.g., state for args(), args for enrichmentTargets())\n const importedResult = rCtx.importObjectUniversal(rCtx.runCallback(fh.handle, ...args));\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${fh.handle}: ${JSON.stringify(rCtx.stats)}`);\n return importedResult;\n } finally {\n scope.dispose();\n }\n}\n"],"mappings":";;;;;;;AAaA,MAAM,wBAAwB,OAAO,OAAO;AAE5C,SAAS,gBACP,QACA,gBACA,QACA,sBACA,gBACA;CACA,IAAIA,cAAAA,cAAc,CAAC,CAAC,oBAAoBA,cAAAA,cAAc,CAAC,CAAC,oBAAoB,SAAS,CAAC,SACpF,IAAI,QACF,QAAQ,IACN,iBAAiB,OAAO,cAAc,mBAAmB,KAAA,IAAY,YAAY,YAAY,MAAM,qBAAqB,EAC1H;MAEA,QAAQ,IACN,mBAAmB,OAAO,aAAa,eAAe,IAAI,mBAAmB,KAAA,IAAY,YAAY,YAAY,KAAK,qBAAqB,EAC7I;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,iBACd,KACA,KACA,IACA,cACA,WACA,MAAuC,CAAC,GACnB;CAErB,MAAM,MAAM,GAAG,IAAI,QAAQ,UAAU,UAAU,GAAG,GAAG;CACrD,MAAM;EAAE,GAAG;EAAK;CAAI;CACpB,IAAI,IAAI,SAAS,KAAA,KAAa,GAAG,cAAc,MAAM,IAAI,OAAO;CAChE,OAAOC,2BAAAA,WAAW,SAAS,SAAS;EAClC,MAAM,EAAE,MAAM,iBAAiB;EAE/B,IAAID,cAAAA,cAAc,CAAC,CAAC,yBAClB,QAAQ,IACN,gCAAgC,IAAI,IAAI,KAAK,mBAAmB,IAAI,KAAK,gBAAgB,cAC3F;EAEF,MAAM,QAAQ,IAAIE,mBAAAA,MAAM;EACxB,IAAI,cAAc;EAClB,KAAK,mBAAmB;GAGtB,IAAI,aAAa,MAAM,QAAQ;EACjC,CAAC;EAED,IAAI;GACF,MAAM,UAAU,MAAM,OAAO,IAAI,QAAQ,WAAW,CAAC;GACrD,QAAQ,eAAe,qBAAqB;GAC5C,QAAQ,gBAAgB,O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"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["getDebugFlags","Computable","Scope","JsExecutionContext"],"sources":["../../src/js_render/index.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from \"../middle_layer/middle_layer\";\nimport type { BlockCodeWithInfo, ConfigRenderLambda } from \"@platforma-sdk/model\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport type { ComputableRenderingOps } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { QuickJSWASMModule } from \"quickjs-emscripten\";\nimport { Scope } from \"quickjs-emscripten\";\nimport type { DeadlineSettings } from \"./context\";\nimport { JsExecutionContext } from \"./context\";\nimport type { BlockContextAny } from \"../middle_layer/block_ctx\";\nimport { getDebugFlags } from \"../debug\";\nimport { recordModelRenderSync } from \"@milaboratories/pl-crash-recorder\";\n\n/** Memory ceiling applied to every QuickJS runtime that evaluates model code. */\nconst QUICK_JS_MEMORY_LIMIT = 1024 * 1024 * 8;\n\nfunction logOutputStatus(\n handle: string,\n renderedResult: unknown,\n stable: boolean,\n recalculationCounter: number,\n unstableMarker?: string,\n) {\n if (getDebugFlags().logOutputStatus && (getDebugFlags().logOutputStatus === \"any\" || !stable)) {\n if (stable)\n console.log(\n `Stable output ${handle} calculated ${renderedResult !== undefined ? \"defined\" : \"undefined\"}; (#${recalculationCounter})`,\n );\n else\n console.log(\n `Unstable output ${handle}; marker = ${unstableMarker}; ${renderedResult !== undefined ? \"defined\" : \"undefined\"} (#${recalculationCounter})`,\n );\n }\n}\n\n/**\n * Creates a Computable that executes a render function (`fh`) from a block's code in a QuickJS virtual machine.\n * This function handles both synchronous and asynchronous execution patterns of the sandboxed JS code.\n *\n * The overall data flow is as follows:\n * 1. A QuickJS VM is initialized.\n * 2. A `JsExecutionContext` is created to bridge the host (TypeScript) and guest (QuickJS) environments. It injects a\n * context object (`cfgRenderCtx`) into the VM, providing helper methods for the sandboxed code to interact with the\n * platform (e.g., to request data).\n * 3. The block's Javascript bundle is evaluated in the VM.\n * 4. The specified render function (`fh.handle`) is executed.\n *\n * Two execution paths are possible depending on the behavior of the render function:\n *\n * ### Synchronous Path\n * If the render function computes its result without requesting any external data requiring asynchronous calculations,\n * it executes synchronously.\n * - The `computablesToResolve` map in `JsExecutionContext` remains empty.\n * - The function returns an object with an `ir` field holding the result (`{ ir: importedResult }`).\n * Since `postprocessValue` is not specified, `ir` is treated as the final resolved value of the Computable.\n * - The QuickJS VM is disposed of immediately as it's no longer needed.\n *\n * ### Asynchronous Path (with `postprocessValue`)\n * If the render function needs external data requiring asynchronous calculations (e.g., fetching a file), it calls\n * one of the injected helper methods. These methods don't return data directly. Instead, they:\n * a. Create a new `Computable` for the data request (e.g., to fetch a blob).\n * b. Register this new `Computable` in the `computablesToResolve` map.\n * c. Return a handle (string) to the sandboxed code.\n *\n * In this case:\n * - The initial execution of the render function returns a scaffold of the final result, which depends on the pending\n * computables.\n * - The `computablesToResolve` map is passed as the `ir` (initial result) to `Computable.makeRaw`.\n * - The `postprocessValue` function is provided to handle the results once the computables are resolved.\n * - The QuickJS VM is kept alive (`keepVmAlive = true`) because its state is needed in `postprocessValue`.\n * - Once the `computable` framework resolves all dependencies, it calls `postprocessValue` with the resolved data.\n * - `postprocessValue` feeds the resolved data back into the VM, allowing the sandboxed code to compute the final\n * result.\n * - The VM is eventually disposed of when the host Computable is destroyed.\n *\n * @param env The middle layer environment.\n * @param ctx The block context.\n * @param fh The config render lambda to execute.\n * @param codeWithInfo The block's code and feature flags.\n * @param configKey A key for the configuration, used for cache busting.\n * @param ops Options for the computable.\n * @returns A `Computable` that will resolve to the result of the lambda execution.\n */\nexport function computableFromRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n blockPack?: BlockPackSpec,\n): Computable<unknown> {\n // adding configKey to reload all outputs on block-pack update\n const key = `${ctx.blockId}#lambda#${configKey}#${fh.handle}`;\n ops = { ...ops, key };\n if (ops.mode === undefined && fh.retentive === true) ops.mode = \"StableOnlyRetentive\";\n return Computable.makeRaw((cCtx) => {\n const { code, featureFlags } = codeWithInfo;\n\n if (getDebugFlags().logOutputRecalculations)\n console.log(\n `Block lambda recalculation : ${key} (${cCtx.changeSourceMarker}; ${cCtx.bodyInvocations} invocations)`,\n );\n\n const scope = new Scope();\n let keepVmAlive = false;\n cCtx.addOnDestroy(() => {\n // If keepVmAlive is false, the scope will be disposed by the finally block,\n // no need to dispose it here.\n if (keepVmAlive) scope.dispose();\n });\n\n try {\n const runtime = scope.manage(env.quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n { computableCtx: cCtx, blockCtx: ctx, mlEnv: env },\n );\n\n const crashRecorder = env.driverKit.crashRecorder;\n const renderInfo = {\n blockId: ctx.blockId,\n // A block id is unique to one project; these say which code it is, so a\n // log can be read against the right version without the project.\n ...describeBlockPack(blockPack),\n sdkVersion: codeWithInfo.sdkVersion,\n key,\n lambda: fh.handle,\n // The sandbox has its own 8 MB ceiling, so the model's own objects can\n // never exhaust the host heap. What can is the volume crossing out of\n // it, which `stats` counts.\n sandboxMemoryLimit: QUICK_JS_MEMORY_LIMIT,\n getStats: () => ({ ...rCtx.stats }),\n };\n\n return recordModelRenderSync(crashRecorder, renderInfo, () => {\n rCtx.evaluateBundle(code.content);\n const result = rCtx.runCallback(fh.handle);\n\n rCtx.resetComputableCtx();\n\n const toBeResolved = rCtx.computableHelper!.computablesToResolve;\n\n if (Object.keys(toBeResolved).length === 0) {\n const importedResult = rCtx.importObjectUniversal(result);\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${key}: ${JSON.stringify(rCtx.stats)}`);\n logOutputStatus(\n fh.handle,\n importedResult,\n cCtx.unstableMarker === undefined,\n -1,\n cCtx.unstableMarker,\n );\n return { ir: importedResult };\n }\n\n let recalculationCounter = 0;\n if (getDebugFlags().logOutputStatus)\n console.log(\n `Output ${fh.handle} scaffold calculated (not all computables resolved yet).`,\n );\n keepVmAlive = true;\n\n return {\n ir: toBeResolved,\n postprocessValue: (resolved: Record<string, unknown>, { unstableMarker, stable }) => {\n recalculationCounter++;\n // A deferred render resumes here, potentially many times, and each\n // resumption can build joins of its own, so each gets its own span.\n return recordModelRenderSync(\n crashRecorder,\n { ...renderInfo, recalculation: recalculationCounter },\n () => {\n // resolving futures\n for (const [handle, value] of Object.entries(resolved))\n rCtx.runCallback(handle, value);\n\n // rendering result\n const renderedResult = rCtx.importObjectUniversal(result);\n\n // logging\n if (getDebugFlags().logJsExecStat)\n console.log(\n `[jsExec] ${key} #${recalculationCounter}: ${JSON.stringify(rCtx.stats)}`,\n );\n logOutputStatus(\n fh.handle,\n renderedResult,\n stable,\n recalculationCounter,\n unstableMarker,\n );\n\n return renderedResult;\n },\n );\n },\n };\n });\n } catch (e) {\n keepVmAlive = false;\n throw e;\n } finally {\n if (!keepVmAlive) scope.dispose();\n }\n }, ops);\n}\n\nexport function executeSingleLambda(\n quickJs: QuickJSWASMModule,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n ...args: unknown[]\n): unknown {\n const { code, featureFlags } = codeWithInfo;\n const scope = new Scope();\n try {\n const runtime = scope.manage(quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n );\n\n // Initializing the model\n rCtx.evaluateBundle(code.content);\n\n // Running the lambda with arguments (e.g., state for args(), args for enrichmentTargets())\n const importedResult = rCtx.importObjectUniversal(rCtx.runCallback(fh.handle, ...args));\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${fh.handle}: ${JSON.stringify(rCtx.stats)}`);\n return importedResult;\n } finally {\n scope.dispose();\n }\n}\n\n/**\n * The part of a block pack that names the code, and nothing else.\n *\n * Registry packs carry an organization, name and version, which is what a reader\n * needs to open the right source. Local and development packs carry a filesystem\n * path instead; the path is deliberately not recorded — it identifies the\n * machine rather than the code, and its `type` already says that no published\n * version exists to look up.\n */\nfunction describeBlockPack(spec: BlockPackSpec | undefined): {\n block?: string;\n blockVersion?: string;\n blockSource?: string;\n} {\n if (spec === undefined) return {};\n if (spec.type === \"from-registry-v1\" || spec.type === \"from-registry-v2\") {\n return {\n block: `${spec.id.organization}:${spec.id.name}`,\n blockVersion: spec.id.version,\n blockSource: spec.type,\n };\n }\n return { block: \"(unpublished)\", blockSource: spec.type };\n}\n"],"mappings":";;;;;;;AAcA,MAAM,wBAAwB,OAAO,OAAO;AAE5C,SAAS,gBACP,QACA,gBACA,QACA,sBACA,gBACA;CACA,IAAIA,cAAAA,cAAc,CAAC,CAAC,oBAAoBA,cAAAA,cAAc,CAAC,CAAC,oBAAoB,SAAS,CAAC,SACpF,IAAI,QACF,QAAQ,IACN,iBAAiB,OAAO,cAAc,mBAAmB,KAAA,IAAY,YAAY,YAAY,MAAM,qBAAqB,EAC1H;MAEA,QAAQ,IACN,mBAAmB,OAAO,aAAa,eAAe,IAAI,mBAAmB,KAAA,IAAY,YAAY,YAAY,KAAK,qBAAqB,EAC7I;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,iBACd,KACA,K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Q,IAAIE,mBAAAA,MAAM;CACxB,IAAI;EACF,MAAM,UAAU,MAAM,OAAO,QAAQ,WAAW,CAAC;EACjD,QAAQ,eAAe,qBAAqB;EAC5C,QAAQ,gBAAgB,OAAO,GAAG;EAElC,IAAI;EACJ,QAAQ,0BAA0B;GAChC,IAAI,qBAAqB,KAAA,GAAW,OAAO;GAC3C,IAAI,KAAK,IAAI,IAAI,iBAAiB,UAAU,OAAO;GACnD,OAAO;EACT,CAAC;EAED,MAAM,OAAO,IAAIC,gBAAAA,mBACf,OAFS,MAAM,OAAO,QAAQ,WAAW,CAGxC,IACA,MAAM;GACL,mBAAmB;EACrB,GACA,YACF;EAGA,KAAK,eAAe,KAAK,OAAO;EAGhC,MAAM,iBAAiB,KAAK,sBAAsB,KAAK,YAAY,GAAG,QAAQ,GAAG,IAAI,CAAC;EACtF,IAAIH,cAAAA,cAAc,CAAC,CAAC,eAClB,QAAQ,IAAI,YAAY,GAAG,OAAO,IAAI,KAAK,UAAU,KAAK,KAAK,GAAG;EACpE,OAAO;CACT,UAAU;EACR,MAAM,QAAQ;CAChB;AACF;;;;;;;;;;AAWA,SAAS,kBAAkB,MAIzB;CACA,IAAI,SAAS,KAAA,GAAW,OAAO,CAAC;CAChC,IAAI,KAAK,SAAS,sBAAsB,KAAK,SAAS,oBACpD,OAAO;EACL,OAAO,GAAG,KAAK,GAAG,aAAa,GAAG,KAAK,GAAG;EAC1C,cAAc,KAAK,GAAG;EACtB,aAAa,KAAK;CACpB;CAEF,OAAO;EAAE,OAAO;EAAiB,aAAa,KAAK;CAAK;AAC1D"}
|
package/dist/js_render/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getDebugFlags } from "../debug/index.js";
|
|
|
2
2
|
import { JsExecutionContext } from "./context.js";
|
|
3
3
|
import { Computable } from "@milaboratories/computable";
|
|
4
4
|
import { Scope } from "quickjs-emscripten";
|
|
5
|
-
import { recordModelRenderSync } from "@milaboratories/pl-
|
|
5
|
+
import { recordModelRenderSync } from "@milaboratories/pl-crash-recorder";
|
|
6
6
|
//#region src/js_render/index.ts
|
|
7
7
|
/** Memory ceiling applied to every QuickJS runtime that evaluates model code. */
|
|
8
8
|
const QUICK_JS_MEMORY_LIMIT = 1024 * 1024 * 8;
|
|
@@ -58,7 +58,7 @@ function logOutputStatus(handle, renderedResult, stable, recalculationCounter, u
|
|
|
58
58
|
* @param ops Options for the computable.
|
|
59
59
|
* @returns A `Computable` that will resolve to the result of the lambda execution.
|
|
60
60
|
*/
|
|
61
|
-
function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}) {
|
|
61
|
+
function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}, blockPack) {
|
|
62
62
|
const key = `${ctx.blockId}#lambda#${configKey}#${fh.handle}`;
|
|
63
63
|
ops = {
|
|
64
64
|
...ops,
|
|
@@ -90,15 +90,17 @@ function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}) {
|
|
|
90
90
|
blockCtx: ctx,
|
|
91
91
|
mlEnv: env
|
|
92
92
|
});
|
|
93
|
-
const
|
|
93
|
+
const crashRecorder = env.driverKit.crashRecorder;
|
|
94
94
|
const renderInfo = {
|
|
95
95
|
blockId: ctx.blockId,
|
|
96
|
+
...describeBlockPack(blockPack),
|
|
97
|
+
sdkVersion: codeWithInfo.sdkVersion,
|
|
96
98
|
key,
|
|
97
99
|
lambda: fh.handle,
|
|
98
100
|
sandboxMemoryLimit: QUICK_JS_MEMORY_LIMIT,
|
|
99
101
|
getStats: () => ({ ...rCtx.stats })
|
|
100
102
|
};
|
|
101
|
-
return recordModelRenderSync(
|
|
103
|
+
return recordModelRenderSync(crashRecorder, renderInfo, () => {
|
|
102
104
|
rCtx.evaluateBundle(code.content);
|
|
103
105
|
const result = rCtx.runCallback(fh.handle);
|
|
104
106
|
rCtx.resetComputableCtx();
|
|
@@ -116,7 +118,7 @@ function computableFromRF(env, ctx, fh, codeWithInfo, configKey, ops = {}) {
|
|
|
116
118
|
ir: toBeResolved,
|
|
117
119
|
postprocessValue: (resolved, { unstableMarker, stable }) => {
|
|
118
120
|
recalculationCounter++;
|
|
119
|
-
return recordModelRenderSync(
|
|
121
|
+
return recordModelRenderSync(crashRecorder, {
|
|
120
122
|
...renderInfo,
|
|
121
123
|
recalculation: recalculationCounter
|
|
122
124
|
}, () => {
|
|
@@ -161,6 +163,27 @@ function executeSingleLambda(quickJs, fh, codeWithInfo, ...args) {
|
|
|
161
163
|
scope.dispose();
|
|
162
164
|
}
|
|
163
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* The part of a block pack that names the code, and nothing else.
|
|
168
|
+
*
|
|
169
|
+
* Registry packs carry an organization, name and version, which is what a reader
|
|
170
|
+
* needs to open the right source. Local and development packs carry a filesystem
|
|
171
|
+
* path instead; the path is deliberately not recorded — it identifies the
|
|
172
|
+
* machine rather than the code, and its `type` already says that no published
|
|
173
|
+
* version exists to look up.
|
|
174
|
+
*/
|
|
175
|
+
function describeBlockPack(spec) {
|
|
176
|
+
if (spec === void 0) return {};
|
|
177
|
+
if (spec.type === "from-registry-v1" || spec.type === "from-registry-v2") return {
|
|
178
|
+
block: `${spec.id.organization}:${spec.id.name}`,
|
|
179
|
+
blockVersion: spec.id.version,
|
|
180
|
+
blockSource: spec.type
|
|
181
|
+
};
|
|
182
|
+
return {
|
|
183
|
+
block: "(unpublished)",
|
|
184
|
+
blockSource: spec.type
|
|
185
|
+
};
|
|
186
|
+
}
|
|
164
187
|
//#endregion
|
|
165
188
|
export { computableFromRF, executeSingleLambda };
|
|
166
189
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/js_render/index.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from \"../middle_layer/middle_layer\";\nimport type { BlockCodeWithInfo, ConfigRenderLambda } from \"@platforma-sdk/model\";\nimport type { ComputableRenderingOps } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { QuickJSWASMModule } from \"quickjs-emscripten\";\nimport { Scope } from \"quickjs-emscripten\";\nimport type { DeadlineSettings } from \"./context\";\nimport { JsExecutionContext } from \"./context\";\nimport type { BlockContextAny } from \"../middle_layer/block_ctx\";\nimport { getDebugFlags } from \"../debug\";\nimport { recordModelRenderSync } from \"@milaboratories/pl-flight-recorder\";\n\n/** Memory ceiling applied to every QuickJS runtime that evaluates model code. */\nconst QUICK_JS_MEMORY_LIMIT = 1024 * 1024 * 8;\n\nfunction logOutputStatus(\n handle: string,\n renderedResult: unknown,\n stable: boolean,\n recalculationCounter: number,\n unstableMarker?: string,\n) {\n if (getDebugFlags().logOutputStatus && (getDebugFlags().logOutputStatus === \"any\" || !stable)) {\n if (stable)\n console.log(\n `Stable output ${handle} calculated ${renderedResult !== undefined ? \"defined\" : \"undefined\"}; (#${recalculationCounter})`,\n );\n else\n console.log(\n `Unstable output ${handle}; marker = ${unstableMarker}; ${renderedResult !== undefined ? \"defined\" : \"undefined\"} (#${recalculationCounter})`,\n );\n }\n}\n\n/**\n * Creates a Computable that executes a render function (`fh`) from a block's code in a QuickJS virtual machine.\n * This function handles both synchronous and asynchronous execution patterns of the sandboxed JS code.\n *\n * The overall data flow is as follows:\n * 1. A QuickJS VM is initialized.\n * 2. A `JsExecutionContext` is created to bridge the host (TypeScript) and guest (QuickJS) environments. It injects a\n * context object (`cfgRenderCtx`) into the VM, providing helper methods for the sandboxed code to interact with the\n * platform (e.g., to request data).\n * 3. The block's Javascript bundle is evaluated in the VM.\n * 4. The specified render function (`fh.handle`) is executed.\n *\n * Two execution paths are possible depending on the behavior of the render function:\n *\n * ### Synchronous Path\n * If the render function computes its result without requesting any external data requiring asynchronous calculations,\n * it executes synchronously.\n * - The `computablesToResolve` map in `JsExecutionContext` remains empty.\n * - The function returns an object with an `ir` field holding the result (`{ ir: importedResult }`).\n * Since `postprocessValue` is not specified, `ir` is treated as the final resolved value of the Computable.\n * - The QuickJS VM is disposed of immediately as it's no longer needed.\n *\n * ### Asynchronous Path (with `postprocessValue`)\n * If the render function needs external data requiring asynchronous calculations (e.g., fetching a file), it calls\n * one of the injected helper methods. These methods don't return data directly. Instead, they:\n * a. Create a new `Computable` for the data request (e.g., to fetch a blob).\n * b. Register this new `Computable` in the `computablesToResolve` map.\n * c. Return a handle (string) to the sandboxed code.\n *\n * In this case:\n * - The initial execution of the render function returns a scaffold of the final result, which depends on the pending\n * computables.\n * - The `computablesToResolve` map is passed as the `ir` (initial result) to `Computable.makeRaw`.\n * - The `postprocessValue` function is provided to handle the results once the computables are resolved.\n * - The QuickJS VM is kept alive (`keepVmAlive = true`) because its state is needed in `postprocessValue`.\n * - Once the `computable` framework resolves all dependencies, it calls `postprocessValue` with the resolved data.\n * - `postprocessValue` feeds the resolved data back into the VM, allowing the sandboxed code to compute the final\n * result.\n * - The VM is eventually disposed of when the host Computable is destroyed.\n *\n * @param env The middle layer environment.\n * @param ctx The block context.\n * @param fh The config render lambda to execute.\n * @param codeWithInfo The block's code and feature flags.\n * @param configKey A key for the configuration, used for cache busting.\n * @param ops Options for the computable.\n * @returns A `Computable` that will resolve to the result of the lambda execution.\n */\nexport function computableFromRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n): Computable<unknown> {\n // adding configKey to reload all outputs on block-pack update\n const key = `${ctx.blockId}#lambda#${configKey}#${fh.handle}`;\n ops = { ...ops, key };\n if (ops.mode === undefined && fh.retentive === true) ops.mode = \"StableOnlyRetentive\";\n return Computable.makeRaw((cCtx) => {\n const { code, featureFlags } = codeWithInfo;\n\n if (getDebugFlags().logOutputRecalculations)\n console.log(\n `Block lambda recalculation : ${key} (${cCtx.changeSourceMarker}; ${cCtx.bodyInvocations} invocations)`,\n );\n\n const scope = new Scope();\n let keepVmAlive = false;\n cCtx.addOnDestroy(() => {\n // If keepVmAlive is false, the scope will be disposed by the finally block,\n // no need to dispose it here.\n if (keepVmAlive) scope.dispose();\n });\n\n try {\n const runtime = scope.manage(env.quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n { computableCtx: cCtx, blockCtx: ctx, mlEnv: env },\n );\n\n const flightRecorder = env.driverKit.flightRecorder;\n const renderInfo = {\n blockId: ctx.blockId,\n key,\n lambda: fh.handle,\n // The sandbox has its own 8 MB ceiling, so the model's own objects can\n // never exhaust the host heap. What can is the volume crossing out of\n // it, which `stats` counts.\n sandboxMemoryLimit: QUICK_JS_MEMORY_LIMIT,\n getStats: () => ({ ...rCtx.stats }),\n };\n\n return recordModelRenderSync(flightRecorder, renderInfo, () => {\n rCtx.evaluateBundle(code.content);\n const result = rCtx.runCallback(fh.handle);\n\n rCtx.resetComputableCtx();\n\n const toBeResolved = rCtx.computableHelper!.computablesToResolve;\n\n if (Object.keys(toBeResolved).length === 0) {\n const importedResult = rCtx.importObjectUniversal(result);\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${key}: ${JSON.stringify(rCtx.stats)}`);\n logOutputStatus(\n fh.handle,\n importedResult,\n cCtx.unstableMarker === undefined,\n -1,\n cCtx.unstableMarker,\n );\n return { ir: importedResult };\n }\n\n let recalculationCounter = 0;\n if (getDebugFlags().logOutputStatus)\n console.log(\n `Output ${fh.handle} scaffold calculated (not all computables resolved yet).`,\n );\n keepVmAlive = true;\n\n return {\n ir: toBeResolved,\n postprocessValue: (resolved: Record<string, unknown>, { unstableMarker, stable }) => {\n recalculationCounter++;\n // A deferred render resumes here, potentially many times, and each\n // resumption can build joins of its own, so each gets its own span.\n return recordModelRenderSync(\n flightRecorder,\n { ...renderInfo, recalculation: recalculationCounter },\n () => {\n // resolving futures\n for (const [handle, value] of Object.entries(resolved))\n rCtx.runCallback(handle, value);\n\n // rendering result\n const renderedResult = rCtx.importObjectUniversal(result);\n\n // logging\n if (getDebugFlags().logJsExecStat)\n console.log(\n `[jsExec] ${key} #${recalculationCounter}: ${JSON.stringify(rCtx.stats)}`,\n );\n logOutputStatus(\n fh.handle,\n renderedResult,\n stable,\n recalculationCounter,\n unstableMarker,\n );\n\n return renderedResult;\n },\n );\n },\n };\n });\n } catch (e) {\n keepVmAlive = false;\n throw e;\n } finally {\n if (!keepVmAlive) scope.dispose();\n }\n }, ops);\n}\n\nexport function executeSingleLambda(\n quickJs: QuickJSWASMModule,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n ...args: unknown[]\n): unknown {\n const { code, featureFlags } = codeWithInfo;\n const scope = new Scope();\n try {\n const runtime = scope.manage(quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n );\n\n // Initializing the model\n rCtx.evaluateBundle(code.content);\n\n // Running the lambda with arguments (e.g., state for args(), args for enrichmentTargets())\n const importedResult = rCtx.importObjectUniversal(rCtx.runCallback(fh.handle, ...args));\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${fh.handle}: ${JSON.stringify(rCtx.stats)}`);\n return importedResult;\n } finally {\n scope.dispose();\n }\n}\n"],"mappings":";;;;;;;AAaA,MAAM,wBAAwB,OAAO,OAAO;AAE5C,SAAS,gBACP,QACA,gBACA,QACA,sBACA,gBACA;CACA,IAAI,cAAc,CAA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ACH,SAAS,GAAG;GACV,cAAc;GACd,MAAM;EACR,UAAU;GACR,IAAI,CAAC,aAAa,MAAM,QAAQ;EAClC;CACF,GAAG,GAAG;AACR;AAEA,SAAgB,oBACd,SACA,IACA,cACA,GAAG,MACM;CACT,MAAM,EAAE,MAAM,iBAAiB;CAC/B,MAAM,QAAQ,IAAI,MAAM;CACxB,IAAI;EACF,MAAM,UAAU,MAAM,OAAO,QAAQ,WAAW,CAAC;EACjD,QAAQ,eAAe,qBAAqB;EAC5C,QAAQ,gBAAgB,OAAO,GAAG;EAElC,IAAI;EACJ,QAAQ,0BAA0B;GAChC,IAAI,qBAAqB,KAAA,GAAW,OAAO;GAC3C,IAAI,KAAK,IAAI,IAAI,iBAAiB,UAAU,OAAO;GACnD,OAAO;EACT,CAAC;EAED,MAAM,OAAO,IAAI,mBACf,OAFS,MAAM,OAAO,QAAQ,WAAW,CAGxC,IACA,MAAM;GACL,mBAAmB;EACrB,GACA,YACF;EAGA,KAAK,eAAe,KAAK,OAAO;EAGhC,MAAM,iBAAiB,KAAK,sBAAsB,KAAK,YAAY,GAAG,QAAQ,GAAG,IAAI,CAAC;EACtF,IAAI,cAAc,CAAC,CAAC,eAClB,QAAQ,IAAI,YAAY,GAAG,OAAO,IAAI,KAAK,UAAU,KAAK,KAAK,GAAG;EACpE,OAAO;CACT,UAAU;EACR,MAAM,QAAQ;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/js_render/index.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from \"../middle_layer/middle_layer\";\nimport type { BlockCodeWithInfo, ConfigRenderLambda } from \"@platforma-sdk/model\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport type { ComputableRenderingOps } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { QuickJSWASMModule } from \"quickjs-emscripten\";\nimport { Scope } from \"quickjs-emscripten\";\nimport type { DeadlineSettings } from \"./context\";\nimport { JsExecutionContext } from \"./context\";\nimport type { BlockContextAny } from \"../middle_layer/block_ctx\";\nimport { getDebugFlags } from \"../debug\";\nimport { recordModelRenderSync } from \"@milaboratories/pl-crash-recorder\";\n\n/** Memory ceiling applied to every QuickJS runtime that evaluates model code. */\nconst QUICK_JS_MEMORY_LIMIT = 1024 * 1024 * 8;\n\nfunction logOutputStatus(\n handle: string,\n renderedResult: unknown,\n stable: boolean,\n recalculationCounter: number,\n unstableMarker?: string,\n) {\n if (getDebugFlags().logOutputStatus && (getDebugFlags().logOutputStatus === \"any\" || !stable)) {\n if (stable)\n console.log(\n `Stable output ${handle} calculated ${renderedResult !== undefined ? \"defined\" : \"undefined\"}; (#${recalculationCounter})`,\n );\n else\n console.log(\n `Unstable output ${handle}; marker = ${unstableMarker}; ${renderedResult !== undefined ? \"defined\" : \"undefined\"} (#${recalculationCounter})`,\n );\n }\n}\n\n/**\n * Creates a Computable that executes a render function (`fh`) from a block's code in a QuickJS virtual machine.\n * This function handles both synchronous and asynchronous execution patterns of the sandboxed JS code.\n *\n * The overall data flow is as follows:\n * 1. A QuickJS VM is initialized.\n * 2. A `JsExecutionContext` is created to bridge the host (TypeScript) and guest (QuickJS) environments. It injects a\n * context object (`cfgRenderCtx`) into the VM, providing helper methods for the sandboxed code to interact with the\n * platform (e.g., to request data).\n * 3. The block's Javascript bundle is evaluated in the VM.\n * 4. The specified render function (`fh.handle`) is executed.\n *\n * Two execution paths are possible depending on the behavior of the render function:\n *\n * ### Synchronous Path\n * If the render function computes its result without requesting any external data requiring asynchronous calculations,\n * it executes synchronously.\n * - The `computablesToResolve` map in `JsExecutionContext` remains empty.\n * - The function returns an object with an `ir` field holding the result (`{ ir: importedResult }`).\n * Since `postprocessValue` is not specified, `ir` is treated as the final resolved value of the Computable.\n * - The QuickJS VM is disposed of immediately as it's no longer needed.\n *\n * ### Asynchronous Path (with `postprocessValue`)\n * If the render function needs external data requiring asynchronous calculations (e.g., fetching a file), it calls\n * one of the injected helper methods. These methods don't return data directly. Instead, they:\n * a. Create a new `Computable` for the data request (e.g., to fetch a blob).\n * b. Register this new `Computable` in the `computablesToResolve` map.\n * c. Return a handle (string) to the sandboxed code.\n *\n * In this case:\n * - The initial execution of the render function returns a scaffold of the final result, which depends on the pending\n * computables.\n * - The `computablesToResolve` map is passed as the `ir` (initial result) to `Computable.makeRaw`.\n * - The `postprocessValue` function is provided to handle the results once the computables are resolved.\n * - The QuickJS VM is kept alive (`keepVmAlive = true`) because its state is needed in `postprocessValue`.\n * - Once the `computable` framework resolves all dependencies, it calls `postprocessValue` with the resolved data.\n * - `postprocessValue` feeds the resolved data back into the VM, allowing the sandboxed code to compute the final\n * result.\n * - The VM is eventually disposed of when the host Computable is destroyed.\n *\n * @param env The middle layer environment.\n * @param ctx The block context.\n * @param fh The config render lambda to execute.\n * @param codeWithInfo The block's code and feature flags.\n * @param configKey A key for the configuration, used for cache busting.\n * @param ops Options for the computable.\n * @returns A `Computable` that will resolve to the result of the lambda execution.\n */\nexport function computableFromRF(\n env: MiddleLayerEnvironment,\n ctx: BlockContextAny,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n configKey: string,\n ops: Partial<ComputableRenderingOps> = {},\n blockPack?: BlockPackSpec,\n): Computable<unknown> {\n // adding configKey to reload all outputs on block-pack update\n const key = `${ctx.blockId}#lambda#${configKey}#${fh.handle}`;\n ops = { ...ops, key };\n if (ops.mode === undefined && fh.retentive === true) ops.mode = \"StableOnlyRetentive\";\n return Computable.makeRaw((cCtx) => {\n const { code, featureFlags } = codeWithInfo;\n\n if (getDebugFlags().logOutputRecalculations)\n console.log(\n `Block lambda recalculation : ${key} (${cCtx.changeSourceMarker}; ${cCtx.bodyInvocations} invocations)`,\n );\n\n const scope = new Scope();\n let keepVmAlive = false;\n cCtx.addOnDestroy(() => {\n // If keepVmAlive is false, the scope will be disposed by the finally block,\n // no need to dispose it here.\n if (keepVmAlive) scope.dispose();\n });\n\n try {\n const runtime = scope.manage(env.quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n { computableCtx: cCtx, blockCtx: ctx, mlEnv: env },\n );\n\n const crashRecorder = env.driverKit.crashRecorder;\n const renderInfo = {\n blockId: ctx.blockId,\n // A block id is unique to one project; these say which code it is, so a\n // log can be read against the right version without the project.\n ...describeBlockPack(blockPack),\n sdkVersion: codeWithInfo.sdkVersion,\n key,\n lambda: fh.handle,\n // The sandbox has its own 8 MB ceiling, so the model's own objects can\n // never exhaust the host heap. What can is the volume crossing out of\n // it, which `stats` counts.\n sandboxMemoryLimit: QUICK_JS_MEMORY_LIMIT,\n getStats: () => ({ ...rCtx.stats }),\n };\n\n return recordModelRenderSync(crashRecorder, renderInfo, () => {\n rCtx.evaluateBundle(code.content);\n const result = rCtx.runCallback(fh.handle);\n\n rCtx.resetComputableCtx();\n\n const toBeResolved = rCtx.computableHelper!.computablesToResolve;\n\n if (Object.keys(toBeResolved).length === 0) {\n const importedResult = rCtx.importObjectUniversal(result);\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${key}: ${JSON.stringify(rCtx.stats)}`);\n logOutputStatus(\n fh.handle,\n importedResult,\n cCtx.unstableMarker === undefined,\n -1,\n cCtx.unstableMarker,\n );\n return { ir: importedResult };\n }\n\n let recalculationCounter = 0;\n if (getDebugFlags().logOutputStatus)\n console.log(\n `Output ${fh.handle} scaffold calculated (not all computables resolved yet).`,\n );\n keepVmAlive = true;\n\n return {\n ir: toBeResolved,\n postprocessValue: (resolved: Record<string, unknown>, { unstableMarker, stable }) => {\n recalculationCounter++;\n // A deferred render resumes here, potentially many times, and each\n // resumption can build joins of its own, so each gets its own span.\n return recordModelRenderSync(\n crashRecorder,\n { ...renderInfo, recalculation: recalculationCounter },\n () => {\n // resolving futures\n for (const [handle, value] of Object.entries(resolved))\n rCtx.runCallback(handle, value);\n\n // rendering result\n const renderedResult = rCtx.importObjectUniversal(result);\n\n // logging\n if (getDebugFlags().logJsExecStat)\n console.log(\n `[jsExec] ${key} #${recalculationCounter}: ${JSON.stringify(rCtx.stats)}`,\n );\n logOutputStatus(\n fh.handle,\n renderedResult,\n stable,\n recalculationCounter,\n unstableMarker,\n );\n\n return renderedResult;\n },\n );\n },\n };\n });\n } catch (e) {\n keepVmAlive = false;\n throw e;\n } finally {\n if (!keepVmAlive) scope.dispose();\n }\n }, ops);\n}\n\nexport function executeSingleLambda(\n quickJs: QuickJSWASMModule,\n fh: ConfigRenderLambda,\n codeWithInfo: BlockCodeWithInfo,\n ...args: unknown[]\n): unknown {\n const { code, featureFlags } = codeWithInfo;\n const scope = new Scope();\n try {\n const runtime = scope.manage(quickJs.newRuntime());\n runtime.setMemoryLimit(QUICK_JS_MEMORY_LIMIT);\n runtime.setMaxStackSize(1024 * 320);\n\n let deadlineSettings: DeadlineSettings | undefined;\n runtime.setInterruptHandler(() => {\n if (deadlineSettings === undefined) return false;\n if (Date.now() > deadlineSettings.deadline) return true;\n return false;\n });\n const vm = scope.manage(runtime.newContext());\n const rCtx = new JsExecutionContext(\n scope,\n vm,\n (s) => {\n deadlineSettings = s;\n },\n featureFlags,\n );\n\n // Initializing the model\n rCtx.evaluateBundle(code.content);\n\n // Running the lambda with arguments (e.g., state for args(), args for enrichmentTargets())\n const importedResult = rCtx.importObjectUniversal(rCtx.runCallback(fh.handle, ...args));\n if (getDebugFlags().logJsExecStat)\n console.log(`[jsExec] ${fh.handle}: ${JSON.stringify(rCtx.stats)}`);\n return importedResult;\n } finally {\n scope.dispose();\n }\n}\n\n/**\n * The part of a block pack that names the code, and nothing else.\n *\n * Registry packs carry an organization, name and version, which is what a reader\n * needs to open the right source. Local and development packs carry a filesystem\n * path instead; the path is deliberately not recorded — it identifies the\n * machine rather than the code, and its `type` already says that no published\n * version exists to look up.\n */\nfunction describeBlockPack(spec: BlockPackSpec | undefined): {\n block?: string;\n blockVersion?: string;\n blockSource?: string;\n} {\n if (spec === undefined) return {};\n if (spec.type === \"from-registry-v1\" || spec.type === \"from-registry-v2\") {\n return {\n block: `${spec.id.organization}:${spec.id.name}`,\n blockVersion: spec.id.version,\n blockSource: spec.type,\n };\n }\n return { block: \"(unpublished)\", blockSource: spec.type };\n}\n"],"mappings":";;;;;;;AAcA,MAAM,wBAAwB,OAAO,OAAO;AAE5C,SAAS,gBACP,QACA,gBACA,QACA,sBACA,gBACA;CACA,IAAI,cAAc,CAAC,CAAC,oBAAoB,cAAc,CAAC,CAAC,oBAAoB,SAAS,CAAC,SACpF,IAAI,QACF,QAAQ,IACN,iBAAiB,OAAO,cAAc,mBAAmB,KAAA,IAAY,YAAY,YAAY,MAAM,qBAAqB,EAC1H;MAEA,QAAQ,IACN,mBAAmB,OAAO,aAAa,eAAe,IAAI,mBAAmB,KAAA,IAAY,YAAY,YAAY,KAAK,qBAAqB,EAC7I;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,iBACd,KACA,KACA,IACA,cACA,WACA,MAAuC,CAAC,GACxC,WACqB;CAErB,MAAM,MAAM,GAAG,IAAI,QAAQ,UAAU,UAAU,GAAG,GAAG;CACrD,MAAM;EAAE,GAAG;EAAK;CAAI;CACpB,IAAI,IAAI,SAAS,KAAA,KAAa,GAAG,cAAc,MAAM,IAAI,OAAO;CAChE,OAAO,WAAW,SAAS,SAAS;EAClC,MAAM,EAAE,MAAM,iBAAiB;EAE/B,IAAI,cAAc,CAAC,CAAC,yBAClB,QAAQ,IACN,gCAAgC,IAAI,IAAI,KAAK,mBAAmB,IAAI,KAAK,gBAAgB,cAC3F;EAEF,MAAM,QAAQ,IAAI,MAAM;EACxB,I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AAC,CAAC,eAClB,QAAQ,IAAI,YAAY,GAAG,OAAO,IAAI,KAAK,UAAU,KAAK,KAAK,GAAG;EACpE,OAAO;CACT,UAAU;EACR,MAAM,QAAQ;CAChB;AACF;;;;;;;;;;AAWA,SAAS,kBAAkB,MAIzB;CACA,IAAI,SAAS,KAAA,GAAW,OAAO,CAAC;CAChC,IAAI,KAAK,SAAS,sBAAsB,KAAK,SAAS,oBACpD,OAAO;EACL,OAAO,GAAG,KAAK,GAAG,aAAa,GAAG,KAAK,GAAG;EAC1C,cAAc,KAAK,GAAG;EACtB,aAAa,KAAK;CACpB;CAEF,OAAO;EAAE,OAAO;EAAiB,aAAa,KAAK;CAAK;AAC1D"}
|
|
@@ -21,7 +21,7 @@ function activeConfigs(prjEntry, env) {
|
|
|
21
21
|
const activeOutputConfigs = Object.entries(bp.cfg.outputs).map(([, cfg]) => cfg).filter((cfg) => require_render.isActive(cfg)).map((cfg) => cfg);
|
|
22
22
|
if (activeOutputConfigs.length === 0) continue;
|
|
23
23
|
const blockCtx = require_block_ctx.constructBlockContext(prj.persist(), id);
|
|
24
|
-
for (const cfg of activeOutputConfigs) ret.push(_milaboratories_computable.Computable.wrapError(require_render.computableFromCfgOrRF(env, blockCtx, cfg, codeWithInfoOrError.value, bp.bpId)));
|
|
24
|
+
for (const cfg of activeOutputConfigs) ret.push(_milaboratories_computable.Computable.wrapError(require_render.computableFromCfgOrRF(env, blockCtx, cfg, codeWithInfoOrError.value, bp.bpId, {}, bp.info.source)));
|
|
25
25
|
}
|
|
26
26
|
return ret;
|
|
27
27
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active_cfg.cjs","names":["Computable","ProjectStructureKey","allBlocks","getBlockPackInfo","isActive","constructBlockContext","computableFromCfgOrRF"],"sources":["../../src/middle_layer/active_cfg.ts"],"sourcesContent":["import { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport { constructBlockContext } from \"./block_ctx\";\nimport { computableFromCfgOrRF, isActive } from \"./render\";\nimport { getBlockPackInfo } from \"./util\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\n\n/** Returns derived general project state form the project resource */\nexport function activeConfigs(\n prjEntry: PlTreeEntry,\n env: MiddleLayerEnvironment,\n): Computable<unknown[]> {\n return Computable.make((ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const ret: Computable<unknown>[] = [];\n for (const { id } of allBlocks(structure)) {\n const bp = getBlockPackInfo(prj, id);\n if (bp === undefined) continue;\n\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(bp.cfg));\n if (codeWithInfoOrError.error) continue;\n\n const activeOutputConfigs = Object.entries(bp.cfg.outputs)\n .map(([, cfg]) => cfg)\n .filter((cfg) => isActive(cfg))\n .map((cfg) => cfg);\n\n if (activeOutputConfigs.length === 0) continue;\n\n const blockCtx = constructBlockContext(prj.persist(), id);\n\n for (const cfg of activeOutputConfigs) {\n ret.push(\n Computable.wrapError(\n computableFromCfgOrRF(env
|
|
1
|
+
{"version":3,"file":"active_cfg.cjs","names":["Computable","ProjectStructureKey","allBlocks","getBlockPackInfo","isActive","constructBlockContext","computableFromCfgOrRF"],"sources":["../../src/middle_layer/active_cfg.ts"],"sourcesContent":["import { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport { constructBlockContext } from \"./block_ctx\";\nimport { computableFromCfgOrRF, isActive } from \"./render\";\nimport { getBlockPackInfo } from \"./util\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\n\n/** Returns derived general project state form the project resource */\nexport function activeConfigs(\n prjEntry: PlTreeEntry,\n env: MiddleLayerEnvironment,\n): Computable<unknown[]> {\n return Computable.make((ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const ret: Computable<unknown>[] = [];\n for (const { id } of allBlocks(structure)) {\n const bp = getBlockPackInfo(prj, id);\n if (bp === undefined) continue;\n\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(bp.cfg));\n if (codeWithInfoOrError.error) continue;\n\n const activeOutputConfigs = Object.entries(bp.cfg.outputs)\n .map(([, cfg]) => cfg)\n .filter((cfg) => isActive(cfg))\n .map((cfg) => cfg);\n\n if (activeOutputConfigs.length === 0) continue;\n\n const blockCtx = constructBlockContext(prj.persist(), id);\n\n for (const cfg of activeOutputConfigs) {\n ret.push(\n Computable.wrapError(\n computableFromCfgOrRF(\n env,\n blockCtx,\n cfg,\n codeWithInfoOrError.value,\n bp.bpId,\n {},\n bp.info.source,\n ),\n ),\n );\n }\n }\n\n return ret;\n });\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,cACd,UACA,KACuB;CACvB,OAAOA,2BAAAA,WAAW,MAAM,QAAQ;EAC9B,MAAM,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK;EAExC,MAAM,aAAA,GAAA,2BAAA,SAAA,CAAqB,IAAI,kBAAoCC,sBAAAA,mBAAmB,CAAC;EACvF,MAAM,MAA6B,CAAC;EACpC,KAAK,MAAM,EAAE,QAAQC,2BAAAA,UAAU,SAAS,GAAG;GACzC,MAAM,KAAKC,aAAAA,iBAAiB,KAAK,EAAE;GACnC,IAAI,OAAO,KAAA,GAAW;GAEtB,MAAM,uBAAA,GAAA,qBAAA,aAAA,QAAA,GAAA,qBAAA,oBAAA,CAA6D,GAAG,GAAG,CAAC;GAC1E,IAAI,oBAAoB,OAAO;GAE/B,MAAM,sBAAsB,OAAO,QAAQ,GAAG,IAAI,OAAO,CAAC,CACvD,KAAK,GAAG,SAAS,GAAG,CAAC,CACrB,QAAQ,QAAQC,eAAAA,SAAS,GAAG,CAAC,CAAC,CAC9B,KAAK,QAAQ,GAAG;GAEnB,IAAI,oBAAoB,WAAW,GAAG;GAEtC,MAAM,WAAWC,kBAAAA,sBAAsB,IAAI,QAAQ,GAAG,EAAE;GAExD,KAAK,MAAM,OAAO,qBAChB,IAAI,KACFL,2BAAAA,WAAW,UACTM,eAAAA,sBACE,KACA,UACA,KACA,oBAAoB,OACpB,GAAG,MACH,CAAC,GACD,GAAG,KAAK,MACV,CACF,CACF;EAEJ;EAEA,OAAO;CACT,CAAC;AACH"}
|
|
@@ -21,7 +21,7 @@ function activeConfigs(prjEntry, env) {
|
|
|
21
21
|
const activeOutputConfigs = Object.entries(bp.cfg.outputs).map(([, cfg]) => cfg).filter((cfg) => isActive(cfg)).map((cfg) => cfg);
|
|
22
22
|
if (activeOutputConfigs.length === 0) continue;
|
|
23
23
|
const blockCtx = constructBlockContext(prj.persist(), id);
|
|
24
|
-
for (const cfg of activeOutputConfigs) ret.push(Computable.wrapError(computableFromCfgOrRF(env, blockCtx, cfg, codeWithInfoOrError.value, bp.bpId)));
|
|
24
|
+
for (const cfg of activeOutputConfigs) ret.push(Computable.wrapError(computableFromCfgOrRF(env, blockCtx, cfg, codeWithInfoOrError.value, bp.bpId, {}, bp.info.source)));
|
|
25
25
|
}
|
|
26
26
|
return ret;
|
|
27
27
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active_cfg.js","names":[],"sources":["../../src/middle_layer/active_cfg.ts"],"sourcesContent":["import { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport { constructBlockContext } from \"./block_ctx\";\nimport { computableFromCfgOrRF, isActive } from \"./render\";\nimport { getBlockPackInfo } from \"./util\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\n\n/** Returns derived general project state form the project resource */\nexport function activeConfigs(\n prjEntry: PlTreeEntry,\n env: MiddleLayerEnvironment,\n): Computable<unknown[]> {\n return Computable.make((ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const ret: Computable<unknown>[] = [];\n for (const { id } of allBlocks(structure)) {\n const bp = getBlockPackInfo(prj, id);\n if (bp === undefined) continue;\n\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(bp.cfg));\n if (codeWithInfoOrError.error) continue;\n\n const activeOutputConfigs = Object.entries(bp.cfg.outputs)\n .map(([, cfg]) => cfg)\n .filter((cfg) => isActive(cfg))\n .map((cfg) => cfg);\n\n if (activeOutputConfigs.length === 0) continue;\n\n const blockCtx = constructBlockContext(prj.persist(), id);\n\n for (const cfg of activeOutputConfigs) {\n ret.push(\n Computable.wrapError(\n computableFromCfgOrRF(env
|
|
1
|
+
{"version":3,"file":"active_cfg.js","names":[],"sources":["../../src/middle_layer/active_cfg.ts"],"sourcesContent":["import { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectStructure } from \"../model/project_model\";\nimport { ProjectStructureKey } from \"../model/project_model\";\nimport { allBlocks } from \"../model/project_model_util\";\nimport { constructBlockContext } from \"./block_ctx\";\nimport { computableFromCfgOrRF, isActive } from \"./render\";\nimport { getBlockPackInfo } from \"./util\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\n\n/** Returns derived general project state form the project resource */\nexport function activeConfigs(\n prjEntry: PlTreeEntry,\n env: MiddleLayerEnvironment,\n): Computable<unknown[]> {\n return Computable.make((ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const ret: Computable<unknown>[] = [];\n for (const { id } of allBlocks(structure)) {\n const bp = getBlockPackInfo(prj, id);\n if (bp === undefined) continue;\n\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(bp.cfg));\n if (codeWithInfoOrError.error) continue;\n\n const activeOutputConfigs = Object.entries(bp.cfg.outputs)\n .map(([, cfg]) => cfg)\n .filter((cfg) => isActive(cfg))\n .map((cfg) => cfg);\n\n if (activeOutputConfigs.length === 0) continue;\n\n const blockCtx = constructBlockContext(prj.persist(), id);\n\n for (const cfg of activeOutputConfigs) {\n ret.push(\n Computable.wrapError(\n computableFromCfgOrRF(\n env,\n blockCtx,\n cfg,\n codeWithInfoOrError.value,\n bp.bpId,\n {},\n bp.info.source,\n ),\n ),\n );\n }\n }\n\n return ret;\n });\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,cACd,UACA,KACuB;CACvB,OAAO,WAAW,MAAM,QAAQ;EAC9B,MAAM,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK;EAExC,MAAM,YAAY,SAAS,IAAI,kBAAoC,mBAAmB,CAAC;EACvF,MAAM,MAA6B,CAAC;EACpC,KAAK,MAAM,EAAE,QAAQ,UAAU,SAAS,GAAG;GACzC,MAAM,KAAK,iBAAiB,KAAK,EAAE;GACnC,IAAI,OAAO,KAAA,GAAW;GAEtB,MAAM,sBAAsB,mBAAmB,oBAAoB,GAAG,GAAG,CAAC;GAC1E,IAAI,oBAAoB,OAAO;GAE/B,MAAM,sBAAsB,OAAO,QAAQ,GAAG,IAAI,OAAO,CAAC,CACvD,KAAK,GAAG,SAAS,GAAG,CAAC,CACrB,QAAQ,QAAQ,SAAS,GAAG,CAAC,CAAC,CAC9B,KAAK,QAAQ,GAAG;GAEnB,IAAI,oBAAoB,WAAW,GAAG;GAEtC,MAAM,WAAW,sBAAsB,IAAI,QAAQ,GAAG,EAAE;GAExD,KAAK,MAAM,OAAO,qBAChB,IAAI,KACF,WAAW,UACT,sBACE,KACA,UACA,KACA,oBAAoB,OACpB,GAAG,MACH,CAAC,GACD,GAAG,KAAK,MACV,CACF,CACF;EAEJ;EAEA,OAAO;CACT,CAAC;AACH"}
|
|
@@ -25,10 +25,10 @@ function blockOutputs(projectEntry, blockId, env) {
|
|
|
25
25
|
if (require_index.getDebugFlags().logOutputRecalculations) console.log(`blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`);
|
|
26
26
|
const prj = c.accessor(projectEntry).node();
|
|
27
27
|
const ctx = require_block_ctx.constructBlockContext(projectEntry, blockId);
|
|
28
|
-
return require_util.ifNotUndef(require_util$1.getBlockPackInfo(prj, blockId), ({ cfg, bpId }) => {
|
|
28
|
+
return require_util.ifNotUndef(require_util$1.getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {
|
|
29
29
|
const outputs = {};
|
|
30
30
|
for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {
|
|
31
|
-
const computableOutput = require_render.computableFromCfgOrRF(env, ctx, cellCfg, (0, _platforma_sdk_model.extractCodeWithInfo)(cfg), bpId);
|
|
31
|
+
const computableOutput = require_render.computableFromCfgOrRF(env, ctx, cellCfg, (0, _platforma_sdk_model.extractCodeWithInfo)(cfg), bpId, {}, info.source);
|
|
32
32
|
outputs[cellId] = _milaboratories_computable.Computable.wrapError(computableOutput, 1);
|
|
33
33
|
}
|
|
34
34
|
return outputs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.cjs","names":["Computable","constructBlockContextArgsOnly","blockArgsAuthorKey","getDebugFlags","constructBlockContext","ifNotUndef","getBlockPackInfo","computableFromCfgOrRF"],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<BlockStateInternalV3, \"outputs\" | \"navigationState\">;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd,cACA,SACA,MAC+C;CAC/C,IAAI,SAAS,KAAA,GACX,OAAOA,2BAAAA,WAAW,MAAM,MAAM,mBAAmB,cAAc,SAAS,CAAC,GAAG,EAC1E,KAAK,WAAA,GAAA,0BAAA,mBAAA,CAA6B,aAAa,GAAG,EAAE,GAAG,UACzD,CAAC;CAEH,MAAM,MAAM,KAAK,SAAS,YAAY,CAAC,CAAC,KAAK;CAE7C,MAAM,mBADMC,kBAAAA,8BAA8B,cAAc,OAC7B,CAAC,CAAC,aAAa,IAAI;CAE9C,MAAM,eACJ,qBAAqB,KAAA,KAAA,GAAA,2BAAA,WAAA,CAAuB,KAAK,MAAM,gBAAgB,CAAC,IAAI,KAAA;CAC9E,OAAO;EACL,QAAQ,IAAI,kBAAgCC,sBAAAA,mBAAmB,OAAO,CAAC;EACvE;CACF;AACF;AAEA,SAAgB,aACd,cACA,SACA,KAC2E;CAC3E,MAAM,MAAM,cAAA,GAAA,0BAAA,mBAAA,CAAgC,aAAa,GAAG,IAAI,MAAM;CACtE,OAAOF,2BAAAA,WAAW,MACf,MAAM;EACL,IAAIG,cAAAA,cAAc,CAAC,CAAC,yBAClB,QAAQ,IACN,+BAA+B,IAAI,IAAI,EAAE,mBAAmB,IAAI,EAAE,gBAAgB,cACpF;EAGF,MAAM,MAAM,EAAE,SAAS,YAAY,CAAC,CAAC,KAAK;EAC1C,MAAM,MAAMC,kBAAAA,sBAAsB,cAAc,OAAO;EAEvD,OAAOC,aAAAA,WAAWC,eAAAA,iBAAiB,KAAK,OAAO,IAAI,EAAE,KAAK,WAAW;
|
|
1
|
+
{"version":3,"file":"block.cjs","names":["Computable","constructBlockContextArgsOnly","blockArgsAuthorKey","getDebugFlags","constructBlockContext","ifNotUndef","getBlockPackInfo","computableFromCfgOrRF"],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<BlockStateInternalV3, \"outputs\" | \"navigationState\">;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n {},\n info.source,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd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B,CAAC;GAC5D;GACA,OAAO;EACT,CAAC;CACH,GACA,EAAE,IAAI,CACR,CAAC,CAAC,eAAe;AACnB"}
|
|
@@ -25,10 +25,10 @@ function blockOutputs(projectEntry, blockId, env) {
|
|
|
25
25
|
if (getDebugFlags().logOutputRecalculations) console.log(`blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`);
|
|
26
26
|
const prj = c.accessor(projectEntry).node();
|
|
27
27
|
const ctx = constructBlockContext(projectEntry, blockId);
|
|
28
|
-
return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId }) => {
|
|
28
|
+
return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {
|
|
29
29
|
const outputs = {};
|
|
30
30
|
for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {
|
|
31
|
-
const computableOutput = computableFromCfgOrRF(env, ctx, cellCfg, extractCodeWithInfo(cfg), bpId);
|
|
31
|
+
const computableOutput = computableFromCfgOrRF(env, ctx, cellCfg, extractCodeWithInfo(cfg), bpId, {}, info.source);
|
|
32
32
|
outputs[cellId] = Computable.wrapError(computableOutput, 1);
|
|
33
33
|
}
|
|
34
34
|
return outputs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","names":[],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<BlockStateInternalV3, \"outputs\" | \"navigationState\">;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd,cACA,SACA,MAC+C;CAC/C,IAAI,SAAS,KAAA,GACX,OAAO,WAAW,MAAM,MAAM,mBAAmB,cAAc,SAAS,CAAC,GAAG,EAC1E,KAAK,UAAU,mBAAmB,aAAa,GAAG,EAAE,GAAG,UACzD,CAAC;CAEH,MAAM,MAAM,KAAK,SAAS,YAAY,CAAC,CAAC,KAAK;CAE7C,MAAM,mBADM,8BAA8B,cAAc,OAC7B,CAAC,CAAC,aAAa,IAAI;CAE9C,MAAM,eACJ,qBAAqB,KAAA,IAAY,WAAW,KAAK,MAAM,gBAAgB,CAAC,IAAI,KAAA;CAC9E,OAAO;EACL,QAAQ,IAAI,kBAAgC,mBAAmB,OAAO,CAAC;EACvE;CACF;AACF;AAEA,SAAgB,aACd,cACA,SACA,KAC2E;CAC3E,MAAM,MAAM,aAAa,mBAAmB,aAAa,GAAG,IAAI,MAAM;CACtE,OAAO,WAAW,MACf,MAAM;EACL,IAAI,cAAc,CAAC,CAAC,yBAClB,QAAQ,IACN,+BAA+B,IAAI,IAAI,EAAE,mBAAmB,IAAI,EAAE,gBAAgB,cACpF;EAGF,MAAM,MAAM,EAAE,SAAS,YAAY,CAAC,CAAC,KAAK;EAC1C,MAAM,MAAM,sBAAsB,cAAc,OAAO;EAEvD,OAAO,WAAW,iBAAiB,KAAK,OAAO,IAAI,EAAE,KAAK,WAAW;
|
|
1
|
+
{"version":3,"file":"block.js","names":[],"sources":["../../src/middle_layer/block.ts"],"sourcesContent":["import type { PlTreeEntry } from \"@milaboratories/pl-tree\";\nimport type {\n ComputableCtx,\n ComputableStableDefined,\n ComputableValueOrErrors,\n} from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { blockArgsAuthorKey } from \"../model/project_model\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport { getBlockPackInfo } from \"./util\";\nimport type { AuthorMarker, BlockStateInternalV3 } from \"@milaboratories/pl-model-middle-layer\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport { resourceIdToString } from \"@milaboratories/pl-client\";\nimport { deepFreeze } from \"@milaboratories/ts-helpers\";\nimport { extractCodeWithInfo } from \"@platforma-sdk/model\";\nimport { getDebugFlags } from \"../debug\";\n\nexport type BlockParameters = Omit<BlockStateInternalV3, \"outputs\" | \"navigationState\">;\n\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n): Computable<BlockParameters>;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx,\n): BlockParameters;\nexport function getBlockParameters(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockParameters | Computable<BlockParameters> {\n if (cCtx === undefined)\n return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {\n key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,\n });\n\n const prj = cCtx.accessor(projectEntry).node();\n const ctx = constructBlockContextArgsOnly(projectEntry, blockId);\n const blockStorageJson = ctx.blockStorage(cCtx);\n // Parse raw storage JSON - UI will derive data using sdk/model\n const blockStorage =\n blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n blockStorage,\n };\n}\n\nexport function blockOutputs(\n projectEntry: PlTreeEntry,\n blockId: string,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>> {\n const key = \"outputs#\" + resourceIdToString(projectEntry.rid) + \"#\" + blockId;\n return Computable.make(\n (c) => {\n if (getDebugFlags().logOutputRecalculations) {\n console.log(\n `blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`,\n );\n }\n\n const prj = c.accessor(projectEntry).node();\n const ctx = constructBlockContext(projectEntry, blockId);\n\n return ifNotUndef(getBlockPackInfo(prj, blockId), ({ cfg, bpId, info }) => {\n const outputs: Record<string, Computable<any>> = {};\n for (const [cellId, cellCfg] of Object.entries(cfg.outputs)) {\n const computableOutput = computableFromCfgOrRF(\n env,\n ctx,\n cellCfg,\n extractCodeWithInfo(cfg),\n bpId,\n {},\n info.source,\n );\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd,cACA,SACA,MAC+C;CAC/C,IAAI,SAAS,KAAA,GACX,OAAO,WAAW,MAAM,MAAM,mBAAmB,cAAc,SAAS,CAAC,GAAG,EAC1E,KAAK,UAAU,mBAAmB,aAAa,GAAG,EAAE,GAAG,UACzD,CAAC;CAEH,MAAM,MAAM,KAAK,SAAS,YAAY,CAAC,CAAC,KAAK;CAE7C,MAAM,mBADM,8BAA8B,cAAc,OAC7B,CAAC,CAAC,aAAa,IAAI;CAE9C,MAAM,eACJ,qBAAqB,KAAA,IAAY,WAAW,KAAK,MAAM,gBAAgB,CAAC,IAAI,KAAA;CAC9E,OAAO;EACL,QAAQ,IAAI,kBAAgC,mBAAmB,OAAO,CAAC;EACvE;CACF;AACF;AAEA,SAAgB,aACd,cACA,SACA,KAC2E;CAC3E,MAAM,MAAM,aAAa,mBAAmB,aAAa,GAAG,IAAI,MAAM;CACtE,OAAO,WAAW,MACf,MAAM;EACL,IAAI,cAAc,CAAC,CAAC,yBAClB,QAAQ,IACN,+BAA+B,IAAI,IAAI,EAAE,mBAAmB,IAAI,EAAE,gBAAgB,cACpF;EAGF,MAAM,MAAM,EAAE,SAAS,YAAY,CAAC,CAAC,KAAK;EAC1C,MAAM,MAAM,sBAAsB,cAAc,OAAO;EAEvD,OAAO,WAAW,iBAAiB,KAAK,OAAO,IAAI,EAAE,KAAK,MAAM,WAAW;GACzE,MAAM,UAA2C,CAAC;GAClD,KAAK,MAAM,CAAC,QAAQ,YAAY,OAAO,QAAQ,IAAI,OAAO,GAAG;IAC3D,MAAM,mBAAmB,sBACvB,KACA,KACA,SACA,oBAAoB,GAAG,GACvB,MACA,CAAC,GACD,KAAK,MACP;IACA,QAAQ,UAAU,WAAW,UAAU,kBAAkB,CAAC;GAC5D;GACA,OAAO;EACT,CAAC;CACH,GACA,EAAE,IAAI,CACR,CAAC,CAAC,eAAe;AACnB"}
|
|
@@ -3,7 +3,7 @@ require("../pool/index.cjs");
|
|
|
3
3
|
const require_ops = require("./ops.cjs");
|
|
4
4
|
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
5
5
|
let _milaboratories_pl_drivers = require("@milaboratories/pl-drivers");
|
|
6
|
-
let
|
|
6
|
+
let _milaboratories_pl_crash_recorder = require("@milaboratories/pl-crash-recorder");
|
|
7
7
|
let _milaboratories_helpers = require("@milaboratories/helpers");
|
|
8
8
|
//#region src/middle_layer/driver_kit.ts
|
|
9
9
|
async function initDriverKit(pl, workdir, frontendDownloadPath, _ops) {
|
|
@@ -31,7 +31,7 @@ async function initDriverKit(pl, workdir, frontendDownloadPath, _ops) {
|
|
|
31
31
|
options: ops.pFrameDriverOps,
|
|
32
32
|
cacheOps: ops.parquetCacheOps
|
|
33
33
|
});
|
|
34
|
-
const
|
|
34
|
+
const recordingSession = (0, _milaboratories_pl_crash_recorder.openRecordingSession)({ role: "middle-layer" });
|
|
35
35
|
const driverKit = {
|
|
36
36
|
blobDriver,
|
|
37
37
|
blobToURLDriver,
|
|
@@ -39,14 +39,14 @@ async function initDriverKit(pl, workdir, frontendDownloadPath, _ops) {
|
|
|
39
39
|
lsDriver,
|
|
40
40
|
signer,
|
|
41
41
|
uploadDriver,
|
|
42
|
-
pFrameDriver:
|
|
42
|
+
pFrameDriver: recordingSession ? (0, _milaboratories_pl_crash_recorder.wrapDataDriver)((0, _milaboratories_pl_crash_recorder.wrapModelDriver)(rawPFrameDriver, recordingSession.recorder, recordingSession.registry), recordingSession.recorder, recordingSession.registry) : rawPFrameDriver,
|
|
43
43
|
frontendDriver: new _milaboratories_pl_drivers.DownloadUrlDriver(ops.logger, pl.httpDispatcher, frontendDownloadPath, signer, ops.frontendDownloadDriverOps),
|
|
44
|
-
|
|
44
|
+
crashRecorder: recordingSession?.recorder
|
|
45
45
|
};
|
|
46
46
|
const dispose = async () => {
|
|
47
47
|
const disposePromises = Object.values(driverKit).flatMap((driver) => (0, _milaboratories_helpers.isAsyncDisposable)(driver) ? [driver[Symbol.asyncDispose]()] : []);
|
|
48
48
|
await Promise.all(disposePromises);
|
|
49
|
-
|
|
49
|
+
recordingSession?.close("driver-kit-disposed");
|
|
50
50
|
};
|
|
51
51
|
return {
|
|
52
52
|
...driverKit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver_kit.cjs","names":["DefaultDriverKitOpsSettings","DefaultDriverKitOpsPaths","HmacSha256Signer","DownloadDriver","DownloadBlobToURLDriver","UploadDriver","LogsStreamDriver","LogsDriver","LsDriver","createPFrameDriver","DownloadUrlDriver"],"sources":["../../src/middle_layer/driver_kit.ts"],"sourcesContent":["import type { PlClient } from \"@milaboratories/pl-client\";\nimport type { InternalLsDriver } from \"@milaboratories/pl-drivers\";\nimport {\n createDownloadClient,\n createLogsClient,\n createUploadBlobClient,\n createUploadProgressClient,\n DownloadDriver,\n DownloadBlobToURLDriver,\n LogsDriver,\n LogsStreamDriver,\n LsDriver,\n UploadDriver,\n DownloadUrlDriver,\n} from \"@milaboratories/pl-drivers\";\nimport type * as Sdk from \"@milaboratories/pl-model-common\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { isAsyncDisposable } from \"@milaboratories/helpers\";\nimport { HmacSha256Signer } from \"@milaboratories/ts-helpers\";\nimport type { InternalPFrameDriver } from \"../pool\";\nimport { createPFrameDriver } from \"../pool\";\nimport type { Recorder } from \"@milaboratories/pl-
|
|
1
|
+
{"version":3,"file":"driver_kit.cjs","names":["DefaultDriverKitOpsSettings","DefaultDriverKitOpsPaths","HmacSha256Signer","DownloadDriver","DownloadBlobToURLDriver","UploadDriver","LogsStreamDriver","LogsDriver","LsDriver","createPFrameDriver","DownloadUrlDriver"],"sources":["../../src/middle_layer/driver_kit.ts"],"sourcesContent":["import type { PlClient } from \"@milaboratories/pl-client\";\nimport type { InternalLsDriver } from \"@milaboratories/pl-drivers\";\nimport {\n createDownloadClient,\n createLogsClient,\n createUploadBlobClient,\n createUploadProgressClient,\n DownloadDriver,\n DownloadBlobToURLDriver,\n LogsDriver,\n LogsStreamDriver,\n LsDriver,\n UploadDriver,\n DownloadUrlDriver,\n} from \"@milaboratories/pl-drivers\";\nimport type * as Sdk from \"@milaboratories/pl-model-common\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { isAsyncDisposable } from \"@milaboratories/helpers\";\nimport { HmacSha256Signer } from \"@milaboratories/ts-helpers\";\nimport type { InternalPFrameDriver } from \"../pool\";\nimport { createPFrameDriver } from \"../pool\";\nimport type { Recorder } from \"@milaboratories/pl-crash-recorder\";\nimport {\n openRecordingSession,\n wrapDataDriver,\n wrapModelDriver,\n} from \"@milaboratories/pl-crash-recorder\";\nimport type { DriverKitOps, DriverKitOpsConstructor } from \"./ops\";\nimport { DefaultDriverKitOpsPaths, DefaultDriverKitOpsSettings } from \"./ops\";\n\n/**\n * Drivers offered by the middle-layer for internal consumers,\n * like configuration rendering routines.\n *\n * This intertface is basically a version of the DriverKit from\n * UI SDK with extended API.\n * */\nexport interface MiddleLayerDriverKit extends Sdk.DriverKit, AsyncDisposable {\n /** Dispose the driver kit and all its resources. */\n dispose(): Promise<void>;\n\n // override with wider interface\n readonly blobDriver: DownloadDriver;\n // override with wider interface\n readonly blobToURLDriver: DownloadBlobToURLDriver;\n // override with wider interface\n readonly logDriver: LogsDriver;\n // override with wider interface\n readonly lsDriver: InternalLsDriver;\n // override with wider interface\n readonly pFrameDriver: InternalPFrameDriver;\n // override with wider interface\n readonly frontendDriver: DownloadUrlDriver;\n\n /**\n * Diagnostics log for the model layer, present only when crash recording is\n * switched on. Render spans are written through it so that a join recorded by\n * the instrumented pFrame driver can be attributed to the block that built it.\n * */\n readonly crashRecorder?: Recorder;\n\n /**\n * Signer is initialized from local secret in drivers initialization routine,\n * so constitutes a part of the driver kit\n * */\n readonly signer: Signer;\n\n /**\n * Used to retrieve upload progress, and initiate upload porecesses driven by\n * upload requests from block outputs.\n * */\n readonly uploadDriver: UploadDriver;\n}\n\nexport async function initDriverKit(\n pl: PlClient,\n workdir: string,\n frontendDownloadPath: string,\n _ops: DriverKitOpsConstructor,\n): Promise<MiddleLayerDriverKit> {\n const ops: DriverKitOps = {\n ...DefaultDriverKitOpsSettings,\n ...DefaultDriverKitOpsPaths(workdir),\n ..._ops,\n };\n\n const signer = new HmacSha256Signer(ops.localSecret);\n\n const downloadClient = createDownloadClient(ops.logger, pl, ops.localProjections);\n const logsClient = createLogsClient(pl, ops.logger);\n const uploadBlobClient = createUploadBlobClient(pl, ops.logger);\n const uploadProgressClient = createUploadProgressClient(pl, ops.logger);\n\n const blobDriver = await DownloadDriver.init(\n ops.logger,\n downloadClient,\n logsClient,\n ops.blobDownloadPath,\n ops.blobDownloadRangesCachePath,\n signer,\n ops.blobDriverOps,\n );\n\n const blobToURLDriver = new DownloadBlobToURLDriver(\n ops.logger,\n signer,\n downloadClient,\n ops.downloadBlobToURLPath,\n ops.downloadBlobToURLDriverOps,\n );\n\n const uploadDriver = new UploadDriver(\n ops.logger,\n signer,\n uploadBlobClient,\n uploadProgressClient,\n ops.uploadDriverOps,\n );\n const logsStreamDriver = new LogsStreamDriver(ops.logger, logsClient, ops.logStreamDriverOps);\n const logDriver = new LogsDriver(ops.logger, logsStreamDriver, blobDriver);\n const lsDriver = await LsDriver.init(\n ops.logger,\n pl,\n signer,\n ops.localProjections,\n ops.openFileDialogCallback,\n ops.virtualLocalStoragesOverride,\n );\n\n const rawPFrameDriver = await createPFrameDriver({\n blobDriver,\n logger: ops.logger,\n spillPath: ops.pframesSpillPath,\n cachePath: ops.parquetCachePath,\n options: ops.pFrameDriverOps,\n cacheOps: ops.parquetCacheOps,\n });\n\n // Every join a block model builds and every row it reads back passes through\n // this one driver, so instrumenting it here covers the whole model layer\n // without touching the call sites. The session is undefined unless recording\n // is switched on, in which case the driver is used exactly as before.\n const recordingSession = openRecordingSession({ role: \"middle-layer\" });\n const pFrameDriver: InternalPFrameDriver = recordingSession\n ? wrapDataDriver(\n wrapModelDriver(rawPFrameDriver, recordingSession.recorder, recordingSession.registry),\n recordingSession.recorder,\n recordingSession.registry,\n )\n : rawPFrameDriver;\n\n const frontendDownloadDriver = new DownloadUrlDriver(\n ops.logger,\n pl.httpDispatcher,\n frontendDownloadPath,\n signer,\n ops.frontendDownloadDriverOps,\n );\n\n const driverKit = {\n blobDriver,\n blobToURLDriver: blobToURLDriver,\n logDriver,\n lsDriver,\n signer,\n uploadDriver,\n pFrameDriver,\n frontendDriver: frontendDownloadDriver,\n crashRecorder: recordingSession?.recorder,\n };\n\n const dispose = async () => {\n const disposePromises = Object.values(driverKit).flatMap((driver) =>\n isAsyncDisposable(driver) ? [driver[Symbol.asyncDispose]()] : [],\n );\n await Promise.all(disposePromises);\n recordingSession?.close(\"driver-kit-disposed\");\n };\n\n return {\n ...driverKit,\n dispose,\n [Symbol.asyncDispose]: dispose,\n };\n}\n"],"mappings":";;;;;;;;AA0EA,eAAsB,cACpB,IACA,SACA,sBACA,MAC+B;CAC/B,MAAM,MAAoB;EACxB,GAAGA,YAAAA;EACH,GAAGC,YAAAA,yBAAyB,OAAO;EACnC,GAAG;CACL;CAEA,MAAM,SAAS,IAAIC,2BAAAA,iBAAiB,IAAI,WAAW;CAEnD,MAAM,kBAAA,GAAA,2BAAA,qBA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kBACjC,IAAI,QACJ,GAAG,gBACH,sBACA,QACA,IAAI,yBAWiC;EACrC,eAAe,kBAAkB;CACnC;CAEA,MAAM,UAAU,YAAY;EAC1B,MAAM,kBAAkB,OAAO,OAAO,SAAS,CAAC,CAAC,SAAS,YAAA,GAAA,wBAAA,kBAAA,CACtC,MAAM,IAAI,CAAC,OAAO,OAAO,aAAa,CAAC,CAAC,IAAI,CAAC,CACjE;EACA,MAAM,QAAQ,IAAI,eAAe;EACjC,kBAAkB,MAAM,qBAAqB;CAC/C;CAEA,OAAO;EACL,GAAG;EACH;GACC,OAAO,eAAe;CACzB;AACF"}
|
|
@@ -5,7 +5,7 @@ import { Signer } from "@milaboratories/ts-helpers";
|
|
|
5
5
|
import * as Sdk from "@milaboratories/pl-model-common";
|
|
6
6
|
import { PlClient } from "@milaboratories/pl-client";
|
|
7
7
|
import { DownloadBlobToURLDriver, DownloadDriver, DownloadUrlDriver, InternalLsDriver, LogsDriver, UploadDriver } from "@milaboratories/pl-drivers";
|
|
8
|
-
import { Recorder } from "@milaboratories/pl-
|
|
8
|
+
import { Recorder } from "@milaboratories/pl-crash-recorder";
|
|
9
9
|
//#region src/middle_layer/driver_kit.d.ts
|
|
10
10
|
/**
|
|
11
11
|
* Drivers offered by the middle-layer for internal consumers,
|
|
@@ -24,11 +24,11 @@ export interface MiddleLayerDriverKit extends Sdk.DriverKit, AsyncDisposable {
|
|
|
24
24
|
readonly pFrameDriver: InternalPFrameDriver;
|
|
25
25
|
readonly frontendDriver: DownloadUrlDriver;
|
|
26
26
|
/**
|
|
27
|
-
* Diagnostics log for the model layer, present only when
|
|
27
|
+
* Diagnostics log for the model layer, present only when crash recording is
|
|
28
28
|
* switched on. Render spans are written through it so that a join recorded by
|
|
29
29
|
* the instrumented pFrame driver can be attributed to the block that built it.
|
|
30
30
|
* */
|
|
31
|
-
readonly
|
|
31
|
+
readonly crashRecorder?: Recorder;
|
|
32
32
|
/**
|
|
33
33
|
* Signer is initialized from local secret in drivers initialization routine,
|
|
34
34
|
* so constitutes a part of the driver kit
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver_kit.d.ts","names":[],"sources":["../../src/middle_layer/driver_kit.ts"],"mappings":";;;;;;;;;;;;;;;;iBAqCiB,6BAA6B,IAAI,WAAW;;EAE3D,WAAW;WAGF,YAAY;WAEZ,iBAAiB;WAEjB,WAAW;WAEX,UAAU;WAEV,cAAc;WAEd,gBAAgB;;;;;;WAOhB,
|
|
1
|
+
{"version":3,"file":"driver_kit.d.ts","names":[],"sources":["../../src/middle_layer/driver_kit.ts"],"mappings":";;;;;;;;;;;;;;;;iBAqCiB,6BAA6B,IAAI,WAAW;;EAE3D,WAAW;WAGF,YAAY;WAEZ,iBAAiB;WAEjB,WAAW;WAEX,UAAU;WAEV,cAAc;WAEd,gBAAgB;;;;;;WAOhB,gBAAgB;;;;;WAMhB,QAAQ;;;;;WAMR,cAAc;;wBAGH,cACpB,IAAI,UACJ,iBACA,8BACA,MAAM,0BACL,QAAQ"}
|
|
@@ -3,7 +3,7 @@ import "../pool/index.js";
|
|
|
3
3
|
import { DefaultDriverKitOpsPaths, DefaultDriverKitOpsSettings } from "./ops.js";
|
|
4
4
|
import { HmacSha256Signer } from "@milaboratories/ts-helpers";
|
|
5
5
|
import { DownloadBlobToURLDriver, DownloadDriver, DownloadUrlDriver, LogsDriver, LogsStreamDriver, LsDriver, UploadDriver, createDownloadClient, createLogsClient, createUploadBlobClient, createUploadProgressClient } from "@milaboratories/pl-drivers";
|
|
6
|
-
import {
|
|
6
|
+
import { openRecordingSession, wrapDataDriver, wrapModelDriver } from "@milaboratories/pl-crash-recorder";
|
|
7
7
|
import { isAsyncDisposable } from "@milaboratories/helpers";
|
|
8
8
|
//#region src/middle_layer/driver_kit.ts
|
|
9
9
|
async function initDriverKit(pl, workdir, frontendDownloadPath, _ops) {
|
|
@@ -31,7 +31,7 @@ async function initDriverKit(pl, workdir, frontendDownloadPath, _ops) {
|
|
|
31
31
|
options: ops.pFrameDriverOps,
|
|
32
32
|
cacheOps: ops.parquetCacheOps
|
|
33
33
|
});
|
|
34
|
-
const
|
|
34
|
+
const recordingSession = openRecordingSession({ role: "middle-layer" });
|
|
35
35
|
const driverKit = {
|
|
36
36
|
blobDriver,
|
|
37
37
|
blobToURLDriver,
|
|
@@ -39,14 +39,14 @@ async function initDriverKit(pl, workdir, frontendDownloadPath, _ops) {
|
|
|
39
39
|
lsDriver,
|
|
40
40
|
signer,
|
|
41
41
|
uploadDriver,
|
|
42
|
-
pFrameDriver:
|
|
42
|
+
pFrameDriver: recordingSession ? wrapDataDriver(wrapModelDriver(rawPFrameDriver, recordingSession.recorder, recordingSession.registry), recordingSession.recorder, recordingSession.registry) : rawPFrameDriver,
|
|
43
43
|
frontendDriver: new DownloadUrlDriver(ops.logger, pl.httpDispatcher, frontendDownloadPath, signer, ops.frontendDownloadDriverOps),
|
|
44
|
-
|
|
44
|
+
crashRecorder: recordingSession?.recorder
|
|
45
45
|
};
|
|
46
46
|
const dispose = async () => {
|
|
47
47
|
const disposePromises = Object.values(driverKit).flatMap((driver) => isAsyncDisposable(driver) ? [driver[Symbol.asyncDispose]()] : []);
|
|
48
48
|
await Promise.all(disposePromises);
|
|
49
|
-
|
|
49
|
+
recordingSession?.close("driver-kit-disposed");
|
|
50
50
|
};
|
|
51
51
|
return {
|
|
52
52
|
...driverKit,
|