@milaboratories/pl-middle-layer 1.46.6 → 1.46.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/middle_layer/project.cjs +4 -1
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts.map +1 -1
- package/dist/middle_layer/project.js +4 -1
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/middle_layer/project_overview.cjs +4 -4
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.js +4 -4
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/dist/model/project_helper.cjs +7 -29
- package/dist/model/project_helper.cjs.map +1 -1
- package/dist/model/project_helper.d.ts +6 -25
- package/dist/model/project_helper.d.ts.map +1 -1
- package/dist/model/project_helper.js +7 -29
- package/dist/model/project_helper.js.map +1 -1
- package/package.json +15 -15
- package/src/middle_layer/project.ts +4 -1
- package/src/middle_layer/project_overview.ts +4 -4
- package/src/model/project_helper.ts +10 -44
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_helper.js","sources":["../../src/model/project_helper.ts"],"sourcesContent":["import type { ResultOrError, BlockConfig, PlRef, ConfigRenderLambda } from '@platforma-sdk/model';\nimport { extractCodeWithInfo, ensureError } from '@platforma-sdk/model';\nimport { LRUCache } from 'lru-cache';\nimport type { QuickJSWASMModule } from 'quickjs-emscripten';\nimport { executeSingleLambda } from '../js_render';\nimport type { ResourceId } from '@milaboratories/pl-client';\n\ntype EnrichmentTargetsRequest = {\n blockConfig: () => BlockConfig;\n args: () => unknown;\n};\n\ntype EnrichmentTargetsValue = {\n value: PlRef[] | undefined;\n};\n\n/**\n * Result of VM-based storage normalization\n */\ninterface NormalizeStorageResult {\n storage: unknown;\n data: unknown;\n}\n\n/**\n * Result of VM-based storage migration.\n * Returned by migrateStorageInVM().\n *\n * - Error result: { error: string } - serious failure (no context, etc.)\n * - Success result: { newStorageJson: string, info: string, warn?: string } - migration succeeded or reset to initial\n */\nexport type MigrationResult =\n | { error: string }\n | { error?: undefined; newStorageJson: string; info: string; warn?: string };\n\n// Internal lambda handles for storage operations (registered by SDK's block_storage_vm.ts)\n// All callbacks are prefixed with `__pl_` to indicate internal SDK use\nconst STORAGE_NORMALIZE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_normalize' };\nconst STORAGE_APPLY_UPDATE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_applyUpdate' };\nconst STORAGE_GET_INFO_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_getInfo' };\nconst STORAGE_MIGRATE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_migrate' };\nconst ARGS_DERIVE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_args_derive' };\nconst PRERUN_ARGS_DERIVE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_prerunArgs_derive' };\n// Registered by DataModel.registerCallbacks()\nconst INITIAL_STORAGE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_initial' };\n\n/**\n * Result of args derivation from storage.\n * Returned by __pl_args_derive and __pl_prerunArgs_derive VM callbacks.\n */\ntype ArgsDeriveResult =\n | { error: string }\n | { error?: undefined; value: unknown };\n\nexport class ProjectHelper {\n private readonly enrichmentTargetsCache = new LRUCache<string, EnrichmentTargetsValue, EnrichmentTargetsRequest>({\n max: 256,\n memoMethod: (_key, _value, { context }) => {\n return { value: this.calculateEnrichmentTargets(context) };\n },\n });\n\n constructor(private readonly quickJs: QuickJSWASMModule) {}\n\n // =============================================================================\n // Args Derivation from Storage (V3+)\n // =============================================================================\n\n /**\n * Derives args directly from storage JSON using VM callback.\n * The VM extracts data from storage and calls the block's args() function.\n *\n * This allows the middle layer to work only with storage JSON,\n * without needing to know the underlying data structure.\n *\n * @param blockConfig The block configuration (provides the model code)\n * @param storageJson Storage as JSON string\n * @returns The derived args object, or error if derivation fails\n */\n public deriveArgsFromStorage(blockConfig: BlockConfig, storageJson: string): ResultOrError<unknown> {\n if (blockConfig.modelAPIVersion !== 2) {\n return { error: new Error('deriveArgsFromStorage is only supported for model API version 2') };\n }\n\n try {\n const result = executeSingleLambda(\n this.quickJs,\n ARGS_DERIVE_HANDLE,\n extractCodeWithInfo(blockConfig),\n storageJson,\n ) as ArgsDeriveResult;\n\n if (result.error !== undefined) {\n return { error: new Error(result.error) };\n }\n return { value: result.value };\n } catch (e) {\n return { error: new Error('Args derivation from storage failed', { cause: ensureError(e) }) };\n }\n }\n\n /**\n * Derives prerunArgs directly from storage JSON using VM callback.\n * Falls back to args() if prerunArgs is not defined in the block model.\n *\n * @param blockConfig The block configuration (provides the model code)\n * @param storageJson Storage as JSON string\n * @returns The derived prerunArgs, or undefined if derivation fails\n */\n public derivePrerunArgsFromStorage(blockConfig: BlockConfig, storageJson: string): unknown {\n if (blockConfig.modelAPIVersion !== 2) {\n throw new Error('derivePrerunArgsFromStorage is only supported for model API version 2');\n }\n\n try {\n const result = executeSingleLambda(\n this.quickJs,\n PRERUN_ARGS_DERIVE_HANDLE,\n extractCodeWithInfo(blockConfig),\n storageJson,\n ) as ArgsDeriveResult;\n\n if (result.error !== undefined) {\n // Return undefined if derivation fails (skip block in staging)\n return undefined;\n }\n return result.value;\n } catch {\n // Return undefined if derivation fails (skip block in staging)\n return undefined;\n }\n }\n\n private calculateEnrichmentTargets(req: EnrichmentTargetsRequest): PlRef[] | undefined {\n const blockConfig = req.blockConfig();\n if (blockConfig.enrichmentTargets === undefined) return undefined;\n const args = req.args();\n const result = executeSingleLambda(this.quickJs, blockConfig.enrichmentTargets, extractCodeWithInfo(blockConfig), args) as PlRef[];\n return result;\n }\n\n public getEnrichmentTargets(blockConfig: () => BlockConfig, args: () => unknown, key?: { argsRid: ResourceId; blockPackRid: ResourceId }): PlRef[] | undefined {\n const req = { blockConfig, args };\n if (key === undefined)\n return this.calculateEnrichmentTargets(req);\n const cacheKey = `${key.argsRid}:${key.blockPackRid}`;\n return this.enrichmentTargetsCache.memo(cacheKey, { context: req }).value;\n }\n\n // =============================================================================\n // VM-based Storage Operations\n // =============================================================================\n\n /**\n * Normalizes raw blockStorage data using VM-based transformation.\n * This calls the model's `__pl_storage_normalize` callback which:\n * - Handles BlockStorage format (with discriminator)\n * - Handles legacy V1/V2 format ({ args, uiState })\n * - Handles raw V3 state\n *\n * @param blockConfig The block configuration (provides the model code)\n * @param rawStorage Raw storage data from resource tree (may be JSON string or object)\n * @returns Object with { storage, state } or undefined if transformation fails\n */\n public normalizeStorageInVM(blockConfig: BlockConfig, rawStorage: unknown): NormalizeStorageResult | undefined {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n STORAGE_NORMALIZE_HANDLE,\n extractCodeWithInfo(blockConfig),\n rawStorage,\n ) as NormalizeStorageResult;\n return result;\n } catch (e) {\n console.warn('[ProjectHelper.normalizeStorageInVM] Storage normalization failed:', e);\n return undefined;\n }\n }\n\n /**\n * Creates initial BlockStorage for a new block using VM-based transformation.\n * This calls the '__pl_storage_initial' callback registered by DataModel which:\n * - Gets initial data from DataModel.getDefaultData()\n * - Creates BlockStorage with correct version\n *\n * @param blockConfig The block configuration (provides the model code)\n * @returns Initial storage as JSON string\n * @throws Error if storage creation fails\n */\n public getInitialStorageInVM(blockConfig: BlockConfig): string {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n INITIAL_STORAGE_HANDLE,\n extractCodeWithInfo(blockConfig),\n ) as string;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.getInitialStorageInVM] Initial storage creation failed:', e);\n throw new Error(`Block initial storage creation failed: ${e}`);\n }\n }\n\n /**\n * Applies a state update using VM-based transformation.\n * This calls the model's `__pl_storage_applyUpdate` callback which:\n * - Normalizes current storage\n * - Updates state while preserving other fields (version, plugins)\n * - Returns the updated storage as JSON string\n *\n * @param blockConfig The block configuration (provides the model code)\n * @param currentStorageJson Current storage as JSON string (must be defined)\n * @param newState New state from developer\n * @returns Updated storage as JSON string\n * @throws Error if storage update fails\n */\n public applyStorageUpdateInVM(blockConfig: BlockConfig, currentStorageJson: string, payload: { operation: string; value: unknown }): string {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n STORAGE_APPLY_UPDATE_HANDLE,\n extractCodeWithInfo(blockConfig),\n currentStorageJson,\n payload,\n ) as string;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.applyStorageUpdateInVM] Storage update failed:', e);\n throw new Error(`Block storage update failed: ${e}`);\n }\n }\n\n /**\n * Gets storage info from raw storage data by calling the VM's __pl_storage_getInfo callback.\n * Returns structured info about the storage (e.g., dataVersion).\n *\n * @param blockConfig Block configuration\n * @param rawStorageJson Raw storage as JSON string (or undefined)\n * @returns Storage info as JSON string (e.g., '{\"dataVersion\": 1}')\n */\n public getStorageInfoInVM(blockConfig: BlockConfig, rawStorageJson: string | undefined): string | undefined {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n STORAGE_GET_INFO_HANDLE,\n extractCodeWithInfo(blockConfig),\n rawStorageJson,\n ) as string;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.getStorageInfoInVM] Get storage info failed:', e);\n return undefined;\n }\n }\n\n // =============================================================================\n // Block State Migrations\n // =============================================================================\n\n /**\n * Runs block state migrations via VM-based transformation.\n * This calls the model's `__pl_storage_migrate` callback which:\n * - Normalizes current storage to get state and version\n * - Calculates target version from number of registered migrations\n * - Runs all necessary migrations sequentially\n * - Returns new storage with updated state and version\n *\n * The middle layer doesn't need to know about dataVersion or storage internals.\n * All migration logic is encapsulated in the model.\n *\n * @param blockConfig The NEW block configuration (provides the model code with migrations)\n * @param currentStorageJson Current storage as JSON string (or undefined)\n * @returns MigrationResult with new storage or skip/error info\n */\n public migrateStorageInVM(blockConfig: BlockConfig, currentStorageJson: string | undefined): MigrationResult {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n STORAGE_MIGRATE_HANDLE,\n extractCodeWithInfo(blockConfig),\n currentStorageJson,\n ) as MigrationResult;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.migrateStorageInVM] Migration failed:', e);\n return { error: `VM execution failed: ${e}` };\n }\n }\n}\n"],"names":[],"mappings":";;;;AAmCA;AACA;AACA,MAAM,wBAAwB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,wBAAwB,EAAE;AAC/G,MAAM,2BAA2B,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,0BAA0B,EAAE;AACpH,MAAM,uBAAuB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE;AAC5G,MAAM,sBAAsB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE;AAC3G,MAAM,kBAAkB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE;AACnG,MAAM,yBAAyB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,wBAAwB,EAAE;AAChH;AACA,MAAM,sBAAsB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE;MAU9F,aAAa,CAAA;AAQK,IAAA,OAAA;IAPZ,sBAAsB,GAAG,IAAI,QAAQ,CAA2D;AAC/G,QAAA,GAAG,EAAE,GAAG;QACR,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,KAAI;YACxC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE;QAC5D,CAAC;AACF,KAAA,CAAC;AAEF,IAAA,WAAA,CAA6B,OAA0B,EAAA;QAA1B,IAAA,CAAA,OAAO,GAAP,OAAO;IAAsB;;;;AAM1D;;;;;;;;;;AAUG;IACI,qBAAqB,CAAC,WAAwB,EAAE,WAAmB,EAAA;AACxE,QAAA,IAAI,WAAW,CAAC,eAAe,KAAK,CAAC,EAAE;YACrC,OAAO,EA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,OAAO,MAAM;QACf;QAAE,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE,CAAC,CAAC;AACxE,YAAA,OAAO,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAA,CAAE,EAAE;QAC/C;IACF;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"project_helper.js","sources":["../../src/model/project_helper.ts"],"sourcesContent":["import type { ResultOrError, BlockConfig, PlRef, ConfigRenderLambda, StorageDebugView } from '@platforma-sdk/model';\nimport type { StringifiedJson } from '@milaboratories/pl-model-common';\nimport { extractCodeWithInfo, ensureError } from '@platforma-sdk/model';\nimport { LRUCache } from 'lru-cache';\nimport type { QuickJSWASMModule } from 'quickjs-emscripten';\nimport { executeSingleLambda } from '../js_render';\nimport type { ResourceId } from '@milaboratories/pl-client';\n\ntype EnrichmentTargetsRequest = {\n blockConfig: () => BlockConfig;\n args: () => unknown;\n};\n\ntype EnrichmentTargetsValue = {\n value: PlRef[] | undefined;\n};\n\n/**\n * Result of VM-based storage migration.\n * Returned by migrateStorageInVM().\n *\n * - Error result: { error: string } - serious failure (no context, etc.)\n * - Success result: { newStorageJson: string, info: string, warn?: string } - migration succeeded or reset to initial\n */\nexport type MigrationResult =\n | { error: string }\n | { error?: undefined; newStorageJson: string; info: string; warn?: string };\n\n// Internal lambda handles for storage operations (registered by SDK's block_storage_vm.ts)\n// All callbacks are prefixed with `__pl_` to indicate internal SDK use\nconst STORAGE_APPLY_UPDATE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_applyUpdate' };\nconst STORAGE_DEBUG_VIEW_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_debugView' };\nconst STORAGE_MIGRATE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_migrate' };\nconst ARGS_DERIVE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_args_derive' };\nconst PRERUN_ARGS_DERIVE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_prerunArgs_derive' };\n// Registered by DataModel.registerCallbacks()\nconst INITIAL_STORAGE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_initial' };\n\n/**\n * Result of args derivation from storage.\n * Returned by __pl_args_derive and __pl_prerunArgs_derive VM callbacks.\n */\ntype ArgsDeriveResult =\n | { error: string }\n | { error?: undefined; value: unknown };\n\nexport class ProjectHelper {\n private readonly enrichmentTargetsCache = new LRUCache<string, EnrichmentTargetsValue, EnrichmentTargetsRequest>({\n max: 256,\n memoMethod: (_key, _value, { context }) => {\n return { value: this.calculateEnrichmentTargets(context) };\n },\n });\n\n constructor(private readonly quickJs: QuickJSWASMModule) {}\n\n // =============================================================================\n // Args Derivation from Storage (V3+)\n // =============================================================================\n\n /**\n * Derives args directly from storage JSON using VM callback.\n * The VM extracts data from storage and calls the block's args() function.\n *\n * This allows the middle layer to work only with storage JSON,\n * without needing to know the underlying data structure.\n *\n * @param blockConfig The block configuration (provides the model code)\n * @param storageJson Storage as JSON string\n * @returns The derived args object, or error if derivation fails\n */\n public deriveArgsFromStorage(blockConfig: BlockConfig, storageJson: string): ResultOrError<unknown> {\n if (blockConfig.modelAPIVersion !== 2) {\n return { error: new Error('deriveArgsFromStorage is only supported for model API version 2') };\n }\n\n try {\n const result = executeSingleLambda(\n this.quickJs,\n ARGS_DERIVE_HANDLE,\n extractCodeWithInfo(blockConfig),\n storageJson,\n ) as ArgsDeriveResult;\n\n if (result.error !== undefined) {\n return { error: new Error(result.error) };\n }\n return { value: result.value };\n } catch (e) {\n return { error: new Error('Args derivation from storage failed', { cause: ensureError(e) }) };\n }\n }\n\n /**\n * Derives prerunArgs directly from storage JSON using VM callback.\n * Falls back to args() if prerunArgs is not defined in the block model.\n *\n * @param blockConfig The block configuration (provides the model code)\n * @param storageJson Storage as JSON string\n * @returns The derived prerunArgs, or undefined if derivation fails\n */\n public derivePrerunArgsFromStorage(blockConfig: BlockConfig, storageJson: string): unknown {\n if (blockConfig.modelAPIVersion !== 2) {\n throw new Error('derivePrerunArgsFromStorage is only supported for model API version 2');\n }\n\n try {\n const result = executeSingleLambda(\n this.quickJs,\n PRERUN_ARGS_DERIVE_HANDLE,\n extractCodeWithInfo(blockConfig),\n storageJson,\n ) as ArgsDeriveResult;\n\n if (result.error !== undefined) {\n // Return undefined if derivation fails (skip block in staging)\n return undefined;\n }\n return result.value;\n } catch {\n // Return undefined if derivation fails (skip block in staging)\n return undefined;\n }\n }\n\n private calculateEnrichmentTargets(req: EnrichmentTargetsRequest): PlRef[] | undefined {\n const blockConfig = req.blockConfig();\n if (blockConfig.enrichmentTargets === undefined) return undefined;\n const args = req.args();\n const result = executeSingleLambda(this.quickJs, blockConfig.enrichmentTargets, extractCodeWithInfo(blockConfig), args) as PlRef[];\n return result;\n }\n\n public getEnrichmentTargets(blockConfig: () => BlockConfig, args: () => unknown, key?: { argsRid: ResourceId; blockPackRid: ResourceId }): PlRef[] | undefined {\n const req = { blockConfig, args };\n if (key === undefined)\n return this.calculateEnrichmentTargets(req);\n const cacheKey = `${key.argsRid}:${key.blockPackRid}`;\n return this.enrichmentTargetsCache.memo(cacheKey, { context: req }).value;\n }\n\n // =============================================================================\n // VM-based Storage Operations\n // =============================================================================\n\n /**\n * Creates initial BlockStorage for a new block using VM-based transformation.\n * This calls the '__pl_storage_initial' callback registered by DataModel which:\n * - Gets initial data from DataModel.getDefaultData()\n * - Creates BlockStorage with correct version\n *\n * @param blockConfig The block configuration (provides the model code)\n * @returns Initial storage as JSON string\n * @throws Error if storage creation fails\n */\n public getInitialStorageInVM(blockConfig: BlockConfig): string {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n INITIAL_STORAGE_HANDLE,\n extractCodeWithInfo(blockConfig),\n ) as string;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.getInitialStorageInVM] Initial storage creation failed:', e);\n throw new Error(`Block initial storage creation failed: ${e}`);\n }\n }\n\n /**\n * Applies a state update using VM-based transformation.\n * This calls the model's `__pl_storage_applyUpdate` callback which:\n * - Normalizes current storage\n * - Updates state while preserving other fields (version, plugins)\n * - Returns the updated storage as JSON string\n *\n * @param blockConfig The block configuration (provides the model code)\n * @param currentStorageJson Current storage as JSON string (must be defined)\n * @param newState New state from developer\n * @returns Updated storage as JSON string\n * @throws Error if storage update fails\n */\n public applyStorageUpdateInVM(blockConfig: BlockConfig, currentStorageJson: string, payload: { operation: string; value: unknown }): string {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n STORAGE_APPLY_UPDATE_HANDLE,\n extractCodeWithInfo(blockConfig),\n currentStorageJson,\n payload,\n ) as string;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.applyStorageUpdateInVM] Storage update failed:', e);\n throw new Error(`Block storage update failed: ${e}`);\n }\n }\n\n /**\n * Gets storage debug view from raw storage data by calling the VM's __pl_storage_debugView callback.\n * Returns structured debug info about the storage (e.g., dataVersion).\n *\n * @param blockConfig Block configuration\n * @param rawStorageJson Raw storage as JSON string (or undefined)\n * @returns Storage debug view as JSON string (e.g., '{\"dataVersion\": 1}')\n */\n public getStorageDebugViewInVM(blockConfig: BlockConfig, rawStorageJson: string | undefined): StringifiedJson<StorageDebugView> | undefined {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n STORAGE_DEBUG_VIEW_HANDLE,\n extractCodeWithInfo(blockConfig),\n rawStorageJson,\n ) as StringifiedJson<StorageDebugView>;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.getStorageDebugViewInVM] Get storage debug view failed:', e);\n return undefined;\n }\n }\n\n // =============================================================================\n // Block State Migrations\n // =============================================================================\n\n /**\n * Runs block state migrations via VM-based transformation.\n * This calls the model's `__pl_storage_migrate` callback which:\n * - Normalizes current storage to get state and version\n * - Calculates target version from number of registered migrations\n * - Runs all necessary migrations sequentially\n * - Returns new storage with updated state and version\n *\n * The middle layer doesn't need to know about dataVersion or storage internals.\n * All migration logic is encapsulated in the model.\n *\n * @param blockConfig The NEW block configuration (provides the model code with migrations)\n * @param currentStorageJson Current storage as JSON string (or undefined)\n * @returns MigrationResult with new storage or skip/error info\n */\n public migrateStorageInVM(blockConfig: BlockConfig, currentStorageJson: string | undefined): MigrationResult {\n try {\n const result = executeSingleLambda(\n this.quickJs,\n STORAGE_MIGRATE_HANDLE,\n extractCodeWithInfo(blockConfig),\n currentStorageJson,\n ) as MigrationResult;\n return result;\n } catch (e) {\n console.error('[ProjectHelper.migrateStorageInVM] Migration failed:', e);\n return { error: `VM execution failed: ${e}` };\n }\n }\n}\n"],"names":[],"mappings":";;;;AA4BA;AACA;AACA,MAAM,2BAA2B,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,0BAA0B,EAAE;AACpH,MAAM,yBAAyB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,wBAAwB,EAAE;AAChH,MAAM,sBAAsB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE;AAC3G,MAAM,kBAAkB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE;AACnG,MAAM,yBAAyB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,wBAAwB,EAAE;AAChH;AACA,MAAM,sBAAsB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE;MAU9F,aAAa,CAAA;AAQK,IAAA,OAAA;IAPZ,sBAAsB,GAAG,IAAI,QAAQ,CAA2D;AAC/G,QAAA,GAAG,EAAE,GAAG;QACR,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,KAAI;YACxC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE;QAC5D,CAAC;AACF,KAAA,CAAC;AAEF,IAAA,WAAA,CAA6B,OAA0B,EAAA;QAA1B,IAAA,CAAA,OAAO,GAAP,OAAO;IAAs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@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-middle-layer",
|
|
3
|
-
"version": "1.46.
|
|
3
|
+
"version": "1.46.8",
|
|
4
4
|
"description": "Pl Middle Layer",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.19.0"
|
|
@@ -33,22 +33,22 @@
|
|
|
33
33
|
"zod": "~3.23.8",
|
|
34
34
|
"remeda": "^2.28.0",
|
|
35
35
|
"@milaboratories/pl-http": "1.2.0",
|
|
36
|
-
"@milaboratories/computable": "2.8.2",
|
|
37
36
|
"@milaboratories/resolve-helper": "1.1.1",
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@milaboratories/pl-
|
|
41
|
-
"@milaboratories/pl-
|
|
42
|
-
"@milaboratories/pl-
|
|
43
|
-
"@milaboratories/pl-
|
|
44
|
-
"@
|
|
45
|
-
"@milaboratories/pl-
|
|
37
|
+
"@milaboratories/computable": "2.8.2",
|
|
38
|
+
"@platforma-sdk/block-tools": "2.6.33",
|
|
39
|
+
"@milaboratories/pl-drivers": "1.11.42",
|
|
40
|
+
"@milaboratories/pl-client": "2.16.24",
|
|
41
|
+
"@milaboratories/pl-model-backend": "1.1.41",
|
|
42
|
+
"@milaboratories/pl-tree": "1.8.32",
|
|
43
|
+
"@milaboratories/pl-model-common": "1.24.1",
|
|
44
|
+
"@milaboratories/pl-model-middle-layer": "1.10.2",
|
|
46
45
|
"@milaboratories/ts-helpers": "1.7.0",
|
|
46
|
+
"@platforma-sdk/model": "1.53.0",
|
|
47
|
+
"@milaboratories/pl-errors": "1.1.56",
|
|
47
48
|
"@platforma-sdk/workflow-tengo": "5.8.1",
|
|
48
|
-
"@milaboratories/pl-errors": "1.1.55",
|
|
49
49
|
"@milaboratories/pl-config": "1.7.11",
|
|
50
|
-
"@milaboratories/pl-deployments": "2.15.
|
|
51
|
-
"@milaboratories/pf-driver": "1.0.
|
|
50
|
+
"@milaboratories/pl-deployments": "2.15.5",
|
|
51
|
+
"@milaboratories/pf-driver": "1.0.28"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"semver": "^7.7.2",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"@types/node": "~24.5.2",
|
|
61
61
|
"tslib": "~2.7.0",
|
|
62
62
|
"@milaboratories/build-configs": "1.4.0",
|
|
63
|
+
"@milaboratories/ts-configs": "1.2.0",
|
|
63
64
|
"@milaboratories/eslint-config": "1.0.5",
|
|
64
|
-
"@milaboratories/ts-builder": "1.2.4"
|
|
65
|
-
"@milaboratories/ts-configs": "1.2.0"
|
|
65
|
+
"@milaboratories/ts-builder": "1.2.4"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"type-check": "ts-builder types --target node",
|
|
@@ -477,7 +477,9 @@ export class Project {
|
|
|
477
477
|
},
|
|
478
478
|
{
|
|
479
479
|
postprocessValue: (v) => {
|
|
480
|
-
const
|
|
480
|
+
const blockOverview = v.overview?.blocks?.find((b) => b.id == blockId);
|
|
481
|
+
const sdkVersion = blockOverview?.sdkVersion;
|
|
482
|
+
const storageDebugView = blockOverview?.storageDebugView;
|
|
481
483
|
const toString = sdkVersion && shouldStillUseStringErrors(sdkVersion);
|
|
482
484
|
const newOutputs = toString && v.outputs !== undefined
|
|
483
485
|
? convertErrorsToStrings(v.outputs)
|
|
@@ -487,6 +489,7 @@ export class Project {
|
|
|
487
489
|
...v.parameters,
|
|
488
490
|
outputs: newOutputs,
|
|
489
491
|
navigationState: v.navigationState,
|
|
492
|
+
storageDebugView,
|
|
490
493
|
} as BlockStateInternalV3;
|
|
491
494
|
},
|
|
492
495
|
},
|
|
@@ -271,8 +271,8 @@ export function projectOverview(
|
|
|
271
271
|
})
|
|
272
272
|
.getDataAsJson() as BlockSettings;
|
|
273
273
|
|
|
274
|
-
// Get block storage
|
|
275
|
-
const
|
|
274
|
+
// Get block storage debug view by calling VM function (only for Model API v2 blocks)
|
|
275
|
+
const storageDebugView = ifNotUndef(bp, ({ cfg }) => {
|
|
276
276
|
if (cfg.modelAPIVersion !== 2) {
|
|
277
277
|
return undefined;
|
|
278
278
|
}
|
|
@@ -282,7 +282,7 @@ export function projectOverview(
|
|
|
282
282
|
stableIfNotFound: true,
|
|
283
283
|
});
|
|
284
284
|
const rawStorageJson = storageNode?.getDataAsString();
|
|
285
|
-
return env.projectHelper.
|
|
285
|
+
return env.projectHelper.getStorageDebugViewInVM(cfg, rawStorageJson);
|
|
286
286
|
});
|
|
287
287
|
|
|
288
288
|
const updates = ifNotUndef(bp, ({ info }) =>
|
|
@@ -315,7 +315,7 @@ export function projectOverview(
|
|
|
315
315
|
featureFlags,
|
|
316
316
|
isIncompatibleWithRuntime,
|
|
317
317
|
navigationState: navigationStates.getState(id),
|
|
318
|
-
|
|
318
|
+
storageDebugView,
|
|
319
319
|
};
|
|
320
320
|
});
|
|
321
321
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ResultOrError, BlockConfig, PlRef, ConfigRenderLambda } from '@platforma-sdk/model';
|
|
1
|
+
import type { ResultOrError, BlockConfig, PlRef, ConfigRenderLambda, StorageDebugView } from '@platforma-sdk/model';
|
|
2
|
+
import type { StringifiedJson } from '@milaboratories/pl-model-common';
|
|
2
3
|
import { extractCodeWithInfo, ensureError } from '@platforma-sdk/model';
|
|
3
4
|
import { LRUCache } from 'lru-cache';
|
|
4
5
|
import type { QuickJSWASMModule } from 'quickjs-emscripten';
|
|
@@ -14,14 +15,6 @@ type EnrichmentTargetsValue = {
|
|
|
14
15
|
value: PlRef[] | undefined;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
* Result of VM-based storage normalization
|
|
19
|
-
*/
|
|
20
|
-
interface NormalizeStorageResult {
|
|
21
|
-
storage: unknown;
|
|
22
|
-
data: unknown;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
18
|
/**
|
|
26
19
|
* Result of VM-based storage migration.
|
|
27
20
|
* Returned by migrateStorageInVM().
|
|
@@ -35,9 +28,8 @@ export type MigrationResult =
|
|
|
35
28
|
|
|
36
29
|
// Internal lambda handles for storage operations (registered by SDK's block_storage_vm.ts)
|
|
37
30
|
// All callbacks are prefixed with `__pl_` to indicate internal SDK use
|
|
38
|
-
const STORAGE_NORMALIZE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_normalize' };
|
|
39
31
|
const STORAGE_APPLY_UPDATE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_applyUpdate' };
|
|
40
|
-
const
|
|
32
|
+
const STORAGE_DEBUG_VIEW_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_debugView' };
|
|
41
33
|
const STORAGE_MIGRATE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_storage_migrate' };
|
|
42
34
|
const ARGS_DERIVE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_args_derive' };
|
|
43
35
|
const PRERUN_ARGS_DERIVE_HANDLE: ConfigRenderLambda = { __renderLambda: true, handle: '__pl_prerunArgs_derive' };
|
|
@@ -151,32 +143,6 @@ export class ProjectHelper {
|
|
|
151
143
|
// VM-based Storage Operations
|
|
152
144
|
// =============================================================================
|
|
153
145
|
|
|
154
|
-
/**
|
|
155
|
-
* Normalizes raw blockStorage data using VM-based transformation.
|
|
156
|
-
* This calls the model's `__pl_storage_normalize` callback which:
|
|
157
|
-
* - Handles BlockStorage format (with discriminator)
|
|
158
|
-
* - Handles legacy V1/V2 format ({ args, uiState })
|
|
159
|
-
* - Handles raw V3 state
|
|
160
|
-
*
|
|
161
|
-
* @param blockConfig The block configuration (provides the model code)
|
|
162
|
-
* @param rawStorage Raw storage data from resource tree (may be JSON string or object)
|
|
163
|
-
* @returns Object with { storage, state } or undefined if transformation fails
|
|
164
|
-
*/
|
|
165
|
-
public normalizeStorageInVM(blockConfig: BlockConfig, rawStorage: unknown): NormalizeStorageResult | undefined {
|
|
166
|
-
try {
|
|
167
|
-
const result = executeSingleLambda(
|
|
168
|
-
this.quickJs,
|
|
169
|
-
STORAGE_NORMALIZE_HANDLE,
|
|
170
|
-
extractCodeWithInfo(blockConfig),
|
|
171
|
-
rawStorage,
|
|
172
|
-
) as NormalizeStorageResult;
|
|
173
|
-
return result;
|
|
174
|
-
} catch (e) {
|
|
175
|
-
console.warn('[ProjectHelper.normalizeStorageInVM] Storage normalization failed:', e);
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
146
|
/**
|
|
181
147
|
* Creates initial BlockStorage for a new block using VM-based transformation.
|
|
182
148
|
* This calls the '__pl_storage_initial' callback registered by DataModel which:
|
|
@@ -231,24 +197,24 @@ export class ProjectHelper {
|
|
|
231
197
|
}
|
|
232
198
|
|
|
233
199
|
/**
|
|
234
|
-
* Gets storage
|
|
235
|
-
* Returns structured info about the storage (e.g., dataVersion).
|
|
200
|
+
* Gets storage debug view from raw storage data by calling the VM's __pl_storage_debugView callback.
|
|
201
|
+
* Returns structured debug info about the storage (e.g., dataVersion).
|
|
236
202
|
*
|
|
237
203
|
* @param blockConfig Block configuration
|
|
238
204
|
* @param rawStorageJson Raw storage as JSON string (or undefined)
|
|
239
|
-
* @returns Storage
|
|
205
|
+
* @returns Storage debug view as JSON string (e.g., '{"dataVersion": 1}')
|
|
240
206
|
*/
|
|
241
|
-
public
|
|
207
|
+
public getStorageDebugViewInVM(blockConfig: BlockConfig, rawStorageJson: string | undefined): StringifiedJson<StorageDebugView> | undefined {
|
|
242
208
|
try {
|
|
243
209
|
const result = executeSingleLambda(
|
|
244
210
|
this.quickJs,
|
|
245
|
-
|
|
211
|
+
STORAGE_DEBUG_VIEW_HANDLE,
|
|
246
212
|
extractCodeWithInfo(blockConfig),
|
|
247
213
|
rawStorageJson,
|
|
248
|
-
) as
|
|
214
|
+
) as StringifiedJson<StorageDebugView>;
|
|
249
215
|
return result;
|
|
250
216
|
} catch (e) {
|
|
251
|
-
console.error('[ProjectHelper.
|
|
217
|
+
console.error('[ProjectHelper.getStorageDebugViewInVM] Get storage debug view failed:', e);
|
|
252
218
|
return undefined;
|
|
253
219
|
}
|
|
254
220
|
}
|