@milaboratories/pl-middle-layer 1.44.1 → 1.45.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.
@@ -408,7 +408,12 @@ class ProjectMutator {
408
408
  isProduction: this.tx.createValue(plClient.Pl.JsonBool, JSON.stringify(false)),
409
409
  context: ctx,
410
410
  });
411
- this.setBlockField(blockId, 'stagingCtx', plClient.Pl.wrapInEphHolder(this.tx, results.context), 'NotReady');
411
+ // Here we set the staging ctx to the input context of the staging workflow, not the output because exports
412
+ // of one staging context should stay within the same block, and not travel downstream.
413
+ // We may change this decision in the future if wanted to support traveling staging exports downstream.
414
+ this.setBlockField(blockId, 'stagingCtx', plClient.Pl.wrapInEphHolder(this.tx, ctx), 'NotReady');
415
+ // Yet the staging UI Ctx is the output context of the staging workflow, because it is used to form the result pool
416
+ // thus creating a certain discrepancy between staging workflow context behavior and desktop's result pool.
412
417
  this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');
413
418
  this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');
414
419
  }
@@ -721,9 +726,11 @@ class ProjectMutator {
721
726
  }
722
727
  }
723
728
  }
724
- // blocks under stopped blocks, but still having results, goes to limbo
729
+ // blocks under stopped blocks, but having finished production results, goes to limbo
725
730
  for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))
726
731
  this.resetOrLimboProduction(blockId);
732
+ // reset staging outputs for all downstream blocks
733
+ this.getStagingGraph().traverse('downstream', stopped, ({ id }) => this.resetStaging(id));
727
734
  }
