@milaboratories/pl-middle-layer 1.45.4 → 1.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/dist/index.cjs +58 -0
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/js_render/computable_context.cjs +37 -7
  6. package/dist/js_render/computable_context.cjs.map +1 -1
  7. package/dist/js_render/computable_context.d.ts.map +1 -1
  8. package/dist/js_render/computable_context.js +37 -7
  9. package/dist/js_render/computable_context.js.map +1 -1
  10. package/dist/js_render/context.cjs +12 -4
  11. package/dist/js_render/context.cjs.map +1 -1
  12. package/dist/js_render/context.d.ts +9 -0
  13. package/dist/js_render/context.d.ts.map +1 -1
  14. package/dist/js_render/context.js +12 -4
  15. package/dist/js_render/context.js.map +1 -1
  16. package/dist/js_render/index.cjs +1 -1
  17. package/dist/js_render/index.cjs.map +1 -1
  18. package/dist/js_render/index.js +1 -1
  19. package/dist/js_render/index.js.map +1 -1
  20. package/dist/middle_layer/block.cjs +7 -8
  21. package/dist/middle_layer/block.cjs.map +1 -1
  22. package/dist/middle_layer/block.d.ts +4 -4
  23. package/dist/middle_layer/block.d.ts.map +1 -1
  24. package/dist/middle_layer/block.js +7 -8
  25. package/dist/middle_layer/block.js.map +1 -1
  26. package/dist/middle_layer/block_ctx.cjs +67 -13
  27. package/dist/middle_layer/block_ctx.cjs.map +1 -1
  28. package/dist/middle_layer/block_ctx.d.ts +4 -7
  29. package/dist/middle_layer/block_ctx.d.ts.map +1 -1
  30. package/dist/middle_layer/block_ctx.js +68 -14
  31. package/dist/middle_layer/block_ctx.js.map +1 -1
  32. package/dist/middle_layer/block_ctx_unsafe.cjs +10 -3
  33. package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -1
  34. package/dist/middle_layer/block_ctx_unsafe.d.ts +1 -1
  35. package/dist/middle_layer/block_ctx_unsafe.d.ts.map +1 -1
  36. package/dist/middle_layer/block_ctx_unsafe.js +10 -3
  37. package/dist/middle_layer/block_ctx_unsafe.js.map +1 -1
  38. package/dist/middle_layer/frontend_path.cjs +1 -0
  39. package/dist/middle_layer/frontend_path.cjs.map +1 -1
  40. package/dist/middle_layer/frontend_path.js +1 -0
  41. package/dist/middle_layer/frontend_path.js.map +1 -1
  42. package/dist/middle_layer/middle_layer.cjs +1 -0
  43. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  44. package/dist/middle_layer/middle_layer.d.ts +1 -1
  45. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  46. package/dist/middle_layer/middle_layer.js +1 -0
  47. package/dist/middle_layer/middle_layer.js.map +1 -1
  48. package/dist/middle_layer/project.cjs +75 -28
  49. package/dist/middle_layer/project.cjs.map +1 -1
  50. package/dist/middle_layer/project.d.ts +34 -7
  51. package/dist/middle_layer/project.d.ts.map +1 -1
  52. package/dist/middle_layer/project.js +76 -29
  53. package/dist/middle_layer/project.js.map +1 -1
  54. package/dist/middle_layer/project_overview.cjs +32 -11
  55. package/dist/middle_layer/project_overview.cjs.map +1 -1
  56. package/dist/middle_layer/project_overview.d.ts.map +1 -1
  57. package/dist/middle_layer/project_overview.js +32 -11
  58. package/dist/middle_layer/project_overview.js.map +1 -1
  59. package/dist/middle_layer/render.cjs +1 -1
  60. package/dist/middle_layer/render.cjs.map +1 -1
  61. package/dist/middle_layer/render.js +1 -1
  62. package/dist/middle_layer/render.js.map +1 -1
  63. package/dist/middle_layer/render.test.d.ts.map +1 -1
  64. package/dist/model/block_storage_helper.cjs +210 -0
  65. package/dist/model/block_storage_helper.cjs.map +1 -0
  66. package/dist/model/block_storage_helper.d.ts +98 -0
  67. package/dist/model/block_storage_helper.d.ts.map +1 -0
  68. package/dist/model/block_storage_helper.js +153 -0
  69. package/dist/model/block_storage_helper.js.map +1 -0
  70. package/dist/model/index.d.ts +2 -1
  71. package/dist/model/index.d.ts.map +1 -1
  72. package/dist/model/project_helper.cjs +177 -0
  73. package/dist/model/project_helper.cjs.map +1 -1
  74. package/dist/model/project_helper.d.ts +110 -1
  75. package/dist/model/project_helper.d.ts.map +1 -1
  76. package/dist/model/project_helper.js +178 -1
  77. package/dist/model/project_helper.js.map +1 -1
  78. package/dist/model/project_model.cjs +6 -3
  79. package/dist/model/project_model.cjs.map +1 -1
  80. package/dist/model/project_model.d.ts +3 -2
  81. package/dist/model/project_model.d.ts.map +1 -1
  82. package/dist/model/project_model.js +6 -4
  83. package/dist/model/project_model.js.map +1 -1
  84. package/dist/mutator/block-pack/block_pack.cjs +1 -2
  85. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  86. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  87. package/dist/mutator/block-pack/block_pack.js +1 -2
  88. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  89. package/dist/mutator/block-pack/frontend.cjs +1 -0
  90. package/dist/mutator/block-pack/frontend.cjs.map +1 -1
  91. package/dist/mutator/block-pack/frontend.js +1 -0
  92. package/dist/mutator/block-pack/frontend.js.map +1 -1
  93. package/dist/mutator/migration.cjs +64 -3
  94. package/dist/mutator/migration.cjs.map +1 -1
  95. package/dist/mutator/migration.d.ts.map +1 -1
  96. package/dist/mutator/migration.js +66 -5
  97. package/dist/mutator/migration.js.map +1 -1
  98. package/dist/mutator/project-v3.test.d.ts +2 -0
  99. package/dist/mutator/project-v3.test.d.ts.map +1 -0
  100. package/dist/mutator/project.cjs +282 -41
  101. package/dist/mutator/project.cjs.map +1 -1
  102. package/dist/mutator/project.d.ts +77 -12
  103. package/dist/mutator/project.d.ts.map +1 -1
  104. package/dist/mutator/project.js +283 -42
  105. package/dist/mutator/project.js.map +1 -1
  106. package/dist/pool/result_pool.cjs +9 -6
  107. package/dist/pool/result_pool.cjs.map +1 -1
  108. package/dist/pool/result_pool.d.ts.map +1 -1
  109. package/dist/pool/result_pool.js +9 -6
  110. package/dist/pool/result_pool.js.map +1 -1
  111. package/package.json +16 -16
  112. package/src/js_render/computable_context.ts +37 -7
  113. package/src/js_render/context.ts +12 -5
  114. package/src/js_render/index.ts +1 -1
  115. package/src/middle_layer/block.ts +13 -14
  116. package/src/middle_layer/block_ctx.ts +70 -23
  117. package/src/middle_layer/block_ctx_unsafe.ts +11 -4
  118. package/src/middle_layer/middle_layer.ts +2 -1
  119. package/src/middle_layer/project.ts +86 -40
  120. package/src/middle_layer/project_overview.ts +44 -20
  121. package/src/middle_layer/render.test.ts +1 -1
  122. package/src/middle_layer/render.ts +1 -1
  123. package/src/model/block_storage_helper.ts +213 -0
  124. package/src/model/index.ts +2 -1
  125. package/src/model/project_helper.ts +249 -1
  126. package/src/model/project_model.ts +9 -5
  127. package/src/mutator/block-pack/block_pack.ts +1 -2
  128. package/src/mutator/migration.ts +79 -6
  129. package/src/mutator/project-v3.test.ts +280 -0
  130. package/src/mutator/project.test.ts +27 -27
  131. package/src/mutator/project.ts +351 -68
  132. package/src/pool/result_pool.ts +11 -4
