@milaboratories/pl-middle-layer 1.46.6 → 1.46.7
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 +8 -8
- 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_overview.cjs","sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport type { ComputableStableDefined } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport type {\n ProjectRenderingState,\n ProjectStructure } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from '../model/project_model';\nimport { notEmpty } from '@milaboratories/ts-helpers';\nimport { allBlocks, productionGraph } from '../model/project_model_util';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from '@milaboratories/pl-model-middle-layer';\nimport { constructBlockContext, constructBlockContextArgsOnly } from './block_ctx';\nimport { ifNotUndef } from '../cfg_render/util';\nimport { type BlockSection } from '@platforma-sdk/model';\nimport { extractCodeWithInfo, wrapCallback } from '@platforma-sdk/model';\nimport { computableFromCfgOrRF } from './render';\nimport type { NavigationStates } from './navigation_states';\nimport { getBlockPackInfo } from './util';\nimport { resourceIdToString, type ResourceId } from '@milaboratories/pl-client';\nimport * as R from 'remeda';\n\ntype BlockInfo = {\n argsRid?: ResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(a: Record<string, unknown> | undefined, b: Record<string, unknown> | undefined): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const clean = R.omitBy<Record<string, unknown>>((_, key) => key.startsWith('__'));\n return R.isDeepEqual(clean(a), clean(b));\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, 'currentArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, 'prodArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, 'prodOutput'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, 'prodUiCtx'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined\n || ctx.error !== undefined\n || result.value?.getError() !== undefined\n || ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError())\n || (result.error !== undefined && result.error.getIsReadyOrError()))\n && ((ctx.value !== undefined && ctx.value.getIsReadyOrError())\n || (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = 'NotCalculated';\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = 'Limbo';\n else calculationStatus = info.prod.finished ? 'Done' : 'Running';\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const { sections, title, subtitle, tags, inputsValid, sdkVersion, featureFlags, isIncompatibleWithRuntime }\n = ifNotUndef(bp, ({ bpId, cfg }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model sections', { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model title', { cause }));\n return 'Invalid title';\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n subtitle,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model subtitle', { cause }));\n return 'Invalid subtitle';\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model tags', { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // For older blocks, use the inputsValid callback from config\n inputsValid: cfg.modelAPIVersion === 2\n ? info.currentArguments !== undefined\n : cfg.inputsValid\n ? computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model inputsValid', { cause }));\n return false;\n },\n }) as ComputableStableDefined<boolean>\n : undefined,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, 'blockSettings'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n // Get block storage info by calling VM function (only for Model API v2 blocks)\n const blockStorageInfo = ifNotUndef(bp, ({ cfg }) => {\n if (cfg.modelAPIVersion !== 2) {\n return undefined;\n }\n const storageNode = prj.traverse({\n field: projectFieldName(id, 'blockStorage'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const rawStorageJson = storageNode?.getDataAsString();\n return env.projectHelper.getStorageInfoInVM(cfg, rawStorageJson);\n });\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === 'Limbo',\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots('upstream', id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots('downstream', id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n blockStorageInfo,\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return {\n ...value,\n blocks: value.blocks.map((b) => {\n if (!b.inputsValid) cantRun.add(b.id);\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.findIndex((u) => staleBlocks.has(u)) !== -1;\n const canRun\n = (stale || b.outputErrors)\n && Boolean(b.inputsValid)\n && !b.missingReference\n && b.upstreams.findIndex((u) => cantRun.has(u)) === -1;\n const bb = {\n ...b,\n canRun,\n stale,\n updateSuggestions: b.updates?.suggestions ?? [],\n updatedBlockPack: b.updates?.mainSuggestion,\n };\n delete bb['updates'];\n return bb;\n }),\n };\n },\n },\n ).withStableType();\n}\n"],"names":["R","Computable","notEmpty","ProjectCreatedTimestamp","ProjectLastModifiedTimestamp","ProjectMetaKey","ProjectStructureKey","BlockRenderingStateKey","allBlocks","projectFieldName","productionGraph","getBlockPackInfo","ifNotUndef","constructBlockContext","constructBlockContextArgsOnly","wrapCallback","extractCodeWithInfo","computableFromCfgOrRF","resourceIdToString","ProjectStructureAuthorKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAS,UAAU,CAAC,CAAsC,EAAE,CAAsC,EAAA;IAChG,IAAI,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;AACxB,IAAA,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;IACpD,MAAM,KAAK,GAAGA,YAAC,C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G,CAAC,CAAC,CAAC,EAAE,CAAC;oBACrC,IAAI,CAAC,CAAC,KAAK;AAAE,wBAAA,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;oBAClC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;oBAChF,MAAM,MAAM,GACR,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY;AACvB,2BAAA,OAAO,CAAC,CAAC,CAAC,WAAW;2BACrB,CAAC,CAAC,CAAC;2BACH,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;AACxD,oBAAA,MAAM,EAAE,GAAG;AACT,wBAAA,GAAG,CAAC;wBACJ,MAAM;wBACN,KAAK;AACL,wBAAA,iBAAiB,EAAE,CAAC,CAAC,OAAO,EAAE,WAAW,IAAI,EAAE;AAC/C,wBAAA,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE,cAAc;qBAC5C;AACD,oBAAA,OAAO,EAAE,CAAC,SAAS,CAAC;AACpB,oBAAA,OAAO,EAAE;AACX,gBAAA,CAAC,CAAC;aACH;QACH,CAAC;KACF,CACF,CAAC,cAAc,EAAE;AACpB;;;;"}
|
|
1
|
+
{"version":3,"file":"project_overview.cjs","sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport type { ComputableStableDefined } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport type {\n ProjectRenderingState,\n ProjectStructure } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from '../model/project_model';\nimport { notEmpty } from '@milaboratories/ts-helpers';\nimport { allBlocks, productionGraph } from '../model/project_model_util';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from '@milaboratories/pl-model-middle-layer';\nimport { constructBlockContext, constructBlockContextArgsOnly } from './block_ctx';\nimport { ifNotUndef } from '../cfg_render/util';\nimport { type BlockSection } from '@platforma-sdk/model';\nimport { extractCodeWithInfo, wrapCallback } from '@platforma-sdk/model';\nimport { computableFromCfgOrRF } from './render';\nimport type { NavigationStates } from './navigation_states';\nimport { getBlockPackInfo } from './util';\nimport { resourceIdToString, type ResourceId } from '@milaboratories/pl-client';\nimport * as R from 'remeda';\n\ntype BlockInfo = {\n argsRid?: ResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(a: Record<string, unknown> | undefined, b: Record<string, unknown> | undefined): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const clean = R.omitBy<Record<string, unknown>>((_, key) => key.startsWith('__'));\n return R.isDeepEqual(clean(a), clean(b));\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, 'currentArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, 'prodArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, 'prodOutput'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, 'prodUiCtx'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined\n || ctx.error !== undefined\n || result.value?.getError() !== undefined\n || ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError())\n || (result.error !== undefined && result.error.getIsReadyOrError()))\n && ((ctx.value !== undefined && ctx.value.getIsReadyOrError())\n || (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = 'NotCalculated';\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = 'Limbo';\n else calculationStatus = info.prod.finished ? 'Done' : 'Running';\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const { sections, title, subtitle, tags, inputsValid, sdkVersion, featureFlags, isIncompatibleWithRuntime }\n = ifNotUndef(bp, ({ bpId, cfg }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model sections', { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model title', { cause }));\n return 'Invalid title';\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n subtitle,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model subtitle', { cause }));\n return 'Invalid subtitle';\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model tags', { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // For older blocks, use the inputsValid callback from config\n inputsValid: cfg.modelAPIVersion === 2\n ? info.currentArguments !== undefined\n : cfg.inputsValid\n ? computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model inputsValid', { cause }));\n return false;\n },\n }) as ComputableStableDefined<boolean>\n : undefined,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, 'blockSettings'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n // Get block storage debug view by calling VM function (only for Model API v2 blocks)\n const storageDebugView = ifNotUndef(bp, ({ cfg }) => {\n if (cfg.modelAPIVersion !== 2) {\n return undefined;\n }\n const storageNode = prj.traverse({\n field: projectFieldName(id, 'blockStorage'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const rawStorageJson = storageNode?.getDataAsString();\n return env.projectHelper.getStorageDebugViewInVM(cfg, rawStorageJson);\n });\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === 'Limbo',\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots('upstream', id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots('downstream', id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n storageDebugView,\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return {\n ...value,\n blocks: value.blocks.map((b) => {\n if (!b.inputsValid) cantRun.add(b.id);\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.findIndex((u) => staleBlocks.has(u)) !== -1;\n const canRun\n = (stale || b.outputErrors)\n && Boolean(b.inputsValid)\n && !b.missingReference\n && b.upstreams.findIndex((u) => cantRun.has(u)) === -1;\n const bb = {\n ...b,\n canRun,\n stale,\n updateSuggestions: b.updates?.suggestions ?? [],\n updatedBlockPack: b.updates?.mainSuggestion,\n };\n delete bb['updates'];\n return bb;\n }),\n };\n },\n },\n ).withStableType();\n}\n"],"names":["R","Computable","notEmpty","ProjectCreatedTimestamp","ProjectLastModifiedTimestamp","ProjectMetaKey","ProjectStructureKey","BlockRenderingStateKey","allBlocks","projectFieldName","productionGraph","getBlockPackInfo","ifNotUndef","constructBlockContext","constructBlockContextArgsOnly","wrapCallback","extractCodeWithInfo","computableFromCfgOrRF","resourceIdToString","ProjectStructureAuthorKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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DataAsJson();
|
|
163
|
-
// Get block storage
|
|
164
|
-
const
|
|
163
|
+
// Get block storage debug view by calling VM function (only for Model API v2 blocks)
|
|
164
|
+
const storageDebugView = ifNotUndef(bp, ({ cfg }) => {
|
|
165
165
|
if (cfg.modelAPIVersion !== 2) {
|
|
166
166
|
return undefined;
|
|
167
167
|
}
|
|
@@ -171,7 +171,7 @@ function projectOverview(prjEntry, navigationStates, env) {
|
|
|
171
171
|
stableIfNotFound: true,
|
|
172
172
|
});
|
|
173
173
|
const rawStorageJson = storageNode?.getDataAsString();
|
|
174
|
-
return env.projectHelper.
|
|
174
|
+
return env.projectHelper.getStorageDebugViewInVM(cfg, rawStorageJson);
|
|
175
175
|
});
|
|
176
176
|
const updates = ifNotUndef(bp, ({ info }) => env.blockUpdateWatcher.get({ currentSpec: info.source, settings }));
|
|
177
177
|
return {
|
|
@@ -200,7 +200,7 @@ function projectOverview(prjEntry, navigationStates, env) {
|
|
|
200
200
|
featureFlags,
|
|
201
201
|
isIncompatibleWithRuntime,
|
|
202
202
|
navigationState: navigationStates.getState(id),
|
|
203
|
-
|
|
203
|
+
storageDebugView,
|
|
204
204
|
};
|
|
205
205
|
});
|
|
206
206
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_overview.js","sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport type { ComputableStableDefined } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport type {\n ProjectRenderingState,\n ProjectStructure } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from '../model/project_model';\nimport { notEmpty } from '@milaboratories/ts-helpers';\nimport { allBlocks, productionGraph } from '../model/project_model_util';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from '@milaboratories/pl-model-middle-layer';\nimport { constructBlockContext, constructBlockContextArgsOnly } from './block_ctx';\nimport { ifNotUndef } from '../cfg_render/util';\nimport { type BlockSection } from '@platforma-sdk/model';\nimport { extractCodeWithInfo, wrapCallback } from '@platforma-sdk/model';\nimport { computableFromCfgOrRF } from './render';\nimport type { NavigationStates } from './navigation_states';\nimport { getBlockPackInfo } from './util';\nimport { resourceIdToString, type ResourceId } from '@milaboratories/pl-client';\nimport * as R from 'remeda';\n\ntype BlockInfo = {\n argsRid?: ResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(a: Record<string, unknown> | undefined, b: Record<string, unknown> | undefined): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const clean = R.omitBy<Record<string, unknown>>((_, key) => key.startsWith('__'));\n return R.isDeepEqual(clean(a), clean(b));\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, 'currentArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, 'prodArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, 'prodOutput'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, 'prodUiCtx'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined\n || ctx.error !== undefined\n || result.value?.getError() !== undefined\n || ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError())\n || (result.error !== undefined && result.error.getIsReadyOrError()))\n && ((ctx.value !== undefined && ctx.value.getIsReadyOrError())\n || (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = 'NotCalculated';\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = 'Limbo';\n else calculationStatus = info.prod.finished ? 'Done' : 'Running';\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const { sections, title, subtitle, tags, inputsValid, sdkVersion, featureFlags, isIncompatibleWithRuntime }\n = ifNotUndef(bp, ({ bpId, cfg }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model sections', { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model title', { cause }));\n return 'Invalid title';\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n subtitle,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model subtitle', { cause }));\n return 'Invalid subtitle';\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model tags', { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // For older blocks, use the inputsValid callback from config\n inputsValid: cfg.modelAPIVersion === 2\n ? info.currentArguments !== undefined\n : cfg.inputsValid\n ? computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model inputsValid', { cause }));\n return false;\n },\n }) as ComputableStableDefined<boolean>\n : undefined,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, 'blockSettings'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n // Get block storage info by calling VM function (only for Model API v2 blocks)\n const blockStorageInfo = ifNotUndef(bp, ({ cfg }) => {\n if (cfg.modelAPIVersion !== 2) {\n return undefined;\n }\n const storageNode = prj.traverse({\n field: projectFieldName(id, 'blockStorage'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const rawStorageJson = storageNode?.getDataAsString();\n return env.projectHelper.getStorageInfoInVM(cfg, rawStorageJson);\n });\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === 'Limbo',\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots('upstream', id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots('downstream', id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n blockStorageInfo,\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return {\n ...value,\n blocks: value.blocks.map((b) => {\n if (!b.inputsValid) cantRun.add(b.id);\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.findIndex((u) => staleBlocks.has(u)) !== -1;\n const canRun\n = (stale || b.outputErrors)\n && Boolean(b.inputsValid)\n && !b.missingReference\n && b.upstreams.findIndex((u) => cantRun.has(u)) === -1;\n const bb = {\n ...b,\n canRun,\n stale,\n updateSuggestions: b.updates?.suggestions ?? [],\n updatedBlockPack: b.updates?.mainSuggestion,\n };\n delete bb['updates'];\n return bb;\n }),\n };\n },\n },\n ).withStableType();\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAwDA,SAAS,UAAU,CAAC,CAAsC,EAAE,CAAsC,EAAA;IAChG,IAAI,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;AACxB,IAAA,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;IACpD,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAA0B,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjF,IAAA,OAAO,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CA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CAAC,KAAK,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;oBAChF,MAAM,MAAM,GACR,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY;AACvB,2BAAA,OAAO,CAAC,CAAC,CAAC,WAAW;2BACrB,CAAC,CAAC,CAAC;2BACH,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;AACxD,oBAAA,MAAM,EAAE,GAAG;AACT,wBAAA,GAAG,CAAC;wBACJ,MAAM;wBACN,KAAK;AACL,wBAAA,iBAAiB,EAAE,CAAC,CAAC,OAAO,EAAE,WAAW,IAAI,EAAE;AAC/C,wBAAA,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE,cAAc;qBAC5C;AACD,oBAAA,OAAO,EAAE,CAAC,SAAS,CAAC;AACpB,oBAAA,OAAO,EAAE;AACX,gBAAA,CAAC,CAAC;aACH;QACH,CAAC;KACF,CACF,CAAC,cAAc,EAAE;AACpB;;;;"}
|
|
1
|
+
{"version":3,"file":"project_overview.js","sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry } from '@milaboratories/pl-tree';\nimport type { ComputableStableDefined } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport type {\n ProjectRenderingState,\n ProjectStructure } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from '../model/project_model';\nimport { notEmpty } from '@milaboratories/ts-helpers';\nimport { allBlocks, productionGraph } from '../model/project_model_util';\nimport type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from '@milaboratories/pl-model-middle-layer';\nimport { constructBlockContext, constructBlockContextArgsOnly } from './block_ctx';\nimport { ifNotUndef } from '../cfg_render/util';\nimport { type BlockSection } from '@platforma-sdk/model';\nimport { extractCodeWithInfo, wrapCallback } from '@platforma-sdk/model';\nimport { computableFromCfgOrRF } from './render';\nimport type { NavigationStates } from './navigation_states';\nimport { getBlockPackInfo } from './util';\nimport { resourceIdToString, type ResourceId } from '@milaboratories/pl-client';\nimport * as R from 'remeda';\n\ntype BlockInfo = {\n argsRid?: ResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(a: Record<string, unknown> | undefined, b: Record<string, unknown> | undefined): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const clean = R.omitBy<Record<string, unknown>>((_, key) => key.startsWith('__'));\n return R.isDeepEqual(clean(a), clean(b));\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, 'currentArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, 'prodArgs'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, 'prodOutput'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, 'prodUiCtx'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined\n || ctx.error !== undefined\n || result.value?.getError() !== undefined\n || ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError())\n || (result.error !== undefined && result.error.getIsReadyOrError()))\n && ((ctx.value !== undefined && ctx.value.getIsReadyOrError())\n || (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = 'NotCalculated';\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = 'Limbo';\n else calculationStatus = info.prod.finished ? 'Done' : 'Running';\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const { sections, title, subtitle, tags, inputsValid, sdkVersion, featureFlags, isIncompatibleWithRuntime }\n = ifNotUndef(bp, ({ bpId, cfg }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model sections', { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model title', { cause }));\n return 'Invalid title';\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n subtitle,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model subtitle', { cause }));\n return 'Invalid subtitle';\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model tags', { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // For older blocks, use the inputsValid callback from config\n inputsValid: cfg.modelAPIVersion === 2\n ? info.currentArguments !== undefined\n : cfg.inputsValid\n ? computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error('Error in block model inputsValid', { cause }));\n return false;\n },\n }) as ComputableStableDefined<boolean>\n : undefined,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, 'blockSettings'),\n assertFieldType: 'Dynamic',\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n // Get block storage debug view by calling VM function (only for Model API v2 blocks)\n const storageDebugView = ifNotUndef(bp, ({ cfg }) => {\n if (cfg.modelAPIVersion !== 2) {\n return undefined;\n }\n const storageNode = prj.traverse({\n field: projectFieldName(id, 'blockStorage'),\n assertFieldType: 'Dynamic',\n stableIfNotFound: true,\n });\n const rawStorageJson = storageNode?.getDataAsString();\n return env.projectHelper.getStorageDebugViewInVM(cfg, rawStorageJson);\n });\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === 'Limbo',\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots('upstream', id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots('downstream', id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n storageDebugView,\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return {\n ...value,\n blocks: value.blocks.map((b) => {\n if (!b.inputsValid) cantRun.add(b.id);\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.findIndex((u) => staleBlocks.has(u)) !== -1;\n const canRun\n = (stale || b.outputErrors)\n && Boolean(b.inputsValid)\n && !b.missingReference\n && b.upstreams.findIndex((u) => cantRun.has(u)) === -1;\n const bb = {\n ...b,\n canRun,\n stale,\n updateSuggestions: b.updates?.suggestions ?? [],\n updatedBlockPack: b.updates?.mainSuggestion,\n };\n delete bb['updates'];\n return bb;\n }),\n };\n },\n },\n ).withStableType();\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAwDA,SAAS,UAAU,CAAC,CAAsC,EAAE,CAAsC,EAAA;IAChG,IAAI,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;AACxB,IAAA,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;IACpD,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAA0B,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACjF,IAAA,OAAO,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1C;AAEA;SACgB,eAAe,CAC7B,QAAqB,EACrB,g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AC,KAAK,IAAI,CAAC,CAAC,YAAY;AACvB,2BAAA,OAAO,CAAC,CAAC,CAAC,WAAW;2BACrB,CAAC,CAAC,CAAC;2BACH,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;AACxD,oBAAA,MAAM,EAAE,GAAG;AACT,wBAAA,GAAG,CAAC;wBACJ,MAAM;wBACN,KAAK;AACL,wBAAA,iBAAiB,EAAE,CAAC,CAAC,OAAO,EAAE,WAAW,IAAI,EAAE;AAC/C,wBAAA,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE,cAAc;qBAC5C;AACD,oBAAA,OAAO,EAAE,CAAC,SAAS,CAAC;AACpB,oBAAA,OAAO,EAAE;AACX,gBAAA,CAAC,CAAC;aACH;QACH,CAAC;KACF,CACF,CAAC,cAAc,EAAE;AACpB;;;;"}
|
|
@@ -6,9 +6,8 @@ var index = require('../js_render/index.cjs');
|
|
|
6
6
|
|
|
7
7
|
// Internal lambda handles for storage operations (registered by SDK's block_storage_vm.ts)
|
|
8
8
|
// All callbacks are prefixed with `__pl_` to indicate internal SDK use
|
|
9
|
-
const STORAGE_NORMALIZE_HANDLE = { __renderLambda: true, handle: '__pl_storage_normalize' };
|
|
10
9
|
const STORAGE_APPLY_UPDATE_HANDLE = { __renderLambda: true, handle: '__pl_storage_applyUpdate' };
|
|
11
|
-
const
|
|
10
|
+
const STORAGE_DEBUG_VIEW_HANDLE = { __renderLambda: true, handle: '__pl_storage_debugView' };
|
|
12
11
|
const STORAGE_MIGRATE_HANDLE = { __renderLambda: true, handle: '__pl_storage_migrate' };
|
|
13
12
|
const ARGS_DERIVE_HANDLE = { __renderLambda: true, handle: '__pl_args_derive' };
|
|
14
13
|
const PRERUN_ARGS_DERIVE_HANDLE = { __renderLambda: true, handle: '__pl_prerunArgs_derive' };
|
|
@@ -97,27 +96,6 @@ class ProjectHelper {
|
|
|
97
96
|
// =============================================================================
|
|
98
97
|
// VM-based Storage Operations
|
|
99
98
|
// =============================================================================
|
|
100
|
-
/**
|
|
101
|
-
* Normalizes raw blockStorage data using VM-based transformation.
|
|
102
|
-
* This calls the model's `__pl_storage_normalize` callback which:
|
|
103
|
-
* - Handles BlockStorage format (with discriminator)
|
|
104
|
-
* - Handles legacy V1/V2 format ({ args, uiState })
|
|
105
|
-
* - Handles raw V3 state
|
|
106
|
-
*
|
|
107
|
-
* @param blockConfig The block configuration (provides the model code)
|
|
108
|
-
* @param rawStorage Raw storage data from resource tree (may be JSON string or object)
|
|
109
|
-
* @returns Object with { storage, state } or undefined if transformation fails
|
|
110
|
-
*/
|
|
111
|
-
normalizeStorageInVM(blockConfig, rawStorage) {
|
|
112
|
-
try {
|
|
113
|
-
const result = index.executeSingleLambda(this.quickJs, STORAGE_NORMALIZE_HANDLE, model.extractCodeWithInfo(blockConfig), rawStorage);
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
console.warn('[ProjectHelper.normalizeStorageInVM] Storage normalization failed:', e);
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
99
|
/**
|
|
122
100
|
* Creates initial BlockStorage for a new block using VM-based transformation.
|
|
123
101
|
* This calls the '__pl_storage_initial' callback registered by DataModel which:
|
|
@@ -162,20 +140,20 @@ class ProjectHelper {
|
|
|
162
140
|
}
|
|
163
141
|
}
|
|
164
142
|
/**
|
|
165
|
-
* Gets storage
|
|
166
|
-
* Returns structured info about the storage (e.g., dataVersion).
|
|
143
|
+
* Gets storage debug view from raw storage data by calling the VM's __pl_storage_debugView callback.
|
|
144
|
+
* Returns structured debug info about the storage (e.g., dataVersion).
|
|
167
145
|
*
|
|
168
146
|
* @param blockConfig Block configuration
|
|
169
147
|
* @param rawStorageJson Raw storage as JSON string (or undefined)
|
|
170
|
-
* @returns Storage
|
|
148
|
+
* @returns Storage debug view as JSON string (e.g., '{"dataVersion": 1}')
|
|
171
149
|
*/
|
|
172
|
-
|
|
150
|
+
getStorageDebugViewInVM(blockConfig, rawStorageJson) {
|
|
173
151
|
try {
|
|
174
|
-
const result = index.executeSingleLambda(this.quickJs,
|
|
152
|
+
const result = index.executeSingleLambda(this.quickJs, STORAGE_DEBUG_VIEW_HANDLE, model.extractCodeWithInfo(blockConfig), rawStorageJson);
|
|
175
153
|
return result;
|
|
176
154
|
}
|
|
177
155
|
catch (e) {
|
|
178
|
-
console.error('[ProjectHelper.
|
|
156
|
+
console.error('[ProjectHelper.getStorageDebugViewInVM] Get storage debug view failed:', e);
|
|
179
157
|
return undefined;
|
|
180
158
|
}
|
|
181
159
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_helper.cjs","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":["LRUCache","executeSingleLambda","extractCodeWithInfo","ensureError"],"mappings":";;;;;;AAmCA;AACA;AACA,MAAM,wBAAwB,GAAuB,EAAE,cAAc,EAAE,IAAI,EAAE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AAA,CAAE,EAAE;QAC/C;IACF;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"project_helper.cjs","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":["LRUCache","executeSingleLambda","extractCodeWithInfo","ensureError"],"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,IAAIA,iBAAQ,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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fig, PlRef, StorageDebugView } from '@platforma-sdk/model';
|
|
2
|
+
import type { StringifiedJson } from '@milaboratories/pl-model-common';
|
|
2
3
|
import type { QuickJSWASMModule } from 'quickjs-emscripten';
|
|
3
4
|
import type { ResourceId } from '@milaboratories/pl-client';
|
|
4
|
-
/**
|
|
5
|
-
* Result of VM-based storage normalization
|
|
6
|
-
*/
|
|
7
|
-
interface NormalizeStorageResult {
|
|
8
|
-
storage: unknown;
|
|
9
|
-
data: unknown;
|
|
10
|
-
}
|
|
11
5
|
/**
|
|
12
6
|
* Result of VM-based storage migration.
|
|
13
7
|
* Returned by migrateStorageInVM().
|
|
@@ -53,18 +47,6 @@ export declare class ProjectHelper {
|
|
|
53
47
|
argsRid: ResourceId;
|
|
54
48
|
blockPackRid: ResourceId;
|
|
55
49
|
}): PlRef[] | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* Normalizes raw blockStorage data using VM-based transformation.
|
|
58
|
-
* This calls the model's `__pl_storage_normalize` callback which:
|
|
59
|
-
* - Handles BlockStorage format (with discriminator)
|
|
60
|
-
* - Handles legacy V1/V2 format ({ args, uiState })
|
|
61
|
-
* - Handles raw V3 state
|
|
62
|
-
*
|
|
63
|
-
* @param blockConfig The block configuration (provides the model code)
|
|
64
|
-
* @param rawStorage Raw storage data from resource tree (may be JSON string or object)
|
|
65
|
-
* @returns Object with { storage, state } or undefined if transformation fails
|
|
66
|
-
*/
|
|
67
|
-
normalizeStorageInVM(blockConfig: BlockConfig, rawStorage: unknown): NormalizeStorageResult | undefined;
|
|
68
50
|
/**
|
|
69
51
|
* Creates initial BlockStorage for a new block using VM-based transformation.
|
|
70
52
|
* This calls the '__pl_storage_initial' callback registered by DataModel which:
|
|
@@ -94,14 +76,14 @@ export declare class ProjectHelper {
|
|
|
94
76
|
value: unknown;
|
|
95
77
|
}): string;
|
|
96
78
|
/**
|
|
97
|
-
* Gets storage
|
|
98
|
-
* Returns structured info about the storage (e.g., dataVersion).
|
|
79
|
+
* Gets storage debug view from raw storage data by calling the VM's __pl_storage_debugView callback.
|
|
80
|
+
* Returns structured debug info about the storage (e.g., dataVersion).
|
|
99
81
|
*
|
|
100
82
|
* @param blockConfig Block configuration
|
|
101
83
|
* @param rawStorageJson Raw storage as JSON string (or undefined)
|
|
102
|
-
* @returns Storage
|
|
84
|
+
* @returns Storage debug view as JSON string (e.g., '{"dataVersion": 1}')
|
|
103
85
|
*/
|
|
104
|
-
|
|
86
|
+
getStorageDebugViewInVM(blockConfig: BlockConfig, rawStorageJson: string | undefined): StringifiedJson<StorageDebugView> | undefined;
|
|
105
87
|
/**
|
|
106
88
|
* Runs block state migrations via VM-based transformation.
|
|
107
89
|
* This calls the model's `__pl_storage_migrate` callback which:
|
|
@@ -119,5 +101,4 @@ export declare class ProjectHelper {
|
|
|
119
101
|
*/
|
|
120
102
|
migrateStorageInVM(blockConfig: BlockConfig, currentStorageJson: string | undefined): MigrationResult;
|
|
121
103
|
}
|
|
122
|
-
export {};
|
|
123
104
|
//# sourceMappingURL=project_helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_helper.d.ts","sourceRoot":"","sources":["../../src/model/project_helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAsB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"project_helper.d.ts","sourceRoot":"","sources":["../../src/model/project_helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAsB,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACpH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAW5D;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,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,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe;CAc7G"}
|
|
@@ -4,9 +4,8 @@ import { executeSingleLambda } from '../js_render/index.js';
|
|
|
4
4
|
|
|
5
5
|
// Internal lambda handles for storage operations (registered by SDK's block_storage_vm.ts)
|
|
6
6
|
// All callbacks are prefixed with `__pl_` to indicate internal SDK use
|
|
7
|
-
const STORAGE_NORMALIZE_HANDLE = { __renderLambda: true, handle: '__pl_storage_normalize' };
|
|
8
7
|
const STORAGE_APPLY_UPDATE_HANDLE = { __renderLambda: true, handle: '__pl_storage_applyUpdate' };
|
|
9
|
-
const
|
|
8
|
+
const STORAGE_DEBUG_VIEW_HANDLE = { __renderLambda: true, handle: '__pl_storage_debugView' };
|
|
10
9
|
const STORAGE_MIGRATE_HANDLE = { __renderLambda: true, handle: '__pl_storage_migrate' };
|
|
11
10
|
const ARGS_DERIVE_HANDLE = { __renderLambda: true, handle: '__pl_args_derive' };
|
|
12
11
|
const PRERUN_ARGS_DERIVE_HANDLE = { __renderLambda: true, handle: '__pl_prerunArgs_derive' };
|
|
@@ -95,27 +94,6 @@ class ProjectHelper {
|
|
|
95
94
|
// =============================================================================
|
|
96
95
|
// VM-based Storage Operations
|
|
97
96
|
// =============================================================================
|
|
98
|
-
/**
|
|
99
|
-
* Normalizes raw blockStorage data using VM-based transformation.
|
|
100
|
-
* This calls the model's `__pl_storage_normalize` callback which:
|
|
101
|
-
* - Handles BlockStorage format (with discriminator)
|
|
102
|
-
* - Handles legacy V1/V2 format ({ args, uiState })
|
|
103
|
-
* - Handles raw V3 state
|
|
104
|
-
*
|
|
105
|
-
* @param blockConfig The block configuration (provides the model code)
|
|
106
|
-
* @param rawStorage Raw storage data from resource tree (may be JSON string or object)
|
|
107
|
-
* @returns Object with { storage, state } or undefined if transformation fails
|
|
108
|
-
*/
|
|
109
|
-
normalizeStorageInVM(blockConfig, rawStorage) {
|
|
110
|
-
try {
|
|
111
|
-
const result = executeSingleLambda(this.quickJs, STORAGE_NORMALIZE_HANDLE, extractCodeWithInfo(blockConfig), rawStorage);
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
catch (e) {
|
|
115
|
-
console.warn('[ProjectHelper.normalizeStorageInVM] Storage normalization failed:', e);
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
97
|
/**
|
|
120
98
|
* Creates initial BlockStorage for a new block using VM-based transformation.
|
|
121
99
|
* This calls the '__pl_storage_initial' callback registered by DataModel which:
|
|
@@ -160,20 +138,20 @@ class ProjectHelper {
|
|
|
160
138
|
}
|
|
161
139
|
}
|
|
162
140
|
/**
|
|
163
|
-
* Gets storage
|
|
164
|
-
* Returns structured info about the storage (e.g., dataVersion).
|
|
141
|
+
* Gets storage debug view from raw storage data by calling the VM's __pl_storage_debugView callback.
|
|
142
|
+
* Returns structured debug info about the storage (e.g., dataVersion).
|
|
165
143
|
*
|
|
166
144
|
* @param blockConfig Block configuration
|
|
167
145
|
* @param rawStorageJson Raw storage as JSON string (or undefined)
|
|
168
|
-
* @returns Storage
|
|
146
|
+
* @returns Storage debug view as JSON string (e.g., '{"dataVersion": 1}')
|
|
169
147
|
*/
|
|
170
|
-
|
|
148
|
+
getStorageDebugViewInVM(blockConfig, rawStorageJson) {
|
|
171
149
|
try {
|
|
172
|
-
const result = executeSingleLambda(this.quickJs,
|
|
150
|
+
const result = executeSingleLambda(this.quickJs, STORAGE_DEBUG_VIEW_HANDLE, extractCodeWithInfo(blockConfig), rawStorageJson);
|
|
173
151
|
return result;
|
|
174
152
|
}
|
|
175
153
|
catch (e) {
|
|
176
|
-
console.error('[ProjectHelper.
|
|
154
|
+
console.error('[ProjectHelper.getStorageDebugViewInVM] Get storage debug view failed:', e);
|
|
177
155
|
return undefined;
|
|
178
156
|
}
|
|
179
157
|
}
|