728
735
  traverseWithStagingLag(cb) {
729
736
  const lags = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"project.cjs","sources":["../../src/mutator/project.ts"],"sourcesContent":["import type {\n AnyRef,\n AnyResourceRef,\n BasicResourceData,\n PlTransaction,\n ResourceData,\n ResourceId,\n TxOps } from '@milaboratories/pl-client';\nimport {\n ensureResourceIdNotNull,\n field,\n isNotNullResourceId,\n isNullResourceId,\n isResource,\n isResourceId,\n isResourceRef,\n Pl,\n PlClient,\n} from '@milaboratories/pl-client';\nimport { createRenderHeavyBlock, createBContextFromUpstreams } from './template/render_block';\nimport type {\n Block,\n ProjectStructure,\n ProjectField,\n ProjectRenderingState } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectStructureKey,\n parseProjectField,\n projectFieldName,\n SchemaVersionCurrent,\n SchemaVersionKey,\n ProjectResourceType,\n InitialBlockStructure,\n InitialProjectRenderingState,\n ProjectMetaKey,\n InitialBlockMeta,\n blockArgsAuthorKey,\n ProjectLastModifiedTimestamp,\n ProjectCreatedTimestamp,\n ProjectStructureAuthorKey,\n getServiceTemplateField,\n FieldsToDuplicate,\n} from '../model/project_model';\nimport { BlockPackTemplateField, createBlockPack } from './block-pack/block_pack';\nimport type {\n BlockGraph,\n ProductionGraphBlockInfo } from '../model/project_model_util';\nimport {\n allBlocks,\n graphDiff,\n productionGraph,\n stagingGraph,\n} from '../model/project_model_util';\nimport type { BlockPackSpecPrepared } from '../model';\nimport type {\n AuthorMarker,\n BlockPackSpec,\n BlockSettings,\n ProjectMeta,\n} from '@milaboratories/pl-model-middle-layer';\nimport {\n InitialBlockSettings,\n} from '@milaboratories/pl-model-middle-layer';\nimport Denque from 'denque';\nimport { exportContext, getPreparedExportTemplateEnvelope } from './context_export';\nimport { loadTemplate } from './template/template_loading';\nimport { cachedDeserialize, notEmpty, canonicalJsonGzBytes, canonicalJsonBytes } from '@milaboratories/ts-helpers';\nimport type { ProjectHelper } from '../model/project_helper';\nimport { extractConfig, UiError, type BlockConfig } from '@platforma-sdk/model';\nimport { getDebugFlags } from '../debug';\nimport type { BlockPackInfo } from '../model/block_pack';\n\ntype FieldStatus = 'NotReady' | 'Ready' | 'Error';\n\ninterface BlockFieldState {\n modCount: number;\n ref?: AnyRef;\n status?: FieldStatus;\n value?: Uint8Array;\n}\n\ntype BlockFieldStates = Partial<Record<ProjectField['fieldName'], BlockFieldState>>;\ntype BlockFieldStateValue = Omit<BlockFieldState, 'modCount'>;\n\ninterface BlockInfoState {\n readonly id: string;\n readonly fields: BlockFieldStates;\n blockConfig?: BlockConfig;\n blockPack?: BlockPackSpec;\n}\n\nfunction cached<ModId, T>(modIdCb: () => ModId, valueCb: () => T): () => T {\n let initialized = false;\n let lastModId: ModId | undefined = undefined;\n let value: T | undefined = undefined;\n return () => {\n if (!initialized) {\n initialized = true;\n lastModId = modIdCb();\n value = valueCb();\n return value;\n }\n const currentModId = modIdCb();\n if (lastModId !== currentModId) {\n lastModId = currentModId;\n value = valueCb();\n }\n return valueCb();\n };\n}\n\nclass BlockInfo {\n constructor(\n public readonly id: string,\n public readonly fields: BlockFieldStates,\n public readonly config: BlockConfig,\n public readonly source: BlockPackSpec,\n ) {}\n\n public check() {\n // state assertions\n\n if ((this.fields.prodOutput === undefined) !== (this.fields.prodCtx === undefined))\n throw new Error('inconsistent prod fields');\n\n if ((this.fields.stagingOutput === undefined) !== (this.fields.stagingCtx === undefined))\n throw new Error('inconsistent stage fields');\n\n if (\n (this.fields.prodOutputPrevious === undefined)\n !== (this.fields.prodCtxPrevious === undefined)\n )\n throw new Error('inconsistent prod cache fields');\n\n if (\n (this.fields.stagingOutputPrevious === undefined)\n !== (this.fields.stagingCtxPrevious === undefined)\n )\n throw new Error('inconsistent stage cache fields');\n\n if (this.fields.blockPack === undefined) throw new Error('no block pack field');\n\n if (this.fields.currentArgs === undefined) throw new Error('no current args field');\n }\n\n private readonly currentArgsC = cached(\n () => this.fields.currentArgs!.modCount,\n () => cachedDeserialize(this.fields.currentArgs!.value!),\n );\n\n private readonly prodArgsC = cached(\n () => this.fields.prodArgs?.modCount,\n () => {\n const bin = this.fields.prodArgs?.value;\n if (bin === undefined) return undefined;\n return cachedDeserialize(bin);\n },\n );\n\n get currentArgs(): unknown {\n return this.currentArgsC();\n }\n\n get stagingRendered(): boolean {\n return this.fields.stagingCtx !== undefined;\n }\n\n get productionRendered(): boolean {\n return this.fields.prodCtx !== undefined;\n }\n\n get productionHasErrors(): boolean {\n return this.fields.prodUiCtx?.status === 'Error';\n }\n\n private readonly productionStaleC: () => boolean = cached(\n () => `${this.fields.currentArgs!.modCount}_${this.fields.prodArgs?.modCount}`,\n () =>\n this.fields.prodArgs === undefined\n || Buffer.compare(this.fields.currentArgs!.value!, this.fields.prodArgs.value!) !== 0,\n );\n\n // get productionStale(): boolean {\n // return this.productionRendered && this.productionStaleC() && ;\n // }\n\n get requireProductionRendering(): boolean {\n return !this.productionRendered || this.productionStaleC() || this.productionHasErrors;\n }\n\n get prodArgs(): unknown {\n return this.prodArgsC();\n }\n\n public getTemplate(tx: PlTransaction): AnyRef {\n return tx.getFutureFieldValue(\n Pl.unwrapHolder(tx, this.fields.blockPack!.ref!),\n BlockPackTemplateField,\n 'Input',\n );\n }\n}\n\nexport interface NewBlockSpec {\n blockPack: BlockPackSpecPrepared;\n args: string;\n uiState: string;\n}\n\nconst NoNewBlocks = (blockId: string) => {\n throw new Error(`No new block info for ${blockId}`);\n};\n\nexport interface SetStatesRequest {\n blockId: string;\n args?: unknown;\n uiState?: unknown;\n}\n\ntype _GraphInfoFields =\n | 'stagingUpstream'\n | 'stagingDownstream'\n | 'futureProductionUpstream'\n | 'futureProductionDownstream'\n | 'actualProductionUpstream'\n | 'actualProductionDownstream';\n\nexport type ArgsAndUiState = {\n args: unknown;\n uiState: unknown;\n};\n\nexport class ProjectMutator {\n private globalModCount = 0;\n private fieldsChanged: boolean = false;\n\n //\n // Change trackers\n //\n\n private lastModifiedChanged = false;\n private structureChanged = false;\n private metaChanged = false;\n private renderingStateChanged = false;\n\n /** Set blocks will be assigned current mutator author marker on save */\n private readonly blocksWithChangedInputs = new Set<string>();\n\n constructor(\n public readonly rid: ResourceId,\n private readonly tx: PlTransaction,\n private readonly author: AuthorMarker | undefined,\n private readonly schema: string,\n private lastModified: number,\n private meta: ProjectMeta,\n private struct: ProjectStructure,\n private readonly renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>,\n private readonly blocksInLimbo: Set<string>,\n private readonly blockInfos: Map<string, BlockInfo>,\n private readonly ctxExportTplHolder: AnyResourceRef,\n private readonly projectHelper: ProjectHelper,\n ) {}\n\n private fixProblemsAndMigrate() {\n // Fixing problems introduced by old code\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodArgs === undefined\n || blockInfo.fields.prodOutput === undefined\n || blockInfo.fields.prodCtx === undefined\n )\n this.deleteBlockFields(blockInfo.id, 'prodArgs', 'prodOutput', 'prodCtx');\n });\n\n // Migration for addition of block settings field\n let initialBlockSettings: Omit<BlockFieldState, 'modCount'> | undefined;\n this.blockInfos.forEach((blockInfo) => {\n if (blockInfo.fields.blockSettings === undefined) {\n if (initialBlockSettings === undefined)\n initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);\n this.setBlockFieldObj(blockInfo.id, 'blockSettings', initialBlockSettings);\n }\n });\n }\n\n get wasModified(): boolean {\n return (\n this.lastModifiedChanged\n || this.structureChanged\n || this.fieldsChanged\n || this.metaChanged\n || this.renderingStateChanged\n );\n }\n\n get structure(): ProjectStructure {\n // clone\n return JSON.parse(JSON.stringify(this.struct)) as ProjectStructure;\n }\n\n //\n // Graph calculation\n //\n\n private stagingGraph: BlockGraph | undefined = undefined;\n private pendingProductionGraph: BlockGraph | undefined = undefined;\n private actualProductionGraph: BlockGraph | undefined = undefined;\n\n private getStagingGraph(): BlockGraph {\n if (this.stagingGraph === undefined) this.stagingGraph = stagingGraph(this.struct);\n return this.stagingGraph;\n }\n\n private getProductionGraphBlockInfo(blockId: string, prod: boolean): ProductionGraphBlockInfo | undefined {\n const bInfo = this.getBlockInfo(blockId);\n\n let argsField: BlockFieldState;\n let args: unknown;\n\n if (prod) {\n if (bInfo.fields.prodArgs === undefined) return undefined;\n argsField = bInfo.fields.prodArgs;\n args = bInfo.prodArgs;\n } else {\n argsField = notEmpty(bInfo.fields.currentArgs);\n args = bInfo.currentArgs;\n }\n\n const blockPackField = notEmpty(bInfo.fields.blockPack);\n\n if (isResourceId(argsField.ref!) && isResourceId(blockPackField.ref!))\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args,\n { argsRid: argsField.ref, blockPackRid: blockPackField.ref }),\n };\n else\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args),\n };\n }\n\n private getPendingProductionGraph(): BlockGraph {\n if (this.pendingProductionGraph === undefined)\n this.pendingProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, false),\n );\n return this.pendingProductionGraph;\n }\n\n private getActualProductionGraph(): BlockGraph {\n if (this.actualProductionGraph === undefined)\n this.actualProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n return this.actualProductionGraph;\n }\n\n //\n // Generic helpers to interact with project state\n //\n\n private getBlockInfo(blockId: string): BlockInfo {\n const info = this.blockInfos.get(blockId);\n if (info === undefined) throw new Error(`No such block: ${blockId}`);\n return info;\n }\n\n private createJsonFieldValueByContent(content: string): BlockFieldStateValue {\n const value = Buffer.from(content);\n const ref = this.tx.createValue(Pl.JsonObject, value);\n return { ref, value, status: 'Ready' };\n }\n\n private createJsonFieldValue(obj: unknown): BlockFieldStateValue {\n return this.createJsonFieldValueByContent(JSON.stringify(obj));\n }\n\n private getBlock(blockId: string): Block {\n for (const block of allBlocks(this.struct)) if (block.id === blockId) return block;\n throw new Error('block not found');\n }\n\n private setBlockFieldObj(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n state: BlockFieldStateValue,\n ) {\n const fid = field(this.rid, projectFieldName(blockId, fieldName));\n\n if (state.ref === undefined) throw new Error('Can\\'t set value with empty ref');\n\n if (this.getBlockInfo(blockId).fields[fieldName] === undefined)\n this.tx.createField(fid, 'Dynamic', state.ref);\n else this.tx.setField(fid, state.ref);\n\n this.getBlockInfo(blockId).fields[fieldName] = {\n modCount: this.globalModCount++,\n ...state,\n };\n\n this.fieldsChanged = true;\n }\n\n private setBlockField(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n ref: AnyRef,\n status: FieldStatus,\n value?: Uint8Array,\n ) {\n this.setBlockFieldObj(blockId, fieldName, { ref, status, value });\n }\n\n private deleteBlockFields(blockId: string, ...fieldNames: (keyof BlockFieldStates)[]): boolean {\n let deleted = false;\n const info = this.getBlockInfo(blockId);\n for (const fieldName of fieldNames) {\n const fields = info.fields;\n if (!(fieldName in fields)) continue;\n this.tx.removeField(field(this.rid, projectFieldName(blockId, fieldName)));\n delete fields[fieldName];\n this.fieldsChanged = true;\n deleted = true;\n }\n return deleted;\n }\n\n private updateLastModified() {\n this.lastModified = Date.now();\n this.lastModifiedChanged = true;\n }\n\n //\n // Main project actions\n //\n\n private resetStagingRefreshTimestamp() {\n this.renderingState.stagingRefreshTimestamp = Date.now();\n this.renderingStateChanged = true;\n }\n\n private resetStaging(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.stagingOutput?.status === 'Ready'\n && fields.stagingCtx?.status === 'Ready'\n && fields.stagingUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'stagingOutputPrevious', fields.stagingOutput);\n this.setBlockFieldObj(blockId, 'stagingCtxPrevious', fields.stagingCtx);\n this.setBlockFieldObj(blockId, 'stagingUiCtxPrevious', fields.stagingUiCtx);\n }\n if (this.deleteBlockFields(blockId, 'stagingOutput', 'stagingCtx', 'stagingUiCtx'))\n this.resetStagingRefreshTimestamp();\n }\n\n private resetProduction(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.prodOutput?.status === 'Ready'\n && fields.prodCtx?.status === 'Ready'\n && fields.prodUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'prodOutputPrevious', fields.prodOutput);\n this.setBlockFieldObj(blockId, 'prodCtxPrevious', fields.prodCtx);\n this.setBlockFieldObj(blockId, 'prodUiCtxPrevious', fields.prodUiCtx);\n }\n this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs');\n }\n\n /** Running blocks are reset, already computed moved to limbo. Returns if\n * either of the actions were actually performed.\n * This method ensures the block is left in a consistent state that passes check() constraints. */\n private resetOrLimboProduction(blockId: string): boolean {\n const fields = this.getBlockInfo(blockId).fields;\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return false;\n\n // limbo - keep the ready production results but clean up cache\n this.blocksInLimbo.add(blockId);\n this.renderingStateChanged = true;\n\n // doing some gc - clean up previous cache fields\n this.deleteBlockFields(blockId, 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');\n\n return true;\n } else {\n // reset - clean up any partial/inconsistent production stat\n return this.deleteBlockFields(\n blockId,\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n }\n }\n\n /** Optimally sets inputs for multiple blocks in one go */\n public setStates(requests: SetStatesRequest[]) {\n const changedArgs: string[] = [];\n let somethingChanged = false;\n for (const req of requests) {\n const info = this.getBlockInfo(req.blockId);\n let blockChanged = false;\n for (const stateKey of ['args', 'uiState'] as const) {\n if (!(stateKey in req)) continue;\n const statePart = req[stateKey];\n if (statePart === undefined || statePart === null)\n throw new Error(\n `Can't set ${stateKey} to null or undefined, please omit the key if you don't want to change it`,\n );\n\n const fieldName = stateKey === 'args' ? 'currentArgs' : 'uiState';\n\n let data: Uint8Array;\n let gzipped: boolean = false;\n if (stateKey === 'args') {\n // don't gzip args, workflow code can't uncompress gzip yet\n data = canonicalJsonBytes(statePart);\n } else {\n const { data: binary, isGzipped } = canonicalJsonGzBytes(statePart);\n data = binary;\n gzipped = isGzipped;\n }\n if (Buffer.compare(info.fields[fieldName]!.value!, data) === 0) continue;\n // console.log('setting', fieldName, gzipped, data.length);\n const statePartRef = this.tx.createValue(gzipped ? Pl.JsonGzObject : Pl.JsonObject, data);\n this.setBlockField(req.blockId, fieldName, statePartRef, 'Ready', data);\n\n blockChanged = true;\n if (stateKey === 'args') changedArgs.push(req.blockId);\n }\n if (blockChanged) {\n // will be assigned our author marker\n this.blocksWithChangedInputs.add(req.blockId);\n somethingChanged = true;\n }\n }\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', changedArgs, ({ id }) => this.resetStaging(id));\n\n if (somethingChanged) this.updateLastModified();\n }\n\n public setBlockSettings(blockId: string, newValue: BlockSettings): void {\n this.setBlockFieldObj(blockId, 'blockSettings', this.createJsonFieldValue(newValue));\n this.updateLastModified();\n }\n\n private createProdCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['prodCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private createStagingCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['stagingCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['stagingCtx'].ref));\n if (info.fields['prodCtx']?.ref !== undefined)\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private exportCtx(ctx: AnyRef): AnyRef {\n return exportContext(this.tx, Pl.unwrapHolder(this.tx, this.ctxExportTplHolder), ctx);\n }\n\n private renderStagingFor(blockId: string) {\n this.resetStaging(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode !== 'Heavy') throw new Error('not supported yet');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),\n context: ctx,\n });\n\n this.setBlockField(\n blockId,\n 'stagingCtx',\n Pl.wrapInEphHolder(this.tx, results.context),\n 'NotReady',\n );\n\n this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');\n\n this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');\n }\n\n private renderProductionFor(blockId: string) {\n this.resetProduction(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode === 'Light')\n throw new Error('Can\\'t render production for light block.');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(true)),\n context: ctx,\n });\n this.setBlockField(\n blockId,\n 'prodCtx',\n Pl.wrapInEphHolder(this.tx, results.context),\n 'NotReady',\n );\n this.setBlockField(blockId, 'prodUiCtx', this.exportCtx(results.context), 'NotReady');\n this.setBlockField(blockId, 'prodOutput', results.result, 'NotReady');\n\n // saving inputs for which we rendered the production\n this.setBlockFieldObj(blockId, 'prodArgs', info.fields.currentArgs!);\n\n // removing block from limbo as we juts rendered fresh production for it\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n //\n // Structure changes\n //\n\n private initializeNewBlock(blockId: string, spec: NewBlockSpec): void {\n const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);\n this.blockInfos.set(blockId, info);\n\n // block pack\n const bp = createBlockPack(this.tx, spec.blockPack);\n this.setBlockField(blockId, 'blockPack', Pl.wrapInHolder(this.tx, bp), 'NotReady');\n\n // settings\n this.setBlockFieldObj(\n blockId,\n 'blockSettings',\n this.createJsonFieldValue(InitialBlockSettings),\n );\n\n // args\n this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValueByContent(spec.args));\n\n // uiState\n this.setBlockFieldObj(blockId, 'uiState', this.createJsonFieldValueByContent(spec.uiState ?? '{}'));\n\n // checking structure\n info.check();\n }\n\n private getFieldNamesToDuplicate(blockId: string): Set<ProjectField['fieldName']> {\n const fields = this.getBlockInfo(blockId).fields;\n\n const diff = <T>(setA: Set<T>, setB: Set<T>): Set<T> => new Set([...setA].filter((x) => !setB.has(x)));\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return FieldsToDuplicate;\n\n return diff(FieldsToDuplicate, new Set([\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n } else {\n return diff(FieldsToDuplicate, new Set([\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n }\n }\n\n private initializeBlockDuplicate(blockId: string, originalBlockInfo: BlockInfo) {\n const info = new BlockInfo(\n blockId,\n {},\n originalBlockInfo.config,\n originalBlockInfo.source,\n );\n\n this.blockInfos.set(blockId, info);\n\n const fieldNamesToDuplicate = this.getFieldNamesToDuplicate(blockId);\n\n // Copy all fields from original block to new block by sharing references\n for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) {\n if (fieldNamesToDuplicate.has(fieldName as ProjectField['fieldName']) && fieldState && fieldState.ref) {\n this.setBlockFieldObj(blockId, fieldName as keyof BlockFieldStates, {\n ref: fieldState.ref,\n status: fieldState.status,\n value: fieldState.value,\n });\n }\n }\n\n this.resetOrLimboProduction(blockId);\n\n info.check();\n }\n\n /** Very generic method, better check for more specialized case-specific methods first. */\n public updateStructure(\n newStructure: ProjectStructure,\n newBlockInitializer: (blockId: string) => void = NoNewBlocks,\n ): void {\n const currentStagingGraph = this.getStagingGraph();\n const currentActualProductionGraph = this.getActualProductionGraph();\n\n const newStagingGraph = stagingGraph(newStructure);\n\n const stagingDiff = graphDiff(currentStagingGraph, newStagingGraph);\n\n // removing blocks\n for (const blockId of stagingDiff.onlyInA) {\n const { fields } = this.getBlockInfo(blockId);\n this.deleteBlockFields(blockId, ...(Object.keys(fields) as ProjectField['fieldName'][]));\n this.blockInfos.delete(blockId);\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n // creating new blocks\n for (const blockId of stagingDiff.onlyInB) {\n newBlockInitializer(blockId);\n }\n\n // resetting stagings affected by topology change\n for (const blockId of stagingDiff.different) this.resetStaging(blockId);\n\n // new actual production graph without new blocks\n const newActualProductionGraph = productionGraph(\n newStructure,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n\n const prodDiff = graphDiff(currentActualProductionGraph, newActualProductionGraph);\n\n // applying changes due to topology change in production to affected nodes and\n // all their downstreams\n currentActualProductionGraph.traverse('downstream', [...prodDiff.different], (node) => {\n this.resetOrLimboProduction(node.id);\n });\n\n if (\n stagingDiff.onlyInB.size > 0\n || stagingDiff.onlyInA.size > 0\n || stagingDiff.different.size > 0\n )\n this.resetStagingRefreshTimestamp();\n\n this.struct = newStructure;\n this.structureChanged = true;\n this.stagingGraph = undefined;\n this.pendingProductionGraph = undefined;\n this.actualProductionGraph = undefined;\n\n this.updateLastModified();\n }\n\n //\n // Structure change helpers\n //\n\n public addBlock(block: Block, spec: NewBlockSpec, before?: string): void {\n const newStruct = this.structure; // copy current structure\n if (before === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(block);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === before);\n if (idx < 0) continue;\n group.blocks.splice(idx, 0, block);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${before}`);\n }\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== block.id) throw new Error('Unexpected');\n this.initializeNewBlock(blockId, spec);\n });\n }\n\n /**\n * Duplicates an existing block by copying all its fields and structure.\n * This method creates a deep copy of the block at the mutator level.\n *\n * @param originalBlockId id of the block to duplicate\n * @param newBlockId id for the new duplicated block\n * @param after id of the block to insert new block after\n */\n public duplicateBlock(originalBlockId: string, newBlockId: string, after?: string): void {\n // Get the original block from structure\n const originalBlock = this.getBlock(originalBlockId);\n const originalBlockInfo = this.getBlockInfo(originalBlockId);\n\n // Create new block in structure\n const newBlock: Block = {\n id: newBlockId,\n label: originalBlock.label,\n renderingMode: originalBlock.renderingMode,\n };\n\n // Add the new block to structure\n const newStruct = this.structure; // copy current structure\n if (after === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(newBlock);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === after);\n if (idx < 0) continue;\n group.blocks.splice(idx + 1, 0, newBlock);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${after}`);\n }\n\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== newBlockId) throw new Error('Unexpected');\n this.initializeBlockDuplicate(blockId, originalBlockInfo);\n });\n }\n\n public deleteBlock(blockId: string): void {\n const newStruct = this.structure; // copy current structure\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === blockId);\n if (idx < 0) continue;\n group.blocks.splice(idx, 1);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${blockId}`);\n this.updateStructure(newStruct);\n }\n\n //\n // Block-pack migration\n //\n\n public migrateBlockPack(blockId: string, spec: BlockPackSpecPrepared, newArgsAndUiState?: ArgsAndUiState): void {\n const info = this.getBlockInfo(blockId);\n\n this.setBlockField(\n blockId,\n 'blockPack',\n Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)),\n 'NotReady',\n );\n\n if (newArgsAndUiState !== undefined) {\n // this will also reset all downstream stagings\n this.setStates([{ blockId, args: newArgsAndUiState.args, uiState: newArgsAndUiState.uiState }]);\n } else {\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', [blockId], ({ id }) => this.resetStaging(id));\n }\n\n // also reset or limbo all downstream productions\n if (info.productionRendered)\n this.getActualProductionGraph().traverse('downstream', [blockId], ({ id }) =>\n this.resetOrLimboProduction(id),\n );\n\n this.updateLastModified();\n }\n\n //\n // Render\n //\n\n public renderProduction(blockIds: string[], addUpstreams: boolean = false): Set<string> {\n const blockIdsSet = new Set(blockIds);\n\n const prodGraph = this.getPendingProductionGraph();\n if (addUpstreams)\n // adding all upstreams automatically\n prodGraph.traverse('upstream', blockIds, (node) => {\n blockIdsSet.add(node.id);\n });\n else // checking that targets contain all upstreams\n for (const blockId of blockIdsSet) {\n const node = prodGraph.nodes.get(blockId);\n if (node === undefined) throw new Error(`Can't find block with id: ${blockId}`);\n for (const upstream of node.upstream)\n if (!blockIdsSet.has(upstream))\n throw new Error('Can\\'t render blocks not including all upstreams.');\n }\n\n // traversing in topological order and rendering target blocks\n const rendered = new Set<string>();\n for (const block of allBlocks(this.structure)) {\n if (!blockIdsSet.has(block.id)) continue;\n\n let render\n = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);\n\n if (!render)\n for (const upstream of prodGraph.nodes.get(block.id)!.upstream)\n if (rendered.has(upstream)) {\n render = true;\n break;\n }\n\n if (render) {\n this.renderProductionFor(block.id);\n rendered.add(block.id);\n }\n }\n\n const renderedArray = [...rendered];\n\n // sending to limbo all downstream blocks\n prodGraph.traverse('downstream', renderedArray, (node) => {\n if (rendered.has(node.id))\n // don't send to limbo blocks that were just rendered\n return;\n this.resetOrLimboProduction(node.id);\n });\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', renderedArray, ({ id }) => {\n // don't reset staging of the first rendered block\n if (renderedArray[0] !== id) this.resetStaging(id);\n });\n\n if (rendered.size > 0) this.updateLastModified();\n\n return rendered;\n }\n\n /** Stops running blocks from the list and modify states of other blocks\n * accordingly */\n public stopProduction(...blockIds: string[]) {\n const activeProdGraph = this.getActualProductionGraph();\n\n // we will stop all blocks listed in request and all their downstreams\n const queue = new Denque(blockIds);\n const queued = new Set(blockIds);\n const stopped: string[] = [];\n\n while (!queue.isEmpty()) {\n const blockId = queue.shift()!;\n const fields = this.getBlockInfo(blockId).fields;\n\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready')\n // skipping finished blocks\n continue;\n\n if (this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs')) {\n // was actually stopped\n stopped.push(blockId);\n\n // will try to stop all its downstreams\n for (const downstream of activeProdGraph.traverseIdsExcludingRoots('downstream', blockId)) {\n if (queued.has(downstream)) continue;\n queue.push(downstream);\n queued.add(downstream);\n }\n }\n }\n\n // blocks under stopped blocks, but still having results, goes to limbo\n for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))\n this.resetOrLimboProduction(blockId);\n }\n\n private traverseWithStagingLag(cb: (blockId: string, lag: number) => void) {\n const lags = new Map<string, number>();\n const stagingGraph = this.getStagingGraph();\n stagingGraph.nodes.forEach((node) => {\n const info = this.getBlockInfo(node.id);\n let lag = info.stagingRendered ? 0 : 1;\n node.upstream.forEach((upstream) => {\n const upstreamLag = lags.get(upstream)!;\n if (upstreamLag === 0) return;\n lag = Math.max(upstreamLag + 1, lag);\n });\n cb(node.id, lag);\n lags.set(node.id, lag);\n });\n }\n\n /** @param stagingRenderingRate rate in blocks per second */\n private refreshStagings(stagingRenderingRate?: number) {\n const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;\n const lagThreshold\n = stagingRenderingRate === undefined\n ? undefined\n : 1 + Math.max(0, (elapsed * stagingRenderingRate) / 1000);\n let rendered = 0;\n this.traverseWithStagingLag((blockId, lag) => {\n if (lag === 0)\n // meaning staging already rendered\n return;\n if (lagThreshold === undefined || lag <= lagThreshold) {\n this.renderStagingFor(blockId);\n rendered++;\n }\n });\n if (rendered > 0) this.resetStagingRefreshTimestamp();\n }\n\n //\n // Meta\n //\n\n /** Updates project metadata */\n public setMeta(meta: ProjectMeta): void {\n this.meta = meta;\n this.metaChanged = true;\n this.updateLastModified();\n }\n\n //\n // Maintenance\n //\n\n /** @param stagingRenderingRate rate in blocks per second */\n public doRefresh(stagingRenderingRate?: number) {\n this.refreshStagings(stagingRenderingRate);\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodCtx?.status === 'Ready'\n && blockInfo.fields.prodOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n if (\n blockInfo.fields.stagingCtx?.status === 'Ready'\n && blockInfo.fields.stagingOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'stagingOutputPrevious',\n 'stagingCtxPrevious',\n 'stagingUiCtxPrevious',\n );\n });\n }\n\n private assignAuthorMarkers() {\n const markerStr = this.author ? JSON.stringify(this.author) : undefined;\n\n for (const blockId of this.blocksWithChangedInputs)\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, blockArgsAuthorKey(blockId));\n else this.tx.setKValue(this.rid, blockArgsAuthorKey(blockId), markerStr);\n\n if (this.metaChanged || this.structureChanged) {\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, ProjectStructureAuthorKey);\n else this.tx.setKValue(this.rid, ProjectStructureAuthorKey, markerStr);\n }\n }\n\n public save() {\n if (!this.wasModified) return;\n\n if (this.lastModifiedChanged)\n this.tx.setKValue(this.rid, ProjectLastModifiedTimestamp, JSON.stringify(this.lastModified));\n\n if (this.structureChanged)\n this.tx.setKValue(this.rid, ProjectStructureKey, JSON.stringify(this.struct));\n\n if (this.renderingStateChanged)\n this.tx.setKValue(\n this.rid,\n BlockRenderingStateKey,\n JSON.stringify({\n ...this.renderingState,\n blocksInLimbo: [...this.blocksInLimbo],\n } as ProjectRenderingState),\n );\n\n if (this.metaChanged) this.tx.setKValue(this.rid, ProjectMetaKey, JSON.stringify(this.meta));\n\n this.assignAuthorMarkers();\n }\n\n public static async load(\n projectHelper: ProjectHelper,\n tx: PlTransaction,\n rid: ResourceId,\n author?: AuthorMarker,\n ): Promise<ProjectMutator> {\n //\n // Sending initial requests to read project state (start of round-trip #1)\n //\n\n const fullResourceStateP = tx.getResourceData(rid, true);\n const schemaP = tx.getKValueJson<string>(rid, SchemaVersionKey);\n const lastModifiedP = tx.getKValueJson<number>(rid, ProjectLastModifiedTimestamp);\n const metaP = tx.getKValueJson<ProjectMeta>(rid, ProjectMetaKey);\n const structureP = tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey);\n const renderingStateP = tx.getKValueJson<ProjectRenderingState>(rid, BlockRenderingStateKey);\n\n const fullResourceState = await fullResourceStateP;\n\n // loading field information\n const blockInfoStates = new Map<string, BlockInfoState>();\n for (const f of fullResourceState.fields) {\n const projectField = parseProjectField(f.name);\n\n // processing only fields with known structure\n if (projectField === undefined) continue;\n\n let info = blockInfoStates.get(projectField.blockId);\n if (info === undefined) {\n info = {\n id: projectField.blockId,\n fields: {},\n };\n blockInfoStates.set(projectField.blockId, info);\n }\n\n info.fields[projectField.fieldName] = isNullResourceId(f.value)\n ? { modCount: 0 }\n : { modCount: 0, ref: f.value };\n }\n\n //\n // Roundtrip #1 not yet finished, but as soon as field list is received,\n // we can start sending requests to read states of referenced resources\n // (start of round-trip #2)\n //\n\n const blockFieldRequests: [BlockInfoState, ProjectField['fieldName'], BlockFieldState, Promise<BasicResourceData | ResourceData>][] = [];\n blockInfoStates.forEach((info) => {\n const fields = info.fields;\n for (const [fName, state] of Object.entries(fields)) {\n if (state.ref === undefined) continue;\n if (!isResource(state.ref) || isResourceRef(state.ref))\n throw new Error('unexpected behaviour');\n const fieldName = fName as ProjectField['fieldName'];\n blockFieldRequests.push([\n info, fieldName,\n state, tx.getResourceData(state.ref, fieldName == 'blockPack')]);\n }\n });\n\n // loading jsons\n const [\n schema,\n lastModified,\n meta,\n structure,\n { stagingRefreshTimestamp, blocksInLimbo },\n ] = await Promise.all([\n schemaP,\n lastModifiedP,\n metaP,\n structureP,\n renderingStateP,\n ]);\n\n // Checking schema version of the project\n if (schema !== SchemaVersionCurrent) {\n if (Number(schema) < Number(SchemaVersionCurrent))\n throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);\n else\n throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);\n }\n\n //\n // <- at this point we have all the responses from round-trip #1\n //\n\n //\n // Receiving responses from round-trip #2 and sending requests to read block pack descriptions\n // (start of round-trip #3)\n //\n\n const blockPackRequests: [BlockInfoState, Promise<BasicResourceData>][] = [];\n for (const [info, fieldName, state, response] of blockFieldRequests) {\n const result = await response;\n state.value = result.data;\n if (isNotNullResourceId(result.error)) state.status = 'Error';\n else if (result.resourceReady || isNotNullResourceId(result.originalResourceId))\n state.status = 'Ready';\n else state.status = 'NotReady';\n\n // For block pack we need to traverse the ref field from the resource data\n if (fieldName === 'blockPack') {\n const refField = (result as ResourceData).fields.find((f) => f.name === Pl.HolderRefField);\n if (refField === undefined)\n throw new Error('Block pack ref field is missing');\n blockPackRequests.push([info, tx.getResourceData(ensureResourceIdNotNull(refField.value), false)]);\n }\n }\n\n //\n // <- at this point we have all the responses from round-trip #2\n //\n\n for (const [info, response] of blockPackRequests) {\n const result = await response;\n const bpInfo = cachedDeserialize<BlockPackInfo>(notEmpty(result.data));\n info.blockConfig = extractConfig(bpInfo.config);\n info.blockPack = bpInfo.source;\n }\n\n //\n // <- at this point we have all the responses from round-trip #3\n //\n\n // loading ctx export template to check if we already have cached materialized template in our project\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n\n // expected field name\n const ctxExportTplCacheFieldName = getServiceTemplateField(ctxExportTplEnvelope.hash);\n const ctxExportTplField = fullResourceState.fields.find(\n (f) => f.name === ctxExportTplCacheFieldName,\n );\n let ctxExportTplHolder: AnyResourceRef;\n if (ctxExportTplField !== undefined)\n ctxExportTplHolder = ensureResourceIdNotNull(ctxExportTplField.value);\n else {\n ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));\n tx.createField(\n field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n ctxExportTplHolder,\n );\n }\n\n const renderingState = { stagingRefreshTimestamp };\n const blocksInLimboSet = new Set(blocksInLimbo);\n\n const blockInfos = new Map<string, BlockInfo>();\n blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id,\n new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));\n\n // check consistency of project state\n const blockInStruct = new Set<string>();\n for (const b of allBlocks(structure)) {\n if (!blockInfos.has(b.id))\n throw new Error(`Inconsistent project structure: no inputs for ${b.id}`);\n blockInStruct.add(b.id);\n }\n blockInfos.forEach((info) => {\n if (!blockInStruct.has(info.id))\n throw new Error(`Inconsistent project structure: no structure entry for ${info.id}`);\n // checking structure\n info.check();\n });\n\n const prj = new ProjectMutator(\n rid,\n tx,\n author,\n schema,\n lastModified,\n meta,\n structure,\n renderingState,\n blocksInLimboSet,\n blockInfos,\n ctxExportTplHolder,\n projectHelper,\n );\n\n prj.fixProblemsAndMigrate();\n\n return prj;\n }\n}\n\nexport interface ProjectState {\n schema: string;\n structure: ProjectStructure;\n renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>;\n blocksInLimbo: Set<string>;\n blockInfos: Map<string, BlockInfo>;\n}\n\nexport async function createProject(\n tx: PlTransaction,\n meta: ProjectMeta = InitialBlockMeta,\n): Promise<AnyResourceRef> {\n const prj = tx.createEphemeral(ProjectResourceType);\n tx.lock(prj);\n const ts = String(Date.now());\n tx.setKValue(prj, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n tx.setKValue(prj, ProjectCreatedTimestamp, ts);\n tx.setKValue(prj, ProjectLastModifiedTimestamp, ts);\n tx.setKValue(prj, ProjectMetaKey, JSON.stringify(meta));\n tx.setKValue(prj, ProjectStructureKey, JSON.stringify(InitialBlockStructure));\n tx.setKValue(prj, BlockRenderingStateKey, JSON.stringify(InitialProjectRenderingState));\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n tx.createField(\n field(prj, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec)),\n );\n return prj;\n}\n\nexport async function withProject<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops?: Partial<TxOps>,\n): Promise<T> {\n return withProjectAuthored(projectHelper, txOrPl, rid, undefined, cb, ops);\n}\n\nexport async function withProjectAuthored<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n author: AuthorMarker | undefined,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops: Partial<TxOps> = {},\n): Promise<T> {\n if (txOrPl instanceof PlClient) {\n return await txOrPl.withWriteTx('ProjectAction' + (ops.name ? `: ${ops.name}` : ''), async (tx) => {\n const mut = await ProjectMutator.load(projectHelper, tx, rid, author);\n const result = await cb(mut);\n if (!mut.wasModified)\n // skipping save and commit altogether if no modifications were actually made\n return result;\n mut.save();\n await tx.commit();\n if (getDebugFlags().logProjectMutationStat) console.log(JSON.stringify(tx.stat));\n return result;\n }, ops);\n } else {\n const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);\n const result = await cb(mut);\n mut.save();\n return result;\n }\n}\n"],"names":["cachedDeserialize","Pl","BlockPackTemplateField","InitialBlockSettings","stagingGraph","notEmpty","isResourceId","productionGraph","allBlocks","field","projectFieldName","canonicalJsonBytes","canonicalJsonGzBytes","createBContextFromUpstreams","exportContext","createRenderHeavyBlock","extractConfig","createBlockPack","FieldsToDuplicate","graphDiff","blockArgsAuthorKey","ProjectStructureAuthorKey","ProjectLastModifiedTimestamp","ProjectStructureKey","BlockRenderingStateKey","ProjectMetaKey","SchemaVersionKey","parseProjectField","isNullResourceId","isResource","isResourceRef","SchemaVersionCurrent","UiError","isNotNullResourceId","ensureResourceIdNotNull","getPreparedExportTemplateEnvelope","getServiceTemplateField","loadTemplate","InitialBlockMeta","ProjectResourceType","ProjectCreatedTimestamp","InitialBlockStructure","InitialProjectRenderingState","PlClient","getDebugFlags"],"mappings":";;;;;;;;;;;;;;;AA4FA,SAAS,MAAM,CAAW,OAAoB,EAAE,OAAgB,EAAA;IAC9D,IAAI,WAAW,GAAG,KAAK;IACvB,IAAI,SAAS,GAAsB,SAAS;IAC5C,IAAI,KAAK,GAAkB,SAAS;AACpC,IAAA,OAAO,MAAK;QACV,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI;YAClB,SAAS,GAAG,OAAO,EAAE;YACrB,KAAK,GAAG,OAAO,EAAE;AACjB,YAAA,OAAO,KAAK;QACd;AACA,QAAA,MAAM,YAAY,GAAG,OAAO,EAAE;AAC9B,QAAA,IAAI,SAAS,KAAK,YAAY,EAAE;YAC9B,SAAS,GAAG,YAAY;YACxB,KAAK,GAAG,OAAO,EAAE;QACnB;QACA,OAAO,OAAO,EAAE;AAClB,IAAA,CAAC;AACH;AAEA,MAAM,SAAS,CAAA;AAEK,IAAA,EAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AAJlB,IAAA,WAAA,CACkB,EAAU,EACV,MAAwB,EACxB,MAAmB,EACnB,MAAqB,EAAA;QAHrB,IAAA,CAAA,EAAE,GAAF,EAAE;QACF,IAAA,CAAA,MAAM,GAAN,MAA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AC;YAC5B,IAAI,CAAC,GAAG,CAAC,WAAW;;AAElB,gBAAA,OAAO,MAAM;YACf,GAAG,CAAC,IAAI,EAAE;AACV,YAAA,MAAM,EAAE,CAAC,MAAM,EAAE;YACjB,IAAIC,mBAAa,EAAE,CAAC,sBAAsB;AAAE,gBAAA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAChF,YAAA,OAAO,MAAM;QACf,CAAC,EAAE,GAAG,CAAC;IACT;SAAO;AACL,QAAA,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC;AACzE,QAAA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC;QAC5B,GAAG,CAAC,IAAI,EAAE;AACV,QAAA,OAAO,MAAM;IACf;AACF;;;;;;;"}