@@ -148,7 +148,7 @@ function executeSingleLambda(quickJs, fh, codeWithInfo, ...args) {
148
148
  const rCtx = new JsExecutionContext(scope, vm, (s) => { deadlineSettings = s; }, featureFlags);
149
149
  // Initializing the model
150
150
  rCtx.evaluateBundle(code.content);
151
- // Running the lambda
151
+ // Running the lambda with arguments (e.g., state for args(), args for enrichmentTargets())
152
152
  return rCtx.importObjectUniversal(rCtx.runCallback(fh.handle, ...args));
153
153
  }
154
154
  finally {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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';\n\nfunction logOutputStatus(handle: string, renderedResult: unknown, stable: boolean, recalculationCounter: number, unstableMarker?: string) {\n if (getDebugFlags().logOutputStatus && (getDebugFlags().logOutputStatus === 'any' || !stable)) {\n if (stable)\n console.log(`Stable output ${handle} calculated ${renderedResult !== undefined ? 'defined' : 'undefined'}; (#${recalculationCounter})`);\n else\n console.log(`Unstable output ${handle}; marker = ${unstableMarker}; ${renderedResult !== undefined ? 'defined' : 'undefined'} (#${recalculationCounter})`);\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(`Block lambda recalculation : ${key} (${cCtx.changeSourceMarker}; ${cCtx.bodyInvocations} invocations)`);\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(1024 * 1024 * 8);\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(scope, vm,\n (s) => { deadlineSettings = s; },\n featureFlags,\n { computableCtx: cCtx, blockCtx: ctx, mlEnv: env });\n\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 logOutputStatus(fh.handle, importedResult, cCtx.unstableMarker === undefined, -1, cCtx.unstableMarker);\n return { ir: importedResult };\n }\n\n let recalculationCounter = 0;\n if (getDebugFlags().logOutputStatus)\n console.log(`Output ${fh.handle} scaffold calculated (not all computables resolved yet).`);\n keepVmAlive = true;\n\n return {\n ir: toBeResolved,\n postprocessValue: (resolved: Record<string, unknown>, { unstableMarker, stable }) => {\n // resolving futures\n for (const [handle, value] of Object.entries(resolved)) rCtx.runCallback(handle, value);\n\n // rendering result\n const renderedResult = rCtx.importObjectUniversal(result);\n\n // logging\n recalculationCounter++;\n logOutputStatus(fh.handle, renderedResult, stable, recalculationCounter, unstableMarker);\n\n return renderedResult;\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(1024 * 1024 * 8);\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(scope, vm,\n (s) => { deadlineSettings = s; },\n featureFlags,\n );\n\n // Initializing the model\n rCtx.evaluateBundle(code.content);\n\n // Running the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,QAAA,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;;AAGjC,QAAA,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IACzE;YAAU;QACR,KAAK,CAAC,OAAO,EAAE;IACjB;AACF;;;;"}
1
+ {"version":3,"file":"index.js","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';\n\nfunction logOutputStatus(handle: string, renderedResult: unknown, stable: boolean, recalculationCounter: number, unstableMarker?: string) {\n if (getDebugFlags().logOutputStatus && (getDebugFlags().logOutputStatus === 'any' || !stable)) {\n if (stable)\n console.log(`Stable output ${handle} calculated ${renderedResult !== undefined ? 'defined' : 'undefined'}; (#${recalculationCounter})`);\n else\n console.log(`Unstable output ${handle}; marker = ${unstableMarker}; ${renderedResult !== undefined ? 'defined' : 'undefined'} (#${recalculationCounter})`);\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(`Block lambda recalculation : ${key} (${cCtx.changeSourceMarker}; ${cCtx.bodyInvocations} invocations)`);\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(1024 * 1024 * 8);\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(scope, vm,\n (s) => { deadlineSettings = s; },\n featureFlags,\n { computableCtx: cCtx, blockCtx: ctx, mlEnv: env });\n\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 logOutputStatus(fh.handle, importedResult, cCtx.unstableMarker === undefined, -1, cCtx.unstableMarker);\n return { ir: importedResult };\n }\n\n let recalculationCounter = 0;\n if (getDebugFlags().logOutputStatus)\n console.log(`Output ${fh.handle} scaffold calculated (not all computables resolved yet).`);\n keepVmAlive = true;\n\n return {\n ir: toBeResolved,\n postprocessValue: (resolved: Record<string, unknown>, { unstableMarker, stable }) => {\n // resolving futures\n for (const [handle, value] of Object.entries(resolved)) rCtx.runCallback(handle, value);\n\n // rendering result\n const renderedResult = rCtx.importObjectUniversal(result);\n\n // logging\n recalculationCounter++;\n logOutputStatus(fh.handle, renderedResult, stable, recalculationCounter, unstableMarker);\n\n return renderedResult;\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(1024 * 1024 * 8);\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(scope, vm,\n (s) => { deadlineSettings = s; },\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 return rCtx.importObjectUniversal(rCtx.runCallback(fh.handle, ...args));\n } finally {\n scope.dispose();\n }\n}\n"],"names":[],"mappings":";;;;;AAWA,SAAS,eAAe,CAAC,MAAc,EAAE,cAAuB,EAAE,MAAe,EAAE,oBAA4B,EAAE,cAAuB,EAAA;AACtI,IAAA,IAAI,aAAa,EAAE,CAAC,eAAe,KAAK,aAAa,EAAE,CAAC,eAAe,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE;AAC7F,QAAA,IAAI,MAAM;YACR,OAAO,CAAC,GAAG,CAAC,CAAA,cAAA,EAAiB,MAAM,CAAA,YAAA,EAAe,cAAc,KAAK,SAAS,GAAG,SAAS,GAAG,WAAW,CAAA,IAAA,EAAO,oBAAoB,CAAA,CAAA,CAAG,CAAC;;YAEvI,OAAO,CAAC,GAAG,CAAC,CAAA,gBAAA,EAAmB,MAAM,CAAA,WAAA,EAAc,cAAc,CAAA,EAAA,EAAK,cAAc,KAAK,SAAS,GAAG,SAAS,GAAG,WAA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AAI,GAAG,IAAI,GAAG,CAAC,CAAC;AACvC,QAAA,OAAO,CAAC,eAAe,CAAC,IAAI,GAAG,GAAG,CAAC;AAEnC,QAAA,IAAI,gBAA8C;AAClD,QAAA,OAAO,CAAC,mBAAmB,CAAC,MAAK;YAC/B,IAAI,gBAAgB,KAAK,SAAS;AAAE,gBAAA,OAAO,KAAK;AAChD,YAAA,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC,QAAQ;AAAE,gBAAA,OAAO,IAAI;AACvD,YAAA,OAAO,KAAK;AACd,QAAA,CAAC,CAAC;QACF,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,IAAI,kBAAkB,CAAC,KAAK,EAAE,EAAE,EAC3C,CAAC,CAAC,KAAI,EAAG,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC,EAChC,YAAY,CACb;;AAGD,QAAA,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;;AAGjC,QAAA,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IACzE;YAAU;QACR,KAAK,CAAC,OAAO,EAAE;IACjB;AACF;;;;"}
@@ -11,20 +11,19 @@ var tsHelpers = require('@milaboratories/ts-helpers');
11
11
  var model = require('@platforma-sdk/model');
12
12
  var index = require('../debug/index.cjs');
13
13
 
