@milaboratories/pl-middle-layer 1.42.2 → 1.42.4
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/block_registry/index.d.ts +0 -1
- package/dist/block_registry/registry-v2-provider.cjs +22 -0
- package/dist/block_registry/registry-v2-provider.cjs.map +1 -0
- package/dist/block_registry/registry-v2-provider.d.ts +0 -1
- package/dist/block_registry/registry-v2-provider.js +20 -0
- package/dist/block_registry/registry-v2-provider.js.map +1 -0
- package/dist/block_registry/registry.cjs +231 -0
- package/dist/block_registry/registry.cjs.map +1 -0
- package/dist/block_registry/registry.d.ts +0 -1
- package/dist/block_registry/registry.js +227 -0
- package/dist/block_registry/registry.js.map +1 -0
- package/dist/block_registry/registry.test.d.ts +0 -1
- package/dist/block_registry/watcher.cjs +174 -0
- package/dist/block_registry/watcher.cjs.map +1 -0
- package/dist/block_registry/watcher.d.ts +0 -1
- package/dist/block_registry/watcher.js +171 -0
- package/dist/block_registry/watcher.js.map +1 -0
- package/dist/block_registry/well_known_registries.cjs +19 -0
- package/dist/block_registry/well_known_registries.cjs.map +1 -0
- package/dist/block_registry/well_known_registries.d.ts +0 -1
- package/dist/block_registry/well_known_registries.js +15 -0
- package/dist/block_registry/well_known_registries.js.map +1 -0
- package/dist/cfg_render/executor.cjs +159 -0
- package/dist/cfg_render/executor.cjs.map +1 -0
- package/dist/cfg_render/executor.d.ts +0 -1
- package/dist/cfg_render/executor.js +156 -0
- package/dist/cfg_render/executor.js.map +1 -0
- package/dist/cfg_render/executor.test.d.ts +0 -1
- package/dist/cfg_render/operation.d.ts +0 -1
- package/dist/cfg_render/renderer.cjs +528 -0
- package/dist/cfg_render/renderer.cjs.map +1 -0
- package/dist/cfg_render/renderer.d.ts +0 -1
- package/dist/cfg_render/renderer.js +525 -0
- package/dist/cfg_render/renderer.js.map +1 -0
- package/dist/cfg_render/traverse.cjs +65 -0
- package/dist/cfg_render/traverse.cjs.map +1 -0
- package/dist/cfg_render/traverse.d.ts +0 -1
- package/dist/cfg_render/traverse.js +63 -0
- package/dist/cfg_render/traverse.js.map +1 -0
- package/dist/cfg_render/util.cjs +32 -0
- package/dist/cfg_render/util.cjs.map +1 -0
- package/dist/cfg_render/util.d.ts +0 -1
- package/dist/cfg_render/util.js +28 -0
- package/dist/cfg_render/util.js.map +1 -0
- package/dist/debug/index.cjs +21 -0
- package/dist/debug/index.cjs.map +1 -0
- package/dist/debug/index.d.ts +0 -1
- package/dist/debug/index.js +19 -0
- package/dist/debug/index.js.map +1 -0
- package/dist/dev_env/index.cjs +59 -0
- package/dist/dev_env/index.cjs.map +1 -0
- package/dist/dev_env/index.d.ts +0 -1
- package/dist/dev_env/index.js +48 -0
- package/dist/dev_env/index.js.map +1 -0
- package/dist/dev_env/util.cjs +37 -0
- package/dist/dev_env/util.cjs.map +1 -0
- package/dist/dev_env/util.d.ts +0 -1
- package/dist/dev_env/util.js +16 -0
- package/dist/dev_env/util.js.map +1 -0
- package/dist/index.cjs +74 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +15 -75
- package/dist/index.js.map +1 -1
- package/dist/js_render/computable_context.cjs +525 -0
- package/dist/js_render/computable_context.cjs.map +1 -0
- package/dist/js_render/computable_context.d.ts +0 -1
- package/dist/js_render/computable_context.js +523 -0
- package/dist/js_render/computable_context.js.map +1 -0
- package/dist/js_render/context.cjs +229 -0
- package/dist/js_render/context.cjs.map +1 -0
- package/dist/js_render/context.d.ts +0 -1
- package/dist/js_render/context.js +226 -0
- package/dist/js_render/context.js.map +1 -0
- package/dist/js_render/index.cjs +163 -0
- package/dist/js_render/index.cjs.map +1 -0
- package/dist/js_render/index.d.ts +0 -1
- package/dist/js_render/index.js +160 -0
- package/dist/js_render/index.js.map +1 -0
- package/dist/middle_layer/active_cfg.cjs +37 -0
- package/dist/middle_layer/active_cfg.cjs.map +1 -0
- package/dist/middle_layer/active_cfg.d.ts +0 -1
- package/dist/middle_layer/active_cfg.js +35 -0
- package/dist/middle_layer/active_cfg.js.map +1 -0
- package/dist/middle_layer/block.cjs +51 -0
- package/dist/middle_layer/block.cjs.map +1 -0
- package/dist/middle_layer/block.d.ts +0 -1
- package/dist/middle_layer/block.js +48 -0
- package/dist/middle_layer/block.js.map +1 -0
- package/dist/middle_layer/block_ctx.cjs +87 -0
- package/dist/middle_layer/block_ctx.cjs.map +1 -0
- package/dist/middle_layer/block_ctx.d.ts +0 -1
- package/dist/middle_layer/block_ctx.js +84 -0
- package/dist/middle_layer/block_ctx.js.map +1 -0
- package/dist/middle_layer/block_ctx_unsafe.cjs +19 -0
- package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -0
- package/dist/middle_layer/block_ctx_unsafe.d.ts +0 -1
- package/dist/middle_layer/block_ctx_unsafe.js +16 -0
- package/dist/middle_layer/block_ctx_unsafe.js.map +1 -0
- package/dist/middle_layer/driver_kit.cjs +42 -0
- package/dist/middle_layer/driver_kit.cjs.map +1 -0
- package/dist/middle_layer/driver_kit.d.ts +0 -1
- package/dist/middle_layer/driver_kit.js +40 -0
- package/dist/middle_layer/driver_kit.js.map +1 -0
- package/dist/middle_layer/frontend_path.cjs +64 -0
- package/dist/middle_layer/frontend_path.cjs.map +1 -0
- package/dist/middle_layer/frontend_path.d.ts +0 -1
- package/dist/middle_layer/frontend_path.js +62 -0
- package/dist/middle_layer/frontend_path.js.map +1 -0
- package/dist/middle_layer/index.d.ts +0 -1
- package/dist/middle_layer/middle_layer.cjs +226 -0
- package/dist/middle_layer/middle_layer.cjs.map +1 -0
- package/dist/middle_layer/middle_layer.d.ts +0 -1
- package/dist/middle_layer/middle_layer.js +224 -0
- package/dist/middle_layer/middle_layer.js.map +1 -0
- package/dist/middle_layer/navigation_states.cjs +41 -0
- package/dist/middle_layer/navigation_states.cjs.map +1 -0
- package/dist/middle_layer/navigation_states.d.ts +0 -1
- package/dist/middle_layer/navigation_states.js +39 -0
- package/dist/middle_layer/navigation_states.js.map +1 -0
- package/dist/middle_layer/ops.cjs +75 -0
- package/dist/middle_layer/ops.cjs.map +1 -0
- package/dist/middle_layer/ops.d.ts +0 -1
- package/dist/middle_layer/ops.js +70 -0
- package/dist/middle_layer/ops.js.map +1 -0
- package/dist/middle_layer/project.cjs +446 -0
- package/dist/middle_layer/project.cjs.map +1 -0
- package/dist/middle_layer/project.d.ts +0 -1
- package/dist/middle_layer/project.js +444 -0
- package/dist/middle_layer/project.js.map +1 -0
- package/dist/middle_layer/project_list.cjs +53 -0
- package/dist/middle_layer/project_list.cjs.map +1 -0
- package/dist/middle_layer/project_list.d.ts +0 -1
- package/dist/middle_layer/project_list.js +48 -0
- package/dist/middle_layer/project_list.js.map +1 -0
- package/dist/middle_layer/project_overview.cjs +225 -0
- package/dist/middle_layer/project_overview.cjs.map +1 -0
- package/dist/middle_layer/project_overview.d.ts +0 -1
- package/dist/middle_layer/project_overview.js +204 -0
- package/dist/middle_layer/project_overview.js.map +1 -0
- package/dist/middle_layer/project_overview_light.cjs +20 -0
- package/dist/middle_layer/project_overview_light.cjs.map +1 -0
- package/dist/middle_layer/project_overview_light.d.ts +0 -1
- package/dist/middle_layer/project_overview_light.js +18 -0
- package/dist/middle_layer/project_overview_light.js.map +1 -0
- package/dist/middle_layer/render.cjs +26 -0
- package/dist/middle_layer/render.cjs.map +1 -0
- package/dist/middle_layer/render.d.ts +0 -1
- package/dist/middle_layer/render.js +23 -0
- package/dist/middle_layer/render.js.map +1 -0
- package/dist/middle_layer/render.test.d.ts +0 -1
- package/dist/middle_layer/types.d.ts +0 -1
- package/dist/middle_layer/util.cjs +22 -0
- package/dist/middle_layer/util.cjs.map +1 -0
- package/dist/middle_layer/util.d.ts +0 -1
- package/dist/middle_layer/util.js +20 -0
- package/dist/middle_layer/util.js.map +1 -0
- package/dist/model/args.cjs +62 -0
- package/dist/model/args.cjs.map +1 -0
- package/dist/model/args.d.ts +0 -1
- package/dist/model/args.js +58 -0
- package/dist/model/args.js.map +1 -0
- package/dist/model/block_pack.d.ts +0 -1
- package/dist/model/block_pack_spec.cjs +11 -0
- package/dist/model/block_pack_spec.cjs.map +1 -0
- package/dist/model/block_pack_spec.d.ts +0 -1
- package/dist/model/block_pack_spec.js +8 -0
- package/dist/model/block_pack_spec.js.map +1 -0
- package/dist/model/frontend.d.ts +0 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/project_helper.cjs +36 -0
- package/dist/model/project_helper.cjs.map +1 -0
- package/dist/model/project_helper.d.ts +0 -1
- package/dist/model/project_helper.js +34 -0
- package/dist/model/project_helper.js.map +1 -0
- package/dist/model/project_model.cjs +74 -0
- package/dist/model/project_model.cjs.map +1 -0
- package/dist/model/project_model.d.ts +0 -1
- package/dist/model/project_model.js +54 -0
- package/dist/model/project_model.js.map +1 -0
- package/dist/model/project_model.test.d.ts +0 -1
- package/dist/model/project_model_util.cjs +176 -0
- package/dist/model/project_model_util.cjs.map +1 -0
- package/dist/model/project_model_util.d.ts +0 -1
- package/dist/model/project_model_util.js +170 -0
- package/dist/model/project_model_util.js.map +1 -0
- package/dist/model/project_model_util.test.d.ts +0 -1
- package/dist/model/project_model_v1.cjs +9 -0
- package/dist/model/project_model_v1.cjs.map +1 -0
- package/dist/model/project_model_v1.d.ts +0 -1
- package/dist/model/project_model_v1.js +6 -0
- package/dist/model/project_model_v1.js.map +1 -0
- package/dist/model/template_spec.d.ts +0 -1
- package/dist/mutator/block-pack/block_pack.cjs +233 -0
- package/dist/mutator/block-pack/block_pack.cjs.map +1 -0
- package/dist/mutator/block-pack/block_pack.d.ts +0 -1
- package/dist/mutator/block-pack/block_pack.js +227 -0
- package/dist/mutator/block-pack/block_pack.js.map +1 -0
- package/dist/mutator/block-pack/block_pack.test.d.ts +0 -1
- package/dist/mutator/block-pack/frontend.cjs +21 -0
- package/dist/mutator/block-pack/frontend.cjs.map +1 -0
- package/dist/mutator/block-pack/frontend.d.ts +0 -1
- package/dist/mutator/block-pack/frontend.js +19 -0
- package/dist/mutator/block-pack/frontend.js.map +1 -0
- package/dist/mutator/context_export.cjs +26 -0
- package/dist/mutator/context_export.cjs.map +1 -0
- package/dist/mutator/context_export.d.ts +2 -3
- package/dist/mutator/context_export.js +23 -0
- package/dist/mutator/context_export.js.map +1 -0
- package/dist/mutator/migration.cjs +57 -0
- package/dist/mutator/migration.cjs.map +1 -0
- package/dist/mutator/migration.d.ts +0 -1
- package/dist/mutator/migration.js +55 -0
- package/dist/mutator/migration.js.map +1 -0
- package/dist/mutator/project.cjs +997 -0
- package/dist/mutator/project.cjs.map +1 -0
- package/dist/mutator/project.d.ts +0 -1
- package/dist/mutator/project.js +992 -0
- package/dist/mutator/project.js.map +1 -0
- package/dist/mutator/project.test.d.ts +0 -1
- package/dist/mutator/template/direct_template_loader.cjs +146 -0
- package/dist/mutator/template/direct_template_loader.cjs.map +1 -0
- package/dist/mutator/template/direct_template_loader.d.ts +0 -1
- package/dist/mutator/template/direct_template_loader.js +143 -0
- package/dist/mutator/template/direct_template_loader.js.map +1 -0
- package/dist/mutator/template/direct_template_loader_v3.cjs +139 -0
- package/dist/mutator/template/direct_template_loader_v3.cjs.map +1 -0
- package/dist/mutator/template/direct_template_loader_v3.d.ts +0 -1
- package/dist/mutator/template/direct_template_loader_v3.js +137 -0
- package/dist/mutator/template/direct_template_loader_v3.js.map +1 -0
- package/dist/mutator/template/render_block.cjs +43 -0
- package/dist/mutator/template/render_block.cjs.map +1 -0
- package/dist/mutator/template/render_block.d.ts +0 -1
- package/dist/mutator/template/render_block.js +34 -0
- package/dist/mutator/template/render_block.js.map +1 -0
- package/dist/mutator/template/render_template.cjs +35 -0
- package/dist/mutator/template/render_template.cjs.map +1 -0
- package/dist/mutator/template/render_template.d.ts +0 -1
- package/dist/mutator/template/render_template.js +33 -0
- package/dist/mutator/template/render_template.js.map +1 -0
- package/dist/mutator/template/template_loading.cjs +71 -0
- package/dist/mutator/template/template_loading.cjs.map +1 -0
- package/dist/mutator/template/template_loading.d.ts +0 -1
- package/dist/mutator/template/template_loading.js +60 -0
- package/dist/mutator/template/template_loading.js.map +1 -0
- package/dist/mutator/template/template_render.test.d.ts +0 -1
- package/dist/network_check/network_check.cjs +267 -0
- package/dist/network_check/network_check.cjs.map +1 -0
- package/dist/network_check/network_check.d.ts +0 -1
- package/dist/network_check/network_check.js +264 -0
- package/dist/network_check/network_check.js.map +1 -0
- package/dist/network_check/network_check.test.d.ts +0 -1
- package/dist/network_check/pings.cjs +107 -0
- package/dist/network_check/pings.cjs.map +1 -0
- package/dist/network_check/pings.d.ts +0 -1
- package/dist/network_check/pings.js +96 -0
- package/dist/network_check/pings.js.map +1 -0
- package/dist/network_check/template.cjs +318 -0
- package/dist/network_check/template.cjs.map +1 -0
- package/dist/network_check/template.d.ts +0 -1
- package/dist/network_check/template.js +302 -0
- package/dist/network_check/template.js.map +1 -0
- package/dist/network_check/template.test.d.ts +0 -1
- package/dist/network_check/test_utils.d.ts +0 -1
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.45.1_tslib@2.7.0_typescript@5.6.3/node_modules/tslib/tslib.es6.cjs +77 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.45.1_tslib@2.7.0_typescript@5.6.3/node_modules/tslib/tslib.es6.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.45.1_tslib@2.7.0_typescript@5.6.3/node_modules/tslib/tslib.es6.js +74 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.45.1_tslib@2.7.0_typescript@5.6.3/node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/pool/data.cjs +298 -0
- package/dist/pool/data.cjs.map +1 -0
- package/dist/pool/data.d.ts +7 -9
- package/dist/pool/data.js +282 -0
- package/dist/pool/data.js.map +1 -0
- package/dist/pool/driver.cjs +620 -0
- package/dist/pool/driver.cjs.map +1 -0
- package/dist/pool/driver.d.ts +0 -1
- package/dist/pool/driver.js +598 -0
- package/dist/pool/driver.js.map +1 -0
- package/dist/pool/index.d.ts +0 -1
- package/dist/pool/p_object_collection.cjs +87 -0
- package/dist/pool/p_object_collection.cjs.map +1 -0
- package/dist/pool/p_object_collection.d.ts +0 -1
- package/dist/pool/p_object_collection.js +84 -0
- package/dist/pool/p_object_collection.js.map +1 -0
- package/dist/pool/ref_count_pool.cjs +58 -0
- package/dist/pool/ref_count_pool.cjs.map +1 -0
- package/dist/pool/ref_count_pool.d.ts +0 -1
- package/dist/pool/ref_count_pool.js +56 -0
- package/dist/pool/ref_count_pool.js.map +1 -0
- package/dist/pool/result_pool.cjs +265 -0
- package/dist/pool/result_pool.cjs.map +1 -0
- package/dist/pool/result_pool.d.ts +0 -1
- package/dist/pool/result_pool.js +263 -0
- package/dist/pool/result_pool.js.map +1 -0
- package/dist/test/block_packs.d.ts +0 -1
- package/dist/test/explicit_templates.d.ts +0 -1
- package/dist/test/known_templates.d.ts +0 -1
- package/dist/test_env.d.ts +0 -1
- package/dist/worker/WorkerManager.cjs +53 -0
- package/dist/worker/WorkerManager.cjs.map +1 -0
- package/dist/worker/WorkerManager.d.ts +0 -1
- package/dist/worker/WorkerManager.js +51 -0
- package/dist/worker/WorkerManager.js.map +1 -0
- package/dist/worker/worker.cjs +16 -0
- package/dist/worker/worker.cjs.map +1 -0
- package/dist/worker/worker.d.ts +0 -1
- package/dist/worker/worker.js +14 -0
- package/dist/worker/worker.js.map +1 -0
- package/dist/worker/workerApi.cjs +20 -0
- package/dist/worker/workerApi.cjs.map +1 -0
- package/dist/worker/workerApi.d.ts +1 -3
- package/dist/worker/workerApi.js +18 -0
- package/dist/worker/workerApi.js.map +1 -0
- package/package.json +25 -33
- package/src/cfg_render/executor.test.ts +5 -4
- package/src/model/project_model.test.ts +3 -3
- package/src/model/project_model_util.test.ts +3 -2
- package/src/mutator/block-pack/block_pack.test.ts +5 -4
- package/src/mutator/project.test.ts +4 -4
- package/src/mutator/template/template_render.test.ts +7 -6
- package/src/network_check/network_check.test.ts +1 -0
- package/src/network_check/test_utils.ts +2 -0
- package/src/worker/WorkerManager.ts +6 -8
- 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.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.map +0 -1
- package/dist/cfg_render/executor.test.d.ts.map +0 -1
- package/dist/cfg_render/operation.d.ts.map +0 -1
- package/dist/cfg_render/renderer.d.ts.map +0 -1
- package/dist/cfg_render/traverse.d.ts.map +0 -1
- package/dist/cfg_render/util.d.ts.map +0 -1
- package/dist/debug/index.d.ts.map +0 -1
- package/dist/dev_env/index.d.ts.map +0 -1
- package/dist/dev_env/util.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.mjs +0 -6742
- package/dist/index.mjs.map +0 -1
- package/dist/js_render/computable_context.d.ts.map +0 -1
- package/dist/js_render/context.d.ts.map +0 -1
- package/dist/js_render/index.d.ts.map +0 -1
- package/dist/middle_layer/active_cfg.d.ts.map +0 -1
- package/dist/middle_layer/block.d.ts.map +0 -1
- package/dist/middle_layer/block_ctx.d.ts.map +0 -1
- 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.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.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.map +0 -1
- package/dist/middle_layer/project_overview.d.ts.map +0 -1
- package/dist/middle_layer/project_overview_light.d.ts.map +0 -1
- package/dist/middle_layer/render.d.ts.map +0 -1
- 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.map +0 -1
- package/dist/model/args.d.ts.map +0 -1
- 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.map +0 -1
- package/dist/model/project_model_util.d.ts.map +0 -1
- package/dist/model/project_model_util.test.d.ts.map +0 -1
- 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.map +0 -1
- package/dist/mutator/block-pack/frontend.d.ts.map +0 -1
- package/dist/mutator/context_export.d.ts.map +0 -1
- package/dist/mutator/migration.d.ts.map +0 -1
- package/dist/mutator/project.d.ts.map +0 -1
- package/dist/mutator/project.test.d.ts.map +0 -1
- package/dist/mutator/template/direct_template_loader.d.ts.map +0 -1
- package/dist/mutator/template/direct_template_loader_v3.d.ts.map +0 -1
- 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.map +0 -1
- package/dist/network_check/network_check.d.ts.map +0 -1
- package/dist/network_check/network_check.test.d.ts.map +0 -1
- package/dist/network_check/pings.d.ts.map +0 -1
- package/dist/network_check/template.d.ts.map +0 -1
- package/dist/network_check/template.test.d.ts.map +0 -1
- 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/ref_count_pool.d.ts.map +0 -1
- package/dist/pool/result_pool.d.ts.map +0 -1
- package/dist/test/block_packs.d.ts.map +0 -1
- package/dist/test/explicit_templates.d.ts.map +0 -1
- package/dist/test/known_templates.d.ts.map +0 -1
- package/dist/test_env.d.ts.map +0 -1
- package/dist/worker/WorkerManager.d.ts.map +0 -1
- package/dist/worker/worker.d.ts.map +0 -1
- package/dist/worker/workerApi.d.ts.map +0 -1
- package/dist/worker.js +0 -2
- package/dist/worker.js.map +0 -1
- package/dist/worker.mjs +0 -20
- package/dist/worker.mjs.map +0 -1
|
@@ -0,0 +1,992 @@
|
|
|
1
|
+
import { field, Pl, PlClient, isResourceId, isNullResourceId, isResource, isResourceRef, isNotNullResourceId, ensureResourceIdNotNull } from '@milaboratories/pl-client';
|
|
2
|
+
import { createBContextFromUpstreams, createRenderHeavyBlock } from './template/render_block.js';
|
|
3
|
+
import { InitialBlockMeta, ProjectResourceType, SchemaVersionKey, SchemaVersionCurrent, ProjectCreatedTimestamp, ProjectLastModifiedTimestamp, ProjectMetaKey, ProjectStructureKey, InitialBlockStructure, BlockRenderingStateKey, InitialProjectRenderingState, getServiceTemplateField, projectFieldName, FieldsToDuplicate, blockArgsAuthorKey, ProjectStructureAuthorKey, parseProjectField } from '../model/project_model.js';
|
|
4
|
+
import { createBlockPack, BlockPackTemplateField } from './block-pack/block_pack.js';
|
|
5
|
+
import { stagingGraph, productionGraph, allBlocks, graphDiff } from '../model/project_model_util.js';
|
|
6
|
+
import { InitialBlockSettings } from '@milaboratories/pl-model-middle-layer';
|
|
7
|
+
import Denque from 'denque';
|
|
8
|
+
import { getPreparedExportTemplateEnvelope, exportContext } from './context_export.js';
|
|
9
|
+
import { loadTemplate } from './template/template_loading.js';
|
|
10
|
+
import { notEmpty, canonicalJsonBytes, canonicalJsonGzBytes, cachedDeserialize } from '@milaboratories/ts-helpers';
|
|
11
|
+
import { extractConfig, UiError } from '@platforma-sdk/model';
|
|
12
|
+
import { getDebugFlags } from '../debug/index.js';
|
|
13
|
+
|
|
14
|
+
function cached(modIdCb, valueCb) {
|
|
15
|
+
let initialized = false;
|
|
16
|
+
let lastModId = undefined;
|
|
17
|
+
let value = undefined;
|
|
18
|
+
return () => {
|
|
19
|
+
if (!initialized) {
|
|
20
|
+
initialized = true;
|
|
21
|
+
lastModId = modIdCb();
|
|
22
|
+
value = valueCb();
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
const currentModId = modIdCb();
|
|
26
|
+
if (lastModId !== currentModId) {
|
|
27
|
+
lastModId = currentModId;
|
|
28
|
+
value = valueCb();
|
|
29
|
+
}
|
|
30
|
+
return valueCb();
|
|
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.currentArgs === undefined)
|
|
59
|
+
throw new Error('no current args field');
|
|
60
|
+
}
|
|
61
|
+
currentArgsC = cached(() => this.fields.currentArgs.modCount, () => cachedDeserialize(this.fields.currentArgs.value));
|
|
62
|
+
prodArgsC = cached(() => this.fields.prodArgs?.modCount, () => {
|
|
63
|
+
const bin = this.fields.prodArgs?.value;
|
|
64
|
+
if (bin === undefined)
|
|
65
|
+
return undefined;
|
|
66
|
+
return cachedDeserialize(bin);
|
|
67
|
+
});
|
|
68
|
+
get currentArgs() {
|
|
69
|
+
return this.currentArgsC();
|
|
70
|
+
}
|
|
71
|
+
get stagingRendered() {
|
|
72
|
+
return this.fields.stagingCtx !== undefined;
|
|
73
|
+
}
|
|
74
|
+
get productionRendered() {
|
|
75
|
+
return this.fields.prodCtx !== undefined;
|
|
76
|
+
}
|
|
77
|
+
get productionHasErrors() {
|
|
78
|
+
return this.fields.prodUiCtx?.status === 'Error';
|
|
79
|
+
}
|
|
80
|
+
productionStaleC = cached(() => `${this.fields.currentArgs.modCount}_${this.fields.prodArgs?.modCount}`, () => this.fields.prodArgs === undefined
|
|
81
|
+
|| Buffer.compare(this.fields.currentArgs.value, this.fields.prodArgs.value) !== 0);
|
|
82
|
+
// get productionStale(): boolean {
|
|
83
|
+
// return this.productionRendered && this.productionStaleC() && ;
|
|
84
|
+
// }
|
|
85
|
+
get requireProductionRendering() {
|
|
86
|
+
return !this.productionRendered || this.productionStaleC() || this.productionHasErrors;
|
|
87
|
+
}
|
|
88
|
+
get prodArgs() {
|
|
89
|
+
return this.prodArgsC();
|
|
90
|
+
}
|
|
91
|
+
getTemplate(tx) {
|
|
92
|
+
return tx.getFutureFieldValue(Pl.unwrapHolder(tx, this.fields.blockPack.ref), BlockPackTemplateField, 'Input');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const NoNewBlocks = (blockId) => {
|
|
96
|
+
throw new Error(`No new block info for ${blockId}`);
|
|
97
|
+
};
|
|
98
|
+
class ProjectMutator {
|
|
99
|
+
rid;
|
|
100
|
+
tx;
|
|
101
|
+
author;
|
|
102
|
+
schema;
|
|
103
|
+
lastModified;
|
|
104
|
+
meta;
|
|
105
|
+
struct;
|
|
106
|
+
renderingState;
|
|
107
|
+
blocksInLimbo;
|
|
108
|
+
blockInfos;
|
|
109
|
+
ctxExportTplHolder;
|
|
110
|
+
projectHelper;
|
|
111
|
+
globalModCount = 0;
|
|
112
|
+
fieldsChanged = false;
|
|
113
|
+
//
|
|
114
|
+
// Change trackers
|
|
115
|
+
//
|
|
116
|
+
lastModifiedChanged = false;
|
|
117
|
+
structureChanged = false;
|
|
118
|
+
metaChanged = false;
|
|
119
|
+
renderingStateChanged = false;
|
|
120
|
+
/** Set blocks will be assigned current mutator author marker on save */
|
|
121
|
+
blocksWithChangedInputs = new Set();
|
|
122
|
+
constructor(rid, tx, author, schema, lastModified, meta, struct, renderingState, blocksInLimbo, blockInfos, ctxExportTplHolder, projectHelper) {
|
|
123
|
+
this.rid = rid;
|
|
124
|
+
this.tx = tx;
|
|
125
|
+
this.author = author;
|
|
126
|
+
this.schema = schema;
|
|
127
|
+
this.lastModified = lastModified;
|
|
128
|
+
this.meta = meta;
|
|
129
|
+
this.struct = struct;
|
|
130
|
+
this.renderingState = renderingState;
|
|
131
|
+
this.blocksInLimbo = blocksInLimbo;
|
|
132
|
+
this.blockInfos = blockInfos;
|
|
133
|
+
this.ctxExportTplHolder = ctxExportTplHolder;
|
|
134
|
+
this.projectHelper = projectHelper;
|
|
135
|
+
}
|
|
136
|
+
fixProblemsAndMigrate() {
|
|
137
|
+
// Fixing problems introduced by old code
|
|
138
|
+
this.blockInfos.forEach((blockInfo) => {
|
|
139
|
+
if (blockInfo.fields.prodArgs === undefined
|
|
140
|
+
|| blockInfo.fields.prodOutput === undefined
|
|
141
|
+
|| blockInfo.fields.prodCtx === undefined)
|
|
142
|
+
this.deleteBlockFields(blockInfo.id, 'prodArgs', 'prodOutput', 'prodCtx');
|
|
143
|
+
});
|
|
144
|
+
// Migration for addition of block settings field
|
|
145
|
+
let initialBlockSettings;
|
|
146
|
+
this.blockInfos.forEach((blockInfo) => {
|
|
147
|
+
if (blockInfo.fields.blockSettings === undefined) {
|
|
148
|
+
if (initialBlockSettings === undefined)
|
|
149
|
+
initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);
|
|
150
|
+
this.setBlockFieldObj(blockInfo.id, 'blockSettings', initialBlockSettings);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
get wasModified() {
|
|
155
|
+
return (this.lastModifiedChanged
|
|
156
|
+
|| this.structureChanged
|
|
157
|
+
|| this.fieldsChanged
|
|
158
|
+
|| this.metaChanged
|
|
159
|
+
|| this.renderingStateChanged);
|
|
160
|
+
}
|
|
161
|
+
get structure() {
|
|
162
|
+
// clone
|
|
163
|
+
return JSON.parse(JSON.stringify(this.struct));
|
|
164
|
+
}
|
|
165
|
+
//
|
|
166
|
+
// Graph calculation
|
|
167
|
+
//
|
|
168
|
+
stagingGraph = undefined;
|
|
169
|
+
pendingProductionGraph = undefined;
|
|
170
|
+
actualProductionGraph = undefined;
|
|
171
|
+
getStagingGraph() {
|
|
172
|
+
if (this.stagingGraph === undefined)
|
|
173
|
+
this.stagingGraph = stagingGraph(this.struct);
|
|
174
|
+
return this.stagingGraph;
|
|
175
|
+
}
|
|
176
|
+
getProductionGraphBlockInfo(blockId, prod) {
|
|
177
|
+
const bInfo = this.getBlockInfo(blockId);
|
|
178
|
+
let argsField;
|
|
179
|
+
let args;
|
|
180
|
+
if (prod) {
|
|
181
|
+
if (bInfo.fields.prodArgs === undefined)
|
|
182
|
+
return undefined;
|
|
183
|
+
argsField = bInfo.fields.prodArgs;
|
|
184
|
+
args = bInfo.prodArgs;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
argsField = notEmpty(bInfo.fields.currentArgs);
|
|
188
|
+
args = bInfo.currentArgs;
|
|
189
|
+
}
|
|
190
|
+
const blockPackField = notEmpty(bInfo.fields.blockPack);
|
|
191
|
+
if (isResourceId(argsField.ref) && isResourceId(blockPackField.ref))
|
|
192
|
+
return {
|
|
193
|
+
args,
|
|
194
|
+
enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args, { argsRid: argsField.ref, blockPackRid: blockPackField.ref }),
|
|
195
|
+
};
|
|
196
|
+
else
|
|
197
|
+
return {
|
|
198
|
+
args,
|
|
199
|
+
enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
getPendingProductionGraph() {
|
|
203
|
+
if (this.pendingProductionGraph === undefined)
|
|
204
|
+
this.pendingProductionGraph = productionGraph(this.struct, (blockId) => this.getProductionGraphBlockInfo(blockId, false));
|
|
205
|
+
return this.pendingProductionGraph;
|
|
206
|
+
}
|
|
207
|
+
getActualProductionGraph() {
|
|
208
|
+
if (this.actualProductionGraph === undefined)
|
|
209
|
+
this.actualProductionGraph = productionGraph(this.struct, (blockId) => this.getProductionGraphBlockInfo(blockId, true));
|
|
210
|
+
return this.actualProductionGraph;
|
|
211
|
+
}
|
|
212
|
+
//
|
|
213
|
+
// Generic helpers to interact with project state
|
|
214
|
+
//
|
|
215
|
+
getBlockInfo(blockId) {
|
|
216
|
+
const info = this.blockInfos.get(blockId);
|
|
217
|
+
if (info === undefined)
|
|
218
|
+
throw new Error(`No such block: ${blockId}`);
|
|
219
|
+
return info;
|
|
220
|
+
}
|
|
221
|
+
createJsonFieldValueByContent(content) {
|
|
222
|
+
const value = Buffer.from(content);
|
|
223
|
+
const ref = this.tx.createValue(Pl.JsonObject, value);
|
|
224
|
+
return { ref, value, status: 'Ready' };
|
|
225
|
+
}
|
|
226
|
+
createJsonFieldValue(obj) {
|
|
227
|
+
return this.createJsonFieldValueByContent(JSON.stringify(obj));
|
|
228
|
+
}
|
|
229
|
+
getBlock(blockId) {
|
|
230
|
+
for (const block of allBlocks(this.struct))
|
|
231
|
+
if (block.id === blockId)
|
|
232
|
+
return block;
|
|
233
|
+
throw new Error('block not found');
|
|
234
|
+
}
|
|
235
|
+
setBlockFieldObj(blockId, fieldName, state) {
|
|
236
|
+
const fid = field(this.rid, projectFieldName(blockId, fieldName));
|
|
237
|
+
if (state.ref === undefined)
|
|
238
|
+
throw new Error('Can\'t set value with empty ref');
|
|
239
|
+
if (this.getBlockInfo(blockId).fields[fieldName] === undefined)
|
|
240
|
+
this.tx.createField(fid, 'Dynamic', state.ref);
|
|
241
|
+
else
|
|
242
|
+
this.tx.setField(fid, state.ref);
|
|
243
|
+
this.getBlockInfo(blockId).fields[fieldName] = {
|
|
244
|
+
modCount: this.globalModCount++,
|
|
245
|
+
...state,
|
|
246
|
+
};
|
|
247
|
+
this.fieldsChanged = true;
|
|
248
|
+
}
|
|
249
|
+
setBlockField(blockId, fieldName, ref, status, value) {
|
|
250
|
+
this.setBlockFieldObj(blockId, fieldName, { ref, status, value });
|
|
251
|
+
}
|
|
252
|
+
deleteBlockFields(blockId, ...fieldNames) {
|
|
253
|
+
let deleted = false;
|
|
254
|
+
const info = this.getBlockInfo(blockId);
|
|
255
|
+
for (const fieldName of fieldNames) {
|
|
256
|
+
const fields = info.fields;
|
|
257
|
+
if (!(fieldName in fields))
|
|
258
|
+
continue;
|
|
259
|
+
this.tx.removeField(field(this.rid, projectFieldName(blockId, fieldName)));
|
|
260
|
+
delete fields[fieldName];
|
|
261
|
+
this.fieldsChanged = true;
|
|
262
|
+
deleted = true;
|
|
263
|
+
}
|
|
264
|
+
return deleted;
|
|
265
|
+
}
|
|
266
|
+
updateLastModified() {
|
|
267
|
+
this.lastModified = Date.now();
|
|
268
|
+
this.lastModifiedChanged = true;
|
|
269
|
+
}
|
|
270
|
+
//
|
|
271
|
+
// Main project actions
|
|
272
|
+
//
|
|
273
|
+
resetStagingRefreshTimestamp() {
|
|
274
|
+
this.renderingState.stagingRefreshTimestamp = Date.now();
|
|
275
|
+
this.renderingStateChanged = true;
|
|
276
|
+
}
|
|
277
|
+
resetStaging(blockId) {
|
|
278
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
279
|
+
if (fields.stagingOutput?.status === 'Ready'
|
|
280
|
+
&& fields.stagingCtx?.status === 'Ready'
|
|
281
|
+
&& fields.stagingUiCtx?.status === 'Ready') {
|
|
282
|
+
this.setBlockFieldObj(blockId, 'stagingOutputPrevious', fields.stagingOutput);
|
|
283
|
+
this.setBlockFieldObj(blockId, 'stagingCtxPrevious', fields.stagingCtx);
|
|
284
|
+
this.setBlockFieldObj(blockId, 'stagingUiCtxPrevious', fields.stagingUiCtx);
|
|
285
|
+
}
|
|
286
|
+
if (this.deleteBlockFields(blockId, 'stagingOutput', 'stagingCtx', 'stagingUiCtx'))
|
|
287
|
+
this.resetStagingRefreshTimestamp();
|
|
288
|
+
}
|
|
289
|
+
resetProduction(blockId) {
|
|
290
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
291
|
+
if (fields.prodOutput?.status === 'Ready'
|
|
292
|
+
&& fields.prodCtx?.status === 'Ready'
|
|
293
|
+
&& fields.prodUiCtx?.status === 'Ready') {
|
|
294
|
+
this.setBlockFieldObj(blockId, 'prodOutputPrevious', fields.prodOutput);
|
|
295
|
+
this.setBlockFieldObj(blockId, 'prodCtxPrevious', fields.prodCtx);
|
|
296
|
+
this.setBlockFieldObj(blockId, 'prodUiCtxPrevious', fields.prodUiCtx);
|
|
297
|
+
}
|
|
298
|
+
this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs');
|
|
299
|
+
}
|
|
300
|
+
/** Running blocks are reset, already computed moved to limbo. Returns if
|
|
301
|
+
* either of the actions were actually performed.
|
|
302
|
+
* This method ensures the block is left in a consistent state that passes check() constraints. */
|
|
303
|
+
resetOrLimboProduction(blockId) {
|
|
304
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
305
|
+
// Check if we can safely move to limbo (both core production fields are ready)
|
|
306
|
+
if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {
|
|
307
|
+
if (this.blocksInLimbo.has(blockId))
|
|
308
|
+
// we are already in limbo
|
|
309
|
+
return false;
|
|
310
|
+
// limbo - keep the ready production results but clean up cache
|
|
311
|
+
this.blocksInLimbo.add(blockId);
|
|
312
|
+
this.renderingStateChanged = true;
|
|
313
|
+
// doing some gc - clean up previous cache fields
|
|
314
|
+
this.deleteBlockFields(blockId, 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
// reset - clean up any partial/inconsistent production stat
|
|
319
|
+
return this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs', 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/** Optimally sets inputs for multiple blocks in one go */
|
|
323
|
+
setStates(requests) {
|
|
324
|
+
const changedArgs = [];
|
|
325
|
+
let somethingChanged = false;
|
|
326
|
+
for (const req of requests) {
|
|
327
|
+
const info = this.getBlockInfo(req.blockId);
|
|
328
|
+
let blockChanged = false;
|
|
329
|
+
for (const stateKey of ['args', 'uiState']) {
|
|
330
|
+
if (!(stateKey in req))
|
|
331
|
+
continue;
|
|
332
|
+
const statePart = req[stateKey];
|
|
333
|
+
if (statePart === undefined || statePart === null)
|
|
334
|
+
throw new Error(`Can't set ${stateKey} to null or undefined, please omit the key if you don't want to change it`);
|
|
335
|
+
const fieldName = stateKey === 'args' ? 'currentArgs' : 'uiState';
|
|
336
|
+
let data;
|
|
337
|
+
let gzipped = false;
|
|
338
|
+
if (stateKey === 'args') {
|
|
339
|
+
// don't gzip args, workflow code can't uncompress gzip yet
|
|
340
|
+
data = canonicalJsonBytes(statePart);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
const { data: binary, isGzipped } = canonicalJsonGzBytes(statePart);
|
|
344
|
+
data = binary;
|
|
345
|
+
gzipped = isGzipped;
|
|
346
|
+
}
|
|
347
|
+
if (Buffer.compare(info.fields[fieldName].value, data) === 0)
|
|
348
|
+
continue;
|
|
349
|
+
console.log('setting', fieldName, gzipped, data.length);
|
|
350
|
+
const statePartRef = this.tx.createValue(gzipped ? Pl.JsonGzObject : Pl.JsonObject, data);
|
|
351
|
+
this.setBlockField(req.blockId, fieldName, statePartRef, 'Ready', data);
|
|
352
|
+
blockChanged = true;
|
|
353
|
+
if (stateKey === 'args')
|
|
354
|
+
changedArgs.push(req.blockId);
|
|
355
|
+
}
|
|
356
|
+
if (blockChanged) {
|
|
357
|
+
// will be assigned our author marker
|
|
358
|
+
this.blocksWithChangedInputs.add(req.blockId);
|
|
359
|
+
somethingChanged = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// resetting staging outputs for all downstream blocks
|
|
363
|
+
this.getStagingGraph().traverse('downstream', changedArgs, ({ id }) => this.resetStaging(id));
|
|
364
|
+
if (somethingChanged)
|
|
365
|
+
this.updateLastModified();
|
|
366
|
+
}
|
|
367
|
+
setBlockSettings(blockId, newValue) {
|
|
368
|
+
this.setBlockFieldObj(blockId, 'blockSettings', this.createJsonFieldValue(newValue));
|
|
369
|
+
this.updateLastModified();
|
|
370
|
+
}
|
|
371
|
+
createProdCtx(upstream) {
|
|
372
|
+
const upstreamContexts = [];
|
|
373
|
+
upstream.forEach((id) => {
|
|
374
|
+
const info = this.getBlockInfo(id);
|
|
375
|
+
if (info.fields['prodCtx']?.ref === undefined)
|
|
376
|
+
throw new Error('One of the upstreams staging is not rendered.');
|
|
377
|
+
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));
|
|
378
|
+
});
|
|
379
|
+
return createBContextFromUpstreams(this.tx, upstreamContexts);
|
|
380
|
+
}
|
|
381
|
+
createStagingCtx(upstream) {
|
|
382
|
+
const upstreamContexts = [];
|
|
383
|
+
upstream.forEach((id) => {
|
|
384
|
+
const info = this.getBlockInfo(id);
|
|
385
|
+
if (info.fields['stagingCtx']?.ref === undefined)
|
|
386
|
+
throw new Error('One of the upstreams staging is not rendered.');
|
|
387
|
+
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['stagingCtx'].ref));
|
|
388
|
+
if (info.fields['prodCtx']?.ref !== undefined)
|
|
389
|
+
upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));
|
|
390
|
+
});
|
|
391
|
+
return createBContextFromUpstreams(this.tx, upstreamContexts);
|
|
392
|
+
}
|
|
393
|
+
exportCtx(ctx) {
|
|
394
|
+
return exportContext(this.tx, Pl.unwrapHolder(this.tx, this.ctxExportTplHolder), ctx);
|
|
395
|
+
}
|
|
396
|
+
renderStagingFor(blockId) {
|
|
397
|
+
this.resetStaging(blockId);
|
|
398
|
+
const info = this.getBlockInfo(blockId);
|
|
399
|
+
const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId).upstream);
|
|
400
|
+
if (this.getBlock(blockId).renderingMode !== 'Heavy')
|
|
401
|
+
throw new Error('not supported yet');
|
|
402
|
+
const tpl = info.getTemplate(this.tx);
|
|
403
|
+
const results = createRenderHeavyBlock(this.tx, tpl, {
|
|
404
|
+
args: info.fields.currentArgs.ref,
|
|
405
|
+
blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),
|
|
406
|
+
isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(false)),
|
|
407
|
+
context: ctx,
|
|
408
|
+
});
|
|
409
|
+
this.setBlockField(blockId, 'stagingCtx', Pl.wrapInEphHolder(this.tx, results.context), 'NotReady');
|
|
410
|
+
this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');
|
|
411
|
+
this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');
|
|
412
|
+
}
|
|
413
|
+
renderProductionFor(blockId) {
|
|
414
|
+
this.resetProduction(blockId);
|
|
415
|
+
const info = this.getBlockInfo(blockId);
|
|
416
|
+
const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId).upstream);
|
|
417
|
+
if (this.getBlock(blockId).renderingMode === 'Light')
|
|
418
|
+
throw new Error('Can\'t render production for light block.');
|
|
419
|
+
const tpl = info.getTemplate(this.tx);
|
|
420
|
+
const results = createRenderHeavyBlock(this.tx, tpl, {
|
|
421
|
+
args: info.fields.currentArgs.ref,
|
|
422
|
+
blockId: this.tx.createValue(Pl.JsonString, JSON.stringify(blockId)),
|
|
423
|
+
isProduction: this.tx.createValue(Pl.JsonBool, JSON.stringify(true)),
|
|
424
|
+
context: ctx,
|
|
425
|
+
});
|
|
426
|
+
this.setBlockField(blockId, 'prodCtx', Pl.wrapInEphHolder(this.tx, results.context), 'NotReady');
|
|
427
|
+
this.setBlockField(blockId, 'prodUiCtx', this.exportCtx(results.context), 'NotReady');
|
|
428
|
+
this.setBlockField(blockId, 'prodOutput', results.result, 'NotReady');
|
|
429
|
+
// saving inputs for which we rendered the production
|
|
430
|
+
this.setBlockFieldObj(blockId, 'prodArgs', info.fields.currentArgs);
|
|
431
|
+
// removing block from limbo as we juts rendered fresh production for it
|
|
432
|
+
if (this.blocksInLimbo.delete(blockId))
|
|
433
|
+
this.renderingStateChanged = true;
|
|
434
|
+
}
|
|
435
|
+
//
|
|
436
|
+
// Structure changes
|
|
437
|
+
//
|
|
438
|
+
initializeNewBlock(blockId, spec) {
|
|
439
|
+
const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);
|
|
440
|
+
this.blockInfos.set(blockId, info);
|
|
441
|
+
// block pack
|
|
442
|
+
const bp = createBlockPack(this.tx, spec.blockPack);
|
|
443
|
+
this.setBlockField(blockId, 'blockPack', Pl.wrapInHolder(this.tx, bp), 'NotReady');
|
|
444
|
+
// settings
|
|
445
|
+
this.setBlockFieldObj(blockId, 'blockSettings', this.createJsonFieldValue(InitialBlockSettings));
|
|
446
|
+
// args
|
|
447
|
+
this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValueByContent(spec.args));
|
|
448
|
+
// uiState
|
|
449
|
+
this.setBlockFieldObj(blockId, 'uiState', this.createJsonFieldValueByContent(spec.uiState ?? '{}'));
|
|
450
|
+
// checking structure
|
|
451
|
+
info.check();
|
|
452
|
+
}
|
|
453
|
+
getFieldNamesToDuplicate(blockId) {
|
|
454
|
+
const fields = this.getBlockInfo(blockId).fields;
|
|
455
|
+
const diff = (setA, setB) => new Set([...setA].filter((x) => !setB.has(x)));
|
|
456
|
+
// Check if we can safely move to limbo (both core production fields are ready)
|
|
457
|
+
if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {
|
|
458
|
+
if (this.blocksInLimbo.has(blockId))
|
|
459
|
+
// we are already in limbo
|
|
460
|
+
return FieldsToDuplicate;
|
|
461
|
+
return diff(FieldsToDuplicate, new Set([
|
|
462
|
+
'prodOutputPrevious',
|
|
463
|
+
'prodCtxPrevious',
|
|
464
|
+
'prodUiCtxPrevious',
|
|
465
|
+
]));
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
return diff(FieldsToDuplicate, new Set([
|
|
469
|
+
'prodOutput',
|
|
470
|
+
'prodCtx',
|
|
471
|
+
'prodUiCtx',
|
|
472
|
+
'prodArgs',
|
|
473
|
+
'prodOutputPrevious',
|
|
474
|
+
'prodCtxPrevious',
|
|
475
|
+
'prodUiCtxPrevious',
|
|
476
|
+
]));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
initializeBlockDuplicate(blockId, originalBlockInfo) {
|
|
480
|
+
const info = new BlockInfo(blockId, {}, originalBlockInfo.config, originalBlockInfo.source);
|
|
481
|
+
this.blockInfos.set(blockId, info);
|
|
482
|
+
const fieldNamesToDuplicate = this.getFieldNamesToDuplicate(blockId);
|
|
483
|
+
// Copy all fields from original block to new block by sharing references
|
|
484
|
+
for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) {
|
|
485
|
+
if (fieldNamesToDuplicate.has(fieldName) && fieldState && fieldState.ref) {
|
|
486
|
+
this.setBlockFieldObj(blockId, fieldName, {
|
|
487
|
+
ref: fieldState.ref,
|
|
488
|
+
status: fieldState.status,
|
|
489
|
+
value: fieldState.value,
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
this.resetOrLimboProduction(blockId);
|
|
494
|
+
info.check();
|
|
495
|
+
}
|
|
496
|
+
/** Very generic method, better check for more specialized case-specific methods first. */
|
|
497
|
+
updateStructure(newStructure, newBlockInitializer = NoNewBlocks) {
|
|
498
|
+
const currentStagingGraph = this.getStagingGraph();
|
|
499
|
+
const currentActualProductionGraph = this.getActualProductionGraph();
|
|
500
|
+
const newStagingGraph = stagingGraph(newStructure);
|
|
501
|
+
const stagingDiff = graphDiff(currentStagingGraph, newStagingGraph);
|
|
502
|
+
// removing blocks
|
|
503
|
+
for (const blockId of stagingDiff.onlyInA) {
|
|
504
|
+
const { fields } = this.getBlockInfo(blockId);
|
|
505
|
+
this.deleteBlockFields(blockId, ...Object.keys(fields));
|
|
506
|
+
this.blockInfos.delete(blockId);
|
|
507
|
+
if (this.blocksInLimbo.delete(blockId))
|
|
508
|
+
this.renderingStateChanged = true;
|
|
509
|
+
}
|
|
510
|
+
// creating new blocks
|
|
511
|
+
for (const blockId of stagingDiff.onlyInB) {
|
|
512
|
+
newBlockInitializer(blockId);
|
|
513
|
+
}
|
|
514
|
+
// resetting stagings affected by topology change
|
|
515
|
+
for (const blockId of stagingDiff.different)
|
|
516
|
+
this.resetStaging(blockId);
|
|
517
|
+
// new actual production graph without new blocks
|
|
518
|
+
const newActualProductionGraph = productionGraph(newStructure, (blockId) => this.getProductionGraphBlockInfo(blockId, true));
|
|
519
|
+
const prodDiff = graphDiff(currentActualProductionGraph, newActualProductionGraph);
|
|
520
|
+
// applying changes due to topology change in production to affected nodes and
|
|
521
|
+
// all their downstreams
|
|
522
|
+
currentActualProductionGraph.traverse('downstream', [...prodDiff.different], (node) => {
|
|
523
|
+
this.resetOrLimboProduction(node.id);
|
|
524
|
+
});
|
|
525
|
+
if (stagingDiff.onlyInB.size > 0
|
|
526
|
+
|| stagingDiff.onlyInA.size > 0
|
|
527
|
+
|| stagingDiff.different.size > 0)
|
|
528
|
+
this.resetStagingRefreshTimestamp();
|
|
529
|
+
this.struct = newStructure;
|
|
530
|
+
this.structureChanged = true;
|
|
531
|
+
this.stagingGraph = undefined;
|
|
532
|
+
this.pendingProductionGraph = undefined;
|
|
533
|
+
this.actualProductionGraph = undefined;
|
|
534
|
+
this.updateLastModified();
|
|
535
|
+
}
|
|
536
|
+
//
|
|
537
|
+
// Structure change helpers
|
|
538
|
+
//
|
|
539
|
+
addBlock(block, spec, before) {
|
|
540
|
+
const newStruct = this.structure; // copy current structure
|
|
541
|
+
if (before === undefined) {
|
|
542
|
+
// adding as a very last block
|
|
543
|
+
newStruct.groups[newStruct.groups.length - 1].blocks.push(block);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
let done = false;
|
|
547
|
+
for (const group of newStruct.groups) {
|
|
548
|
+
const idx = group.blocks.findIndex((b) => b.id === before);
|
|
549
|
+
if (idx < 0)
|
|
550
|
+
continue;
|
|
551
|
+
group.blocks.splice(idx, 0, block);
|
|
552
|
+
done = true;
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
if (!done)
|
|
556
|
+
throw new Error(`Can't find element with id: ${before}`);
|
|
557
|
+
}
|
|
558
|
+
this.updateStructure(newStruct, (blockId) => {
|
|
559
|
+
if (blockId !== block.id)
|
|
560
|
+
throw new Error('Unexpected');
|
|
561
|
+
this.initializeNewBlock(blockId, spec);
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Duplicates an existing block by copying all its fields and structure.
|
|
566
|
+
* This method creates a deep copy of the block at the mutator level.
|
|
567
|
+
*
|
|
568
|
+
* @param originalBlockId id of the block to duplicate
|
|
569
|
+
* @param newBlockId id for the new duplicated block
|
|
570
|
+
* @param after id of the block to insert new block after
|
|
571
|
+
*/
|
|
572
|
+
duplicateBlock(originalBlockId, newBlockId, after) {
|
|
573
|
+
// Get the original block from structure
|
|
574
|
+
const originalBlock = this.getBlock(originalBlockId);
|
|
575
|
+
const originalBlockInfo = this.getBlockInfo(originalBlockId);
|
|
576
|
+
// Create new block in structure
|
|
577
|
+
const newBlock = {
|
|
578
|
+
id: newBlockId,
|
|
579
|
+
label: originalBlock.label,
|
|
580
|
+
renderingMode: originalBlock.renderingMode,
|
|
581
|
+
};
|
|
582
|
+
// Add the new block to structure
|
|
583
|
+
const newStruct = this.structure; // copy current structure
|
|
584
|
+
if (after === undefined) {
|
|
585
|
+
// adding as a very last block
|
|
586
|
+
newStruct.groups[newStruct.groups.length - 1].blocks.push(newBlock);
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
let done = false;
|
|
590
|
+
for (const group of newStruct.groups) {
|
|
591
|
+
const idx = group.blocks.findIndex((b) => b.id === after);
|
|
592
|
+
if (idx < 0)
|
|
593
|
+
continue;
|
|
594
|
+
group.blocks.splice(idx + 1, 0, newBlock);
|
|
595
|
+
done = true;
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
if (!done)
|
|
599
|
+
throw new Error(`Can't find element with id: ${after}`);
|
|
600
|
+
}
|
|
601
|
+
this.updateStructure(newStruct, (blockId) => {
|
|
602
|
+
if (blockId !== newBlockId)
|
|
603
|
+
throw new Error('Unexpected');
|
|
604
|
+
this.initializeBlockDuplicate(blockId, originalBlockInfo);
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
deleteBlock(blockId) {
|
|
608
|
+
const newStruct = this.structure; // copy current structure
|
|
609
|
+
let done = false;
|
|
610
|
+
for (const group of newStruct.groups) {
|
|
611
|
+
const idx = group.blocks.findIndex((b) => b.id === blockId);
|
|
612
|
+
if (idx < 0)
|
|
613
|
+
continue;
|
|
614
|
+
group.blocks.splice(idx, 1);
|
|
615
|
+
done = true;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
if (!done)
|
|
619
|
+
throw new Error(`Can't find element with id: ${blockId}`);
|
|
620
|
+
this.updateStructure(newStruct);
|
|
621
|
+
}
|
|
622
|
+
//
|
|
623
|
+
// Block-pack migration
|
|
624
|
+
//
|
|
625
|
+
migrateBlockPack(blockId, spec, newArgsAndUiState) {
|
|
626
|
+
const info = this.getBlockInfo(blockId);
|
|
627
|
+
this.setBlockField(blockId, 'blockPack', Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)), 'NotReady');
|
|
628
|
+
if (newArgsAndUiState !== undefined) {
|
|
629
|
+
// this will also reset all downstream stagings
|
|
630
|
+
this.setStates([{ blockId, args: newArgsAndUiState.args, uiState: newArgsAndUiState.uiState }]);
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
// resetting staging outputs for all downstream blocks
|
|
634
|
+
this.getStagingGraph().traverse('downstream', [blockId], ({ id }) => this.resetStaging(id));
|
|
635
|
+
}
|
|
636
|
+
// also reset or limbo all downstream productions
|
|
637
|
+
if (info.productionRendered)
|
|
638
|
+
this.getActualProductionGraph().traverse('downstream', [blockId], ({ id }) => this.resetOrLimboProduction(id));
|
|
639
|
+
this.updateLastModified();
|
|
640
|
+
}
|
|
641
|
+
//
|
|
642
|
+
// Render
|
|
643
|
+
//
|
|
644
|
+
renderProduction(blockIds, addUpstreams = false) {
|
|
645
|
+
const blockIdsSet = new Set(blockIds);
|
|
646
|
+
const prodGraph = this.getPendingProductionGraph();
|
|
647
|
+
if (addUpstreams)
|
|
648
|
+
// adding all upstreams automatically
|
|
649
|
+
prodGraph.traverse('upstream', blockIds, (node) => {
|
|
650
|
+
blockIdsSet.add(node.id);
|
|
651
|
+
});
|
|
652
|
+
else // checking that targets contain all upstreams
|
|
653
|
+
for (const blockId of blockIdsSet) {
|
|
654
|
+
const node = prodGraph.nodes.get(blockId);
|
|
655
|
+
if (node === undefined)
|
|
656
|
+
throw new Error(`Can't find block with id: ${blockId}`);
|
|
657
|
+
for (const upstream of node.upstream)
|
|
658
|
+
if (!blockIdsSet.has(upstream))
|
|
659
|
+
throw new Error('Can\'t render blocks not including all upstreams.');
|
|
660
|
+
}
|
|
661
|
+
// traversing in topological order and rendering target blocks
|
|
662
|
+
const rendered = new Set();
|
|
663
|
+
for (const block of allBlocks(this.structure)) {
|
|
664
|
+
if (!blockIdsSet.has(block.id))
|
|
665
|
+
continue;
|
|
666
|
+
let render = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);
|
|
667
|
+
if (!render)
|
|
668
|
+
for (const upstream of prodGraph.nodes.get(block.id).upstream)
|
|
669
|
+
if (rendered.has(upstream)) {
|
|
670
|
+
render = true;
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
if (render) {
|
|
674
|
+
this.renderProductionFor(block.id);
|
|
675
|
+
rendered.add(block.id);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const renderedArray = [...rendered];
|
|
679
|
+
// sending to limbo all downstream blocks
|
|
680
|
+
prodGraph.traverse('downstream', renderedArray, (node) => {
|
|
681
|
+
if (rendered.has(node.id))
|
|
682
|
+
// don't send to limbo blocks that were just rendered
|
|
683
|
+
return;
|
|
684
|
+
this.resetOrLimboProduction(node.id);
|
|
685
|
+
});
|
|
686
|
+
// resetting staging outputs for all downstream blocks
|
|
687
|
+
this.getStagingGraph().traverse('downstream', renderedArray, ({ id }) => {
|
|
688
|
+
// don't reset staging of the first rendered block
|
|
689
|
+
if (renderedArray[0] !== id)
|
|
690
|
+
this.resetStaging(id);
|
|
691
|
+
});
|
|
692
|
+
if (rendered.size > 0)
|
|
693
|
+
this.updateLastModified();
|
|
694
|
+
return rendered;
|
|
695
|
+
}
|
|
696
|
+
/** Stops running blocks from the list and modify states of other blocks
|
|
697
|
+
* accordingly */
|
|
698
|
+
stopProduction(...blockIds) {
|
|
699
|
+
const activeProdGraph = this.getActualProductionGraph();
|
|
700
|
+
// we will stop all blocks listed in request and all their downstreams
|
|
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')
|
|
708
|
+
// skipping finished blocks
|
|
709
|
+
continue;
|
|
710
|
+
if (this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs')) {
|
|
711
|
+
// was actually stopped
|
|
712
|
+
stopped.push(blockId);
|
|
713
|
+
// will try to stop all its downstreams
|
|
714
|
+
for (const downstream of activeProdGraph.traverseIdsExcludingRoots('downstream', blockId)) {
|
|
715
|
+
if (queued.has(downstream))
|
|
716
|
+
continue;
|
|
717
|
+
queue.push(downstream);
|
|
718
|
+
queued.add(downstream);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
// blocks under stopped blocks, but still having results, goes to limbo
|
|
723
|
+
for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))
|
|
724
|
+
this.resetOrLimboProduction(blockId);
|
|
725
|
+
}
|
|
726
|
+
traverseWithStagingLag(cb) {
|
|
727
|
+
const lags = new Map();
|
|
728
|
+
const stagingGraph = this.getStagingGraph();
|
|
729
|
+
stagingGraph.nodes.forEach((node) => {
|
|
730
|
+
const info = this.getBlockInfo(node.id);
|
|
731
|
+
let lag = info.stagingRendered ? 0 : 1;
|
|
732
|
+
node.upstream.forEach((upstream) => {
|
|
733
|
+
const upstreamLag = lags.get(upstream);
|
|
734
|
+
if (upstreamLag === 0)
|
|
735
|
+
return;
|
|
736
|
+
lag = Math.max(upstreamLag + 1, lag);
|
|
737
|
+
});
|
|
738
|
+
cb(node.id, lag);
|
|
739
|
+
lags.set(node.id, lag);
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
/** @param stagingRenderingRate rate in blocks per second */
|
|
743
|
+
refreshStagings(stagingRenderingRate) {
|
|
744
|
+
const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;
|
|
745
|
+
const lagThreshold = stagingRenderingRate === undefined
|
|
746
|
+
? undefined
|
|
747
|
+
: 1 + Math.max(0, (elapsed * stagingRenderingRate) / 1000);
|
|
748
|
+
let rendered = 0;
|
|
749
|
+
this.traverseWithStagingLag((blockId, lag) => {
|
|
750
|
+
if (lag === 0)
|
|
751
|
+
// meaning staging already rendered
|
|
752
|
+
return;
|
|
753
|
+
if (lagThreshold === undefined || lag <= lagThreshold) {
|
|
754
|
+
this.renderStagingFor(blockId);
|
|
755
|
+
rendered++;
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
if (rendered > 0)
|
|
759
|
+
this.resetStagingRefreshTimestamp();
|
|
760
|
+
}
|
|
761
|
+
//
|
|
762
|
+
// Meta
|
|
763
|
+
//
|
|
764
|
+
/** Updates project metadata */
|
|
765
|
+
setMeta(meta) {
|
|
766
|
+
this.meta = meta;
|
|
767
|
+
this.metaChanged = true;
|
|
768
|
+
this.updateLastModified();
|
|
769
|
+
}
|
|
770
|
+
//
|
|
771
|
+
// Maintenance
|
|
772
|
+
//
|
|
773
|
+
/** @param stagingRenderingRate rate in blocks per second */
|
|
774
|
+
doRefresh(stagingRenderingRate) {
|
|
775
|
+
this.refreshStagings(stagingRenderingRate);
|
|
776
|
+
this.blockInfos.forEach((blockInfo) => {
|
|
777
|
+
if (blockInfo.fields.prodCtx?.status === 'Ready'
|
|
778
|
+
&& blockInfo.fields.prodOutput?.status === 'Ready')
|
|
779
|
+
this.deleteBlockFields(blockInfo.id, 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');
|
|
780
|
+
if (blockInfo.fields.stagingCtx?.status === 'Ready'
|
|
781
|
+
&& blockInfo.fields.stagingOutput?.status === 'Ready')
|
|
782
|
+
this.deleteBlockFields(blockInfo.id, 'stagingOutputPrevious', 'stagingCtxPrevious', 'stagingUiCtxPrevious');
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
assignAuthorMarkers() {
|
|
786
|
+
const markerStr = this.author ? JSON.stringify(this.author) : undefined;
|
|
787
|
+
for (const blockId of this.blocksWithChangedInputs)
|
|
788
|
+
if (markerStr === undefined)
|
|
789
|
+
this.tx.deleteKValue(this.rid, blockArgsAuthorKey(blockId));
|
|
790
|
+
else
|
|
791
|
+
this.tx.setKValue(this.rid, blockArgsAuthorKey(blockId), markerStr);
|
|
792
|
+
if (this.metaChanged || this.structureChanged) {
|
|
793
|
+
if (markerStr === undefined)
|
|
794
|
+
this.tx.deleteKValue(this.rid, ProjectStructureAuthorKey);
|
|
795
|
+
else
|
|
796
|
+
this.tx.setKValue(this.rid, ProjectStructureAuthorKey, markerStr);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
save() {
|
|
800
|
+
if (!this.wasModified)
|
|
801
|
+
return;
|
|
802
|
+
if (this.lastModifiedChanged)
|
|
803
|
+
this.tx.setKValue(this.rid, ProjectLastModifiedTimestamp, JSON.stringify(this.lastModified));
|
|
804
|
+
if (this.structureChanged)
|
|
805
|
+
this.tx.setKValue(this.rid, ProjectStructureKey, JSON.stringify(this.struct));
|
|
806
|
+
if (this.renderingStateChanged)
|
|
807
|
+
this.tx.setKValue(this.rid, BlockRenderingStateKey, JSON.stringify({
|
|
808
|
+
...this.renderingState,
|
|
809
|
+
blocksInLimbo: [...this.blocksInLimbo],
|
|
810
|
+
}));
|
|
811
|
+
if (this.metaChanged)
|
|
812
|
+
this.tx.setKValue(this.rid, ProjectMetaKey, JSON.stringify(this.meta));
|
|
813
|
+
this.assignAuthorMarkers();
|
|
814
|
+
}
|
|
815
|
+
static async load(projectHelper, tx, rid, author) {
|
|
816
|
+
//
|
|
817
|
+
// Sending initial requests to read project state (start of round-trip #1)
|
|
818
|
+
//
|
|
819
|
+
const fullResourceStateP = tx.getResourceData(rid, true);
|
|
820
|
+
const schemaP = tx.getKValueJson(rid, SchemaVersionKey);
|
|
821
|
+
const lastModifiedP = tx.getKValueJson(rid, ProjectLastModifiedTimestamp);
|
|
822
|
+
const metaP = tx.getKValueJson(rid, ProjectMetaKey);
|
|
823
|
+
const structureP = tx.getKValueJson(rid, ProjectStructureKey);
|
|
824
|
+
const renderingStateP = tx.getKValueJson(rid, BlockRenderingStateKey);
|
|
825
|
+
const fullResourceState = await fullResourceStateP;
|
|
826
|
+
// loading field information
|
|
827
|
+
const blockInfoStates = new Map();
|
|
828
|
+
for (const f of fullResourceState.fields) {
|
|
829
|
+
const projectField = parseProjectField(f.name);
|
|
830
|
+
// processing only fields with known structure
|
|
831
|
+
if (projectField === undefined)
|
|
832
|
+
continue;
|
|
833
|
+
let info = blockInfoStates.get(projectField.blockId);
|
|
834
|
+
if (info === undefined) {
|
|
835
|
+
info = {
|
|
836
|
+
id: projectField.blockId,
|
|
837
|
+
fields: {},
|
|
838
|
+
};
|
|
839
|
+
blockInfoStates.set(projectField.blockId, info);
|
|
840
|
+
}
|
|
841
|
+
info.fields[projectField.fieldName] = isNullResourceId(f.value)
|
|
842
|
+
? { modCount: 0 }
|
|
843
|
+
: { modCount: 0, ref: f.value };
|
|
844
|
+
}
|
|
845
|
+
//
|
|
846
|
+
// Roundtrip #1 not yet finished, but as soon as field list is received,
|
|
847
|
+
// we can start sending requests to read states of referenced resources
|
|
848
|
+
// (start of round-trip #2)
|
|
849
|
+
//
|
|
850
|
+
const blockFieldRequests = [];
|
|
851
|
+
blockInfoStates.forEach((info) => {
|
|
852
|
+
const fields = info.fields;
|
|
853
|
+
for (const [fName, state] of Object.entries(fields)) {
|
|
854
|
+
if (state.ref === undefined)
|
|
855
|
+
continue;
|
|
856
|
+
if (!isResource(state.ref) || isResourceRef(state.ref))
|
|
857
|
+
throw new Error('unexpected behaviour');
|
|
858
|
+
const fieldName = fName;
|
|
859
|
+
blockFieldRequests.push([
|
|
860
|
+
info, fieldName,
|
|
861
|
+
state, tx.getResourceData(state.ref, fieldName == 'blockPack')
|
|
862
|
+
]);
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
// loading jsons
|
|
866
|
+
const [schema, lastModified, meta, structure, { stagingRefreshTimestamp, blocksInLimbo },] = await Promise.all([
|
|
867
|
+
schemaP,
|
|
868
|
+
lastModifiedP,
|
|
869
|
+
metaP,
|
|
870
|
+
structureP,
|
|
871
|
+
renderingStateP,
|
|
872
|
+
]);
|
|
873
|
+
// Checking schema version of the project
|
|
874
|
+
if (schema !== SchemaVersionCurrent) {
|
|
875
|
+
if (Number(schema) < Number(SchemaVersionCurrent))
|
|
876
|
+
throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);
|
|
877
|
+
else
|
|
878
|
+
throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);
|
|
879
|
+
}
|
|
880
|
+
//
|
|
881
|
+
// <- at this point we have all the responses from round-trip #1
|
|
882
|
+
//
|
|
883
|
+
//
|
|
884
|
+
// Receiving responses from round-trip #2 and sending requests to read block pack descriptions
|
|
885
|
+
// (start of round-trip #3)
|
|
886
|
+
//
|
|
887
|
+
const blockPackRequests = [];
|
|
888
|
+
for (const [info, fieldName, state, response] of blockFieldRequests) {
|
|
889
|
+
const result = await response;
|
|
890
|
+
state.value = result.data;
|
|
891
|
+
if (isNotNullResourceId(result.error))
|
|
892
|
+
state.status = 'Error';
|
|
893
|
+
else if (result.resourceReady || isNotNullResourceId(result.originalResourceId))
|
|
894
|
+
state.status = 'Ready';
|
|
895
|
+
else
|
|
896
|
+
state.status = 'NotReady';
|
|
897
|
+
// For block pack we need to traverse the ref field from the resource data
|
|
898
|
+
if (fieldName === 'blockPack') {
|
|
899
|
+
const refField = result.fields.find((f) => f.name === Pl.HolderRefField);
|
|
900
|
+
if (refField === undefined)
|
|
901
|
+
throw new Error('Block pack ref field is missing');
|
|
902
|
+
blockPackRequests.push([info, tx.getResourceData(ensureResourceIdNotNull(refField.value), false)]);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
//
|
|
906
|
+
// <- at this point we have all the responses from round-trip #2
|
|
907
|
+
//
|
|
908
|
+
for (const [info, response] of blockPackRequests) {
|
|
909
|
+
const result = await response;
|
|
910
|
+
const bpInfo = cachedDeserialize(notEmpty(result.data));
|
|
911
|
+
info.blockConfig = extractConfig(bpInfo.config);
|
|
912
|
+
info.blockPack = bpInfo.source;
|
|
913
|
+
}
|
|
914
|
+
//
|
|
915
|
+
// <- at this point we have all the responses from round-trip #3
|
|
916
|
+
//
|
|
917
|
+
// loading ctx export template to check if we already have cached materialized template in our project
|
|
918
|
+
const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();
|
|
919
|
+
// expected field name
|
|
920
|
+
const ctxExportTplCacheFieldName = getServiceTemplateField(ctxExportTplEnvelope.hash);
|
|
921
|
+
const ctxExportTplField = fullResourceState.fields.find((f) => f.name === ctxExportTplCacheFieldName);
|
|
922
|
+
let ctxExportTplHolder;
|
|
923
|
+
if (ctxExportTplField !== undefined)
|
|
924
|
+
ctxExportTplHolder = ensureResourceIdNotNull(ctxExportTplField.value);
|
|
925
|
+
else {
|
|
926
|
+
ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));
|
|
927
|
+
tx.createField(field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)), 'Dynamic', ctxExportTplHolder);
|
|
928
|
+
}
|
|
929
|
+
const renderingState = { stagingRefreshTimestamp };
|
|
930
|
+
const blocksInLimboSet = new Set(blocksInLimbo);
|
|
931
|
+
const blockInfos = new Map();
|
|
932
|
+
blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id, new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));
|
|
933
|
+
// check consistency of project state
|
|
934
|
+
const blockInStruct = new Set();
|
|
935
|
+
for (const b of allBlocks(structure)) {
|
|
936
|
+
if (!blockInfos.has(b.id))
|
|
937
|
+
throw new Error(`Inconsistent project structure: no inputs for ${b.id}`);
|
|
938
|
+
blockInStruct.add(b.id);
|
|
939
|
+
}
|
|
940
|
+
blockInfos.forEach((info) => {
|
|
941
|
+
if (!blockInStruct.has(info.id))
|
|
942
|
+
throw new Error(`Inconsistent project structure: no structure entry for ${info.id}`);
|
|
943
|
+
// checking structure
|
|
944
|
+
info.check();
|
|
945
|
+
});
|
|
946
|
+
const prj = new ProjectMutator(rid, tx, author, schema, lastModified, meta, structure, renderingState, blocksInLimboSet, blockInfos, ctxExportTplHolder, projectHelper);
|
|
947
|
+
prj.fixProblemsAndMigrate();
|
|
948
|
+
return prj;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
async function createProject(tx, meta = InitialBlockMeta) {
|
|
952
|
+
const prj = tx.createEphemeral(ProjectResourceType);
|
|
953
|
+
tx.lock(prj);
|
|
954
|
+
const ts = String(Date.now());
|
|
955
|
+
tx.setKValue(prj, SchemaVersionKey, JSON.stringify(SchemaVersionCurrent));
|
|
956
|
+
tx.setKValue(prj, ProjectCreatedTimestamp, ts);
|
|
957
|
+
tx.setKValue(prj, ProjectLastModifiedTimestamp, ts);
|
|
958
|
+
tx.setKValue(prj, ProjectMetaKey, JSON.stringify(meta));
|
|
959
|
+
tx.setKValue(prj, ProjectStructureKey, JSON.stringify(InitialBlockStructure));
|
|
960
|
+
tx.setKValue(prj, BlockRenderingStateKey, JSON.stringify(InitialProjectRenderingState));
|
|
961
|
+
const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();
|
|
962
|
+
tx.createField(field(prj, getServiceTemplateField(ctxExportTplEnvelope.hash)), 'Dynamic', Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec)));
|
|
963
|
+
return prj;
|
|
964
|
+
}
|
|
965
|
+
async function withProject(projectHelper, txOrPl, rid, cb) {
|
|
966
|
+
return withProjectAuthored(projectHelper, txOrPl, rid, undefined, cb);
|
|
967
|
+
}
|
|
968
|
+
async function withProjectAuthored(projectHelper, txOrPl, rid, author, cb, ops = {}) {
|
|
969
|
+
if (txOrPl instanceof PlClient) {
|
|
970
|
+
return await txOrPl.withWriteTx('ProjectAction', async (tx) => {
|
|
971
|
+
const mut = await ProjectMutator.load(projectHelper, tx, rid, author);
|
|
972
|
+
const result = await cb(mut);
|
|
973
|
+
if (!mut.wasModified)
|
|
974
|
+
// skipping save and commit altogether if no modifications were actually made
|
|
975
|
+
return result;
|
|
976
|
+
mut.save();
|
|
977
|
+
await tx.commit();
|
|
978
|
+
if (getDebugFlags().logProjectMutationStat)
|
|
979
|
+
console.log(JSON.stringify(tx.stat));
|
|
980
|
+
return result;
|
|
981
|
+
}, ops);
|
|
982
|
+
}
|
|
983
|
+
else {
|
|
984
|
+
const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);
|
|
985
|
+
const result = await cb(mut);
|
|
986
|
+
mut.save();
|
|
987
|
+
return result;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
export { ProjectMutator, createProject, withProject, withProjectAuthored };
|
|
992
|
+
//# sourceMappingURL=project.js.map
|