1
+ {"version":3,"file":"project.cjs","sources":["../../src/mutator/project.ts"],"sourcesContent":["import type {\n AnyRef,\n AnyResourceRef,\n BasicResourceData,\n PlTransaction,\n ResourceData,\n ResourceId,\n TxOps } from '@milaboratories/pl-client';\nimport {\n ensureResourceIdNotNull,\n field,\n isNotNullResourceId,\n isNullResourceId,\n isResource,\n isResourceId,\n isResourceRef,\n Pl,\n PlClient,\n} from '@milaboratories/pl-client';\nimport { createRenderHeavyBlock, createBContextFromUpstreams } from './template/render_block';\nimport type {\n Block,\n ProjectStructure,\n ProjectField,\n ProjectRenderingState } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectStructureKey,\n parseProjectField,\n projectFieldName,\n SchemaVersionCurrent,\n SchemaVersionKey,\n ProjectResourceType,\n InitialBlockStructure,\n InitialProjectRenderingState,\n ProjectMetaKey,\n InitialBlockMeta,\n blockArgsAuthorKey,\n ProjectLastModifiedTimestamp,\n ProjectCreatedTimestamp,\n ProjectStructureAuthorKey,\n getServiceTemplateField,\n FieldsToDuplicate,\n} from '../model/project_model';\nimport { BlockPackTemplateField, createBlockPack } from './block-pack/block_pack';\nimport type {\n BlockGraph,\n ProductionGraphBlockInfo } from '../model/project_model_util';\nimport {\n allBlocks,\n graphDiff,\n productionGraph,\n stagingGraph,\n} from '../model/project_model_util';\nimport type { BlockPackSpecPrepared } from '../model';\nimport type {\n AuthorMarker,\n BlockPackSpec,\n BlockSettings,\n ProjectMeta,\n} from '@milaboratories/pl-model-middle-layer';\nimport {\n InitialBlockSettings,\n} from '@milaboratories/pl-model-middle-layer';\nimport Denque from 'denque';\nimport { exportContext, getPreparedExportTemplateEnvelope } from './context_export';\nimport { loadTemplate } from './template/template_loading';\nimport { cachedDeserialize, notEmpty, canonicalJsonGzBytes, canonicalJsonBytes } from '@milaboratories/ts-helpers';\nimport type { ProjectHelper } from '../model/project_helper';\nimport { extractConfig, UiError, type BlockConfig } from '@platforma-sdk/model';\nimport { getDebugFlags } from '../debug';\nimport type { BlockPackInfo } from '../model/block_pack';\n\ntype FieldStatus = 'NotReady' | 'Ready' | 'Error';\n\ninterface BlockFieldState {\n modCount: number;\n ref?: AnyRef;\n status?: FieldStatus;\n value?: Uint8Array;\n}\n\ntype BlockFieldStates = Partial<Record<ProjectField['fieldName'], BlockFieldState>>;\ntype BlockFieldStateValue = Omit<BlockFieldState, 'modCount'>;\n\ninterface BlockInfoState {\n readonly id: string;\n readonly fields: BlockFieldStates;\n blockConfig?: BlockConfig;\n blockPack?: BlockPackSpec;\n}\n\nfunction cached<ModId, T>(modIdCb: () => ModId, valueCb: () => T): () => T {\n let initialized = false;\n let lastModId: ModId | undefined = undefined;\n let value: T | undefined = undefined;\n return () => {\n if (!initialized) {\n initialized = true;\n lastModId = modIdCb();\n value = valueCb();\n return value;\n }\n const currentModId = modIdCb();\n if (lastModId !== currentModId) {\n lastModId = currentModId;\n value = valueCb();\n }\n return valueCb();\n };\n}\n\nclass BlockInfo {\n constructor(\n public readonly id: string,\n public readonly fields: BlockFieldStates,\n public readonly config: BlockConfig,\n public readonly source: BlockPackSpec,\n ) {}\n\n public check() {\n // state assertions\n\n if ((this.fields.prodOutput === undefined) !== (this.fields.prodCtx === undefined))\n throw new Error('inconsistent prod fields');\n\n if ((this.fields.stagingOutput === undefined) !== (this.fields.stagingCtx === undefined))\n throw new Error('inconsistent stage fields');\n\n if (\n (this.fields.prodOutputPrevious === undefined)\n !== (this.fields.prodCtxPrevious === undefined)\n )\n throw new Error('inconsistent prod cache fields');\n\n if (\n (this.fields.stagingOutputPrevious === undefined)\n !== (this.fields.stagingCtxPrevious === undefined)\n )\n throw new Error('inconsistent stage cache fields');\n\n if (this.fields.blockPack === undefined) throw new Error('no block pack field');\n\n if (this.fields.currentArgs === undefined) throw new Error('no current args field');\n }\n\n private readonly currentArgsC = cached(\n () => this.fields.currentArgs!.modCount,\n () => cachedDeserialize(this.fields.currentArgs!.value!),\n );\n\n private readonly prodArgsC = cached(\n () => this.fields.prodArgs?.modCount,\n () => {\n const bin = this.fields.prodArgs?.value;\n if (bin === undefined) return undefined;\n return cachedDeserialize(bin);\n },\n );\n\n get currentArgs(): unknown {\n return this.currentArgsC();\n }\n\n get stagingRendered(): boolean {\n return this.fields.stagingCtx !== undefined;\n }\n\n get productionRendered(): boolean {\n return this.fields.prodCtx !== undefined;\n }\n\n get productionHasErrors(): boolean {\n return this.fields.prodUiCtx?.status === 'Error';\n }\n\n private readonly productionStaleC: () => boolean = cached(\n () => `${this.fields.currentArgs!.modCount}_${this.fields.prodArgs?.modCount}`,\n () =>\n this.fields.prodArgs === undefined\n || Buffer.compare(this.fields.currentArgs!.value!, this.fields.prodArgs.value!) !== 0,\n );\n\n // get productionStale(): boolean {\n // return this.productionRendered && this.productionStaleC() && ;\n // }\n\n get requireProductionRendering(): boolean {\n return !this.productionRendered || this.productionStaleC() || this.productionHasErrors;\n }\n\n get prodArgs(): unknown {\n return this.prodArgsC();\n }\n\n public getTemplate(tx: PlTransaction): AnyRef {\n return tx.getFutureFieldValue(\n Pl.unwrapHolder(tx, this.fields.blockPack!.ref!),\n BlockPackTemplateField,\n 'Input',\n );\n }\n}\n\nexport interface NewBlockSpec {\n blockPack: BlockPackSpecPrepared;\n args: string;\n uiState: string;\n}\n\nconst NoNewBlocks = (blockId: string) => {\n throw new Error(`No new block info for ${blockId}`);\n};\n\nexport interface SetStatesRequest {\n blockId: string;\n args?: unknown;\n uiState?: unknown;\n}\n\ntype _GraphInfoFields =\n | 'stagingUpstream'\n | 'stagingDownstream'\n | 'futureProductionUpstream'\n | 'futureProductionDownstream'\n | 'actualProductionUpstream'\n | 'actualProductionDownstream';\n\nexport type ArgsAndUiState = {\n args: unknown;\n uiState: unknown;\n};\n\nexport class ProjectMutator {\n private globalModCount = 0;\n private fieldsChanged: boolean = false;\n\n //\n // Change trackers\n //\n\n private lastModifiedChanged = false;\n private structureChanged = false;\n private metaChanged = false;\n private renderingStateChanged = false;\n\n /** Set blocks will be assigned current mutator author marker on save */\n private readonly blocksWithChangedInputs = new Set<string>();\n\n constructor(\n public readonly rid: ResourceId,\n private readonly tx: PlTransaction,\n private readonly author: AuthorMarker | undefined,\n private readonly schema: string,\n private lastModified: number,\n private meta: ProjectMeta,\n private struct: ProjectStructure,\n private readonly renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>,\n private readonly blocksInLimbo: Set<string>,\n private readonly blockInfos: Map<string, BlockInfo>,\n private readonly ctxExportTplHolder: AnyResourceRef,\n private readonly projectHelper: ProjectHelper,\n ) {}\n\n private fixProblemsAndMigrate() {\n // Fixing problems introduced by old code\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodArgs === undefined\n || blockInfo.fields.prodOutput === undefined\n || blockInfo.fields.prodCtx === undefined\n )\n this.deleteBlockFields(blockInfo.id, 'prodArgs', 'prodOutput', 'prodCtx');\n });\n\n // Migration for addition of block settings field\n let initialBlockSettings: Omit<BlockFieldState, 'modCount'> | undefined;\n this.blockInfos.forEach((blockInfo) => {\n if (blockInfo.fields.blockSettings === undefined) {\n if (initialBlockSettings === undefined)\n initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);\n this.setBlockFieldObj(blockInfo.id, 'blockSettings', initialBlockSettings);\n }\n });\n }\n\n get wasModified(): boolean {\n return (\n this.lastModifiedChanged\n || this.structureChanged\n || this.fieldsChanged\n || this.metaChanged\n || this.renderingStateChanged\n );\n }\n\n get structure(): ProjectStructure {\n // clone\n return JSON.parse(JSON.stringify(this.struct)) as ProjectStructure;\n }\n\n //\n // Graph calculation\n //\n\n private stagingGraph: BlockGraph | undefined = undefined;\n private pendingProductionGraph: BlockGraph | undefined = undefined;\n private actualProductionGraph: BlockGraph | undefined = undefined;\n\n private getStagingGraph(): BlockGraph {\n if (this.stagingGraph === undefined) this.stagingGraph = stagingGraph(this.struct);\n return this.stagingGraph;\n }\n\n private getProductionGraphBlockInfo(blockId: string, prod: boolean): ProductionGraphBlockInfo | undefined {\n const bInfo = this.getBlockInfo(blockId);\n\n let argsField: BlockFieldState;\n let args: unknown;\n\n if (prod) {\n if (bInfo.fields.prodArgs === undefined) return undefined;\n argsField = bInfo.fields.prodArgs;\n args = bInfo.prodArgs;\n } else {\n argsField = notEmpty(bInfo.fields.currentArgs);\n args = bInfo.currentArgs;\n }\n\n const blockPackField = notEmpty(bInfo.fields.blockPack);\n\n if (isResourceId(argsField.ref!) && isResourceId(blockPackField.ref!))\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args,\n { argsRid: argsField.ref, blockPackRid: blockPackField.ref }),\n };\n else\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args),\n };\n }\n\n private getPendingProductionGraph(): BlockGraph {\n if (this.pendingProductionGraph === undefined)\n this.pendingProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, false),\n );\n return this.pendingProductionGraph;\n }\n\n private getActualProductionGraph(): BlockGraph {\n if (this.actualProductionGraph === undefined)\n this.actualProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n return this.actualProductionGraph;\n }\n\n //\n // Generic helpers to interact with project state\n //\n\n private getBlockInfo(blockId: string): BlockInfo {\n const info = this.blockInfos.get(blockId);\n if (info === undefined) throw new Error(`No such block: ${blockId}`);\n return info;\n }\n\n private createJsonFieldValueByContent(content: string): BlockFieldStateValue {\n const value = Buffer.from(content);\n const ref = this.tx.createValue(Pl.JsonObject, value);\n return { ref, value, status: 'Ready' };\n }\n\n private createJsonFieldValue(obj: unknown): BlockFieldStateValue {\n return this.createJsonFieldValueByContent(JSON.stringify(obj));\n }\n\n private getBlock(blockId: string): Block {\n for (const block of allBlocks(this.struct)) if (block.id === blockId) return block;\n throw new Error('block not found');\n }\n\n private setBlockFieldObj(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n state: BlockFieldStateValue,\n ) {\n const fid = field(this.rid, projectFieldName(blockId, fieldName));\n\n if (state.ref === undefined) throw new Error('Can\\'t set value with empty ref');\n\n if (this.getBlockInfo(blockId).fields[fieldName] === undefined)\n this.tx.createField(fid, 'Dynamic', state.ref);\n else this.tx.setField(fid, state.ref);\n\n this.getBlockInfo(blockId).fields[fieldName] = {\n modCount: this.globalModCount++,\n ...state,\n };\n\n this.fieldsChanged = true;\n }\n\n private setBlockField(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n ref: AnyRef,\n status: FieldStatus,\n value?: Uint8Array,\n ) {\n this.setBlockFieldObj(blockId, fieldName, { ref, status, value });\n }\n\n private deleteBlockFields(blockId: string, ...fieldNames: (keyof BlockFieldStates)[]): boolean {\n let deleted = false;\n const info = this.getBlockInfo(blockId);\n for (const fieldName of fieldNames) {\n const fields = info.fields;\n if (!(fieldName in fields)) continue;\n this.tx.removeField(field(this.rid, projectFieldName(blockId, fieldName)));\n delete fields[fieldName];\n this.fieldsChanged = true;\n deleted = true;\n }\n return deleted;\n }\n\n private updateLastModified() {\n this.lastModified = Date.now();\n this.lastModifiedChanged = true;\n }\n\n //\n // Main project actions\n //\n\n private resetStagingRefreshTimestamp() {\n this.renderingState.stagingRefreshTimestamp = Date.now();\n this.renderingStateChanged = true;\n }\n\n private resetStaging(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.stagingOutput?.status === 'Ready'\n && fields.stagingCtx?.status === 'Ready'\n && fields.stagingUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'stagingOutputPrevious', fields.stagingOutput);\n this.setBlockFieldObj(blockId, 'stagingCtxPrevious', fields.stagingCtx);\n this.setBlockFieldObj(blockId, 'stagingUiCtxPrevious', fields.stagingUiCtx);\n }\n if (this.deleteBlockFields(blockId, 'stagingOutput', 'stagingCtx', 'stagingUiCtx'))\n this.resetStagingRefreshTimestamp();\n }\n\n private resetProduction(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.prodOutput?.status === 'Ready'\n && fields.prodCtx?.status === 'Ready'\n && fields.prodUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'prodOutputPrevious', fields.prodOutput);\n this.setBlockFieldObj(blockId, 'prodCtxPrevious', fields.prodCtx);\n this.setBlockFieldObj(blockId, 'prodUiCtxPrevious', fields.prodUiCtx);\n }\n this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs');\n }\n\n /** Running blocks are reset, already computed moved to limbo. Returns if\n * either of the actions were actually performed.\n * This method ensures the block is left in a consistent state that passes check() constraints. */\n private resetOrLimboProduction(blockId: string): boolean {\n const fields = this.getBlockInfo(blockId).fields;\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return false;\n\n // limbo - keep the ready production results but clean up cache\n this.blocksInLimbo.add(blockId);\n this.renderingStateChanged = true;\n\n // doing some gc - clean up previous cache fields\n this.deleteBlockFields(blockId, 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');\n\n return true;\n } else {\n // reset - clean up any partial/inconsistent production stat\n return this.deleteBlockFields(\n blockId,\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n }\n }\n\n /** Optimally sets inputs for multiple blocks in one go */\n public setStates(requests: SetStatesRequest[]) {\n const changedArgs: string[] = [];\n let somethingChanged = false;\n for (const req of requests) {\n const info = this.getBlockInfo(req.blockId);\n let blockChanged = false;\n for (const stateKey of ['args', 'uiState'] as const) {\n if (!(stateKey in req)) continue;\n const statePart = req[stateKey];\n if (statePart === undefined || statePart === null)\n throw new Error(\n `Can't set ${stateKey} to null or undefined, please omit the key if you don't want to change it`,\n );\n\n const fieldName = stateKey === 'args' ? 'currentArgs' : 'uiState';\n\n let data: Uint8Array;\n let gzipped: boolean = false;\n if (stateKey === 'args') {\n // don't gzip args, workflow code can't uncompress gzip yet\n data = canonicalJsonBytes(statePart);\n } else {\n const { data: binary, isGzipped } = canonicalJsonGzBytes(statePart);\n data = binary;\n gzipped = isGzipped;\n }\n if (Buffer.compare(info.fields[fieldName]!.value!, data) === 0) continue;\n // console.log('setting', fieldName, gzipped, data.length);\n const statePartRef = this.tx.createValue(gzipped ? Pl.JsonGzObject : Pl.JsonObject, data);\n this.setBlockField(req.blockId, fieldName, statePartRef, 'Ready', data);\n\n blockChanged = true;\n if (stateKey === 'args') changedArgs.push(req.blockId);\n }\n if (blockChanged) {\n // will be assigned our author marker\n this.blocksWithChangedInputs.add(req.blockId);\n somethingChanged = true;\n }\n }\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', changedArgs, ({ id }) => this.resetStaging(id));\n\n if (somethingChanged) this.updateLastModified();\n }\n\n public setBlockSettings(blockId: string, newValue: BlockSettings): void {\n this.setBlockFieldObj(blockId, 'blockSettings', this.createJsonFieldValue(newValue));\n this.updateLastModified();\n }\n\n private createProdCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['prodCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private createStagingCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['stagingCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['stagingCtx'].ref));\n if (info.fields['prodCtx']?.ref !== undefined)\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private exportCtx(ctx: AnyRef): AnyRef {\n return exportContext(this.tx, Pl.unwrapHolder(this.tx, this.ctxExportTplHolder), ctx);\n }\n\n private renderStagingFor(blockId: string) {\n this.resetStaging(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode !== 'Heavy') throw new Error('not supported yet');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),\n context: ctx,\n });\n\n // Here we set the staging ctx to the input context of the staging workflow, not the output because exports\n // of one staging context should stay within the same block, and not travel downstream.\n // We may change this decision in the future if wanted to support traveling staging exports downstream.\n this.setBlockField(\n blockId,\n 'stagingCtx',\n Pl.wrapInEphHolder(this.tx, ctx),\n 'NotReady',\n );\n\n // Yet the staging UI Ctx is the output context of the staging workflow, because it is used to form the result pool\n // thus creating a certain discrepancy between staging workflow context behavior and desktop's result pool.\n this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');\n this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');\n }\n\n private renderProductionFor(blockId: string) {\n this.resetProduction(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode === 'Light')\n throw new Error('Can\\'t render production for light block.');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(true)),\n context: ctx,\n });\n this.setBlockField(\n blockId,\n 'prodCtx',\n Pl.wrapInEphHolder(this.tx, results.context),\n 'NotReady',\n );\n this.setBlockField(blockId, 'prodUiCtx', this.exportCtx(results.context), 'NotReady');\n this.setBlockField(blockId, 'prodOutput', results.result, 'NotReady');\n\n // saving inputs for which we rendered the production\n this.setBlockFieldObj(blockId, 'prodArgs', info.fields.currentArgs!);\n\n // removing block from limbo as we juts rendered fresh production for it\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n //\n // Structure changes\n //\n\n private initializeNewBlock(blockId: string, spec: NewBlockSpec): void {\n const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);\n this.blockInfos.set(blockId, info);\n\n // block pack\n const bp = createBlockPack(this.tx, spec.blockPack);\n this.setBlockField(blockId, 'blockPack', Pl.wrapInHolder(this.tx, bp), 'NotReady');\n\n // settings\n this.setBlockFieldObj(\n blockId,\n 'blockSettings',\n this.createJsonFieldValue(InitialBlockSettings),\n );\n\n // args\n this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValueByContent(spec.args));\n\n // uiState\n this.setBlockFieldObj(blockId, 'uiState', this.createJsonFieldValueByContent(spec.uiState ?? '{}'));\n\n // checking structure\n info.check();\n }\n\n private getFieldNamesToDuplicate(blockId: string): Set<ProjectField['fieldName']> {\n const fields = this.getBlockInfo(blockId).fields;\n\n const diff = <T>(setA: Set<T>, setB: Set<T>): Set<T> => new Set([...setA].filter((x) => !setB.has(x)));\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return FieldsToDuplicate;\n\n return diff(FieldsToDuplicate, new Set([\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n } else {\n return diff(FieldsToDuplicate, new Set([\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n }\n }\n\n private initializeBlockDuplicate(blockId: string, originalBlockInfo: BlockInfo) {\n const info = new BlockInfo(\n blockId,\n {},\n originalBlockInfo.config,\n originalBlockInfo.source,\n );\n\n this.blockInfos.set(blockId, info);\n\n const fieldNamesToDuplicate = this.getFieldNamesToDuplicate(blockId);\n\n // Copy all fields from original block to new block by sharing references\n for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) {\n if (fieldNamesToDuplicate.has(fieldName as ProjectField['fieldName']) && fieldState && fieldState.ref) {\n this.setBlockFieldObj(blockId, fieldName as keyof BlockFieldStates, {\n ref: fieldState.ref,\n status: fieldState.status,\n value: fieldState.value,\n });\n }\n }\n\n this.resetOrLimboProduction(blockId);\n\n info.check();\n }\n\n /** Very generic method, better check for more specialized case-specific methods first. */\n public updateStructure(\n newStructure: ProjectStructure,\n newBlockInitializer: (blockId: string) => void = NoNewBlocks,\n ): void {\n const currentStagingGraph = this.getStagingGraph();\n const currentActualProductionGraph = this.getActualProductionGraph();\n\n const newStagingGraph = stagingGraph(newStructure);\n\n const stagingDiff = graphDiff(currentStagingGraph, newStagingGraph);\n\n // removing blocks\n for (const blockId of stagingDiff.onlyInA) {\n const { fields } = this.getBlockInfo(blockId);\n this.deleteBlockFields(blockId, ...(Object.keys(fields) as ProjectField['fieldName'][]));\n this.blockInfos.delete(blockId);\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n // creating new blocks\n for (const blockId of stagingDiff.onlyInB) {\n newBlockInitializer(blockId);\n }\n\n // resetting stagings affected by topology change\n for (const blockId of stagingDiff.different) this.resetStaging(blockId);\n\n // new actual production graph without new blocks\n const newActualProductionGraph = productionGraph(\n newStructure,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n\n const prodDiff = graphDiff(currentActualProductionGraph, newActualProductionGraph);\n\n // applying changes due to topology change in production to affected nodes and\n // all their downstreams\n currentActualProductionGraph.traverse('downstream', [...prodDiff.different], (node) => {\n this.resetOrLimboProduction(node.id);\n });\n\n if (\n stagingDiff.onlyInB.size > 0\n || stagingDiff.onlyInA.size > 0\n || stagingDiff.different.size > 0\n )\n this.resetStagingRefreshTimestamp();\n\n this.struct = newStructure;\n this.structureChanged = true;\n this.stagingGraph = undefined;\n this.pendingProductionGraph = undefined;\n this.actualProductionGraph = undefined;\n\n this.updateLastModified();\n }\n\n //\n // Structure change helpers\n //\n\n public addBlock(block: Block, spec: NewBlockSpec, before?: string): void {\n const newStruct = this.structure; // copy current structure\n if (before === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(block);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === before);\n if (idx < 0) continue;\n group.blocks.splice(idx, 0, block);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${before}`);\n }\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== block.id) throw new Error('Unexpected');\n this.initializeNewBlock(blockId, spec);\n });\n }\n\n /**\n * Duplicates an existing block by copying all its fields and structure.\n * This method creates a deep copy of the block at the mutator level.\n *\n * @param originalBlockId id of the block to duplicate\n * @param newBlockId id for the new duplicated block\n * @param after id of the block to insert new block after\n */\n public duplicateBlock(originalBlockId: string, newBlockId: string, after?: string): void {\n // Get the original block from structure\n const originalBlock = this.getBlock(originalBlockId);\n const originalBlockInfo = this.getBlockInfo(originalBlockId);\n\n // Create new block in structure\n const newBlock: Block = {\n id: newBlockId,\n label: originalBlock.label,\n renderingMode: originalBlock.renderingMode,\n };\n\n // Add the new block to structure\n const newStruct = this.structure; // copy current structure\n if (after === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(newBlock);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === after);\n if (idx < 0) continue;\n group.blocks.splice(idx + 1, 0, newBlock);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${after}`);\n }\n\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== newBlockId) throw new Error('Unexpected');\n this.initializeBlockDuplicate(blockId, originalBlockInfo);\n });\n }\n\n public deleteBlock(blockId: string): void {\n const newStruct = this.structure; // copy current structure\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === blockId);\n if (idx < 0) continue;\n group.blocks.splice(idx, 1);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${blockId}`);\n this.updateStructure(newStruct);\n }\n\n //\n // Block-pack migration\n //\n\n public migrateBlockPack(blockId: string, spec: BlockPackSpecPrepared, newArgsAndUiState?: ArgsAndUiState): void {\n const info = this.getBlockInfo(blockId);\n\n this.setBlockField(\n blockId,\n 'blockPack',\n Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)),\n 'NotReady',\n );\n\n if (newArgsAndUiState !== undefined) {\n // this will also reset all downstream stagings\n this.setStates([{ blockId, args: newArgsAndUiState.args, uiState: newArgsAndUiState.uiState }]);\n } else {\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', [blockId], ({ id }) => this.resetStaging(id));\n }\n\n // also reset or limbo all downstream productions\n if (info.productionRendered)\n this.getActualProductionGraph().traverse('downstream', [blockId], ({ id }) =>\n this.resetOrLimboProduction(id),\n );\n\n this.updateLastModified();\n }\n\n //\n // Render\n //\n\n public renderProduction(blockIds: string[], addUpstreams: boolean = false): Set<string> {\n const blockIdsSet = new Set(blockIds);\n\n const prodGraph = this.getPendingProductionGraph();\n if (addUpstreams)\n // adding all upstreams automatically\n prodGraph.traverse('upstream', blockIds, (node) => {\n blockIdsSet.add(node.id);\n });\n else // checking that targets contain all upstreams\n for (const blockId of blockIdsSet) {\n const node = prodGraph.nodes.get(blockId);\n if (node === undefined) throw new Error(`Can't find block with id: ${blockId}`);\n for (const upstream of node.upstream)\n if (!blockIdsSet.has(upstream))\n throw new Error('Can\\'t render blocks not including all upstreams.');\n }\n\n // traversing in topological order and rendering target blocks\n const rendered = new Set<string>();\n for (const block of allBlocks(this.structure)) {\n if (!blockIdsSet.has(block.id)) continue;\n\n let render\n = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);\n\n if (!render)\n for (const upstream of prodGraph.nodes.get(block.id)!.upstream)\n if (rendered.has(upstream)) {\n render = true;\n break;\n }\n\n if (render) {\n this.renderProductionFor(block.id);\n rendered.add(block.id);\n }\n }\n\n const renderedArray = [...rendered];\n\n // sending to limbo all downstream blocks\n prodGraph.traverse('downstream', renderedArray, (node) => {\n if (rendered.has(node.id))\n // don't send to limbo blocks that were just rendered\n return;\n this.resetOrLimboProduction(node.id);\n });\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', renderedArray, ({ id }) => {\n // don't reset staging of the first rendered block\n if (renderedArray[0] !== id) this.resetStaging(id);\n });\n\n if (rendered.size > 0) this.updateLastModified();\n\n return rendered;\n }\n\n /** Stops running blocks from the list and modify states of other blocks\n * accordingly */\n public stopProduction(...blockIds: string[]) {\n const activeProdGraph = this.getActualProductionGraph();\n\n // we will stop all blocks listed in request and all their downstreams\n const queue = new Denque(blockIds);\n const queued = new Set(blockIds);\n const stopped: string[] = [];\n\n while (!queue.isEmpty()) {\n const blockId = queue.shift()!;\n const fields = this.getBlockInfo(blockId).fields;\n\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready')\n // skipping finished blocks\n continue;\n\n if (this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs')) {\n // was actually stopped\n stopped.push(blockId);\n\n // will try to stop all its downstreams\n for (const downstream of activeProdGraph.traverseIdsExcludingRoots('downstream', blockId)) {\n if (queued.has(downstream)) continue;\n queue.push(downstream);\n queued.add(downstream);\n }\n }\n }\n\n // blocks under stopped blocks, but having finished production results, goes to limbo\n for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))\n this.resetOrLimboProduction(blockId);\n\n // reset staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', stopped, ({ id }) => this.resetStaging(id));\n }\n\n private traverseWithStagingLag(cb: (blockId: string, lag: number) => void) {\n const lags = new Map<string, number>();\n const stagingGraph = this.getStagingGraph();\n stagingGraph.nodes.forEach((node) => {\n const info = this.getBlockInfo(node.id);\n let lag = info.stagingRendered ? 0 : 1;\n node.upstream.forEach((upstream) => {\n const upstreamLag = lags.get(upstream)!;\n if (upstreamLag === 0) return;\n lag = Math.max(upstreamLag + 1, lag);\n });\n cb(node.id, lag);\n lags.set(node.id, lag);\n });\n }\n\n /** @param stagingRenderingRate rate in blocks per second */\n private refreshStagings(stagingRenderingRate?: number) {\n const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;\n const lagThreshold\n = stagingRenderingRate === undefined\n ? undefined\n : 1 + Math.max(0, (elapsed * stagingRenderingRate) / 1000);\n let rendered = 0;\n this.traverseWithStagingLag((blockId, lag) => {\n if (lag === 0)\n // meaning staging already rendered\n return;\n if (lagThreshold === undefined || lag <= lagThreshold) {\n this.renderStagingFor(blockId);\n rendered++;\n }\n });\n if (rendered > 0) this.resetStagingRefreshTimestamp();\n }\n\n //\n // Meta\n //\n\n /** Updates project metadata */\n public setMeta(meta: ProjectMeta): void {\n this.meta = meta;\n this.metaChanged = true;\n this.updateLastModified();\n }\n\n //\n // Maintenance\n //\n\n /** @param stagingRenderingRate rate in blocks per second */\n public doRefresh(stagingRenderingRate?: number) {\n this.refreshStagings(stagingRenderingRate);\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodCtx?.status === 'Ready'\n && blockInfo.fields.prodOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n if (\n blockInfo.fields.stagingCtx?.status === 'Ready'\n && blockInfo.fields.stagingOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'stagingOutputPrevious',\n 'stagingCtxPrevious',\n 'stagingUiCtxPrevious',\n );\n });\n }\n\n private assignAuthorMarkers() {\n const markerStr = this.author ? JSON.stringify(this.author) : undefined;\n\n for (const blockId of this.blocksWithChangedInputs)\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, blockArgsAuthorKey(blockId));\n else this.tx.setKValue(this.rid, blockArgsAuthorKey(blockId), markerStr);\n\n if (this.metaChanged || this.structureChanged) {\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, ProjectStructureAuthorKey);\n else this.tx.setKValue(this.rid, ProjectStructureAuthorKey, markerStr);\n }\n }\n\n public save() {\n if (!this.wasModified) return;\n\n if (this.lastModifiedChanged)\n this.tx.setKValue(this.rid, ProjectLastModifiedTimestamp, JSON.stringify(this.lastModified));\n\n if (this.structureChanged)\n this.tx.setKValue(this.rid, ProjectStructureKey, JSON.stringify(this.struct));\n\n if (this.renderingStateChanged)\n this.tx.setKValue(\n this.rid,\n BlockRenderingStateKey,\n JSON.stringify({\n ...this.renderingState,\n blocksInLimbo: [...this.blocksInLimbo],\n } as ProjectRenderingState),\n );\n\n if (this.metaChanged) this.tx.setKValue(this.rid, ProjectMetaKey, JSON.stringify(this.meta));\n\n this.assignAuthorMarkers();\n }\n\n public static async load(\n projectHelper: ProjectHelper,\n tx: PlTransaction,\n rid: ResourceId,\n author?: AuthorMarker,\n ): Promise<ProjectMutator> {\n //\n // Sending initial requests to read project state (start of round-trip #1)\n //\n\n const fullResourceStateP = tx.getResourceData(rid, true);\n const schemaP = tx.getKValueJson<string>(rid, SchemaVersionKey);\n const lastModifiedP = tx.getKValueJson<number>(rid, ProjectLastModifiedTimestamp);\n const metaP = tx.getKValueJson<ProjectMeta>(rid, ProjectMetaKey);\n const structureP = tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey);\n const renderingStateP = tx.getKValueJson<ProjectRenderingState>(rid, BlockRenderingStateKey);\n\n const fullResourceState = await fullResourceStateP;\n\n // loading field information\n const blockInfoStates = new Map<string, BlockInfoState>();\n for (const f of fullResourceState.fields) {\n const projectField = parseProjectField(f.name);\n\n // processing only fields with known structure\n if (projectField === undefined) continue;\n\n let info = blockInfoStates.get(projectField.blockId);\n if (info === undefined) {\n info = {\n id: projectField.blockId,\n fields: {},\n };\n blockInfoStates.set(projectField.blockId, info);\n }\n\n info.fields[projectField.fieldName] = isNullResourceId(f.value)\n ? { modCount: 0 }\n : { modCount: 0, ref: f.value };\n }\n\n //\n // Roundtrip #1 not yet finished, but as soon as field list is received,\n // we can start sending requests to read states of referenced resources\n // (start of round-trip #2)\n //\n\n const blockFieldRequests: [BlockInfoState, ProjectField['fieldName'], BlockFieldState, Promise<BasicResourceData | ResourceData>][] = [];\n blockInfoStates.forEach((info) => {\n const fields = info.fields;\n for (const [fName, state] of Object.entries(fields)) {\n if (state.ref === undefined) continue;\n if (!isResource(state.ref) || isResourceRef(state.ref))\n throw new Error('unexpected behaviour');\n const fieldName = fName as ProjectField['fieldName'];\n blockFieldRequests.push([\n info, fieldName,\n state, tx.getResourceData(state.ref, fieldName == 'blockPack')]);\n }\n });\n\n // loading jsons\n const [\n schema,\n lastModified,\n meta,\n structure,\n { stagingRefreshTimestamp, blocksInLimbo },\n ] = await Promise.all([\n schemaP,\n lastModifiedP,\n metaP,\n structureP,\n renderingStateP,\n ]);\n\n // Checking schema version of the project\n if (schema !== SchemaVersionCurrent) {\n if (Number(schema) < Number(SchemaVersionCurrent))\n throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);\n else\n throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);\n }\n\n //\n // <- at this point we have all the responses from round-trip #1\n //\n\n //\n // Receiving responses from round-trip #2 and sending requests to read block pack descriptions\n // (start of round-trip #3)\n //\n\n const blockPackRequests: [BlockInfoState, Promise<BasicResourceData>][] = [];\n for (const [info, fieldName, state, response] of blockFieldRequests) {\n const result = await response;\n state.value = result.data;\n if (isNotNullResourceId(result.error)) state.status = 'Error';\n else if (result.resourceReady || isNotNullResourceId(result.originalResourceId))\n state.status = 'Ready';\n else state.status = 'NotReady';\n\n // For block pack we need to traverse the ref field from the resource data\n if (fieldName === 'blockPack') {\n const refField = (result as ResourceData).fields.find((f) => f.name === Pl.HolderRefField);\n if (refField === undefined)\n throw new Error('Block pack ref field is missing');\n blockPackRequests.push([info, tx.getResourceData(ensureResourceIdNotNull(refField.value), false)]);\n }\n }\n\n //\n // <- at this point we have all the responses from round-trip #2\n //\n\n for (const [info, response] of blockPackRequests) {\n const result = await response;\n const bpInfo = cachedDeserialize<BlockPackInfo>(notEmpty(result.data));\n info.blockConfig = extractConfig(bpInfo.config);\n info.blockPack = bpInfo.source;\n }\n\n //\n // <- at this point we have all the responses from round-trip #3\n //\n\n // loading ctx export template to check if we already have cached materialized template in our project\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n\n // expected field name\n const ctxExportTplCacheFieldName = getServiceTemplateField(ctxExportTplEnvelope.hash);\n const ctxExportTplField = fullResourceState.fields.find(\n (f) => f.name === ctxExportTplCacheFieldName,\n );\n let ctxExportTplHolder: AnyResourceRef;\n if (ctxExportTplField !== undefined)\n ctxExportTplHolder = ensureResourceIdNotNull(ctxExportTplField.value);\n else {\n ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));\n tx.createField(\n field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n ctxExportTplHolder,\n );\n }\n\n const renderingState = { stagingRefreshTimestamp };\n const blocksInLimboSet = new Set(blocksInLimbo);\n\n const blockInfos = new Map<string, BlockInfo>();\n blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id,\n new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));\n\n // check consistency of project state\n const blockInStruct = new Set<string>();\n for (const b of allBlocks(structure)) {\n if (!blockInfos.has(b.id))\n throw new Error(`Inconsistent project structure: no inputs for ${b.id}`);\n blockInStruct.add(b.id);\n }\n blockInfos.forEach((info) => {\n if (!blockInStruct.has(info.id))\n throw new Error(`Inconsistent project structure: no structure entry for ${info.id}`);\n // checking structure\n info.check();\n });\n\n const prj = new ProjectMutator(\n rid,\n tx,\n author,\n schema,\n lastModified,\n meta,\n structure,\n renderingState,\n blocksInLimboSet,\n blockInfos,\n ctxExportTplHolder,\n projectHelper,\n );\n\n prj.fixProblemsAndMigrate();\n\n return prj;\n }\n}\n\nexport interface ProjectState {\n schema: string;\n structure: ProjectStructure;\n renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>;\n blocksInLimbo: Set<string>;\n blockInfos: Map<string, BlockInfo>;\n}\n\nexport async function createProject(\n tx: PlTransaction,\n meta: ProjectMeta = InitialBlockMeta,\n): Promise<AnyResourceRef> {\n const prj = tx.createEphemeral(ProjectResourceType);\n tx.lock(prj);\n const ts = String(Date.now());\n tx.setKValue(prj, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n tx.setKValue(prj, ProjectCreatedTimestamp, ts);\n tx.setKValue(prj, ProjectLastModifiedTimestamp, ts);\n tx.setKValue(prj, ProjectMetaKey, JSON.stringify(meta));\n tx.setKValue(prj, ProjectStructureKey, JSON.stringify(InitialBlockStructure));\n tx.setKValue(prj, BlockRenderingStateKey, JSON.stringify(InitialProjectRenderingState));\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n tx.createField(\n field(prj, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec)),\n );\n return prj;\n}\n\nexport async function withProject<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops?: Partial<TxOps>,\n): Promise<T> {\n return withProjectAuthored(projectHelper, txOrPl, rid, undefined, cb, ops);\n}\n\nexport async function withProjectAuthored<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n author: AuthorMarker | undefined,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops: Partial<TxOps> = {},\n): Promise<T> {\n if (txOrPl instanceof PlClient) {\n return await txOrPl.withWriteTx('ProjectAction' + (ops.name ? `: ${ops.name}` : ''), async (tx) => {\n const mut = await ProjectMutator.load(projectHelper, tx, rid, author);\n const result = await cb(mut);\n if (!mut.wasModified)\n // skipping save and commit altogether if no modifications were actually made\n return result;\n mut.save();\n await tx.commit();\n if (getDebugFlags().logProjectMutationStat) console.log(JSON.stringify(tx.stat));\n return result;\n }, ops);\n } else {\n const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);\n const result = await cb(mut);\n mut.save();\n return result;\n }\n}\n"],"names":["cachedDeserialize","Pl","BlockPackTemplateField","InitialBlockSettings","stagingGraph","notEmpty","isResourceId","productionGraph","allBlocks","field","projectFieldName","canonicalJsonBytes","canonicalJsonGzBytes","createBContextFromUpstreams","exportContext","createRenderHeavyBlock","extractConfig","createBlockPack","FieldsToDuplicate","graphDiff","blockArgsAuthorKey","ProjectStructureAuthorKey","ProjectLastModifiedTimestamp","ProjectStructureKey","BlockRenderingStateKey","ProjectMetaKey","SchemaVersionKey","parseProjectField","isNullResourceId","isResource","isResourceRef","SchemaVersionCurrent","UiError","isNotNullResourceId","ensureResourceIdNotNull","getPreparedExportTemplateEnvelope","getServiceTemplateField","loadTemplate","InitialBlockMeta","ProjectResourceType","ProjectCreatedTimestamp","InitialBlockStructure","InitialProjectRenderingState","PlClient","getDebugFlags"],"mappings":";;;;;;;;;;;;;;;AA4FA,SAAS,MAAM,CAAW,OAAoB,EAAE,OAAgB,EAAA;IAC9D,IAAI,WAAW,GAAG,KAAK;IACvB,IAAI,SAAS,GAAsB,SAAS;IAC5C,IAAI,KAAK,GAAkB,SAAS;AACpC,IAAA,OAAO,MAAK;QACV,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI;YAClB,SAAS,GAAG,OAAO,EAAE;YACrB,KAAK,GAAG,OAAO,EAAE;AACjB,YAAA,OAAO,KAAK;QACd;AACA,QAAA,MAAM,YAAY,GAAG,OAAO,EAAE;AAC9B,QAAA,IAAI,SAAS,KAAK,YAAY,EAAE;YAC9B,SAAS,GAAG,YAAY;YACxB,KAAK,GAAG,OAAO,EAAE;QACnB;QACA,OAAO,OAAO,EAAE;AAClB,IAAA,CAAC;AACH;AAEA,MAAM,SAAS,CAAA;AAEK,IAAA,EAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AAJlB,IAAA,WAAA,CACkB,EAAU,EACV,MAAwB,EACxB,MAAmB,EACnB,MAAqB,EAAA;QAHrB,IAAA,CAAA,EAAE,GAAF,EAAE;QACF,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,MAAM,GAAN,MAAM;IACrB;IAEI,KAAK,GAAA;;AAGV,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,K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sB,mBAAmB,CAAC,CAAC,EACzC,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,aAAa,GAAG,QAAQ,EAChC,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,YAAY,GAAG,SAAS,EAChC,EAAE,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACzC,GAAG,GAAE,OAAO,CAAC,KAAK,CAAM,GACvB,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
@@ -406,7 +406,12 @@ class ProjectMutator {
406
406
  isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),
407
407
  context: ctx,
408
408
  });