14
- function blockArgsAndUiState(projectEntry, blockId, cCtx) {
14
+ function getBlockParameters(projectEntry, blockId, cCtx) {
15
15
  if (cCtx === undefined)
16
- return computable.Computable.make((c) => blockArgsAndUiState(projectEntry, blockId, c), {
16
+ return computable.Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {
17
17
  key: `inputs#${plClient.resourceIdToString(projectEntry.rid)}#${blockId}`,
18
18
  });
19
19
  const prj = cCtx.accessor(projectEntry).node();
20
20
  const ctx = block_ctx.constructBlockContextArgsOnly(projectEntry, blockId);
21
- const uiState = ctx.uiState(cCtx);
21
+ const blockStorageJson = ctx.blockStorage(cCtx);
22
+ // Parse raw storage JSON - UI will derive data using sdk/model
23
+ const blockStorage = blockStorageJson !== undefined ? tsHelpers.deepFreeze(JSON.parse(blockStorageJson)) : undefined;
22
24
  return {
23
25
  author: prj.getKeyValueAsJson(project_model.blockArgsAuthorKey(blockId)),
24
- // @TODO add deserialization caching
25
- args: tsHelpers.deepFreeze(JSON.parse(ctx.args(cCtx))),
26
- // @TODO add deserialization caching
27
- ui: uiState !== undefined ? tsHelpers.deepFreeze(JSON.parse(uiState)) : undefined,
26
+ blockStorage,
28
27
  };
29
28
  }
30
29
  function blockOutputs(projectEntry, blockId, env) {
@@ -46,6 +45,6 @@ function blockOutputs(projectEntry, blockId, env) {
46
45
  }, { key }).withStableType();
47
46
  }
48
47
 
49
- exports.blockArgsAndUiState = blockArgsAndUiState;
50
48
  exports.blockOutputs = blockOutputs;
49
+ exports.getBlockParameters = getBlockParameters;
51
50
  //# sourceMappingURL=block.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.cjs","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 {\n Computable,\n} 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, BlockStateInternal } 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 BlockArgsAndUiState = Omit<BlockStateInternal, 'outputs' | 'navigationState'>;\n\nexport function blockArgsAndUiState(\n projectEntry: PlTreeEntry,\n blockId: string\n): Computable<BlockArgsAndUiState>;\nexport function blockArgsAndUiState(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx\n): BlockArgsAndUiState;\nexport function blockArgsAndUiState(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockArgsAndUiState | Computable<BlockArgsAndUiState> {\n if (cCtx === undefined)\n return Computable.make((c) => blockArgsAndUiState(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 uiState = ctx.uiState(cCtx);\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n // @TODO add deserialization caching\n args: deepFreeze(JSON.parse(ctx.args(cCtx))),\n // @TODO add deserialization caching\n ui: uiState !== undefined ? deepFreeze(JSON.parse(uiState)) : undefined,\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(`blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`);\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(env, ctx, cellCfg, extractCodeWithInfo(cfg), bpId);\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"names":["Computable","resourceIdToString","constructBlockContextArgsOnly","blockArgsAuthorKey","deepFreeze","getDebugFlags","constructBlockContext","ifNotUndef","getBlockPackInfo","computableFromCfgOrRF","extractCodeWithInfo"],"mappings":";;;;;;;;;;;;;SAgCgB,mBAAmB,CACjC,YAAyB,EACzB,OAAe,EACf,IAAoB,EAAA;IAEpB,IAAI,IAAI,KAAK,SAAS;AACpB,QAAA,OAAOA,qBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,mBAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;YAC3E,GAAG,EAAE,CAAA,OAAA,EAAUC,2BAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA,CAAA,EAAI,OAAO,CAAA,CAAE;AACjE,SAAA,CAAC;IAEJ,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE;IAC9C,MAAM,GAAG,GAAGC,uCAA6B,CAAC,YAAY,EAAE,OAAO,CAAC;IAChE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IACjC,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,iBAAiB,CAAeC,gCAAkB,CAAC,OAAO,CAAC,CAAC;;AAExE,QAAA,IAAI,EAAEC,oBAAU,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;;AAE5C,QAAA,EAAE,EAAE,OAAO,KAAK,SAAS,GAAGA,oBAAU,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS;KACxE;AACH;SAEgB,YAAY,CAC1B,YAAyB,EACzB,OAAe,EACf,GAA2B,EAAA;AAE3B,IAAA,MAAM,GAAG,GAAG,UAAU,GAAGH,2BAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,OAAO;AAC7E,IAAA,OAAOD,qBAAU,CAAC,IAAI,CACpB,CAAC,CAAC,KAAI;AACJ,QAAA,IAAIK,mBAAa,EAAE,CAAC,uBAAuB,EAAE;AAC3C,YAAA,OAAO,CAAC,GAAG,CAAC,CAAA,4BAAA,EAA+B,GAAG,CAAA,EAAA,EAAK,CAAC,CAAC,kBAAkB,KAAK,CAAC,CAAC,eAAe,CAAA,aAAA,CAAe,CAAC;QAC/G;QAEA,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE;QAC3C,MAAM,GAAG,GAAGC,+BAAqB,CAAC,YAAY,EAAE,OAAO,CAAC;AAExD,QAAA,OAAOC,eAAU,CAACC,uBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAI;YAClE,MAAM,OAAO,GAAoC,EAAE;AACnD,YAAA,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;AAC3D,gBAAA,MAAM,gBAAgB,GAAGC,4BAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAEC,yBAAmB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;AACjG,gBAAA,OAAO,CAAC,MAAM,CAAC,GAAGV,qBAAU,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAC7D;AACA,YAAA,OAAO,OAAO;AAChB,QAAA,CAAC,CAAC;IACJ,CAAC,EACD,EAAE,GAAG,EAAE,CACR,CAAC,cAAc,EAAE;AACpB;;;;;"}
1
+ {"version":3,"file":"block.cjs","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 {\n Computable,\n} 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 = 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(`blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`);\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(env, ctx, cellCfg, extractCodeWithInfo(cfg), bpId);\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"names":["Computable","resourceIdToString","constructBlockContextArgsOnly","deepFreeze","blockArgsAuthorKey","getDebugFlags","constructBlockContext","ifNotUndef","getBlockPackInfo","computableFromCfgOrRF","extractCodeWithInfo"],"mappings":";;;;;;;;;;;;;SAgCgB,kBAAkB,CAChC,YAAyB,EACzB,OAAe,EACf,IAAoB,EAAA;IAEpB,IAAI,IAAI,KAAK,SAAS;AACpB,QAAA,OAAOA,qBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;YAC1E,GAAG,EAAE,CAAA,OAAA,EAAUC,2BAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA,CAAA,EAAI,OAAO,CAAA,CAAE;AACjE,SAAA,CAAC;IAEJ,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE;IAC9C,MAAM,GAAG,GAAGC,uCAA6B,CAAC,YAAY,EAAE,OAAO,CAAC;IAChE,MAAM,gBAAgB,GAAG,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC;;IAE/C,MAAM,YAAY,GAAG,gBAAgB,KAAK,SAAS,GAAGC,oBAAU,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS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AAC,CAAC;IACJ,CAAC,EACD,EAAE,GAAG,EAAE,CACR,CAAC,cAAc,EAAE;AACpB;;;;;"}
@@ -2,9 +2,9 @@ import type { PlTreeEntry } from '@milaboratories/pl-tree';
2
2
  import type { ComputableCtx, ComputableStableDefined, ComputableValueOrErrors } from '@milaboratories/computable';
3
3
  import { Computable } from '@milaboratories/computable';
4
4
  import type { MiddleLayerEnvironment } from './middle_layer';
5
- import type { BlockStateInternal } from '@milaboratories/pl-model-middle-layer';
6
- export type BlockArgsAndUiState = Omit<BlockStateInternal, 'outputs' | 'navigationState'>;
7
- export declare function blockArgsAndUiState(projectEntry: PlTreeEntry, blockId: string): Computable<BlockArgsAndUiState>;
8
- export declare function blockArgsAndUiState(projectEntry: PlTreeEntry, blockId: string, cCtx: ComputableCtx): BlockArgsAndUiState;
5
+ import type { BlockStateInternalV3 } from '@milaboratories/pl-model-middle-layer';
6
+ export type BlockParameters = Omit<BlockStateInternalV3, 'outputs' | 'navigationState'>;
7
+ export declare function getBlockParameters(projectEntry: PlTreeEntry, blockId: string): Computable<BlockParameters>;
8
+ export declare function getBlockParameters(projectEntry: PlTreeEntry, blockId: string, cCtx: ComputableCtx): BlockParameters;
9
9
  export declare function blockOutputs(projectEntry: PlTreeEntry, blockId: string, env: MiddleLayerEnvironment): ComputableStableDefined<Record<string, ComputableValueOrErrors<unknown>>>;
10
10
  //# sourceMappingURL=block.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/middle_layer/block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,UAAU,EACX,MAAM,4BAA4B,CAAC;AAIpC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,E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AAe,CAAC;AAsBnB,wBAAgB,YAAY,CAC1B,YAAY,EAAE,WAAW,EACzB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,sBAAsB,GAC1B,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC,CAsB3E"}
@@ -9,20 +9,19 @@ import { deepFreeze } from '@milaboratories/ts-helpers';
9
9
  import { extractCodeWithInfo } from '@platforma-sdk/model';
10
10
  import { getDebugFlags } from '../debug/index.js';
11
11
 
12
- function blockArgsAndUiState(projectEntry, blockId, cCtx) {
12
+ function getBlockParameters(projectEntry, blockId, cCtx) {
13
13
  if (cCtx === undefined)
14
- return Computable.make((c) => blockArgsAndUiState(projectEntry, blockId, c), {
14
+ return Computable.make((c) => getBlockParameters(projectEntry, blockId, c), {
15
15
  key: `inputs#${resourceIdToString(projectEntry.rid)}#${blockId}`,
16
16
  });
17
17
  const prj = cCtx.accessor(projectEntry).node();
18
18
  const ctx = constructBlockContextArgsOnly(projectEntry, blockId);
19
- const uiState = ctx.uiState(cCtx);
19
+ const blockStorageJson = ctx.blockStorage(cCtx);
20
+ // Parse raw storage JSON - UI will derive data using sdk/model
21
+ const blockStorage = blockStorageJson !== undefined ? deepFreeze(JSON.parse(blockStorageJson)) : undefined;
20
22
  return {
21
23
  author: prj.getKeyValueAsJson(blockArgsAuthorKey(blockId)),
22
- // @TODO add deserialization caching
23
- args: deepFreeze(JSON.parse(ctx.args(cCtx))),
24
- // @TODO add deserialization caching
25
- ui: uiState !== undefined ? deepFreeze(JSON.parse(uiState)) : undefined,
24
+ blockStorage,
26
25
  };
27
26
  }
28
27
  function blockOutputs(projectEntry, blockId, env) {
@@ -44,5 +43,5 @@ function blockOutputs(projectEntry, blockId, env) {
44
43
  }, { key }).withStableType();
45
44
  }
46
45
 
47
- export { blockArgsAndUiState, blockOutputs };
46
+ export { blockOutputs, getBlockParameters };
48
47
  //# sourceMappingURL=block.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"block.js","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 {\n Computable,\n} 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, BlockStateInternal } 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 BlockArgsAndUiState = Omit<BlockStateInternal, 'outputs' | 'navigationState'>;\n\nexport function blockArgsAndUiState(\n projectEntry: PlTreeEntry,\n blockId: string\n): Computable<BlockArgsAndUiState>;\nexport function blockArgsAndUiState(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx: ComputableCtx\n): BlockArgsAndUiState;\nexport function blockArgsAndUiState(\n projectEntry: PlTreeEntry,\n blockId: string,\n cCtx?: ComputableCtx,\n): BlockArgsAndUiState | Computable<BlockArgsAndUiState> {\n if (cCtx === undefined)\n return Computable.make((c) => blockArgsAndUiState(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 uiState = ctx.uiState(cCtx);\n return {\n author: prj.getKeyValueAsJson<AuthorMarker>(blockArgsAuthorKey(blockId)),\n // @TODO add deserialization caching\n args: deepFreeze(JSON.parse(ctx.args(cCtx))),\n // @TODO add deserialization caching\n ui: uiState !== undefined ? deepFreeze(JSON.parse(uiState)) : undefined,\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(`blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`);\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(env, ctx, cellCfg, extractCodeWithInfo(cfg), bpId);\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"names":[],"mappings":";;;;;;;;;;;SAgCgB,mBAAmB,CACjC,YAAyB,EACzB,OAAe,EACf,IAAoB,EAAA;IAEpB,IAAI,IAAI,KAAK,SAAS;AACpB,QAAA,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,mBAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;YAC3E,GAAG,EAAE,CAAA,OAAA,EAAU,kBAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA,CAAA,EAAI,OAAO,CAAA,CAAE;AACjE,SAAA,CAAC;IAEJ,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE;IAC9C,MAAM,GAAG,GAAG,6BAA6B,CAAC,YAAY,EAAE,OAAO,CAAC;IAChE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IACjC,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,iBAAiB,CAAe,kB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AC;AACjG,gBAAA,OAAO,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAC7D;AACA,YAAA,OAAO,OAAO;AAChB,QAAA,CAAC,CAAC;IACJ,CAAC,EACD,EAAE,GAAG,EAAE,CACR,CAAC,cAAc,EAAE;AACpB;;;;"}
1
+ {"version":3,"file":"block.js","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 {\n Computable,\n} 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 = 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(`blockOutput recalculation : ${key} (${c.changeSourceMarker}; ${c.bodyInvocations} invocations)`);\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(env, ctx, cellCfg, extractCodeWithInfo(cfg), bpId);\n outputs[cellId] = Computable.wrapError(computableOutput, 1);\n }\n return outputs;\n });\n },\n { key },\n ).withStableType();\n}\n"],"names":[],"mappings":";;;;;;;;;;;SAgCgB,kBAAkB,CAChC,YAAyB,EACzB,OAAe,EACf,IAAoB,EAAA;IAEpB,IAAI,IAAI,KAAK,SAAS;AACpB,QAAA,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;YAC1E,GAAG,EAAE,CAAA,OAAA,EAAU,kBAAkB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA,CAAA,EAAI,OAAO,CAAA,CAAE;AACjE,SAAA,CAAC;IAEJ,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE;IA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AAqB,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,mBAAmB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;AACjG,gBAAA,OAAO,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAC7D;AACA,YAAA,OAAO,OAAO;AAChB,QAAA,CAAC,CAAC;IACJ,CAAC,EACD,EAAE,GAAG,EAAE,CACR,CAAC,cAAc,EAAE;AACpB;;;;"}
@@ -4,16 +4,20 @@ var tsHelpers = require('@milaboratories/ts-helpers');
4
4
  var project_model = require('../model/project_model.cjs');
5
5
  var project_model_util = require('../model/project_model_util.cjs');
6
6
  var result_pool = require('../pool/result_pool.cjs');
7
+ var model = require('@platforma-sdk/model');
7
8
 
8
9
  function constructBlockContextArgsOnly(projectEntry, blockId) {
9
- const args = (cCtx) => tsHelpers.cachedDecode(tsHelpers.notEmpty(cCtx
10
- .accessor(projectEntry)
11
- .node()
12
- .traverse({
13
- field: project_model.projectFieldName(blockId, 'currentArgs'),
14
- errorIfFieldNotSet: true,
15
- })
16
- .getData()));
10
+ const args = (cCtx) => {
11
+ const data = cCtx
12
+ .accessor(projectEntry)
13
+ .node()
14
+ .traverse({
15
+ field: project_model.projectFieldName(blockId, 'currentArgs'),
16
+ stableIfNotFound: true,
17
+ })
18
+ ?.getData();
19
+ return data ? tsHelpers.cachedDecode(data) : undefined;
20
+ };
17
21
  const activeArgs = (cCtx) => {
18
22
  const data = cCtx
19
23
  .accessor(projectEntry)
@@ -25,12 +29,50 @@ function constructBlockContextArgsOnly(projectEntry, blockId) {
25
29
  ?.getData();
26
30
  return data ? tsHelpers.cachedDecode(data) : undefined;
27
31
  };
28
- const uiState = (cCtx) => {
32
+ const data = (cCtx) => {
29
33
  const data = cCtx
30
34
  .accessor(projectEntry)
31
35
  .node()
32
36
  .traverse({
33
- field: project_model.projectFieldName(blockId, 'uiState'),
37
+ field: project_model.projectFieldName(blockId, 'blockStorage'),
38
+ stableIfNotFound: true,
39
+ })
40
+ ?.getData();
41
+ if (!data)
42
+ return undefined;
43
+ const rawJson = tsHelpers.cachedDecode(data);
44
+ if (!rawJson)
45
+ return undefined;
46
+ // Parse to check if it's BlockStorage format
47
+ try {
48
+ const parsed = JSON.parse(rawJson);
49
+ return JSON.stringify(model.deriveDataFromStorage(parsed));
50
+ }
51
+ catch (err) {
52
+ console.error('Error deriving data from storage', err);
53
+ return undefined;
54
+ }
55
+ };
56
+ // Returns raw blockStorage JSON - UI derives data using sdk/model
57
+ const blockStorage = (cCtx) => {
58
+ const storageData = cCtx
59
+ .accessor(projectEntry)
60
+ .node()
61
+ .traverse({
62
+ field: project_model.projectFieldName(blockId, 'blockStorage'),
63
+ stableIfNotFound: true,
64
+ })
65
+ ?.getData();
66
+ if (!storageData)
67
+ return undefined;
68
+ return tsHelpers.cachedDecode(storageData);
69
+ };
70
+ const prerunArgs = (cCtx) => {
71
+ const data = cCtx
72
+ .accessor(projectEntry)
73
+ .node()
74
+ .traverse({
75
+ field: project_model.projectFieldName(blockId, 'currentPrerunArgs'),
34
76
  stableIfNotFound: true,
35
77
  })
36
78
  ?.getData();
@@ -40,7 +82,9 @@ function constructBlockContextArgsOnly(projectEntry, blockId) {
40
82
  blockId,
41
83
  args,
42
84
  activeArgs,
43
- uiState,
85
+ data,
86
+ blockStorage,
87
+ prerunArgs,
44
88
  blockMeta: (cCtx) => {
45
89
  const prj = cCtx.accessor(projectEntry).node();
46
90
  const structure = tsHelpers.notEmpty(prj.getKeyValueAsJson(project_model.ProjectStructureKey));
@@ -66,16 +110,26 @@ function constructBlockContext(projectEntry, blockId) {
66
110
  ?.persist();
67
111
  },
68
112
  staging: (cCtx) => {
113
+ // Check if staging is expected (currentPrerunArgs is set)
114
+ // For blocks with failed args derivation, staging will never be rendered
115
+ const hasPrerunArgs = cCtx
116
+ .accessor(projectEntry)
117
+ .node({ ignoreError: true })
118
+ .traverse({
119
+ field: project_model.projectFieldName(blockId, 'currentPrerunArgs'),
120
+ stableIfNotFound: true,
121
+ ignoreError: true,
122
+ }) !== undefined;
69
123
  const result = cCtx
70
124
  .accessor(projectEntry)
71
125
  .node({ ignoreError: true })
72
126
  .traverse({
73
127
  field: project_model.projectFieldName(blockId, 'stagingOutput'),
128
+ // Only mark stable if staging is NOT expected (no prerunArgs)
129
+ stableIfNotFound: !hasPrerunArgs,
74
130
  ignoreError: true,
75
131
  })
76
132
  ?.persist();
77
- if (result === undefined)
78
- cCtx.markUnstable('staging_not_rendered');
79
133
  return result;
80
134
  },
81
135
  getResultsPool: (cCtx) => result_pool.ResultPool.create(cCtx, projectEntry, blockId),
@@ -1 +1 @@
1
- {"version":3,"file":"block_ctx.cjs","sources":["../../src/middle_layer/block_ctx.ts"],"sourcesContent":["import type { ComputableCtx } from '@milaboratories/computable';\nimport type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport { cachedDecode, notEmpty } from '@milaboratories/ts-helpers';\nimport type { Optional } from 'utility-types';\nimport type {\n Block,\n ProjectStructure } from '../model/project_model';\nimport {\n ProjectStructureKey,\n projectFieldName,\n} from '../model/project_model';\nimport { allBlocks } from '../model/project_model_util';\nimport { ResultPool } from '../pool/result_pool';\n\nexport type BlockContextMaterialized = {\n readonly blockId: string;\n readonly args: string;\n readonly uiState?: string;\n};\n\nexport type BlockContextArgsOnly = {\n readonly blockId: string;\n readonly args: (cCtx: ComputableCtx) => string;\n readonly activeArgs: (cCtx: ComputableCtx) => string | undefined;\n readonly uiState: (cCtx: ComputableCtx) => string | undefined;\n readonly blockMeta: (cCtx: ComputableCtx) => Map<string, Block>;\n};\n\nexport type BlockContextFull = BlockContextArgsOnly & {\n readonly prod: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly staging: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly getResultsPool: (cCtx: ComputableCtx) => ResultPool;\n};\n\nexport type BlockContextAny = Optional<BlockContextFull, 'prod' | 'staging' | 'getResultsPool'>;\n\nexport function constructBlockContextArgsOnly(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextArgsOnly {\n const args = (cCtx: ComputableCtx) =>\n cachedDecode(notEmpty(\n cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'currentArgs'),\n errorIfFieldNotSet: true,\n })\n .getData(),\n ));\n const activeArgs = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'prodArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n const uiState = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'uiState'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n return {\n blockId,\n args,\n activeArgs,\n uiState,\n blockMeta: (cCtx: ComputableCtx) => {\n const prj = cCtx.accessor(projectEntry).node();\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const result = new Map<string, Block>();\n for (const block of allBlocks(structure)) result.set(block.id, block);\n return result;\n },\n };\n}\n\nexport function constructBlockContext(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextFull {\n return {\n ...constructBlockContextArgsOnly(projectEntry, blockId),\n prod: (cCtx: ComputableCtx) => {\n return cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'prodOutput'),\n stableIfNotFound: true,\n ignoreError: true,\n })\n ?.persist();\n },\n staging: (cCtx: ComputableCtx) => {\n const result = cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'stagingOutput'),\n ignoreError: true,\n })\n ?.persist();\n if (result === undefined) cCtx.markUnstable('staging_not_rendered');\n return result;\n },\n getResultsPool: (cCtx: ComputableCtx) => ResultPool.create(cCtx, projectEntry, blockId),\n };\n}\n"],"names":["cachedDecode","notEmp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KAAKG,sBAAU,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC;KACxF;AACH;;;;;"}
1
+ {"version":3,"file":"block_ctx.cjs","sources":["../../src/middle_layer/block_ctx.ts"],"sourcesContent":["import type { ComputableCtx } from '@milaboratories/computable';\nimport type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport { cachedDecode, notEmpty } from '@milaboratories/ts-helpers';\nimport type { Optional } from 'utility-types';\nimport type {\n Block,\n ProjectStructure } from '../model/project_model';\nimport {\n ProjectStructureKey,\n projectFieldName,\n} from '../model/project_model';\nimport { allBlocks } from '../model/project_model_util';\nimport { ResultPool } from '../pool/result_pool';\nimport { deriveDataFromStorage } from '@platforma-sdk/model';\n\nexport type BlockContextArgsOnly = {\n readonly blockId: string;\n readonly args: (cCtx: ComputableCtx) => string | undefined;\n readonly activeArgs: (cCtx: ComputableCtx) => string | undefined;\n readonly blockMeta: (cCtx: ComputableCtx) => Map<string, Block>;\n readonly data: (cCtx: ComputableCtx) => string | undefined;\n readonly blockStorage: (cCtx: ComputableCtx) => string | undefined;\n readonly prerunArgs: (cCtx: ComputableCtx) => string | undefined;\n};\n\nexport type BlockContextFull = BlockContextArgsOnly & {\n readonly prod: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly staging: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly getResultsPool: (cCtx: ComputableCtx) => ResultPool;\n};\n\nexport type BlockContextAny = Optional<BlockContextFull, 'prod' | 'staging' | 'getResultsPool'>;\n\nexport function constructBlockContextArgsOnly(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextArgsOnly {\n const args = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'currentArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n const activeArgs = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'prodArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n const data = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'blockStorage'),\n stableIfNotFound: true,\n })\n ?.getData();\n if (!data) return undefined;\n\n const rawJson = cachedDecode(data);\n if (!rawJson) return undefined;\n\n // Parse to check if it's BlockStorage format\n try {\n const parsed = JSON.parse(rawJson);\n return JSON.stringify(deriveDataFromStorage(parsed));\n } catch (err) {\n console.error('Error deriving data from storage', err);\n return undefined;\n }\n };\n // Returns raw blockStorage JSON - UI derives data using sdk/model\n const blockStorage = (cCtx: ComputableCtx) => {\n const storageData = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'blockStorage'),\n stableIfNotFound: true,\n })\n ?.getData();\n if (!storageData) return undefined;\n return cachedDecode(storageData);\n };\n const prerunArgs = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'currentPrerunArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n return {\n blockId,\n args,\n activeArgs,\n data,\n blockStorage,\n prerunArgs,\n blockMeta: (cCtx: ComputableCtx) => {\n const prj = cCtx.accessor(projectEntry).node();\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const result = new Map<string, Block>();\n for (const block of allBlocks(structure)) result.set(block.id, block);\n return result;\n },\n };\n}\n\nexport function constructBlockContext(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextFull {\n return {\n ...constructBlockContextArgsOnly(projectEntry, blockId),\n prod: (cCtx: ComputableCtx) => {\n return cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'prodOutput'),\n stableIfNotFound: true,\n ignoreError: true,\n })\n ?.persist();\n },\n staging: (cCtx: ComputableCtx) => {\n // Check if staging is expected (currentPrerunArgs is set)\n // For blocks with failed args derivation, staging will never be rendered\n const hasPrerunArgs = cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'currentPrerunArgs'),\n stableIfNotFound: true,\n ignoreError: true,\n }) !== undefined;\n\n const result = cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'stagingOutput'),\n // Only mark stable if staging is NOT expected (no prerunArgs)\n stableIfNotFound: !hasPrerunArgs,\n ignoreError: true,\n })\n ?.persist();\n return result;\n },\n getResultsPool: (cCtx: ComputableCtx) => ResultPool.create(cCtx, projectEntry, blockId),\n };\n}\n"],"names":["projectFieldName","cachedDecode","deriveDataFromStorage","notEmpty","ProjectStructureKey","allBlocks","ResultPool"],"mappings":";;;;;;;;AAiCM,SAAU,6BAA6B,CAC3C,YAAyB,EACzB,OAAe,EAAA;AAEf,IAAA,MAAM,IAAI,GAAG,CAAC,IAAmB,KAAI;QACnC,MAAM,IAAI,GAAG;aACV,QAAQ,CAAC,YAAY;AACrB,aAAA,IAAI;AACJ,aAAA,QAAQ,CAAC;AACR,YAAA,KAAK,EAAEA,8BAAgB,CAAC,OAAO,EAAE,aAAa,CAAC;AAC/C,YAAA,gBAAgB,EAAE,IAAI;SACvB;cACC,OAAO,EAAE;AACb,QAAA,OAAO,IAAI,GAAGC,sBAAY,CAAC,IAAI,CAAC,GAAG,SAAS;AAC9C,IAAA,CAAC;AACD,IAAA,MAAM,UAAU,GAAG,CAAC,IAAmB,KAAI;QACzC,MAAM,IAAI,GAAG;aACV,QAAQ,CAAC,YAAY;AACrB,aAAA,IAAI;AACJ,aAAA,QAAQ,CAAC;AACR,YAAA,KAAK,EAAED,8BAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;AAC5C,YAAA,gBAAgB,EAAE,IAAI;SACvB;cACC,OAAO,EAAE;AACb,QAAA,O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;QACf,CAAC;AACD,QAAA,OAAO,EAAE,CAAC,IAAmB,KAAI;;;YAG/B,MAAM,aAAa,GAAG;iBACnB,QAAQ,CAAC,YAAY;AACrB,iBAAA,IAAI,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE;AAC1B,iBAAA,QAAQ,CAAC;AACR,gBAAA,KAAK,EAAEA,8BAAgB,CAAC,OAAO,EAAE,mBAAmB,CAAC;AACrD,gBAAA,gBAAgB,EAAE,IAAI;AACtB,gBAAA,WAAW,EAAE,IAAI;aAClB,CAAC,KAAK,SAAS;YAElB,MAAM,MAAM,GAAG;iBACZ,QAAQ,CAAC,YAAY;AACrB,iBAAA,IAAI,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE;AAC1B,iBAAA,QAAQ,CAAC;AACR,gBAAA,KAAK,EAAEA,8BAAgB,CAAC,OAAO,EAAE,eAAe,CAAC;;gBAEjD,gBAAgB,EAAE,CAAC,aAAa;AAChC,gBAAA,WAAW,EAAE,IAAI;aAClB;kBACC,OAAO,EAAE;AACb,YAAA,OAAO,MAAM;QACf,CAAC;AACD,QAAA,cAAc,EAAE,CAAC,IAAmB,KAAKM,sBAAU,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC;KACxF;AACH;;;;;"}
@@ -3,17 +3,14 @@ import type { PlTreeEntry } from '@milaboratories/pl-tree';
3
3
  import type { Optional } from 'utility-types';
4
4
  import type { Block } from '../model/project_model';
5
5
  import { ResultPool } from '../pool/result_pool';
6
- export type BlockContextMaterialized = {
7
- readonly blockId: string;
8
- readonly args: string;
9
- readonly uiState?: string;
10
- };
11
6
  export type BlockContextArgsOnly = {
12
7
  readonly blockId: string;
13
- readonly args: (cCtx: ComputableCtx) => string;
8
+ readonly args: (cCtx: ComputableCtx) => string | undefined;
14
9
  readonly activeArgs: (cCtx: ComputableCtx) => string | undefined;
15
- readonly uiState: (cCtx: ComputableCtx) => string | undefined;
16
10
  readonly blockMeta: (cCtx: ComputableCtx) => Map<string, Block>;
11
+ readonly data: (cCtx: ComputableCtx) => string | undefined;
12
+ readonly blockStorage: (cCtx: ComputableCtx) => string | undefined;
13
+ readonly prerunArgs: (cCtx: ComputableCtx) => string | undefined;
17
14
  };
18
15
  export type BlockContextFull = BlockContextArgsOnly & {
19
16
  readonly prod: (cCtx: ComputableCtx) => PlTreeEntry | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"block_ctx.d.ts","sourceRoot":"","sources":["../../src/middle_layer/block_ctx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EACV,KAAK,EACa,MAAM,wBAAwB,CAAC;AAMnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,CAAC;IAC/C,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,GAAG,SAAS,CAAC;IACjE,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,GAAG,SAAS,CAAC;IAC9D,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACjE,CAAC;AAEF,MAAM,MAA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EAAE,aAAa,KAAK,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,YAAY,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,GAAG,SAAS,CAAC;IACnE,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,MAAM,GAAG,SAAS,CAAC;CAClE,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG;IACpD,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,WAAW,GAAG,SAAS,CAAC;IAChE,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,WAAW,GAAG,SAAS,CAAC;IACnE,QAAQ,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,UAAU,CAAC;CAC9D,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,CAAC,CAAC;AAEhG,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,WAAW,EACzB,OAAO,EAAE,MAAM,GACd,oBAAoB,CAqFtB;AAED,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,WAAW,EACzB,OAAO,EAAE,MAAM,GACd,gBAAgB,CAwClB"}
@@ -1,17 +1,21 @@
1
- import { cachedDecode, notEmpty } from '@milaboratories/ts-helpers';
1
+ import { notEmpty, cachedDecode } from '@milaboratories/ts-helpers';
2
2
  import { projectFieldName, ProjectStructureKey } from '../model/project_model.js';
3
3
  import { allBlocks } from '../model/project_model_util.js';
4
4
  import { ResultPool } from '../pool/result_pool.js';
5
+ import { deriveDataFromStorage } from '@platforma-sdk/model';
5
6
 
6
7
  function constructBlockContextArgsOnly(projectEntry, blockId) {
7
- const args = (cCtx) => cachedDecode(notEmpty(cCtx
8
- .accessor(projectEntry)
9
- .node()
10
- .traverse({
11
- field: projectFieldName(blockId, 'currentArgs'),
12
- errorIfFieldNotSet: true,
13
- })
14
- .getData()));
8
+ const args = (cCtx) => {
9
+ const data = cCtx
10
+ .accessor(projectEntry)
11
+ .node()
12
+ .traverse({
13
+ field: projectFieldName(blockId, 'currentArgs'),
14
+ stableIfNotFound: true,
15
+ })
16
+ ?.getData();
17
+ return data ? cachedDecode(data) : undefined;
18
+ };
15
19
  const activeArgs = (cCtx) => {
16
20
  const data = cCtx
17
21
  .accessor(projectEntry)
@@ -23,12 +27,50 @@ function constructBlockContextArgsOnly(projectEntry, blockId) {
23
27
  ?.getData();
24
28
  return data ? cachedDecode(data) : undefined;
25
29
  };
26
- const uiState = (cCtx) => {
30
+ const data = (cCtx) => {
27
31
  const data = cCtx
28
32
  .accessor(projectEntry)
29
33
  .node()
30
34
  .traverse({
31
- field: projectFieldName(blockId, 'uiState'),
35
+ field: projectFieldName(blockId, 'blockStorage'),
36
+ stableIfNotFound: true,
37
+ })
38
+ ?.getData();
39
+ if (!data)
40
+ return undefined;
41
+ const rawJson = cachedDecode(data);
42
+ if (!rawJson)
43
+ return undefined;
44
+ // Parse to check if it's BlockStorage format
45
+ try {
46
+ const parsed = JSON.parse(rawJson);
47
+ return JSON.stringify(deriveDataFromStorage(parsed));
48
+ }
49
+ catch (err) {
50
+ console.error('Error deriving data from storage', err);
51
+ return undefined;
52
+ }
53
+ };
54
+ // Returns raw blockStorage JSON - UI derives data using sdk/model
55
+ const blockStorage = (cCtx) => {
56
+ const storageData = cCtx
57
+ .accessor(projectEntry)
58
+ .node()
59
+ .traverse({
60
+ field: projectFieldName(blockId, 'blockStorage'),
61
+ stableIfNotFound: true,
62
+ })
63
+ ?.getData();
64
+ if (!storageData)
65
+ return undefined;
66
+ return cachedDecode(storageData);
67
+ };
68
+ const prerunArgs = (cCtx) => {
69
+ const data = cCtx
70
+ .accessor(projectEntry)
71
+ .node()
72
+ .traverse({
73
+ field: projectFieldName(blockId, 'currentPrerunArgs'),
32
74
  stableIfNotFound: true,
33
75
  })
34
76
  ?.getData();
@@ -38,7 +80,9 @@ function constructBlockContextArgsOnly(projectEntry, blockId) {
38
80
  blockId,
39
81
  args,
40
82
  activeArgs,
41
- uiState,
83
+ data,
84
+ blockStorage,
85
+ prerunArgs,
42
86
  blockMeta: (cCtx) => {
43
87
  const prj = cCtx.accessor(projectEntry).node();
44
88
  const structure = notEmpty(prj.getKeyValueAsJson(ProjectStructureKey));
@@ -64,16 +108,26 @@ function constructBlockContext(projectEntry, blockId) {
64
108
  ?.persist();
65
109
  },
66
110
  staging: (cCtx) => {
111
+ // Check if staging is expected (currentPrerunArgs is set)
112
+ // For blocks with failed args derivation, staging will never be rendered
113
+ const hasPrerunArgs = cCtx
114
+ .accessor(projectEntry)
115
+ .node({ ignoreError: true })
116
+ .traverse({
117
+ field: projectFieldName(blockId, 'currentPrerunArgs'),
118
+ stableIfNotFound: true,
119
+ ignoreError: true,
120
+ }) !== undefined;
67
121
  const result = cCtx
68
122
  .accessor(projectEntry)
69
123
  .node({ ignoreError: true })
70
124
  .traverse({
71
125
  field: projectFieldName(blockId, 'stagingOutput'),
126
+ // Only mark stable if staging is NOT expected (no prerunArgs)
127
+ stableIfNotFound: !hasPrerunArgs,
72
128
  ignoreError: true,
73
129
  })
74
130
  ?.persist();
75
- if (result === undefined)
76
- cCtx.markUnstable('staging_not_rendered');
77
131
  return result;
78
132
  },
79
133
  getResultsPool: (cCtx) => ResultPool.create(cCtx, projectEntry, blockId),
@@ -1 +1 @@
1
- {"version":3,"file":"block_ctx.js","sources":["../../src/middle_layer/block_ctx.ts"],"sourcesContent":["import type { ComputableCtx } from '@milaboratories/computable';\nimport type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport { cachedDecode, notEmpty } from '@milaboratories/ts-helpers';\nimport type { Optional } from 'utility-types';\nimport type {\n Block,\n ProjectStructure } from '../model/project_model';\nimport {\n ProjectStructureKey,\n projectFieldName,\n} from '../model/project_model';\nimport { allBlocks } from '../model/project_model_util';\nimport { ResultPool } from '../pool/result_pool';\n\nexport type BlockContextMaterialized = {\n readonly blockId: string;\n readonly args: string;\n readonly uiState?: string;\n};\n\nexport type BlockContextArgsOnly = {\n readonly blockId: string;\n readonly args: (cCtx: ComputableCtx) => string;\n readonly activeArgs: (cCtx: ComputableCtx) => string | undefined;\n readonly uiState: (cCtx: ComputableCtx) => string | undefined;\n readonly blockMeta: (cCtx: ComputableCtx) => Map<string, Block>;\n};\n\nexport type BlockContextFull = BlockContextArgsOnly & {\n readonly prod: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly staging: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly getResultsPool: (cCtx: ComputableCtx) => ResultPool;\n};\n\nexport type BlockContextAny = Optional<BlockContextFull, 'prod' | 'staging' | 'getResultsPool'>;\n\nexport function constructBlockContextArgsOnly(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextArgsOnly {\n const args = (cCtx: ComputableCtx) =>\n cachedDecode(notEmpty(\n cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'currentArgs'),\n errorIfFieldNotSet: true,\n })\n .getData(),\n ));\n const activeArgs = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'prodArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n const uiState = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'uiState'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n return {\n blockId,\n args,\n activeArgs,\n uiState,\n blockMeta: (cCtx: ComputableCtx) => {\n const prj = cCtx.accessor(projectEntry).node();\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const result = new Map<string, Block>();\n for (const block of allBlocks(structure)) result.set(block.id, block);\n return result;\n },\n };\n}\n\nexport function constructBlockContext(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextFull {\n return {\n ...constructBlockContextArgsOnly(projectEntry, blockId),\n prod: (cCtx: ComputableCtx) => {\n return cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'prodOutput'),\n stableIfNotFound: true,\n ignoreError: true,\n })\n ?.persist();\n },\n staging: (cCtx: ComputableCtx) => {\n const result = cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'stagingOutput'),\n ignoreError: true,\n })\n ?.persist();\n if (result === undefined) cCtx.markUnstable('staging_not_rendered');\n return result;\n },\n getResultsPool: (cCtx: ComputableCtx) => ResultPool.create(cCtx, projectEntry, blockId),\n };\n}\n"],"names":[],"mappings":";;;;;AAoCM,SAAU,6BAA6B,CAC3C,YAAyB,EACzB,OAAe,EAAA;IAEf,MAAM,IAAI,GAAG,CAAC,IAAmB,KAC/B,YAAY,CAAC,QAAQ,CACnB;SACG,QAAQ,CAAC,YAAY;AACrB,SAAA,IAAI;AACJ,SAAA,QAAQ,CAAC;AACR,QAAA,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC;AAC/C,QAAA,kBAAkB,EAAE,IAAI;KACzB;SACA,OAAO,EAAE,CACb,CAAC;AACJ,IAAA,MAAM,UAAU,GAAG,CAAC,IAAmB,KAAI;QACzC,MAAM,IAAI,GAAG;aACV,QAAQ,CAAC,YAAY;AACrB,aAAA,IAAI;AACJ,aAAA,QAAQ,CAAC;AACR,YAAA,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;AAC5C,YAAA,gBAAgB,EAAE,IAAI;SACvB;cACC,OAAO,EAAE;AACb,QAAA,OAAO,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,SAAS;AAC9C,I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gBAAA,WAAW,EAAE,IAAI;aAClB;kBACC,OAAO,EAAE;QACf,CAAC;AACD,QAAA,OAAO,EAAE,CAAC,IAAmB,KAAI;YAC/B,MAAM,MAAM,GAAG;iBACZ,QAAQ,CAAC,YAAY;AACrB,iBAAA,IAAI,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE;AAC1B,iBAAA,QAAQ,CAAC;AACR,gBAAA,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,eAAe,CAAC;AACjD,gBAAA,WAAW,EAAE,IAAI;aAClB;kBACC,OAAO,EAAE;YACb,IAAI,MAAM,KAAK,SAAS;AAAE,gBAAA,IAAI,CAAC,YAAY,CAAC,sBAAsB,CAAC;AACnE,YAAA,OAAO,MAAM;QACf,CAAC;AACD,QAAA,cAAc,EAAE,CAAC,IAAmB,KAAK,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC;KACxF;AACH;;;;"}
1
+ {"version":3,"file":"block_ctx.js","sources":["../../src/middle_layer/block_ctx.ts"],"sourcesContent":["import type { ComputableCtx } from '@milaboratories/computable';\nimport type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport { cachedDecode, notEmpty } from '@milaboratories/ts-helpers';\nimport type { Optional } from 'utility-types';\nimport type {\n Block,\n ProjectStructure } from '../model/project_model';\nimport {\n ProjectStructureKey,\n projectFieldName,\n} from '../model/project_model';\nimport { allBlocks } from '../model/project_model_util';\nimport { ResultPool } from '../pool/result_pool';\nimport { deriveDataFromStorage } from '@platforma-sdk/model';\n\nexport type BlockContextArgsOnly = {\n readonly blockId: string;\n readonly args: (cCtx: ComputableCtx) => string | undefined;\n readonly activeArgs: (cCtx: ComputableCtx) => string | undefined;\n readonly blockMeta: (cCtx: ComputableCtx) => Map<string, Block>;\n readonly data: (cCtx: ComputableCtx) => string | undefined;\n readonly blockStorage: (cCtx: ComputableCtx) => string | undefined;\n readonly prerunArgs: (cCtx: ComputableCtx) => string | undefined;\n};\n\nexport type BlockContextFull = BlockContextArgsOnly & {\n readonly prod: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly staging: (cCtx: ComputableCtx) => PlTreeEntry | undefined;\n readonly getResultsPool: (cCtx: ComputableCtx) => ResultPool;\n};\n\nexport type BlockContextAny = Optional<BlockContextFull, 'prod' | 'staging' | 'getResultsPool'>;\n\nexport function constructBlockContextArgsOnly(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextArgsOnly {\n const args = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'currentArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n const activeArgs = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'prodArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n const data = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'blockStorage'),\n stableIfNotFound: true,\n })\n ?.getData();\n if (!data) return undefined;\n\n const rawJson = cachedDecode(data);\n if (!rawJson) return undefined;\n\n // Parse to check if it's BlockStorage format\n try {\n const parsed = JSON.parse(rawJson);\n return JSON.stringify(deriveDataFromStorage(parsed));\n } catch (err) {\n console.error('Error deriving data from storage', err);\n return undefined;\n }\n };\n // Returns raw blockStorage JSON - UI derives data using sdk/model\n const blockStorage = (cCtx: ComputableCtx) => {\n const storageData = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'blockStorage'),\n stableIfNotFound: true,\n })\n ?.getData();\n if (!storageData) return undefined;\n return cachedDecode(storageData);\n };\n const prerunArgs = (cCtx: ComputableCtx) => {\n const data = cCtx\n .accessor(projectEntry)\n .node()\n .traverse({\n field: projectFieldName(blockId, 'currentPrerunArgs'),\n stableIfNotFound: true,\n })\n ?.getData();\n return data ? cachedDecode(data) : undefined;\n };\n return {\n blockId,\n args,\n activeArgs,\n data,\n blockStorage,\n prerunArgs,\n blockMeta: (cCtx: ComputableCtx) => {\n const prj = cCtx.accessor(projectEntry).node();\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const result = new Map<string, Block>();\n for (const block of allBlocks(structure)) result.set(block.id, block);\n return result;\n },\n };\n}\n\nexport function constructBlockContext(\n projectEntry: PlTreeEntry,\n blockId: string,\n): BlockContextFull {\n return {\n ...constructBlockContextArgsOnly(projectEntry, blockId),\n prod: (cCtx: ComputableCtx) => {\n return cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'prodOutput'),\n stableIfNotFound: true,\n ignoreError: true,\n })\n ?.persist();\n },\n staging: (cCtx: ComputableCtx) => {\n // Check if staging is expected (currentPrerunArgs is set)\n // For blocks with failed args derivation, staging will never be rendered\n const hasPrerunArgs = cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'currentPrerunArgs'),\n stableIfNotFound: true,\n ignoreError: true,\n }) !== undefined;\n\n const result = cCtx\n .accessor(projectEntry)\n .node({ ignoreError: true })\n .traverse({\n field: projectFieldName(blockId, 'stagingOutput'),\n // Only mark stable if staging is NOT expected (no prerunArgs)\n stableIfNotFound: !hasPrerunArgs,\n ignoreError: true,\n })\n ?.persist();\n return result;\n },\n getResultsPool: (cCtx: ComputableCtx) => ResultPool.create(cCtx, projectEntry, blockId),\n };\n}\n"],"names":[],"mappings":";;;;;;AAiCM,SAAU,6BAA6B,CAC3C,YAAyB,EACzB,OAAe,EAAA;AAEf,IAAA,MAAM,IAAI,GAAG,CAAC,IAAmB,KAAI;QACnC,MAAM,IAAI,GAAG;aACV,QAAQ,CAAC,YAAY;AACrB,aAAA,IAAI;AACJ,aAAA,QAAQ,CAAC;AACR,YAAA,KAAK,EAAE,gBAAgB,CAAC,OAA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= ['$prod', '$staging'];
4
4
  function toCfgContext(ctx) {
5
5
  return {
6
6
  $blockId: ctx.blockId,
7
- $args: (cCtx) => JSON.parse(ctx.args(cCtx)),
7
+ $args: (cCtx) => {
8
+ const args = ctx.args(cCtx);
9
+ return args !== undefined ? JSON.parse(args) : undefined;
10
+ },
8
11
  $ui: (cCtx) => {
9
- const uiState = ctx.uiState(cCtx);
10
- return uiState !== undefined ? JSON.parse(uiState) : undefined;
12
+ const data = ctx.data(cCtx);
13
+ return data !== undefined ? JSON.parse(data) : undefined;
14
+ },
15
+ $data: (cCtx) => {
16
+ const data = ctx.data(cCtx);
17
+ return data !== undefined ? JSON.parse(data) : undefined;
11
18
  },
12
19
  $prod: ctx.prod,
13
20
  $staging: ctx.staging,