@milaboratories/pl-middle-layer 1.48.11 → 1.48.13
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.114.0/helpers/usingCtx.cjs +59 -0
- package/dist/_virtual/_@oxc-project_runtime@0.114.0/helpers/usingCtx.js +58 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/block_registry/index.cjs +3 -0
- package/dist/block_registry/index.d.ts +3 -4
- package/dist/block_registry/index.js +3 -0
- package/dist/block_registry/registry-v2-provider.cjs +18 -19
- package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
- package/dist/block_registry/registry-v2-provider.d.ts +10 -6
- package/dist/block_registry/registry-v2-provider.js +17 -17
- package/dist/block_registry/registry-v2-provider.js.map +1 -1
- package/dist/block_registry/registry.cjs +188 -219
- package/dist/block_registry/registry.cjs.map +1 -1
- package/dist/block_registry/registry.d.ts +18 -14
- package/dist/block_registry/registry.js +184 -217
- package/dist/block_registry/registry.js.map +1 -1
- package/dist/block_registry/watcher.cjs +141 -170
- package/dist/block_registry/watcher.cjs.map +1 -1
- package/dist/block_registry/watcher.d.ts +26 -24
- package/dist/block_registry/watcher.js +139 -168
- package/dist/block_registry/watcher.js.map +1 -1
- package/dist/block_registry/well_known_registries.cjs +9 -8
- package/dist/block_registry/well_known_registries.cjs.map +1 -1
- package/dist/block_registry/well_known_registries.d.ts +8 -4
- package/dist/block_registry/well_known_registries.js +9 -7
- package/dist/block_registry/well_known_registries.js.map +1 -1
- package/dist/cfg_render/executor.cjs +136 -137
- package/dist/cfg_render/executor.cjs.map +1 -1
- package/dist/cfg_render/executor.js +133 -135
- package/dist/cfg_render/executor.js.map +1 -1
- package/dist/cfg_render/renderer.cjs +354 -462
- package/dist/cfg_render/renderer.cjs.map +1 -1
- package/dist/cfg_render/renderer.js +353 -460
- package/dist/cfg_render/renderer.js.map +1 -1
- package/dist/cfg_render/traverse.cjs +58 -60
- package/dist/cfg_render/traverse.cjs.map +1 -1
- package/dist/cfg_render/traverse.js +57 -58
- package/dist/cfg_render/traverse.js.map +1 -1
- package/dist/cfg_render/util.cjs +14 -19
- package/dist/cfg_render/util.cjs.map +1 -1
- package/dist/cfg_render/util.js +14 -17
- package/dist/cfg_render/util.js.map +1 -1
- package/dist/debug/index.cjs +13 -17
- package/dist/debug/index.cjs.map +1 -1
- package/dist/debug/index.js +13 -16
- package/dist/debug/index.js.map +1 -1
- package/dist/dev_env/index.cjs +60 -44
- package/dist/dev_env/index.cjs.map +1 -1
- package/dist/dev_env/index.js +57 -33
- package/dist/dev_env/index.js.map +1 -1
- package/dist/dev_env/util.cjs +12 -32
- package/dist/dev_env/util.cjs.map +1 -1
- package/dist/dev_env/util.js +10 -11
- package/dist/dev_env/util.js.map +1 -1
- package/dist/index.cjs +75 -74
- package/dist/index.d.ts +21 -13
- package/dist/index.js +25 -18
- package/dist/js_render/computable_context.cjs +432 -568
- package/dist/js_render/computable_context.cjs.map +1 -1
- package/dist/js_render/computable_context.js +431 -566
- package/dist/js_render/computable_context.js.map +1 -1
- package/dist/js_render/context.cjs +184 -237
- package/dist/js_render/context.cjs.map +1 -1
- package/dist/js_render/context.js +184 -235
- package/dist/js_render/context.js.map +1 -1
- package/dist/js_render/index.cjs +137 -156
- package/dist/js_render/index.cjs.map +1 -1
- package/dist/js_render/index.js +136 -154
- package/dist/js_render/index.js.map +1 -1
- package/dist/middle_layer/active_cfg.cjs +28 -35
- package/dist/middle_layer/active_cfg.cjs.map +1 -1
- package/dist/middle_layer/active_cfg.js +27 -33
- package/dist/middle_layer/active_cfg.js.map +1 -1
- package/dist/middle_layer/block.cjs +36 -42
- package/dist/middle_layer/block.cjs.map +1 -1
- package/dist/middle_layer/block.js +35 -40
- package/dist/middle_layer/block.js.map +1 -1
- package/dist/middle_layer/block_ctx.cjs +91 -133
- package/dist/middle_layer/block_ctx.cjs.map +1 -1
- package/dist/middle_layer/block_ctx.js +90 -131
- package/dist/middle_layer/block_ctx.js.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.cjs +20 -19
- package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.js +20 -18
- package/dist/middle_layer/block_ctx_unsafe.js.map +1 -1
- package/dist/middle_layer/driver_kit.cjs +47 -51
- package/dist/middle_layer/driver_kit.cjs.map +1 -1
- package/dist/middle_layer/driver_kit.d.ts +31 -27
- package/dist/middle_layer/driver_kit.js +46 -49
- package/dist/middle_layer/driver_kit.js.map +1 -1
- package/dist/middle_layer/frontend_path.cjs +49 -55
- package/dist/middle_layer/frontend_path.cjs.map +1 -1
- package/dist/middle_layer/frontend_path.js +48 -53
- package/dist/middle_layer/frontend_path.js.map +1 -1
- package/dist/middle_layer/index.cjs +4 -0
- package/dist/middle_layer/index.d.ts +4 -5
- package/dist/middle_layer/index.js +4 -0
- package/dist/middle_layer/middle_layer.cjs +216 -245
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +95 -91
- package/dist/middle_layer/middle_layer.js +215 -243
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/navigation_states.cjs +45 -38
- package/dist/middle_layer/navigation_states.cjs.map +1 -1
- package/dist/middle_layer/navigation_states.js +44 -36
- package/dist/middle_layer/navigation_states.js.map +1 -1
- package/dist/middle_layer/ops.cjs +56 -57
- package/dist/middle_layer/ops.cjs.map +1 -1
- package/dist/middle_layer/ops.d.ts +86 -96
- package/dist/middle_layer/ops.js +54 -55
- package/dist/middle_layer/ops.js.map +1 -1
- package/dist/middle_layer/project.cjs +497 -527
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +155 -152
- package/dist/middle_layer/project.js +494 -525
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/middle_layer/project_list.cjs +45 -43
- package/dist/middle_layer/project_list.cjs.map +1 -1
- package/dist/middle_layer/project_list.js +45 -41
- package/dist/middle_layer/project_list.js.map +1 -1
- package/dist/middle_layer/project_overview.cjs +202 -240
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.js +201 -238
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/dist/middle_layer/project_overview_light.cjs +11 -14
- package/dist/middle_layer/project_overview_light.cjs.map +1 -1
- package/dist/middle_layer/project_overview_light.js +10 -12
- package/dist/middle_layer/project_overview_light.js.map +1 -1
- package/dist/middle_layer/render.cjs +14 -18
- package/dist/middle_layer/render.cjs.map +1 -1
- package/dist/middle_layer/render.js +13 -16
- package/dist/middle_layer/render.js.map +1 -1
- package/dist/middle_layer/types.d.ts +7 -10
- package/dist/middle_layer/util.cjs +26 -21
- package/dist/middle_layer/util.cjs.map +1 -1
- package/dist/middle_layer/util.js +25 -19
- package/dist/middle_layer/util.js.map +1 -1
- package/dist/model/args.cjs +44 -53
- package/dist/model/args.cjs.map +1 -1
- package/dist/model/args.js +44 -51
- package/dist/model/args.js.map +1 -1
- package/dist/model/block_pack_spec.cjs +9 -5
- package/dist/model/block_pack_spec.cjs.map +1 -1
- package/dist/model/block_pack_spec.d.ts +34 -30
- package/dist/model/block_pack_spec.js +9 -4
- package/dist/model/block_pack_spec.js.map +1 -1
- package/dist/model/frontend.d.ts +8 -5
- package/dist/model/index.d.ts +2 -3
- package/dist/model/project_helper.cjs +154 -193
- package/dist/model/project_helper.cjs.map +1 -1
- package/dist/model/project_helper.d.ts +96 -92
- package/dist/model/project_helper.js +153 -191
- package/dist/model/project_helper.js.map +1 -1
- package/dist/model/project_model.cjs +33 -32
- package/dist/model/project_model.cjs.map +1 -1
- package/dist/model/project_model.d.ts +13 -64
- package/dist/model/project_model.js +34 -30
- package/dist/model/project_model.js.map +1 -1
- package/dist/model/project_model_util.cjs +119 -158
- package/dist/model/project_model_util.cjs.map +1 -1
- package/dist/model/project_model_util.js +120 -156
- package/dist/model/project_model_util.js.map +1 -1
- package/dist/model/project_model_v1.cjs +3 -2
- package/dist/model/project_model_v1.cjs.map +1 -1
- package/dist/model/project_model_v1.js +3 -1
- package/dist/model/project_model_v1.js.map +1 -1
- package/dist/model/template_spec.d.ts +20 -16
- package/dist/mutator/block-pack/block_pack.cjs +200 -223
- package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
- package/dist/mutator/block-pack/block_pack.d.ts +20 -19
- package/dist/mutator/block-pack/block_pack.js +199 -221
- package/dist/mutator/block-pack/block_pack.js.map +1 -1
- package/dist/mutator/block-pack/frontend.cjs +14 -16
- package/dist/mutator/block-pack/frontend.cjs.map +1 -1
- package/dist/mutator/block-pack/frontend.js +13 -14
- package/dist/mutator/block-pack/frontend.js.map +1 -1
- package/dist/mutator/context_export.cjs +18 -17
- package/dist/mutator/context_export.cjs.map +1 -1
- package/dist/mutator/context_export.js +17 -15
- package/dist/mutator/context_export.js.map +1 -1
- package/dist/mutator/migration.cjs +86 -112
- package/dist/mutator/migration.cjs.map +1 -1
- package/dist/mutator/migration.js +85 -110
- package/dist/mutator/migration.js.map +1 -1
- package/dist/mutator/project.cjs +903 -1240
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.js +901 -1237
- package/dist/mutator/project.js.map +1 -1
- package/dist/mutator/template/direct_template_loader.cjs +104 -130
- package/dist/mutator/template/direct_template_loader.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader.js +103 -128
- package/dist/mutator/template/direct_template_loader.js.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.cjs +104 -124
- package/dist/mutator/template/direct_template_loader_v3.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.js +103 -122
- package/dist/mutator/template/direct_template_loader_v3.js.map +1 -1
- package/dist/mutator/template/render_block.cjs +26 -30
- package/dist/mutator/template/render_block.cjs.map +1 -1
- package/dist/mutator/template/render_block.js +26 -23
- package/dist/mutator/template/render_block.js.map +1 -1
- package/dist/mutator/template/render_template.cjs +25 -25
- package/dist/mutator/template/render_template.cjs.map +1 -1
- package/dist/mutator/template/render_template.d.ts +6 -3
- package/dist/mutator/template/render_template.js +24 -23
- package/dist/mutator/template/render_template.js.map +1 -1
- package/dist/mutator/template/template_loading.cjs +42 -46
- package/dist/mutator/template/template_loading.cjs.map +1 -1
- package/dist/mutator/template/template_loading.d.ts +16 -12
- package/dist/mutator/template/template_loading.js +40 -44
- package/dist/mutator/template/template_loading.js.map +1 -1
- package/dist/network_check/network_check.cjs +149 -194
- package/dist/network_check/network_check.cjs.map +1 -1
- package/dist/network_check/network_check.d.ts +50 -66
- package/dist/network_check/network_check.js +146 -190
- package/dist/network_check/network_check.js.map +1 -1
- package/dist/network_check/pings.cjs +71 -69
- package/dist/network_check/pings.cjs.map +1 -1
- package/dist/network_check/pings.js +71 -65
- package/dist/network_check/pings.js.map +1 -1
- package/dist/network_check/template.cjs +256 -273
- package/dist/network_check/template.cjs.map +1 -1
- package/dist/network_check/template.js +253 -265
- package/dist/network_check/template.js.map +1 -1
- package/dist/pool/data.cjs +205 -226
- package/dist/pool/data.cjs.map +1 -1
- package/dist/pool/data.d.ts +10 -27
- package/dist/pool/data.js +196 -209
- package/dist/pool/data.js.map +1 -1
- package/dist/pool/driver.cjs +180 -207
- package/dist/pool/driver.cjs.map +1 -1
- package/dist/pool/driver.d.ts +12 -17
- package/dist/pool/driver.js +178 -205
- package/dist/pool/driver.js.map +1 -1
- package/dist/pool/index.cjs +2 -0
- package/dist/pool/index.d.ts +2 -3
- package/dist/pool/index.js +2 -0
- package/dist/pool/p_object_collection.cjs +67 -79
- package/dist/pool/p_object_collection.cjs.map +1 -1
- package/dist/pool/p_object_collection.d.ts +7 -28
- package/dist/pool/p_object_collection.js +65 -77
- package/dist/pool/p_object_collection.js.map +1 -1
- package/dist/pool/result_pool.cjs +217 -262
- package/dist/pool/result_pool.cjs.map +1 -1
- package/dist/pool/result_pool.d.ts +4 -27
- package/dist/pool/result_pool.js +216 -260
- package/dist/pool/result_pool.js.map +1 -1
- package/dist/worker/WorkerManager.cjs +51 -49
- package/dist/worker/WorkerManager.cjs.map +1 -1
- package/dist/worker/WorkerManager.js +49 -47
- package/dist/worker/WorkerManager.js.map +1 -1
- package/dist/worker/worker.cjs +19 -15
- package/dist/worker/worker.cjs.map +1 -1
- package/dist/worker/worker.d.ts +1 -2
- package/dist/worker/worker.js +18 -13
- package/dist/worker/worker.js.map +1 -1
- package/dist/worker/workerApi.cjs +14 -18
- package/dist/worker/workerApi.cjs.map +1 -1
- package/dist/worker/workerApi.js +13 -16
- package/dist/worker/workerApi.js.map +1 -1
- package/package.json +24 -24
- package/src/mutator/template/template_render.test.ts +22 -18
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs +0 -77
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs.map +0 -1
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js +0 -74
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.cjs +0 -162
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.js +0 -160
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.cjs +0 -576
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.js +0 -574
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.cjs +0 -337
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.js +0 -335
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.cjs +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.js +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.cjs +0 -73
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.js +0 -71
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.cjs +0 -78
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.js +0 -76
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.cjs +0 -23
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.js +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.cjs +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.js +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.cjs +0 -74
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.js +0 -72
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.cjs +0 -35
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.js +0 -33
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.cjs +0 -32
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.js +0 -30
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.cjs +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.js +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.cjs +0 -26
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.js +0 -24
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.cjs +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.js +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.cjs +0 -145
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.js +0 -143
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.cjs +0 -49
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.js +0 -47
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.cjs +0 -23
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.js +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.cjs +0 -37
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.js +0 -35
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.cjs +0 -54
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.js +0 -52
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.cjs +0 -29
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.js +0 -27
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.cjs +0 -240
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.js +0 -238
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.cjs +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.js +0 -18
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.cjs +0 -23
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.js +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.cjs +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.js +0 -18
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.cjs +0 -42
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.js +0 -40
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.cjs +0 -41
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.js +0 -39
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.cjs +0 -79
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.js +0 -77
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.cjs +0 -103
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.js +0 -101
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.cjs +0 -64
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.js +0 -62
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.cjs +0 -266
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.js +0 -264
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.cjs +0 -24
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.js +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.cjs +0 -27
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.js +0 -25
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.js.map +0 -1
- package/dist/_virtual/index.cjs +0 -8
- package/dist/_virtual/index.cjs.map +0 -1
- package/dist/_virtual/index.js +0 -6
- package/dist/_virtual/index.js.map +0 -1
- package/dist/_virtual/re.cjs +0 -6
- package/dist/_virtual/re.cjs.map +0 -1
- package/dist/_virtual/re.js +0 -4
- package/dist/_virtual/re.js.map +0 -1
- package/dist/block_registry/index.d.ts.map +0 -1
- package/dist/block_registry/registry-v2-provider.d.ts.map +0 -1
- package/dist/block_registry/registry.d.ts.map +0 -1
- package/dist/block_registry/registry.test.d.ts +0 -2
- package/dist/block_registry/registry.test.d.ts.map +0 -1
- package/dist/block_registry/watcher.d.ts.map +0 -1
- package/dist/block_registry/well_known_registries.d.ts.map +0 -1
- package/dist/cfg_render/executor.d.ts +0 -9
- package/dist/cfg_render/executor.d.ts.map +0 -1
- package/dist/cfg_render/executor.test.d.ts +0 -2
- package/dist/cfg_render/executor.test.d.ts.map +0 -1
- package/dist/cfg_render/operation.d.ts +0 -29
- package/dist/cfg_render/operation.d.ts.map +0 -1
- package/dist/cfg_render/renderer.d.ts +0 -6
- package/dist/cfg_render/renderer.d.ts.map +0 -1
- package/dist/cfg_render/traverse.d.ts +0 -3
- package/dist/cfg_render/traverse.d.ts.map +0 -1
- package/dist/cfg_render/util.d.ts +0 -5
- package/dist/cfg_render/util.d.ts.map +0 -1
- package/dist/debug/index.d.ts +0 -9
- package/dist/debug/index.d.ts.map +0 -1
- package/dist/dev_env/index.d.ts +0 -21
- package/dist/dev_env/index.d.ts.map +0 -1
- package/dist/dev_env/util.d.ts +0 -3
- package/dist/dev_env/util.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/js_render/computable_context.d.ts +0 -74
- package/dist/js_render/computable_context.d.ts.map +0 -1
- package/dist/js_render/context.d.ts +0 -73
- package/dist/js_render/context.d.ts.map +0 -1
- package/dist/js_render/index.d.ts +0 -57
- package/dist/js_render/index.d.ts.map +0 -1
- package/dist/middle_layer/active_cfg.d.ts +0 -6
- package/dist/middle_layer/active_cfg.d.ts.map +0 -1
- package/dist/middle_layer/block.d.ts +0 -10
- package/dist/middle_layer/block.d.ts.map +0 -1
- package/dist/middle_layer/block_ctx.d.ts +0 -23
- package/dist/middle_layer/block_ctx.d.ts.map +0 -1
- package/dist/middle_layer/block_ctx_unsafe.d.ts +0 -16
- package/dist/middle_layer/block_ctx_unsafe.d.ts.map +0 -1
- package/dist/middle_layer/driver_kit.d.ts.map +0 -1
- package/dist/middle_layer/frontend_path.d.ts +0 -6
- package/dist/middle_layer/frontend_path.d.ts.map +0 -1
- package/dist/middle_layer/index.d.ts.map +0 -1
- package/dist/middle_layer/middle_layer.d.ts.map +0 -1
- package/dist/middle_layer/navigation_states.d.ts +0 -10
- package/dist/middle_layer/navigation_states.d.ts.map +0 -1
- package/dist/middle_layer/ops.d.ts.map +0 -1
- package/dist/middle_layer/project.d.ts.map +0 -1
- package/dist/middle_layer/project_list.d.ts +0 -11
- package/dist/middle_layer/project_list.d.ts.map +0 -1
- package/dist/middle_layer/project_overview.d.ts +0 -8
- package/dist/middle_layer/project_overview.d.ts.map +0 -1
- package/dist/middle_layer/project_overview_light.d.ts +0 -8
- package/dist/middle_layer/project_overview_light.d.ts.map +0 -1
- package/dist/middle_layer/render.d.ts +0 -7
- package/dist/middle_layer/render.d.ts.map +0 -1
- package/dist/middle_layer/render.test.d.ts +0 -5
- package/dist/middle_layer/render.test.d.ts.map +0 -1
- package/dist/middle_layer/types.d.ts.map +0 -1
- package/dist/middle_layer/util.d.ts +0 -16
- package/dist/middle_layer/util.d.ts.map +0 -1
- package/dist/model/args.d.ts +0 -14
- package/dist/model/args.d.ts.map +0 -1
- package/dist/model/block_pack.d.ts +0 -8
- package/dist/model/block_pack.d.ts.map +0 -1
- package/dist/model/block_pack_spec.d.ts.map +0 -1
- package/dist/model/frontend.d.ts.map +0 -1
- package/dist/model/index.d.ts.map +0 -1
- package/dist/model/project_helper.d.ts.map +0 -1
- package/dist/model/project_model.d.ts.map +0 -1
- package/dist/model/project_model.test.d.ts +0 -2
- package/dist/model/project_model.test.d.ts.map +0 -1
- package/dist/model/project_model_util.d.ts +0 -43
- package/dist/model/project_model_util.d.ts.map +0 -1
- package/dist/model/project_model_util.test.d.ts +0 -2
- package/dist/model/project_model_util.test.d.ts.map +0 -1
- package/dist/model/project_model_v1.d.ts +0 -8
- package/dist/model/project_model_v1.d.ts.map +0 -1
- package/dist/model/template_spec.d.ts.map +0 -1
- package/dist/mutator/block-pack/block_pack.d.ts.map +0 -1
- package/dist/mutator/block-pack/block_pack.test.d.ts +0 -2
- package/dist/mutator/block-pack/block_pack.test.d.ts.map +0 -1
- package/dist/mutator/block-pack/frontend.d.ts +0 -4
- package/dist/mutator/block-pack/frontend.d.ts.map +0 -1
- package/dist/mutator/context_export.d.ts +0 -9
- package/dist/mutator/context_export.d.ts.map +0 -1
- package/dist/mutator/migration.d.ts +0 -9
- package/dist/mutator/migration.d.ts.map +0 -1
- package/dist/mutator/project-v3.test.d.ts +0 -2
- package/dist/mutator/project-v3.test.d.ts.map +0 -1
- package/dist/mutator/project.d.ts +0 -211
- package/dist/mutator/project.d.ts.map +0 -1
- package/dist/mutator/project.test.d.ts +0 -2
- package/dist/mutator/project.test.d.ts.map +0 -1
- package/dist/mutator/template/direct_template_loader.d.ts +0 -5
- package/dist/mutator/template/direct_template_loader.d.ts.map +0 -1
- package/dist/mutator/template/direct_template_loader_v3.d.ts +0 -15
- package/dist/mutator/template/direct_template_loader_v3.d.ts.map +0 -1
- package/dist/mutator/template/render_block.d.ts +0 -32
- package/dist/mutator/template/render_block.d.ts.map +0 -1
- package/dist/mutator/template/render_template.d.ts.map +0 -1
- package/dist/mutator/template/template_loading.d.ts.map +0 -1
- package/dist/mutator/template/template_render.test.d.ts +0 -2
- package/dist/mutator/template/template_render.test.d.ts.map +0 -1
- package/dist/network_check/network_check.d.ts.map +0 -1
- package/dist/network_check/network_check.test.d.ts +0 -2
- package/dist/network_check/network_check.test.d.ts.map +0 -1
- package/dist/network_check/pings.d.ts +0 -32
- package/dist/network_check/pings.d.ts.map +0 -1
- package/dist/network_check/template.d.ts +0 -57
- package/dist/network_check/template.d.ts.map +0 -1
- package/dist/network_check/template.test.d.ts +0 -2
- package/dist/network_check/template.test.d.ts.map +0 -1
- package/dist/network_check/test_utils.d.ts +0 -6
- package/dist/network_check/test_utils.d.ts.map +0 -1
- package/dist/pool/data.d.ts.map +0 -1
- package/dist/pool/driver.d.ts.map +0 -1
- package/dist/pool/index.d.ts.map +0 -1
- package/dist/pool/p_object_collection.d.ts.map +0 -1
- package/dist/pool/result_pool.d.ts.map +0 -1
- package/dist/test/block_packs.d.ts +0 -6
- package/dist/test/block_packs.d.ts.map +0 -1
- package/dist/test/explicit_templates.d.ts +0 -3
- package/dist/test/explicit_templates.d.ts.map +0 -1
- package/dist/test/known_templates.d.ts +0 -6
- package/dist/test/known_templates.d.ts.map +0 -1
- package/dist/test_env.d.ts +0 -6
- package/dist/test_env.d.ts.map +0 -1
- package/dist/worker/WorkerManager.d.ts +0 -12
- package/dist/worker/WorkerManager.d.ts.map +0 -1
- package/dist/worker/worker.d.ts.map +0 -1
- package/dist/worker/workerApi.d.ts +0 -15
- package/dist/worker/workerApi.d.ts.map +0 -1
package/dist/mutator/project.js
CHANGED
|
@@ -1,1249 +1,913 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createBContextFromUpstreams, createRenderHeavyBlock } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
1
|
+
import { BlockRenderingStateKey, FieldsToDuplicate, InitialBlockMeta, InitialBlockStructure, InitialProjectRenderingState, ProjectCreatedTimestamp, ProjectLastModifiedTimestamp, ProjectMetaKey, ProjectResourceType, ProjectStructureAuthorKey, ProjectStructureKey, SchemaVersionCurrent, SchemaVersionKey, blockArgsAuthorKey, getServiceTemplateField, parseProjectField, projectFieldName } from "../model/project_model.js";
|
|
2
|
+
import { createBContextFromUpstreams, createRenderHeavyBlock } from "./template/render_block.js";
|
|
3
|
+
import { loadTemplate } from "./template/template_loading.js";
|
|
4
|
+
import { BlockPackTemplateField, createBlockPack } from "./block-pack/block_pack.js";
|
|
5
|
+
import { allBlocks, graphDiff, productionGraph, stagingGraph } from "../model/project_model_util.js";
|
|
6
|
+
import { exportContext, getPreparedExportTemplateEnvelope } from "./context_export.js";
|
|
7
|
+
import { getDebugFlags } from "../debug/index.js";
|
|
8
|
+
import { BLOCK_STORAGE_FACADE_VERSION, UiError, extractConfig } from "@platforma-sdk/model";
|
|
9
|
+
import { InitialBlockSettings } from "@milaboratories/pl-model-middle-layer";
|
|
10
|
+
import { cachedDecode, cachedDeserialize, canonicalJsonBytes, notEmpty } from "@milaboratories/ts-helpers";
|
|
11
|
+
import { Pl, PlClient, ensureResourceIdNotNull, field, isNotNullResourceId, isNullResourceId, isResource, isResourceId, isResourceRef } from "@milaboratories/pl-client";
|
|
12
|
+
import Denque from "denque";
|
|
13
13
|
|
|
14
|
+
//#region src/mutator/project.ts
|
|
14
15
|
function cached(modIdCb, valueCb) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
class BlockInfo {
|
|
34
|
-
id;
|
|
35
|
-
fields;
|
|
36
|
-
config;
|
|
37
|
-
source;
|
|
38
|
-
constructor(id, fields, config, source) {
|
|
39
|
-
this.id = id;
|
|
40
|
-
this.fields = fields;
|
|
41
|
-
this.config = config;
|
|
42
|
-
this.source = source;
|
|
43
|
-
}
|
|
44
|
-
check() {
|
|
45
|
-
// state assertions
|
|
46
|
-
if ((this.fields.prodOutput === undefined) !== (this.fields.prodCtx === undefined))
|
|
47
|
-
throw new Error("inconsistent prod fields");
|
|
48
|
-
if ((this.fields.stagingOutput === undefined) !== (this.fields.stagingCtx === undefined))
|
|
49
|
-
throw new Error("inconsistent stage fields");
|
|
50
|
-
if ((this.fields.prodOutputPrevious === undefined) !==
|
|
51
|
-
(this.fields.prodCtxPrevious === undefined))
|
|
52
|
-
throw new Error("inconsistent prod cache fields");
|
|
53
|
-
if ((this.fields.stagingOutputPrevious === undefined) !==
|
|
54
|
-
(this.fields.stagingCtxPrevious === undefined))
|
|
55
|
-
throw new Error("inconsistent stage cache fields");
|
|
56
|
-
if (this.fields.blockPack === undefined)
|
|
57
|
-
throw new Error("no block pack field");
|
|
58
|
-
if (this.fields.blockStorage === undefined)
|
|
59
|
-
throw new Error("no block storage field");
|
|
60
|
-
}
|
|
61
|
-
currentArgsC = cached(() => this.fields.currentArgs?.modCount, () => {
|
|
62
|
-
const bin = this.fields.currentArgs?.value;
|
|
63
|
-
if (bin === undefined)
|
|
64
|
-
return undefined;
|
|
65
|
-
return cachedDeserialize(bin);
|
|
66
|
-
});
|
|
67
|
-
blockStorageC = cached(() => this.fields.blockStorage.modCount, () => {
|
|
68
|
-
const bin = this.fields.blockStorage?.value;
|
|
69
|
-
if (bin === undefined)
|
|
70
|
-
return undefined;
|
|
71
|
-
return cachedDeserialize(bin);
|
|
72
|
-
});
|
|
73
|
-
blockStorageJ = cached(() => this.fields.blockStorage.modCount, () => {
|
|
74
|
-
const bin = this.fields.blockStorage?.value;
|
|
75
|
-
if (bin === undefined)
|
|
76
|
-
return undefined;
|
|
77
|
-
return cachedDecode(bin);
|
|
78
|
-
});
|
|
79
|
-
prodArgsC = cached(() => this.fields.prodArgs?.modCount, () => {
|
|
80
|
-
const bin = this.fields.prodArgs?.value;
|
|
81
|
-
if (bin === undefined)
|
|
82
|
-
return undefined;
|
|
83
|
-
return cachedDeserialize(bin);
|
|
84
|
-
});
|
|
85
|
-
currentPrerunArgsC = cached(() => this.fields.currentPrerunArgs?.modCount, () => {
|
|
86
|
-
const bin = this.fields.currentPrerunArgs?.value;
|
|
87
|
-
if (bin === undefined)
|
|
88
|
-
return undefined;
|
|
89
|
-
return cachedDeserialize(bin);
|
|
90
|
-
});
|
|
91
|
-
get currentArgs() {
|
|
92
|
-
return this.currentArgsC();
|
|
93
|
-
}
|
|
94
|
-
get blockStorage() {
|
|
95
|
-
try {
|
|
96
|
-
return this.blockStorageC();
|
|
97
|
-
}
|
|
98
|
-
catch (e) {
|
|
99
|
-
console.error("Error getting blockStorage:", e);
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
get blockStorageJson() {
|
|
104
|
-
return this.blockStorageJ();
|
|
105
|
-
}
|
|
106
|
-
get currentPrerunArgs() {
|
|
107
|
-
return this.currentPrerunArgsC();
|
|
108
|
-
}
|
|
109
|
-
get stagingRendered() {
|
|
110
|
-
return this.fields.stagingCtx !== undefined;
|
|
111
|
-
}
|
|
112
|
-
get productionRendered() {
|
|
113
|
-
return this.fields.prodCtx !== undefined;
|
|
114
|
-
}
|
|
115
|
-
get productionHasErrors() {
|
|
116
|
-
return this.fields.prodUiCtx?.status === "Error";
|
|
117
|
-
}
|
|
118
|
-
productionStaleC = cached(() => `${this.fields.currentArgs.modCount}_${this.fields.prodArgs?.modCount}`, () => this.fields.prodArgs === undefined ||
|
|
119
|
-
Buffer.compare(this.fields.currentArgs.value, this.fields.prodArgs.value) !== 0);
|
|
120
|
-
get requireProductionRendering() {
|
|
121
|
-
return !this.productionRendered || this.productionStaleC() || this.productionHasErrors;
|
|
122
|
-
}
|
|
123
|
-
/** Returns true if staging should be re-rendered (stagingCtx is not set) */
|
|
124
|
-
get requireStagingRendering() {
|
|
125
|
-
// No staging needed if currentPrerunArgs is undefined (args derivation failed)
|
|
126
|
-
if (this.fields.currentPrerunArgs === undefined)
|
|
127
|
-
return false;
|
|
128
|
-
return !this.stagingRendered;
|
|
129
|
-
}
|
|
130
|
-
get prodArgs() {
|
|
131
|
-
return this.prodArgsC();
|
|
132
|
-
}
|
|
133
|
-
getTemplate(tx) {
|
|
134
|
-
return tx.getFutureFieldValue(Pl.unwrapHolder(tx, this.fields.blockPack.ref), BlockPackTemplateField, "Input");
|
|
135
|
-
}
|
|
16
|
+
let initialized = false;
|
|
17
|
+
let lastModId = void 0;
|
|
18
|
+
let value = void 0;
|
|
19
|
+
return () => {
|
|
20
|
+
if (!initialized) {
|
|
21
|
+
initialized = true;
|
|
22
|
+
lastModId = modIdCb();
|
|
23
|
+
value = valueCb();
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
const currentModId = modIdCb();
|
|
27
|
+
if (lastModId !== currentModId) {
|
|
28
|
+
lastModId = currentModId;
|
|
29
|
+
value = valueCb();
|
|
30
|
+
}
|
|
31
|
+
return valueCb();
|
|
32
|
+
};
|
|
136
33
|
}
|
|
34
|
+
var BlockInfo = class {
|
|
35
|
+
constructor(id, fields, config, source) {
|
|
36
|
+
this.id = id;
|
|
37
|
+
this.fields = fields;
|
|
38
|
+
this.config = config;
|
|
39
|
+
this.source = source;
|
|
40
|
+
}
|
|
41
|
+
check() {
|
|
42
|
+
if (this.fields.prodOutput === void 0 !== (this.fields.prodCtx === void 0)) throw new Error("inconsistent prod fields");
|
|
43
|
+
if (this.fields.stagingOutput === void 0 !== (this.fields.stagingCtx === void 0)) throw new Error("inconsistent stage fields");
|
|
44
|
+
if (this.fields.prodOutputPrevious === void 0 !== (this.fields.prodCtxPrevious === void 0)) throw new Error("inconsistent prod cache fields");
|
|
45
|
+
if (this.fields.stagingOutputPrevious === void 0 !== (this.fields.stagingCtxPrevious === void 0)) throw new Error("inconsistent stage cache fields");
|
|
46
|
+
if (this.fields.blockPack === void 0) throw new Error("no block pack field");
|
|
47
|
+
if (this.fields.blockStorage === void 0) throw new Error("no block storage field");
|
|
48
|
+
}
|
|
49
|
+
currentArgsC = cached(() => this.fields.currentArgs?.modCount, () => {
|
|
50
|
+
const bin = this.fields.currentArgs?.value;
|
|
51
|
+
if (bin === void 0) return void 0;
|
|
52
|
+
return cachedDeserialize(bin);
|
|
53
|
+
});
|
|
54
|
+
blockStorageC = cached(() => this.fields.blockStorage.modCount, () => {
|
|
55
|
+
const bin = this.fields.blockStorage?.value;
|
|
56
|
+
if (bin === void 0) return void 0;
|
|
57
|
+
return cachedDeserialize(bin);
|
|
58
|
+
});
|
|
59
|
+
blockStorageJ = cached(() => this.fields.blockStorage.modCount, () => {
|
|
60
|
+
const bin = this.fields.blockStorage?.value;
|
|
61
|
+
if (bin === void 0) return void 0;
|
|
62
|
+
return cachedDecode(bin);
|
|
63
|
+
});
|
|
64
|
+
prodArgsC = cached(() => this.fields.prodArgs?.modCount, () => {
|
|
65
|
+
const bin = this.fields.prodArgs?.value;
|
|
66
|
+
if (bin === void 0) return void 0;
|
|
67
|
+
return cachedDeserialize(bin);
|
|
68
|
+
});
|
|
69
|
+
currentPrerunArgsC = cached(() => this.fields.currentPrerunArgs?.modCount, () => {
|
|
70
|
+
const bin = this.fields.currentPrerunArgs?.value;
|
|
71
|
+
if (bin === void 0) return void 0;
|
|
72
|
+
return cachedDeserialize(bin);
|
|
73
|
+
});
|
|
74
|
+
get currentArgs() {
|
|
75
|
+
return this.currentArgsC();
|
|
76
|
+
}
|
|
77
|
+
get blockStorage() {
|
|
78
|
+
try {
|
|
79
|
+
return this.blockStorageC();
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error("Error getting blockStorage:", e);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
get blockStorageJson() {
|
|
86
|
+
return this.blockStorageJ();
|
|
87
|
+
}
|
|
88
|
+
get currentPrerunArgs() {
|
|
89
|
+
return this.currentPrerunArgsC();
|
|
90
|
+
}
|
|
91
|
+
get stagingRendered() {
|
|
92
|
+
return this.fields.stagingCtx !== void 0;
|
|
93
|
+
}
|
|
94
|
+
get productionRendered() {
|
|
95
|
+
return this.fields.prodCtx !== void 0;
|
|
96
|
+
}
|
|
97
|
+
get productionHasErrors() {
|
|
98
|
+
return this.fields.prodUiCtx?.status === "Error";
|
|
99
|
+
}
|
|
100
|
+
productionStaleC = cached(() => `${this.fields.currentArgs.modCount}_${this.fields.prodArgs?.modCount}`, () => this.fields.prodArgs === void 0 || Buffer.compare(this.fields.currentArgs.value, this.fields.prodArgs.value) !== 0);
|
|
101
|
+
get requireProductionRendering() {
|
|
102
|
+
return !this.productionRendered || this.productionStaleC() || this.productionHasErrors;
|
|
103
|
+
}
|
|
104
|
+
/** Returns true if staging should be re-rendered (stagingCtx is not set) */
|
|
105
|
+
get requireStagingRendering() {
|
|
106
|
+
if (this.fields.currentPrerunArgs === void 0) return false;
|
|
107
|
+
return !this.stagingRendered;
|
|
108
|
+
}
|
|
109
|
+
get prodArgs() {
|
|
110
|
+
return this.prodArgsC();
|
|
111
|
+
}
|
|
112
|
+
getTemplate(tx) {
|
|
113
|
+
return tx.getFutureFieldValue(Pl.unwrapHolder(tx, this.fields.blockPack.ref), BlockPackTemplateField, "Input");
|
|
114
|
+
}
|
|
115
|
+
};
|
|
137
116
|
const NoNewBlocks = (blockId) => {
|
|
138
|
-
|
|
117
|
+
throw new Error(`No new block info for ${blockId}`);
|
|
118
|
+
};
|
|
119
|
+
var ProjectMutator = class ProjectMutator {
|
|
120
|
+
globalModCount = 0;
|
|
121
|
+
fieldsChanged = false;
|
|
122
|
+
lastModifiedChanged = false;
|
|
123
|
+
structureChanged = false;
|
|
124
|
+
metaChanged = false;
|
|
125
|
+
renderingStateChanged = false;
|
|
126
|
+
/** Set blocks will be assigned current mutator author marker on save */
|
|
127
|
+
blocksWithChangedInputs = /* @__PURE__ */ new Set();
|
|
128
|
+
constructor(rid, tx, author, schema, lastModified, meta, struct, renderingState, blocksInLimbo, blockInfos, ctxExportTplHolder, projectHelper) {
|
|
129
|
+
this.rid = rid;
|
|
130
|
+
this.tx = tx;
|
|
131
|
+
this.author = author;
|
|
132
|
+
this.schema = schema;
|
|
133
|
+
this.lastModified = lastModified;
|
|
134
|
+
this.meta = meta;
|
|
135
|
+
this.struct = struct;
|
|
136
|
+
this.renderingState = renderingState;
|
|
137
|
+
this.blocksInLimbo = blocksInLimbo;
|
|
138
|
+
this.blockInfos = blockInfos;
|
|
139
|
+
this.ctxExportTplHolder = ctxExportTplHolder;
|
|
140
|
+
this.projectHelper = projectHelper;
|
|
141
|
+
}
|
|
142
|
+
fixProblemsAndMigrate() {
|
|
143
|
+
this.blockInfos.forEach((blockInfo) => {
|
|
144
|
+
if (blockInfo.fields.prodArgs === void 0 || blockInfo.fields.prodOutput === void 0 || blockInfo.fields.prodCtx === void 0) this.deleteBlockFields(blockInfo.id, "prodArgs", "prodOutput", "prodCtx");
|
|
145
|
+
});
|
|
146
|
+
let initialBlockSettings;
|
|
147
|
+
this.blockInfos.forEach((blockInfo) => {
|
|
148
|
+
if (blockInfo.fields.blockSettings === void 0) {
|
|
149
|
+
if (initialBlockSettings === void 0) initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);
|
|
150
|
+
this.setBlockFieldObj(blockInfo.id, "blockSettings", initialBlockSettings);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
get wasModified() {
|
|
155
|
+
return this.lastModifiedChanged || this.structureChanged || this.fieldsChanged || this.metaChanged || this.renderingStateChanged;
|
|
156
|
+
}
|
|
157
|
+
get structure() {
|
|
158
|
+
return JSON.parse(JSON.stringify(this.struct));
|
|
159
|
+
}
|
|
160
|
+
stagingGraph = void 0;
|
|
161
|
+
pendingProductionGraph = void 0;
|
|
162
|
+
actualProductionGraph = void 0;
|
|
163
|
+
getStagingGraph() {
|
|
164
|
+
if (this.stagingGraph === void 0) this.stagingGraph = stagingGraph(this.struct);
|
|
165
|
+
return this.stagingGraph;
|
|
166
|
+
}
|
|
167
|
+
getProductionGraphBlockInfo(blockId, prod) {
|
|
168
|
+
const bInfo = this.getBlockInfo(blockId);
|
|
169
|
+
let argsField;
|
|
170
|
+
let args;
|
|
171
|
+
if (prod) {
|
|
172
|
+
if (bInfo.fields.prodArgs === void 0) return void 0;
|
|
173
|
+
argsField = bInfo.fields.prodArgs;
|
|
174
|
+
args = bInfo.prodArgs;
|
|
175
|
+
} else {
|
|
176
|
+
argsField = bInfo.fields.currentArgs;
|
|
177
|
+
args = bInfo.currentArgs;
|
|
178
|
+
}
|
|
179
|
+
if (argsField === void 0) return {
|
|
180
|
+
args,
|
|
181
|
+
enrichmentTargets: void 0
|
|
182
|
+
};
|
|
183
|
+
const blockPackField = notEmpty(bInfo.fields.blockPack);
|
|
184
|
+
if (isResourceId(argsField.ref) && isResourceId(blockPackField.ref)) return {
|
|
185
|
+
args,
|
|
186
|
+
enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args, {
|
|
187
|
+
argsRid: argsField.ref,
|
|
188
|
+
blockPackRid: blockPackField.ref
|
|
189
|
+
})
|
|
190
|
+
};
|
|
191
|
+
else return {
|
|
192
|
+
args,
|
|
193
|
+
enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
getPendingProductionGraph() {
|
|
197
|
+
if (this.pendingProductionGraph === void 0) this.pendingProductionGraph = productionGraph(this.struct, (blockId) => this.getProductionGraphBlockInfo(blockId, false));
|
|
198
|
+
return this.pendingProductionGraph;
|
|
199
|
+
}
|
|
200
|
+
getActualProductionGraph() {
|
|
201
|
+
if (this.actualProductionGraph === void 0) this.actualProductionGraph = productionGraph(this.struct, (blockId) => this.getProductionGraphBlockInfo(blockId, true));
|
|
202
|
+
return this.actualProductionGraph;
|
|
203
|
+
}
|
|
204
|
+
getBlockInfo(blockId) {
|
|
205
|
+
const info = this.blockInfos.get(blockId);
|
|
206
|
+
if (info === void 0) throw new Error(`No such block: ${blockId}`);
|
|
207
|
+
return info;
|
|
208
|
+
}
|
|
209
|
+
createJsonFieldValueByContent(content) {
|
|
210
|
+
if (content === void 0) throw new Error("content is undefined");
|
|
211
|
+
const value = Buffer.from(content);
|
|
212
|
+
return {
|
|
213
|
+
ref: this.tx.createValue(Pl.JsonObject, value),
|
|
214
|
+
value,
|
|
215
|
+
status: "Ready"
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
createJsonFieldValue(obj) {
|
|
219
|
+
return this.createJsonFieldValueByContent(JSON.stringify(obj));
|
|
220
|
+
}
|
|
221
|
+
getBlock(blockId) {
|
|
222
|
+
for (const block of allBlocks(this.struct)) if (block.id === blockId) return block;
|
|
223
|
+
throw new Error("block not found");
|
|
224
|
+
}
|
|
225
|
+
setBlockFieldObj(blockId, fieldName, state) {
|
|
226
|
+
const fid = field(this.rid, projectFieldName(blockId, fieldName));
|
|
227
|
+
if (state.ref === void 0) throw new Error("Can't set value with empty ref");
|
|
228
|
+
if (this.getBlockInfo(blockId).fields[fieldName] === void 0) this.tx.createField(fid, "Dynamic", state.ref);
|
|
229
|
+
else this.tx.setField(fid, state.ref);
|
|
230
|
+
this.getBlockInfo(blockId).fields[fieldName] = {
|
|
231
|
+
modCount: this.globalModCount++,
|
|
232
|
+
...state
|
|
233
|
+
};
|
|
234
|
+
this.fieldsChanged = true;
|
|
235
|
+
}
|
|
236
|
+
setBlockField(blockId, fieldName, ref, status, value) {
|
|
237
|
+
this.setBlockFieldObj(blockId, fieldName, {
|
|
238
|
+
ref,
|
|
239
|
+
status,
|
|
240
|
+
value
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
deleteBlockFields(blockId, ...fieldNames) {
|
|
244
|
+
let deleted = false;
|
|
245
|
+
const info = this.getBlockInfo(blockId);
|
|
246
|
+
for (const fieldName of fieldNames) {
|
|
247
|
+
const fields = info.fields;
|
|
248
|
+
if (!(fieldName in fields)) continue;
|
|
249
|
+
this.tx.removeField(field(this.rid, projectFieldName(blockId, fieldName)));
|
|
250
|
+
delete fields[fieldName];
|
|
251
|
+
this.fieldsChanged = true;
|
|
252
|
+
deleted = true;
|
|
253
|
+
}
|
|
254
|
+
return deleted;
|
|
255
|
+
}
|
|
256
|
+
updateLastModified() {
|
|
257
|
+
this.lastModified = Date.now();
|
|
258
|
+
this.lastModifiedChanged = true;
|
|
259
|
+
}
|
|
260
|
+
resetStagingRefreshTimestamp() {
|
|
261
|
+
this.renderingState.stagingRefreshTimestamp = Date.now();
|
|
262
|
+
this.renderingStateChanged = true;
|
|
263
|
+
}
|
|
264
|
+
resetStaging(blockId) {
|
|
265
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
266
|
+
if (fields.stagingOutput?.status === "Ready" && fields.stagingCtx?.status === "Ready" && fields.stagingUiCtx?.status === "Ready") {
|
|
267
|
+
this.setBlockFieldObj(blockId, "stagingOutputPrevious", fields.stagingOutput);
|
|
268
|
+
this.setBlockFieldObj(blockId, "stagingCtxPrevious", fields.stagingCtx);
|
|
269
|
+
this.setBlockFieldObj(blockId, "stagingUiCtxPrevious", fields.stagingUiCtx);
|
|
270
|
+
}
|
|
271
|
+
if (this.deleteBlockFields(blockId, "stagingOutput", "stagingCtx", "stagingUiCtx")) this.resetStagingRefreshTimestamp();
|
|
272
|
+
}
|
|
273
|
+
resetProduction(blockId) {
|
|
274
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
275
|
+
if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready" && fields.prodUiCtx?.status === "Ready") {
|
|
276
|
+
this.setBlockFieldObj(blockId, "prodOutputPrevious", fields.prodOutput);
|
|
277
|
+
this.setBlockFieldObj(blockId, "prodCtxPrevious", fields.prodCtx);
|
|
278
|
+
this.setBlockFieldObj(blockId, "prodUiCtxPrevious", fields.prodUiCtx);
|
|
279
|
+
}
|
|
280
|
+
this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs");
|
|
281
|
+
}
|
|
282
|
+
/** Running blocks are reset, already computed moved to limbo. Returns if
|
|
283
|
+
* either of the actions were actually performed.
|
|
284
|
+
* This method ensures the block is left in a consistent state that passes check() constraints. */
|
|
285
|
+
resetOrLimboProduction(blockId) {
|
|
286
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
287
|
+
if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready") {
|
|
288
|
+
if (this.blocksInLimbo.has(blockId)) return false;
|
|
289
|
+
this.blocksInLimbo.add(blockId);
|
|
290
|
+
this.renderingStateChanged = true;
|
|
291
|
+
this.deleteBlockFields(blockId, "prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious");
|
|
292
|
+
return true;
|
|
293
|
+
} else return this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs", "prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious");
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Gets current block state and merges with partial updates.
|
|
297
|
+
* Used by legacy v1/v2 methods like setBlockArgs and setUiState.
|
|
298
|
+
*
|
|
299
|
+
* @param blockId The block to get state for
|
|
300
|
+
* @param partialUpdate Partial state to merge (e.g. { args } or { uiState })
|
|
301
|
+
* @returns Merged state in unified format { args, uiState }
|
|
302
|
+
*/
|
|
303
|
+
mergeBlockState(blockId, partialUpdate) {
|
|
304
|
+
return {
|
|
305
|
+
...this.getBlockInfo(blockId).blockStorage,
|
|
306
|
+
...partialUpdate
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Sets raw block storage content directly (for testing purposes).
|
|
311
|
+
* This bypasses all normalization and VM transformations.
|
|
312
|
+
*
|
|
313
|
+
* @param blockId The block to set storage for
|
|
314
|
+
* @param rawStorageJson Raw storage as JSON string
|
|
315
|
+
*/
|
|
316
|
+
setBlockStorageRaw(blockId, rawStorageJson) {
|
|
317
|
+
this.setBlockFieldObj(blockId, "blockStorage", this.createJsonFieldValueByContent(rawStorageJson));
|
|
318
|
+
this.blocksWithChangedInputs.add(blockId);
|
|
319
|
+
this.updateLastModified();
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Resets a v2+ block to its initial storage state.
|
|
323
|
+
* Gets initial storage from VM and derives args from it.
|
|
324
|
+
*
|
|
325
|
+
* For v1 blocks, use setStates() instead.
|
|
326
|
+
*
|
|
327
|
+
* @param blockId The block to reset
|
|
328
|
+
*/
|
|
329
|
+
resetToInitialStorage(blockId) {
|
|
330
|
+
const blockConfig = this.getBlockInfo(blockId).config;
|
|
331
|
+
if (blockConfig.modelAPIVersion !== BLOCK_STORAGE_FACADE_VERSION) throw new Error("resetToInitialStorage is only supported for model API version 2");
|
|
332
|
+
const initialStorageJson = this.projectHelper.getInitialStorageInVM(blockConfig);
|
|
333
|
+
this.setBlockStorageRaw(blockId, initialStorageJson);
|
|
334
|
+
const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, initialStorageJson);
|
|
335
|
+
if (!deriveArgsResult.error) {
|
|
336
|
+
this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(deriveArgsResult.value));
|
|
337
|
+
const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, initialStorageJson);
|
|
338
|
+
if (prerunArgs !== void 0) this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
|
|
339
|
+
} else this.deleteBlockFields(blockId, "currentArgs");
|
|
340
|
+
}
|
|
341
|
+
/** Optimally sets inputs for multiple blocks in one go */
|
|
342
|
+
setStates(requests) {
|
|
343
|
+
const changedArgs = [];
|
|
344
|
+
let somethingChanged = false;
|
|
345
|
+
for (const req of requests) {
|
|
346
|
+
const info = this.getBlockInfo(req.blockId);
|
|
347
|
+
let blockChanged = false;
|
|
348
|
+
const blockConfig = info.config;
|
|
349
|
+
if (req.modelAPIVersion !== blockConfig.modelAPIVersion) throw new Error(`Model API version mismatch for block ${req.blockId}: ${req.modelAPIVersion} !== ${blockConfig.modelAPIVersion}`);
|
|
350
|
+
let args;
|
|
351
|
+
let prerunArgs;
|
|
352
|
+
if (req.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION) {
|
|
353
|
+
const currentStorageJson = info.blockStorageJson;
|
|
354
|
+
if (currentStorageJson === void 0) throw new Error(`Block ${req.blockId} has no blockStorage - this should not happen`);
|
|
355
|
+
const updatedStorageJson = this.projectHelper.applyStorageUpdateInVM(blockConfig, currentStorageJson, req.payload);
|
|
356
|
+
this.setBlockFieldObj(req.blockId, "blockStorage", this.createJsonFieldValueByContent(updatedStorageJson));
|
|
357
|
+
const derivedArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, updatedStorageJson);
|
|
358
|
+
if (derivedArgsResult.error) {
|
|
359
|
+
args = void 0;
|
|
360
|
+
prerunArgs = void 0;
|
|
361
|
+
} else {
|
|
362
|
+
args = derivedArgsResult.value;
|
|
363
|
+
prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, updatedStorageJson);
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
this.setBlockFieldObj(req.blockId, "blockStorage", this.createJsonFieldValue(req.state));
|
|
367
|
+
if (req.state !== null && typeof req.state === "object" && "args" in req.state) args = req.state.args;
|
|
368
|
+
else args = req.state;
|
|
369
|
+
prerunArgs = args;
|
|
370
|
+
}
|
|
371
|
+
if (args !== void 0) {
|
|
372
|
+
const currentArgsData = canonicalJsonBytes(args);
|
|
373
|
+
const argsPartRef = this.tx.createValue(Pl.JsonObject, currentArgsData);
|
|
374
|
+
this.setBlockField(req.blockId, "currentArgs", argsPartRef, "Ready", currentArgsData);
|
|
375
|
+
} else this.deleteBlockFields(req.blockId, "currentArgs");
|
|
376
|
+
let prerunArgsChanged = false;
|
|
377
|
+
if (prerunArgs !== void 0) {
|
|
378
|
+
const prerunArgsData = canonicalJsonBytes(prerunArgs);
|
|
379
|
+
const oldPrerunArgsData = info.fields.currentPrerunArgs?.value;
|
|
380
|
+
if (oldPrerunArgsData === void 0 || Buffer.compare(oldPrerunArgsData, prerunArgsData) !== 0) prerunArgsChanged = true;
|
|
381
|
+
const prerunArgsRef = this.tx.createValue(Pl.JsonObject, prerunArgsData);
|
|
382
|
+
this.setBlockField(req.blockId, "currentPrerunArgs", prerunArgsRef, "Ready", prerunArgsData);
|
|
383
|
+
} else if (info.fields.currentPrerunArgs !== void 0) prerunArgsChanged = true;
|
|
384
|
+
blockChanged = true;
|
|
385
|
+
if (prerunArgsChanged) changedArgs.push(req.blockId);
|
|
386
|
+
if (blockChanged) {
|
|
387
|
+
this.blocksWithChangedInputs.add(req.blockId);
|
|
388
|
+
somethingChanged = true;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
this.getStagingGraph().traverse("downstream", changedArgs, ({ id }) => this.resetStaging(id));
|
|
392
|
+
if (somethingChanged) this.updateLastModified();
|
|
393
|
+
}
|
|
394
|
+
setBlockSettings(blockId, newValue) {
|
|
395
|
+
this.setBlockFieldObj(blockId, "blockSettings", this.createJsonFieldValue(newValue));
|
|
396
|
+
this.updateLastModified();
|
|
397
|
+
}
|
|
398
|
+
createProdCtx(upstream) {
|
|
399
|
+
const upstreamContexts = [];
|
|
400
|
+
upstream.forEach((id) => {
|
|
401
|
+
const info = this.getBlockInfo(id);
|
|
402
|
+
if (info.fields["prodCtx"]?.ref === void 0) throw new Error("One of the upstreams staging is not rendered.");
|
|
403
|
+
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["prodCtx"].ref));
|
|
404
|
+
});
|
|
405
|
+
return createBContextFromUpstreams(this.tx, upstreamContexts);
|
|
406
|
+
}
|
|
407
|
+
createStagingCtx(upstream) {
|
|
408
|
+
const upstreamContexts = [];
|
|
409
|
+
upstream.forEach((id) => {
|
|
410
|
+
const info = this.getBlockInfo(id);
|
|
411
|
+
if (info.fields["stagingCtx"]?.ref === void 0) throw new Error("One of the upstreams staging is not rendered.");
|
|
412
|
+
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["stagingCtx"].ref));
|
|
413
|
+
if (info.fields["prodCtx"]?.ref !== void 0) upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["prodCtx"].ref));
|
|
414
|
+
});
|
|
415
|
+
return createBContextFromUpstreams(this.tx, upstreamContexts);
|
|
416
|
+
}
|
|
417
|
+
exportCtx(ctx) {
|
|
418
|
+
return exportContext(this.tx, Pl.unwrapHolder(this.tx, this.ctxExportTplHolder), ctx);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Renders staging for a block using currentPrerunArgs.
|
|
422
|
+
* If currentPrerunArgs is not set (prerunArgs returned undefined), skips staging for this block.
|
|
423
|
+
*/
|
|
424
|
+
renderStagingFor(blockId) {
|
|
425
|
+
this.resetStaging(blockId);
|
|
426
|
+
const info = this.getBlockInfo(blockId);
|
|
427
|
+
const prerunArgsRef = info.fields.currentPrerunArgs?.ref;
|
|
428
|
+
if (prerunArgsRef === void 0) return;
|
|
429
|
+
const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId).upstream);
|
|
430
|
+
if (this.getBlock(blockId).renderingMode !== "Heavy") throw new Error("not supported yet");
|
|
431
|
+
const tpl = info.getTemplate(this.tx);
|
|
432
|
+
const results = createRenderHeavyBlock(this.tx, tpl, {
|
|
433
|
+
args: prerunArgsRef,
|
|
434
|
+
blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),
|
|
435
|
+
isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),
|
|
436
|
+
context: ctx
|
|
437
|
+
});
|
|
438
|
+
this.setBlockField(blockId, "stagingCtx", Pl.wrapInEphHolder(this.tx, ctx), "NotReady");
|
|
439
|
+
this.setBlockField(blockId, "stagingUiCtx", this.exportCtx(results.context), "NotReady");
|
|
440
|
+
this.setBlockField(blockId, "stagingOutput", results.result, "NotReady");
|
|
441
|
+
}
|
|
442
|
+
renderProductionFor(blockId) {
|
|
443
|
+
this.resetProduction(blockId);
|
|
444
|
+
const info = this.getBlockInfo(blockId);
|
|
445
|
+
if (info.fields.currentArgs === void 0) throw new Error(`Can't render production for block ${blockId}: currentArgs not set`);
|
|
446
|
+
const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId).upstream);
|
|
447
|
+
if (this.getBlock(blockId).renderingMode === "Light") throw new Error("Can't render production for light block.");
|
|
448
|
+
const tpl = info.getTemplate(this.tx);
|
|
449
|
+
const results = createRenderHeavyBlock(this.tx, tpl, {
|
|
450
|
+
args: info.fields.currentArgs.ref,
|
|
451
|
+
blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),
|
|
452
|
+
isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(true)),
|
|
453
|
+
context: ctx
|
|
454
|
+
});
|
|
455
|
+
this.setBlockField(blockId, "prodCtx", Pl.wrapInEphHolder(this.tx, results.context), "NotReady");
|
|
456
|
+
this.setBlockField(blockId, "prodUiCtx", this.exportCtx(results.context), "NotReady");
|
|
457
|
+
this.setBlockField(blockId, "prodOutput", results.result, "NotReady");
|
|
458
|
+
this.setBlockFieldObj(blockId, "prodArgs", info.fields.currentArgs);
|
|
459
|
+
if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;
|
|
460
|
+
}
|
|
461
|
+
initializeNewBlock(blockId, spec) {
|
|
462
|
+
const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);
|
|
463
|
+
this.blockInfos.set(blockId, info);
|
|
464
|
+
const bp = createBlockPack(this.tx, spec.blockPack);
|
|
465
|
+
this.setBlockField(blockId, "blockPack", Pl.wrapInHolder(this.tx, bp), "NotReady");
|
|
466
|
+
this.setBlockFieldObj(blockId, "blockSettings", this.createJsonFieldValue(InitialBlockSettings));
|
|
467
|
+
const blockConfig = info.config;
|
|
468
|
+
let args;
|
|
469
|
+
let prerunArgs;
|
|
470
|
+
let storageToWrite;
|
|
471
|
+
if (spec.storageMode === "fromModel") {
|
|
472
|
+
storageToWrite = this.projectHelper.getInitialStorageInVM(blockConfig);
|
|
473
|
+
const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, storageToWrite);
|
|
474
|
+
if (deriveArgsResult.error) {
|
|
475
|
+
args = void 0;
|
|
476
|
+
prerunArgs = void 0;
|
|
477
|
+
} else {
|
|
478
|
+
args = deriveArgsResult.value;
|
|
479
|
+
prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, storageToWrite);
|
|
480
|
+
}
|
|
481
|
+
} else if (spec.storageMode === "legacy") {
|
|
482
|
+
args = JSON.parse(spec.legacyState).args;
|
|
483
|
+
if (args === void 0) throw new Error("args is undefined in legacyState");
|
|
484
|
+
prerunArgs = args;
|
|
485
|
+
storageToWrite = spec.legacyState;
|
|
486
|
+
} else throw new Error(`Unknown storageMode: ${spec.storageMode}`);
|
|
487
|
+
if (args !== void 0) this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(args));
|
|
488
|
+
if (prerunArgs !== void 0) this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
|
|
489
|
+
this.setBlockFieldObj(blockId, "blockStorage", this.createJsonFieldValueByContent(storageToWrite));
|
|
490
|
+
info.check();
|
|
491
|
+
}
|
|
492
|
+
getFieldNamesToDuplicate(blockId) {
|
|
493
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
494
|
+
const diff = (setA, setB) => new Set([...setA].filter((x) => !setB.has(x)));
|
|
495
|
+
if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready") {
|
|
496
|
+
if (this.blocksInLimbo.has(blockId)) return FieldsToDuplicate;
|
|
497
|
+
return diff(FieldsToDuplicate, new Set([
|
|
498
|
+
"prodOutputPrevious",
|
|
499
|
+
"prodCtxPrevious",
|
|
500
|
+
"prodUiCtxPrevious"
|
|
501
|
+
]));
|
|
502
|
+
} else return diff(FieldsToDuplicate, new Set([
|
|
503
|
+
"prodOutput",
|
|
504
|
+
"prodCtx",
|
|
505
|
+
"prodUiCtx",
|
|
506
|
+
"prodArgs",
|
|
507
|
+
"prodOutputPrevious",
|
|
508
|
+
"prodCtxPrevious",
|
|
509
|
+
"prodUiCtxPrevious"
|
|
510
|
+
]));
|
|
511
|
+
}
|
|
512
|
+
initializeBlockDuplicate(blockId, originalBlockInfo) {
|
|
513
|
+
const info = new BlockInfo(blockId, {}, originalBlockInfo.config, originalBlockInfo.source);
|
|
514
|
+
this.blockInfos.set(blockId, info);
|
|
515
|
+
const fieldNamesToDuplicate = this.getFieldNamesToDuplicate(blockId);
|
|
516
|
+
for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) if (fieldNamesToDuplicate.has(fieldName) && fieldState && fieldState.ref) this.setBlockFieldObj(blockId, fieldName, {
|
|
517
|
+
ref: fieldState.ref,
|
|
518
|
+
status: fieldState.status,
|
|
519
|
+
value: fieldState.value
|
|
520
|
+
});
|
|
521
|
+
this.resetOrLimboProduction(blockId);
|
|
522
|
+
info.check();
|
|
523
|
+
}
|
|
524
|
+
/** Very generic method, better check for more specialized case-specific methods first. */
|
|
525
|
+
updateStructure(newStructure, newBlockInitializer = NoNewBlocks) {
|
|
526
|
+
const currentStagingGraph = this.getStagingGraph();
|
|
527
|
+
const currentActualProductionGraph = this.getActualProductionGraph();
|
|
528
|
+
const stagingDiff = graphDiff(currentStagingGraph, stagingGraph(newStructure));
|
|
529
|
+
for (const blockId of stagingDiff.onlyInA) {
|
|
530
|
+
const { fields } = this.getBlockInfo(blockId);
|
|
531
|
+
this.deleteBlockFields(blockId, ...Object.keys(fields));
|
|
532
|
+
this.blockInfos.delete(blockId);
|
|
533
|
+
if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;
|
|
534
|
+
}
|
|
535
|
+
for (const blockId of stagingDiff.onlyInB) newBlockInitializer(blockId);
|
|
536
|
+
for (const blockId of stagingDiff.different) this.resetStaging(blockId);
|
|
537
|
+
const prodDiff = graphDiff(currentActualProductionGraph, productionGraph(newStructure, (blockId) => this.getProductionGraphBlockInfo(blockId, true)));
|
|
538
|
+
currentActualProductionGraph.traverse("downstream", [...prodDiff.different], (node) => {
|
|
539
|
+
this.resetOrLimboProduction(node.id);
|
|
540
|
+
});
|
|
541
|
+
if (stagingDiff.onlyInB.size > 0 || stagingDiff.onlyInA.size > 0 || stagingDiff.different.size > 0) this.resetStagingRefreshTimestamp();
|
|
542
|
+
this.struct = newStructure;
|
|
543
|
+
this.structureChanged = true;
|
|
544
|
+
this.stagingGraph = void 0;
|
|
545
|
+
this.pendingProductionGraph = void 0;
|
|
546
|
+
this.actualProductionGraph = void 0;
|
|
547
|
+
this.updateLastModified();
|
|
548
|
+
}
|
|
549
|
+
addBlock(block, spec, before) {
|
|
550
|
+
const newStruct = this.structure;
|
|
551
|
+
if (before === void 0) newStruct.groups[newStruct.groups.length - 1].blocks.push(block);
|
|
552
|
+
else {
|
|
553
|
+
let done = false;
|
|
554
|
+
for (const group of newStruct.groups) {
|
|
555
|
+
const idx = group.blocks.findIndex((b) => b.id === before);
|
|
556
|
+
if (idx < 0) continue;
|
|
557
|
+
group.blocks.splice(idx, 0, block);
|
|
558
|
+
done = true;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
if (!done) throw new Error(`Can't find element with id: ${before}`);
|
|
562
|
+
}
|
|
563
|
+
this.updateStructure(newStruct, (blockId) => {
|
|
564
|
+
if (blockId !== block.id) throw new Error("Unexpected");
|
|
565
|
+
this.initializeNewBlock(blockId, spec);
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Duplicates an existing block by copying all its fields and structure.
|
|
570
|
+
* This method creates a deep copy of the block at the mutator level.
|
|
571
|
+
*
|
|
572
|
+
* @param originalBlockId id of the block to duplicate
|
|
573
|
+
* @param newBlockId id for the new duplicated block
|
|
574
|
+
* @param after id of the block to insert new block after
|
|
575
|
+
*/
|
|
576
|
+
duplicateBlock(originalBlockId, newBlockId, after) {
|
|
577
|
+
const originalBlock = this.getBlock(originalBlockId);
|
|
578
|
+
const originalBlockInfo = this.getBlockInfo(originalBlockId);
|
|
579
|
+
const newBlock = {
|
|
580
|
+
id: newBlockId,
|
|
581
|
+
label: originalBlock.label,
|
|
582
|
+
renderingMode: originalBlock.renderingMode
|
|
583
|
+
};
|
|
584
|
+
const newStruct = this.structure;
|
|
585
|
+
if (after === void 0) newStruct.groups[newStruct.groups.length - 1].blocks.push(newBlock);
|
|
586
|
+
else {
|
|
587
|
+
let done = false;
|
|
588
|
+
for (const group of newStruct.groups) {
|
|
589
|
+
const idx = group.blocks.findIndex((b) => b.id === after);
|
|
590
|
+
if (idx < 0) continue;
|
|
591
|
+
group.blocks.splice(idx + 1, 0, newBlock);
|
|
592
|
+
done = true;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
if (!done) throw new Error(`Can't find element with id: ${after}`);
|
|
596
|
+
}
|
|
597
|
+
this.updateStructure(newStruct, (blockId) => {
|
|
598
|
+
if (blockId !== newBlockId) throw new Error("Unexpected");
|
|
599
|
+
this.initializeBlockDuplicate(blockId, originalBlockInfo);
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
deleteBlock(blockId) {
|
|
603
|
+
const newStruct = this.structure;
|
|
604
|
+
let done = false;
|
|
605
|
+
for (const group of newStruct.groups) {
|
|
606
|
+
const idx = group.blocks.findIndex((b) => b.id === blockId);
|
|
607
|
+
if (idx < 0) continue;
|
|
608
|
+
group.blocks.splice(idx, 1);
|
|
609
|
+
done = true;
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
if (!done) throw new Error(`Can't find element with id: ${blockId}`);
|
|
613
|
+
this.updateStructure(newStruct);
|
|
614
|
+
}
|
|
615
|
+
migrateBlockPack(blockId, spec, newClearState) {
|
|
616
|
+
const info = this.getBlockInfo(blockId);
|
|
617
|
+
const newConfig = extractConfig(spec.config);
|
|
618
|
+
const persistBlockPack = () => {
|
|
619
|
+
this.setBlockField(blockId, "blockPack", Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)), "NotReady");
|
|
620
|
+
};
|
|
621
|
+
const applyStorageAndDeriveArgs = (storageJson) => {
|
|
622
|
+
persistBlockPack();
|
|
623
|
+
this.setBlockStorageRaw(blockId, storageJson);
|
|
624
|
+
const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(newConfig, storageJson);
|
|
625
|
+
if (!deriveArgsResult.error) {
|
|
626
|
+
this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(deriveArgsResult.value));
|
|
627
|
+
const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(newConfig, storageJson);
|
|
628
|
+
if (prerunArgs !== void 0) this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
if (newClearState !== void 0) if (newConfig.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION) {
|
|
632
|
+
applyStorageAndDeriveArgs(this.projectHelper.getInitialStorageInVM(newConfig));
|
|
633
|
+
this.blocksWithChangedInputs.add(blockId);
|
|
634
|
+
this.updateLastModified();
|
|
635
|
+
} else {
|
|
636
|
+
persistBlockPack();
|
|
637
|
+
this.setStates([{
|
|
638
|
+
modelAPIVersion: 1,
|
|
639
|
+
blockId,
|
|
640
|
+
state: newClearState.state
|
|
641
|
+
}]);
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
if (newConfig.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION) {
|
|
645
|
+
const currentStorageJson = info.blockStorageJson;
|
|
646
|
+
const migrationResult = this.projectHelper.migrateStorageInVM(newConfig, currentStorageJson);
|
|
647
|
+
if (migrationResult.error !== void 0) throw new Error(`[migrateBlockPack] Block ${blockId} migration failed: ${migrationResult.error}`);
|
|
648
|
+
console.log(`[migrateBlockPack] Block ${blockId}: ${migrationResult.info}`);
|
|
649
|
+
applyStorageAndDeriveArgs(migrationResult.newStorageJson);
|
|
650
|
+
} else {
|
|
651
|
+
persistBlockPack();
|
|
652
|
+
if (info.fields.currentArgs !== void 0) this.setBlockFieldObj(blockId, "currentPrerunArgs", info.fields.currentArgs);
|
|
653
|
+
}
|
|
654
|
+
this.blocksWithChangedInputs.add(blockId);
|
|
655
|
+
this.getStagingGraph().traverse("downstream", [blockId], ({ id }) => this.resetStaging(id));
|
|
656
|
+
}
|
|
657
|
+
if (info.productionRendered) this.getActualProductionGraph().traverse("downstream", [blockId], ({ id }) => this.resetOrLimboProduction(id));
|
|
658
|
+
this.updateLastModified();
|
|
659
|
+
}
|
|
660
|
+
renderProduction(blockIds, addUpstreams = false) {
|
|
661
|
+
const blockIdsSet = new Set(blockIds);
|
|
662
|
+
const prodGraph = this.getPendingProductionGraph();
|
|
663
|
+
if (addUpstreams) prodGraph.traverse("upstream", blockIds, (node) => {
|
|
664
|
+
blockIdsSet.add(node.id);
|
|
665
|
+
});
|
|
666
|
+
else for (const blockId of blockIdsSet) {
|
|
667
|
+
const node = prodGraph.nodes.get(blockId);
|
|
668
|
+
if (node === void 0) throw new Error(`Can't find block with id: ${blockId}`);
|
|
669
|
+
for (const upstream of node.upstream) if (!blockIdsSet.has(upstream)) throw new Error("Can't render blocks not including all upstreams.");
|
|
670
|
+
}
|
|
671
|
+
const rendered = /* @__PURE__ */ new Set();
|
|
672
|
+
for (const block of allBlocks(this.structure)) {
|
|
673
|
+
if (!blockIdsSet.has(block.id)) continue;
|
|
674
|
+
let render = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);
|
|
675
|
+
if (!render) {
|
|
676
|
+
for (const upstream of prodGraph.nodes.get(block.id).upstream) if (rendered.has(upstream)) {
|
|
677
|
+
render = true;
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (render) {
|
|
682
|
+
this.renderProductionFor(block.id);
|
|
683
|
+
rendered.add(block.id);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
const renderedArray = [...rendered];
|
|
687
|
+
prodGraph.traverse("downstream", renderedArray, (node) => {
|
|
688
|
+
if (rendered.has(node.id)) return;
|
|
689
|
+
this.resetOrLimboProduction(node.id);
|
|
690
|
+
});
|
|
691
|
+
this.getStagingGraph().traverse("downstream", renderedArray, ({ id }) => {
|
|
692
|
+
if (renderedArray[0] !== id) this.resetStaging(id);
|
|
693
|
+
});
|
|
694
|
+
if (rendered.size > 0) this.updateLastModified();
|
|
695
|
+
return rendered;
|
|
696
|
+
}
|
|
697
|
+
/** Stops running blocks from the list and modify states of other blocks
|
|
698
|
+
* accordingly */
|
|
699
|
+
stopProduction(...blockIds) {
|
|
700
|
+
const activeProdGraph = this.getActualProductionGraph();
|
|
701
|
+
const queue = new Denque(blockIds);
|
|
702
|
+
const queued = new Set(blockIds);
|
|
703
|
+
const stopped = [];
|
|
704
|
+
while (!queue.isEmpty()) {
|
|
705
|
+
const blockId = queue.shift();
|
|
706
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
707
|
+
if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready") continue;
|
|
708
|
+
if (this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs")) {
|
|
709
|
+
stopped.push(blockId);
|
|
710
|
+
for (const downstream of activeProdGraph.traverseIdsExcludingRoots("downstream", blockId)) {
|
|
711
|
+
if (queued.has(downstream)) continue;
|
|
712
|
+
queue.push(downstream);
|
|
713
|
+
queued.add(downstream);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
for (const blockId of activeProdGraph.traverseIdsExcludingRoots("downstream", ...stopped)) this.resetOrLimboProduction(blockId);
|
|
718
|
+
this.getStagingGraph().traverse("downstream", stopped, ({ id }) => this.resetStaging(id));
|
|
719
|
+
}
|
|
720
|
+
traverseWithStagingLag(cb) {
|
|
721
|
+
const lags = /* @__PURE__ */ new Map();
|
|
722
|
+
this.getStagingGraph().nodes.forEach((node) => {
|
|
723
|
+
const info = this.getBlockInfo(node.id);
|
|
724
|
+
const requiresRendering = info.requireStagingRendering;
|
|
725
|
+
let lag = requiresRendering ? 1 : 0;
|
|
726
|
+
node.upstream.forEach((upstream) => {
|
|
727
|
+
const upstreamLag = lags.get(upstream);
|
|
728
|
+
if (upstreamLag === 0) return;
|
|
729
|
+
lag = Math.max(upstreamLag + 1, lag);
|
|
730
|
+
});
|
|
731
|
+
if (!requiresRendering && info.stagingRendered) {}
|
|
732
|
+
cb(node.id, lag);
|
|
733
|
+
lags.set(node.id, lag);
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
/** @param stagingRenderingRate rate in blocks per second */
|
|
737
|
+
refreshStagings(stagingRenderingRate) {
|
|
738
|
+
const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;
|
|
739
|
+
const lagThreshold = stagingRenderingRate === void 0 ? void 0 : 1 + Math.max(0, elapsed * stagingRenderingRate / 1e3);
|
|
740
|
+
let rendered = 0;
|
|
741
|
+
this.traverseWithStagingLag((blockId, lag) => {
|
|
742
|
+
if (lag === 0) return;
|
|
743
|
+
if (lagThreshold === void 0 || lag <= lagThreshold) {
|
|
744
|
+
this.renderStagingFor(blockId);
|
|
745
|
+
rendered++;
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
if (rendered > 0) this.resetStagingRefreshTimestamp();
|
|
749
|
+
}
|
|
750
|
+
/** Updates project metadata */
|
|
751
|
+
setMeta(meta) {
|
|
752
|
+
this.meta = meta;
|
|
753
|
+
this.metaChanged = true;
|
|
754
|
+
this.updateLastModified();
|
|
755
|
+
}
|
|
756
|
+
/** @param stagingRenderingRate rate in blocks per second */
|
|
757
|
+
doRefresh(stagingRenderingRate) {
|
|
758
|
+
this.refreshStagings(stagingRenderingRate);
|
|
759
|
+
this.blockInfos.forEach((blockInfo) => {
|
|
760
|
+
if (blockInfo.fields.prodCtx?.status === "Ready" && blockInfo.fields.prodOutput?.status === "Ready") this.deleteBlockFields(blockInfo.id, "prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious");
|
|
761
|
+
if (blockInfo.fields.stagingCtx?.status === "Ready" && blockInfo.fields.stagingOutput?.status === "Ready") this.deleteBlockFields(blockInfo.id, "stagingOutputPrevious", "stagingCtxPrevious", "stagingUiCtxPrevious");
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
assignAuthorMarkers() {
|
|
765
|
+
const markerStr = this.author ? JSON.stringify(this.author) : void 0;
|
|
766
|
+
for (const blockId of this.blocksWithChangedInputs) if (markerStr === void 0) this.tx.deleteKValue(this.rid, blockArgsAuthorKey(blockId));
|
|
767
|
+
else this.tx.setKValue(this.rid, blockArgsAuthorKey(blockId), markerStr);
|
|
768
|
+
if (this.metaChanged || this.structureChanged) if (markerStr === void 0) this.tx.deleteKValue(this.rid, ProjectStructureAuthorKey);
|
|
769
|
+
else this.tx.setKValue(this.rid, ProjectStructureAuthorKey, markerStr);
|
|
770
|
+
}
|
|
771
|
+
save() {
|
|
772
|
+
if (!this.wasModified) return;
|
|
773
|
+
if (this.lastModifiedChanged) this.tx.setKValue(this.rid, ProjectLastModifiedTimestamp, JSON.stringify(this.lastModified));
|
|
774
|
+
if (this.structureChanged) this.tx.setKValue(this.rid, ProjectStructureKey, JSON.stringify(this.struct));
|
|
775
|
+
if (this.renderingStateChanged) this.tx.setKValue(this.rid, BlockRenderingStateKey, JSON.stringify({
|
|
776
|
+
...this.renderingState,
|
|
777
|
+
blocksInLimbo: [...this.blocksInLimbo]
|
|
778
|
+
}));
|
|
779
|
+
if (this.metaChanged) this.tx.setKValue(this.rid, ProjectMetaKey, JSON.stringify(this.meta));
|
|
780
|
+
this.assignAuthorMarkers();
|
|
781
|
+
}
|
|
782
|
+
static async load(projectHelper, tx, rid, author) {
|
|
783
|
+
const fullResourceStateP = tx.getResourceData(rid, true);
|
|
784
|
+
const schemaP = tx.getKValueJson(rid, SchemaVersionKey);
|
|
785
|
+
const lastModifiedP = tx.getKValueJson(rid, ProjectLastModifiedTimestamp);
|
|
786
|
+
const metaP = tx.getKValueJson(rid, ProjectMetaKey);
|
|
787
|
+
const structureP = tx.getKValueJson(rid, ProjectStructureKey);
|
|
788
|
+
const renderingStateP = tx.getKValueJson(rid, BlockRenderingStateKey);
|
|
789
|
+
const fullResourceState = await fullResourceStateP;
|
|
790
|
+
const blockInfoStates = /* @__PURE__ */ new Map();
|
|
791
|
+
for (const f of fullResourceState.fields) {
|
|
792
|
+
const projectField = parseProjectField(f.name);
|
|
793
|
+
if (projectField === void 0) continue;
|
|
794
|
+
let info = blockInfoStates.get(projectField.blockId);
|
|
795
|
+
if (info === void 0) {
|
|
796
|
+
info = {
|
|
797
|
+
id: projectField.blockId,
|
|
798
|
+
fields: {}
|
|
799
|
+
};
|
|
800
|
+
blockInfoStates.set(projectField.blockId, info);
|
|
801
|
+
}
|
|
802
|
+
info.fields[projectField.fieldName] = isNullResourceId(f.value) ? { modCount: 0 } : {
|
|
803
|
+
modCount: 0,
|
|
804
|
+
ref: f.value
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
const blockFieldRequests = [];
|
|
808
|
+
blockInfoStates.forEach((info) => {
|
|
809
|
+
const fields = info.fields;
|
|
810
|
+
for (const [fName, state] of Object.entries(fields)) {
|
|
811
|
+
if (state.ref === void 0) continue;
|
|
812
|
+
if (!isResource(state.ref) || isResourceRef(state.ref)) throw new Error("unexpected behaviour");
|
|
813
|
+
const fieldName = fName;
|
|
814
|
+
blockFieldRequests.push([
|
|
815
|
+
info,
|
|
816
|
+
fieldName,
|
|
817
|
+
state,
|
|
818
|
+
tx.getResourceData(state.ref, fieldName == "blockPack")
|
|
819
|
+
]);
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
const [schema, lastModified, meta, structure, { stagingRefreshTimestamp, blocksInLimbo }] = await Promise.all([
|
|
823
|
+
schemaP,
|
|
824
|
+
lastModifiedP,
|
|
825
|
+
metaP,
|
|
826
|
+
structureP,
|
|
827
|
+
renderingStateP
|
|
828
|
+
]);
|
|
829
|
+
if (schema !== SchemaVersionCurrent) if (Number(schema) < Number(SchemaVersionCurrent)) throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);
|
|
830
|
+
else throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);
|
|
831
|
+
const blockPackRequests = [];
|
|
832
|
+
for (const [info, fieldName, state, response] of blockFieldRequests) {
|
|
833
|
+
const result = await response;
|
|
834
|
+
state.value = result.data;
|
|
835
|
+
if (isNotNullResourceId(result.error)) state.status = "Error";
|
|
836
|
+
else if (result.resourceReady || isNotNullResourceId(result.originalResourceId)) state.status = "Ready";
|
|
837
|
+
else state.status = "NotReady";
|
|
838
|
+
if (fieldName === "blockPack") {
|
|
839
|
+
const refField = result.fields.find((f) => f.name === Pl.HolderRefField);
|
|
840
|
+
if (refField === void 0) throw new Error("Block pack ref field is missing");
|
|
841
|
+
blockPackRequests.push([info, tx.getResourceData(ensureResourceIdNotNull(refField.value), false)]);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
for (const [info, response] of blockPackRequests) {
|
|
845
|
+
const bpInfo = cachedDeserialize(notEmpty((await response).data));
|
|
846
|
+
info.blockConfig = extractConfig(bpInfo.config);
|
|
847
|
+
info.blockPack = bpInfo.source;
|
|
848
|
+
}
|
|
849
|
+
const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();
|
|
850
|
+
const ctxExportTplCacheFieldName = getServiceTemplateField(ctxExportTplEnvelope.hash);
|
|
851
|
+
const ctxExportTplField = fullResourceState.fields.find((f) => f.name === ctxExportTplCacheFieldName);
|
|
852
|
+
let ctxExportTplHolder;
|
|
853
|
+
if (ctxExportTplField !== void 0) ctxExportTplHolder = ensureResourceIdNotNull(ctxExportTplField.value);
|
|
854
|
+
else {
|
|
855
|
+
ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));
|
|
856
|
+
tx.createField(field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)), "Dynamic", ctxExportTplHolder);
|
|
857
|
+
}
|
|
858
|
+
const renderingState = { stagingRefreshTimestamp };
|
|
859
|
+
const blocksInLimboSet = new Set(blocksInLimbo);
|
|
860
|
+
const blockInfos = /* @__PURE__ */ new Map();
|
|
861
|
+
blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id, new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));
|
|
862
|
+
const blockInStruct = /* @__PURE__ */ new Set();
|
|
863
|
+
for (const b of allBlocks(structure)) {
|
|
864
|
+
if (!blockInfos.has(b.id)) throw new Error(`Inconsistent project structure: no inputs for ${b.id}`);
|
|
865
|
+
blockInStruct.add(b.id);
|
|
866
|
+
}
|
|
867
|
+
blockInfos.forEach((info) => {
|
|
868
|
+
if (!blockInStruct.has(info.id)) throw new Error(`Inconsistent project structure: no structure entry for ${info.id}`);
|
|
869
|
+
info.check();
|
|
870
|
+
});
|
|
871
|
+
const prj = new ProjectMutator(rid, tx, author, schema, lastModified, meta, structure, renderingState, blocksInLimboSet, blockInfos, ctxExportTplHolder, projectHelper);
|
|
872
|
+
prj.fixProblemsAndMigrate();
|
|
873
|
+
return prj;
|
|
874
|
+
}
|
|
139
875
|
};
|
|
140
|
-
class ProjectMutator {
|
|
141
|
-
rid;
|
|
142
|
-
tx;
|
|
143
|
-
author;
|
|
144
|
-
schema;
|
|
145
|
-
lastModified;
|
|
146
|
-
meta;
|
|
147
|
-
struct;
|
|
148
|
-
renderingState;
|
|
149
|
-
blocksInLimbo;
|
|
150
|
-
blockInfos;
|
|
151
|
-
ctxExportTplHolder;
|
|
152
|
-
projectHelper;
|
|
153
|
-
globalModCount = 0;
|
|
154
|
-
fieldsChanged = false;
|
|
155
|
-
//
|
|
156
|
-
// Change trackers
|
|
157
|
-
//
|
|
158
|
-
lastModifiedChanged = false;
|
|
159
|
-
structureChanged = false;
|
|
160
|
-
metaChanged = false;
|
|
161
|
-
renderingStateChanged = false;
|
|
162
|
-
/** Set blocks will be assigned current mutator author marker on save */
|
|
163
|
-
blocksWithChangedInputs = new Set();
|
|
164
|
-
constructor(rid, tx, author, schema, lastModified, meta, struct, renderingState, blocksInLimbo, blockInfos, ctxExportTplHolder, projectHelper) {
|
|
165
|
-
this.rid = rid;
|
|
166
|
-
this.tx = tx;
|
|
167
|
-
this.author = author;
|
|
168
|
-
this.schema = schema;
|
|
169
|
-
this.lastModified = lastModified;
|
|
170
|
-
this.meta = meta;
|
|
171
|
-
this.struct = struct;
|
|
172
|
-
this.renderingState = renderingState;
|
|
173
|
-
this.blocksInLimbo = blocksInLimbo;
|
|
174
|
-
this.blockInfos = blockInfos;
|
|
175
|
-
this.ctxExportTplHolder = ctxExportTplHolder;
|
|
176
|
-
this.projectHelper = projectHelper;
|
|
177
|
-
}
|
|
178
|
-
fixProblemsAndMigrate() {
|
|
179
|
-
// Fixing problems introduced by old code
|
|
180
|
-
this.blockInfos.forEach((blockInfo) => {
|
|
181
|
-
if (blockInfo.fields.prodArgs === undefined ||
|
|
182
|
-
blockInfo.fields.prodOutput === undefined ||
|
|
183
|
-
blockInfo.fields.prodCtx === undefined)
|
|
184
|
-
this.deleteBlockFields(blockInfo.id, "prodArgs", "prodOutput", "prodCtx");
|
|
185
|
-
});
|
|
186
|
-
// Migration for addition of block settings field
|
|
187
|
-
let initialBlockSettings;
|
|
188
|
-
this.blockInfos.forEach((blockInfo) => {
|
|
189
|
-
if (blockInfo.fields.blockSettings === undefined) {
|
|
190
|
-
if (initialBlockSettings === undefined)
|
|
191
|
-
initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);
|
|
192
|
-
this.setBlockFieldObj(blockInfo.id, "blockSettings", initialBlockSettings);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
get wasModified() {
|
|
197
|
-
return (this.lastModifiedChanged ||
|
|
198
|
-
this.structureChanged ||
|
|
199
|
-
this.fieldsChanged ||
|
|
200
|
-
this.metaChanged ||
|
|
201
|
-
this.renderingStateChanged);
|
|
202
|
-
}
|
|
203
|
-
get structure() {
|
|
204
|
-
return JSON.parse(JSON.stringify(this.struct));
|
|
205
|
-
}
|
|
206
|
-
//
|
|
207
|
-
// Graph calculation
|
|
208
|
-
//
|
|
209
|
-
stagingGraph = undefined;
|
|
210
|
-
pendingProductionGraph = undefined;
|
|
211
|
-
actualProductionGraph = undefined;
|
|
212
|
-
getStagingGraph() {
|
|
213
|
-
if (this.stagingGraph === undefined)
|
|
214
|
-
this.stagingGraph = stagingGraph(this.struct);
|
|
215
|
-
return this.stagingGraph;
|
|
216
|
-
}
|
|
217
|
-
getProductionGraphBlockInfo(blockId, prod) {
|
|
218
|
-
const bInfo = this.getBlockInfo(blockId);
|
|
219
|
-
let argsField;
|
|
220
|
-
let args;
|
|
221
|
-
if (prod) {
|
|
222
|
-
if (bInfo.fields.prodArgs === undefined)
|
|
223
|
-
return undefined;
|
|
224
|
-
argsField = bInfo.fields.prodArgs;
|
|
225
|
-
args = bInfo.prodArgs;
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
argsField = bInfo.fields.currentArgs;
|
|
229
|
-
args = bInfo.currentArgs;
|
|
230
|
-
}
|
|
231
|
-
// Can't compute enrichment targets without args
|
|
232
|
-
if (argsField === undefined) {
|
|
233
|
-
return { args, enrichmentTargets: undefined };
|
|
234
|
-
}
|
|
235
|
-
const blockPackField = notEmpty(bInfo.fields.blockPack);
|
|
236
|
-
if (isResourceId(argsField.ref) && isResourceId(blockPackField.ref))
|
|
237
|
-
return {
|
|
238
|
-
args,
|
|
239
|
-
enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args, { argsRid: argsField.ref, blockPackRid: blockPackField.ref }),
|
|
240
|
-
};
|
|
241
|
-
else
|
|
242
|
-
return {
|
|
243
|
-
args,
|
|
244
|
-
enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args),
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
getPendingProductionGraph() {
|
|
248
|
-
if (this.pendingProductionGraph === undefined)
|
|
249
|
-
this.pendingProductionGraph = productionGraph(this.struct, (blockId) => this.getProductionGraphBlockInfo(blockId, false));
|
|
250
|
-
return this.pendingProductionGraph;
|
|
251
|
-
}
|
|
252
|
-
getActualProductionGraph() {
|
|
253
|
-
if (this.actualProductionGraph === undefined)
|
|
254
|
-
this.actualProductionGraph = productionGraph(this.struct, (blockId) => this.getProductionGraphBlockInfo(blockId, true));
|
|
255
|
-
return this.actualProductionGraph;
|
|
256
|
-
}
|
|
257
|
-
//
|
|
258
|
-
// Generic helpers to interact with project state
|
|
259
|
-
//
|
|
260
|
-
getBlockInfo(blockId) {
|
|
261
|
-
const info = this.blockInfos.get(blockId);
|
|
262
|
-
if (info === undefined)
|
|
263
|
-
throw new Error(`No such block: ${blockId}`);
|
|
264
|
-
return info;
|
|
265
|
-
}
|
|
266
|
-
createJsonFieldValueByContent(content) {
|
|
267
|
-
if (content === undefined)
|
|
268
|
-
throw new Error("content is undefined");
|
|
269
|
-
const value = Buffer.from(content);
|
|
270
|
-
const ref = this.tx.createValue(Pl.JsonObject, value);
|
|
271
|
-
return { ref, value, status: "Ready" };
|
|
272
|
-
}
|
|
273
|
-
createJsonFieldValue(obj) {
|
|
274
|
-
return this.createJsonFieldValueByContent(JSON.stringify(obj));
|
|
275
|
-
}
|
|
276
|
-
getBlock(blockId) {
|
|
277
|
-
for (const block of allBlocks(this.struct))
|
|
278
|
-
if (block.id === blockId)
|
|
279
|
-
return block;
|
|
280
|
-
throw new Error("block not found");
|
|
281
|
-
}
|
|
282
|
-
setBlockFieldObj(blockId, fieldName, state) {
|
|
283
|
-
const fid = field(this.rid, projectFieldName(blockId, fieldName));
|
|
284
|
-
if (state.ref === undefined)
|
|
285
|
-
throw new Error("Can't set value with empty ref");
|
|
286
|
-
if (this.getBlockInfo(blockId).fields[fieldName] === undefined)
|
|
287
|
-
this.tx.createField(fid, "Dynamic", state.ref);
|
|
288
|
-
else
|
|
289
|
-
this.tx.setField(fid, state.ref);
|
|
290
|
-
this.getBlockInfo(blockId).fields[fieldName] = {
|
|
291
|
-
modCount: this.globalModCount++,
|
|
292
|
-
...state,
|
|
293
|
-
};
|
|
294
|
-
this.fieldsChanged = true;
|
|
295
|
-
}
|
|
296
|
-
setBlockField(blockId, fieldName, ref, status, value) {
|
|
297
|
-
this.setBlockFieldObj(blockId, fieldName, { ref, status, value });
|
|
298
|
-
}
|
|
299
|
-
deleteBlockFields(blockId, ...fieldNames) {
|
|
300
|
-
let deleted = false;
|
|
301
|
-
const info = this.getBlockInfo(blockId);
|
|
302
|
-
for (const fieldName of fieldNames) {
|
|
303
|
-
const fields = info.fields;
|
|
304
|
-
if (!(fieldName in fields))
|
|
305
|
-
continue;
|
|
306
|
-
this.tx.removeField(field(this.rid, projectFieldName(blockId, fieldName)));
|
|
307
|
-
delete fields[fieldName];
|
|
308
|
-
this.fieldsChanged = true;
|
|
309
|
-
deleted = true;
|
|
310
|
-
}
|
|
311
|
-
return deleted;
|
|
312
|
-
}
|
|
313
|
-
updateLastModified() {
|
|
314
|
-
this.lastModified = Date.now();
|
|
315
|
-
this.lastModifiedChanged = true;
|
|
316
|
-
}
|
|
317
|
-
//
|
|
318
|
-
// Main project actions
|
|
319
|
-
//
|
|
320
|
-
resetStagingRefreshTimestamp() {
|
|
321
|
-
this.renderingState.stagingRefreshTimestamp = Date.now();
|
|
322
|
-
this.renderingStateChanged = true;
|
|
323
|
-
}
|
|
324
|
-
resetStaging(blockId) {
|
|
325
|
-
const fields = this.getBlockInfo(blockId).fields;
|
|
326
|
-
if (fields.stagingOutput?.status === "Ready" &&
|
|
327
|
-
fields.stagingCtx?.status === "Ready" &&
|
|
328
|
-
fields.stagingUiCtx?.status === "Ready") {
|
|
329
|
-
this.setBlockFieldObj(blockId, "stagingOutputPrevious", fields.stagingOutput);
|
|
330
|
-
this.setBlockFieldObj(blockId, "stagingCtxPrevious", fields.stagingCtx);
|
|
331
|
-
this.setBlockFieldObj(blockId, "stagingUiCtxPrevious", fields.stagingUiCtx);
|
|
332
|
-
}
|
|
333
|
-
if (this.deleteBlockFields(blockId, "stagingOutput", "stagingCtx", "stagingUiCtx"))
|
|
334
|
-
this.resetStagingRefreshTimestamp();
|
|
335
|
-
}
|
|
336
|
-
resetProduction(blockId) {
|
|
337
|
-
const fields = this.getBlockInfo(blockId).fields;
|
|
338
|
-
if (fields.prodOutput?.status === "Ready" &&
|
|
339
|
-
fields.prodCtx?.status === "Ready" &&
|
|
340
|
-
fields.prodUiCtx?.status === "Ready") {
|
|
341
|
-
this.setBlockFieldObj(blockId, "prodOutputPrevious", fields.prodOutput);
|
|
342
|
-
this.setBlockFieldObj(blockId, "prodCtxPrevious", fields.prodCtx);
|
|
343
|
-
this.setBlockFieldObj(blockId, "prodUiCtxPrevious", fields.prodUiCtx);
|
|
344
|
-
}
|
|
345
|
-
this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs");
|
|
346
|
-
}
|
|
347
|
-
/** Running blocks are reset, already computed moved to limbo. Returns if
|
|
348
|
-
* either of the actions were actually performed.
|
|
349
|
-
* This method ensures the block is left in a consistent state that passes check() constraints. */
|
|
350
|
-
resetOrLimboProduction(blockId) {
|
|
351
|
-
const fields = this.getBlockInfo(blockId).fields;
|
|
352
|
-
// Check if we can safely move to limbo (both core production fields are ready)
|
|
353
|
-
if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready") {
|
|
354
|
-
if (this.blocksInLimbo.has(blockId))
|
|
355
|
-
// we are already in limbo
|
|
356
|
-
return false;
|
|
357
|
-
// limbo - keep the ready production results but clean up cache
|
|
358
|
-
this.blocksInLimbo.add(blockId);
|
|
359
|
-
this.renderingStateChanged = true;
|
|
360
|
-
// doing some gc - clean up previous cache fields
|
|
361
|
-
this.deleteBlockFields(blockId, "prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious");
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
// reset - clean up any partial/inconsistent production stat
|
|
366
|
-
return this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs", "prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious");
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Gets current block state and merges with partial updates.
|
|
371
|
-
* Used by legacy v1/v2 methods like setBlockArgs and setUiState.
|
|
372
|
-
*
|
|
373
|
-
* @param blockId The block to get state for
|
|
374
|
-
* @param partialUpdate Partial state to merge (e.g. { args } or { uiState })
|
|
375
|
-
* @returns Merged state in unified format { args, uiState }
|
|
376
|
-
*/
|
|
377
|
-
mergeBlockState(blockId, partialUpdate) {
|
|
378
|
-
const info = this.getBlockInfo(blockId);
|
|
379
|
-
const currentState = info.blockStorage;
|
|
380
|
-
return { ...currentState, ...partialUpdate };
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Sets raw block storage content directly (for testing purposes).
|
|
384
|
-
* This bypasses all normalization and VM transformations.
|
|
385
|
-
*
|
|
386
|
-
* @param blockId The block to set storage for
|
|
387
|
-
* @param rawStorageJson Raw storage as JSON string
|
|
388
|
-
*/
|
|
389
|
-
setBlockStorageRaw(blockId, rawStorageJson) {
|
|
390
|
-
this.setBlockFieldObj(blockId, "blockStorage", this.createJsonFieldValueByContent(rawStorageJson));
|
|
391
|
-
this.blocksWithChangedInputs.add(blockId);
|
|
392
|
-
this.updateLastModified();
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Resets a v2+ block to its initial storage state.
|
|
396
|
-
* Gets initial storage from VM and derives args from it.
|
|
397
|
-
*
|
|
398
|
-
* For v1 blocks, use setStates() instead.
|
|
399
|
-
*
|
|
400
|
-
* @param blockId The block to reset
|
|
401
|
-
*/
|
|
402
|
-
resetToInitialStorage(blockId) {
|
|
403
|
-
const info = this.getBlockInfo(blockId);
|
|
404
|
-
const blockConfig = info.config;
|
|
405
|
-
if (blockConfig.modelAPIVersion !== BLOCK_STORAGE_FACADE_VERSION) {
|
|
406
|
-
throw new Error("resetToInitialStorage is only supported for model API version 2");
|
|
407
|
-
}
|
|
408
|
-
// Get initial storage from VM
|
|
409
|
-
const initialStorageJson = this.projectHelper.getInitialStorageInVM(blockConfig);
|
|
410
|
-
this.setBlockStorageRaw(blockId, initialStorageJson);
|
|
411
|
-
// Derive args from storage - set or clear currentArgs based on derivation result
|
|
412
|
-
const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, initialStorageJson);
|
|
413
|
-
if (!deriveArgsResult.error) {
|
|
414
|
-
this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(deriveArgsResult.value));
|
|
415
|
-
// Derive prerunArgs from storage
|
|
416
|
-
const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, initialStorageJson);
|
|
417
|
-
if (prerunArgs !== undefined) {
|
|
418
|
-
this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
this.deleteBlockFields(blockId, "currentArgs");
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
/** Optimally sets inputs for multiple blocks in one go */
|
|
426
|
-
setStates(requests) {
|
|
427
|
-
const changedArgs = [];
|
|
428
|
-
let somethingChanged = false;
|
|
429
|
-
for (const req of requests) {
|
|
430
|
-
const info = this.getBlockInfo(req.blockId);
|
|
431
|
-
let blockChanged = false;
|
|
432
|
-
const blockConfig = info.config;
|
|
433
|
-
// modelAPIVersion === 2 means BlockModelV3 with .args() lambda for deriving args
|
|
434
|
-
if (req.modelAPIVersion !== blockConfig.modelAPIVersion) {
|
|
435
|
-
throw new Error(`Model API version mismatch for block ${req.blockId}: ${req.modelAPIVersion} !== ${blockConfig.modelAPIVersion}`);
|
|
436
|
-
}
|
|
437
|
-
// Derive args from storage using the block's config.args() callback
|
|
438
|
-
let args;
|
|
439
|
-
let prerunArgs;
|
|
440
|
-
if (req.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION) {
|
|
441
|
-
const currentStorageJson = info.blockStorageJson;
|
|
442
|
-
if (currentStorageJson === undefined) {
|
|
443
|
-
throw new Error(`Block ${req.blockId} has no blockStorage - this should not happen`);
|
|
444
|
-
}
|
|
445
|
-
// Apply the state update to storage
|
|
446
|
-
const updatedStorageJson = this.projectHelper.applyStorageUpdateInVM(blockConfig, currentStorageJson, req.payload);
|
|
447
|
-
this.setBlockFieldObj(req.blockId, "blockStorage", this.createJsonFieldValueByContent(updatedStorageJson));
|
|
448
|
-
// Derive args directly from storage (VM extracts data internally)
|
|
449
|
-
const derivedArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, updatedStorageJson);
|
|
450
|
-
if (derivedArgsResult.error) {
|
|
451
|
-
args = undefined;
|
|
452
|
-
prerunArgs = undefined;
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
args = derivedArgsResult.value;
|
|
456
|
-
// Derive prerunArgs from storage, or fall back to args
|
|
457
|
-
prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, updatedStorageJson);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
this.setBlockFieldObj(req.blockId, "blockStorage", this.createJsonFieldValue(req.state));
|
|
462
|
-
if (req.state !== null && typeof req.state === "object" && "args" in req.state) {
|
|
463
|
-
args = req.state.args;
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
args = req.state;
|
|
467
|
-
}
|
|
468
|
-
// For the legacy blocks, prerunArgs = args (same as production args)
|
|
469
|
-
prerunArgs = args;
|
|
470
|
-
}
|
|
471
|
-
// Set or clear currentArgs based on derivation result
|
|
472
|
-
if (args !== undefined) {
|
|
473
|
-
const currentArgsData = canonicalJsonBytes(args);
|
|
474
|
-
const argsPartRef = this.tx.createValue(Pl.JsonObject, currentArgsData);
|
|
475
|
-
this.setBlockField(req.blockId, "currentArgs", argsPartRef, "Ready", currentArgsData);
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
this.deleteBlockFields(req.blockId, "currentArgs");
|
|
479
|
-
}
|
|
480
|
-
// Set currentPrerunArgs field and check if it actually changed
|
|
481
|
-
let prerunArgsChanged = false;
|
|
482
|
-
if (prerunArgs !== undefined) {
|
|
483
|
-
const prerunArgsData = canonicalJsonBytes(prerunArgs);
|
|
484
|
-
const oldPrerunArgsData = info.fields.currentPrerunArgs?.value;
|
|
485
|
-
// Check if prerunArgs actually changed
|
|
486
|
-
if (oldPrerunArgsData === undefined ||
|
|
487
|
-
Buffer.compare(oldPrerunArgsData, prerunArgsData) !== 0) {
|
|
488
|
-
prerunArgsChanged = true;
|
|
489
|
-
}
|
|
490
|
-
const prerunArgsRef = this.tx.createValue(Pl.JsonObject, prerunArgsData);
|
|
491
|
-
this.setBlockField(req.blockId, "currentPrerunArgs", prerunArgsRef, "Ready", prerunArgsData);
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
// prerunArgs is undefined - check if we previously had one
|
|
495
|
-
if (info.fields.currentPrerunArgs !== undefined) {
|
|
496
|
-
prerunArgsChanged = true;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
blockChanged = true;
|
|
500
|
-
// Only add to changedArgs if prerunArgs changed - this controls staging reset
|
|
501
|
-
if (prerunArgsChanged) {
|
|
502
|
-
changedArgs.push(req.blockId);
|
|
503
|
-
}
|
|
504
|
-
if (blockChanged) {
|
|
505
|
-
// will be assigned our author marker
|
|
506
|
-
this.blocksWithChangedInputs.add(req.blockId);
|
|
507
|
-
somethingChanged = true;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
// resetting staging outputs for all downstream blocks
|
|
511
|
-
this.getStagingGraph().traverse("downstream", changedArgs, ({ id }) => this.resetStaging(id));
|
|
512
|
-
if (somethingChanged)
|
|
513
|
-
this.updateLastModified();
|
|
514
|
-
}
|
|
515
|
-
setBlockSettings(blockId, newValue) {
|
|
516
|
-
this.setBlockFieldObj(blockId, "blockSettings", this.createJsonFieldValue(newValue));
|
|
517
|
-
this.updateLastModified();
|
|
518
|
-
}
|
|
519
|
-
createProdCtx(upstream) {
|
|
520
|
-
const upstreamContexts = [];
|
|
521
|
-
upstream.forEach((id) => {
|
|
522
|
-
const info = this.getBlockInfo(id);
|
|
523
|
-
if (info.fields["prodCtx"]?.ref === undefined)
|
|
524
|
-
throw new Error("One of the upstreams staging is not rendered.");
|
|
525
|
-
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["prodCtx"].ref));
|
|
526
|
-
});
|
|
527
|
-
return createBContextFromUpstreams(this.tx, upstreamContexts);
|
|
528
|
-
}
|
|
529
|
-
createStagingCtx(upstream) {
|
|
530
|
-
const upstreamContexts = [];
|
|
531
|
-
upstream.forEach((id) => {
|
|
532
|
-
const info = this.getBlockInfo(id);
|
|
533
|
-
if (info.fields["stagingCtx"]?.ref === undefined)
|
|
534
|
-
throw new Error("One of the upstreams staging is not rendered.");
|
|
535
|
-
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["stagingCtx"].ref));
|
|
536
|
-
if (info.fields["prodCtx"]?.ref !== undefined)
|
|
537
|
-
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["prodCtx"].ref));
|
|
538
|
-
});
|
|
539
|
-
return createBContextFromUpstreams(this.tx, upstreamContexts);
|
|
540
|
-
}
|
|
541
|
-
exportCtx(ctx) {
|
|
542
|
-
return exportContext(this.tx, Pl.unwrapHolder(this.tx, this.ctxExportTplHolder), ctx);
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Renders staging for a block using currentPrerunArgs.
|
|
546
|
-
* If currentPrerunArgs is not set (prerunArgs returned undefined), skips staging for this block.
|
|
547
|
-
*/
|
|
548
|
-
renderStagingFor(blockId) {
|
|
549
|
-
this.resetStaging(blockId);
|
|
550
|
-
const info = this.getBlockInfo(blockId);
|
|
551
|
-
// If currentPrerunArgs is not set (prerunArgs returned undefined), skip staging for this block
|
|
552
|
-
const prerunArgsRef = info.fields.currentPrerunArgs?.ref;
|
|
553
|
-
if (prerunArgsRef === undefined) {
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId).upstream);
|
|
557
|
-
if (this.getBlock(blockId).renderingMode !== "Heavy")
|
|
558
|
-
throw new Error("not supported yet");
|
|
559
|
-
const tpl = info.getTemplate(this.tx);
|
|
560
|
-
// Use currentPrerunArgs for staging rendering
|
|
561
|
-
const results = createRenderHeavyBlock(this.tx, tpl, {
|
|
562
|
-
args: prerunArgsRef,
|
|
563
|
-
blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),
|
|
564
|
-
isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),
|
|
565
|
-
context: ctx,
|
|
566
|
-
});
|
|
567
|
-
// Here we set the staging ctx to the input context of the staging workflow, not the output because exports
|
|
568
|
-
// of one staging context should stay within the same block, and not travel downstream.
|
|
569
|
-
// We may change this decision in the future if wanted to support traveling staging exports downstream.
|
|
570
|
-
this.setBlockField(blockId, "stagingCtx", Pl.wrapInEphHolder(this.tx, ctx), "NotReady");
|
|
571
|
-
// Yet the staging UI Ctx is the output context of the staging workflow, because it is used to form the result pool
|
|
572
|
-
// thus creating a certain discrepancy between staging workflow context behavior and desktop's result pool.
|
|
573
|
-
this.setBlockField(blockId, "stagingUiCtx", this.exportCtx(results.context), "NotReady");
|
|
574
|
-
this.setBlockField(blockId, "stagingOutput", results.result, "NotReady");
|
|
575
|
-
}
|
|
576
|
-
renderProductionFor(blockId) {
|
|
577
|
-
this.resetProduction(blockId);
|
|
578
|
-
const info = this.getBlockInfo(blockId);
|
|
579
|
-
// Can't render production if currentArgs is not set
|
|
580
|
-
if (info.fields.currentArgs === undefined) {
|
|
581
|
-
throw new Error(`Can't render production for block ${blockId}: currentArgs not set`);
|
|
582
|
-
}
|
|
583
|
-
const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId).upstream);
|
|
584
|
-
if (this.getBlock(blockId).renderingMode === "Light")
|
|
585
|
-
throw new Error("Can't render production for light block.");
|
|
586
|
-
const tpl = info.getTemplate(this.tx);
|
|
587
|
-
const results = createRenderHeavyBlock(this.tx, tpl, {
|
|
588
|
-
args: info.fields.currentArgs.ref,
|
|
589
|
-
blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),
|
|
590
|
-
isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(true)),
|
|
591
|
-
context: ctx,
|
|
592
|
-
});
|
|
593
|
-
this.setBlockField(blockId, "prodCtx", Pl.wrapInEphHolder(this.tx, results.context), "NotReady");
|
|
594
|
-
this.setBlockField(blockId, "prodUiCtx", this.exportCtx(results.context), "NotReady");
|
|
595
|
-
this.setBlockField(blockId, "prodOutput", results.result, "NotReady");
|
|
596
|
-
// saving inputs for which we rendered the production
|
|
597
|
-
this.setBlockFieldObj(blockId, "prodArgs", info.fields.currentArgs);
|
|
598
|
-
// removing block from limbo as we juts rendered fresh production for it
|
|
599
|
-
if (this.blocksInLimbo.delete(blockId))
|
|
600
|
-
this.renderingStateChanged = true;
|
|
601
|
-
}
|
|
602
|
-
//
|
|
603
|
-
// Structure changes
|
|
604
|
-
//
|
|
605
|
-
initializeNewBlock(blockId, spec) {
|
|
606
|
-
const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);
|
|
607
|
-
this.blockInfos.set(blockId, info);
|
|
608
|
-
// block pack
|
|
609
|
-
const bp = createBlockPack(this.tx, spec.blockPack);
|
|
610
|
-
this.setBlockField(blockId, "blockPack", Pl.wrapInHolder(this.tx, bp), "NotReady");
|
|
611
|
-
// settings
|
|
612
|
-
this.setBlockFieldObj(blockId, "blockSettings", this.createJsonFieldValue(InitialBlockSettings));
|
|
613
|
-
const blockConfig = info.config;
|
|
614
|
-
let args;
|
|
615
|
-
let prerunArgs;
|
|
616
|
-
let storageToWrite;
|
|
617
|
-
if (spec.storageMode === "fromModel") {
|
|
618
|
-
// Model API v2+: get initial storage and derive args from it
|
|
619
|
-
storageToWrite = this.projectHelper.getInitialStorageInVM(blockConfig);
|
|
620
|
-
// Derive args directly from storage (VM extracts data internally)
|
|
621
|
-
const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, storageToWrite);
|
|
622
|
-
if (deriveArgsResult.error) {
|
|
623
|
-
args = undefined;
|
|
624
|
-
prerunArgs = undefined;
|
|
625
|
-
}
|
|
626
|
-
else {
|
|
627
|
-
args = deriveArgsResult.value;
|
|
628
|
-
prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, storageToWrite);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
else if (spec.storageMode === "legacy") {
|
|
632
|
-
// Model API v1: use legacyState from spec
|
|
633
|
-
const parsedState = JSON.parse(spec.legacyState);
|
|
634
|
-
args = parsedState.args;
|
|
635
|
-
if (args === undefined) {
|
|
636
|
-
throw new Error("args is undefined in legacyState");
|
|
637
|
-
}
|
|
638
|
-
prerunArgs = args;
|
|
639
|
-
storageToWrite = spec.legacyState;
|
|
640
|
-
}
|
|
641
|
-
else {
|
|
642
|
-
throw new Error(`Unknown storageMode: ${spec.storageMode}`);
|
|
643
|
-
}
|
|
644
|
-
// currentArgs
|
|
645
|
-
if (args !== undefined) {
|
|
646
|
-
this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(args));
|
|
647
|
-
}
|
|
648
|
-
// currentPrerunArgs
|
|
649
|
-
if (prerunArgs !== undefined) {
|
|
650
|
-
this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
|
|
651
|
-
}
|
|
652
|
-
// blockStorage
|
|
653
|
-
this.setBlockFieldObj(blockId, "blockStorage", this.createJsonFieldValueByContent(storageToWrite));
|
|
654
|
-
// checking structure
|
|
655
|
-
info.check();
|
|
656
|
-
}
|
|
657
|
-
getFieldNamesToDuplicate(blockId) {
|
|
658
|
-
const fields = this.getBlockInfo(blockId).fields;
|
|
659
|
-
const diff = (setA, setB) => new Set([...setA].filter((x) => !setB.has(x)));
|
|
660
|
-
// Check if we can safely move to limbo (both core production fields are ready)
|
|
661
|
-
if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready") {
|
|
662
|
-
if (this.blocksInLimbo.has(blockId))
|
|
663
|
-
// we are already in limbo
|
|
664
|
-
return FieldsToDuplicate;
|
|
665
|
-
return diff(FieldsToDuplicate, new Set(["prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious"]));
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
return diff(FieldsToDuplicate, new Set([
|
|
669
|
-
"prodOutput",
|
|
670
|
-
"prodCtx",
|
|
671
|
-
"prodUiCtx",
|
|
672
|
-
"prodArgs",
|
|
673
|
-
"prodOutputPrevious",
|
|
674
|
-
"prodCtxPrevious",
|
|
675
|
-
"prodUiCtxPrevious",
|
|
676
|
-
]));
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
initializeBlockDuplicate(blockId, originalBlockInfo) {
|
|
680
|
-
const info = new BlockInfo(blockId, {}, originalBlockInfo.config, originalBlockInfo.source);
|
|
681
|
-
this.blockInfos.set(blockId, info);
|
|
682
|
-
const fieldNamesToDuplicate = this.getFieldNamesToDuplicate(blockId);
|
|
683
|
-
// Copy all fields from original block to new block by sharing references
|
|
684
|
-
for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) {
|
|
685
|
-
if (fieldNamesToDuplicate.has(fieldName) &&
|
|
686
|
-
fieldState &&
|
|
687
|
-
fieldState.ref) {
|
|
688
|
-
this.setBlockFieldObj(blockId, fieldName, {
|
|
689
|
-
ref: fieldState.ref,
|
|
690
|
-
status: fieldState.status,
|
|
691
|
-
value: fieldState.value,
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
this.resetOrLimboProduction(blockId);
|
|
696
|
-
info.check();
|
|
697
|
-
}
|
|
698
|
-
/** Very generic method, better check for more specialized case-specific methods first. */
|
|
699
|
-
updateStructure(newStructure, newBlockInitializer = NoNewBlocks) {
|
|
700
|
-
const currentStagingGraph = this.getStagingGraph();
|
|
701
|
-
const currentActualProductionGraph = this.getActualProductionGraph();
|
|
702
|
-
const newStagingGraph = stagingGraph(newStructure);
|
|
703
|
-
const stagingDiff = graphDiff(currentStagingGraph, newStagingGraph);
|
|
704
|
-
// removing blocks
|
|
705
|
-
for (const blockId of stagingDiff.onlyInA) {
|
|
706
|
-
const { fields } = this.getBlockInfo(blockId);
|
|
707
|
-
this.deleteBlockFields(blockId, ...Object.keys(fields));
|
|
708
|
-
this.blockInfos.delete(blockId);
|
|
709
|
-
if (this.blocksInLimbo.delete(blockId))
|
|
710
|
-
this.renderingStateChanged = true;
|
|
711
|
-
}
|
|
712
|
-
// creating new blocks
|
|
713
|
-
for (const blockId of stagingDiff.onlyInB) {
|
|
714
|
-
newBlockInitializer(blockId);
|
|
715
|
-
}
|
|
716
|
-
// resetting stagings affected by topology change
|
|
717
|
-
for (const blockId of stagingDiff.different)
|
|
718
|
-
this.resetStaging(blockId);
|
|
719
|
-
// new actual production graph without new blocks
|
|
720
|
-
const newActualProductionGraph = productionGraph(newStructure, (blockId) => this.getProductionGraphBlockInfo(blockId, true));
|
|
721
|
-
const prodDiff = graphDiff(currentActualProductionGraph, newActualProductionGraph);
|
|
722
|
-
// applying changes due to topology change in production to affected nodes and
|
|
723
|
-
// all their downstreams
|
|
724
|
-
currentActualProductionGraph.traverse("downstream", [...prodDiff.different], (node) => {
|
|
725
|
-
this.resetOrLimboProduction(node.id);
|
|
726
|
-
});
|
|
727
|
-
if (stagingDiff.onlyInB.size > 0 ||
|
|
728
|
-
stagingDiff.onlyInA.size > 0 ||
|
|
729
|
-
stagingDiff.different.size > 0)
|
|
730
|
-
this.resetStagingRefreshTimestamp();
|
|
731
|
-
this.struct = newStructure;
|
|
732
|
-
this.structureChanged = true;
|
|
733
|
-
this.stagingGraph = undefined;
|
|
734
|
-
this.pendingProductionGraph = undefined;
|
|
735
|
-
this.actualProductionGraph = undefined;
|
|
736
|
-
this.updateLastModified();
|
|
737
|
-
}
|
|
738
|
-
//
|
|
739
|
-
// Structure change helpers
|
|
740
|
-
//
|
|
741
|
-
addBlock(block, spec, before) {
|
|
742
|
-
const newStruct = this.structure; // copy current structure
|
|
743
|
-
if (before === undefined) {
|
|
744
|
-
// adding as a very last block
|
|
745
|
-
newStruct.groups[newStruct.groups.length - 1].blocks.push(block);
|
|
746
|
-
}
|
|
747
|
-
else {
|
|
748
|
-
let done = false;
|
|
749
|
-
for (const group of newStruct.groups) {
|
|
750
|
-
const idx = group.blocks.findIndex((b) => b.id === before);
|
|
751
|
-
if (idx < 0)
|
|
752
|
-
continue;
|
|
753
|
-
group.blocks.splice(idx, 0, block);
|
|
754
|
-
done = true;
|
|
755
|
-
break;
|
|
756
|
-
}
|
|
757
|
-
if (!done)
|
|
758
|
-
throw new Error(`Can't find element with id: ${before}`);
|
|
759
|
-
}
|
|
760
|
-
this.updateStructure(newStruct, (blockId) => {
|
|
761
|
-
if (blockId !== block.id)
|
|
762
|
-
throw new Error("Unexpected");
|
|
763
|
-
this.initializeNewBlock(blockId, spec);
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* Duplicates an existing block by copying all its fields and structure.
|
|
768
|
-
* This method creates a deep copy of the block at the mutator level.
|
|
769
|
-
*
|
|
770
|
-
* @param originalBlockId id of the block to duplicate
|
|
771
|
-
* @param newBlockId id for the new duplicated block
|
|
772
|
-
* @param after id of the block to insert new block after
|
|
773
|
-
*/
|
|
774
|
-
duplicateBlock(originalBlockId, newBlockId, after) {
|
|
775
|
-
// Get the original block from structure
|
|
776
|
-
const originalBlock = this.getBlock(originalBlockId);
|
|
777
|
-
const originalBlockInfo = this.getBlockInfo(originalBlockId);
|
|
778
|
-
// Create new block in structure
|
|
779
|
-
const newBlock = {
|
|
780
|
-
id: newBlockId,
|
|
781
|
-
label: originalBlock.label,
|
|
782
|
-
renderingMode: originalBlock.renderingMode,
|
|
783
|
-
};
|
|
784
|
-
// Add the new block to structure
|
|
785
|
-
const newStruct = this.structure; // copy current structure
|
|
786
|
-
if (after === undefined) {
|
|
787
|
-
// adding as a very last block
|
|
788
|
-
newStruct.groups[newStruct.groups.length - 1].blocks.push(newBlock);
|
|
789
|
-
}
|
|
790
|
-
else {
|
|
791
|
-
let done = false;
|
|
792
|
-
for (const group of newStruct.groups) {
|
|
793
|
-
const idx = group.blocks.findIndex((b) => b.id === after);
|
|
794
|
-
if (idx < 0)
|
|
795
|
-
continue;
|
|
796
|
-
group.blocks.splice(idx + 1, 0, newBlock);
|
|
797
|
-
done = true;
|
|
798
|
-
break;
|
|
799
|
-
}
|
|
800
|
-
if (!done)
|
|
801
|
-
throw new Error(`Can't find element with id: ${after}`);
|
|
802
|
-
}
|
|
803
|
-
this.updateStructure(newStruct, (blockId) => {
|
|
804
|
-
if (blockId !== newBlockId)
|
|
805
|
-
throw new Error("Unexpected");
|
|
806
|
-
this.initializeBlockDuplicate(blockId, originalBlockInfo);
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
deleteBlock(blockId) {
|
|
810
|
-
const newStruct = this.structure; // copy current structure
|
|
811
|
-
let done = false;
|
|
812
|
-
for (const group of newStruct.groups) {
|
|
813
|
-
const idx = group.blocks.findIndex((b) => b.id === blockId);
|
|
814
|
-
if (idx < 0)
|
|
815
|
-
continue;
|
|
816
|
-
group.blocks.splice(idx, 1);
|
|
817
|
-
done = true;
|
|
818
|
-
break;
|
|
819
|
-
}
|
|
820
|
-
if (!done)
|
|
821
|
-
throw new Error(`Can't find element with id: ${blockId}`);
|
|
822
|
-
this.updateStructure(newStruct);
|
|
823
|
-
}
|
|
824
|
-
//
|
|
825
|
-
// Block-pack migration
|
|
826
|
-
//
|
|
827
|
-
migrateBlockPack(blockId, spec, newClearState) {
|
|
828
|
-
const info = this.getBlockInfo(blockId);
|
|
829
|
-
const newConfig = extractConfig(spec.config);
|
|
830
|
-
const persistBlockPack = () => {
|
|
831
|
-
this.setBlockField(blockId, "blockPack", Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)), "NotReady");
|
|
832
|
-
};
|
|
833
|
-
const applyStorageAndDeriveArgs = (storageJson) => {
|
|
834
|
-
persistBlockPack();
|
|
835
|
-
this.setBlockStorageRaw(blockId, storageJson);
|
|
836
|
-
const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(newConfig, storageJson);
|
|
837
|
-
if (!deriveArgsResult.error) {
|
|
838
|
-
this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(deriveArgsResult.value));
|
|
839
|
-
const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(newConfig, storageJson);
|
|
840
|
-
if (prerunArgs !== undefined) {
|
|
841
|
-
this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
if (newClearState !== undefined) {
|
|
846
|
-
// State is being reset - no migration needed
|
|
847
|
-
const supportsStorageFromVM = newConfig.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION;
|
|
848
|
-
if (supportsStorageFromVM) {
|
|
849
|
-
// V2+: Get initial storage directly from VM and derive args from it
|
|
850
|
-
const initialStorageJson = this.projectHelper.getInitialStorageInVM(newConfig);
|
|
851
|
-
applyStorageAndDeriveArgs(initialStorageJson);
|
|
852
|
-
this.blocksWithChangedInputs.add(blockId);
|
|
853
|
-
this.updateLastModified();
|
|
854
|
-
}
|
|
855
|
-
else {
|
|
856
|
-
// V1: Use setStates with legacy state format
|
|
857
|
-
persistBlockPack();
|
|
858
|
-
this.setStates([{ modelAPIVersion: 1, blockId, state: newClearState.state }]);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
else {
|
|
862
|
-
// State is being preserved - run migrations if needed via VM
|
|
863
|
-
// Only Model API v2 blocks support migrations
|
|
864
|
-
const supportsStateMigrations = newConfig.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION;
|
|
865
|
-
if (supportsStateMigrations) {
|
|
866
|
-
const currentStorageJson = info.blockStorageJson;
|
|
867
|
-
// Attempt migration BEFORE persisting block pack — on failure,
|
|
868
|
-
// block stays on old version (no inconsistent new-code/old-storage state)
|
|
869
|
-
const migrationResult = this.projectHelper.migrateStorageInVM(newConfig, currentStorageJson);
|
|
870
|
-
if (migrationResult.error !== undefined) {
|
|
871
|
-
throw new Error(`[migrateBlockPack] Block ${blockId} migration failed: ${migrationResult.error}`);
|
|
872
|
-
}
|
|
873
|
-
console.log(`[migrateBlockPack] Block ${blockId}: ${migrationResult.info}`);
|
|
874
|
-
applyStorageAndDeriveArgs(migrationResult.newStorageJson);
|
|
875
|
-
}
|
|
876
|
-
else {
|
|
877
|
-
// Legacy blocks (modelAPIVersion 1): persist block pack, set prerunArgs = currentArgs
|
|
878
|
-
persistBlockPack();
|
|
879
|
-
if (info.fields.currentArgs !== undefined) {
|
|
880
|
-
this.setBlockFieldObj(blockId, "currentPrerunArgs", info.fields.currentArgs);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
this.blocksWithChangedInputs.add(blockId);
|
|
884
|
-
// resetting staging outputs for all downstream blocks
|
|
885
|
-
this.getStagingGraph().traverse("downstream", [blockId], ({ id }) => this.resetStaging(id));
|
|
886
|
-
}
|
|
887
|
-
// also reset or limbo all downstream productions
|
|
888
|
-
if (info.productionRendered)
|
|
889
|
-
this.getActualProductionGraph().traverse("downstream", [blockId], ({ id }) => this.resetOrLimboProduction(id));
|
|
890
|
-
this.updateLastModified();
|
|
891
|
-
}
|
|
892
|
-
//
|
|
893
|
-
// Render
|
|
894
|
-
//
|
|
895
|
-
renderProduction(blockIds, addUpstreams = false) {
|
|
896
|
-
const blockIdsSet = new Set(blockIds);
|
|
897
|
-
const prodGraph = this.getPendingProductionGraph();
|
|
898
|
-
if (addUpstreams)
|
|
899
|
-
// adding all upstreams automatically
|
|
900
|
-
prodGraph.traverse("upstream", blockIds, (node) => {
|
|
901
|
-
blockIdsSet.add(node.id);
|
|
902
|
-
});
|
|
903
|
-
else
|
|
904
|
-
// checking that targets contain all upstreams
|
|
905
|
-
for (const blockId of blockIdsSet) {
|
|
906
|
-
const node = prodGraph.nodes.get(blockId);
|
|
907
|
-
if (node === undefined)
|
|
908
|
-
throw new Error(`Can't find block with id: ${blockId}`);
|
|
909
|
-
for (const upstream of node.upstream)
|
|
910
|
-
if (!blockIdsSet.has(upstream))
|
|
911
|
-
throw new Error("Can't render blocks not including all upstreams.");
|
|
912
|
-
}
|
|
913
|
-
// traversing in topological order and rendering target blocks
|
|
914
|
-
const rendered = new Set();
|
|
915
|
-
for (const block of allBlocks(this.structure)) {
|
|
916
|
-
if (!blockIdsSet.has(block.id))
|
|
917
|
-
continue;
|
|
918
|
-
let render = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);
|
|
919
|
-
if (!render)
|
|
920
|
-
for (const upstream of prodGraph.nodes.get(block.id).upstream)
|
|
921
|
-
if (rendered.has(upstream)) {
|
|
922
|
-
render = true;
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
if (render) {
|
|
926
|
-
this.renderProductionFor(block.id);
|
|
927
|
-
rendered.add(block.id);
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
const renderedArray = [...rendered];
|
|
931
|
-
// sending to limbo all downstream blocks
|
|
932
|
-
prodGraph.traverse("downstream", renderedArray, (node) => {
|
|
933
|
-
if (rendered.has(node.id))
|
|
934
|
-
// don't send to limbo blocks that were just rendered
|
|
935
|
-
return;
|
|
936
|
-
this.resetOrLimboProduction(node.id);
|
|
937
|
-
});
|
|
938
|
-
// resetting staging outputs for all downstream blocks
|
|
939
|
-
this.getStagingGraph().traverse("downstream", renderedArray, ({ id }) => {
|
|
940
|
-
// don't reset staging of the first rendered block
|
|
941
|
-
if (renderedArray[0] !== id)
|
|
942
|
-
this.resetStaging(id);
|
|
943
|
-
});
|
|
944
|
-
if (rendered.size > 0)
|
|
945
|
-
this.updateLastModified();
|
|
946
|
-
return rendered;
|
|
947
|
-
}
|
|
948
|
-
/** Stops running blocks from the list and modify states of other blocks
|
|
949
|
-
* accordingly */
|
|
950
|
-
stopProduction(...blockIds) {
|
|
951
|
-
const activeProdGraph = this.getActualProductionGraph();
|
|
952
|
-
// we will stop all blocks listed in request and all their downstreams
|
|
953
|
-
const queue = new Denque(blockIds);
|
|
954
|
-
const queued = new Set(blockIds);
|
|
955
|
-
const stopped = [];
|
|
956
|
-
while (!queue.isEmpty()) {
|
|
957
|
-
const blockId = queue.shift();
|
|
958
|
-
const fields = this.getBlockInfo(blockId).fields;
|
|
959
|
-
if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready")
|
|
960
|
-
// skipping finished blocks
|
|
961
|
-
continue;
|
|
962
|
-
if (this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs")) {
|
|
963
|
-
// was actually stopped
|
|
964
|
-
stopped.push(blockId);
|
|
965
|
-
// will try to stop all its downstreams
|
|
966
|
-
for (const downstream of activeProdGraph.traverseIdsExcludingRoots("downstream", blockId)) {
|
|
967
|
-
if (queued.has(downstream))
|
|
968
|
-
continue;
|
|
969
|
-
queue.push(downstream);
|
|
970
|
-
queued.add(downstream);
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
// blocks under stopped blocks, but having finished production results, goes to limbo
|
|
975
|
-
for (const blockId of activeProdGraph.traverseIdsExcludingRoots("downstream", ...stopped))
|
|
976
|
-
this.resetOrLimboProduction(blockId);
|
|
977
|
-
// reset staging outputs for all downstream blocks
|
|
978
|
-
this.getStagingGraph().traverse("downstream", stopped, ({ id }) => this.resetStaging(id));
|
|
979
|
-
}
|
|
980
|
-
traverseWithStagingLag(cb) {
|
|
981
|
-
const lags = new Map();
|
|
982
|
-
const stagingGraph = this.getStagingGraph();
|
|
983
|
-
stagingGraph.nodes.forEach((node) => {
|
|
984
|
-
const info = this.getBlockInfo(node.id);
|
|
985
|
-
// Use requireStagingRendering to check both: staging exists AND prerunArgs hasn't changed
|
|
986
|
-
const requiresRendering = info.requireStagingRendering;
|
|
987
|
-
let lag = requiresRendering ? 1 : 0;
|
|
988
|
-
node.upstream.forEach((upstream) => {
|
|
989
|
-
const upstreamLag = lags.get(upstream);
|
|
990
|
-
if (upstreamLag === 0)
|
|
991
|
-
return;
|
|
992
|
-
lag = Math.max(upstreamLag + 1, lag);
|
|
993
|
-
});
|
|
994
|
-
if (!requiresRendering && info.stagingRendered) ;
|
|
995
|
-
cb(node.id, lag);
|
|
996
|
-
lags.set(node.id, lag);
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
/** @param stagingRenderingRate rate in blocks per second */
|
|
1000
|
-
refreshStagings(stagingRenderingRate) {
|
|
1001
|
-
const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;
|
|
1002
|
-
const lagThreshold = stagingRenderingRate === undefined
|
|
1003
|
-
? undefined
|
|
1004
|
-
: 1 + Math.max(0, (elapsed * stagingRenderingRate) / 1000);
|
|
1005
|
-
let rendered = 0;
|
|
1006
|
-
this.traverseWithStagingLag((blockId, lag) => {
|
|
1007
|
-
if (lag === 0)
|
|
1008
|
-
// meaning staging already rendered
|
|
1009
|
-
return;
|
|
1010
|
-
if (lagThreshold === undefined || lag <= lagThreshold) {
|
|
1011
|
-
// console.log(`[refreshStagings] RENDER staging for ${blockId} (lag=${lag})`);
|
|
1012
|
-
this.renderStagingFor(blockId);
|
|
1013
|
-
rendered++;
|
|
1014
|
-
}
|
|
1015
|
-
});
|
|
1016
|
-
if (rendered > 0)
|
|
1017
|
-
this.resetStagingRefreshTimestamp();
|
|
1018
|
-
}
|
|
1019
|
-
//
|
|
1020
|
-
// Meta
|
|
1021
|
-
//
|
|
1022
|
-
/** Updates project metadata */
|
|
1023
|
-
setMeta(meta) {
|
|
1024
|
-
this.meta = meta;
|
|
1025
|
-
this.metaChanged = true;
|
|
1026
|
-
this.updateLastModified();
|
|
1027
|
-
}
|
|
1028
|
-
//
|
|
1029
|
-
// Maintenance
|
|
1030
|
-
//
|
|
1031
|
-
/** @param stagingRenderingRate rate in blocks per second */
|
|
1032
|
-
doRefresh(stagingRenderingRate) {
|
|
1033
|
-
this.refreshStagings(stagingRenderingRate);
|
|
1034
|
-
this.blockInfos.forEach((blockInfo) => {
|
|
1035
|
-
if (blockInfo.fields.prodCtx?.status === "Ready" &&
|
|
1036
|
-
blockInfo.fields.prodOutput?.status === "Ready")
|
|
1037
|
-
this.deleteBlockFields(blockInfo.id, "prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious");
|
|
1038
|
-
if (blockInfo.fields.stagingCtx?.status === "Ready" &&
|
|
1039
|
-
blockInfo.fields.stagingOutput?.status === "Ready")
|
|
1040
|
-
this.deleteBlockFields(blockInfo.id, "stagingOutputPrevious", "stagingCtxPrevious", "stagingUiCtxPrevious");
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
assignAuthorMarkers() {
|
|
1044
|
-
const markerStr = this.author ? JSON.stringify(this.author) : undefined;
|
|
1045
|
-
for (const blockId of this.blocksWithChangedInputs)
|
|
1046
|
-
if (markerStr === undefined)
|
|
1047
|
-
this.tx.deleteKValue(this.rid, blockArgsAuthorKey(blockId));
|
|
1048
|
-
else
|
|
1049
|
-
this.tx.setKValue(this.rid, blockArgsAuthorKey(blockId), markerStr);
|
|
1050
|
-
if (this.metaChanged || this.structureChanged) {
|
|
1051
|
-
if (markerStr === undefined)
|
|
1052
|
-
this.tx.deleteKValue(this.rid, ProjectStructureAuthorKey);
|
|
1053
|
-
else
|
|
1054
|
-
this.tx.setKValue(this.rid, ProjectStructureAuthorKey, markerStr);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
save() {
|
|
1058
|
-
if (!this.wasModified)
|
|
1059
|
-
return;
|
|
1060
|
-
if (this.lastModifiedChanged)
|
|
1061
|
-
this.tx.setKValue(this.rid, ProjectLastModifiedTimestamp, JSON.stringify(this.lastModified));
|
|
1062
|
-
if (this.structureChanged)
|
|
1063
|
-
this.tx.setKValue(this.rid, ProjectStructureKey, JSON.stringify(this.struct));
|
|
1064
|
-
if (this.renderingStateChanged)
|
|
1065
|
-
this.tx.setKValue(this.rid, BlockRenderingStateKey, JSON.stringify({
|
|
1066
|
-
...this.renderingState,
|
|
1067
|
-
blocksInLimbo: [...this.blocksInLimbo],
|
|
1068
|
-
}));
|
|
1069
|
-
if (this.metaChanged)
|
|
1070
|
-
this.tx.setKValue(this.rid, ProjectMetaKey, JSON.stringify(this.meta));
|
|
1071
|
-
this.assignAuthorMarkers();
|
|
1072
|
-
}
|
|
1073
|
-
static async load(projectHelper, tx, rid, author) {
|
|
1074
|
-
//
|
|
1075
|
-
// Sending initial requests to read project state (start of round-trip #1)
|
|
1076
|
-
//
|
|
1077
|
-
const fullResourceStateP = tx.getResourceData(rid, true);
|
|
1078
|
-
const schemaP = tx.getKValueJson(rid, SchemaVersionKey);
|
|
1079
|
-
const lastModifiedP = tx.getKValueJson(rid, ProjectLastModifiedTimestamp);
|
|
1080
|
-
const metaP = tx.getKValueJson(rid, ProjectMetaKey);
|
|
1081
|
-
const structureP = tx.getKValueJson(rid, ProjectStructureKey);
|
|
1082
|
-
const renderingStateP = tx.getKValueJson(rid, BlockRenderingStateKey);
|
|
1083
|
-
const fullResourceState = await fullResourceStateP;
|
|
1084
|
-
// loading field information
|
|
1085
|
-
const blockInfoStates = new Map();
|
|
1086
|
-
for (const f of fullResourceState.fields) {
|
|
1087
|
-
const projectField = parseProjectField(f.name);
|
|
1088
|
-
// processing only fields with known structure
|
|
1089
|
-
if (projectField === undefined)
|
|
1090
|
-
continue;
|
|
1091
|
-
let info = blockInfoStates.get(projectField.blockId);
|
|
1092
|
-
if (info === undefined) {
|
|
1093
|
-
info = {
|
|
1094
|
-
id: projectField.blockId,
|
|
1095
|
-
fields: {},
|
|
1096
|
-
};
|
|
1097
|
-
blockInfoStates.set(projectField.blockId, info);
|
|
1098
|
-
}
|
|
1099
|
-
info.fields[projectField.fieldName] = isNullResourceId(f.value)
|
|
1100
|
-
? { modCount: 0 }
|
|
1101
|
-
: { modCount: 0, ref: f.value };
|
|
1102
|
-
}
|
|
1103
|
-
//
|
|
1104
|
-
// Roundtrip #1 not yet finished, but as soon as field list is received,
|
|
1105
|
-
// we can start sending requests to read states of referenced resources
|
|
1106
|
-
// (start of round-trip #2)
|
|
1107
|
-
//
|
|
1108
|
-
const blockFieldRequests = [];
|
|
1109
|
-
blockInfoStates.forEach((info) => {
|
|
1110
|
-
const fields = info.fields;
|
|
1111
|
-
for (const [fName, state] of Object.entries(fields)) {
|
|
1112
|
-
if (state.ref === undefined)
|
|
1113
|
-
continue;
|
|
1114
|
-
if (!isResource(state.ref) || isResourceRef(state.ref))
|
|
1115
|
-
throw new Error("unexpected behaviour");
|
|
1116
|
-
const fieldName = fName;
|
|
1117
|
-
blockFieldRequests.push([
|
|
1118
|
-
info,
|
|
1119
|
-
fieldName,
|
|
1120
|
-
state,
|
|
1121
|
-
tx.getResourceData(state.ref, fieldName == "blockPack"),
|
|
1122
|
-
]);
|
|
1123
|
-
}
|
|
1124
|
-
});
|
|
1125
|
-
// loading jsons
|
|
1126
|
-
const [schema, lastModified, meta, structure, { stagingRefreshTimestamp, blocksInLimbo }] = await Promise.all([schemaP, lastModifiedP, metaP, structureP, renderingStateP]);
|
|
1127
|
-
// Checking schema version of the project
|
|
1128
|
-
if (schema !== SchemaVersionCurrent) {
|
|
1129
|
-
if (Number(schema) < Number(SchemaVersionCurrent))
|
|
1130
|
-
throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);
|
|
1131
|
-
else
|
|
1132
|
-
throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);
|
|
1133
|
-
}
|
|
1134
|
-
//
|
|
1135
|
-
// <- at this point we have all the responses from round-trip #1
|
|
1136
|
-
//
|
|
1137
|
-
//
|
|
1138
|
-
// Receiving responses from round-trip #2 and sending requests to read block pack descriptions
|
|
1139
|
-
// (start of round-trip #3)
|
|
1140
|
-
//
|
|
1141
|
-
const blockPackRequests = [];
|
|
1142
|
-
for (const [info, fieldName, state, response] of blockFieldRequests) {
|
|
1143
|
-
const result = await response;
|
|
1144
|
-
state.value = result.data;
|
|
1145
|
-
if (isNotNullResourceId(result.error))
|
|
1146
|
-
state.status = "Error";
|
|
1147
|
-
else if (result.resourceReady || isNotNullResourceId(result.originalResourceId))
|
|
1148
|
-
state.status = "Ready";
|
|
1149
|
-
else
|
|
1150
|
-
state.status = "NotReady";
|
|
1151
|
-
// For block pack we need to traverse the ref field from the resource data
|
|
1152
|
-
if (fieldName === "blockPack") {
|
|
1153
|
-
const refField = result.fields.find((f) => f.name === Pl.HolderRefField);
|
|
1154
|
-
if (refField === undefined)
|
|
1155
|
-
throw new Error("Block pack ref field is missing");
|
|
1156
|
-
blockPackRequests.push([
|
|
1157
|
-
info,
|
|
1158
|
-
tx.getResourceData(ensureResourceIdNotNull(refField.value), false),
|
|
1159
|
-
]);
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
//
|
|
1163
|
-
// <- at this point we have all the responses from round-trip #2
|
|
1164
|
-
//
|
|
1165
|
-
for (const [info, response] of blockPackRequests) {
|
|
1166
|
-
const result = await response;
|
|
1167
|
-
const bpInfo = cachedDeserialize(notEmpty(result.data));
|
|
1168
|
-
info.blockConfig = extractConfig(bpInfo.config);
|
|
1169
|
-
info.blockPack = bpInfo.source;
|
|
1170
|
-
}
|
|
1171
|
-
//
|
|
1172
|
-
// <- at this point we have all the responses from round-trip #3
|
|
1173
|
-
//
|
|
1174
|
-
// loading ctx export template to check if we already have cached materialized template in our project
|
|
1175
|
-
const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();
|
|
1176
|
-
// expected field name
|
|
1177
|
-
const ctxExportTplCacheFieldName = getServiceTemplateField(ctxExportTplEnvelope.hash);
|
|
1178
|
-
const ctxExportTplField = fullResourceState.fields.find((f) => f.name === ctxExportTplCacheFieldName);
|
|
1179
|
-
let ctxExportTplHolder;
|
|
1180
|
-
if (ctxExportTplField !== undefined)
|
|
1181
|
-
ctxExportTplHolder = ensureResourceIdNotNull(ctxExportTplField.value);
|
|
1182
|
-
else {
|
|
1183
|
-
ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));
|
|
1184
|
-
tx.createField(field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)), "Dynamic", ctxExportTplHolder);
|
|
1185
|
-
}
|
|
1186
|
-
const renderingState = { stagingRefreshTimestamp };
|
|
1187
|
-
const blocksInLimboSet = new Set(blocksInLimbo);
|
|
1188
|
-
const blockInfos = new Map();
|
|
1189
|
-
blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id, new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));
|
|
1190
|
-
// check consistency of project state
|
|
1191
|
-
const blockInStruct = new Set();
|
|
1192
|
-
for (const b of allBlocks(structure)) {
|
|
1193
|
-
if (!blockInfos.has(b.id))
|
|
1194
|
-
throw new Error(`Inconsistent project structure: no inputs for ${b.id}`);
|
|
1195
|
-
blockInStruct.add(b.id);
|
|
1196
|
-
}
|
|
1197
|
-
blockInfos.forEach((info) => {
|
|
1198
|
-
if (!blockInStruct.has(info.id))
|
|
1199
|
-
throw new Error(`Inconsistent project structure: no structure entry for ${info.id}`);
|
|
1200
|
-
// checking structure
|
|
1201
|
-
info.check();
|
|
1202
|
-
});
|
|
1203
|
-
const prj = new ProjectMutator(rid, tx, author, schema, lastModified, meta, structure, renderingState, blocksInLimboSet, blockInfos, ctxExportTplHolder, projectHelper);
|
|
1204
|
-
prj.fixProblemsAndMigrate();
|
|
1205
|
-
return prj;
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
876
|
async function createProject(tx, meta = InitialBlockMeta) {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
877
|
+
const prj = tx.createEphemeral(ProjectResourceType);
|
|
878
|
+
tx.lock(prj);
|
|
879
|
+
const ts = String(Date.now());
|
|
880
|
+
tx.setKValue(prj, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));
|
|
881
|
+
tx.setKValue(prj, ProjectCreatedTimestamp, ts);
|
|
882
|
+
tx.setKValue(prj, ProjectLastModifiedTimestamp, ts);
|
|
883
|
+
tx.setKValue(prj, ProjectMetaKey, JSON.stringify(meta));
|
|
884
|
+
tx.setKValue(prj, ProjectStructureKey, JSON.stringify(InitialBlockStructure));
|
|
885
|
+
tx.setKValue(prj, BlockRenderingStateKey, JSON.stringify(InitialProjectRenderingState));
|
|
886
|
+
const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();
|
|
887
|
+
tx.createField(field(prj, getServiceTemplateField(ctxExportTplEnvelope.hash)), "Dynamic", Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec)));
|
|
888
|
+
return prj;
|
|
1221
889
|
}
|
|
1222
890
|
async function withProject(projectHelper, txOrPl, rid, cb, ops) {
|
|
1223
|
-
|
|
891
|
+
return withProjectAuthored(projectHelper, txOrPl, rid, void 0, cb, ops);
|
|
1224
892
|
}
|
|
1225
893
|
async function withProjectAuthored(projectHelper, txOrPl, rid, author, cb, ops = {}) {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);
|
|
1242
|
-
const result = await cb(mut);
|
|
1243
|
-
mut.save();
|
|
1244
|
-
return result;
|
|
1245
|
-
}
|
|
894
|
+
if (txOrPl instanceof PlClient) return await txOrPl.withWriteTx("ProjectAction" + (ops.name ? `: ${ops.name}` : ""), async (tx) => {
|
|
895
|
+
const mut = await ProjectMutator.load(projectHelper, tx, rid, author);
|
|
896
|
+
const result = await cb(mut);
|
|
897
|
+
if (!mut.wasModified) return result;
|
|
898
|
+
mut.save();
|
|
899
|
+
await tx.commit();
|
|
900
|
+
if (getDebugFlags().logProjectMutationStat) console.log(JSON.stringify(tx.stat));
|
|
901
|
+
return result;
|
|
902
|
+
}, ops);
|
|
903
|
+
else {
|
|
904
|
+
const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);
|
|
905
|
+
const result = await cb(mut);
|
|
906
|
+
mut.save();
|
|
907
|
+
return result;
|
|
908
|
+
}
|
|
1246
909
|
}
|
|
1247
910
|
|
|
1248
|
-
|
|
1249
|
-
|
|
911
|
+
//#endregion
|
|
912
|
+
export { createProject, withProject, withProjectAuthored };
|
|
913
|
+
//# sourceMappingURL=project.js.map
|