409
- this.setBlockField(blockId, 'stagingCtx', Pl.wrapInEphHolder(this.tx, results.context), 'NotReady');
409
+ // Here we set the staging ctx to the input context of the staging workflow, not the output because exports
410
+ // of one staging context should stay within the same block, and not travel downstream.
411
+ // We may change this decision in the future if wanted to support traveling staging exports downstream.
412
+ this.setBlockField(blockId, 'stagingCtx', Pl.wrapInEphHolder(this.tx, ctx), 'NotReady');
413
+ // Yet the staging UI Ctx is the output context of the staging workflow, because it is used to form the result pool
414
+ // thus creating a certain discrepancy between staging workflow context behavior and desktop's result pool.
410
415
  this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');
411
416
  this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');
412
417
  }
@@ -719,9 +724,11 @@ class ProjectMutator {
719
724
  }
720
725
  }
721
726
  }
722
- // blocks under stopped blocks, but still having results, goes to limbo
727
+ // blocks under stopped blocks, but having finished production results, goes to limbo
723
728
  for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))
724
729
  this.resetOrLimboProduction(blockId);
730
+ // reset staging outputs for all downstream blocks
731
+ this.getStagingGraph().traverse('downstream', stopped, ({ id }) => this.resetStaging(id));
725
732
  }
