@milaboratories/pl-middle-layer 1.45.5 → 1.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +58 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/js_render/computable_context.cjs +37 -7
- package/dist/js_render/computable_context.cjs.map +1 -1
- package/dist/js_render/computable_context.d.ts.map +1 -1
- package/dist/js_render/computable_context.js +37 -7
- package/dist/js_render/computable_context.js.map +1 -1
- package/dist/js_render/context.cjs +12 -4
- package/dist/js_render/context.cjs.map +1 -1
- package/dist/js_render/context.d.ts +9 -0
- package/dist/js_render/context.d.ts.map +1 -1
- package/dist/js_render/context.js +12 -4
- package/dist/js_render/context.js.map +1 -1
- package/dist/js_render/index.cjs +1 -1
- package/dist/js_render/index.cjs.map +1 -1
- package/dist/js_render/index.js +1 -1
- package/dist/js_render/index.js.map +1 -1
- package/dist/middle_layer/block.cjs +7 -8
- package/dist/middle_layer/block.cjs.map +1 -1
- package/dist/middle_layer/block.d.ts +4 -4
- package/dist/middle_layer/block.d.ts.map +1 -1
- package/dist/middle_layer/block.js +7 -8
- package/dist/middle_layer/block.js.map +1 -1
- package/dist/middle_layer/block_ctx.cjs +67 -13
- package/dist/middle_layer/block_ctx.cjs.map +1 -1
- package/dist/middle_layer/block_ctx.d.ts +4 -7
- package/dist/middle_layer/block_ctx.d.ts.map +1 -1
- package/dist/middle_layer/block_ctx.js +68 -14
- package/dist/middle_layer/block_ctx.js.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.cjs +10 -3
- package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.d.ts +1 -1
- package/dist/middle_layer/block_ctx_unsafe.d.ts.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.js +10 -3
- package/dist/middle_layer/block_ctx_unsafe.js.map +1 -1
- package/dist/middle_layer/frontend_path.cjs +1 -0
- package/dist/middle_layer/frontend_path.cjs.map +1 -1
- package/dist/middle_layer/frontend_path.js +1 -0
- package/dist/middle_layer/frontend_path.js.map +1 -1
- package/dist/middle_layer/middle_layer.cjs +1 -0
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +1 -1
- package/dist/middle_layer/middle_layer.d.ts.map +1 -1
- package/dist/middle_layer/middle_layer.js +1 -0
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/project.cjs +75 -28
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +34 -7
- package/dist/middle_layer/project.d.ts.map +1 -1
- package/dist/middle_layer/project.js +76 -29
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/middle_layer/project_overview.cjs +32 -11
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.d.ts.map +1 -1
- package/dist/middle_layer/project_overview.js +32 -11
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/dist/middle_layer/render.cjs +1 -1
- package/dist/middle_layer/render.cjs.map +1 -1
- package/dist/middle_layer/render.js +1 -1
- package/dist/middle_layer/render.js.map +1 -1
- package/dist/middle_layer/render.test.d.ts.map +1 -1
- package/dist/model/block_storage_helper.cjs +210 -0
- package/dist/model/block_storage_helper.cjs.map +1 -0
- package/dist/model/block_storage_helper.d.ts +98 -0
- package/dist/model/block_storage_helper.d.ts.map +1 -0
- package/dist/model/block_storage_helper.js +153 -0
- package/dist/model/block_storage_helper.js.map +1 -0
- package/dist/model/index.d.ts +2 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/project_helper.cjs +177 -0
- package/dist/model/project_helper.cjs.map +1 -1
- package/dist/model/project_helper.d.ts +110 -1
- package/dist/model/project_helper.d.ts.map +1 -1
- package/dist/model/project_helper.js +178 -1
- package/dist/model/project_helper.js.map +1 -1
- package/dist/model/project_model.cjs +6 -3
- package/dist/model/project_model.cjs.map +1 -1
- package/dist/model/project_model.d.ts +3 -2
- package/dist/model/project_model.d.ts.map +1 -1
- package/dist/model/project_model.js +6 -4
- package/dist/model/project_model.js.map +1 -1
- package/dist/mutator/block-pack/block_pack.cjs +1 -2
- package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
- package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
- package/dist/mutator/block-pack/block_pack.js +1 -2
- package/dist/mutator/block-pack/block_pack.js.map +1 -1
- package/dist/mutator/block-pack/frontend.cjs +1 -0
- package/dist/mutator/block-pack/frontend.cjs.map +1 -1
- package/dist/mutator/block-pack/frontend.js +1 -0
- package/dist/mutator/block-pack/frontend.js.map +1 -1
- package/dist/mutator/migration.cjs +64 -3
- package/dist/mutator/migration.cjs.map +1 -1
- package/dist/mutator/migration.d.ts.map +1 -1
- package/dist/mutator/migration.js +66 -5
- package/dist/mutator/migration.js.map +1 -1
- package/dist/mutator/project-v3.test.d.ts +2 -0
- package/dist/mutator/project-v3.test.d.ts.map +1 -0
- package/dist/mutator/project.cjs +282 -41
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.d.ts +77 -12
- package/dist/mutator/project.d.ts.map +1 -1
- package/dist/mutator/project.js +283 -42
- package/dist/mutator/project.js.map +1 -1
- package/dist/pool/result_pool.cjs +9 -6
- package/dist/pool/result_pool.cjs.map +1 -1
- package/dist/pool/result_pool.d.ts.map +1 -1
- package/dist/pool/result_pool.js +9 -6
- package/dist/pool/result_pool.js.map +1 -1
- package/package.json +17 -17
- package/src/js_render/computable_context.ts +37 -7
- package/src/js_render/context.ts +12 -5
- package/src/js_render/index.ts +1 -1
- package/src/middle_layer/block.ts +13 -14
- package/src/middle_layer/block_ctx.ts +70 -23
- package/src/middle_layer/block_ctx_unsafe.ts +11 -4
- package/src/middle_layer/middle_layer.ts +2 -1
- package/src/middle_layer/project.ts +86 -40
- package/src/middle_layer/project_overview.ts +44 -20
- package/src/middle_layer/render.test.ts +1 -1
- package/src/middle_layer/render.ts +1 -1
- package/src/model/block_storage_helper.ts +213 -0
- package/src/model/index.ts +2 -1
- package/src/model/project_helper.ts +249 -1
- package/src/model/project_model.ts +9 -5
- package/src/mutator/block-pack/block_pack.ts +1 -2
- package/src/mutator/migration.ts +79 -6
- package/src/mutator/project-v3.test.ts +280 -0
- package/src/mutator/project.test.ts +27 -27
- package/src/mutator/project.ts +351 -68
- package/src/pool/result_pool.ts +11 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.cjs","sources":["../../src/middle_layer/project.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n FieldData,\n OptionalAnyResourceId,\n ResourceId,\n} from '@milaboratories/pl-client';\nimport {\n DefaultRetryOptions,\n ensureResourceIdNotNull,\n field,\n isNotFoundError,\n isTimeoutOrCancelError,\n Pl,\n resourceIdToString,\n} from '@milaboratories/pl-client';\nimport type { ComputableStableDefined, ComputableValueOrErrors } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport { projectOverview } from './project_overview';\nimport type { BlockPackSpecAny } from '../model';\nimport { randomUUID } from 'node:crypto';\nimport { withProject, withProjectAuthored } from '../mutator/project';\nimport type { ExtendedResourceData } from '@milaboratories/pl-tree';\nimport { SynchronizedTreeState, treeDumpStats } from '@milaboratories/pl-tree';\nimport { setTimeout } from 'node:timers/promises';\nimport { frontendData } from './frontend_path';\nimport type { NavigationState } from '@milaboratories/pl-model-common';\nimport { blockArgsAndUiState, blockOutputs } from './block';\nimport type { FrontendData } from '../model/frontend';\nimport type { ProjectStructure } from '../model/project_model';\nimport { projectFieldName } from '../model/project_model';\nimport { cachedDeserialize, notEmpty } from '@milaboratories/ts-helpers';\nimport type { BlockPackInfo } from '../model/block_pack';\nimport type {\n ProjectOverview,\n AuthorMarker,\n BlockStateInternal,\n BlockSettings,\n} from '@milaboratories/pl-model-middle-layer';\nimport { activeConfigs } from './active_cfg';\nimport { NavigationStates } from './navigation_states';\nimport { extractConfig } from '@platforma-sdk/model';\nimport fs from 'node:fs/promises';\nimport canonicalize from 'canonicalize';\nimport type { ProjectOverviewLight } from './project_overview_light';\nimport { projectOverviewLight } from './project_overview_light';\nimport { applyProjectMigrations } from '../mutator/migration';\n\ntype BlockStateComputables = {\n readonly fullState: Computable<BlockStateInternal>;\n};\n\nfunction stringifyForDump(object: unknown): string {\n return JSON.stringify(object, (key, value) => {\n if (typeof value === 'bigint')\n return resourceIdToString(value as OptionalAnyResourceId);\n else if (\n ArrayBuffer.isView(value)\n || value instanceof Int8Array\n || value instanceof Uint8Array\n || value instanceof Uint8ClampedArray\n || value instanceof Int16Array\n || value instanceof Uint16Array\n || value instanceof Int32Array\n || value instanceof Uint32Array\n || value instanceof Float32Array\n || value instanceof Float64Array\n || value instanceof BigInt64Array\n || value instanceof BigUint64Array\n )\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString('base64');\n else if (Buffer.isBuffer(value))\n return value.toString('base64');\n\n return value;\n });\n}\n\n/** Data access object, to manipulate and read single opened (!) project data. */\nexport class Project {\n /** Underlying pl resource id */\n public readonly rid: ResourceId;\n\n /** Data for the left panel, contain basic information about block status. */\n public readonly overview: ComputableStableDefined<ProjectOverview>;\n private readonly overviewLight: Computable<ProjectOverviewLight>;\n\n private readonly navigationStates = new NavigationStates();\n // null is set for deleted blocks\n private readonly blockComputables = new Map<string, BlockStateComputables | null>();\n\n private readonly blockFrontends = new Map<string, ComputableStableDefined<FrontendData>>();\n private readonly activeConfigs: Computable<unknown[]>;\n private readonly refreshLoopResult: Promise<void>;\n\n private readonly abortController = new AbortController();\n\n private get destroyed() {\n return this.abortController.signal.aborted;\n }\n\n constructor(\n private readonly env: MiddleLayerEnvironment,\n rid: ResourceId,\n private readonly projectTree: SynchronizedTreeState,\n ) {\n this.overview = projectOverview(\n projectTree.entry(),\n this.navigationStates,\n env,\n ).withPreCalculatedValueTree();\n this.overviewLight = projectOverviewLight(projectTree.entry())\n .withPreCalculatedValueTree();\n this.rid = rid;\n this.refreshLoopResult = this.refreshLoop();\n this.refreshLoopResult.catch((err) => {\n env.logger.warn(new Error('Error during refresh loop', { cause: err })); // TODO (safe voiding for now)\n });\n this.activeConfigs = activeConfigs(projectTree.entry(), env);\n }\n\n get projectLockId(): string {\n return 'project:' + this.rid.toString();\n }\n\n private async refreshLoop(): Promise<void> {\n while (!this.destroyed) {\n try {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (prj) => {\n prj.doRefresh(this.env.ops.stagingRenderingRate);\n }, { name: 'doRefresh', lockId: this.projectLockId });\n await this.activeConfigs.getValue();\n await setTimeout(this.env.ops.projectRefreshInterval, this.abortController.signal);\n\n // Block computables houskeeping\n const overviewLight = await this.overviewLight.getValue();\n const existingBlocks = new Set(overviewLight.listOfBlocks);\n // Doing cleanup for deleted blocks\n for (const blockId of this.blockComputables.keys()) {\n if (!existingBlocks.has(blockId)) {\n const computable = this.blockComputables.get(blockId);\n if (computable !== undefined && computable !== null) computable.fullState.resetState();\n this.blockComputables.set(blockId, null);\n }\n }\n } catch (e: unknown) {\n // If we're destroyed, exit gracefully regardless of error type\n if (this.destroyed) {\n // Log just in case, to help with debugging if something unexpected happens during shutdown\n this.env.logger.warn(new Error('Error during refresh loop shutdown', { cause: e }));\n break;\n }\n\n if (isNotFoundError(e)) {\n console.warn(\n 'project refresh routine terminated, because project was externally deleted',\n );\n break;\n } else if (isTimeoutOrCancelError(e)) {\n // Timeout during normal operation, continue the loop\n } else {\n // TODO: This stops the refresh loop permanently, leaving the project broken.\n // Need to decide how to handle this case.\n throw new Error('Unexpected exception', { cause: e });\n }\n }\n }\n }\n\n /**\n * Adds new block to the project.\n *\n * @param blockLabel block label / title visible to the user\n * @param blockPackSpec object describing the \"block type\", read more in the type docs\n * @param before id of the block to insert new block before\n * @param blockId internal id to be assigned for the block, this arg can be omitted\n * then, randomly generated UUID will be assigned automatically\n *\n * @return returns newly created block id\n * */\n public async addBlock(\n blockLabel: string,\n blockPackSpec: BlockPackSpecAny,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n blockId: string = randomUUID(),\n ): Promise<string> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfgContainer = await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec);\n const blockCfg = extractConfig(blockCfgContainer); // full content of this var should never be persisted\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n return mut.addBlock(\n {\n id: blockId,\n label: blockLabel,\n renderingMode: blockCfg.renderingMode,\n },\n {\n args: canonicalize(blockCfg.initialArgs)!,\n uiState: canonicalize(blockCfg.initialUiState)!,\n blockPack: preparedBp,\n },\n before,\n );\n },\n {\n retryOptions: {\n ...DefaultRetryOptions,\n backoffMultiplier: DefaultRetryOptions.backoffMultiplier * 1.1,\n },\n name: 'addBlock',\n lockId: this.projectLockId,\n });\n\n await this.projectTree.refreshState();\n\n return blockId;\n }\n\n /**\n * Duplicates an existing block by copying all its fields and state.\n * This method works at the mutator level for efficient block copying.\n *\n * @param originalBlockId id of the block to duplicate\n * @param before id of the block to insert new block before\n * @param author author marker for the duplication operation\n * @param newBlockId internal id to be assigned for the duplicated block,\n * if omitted, a randomly generated UUID will be assigned\n *\n * @return returns newly created block id\n * */\n public async duplicateBlock(\n originalBlockId: string,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n newBlockId: string = randomUUID(),\n ): Promise<string> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.duplicateBlock(originalBlockId, newBlockId, before),\n { name: 'duplicateBlock', lockId: this.projectLockId },\n );\n await this.projectTree.refreshState();\n\n return newBlockId;\n }\n\n /**\n * Update block to new block pack, optionally resetting args and ui state to\n * initial values\n * */\n public async updateBlockPack(\n blockId: string,\n blockPackSpec: BlockPackSpecAny,\n resetArgs: boolean = false,\n author?: AuthorMarker,\n ): Promise<void> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfg = extractConfig(await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec));\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.migrateBlockPack(\n blockId,\n preparedBp,\n resetArgs ? { args: blockCfg.initialArgs, uiState: blockCfg.initialUiState } : undefined,\n ),\n { name: 'updateBlockPack', lockId: this.projectLockId },\n );\n await this.projectTree.refreshState();\n }\n\n /** Deletes a block with all associated data. */\n public async deleteBlock(blockId: string, author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.deleteBlock(blockId), { name: 'deleteBlock', lockId: this.projectLockId });\n this.navigationStates.deleteBlock(blockId);\n await this.projectTree.refreshState();\n }\n\n /**\n * Updates block order according to the given array of block ids.\n *\n * Provided array must contain exactly the same set of ids current project cosists of,\n * an error will be thrown instead.\n */\n public async reorderBlocks(blocks: string[], author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n const currentStructure = mut.structure;\n if (currentStructure.groups.length !== 1)\n throw new Error('Unexpected project structure, non-singular block group');\n const currentGroup = currentStructure.groups[0];\n if (currentGroup.blocks.length !== blocks.length)\n throw new Error(`Length mismatch: ${currentGroup.blocks.length} !== ${blocks.length}`);\n if (new Set<string>(blocks).size !== blocks.length) throw new Error(`Repeated block ids`);\n const newStructure: ProjectStructure = {\n groups: [\n {\n id: currentGroup.id,\n label: currentGroup.label,\n blocks: blocks.map((blockId) => {\n const block = currentGroup.blocks.find((b) => b.id === blockId);\n if (block === undefined) throw new Error(`Can't find block: ${blockId}`);\n return block;\n }),\n },\n ],\n };\n mut.updateStructure(newStructure);\n }, { name: 'reorderBlocks', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Renders production part of the block starting all connected heavy computations.\n * Upstream blocks of the specified block will be started automatically if in\n * stale state.\n * */\n public async runBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.renderProduction([blockId], true), { name: 'runBlock', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Stops the block if it is running by destroying its production state. All\n * its downstreams will also be destroyed or moved to limbo if already\n * calculated.\n * */\n public async stopBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.stopProduction(blockId), { name: 'stopBlock', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n // /** Update block label. */\n // public async setBlockLabel(blockId: string, label: string, author?: AuthorMarker) {\n // await withProjectAuthored(this.env.pl, this.rid, author, (mut) => {\n // mut.setBlockLabel(blockId, label);\n // });\n // await this.projectTree.refreshState();\n // }\n\n /**\n * Sets block args, and changes whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgs(blockId: string, args: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.setStates([{ blockId, args }]),\n { name: 'setBlockArgs', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets ui block state associated with the block.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setUiState(blockId: string, uiState: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.setStates([{ blockId, uiState }]),\n { name: 'setUiState', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets navigation state.\n * */\n // eslint-disable-next-line @typescript-eslint/require-await\n public async setNavigationState(blockId: string, state: NavigationState): Promise<void> {\n this.navigationStates.setState(blockId, state);\n }\n\n /**\n * Sets block args and ui state, and changes the whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgsAndUiState(\n blockId: string,\n args: unknown,\n uiState: unknown,\n author?: AuthorMarker,\n ) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n mut.setStates([{ blockId, args, uiState }]);\n }, { name: 'setBlockArgsAndUiState', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /** Update block settings */\n public async setBlockSettings(blockId: string, newValue: BlockSettings) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {\n mut.setBlockSettings(blockId, newValue);\n }, { name: 'setBlockSettings' });\n await this.projectTree.refreshState();\n }\n\n /** Resets arguments and ui state of the block to initial state */\n public async resetBlockArgsAndUiState(blockId: string, author?: AuthorMarker): Promise<void> {\n await this.env.pl.withWriteTx('BlockInputsReset', async (tx) => {\n // reading default arg values from block pack\n const bpHolderRid = ensureResourceIdNotNull(\n (await tx.getField(field(this.rid, projectFieldName(blockId, 'blockPack')))).value,\n );\n const bpRid = ensureResourceIdNotNull(\n (await tx.getField(field(bpHolderRid, Pl.HolderRefField))).value,\n );\n const bpData = await tx.getResourceData(bpRid, false);\n const config = extractConfig(cachedDeserialize<BlockPackInfo>(notEmpty(bpData.data)).config);\n await withProjectAuthored(this.env.projectHelper, tx, this.rid, author, (prj) => {\n prj.setStates([{ blockId, args: config.initialArgs, uiState: config.initialUiState }]);\n }, { name: 'resetBlockArgsAndUiState', lockId: this.projectLockId });\n await tx.commit();\n });\n await this.projectTree.refreshState();\n }\n\n private getBlockComputables(blockId: string): BlockStateComputables {\n const cached = this.blockComputables.get(blockId);\n if (cached === null) throw new Error(`Block ${blockId} is deleted`);\n if (cached === undefined) {\n // state consists of inputs (args + ui state) and outputs\n const outputs = blockOutputs(this.projectTree.entry(), blockId, this.env);\n const fullState = Computable.make(\n (ctx) => {\n return {\n argsAndUiState: blockArgsAndUiState(this.projectTree.entry(), blockId, ctx),\n outputs,\n navigationState: this.navigationStates.getState(blockId),\n overview: this.overview,\n };\n },\n {\n postprocessValue: (v) => {\n const sdkVersion = v.overview?.blocks?.find((b) => b.id == blockId)?.sdkVersion;\n const toString = sdkVersion && shouldStillUseStringErrors(sdkVersion);\n const newOutputs = toString && v.outputs !== undefined\n ? convertErrorsToStrings(v.outputs)\n : v.outputs;\n\n return {\n ...v.argsAndUiState,\n outputs: newOutputs,\n navigationState: v.navigationState,\n } as BlockStateInternal;\n },\n },\n );\n\n const computables: BlockStateComputables = {\n fullState: fullState.withPreCalculatedValueTree(),\n };\n\n this.blockComputables.set(blockId, computables);\n\n return computables;\n }\n return cached;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch full block state,\n * including outputs, arguments, ui state.\n * */\n public getBlockState(blockId: string): Computable<BlockStateInternal> {\n return this.getBlockComputables(blockId).fullState;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch path of the\n * folder containing frontend code.\n * */\n public getBlockFrontend(blockId: string): ComputableStableDefined<FrontendData> {\n const cached = this.blockFrontends.get(blockId);\n if (cached === undefined) {\n const fd = frontendData(\n this.projectTree.entry(),\n blockId,\n this.env,\n ).withPreCalculatedValueTree();\n this.blockFrontends.set(blockId, fd);\n return fd;\n }\n return cached;\n }\n\n /** Called by middle layer on close */\n public async destroy(): Promise<void> {\n // terminating the project service loop\n this.abortController.abort();\n try {\n await this.refreshLoopResult;\n } catch (e: unknown) {\n // Error was already logged in the constructor's catch handler, but log again for context\n this.env.logger.warn(new Error('Refresh loop had terminated with error before destroy', { cause: e }));\n }\n\n // terminating the synchronized project tree\n try {\n await this.projectTree.terminate();\n } catch (e: unknown) {\n // TODO: SynchronizedTreeState.terminate() can throw if mainLoop had an error before termination\n // Log error but continue cleanup - we must clean up remaining resources\n this.env.logger.warn(new Error('Project tree termination failed', { cause: e }));\n }\n\n // the following will deregister all external resource holders, like\n // downloaded files, running uploads and alike\n this.overview.resetState();\n this.blockFrontends.forEach((c) => c.resetState());\n this.blockComputables.forEach((c) => {\n if (c !== null) c.fullState.resetState();\n });\n this.activeConfigs.resetState();\n }\n\n /** @deprecated */\n public async destroyAndAwaitTermination(): Promise<void> {\n await this.destroy();\n }\n\n public dumpState(): ExtendedResourceData[] {\n return this.projectTree.dumpState();\n }\n\n public static async init(env: MiddleLayerEnvironment, rid: ResourceId): Promise<Project> {\n // Applying migrations to the project resource, if needed\n await applyProjectMigrations(env.pl, rid);\n\n // Doing a no-op mutation to apply all migration and schema fixes\n await withProject(env.projectHelper, env.pl, rid, (_) => {}, { name: 'init' });\n\n // Loading project tree\n const projectTree = await SynchronizedTreeState.init(\n env.pl,\n rid,\n {\n ...env.ops.defaultTreeOptions,\n pruning: projectTreePruning,\n },\n env.logger,\n );\n\n if (env.ops.debugOps.dumpInitialTreeState) {\n const state = projectTree.dumpState();\n state.sort((a, b) => (b.data?.byteLength ?? 0) - (a.data?.byteLength ?? 0));\n const stats = treeDumpStats(state);\n await fs.writeFile(`${resourceIdToString(rid)}.json`, stringifyForDump(state));\n await fs.writeFile(`${resourceIdToString(rid)}.stats.json`, stringifyForDump(stats));\n }\n\n return new Project(env, rid, projectTree);\n }\n}\n\nfunction projectTreePruning(r: ExtendedResourceData): FieldData[] {\n // console.log(\n // JSON.stringify(\n // { ...r, kv: [], data: undefined } satisfies ExtendedResourceData,\n // (_, v) => {\n // if (typeof v === 'bigint') return v.toString();\n // return v;\n // }\n // )\n // );\n if (r.type.name.startsWith('StreamWorkdir/'))\n return [];\n switch (r.type.name) {\n case 'BlockPackCustom':\n return r.fields.filter((f) => f.name !== 'template');\n case 'UserProject':\n return r.fields.filter((f) => !f.name.startsWith('__serviceTemplate'));\n case 'Blob':\n return [];\n default:\n return r.fields;\n }\n}\n\n/** Returns true if sdk version of the block is old and we need to convert\n * ErrorLike errors to strings like it was.\n * We need it for keeping old blocks and new UI compatibility. */\nfunction shouldStillUseStringErrors(sdkVersion: string): boolean {\n return !isVersionGreater(sdkVersion, '1.26.0');\n}\n\n/** Checks if sdk version is greater that a target version. */\nfunction isVersionGreater(sdkVersion: string, targetVersion: string): boolean {\n const version = sdkVersion.split('.').map(Number);\n const target = targetVersion.split('.').map(Number);\n\n return (\n version[0] > target[0]\n || (version[0] === target[0] && version[1] > target[1])\n || (version[0] === target[0] && version[1] === target[1] && version[2] > target[2])\n );\n};\n\n/** Converts ErrorLike errors to strings in the outputs like it was in old ML versions. */\nfunction convertErrorsToStrings(\n outputs: Record<string, ComputableValueOrErrors<unknown>>,\n): Record<string, ComputableValueOrErrors<unknown>> {\n const result: Record<string, ComputableValueOrErrors<unknown>> = {};\n for (const [key, val] of Object.entries(outputs)) {\n if (val.ok) {\n result[key] = val;\n continue;\n }\n\n result[key] = {\n ok: false,\n errors: val.errors.map((e) => {\n if (typeof e === 'string') {\n return e;\n } else if (e.type == 'PlError' && e.fullMessage !== undefined) {\n return e.fullMessage;\n }\n return e.message;\n }),\n moreErrors: val.moreErrors,\n };\n }\n\n return result;\n}\n"],"names":["resourceIdToString","NavigationStates","projectOverview","projectOverviewLight","activeConfigs","withProject","setTimeout","isNotFoundError","isTimeoutOrCancelError","randomUUID","extractConfig","withProjectAuthored","DefaultRetryOptions","ensureResourceIdNotNull","field","projectFieldName","Pl","cachedDeserialize","notEmpty","blockOutputs","Computable","blockArgsAndUiState","frontendData","applyProjectMigrations","SynchronizedTreeState","treeDumpStats"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmDA,SAAS,gBAAgB,CAAC,MAAe,EAAA;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KAAI;QAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ;AAC3B,YAAA,OAAOA,2BAAkB,CAAC,KAA8B,CAAC;AACtD,aAAA,IACH,WAAW,CAAC,MAAM,CAAC,KAAK;AACrB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KA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AAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAEvF;AAEA;AACA,SAAS,sBAAsB,CAC7B,OAAyD,EAAA;IAEzD,MAAM,MAAM,GAAqD,EAAE;AACnE,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;AAChD,QAAA,IAAI,GAAG,CAAC,EAAE,EAAE;AACV,YAAA,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG;YACjB;QACF;QAEA,MAAM,CAAC,GAAG,CAAC,GAAG;AACZ,YAAA,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAI;AAC3B,gBAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;AACzB,oBAAA,OAAO,CAAC;gBACV;AAAO,qBAAA,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;oBAC7D,OAAO,CAAC,CAAC,WAAW;gBACtB;gBACA,OAAO,CAAC,CAAC,OAAO;AAClB,YAAA,CAAC,CAAC;YACF,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B;IACH;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
1
|
+
{"version":3,"file":"project.cjs","sources":["../../src/middle_layer/project.ts"],"sourcesContent":["import type { MiddleLayerEnvironment } from './middle_layer';\nimport type {\n FieldData,\n OptionalAnyResourceId,\n ResourceId,\n} from '@milaboratories/pl-client';\nimport {\n DefaultRetryOptions,\n ensureResourceIdNotNull,\n field,\n isNotFoundError,\n isTimeoutOrCancelError,\n Pl,\n resourceIdToString,\n} from '@milaboratories/pl-client';\nimport type { ComputableStableDefined, ComputableValueOrErrors } from '@milaboratories/computable';\nimport { Computable } from '@milaboratories/computable';\nimport { projectOverview } from './project_overview';\nimport type { BlockPackSpecAny } from '../model';\nimport { randomUUID } from 'node:crypto';\nimport { withProject, withProjectAuthored } from '../mutator/project';\nimport type { ExtendedResourceData } from '@milaboratories/pl-tree';\nimport { SynchronizedTreeState, treeDumpStats } from '@milaboratories/pl-tree';\nimport { setTimeout } from 'node:timers/promises';\nimport { frontendData } from './frontend_path';\nimport type { NavigationState } from '@milaboratories/pl-model-common';\nimport { getBlockParameters, blockOutputs } from './block';\nimport type { FrontendData } from '../model/frontend';\nimport type { ProjectStructure } from '../model/project_model';\nimport { projectFieldName } from '../model/project_model';\nimport { cachedDeserialize, notEmpty } from '@milaboratories/ts-helpers';\nimport type { BlockPackInfo } from '../model/block_pack';\nimport type {\n ProjectOverview,\n AuthorMarker,\n BlockSettings,\n BlockStateInternalV3,\n} from '@milaboratories/pl-model-middle-layer';\nimport { activeConfigs } from './active_cfg';\nimport { NavigationStates } from './navigation_states';\nimport { extractConfig } from '@platforma-sdk/model';\nimport fs from 'node:fs/promises';\nimport canonicalize from 'canonicalize';\nimport type { ProjectOverviewLight } from './project_overview_light';\nimport { projectOverviewLight } from './project_overview_light';\nimport { applyProjectMigrations } from '../mutator/migration';\n\ntype BlockStateComputables = {\n readonly fullState: Computable<BlockStateInternalV3>;\n};\n\nfunction stringifyForDump(object: unknown): string {\n return JSON.stringify(object, (key, value) => {\n if (typeof value === 'bigint')\n return resourceIdToString(value as OptionalAnyResourceId);\n else if (\n ArrayBuffer.isView(value)\n || value instanceof Int8Array\n || value instanceof Uint8Array\n || value instanceof Uint8ClampedArray\n || value instanceof Int16Array\n || value instanceof Uint16Array\n || value instanceof Int32Array\n || value instanceof Uint32Array\n || value instanceof Float32Array\n || value instanceof Float64Array\n || value instanceof BigInt64Array\n || value instanceof BigUint64Array\n )\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString('base64');\n else if (Buffer.isBuffer(value))\n return value.toString('base64');\n\n return value;\n });\n}\n\n/** Data access object, to manipulate and read single opened (!) project data. */\nexport class Project {\n /** Underlying pl resource id */\n public readonly rid: ResourceId;\n\n /** Data for the left panel, contain basic information about block status. */\n public readonly overview: ComputableStableDefined<ProjectOverview>;\n private readonly overviewLight: Computable<ProjectOverviewLight>;\n\n private readonly navigationStates = new NavigationStates();\n // null is set for deleted blocks\n private readonly blockComputables = new Map<string, BlockStateComputables | null>();\n\n private readonly blockFrontends = new Map<string, ComputableStableDefined<FrontendData>>();\n private readonly activeConfigs: Computable<unknown[]>;\n private readonly refreshLoopResult: Promise<void>;\n\n private readonly abortController = new AbortController();\n\n private get destroyed() {\n return this.abortController.signal.aborted;\n }\n\n constructor(\n private readonly env: MiddleLayerEnvironment,\n rid: ResourceId,\n private readonly projectTree: SynchronizedTreeState,\n ) {\n this.overview = projectOverview(\n projectTree.entry(),\n this.navigationStates,\n env,\n ).withPreCalculatedValueTree();\n this.overviewLight = projectOverviewLight(projectTree.entry())\n .withPreCalculatedValueTree();\n this.rid = rid;\n this.refreshLoopResult = this.refreshLoop();\n this.refreshLoopResult.catch((err) => {\n env.logger.warn(new Error('Error during refresh loop', { cause: err })); // TODO (safe voiding for now)\n });\n this.activeConfigs = activeConfigs(projectTree.entry(), env);\n }\n\n get projectLockId(): string {\n return 'project:' + this.rid.toString();\n }\n\n private async refreshLoop(): Promise<void> {\n while (!this.destroyed) {\n try {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (prj) => {\n prj.doRefresh(this.env.ops.stagingRenderingRate);\n }, { name: 'doRefresh', lockId: this.projectLockId });\n await this.activeConfigs.getValue();\n await setTimeout(this.env.ops.projectRefreshInterval, this.abortController.signal);\n\n // Block computables housekeeping\n const overviewLight = await this.overviewLight.getValue();\n const existingBlocks = new Set(overviewLight.listOfBlocks);\n // Doing cleanup for deleted blocks\n for (const blockId of this.blockComputables.keys()) {\n if (!existingBlocks.has(blockId)) {\n const computable = this.blockComputables.get(blockId);\n if (computable !== undefined && computable !== null) computable.fullState.resetState();\n this.blockComputables.set(blockId, null);\n }\n }\n } catch (e: unknown) {\n // If we're destroyed, exit gracefully regardless of error type\n if (this.destroyed) {\n // Log just in case, to help with debugging if something unexpected happens during shutdown\n this.env.logger.warn(new Error('Error during refresh loop shutdown', { cause: e }));\n break;\n }\n\n if (isNotFoundError(e)) {\n console.warn(\n 'project refresh routine terminated, because project was externally deleted',\n );\n break;\n } else if (isTimeoutOrCancelError(e)) {\n // Timeout during normal operation, continue the loop\n } else {\n // TODO: This stops the refresh loop permanently, leaving the project broken.\n // Need to decide how to handle this case.\n throw new Error('Unexpected exception', { cause: e });\n }\n }\n }\n }\n\n /**\n * Adds new block to the project.\n *\n * @param blockLabel block label / title visible to the user\n * @param blockPackSpec object describing the \"block type\", read more in the type docs\n * @param before id of the block to insert new block before\n * @param blockId internal id to be assigned for the block, this arg can be omitted\n * then, randomly generated UUID will be assigned automatically\n *\n * @return returns newly created block id\n * */\n public async addBlock(\n blockLabel: string,\n blockPackSpec: BlockPackSpecAny,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n blockId: string = randomUUID(),\n ): Promise<string> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfgContainer = await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec);\n const blockCfg = extractConfig(blockCfgContainer); // full content of this var should never be persisted\n\n // Build NewBlockSpec based on model API version\n const newBlockSpec = blockCfg.modelAPIVersion === 2\n ? { storageMode: 'fromModel' as const, blockPack: preparedBp }\n : { storageMode: 'legacy' as const, blockPack: preparedBp, legacyState: canonicalize({ args: blockCfg.initialArgs, uiState: blockCfg.initialUiState })! };\n\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n return mut.addBlock(\n {\n id: blockId,\n label: blockLabel,\n renderingMode: blockCfg.renderingMode,\n },\n newBlockSpec,\n before,\n );\n },\n {\n retryOptions: {\n ...DefaultRetryOptions,\n backoffMultiplier: DefaultRetryOptions.backoffMultiplier * 1.1,\n },\n name: 'addBlock',\n lockId: this.projectLockId,\n });\n\n await this.projectTree.refreshState();\n\n return blockId;\n }\n\n /**\n * Duplicates an existing block by copying all its fields and state.\n * This method works at the mutator level for efficient block copying.\n *\n * @param originalBlockId id of the block to duplicate\n * @param before id of the block to insert new block before\n * @param author author marker for the duplication operation\n * @param newBlockId internal id to be assigned for the duplicated block,\n * if omitted, a randomly generated UUID will be assigned\n *\n * @return returns newly created block id\n * */\n public async duplicateBlock(\n originalBlockId: string,\n before?: string,\n author: AuthorMarker | undefined = undefined,\n newBlockId: string = randomUUID(),\n ): Promise<string> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.duplicateBlock(originalBlockId, newBlockId, before),\n { name: 'duplicateBlock', lockId: this.projectLockId },\n );\n await this.projectTree.refreshState();\n\n return newBlockId;\n }\n\n /**\n * Update block to new block pack, optionally resetting args and ui state to\n * initial values\n * */\n public async updateBlockPack(\n blockId: string,\n blockPackSpec: BlockPackSpecAny,\n resetArgs: boolean = false,\n author?: AuthorMarker,\n ): Promise<void> {\n const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);\n const blockCfg = extractConfig(await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec));\n // resetState signals to mutator to reset storage\n // For v2+ blocks: mutator gets initial storage directly via getInitialStorageInVM\n // For v1 blocks: we pass the legacy state format\n const resetState = resetArgs\n ? { state: blockCfg.modelAPIVersion === 2 ? {} : { args: blockCfg.initialArgs, uiState: blockCfg.initialUiState } }\n : undefined;\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.migrateBlockPack(\n blockId,\n preparedBp,\n resetState,\n ),\n { name: 'updateBlockPack', lockId: this.projectLockId },\n );\n await this.projectTree.refreshState();\n }\n\n /** Deletes a block with all associated data. */\n public async deleteBlock(blockId: string, author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.deleteBlock(blockId), { name: 'deleteBlock', lockId: this.projectLockId });\n this.navigationStates.deleteBlock(blockId);\n await this.projectTree.refreshState();\n }\n\n /**\n * Updates block order according to the given array of block ids.\n *\n * Provided array must contain exactly the same set of ids current project cosists of,\n * an error will be thrown instead.\n */\n public async reorderBlocks(blocks: string[], author?: AuthorMarker): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n const currentStructure = mut.structure;\n if (currentStructure.groups.length !== 1)\n throw new Error('Unexpected project structure, non-singular block group');\n const currentGroup = currentStructure.groups[0];\n if (currentGroup.blocks.length !== blocks.length)\n throw new Error(`Length mismatch: ${currentGroup.blocks.length} !== ${blocks.length}`);\n if (new Set<string>(blocks).size !== blocks.length) throw new Error(`Repeated block ids`);\n const newStructure: ProjectStructure = {\n groups: [\n {\n id: currentGroup.id,\n label: currentGroup.label,\n blocks: blocks.map((blockId) => {\n const block = currentGroup.blocks.find((b) => b.id === blockId);\n if (block === undefined) throw new Error(`Can't find block: ${blockId}`);\n return block;\n }),\n },\n ],\n };\n mut.updateStructure(newStructure);\n }, { name: 'reorderBlocks', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Renders production part of the block starting all connected heavy computations.\n * Upstream blocks of the specified block will be started automatically if in\n * stale state.\n * */\n public async runBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.renderProduction([blockId], true), { name: 'runBlock', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Stops the block if it is running by destroying its production state. All\n * its downstreams will also be destroyed or moved to limbo if already\n * calculated.\n * */\n public async stopBlock(blockId: string): Promise<void> {\n await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.stopProduction(blockId), { name: 'stopBlock', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * @deprecated Use mutateBlockStorage() for V3 blocks.\n * Sets block args, and changes whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgs(blockId: string, args: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n const state = mut.mergeBlockState(blockId, { args });\n mut.setStates([{ modelAPIVersion: 1, blockId, state }]);\n }, { name: 'setBlockArgs', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * @deprecated Use mutateBlockStorage() for V3 blocks.\n * Sets ui block state associated with the block.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setUiState(blockId: string, uiState: unknown, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n const state = mut.mergeBlockState(blockId, { uiState });\n mut.setStates([{ modelAPIVersion: 1, blockId, state }]);\n }, { name: 'setUiState', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * @deprecated Use mutateBlockStorage() for V3 blocks.\n * Sets block args and ui state, and changes the whole project state accordingly.\n * Along with setting arguments one can specify author marker, that will be\n * transactionally associated with the block, to facilitate conflict resolution\n * in collaborative editing scenario.\n * */\n public async setBlockArgsAndUiState(\n blockId: string,\n args: unknown, // keep for v1/v2 compatibility\n uiState: unknown, // keep for v1/v2 compatibility\n author?: AuthorMarker,\n ) {\n // Normalize to unified state format { args, uiState } for v1/v2 blocks\n const state = { args, uiState };\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {\n mut.setStates([{ modelAPIVersion: 1, blockId, state }]);\n }, { name: 'setBlockArgsAndUiState', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets navigation state.\n * */\n // eslint-disable-next-line @typescript-eslint/require-await\n public async setNavigationState(blockId: string, state: NavigationState): Promise<void> {\n this.navigationStates.setState(blockId, state);\n }\n\n /**\n * Mutates block storage for Model API v3 blocks.\n * Applies a storage operation (e.g., 'update-data') which triggers\n * args derivation (args(data) and prerunArgs(data)).\n * The derived args are stored atomically with the data.\n *\n * @param blockId - The block ID\n * @param payload - Storage mutation payload with operation and value\n * @param author - Optional author marker for collaborative editing\n */\n public async mutateBlockStorage(blockId: string, payload: { operation: string; value: unknown }, author?: AuthorMarker) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>\n mut.setStates([{ modelAPIVersion: 2, blockId, payload }]),\n { name: 'mutateBlockStorage', lockId: this.projectLockId });\n await this.projectTree.refreshState();\n }\n\n /** Update block settings */\n public async setBlockSettings(blockId: string, newValue: BlockSettings) {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {\n mut.setBlockSettings(blockId, newValue);\n }, { name: 'setBlockSettings' });\n await this.projectTree.refreshState();\n }\n\n /**\n * Sets raw block storage content directly.\n * This bypasses all normalization and VM transformations.\n *\n * @param blockId The block to set storage for\n * @param rawStorageJson Raw storage as JSON string\n */\n public async setBlockStorageRaw(blockId: string, rawStorageJson: string): Promise<void> {\n await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {\n mut.setBlockStorageRaw(blockId, rawStorageJson);\n }, { name: 'setBlockStorageRaw' });\n await this.projectTree.refreshState();\n }\n\n /** Resets arguments and ui state of the block to initial state */\n public async resetBlockArgsAndUiState(blockId: string, author?: AuthorMarker): Promise<void> {\n await this.env.pl.withWriteTx('BlockInputsReset', async (tx) => {\n // reading default arg values from block pack\n const bpHolderRid = ensureResourceIdNotNull(\n (await tx.getField(field(this.rid, projectFieldName(blockId, 'blockPack')))).value,\n );\n const bpRid = ensureResourceIdNotNull(\n (await tx.getField(field(bpHolderRid, Pl.HolderRefField))).value,\n );\n const bpData = await tx.getResourceData(bpRid, false);\n const config = extractConfig(cachedDeserialize<BlockPackInfo>(notEmpty(bpData.data)).config);\n\n await withProjectAuthored(this.env.projectHelper, tx, this.rid, author, (prj) => {\n if (config.modelAPIVersion === 2) {\n // V2+: Reset to initial storage via VM\n prj.resetToInitialStorage(blockId);\n } else {\n // V1: Use legacy state format\n const initialState = { args: config.initialArgs, uiState: config.initialUiState };\n prj.setStates([{ modelAPIVersion: 1, blockId, state: initialState }]);\n }\n }, { name: 'resetBlockArgsAndUiState', lockId: this.projectLockId });\n await tx.commit();\n });\n await this.projectTree.refreshState();\n }\n\n private getBlockComputables(blockId: string): BlockStateComputables {\n const cached = this.blockComputables.get(blockId);\n if (cached === null) throw new Error(`Block ${blockId} is deleted`);\n if (cached === undefined) {\n // state consists of inputs (args + ui state) and outputs\n const outputs = blockOutputs(this.projectTree.entry(), blockId, this.env);\n const fullState = Computable.make(\n (ctx) => {\n return {\n parameters: getBlockParameters(this.projectTree.entry(), blockId, ctx),\n outputs,\n navigationState: this.navigationStates.getState(blockId),\n overview: this.overview,\n };\n },\n {\n postprocessValue: (v) => {\n const sdkVersion = v.overview?.blocks?.find((b) => b.id == blockId)?.sdkVersion;\n const toString = sdkVersion && shouldStillUseStringErrors(sdkVersion);\n const newOutputs = toString && v.outputs !== undefined\n ? convertErrorsToStrings(v.outputs)\n : v.outputs;\n\n return {\n ...v.parameters,\n outputs: newOutputs,\n navigationState: v.navigationState,\n } as BlockStateInternalV3;\n },\n },\n );\n\n const computables: BlockStateComputables = {\n fullState: fullState.withPreCalculatedValueTree(),\n };\n\n this.blockComputables.set(blockId, computables);\n\n return computables;\n }\n return cached;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch full block state,\n * including outputs, arguments, ui state.\n * */\n public getBlockState(blockId: string): Computable<BlockStateInternalV3> {\n return this.getBlockComputables(blockId).fullState;\n }\n\n /**\n * Returns a computable, that can be used to retrieve and watch path of the\n * folder containing frontend code.\n * */\n public getBlockFrontend(blockId: string): ComputableStableDefined<FrontendData> {\n const cached = this.blockFrontends.get(blockId);\n if (cached === undefined) {\n const fd = frontendData(\n this.projectTree.entry(),\n blockId,\n this.env,\n ).withPreCalculatedValueTree();\n this.blockFrontends.set(blockId, fd);\n return fd;\n }\n return cached;\n }\n\n /** Called by middle layer on close */\n public async destroy(): Promise<void> {\n // terminating the project service loop\n this.abortController.abort();\n try {\n await this.refreshLoopResult;\n } catch (e: unknown) {\n // Error was already logged in the constructor's catch handler, but log again for context\n this.env.logger.warn(new Error('Refresh loop had terminated with error before destroy', { cause: e }));\n }\n\n // terminating the synchronized project tree\n try {\n await this.projectTree.terminate();\n } catch (e: unknown) {\n // TODO: SynchronizedTreeState.terminate() can throw if mainLoop had an error before termination\n // Log error but continue cleanup - we must clean up remaining resources\n this.env.logger.warn(new Error('Project tree termination failed', { cause: e }));\n }\n\n // the following will deregister all external resource holders, like\n // downloaded files, running uploads and alike\n this.overview.resetState();\n this.blockFrontends.forEach((c) => c.resetState());\n this.blockComputables.forEach((c) => {\n if (c !== null) c.fullState.resetState();\n });\n this.activeConfigs.resetState();\n }\n\n /** @deprecated */\n public async destroyAndAwaitTermination(): Promise<void> {\n await this.destroy();\n }\n\n public dumpState(): ExtendedResourceData[] {\n return this.projectTree.dumpState();\n }\n\n public static async init(env: MiddleLayerEnvironment, rid: ResourceId): Promise<Project> {\n // Applying migrations to the project resource, if needed\n await applyProjectMigrations(env.pl, rid);\n\n // Doing a no-op mutation to apply all migration and schema fixes\n await withProject(env.projectHelper, env.pl, rid, (_) => {}, { name: 'init' });\n\n // Loading project tree\n const projectTree = await SynchronizedTreeState.init(\n env.pl,\n rid,\n {\n ...env.ops.defaultTreeOptions,\n pruning: projectTreePruning,\n },\n env.logger,\n );\n\n if (env.ops.debugOps.dumpInitialTreeState) {\n const state = projectTree.dumpState();\n state.sort((a, b) => (b.data?.byteLength ?? 0) - (a.data?.byteLength ?? 0));\n const stats = treeDumpStats(state);\n await fs.writeFile(`${resourceIdToString(rid)}.json`, stringifyForDump(state));\n await fs.writeFile(`${resourceIdToString(rid)}.stats.json`, stringifyForDump(stats));\n }\n\n return new Project(env, rid, projectTree);\n }\n}\n\nfunction projectTreePruning(r: ExtendedResourceData): FieldData[] {\n // console.log(\n // JSON.stringify(\n // { ...r, kv: [], data: undefined } satisfies ExtendedResourceData,\n // (_, v) => {\n // if (typeof v === 'bigint') return v.toString();\n // return v;\n // }\n // )\n // );\n if (r.type.name.startsWith('StreamWorkdir/'))\n return [];\n switch (r.type.name) {\n case 'BlockPackCustom':\n return r.fields.filter((f) => f.name !== 'template');\n case 'UserProject':\n return r.fields.filter((f) => !f.name.startsWith('__serviceTemplate'));\n case 'Blob':\n return [];\n default:\n return r.fields;\n }\n}\n\n/** Returns true if sdk version of the block is old and we need to convert\n * ErrorLike errors to strings like it was.\n * We need it for keeping old blocks and new UI compatibility. */\nfunction shouldStillUseStringErrors(sdkVersion: string): boolean {\n return !isVersionGreater(sdkVersion, '1.26.0');\n}\n\n/** Checks if sdk version is greater that a target version. */\nfunction isVersionGreater(sdkVersion: string, targetVersion: string): boolean {\n const version = sdkVersion.split('.').map(Number);\n const target = targetVersion.split('.').map(Number);\n\n return (\n version[0] > target[0]\n || (version[0] === target[0] && version[1] > target[1])\n || (version[0] === target[0] && version[1] === target[1] && version[2] > target[2])\n );\n};\n\n/** Converts ErrorLike errors to strings in the outputs like it was in old ML versions. */\nfunction convertErrorsToStrings(\n outputs: Record<string, ComputableValueOrErrors<unknown>>,\n): Record<string, ComputableValueOrErrors<unknown>> {\n const result: Record<string, ComputableValueOrErrors<unknown>> = {};\n for (const [key, val] of Object.entries(outputs)) {\n if (val.ok) {\n result[key] = val;\n continue;\n }\n\n result[key] = {\n ok: false,\n errors: val.errors.map((e) => {\n if (typeof e === 'string') {\n return e;\n } else if (e.type == 'PlError' && e.fullMessage !== undefined) {\n return e.fullMessage;\n }\n return e.message;\n }),\n moreErrors: val.moreErrors,\n };\n }\n\n return result;\n}\n"],"names":["resourceIdToString","NavigationStates","projectOverview","projectOverviewLight","activeConfigs","withProject","setTimeout","isNotFoundError","isTimeoutOrCancelError","randomUUID","extractConfig","withProjectAuthored","DefaultRetryOptions","ensureResourceIdNotNull","field","projectFieldName","Pl","cachedDeserialize","notEmpty","blockOutputs","Computable","getBlockParameters","frontendData","applyProjectMigrations","SynchronizedTreeState","treeDumpStats"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmDA,SAAS,gBAAgB,CAAC,MAAe,EAAA;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,KAAI;QAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ;AAC3B,YAAA,OAAOA,2BAAkB,CAAC,KAA8B,CAAC;AACtD,aAAA,IACH,WAAW,CAAC,MAAM,CAAC,KAAK;AACrB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY;AACjB,eAAA,KAAK,YAAY,cAAc;YAElC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;AACpF,aAAA,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC7B,YAAA,OAAO,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAEjC,QAAA,OAAO,KAAK;AACd,IAAA,CAAC,CAAC;AACJ;AAEA;MACa,OAAO,CAAA;AAuBC,IAAA,GAAA;AAEA,IAAA,WAAA;;AAvBH,IAAA,GAAG;;AAGH,IAAA,QAAQ;AACP,IAAA,aAAa;AAEb,IAAA,gBAAgB,GAAG,IAAIC,kCAAgB,EAAE;;AAEzC,IAAA,gBAAgB,GAAG,IAAI,GAAG,EAAwC;AAElE,IAAA,cAAc,GAAG,IAAI,GAAG,EAAiD;AACzE,IAAA,aAAa;AACb,IAAA,iB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;AACA,SAAS,sBAAsB,CAC7B,OAAyD,EAAA;IAEzD,MAAM,MAAM,GAAqD,EAAE;AACnE,IAAA,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;AAChD,QAAA,IAAI,GAAG,CAAC,EAAE,EAAE;AACV,YAAA,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG;YACjB;QACF;QAEA,MAAM,CAAC,GAAG,CAAC,GAAG;AACZ,YAAA,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAI;AAC3B,gBAAA,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;AACzB,oBAAA,OAAO,CAAC;gBACV;AAAO,qBAAA,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;oBAC7D,OAAO,CAAC,CAAC,WAAW;gBACtB;gBACA,OAAO,CAAC,CAAC,OAAO;AAClB,YAAA,CAAC,CAAC;YACF,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B;IACH;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -7,7 +7,7 @@ import type { ExtendedResourceData } from '@milaboratories/pl-tree';
|
|
|
7
7
|
import { SynchronizedTreeState } from '@milaboratories/pl-tree';
|
|
8
8
|
import type { NavigationState } from '@milaboratories/pl-model-common';
|
|
9
9
|
import type { FrontendData } from '../model/frontend';
|
|
10
|
-
import type { ProjectOverview, AuthorMarker,
|
|
10
|
+
import type { ProjectOverview, AuthorMarker, BlockSettings, BlockStateInternalV3 } from '@milaboratories/pl-model-middle-layer';
|
|
11
11
|
/** Data access object, to manipulate and read single opened (!) project data. */
|
|
12
12
|
export declare class Project {
|
|
13
13
|
private readonly env;
|
|
@@ -79,6 +79,7 @@ export declare class Project {
|
|
|
79
79
|
* */
|
|
80
80
|
stopBlock(blockId: string): Promise<void>;
|
|
81
81
|
/**
|
|
82
|
+
* @deprecated Use mutateBlockStorage() for V3 blocks.
|
|
82
83
|
* Sets block args, and changes whole project state accordingly.
|
|
83
84
|
* Along with setting arguments one can specify author marker, that will be
|
|
84
85
|
* transactionally associated with the block, to facilitate conflict resolution
|
|
@@ -86,6 +87,7 @@ export declare class Project {
|
|
|
86
87
|
* */
|
|
87
88
|
setBlockArgs(blockId: string, args: unknown, author?: AuthorMarker): Promise<void>;
|
|
88
89
|
/**
|
|
90
|
+
* @deprecated Use mutateBlockStorage() for V3 blocks.
|
|
89
91
|
* Sets ui block state associated with the block.
|
|
90
92
|
* Along with setting arguments one can specify author marker, that will be
|
|
91
93
|
* transactionally associated with the block, to facilitate conflict resolution
|
|
@@ -93,18 +95,43 @@ export declare class Project {
|
|
|
93
95
|
* */
|
|
94
96
|
setUiState(blockId: string, uiState: unknown, author?: AuthorMarker): Promise<void>;
|
|
95
97
|
/**
|
|
96
|
-
*
|
|
97
|
-
* */
|
|
98
|
-
setNavigationState(blockId: string, state: NavigationState): Promise<void>;
|
|
99
|
-
/**
|
|
98
|
+
* @deprecated Use mutateBlockStorage() for V3 blocks.
|
|
100
99
|
* Sets block args and ui state, and changes the whole project state accordingly.
|
|
101
100
|
* Along with setting arguments one can specify author marker, that will be
|
|
102
101
|
* transactionally associated with the block, to facilitate conflict resolution
|
|
103
102
|
* in collaborative editing scenario.
|
|
104
103
|
* */
|
|
105
|
-
setBlockArgsAndUiState(blockId: string, args: unknown,
|
|
104
|
+
setBlockArgsAndUiState(blockId: string, args: unknown, // keep for v1/v2 compatibility
|
|
105
|
+
uiState: unknown, // keep for v1/v2 compatibility
|
|
106
|
+
author?: AuthorMarker): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Sets navigation state.
|
|
109
|
+
* */
|
|
110
|
+
setNavigationState(blockId: string, state: NavigationState): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Mutates block storage for Model API v3 blocks.
|
|
113
|
+
* Applies a storage operation (e.g., 'update-data') which triggers
|
|
114
|
+
* args derivation (args(data) and prerunArgs(data)).
|
|
115
|
+
* The derived args are stored atomically with the data.
|
|
116
|
+
*
|
|
117
|
+
* @param blockId - The block ID
|
|
118
|
+
* @param payload - Storage mutation payload with operation and value
|
|
119
|
+
* @param author - Optional author marker for collaborative editing
|
|
120
|
+
*/
|
|
121
|
+
mutateBlockStorage(blockId: string, payload: {
|
|
122
|
+
operation: string;
|
|
123
|
+
value: unknown;
|
|
124
|
+
}, author?: AuthorMarker): Promise<void>;
|
|
106
125
|
/** Update block settings */
|
|
107
126
|
setBlockSettings(blockId: string, newValue: BlockSettings): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Sets raw block storage content directly.
|
|
129
|
+
* This bypasses all normalization and VM transformations.
|
|
130
|
+
*
|
|
131
|
+
* @param blockId The block to set storage for
|
|
132
|
+
* @param rawStorageJson Raw storage as JSON string
|
|
133
|
+
*/
|
|
134
|
+
setBlockStorageRaw(blockId: string, rawStorageJson: string): Promise<void>;
|
|
108
135
|
/** Resets arguments and ui state of the block to initial state */
|
|
109
136
|
resetBlockArgsAndUiState(blockId: string, author?: AuthorMarker): Promise<void>;
|
|
110
137
|
private getBlockComputables;
|
|
@@ -112,7 +139,7 @@ export declare class Project {
|
|
|
112
139
|
* Returns a computable, that can be used to retrieve and watch full block state,
|
|
113
140
|
* including outputs, arguments, ui state.
|
|
114
141
|
* */
|
|
115
|
-
getBlockState(blockId: string): Computable<
|
|
142
|
+
getBlockState(blockId: string): Computable<BlockStateInternalV3>;
|
|
116
143
|
/**
|
|
117
144
|
* Returns a computable, that can be used to retrieve and watch path of the
|
|
118
145
|
* folder containing frontend code.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/middle_layer/project.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,KAAK,EAG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AO,CAAC,IAAI,CAAC;IAOvF,kEAAkE;IACrD,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B5F,OAAO,CAAC,mBAAmB;IA2C3B;;;SAGK;IACE,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC,oBAAoB,CAAC;IAIvE;;;SAGK;IACE,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CAAC,YAAY,CAAC;IAc/E,sCAAsC;IACzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BrC,kBAAkB;IACL,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjD,SAAS,IAAI,oBAAoB,EAAE;WAItB,IAAI,CAAC,GAAG,EAAE,sBAAsB,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CA4BzF"}
|
|
@@ -6,7 +6,7 @@ import { withProject, withProjectAuthored } from '../mutator/project.js';
|
|
|
6
6
|
import { SynchronizedTreeState, treeDumpStats } from '@milaboratories/pl-tree';
|
|
7
7
|
import { setTimeout } from 'node:timers/promises';
|
|
8
8
|
import { frontendData } from './frontend_path.js';
|
|
9
|
-
import { blockOutputs,
|
|
9
|
+
import { blockOutputs, getBlockParameters } from './block.js';
|
|
10
10
|
import { projectFieldName } from '../model/project_model.js';
|
|
11
11
|
import { cachedDeserialize, notEmpty } from '@milaboratories/ts-helpers';
|
|
12
12
|
import { activeConfigs } from './active_cfg.js';
|
|
@@ -82,7 +82,7 @@ class Project {
|
|
|
82
82
|
}, { name: 'doRefresh', lockId: this.projectLockId });
|
|
83
83
|
await this.activeConfigs.getValue();
|
|
84
84
|
await setTimeout(this.env.ops.projectRefreshInterval, this.abortController.signal);
|
|
85
|
-
// Block computables
|
|
85
|
+
// Block computables housekeeping
|
|
86
86
|
const overviewLight = await this.overviewLight.getValue();
|
|
87
87
|
const existingBlocks = new Set(overviewLight.listOfBlocks);
|
|
88
88
|
// Doing cleanup for deleted blocks
|
|
@@ -130,16 +130,16 @@ class Project {
|
|
|
130
130
|
const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);
|
|
131
131
|
const blockCfgContainer = await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec);
|
|
132
132
|
const blockCfg = extractConfig(blockCfgContainer); // full content of this var should never be persisted
|
|
133
|
+
// Build NewBlockSpec based on model API version
|
|
134
|
+
const newBlockSpec = blockCfg.modelAPIVersion === 2
|
|
135
|
+
? { storageMode: 'fromModel', blockPack: preparedBp }
|
|
136
|
+
: { storageMode: 'legacy', blockPack: preparedBp, legacyState: canonicalize({ args: blockCfg.initialArgs, uiState: blockCfg.initialUiState }) };
|
|
133
137
|
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {
|
|
134
138
|
return mut.addBlock({
|
|
135
139
|
id: blockId,
|
|
136
140
|
label: blockLabel,
|
|
137
141
|
renderingMode: blockCfg.renderingMode,
|
|
138
|
-
},
|
|
139
|
-
args: canonicalize(blockCfg.initialArgs),
|
|
140
|
-
uiState: canonicalize(blockCfg.initialUiState),
|
|
141
|
-
blockPack: preparedBp,
|
|
142
|
-
}, before);
|
|
142
|
+
}, newBlockSpec, before);
|
|
143
143
|
}, {
|
|
144
144
|
retryOptions: {
|
|
145
145
|
...DefaultRetryOptions,
|
|
@@ -175,7 +175,13 @@ class Project {
|
|
|
175
175
|
async updateBlockPack(blockId, blockPackSpec, resetArgs = false, author) {
|
|
176
176
|
const preparedBp = await this.env.bpPreparer.prepare(blockPackSpec);
|
|
177
177
|
const blockCfg = extractConfig(await this.env.bpPreparer.getBlockConfigContainer(blockPackSpec));
|
|
178
|
-
|
|
178
|
+
// resetState signals to mutator to reset storage
|
|
179
|
+
// For v2+ blocks: mutator gets initial storage directly via getInitialStorageInVM
|
|
180
|
+
// For v1 blocks: we pass the legacy state format
|
|
181
|
+
const resetState = resetArgs
|
|
182
|
+
? { state: blockCfg.modelAPIVersion === 2 ? {} : { args: blockCfg.initialArgs, uiState: blockCfg.initialUiState } }
|
|
183
|
+
: undefined;
|
|
184
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.migrateBlockPack(blockId, preparedBp, resetState), { name: 'updateBlockPack', lockId: this.projectLockId });
|
|
179
185
|
await this.projectTree.refreshState();
|
|
180
186
|
}
|
|
181
187
|
/** Deletes a block with all associated data. */
|
|
@@ -236,52 +242,72 @@ class Project {
|
|
|
236
242
|
await withProject(this.env.projectHelper, this.env.pl, this.rid, (mut) => mut.stopProduction(blockId), { name: 'stopBlock', lockId: this.projectLockId });
|
|
237
243
|
await this.projectTree.refreshState();
|
|
238
244
|
}
|
|
239
|
-
// /** Update block label. */
|
|
240
|
-
// public async setBlockLabel(blockId: string, label: string, author?: AuthorMarker) {
|
|
241
|
-
// await withProjectAuthored(this.env.pl, this.rid, author, (mut) => {
|
|
242
|
-
// mut.setBlockLabel(blockId, label);
|
|
243
|
-
// });
|
|
244
|
-
// await this.projectTree.refreshState();
|
|
245
|
-
// }
|
|
246
245
|
/**
|
|
246
|
+
* @deprecated Use mutateBlockStorage() for V3 blocks.
|
|
247
247
|
* Sets block args, and changes whole project state accordingly.
|
|
248
248
|
* Along with setting arguments one can specify author marker, that will be
|
|
249
249
|
* transactionally associated with the block, to facilitate conflict resolution
|
|
250
250
|
* in collaborative editing scenario.
|
|
251
251
|
* */
|
|
252
252
|
async setBlockArgs(blockId, args, author) {
|
|
253
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>
|
|
253
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {
|
|
254
|
+
const state = mut.mergeBlockState(blockId, { args });
|
|
255
|
+
mut.setStates([{ modelAPIVersion: 1, blockId, state }]);
|
|
256
|
+
}, { name: 'setBlockArgs', lockId: this.projectLockId });
|
|
254
257
|
await this.projectTree.refreshState();
|
|
255
258
|
}
|
|
256
259
|
/**
|
|
260
|
+
* @deprecated Use mutateBlockStorage() for V3 blocks.
|
|
257
261
|
* Sets ui block state associated with the block.
|
|
258
262
|
* Along with setting arguments one can specify author marker, that will be
|
|
259
263
|
* transactionally associated with the block, to facilitate conflict resolution
|
|
260
264
|
* in collaborative editing scenario.
|
|
261
265
|
* */
|
|
262
266
|
async setUiState(blockId, uiState, author) {
|
|
263
|
-
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) =>
|
|
267
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {
|
|
268
|
+
const state = mut.mergeBlockState(blockId, { uiState });
|
|
269
|
+
mut.setStates([{ modelAPIVersion: 1, blockId, state }]);
|
|
270
|
+
}, { name: 'setUiState', lockId: this.projectLockId });
|
|
264
271
|
await this.projectTree.refreshState();
|
|
265
272
|
}
|
|
266
273
|
/**
|
|
267
|
-
*
|
|
268
|
-
* */
|
|
269
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
270
|
-
async setNavigationState(blockId, state) {
|
|
271
|
-
this.navigationStates.setState(blockId, state);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
+
* @deprecated Use mutateBlockStorage() for V3 blocks.
|
|
274
275
|
* Sets block args and ui state, and changes the whole project state accordingly.
|
|
275
276
|
* Along with setting arguments one can specify author marker, that will be
|
|
276
277
|
* transactionally associated with the block, to facilitate conflict resolution
|
|
277
278
|
* in collaborative editing scenario.
|
|
278
279
|
* */
|
|
279
|
-
async setBlockArgsAndUiState(blockId, args,
|
|
280
|
+
async setBlockArgsAndUiState(blockId, args, // keep for v1/v2 compatibility
|
|
281
|
+
uiState, // keep for v1/v2 compatibility
|
|
282
|
+
author) {
|
|
283
|
+
// Normalize to unified state format { args, uiState } for v1/v2 blocks
|
|
284
|
+
const state = { args, uiState };
|
|
280
285
|
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => {
|
|
281
|
-
mut.setStates([{
|
|
286
|
+
mut.setStates([{ modelAPIVersion: 1, blockId, state }]);
|
|
282
287
|
}, { name: 'setBlockArgsAndUiState', lockId: this.projectLockId });
|
|
283
288
|
await this.projectTree.refreshState();
|
|
284
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Sets navigation state.
|
|
292
|
+
* */
|
|
293
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
294
|
+
async setNavigationState(blockId, state) {
|
|
295
|
+
this.navigationStates.setState(blockId, state);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Mutates block storage for Model API v3 blocks.
|
|
299
|
+
* Applies a storage operation (e.g., 'update-data') which triggers
|
|
300
|
+
* args derivation (args(data) and prerunArgs(data)).
|
|
301
|
+
* The derived args are stored atomically with the data.
|
|
302
|
+
*
|
|
303
|
+
* @param blockId - The block ID
|
|
304
|
+
* @param payload - Storage mutation payload with operation and value
|
|
305
|
+
* @param author - Optional author marker for collaborative editing
|
|
306
|
+
*/
|
|
307
|
+
async mutateBlockStorage(blockId, payload, author) {
|
|
308
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, author, (mut) => mut.setStates([{ modelAPIVersion: 2, blockId, payload }]), { name: 'mutateBlockStorage', lockId: this.projectLockId });
|
|
309
|
+
await this.projectTree.refreshState();
|
|
310
|
+
}
|
|
285
311
|
/** Update block settings */
|
|
286
312
|
async setBlockSettings(blockId, newValue) {
|
|
287
313
|
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {
|
|
@@ -289,6 +315,19 @@ class Project {
|
|
|
289
315
|
}, { name: 'setBlockSettings' });
|
|
290
316
|
await this.projectTree.refreshState();
|
|
291
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Sets raw block storage content directly.
|
|
320
|
+
* This bypasses all normalization and VM transformations.
|
|
321
|
+
*
|
|
322
|
+
* @param blockId The block to set storage for
|
|
323
|
+
* @param rawStorageJson Raw storage as JSON string
|
|
324
|
+
*/
|
|
325
|
+
async setBlockStorageRaw(blockId, rawStorageJson) {
|
|
326
|
+
await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, undefined, (mut) => {
|
|
327
|
+
mut.setBlockStorageRaw(blockId, rawStorageJson);
|
|
328
|
+
}, { name: 'setBlockStorageRaw' });
|
|
329
|
+
await this.projectTree.refreshState();
|
|
330
|
+
}
|
|
292
331
|
/** Resets arguments and ui state of the block to initial state */
|
|
293
332
|
async resetBlockArgsAndUiState(blockId, author) {
|
|
294
333
|
await this.env.pl.withWriteTx('BlockInputsReset', async (tx) => {
|
|
@@ -298,7 +337,15 @@ class Project {
|
|
|
298
337
|
const bpData = await tx.getResourceData(bpRid, false);
|
|
299
338
|
const config = extractConfig(cachedDeserialize(notEmpty(bpData.data)).config);
|
|
300
339
|
await withProjectAuthored(this.env.projectHelper, tx, this.rid, author, (prj) => {
|
|
301
|
-
|
|
340
|
+
if (config.modelAPIVersion === 2) {
|
|
341
|
+
// V2+: Reset to initial storage via VM
|
|
342
|
+
prj.resetToInitialStorage(blockId);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
// V1: Use legacy state format
|
|
346
|
+
const initialState = { args: config.initialArgs, uiState: config.initialUiState };
|
|
347
|
+
prj.setStates([{ modelAPIVersion: 1, blockId, state: initialState }]);
|
|
348
|
+
}
|
|
302
349
|
}, { name: 'resetBlockArgsAndUiState', lockId: this.projectLockId });
|
|
303
350
|
await tx.commit();
|
|
304
351
|
});
|
|
@@ -313,7 +360,7 @@ class Project {
|
|
|
313
360
|
const outputs = blockOutputs(this.projectTree.entry(), blockId, this.env);
|
|
314
361
|
const fullState = Computable.make((ctx) => {
|
|
315
362
|
return {
|
|
316
|
-
|
|
363
|
+
parameters: getBlockParameters(this.projectTree.entry(), blockId, ctx),
|
|
317
364
|
outputs,
|
|
318
365
|
navigationState: this.navigationStates.getState(blockId),
|
|
319
366
|
overview: this.overview,
|
|
@@ -326,7 +373,7 @@ class Project {
|
|
|
326
373
|
? convertErrorsToStrings(v.outputs)
|
|
327
374
|
: v.outputs;
|
|
328
375
|
return {
|
|
329
|
-
...v.
|
|
376
|
+
...v.parameters,
|
|
330
377
|
outputs: newOutputs,
|
|
331
378
|
navigationState: v.navigationState,
|
|
332
379
|
};
|