@milaboratories/pl-middle-layer 1.74.10 → 1.74.12
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/_virtual/{_@oxc-project_runtime@0.137.0 → _@oxc-project_runtime@0.155.0}/helpers/esm/usingCtx.cjs +1 -2
- package/dist/_virtual/{_@oxc-project_runtime@0.137.0 → _@oxc-project_runtime@0.155.0}/helpers/esm/usingCtx.js +1 -2
- package/dist/_virtual/_rolldown/runtime.cjs +2 -3
- package/dist/block_registry/location_provider.cjs +1 -2
- package/dist/block_registry/location_provider.cjs.map +1 -1
- package/dist/block_registry/location_provider.js +1 -2
- package/dist/block_registry/registry-v2-provider.cjs +1 -2
- package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
- package/dist/block_registry/registry-v2-provider.d.ts +0 -2
- package/dist/block_registry/registry-v2-provider.d.ts.map +1 -1
- package/dist/block_registry/registry-v2-provider.js +1 -2
- package/dist/block_registry/registry.cjs +3 -3
- package/dist/block_registry/registry.cjs.map +1 -1
- package/dist/block_registry/registry.d.ts +0 -2
- package/dist/block_registry/registry.d.ts.map +1 -1
- package/dist/block_registry/registry.js +3 -3
- package/dist/block_registry/registry.js.map +1 -1
- package/dist/block_registry/template_provider.cjs +1 -2
- package/dist/block_registry/template_provider.cjs.map +1 -1
- package/dist/block_registry/template_provider.d.ts +0 -2
- package/dist/block_registry/template_provider.d.ts.map +1 -1
- package/dist/block_registry/template_provider.js +1 -2
- package/dist/block_registry/watcher.cjs +15 -14
- package/dist/block_registry/watcher.cjs.map +1 -1
- package/dist/block_registry/watcher.d.ts +0 -2
- package/dist/block_registry/watcher.d.ts.map +1 -1
- package/dist/block_registry/watcher.js +15 -14
- package/dist/block_registry/watcher.js.map +1 -1
- package/dist/block_registry/well_known_registries.cjs +1 -2
- package/dist/block_registry/well_known_registries.d.ts +0 -2
- package/dist/block_registry/well_known_registries.d.ts.map +1 -1
- package/dist/block_registry/well_known_registries.js +1 -2
- package/dist/cfg_render/executor.cjs +1 -2
- package/dist/cfg_render/executor.cjs.map +1 -1
- package/dist/cfg_render/executor.js +1 -2
- package/dist/cfg_render/renderer.cjs +1 -2
- package/dist/cfg_render/renderer.cjs.map +1 -1
- package/dist/cfg_render/renderer.js +1 -2
- package/dist/cfg_render/traverse.cjs +1 -2
- package/dist/cfg_render/traverse.js +1 -2
- package/dist/cfg_render/util.cjs +1 -2
- package/dist/cfg_render/util.js +1 -2
- package/dist/debug/index.cjs +1 -2
- package/dist/debug/index.js +1 -2
- package/dist/dev_env/index.cjs +1 -2
- package/dist/dev_env/index.cjs.map +1 -1
- package/dist/dev_env/index.js +1 -2
- package/dist/dev_env/util.cjs +1 -2
- package/dist/dev_env/util.js +1 -2
- package/dist/js_render/column_registry.cjs +1 -2
- package/dist/js_render/column_registry.cjs.map +1 -1
- package/dist/js_render/column_registry.js +1 -2
- package/dist/js_render/computable_context.cjs +4 -4
- package/dist/js_render/computable_context.cjs.map +1 -1
- package/dist/js_render/computable_context.js +4 -4
- package/dist/js_render/computable_context.js.map +1 -1
- package/dist/js_render/context.cjs +1 -2
- package/dist/js_render/context.cjs.map +1 -1
- package/dist/js_render/context.js +1 -2
- package/dist/js_render/index.cjs +12 -9
- package/dist/js_render/index.cjs.map +1 -1
- package/dist/js_render/index.js +12 -9
- package/dist/js_render/index.js.map +1 -1
- package/dist/js_render/service_injectors.cjs +2 -3
- package/dist/js_render/service_injectors.js +2 -3
- package/dist/js_render/spec_override_collapse.cjs +1 -2
- package/dist/js_render/spec_override_collapse.cjs.map +1 -1
- package/dist/js_render/spec_override_collapse.js +1 -2
- package/dist/middle_layer/active_cfg.cjs +1 -2
- package/dist/middle_layer/active_cfg.cjs.map +1 -1
- package/dist/middle_layer/active_cfg.js +1 -2
- package/dist/middle_layer/block.cjs +1 -2
- package/dist/middle_layer/block.cjs.map +1 -1
- package/dist/middle_layer/block.js +1 -2
- package/dist/middle_layer/block_ctx.cjs +3 -3
- package/dist/middle_layer/block_ctx.cjs.map +1 -1
- package/dist/middle_layer/block_ctx.js +3 -3
- package/dist/middle_layer/block_ctx.js.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.cjs +1 -2
- package/dist/middle_layer/block_ctx_unsafe.js +1 -2
- package/dist/middle_layer/build_stamp.cjs +2 -3
- package/dist/middle_layer/build_stamp.js +2 -3
- package/dist/middle_layer/driver_kit.cjs +6 -2
- package/dist/middle_layer/driver_kit.cjs.map +1 -1
- package/dist/middle_layer/driver_kit.d.ts +0 -2
- package/dist/middle_layer/driver_kit.d.ts.map +1 -1
- package/dist/middle_layer/driver_kit.js +7 -3
- package/dist/middle_layer/driver_kit.js.map +1 -1
- package/dist/middle_layer/finality_stop_rules.cjs +1 -2
- package/dist/middle_layer/finality_stop_rules.js +1 -2
- package/dist/middle_layer/folders.cjs +12 -8
- package/dist/middle_layer/folders.cjs.map +1 -1
- package/dist/middle_layer/folders.d.ts +0 -2
- package/dist/middle_layer/folders.d.ts.map +1 -1
- package/dist/middle_layer/folders.js +12 -8
- package/dist/middle_layer/folders.js.map +1 -1
- package/dist/middle_layer/frontend_path.cjs +1 -2
- package/dist/middle_layer/frontend_path.cjs.map +1 -1
- package/dist/middle_layer/frontend_path.js +1 -2
- package/dist/middle_layer/middle_layer.cjs +7 -6
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +0 -2
- package/dist/middle_layer/middle_layer.d.ts.map +1 -1
- package/dist/middle_layer/middle_layer.js +7 -6
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/navigation_states.cjs +1 -2
- package/dist/middle_layer/navigation_states.js +1 -2
- package/dist/middle_layer/ops.cjs +10 -11
- package/dist/middle_layer/ops.cjs.map +1 -1
- package/dist/middle_layer/ops.d.ts +0 -2
- package/dist/middle_layer/ops.d.ts.map +1 -1
- package/dist/middle_layer/ops.js +10 -11
- package/dist/middle_layer/ops.js.map +1 -1
- package/dist/middle_layer/project.cjs +3 -3
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +3 -5
- package/dist/middle_layer/project.d.ts.map +1 -1
- package/dist/middle_layer/project.js +3 -3
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/middle_layer/project_list.cjs +1 -2
- package/dist/middle_layer/project_list.cjs.map +1 -1
- package/dist/middle_layer/project_list.d.ts +0 -2
- package/dist/middle_layer/project_list.d.ts.map +1 -1
- package/dist/middle_layer/project_list.js +1 -2
- package/dist/middle_layer/project_overview.cjs +8 -5
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.js +8 -5
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/dist/middle_layer/project_overview_light.cjs +4 -3
- package/dist/middle_layer/project_overview_light.cjs.map +1 -1
- package/dist/middle_layer/project_overview_light.js +4 -3
- package/dist/middle_layer/project_overview_light.js.map +1 -1
- package/dist/middle_layer/render.cjs +1 -2
- package/dist/middle_layer/render.cjs.map +1 -1
- package/dist/middle_layer/render.js +1 -2
- package/dist/middle_layer/sharing_list.cjs +1 -2
- package/dist/middle_layer/sharing_list.cjs.map +1 -1
- package/dist/middle_layer/sharing_list.d.ts +0 -2
- package/dist/middle_layer/sharing_list.d.ts.map +1 -1
- package/dist/middle_layer/sharing_list.js +1 -2
- package/dist/middle_layer/sharing_list.js.map +1 -1
- package/dist/middle_layer/template_list.cjs +1 -2
- package/dist/middle_layer/template_list.cjs.map +1 -1
- package/dist/middle_layer/template_list.d.ts +0 -2
- package/dist/middle_layer/template_list.d.ts.map +1 -1
- package/dist/middle_layer/template_list.js +1 -2
- package/dist/middle_layer/tree_snapshot_store.cjs +3 -3
- package/dist/middle_layer/tree_snapshot_store.cjs.map +1 -1
- package/dist/middle_layer/tree_snapshot_store.d.ts +0 -2
- package/dist/middle_layer/tree_snapshot_store.d.ts.map +1 -1
- package/dist/middle_layer/tree_snapshot_store.js +3 -3
- package/dist/middle_layer/tree_snapshot_store.js.map +1 -1
- package/dist/middle_layer/types.d.ts +0 -2
- package/dist/middle_layer/types.d.ts.map +1 -1
- package/dist/middle_layer/util.cjs +1 -2
- package/dist/middle_layer/util.cjs.map +1 -1
- package/dist/middle_layer/util.js +1 -2
- package/dist/model/args.cjs +1 -2
- package/dist/model/args.cjs.map +1 -1
- package/dist/model/args.js +1 -2
- package/dist/model/block_pack_spec.cjs +1 -2
- package/dist/model/block_pack_spec.d.ts +0 -2
- package/dist/model/block_pack_spec.d.ts.map +1 -1
- package/dist/model/block_pack_spec.js +1 -2
- package/dist/model/frontend.d.ts +0 -2
- package/dist/model/frontend.d.ts.map +1 -1
- package/dist/model/project_helper.cjs +1 -2
- package/dist/model/project_helper.cjs.map +1 -1
- package/dist/model/project_helper.d.ts +0 -2
- package/dist/model/project_helper.d.ts.map +1 -1
- package/dist/model/project_helper.js +1 -2
- package/dist/model/project_model.cjs +1 -2
- package/dist/model/project_model.d.ts +0 -2
- package/dist/model/project_model.d.ts.map +1 -1
- package/dist/model/project_model.js +1 -2
- package/dist/model/project_model_util.cjs +1 -2
- package/dist/model/project_model_util.js +1 -2
- package/dist/model/project_model_v1.cjs +1 -2
- package/dist/model/project_model_v1.js +1 -2
- package/dist/model/sharing_model.cjs +1 -2
- package/dist/model/sharing_model.cjs.map +1 -1
- package/dist/model/sharing_model.d.ts +0 -2
- package/dist/model/sharing_model.d.ts.map +1 -1
- package/dist/model/sharing_model.js +1 -2
- package/dist/model/template_apply.cjs +1 -2
- package/dist/model/template_apply.cjs.map +1 -1
- package/dist/model/template_apply.d.ts +0 -2
- package/dist/model/template_apply.d.ts.map +1 -1
- package/dist/model/template_apply.js +1 -2
- package/dist/model/template_export.cjs +1 -2
- package/dist/model/template_export.d.ts +0 -2
- package/dist/model/template_export.d.ts.map +1 -1
- package/dist/model/template_export.js +1 -2
- package/dist/model/template_parser.cjs +1 -2
- package/dist/model/template_parser.cjs.map +1 -1
- package/dist/model/template_parser.d.ts +0 -2
- package/dist/model/template_parser.d.ts.map +1 -1
- package/dist/model/template_parser.js +1 -2
- package/dist/model/template_resolve.cjs +1 -2
- package/dist/model/template_resolve.cjs.map +1 -1
- package/dist/model/template_resolve.d.ts +0 -2
- package/dist/model/template_resolve.d.ts.map +1 -1
- package/dist/model/template_resolve.js +1 -2
- package/dist/model/template_serializer.cjs +1 -2
- package/dist/model/template_serializer.cjs.map +1 -1
- package/dist/model/template_serializer.d.ts +0 -2
- package/dist/model/template_serializer.d.ts.map +1 -1
- package/dist/model/template_serializer.js +1 -2
- package/dist/model/template_spec.d.ts +0 -2
- package/dist/model/template_spec.d.ts.map +1 -1
- package/dist/mutator/block-pack/block_pack.cjs +7 -6
- package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
- package/dist/mutator/block-pack/block_pack.d.ts +0 -2
- package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
- package/dist/mutator/block-pack/block_pack.js +7 -6
- package/dist/mutator/block-pack/block_pack.js.map +1 -1
- package/dist/mutator/block-pack/frontend.cjs +1 -2
- package/dist/mutator/block-pack/frontend.cjs.map +1 -1
- package/dist/mutator/block-pack/frontend.js +1 -2
- package/dist/mutator/block-pack/required_capabilities.cjs +1 -2
- package/dist/mutator/block-pack/required_capabilities.cjs.map +1 -1
- package/dist/mutator/block-pack/required_capabilities.js +1 -2
- package/dist/mutator/context_export.cjs +1 -2
- package/dist/mutator/context_export.cjs.map +1 -1
- package/dist/mutator/context_export.js +1 -2
- package/dist/mutator/list.cjs +1 -2
- package/dist/mutator/list.cjs.map +1 -1
- package/dist/mutator/list.js +1 -2
- package/dist/mutator/migration.cjs +1 -2
- package/dist/mutator/migration.cjs.map +1 -1
- package/dist/mutator/migration.js +1 -2
- package/dist/mutator/project.cjs +30 -22
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.d.ts +0 -2
- package/dist/mutator/project.d.ts.map +1 -1
- package/dist/mutator/project.js +30 -22
- package/dist/mutator/project.js.map +1 -1
- package/dist/mutator/sharing.cjs +1 -2
- package/dist/mutator/sharing.cjs.map +1 -1
- package/dist/mutator/sharing.js +1 -2
- package/dist/mutator/template/direct_template_loader.cjs +1 -2
- package/dist/mutator/template/direct_template_loader.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader.js +1 -2
- package/dist/mutator/template/direct_template_loader_v3.cjs +1 -2
- package/dist/mutator/template/direct_template_loader_v3.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.js +1 -2
- package/dist/mutator/template/render_block.cjs +1 -2
- package/dist/mutator/template/render_block.cjs.map +1 -1
- package/dist/mutator/template/render_block.js +1 -2
- package/dist/mutator/template/render_template.cjs +1 -2
- package/dist/mutator/template/render_template.cjs.map +1 -1
- package/dist/mutator/template/render_template.d.ts +0 -2
- package/dist/mutator/template/render_template.d.ts.map +1 -1
- package/dist/mutator/template/render_template.js +1 -2
- package/dist/mutator/template/template_cache.cjs +6 -5
- package/dist/mutator/template/template_cache.cjs.map +1 -1
- package/dist/mutator/template/template_cache.d.ts +1 -2
- package/dist/mutator/template/template_cache.d.ts.map +1 -1
- package/dist/mutator/template/template_cache.js +6 -5
- package/dist/mutator/template/template_cache.js.map +1 -1
- package/dist/mutator/template/template_loading.cjs +1 -2
- package/dist/mutator/template/template_loading.cjs.map +1 -1
- package/dist/mutator/template/template_loading.d.ts +0 -2
- package/dist/mutator/template/template_loading.d.ts.map +1 -1
- package/dist/mutator/template/template_loading.js +1 -2
- package/dist/mutator/template.cjs +1 -2
- package/dist/mutator/template.cjs.map +1 -1
- package/dist/mutator/template.js +1 -2
- package/dist/mutator/template_construct.cjs +1 -2
- package/dist/mutator/template_construct.cjs.map +1 -1
- package/dist/mutator/template_construct.js +1 -2
- package/dist/network_check/network_check.cjs +2 -3
- package/dist/network_check/network_check.cjs.map +1 -1
- package/dist/network_check/network_check.d.ts +0 -2
- package/dist/network_check/network_check.d.ts.map +1 -1
- package/dist/network_check/network_check.js +2 -3
- package/dist/network_check/network_check.js.map +1 -1
- package/dist/network_check/pings.cjs +1 -2
- package/dist/network_check/pings.cjs.map +1 -1
- package/dist/network_check/pings.js +1 -2
- package/dist/network_check/template.cjs +5 -4
- package/dist/network_check/template.cjs.map +1 -1
- package/dist/network_check/template.js +5 -4
- package/dist/network_check/template.js.map +1 -1
- package/dist/pool/data.cjs +1 -2
- package/dist/pool/data.cjs.map +1 -1
- package/dist/pool/data.d.ts +0 -2
- package/dist/pool/data.d.ts.map +1 -1
- package/dist/pool/data.js +1 -2
- package/dist/pool/driver.cjs +5 -4
- package/dist/pool/driver.cjs.map +1 -1
- package/dist/pool/driver.d.ts +0 -2
- package/dist/pool/driver.d.ts.map +1 -1
- package/dist/pool/driver.js +5 -4
- package/dist/pool/driver.js.map +1 -1
- package/dist/pool/p_object_collection.cjs +9 -8
- package/dist/pool/p_object_collection.cjs.map +1 -1
- package/dist/pool/p_object_collection.d.ts +0 -2
- package/dist/pool/p_object_collection.d.ts.map +1 -1
- package/dist/pool/p_object_collection.js +9 -8
- package/dist/pool/p_object_collection.js.map +1 -1
- package/dist/pool/result_pool.cjs +8 -7
- package/dist/pool/result_pool.cjs.map +1 -1
- package/dist/pool/result_pool.js +8 -7
- package/dist/pool/result_pool.js.map +1 -1
- package/dist/pool/upstream_block_ctx.cjs +1 -2
- package/dist/pool/upstream_block_ctx.cjs.map +1 -1
- package/dist/pool/upstream_block_ctx.js +1 -2
- package/dist/service_factories.cjs +1 -2
- package/dist/service_factories.js +1 -2
- package/dist/worker/WorkerManager.cjs +1 -2
- package/dist/worker/WorkerManager.js +1 -2
- package/dist/worker/WorkerManager.js.map +1 -1
- package/dist/worker/worker.cjs +1 -2
- package/dist/worker/worker.js +1 -2
- package/dist/worker/workerApi.cjs +1 -2
- package/dist/worker/workerApi.cjs.map +1 -1
- package/dist/worker/workerApi.js +1 -2
- package/package.json +33 -33
- package/src/middle_layer/driver_kit.ts +16 -0
- package/src/middle_layer/middle_layer.ts +4 -6
- package/src/middle_layer/tree_snapshot_store.test.ts +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_pack.js","names":[],"sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport type { Branded } from \"@milaboratories/pl-model-common\";\nimport fs from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport { requiredCapabilitiesFromTemplate } from \"./required_capabilities\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport {\n loadPackDescription,\n loadPackDescriptionFromManifest,\n RegistryV1,\n} from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime, getFromPackV2Mtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport canonicalize from \"canonicalize\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\ntype PreparedCacheKey = Branded<string, \"PreparedCacheKey\">;\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n /** Cache of prepared block packs for registry specs (immutable by version). */\n private readonly preparedCache = new LRUCache<PreparedCacheKey, BlockPackSpecPrepared>({\n max: 50,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n /** Returns a stable cache key for registry specs (immutable by version). Dev specs return undefined. */\n private specKey(spec: BlockPackSpecAny): PreparedCacheKey | undefined {\n switch (spec.type) {\n case \"from-registry-v1\":\n return `v1:${spec.registryUrl}:${spec.id.organization}:${spec.id.name}:${spec.id.version}` as PreparedCacheKey;\n case \"from-registry-v2\":\n return `v2:${spec.registryUrl}:${canonicalize(spec.id)}` as PreparedCacheKey;\n default:\n return undefined; // dev, explicit, prepared — not cacheable\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n // Check prepare cache for registry specs\n const key = this.specKey(spec);\n if (key) {\n const cached = this.preparedCache.get(key);\n if (cached) return cached;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n const parsed = await workerManager.process(\"parseTemplate\", explicit.template.content);\n\n const result: BlockPackSpecPrepared = {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: parsed,\n },\n requiredCapabilities: requiredCapabilitiesFromTemplate(parsed),\n };\n\n if (key) {\n this.preparedCache.set(key, result);\n }\n\n return result;\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n // UI ships as ui.tgz inside block-pack/; its absolute path is carried\n // in the ui folder slot. The tarball is unpacked lazily at serve-time by\n // the download driver (local-tgz frontend), not eagerly here — so it\n // inherits the driver's usage-tracking and space recycling.\n const uiTgzPath = description.components.ui.folder;\n const source = { ...spec };\n let mtime = spec.mtime;\n if (mtime === undefined) {\n // No explicit mtime: derive one so the frontend cache key invalidates\n // when the block changes.\n mtime = await getFromPackV2Mtime(packDir, uiTgzPath);\n source.mtime = mtime;\n }\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local-tgz\",\n path: uiTgzPath,\n mtime,\n signature: this.signer.sign(`${uiTgzPath}:${mtime}`),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n const workflowContent = Buffer.from(workflow);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,MAAa,sBAAoC;CAAE,MAAM;CAAmB,SAAS;AAAI;AACzF,MAAa,yBAAyB;AACtC,MAAa,yBAAyB;;AAGtC,SAAS,OAAO,KAAqB;CACnC,IAAI,IAAI,SAAS,GAAG,GAAG,OAAO;MACzB,OAAO,GAAG,IAAI;AACrB;AAEA,SAAS,kBAAkB,eAA6C;CACtE,MAAM,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,KAAK,MAAM,aAAa,CAAC;CAEjF,IAAI,CAAC,IAAI,SACP,MAAM,IAAI,MAAM,wBAAwB;CAG1C,IAAI,CAAC,KAAK,UAAU,IAAI,KAAK,IAAI,CAAC,CAAC,SACjC,MAAM,IAAI,MAAM,kCAAkC;CAGpD,OAAO,IAAI;AACb;AAEA,SAAS,kBAAkB,QAA2C;CACpE,OAAO,kBAAkB,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC;AAC/D;AAEA,IAAa,oBAAb,MAA+B;CAEV;CACA;CACA;CAHnB,YACE,oBACA,QACA,MACA;EAHiB,KAAA,qBAAA;EACA,KAAA,SAAA;EACA,KAAA,OAAA;CAChB;CAEH,qBAAsC,IAAI,SAA8B;EACtE,KAAK;EACL,SAAS,MAAM,OAAO;EACtB,aAAa,OAAO,QAAQ;GAE1B,OAAO,OAAO,MAAM,QAAQ,KADR,KAAK,SAAS,KAAA,IAAY,EAAE,YAAY,KAAK,KAAK,IAAI,CAAC,CAC/B,EAAA,CAAG,KAAK,YAAY;EAClE;EACA,kBAAkB,UAAU,MAAM;CACpC,CAAC;;CAGD,gBAAiC,IAAI,SAAkD,EACrF,KAAK,GACP,CAAC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,MAAM,IAAI,sBAAsB,GAAG,SAAS,aAAa,IAAI,KAAK,QAAQ,CAAC;CAC1F,GAAG,YAAY,MAAM,IAAI,sBAAsB,GAAG,SAAS,eAAe,IAAI,KAAK,QAAQ,CAAC;CAC5F,GAAG,KAAK,EAAE;CAEV,OAAO;AACT;AAEA,SAAgB,gBAAgB,IAAmB,MAA6C;CAC9F,QAAQ,KAAK,MAAb;EACE,KAAK,YACH,OAAO,sBAAsB,IAAI,IAAI;EACvC,SACE,OAAO,YAAY,KAAK,IAAI;CAChC;AACF"}
|
|
1
|
+
{"version":3,"file":"block_pack.js","names":[],"sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport type { Branded } from \"@milaboratories/pl-model-common\";\nimport fs from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport { requiredCapabilitiesFromTemplate } from \"./required_capabilities\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport {\n loadPackDescription,\n loadPackDescriptionFromManifest,\n RegistryV1,\n} from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime, getFromPackV2Mtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport canonicalize from \"canonicalize\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\ntype PreparedCacheKey = Branded<string, \"PreparedCacheKey\">;\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n /** Cache of prepared block packs for registry specs (immutable by version). */\n private readonly preparedCache = new LRUCache<PreparedCacheKey, BlockPackSpecPrepared>({\n max: 50,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n /** Returns a stable cache key for registry specs (immutable by version). Dev specs return undefined. */\n private specKey(spec: BlockPackSpecAny): PreparedCacheKey | undefined {\n switch (spec.type) {\n case \"from-registry-v1\":\n return `v1:${spec.registryUrl}:${spec.id.organization}:${spec.id.name}:${spec.id.version}` as PreparedCacheKey;\n case \"from-registry-v2\":\n return `v2:${spec.registryUrl}:${canonicalize(spec.id)}` as PreparedCacheKey;\n default:\n return undefined; // dev, explicit, prepared — not cacheable\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n // Check prepare cache for registry specs\n const key = this.specKey(spec);\n if (key) {\n const cached = this.preparedCache.get(key);\n if (cached) return cached;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n const parsed = await workerManager.process(\"parseTemplate\", explicit.template.content);\n\n const result: BlockPackSpecPrepared = {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: parsed,\n },\n requiredCapabilities: requiredCapabilitiesFromTemplate(parsed),\n };\n\n if (key) {\n this.preparedCache.set(key, result);\n }\n\n return result;\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n // UI ships as ui.tgz inside block-pack/; its absolute path is carried\n // in the ui folder slot. The tarball is unpacked lazily at serve-time by\n // the download driver (local-tgz frontend), not eagerly here — so it\n // inherits the driver's usage-tracking and space recycling.\n const uiTgzPath = description.components.ui.folder;\n const source = { ...spec };\n let mtime = spec.mtime;\n if (mtime === undefined) {\n // No explicit mtime: derive one so the frontend cache key invalidates\n // when the block changes.\n mtime = await getFromPackV2Mtime(packDir, uiTgzPath);\n source.mtime = mtime;\n }\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local-tgz\",\n path: uiTgzPath,\n mtime,\n signature: this.signer.sign(`${uiTgzPath}:${mtime}`),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n const workflowContent = Buffer.from(workflow);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,MAAa,sBAAoC;CAAE,MAAM;CAAmB,SAAS;AAAI;AACzF,MAAa,yBAAyB;AACtC,MAAa,yBAAyB;;AAGtC,SAAS,OAAO,KAAqB;CACnC,IAAI,IAAI,SAAS,GAAG,GAAG,OAAO;MACzB,OAAO,GAAG,IAAI;AACrB;AAEA,SAAS,kBAAkB,eAA6C;CACtE,MAAM,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,KAAK,MAAM,aAAa,CAAC;CAEjF,IAAI,CAAC,IAAI,SACP,MAAM,IAAI,MAAM,wBAAwB;CAG1C,IAAI,CAAC,KAAK,UAAU,IAAI,KAAK,IAAI,CAAC,CAAC,SACjC,MAAM,IAAI,MAAM,kCAAkC;CAGpD,OAAO,IAAI;AACb;AAEA,SAAS,kBAAkB,QAA2C;CACpE,OAAO,kBAAkB,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC;AAC/D;AAEA,IAAa,oBAAb,MAA+B;CAEV;CACA;CACA;CAHnB,YACE,oBACA,QACA,MACA;EAHiB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AGvE,OAAO;KACL,MAAM;KACN,UAAU;MACR,MAAM;MACN,SANoB,OAAO,KAAK,QAMT;KACzB;KACA,QAAQ;KACR,UAAU;MACR,MAAM;MACN,KAAK,WAAW,GAAG;KACrB;KACA,QAAQ;IACV;GACF;GAEA,SACE,OAAO,YAAY,IAAI;EAC3B;CACF;AACF;AAEA,SAAS,sBAAsB,IAAmB,MAA6C;CAC7F,MAAM,gBAA+B;EAAE,QAAQ,KAAK;EAAQ,QAAQ,KAAK;CAAO;CAChF,MAAM,KAAK,GAAG,aAAa,qBAAqB,KAAK,UAAU,aAAa,CAAC;CAC7E,GAAG,YAAY,MAAM,IAAI,sBAAsB,GAAG,SAAS,aAAa,IAAI,KAAK,QAAQ,CAAC;CAC1F,GAAG,YAAY,MAAM,IAAI,sBAAsB,GAAG,SAAS,eAAe,IAAI,KAAK,QAAQ,CAAC;CAC5F,GAAG,KAAK,EAAE;CAEV,OAAO;AACT;AAEA,SAAgB,gBAAgB,IAAmB,MAA6C;CAC9F,QAAQ,KAAK,MAAb;EACE,KAAK,YACH,OAAO,sBAAsB,IAAI,IAAI;EACvC,SACE,OAAO,YAAY,KAAK,IAAI;CAChC;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_block_pack_spec = require("../../model/block_pack_spec.cjs");
|
|
2
2
|
require("../../model/index.cjs");
|
|
3
3
|
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
4
|
-
|
|
4
|
+
// src/mutator/block-pack/frontend.ts
|
|
5
5
|
function createFrontend(tx, spec) {
|
|
6
6
|
switch (spec.type) {
|
|
7
7
|
case "url": return tx.createValue(require_block_pack_spec.FrontendFromUrlResourceType, JSON.stringify({ url: spec.url }));
|
|
@@ -17,7 +17,6 @@ function createFrontend(tx, spec) {
|
|
|
17
17
|
default: return (0, _milaboratories_ts_helpers.assertNever)(spec);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
//#endregion
|
|
21
20
|
exports.createFrontend = createFrontend;
|
|
22
21
|
|
|
23
22
|
//# sourceMappingURL=frontend.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend.cjs","names":["FrontendFromUrlResourceType","FrontendFromFolderResourceType","FrontendFromLocalTgzResourceType"],"sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type {\n FrontendFromFolderData,\n FrontendFromLocalTgzData,\n FrontendFromUrlData,\n FrontendSpec,\n} from \"../../model\";\nimport {\n FrontendFromFolderResourceType,\n FrontendFromLocalTgzResourceType,\n FrontendFromUrlResourceType,\n} from \"../../model\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case \"url\":\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case \"local\":\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n case \"local-tgz\":\n return tx.createValue(\n FrontendFromLocalTgzResourceType,\n JSON.stringify({\n path: spec.path,\n mtime: spec.mtime,\n signature: spec.signature,\n } as FrontendFromLocalTgzData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"mappings":";;;;AAcA,SAAgB,eAAe,IAAmB,MAAoC;CACpF,QAAQ,KAAK,MAAb;EACE,KAAK,OACH,OAAO,GAAG,YACRA,wBAAAA,6BACA,KAAK,UAAU,EAAE,KAAK,KAAK,IAAI,CAAwB,CACzD;EACF,KAAK,SACH,OAAO,GAAG,YACRC,wBAAAA,gCACA,KAAK,UAAU;GACb,MAAM,KAAK;GACX,WAAW,KAAK;EAClB,CAA2B,CAC7B;EACF,KAAK,aACH,OAAO,GAAG,YACRC,wBAAAA,kCACA,KAAK,UAAU;GACb,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,WAAW,KAAK;EAClB,CAA6B,CAC/B;EACF,SACE,QAAA,
|
|
1
|
+
{"version":3,"file":"frontend.cjs","names":["FrontendFromUrlResourceType","FrontendFromFolderResourceType","FrontendFromLocalTgzResourceType","assertNever"],"sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type {\n FrontendFromFolderData,\n FrontendFromLocalTgzData,\n FrontendFromUrlData,\n FrontendSpec,\n} from \"../../model\";\nimport {\n FrontendFromFolderResourceType,\n FrontendFromLocalTgzResourceType,\n FrontendFromUrlResourceType,\n} from \"../../model\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case \"url\":\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case \"local\":\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n case \"local-tgz\":\n return tx.createValue(\n FrontendFromLocalTgzResourceType,\n JSON.stringify({\n path: spec.path,\n mtime: spec.mtime,\n signature: spec.signature,\n } as FrontendFromLocalTgzData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"mappings":";;;;AAcA,SAAgB,eAAe,IAAmB,MAAoC;CACpF,QAAQ,KAAK,MAAb;EACE,KAAK,OACH,OAAO,GAAG,YACRA,wBAAAA,6BACA,KAAK,UAAU,EAAE,KAAK,KAAK,IAAI,CAAwB,CACzD;EACF,KAAK,SACH,OAAO,GAAG,YACRC,wBAAAA,gCACA,KAAK,UAAU;GACb,MAAM,KAAK;GACX,WAAW,KAAK;EAClB,CAA2B,CAC7B;EACF,KAAK,aACH,OAAO,GAAG,YACRC,wBAAAA,kCACA,KAAK,UAAU;GACb,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,WAAW,KAAK;EAClB,CAA6B,CAC/B;EACF,SACE,QAAA,GAAOC,2BAAAA,YAAAA,CAAY,IAAI;CAC3B;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FrontendFromFolderResourceType, FrontendFromLocalTgzResourceType, FrontendFromUrlResourceType } from "../../model/block_pack_spec.js";
|
|
2
2
|
import "../../model/index.js";
|
|
3
3
|
import { assertNever } from "@milaboratories/ts-helpers";
|
|
4
|
-
|
|
4
|
+
// src/mutator/block-pack/frontend.ts
|
|
5
5
|
function createFrontend(tx, spec) {
|
|
6
6
|
switch (spec.type) {
|
|
7
7
|
case "url": return tx.createValue(FrontendFromUrlResourceType, JSON.stringify({ url: spec.url }));
|
|
@@ -17,7 +17,6 @@ function createFrontend(tx, spec) {
|
|
|
17
17
|
default: return assertNever(spec);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
//#endregion
|
|
21
20
|
export { createFrontend };
|
|
22
21
|
|
|
23
22
|
//# sourceMappingURL=frontend.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let node_zlib = require("node:zlib");
|
|
2
|
-
|
|
2
|
+
// src/mutator/block-pack/required_capabilities.ts
|
|
3
3
|
/**
|
|
4
4
|
* Reads the capability tokens a template declares it requires via
|
|
5
5
|
* `TemplateDataV3.requiredCapabilities` (populated by `tengo-builder` at
|
|
@@ -36,7 +36,6 @@ function deriveRequiredCapabilities(workflowContent) {
|
|
|
36
36
|
}
|
|
37
37
|
return requiredCapabilitiesFromTemplate(parsed);
|
|
38
38
|
}
|
|
39
|
-
//#endregion
|
|
40
39
|
exports.deriveRequiredCapabilities = deriveRequiredCapabilities;
|
|
41
40
|
exports.requiredCapabilitiesFromTemplate = requiredCapabilitiesFromTemplate;
|
|
42
41
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"required_capabilities.cjs","names":[],"sources":["../../../src/mutator/block-pack/required_capabilities.ts"],"sourcesContent":["import { gunzipSync } from \"node:zlib\";\nimport type { CompiledTemplateV3, TemplateData } from \"@milaboratories/pl-model-backend\";\n\n/**\n * Reads the capability tokens a template declares it requires via\n * `TemplateDataV3.requiredCapabilities` (populated by `tengo-builder` at\n * compile time).\n *\n * Use this on the install path: `BlockPackPreparer.prepare` parses the\n * workflow off-thread via the worker, and the parsed result feeds\n * straight into this function — no second gunzip+JSON.parse on the main\n * thread, no recursive walk to re-derive what the compiler already wrote\n * down.\n *\n * Returns `undefined` for v2 templates (no compile-time capability\n * field) and for v3 templates that declare no requirements; otherwise\n * the array as the compiler wrote it.\n */\nexport function requiredCapabilitiesFromTemplate(\n parsed: TemplateData | CompiledTemplateV3,\n): string[] | undefined {\n if (parsed.type !== \"pl.tengo-template.v3\") return undefined;\n return parsed.template.requiredCapabilities;\n}\n\n/**\n * Same lookup, starting from raw `main.plj.gz` bytes. Used only at\n * catalog-listing time for local-dev blocks where the worker pipeline\n * isn't in play (`block_registry/registry.ts`). Install paths go through\n * `requiredCapabilitiesFromTemplate` instead to avoid parsing the\n * workflow twice.\n */\nexport function deriveRequiredCapabilities(\n workflowContent: Uint8Array | Buffer,\n): string[] | undefined {\n let parsed: unknown;\n try {\n const json = gunzipSync(workflowContent).toString(\"utf-8\");\n parsed = JSON.parse(json);\n } catch {\n return undefined;\n }\n return requiredCapabilitiesFromTemplate(parsed as TemplateData | CompiledTemplateV3);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,SAAgB,iCACd,QACsB;CACtB,IAAI,OAAO,SAAS,wBAAwB,OAAO,KAAA;CACnD,OAAO,OAAO,SAAS;AACzB;;;;;;;;AASA,SAAgB,2BACd,iBACsB;CACtB,IAAI;CACJ,IAAI;EACF,MAAM,QAAA,
|
|
1
|
+
{"version":3,"file":"required_capabilities.cjs","names":["gunzipSync"],"sources":["../../../src/mutator/block-pack/required_capabilities.ts"],"sourcesContent":["import { gunzipSync } from \"node:zlib\";\nimport type { CompiledTemplateV3, TemplateData } from \"@milaboratories/pl-model-backend\";\n\n/**\n * Reads the capability tokens a template declares it requires via\n * `TemplateDataV3.requiredCapabilities` (populated by `tengo-builder` at\n * compile time).\n *\n * Use this on the install path: `BlockPackPreparer.prepare` parses the\n * workflow off-thread via the worker, and the parsed result feeds\n * straight into this function — no second gunzip+JSON.parse on the main\n * thread, no recursive walk to re-derive what the compiler already wrote\n * down.\n *\n * Returns `undefined` for v2 templates (no compile-time capability\n * field) and for v3 templates that declare no requirements; otherwise\n * the array as the compiler wrote it.\n */\nexport function requiredCapabilitiesFromTemplate(\n parsed: TemplateData | CompiledTemplateV3,\n): string[] | undefined {\n if (parsed.type !== \"pl.tengo-template.v3\") return undefined;\n return parsed.template.requiredCapabilities;\n}\n\n/**\n * Same lookup, starting from raw `main.plj.gz` bytes. Used only at\n * catalog-listing time for local-dev blocks where the worker pipeline\n * isn't in play (`block_registry/registry.ts`). Install paths go through\n * `requiredCapabilitiesFromTemplate` instead to avoid parsing the\n * workflow twice.\n */\nexport function deriveRequiredCapabilities(\n workflowContent: Uint8Array | Buffer,\n): string[] | undefined {\n let parsed: unknown;\n try {\n const json = gunzipSync(workflowContent).toString(\"utf-8\");\n parsed = JSON.parse(json);\n } catch {\n return undefined;\n }\n return requiredCapabilitiesFromTemplate(parsed as TemplateData | CompiledTemplateV3);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,SAAgB,iCACd,QACsB;CACtB,IAAI,OAAO,SAAS,wBAAwB,OAAO,KAAA;CACnD,OAAO,OAAO,SAAS;AACzB;;;;;;;;AASA,SAAgB,2BACd,iBACsB;CACtB,IAAI;CACJ,IAAI;EACF,MAAM,QAAA,GAAOA,UAAAA,WAAAA,CAAW,eAAe,CAAC,CAAC,SAAS,OAAO;EACzD,SAAS,KAAK,MAAM,IAAI;CAC1B,QAAQ;EACN;CACF;CACA,OAAO,iCAAiC,MAA2C;AACrF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { gunzipSync } from "node:zlib";
|
|
2
|
-
|
|
2
|
+
// src/mutator/block-pack/required_capabilities.ts
|
|
3
3
|
/**
|
|
4
4
|
* Reads the capability tokens a template declares it requires via
|
|
5
5
|
* `TemplateDataV3.requiredCapabilities` (populated by `tengo-builder` at
|
|
@@ -36,7 +36,6 @@ function deriveRequiredCapabilities(workflowContent) {
|
|
|
36
36
|
}
|
|
37
37
|
return requiredCapabilitiesFromTemplate(parsed);
|
|
38
38
|
}
|
|
39
|
-
//#endregion
|
|
40
39
|
export { deriveRequiredCapabilities, requiredCapabilitiesFromTemplate };
|
|
41
40
|
|
|
42
41
|
//# sourceMappingURL=required_capabilities.js.map
|
|
@@ -2,7 +2,7 @@ const require_render_template = require("./template/render_template.cjs");
|
|
|
2
2
|
const require_template_loading = require("./template/template_loading.cjs");
|
|
3
3
|
let node_crypto = require("node:crypto");
|
|
4
4
|
let _platforma_sdk_workflow_tengo = require("@platforma-sdk/workflow-tengo");
|
|
5
|
-
|
|
5
|
+
// src/mutator/context_export.ts
|
|
6
6
|
let preparedTemplateEnvelop;
|
|
7
7
|
async function getPreparedExportTemplateEnvelope() {
|
|
8
8
|
if (preparedTemplateEnvelop === void 0) {
|
|
@@ -18,7 +18,6 @@ async function getPreparedExportTemplateEnvelope() {
|
|
|
18
18
|
function exportContext(tx, exportTpl, ctx) {
|
|
19
19
|
return require_render_template.createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ["result"]).result;
|
|
20
20
|
}
|
|
21
|
-
//#endregion
|
|
22
21
|
exports.exportContext = exportContext;
|
|
23
22
|
exports.getPreparedExportTemplateEnvelope = getPreparedExportTemplateEnvelope;
|
|
24
23
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context_export.cjs","names":["prepareTemplateSpec","SdkTemplates","createRenderTemplate"],"sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport { createRenderTemplate } from \"./template/render_template\";\nimport { prepareTemplateSpec } from \"./template/template_loading\";\nimport type { TemplateSpecPrepared } from \"../model/template_spec\";\nimport { createHash } from \"node:crypto\";\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from \"@platforma-sdk/workflow-tengo\";\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(\n SdkTemplates[\"pframes.export-pframe-for-ui\"],\n );\n if (preparedTemplate.type !== \"explicit\") throw new Error(\"Unexpected prepared template type.\");\n const hash = createHash(\"sha256\").update(preparedTemplate.content).digest(\"hex\");\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [\"result\"]).result;\n}\n"],"mappings":";;;;;AAgBA,IAAI;AAEJ,eAAsB,oCAA8D;CAClF,IAAI,4BAA4B,KAAA,GAAW;EAEzC,MAAM,mBAAmB,MAAMA,yBAAAA,oBAC7BC,8BAAAA,UAAa,+BACf;EACA,IAAI,iBAAiB,SAAS,YAAY,MAAM,IAAI,MAAM,oCAAoC;EAE9F,0BAA0B;GAAE,MAAM;GAAkB,OAAA,
|
|
1
|
+
{"version":3,"file":"context_export.cjs","names":["prepareTemplateSpec","SdkTemplates","createHash","createRenderTemplate"],"sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport { createRenderTemplate } from \"./template/render_template\";\nimport { prepareTemplateSpec } from \"./template/template_loading\";\nimport type { TemplateSpecPrepared } from \"../model/template_spec\";\nimport { createHash } from \"node:crypto\";\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from \"@platforma-sdk/workflow-tengo\";\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(\n SdkTemplates[\"pframes.export-pframe-for-ui\"],\n );\n if (preparedTemplate.type !== \"explicit\") throw new Error(\"Unexpected prepared template type.\");\n const hash = createHash(\"sha256\").update(preparedTemplate.content).digest(\"hex\");\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [\"result\"]).result;\n}\n"],"mappings":";;;;;AAgBA,IAAI;AAEJ,eAAsB,oCAA8D;CAClF,IAAI,4BAA4B,KAAA,GAAW;EAEzC,MAAM,mBAAmB,MAAMA,yBAAAA,oBAC7BC,8BAAAA,UAAa,+BACf;EACA,IAAI,iBAAiB,SAAS,YAAY,MAAM,IAAI,MAAM,oCAAoC;EAE9F,0BAA0B;GAAE,MAAM;GAAkB,OAAA,GADvCC,YAAAA,WAAAA,CAAW,QAAQ,CAAC,CAAC,OAAO,iBAAiB,OAAO,CAAC,CAAC,OAAO,KACnB;EAAE;CAC3D;CAEA,OAAO;AACT;AAEA,SAAgB,cAAc,IAAmB,WAAmB,KAAa;CAC/E,OAAOC,wBAAAA,qBAAqB,IAAI,WAAW,MAAM,EAAE,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC5E"}
|
|
@@ -2,7 +2,7 @@ import { createRenderTemplate } from "./template/render_template.js";
|
|
|
2
2
|
import { prepareTemplateSpec } from "./template/template_loading.js";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { Templates } from "@platforma-sdk/workflow-tengo";
|
|
5
|
-
|
|
5
|
+
// src/mutator/context_export.ts
|
|
6
6
|
let preparedTemplateEnvelop;
|
|
7
7
|
async function getPreparedExportTemplateEnvelope() {
|
|
8
8
|
if (preparedTemplateEnvelop === void 0) {
|
|
@@ -18,7 +18,6 @@ async function getPreparedExportTemplateEnvelope() {
|
|
|
18
18
|
function exportContext(tx, exportTpl, ctx) {
|
|
19
19
|
return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ["result"]).result;
|
|
20
20
|
}
|
|
21
|
-
//#endregion
|
|
22
21
|
export { exportContext, getPreparedExportTemplateEnvelope };
|
|
23
22
|
|
|
24
23
|
//# sourceMappingURL=context_export.js.map
|
package/dist/mutator/list.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
2
|
-
|
|
2
|
+
// src/mutator/list.ts
|
|
3
3
|
/**
|
|
4
4
|
* Every entry of a list resource — the project list or the template list — keyed by the string
|
|
5
5
|
* form of the resource id it points at, which is what a project or template id is.
|
|
@@ -23,7 +23,6 @@ async function listedById(tx, listRid) {
|
|
|
23
23
|
function notListedError(kind, id) {
|
|
24
24
|
return /* @__PURE__ */ new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
exports.listedById = listedById;
|
|
28
27
|
exports.notListedError = notListedError;
|
|
29
28
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.cjs","names":[],"sources":["../../src/mutator/list.ts"],"sourcesContent":["import type { PlTransaction, SignedResourceId } from \"@milaboratories/pl-client\";\nimport { isNullSignedResourceId, resourceIdToString } from \"@milaboratories/pl-client\";\n\n/** One entry of a list resource: the field holding it and the resource that field points at. */\nexport interface ListedEntry {\n readonly fieldName: string;\n readonly rid: SignedResourceId;\n}\n\n/** The kinds of list a root keeps, as a not-found message names them. */\nexport type ListedKind = \"Project\" | \"Template\";\n\n/**\n * Every entry of a list resource — the project list or the template list — keyed by the string\n * form of the resource id it points at, which is what a project or template id is.\n *\n * A list field's name is a uuid unrelated to the id of what it holds, so an entry is only ever\n * found by value. Fields that point at nothing yet are left out.\n */\nexport async function listedById(\n tx: PlTransaction,\n listRid: SignedResourceId,\n): Promise<Map<string, ListedEntry>> {\n const data = await tx.getResourceData(listRid, true);\n const entries = new Map<string, ListedEntry>();\n for (const f of data.fields) {\n if (isNullSignedResourceId(f.value)) continue;\n entries.set(resourceIdToString(f.value), { fieldName: f.name, rid: f.value });\n }\n return entries;\n}\n\n/** What is thrown for an id the list does not hold, worded the same for every list. */\nexport function notListedError(kind: ListedKind, id: string): Error {\n return new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);\n}\n"],"mappings":";;;;;;;;;AAmBA,eAAsB,WACpB,IACA,SACmC;CACnC,MAAM,OAAO,MAAM,GAAG,gBAAgB,SAAS,IAAI;CACnD,MAAM,0BAAU,IAAI,IAAyB;CAC7C,KAAK,MAAM,KAAK,KAAK,QAAQ;EAC3B,KAAA,
|
|
1
|
+
{"version":3,"file":"list.cjs","names":["isNullSignedResourceId","resourceIdToString"],"sources":["../../src/mutator/list.ts"],"sourcesContent":["import type { PlTransaction, SignedResourceId } from \"@milaboratories/pl-client\";\nimport { isNullSignedResourceId, resourceIdToString } from \"@milaboratories/pl-client\";\n\n/** One entry of a list resource: the field holding it and the resource that field points at. */\nexport interface ListedEntry {\n readonly fieldName: string;\n readonly rid: SignedResourceId;\n}\n\n/** The kinds of list a root keeps, as a not-found message names them. */\nexport type ListedKind = \"Project\" | \"Template\";\n\n/**\n * Every entry of a list resource — the project list or the template list — keyed by the string\n * form of the resource id it points at, which is what a project or template id is.\n *\n * A list field's name is a uuid unrelated to the id of what it holds, so an entry is only ever\n * found by value. Fields that point at nothing yet are left out.\n */\nexport async function listedById(\n tx: PlTransaction,\n listRid: SignedResourceId,\n): Promise<Map<string, ListedEntry>> {\n const data = await tx.getResourceData(listRid, true);\n const entries = new Map<string, ListedEntry>();\n for (const f of data.fields) {\n if (isNullSignedResourceId(f.value)) continue;\n entries.set(resourceIdToString(f.value), { fieldName: f.name, rid: f.value });\n }\n return entries;\n}\n\n/** What is thrown for an id the list does not hold, worded the same for every list. */\nexport function notListedError(kind: ListedKind, id: string): Error {\n return new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);\n}\n"],"mappings":";;;;;;;;;AAmBA,eAAsB,WACpB,IACA,SACmC;CACnC,MAAM,OAAO,MAAM,GAAG,gBAAgB,SAAS,IAAI;CACnD,MAAM,0BAAU,IAAI,IAAyB;CAC7C,KAAK,MAAM,KAAK,KAAK,QAAQ;EAC3B,KAAA,GAAIA,0BAAAA,uBAAAA,CAAuB,EAAE,KAAK,GAAG;EACrC,QAAQ,KAAA,GAAIC,0BAAAA,mBAAAA,CAAmB,EAAE,KAAK,GAAG;GAAE,WAAW,EAAE;GAAM,KAAK,EAAE;EAAM,CAAC;CAC9E;CACA,OAAO;AACT;;AAGA,SAAgB,eAAe,MAAkB,IAAmB;CAClE,uBAAO,IAAI,MAAM,GAAG,KAAK,GAAG,GAAG,oBAAoB,KAAK,YAAY,EAAE,OAAO;AAC/E"}
|
package/dist/mutator/list.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNullSignedResourceId, resourceIdToString } from "@milaboratories/pl-client";
|
|
2
|
-
|
|
2
|
+
// src/mutator/list.ts
|
|
3
3
|
/**
|
|
4
4
|
* Every entry of a list resource — the project list or the template list — keyed by the string
|
|
5
5
|
* form of the resource id it points at, which is what a project or template id is.
|
|
@@ -23,7 +23,6 @@ async function listedById(tx, listRid) {
|
|
|
23
23
|
function notListedError(kind, id) {
|
|
24
24
|
return /* @__PURE__ */ new Error(`${kind} ${id} not found in the ${kind.toLowerCase()} list.`);
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { listedById, notListedError };
|
|
28
27
|
|
|
29
28
|
//# sourceMappingURL=list.js.map
|
|
@@ -4,7 +4,7 @@ const require_project_model_v1 = require("../model/project_model_v1.cjs");
|
|
|
4
4
|
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
5
5
|
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
6
6
|
let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
7
|
-
|
|
7
|
+
// src/mutator/migration.ts
|
|
8
8
|
/**
|
|
9
9
|
* Migrates the project to the latest schema version.
|
|
10
10
|
*
|
|
@@ -95,7 +95,6 @@ async function migrateV2ToV3(tx, rid) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
//#endregion
|
|
99
98
|
exports.applyProjectMigrations = applyProjectMigrations;
|
|
100
99
|
|
|
101
100
|
//# sourceMappingURL=migration.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.cjs","names":["SchemaVersionKey","UiError","ProjectStructureKey","allBlocks","BlockFrontendStateKeyPrefixV1","projectFieldName"],"sources":["../../src/mutator/migration.ts"],"sourcesContent":["import { UiError } from \"@milaboratories/pl-model-common\";\nimport type { PlClient, PlTransaction, SignedResourceId } from \"@milaboratories/pl-client\";\nimport type { ProjectField, ProjectStructure } from \"../model/project_model\";\nimport {\n projectFieldName,\n ProjectStructureKey,\n SchemaVersionCurrent,\n SchemaVersionKey,\n SchemaVersionV2,\n SchemaVersionV3,\n} from \"../model/project_model\";\nimport { BlockFrontendStateKeyPrefixV1, SchemaVersionV1 } from \"../model/project_model_v1\";\nimport { field, isNullSignedResourceId } from \"@milaboratories/pl-client\";\nimport { cachedDeserialize } from \"@milaboratories/ts-helpers\";\nimport { allBlocks } from \"../model/project_model_util\";\n\n/**\n * Migrates the project to the latest schema version.\n *\n * @param pl - The client to use.\n * @param rid - The resource id of the project.\n */\nexport async function applyProjectMigrations(pl: PlClient, rid: SignedResourceId) {\n await pl.withWriteTx(\"ProjectMigration\", async (tx) => {\n let schemaVersion = await tx.getKValueJson<string>(rid, SchemaVersionKey);\n if (schemaVersion === SchemaVersionCurrent) return;\n\n // Apply migrations in sequence\n if (schemaVersion === SchemaVersionV1) {\n await migrateV1ToV2(tx, rid);\n schemaVersion = SchemaVersionV2;\n }\n\n if (schemaVersion === SchemaVersionV2) {\n await migrateV2ToV3(tx, rid);\n schemaVersion = SchemaVersionV3;\n }\n\n if (schemaVersion === SchemaVersionV3) {\n // V3 → V4: production context chain + staging re-render.\n // The actual chain building and staging reset happens in fixProblemsAndMigrate()\n // (called from ProjectMutator.load). This migration step just bumps the schema\n // to prevent older clients from operating on the new project structure.\n schemaVersion = SchemaVersionCurrent;\n }\n\n if (schemaVersion !== SchemaVersionCurrent) {\n throw new UiError(\n `This project was created with a newer version of Platforma. Please update to the latest version to open it.`,\n );\n }\n\n tx.setKValue(rid, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n await tx.commit();\n });\n}\n\n/**\n * Migrates the project from schema version 1 to 2.\n *\n * Summary of changes:\n * - uiState is now stored in a field instead of a KV\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV1ToV2(tx: PlTransaction, rid: SignedResourceId) {\n const [structure, allKV] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.listKeyValues(rid),\n ]);\n const kvMap = new Map<string, Uint8Array>(allKV.map((kv) => [kv.key, kv.value]));\n for (const block of allBlocks(structure)) {\n const kvKey = BlockFrontendStateKeyPrefixV1 + block.id;\n const uiState = kvMap.get(kvKey);\n const valueJson = uiState ? cachedDeserialize(uiState) : {};\n const uiStateR = tx.createJsonGzValue(valueJson);\n const uiStateF = field(rid, projectFieldName(block.id, \"blockStorage\"));\n tx.createField(uiStateF, \"Dynamic\", uiStateR);\n tx.deleteKValue(rid, kvKey);\n }\n}\n\n/**\n * Migrates the project from schema version 2 to 3.\n *\n * Summary of changes:\n * - Introduces unified 'blockStorage' field containing { args, uiState }\n * - Adds 'currentPrerunArgs' field for staging/prerun rendering\n * - For each block:\n * 1. Read existing 'blockStorage' field (contains uiState in v2)\n * 2. Read existing 'currentArgs' field (contains args)\n * 3. Create unified state = { args: currentArgs, uiState: oldState }\n * 4. Write to new {blockId}-blockStorage field (overwrites)\n * 5. Initialize {blockId}-currentPrerunArgs (same as prodArgs for v1/v2 blocks)\n * - Note: currentArgs and prodArgs fields remain for compatibility layer\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV2ToV3(tx: PlTransaction, rid: SignedResourceId) {\n const [structure, fullResourceState] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.getResourceData(rid, true),\n ]);\n\n // Build a map of field name -> resource id for quick lookup\n const fieldMap = new Map<string, SignedResourceId>();\n for (const f of fullResourceState.fields) {\n if (!isNullSignedResourceId(f.value)) {\n fieldMap.set(f.name, f.value);\n }\n }\n\n for (const block of allBlocks(structure)) {\n // Read existing field values\n const uiStateFieldName = projectFieldName(block.id, \"uiState\" as ProjectField[\"fieldName\"]);\n const currentArgsFieldName = projectFieldName(block.id, \"currentArgs\");\n\n const uiStateRid = fieldMap.get(uiStateFieldName);\n const currentArgsRid = fieldMap.get(currentArgsFieldName);\n\n // Read field data in parallel where available\n const [uiStateData, currentArgsData] = await Promise.all([\n uiStateRid ? tx.getResourceData(uiStateRid, false) : Promise.resolve(undefined),\n currentArgsRid ? tx.getResourceData(currentArgsRid, false) : Promise.resolve(undefined),\n ]);\n\n // Extract values - in v2, 'blockStorage' contains raw uiState, not wrapped\n const uiState = uiStateData?.data ? cachedDeserialize(uiStateData.data) : {};\n const args = currentArgsData?.data ? cachedDeserialize(currentArgsData.data) : {};\n\n // Create unified state: { args, uiState }\n const unifiedState = {\n args,\n uiState,\n };\n\n const blockStorageFieldName = projectFieldName(block.id, \"blockStorage\");\n\n // Write new unified blockStorage field (overwrite existing)\n const stateR = tx.createJsonGzValue(unifiedState);\n const stateF = field(rid, blockStorageFieldName);\n tx.createField(stateF, \"Dynamic\", stateR);\n\n // Initialize currentPrerunArgs from currentArgs (for legacy blocks, prerunArgs = args)\n if (currentArgsRid) {\n const prerunArgsR = tx.createJsonGzValue(args);\n const prerunArgsF = field(rid, projectFieldName(block.id, \"currentPrerunArgs\"));\n tx.createField(prerunArgsF, \"Dynamic\", prerunArgsR);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,eAAsB,uBAAuB,IAAc,KAAuB;CAChF,MAAM,GAAG,YAAY,oBAAoB,OAAO,OAAO;EACrD,IAAI,gBAAgB,MAAM,GAAG,cAAsB,KAAKA,sBAAAA,gBAAgB;EACxE,IAAI,kBAAA,KAAwC;EAG5C,IAAI,kBAAA,KAAmC;GACrC,MAAM,cAAc,IAAI,GAAG;GAC3B,gBAAA;EACF;EAEA,IAAI,kBAAA,KAAmC;GACrC,MAAM,cAAc,IAAI,GAAG;GAC3B,gBAAA;EACF;EAEA,IAAI,kBAAA,KAKF,gBAAA;EAGF,IAAI,kBAAA,KACF,MAAM,IAAIC,gCAAAA,QACR,6GACF;EAGF,GAAG,UAAU,KAAKD,sBAAAA,kBAAkB,KAAK,UAAA,GAA8B,CAAC;EACxE,MAAM,GAAG,OAAO;CAClB,CAAC;AACH;;;;;;;;;;AAWA,eAAe,cAAc,IAAmB,KAAuB;CACrE,MAAM,CAAC,WAAW,SAAS,MAAM,QAAQ,IAAI,CAC3C,GAAG,cAAgC,KAAKE,sBAAAA,mBAAmB,GAC3D,GAAG,cAAc,GAAG,CACtB,CAAC;CACD,MAAM,QAAQ,IAAI,IAAwB,MAAM,KAAK,OAAO,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,CAAC;CAC/E,KAAK,MAAM,SAASC,2BAAAA,UAAU,SAAS,GAAG;EACxC,MAAM,QAAQC,yBAAAA,gCAAgC,MAAM;EACpD,MAAM,UAAU,MAAM,IAAI,KAAK;EAC/B,MAAM,YAAY,WAAA,
|
|
1
|
+
{"version":3,"file":"migration.cjs","names":["SchemaVersionKey","UiError","ProjectStructureKey","allBlocks","BlockFrontendStateKeyPrefixV1","cachedDeserialize","field","projectFieldName","isNullSignedResourceId"],"sources":["../../src/mutator/migration.ts"],"sourcesContent":["import { UiError } from \"@milaboratories/pl-model-common\";\nimport type { PlClient, PlTransaction, SignedResourceId } from \"@milaboratories/pl-client\";\nimport type { ProjectField, ProjectStructure } from \"../model/project_model\";\nimport {\n projectFieldName,\n ProjectStructureKey,\n SchemaVersionCurrent,\n SchemaVersionKey,\n SchemaVersionV2,\n SchemaVersionV3,\n} from \"../model/project_model\";\nimport { BlockFrontendStateKeyPrefixV1, SchemaVersionV1 } from \"../model/project_model_v1\";\nimport { field, isNullSignedResourceId } from \"@milaboratories/pl-client\";\nimport { cachedDeserialize } from \"@milaboratories/ts-helpers\";\nimport { allBlocks } from \"../model/project_model_util\";\n\n/**\n * Migrates the project to the latest schema version.\n *\n * @param pl - The client to use.\n * @param rid - The resource id of the project.\n */\nexport async function applyProjectMigrations(pl: PlClient, rid: SignedResourceId) {\n await pl.withWriteTx(\"ProjectMigration\", async (tx) => {\n let schemaVersion = await tx.getKValueJson<string>(rid, SchemaVersionKey);\n if (schemaVersion === SchemaVersionCurrent) return;\n\n // Apply migrations in sequence\n if (schemaVersion === SchemaVersionV1) {\n await migrateV1ToV2(tx, rid);\n schemaVersion = SchemaVersionV2;\n }\n\n if (schemaVersion === SchemaVersionV2) {\n await migrateV2ToV3(tx, rid);\n schemaVersion = SchemaVersionV3;\n }\n\n if (schemaVersion === SchemaVersionV3) {\n // V3 → V4: production context chain + staging re-render.\n // The actual chain building and staging reset happens in fixProblemsAndMigrate()\n // (called from ProjectMutator.load). This migration step just bumps the schema\n // to prevent older clients from operating on the new project structure.\n schemaVersion = SchemaVersionCurrent;\n }\n\n if (schemaVersion !== SchemaVersionCurrent) {\n throw new UiError(\n `This project was created with a newer version of Platforma. Please update to the latest version to open it.`,\n );\n }\n\n tx.setKValue(rid, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));\n await tx.commit();\n });\n}\n\n/**\n * Migrates the project from schema version 1 to 2.\n *\n * Summary of changes:\n * - uiState is now stored in a field instead of a KV\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV1ToV2(tx: PlTransaction, rid: SignedResourceId) {\n const [structure, allKV] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.listKeyValues(rid),\n ]);\n const kvMap = new Map<string, Uint8Array>(allKV.map((kv) => [kv.key, kv.value]));\n for (const block of allBlocks(structure)) {\n const kvKey = BlockFrontendStateKeyPrefixV1 + block.id;\n const uiState = kvMap.get(kvKey);\n const valueJson = uiState ? cachedDeserialize(uiState) : {};\n const uiStateR = tx.createJsonGzValue(valueJson);\n const uiStateF = field(rid, projectFieldName(block.id, \"blockStorage\"));\n tx.createField(uiStateF, \"Dynamic\", uiStateR);\n tx.deleteKValue(rid, kvKey);\n }\n}\n\n/**\n * Migrates the project from schema version 2 to 3.\n *\n * Summary of changes:\n * - Introduces unified 'blockStorage' field containing { args, uiState }\n * - Adds 'currentPrerunArgs' field for staging/prerun rendering\n * - For each block:\n * 1. Read existing 'blockStorage' field (contains uiState in v2)\n * 2. Read existing 'currentArgs' field (contains args)\n * 3. Create unified state = { args: currentArgs, uiState: oldState }\n * 4. Write to new {blockId}-blockStorage field (overwrites)\n * 5. Initialize {blockId}-currentPrerunArgs (same as prodArgs for v1/v2 blocks)\n * - Note: currentArgs and prodArgs fields remain for compatibility layer\n *\n * @param tx - The transaction to use.\n * @param rid - The resource id of the project.\n */\nasync function migrateV2ToV3(tx: PlTransaction, rid: SignedResourceId) {\n const [structure, fullResourceState] = await Promise.all([\n tx.getKValueJson<ProjectStructure>(rid, ProjectStructureKey),\n tx.getResourceData(rid, true),\n ]);\n\n // Build a map of field name -> resource id for quick lookup\n const fieldMap = new Map<string, SignedResourceId>();\n for (const f of fullResourceState.fields) {\n if (!isNullSignedResourceId(f.value)) {\n fieldMap.set(f.name, f.value);\n }\n }\n\n for (const block of allBlocks(structure)) {\n // Read existing field values\n const uiStateFieldName = projectFieldName(block.id, \"uiState\" as ProjectField[\"fieldName\"]);\n const currentArgsFieldName = projectFieldName(block.id, \"currentArgs\");\n\n const uiStateRid = fieldMap.get(uiStateFieldName);\n const currentArgsRid = fieldMap.get(currentArgsFieldName);\n\n // Read field data in parallel where available\n const [uiStateData, currentArgsData] = await Promise.all([\n uiStateRid ? tx.getResourceData(uiStateRid, false) : Promise.resolve(undefined),\n currentArgsRid ? tx.getResourceData(currentArgsRid, false) : Promise.resolve(undefined),\n ]);\n\n // Extract values - in v2, 'blockStorage' contains raw uiState, not wrapped\n const uiState = uiStateData?.data ? cachedDeserialize(uiStateData.data) : {};\n const args = currentArgsData?.data ? cachedDeserialize(currentArgsData.data) : {};\n\n // Create unified state: { args, uiState }\n const unifiedState = {\n args,\n uiState,\n };\n\n const blockStorageFieldName = projectFieldName(block.id, \"blockStorage\");\n\n // Write new unified blockStorage field (overwrite existing)\n const stateR = tx.createJsonGzValue(unifiedState);\n const stateF = field(rid, blockStorageFieldName);\n tx.createField(stateF, \"Dynamic\", stateR);\n\n // Initialize currentPrerunArgs from currentArgs (for legacy blocks, prerunArgs = args)\n if (currentArgsRid) {\n const prerunArgsR = tx.createJsonGzValue(args);\n const prerunArgsF = field(rid, projectFieldName(block.id, \"currentPrerunArgs\"));\n tx.createField(prerunArgsF, \"Dynamic\", prerunArgsR);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;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B,MAAM,cAAc,GAAG,kBAAkB,IAAI;GAC7C,MAAM,eAAA,GAAcA,0BAAAA,MAAAA,CAAM,KAAKC,sBAAAA,iBAAiB,MAAM,IAAI,mBAAmB,CAAC;GAC9E,GAAG,YAAY,aAAa,WAAW,WAAW;EACpD;CACF;AACF"}
|
|
@@ -4,7 +4,7 @@ import { BlockFrontendStateKeyPrefixV1 } from "../model/project_model_v1.js";
|
|
|
4
4
|
import { cachedDeserialize } from "@milaboratories/ts-helpers";
|
|
5
5
|
import { UiError } from "@milaboratories/pl-model-common";
|
|
6
6
|
import { field, isNullSignedResourceId } from "@milaboratories/pl-client";
|
|
7
|
-
|
|
7
|
+
// src/mutator/migration.ts
|
|
8
8
|
/**
|
|
9
9
|
* Migrates the project to the latest schema version.
|
|
10
10
|
*
|
|
@@ -95,7 +95,6 @@ async function migrateV2ToV3(tx, rid) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
//#endregion
|
|
99
98
|
export { applyProjectMigrations };
|
|
100
99
|
|
|
101
100
|
//# sourceMappingURL=migration.js.map
|
package/dist/mutator/project.cjs
CHANGED
|
@@ -15,7 +15,7 @@ let _milaboratories_pl_client = require("@milaboratories/pl-client");
|
|
|
15
15
|
let _milaboratories_pl_errors = require("@milaboratories/pl-errors");
|
|
16
16
|
let denque = require("denque");
|
|
17
17
|
denque = require_runtime.__toESM(denque, 1);
|
|
18
|
-
|
|
18
|
+
// src/mutator/project.ts
|
|
19
19
|
/**
|
|
20
20
|
* A production core field is "settled" once its result is immutable — `Ready` or a finished
|
|
21
21
|
* `Error`. `NotReady` (still computing) is the only unsettled status; a missing field is unsettled.
|
|
@@ -703,7 +703,8 @@ var ProjectMutator = class ProjectMutator {
|
|
|
703
703
|
updateStructure(newStructure, newBlockInitializer = NoNewBlocks) {
|
|
704
704
|
const currentStagingGraph = this.getStagingGraph();
|
|
705
705
|
const currentActualProductionGraph = this.getActualProductionGraph();
|
|
706
|
-
const
|
|
706
|
+
const newStagingGraph = require_project_model_util.stagingGraph(newStructure);
|
|
707
|
+
const stagingDiff = require_project_model_util.graphDiff(currentStagingGraph, newStagingGraph);
|
|
707
708
|
for (const blockId of stagingDiff.onlyInA) {
|
|
708
709
|
const { fields } = this.getBlockInfo(blockId);
|
|
709
710
|
this.deleteBlockFields(blockId, ...Object.keys(fields));
|
|
@@ -712,7 +713,8 @@ var ProjectMutator = class ProjectMutator {
|
|
|
712
713
|
}
|
|
713
714
|
for (const blockId of stagingDiff.onlyInB) newBlockInitializer(blockId);
|
|
714
715
|
for (const blockId of stagingDiff.different) this.resetStaging(blockId);
|
|
715
|
-
const
|
|
716
|
+
const newActualProductionGraph = require_project_model_util.productionGraph(newStructure, (blockId) => this.getProductionGraphBlockInfo(blockId, true));
|
|
717
|
+
const prodDiff = require_project_model_util.graphDiff(currentActualProductionGraph, newActualProductionGraph);
|
|
716
718
|
currentActualProductionGraph.traverse("downstream", [...prodDiff.different], (node) => {
|
|
717
719
|
this.resetOrLimboProduction(node.id);
|
|
718
720
|
});
|
|
@@ -812,19 +814,20 @@ var ProjectMutator = class ProjectMutator {
|
|
|
812
814
|
if (!deriveArgsResult.error && deriveArgsResult.value !== void 0) this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(deriveArgsResult.value));
|
|
813
815
|
else this.deleteBlockFields(blockId, "currentArgs");
|
|
814
816
|
};
|
|
815
|
-
if (newClearState !== void 0)
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
817
|
+
if (newClearState !== void 0) {
|
|
818
|
+
if (newConfig.modelAPIVersion === _platforma_sdk_model.BLOCK_STORAGE_FACADE_VERSION) {
|
|
819
|
+
applyStorageAndDeriveArgs(this.projectHelper.getInitialStorageInVM(newConfig));
|
|
820
|
+
this.blocksWithChangedInputs.add(blockId);
|
|
821
|
+
this.updateLastModified();
|
|
822
|
+
} else {
|
|
823
|
+
persistBlockPack();
|
|
824
|
+
this.setStates([{
|
|
825
|
+
modelAPIVersion: 1,
|
|
826
|
+
blockId,
|
|
827
|
+
state: newClearState.state
|
|
828
|
+
}]);
|
|
829
|
+
}
|
|
819
830
|
} else {
|
|
820
|
-
persistBlockPack();
|
|
821
|
-
this.setStates([{
|
|
822
|
-
modelAPIVersion: 1,
|
|
823
|
-
blockId,
|
|
824
|
-
state: newClearState.state
|
|
825
|
-
}]);
|
|
826
|
-
}
|
|
827
|
-
else {
|
|
828
831
|
if (newConfig.modelAPIVersion === _platforma_sdk_model.BLOCK_STORAGE_FACADE_VERSION) {
|
|
829
832
|
const currentStorageJson = info.blockStorageJson;
|
|
830
833
|
const migrationResult = this.projectHelper.migrateStorageInVM(newConfig, currentStorageJson);
|
|
@@ -965,8 +968,10 @@ var ProjectMutator = class ProjectMutator {
|
|
|
965
968
|
const markerStr = this.author ? JSON.stringify(this.author) : void 0;
|
|
966
969
|
for (const blockId of this.blocksWithChangedInputs) if (markerStr === void 0) this.tx.deleteKValue(this.rid, require_project_model.blockArgsAuthorKey(blockId));
|
|
967
970
|
else this.tx.setKValue(this.rid, require_project_model.blockArgsAuthorKey(blockId), markerStr);
|
|
968
|
-
if (this.metaChanged || this.structureChanged)
|
|
969
|
-
|
|
971
|
+
if (this.metaChanged || this.structureChanged) {
|
|
972
|
+
if (markerStr === void 0) this.tx.deleteKValue(this.rid, require_project_model.ProjectStructureAuthorKey);
|
|
973
|
+
else this.tx.setKValue(this.rid, require_project_model.ProjectStructureAuthorKey, markerStr);
|
|
974
|
+
}
|
|
970
975
|
}
|
|
971
976
|
save() {
|
|
972
977
|
if (!this.wasModified) return;
|
|
@@ -1031,8 +1036,10 @@ var ProjectMutator = class ProjectMutator {
|
|
|
1031
1036
|
structureP,
|
|
1032
1037
|
renderingStateP
|
|
1033
1038
|
]);
|
|
1034
|
-
if (schema !== "4")
|
|
1035
|
-
|
|
1039
|
+
if (schema !== "4") {
|
|
1040
|
+
if (Number(schema) < 4) throw new _platforma_sdk_model.UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);
|
|
1041
|
+
else throw new _platforma_sdk_model.UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);
|
|
1042
|
+
}
|
|
1036
1043
|
const blockPackRequests = [];
|
|
1037
1044
|
for (const [info, fieldName, state, response] of blockFieldRequests) {
|
|
1038
1045
|
const result = await response;
|
|
@@ -1047,7 +1054,8 @@ var ProjectMutator = class ProjectMutator {
|
|
|
1047
1054
|
}
|
|
1048
1055
|
}
|
|
1049
1056
|
for (const [info, response] of blockPackRequests) {
|
|
1050
|
-
const
|
|
1057
|
+
const result = await response;
|
|
1058
|
+
const bpInfo = (0, _milaboratories_ts_helpers.cachedDeserialize)((0, _milaboratories_ts_helpers.notEmpty)(result.data));
|
|
1051
1059
|
info.blockConfig = (0, _platforma_sdk_model.extractConfig)(bpInfo.config);
|
|
1052
1060
|
info.blockKind = bpInfo.config.kind;
|
|
1053
1061
|
info.blockPack = bpInfo.source;
|
|
@@ -1123,7 +1131,8 @@ async function duplicateProject(tx, sourceRid, options, projectHelper) {
|
|
|
1123
1131
|
const isTargetSettled = async (rid) => {
|
|
1124
1132
|
if (rid === void 0 || (0, _milaboratories_pl_client.isNullSignedResourceId)(rid)) return false;
|
|
1125
1133
|
try {
|
|
1126
|
-
|
|
1134
|
+
const r = await tx.getResourceData(rid, false);
|
|
1135
|
+
return (0, _milaboratories_pl_client.readyOrDuplicateOrError)(r);
|
|
1127
1136
|
} catch {
|
|
1128
1137
|
return false;
|
|
1129
1138
|
}
|
|
@@ -1193,7 +1202,6 @@ async function withProjectAuthored(projectHelper, txOrPl, rid, author, cb, ops =
|
|
|
1193
1202
|
return result;
|
|
1194
1203
|
}
|
|
1195
1204
|
}
|
|
1196
|
-
//#endregion
|
|
1197
1205
|
exports.ProjectMutator = ProjectMutator;
|
|
1198
1206
|
exports.createProject = createProject;
|
|
1199
1207
|
exports.duplicateProject = duplicateProject;
|