726
733
  traverseWithStagingLag(cb) {
727
734
  const lags = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","sources":["../../src/mutator/project.ts"],"sourcesContent":["import type {\n AnyRef,\n AnyResourceRef,\n BasicResourceData,\n PlTransaction,\n ResourceData,\n ResourceId,\n TxOps } from '@milaboratories/pl-client';\nimport {\n ensureResourceIdNotNull,\n field,\n isNotNullResourceId,\n isNullResourceId,\n isResource,\n isResourceId,\n isResourceRef,\n Pl,\n PlClient,\n} from '@milaboratories/pl-client';\nimport { createRenderHeavyBlock, createBContextFromUpstreams } from './template/render_block';\nimport type {\n Block,\n ProjectStructure,\n ProjectField,\n ProjectRenderingState } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectStructureKey,\n parseProjectField,\n projectFieldName,\n SchemaVersionCurrent,\n SchemaVersionKey,\n ProjectResourceType,\n InitialBlockStructure,\n InitialProjectRenderingState,\n ProjectMetaKey,\n InitialBlockMeta,\n blockArgsAuthorKey,\n ProjectLastModifiedTimestamp,\n ProjectCreatedTimestamp,\n ProjectStructureAuthorKey,\n getServiceTemplateField,\n FieldsToDuplicate,\n} from '../model/project_model';\nimport { BlockPackTemplateField, createBlockPack } from './block-pack/block_pack';\nimport type {\n BlockGraph,\n ProductionGraphBlockInfo } from '../model/project_model_util';\nimport {\n allBlocks,\n graphDiff,\n productionGraph,\n stagingGraph,\n} from '../model/project_model_util';\nimport type { BlockPackSpecPrepared } from '../model';\nimport type {\n AuthorMarker,\n BlockPackSpec,\n BlockSettings,\n ProjectMeta,\n} from '@milaboratories/pl-model-middle-layer';\nimport {\n InitialBlockSettings,\n} from '@milaboratories/pl-model-middle-layer';\nimport Denque from 'denque';\nimport { exportContext, getPreparedExportTemplateEnvelope } from './context_export';\nimport { loadTemplate } from './template/template_loading';\nimport { cachedDeserialize, notEmpty, canonicalJsonGzBytes, canonicalJsonBytes } from '@milaboratories/ts-helpers';\nimport type { ProjectHelper } from '../model/project_helper';\nimport { extractConfig, UiError, type BlockConfig } from '@platforma-sdk/model';\nimport { getDebugFlags } from '../debug';\nimport type { BlockPackInfo } from '../model/block_pack';\n\ntype FieldStatus = 'NotReady' | 'Ready' | 'Error';\n\ninterface BlockFieldState {\n modCount: number;\n ref?: AnyRef;\n status?: FieldStatus;\n value?: Uint8Array;\n}\n\ntype BlockFieldStates = Partial<Record<ProjectField['fieldName'], BlockFieldState>>;\ntype BlockFieldStateValue = Omit<BlockFieldState, 'modCount'>;\n\ninterface BlockInfoState {\n readonly id: string;\n readonly fields: BlockFieldStates;\n blockConfig?: BlockConfig;\n blockPack?: BlockPackSpec;\n}\n\nfunction cached<ModId, T>(modIdCb: () => ModId, valueCb: () => T): () => T {\n let initialized = false;\n let lastModId: ModId | undefined = undefined;\n let value: T | undefined = undefined;\n return () => {\n if (!initialized) {\n initialized = true;\n lastModId = modIdCb();\n value = valueCb();\n return value;\n }\n const currentModId = modIdCb();\n if (lastModId !== currentModId) {\n lastModId = currentModId;\n value = valueCb();\n }\n return valueCb();\n };\n}\n\nclass BlockInfo {\n constructor(\n public readonly id: string,\n public readonly fields: BlockFieldStates,\n public readonly config: BlockConfig,\n public readonly source: BlockPackSpec,\n ) {}\n\n public check() {\n // state assertions\n\n if ((this.fields.prodOutput === undefined) !== (this.fields.prodCtx === undefined))\n throw new Error('inconsistent prod fields');\n\n if ((this.fields.stagingOutput === undefined) !== (this.fields.stagingCtx === undefined))\n throw new Error('inconsistent stage fields');\n\n if (\n (this.fields.prodOutputPrevious === undefined)\n !== (this.fields.prodCtxPrevious === undefined)\n )\n throw new Error('inconsistent prod cache fields');\n\n if (\n (this.fields.stagingOutputPrevious === undefined)\n !== (this.fields.stagingCtxPrevious === undefined)\n )\n throw new Error('inconsistent stage cache fields');\n\n if (this.fields.blockPack === undefined) throw new Error('no block pack field');\n\n if (this.fields.currentArgs === undefined) throw new Error('no current args field');\n }\n\n private readonly currentArgsC = cached(\n () => this.fields.currentArgs!.modCount,\n () => cachedDeserialize(this.fields.currentArgs!.value!),\n );\n\n private readonly prodArgsC = cached(\n () => this.fields.prodArgs?.modCount,\n () => {\n const bin = this.fields.prodArgs?.value;\n if (bin === undefined) return undefined;\n return cachedDeserialize(bin);\n },\n );\n\n get currentArgs(): unknown {\n return this.currentArgsC();\n }\n\n get stagingRendered(): boolean {\n return this.fields.stagingCtx !== undefined;\n }\n\n get productionRendered(): boolean {\n return this.fields.prodCtx !== undefined;\n }\n\n get productionHasErrors(): boolean {\n return this.fields.prodUiCtx?.status === 'Error';\n }\n\n private readonly productionStaleC: () => boolean = cached(\n () => `${this.fields.currentArgs!.modCount}_${this.fields.prodArgs?.modCount}`,\n () =>\n this.fields.prodArgs === undefined\n || Buffer.compare(this.fields.currentArgs!.value!, this.fields.prodArgs.value!) !== 0,\n );\n\n // get productionStale(): boolean {\n // return this.productionRendered && this.productionStaleC() && ;\n // }\n\n get requireProductionRendering(): boolean {\n return !this.productionRendered || this.productionStaleC() || this.productionHasErrors;\n }\n\n get prodArgs(): unknown {\n return this.prodArgsC();\n }\n\n public getTemplate(tx: PlTransaction): AnyRef {\n return tx.getFutureFieldValue(\n Pl.unwrapHolder(tx, this.fields.blockPack!.ref!),\n BlockPackTemplateField,\n 'Input',\n );\n }\n}\n\nexport interface NewBlockSpec {\n blockPack: BlockPackSpecPrepared;\n args: string;\n uiState: string;\n}\n\nconst NoNewBlocks = (blockId: string) => {\n throw new Error(`No new block info for ${blockId}`);\n};\n\nexport interface SetStatesRequest {\n blockId: string;\n args?: unknown;\n uiState?: unknown;\n}\n\ntype _GraphInfoFields =\n | 'stagingUpstream'\n | 'stagingDownstream'\n | 'futureProductionUpstream'\n | 'futureProductionDownstream'\n | 'actualProductionUpstream'\n | 'actualProductionDownstream';\n\nexport type ArgsAndUiState = {\n args: unknown;\n uiState: unknown;\n};\n\nexport class ProjectMutator {\n private globalModCount = 0;\n private fieldsChanged: boolean = false;\n\n //\n // Change trackers\n //\n\n private lastModifiedChanged = false;\n private structureChanged = false;\n private metaChanged = false;\n private renderingStateChanged = false;\n\n /** Set blocks will be assigned current mutator author marker on save */\n private readonly blocksWithChangedInputs = new Set<string>();\n\n constructor(\n public readonly rid: ResourceId,\n private readonly tx: PlTransaction,\n private readonly author: AuthorMarker | undefined,\n private readonly schema: string,\n private lastModified: number,\n private meta: ProjectMeta,\n private struct: ProjectStructure,\n private readonly renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>,\n private readonly blocksInLimbo: Set<string>,\n private readonly blockInfos: Map<string, BlockInfo>,\n private readonly ctxExportTplHolder: AnyResourceRef,\n private readonly projectHelper: ProjectHelper,\n ) {}\n\n private fixProblemsAndMigrate() {\n // Fixing problems introduced by old code\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodArgs === undefined\n || blockInfo.fields.prodOutput === undefined\n || blockInfo.fields.prodCtx === undefined\n )\n this.deleteBlockFields(blockInfo.id, 'prodArgs', 'prodOutput', 'prodCtx');\n });\n\n // Migration for addition of block settings field\n let initialBlockSettings: Omit<BlockFieldState, 'modCount'> | undefined;\n this.blockInfos.forEach((blockInfo) => {\n if (blockInfo.fields.blockSettings === undefined) {\n if (initialBlockSettings === undefined)\n initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);\n this.setBlockFieldObj(blockInfo.id, 'blockSettings', initialBlockSettings);\n }\n });\n }\n\n get wasModified(): boolean {\n return (\n this.lastModifiedChanged\n || this.structureChanged\n || this.fieldsChanged\n || this.metaChanged\n || this.renderingStateChanged\n );\n }\n\n get structure(): ProjectStructure {\n // clone\n return JSON.parse(JSON.stringify(this.struct)) as ProjectStructure;\n }\n\n //\n // Graph calculation\n //\n\n private stagingGraph: BlockGraph | undefined = undefined;\n private pendingProductionGraph: BlockGraph | undefined = undefined;\n private actualProductionGraph: BlockGraph | undefined = undefined;\n\n private getStagingGraph(): BlockGraph {\n if (this.stagingGraph === undefined) this.stagingGraph = stagingGraph(this.struct);\n return this.stagingGraph;\n }\n\n private getProductionGraphBlockInfo(blockId: string, prod: boolean): ProductionGraphBlockInfo | undefined {\n const bInfo = this.getBlockInfo(blockId);\n\n let argsField: BlockFieldState;\n let args: unknown;\n\n if (prod) {\n if (bInfo.fields.prodArgs === undefined) return undefined;\n argsField = bInfo.fields.prodArgs;\n args = bInfo.prodArgs;\n } else {\n argsField = notEmpty(bInfo.fields.currentArgs);\n args = bInfo.currentArgs;\n }\n\n const blockPackField = notEmpty(bInfo.fields.blockPack);\n\n if (isResourceId(argsField.ref!) && isResourceId(blockPackField.ref!))\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args,\n { argsRid: argsField.ref, blockPackRid: blockPackField.ref }),\n };\n else\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args),\n };\n }\n\n private getPendingProductionGraph(): BlockGraph {\n if (this.pendingProductionGraph === undefined)\n this.pendingProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, false),\n );\n return this.pendingProductionGraph;\n }\n\n private getActualProductionGraph(): BlockGraph {\n if (this.actualProductionGraph === undefined)\n this.actualProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n return this.actualProductionGraph;\n }\n\n //\n // Generic helpers to interact with project state\n //\n\n private getBlockInfo(blockId: string): BlockInfo {\n const info = this.blockInfos.get(blockId);\n if (info === undefined) throw new Error(`No such block: ${blockId}`);\n return info;\n }\n\n private createJsonFieldValueByContent(content: string): BlockFieldStateValue {\n const value = Buffer.from(content);\n const ref = this.tx.createValue(Pl.JsonObject, value);\n return { ref, value, status: 'Ready' };\n }\n\n private createJsonFieldValue(obj: unknown): BlockFieldStateValue {\n return this.createJsonFieldValueByContent(JSON.stringify(obj));\n }\n\n private getBlock(blockId: string): Block {\n for (const block of allBlocks(this.struct)) if (block.id === blockId) return block;\n throw new Error('block not found');\n }\n\n private setBlockFieldObj(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n state: BlockFieldStateValue,\n ) {\n const fid = field(this.rid, projectFieldName(blockId, fieldName));\n\n if (state.ref === undefined) throw new Error('Can\\'t set value with empty ref');\n\n if (this.getBlockInfo(blockId).fields[fieldName] === undefined)\n this.tx.createField(fid, 'Dynamic', state.ref);\n else this.tx.setField(fid, state.ref);\n\n this.getBlockInfo(blockId).fields[fieldName] = {\n modCount: this.globalModCount++,\n ...state,\n };\n\n this.fieldsChanged = true;\n }\n\n private setBlockField(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n ref: AnyRef,\n status: FieldStatus,\n value?: Uint8Array,\n ) {\n this.setBlockFieldObj(blockId, fieldName, { ref, status, value });\n }\n\n private deleteBlockFields(blockId: string, ...fieldNames: (keyof BlockFieldStates)[]): boolean {\n let deleted = false;\n const info = this.getBlockInfo(blockId);\n for (const fieldName of fieldNames) {\n const fields = info.fields;\n if (!(fieldName in fields)) continue;\n this.tx.removeField(field(this.rid, projectFieldName(blockId, fieldName)));\n delete fields[fieldName];\n this.fieldsChanged = true;\n deleted = true;\n }\n return deleted;\n }\n\n private updateLastModified() {\n this.lastModified = Date.now();\n this.lastModifiedChanged = true;\n }\n\n //\n // Main project actions\n //\n\n private resetStagingRefreshTimestamp() {\n this.renderingState.stagingRefreshTimestamp = Date.now();\n this.renderingStateChanged = true;\n }\n\n private resetStaging(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.stagingOutput?.status === 'Ready'\n && fields.stagingCtx?.status === 'Ready'\n && fields.stagingUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'stagingOutputPrevious', fields.stagingOutput);\n this.setBlockFieldObj(blockId, 'stagingCtxPrevious', fields.stagingCtx);\n this.setBlockFieldObj(blockId, 'stagingUiCtxPrevious', fields.stagingUiCtx);\n }\n if (this.deleteBlockFields(blockId, 'stagingOutput', 'stagingCtx', 'stagingUiCtx'))\n this.resetStagingRefreshTimestamp();\n }\n\n private resetProduction(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.prodOutput?.status === 'Ready'\n && fields.prodCtx?.status === 'Ready'\n && fields.prodUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'prodOutputPrevious', fields.prodOutput);\n this.setBlockFieldObj(blockId, 'prodCtxPrevious', fields.prodCtx);\n this.setBlockFieldObj(blockId, 'prodUiCtxPrevious', fields.prodUiCtx);\n }\n this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs');\n }\n\n /** Running blocks are reset, already computed moved to limbo. Returns if\n * either of the actions were actually performed.\n * This method ensures the block is left in a consistent state that passes check() constraints. */\n private resetOrLimboProduction(blockId: string): boolean {\n const fields = this.getBlockInfo(blockId).fields;\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return false;\n\n // limbo - keep the ready production results but clean up cache\n this.blocksInLimbo.add(blockId);\n this.renderingStateChanged = true;\n\n // doing some gc - clean up previous cache fields\n this.deleteBlockFields(blockId, 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');\n\n return true;\n } else {\n // reset - clean up any partial/inconsistent production stat\n return this.deleteBlockFields(\n blockId,\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n }\n }\n\n /** Optimally sets inputs for multiple blocks in one go */\n public setStates(requests: SetStatesRequest[]) {\n const changedArgs: string[] = [];\n let somethingChanged = false;\n for (const req of requests) {\n const info = this.getBlockInfo(req.blockId);\n let blockChanged = false;\n for (const stateKey of ['args', 'uiState'] as const) {\n if (!(stateKey in req)) continue;\n const statePart = req[stateKey];\n if (statePart === undefined || statePart === null)\n throw new Error(\n `Can't set ${stateKey} to null or undefined, please omit the key if you don't want to change it`,\n );\n\n const fieldName = stateKey === 'args' ? 'currentArgs' : 'uiState';\n\n let data: Uint8Array;\n let gzipped: boolean = false;\n if (stateKey === 'args') {\n // don't gzip args, workflow code can't uncompress gzip yet\n data = canonicalJsonBytes(statePart);\n } else {\n const { data: binary, isGzipped } = canonicalJsonGzBytes(statePart);\n data = binary;\n gzipped = isGzipped;\n }\n if (Buffer.compare(info.fields[fieldName]!.value!, data) === 0) continue;\n // console.log('setting', fieldName, gzipped, data.length);\n const statePartRef = this.tx.createValue(gzipped ? Pl.JsonGzObject : Pl.JsonObject, data);\n this.setBlockField(req.blockId, fieldName, statePartRef, 'Ready', data);\n\n blockChanged = true;\n if (stateKey === 'args') changedArgs.push(req.blockId);\n }\n if (blockChanged) {\n // will be assigned our author marker\n this.blocksWithChangedInputs.add(req.blockId);\n somethingChanged = true;\n }\n }\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', changedArgs, ({ id }) => this.resetStaging(id));\n\n if (somethingChanged) this.updateLastModified();\n }\n\n public setBlockSettings(blockId: string, newValue: BlockSettings): void {\n this.setBlockFieldObj(blockId, 'blockSettings', this.createJsonFieldValue(newValue));\n this.updateLastModified();\n }\n\n private createProdCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['prodCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private createStagingCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['stagingCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['stagingCtx'].ref));\n if (info.fields['prodCtx']?.ref !== undefined)\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private exportCtx(ctx: AnyRef): AnyRef {\n return exportContext(this.tx, Pl.unwrapHolder(this.tx, this.ctxExportTplHolder), ctx);\n }\n\n private renderStagingFor(blockId: string) {\n this.resetStaging(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode !== 'Heavy') throw new Error('not supported yet');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),\n context: ctx,\n });\n\n this.setBlockField(\n blockId,\n 'stagingCtx',\n Pl.wrapInEphHolder(this.tx, results.context),\n 'NotReady',\n );\n\n this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');\n\n this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');\n }\n\n private renderProductionFor(blockId: string) {\n this.resetProduction(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode === 'Light')\n throw new Error('Can\\'t render production for light block.');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(true)),\n context: ctx,\n });\n this.setBlockField(\n blockId,\n 'prodCtx',\n Pl.wrapInEphHolder(this.tx, results.context),\n 'NotReady',\n );\n this.setBlockField(blockId, 'prodUiCtx', this.exportCtx(results.context), 'NotReady');\n this.setBlockField(blockId, 'prodOutput', results.result, 'NotReady');\n\n // saving inputs for which we rendered the production\n this.setBlockFieldObj(blockId, 'prodArgs', info.fields.currentArgs!);\n\n // removing block from limbo as we juts rendered fresh production for it\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n //\n // Structure changes\n //\n\n private initializeNewBlock(blockId: string, spec: NewBlockSpec): void {\n const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);\n this.blockInfos.set(blockId, info);\n\n // block pack\n const bp = createBlockPack(this.tx, spec.blockPack);\n this.setBlockField(blockId, 'blockPack', Pl.wrapInHolder(this.tx, bp), 'NotReady');\n\n // settings\n this.setBlockFieldObj(\n blockId,\n 'blockSettings',\n this.createJsonFieldValue(InitialBlockSettings),\n );\n\n // args\n this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValueByContent(spec.args));\n\n // uiState\n this.setBlockFieldObj(blockId, 'uiState', this.createJsonFieldValueByContent(spec.uiState ?? '{}'));\n\n // checking structure\n info.check();\n }\n\n private getFieldNamesToDuplicate(blockId: string): Set<ProjectField['fieldName']> {\n const fields = this.getBlockInfo(blockId).fields;\n\n const diff = <T>(setA: Set<T>, setB: Set<T>): Set<T> => new Set([...setA].filter((x) => !setB.has(x)));\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return FieldsToDuplicate;\n\n return diff(FieldsToDuplicate, new Set([\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n } else {\n return diff(FieldsToDuplicate, new Set([\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n }\n }\n\n private initializeBlockDuplicate(blockId: string, originalBlockInfo: BlockInfo) {\n const info = new BlockInfo(\n blockId,\n {},\n originalBlockInfo.config,\n originalBlockInfo.source,\n );\n\n this.blockInfos.set(blockId, info);\n\n const fieldNamesToDuplicate = this.getFieldNamesToDuplicate(blockId);\n\n // Copy all fields from original block to new block by sharing references\n for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) {\n if (fieldNamesToDuplicate.has(fieldName as ProjectField['fieldName']) && fieldState && fieldState.ref) {\n this.setBlockFieldObj(blockId, fieldName as keyof BlockFieldStates, {\n ref: fieldState.ref,\n status: fieldState.status,\n value: fieldState.value,\n });\n }\n }\n\n this.resetOrLimboProduction(blockId);\n\n info.check();\n }\n\n /** Very generic method, better check for more specialized case-specific methods first. */\n public updateStructure(\n newStructure: ProjectStructure,\n newBlockInitializer: (blockId: string) => void = NoNewBlocks,\n ): void {\n const currentStagingGraph = this.getStagingGraph();\n const currentActualProductionGraph = this.getActualProductionGraph();\n\n const newStagingGraph = stagingGraph(newStructure);\n\n const stagingDiff = graphDiff(currentStagingGraph, newStagingGraph);\n\n // removing blocks\n for (const blockId of stagingDiff.onlyInA) {\n const { fields } = this.getBlockInfo(blockId);\n this.deleteBlockFields(blockId, ...(Object.keys(fields) as ProjectField['fieldName'][]));\n this.blockInfos.delete(blockId);\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n // creating new blocks\n for (const blockId of stagingDiff.onlyInB) {\n newBlockInitializer(blockId);\n }\n\n // resetting stagings affected by topology change\n for (const blockId of stagingDiff.different) this.resetStaging(blockId);\n\n // new actual production graph without new blocks\n const newActualProductionGraph = productionGraph(\n newStructure,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n\n const prodDiff = graphDiff(currentActualProductionGraph, newActualProductionGraph);\n\n // applying changes due to topology change in production to affected nodes and\n // all their downstreams\n currentActualProductionGraph.traverse('downstream', [...prodDiff.different], (node) => {\n this.resetOrLimboProduction(node.id);\n });\n\n if (\n stagingDiff.onlyInB.size > 0\n || stagingDiff.onlyInA.size > 0\n || stagingDiff.different.size > 0\n )\n this.resetStagingRefreshTimestamp();\n\n this.struct = newStructure;\n this.structureChanged = true;\n this.stagingGraph = undefined;\n this.pendingProductionGraph = undefined;\n this.actualProductionGraph = undefined;\n\n this.updateLastModified();\n }\n\n //\n // Structure change helpers\n //\n\n public addBlock(block: Block, spec: NewBlockSpec, before?: string): void {\n const newStruct = this.structure; // copy current structure\n if (before === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(block);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === before);\n if (idx < 0) continue;\n group.blocks.splice(idx, 0, block);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${before}`);\n }\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== block.id) throw new Error('Unexpected');\n this.initializeNewBlock(blockId, spec);\n });\n }\n\n /**\n * Duplicates an existing block by copying all its fields and structure.\n * This method creates a deep copy of the block at the mutator level.\n *\n * @param originalBlockId id of the block to duplicate\n * @param newBlockId id for the new duplicated block\n * @param after id of the block to insert new block after\n */\n public duplicateBlock(originalBlockId: string, newBlockId: string, after?: string): void {\n // Get the original block from structure\n const originalBlock = this.getBlock(originalBlockId);\n const originalBlockInfo = this.getBlockInfo(originalBlockId);\n\n // Create new block in structure\n const newBlock: Block = {\n id: newBlockId,\n label: originalBlock.label,\n renderingMode: originalBlock.renderingMode,\n };\n\n // Add the new block to structure\n const newStruct = this.structure; // copy current structure\n if (after === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(newBlock);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === after);\n if (idx < 0) continue;\n group.blocks.splice(idx + 1, 0, newBlock);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${after}`);\n }\n\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== newBlockId) throw new Error('Unexpected');\n this.initializeBlockDuplicate(blockId, originalBlockInfo);\n });\n }\n\n public deleteBlock(blockId: string): void {\n const newStruct = this.structure; // copy current structure\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === blockId);\n if (idx < 0) continue;\n group.blocks.splice(idx, 1);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${blockId}`);\n this.updateStructure(newStruct);\n }\n\n //\n // Block-pack migration\n //\n\n public migrateBlockPack(blockId: string, spec: BlockPackSpecPrepared, newArgsAndUiState?: ArgsAndUiState): void {\n const info = this.getBlockInfo(blockId);\n\n this.setBlockField(\n blockId,\n 'blockPack',\n Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)),\n 'NotReady',\n );\n\n if (newArgsAndUiState !== undefined) {\n // this will also reset all downstream stagings\n this.setStates([{ blockId, args: newArgsAndUiState.args, uiState: newArgsAndUiState.uiState }]);\n } else {\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', [blockId], ({ id }) => this.resetStaging(id));\n }\n\n // also reset or limbo all downstream productions\n if (info.productionRendered)\n this.getActualProductionGraph().traverse('downstream', [blockId], ({ id }) =>\n this.resetOrLimboProduction(id),\n );\n\n this.updateLastModified();\n }\n\n //\n // Render\n //\n\n public renderProduction(blockIds: string[], addUpstreams: boolean = false): Set<string> {\n const blockIdsSet = new Set(blockIds);\n\n const prodGraph = this.getPendingProductionGraph();\n if (addUpstreams)\n // adding all upstreams automatically\n prodGraph.traverse('upstream', blockIds, (node) => {\n blockIdsSet.add(node.id);\n });\n else // checking that targets contain all upstreams\n for (const blockId of blockIdsSet) {\n const node = prodGraph.nodes.get(blockId);\n if (node === undefined) throw new Error(`Can't find block with id: ${blockId}`);\n for (const upstream of node.upstream)\n if (!blockIdsSet.has(upstream))\n throw new Error('Can\\'t render blocks not including all upstreams.');\n }\n\n // traversing in topological order and rendering target blocks\n const rendered = new Set<string>();\n for (const block of allBlocks(this.structure)) {\n if (!blockIdsSet.has(block.id)) continue;\n\n let render\n = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);\n\n if (!render)\n for (const upstream of prodGraph.nodes.get(block.id)!.upstream)\n if (rendered.has(upstream)) {\n render = true;\n break;\n }\n\n if (render) {\n this.renderProductionFor(block.id);\n rendered.add(block.id);\n }\n }\n\n const renderedArray = [...rendered];\n\n // sending to limbo all downstream blocks\n prodGraph.traverse('downstream', renderedArray, (node) => {\n if (rendered.has(node.id))\n // don't send to limbo blocks that were just rendered\n return;\n this.resetOrLimboProduction(node.id);\n });\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', renderedArray, ({ id }) => {\n // don't reset staging of the first rendered block\n if (renderedArray[0] !== id) this.resetStaging(id);\n });\n\n if (rendered.size > 0) this.updateLastModified();\n\n return rendered;\n }\n\n /** Stops running blocks from the list and modify states of other blocks\n * accordingly */\n public stopProduction(...blockIds: string[]) {\n const activeProdGraph = this.getActualProductionGraph();\n\n // we will stop all blocks listed in request and all their downstreams\n const queue = new Denque(blockIds);\n const queued = new Set(blockIds);\n const stopped: string[] = [];\n\n while (!queue.isEmpty()) {\n const blockId = queue.shift()!;\n const fields = this.getBlockInfo(blockId).fields;\n\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready')\n // skipping finished blocks\n continue;\n\n if (this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs')) {\n // was actually stopped\n stopped.push(blockId);\n\n // will try to stop all its downstreams\n for (const downstream of activeProdGraph.traverseIdsExcludingRoots('downstream', blockId)) {\n if (queued.has(downstream)) continue;\n queue.push(downstream);\n queued.add(downstream);\n }\n }\n }\n\n // blocks under stopped blocks, but still having results, goes to limbo\n for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))\n this.resetOrLimboProduction(blockId);\n }\n\n private traverseWithStagingLag(cb: (blockId: string, lag: number) => void) {\n const lags = new Map<string, number>();\n const stagingGraph = this.getStagingGraph();\n stagingGraph.nodes.forEach((node) => {\n const info = this.getBlockInfo(node.id);\n let lag = info.stagingRendered ? 0 : 1;\n node.upstream.forEach((upstream) => {\n const upstreamLag = lags.get(upstream)!;\n if (upstreamLag === 0) return;\n lag = Math.max(upstreamLag + 1, lag);\n });\n cb(node.id, lag);\n lags.set(node.id, lag);\n });\n }\n\n /** @param stagingRenderingRate rate in blocks per second */\n private refreshStagings(stagingRenderingRate?: number) {\n const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;\n const lagThreshold\n = stagingRenderingRate === undefined\n ? undefined\n : 1 + Math.max(0, (elapsed * stagingRenderingRate) / 1000);\n let rendered = 0;\n this.traverseWithStagingLag((blockId, lag) => {\n if (lag === 0)\n // meaning staging already rendered\n return;\n if (lagThreshold === undefined || lag <= lagThreshold) {\n this.renderStagingFor(blockId);\n rendered++;\n }\n });\n if (rendered > 0) this.resetStagingRefreshTimestamp();\n }\n\n //\n // Meta\n //\n\n /** Updates project metadata */\n public setMeta(meta: ProjectMeta): void {\n this.meta = meta;\n this.metaChanged = true;\n this.updateLastModified();\n }\n\n //\n // Maintenance\n //\n\n /** @param stagingRenderingRate rate in blocks per second */\n public doRefresh(stagingRenderingRate?: number) {\n this.refreshStagings(stagingRenderingRate);\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodCtx?.status === 'Ready'\n && blockInfo.fields.prodOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n if (\n blockInfo.fields.stagingCtx?.status === 'Ready'\n && blockInfo.fields.stagingOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'stagingOutputPrevious',\n 'stagingCtxPrevious',\n 'stagingUiCtxPrevious',\n );\n });\n }\n\n private assignAuthorMarkers() {\n const markerStr = this.author ? JSON.stringify(this.author) : undefined;\n\n for (const blockId of this.blocksWithChangedInputs)\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, blockArgsAuthorKey(blockId));\n else this.tx.setKValue(this.rid, blockArgsAuthorKey(blockId), markerStr);\n\n if (this.metaChanged || this.structureChanged) {\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, ProjectStructureAuthorKey);\n else this.tx.setKValue(this.rid, ProjectStructureAuthorKey, markerStr);\n }\n }\n\n public save() {\n if (!this.wasModified) return;\n\n if (this.lastModifiedChanged)\n this.tx.setKValue(this.rid, ProjectLastModifiedTimestamp, JSON.stringify(this.lastModified));\n\n if (this.structureChanged)\n this.tx.setKValue(this.rid, ProjectStructureKey, JSON.stringify(this.struct));\n\n if (this.renderingStateChanged)\n this.tx.setKValue(\n this.rid,\n BlockRenderingStateKey,\n JSON.stringify({\n ...this.renderingState,\n blocksInLimbo: [...this.blocksInLimbo],\n } as ProjectRenderingState),\n );\n\n if (this.metaChanged) this.tx.setKValue(this.rid, ProjectMetaKey, JSON.stringify(this.meta));\n\n this.assignAuthorMarkers();\n }\n\n public static async load(\n projectHelper: ProjectHelper,\n tx: PlTransaction,\n rid: ResourceId,\n author?: AuthorMarker,\n ): Promise<ProjectMutator> {\n //\n // Sending initial requests to read project state (start of round-trip #1)\n //\n\n const fullResourceStateP = tx.getResourceData(rid, true);\n const schemaP = tx.getKValueJson<string>(rid, SchemaVersionKey);\n const lastModifiedP = tx.getKValueJson<number>(rid, ProjectLastModifiedTimestamp);\n const metaP = tx.getKValueJson<ProjectMeta>(rid, ProjectMetaKey);\n const structureP = tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey);\n const renderingStateP = tx.getKValueJson<ProjectRenderingState>(rid, BlockRenderingStateKey);\n\n const fullResourceState = await fullResourceStateP;\n\n // loading field information\n const blockInfoStates = new Map<string, BlockInfoState>();\n for (const f of fullResourceState.fields) {\n const projectField = parseProjectField(f.name);\n\n // processing only fields with known structure\n if (projectField === undefined) continue;\n\n let info = blockInfoStates.get(projectField.blockId);\n if (info === undefined) {\n info = {\n id: projectField.blockId,\n fields: {},\n };\n blockInfoStates.set(projectField.blockId, info);\n }\n\n info.fields[projectField.fieldName] = isNullResourceId(f.value)\n ? { modCount: 0 }\n : { modCount: 0, ref: f.value };\n }\n\n //\n // Roundtrip #1 not yet finished, but as soon as field list is received,\n // we can start sending requests to read states of referenced resources\n // (start of round-trip #2)\n //\n\n const blockFieldRequests: [BlockInfoState, ProjectField['fieldName'], BlockFieldState, Promise<BasicResourceData | ResourceData>][] = [];\n blockInfoStates.forEach((info) => {\n const fields = info.fields;\n for (const [fName, state] of Object.entries(fields)) {\n if (state.ref === undefined) continue;\n if (!isResource(state.ref) || isResourceRef(state.ref))\n throw new Error('unexpected behaviour');\n const fieldName = fName as ProjectField['fieldName'];\n blockFieldRequests.push([\n info, fieldName,\n state, tx.getResourceData(state.ref, fieldName == 'blockPack')]);\n }\n });\n\n // loading jsons\n const [\n schema,\n lastModified,\n meta,\n structure,\n { stagingRefreshTimestamp, blocksInLimbo },\n ] = await Promise.all([\n schemaP,\n lastModifiedP,\n metaP,\n structureP,\n renderingStateP,\n ]);\n\n // Checking schema version of the project\n if (schema !== SchemaVersionCurrent) {\n if (Number(schema) < Number(SchemaVersionCurrent))\n throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);\n else\n throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);\n }\n\n //\n // <- at this point we have all the responses from round-trip #1\n //\n\n //\n // Receiving responses from round-trip #2 and sending requests to read block pack descriptions\n // (start of round-trip #3)\n //\n\n const blockPackRequests: [BlockInfoState, Promise<BasicResourceData>][] = [];\n for (const [info, fieldName, state, response] of blockFieldRequests) {\n const result = await response;\n state.value = result.data;\n if (isNotNullResourceId(result.error)) state.status = 'Error';\n else if (result.resourceReady || isNotNullResourceId(result.originalResourceId))\n state.status = 'Ready';\n else state.status = 'NotReady';\n\n // For block pack we need to traverse the ref field from the resource data\n if (fieldName === 'blockPack') {\n const refField = (result as ResourceData).fields.find((f) => f.name === Pl.HolderRefField);\n if (refField === undefined)\n throw new Error('Block pack ref field is missing');\n blockPackRequests.push([info, tx.getResourceData(ensureResourceIdNotNull(refField.value), false)]);\n }\n }\n\n //\n // <- at this point we have all the responses from round-trip #2\n //\n\n for (const [info, response] of blockPackRequests) {\n const result = await response;\n const bpInfo = cachedDeserialize<BlockPackInfo>(notEmpty(result.data));\n info.blockConfig = extractConfig(bpInfo.config);\n info.blockPack = bpInfo.source;\n }\n\n //\n // <- at this point we have all the responses from round-trip #3\n //\n\n // loading ctx export template to check if we already have cached materialized template in our project\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n\n // expected field name\n const ctxExportTplCacheFieldName = getServiceTemplateField(ctxExportTplEnvelope.hash);\n const ctxExportTplField = fullResourceState.fields.find(\n (f) => f.name === ctxExportTplCacheFieldName,\n );\n let ctxExportTplHolder: AnyResourceRef;\n if (ctxExportTplField !== undefined)\n ctxExportTplHolder = ensureResourceIdNotNull(ctxExportTplField.value);\n else {\n ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));\n tx.createField(\n field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n ctxExportTplHolder,\n );\n }\n\n const renderingState = { stagingRefreshTimestamp };\n const blocksInLimboSet = new Set(blocksInLimbo);\n\n const blockInfos = new Map<string, BlockInfo>();\n blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id,\n new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));\n\n // check consistency of project state\n const blockInStruct = new Set<string>();\n for (const b of allBlocks(structure)) {\n if (!blockInfos.has(b.id))\n throw new Error(`Inconsistent project structure: no inputs for ${b.id}`);\n blockInStruct.add(b.id);\n }\n blockInfos.forEach((info) => {\n if (!blockInStruct.has(info.id))\n throw new Error(`Inconsistent project structure: no structure entry for ${info.id}`);\n // checking structure\n info.check();\n });\n\n const prj = new ProjectMutator(\n rid,\n tx,\n author,\n schema,\n lastModified,\n meta,\n structure,\n renderingState,\n blocksInLimboSet,\n blockInfos,\n ctxExportTplHolder,\n projectHelper,\n );\n\n prj.fixProblemsAndMigrate();\n\n return prj;\n }\n}\n\nexport interface ProjectState {\n schema: string;\n structure: ProjectStructure;\n renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>;\n blocksInLimbo: Set<string>;\n blockInfos: Map<string, BlockInfo>;\n}\n\nexport async function createProject(\n tx: PlTransaction,\n meta: ProjectMeta = InitialBlockMeta,\n): Promise<AnyResourceRef> {\n const prj = tx.createEphemeral(ProjectResourceType);\n tx.lock(prj);\n const ts = String(Date.now());\n tx.setKValue(prj, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n tx.setKValue(prj, ProjectCreatedTimestamp, ts);\n tx.setKValue(prj, ProjectLastModifiedTimestamp, ts);\n tx.setKValue(prj, ProjectMetaKey, JSON.stringify(meta));\n tx.setKValue(prj, ProjectStructureKey, JSON.stringify(InitialBlockStructure));\n tx.setKValue(prj, BlockRenderingStateKey, JSON.stringify(InitialProjectRenderingState));\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n tx.createField(\n field(prj, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec)),\n );\n return prj;\n}\n\nexport async function withProject<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops?: Partial<TxOps>,\n): Promise<T> {\n return withProjectAuthored(projectHelper, txOrPl, rid, undefined, cb, ops);\n}\n\nexport async function withProjectAuthored<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n author: AuthorMarker | undefined,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops: Partial<TxOps> = {},\n): Promise<T> {\n if (txOrPl instanceof PlClient) {\n return await txOrPl.withWriteTx('ProjectAction' + (ops.name ? `: ${ops.name}` : ''), async (tx) => {\n const mut = await ProjectMutator.load(projectHelper, tx, rid, author);\n const result = await cb(mut);\n if (!mut.wasModified)\n // skipping save and commit altogether if no modifications were actually made\n return result;\n mut.save();\n await tx.commit();\n if (getDebugFlags().logProjectMutationStat) console.log(JSON.stringify(tx.stat));\n return result;\n }, ops);\n } else {\n const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);\n const result = await cb(mut);\n mut.save();\n return result;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA4FA,SAAS,MAAM,CAAW,OAAoB,EAAE,OAAgB,EAAA;IAC9D,IAAI,WAAW,GAAG,KAAK;IACvB,IAAI,SAAS,GAAsB,SAAS;IAC5C,IAAI,KAAK,GAAkB,SAAS;AACpC,IAAA,OAAO,MAAK;QACV,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI;YAClB,SAAS,GAAG,OAAO,EAAE;YACrB,KAAK,GAAG,OAAO,EAAE;AACjB,YAAA,OAAO,KAAK;QACd;AACA,QAAA,MAAM,YAAY,GAAG,OAAO,EAAE;AAC9B,QAAA,IAAI,SAAS,KAAK,YAAY,EAAE;YAC9B,SAAS,GAAG,YAAY;YACxB,KAAK,GAAG,OAAO,EAAE;QACnB;QACA,OAAO,OAAO,EAAE;AAClB,IAAA,CAAC;AACH;AAEA,MAAM,SAAS,CAAA;AAEK,IAAA,EAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AAJlB,IAAA,WAAA,CACkB,EAAU,EACV,MAAwB,EACxB,MAAmB,EACnB,MAAqB,EAAA;QAHrB,IAAA,CAAA,EAAE,GAAF,EAAE;QACF,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,MAAM,GAAN,MAAM;QACN,IAAA,CAAA,MAAM,GAAN,MAAM;IACrB;IAEI,KAAK,GAAA;;AAGV,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC;AAChF,YAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC;AAE7C,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC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AAC,GAAG,CAAC;QAC5B,GAAG,CAAC,IAAI,EAAE;AACV,QAAA,OAAO,MAAM;IACf;AACF;;;;"}
1
+ {"version":3,"file":"project.js","sources":["../../src/mutator/project.ts"],"sourcesContent":["import type {\n AnyRef,\n AnyResourceRef,\n BasicResourceData,\n PlTransaction,\n ResourceData,\n ResourceId,\n TxOps } from '@milaboratories/pl-client';\nimport {\n ensureResourceIdNotNull,\n field,\n isNotNullResourceId,\n isNullResourceId,\n isResource,\n isResourceId,\n isResourceRef,\n Pl,\n PlClient,\n} from '@milaboratories/pl-client';\nimport { createRenderHeavyBlock, createBContextFromUpstreams } from './template/render_block';\nimport type {\n Block,\n ProjectStructure,\n ProjectField,\n ProjectRenderingState } from '../model/project_model';\nimport {\n BlockRenderingStateKey,\n ProjectStructureKey,\n parseProjectField,\n projectFieldName,\n SchemaVersionCurrent,\n SchemaVersionKey,\n ProjectResourceType,\n InitialBlockStructure,\n InitialProjectRenderingState,\n ProjectMetaKey,\n InitialBlockMeta,\n blockArgsAuthorKey,\n ProjectLastModifiedTimestamp,\n ProjectCreatedTimestamp,\n ProjectStructureAuthorKey,\n getServiceTemplateField,\n FieldsToDuplicate,\n} from '../model/project_model';\nimport { BlockPackTemplateField, createBlockPack } from './block-pack/block_pack';\nimport type {\n BlockGraph,\n ProductionGraphBlockInfo } from '../model/project_model_util';\nimport {\n allBlocks,\n graphDiff,\n productionGraph,\n stagingGraph,\n} from '../model/project_model_util';\nimport type { BlockPackSpecPrepared } from '../model';\nimport type {\n AuthorMarker,\n BlockPackSpec,\n BlockSettings,\n ProjectMeta,\n} from '@milaboratories/pl-model-middle-layer';\nimport {\n InitialBlockSettings,\n} from '@milaboratories/pl-model-middle-layer';\nimport Denque from 'denque';\nimport { exportContext, getPreparedExportTemplateEnvelope } from './context_export';\nimport { loadTemplate } from './template/template_loading';\nimport { cachedDeserialize, notEmpty, canonicalJsonGzBytes, canonicalJsonBytes } from '@milaboratories/ts-helpers';\nimport type { ProjectHelper } from '../model/project_helper';\nimport { extractConfig, UiError, type BlockConfig } from '@platforma-sdk/model';\nimport { getDebugFlags } from '../debug';\nimport type { BlockPackInfo } from '../model/block_pack';\n\ntype FieldStatus = 'NotReady' | 'Ready' | 'Error';\n\ninterface BlockFieldState {\n modCount: number;\n ref?: AnyRef;\n status?: FieldStatus;\n value?: Uint8Array;\n}\n\ntype BlockFieldStates = Partial<Record<ProjectField['fieldName'], BlockFieldState>>;\ntype BlockFieldStateValue = Omit<BlockFieldState, 'modCount'>;\n\ninterface BlockInfoState {\n readonly id: string;\n readonly fields: BlockFieldStates;\n blockConfig?: BlockConfig;\n blockPack?: BlockPackSpec;\n}\n\nfunction cached<ModId, T>(modIdCb: () => ModId, valueCb: () => T): () => T {\n let initialized = false;\n let lastModId: ModId | undefined = undefined;\n let value: T | undefined = undefined;\n return () => {\n if (!initialized) {\n initialized = true;\n lastModId = modIdCb();\n value = valueCb();\n return value;\n }\n const currentModId = modIdCb();\n if (lastModId !== currentModId) {\n lastModId = currentModId;\n value = valueCb();\n }\n return valueCb();\n };\n}\n\nclass BlockInfo {\n constructor(\n public readonly id: string,\n public readonly fields: BlockFieldStates,\n public readonly config: BlockConfig,\n public readonly source: BlockPackSpec,\n ) {}\n\n public check() {\n // state assertions\n\n if ((this.fields.prodOutput === undefined) !== (this.fields.prodCtx === undefined))\n throw new Error('inconsistent prod fields');\n\n if ((this.fields.stagingOutput === undefined) !== (this.fields.stagingCtx === undefined))\n throw new Error('inconsistent stage fields');\n\n if (\n (this.fields.prodOutputPrevious === undefined)\n !== (this.fields.prodCtxPrevious === undefined)\n )\n throw new Error('inconsistent prod cache fields');\n\n if (\n (this.fields.stagingOutputPrevious === undefined)\n !== (this.fields.stagingCtxPrevious === undefined)\n )\n throw new Error('inconsistent stage cache fields');\n\n if (this.fields.blockPack === undefined) throw new Error('no block pack field');\n\n if (this.fields.currentArgs === undefined) throw new Error('no current args field');\n }\n\n private readonly currentArgsC = cached(\n () => this.fields.currentArgs!.modCount,\n () => cachedDeserialize(this.fields.currentArgs!.value!),\n );\n\n private readonly prodArgsC = cached(\n () => this.fields.prodArgs?.modCount,\n () => {\n const bin = this.fields.prodArgs?.value;\n if (bin === undefined) return undefined;\n return cachedDeserialize(bin);\n },\n );\n\n get currentArgs(): unknown {\n return this.currentArgsC();\n }\n\n get stagingRendered(): boolean {\n return this.fields.stagingCtx !== undefined;\n }\n\n get productionRendered(): boolean {\n return this.fields.prodCtx !== undefined;\n }\n\n get productionHasErrors(): boolean {\n return this.fields.prodUiCtx?.status === 'Error';\n }\n\n private readonly productionStaleC: () => boolean = cached(\n () => `${this.fields.currentArgs!.modCount}_${this.fields.prodArgs?.modCount}`,\n () =>\n this.fields.prodArgs === undefined\n || Buffer.compare(this.fields.currentArgs!.value!, this.fields.prodArgs.value!) !== 0,\n );\n\n // get productionStale(): boolean {\n // return this.productionRendered && this.productionStaleC() && ;\n // }\n\n get requireProductionRendering(): boolean {\n return !this.productionRendered || this.productionStaleC() || this.productionHasErrors;\n }\n\n get prodArgs(): unknown {\n return this.prodArgsC();\n }\n\n public getTemplate(tx: PlTransaction): AnyRef {\n return tx.getFutureFieldValue(\n Pl.unwrapHolder(tx, this.fields.blockPack!.ref!),\n BlockPackTemplateField,\n 'Input',\n );\n }\n}\n\nexport interface NewBlockSpec {\n blockPack: BlockPackSpecPrepared;\n args: string;\n uiState: string;\n}\n\nconst NoNewBlocks = (blockId: string) => {\n throw new Error(`No new block info for ${blockId}`);\n};\n\nexport interface SetStatesRequest {\n blockId: string;\n args?: unknown;\n uiState?: unknown;\n}\n\ntype _GraphInfoFields =\n | 'stagingUpstream'\n | 'stagingDownstream'\n | 'futureProductionUpstream'\n | 'futureProductionDownstream'\n | 'actualProductionUpstream'\n | 'actualProductionDownstream';\n\nexport type ArgsAndUiState = {\n args: unknown;\n uiState: unknown;\n};\n\nexport class ProjectMutator {\n private globalModCount = 0;\n private fieldsChanged: boolean = false;\n\n //\n // Change trackers\n //\n\n private lastModifiedChanged = false;\n private structureChanged = false;\n private metaChanged = false;\n private renderingStateChanged = false;\n\n /** Set blocks will be assigned current mutator author marker on save */\n private readonly blocksWithChangedInputs = new Set<string>();\n\n constructor(\n public readonly rid: ResourceId,\n private readonly tx: PlTransaction,\n private readonly author: AuthorMarker | undefined,\n private readonly schema: string,\n private lastModified: number,\n private meta: ProjectMeta,\n private struct: ProjectStructure,\n private readonly renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>,\n private readonly blocksInLimbo: Set<string>,\n private readonly blockInfos: Map<string, BlockInfo>,\n private readonly ctxExportTplHolder: AnyResourceRef,\n private readonly projectHelper: ProjectHelper,\n ) {}\n\n private fixProblemsAndMigrate() {\n // Fixing problems introduced by old code\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodArgs === undefined\n || blockInfo.fields.prodOutput === undefined\n || blockInfo.fields.prodCtx === undefined\n )\n this.deleteBlockFields(blockInfo.id, 'prodArgs', 'prodOutput', 'prodCtx');\n });\n\n // Migration for addition of block settings field\n let initialBlockSettings: Omit<BlockFieldState, 'modCount'> | undefined;\n this.blockInfos.forEach((blockInfo) => {\n if (blockInfo.fields.blockSettings === undefined) {\n if (initialBlockSettings === undefined)\n initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);\n this.setBlockFieldObj(blockInfo.id, 'blockSettings', initialBlockSettings);\n }\n });\n }\n\n get wasModified(): boolean {\n return (\n this.lastModifiedChanged\n || this.structureChanged\n || this.fieldsChanged\n || this.metaChanged\n || this.renderingStateChanged\n );\n }\n\n get structure(): ProjectStructure {\n // clone\n return JSON.parse(JSON.stringify(this.struct)) as ProjectStructure;\n }\n\n //\n // Graph calculation\n //\n\n private stagingGraph: BlockGraph | undefined = undefined;\n private pendingProductionGraph: BlockGraph | undefined = undefined;\n private actualProductionGraph: BlockGraph | undefined = undefined;\n\n private getStagingGraph(): BlockGraph {\n if (this.stagingGraph === undefined) this.stagingGraph = stagingGraph(this.struct);\n return this.stagingGraph;\n }\n\n private getProductionGraphBlockInfo(blockId: string, prod: boolean): ProductionGraphBlockInfo | undefined {\n const bInfo = this.getBlockInfo(blockId);\n\n let argsField: BlockFieldState;\n let args: unknown;\n\n if (prod) {\n if (bInfo.fields.prodArgs === undefined) return undefined;\n argsField = bInfo.fields.prodArgs;\n args = bInfo.prodArgs;\n } else {\n argsField = notEmpty(bInfo.fields.currentArgs);\n args = bInfo.currentArgs;\n }\n\n const blockPackField = notEmpty(bInfo.fields.blockPack);\n\n if (isResourceId(argsField.ref!) && isResourceId(blockPackField.ref!))\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args,\n { argsRid: argsField.ref, blockPackRid: blockPackField.ref }),\n };\n else\n return {\n args,\n enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args),\n };\n }\n\n private getPendingProductionGraph(): BlockGraph {\n if (this.pendingProductionGraph === undefined)\n this.pendingProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, false),\n );\n return this.pendingProductionGraph;\n }\n\n private getActualProductionGraph(): BlockGraph {\n if (this.actualProductionGraph === undefined)\n this.actualProductionGraph = productionGraph(\n this.struct,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n return this.actualProductionGraph;\n }\n\n //\n // Generic helpers to interact with project state\n //\n\n private getBlockInfo(blockId: string): BlockInfo {\n const info = this.blockInfos.get(blockId);\n if (info === undefined) throw new Error(`No such block: ${blockId}`);\n return info;\n }\n\n private createJsonFieldValueByContent(content: string): BlockFieldStateValue {\n const value = Buffer.from(content);\n const ref = this.tx.createValue(Pl.JsonObject, value);\n return { ref, value, status: 'Ready' };\n }\n\n private createJsonFieldValue(obj: unknown): BlockFieldStateValue {\n return this.createJsonFieldValueByContent(JSON.stringify(obj));\n }\n\n private getBlock(blockId: string): Block {\n for (const block of allBlocks(this.struct)) if (block.id === blockId) return block;\n throw new Error('block not found');\n }\n\n private setBlockFieldObj(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n state: BlockFieldStateValue,\n ) {\n const fid = field(this.rid, projectFieldName(blockId, fieldName));\n\n if (state.ref === undefined) throw new Error('Can\\'t set value with empty ref');\n\n if (this.getBlockInfo(blockId).fields[fieldName] === undefined)\n this.tx.createField(fid, 'Dynamic', state.ref);\n else this.tx.setField(fid, state.ref);\n\n this.getBlockInfo(blockId).fields[fieldName] = {\n modCount: this.globalModCount++,\n ...state,\n };\n\n this.fieldsChanged = true;\n }\n\n private setBlockField(\n blockId: string,\n fieldName: keyof BlockFieldStates,\n ref: AnyRef,\n status: FieldStatus,\n value?: Uint8Array,\n ) {\n this.setBlockFieldObj(blockId, fieldName, { ref, status, value });\n }\n\n private deleteBlockFields(blockId: string, ...fieldNames: (keyof BlockFieldStates)[]): boolean {\n let deleted = false;\n const info = this.getBlockInfo(blockId);\n for (const fieldName of fieldNames) {\n const fields = info.fields;\n if (!(fieldName in fields)) continue;\n this.tx.removeField(field(this.rid, projectFieldName(blockId, fieldName)));\n delete fields[fieldName];\n this.fieldsChanged = true;\n deleted = true;\n }\n return deleted;\n }\n\n private updateLastModified() {\n this.lastModified = Date.now();\n this.lastModifiedChanged = true;\n }\n\n //\n // Main project actions\n //\n\n private resetStagingRefreshTimestamp() {\n this.renderingState.stagingRefreshTimestamp = Date.now();\n this.renderingStateChanged = true;\n }\n\n private resetStaging(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.stagingOutput?.status === 'Ready'\n && fields.stagingCtx?.status === 'Ready'\n && fields.stagingUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'stagingOutputPrevious', fields.stagingOutput);\n this.setBlockFieldObj(blockId, 'stagingCtxPrevious', fields.stagingCtx);\n this.setBlockFieldObj(blockId, 'stagingUiCtxPrevious', fields.stagingUiCtx);\n }\n if (this.deleteBlockFields(blockId, 'stagingOutput', 'stagingCtx', 'stagingUiCtx'))\n this.resetStagingRefreshTimestamp();\n }\n\n private resetProduction(blockId: string): void {\n const fields = this.getBlockInfo(blockId).fields;\n if (\n fields.prodOutput?.status === 'Ready'\n && fields.prodCtx?.status === 'Ready'\n && fields.prodUiCtx?.status === 'Ready'\n ) {\n this.setBlockFieldObj(blockId, 'prodOutputPrevious', fields.prodOutput);\n this.setBlockFieldObj(blockId, 'prodCtxPrevious', fields.prodCtx);\n this.setBlockFieldObj(blockId, 'prodUiCtxPrevious', fields.prodUiCtx);\n }\n this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs');\n }\n\n /** Running blocks are reset, already computed moved to limbo. Returns if\n * either of the actions were actually performed.\n * This method ensures the block is left in a consistent state that passes check() constraints. */\n private resetOrLimboProduction(blockId: string): boolean {\n const fields = this.getBlockInfo(blockId).fields;\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return false;\n\n // limbo - keep the ready production results but clean up cache\n this.blocksInLimbo.add(blockId);\n this.renderingStateChanged = true;\n\n // doing some gc - clean up previous cache fields\n this.deleteBlockFields(blockId, 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');\n\n return true;\n } else {\n // reset - clean up any partial/inconsistent production stat\n return this.deleteBlockFields(\n blockId,\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n }\n }\n\n /** Optimally sets inputs for multiple blocks in one go */\n public setStates(requests: SetStatesRequest[]) {\n const changedArgs: string[] = [];\n let somethingChanged = false;\n for (const req of requests) {\n const info = this.getBlockInfo(req.blockId);\n let blockChanged = false;\n for (const stateKey of ['args', 'uiState'] as const) {\n if (!(stateKey in req)) continue;\n const statePart = req[stateKey];\n if (statePart === undefined || statePart === null)\n throw new Error(\n `Can't set ${stateKey} to null or undefined, please omit the key if you don't want to change it`,\n );\n\n const fieldName = stateKey === 'args' ? 'currentArgs' : 'uiState';\n\n let data: Uint8Array;\n let gzipped: boolean = false;\n if (stateKey === 'args') {\n // don't gzip args, workflow code can't uncompress gzip yet\n data = canonicalJsonBytes(statePart);\n } else {\n const { data: binary, isGzipped } = canonicalJsonGzBytes(statePart);\n data = binary;\n gzipped = isGzipped;\n }\n if (Buffer.compare(info.fields[fieldName]!.value!, data) === 0) continue;\n // console.log('setting', fieldName, gzipped, data.length);\n const statePartRef = this.tx.createValue(gzipped ? Pl.JsonGzObject : Pl.JsonObject, data);\n this.setBlockField(req.blockId, fieldName, statePartRef, 'Ready', data);\n\n blockChanged = true;\n if (stateKey === 'args') changedArgs.push(req.blockId);\n }\n if (blockChanged) {\n // will be assigned our author marker\n this.blocksWithChangedInputs.add(req.blockId);\n somethingChanged = true;\n }\n }\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', changedArgs, ({ id }) => this.resetStaging(id));\n\n if (somethingChanged) this.updateLastModified();\n }\n\n public setBlockSettings(blockId: string, newValue: BlockSettings): void {\n this.setBlockFieldObj(blockId, 'blockSettings', this.createJsonFieldValue(newValue));\n this.updateLastModified();\n }\n\n private createProdCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['prodCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private createStagingCtx(upstream: Set<string>): AnyRef {\n const upstreamContexts: AnyRef[] = [];\n upstream.forEach((id) => {\n const info = this.getBlockInfo(id);\n if (info.fields['stagingCtx']?.ref === undefined)\n throw new Error('One of the upstreams staging is not rendered.');\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['stagingCtx'].ref));\n if (info.fields['prodCtx']?.ref !== undefined)\n upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));\n });\n return createBContextFromUpstreams(this.tx, upstreamContexts);\n }\n\n private exportCtx(ctx: AnyRef): AnyRef {\n return exportContext(this.tx, Pl.unwrapHolder(this.tx, this.ctxExportTplHolder), ctx);\n }\n\n private renderStagingFor(blockId: string) {\n this.resetStaging(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode !== 'Heavy') throw new Error('not supported yet');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),\n context: ctx,\n });\n\n // Here we set the staging ctx to the input context of the staging workflow, not the output because exports\n // of one staging context should stay within the same block, and not travel downstream.\n // We may change this decision in the future if wanted to support traveling staging exports downstream.\n this.setBlockField(\n blockId,\n 'stagingCtx',\n Pl.wrapInEphHolder(this.tx, ctx),\n 'NotReady',\n );\n\n // Yet the staging UI Ctx is the output context of the staging workflow, because it is used to form the result pool\n // thus creating a certain discrepancy between staging workflow context behavior and desktop's result pool.\n this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');\n this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');\n }\n\n private renderProductionFor(blockId: string) {\n this.resetProduction(blockId);\n\n const info = this.getBlockInfo(blockId);\n\n const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId)!.upstream);\n\n if (this.getBlock(blockId).renderingMode === 'Light')\n throw new Error('Can\\'t render production for light block.');\n\n const tpl = info.getTemplate(this.tx);\n\n const results = createRenderHeavyBlock(this.tx, tpl, {\n args: info.fields.currentArgs!.ref!,\n blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),\n isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(true)),\n context: ctx,\n });\n this.setBlockField(\n blockId,\n 'prodCtx',\n Pl.wrapInEphHolder(this.tx, results.context),\n 'NotReady',\n );\n this.setBlockField(blockId, 'prodUiCtx', this.exportCtx(results.context), 'NotReady');\n this.setBlockField(blockId, 'prodOutput', results.result, 'NotReady');\n\n // saving inputs for which we rendered the production\n this.setBlockFieldObj(blockId, 'prodArgs', info.fields.currentArgs!);\n\n // removing block from limbo as we juts rendered fresh production for it\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n //\n // Structure changes\n //\n\n private initializeNewBlock(blockId: string, spec: NewBlockSpec): void {\n const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);\n this.blockInfos.set(blockId, info);\n\n // block pack\n const bp = createBlockPack(this.tx, spec.blockPack);\n this.setBlockField(blockId, 'blockPack', Pl.wrapInHolder(this.tx, bp), 'NotReady');\n\n // settings\n this.setBlockFieldObj(\n blockId,\n 'blockSettings',\n this.createJsonFieldValue(InitialBlockSettings),\n );\n\n // args\n this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValueByContent(spec.args));\n\n // uiState\n this.setBlockFieldObj(blockId, 'uiState', this.createJsonFieldValueByContent(spec.uiState ?? '{}'));\n\n // checking structure\n info.check();\n }\n\n private getFieldNamesToDuplicate(blockId: string): Set<ProjectField['fieldName']> {\n const fields = this.getBlockInfo(blockId).fields;\n\n const diff = <T>(setA: Set<T>, setB: Set<T>): Set<T> => new Set([...setA].filter((x) => !setB.has(x)));\n\n // Check if we can safely move to limbo (both core production fields are ready)\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {\n if (this.blocksInLimbo.has(blockId))\n // we are already in limbo\n return FieldsToDuplicate;\n\n return diff(FieldsToDuplicate, new Set([\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n } else {\n return diff(FieldsToDuplicate, new Set([\n 'prodOutput',\n 'prodCtx',\n 'prodUiCtx',\n 'prodArgs',\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n ]));\n }\n }\n\n private initializeBlockDuplicate(blockId: string, originalBlockInfo: BlockInfo) {\n const info = new BlockInfo(\n blockId,\n {},\n originalBlockInfo.config,\n originalBlockInfo.source,\n );\n\n this.blockInfos.set(blockId, info);\n\n const fieldNamesToDuplicate = this.getFieldNamesToDuplicate(blockId);\n\n // Copy all fields from original block to new block by sharing references\n for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) {\n if (fieldNamesToDuplicate.has(fieldName as ProjectField['fieldName']) && fieldState && fieldState.ref) {\n this.setBlockFieldObj(blockId, fieldName as keyof BlockFieldStates, {\n ref: fieldState.ref,\n status: fieldState.status,\n value: fieldState.value,\n });\n }\n }\n\n this.resetOrLimboProduction(blockId);\n\n info.check();\n }\n\n /** Very generic method, better check for more specialized case-specific methods first. */\n public updateStructure(\n newStructure: ProjectStructure,\n newBlockInitializer: (blockId: string) => void = NoNewBlocks,\n ): void {\n const currentStagingGraph = this.getStagingGraph();\n const currentActualProductionGraph = this.getActualProductionGraph();\n\n const newStagingGraph = stagingGraph(newStructure);\n\n const stagingDiff = graphDiff(currentStagingGraph, newStagingGraph);\n\n // removing blocks\n for (const blockId of stagingDiff.onlyInA) {\n const { fields } = this.getBlockInfo(blockId);\n this.deleteBlockFields(blockId, ...(Object.keys(fields) as ProjectField['fieldName'][]));\n this.blockInfos.delete(blockId);\n if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;\n }\n\n // creating new blocks\n for (const blockId of stagingDiff.onlyInB) {\n newBlockInitializer(blockId);\n }\n\n // resetting stagings affected by topology change\n for (const blockId of stagingDiff.different) this.resetStaging(blockId);\n\n // new actual production graph without new blocks\n const newActualProductionGraph = productionGraph(\n newStructure,\n (blockId) => this.getProductionGraphBlockInfo(blockId, true),\n );\n\n const prodDiff = graphDiff(currentActualProductionGraph, newActualProductionGraph);\n\n // applying changes due to topology change in production to affected nodes and\n // all their downstreams\n currentActualProductionGraph.traverse('downstream', [...prodDiff.different], (node) => {\n this.resetOrLimboProduction(node.id);\n });\n\n if (\n stagingDiff.onlyInB.size > 0\n || stagingDiff.onlyInA.size > 0\n || stagingDiff.different.size > 0\n )\n this.resetStagingRefreshTimestamp();\n\n this.struct = newStructure;\n this.structureChanged = true;\n this.stagingGraph = undefined;\n this.pendingProductionGraph = undefined;\n this.actualProductionGraph = undefined;\n\n this.updateLastModified();\n }\n\n //\n // Structure change helpers\n //\n\n public addBlock(block: Block, spec: NewBlockSpec, before?: string): void {\n const newStruct = this.structure; // copy current structure\n if (before === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(block);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === before);\n if (idx < 0) continue;\n group.blocks.splice(idx, 0, block);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${before}`);\n }\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== block.id) throw new Error('Unexpected');\n this.initializeNewBlock(blockId, spec);\n });\n }\n\n /**\n * Duplicates an existing block by copying all its fields and structure.\n * This method creates a deep copy of the block at the mutator level.\n *\n * @param originalBlockId id of the block to duplicate\n * @param newBlockId id for the new duplicated block\n * @param after id of the block to insert new block after\n */\n public duplicateBlock(originalBlockId: string, newBlockId: string, after?: string): void {\n // Get the original block from structure\n const originalBlock = this.getBlock(originalBlockId);\n const originalBlockInfo = this.getBlockInfo(originalBlockId);\n\n // Create new block in structure\n const newBlock: Block = {\n id: newBlockId,\n label: originalBlock.label,\n renderingMode: originalBlock.renderingMode,\n };\n\n // Add the new block to structure\n const newStruct = this.structure; // copy current structure\n if (after === undefined) {\n // adding as a very last block\n newStruct.groups[newStruct.groups.length - 1].blocks.push(newBlock);\n } else {\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === after);\n if (idx < 0) continue;\n group.blocks.splice(idx + 1, 0, newBlock);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${after}`);\n }\n\n this.updateStructure(newStruct, (blockId) => {\n if (blockId !== newBlockId) throw new Error('Unexpected');\n this.initializeBlockDuplicate(blockId, originalBlockInfo);\n });\n }\n\n public deleteBlock(blockId: string): void {\n const newStruct = this.structure; // copy current structure\n let done = false;\n for (const group of newStruct.groups) {\n const idx = group.blocks.findIndex((b) => b.id === blockId);\n if (idx < 0) continue;\n group.blocks.splice(idx, 1);\n done = true;\n break;\n }\n if (!done) throw new Error(`Can't find element with id: ${blockId}`);\n this.updateStructure(newStruct);\n }\n\n //\n // Block-pack migration\n //\n\n public migrateBlockPack(blockId: string, spec: BlockPackSpecPrepared, newArgsAndUiState?: ArgsAndUiState): void {\n const info = this.getBlockInfo(blockId);\n\n this.setBlockField(\n blockId,\n 'blockPack',\n Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)),\n 'NotReady',\n );\n\n if (newArgsAndUiState !== undefined) {\n // this will also reset all downstream stagings\n this.setStates([{ blockId, args: newArgsAndUiState.args, uiState: newArgsAndUiState.uiState }]);\n } else {\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', [blockId], ({ id }) => this.resetStaging(id));\n }\n\n // also reset or limbo all downstream productions\n if (info.productionRendered)\n this.getActualProductionGraph().traverse('downstream', [blockId], ({ id }) =>\n this.resetOrLimboProduction(id),\n );\n\n this.updateLastModified();\n }\n\n //\n // Render\n //\n\n public renderProduction(blockIds: string[], addUpstreams: boolean = false): Set<string> {\n const blockIdsSet = new Set(blockIds);\n\n const prodGraph = this.getPendingProductionGraph();\n if (addUpstreams)\n // adding all upstreams automatically\n prodGraph.traverse('upstream', blockIds, (node) => {\n blockIdsSet.add(node.id);\n });\n else // checking that targets contain all upstreams\n for (const blockId of blockIdsSet) {\n const node = prodGraph.nodes.get(blockId);\n if (node === undefined) throw new Error(`Can't find block with id: ${blockId}`);\n for (const upstream of node.upstream)\n if (!blockIdsSet.has(upstream))\n throw new Error('Can\\'t render blocks not including all upstreams.');\n }\n\n // traversing in topological order and rendering target blocks\n const rendered = new Set<string>();\n for (const block of allBlocks(this.structure)) {\n if (!blockIdsSet.has(block.id)) continue;\n\n let render\n = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);\n\n if (!render)\n for (const upstream of prodGraph.nodes.get(block.id)!.upstream)\n if (rendered.has(upstream)) {\n render = true;\n break;\n }\n\n if (render) {\n this.renderProductionFor(block.id);\n rendered.add(block.id);\n }\n }\n\n const renderedArray = [...rendered];\n\n // sending to limbo all downstream blocks\n prodGraph.traverse('downstream', renderedArray, (node) => {\n if (rendered.has(node.id))\n // don't send to limbo blocks that were just rendered\n return;\n this.resetOrLimboProduction(node.id);\n });\n\n // resetting staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', renderedArray, ({ id }) => {\n // don't reset staging of the first rendered block\n if (renderedArray[0] !== id) this.resetStaging(id);\n });\n\n if (rendered.size > 0) this.updateLastModified();\n\n return rendered;\n }\n\n /** Stops running blocks from the list and modify states of other blocks\n * accordingly */\n public stopProduction(...blockIds: string[]) {\n const activeProdGraph = this.getActualProductionGraph();\n\n // we will stop all blocks listed in request and all their downstreams\n const queue = new Denque(blockIds);\n const queued = new Set(blockIds);\n const stopped: string[] = [];\n\n while (!queue.isEmpty()) {\n const blockId = queue.shift()!;\n const fields = this.getBlockInfo(blockId).fields;\n\n if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready')\n // skipping finished blocks\n continue;\n\n if (this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs')) {\n // was actually stopped\n stopped.push(blockId);\n\n // will try to stop all its downstreams\n for (const downstream of activeProdGraph.traverseIdsExcludingRoots('downstream', blockId)) {\n if (queued.has(downstream)) continue;\n queue.push(downstream);\n queued.add(downstream);\n }\n }\n }\n\n // blocks under stopped blocks, but having finished production results, goes to limbo\n for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))\n this.resetOrLimboProduction(blockId);\n\n // reset staging outputs for all downstream blocks\n this.getStagingGraph().traverse('downstream', stopped, ({ id }) => this.resetStaging(id));\n }\n\n private traverseWithStagingLag(cb: (blockId: string, lag: number) => void) {\n const lags = new Map<string, number>();\n const stagingGraph = this.getStagingGraph();\n stagingGraph.nodes.forEach((node) => {\n const info = this.getBlockInfo(node.id);\n let lag = info.stagingRendered ? 0 : 1;\n node.upstream.forEach((upstream) => {\n const upstreamLag = lags.get(upstream)!;\n if (upstreamLag === 0) return;\n lag = Math.max(upstreamLag + 1, lag);\n });\n cb(node.id, lag);\n lags.set(node.id, lag);\n });\n }\n\n /** @param stagingRenderingRate rate in blocks per second */\n private refreshStagings(stagingRenderingRate?: number) {\n const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;\n const lagThreshold\n = stagingRenderingRate === undefined\n ? undefined\n : 1 + Math.max(0, (elapsed * stagingRenderingRate) / 1000);\n let rendered = 0;\n this.traverseWithStagingLag((blockId, lag) => {\n if (lag === 0)\n // meaning staging already rendered\n return;\n if (lagThreshold === undefined || lag <= lagThreshold) {\n this.renderStagingFor(blockId);\n rendered++;\n }\n });\n if (rendered > 0) this.resetStagingRefreshTimestamp();\n }\n\n //\n // Meta\n //\n\n /** Updates project metadata */\n public setMeta(meta: ProjectMeta): void {\n this.meta = meta;\n this.metaChanged = true;\n this.updateLastModified();\n }\n\n //\n // Maintenance\n //\n\n /** @param stagingRenderingRate rate in blocks per second */\n public doRefresh(stagingRenderingRate?: number) {\n this.refreshStagings(stagingRenderingRate);\n this.blockInfos.forEach((blockInfo) => {\n if (\n blockInfo.fields.prodCtx?.status === 'Ready'\n && blockInfo.fields.prodOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'prodOutputPrevious',\n 'prodCtxPrevious',\n 'prodUiCtxPrevious',\n );\n if (\n blockInfo.fields.stagingCtx?.status === 'Ready'\n && blockInfo.fields.stagingOutput?.status === 'Ready'\n )\n this.deleteBlockFields(\n blockInfo.id,\n 'stagingOutputPrevious',\n 'stagingCtxPrevious',\n 'stagingUiCtxPrevious',\n );\n });\n }\n\n private assignAuthorMarkers() {\n const markerStr = this.author ? JSON.stringify(this.author) : undefined;\n\n for (const blockId of this.blocksWithChangedInputs)\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, blockArgsAuthorKey(blockId));\n else this.tx.setKValue(this.rid, blockArgsAuthorKey(blockId), markerStr);\n\n if (this.metaChanged || this.structureChanged) {\n if (markerStr === undefined) this.tx.deleteKValue(this.rid, ProjectStructureAuthorKey);\n else this.tx.setKValue(this.rid, ProjectStructureAuthorKey, markerStr);\n }\n }\n\n public save() {\n if (!this.wasModified) return;\n\n if (this.lastModifiedChanged)\n this.tx.setKValue(this.rid, ProjectLastModifiedTimestamp, JSON.stringify(this.lastModified));\n\n if (this.structureChanged)\n this.tx.setKValue(this.rid, ProjectStructureKey, JSON.stringify(this.struct));\n\n if (this.renderingStateChanged)\n this.tx.setKValue(\n this.rid,\n BlockRenderingStateKey,\n JSON.stringify({\n ...this.renderingState,\n blocksInLimbo: [...this.blocksInLimbo],\n } as ProjectRenderingState),\n );\n\n if (this.metaChanged) this.tx.setKValue(this.rid, ProjectMetaKey, JSON.stringify(this.meta));\n\n this.assignAuthorMarkers();\n }\n\n public static async load(\n projectHelper: ProjectHelper,\n tx: PlTransaction,\n rid: ResourceId,\n author?: AuthorMarker,\n ): Promise<ProjectMutator> {\n //\n // Sending initial requests to read project state (start of round-trip #1)\n //\n\n const fullResourceStateP = tx.getResourceData(rid, true);\n const schemaP = tx.getKValueJson<string>(rid, SchemaVersionKey);\n const lastModifiedP = tx.getKValueJson<number>(rid, ProjectLastModifiedTimestamp);\n const metaP = tx.getKValueJson<ProjectMeta>(rid, ProjectMetaKey);\n const structureP = tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey);\n const renderingStateP = tx.getKValueJson<ProjectRenderingState>(rid, BlockRenderingStateKey);\n\n const fullResourceState = await fullResourceStateP;\n\n // loading field information\n const blockInfoStates = new Map<string, BlockInfoState>();\n for (const f of fullResourceState.fields) {\n const projectField = parseProjectField(f.name);\n\n // processing only fields with known structure\n if (projectField === undefined) continue;\n\n let info = blockInfoStates.get(projectField.blockId);\n if (info === undefined) {\n info = {\n id: projectField.blockId,\n fields: {},\n };\n blockInfoStates.set(projectField.blockId, info);\n }\n\n info.fields[projectField.fieldName] = isNullResourceId(f.value)\n ? { modCount: 0 }\n : { modCount: 0, ref: f.value };\n }\n\n //\n // Roundtrip #1 not yet finished, but as soon as field list is received,\n // we can start sending requests to read states of referenced resources\n // (start of round-trip #2)\n //\n\n const blockFieldRequests: [BlockInfoState, ProjectField['fieldName'], BlockFieldState, Promise<BasicResourceData | ResourceData>][] = [];\n blockInfoStates.forEach((info) => {\n const fields = info.fields;\n for (const [fName, state] of Object.entries(fields)) {\n if (state.ref === undefined) continue;\n if (!isResource(state.ref) || isResourceRef(state.ref))\n throw new Error('unexpected behaviour');\n const fieldName = fName as ProjectField['fieldName'];\n blockFieldRequests.push([\n info, fieldName,\n state, tx.getResourceData(state.ref, fieldName == 'blockPack')]);\n }\n });\n\n // loading jsons\n const [\n schema,\n lastModified,\n meta,\n structure,\n { stagingRefreshTimestamp, blocksInLimbo },\n ] = await Promise.all([\n schemaP,\n lastModifiedP,\n metaP,\n structureP,\n renderingStateP,\n ]);\n\n // Checking schema version of the project\n if (schema !== SchemaVersionCurrent) {\n if (Number(schema) < Number(SchemaVersionCurrent))\n throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);\n else\n throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);\n }\n\n //\n // <- at this point we have all the responses from round-trip #1\n //\n\n //\n // Receiving responses from round-trip #2 and sending requests to read block pack descriptions\n // (start of round-trip #3)\n //\n\n const blockPackRequests: [BlockInfoState, Promise<BasicResourceData>][] = [];\n for (const [info, fieldName, state, response] of blockFieldRequests) {\n const result = await response;\n state.value = result.data;\n if (isNotNullResourceId(result.error)) state.status = 'Error';\n else if (result.resourceReady || isNotNullResourceId(result.originalResourceId))\n state.status = 'Ready';\n else state.status = 'NotReady';\n\n // For block pack we need to traverse the ref field from the resource data\n if (fieldName === 'blockPack') {\n const refField = (result as ResourceData).fields.find((f) => f.name === Pl.HolderRefField);\n if (refField === undefined)\n throw new Error('Block pack ref field is missing');\n blockPackRequests.push([info, tx.getResourceData(ensureResourceIdNotNull(refField.value), false)]);\n }\n }\n\n //\n // <- at this point we have all the responses from round-trip #2\n //\n\n for (const [info, response] of blockPackRequests) {\n const result = await response;\n const bpInfo = cachedDeserialize<BlockPackInfo>(notEmpty(result.data));\n info.blockConfig = extractConfig(bpInfo.config);\n info.blockPack = bpInfo.source;\n }\n\n //\n // <- at this point we have all the responses from round-trip #3\n //\n\n // loading ctx export template to check if we already have cached materialized template in our project\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n\n // expected field name\n const ctxExportTplCacheFieldName = getServiceTemplateField(ctxExportTplEnvelope.hash);\n const ctxExportTplField = fullResourceState.fields.find(\n (f) => f.name === ctxExportTplCacheFieldName,\n );\n let ctxExportTplHolder: AnyResourceRef;\n if (ctxExportTplField !== undefined)\n ctxExportTplHolder = ensureResourceIdNotNull(ctxExportTplField.value);\n else {\n ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));\n tx.createField(\n field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n ctxExportTplHolder,\n );\n }\n\n const renderingState = { stagingRefreshTimestamp };\n const blocksInLimboSet = new Set(blocksInLimbo);\n\n const blockInfos = new Map<string, BlockInfo>();\n blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id,\n new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));\n\n // check consistency of project state\n const blockInStruct = new Set<string>();\n for (const b of allBlocks(structure)) {\n if (!blockInfos.has(b.id))\n throw new Error(`Inconsistent project structure: no inputs for ${b.id}`);\n blockInStruct.add(b.id);\n }\n blockInfos.forEach((info) => {\n if (!blockInStruct.has(info.id))\n throw new Error(`Inconsistent project structure: no structure entry for ${info.id}`);\n // checking structure\n info.check();\n });\n\n const prj = new ProjectMutator(\n rid,\n tx,\n author,\n schema,\n lastModified,\n meta,\n structure,\n renderingState,\n blocksInLimboSet,\n blockInfos,\n ctxExportTplHolder,\n projectHelper,\n );\n\n prj.fixProblemsAndMigrate();\n\n return prj;\n }\n}\n\nexport interface ProjectState {\n schema: string;\n structure: ProjectStructure;\n renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>;\n blocksInLimbo: Set<string>;\n blockInfos: Map<string, BlockInfo>;\n}\n\nexport async function createProject(\n tx: PlTransaction,\n meta: ProjectMeta = InitialBlockMeta,\n): Promise<AnyResourceRef> {\n const prj = tx.createEphemeral(ProjectResourceType);\n tx.lock(prj);\n const ts = String(Date.now());\n tx.setKValue(prj, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n tx.setKValue(prj, ProjectCreatedTimestamp, ts);\n tx.setKValue(prj, ProjectLastModifiedTimestamp, ts);\n tx.setKValue(prj, ProjectMetaKey, JSON.stringify(meta));\n tx.setKValue(prj, ProjectStructureKey, JSON.stringify(InitialBlockStructure));\n tx.setKValue(prj, BlockRenderingStateKey, JSON.stringify(InitialProjectRenderingState));\n const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();\n tx.createField(\n field(prj, getServiceTemplateField(ctxExportTplEnvelope.hash)),\n 'Dynamic',\n Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec)),\n );\n return prj;\n}\n\nexport async function withProject<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops?: Partial<TxOps>,\n): Promise<T> {\n return withProjectAuthored(projectHelper, txOrPl, rid, undefined, cb, ops);\n}\n\nexport async function withProjectAuthored<T>(\n projectHelper: ProjectHelper,\n txOrPl: PlTransaction | PlClient,\n rid: ResourceId,\n author: AuthorMarker | undefined,\n cb: (p: ProjectMutator) => T | Promise<T>,\n ops: Partial<TxOps> = {},\n): Promise<T> {\n if (txOrPl instanceof PlClient) {\n return await txOrPl.withWriteTx('ProjectAction' + (ops.name ? `: ${ops.name}` : ''), async (tx) => {\n const mut = await ProjectMutator.load(projectHelper, tx, rid, author);\n const result = await cb(mut);\n if (!mut.wasModified)\n // skipping save and commit altogether if no modifications were actually made\n return result;\n mut.save();\n await tx.commit();\n if (getDebugFlags().logProjectMutationStat) console.log(JSON.stringify(tx.stat));\n return result;\n }, ops);\n } else {\n const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);\n const result = await cb(mut);\n mut.save();\n return result;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA4FA,SAAS,MAAM,CAAW,OAAoB,EAAE,OAAgB,EAAA;IAC9D,IAAI,WAAW,GAAG,KAAK;IACvB,IAAI,SAAS,GAAsB,SAAS;IAC5C,IAAI,KAAK,GAAkB,SAAS;AACpC,IAAA,OAAO,MAAK;QACV,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI;YAClB,SAAS,GAAG,OAAO,EAAE;YACrB,KAAK,GAAG,OAAO,EAAE;AACjB,YAAA,OAAO,KAAK;QACd;AACA,QAAA,MAAM,YAAY,GAAG,OAAO,EAAE;AAC9B,QAAA,IAAI,SAAS,KAAK,YAAY,EAAE;YAC9B,SAAS,GAAG,YAAY;YACxB,KAAK,GAAG,OAAO,EAAE;QACnB;QACA,OAAO,OAAO,EAAE;AAClB,IAAA,CAAC;AACH;AAEA,MAAM,SAAS,CAAA;AAEK,IAAA,EAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AACA,IAAA,MAAA;AAJlB,IAAA,WAAA,CACkB,EAAU,EACV,MAAwB,EACxB,MAAmB,EACnB,MAAqB,EAAA;QAHrB,IAAA,CAAA,EA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AAM,EAAE,CAAC,GAAG,CAAC;YAC5B,IAAI,CAAC,GAAG,CAAC,WAAW;;AAElB,gBAAA,OAAO,MAAM;YACf,GAAG,CAAC,IAAI,EAAE;AACV,YAAA,MAAM,EAAE,CAAC,MAAM,EAAE;YACjB,IAAI,aAAa,EAAE,CAAC,sBAAsB;AAAE,gBAAA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAChF,YAAA,OAAO,MAAM;QACf,CAAC,EAAE,GAAG,CAAC;IACT;SAAO;AACL,QAAA,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC;AACzE,QAAA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC;QAC5B,GAAG,CAAC,IAAI,EAAE;AACV,QAAA,OAAO,MAAM;IACf;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-middle-layer",
3
- "version": "1.44.1",
3
+ "version": "1.45.0",
4
4
  "description": "Pl Middle Layer",
5
5
  "engines": {
6
6
  "node": ">=22.19.0"
@@ -33,22 +33,22 @@
33
33
  "zod": "~3.23.8",
34
34
  "remeda": "^2.28.0",
35
35
  "@milaboratories/pl-http": "1.2.0",
36
- "@milaboratories/pl-client": "2.16.19",
37
- "@milaboratories/computable": "2.7.5",
38
- "@milaboratories/pl-drivers": "1.11.36",
39
- "@platforma-sdk/block-tools": "2.6.28",
40
36
  "@milaboratories/resolve-helper": "1.1.1",
41
- "@milaboratories/pl-model-middle-layer": "1.9.0",
42
- "@milaboratories/pl-model-backend": "1.1.36",
43
- "@milaboratories/pl-tree": "1.8.27",
44
- "@platforma-sdk/model": "1.49.0",
37
+ "@milaboratories/computable": "2.8.0",
38
+ "@platforma-sdk/block-tools": "2.6.29",
39
+ "@milaboratories/pl-drivers": "1.11.37",
40
+ "@milaboratories/pl-client": "2.16.20",
41
+ "@milaboratories/pl-model-common": "1.23.0",
42
+ "@milaboratories/pl-model-backend": "1.1.37",
43
+ "@milaboratories/pl-model-middle-layer": "1.9.1",
45
44
  "@milaboratories/ts-helpers": "1.5.4",
46
- "@milaboratories/pl-config": "1.7.9",
47
45
  "@platforma-sdk/workflow-tengo": "5.7.3",
48
- "@milaboratories/pl-deployments": "2.15.0",
49
- "@milaboratories/pf-driver": "1.0.18",
50
- "@milaboratories/pl-model-common": "1.22.0",
51
- "@milaboratories/pl-errors": "1.1.51"
46
+ "@platforma-sdk/model": "1.50.0",
47
+ "@milaboratories/pl-config": "1.7.9",
48
+ "@milaboratories/pl-errors": "1.1.52",
49
+ "@milaboratories/pl-tree": "1.8.28",
50
+ "@milaboratories/pl-deployments": "2.15.1",
51
+ "@milaboratories/pf-driver": "1.0.19"
52
52
  },
53
53
  "devDependencies": {
54
54
  "semver": "^7.7.2",
@@ -59,9 +59,9 @@
59
59
  "eslint": "^9.25.1",
60
60
  "@types/node": "~24.5.2",
61
61
  "tslib": "~2.7.0",
62
- "@milaboratories/ts-builder": "1.2.1",
63
62
  "@milaboratories/build-configs": "1.2.1",
64
63
  "@milaboratories/eslint-config": "1.0.5",
64
+ "@milaboratories/ts-builder": "1.2.1",
65
65
  "@milaboratories/ts-configs": "1.2.0"
66
66
  },
67
67
  "scripts": {
@@ -607,15 +607,19 @@ export class ProjectMutator {
607
607
  context: ctx,
608
608
  });
609
609
 
610
+ // Here we set the staging ctx to the input context of the staging workflow, not the output because exports
611
+ // of one staging context should stay within the same block, and not travel downstream.
612
+ // We may change this decision in the future if wanted to support traveling staging exports downstream.
610
613
  this.setBlockField(
611
614
  blockId,
612
615
  'stagingCtx',
613
- Pl.wrapInEphHolder(this.tx, results.context),
616
+ Pl.wrapInEphHolder(this.tx, ctx),
614
617
  'NotReady',
615
618
  );
616
619
 
620
+ // Yet the staging UI Ctx is the output context of the staging workflow, because it is used to form the result pool
621
+ // thus creating a certain discrepancy between staging workflow context behavior and desktop's result pool.
617
622
  this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');
618
-
619
623
  this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');
620
624
  }
621
625
 
@@ -1006,9 +1010,12 @@ export class ProjectMutator {
1006
1010
  }
1007
1011
  }
1008
1012
 
1009
- // blocks under stopped blocks, but still having results, goes to limbo
1013
+ // blocks under stopped blocks, but having finished production results, goes to limbo
1010
1014
  for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))
1011
1015
  this.resetOrLimboProduction(blockId);
1016
+
1017
+ // reset staging outputs for all downstream blocks
1018
+ this.getStagingGraph().traverse('downstream', stopped, ({ id }) => this.resetStaging(id));
1012
1019
  }
1013
1020
 
1014
1021
  private traverseWithStagingLag(cb: (blockId: string, lag: number) => void) {