@milaboratories/pl-middle-layer 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/middle_layer/build_stamp.cjs +1 -1
- package/dist/middle_layer/build_stamp.js +1 -1
- package/dist/middle_layer/project_overview.cjs +1 -1
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.js +1 -1
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/package.json +2 -2
- package/src/middle_layer/project_overview.ts +3 -1
|
@@ -114,7 +114,7 @@ function projectOverview(prjEntry, navigationStates, env) {
|
|
|
114
114
|
env.logger.error(new Error("Error in block model title", { cause }));
|
|
115
115
|
return "Invalid title";
|
|
116
116
|
} })),
|
|
117
|
-
subtitle: require_util.ifNotUndef(cfg.subtitle, (subtitle) => require_render.computableFromCfgOrRF(env,
|
|
117
|
+
subtitle: require_util.ifNotUndef(cfg.subtitle, (subtitle) => require_render.computableFromCfgOrRF(env, blockCtx, subtitle, codeWithInfo, bpId, {}, blockPackInfo.source).wrap({ recover: (cause) => {
|
|
118
118
|
env.logger.error(new Error("Error in block model subtitle", { cause }));
|
|
119
119
|
return "Invalid subtitle";
|
|
120
120
|
} })),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_overview.cjs","names":["omitBy","isEqual","Computable","notEmpty","ProjectCreatedTimestamp","ProjectLastModifiedTimestamp","ProjectMetaKey","ProjectStructureKey","BlockRenderingStateKey","allBlocks","projectFieldName","productionGraph","getBlockPackInfo","ifNotUndef","constructBlockContext","constructBlockContextArgsOnly","wrapCallback","extractCodeWithInfo","computableFromCfgOrRF","BLOCK_STORAGE_FACADE_VERSION","resourceIdToString","ProjectStructureAuthorKey","getDebugFlags","readArgsErrorsField"],"sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport type { ComputableStableDefined } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectRenderingState, ProjectStructure } from \"../model/project_model\";\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from \"../model/project_model\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { allBlocks, productionGraph } from \"../model/project_model_util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from \"@milaboratories/pl-model-middle-layer\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport { type BlockSection, BLOCK_STORAGE_FACADE_VERSION } from \"@platforma-sdk/model\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport type { NavigationStates } from \"./navigation_states\";\nimport { getBlockPackInfo } from \"./util\";\nimport { resourceIdToString, type SignedResourceId } from \"@milaboratories/pl-client\";\nimport { omitBy, isEqual } from \"es-toolkit\";\nimport { getDebugFlags } from \"../debug\";\nimport { readArgsErrorsField } from \"../model/args_derivation\";\n\ntype BlockInfo = {\n argsRid?: SignedResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(\n a: Record<string, unknown> | undefined,\n b: Record<string, unknown> | undefined,\n): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const cleanA = omitBy(a, (_, key) => key.startsWith(\"__\"));\n const cleanB = omitBy(b, (_, key) => key.startsWith(\"__\"));\n return isEqual(cleanA, cleanB);\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, \"currentArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, \"prodArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, \"prodOutput\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, \"prodUiCtx\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined ||\n ctx.error !== undefined ||\n result.value?.getError() !== undefined ||\n ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError()) ||\n (result.error !== undefined && result.error.getIsReadyOrError())) &&\n ((ctx.value !== undefined && ctx.value.getIsReadyOrError()) ||\n (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = \"NotCalculated\";\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = \"Limbo\";\n else calculationStatus = info.prod.finished ? \"Done\" : \"Running\";\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const {\n sections,\n title,\n subtitle,\n tags,\n inputsValid,\n inputsValidFromArgs,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n } =\n ifNotUndef(bp, ({ bpId, cfg, info: blockPackInfo }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model sections\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model title\", { cause }));\n return \"Invalid title\";\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n subtitle,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model subtitle\", { cause }));\n return \"Invalid subtitle\";\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model tags\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // and the block's argsIssues() is known to have found no errors in them.\n // For older blocks, use the inputsValid callback from config\n inputsValid:\n cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION\n ? argsAllowRun(prj, id, info.currentArguments)\n : cfg.inputsValid\n ? (computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(\n new Error(\"Error in block model inputsValid\", { cause }),\n );\n return false;\n },\n }) as ComputableStableDefined<boolean>)\n : undefined,\n inputsValidFromArgs: cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, \"blockSettings\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === \"Limbo\",\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots(\"upstream\", id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots(\"downstream\", id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n inputsValidFromArgs: inputsValidFromArgs === true,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => ({\n ...value,\n blocks: withRunState(value.blocks).map(({ updates, inputsValidFromArgs: _, ...b }) => ({\n ...b,\n updateSuggestions: updates?.suggestions ?? [],\n updatedBlockPack: updates?.mainSuggestion,\n })),\n }),\n onRecalculation: getDebugFlags().logProjectOverviewStat\n ? (stats) => {\n console.log(`[projectOverview] ${JSON.stringify(stats)}`);\n }\n : undefined,\n },\n ).withStableType();\n}\n\n/**\n * Whether the args of a block with model API version 2 let it run: the block has current args,\n * and its `inputsValid` field records no errors its `argsIssues()` found in them (see\n * `readArgsErrorsField`).\n *\n * @param currentArgs - The block's current args as decoded from its `currentArgs` field;\n * `undefined` when it has none\n */\nexport function argsAllowRun(\n prj: PlTreeNodeAccessor,\n blockId: string,\n currentArgs: unknown,\n): boolean {\n if (currentArgs === undefined) return false;\n const argsErrors = prj.getField({\n field: projectFieldName(blockId, \"inputsValid\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n return readArgsErrorsField(argsErrors?.value?.getData(), currentArgs).length === 0;\n}\n\n/** What the run state of a block is derived from. */\nexport type RunStateSource = {\n id: string;\n /** Whether the block's own args differ from those its results were rendered with. */\n stale: boolean;\n outputErrors: boolean;\n inputsValid: boolean | undefined;\n /**\n * Whether `inputsValid` tells only whether the block's current args may run: a block with model\n * API version 2 this runtime is compatible with. Otherwise it also stands for a block whose code\n * cannot run here, or for checks of a model that predates args issues.\n */\n inputsValidFromArgs: boolean;\n missingReference: boolean;\n /** Every block upstream of this one, direct or not. */\n upstreams: string[];\n};\n\n/**\n * Adds the run state to each block of a project, the blocks listed upstream first. A block is\n * stale when its own args changed or an upstream block is stale. It can run when it needs to run\n * (it is stale or its outputs failed), its args allow it, it references no missing block, and no\n * upstream block that needs to run is kept from running. An upstream block whose `inputsValid`\n * comes from its args and whose results are up to date feeds its dependents even when its args\n * could not run again; any other upstream block that is not valid keeps them from running.\n */\nexport function withRunState<B extends RunStateSource>(\n blocks: B[],\n): (B & { stale: boolean; canRun: boolean })[] {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return blocks.map((b) => {\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.some((u) => staleBlocks.has(u));\n const needsRun = stale || b.outputErrors;\n if (!b.inputsValid && (needsRun || !b.inputsValidFromArgs)) cantRun.add(b.id);\n const canRun =\n needsRun &&\n Boolean(b.inputsValid) &&\n !b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BC,cAAAA,cAAc,CAAC,CAAC,0BAC5B,UAAU;GACT,QAAQ,IAAI,qBAAqB,KAAK,UAAU,KAAK,GAAG;EAC1D,IACA,KAAA;CACN,CACF,CAAC,CAAC,eAAe;AACnB;;;;;;;;;AAUA,SAAgB,aACd,KACA,SACA,aACS;CACT,IAAI,gBAAgB,KAAA,GAAW,OAAO;CACtC,MAAM,aAAa,IAAI,SAAS;EAC9B,OAAOZ,sBAAAA,iBAAiB,SAAS,aAAa;EAC9C,iBAAiB;EACjB,kBAAkB;CACpB,CAAC;CACD,OAAOa,wBAAAA,oBAAoB,YAAY,OAAO,QAAQ,GAAG,WAAW,CAAC,CAAC,WAAW;AACnF;;;;;;;;;AA4BA,SAAgB,aACd,QAC6C;CAC7C,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,8BAAc,IAAI,IAAY;CACpC,OAAO,OAAO,KAAK,MAAM;EACvB,IAAI,EAAE,OAAO,YAAY,IAAI,EAAE,EAAE;EACjC,MAAM,QAAQ,EAAE,SAAS,EAAE,UAAU,MAAM,MAAM,YAAY,IAAI,CAAC,CAAC;EACnE,MAAM,WAAW,SAAS,EAAE;EAC5B,IAAI,CAAC,EAAE,gBAAgB,YAAY,CAAC,EAAE,sBAAsB,QAAQ,IAAI,EAAE,EAAE;EAC5E,MAAM,SACJ,YACA,QAAQ,EAAE,WAAW,KACrB,CAAC,EAAE,oBACH,CAAC,EAAE,UAAU,MAAM,MAAM,QAAQ,IAAI,CAAC,CAAC;EACzC,OAAO;GAAE,GAAG;GAAG;GAAO;EAAO;CAC/B,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"project_overview.cjs","names":["omitBy","isEqual","Computable","notEmpty","ProjectCreatedTimestamp","ProjectLastModifiedTimestamp","ProjectMetaKey","ProjectStructureKey","BlockRenderingStateKey","allBlocks","projectFieldName","productionGraph","getBlockPackInfo","ifNotUndef","constructBlockContext","constructBlockContextArgsOnly","wrapCallback","extractCodeWithInfo","computableFromCfgOrRF","BLOCK_STORAGE_FACADE_VERSION","resourceIdToString","ProjectStructureAuthorKey","getDebugFlags","readArgsErrorsField"],"sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport type { ComputableStableDefined } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectRenderingState, ProjectStructure } from \"../model/project_model\";\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from \"../model/project_model\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { allBlocks, productionGraph } from \"../model/project_model_util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from \"@milaboratories/pl-model-middle-layer\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport { type BlockSection, BLOCK_STORAGE_FACADE_VERSION } from \"@platforma-sdk/model\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport type { NavigationStates } from \"./navigation_states\";\nimport { getBlockPackInfo } from \"./util\";\nimport { resourceIdToString, type SignedResourceId } from \"@milaboratories/pl-client\";\nimport { omitBy, isEqual } from \"es-toolkit\";\nimport { getDebugFlags } from \"../debug\";\nimport { readArgsErrorsField } from \"../model/args_derivation\";\n\ntype BlockInfo = {\n argsRid?: SignedResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(\n a: Record<string, unknown> | undefined,\n b: Record<string, unknown> | undefined,\n): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const cleanA = omitBy(a, (_, key) => key.startsWith(\"__\"));\n const cleanB = omitBy(b, (_, key) => key.startsWith(\"__\"));\n return isEqual(cleanA, cleanB);\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, \"currentArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, \"prodArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, \"prodOutput\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, \"prodUiCtx\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined ||\n ctx.error !== undefined ||\n result.value?.getError() !== undefined ||\n ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError()) ||\n (result.error !== undefined && result.error.getIsReadyOrError())) &&\n ((ctx.value !== undefined && ctx.value.getIsReadyOrError()) ||\n (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = \"NotCalculated\";\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = \"Limbo\";\n else calculationStatus = info.prod.finished ? \"Done\" : \"Running\";\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const {\n sections,\n title,\n subtitle,\n tags,\n inputsValid,\n inputsValidFromArgs,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n } =\n ifNotUndef(bp, ({ bpId, cfg, info: blockPackInfo }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model sections\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model title\", { cause }));\n return \"Invalid title\";\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n // The subtitle names the inputs the block reads, so it renders with the\n // result pool; the title stays args-only.\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n subtitle,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model subtitle\", { cause }));\n return \"Invalid subtitle\";\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model tags\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // and the block's argsIssues() is known to have found no errors in them.\n // For older blocks, use the inputsValid callback from config\n inputsValid:\n cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION\n ? argsAllowRun(prj, id, info.currentArguments)\n : cfg.inputsValid\n ? (computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(\n new Error(\"Error in block model inputsValid\", { cause }),\n );\n return false;\n },\n }) as ComputableStableDefined<boolean>)\n : undefined,\n inputsValidFromArgs: cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, \"blockSettings\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === \"Limbo\",\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots(\"upstream\", id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots(\"downstream\", id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n inputsValidFromArgs: inputsValidFromArgs === true,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => ({\n ...value,\n blocks: withRunState(value.blocks).map(({ updates, inputsValidFromArgs: _, ...b }) => ({\n ...b,\n updateSuggestions: updates?.suggestions ?? [],\n updatedBlockPack: updates?.mainSuggestion,\n })),\n }),\n onRecalculation: getDebugFlags().logProjectOverviewStat\n ? (stats) => {\n console.log(`[projectOverview] ${JSON.stringify(stats)}`);\n }\n : undefined,\n },\n ).withStableType();\n}\n\n/**\n * Whether the args of a block with model API version 2 let it run: the block has current args,\n * and its `inputsValid` field records no errors its `argsIssues()` found in them (see\n * `readArgsErrorsField`).\n *\n * @param currentArgs - The block's current args as decoded from its `currentArgs` field;\n * `undefined` when it has none\n */\nexport function argsAllowRun(\n prj: PlTreeNodeAccessor,\n blockId: string,\n currentArgs: unknown,\n): boolean {\n if (currentArgs === undefined) return false;\n const argsErrors = prj.getField({\n field: projectFieldName(blockId, \"inputsValid\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n return readArgsErrorsField(argsErrors?.value?.getData(), currentArgs).length === 0;\n}\n\n/** What the run state of a block is derived from. */\nexport type RunStateSource = {\n id: string;\n /** Whether the block's own args differ from those its results were rendered with. */\n stale: boolean;\n outputErrors: boolean;\n inputsValid: boolean | undefined;\n /**\n * Whether `inputsValid` tells only whether the block's current args may run: a block with model\n * API version 2 this runtime is compatible with. Otherwise it also stands for a block whose code\n * cannot run here, or for checks of a model that predates args issues.\n */\n inputsValidFromArgs: boolean;\n missingReference: boolean;\n /** Every block upstream of this one, direct or not. */\n upstreams: string[];\n};\n\n/**\n * Adds the run state to each block of a project, the blocks listed upstream first. A block is\n * stale when its own args changed or an upstream block is stale. It can run when it needs to run\n * (it is stale or its outputs failed), its args allow it, it references no missing block, and no\n * upstream block that needs to run is kept from running. An upstream block whose `inputsValid`\n * comes from its args and whose results are up to date feeds its dependents even when its args\n * could not run again; any other upstream block that is not valid keeps them from running.\n */\nexport function withRunState<B extends RunStateSource>(\n blocks: B[],\n): (B & { stale: boolean; canRun: boolean })[] {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return blocks.map((b) => {\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.some((u) => staleBlocks.has(u));\n const needsRun = stale || b.outputErrors;\n if (!b.inputsValid && (needsRun || !b.inputsValidFromArgs)) cantRun.add(b.id);\n const canRun =\n needsRun &&\n Boolean(b.inputsValid) &&\n !b.missingReference &&\n !b.upstreams.some((u) => cantRun.has(u));\n return { ...b, stale, canRun };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAwDA,SAAS,WACP,GACA,GACS;CACT,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,MAAM,KAAA,KAAa,MAAM,KAAA,GAAW,OAAO;CAC/C,MAAM,UAAA,GAASA,WAAAA,OAAAA,CAAO,IAAI,GAAG,QAAQ,IAAI,WAAW,IAAI,CAAC;CACzD,MAAM,UAAA,GAASA,WAAAA,OAAAA,CAAO,IAAI,GAAG,QAAQ,IAAI,WAAW,IAAI,CAAC;CACzD,QAAA,GAAOC,WAAAA,QAAAA,CAAQ,QAAQ,MAAM;AAC/B;;AAGA,SAAgB,gBACd,UACA,kBACA,KAC0C;CAC1C,OAAOC,2BAAAA,WAAW,MACf,QAAQ;EACP,MAAM,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK;EAExC,MAAM,WAAA,GAAUC,2BAAAA,SAAAA,CAAS,IAAI,kBAA0BC,sBAAAA,uBAAuB,CAAC;EAC/E,MAAM,gBAAA,GAAeD,2BAAAA,SAAAA,CAAS,IAAI,kBAA0BE,sBAAAA,4BAA4B,CAAC;EAEzF,MAAM,QAAA,GAAOF,2BAAAA,SAAAA,CAAS,IAAI,kBAA+BG,sBAAAA,cAAc,CAAC;EACxE,MAAM,aAAA,GAAYH,2BAAAA,SAAAA,CAAS,IAAI,kBAAoCI,sBAAAA,mBAAmB,CAAC;EACvF,MAAM,kBAAA,GAAiBJ,2BAAAA,SAAAA,CACrB,IAAI,kBAAyCK,sBAAAA,sBAAsB,CACrE;EAEA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projectOverview(prjEntry, navigationStates, env) {
|
|
|
114
114
|
env.logger.error(new Error("Error in block model title", { cause }));
|
|
115
115
|
return "Invalid title";
|
|
116
116
|
} })),
|
|
117
|
-
subtitle: ifNotUndef(cfg.subtitle, (subtitle) => computableFromCfgOrRF(env,
|
|
117
|
+
subtitle: ifNotUndef(cfg.subtitle, (subtitle) => computableFromCfgOrRF(env, blockCtx, subtitle, codeWithInfo, bpId, {}, blockPackInfo.source).wrap({ recover: (cause) => {
|
|
118
118
|
env.logger.error(new Error("Error in block model subtitle", { cause }));
|
|
119
119
|
return "Invalid subtitle";
|
|
120
120
|
} })),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project_overview.js","names":[],"sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport type { ComputableStableDefined } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectRenderingState, ProjectStructure } from \"../model/project_model\";\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from \"../model/project_model\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { allBlocks, productionGraph } from \"../model/project_model_util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from \"@milaboratories/pl-model-middle-layer\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport { type BlockSection, BLOCK_STORAGE_FACADE_VERSION } from \"@platforma-sdk/model\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport type { NavigationStates } from \"./navigation_states\";\nimport { getBlockPackInfo } from \"./util\";\nimport { resourceIdToString, type SignedResourceId } from \"@milaboratories/pl-client\";\nimport { omitBy, isEqual } from \"es-toolkit\";\nimport { getDebugFlags } from \"../debug\";\nimport { readArgsErrorsField } from \"../model/args_derivation\";\n\ntype BlockInfo = {\n argsRid?: SignedResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(\n a: Record<string, unknown> | undefined,\n b: Record<string, unknown> | undefined,\n): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const cleanA = omitBy(a, (_, key) => key.startsWith(\"__\"));\n const cleanB = omitBy(b, (_, key) => key.startsWith(\"__\"));\n return isEqual(cleanA, cleanB);\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, \"currentArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, \"prodArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, \"prodOutput\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, \"prodUiCtx\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined ||\n ctx.error !== undefined ||\n result.value?.getError() !== undefined ||\n ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError()) ||\n (result.error !== undefined && result.error.getIsReadyOrError())) &&\n ((ctx.value !== undefined && ctx.value.getIsReadyOrError()) ||\n (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = \"NotCalculated\";\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = \"Limbo\";\n else calculationStatus = info.prod.finished ? \"Done\" : \"Running\";\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const {\n sections,\n title,\n subtitle,\n tags,\n inputsValid,\n inputsValidFromArgs,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n } =\n ifNotUndef(bp, ({ bpId, cfg, info: blockPackInfo }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model sections\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model title\", { cause }));\n return \"Invalid title\";\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n subtitle,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model subtitle\", { cause }));\n return \"Invalid subtitle\";\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model tags\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // and the block's argsIssues() is known to have found no errors in them.\n // For older blocks, use the inputsValid callback from config\n inputsValid:\n cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION\n ? argsAllowRun(prj, id, info.currentArguments)\n : cfg.inputsValid\n ? (computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(\n new Error(\"Error in block model inputsValid\", { cause }),\n );\n return false;\n },\n }) as ComputableStableDefined<boolean>)\n : undefined,\n inputsValidFromArgs: cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, \"blockSettings\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === \"Limbo\",\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots(\"upstream\", id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots(\"downstream\", id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n inputsValidFromArgs: inputsValidFromArgs === true,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => ({\n ...value,\n blocks: withRunState(value.blocks).map(({ updates, inputsValidFromArgs: _, ...b }) => ({\n ...b,\n updateSuggestions: updates?.suggestions ?? [],\n updatedBlockPack: updates?.mainSuggestion,\n })),\n }),\n onRecalculation: getDebugFlags().logProjectOverviewStat\n ? (stats) => {\n console.log(`[projectOverview] ${JSON.stringify(stats)}`);\n }\n : undefined,\n },\n ).withStableType();\n}\n\n/**\n * Whether the args of a block with model API version 2 let it run: the block has current args,\n * and its `inputsValid` field records no errors its `argsIssues()` found in them (see\n * `readArgsErrorsField`).\n *\n * @param currentArgs - The block's current args as decoded from its `currentArgs` field;\n * `undefined` when it has none\n */\nexport function argsAllowRun(\n prj: PlTreeNodeAccessor,\n blockId: string,\n currentArgs: unknown,\n): boolean {\n if (currentArgs === undefined) return false;\n const argsErrors = prj.getField({\n field: projectFieldName(blockId, \"inputsValid\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n return readArgsErrorsField(argsErrors?.value?.getData(), currentArgs).length === 0;\n}\n\n/** What the run state of a block is derived from. */\nexport type RunStateSource = {\n id: string;\n /** Whether the block's own args differ from those its results were rendered with. */\n stale: boolean;\n outputErrors: boolean;\n inputsValid: boolean | undefined;\n /**\n * Whether `inputsValid` tells only whether the block's current args may run: a block with model\n * API version 2 this runtime is compatible with. Otherwise it also stands for a block whose code\n * cannot run here, or for checks of a model that predates args issues.\n */\n inputsValidFromArgs: boolean;\n missingReference: boolean;\n /** Every block upstream of this one, direct or not. */\n upstreams: string[];\n};\n\n/**\n * Adds the run state to each block of a project, the blocks listed upstream first. A block is\n * stale when its own args changed or an upstream block is stale. It can run when it needs to run\n * (it is stale or its outputs failed), its args allow it, it references no missing block, and no\n * upstream block that needs to run is kept from running. An upstream block whose `inputsValid`\n * comes from its args and whose results are up to date feeds its dependents even when its args\n * could not run again; any other upstream block that is not valid keeps them from running.\n */\nexport function withRunState<B extends RunStateSource>(\n blocks: B[],\n): (B & { stale: boolean; canRun: boolean })[] {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return blocks.map((b) => {\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.some((u) => staleBlocks.has(u));\n const needsRun = stale || b.outputErrors;\n if (!b.inputsValid && (needsRun || !b.inputsValidFromArgs)) cantRun.add(b.id);\n const canRun =\n needsRun &&\n Boolean(b.inputsValid) &&\n !b.missingReference &&\n !b.upstreams.some((u) => cantRun.has(u));\n return { ...b, stale, canRun };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAwDA,SAAS,WACP,GACA,GACS;CACT,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,MAAM,KAAA,KAAa,MAAM,KAAA,GAAW,OAAO;CAC/C,MAAM,SAAS,OAAO,IAAI,GAAG,QAAQ,IAAI,WAAW,IAAI,CAAC;CACzD,MAAM,SAAS,OAAO,IAAI,GAAG,QAAQ,IAAI,WAAW,IAAI,CAAC;CACzD,OAAO,QAAQ,QAAQ,MAAM;AAC/B;;AAGA,SAAgB,gBACd,UACA,kBACA,KAC0C;CAC1C,OAAO,WAAW,MACf,QAAQ;EACP,MAAM,MAAM,IAAI,SAAS,QAAQ,CAAC,CAAC,KAAK;EAExC,MAAM,UAAU,SAAS,IAAI,kBAA0B,uBAAuB,CAAC;EAC/E,MAAM,eAAe,SAAS,IAAI,kBAA0B,4BAA4B,CAAC;EAEzF,MAAM,OAAO,SAAS,IAAI,kBAA+B,cAAc,CAAC;EACxE,MAAM,YAA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CAAC,0BAC5B,UAAU;GACT,QAAQ,IAAI,qBAAqB,KAAK,UAAU,KAAK,GAAG;EAC1D,IACA,KAAA;CACN,CACF,CAAC,CAAC,eAAe;AACnB;;;;;;;;;AAUA,SAAgB,aACd,KACA,SACA,aACS;CACT,IAAI,gBAAgB,KAAA,GAAW,OAAO;CACtC,MAAM,aAAa,IAAI,SAAS;EAC9B,OAAO,iBAAiB,SAAS,aAAa;EAC9C,iBAAiB;EACjB,kBAAkB;CACpB,CAAC;CACD,OAAO,oBAAoB,YAAY,OAAO,QAAQ,GAAG,WAAW,CAAC,CAAC,WAAW;AACnF;;;;;;;;;AA4BA,SAAgB,aACd,QAC6C;CAC7C,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,8BAAc,IAAI,IAAY;CACpC,OAAO,OAAO,KAAK,MAAM;EACvB,IAAI,EAAE,OAAO,YAAY,IAAI,EAAE,EAAE;EACjC,MAAM,QAAQ,EAAE,SAAS,EAAE,UAAU,MAAM,MAAM,YAAY,IAAI,CAAC,CAAC;EACnE,MAAM,WAAW,SAAS,EAAE;EAC5B,IAAI,CAAC,EAAE,gBAAgB,YAAY,CAAC,EAAE,sBAAsB,QAAQ,IAAI,EAAE,EAAE;EAC5E,MAAM,SACJ,YACA,QAAQ,EAAE,WAAW,KACrB,CAAC,EAAE,oBACH,CAAC,EAAE,UAAU,MAAM,MAAM,QAAQ,IAAI,CAAC,CAAC;EACzC,OAAO;GAAE,GAAG;GAAG;GAAO;EAAO;CAC/B,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"project_overview.js","names":[],"sources":["../../src/middle_layer/project_overview.ts"],"sourcesContent":["import type { PlTreeEntry, PlTreeNodeAccessor } from \"@milaboratories/pl-tree\";\nimport type { ComputableStableDefined } from \"@milaboratories/computable\";\nimport { Computable } from \"@milaboratories/computable\";\nimport type { ProjectRenderingState, ProjectStructure } from \"../model/project_model\";\nimport {\n BlockRenderingStateKey,\n ProjectCreatedTimestamp,\n projectFieldName,\n ProjectLastModifiedTimestamp,\n ProjectMetaKey,\n ProjectStructureAuthorKey,\n ProjectStructureKey,\n} from \"../model/project_model\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport { allBlocks, productionGraph } from \"../model/project_model_util\";\nimport type { MiddleLayerEnvironment } from \"./middle_layer\";\nimport type {\n AuthorMarker,\n BlockCalculationStatus,\n BlockSettings,\n ProjectMeta,\n ProjectOverview,\n} from \"@milaboratories/pl-model-middle-layer\";\nimport { constructBlockContext, constructBlockContextArgsOnly } from \"./block_ctx\";\nimport { ifNotUndef } from \"../cfg_render/util\";\nimport { type BlockSection, BLOCK_STORAGE_FACADE_VERSION } from \"@platforma-sdk/model\";\nimport { extractCodeWithInfo, wrapCallback } from \"@platforma-sdk/model\";\nimport { computableFromCfgOrRF } from \"./render\";\nimport type { NavigationStates } from \"./navigation_states\";\nimport { getBlockPackInfo } from \"./util\";\nimport { resourceIdToString, type SignedResourceId } from \"@milaboratories/pl-client\";\nimport { omitBy, isEqual } from \"es-toolkit\";\nimport { getDebugFlags } from \"../debug\";\nimport { readArgsErrorsField } from \"../model/args_derivation\";\n\ntype BlockInfo = {\n argsRid?: SignedResourceId;\n currentArguments: unknown;\n prod?: ProdState;\n};\n\ntype ProdState = {\n finished: boolean;\n\n outputError: boolean;\n\n outputsError?: string;\n\n exportsError?: string;\n\n stale: boolean;\n\n /** Arguments current production was rendered with. */\n arguments: Record<string, unknown>;\n};\n\nfunction argsEquals(\n a: Record<string, unknown> | undefined,\n b: Record<string, unknown> | undefined,\n): boolean {\n if (a === b) return true;\n if (a === undefined || b === undefined) return false;\n const cleanA = omitBy(a, (_, key) => key.startsWith(\"__\"));\n const cleanB = omitBy(b, (_, key) => key.startsWith(\"__\"));\n return isEqual(cleanA, cleanB);\n}\n\n/** Returns derived general project state form the project resource */\nexport function projectOverview(\n prjEntry: PlTreeEntry,\n navigationStates: NavigationStates,\n env: MiddleLayerEnvironment,\n): ComputableStableDefined<ProjectOverview> {\n return Computable.make(\n (ctx) => {\n const prj = ctx.accessor(prjEntry).node();\n\n const created = notEmpty(prj.getKeyValueAsJson<number>(ProjectCreatedTimestamp));\n const lastModified = notEmpty(prj.getKeyValueAsJson<number>(ProjectLastModifiedTimestamp));\n\n const meta = notEmpty(prj.getKeyValueAsJson<ProjectMeta>(ProjectMetaKey));\n const structure = notEmpty(prj.getKeyValueAsJson<ProjectStructure>(ProjectStructureKey));\n const renderingState = notEmpty(\n prj.getKeyValueAsJson<ProjectRenderingState>(BlockRenderingStateKey),\n );\n\n const infos = new Map<string, BlockInfo>();\n for (const { id } of allBlocks(structure)) {\n const cInputs = prj.traverse({\n field: projectFieldName(id, \"currentArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n const currentArguments = cInputs?.getDataAsJson<Record<string, unknown>>();\n\n let prod: ProdState | undefined = undefined;\n\n const rInputs = prj.traverse({\n field: projectFieldName(id, \"prodArgs\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n if (rInputs !== undefined) {\n const prodArgs = rInputs.getDataAsJson() as Record<string, unknown>;\n const result = prj.getField({\n field: projectFieldName(id, \"prodOutput\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n const ctx = prj.getField({\n field: projectFieldName(id, \"prodUiCtx\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotFound: true,\n });\n prod = {\n arguments: prodArgs,\n stale: !argsEquals(currentArguments, prodArgs),\n outputError:\n result.error !== undefined ||\n ctx.error !== undefined ||\n result.value?.getError() !== undefined ||\n ctx.value?.getError() !== undefined,\n outputsError:\n result.error?.getDataAsString() ?? result.value?.getError()?.getDataAsString(),\n exportsError: ctx.error?.getDataAsString() ?? ctx.value?.getError()?.getDataAsString(),\n finished:\n ((result.value !== undefined && result.value.getIsReadyOrError()) ||\n (result.error !== undefined && result.error.getIsReadyOrError())) &&\n ((ctx.value !== undefined && ctx.value.getIsReadyOrError()) ||\n (ctx.error !== undefined && ctx.error.getIsReadyOrError())),\n };\n }\n\n infos.set(id, { currentArguments, prod, argsRid: cInputs?.resourceInfo.id });\n }\n\n const currentGraph = productionGraph(structure, (id) => {\n const bpInfo = getBlockPackInfo(prj, id)!;\n const bInfo = infos.get(id)!;\n const args = bInfo.currentArguments;\n return {\n args,\n enrichmentTargets: bInfo.argsRid\n ? env.projectHelper.getEnrichmentTargets(\n () => bpInfo.cfg,\n () => args,\n { argsRid: bInfo.argsRid, blockPackRid: bpInfo.bpResourceId },\n )\n : undefined,\n };\n });\n\n const limbo = new Set(renderingState.blocksInLimbo);\n\n const blocks = [...allBlocks(structure)].map(({ id, label: defaultLabel, renderingMode }) => {\n const info = notEmpty(infos.get(id));\n const gNode = notEmpty(currentGraph.nodes.get(id));\n let calculationStatus: BlockCalculationStatus = \"NotCalculated\";\n if (info.prod !== undefined) {\n if (limbo.has(id)) calculationStatus = \"Limbo\";\n else calculationStatus = info.prod.finished ? \"Done\" : \"Running\";\n }\n\n const bp = getBlockPackInfo(prj, id);\n\n const {\n sections,\n title,\n subtitle,\n tags,\n inputsValid,\n inputsValidFromArgs,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n } =\n ifNotUndef(bp, ({ bpId, cfg, info: blockPackInfo }) => {\n if (!env.runtimeCapabilities.checkCompatibility(cfg.featureFlags)) {\n return {\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const blockCtx = constructBlockContext(prjEntry, id);\n const blockCtxArgsOnly = constructBlockContextArgsOnly(prjEntry, id);\n const codeWithInfoOrError = wrapCallback(() => extractCodeWithInfo(cfg));\n if (codeWithInfoOrError.error) {\n return {\n title: codeWithInfoOrError.error.message,\n isIncompatibleWithRuntime: true,\n featureFlags: cfg.featureFlags,\n };\n }\n const codeWithInfo = codeWithInfoOrError.value;\n return {\n sections: computableFromCfgOrRF(\n env,\n blockCtx,\n cfg.sections,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model sections\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<BlockSection[]>,\n title: ifNotUndef(\n cfg.title,\n (title) =>\n computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n title,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model title\", { cause }));\n return \"Invalid title\";\n },\n }) as ComputableStableDefined<string>,\n ),\n subtitle: ifNotUndef(\n cfg.subtitle,\n // The subtitle names the inputs the block reads, so it renders with the\n // result pool; the title stays args-only.\n (subtitle) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n subtitle,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model subtitle\", { cause }));\n return \"Invalid subtitle\";\n },\n }) as ComputableStableDefined<string>,\n ),\n tags: ifNotUndef(\n cfg.tags,\n (tags) =>\n computableFromCfgOrRF(\n env,\n blockCtx,\n tags,\n codeWithInfo,\n bpId,\n {},\n blockPackInfo.source,\n ).wrap({\n recover: (cause) => {\n env.logger.error(new Error(\"Error in block model tags\", { cause }));\n return [];\n },\n }) as ComputableStableDefined<string[]>,\n ),\n // inputsValid: for modelAPIVersion 2, it's true if currentArgs exists (args derivation succeeded)\n // and the block's argsIssues() is known to have found no errors in them.\n // For older blocks, use the inputsValid callback from config\n inputsValid:\n cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION\n ? argsAllowRun(prj, id, info.currentArguments)\n : cfg.inputsValid\n ? (computableFromCfgOrRF(\n env,\n blockCtxArgsOnly,\n cfg.inputsValid,\n codeWithInfo,\n bpId,\n ).wrap({\n recover: (cause) => {\n env.logger.error(\n new Error(\"Error in block model inputsValid\", { cause }),\n );\n return false;\n },\n }) as ComputableStableDefined<boolean>)\n : undefined,\n inputsValidFromArgs: cfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION,\n sdkVersion: codeWithInfo?.sdkVersion,\n featureFlags: codeWithInfo?.featureFlags ?? {},\n isIncompatibleWithRuntime: false,\n };\n }) || {};\n\n const settings = prj\n .traverse({\n field: projectFieldName(id, \"blockSettings\"),\n assertFieldType: \"Dynamic\",\n errorIfFieldNotSet: true,\n })\n .getDataAsJson() as BlockSettings;\n\n const updates = ifNotUndef(bp, ({ info }) =>\n env.blockUpdateWatcher.get({ currentSpec: info.source, settings }),\n );\n\n return {\n projectResourceId: resourceIdToString(prjEntry.rid),\n id,\n label: title ?? defaultLabel,\n title: title ?? defaultLabel,\n subtitle,\n tags,\n renderingMode,\n stale: info.prod?.stale !== false || calculationStatus === \"Limbo\",\n missingReference: gNode.missingReferences,\n upstreams: [...currentGraph.traverseIdsExcludingRoots(\"upstream\", id)],\n downstreams: [...currentGraph.traverseIdsExcludingRoots(\"downstream\", id)],\n calculationStatus,\n outputErrors: info.prod?.outputError === true,\n outputsError: info.prod?.outputsError,\n exportsError: info.prod?.exportsError,\n settings,\n sections,\n inputsValid,\n inputsValidFromArgs: inputsValidFromArgs === true,\n updateInfo: {},\n currentBlockPack: bp?.info?.source,\n updates,\n sdkVersion,\n featureFlags,\n isIncompatibleWithRuntime,\n navigationState: navigationStates.getState(id),\n };\n });\n\n return {\n meta,\n created: new Date(created),\n lastModified: new Date(lastModified),\n authorMarker: prj.getKeyValueAsJson<AuthorMarker>(ProjectStructureAuthorKey),\n blocks,\n };\n },\n {\n postprocessValue: (value) => ({\n ...value,\n blocks: withRunState(value.blocks).map(({ updates, inputsValidFromArgs: _, ...b }) => ({\n ...b,\n updateSuggestions: updates?.suggestions ?? [],\n updatedBlockPack: updates?.mainSuggestion,\n })),\n }),\n onRecalculation: getDebugFlags().logProjectOverviewStat\n ? (stats) => {\n console.log(`[projectOverview] ${JSON.stringify(stats)}`);\n }\n : undefined,\n },\n ).withStableType();\n}\n\n/**\n * Whether the args of a block with model API version 2 let it run: the block has current args,\n * and its `inputsValid` field records no errors its `argsIssues()` found in them (see\n * `readArgsErrorsField`).\n *\n * @param currentArgs - The block's current args as decoded from its `currentArgs` field;\n * `undefined` when it has none\n */\nexport function argsAllowRun(\n prj: PlTreeNodeAccessor,\n blockId: string,\n currentArgs: unknown,\n): boolean {\n if (currentArgs === undefined) return false;\n const argsErrors = prj.getField({\n field: projectFieldName(blockId, \"inputsValid\"),\n assertFieldType: \"Dynamic\",\n stableIfNotFound: true,\n });\n return readArgsErrorsField(argsErrors?.value?.getData(), currentArgs).length === 0;\n}\n\n/** What the run state of a block is derived from. */\nexport type RunStateSource = {\n id: string;\n /** Whether the block's own args differ from those its results were rendered with. */\n stale: boolean;\n outputErrors: boolean;\n inputsValid: boolean | undefined;\n /**\n * Whether `inputsValid` tells only whether the block's current args may run: a block with model\n * API version 2 this runtime is compatible with. Otherwise it also stands for a block whose code\n * cannot run here, or for checks of a model that predates args issues.\n */\n inputsValidFromArgs: boolean;\n missingReference: boolean;\n /** Every block upstream of this one, direct or not. */\n upstreams: string[];\n};\n\n/**\n * Adds the run state to each block of a project, the blocks listed upstream first. A block is\n * stale when its own args changed or an upstream block is stale. It can run when it needs to run\n * (it is stale or its outputs failed), its args allow it, it references no missing block, and no\n * upstream block that needs to run is kept from running. An upstream block whose `inputsValid`\n * comes from its args and whose results are up to date feeds its dependents even when its args\n * could not run again; any other upstream block that is not valid keeps them from running.\n */\nexport function withRunState<B extends RunStateSource>(\n blocks: B[],\n): (B & { stale: boolean; canRun: boolean })[] {\n const cantRun = new Set<string>();\n const staleBlocks = new Set<string>();\n return blocks.map((b) => {\n if (b.stale) staleBlocks.add(b.id);\n const stale = b.stale || b.upstreams.some((u) => staleBlocks.has(u));\n const needsRun = stale || b.outputErrors;\n if (!b.inputsValid && (needsRun || !b.inputsValidFromArgs)) cantRun.add(b.id);\n const canRun =\n needsRun &&\n Boolean(b.inputsValid) &&\n !b.missingReference &&\n !b.upstreams.some((u) => cantRun.has(u));\n return { ...b, stale, canRun };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAwDA,SAAS,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AS,EAAE;EAC5B,IAAI,CAAC,EAAE,gBAAgB,YAAY,CAAC,EAAE,sBAAsB,QAAQ,IAAI,EAAE,EAAE;EAC5E,MAAM,SACJ,YACA,QAAQ,EAAE,WAAW,KACrB,CAAC,EAAE,oBACH,CAAC,EAAE,UAAU,MAAM,MAAM,QAAQ,IAAI,CAAC,CAAC;EACzC,OAAO;GAAE,GAAG;GAAG;GAAO;EAAO;CAC/B,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-middle-layer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Pl Middle Layer",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@milaboratories/resolve-helper": "1.1.3",
|
|
38
38
|
"@milaboratories/ts-helpers": "1.9.1",
|
|
39
39
|
"@platforma-sdk/block-tools": "2.17.8",
|
|
40
|
-
"@platforma-sdk/model": "1.88.
|
|
40
|
+
"@platforma-sdk/model": "1.88.10",
|
|
41
41
|
"@platforma-sdk/workflow-tengo": "6.22.1",
|
|
42
42
|
"canonicalize": "~2.1.0",
|
|
43
43
|
"denque": "^2.1.0",
|
|
@@ -227,10 +227,12 @@ export function projectOverview(
|
|
|
227
227
|
),
|
|
228
228
|
subtitle: ifNotUndef(
|
|
229
229
|
cfg.subtitle,
|
|
230
|
+
// The subtitle names the inputs the block reads, so it renders with the
|
|
231
|
+
// result pool; the title stays args-only.
|
|
230
232
|
(subtitle) =>
|
|
231
233
|
computableFromCfgOrRF(
|
|
232
234
|
env,
|
|
233
|
-
|
|
235
|
+
blockCtx,
|
|
234
236
|
subtitle,
|
|
235
237
|
codeWithInfo,
|
|
236
238
|
bpId,
|