@milaboratories/pl-middle-layer 1.46.20 → 1.46.22
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 +3 -3
- package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
- package/dist/block_registry/registry-v2-provider.d.ts +2 -2
- package/dist/block_registry/registry-v2-provider.js.map +1 -1
- package/dist/block_registry/registry.cjs +54 -53
- package/dist/block_registry/registry.cjs.map +1 -1
- package/dist/block_registry/registry.d.ts +4 -4
- package/dist/block_registry/registry.d.ts.map +1 -1
- package/dist/block_registry/registry.js +54 -53
- package/dist/block_registry/registry.js.map +1 -1
- package/dist/block_registry/watcher.cjs +12 -12
- package/dist/block_registry/watcher.cjs.map +1 -1
- package/dist/block_registry/watcher.d.ts +6 -6
- package/dist/block_registry/watcher.d.ts.map +1 -1
- package/dist/block_registry/watcher.js +12 -12
- package/dist/block_registry/watcher.js.map +1 -1
- package/dist/block_registry/well_known_registries.cjs +6 -6
- package/dist/block_registry/well_known_registries.cjs.map +1 -1
- package/dist/block_registry/well_known_registries.d.ts +1 -1
- package/dist/block_registry/well_known_registries.js +6 -6
- package/dist/block_registry/well_known_registries.js.map +1 -1
- package/dist/cfg_render/executor.cjs +11 -11
- package/dist/cfg_render/executor.cjs.map +1 -1
- package/dist/cfg_render/executor.d.ts +5 -5
- package/dist/cfg_render/executor.js +11 -11
- package/dist/cfg_render/executor.js.map +1 -1
- package/dist/cfg_render/operation.d.ts +5 -5
- package/dist/cfg_render/renderer.cjs +74 -75
- package/dist/cfg_render/renderer.cjs.map +1 -1
- package/dist/cfg_render/renderer.d.ts +2 -2
- package/dist/cfg_render/renderer.d.ts.map +1 -1
- package/dist/cfg_render/renderer.js +74 -75
- package/dist/cfg_render/renderer.js.map +1 -1
- package/dist/cfg_render/traverse.cjs +27 -27
- package/dist/cfg_render/traverse.cjs.map +1 -1
- package/dist/cfg_render/traverse.d.ts +1 -1
- package/dist/cfg_render/traverse.js +27 -27
- package/dist/cfg_render/traverse.js.map +1 -1
- package/dist/cfg_render/util.cjs +1 -1
- package/dist/cfg_render/util.cjs.map +1 -1
- package/dist/cfg_render/util.d.ts +1 -1
- package/dist/cfg_render/util.js +1 -1
- package/dist/cfg_render/util.js.map +1 -1
- package/dist/debug/index.cjs +4 -2
- package/dist/debug/index.cjs.map +1 -1
- package/dist/debug/index.d.ts +2 -2
- package/dist/debug/index.d.ts.map +1 -1
- package/dist/debug/index.js +4 -2
- package/dist/debug/index.js.map +1 -1
- package/dist/dev_env/index.cjs +8 -8
- package/dist/dev_env/index.cjs.map +1 -1
- package/dist/dev_env/index.js +8 -8
- package/dist/dev_env/index.js.map +1 -1
- package/dist/dev_env/util.cjs +1 -1
- package/dist/dev_env/util.cjs.map +1 -1
- package/dist/dev_env/util.d.ts +1 -1
- package/dist/dev_env/util.js +1 -1
- package/dist/dev_env/util.js.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/js_render/computable_context.cjs +78 -78
- package/dist/js_render/computable_context.cjs.map +1 -1
- package/dist/js_render/computable_context.d.ts +9 -9
- package/dist/js_render/computable_context.d.ts.map +1 -1
- package/dist/js_render/computable_context.js +78 -78
- package/dist/js_render/computable_context.js.map +1 -1
- package/dist/js_render/context.cjs +33 -27
- package/dist/js_render/context.cjs.map +1 -1
- package/dist/js_render/context.d.ts +7 -7
- package/dist/js_render/context.d.ts.map +1 -1
- package/dist/js_render/context.js +33 -27
- package/dist/js_render/context.js.map +1 -1
- package/dist/js_render/index.cjs +10 -6
- package/dist/js_render/index.cjs.map +1 -1
- package/dist/js_render/index.d.ts +6 -6
- package/dist/js_render/index.d.ts.map +1 -1
- package/dist/js_render/index.js +10 -6
- package/dist/js_render/index.js.map +1 -1
- package/dist/middle_layer/active_cfg.cjs.map +1 -1
- package/dist/middle_layer/active_cfg.d.ts +3 -3
- package/dist/middle_layer/active_cfg.d.ts.map +1 -1
- package/dist/middle_layer/active_cfg.js.map +1 -1
- package/dist/middle_layer/block.cjs +1 -1
- package/dist/middle_layer/block.cjs.map +1 -1
- package/dist/middle_layer/block.d.ts +6 -6
- package/dist/middle_layer/block.d.ts.map +1 -1
- package/dist/middle_layer/block.js +1 -1
- package/dist/middle_layer/block.js.map +1 -1
- package/dist/middle_layer/block_ctx.cjs +9 -9
- package/dist/middle_layer/block_ctx.cjs.map +1 -1
- package/dist/middle_layer/block_ctx.d.ts +6 -6
- package/dist/middle_layer/block_ctx.d.ts.map +1 -1
- package/dist/middle_layer/block_ctx.js +9 -9
- package/dist/middle_layer/block_ctx.js.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.cjs +1 -1
- package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.d.ts +5 -5
- package/dist/middle_layer/block_ctx_unsafe.js +1 -1
- package/dist/middle_layer/block_ctx_unsafe.js.map +1 -1
- package/dist/middle_layer/driver_kit.cjs +1 -2
- package/dist/middle_layer/driver_kit.cjs.map +1 -1
- package/dist/middle_layer/driver_kit.d.ts +7 -7
- package/dist/middle_layer/driver_kit.d.ts.map +1 -1
- package/dist/middle_layer/driver_kit.js +1 -2
- package/dist/middle_layer/driver_kit.js.map +1 -1
- package/dist/middle_layer/frontend_path.cjs +5 -5
- package/dist/middle_layer/frontend_path.cjs.map +1 -1
- package/dist/middle_layer/frontend_path.d.ts +4 -4
- package/dist/middle_layer/frontend_path.d.ts.map +1 -1
- package/dist/middle_layer/frontend_path.js +5 -5
- package/dist/middle_layer/frontend_path.js.map +1 -1
- package/dist/middle_layer/index.d.ts +4 -4
- package/dist/middle_layer/middle_layer.cjs +11 -11
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +18 -18
- package/dist/middle_layer/middle_layer.d.ts.map +1 -1
- package/dist/middle_layer/middle_layer.js +11 -11
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/navigation_states.cjs +2 -2
- package/dist/middle_layer/navigation_states.cjs.map +1 -1
- package/dist/middle_layer/navigation_states.d.ts +2 -2
- package/dist/middle_layer/navigation_states.js +2 -2
- package/dist/middle_layer/navigation_states.js.map +1 -1
- package/dist/middle_layer/ops.cjs +5 -5
- package/dist/middle_layer/ops.cjs.map +1 -1
- package/dist/middle_layer/ops.d.ts +11 -11
- package/dist/middle_layer/ops.d.ts.map +1 -1
- package/dist/middle_layer/ops.js +5 -5
- package/dist/middle_layer/ops.js.map +1 -1
- package/dist/middle_layer/project.cjs +71 -63
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +10 -10
- package/dist/middle_layer/project.d.ts.map +1 -1
- package/dist/middle_layer/project.js +71 -63
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/middle_layer/project_list.cjs +2 -2
- package/dist/middle_layer/project_list.cjs.map +1 -1
- package/dist/middle_layer/project_list.d.ts +6 -6
- package/dist/middle_layer/project_list.d.ts.map +1 -1
- package/dist/middle_layer/project_list.js +2 -2
- package/dist/middle_layer/project_list.js.map +1 -1
- package/dist/middle_layer/project_overview.cjs +40 -40
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.d.ts +5 -5
- package/dist/middle_layer/project_overview.d.ts.map +1 -1
- package/dist/middle_layer/project_overview.js +40 -40
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/dist/middle_layer/project_overview_light.cjs.map +1 -1
- package/dist/middle_layer/project_overview_light.d.ts +2 -2
- package/dist/middle_layer/project_overview_light.d.ts.map +1 -1
- package/dist/middle_layer/project_overview_light.js.map +1 -1
- package/dist/middle_layer/render.cjs +1 -1
- package/dist/middle_layer/render.cjs.map +1 -1
- package/dist/middle_layer/render.d.ts +4 -4
- package/dist/middle_layer/render.js +1 -1
- package/dist/middle_layer/render.js.map +1 -1
- package/dist/middle_layer/render.test.d.ts +2 -2
- package/dist/middle_layer/types.d.ts +3 -3
- package/dist/middle_layer/util.cjs +9 -4
- package/dist/middle_layer/util.cjs.map +1 -1
- package/dist/middle_layer/util.d.ts +4 -4
- package/dist/middle_layer/util.d.ts.map +1 -1
- package/dist/middle_layer/util.js +9 -4
- package/dist/middle_layer/util.js.map +1 -1
- package/dist/model/args.cjs +19 -15
- package/dist/model/args.cjs.map +1 -1
- package/dist/model/args.d.ts +1 -1
- package/dist/model/args.d.ts.map +1 -1
- package/dist/model/args.js +19 -15
- package/dist/model/args.js.map +1 -1
- package/dist/model/block_pack.d.ts +2 -2
- package/dist/model/block_pack_spec.cjs +3 -3
- package/dist/model/block_pack_spec.cjs.map +1 -1
- package/dist/model/block_pack_spec.d.ts +8 -8
- package/dist/model/block_pack_spec.js +3 -3
- package/dist/model/block_pack_spec.js.map +1 -1
- package/dist/model/block_storage_helper.cjs +4 -4
- package/dist/model/block_storage_helper.cjs.map +1 -1
- package/dist/model/block_storage_helper.d.ts +2 -2
- package/dist/model/block_storage_helper.d.ts.map +1 -1
- package/dist/model/block_storage_helper.js +4 -4
- package/dist/model/block_storage_helper.js.map +1 -1
- package/dist/model/index.d.ts +3 -3
- package/dist/model/project_helper.cjs +30 -13
- package/dist/model/project_helper.cjs.map +1 -1
- package/dist/model/project_helper.d.ts +4 -4
- package/dist/model/project_helper.d.ts.map +1 -1
- package/dist/model/project_helper.js +30 -13
- package/dist/model/project_helper.js.map +1 -1
- package/dist/model/project_model.cjs +23 -23
- package/dist/model/project_model.cjs.map +1 -1
- package/dist/model/project_model.d.ts +6 -6
- package/dist/model/project_model.d.ts.map +1 -1
- package/dist/model/project_model.js +23 -23
- package/dist/model/project_model.js.map +1 -1
- package/dist/model/project_model_util.cjs +2 -2
- package/dist/model/project_model_util.cjs.map +1 -1
- package/dist/model/project_model_util.d.ts +3 -3
- package/dist/model/project_model_util.d.ts.map +1 -1
- package/dist/model/project_model_util.js +2 -2
- package/dist/model/project_model_util.js.map +1 -1
- package/dist/model/project_model_v1.cjs +2 -2
- package/dist/model/project_model_v1.cjs.map +1 -1
- package/dist/model/project_model_v1.js +2 -2
- package/dist/model/project_model_v1.js.map +1 -1
- package/dist/model/template_spec.d.ts +5 -5
- package/dist/mutator/block-pack/block_pack.cjs +43 -43
- package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
- package/dist/mutator/block-pack/block_pack.d.ts +6 -6
- package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
- package/dist/mutator/block-pack/block_pack.js +43 -43
- package/dist/mutator/block-pack/block_pack.js.map +1 -1
- package/dist/mutator/block-pack/frontend.cjs +2 -2
- package/dist/mutator/block-pack/frontend.cjs.map +1 -1
- package/dist/mutator/block-pack/frontend.d.ts +2 -2
- package/dist/mutator/block-pack/frontend.d.ts.map +1 -1
- package/dist/mutator/block-pack/frontend.js +2 -2
- package/dist/mutator/block-pack/frontend.js.map +1 -1
- package/dist/mutator/context_export.cjs +5 -5
- package/dist/mutator/context_export.cjs.map +1 -1
- package/dist/mutator/context_export.d.ts +2 -2
- package/dist/mutator/context_export.d.ts.map +1 -1
- package/dist/mutator/context_export.js +5 -5
- package/dist/mutator/context_export.js.map +1 -1
- package/dist/mutator/migration.cjs +7 -7
- package/dist/mutator/migration.cjs.map +1 -1
- package/dist/mutator/migration.d.ts +1 -1
- package/dist/mutator/migration.d.ts.map +1 -1
- package/dist/mutator/migration.js +7 -7
- package/dist/mutator/migration.js.map +1 -1
- package/dist/mutator/project.cjs +147 -148
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.d.ts +13 -13
- package/dist/mutator/project.d.ts.map +1 -1
- package/dist/mutator/project.js +147 -148
- package/dist/mutator/project.js.map +1 -1
- package/dist/mutator/template/direct_template_loader.cjs +16 -16
- package/dist/mutator/template/direct_template_loader.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader.d.ts +2 -2
- package/dist/mutator/template/direct_template_loader.d.ts.map +1 -1
- package/dist/mutator/template/direct_template_loader.js +16 -16
- package/dist/mutator/template/direct_template_loader.js.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.cjs +13 -13
- package/dist/mutator/template/direct_template_loader_v3.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.d.ts +3 -3
- package/dist/mutator/template/direct_template_loader_v3.d.ts.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.js +13 -13
- package/dist/mutator/template/direct_template_loader_v3.js.map +1 -1
- package/dist/mutator/template/render_block.cjs +7 -7
- package/dist/mutator/template/render_block.cjs.map +1 -1
- package/dist/mutator/template/render_block.d.ts +1 -1
- package/dist/mutator/template/render_block.d.ts.map +1 -1
- package/dist/mutator/template/render_block.js +7 -7
- package/dist/mutator/template/render_block.js.map +1 -1
- package/dist/mutator/template/render_template.cjs +10 -10
- package/dist/mutator/template/render_template.cjs.map +1 -1
- package/dist/mutator/template/render_template.d.ts +2 -2
- package/dist/mutator/template/render_template.js +10 -10
- package/dist/mutator/template/render_template.js.map +1 -1
- package/dist/mutator/template/template_loading.cjs +17 -17
- package/dist/mutator/template/template_loading.cjs.map +1 -1
- package/dist/mutator/template/template_loading.d.ts +2 -2
- package/dist/mutator/template/template_loading.js +17 -17
- package/dist/mutator/template/template_loading.js.map +1 -1
- package/dist/network_check/network_check.cjs +33 -32
- package/dist/network_check/network_check.cjs.map +1 -1
- package/dist/network_check/network_check.d.ts +6 -6
- package/dist/network_check/network_check.d.ts.map +1 -1
- package/dist/network_check/network_check.js +33 -32
- package/dist/network_check/network_check.js.map +1 -1
- package/dist/network_check/pings.cjs +3 -3
- package/dist/network_check/pings.cjs.map +1 -1
- package/dist/network_check/pings.d.ts +4 -4
- package/dist/network_check/pings.d.ts.map +1 -1
- package/dist/network_check/pings.js +3 -3
- package/dist/network_check/pings.js.map +1 -1
- package/dist/network_check/template.cjs +57 -44
- package/dist/network_check/template.cjs.map +1 -1
- package/dist/network_check/template.d.ts +8 -8
- package/dist/network_check/template.d.ts.map +1 -1
- package/dist/network_check/template.js +57 -44
- package/dist/network_check/template.js.map +1 -1
- package/dist/pool/data.cjs +45 -33
- package/dist/pool/data.cjs.map +1 -1
- package/dist/pool/data.d.ts +3 -3
- package/dist/pool/data.d.ts.map +1 -1
- package/dist/pool/data.js +45 -33
- package/dist/pool/data.js.map +1 -1
- package/dist/pool/driver.cjs +18 -16
- package/dist/pool/driver.cjs.map +1 -1
- package/dist/pool/driver.d.ts +5 -5
- package/dist/pool/driver.d.ts.map +1 -1
- package/dist/pool/driver.js +18 -16
- package/dist/pool/driver.js.map +1 -1
- package/dist/pool/index.d.ts +2 -2
- package/dist/pool/p_object_collection.cjs +5 -5
- package/dist/pool/p_object_collection.cjs.map +1 -1
- package/dist/pool/p_object_collection.d.ts +2 -2
- package/dist/pool/p_object_collection.d.ts.map +1 -1
- package/dist/pool/p_object_collection.js +5 -5
- package/dist/pool/p_object_collection.js.map +1 -1
- package/dist/pool/result_pool.cjs +6 -6
- package/dist/pool/result_pool.cjs.map +1 -1
- package/dist/pool/result_pool.d.ts +6 -6
- package/dist/pool/result_pool.d.ts.map +1 -1
- package/dist/pool/result_pool.js +6 -6
- package/dist/pool/result_pool.js.map +1 -1
- package/dist/test/block_packs.d.ts +2 -2
- package/dist/test/known_templates.d.ts +1 -1
- package/dist/worker/WorkerManager.cjs +7 -8
- package/dist/worker/WorkerManager.cjs.map +1 -1
- package/dist/worker/WorkerManager.d.ts +2 -2
- package/dist/worker/WorkerManager.d.ts.map +1 -1
- package/dist/worker/WorkerManager.js +7 -8
- package/dist/worker/WorkerManager.js.map +1 -1
- package/dist/worker/worker.cjs +6 -4
- package/dist/worker/worker.cjs.map +1 -1
- package/dist/worker/worker.js +6 -4
- package/dist/worker/worker.js.map +1 -1
- package/dist/worker/workerApi.cjs.map +1 -1
- package/dist/worker/workerApi.js.map +1 -1
- package/package.json +41 -41
- package/src/block_registry/index.ts +3 -3
- package/src/block_registry/registry-v2-provider.ts +2 -2
- package/src/block_registry/registry.test.ts +17 -17
- package/src/block_registry/registry.ts +55 -60
- package/src/block_registry/watcher.ts +24 -23
- package/src/block_registry/well_known_registries.ts +7 -7
- package/src/cfg_render/executor.test.ts +36 -36
- package/src/cfg_render/executor.ts +24 -24
- package/src/cfg_render/operation.ts +5 -5
- package/src/cfg_render/renderer.ts +96 -93
- package/src/cfg_render/traverse.ts +50 -50
- package/src/cfg_render/util.ts +3 -3
- package/src/debug/index.ts +6 -4
- package/src/dev_env/index.ts +16 -16
- package/src/dev_env/util.ts +3 -3
- package/src/index.ts +16 -16
- package/src/js_render/computable_context.ts +143 -126
- package/src/js_render/context.ts +72 -44
- package/src/js_render/index.ts +51 -24
- package/src/middle_layer/active_cfg.ts +14 -12
- package/src/middle_layer/block.ts +30 -23
- package/src/middle_layer/block_ctx.ts +27 -31
- package/src/middle_layer/block_ctx_unsafe.ts +9 -9
- package/src/middle_layer/driver_kit.ts +13 -19
- package/src/middle_layer/frontend_path.ts +18 -23
- package/src/middle_layer/index.ts +4 -4
- package/src/middle_layer/middle_layer.ts +57 -55
- package/src/middle_layer/navigation_states.ts +6 -6
- package/src/middle_layer/ops.ts +43 -42
- package/src/middle_layer/project.ts +274 -173
- package/src/middle_layer/project_list.ts +14 -15
- package/src/middle_layer/project_overview.ts +104 -113
- package/src/middle_layer/project_overview_light.ts +7 -9
- package/src/middle_layer/render.test.ts +49 -48
- package/src/middle_layer/render.ts +9 -9
- package/src/middle_layer/types.ts +3 -3
- package/src/middle_layer/util.ts +17 -12
- package/src/model/args.ts +22 -19
- package/src/model/block_pack.ts +2 -2
- package/src/model/block_pack_spec.ts +11 -11
- package/src/model/block_storage_helper.ts +11 -11
- package/src/model/index.ts +3 -3
- package/src/model/project_helper.ts +78 -32
- package/src/model/project_model.test.ts +5 -9
- package/src/model/project_model.ts +48 -49
- package/src/model/project_model_util.test.ts +86 -53
- package/src/model/project_model_util.ts +18 -14
- package/src/model/project_model_v1.ts +3 -3
- package/src/model/template_spec.ts +5 -5
- package/src/mutator/block-pack/block_pack.test.ts +25 -25
- package/src/mutator/block-pack/block_pack.ts +70 -68
- package/src/mutator/block-pack/frontend.ts +6 -13
- package/src/mutator/context_export.ts +12 -10
- package/src/mutator/migration.ts +20 -14
- package/src/mutator/project-v3.test.ts +123 -118
- package/src/mutator/project.test.ts +105 -94
- package/src/mutator/project.ts +357 -274
- package/src/mutator/template/direct_template_loader.ts +26 -32
- package/src/mutator/template/direct_template_loader_v3.ts +51 -25
- package/src/mutator/template/render_block.ts +14 -21
- package/src/mutator/template/render_template.ts +13 -13
- package/src/mutator/template/template_loading.ts +23 -23
- package/src/mutator/template/template_render.test.ts +87 -86
- package/src/network_check/network_check.test.ts +4 -4
- package/src/network_check/network_check.ts +102 -79
- package/src/network_check/pings.ts +35 -16
- package/src/network_check/template.test.ts +47 -44
- package/src/network_check/template.ts +151 -95
- package/src/network_check/test_utils.ts +1 -1
- package/src/pool/data.ts +81 -69
- package/src/pool/driver.ts +56 -51
- package/src/pool/index.ts +2 -2
- package/src/pool/p_object_collection.ts +16 -15
- package/src/pool/result_pool.ts +23 -34
- package/src/test/block_packs.ts +15 -15
- package/src/test/explicit_templates.ts +4 -4
- package/src/test/known_templates.ts +10 -10
- package/src/test_env.ts +1 -1
- package/src/worker/WorkerManager.ts +22 -18
- package/src/worker/worker.ts +11 -9
- package/src/worker/workerApi.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_pack.cjs","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { Code } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\nimport { z } from 'zod';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error('Invalid config content');\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error('parseStringConfig:No code bundle');\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString('utf8'));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent);\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return parseStringConfig(configContent);\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString('utf8'));\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n );\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(Buffer.from(configResponse).toString('utf8')) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":["z","Code","LRUCache","request","resolveDevPacket","loadPackDescription","RegistryV1","assertNever","__addDisposableResource","WorkerManager","getDevV2PacketMtime","field","loadTemplate","createFrontend"],"mappings":";;;;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAGA,KAAC,CAAC,MAAM,CAACA,KAAC,CAAC,MAAM,EAAE,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAElF,IAAA,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IAC3C;AAEA,IAAA,IAAI,CAACC,UAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;AAC1C,QAAA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;IACrD;IAEA,OAAO,GAAG,CA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AE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;AACjF,IAAA,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9E,EAAE,CAAC,WAAW,CAACI,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEC,6BAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAACD,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEE,uBAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAON,qBAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"block_pack.cjs","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport fs from \"node:fs\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport { loadPackDescription, RegistryV1 } from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: await workerManager.process(\"parseTemplate\", explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":["z","Code","LRUCache","request","resolveDevPacket","loadPackDescription","RegistryV1","assertNever","__addDisposableResource","WorkerManager","getDevV2PacketMtime","field","loadTemplate","createFrontend"],"mappings":";;;;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAGA,KAAC,CAAC,MAAM,CAACA,KAAC,CAAC,MAAM,EAAE,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAElF,IAAA,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IAC3C;AAEA,IAAA,IAAI,CAACC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AW,CAAC,IAAI,CAAC;;IAE9B;AACD;AAED,SAAS,qBAAqB,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC3E,IAAA,MAAM,aAAa,GAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;AACjF,IAAA,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9E,EAAE,CAAC,WAAW,CAACI,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEC,6BAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAACD,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEE,uBAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAON,qBAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { AnyResourceRef, PlTransaction, ResourceType } from
|
|
2
|
-
import type { BlockPackSpecAny, BlockPackSpecPrepared } from
|
|
3
|
-
import type { Signer } from
|
|
4
|
-
import type { Dispatcher } from
|
|
5
|
-
import type { BlockConfigContainer } from
|
|
6
|
-
import type { V2RegistryProvider } from
|
|
1
|
+
import type { AnyResourceRef, PlTransaction, ResourceType } from "@milaboratories/pl-client";
|
|
2
|
+
import type { BlockPackSpecAny, BlockPackSpecPrepared } from "../../model";
|
|
3
|
+
import type { Signer } from "@milaboratories/ts-helpers";
|
|
4
|
+
import type { Dispatcher } from "undici";
|
|
5
|
+
import type { BlockConfigContainer } from "@platforma-sdk/model";
|
|
6
|
+
import type { V2RegistryProvider } from "../../block_registry/registry-v2-provider";
|
|
7
7
|
export declare const BlockPackCustomType: ResourceType;
|
|
8
8
|
export declare const BlockPackTemplateField = "template";
|
|
9
9
|
export declare const BlockPackFrontendField = "frontend";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_pack.d.ts","sourceRoot":"","sources":["../../../src/mutator/block-pack/block_pack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG7F,OAAO,KAAK,EAAqB,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAMjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAMpF,eAAO,MAAM,mBAAmB,EAAE,YAAwD,CAAC;AAC3F,eAAO,MAAM,sBAAsB,aAAa,CAAC;AACjD,eAAO,MAAM,sBAAsB,aAAa,CAAC;AA0BjD,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAFL,kBAAkB,EAAE,kBAAkB,EACtC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,UAAU,YAAA;IAGpC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAQhC;IAEU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gB,eAAe,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,qBAAqB,GAAG,cAAc,CAO9F"}
|
|
@@ -13,12 +13,12 @@ import { LRUCache } from 'lru-cache';
|
|
|
13
13
|
import { WorkerManager } from '../../worker/WorkerManager.js';
|
|
14
14
|
import { z } from 'zod';
|
|
15
15
|
|
|
16
|
-
const BlockPackCustomType = { name:
|
|
17
|
-
const BlockPackTemplateField =
|
|
18
|
-
const BlockPackFrontendField =
|
|
16
|
+
const BlockPackCustomType = { name: "BlockPackCustom", version: "1" };
|
|
17
|
+
const BlockPackTemplateField = "template";
|
|
18
|
+
const BlockPackFrontendField = "frontend";
|
|
19
19
|
/** Ensure trailing slash */
|
|
20
20
|
function tSlash(str) {
|
|
21
|
-
if (str.endsWith(
|
|
21
|
+
if (str.endsWith("/"))
|
|
22
22
|
return str;
|
|
23
23
|
else
|
|
24
24
|
return `${str}/`;
|
|
@@ -26,15 +26,15 @@ function tSlash(str) {
|
|
|
26
26
|
function parseStringConfig(configContent) {
|
|
27
27
|
const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));
|
|
28
28
|
if (!res.success) {
|
|
29
|
-
throw new Error(
|
|
29
|
+
throw new Error("Invalid config content");
|
|
30
30
|
}
|
|
31
31
|
if (!Code.safeParse(res.data.code).success) {
|
|
32
|
-
throw new Error(
|
|
32
|
+
throw new Error("parseStringConfig:No code bundle");
|
|
33
33
|
}
|
|
34
34
|
return res.data;
|
|
35
35
|
}
|
|
36
36
|
function parseBufferConfig(buffer) {
|
|
37
|
-
return parseStringConfig(Buffer.from(buffer).toString(
|
|
37
|
+
return parseStringConfig(Buffer.from(buffer).toString("utf8"));
|
|
38
38
|
}
|
|
39
39
|
class BlockPackPreparer {
|
|
40
40
|
v2RegistryProvider;
|
|
@@ -56,28 +56,28 @@ class BlockPackPreparer {
|
|
|
56
56
|
});
|
|
57
57
|
async getBlockConfigContainer(spec) {
|
|
58
58
|
switch (spec.type) {
|
|
59
|
-
case
|
|
59
|
+
case "explicit":
|
|
60
60
|
return spec.config;
|
|
61
|
-
case
|
|
61
|
+
case "prepared":
|
|
62
62
|
return spec.config;
|
|
63
|
-
case
|
|
63
|
+
case "dev-v1": {
|
|
64
64
|
const devPaths = await resolveDevPacket(spec.folder);
|
|
65
|
-
const configContent = await fs.promises.readFile(devPaths.config, { encoding:
|
|
65
|
+
const configContent = await fs.promises.readFile(devPaths.config, { encoding: "utf-8" });
|
|
66
66
|
return JSON.parse(configContent);
|
|
67
67
|
}
|
|
68
|
-
case
|
|
68
|
+
case "dev-v2": {
|
|
69
69
|
const description = await loadPackDescription(spec.folder);
|
|
70
70
|
const configContent = await fs.promises.readFile(description.components.model.file, {
|
|
71
|
-
encoding:
|
|
71
|
+
encoding: "utf-8",
|
|
72
72
|
});
|
|
73
73
|
return parseStringConfig(configContent);
|
|
74
74
|
}
|
|
75
|
-
case
|
|
75
|
+
case "from-registry-v1": {
|
|
76
76
|
const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;
|
|
77
77
|
const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
|
|
78
|
-
return JSON.parse(Buffer.from(configResponse).toString(
|
|
78
|
+
return JSON.parse(Buffer.from(configResponse).toString("utf8"));
|
|
79
79
|
}
|
|
80
|
-
case
|
|
80
|
+
case "from-registry-v2": {
|
|
81
81
|
const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
|
|
82
82
|
const components = await registry.getComponents(spec.id);
|
|
83
83
|
const configResponse = await this.remoteContentCache.forceFetch(components.model.url);
|
|
@@ -90,17 +90,17 @@ class BlockPackPreparer {
|
|
|
90
90
|
async prepare(spec) {
|
|
91
91
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
92
92
|
try {
|
|
93
|
-
if (spec.type ===
|
|
93
|
+
if (spec.type === "prepared") {
|
|
94
94
|
return spec;
|
|
95
95
|
}
|
|
96
96
|
const explicit = await this.prepareWithoutUnpacking(spec);
|
|
97
97
|
const workerManager = __addDisposableResource(env_1, new WorkerManager(), true);
|
|
98
98
|
return {
|
|
99
99
|
...explicit,
|
|
100
|
-
type:
|
|
100
|
+
type: "prepared",
|
|
101
101
|
template: {
|
|
102
|
-
type:
|
|
103
|
-
data: await workerManager.process(
|
|
102
|
+
type: "prepared",
|
|
103
|
+
data: await workerManager.process("parseTemplate", explicit.template.content),
|
|
104
104
|
},
|
|
105
105
|
};
|
|
106
106
|
}
|
|
@@ -116,35 +116,35 @@ class BlockPackPreparer {
|
|
|
116
116
|
}
|
|
117
117
|
async prepareWithoutUnpacking(spec) {
|
|
118
118
|
switch (spec.type) {
|
|
119
|
-
case
|
|
119
|
+
case "explicit":
|
|
120
120
|
return spec;
|
|
121
|
-
case
|
|
121
|
+
case "dev-v1": {
|
|
122
122
|
const devPaths = await resolveDevPacket(spec.folder);
|
|
123
123
|
// template
|
|
124
124
|
const templateContent = await fs.promises.readFile(devPaths.workflow);
|
|
125
125
|
// config
|
|
126
|
-
const config = JSON.parse(await fs.promises.readFile(devPaths.config,
|
|
126
|
+
const config = JSON.parse(await fs.promises.readFile(devPaths.config, "utf-8"));
|
|
127
127
|
// frontend
|
|
128
128
|
const frontendPath = devPaths.ui;
|
|
129
129
|
return {
|
|
130
|
-
type:
|
|
130
|
+
type: "explicit",
|
|
131
131
|
template: {
|
|
132
|
-
type:
|
|
132
|
+
type: "explicit",
|
|
133
133
|
content: templateContent,
|
|
134
134
|
},
|
|
135
135
|
config,
|
|
136
136
|
frontend: {
|
|
137
|
-
type:
|
|
137
|
+
type: "local",
|
|
138
138
|
path: frontendPath,
|
|
139
139
|
signature: this.signer.sign(frontendPath),
|
|
140
140
|
},
|
|
141
141
|
source: spec,
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
case
|
|
144
|
+
case "dev-v2": {
|
|
145
145
|
const description = await loadPackDescription(spec.folder);
|
|
146
146
|
const config = parseStringConfig(await fs.promises.readFile(description.components.model.file, {
|
|
147
|
-
encoding:
|
|
147
|
+
encoding: "utf-8",
|
|
148
148
|
}));
|
|
149
149
|
const workflowContent = await fs.promises.readFile(description.components.workflow.main.file);
|
|
150
150
|
const frontendPath = description.components.ui.folder;
|
|
@@ -153,21 +153,21 @@ class BlockPackPreparer {
|
|
|
153
153
|
// if absent, calculating the mtime here, so the block will correctly show whether it can be updated
|
|
154
154
|
source.mtime = await getDevV2PacketMtime(description);
|
|
155
155
|
return {
|
|
156
|
-
type:
|
|
156
|
+
type: "explicit",
|
|
157
157
|
template: {
|
|
158
|
-
type:
|
|
158
|
+
type: "explicit",
|
|
159
159
|
content: workflowContent,
|
|
160
160
|
},
|
|
161
161
|
config,
|
|
162
162
|
frontend: {
|
|
163
|
-
type:
|
|
163
|
+
type: "local",
|
|
164
164
|
path: frontendPath,
|
|
165
165
|
signature: this.signer.sign(frontendPath),
|
|
166
166
|
},
|
|
167
167
|
source,
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
|
-
case
|
|
170
|
+
case "from-registry-v1": {
|
|
171
171
|
const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;
|
|
172
172
|
const templateUrl = `${urlPrefix}/template.plj.gz`;
|
|
173
173
|
// template
|
|
@@ -175,36 +175,36 @@ class BlockPackPreparer {
|
|
|
175
175
|
const templateContent = new Uint8Array(templateResponse);
|
|
176
176
|
// config
|
|
177
177
|
const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
|
|
178
|
-
const config = JSON.parse(Buffer.from(configResponse).toString(
|
|
178
|
+
const config = JSON.parse(Buffer.from(configResponse).toString("utf8"));
|
|
179
179
|
return {
|
|
180
|
-
type:
|
|
180
|
+
type: "explicit",
|
|
181
181
|
template: {
|
|
182
|
-
type:
|
|
182
|
+
type: "explicit",
|
|
183
183
|
content: templateContent,
|
|
184
184
|
},
|
|
185
185
|
config,
|
|
186
186
|
frontend: {
|
|
187
|
-
type:
|
|
187
|
+
type: "url",
|
|
188
188
|
url: `${urlPrefix}/frontend.tgz`,
|
|
189
189
|
},
|
|
190
190
|
source: spec,
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
|
-
case
|
|
193
|
+
case "from-registry-v2": {
|
|
194
194
|
const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
|
|
195
195
|
const components = await registry.getComponents(spec.id);
|
|
196
196
|
const getModel = async () => parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));
|
|
197
197
|
const getWorkflow = async () => await this.remoteContentCache.forceFetch(components.workflow.main.url);
|
|
198
198
|
const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);
|
|
199
199
|
return {
|
|
200
|
-
type:
|
|
200
|
+
type: "explicit",
|
|
201
201
|
template: {
|
|
202
|
-
type:
|
|
202
|
+
type: "explicit",
|
|
203
203
|
content: Buffer.from(workflow),
|
|
204
204
|
},
|
|
205
205
|
config: model,
|
|
206
206
|
frontend: {
|
|
207
|
-
type:
|
|
207
|
+
type: "url",
|
|
208
208
|
url: components.ui.url,
|
|
209
209
|
},
|
|
210
210
|
source: spec,
|
|
@@ -218,14 +218,14 @@ class BlockPackPreparer {
|
|
|
218
218
|
function createCustomBlockPack(tx, spec) {
|
|
219
219
|
const blockPackInfo = { config: spec.config, source: spec.source };
|
|
220
220
|
const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));
|
|
221
|
-
tx.createField(field(bp, BlockPackTemplateField),
|
|
222
|
-
tx.createField(field(bp, BlockPackFrontendField),
|
|
221
|
+
tx.createField(field(bp, BlockPackTemplateField), "Input", loadTemplate(tx, spec.template));
|
|
222
|
+
tx.createField(field(bp, BlockPackFrontendField), "Input", createFrontend(tx, spec.frontend));
|
|
223
223
|
tx.lock(bp);
|
|
224
224
|
return bp;
|
|
225
225
|
}
|
|
226
226
|
function createBlockPack(tx, spec) {
|
|
227
227
|
switch (spec.type) {
|
|
228
|
-
case
|
|
228
|
+
case "prepared":
|
|
229
229
|
return createCustomBlockPack(tx, spec);
|
|
230
230
|
default:
|
|
231
231
|
return assertNever(spec.type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_pack.js","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { Code } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\nimport { z } from 'zod';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error('Invalid config content');\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error('parseStringConfig:No code bundle');\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString('utf8'));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent);\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return parseStringConfig(configContent);\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString('utf8'));\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n );\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(Buffer.from(configResponse).toString('utf8')) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;A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;;;;"}
|
|
1
|
+
{"version":3,"file":"block_pack.js","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport fs from \"node:fs\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport { loadPackDescription, RegistryV1 } from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: await workerManager.process(\"parseTemplate\", explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA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,CAAC;;AAEnC;;;;"}
|
|
@@ -6,9 +6,9 @@ var tsHelpers = require('@milaboratories/ts-helpers');
|
|
|
6
6
|
|
|
7
7
|
function createFrontend(tx, spec) {
|
|
8
8
|
switch (spec.type) {
|
|
9
|
-
case
|
|
9
|
+
case "url":
|
|
10
10
|
return tx.createValue(block_pack_spec.FrontendFromUrlResourceType, JSON.stringify({ url: spec.url }));
|
|
11
|
-
case
|
|
11
|
+
case "local":
|
|
12
12
|
return tx.createValue(block_pack_spec.FrontendFromFolderResourceType, JSON.stringify({
|
|
13
13
|
path: spec.path,
|
|
14
14
|
signature: spec.signature,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend.cjs","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from
|
|
1
|
+
{"version":3,"file":"frontend.cjs","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { FrontendFromFolderData, FrontendFromUrlData, FrontendSpec } from \"../../model\";\nimport { FrontendFromFolderResourceType, FrontendFromUrlResourceType } from \"../../model\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case \"url\":\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case \"local\":\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"names":["FrontendFromUrlResourceType","FrontendFromFolderResourceType","assertNever"],"mappings":";;;;;;AAKM,SAAU,cAAc,CAAC,EAAiB,EAAE,IAAkB,EAAA;AAClE,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,EAAE,CAAC,WAAW,CACnBA,2CAA2B,EAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAyB,CAAC,CACzD;AACH,QAAA,KAAK,OAAO;YACV,OAAO,EAAE,CAAC,WAAW,CACnBC,8CAA8B,EAC9B,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,SAAS,EAAE,IAAI,CAAC,SAAS;AACA,aAAA,CAAC,CAC7B;AACH,QAAA;AACE,YAAA,OAAOC,qBAAW,CAAC,IAAI,CAAC;;AAE9B;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyResourceRef, PlTransaction } from
|
|
2
|
-
import type { FrontendSpec } from
|
|
1
|
+
import type { AnyResourceRef, PlTransaction } from "@milaboratories/pl-client";
|
|
2
|
+
import type { FrontendSpec } from "../../model";
|
|
3
3
|
export declare function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef;
|
|
4
4
|
//# sourceMappingURL=frontend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../../../src/mutator/block-pack/frontend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../../../src/mutator/block-pack/frontend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAA+C,YAAY,EAAE,MAAM,aAAa,CAAC;AAI7F,wBAAgB,cAAc,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,cAAc,CAkBpF"}
|
|
@@ -4,9 +4,9 @@ import { assertNever } from '@milaboratories/ts-helpers';
|
|
|
4
4
|
|
|
5
5
|
function createFrontend(tx, spec) {
|
|
6
6
|
switch (spec.type) {
|
|
7
|
-
case
|
|
7
|
+
case "url":
|
|
8
8
|
return tx.createValue(FrontendFromUrlResourceType, JSON.stringify({ url: spec.url }));
|
|
9
|
-
case
|
|
9
|
+
case "local":
|
|
10
10
|
return tx.createValue(FrontendFromFolderResourceType, JSON.stringify({
|
|
11
11
|
path: spec.path,
|
|
12
12
|
signature: spec.signature,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend.js","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from
|
|
1
|
+
{"version":3,"file":"frontend.js","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { FrontendFromFolderData, FrontendFromUrlData, FrontendSpec } from \"../../model\";\nimport { FrontendFromFolderResourceType, FrontendFromUrlResourceType } from \"../../model\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case \"url\":\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case \"local\":\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"names":[],"mappings":";;;;AAKM,SAAU,cAAc,CAAC,EAAiB,EAAE,IAAkB,EAAA;AAClE,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,EAAE,CAAC,WAAW,CACnB,2BAA2B,EAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAyB,CAAC,CACzD;AACH,QAAA,KAAK,OAAO;YACV,OAAO,EAAE,CAAC,WAAW,CACnB,8BAA8B,EAC9B,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,SAAS,EAAE,IAAI,CAAC,SAAS;AACA,aAAA,CAAC,CAC7B;AACH,QAAA;AACE,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC;;AAE9B;;;;"}
|
|
@@ -9,16 +9,16 @@ let preparedTemplateEnvelop;
|
|
|
9
9
|
async function getPreparedExportTemplateEnvelope() {
|
|
10
10
|
if (preparedTemplateEnvelop === undefined) {
|
|
11
11
|
// (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']
|
|
12
|
-
const preparedTemplate = await template_loading.prepareTemplateSpec(workflowTengo.Templates[
|
|
13
|
-
if (preparedTemplate.type !==
|
|
14
|
-
throw new Error(
|
|
15
|
-
const hash = node_crypto.createHash(
|
|
12
|
+
const preparedTemplate = await template_loading.prepareTemplateSpec(workflowTengo.Templates["pframes.export-pframe-for-ui"]);
|
|
13
|
+
if (preparedTemplate.type !== "explicit")
|
|
14
|
+
throw new Error("Unexpected prepared template type.");
|
|
15
|
+
const hash = node_crypto.createHash("sha256").update(preparedTemplate.content).digest("hex");
|
|
16
16
|
preparedTemplateEnvelop = { spec: preparedTemplate, hash };
|
|
17
17
|
}
|
|
18
18
|
return preparedTemplateEnvelop;
|
|
19
19
|
}
|
|
20
20
|
function exportContext(tx, exportTpl, ctx) {
|
|
21
|
-
return render_template.createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [
|
|
21
|
+
return render_template.createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ["result"]).result;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
exports.exportContext = exportContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context_export.cjs","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from
|
|
1
|
+
{"version":3,"file":"context_export.cjs","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport { createRenderTemplate } from \"./template/render_template\";\nimport { prepareTemplateSpec } from \"./template/template_loading\";\nimport type { TemplateSpecPrepared } from \"../model/template_spec\";\nimport { createHash } from \"node:crypto\";\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from \"@platforma-sdk/workflow-tengo\";\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(\n SdkTemplates[\"pframes.export-pframe-for-ui\"],\n );\n if (preparedTemplate.type !== \"explicit\") throw new Error(\"Unexpected prepared template type.\");\n const hash = createHash(\"sha256\").update(preparedTemplate.content).digest(\"hex\");\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [\"result\"]).result;\n}\n"],"names":["prepareTemplateSpec","SdkTemplates","createHash","createRenderTemplate"],"mappings":";;;;;;;AAgBA,IAAI,uBAAoD;AAEjD,eAAe,iCAAiC,GAAA;AACrD,IAAA,IAAI,uBAAuB,KAAK,SAAS,EAAE;;QAEzC,MAAM,gBAAgB,GAAG,MAAMA,oCAAmB,CAChDC,uBAAY,CAAC,8BAA8B,CAAC,CAC7C;AACD,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;AAC/F,QAAA,MAAM,IAAI,GAAGC,sBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAChF,uBAAuB,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC5D;AAEA,IAAA,OAAO,uBAAuB;AAChC;SAEgB,aAAa,CAAC,EAAiB,EAAE,SAAiB,EAAE,GAAW,EAAA;IAC7E,OAAOC,oCAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;AAClF;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AnyRef, PlTransaction } from
|
|
2
|
-
import type { TemplateSpecPrepared } from
|
|
1
|
+
import type { AnyRef, PlTransaction } from "@milaboratories/pl-client";
|
|
2
|
+
import type { TemplateSpecPrepared } from "../model/template_spec";
|
|
3
3
|
export type TemplateEnvelop = {
|
|
4
4
|
spec: TemplateSpecPrepared;
|
|
5
5
|
hash: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context_export.d.ts","sourceRoot":"","sources":["../../src/mutator/context_export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAWnE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI3E,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"context_export.d.ts","sourceRoot":"","sources":["../../src/mutator/context_export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAWnE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI3E,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,eAAe,CAAC,CAYlF;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gDAE9E"}
|
|
@@ -7,16 +7,16 @@ let preparedTemplateEnvelop;
|
|
|
7
7
|
async function getPreparedExportTemplateEnvelope() {
|
|
8
8
|
if (preparedTemplateEnvelop === undefined) {
|
|
9
9
|
// (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']
|
|
10
|
-
const preparedTemplate = await prepareTemplateSpec(Templates[
|
|
11
|
-
if (preparedTemplate.type !==
|
|
12
|
-
throw new Error(
|
|
13
|
-
const hash = createHash(
|
|
10
|
+
const preparedTemplate = await prepareTemplateSpec(Templates["pframes.export-pframe-for-ui"]);
|
|
11
|
+
if (preparedTemplate.type !== "explicit")
|
|
12
|
+
throw new Error("Unexpected prepared template type.");
|
|
13
|
+
const hash = createHash("sha256").update(preparedTemplate.content).digest("hex");
|
|
14
14
|
preparedTemplateEnvelop = { spec: preparedTemplate, hash };
|
|
15
15
|
}
|
|
16
16
|
return preparedTemplateEnvelop;
|
|
17
17
|
}
|
|
18
18
|
function exportContext(tx, exportTpl, ctx) {
|
|
19
|
-
return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [
|
|
19
|
+
return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ["result"]).result;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export { exportContext, getPreparedExportTemplateEnvelope };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context_export.js","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from
|
|
1
|
+
{"version":3,"file":"context_export.js","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport { createRenderTemplate } from \"./template/render_template\";\nimport { prepareTemplateSpec } from \"./template/template_loading\";\nimport type { TemplateSpecPrepared } from \"../model/template_spec\";\nimport { createHash } from \"node:crypto\";\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from \"@platforma-sdk/workflow-tengo\";\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(\n SdkTemplates[\"pframes.export-pframe-for-ui\"],\n );\n if (preparedTemplate.type !== \"explicit\") throw new Error(\"Unexpected prepared template type.\");\n const hash = createHash(\"sha256\").update(preparedTemplate.content).digest(\"hex\");\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [\"result\"]).result;\n}\n"],"names":["SdkTemplates"],"mappings":";;;;;AAgBA,IAAI,uBAAoD;AAEjD,eAAe,iCAAiC,GAAA;AACrD,IAAA,IAAI,uBAAuB,KAAK,SAAS,EAAE;;QAEzC,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAChDA,SAAY,CAAC,8BAA8B,CAAC,CAC7C;AACD,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;AAC/F,QAAA,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAChF,uBAAuB,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC5D;AAEA,IAAA,OAAO,uBAAuB;AAChC;SAEgB,aAAa,CAAC,EAAiB,EAAE,SAAiB,EAAE,GAAW,EAAA;IAC7E,OAAO,oBAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;AAClF;;;;"}
|