@milaboratories/pl-middle-layer 1.48.11 → 1.48.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_@oxc-project_runtime@0.114.0/helpers/usingCtx.cjs +59 -0
- package/dist/_virtual/_@oxc-project_runtime@0.114.0/helpers/usingCtx.js +58 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/block_registry/index.cjs +3 -0
- package/dist/block_registry/index.d.ts +3 -4
- package/dist/block_registry/index.js +3 -0
- package/dist/block_registry/registry-v2-provider.cjs +18 -19
- package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
- package/dist/block_registry/registry-v2-provider.d.ts +10 -6
- package/dist/block_registry/registry-v2-provider.js +17 -17
- package/dist/block_registry/registry-v2-provider.js.map +1 -1
- package/dist/block_registry/registry.cjs +188 -219
- package/dist/block_registry/registry.cjs.map +1 -1
- package/dist/block_registry/registry.d.ts +18 -14
- package/dist/block_registry/registry.js +184 -217
- package/dist/block_registry/registry.js.map +1 -1
- package/dist/block_registry/watcher.cjs +141 -170
- package/dist/block_registry/watcher.cjs.map +1 -1
- package/dist/block_registry/watcher.d.ts +26 -24
- package/dist/block_registry/watcher.js +139 -168
- package/dist/block_registry/watcher.js.map +1 -1
- package/dist/block_registry/well_known_registries.cjs +9 -8
- package/dist/block_registry/well_known_registries.cjs.map +1 -1
- package/dist/block_registry/well_known_registries.d.ts +8 -4
- package/dist/block_registry/well_known_registries.js +9 -7
- package/dist/block_registry/well_known_registries.js.map +1 -1
- package/dist/cfg_render/executor.cjs +136 -137
- package/dist/cfg_render/executor.cjs.map +1 -1
- package/dist/cfg_render/executor.js +133 -135
- package/dist/cfg_render/executor.js.map +1 -1
- package/dist/cfg_render/renderer.cjs +354 -462
- package/dist/cfg_render/renderer.cjs.map +1 -1
- package/dist/cfg_render/renderer.js +353 -460
- package/dist/cfg_render/renderer.js.map +1 -1
- package/dist/cfg_render/traverse.cjs +58 -60
- package/dist/cfg_render/traverse.cjs.map +1 -1
- package/dist/cfg_render/traverse.js +57 -58
- package/dist/cfg_render/traverse.js.map +1 -1
- package/dist/cfg_render/util.cjs +14 -19
- package/dist/cfg_render/util.cjs.map +1 -1
- package/dist/cfg_render/util.js +14 -17
- package/dist/cfg_render/util.js.map +1 -1
- package/dist/debug/index.cjs +13 -17
- package/dist/debug/index.cjs.map +1 -1
- package/dist/debug/index.js +13 -16
- package/dist/debug/index.js.map +1 -1
- package/dist/dev_env/index.cjs +60 -44
- package/dist/dev_env/index.cjs.map +1 -1
- package/dist/dev_env/index.js +57 -33
- package/dist/dev_env/index.js.map +1 -1
- package/dist/dev_env/util.cjs +12 -32
- package/dist/dev_env/util.cjs.map +1 -1
- package/dist/dev_env/util.js +10 -11
- package/dist/dev_env/util.js.map +1 -1
- package/dist/index.cjs +75 -74
- package/dist/index.d.ts +21 -13
- package/dist/index.js +25 -18
- package/dist/js_render/computable_context.cjs +432 -568
- package/dist/js_render/computable_context.cjs.map +1 -1
- package/dist/js_render/computable_context.js +431 -566
- package/dist/js_render/computable_context.js.map +1 -1
- package/dist/js_render/context.cjs +184 -237
- package/dist/js_render/context.cjs.map +1 -1
- package/dist/js_render/context.js +184 -235
- package/dist/js_render/context.js.map +1 -1
- package/dist/js_render/index.cjs +137 -156
- package/dist/js_render/index.cjs.map +1 -1
- package/dist/js_render/index.js +136 -154
- package/dist/js_render/index.js.map +1 -1
- package/dist/middle_layer/active_cfg.cjs +28 -35
- package/dist/middle_layer/active_cfg.cjs.map +1 -1
- package/dist/middle_layer/active_cfg.js +27 -33
- package/dist/middle_layer/active_cfg.js.map +1 -1
- package/dist/middle_layer/block.cjs +36 -42
- package/dist/middle_layer/block.cjs.map +1 -1
- package/dist/middle_layer/block.js +35 -40
- package/dist/middle_layer/block.js.map +1 -1
- package/dist/middle_layer/block_ctx.cjs +91 -133
- package/dist/middle_layer/block_ctx.cjs.map +1 -1
- package/dist/middle_layer/block_ctx.js +90 -131
- package/dist/middle_layer/block_ctx.js.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.cjs +20 -19
- package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -1
- package/dist/middle_layer/block_ctx_unsafe.js +20 -18
- package/dist/middle_layer/block_ctx_unsafe.js.map +1 -1
- package/dist/middle_layer/driver_kit.cjs +47 -51
- package/dist/middle_layer/driver_kit.cjs.map +1 -1
- package/dist/middle_layer/driver_kit.d.ts +31 -27
- package/dist/middle_layer/driver_kit.js +46 -49
- package/dist/middle_layer/driver_kit.js.map +1 -1
- package/dist/middle_layer/frontend_path.cjs +49 -55
- package/dist/middle_layer/frontend_path.cjs.map +1 -1
- package/dist/middle_layer/frontend_path.js +48 -53
- package/dist/middle_layer/frontend_path.js.map +1 -1
- package/dist/middle_layer/index.cjs +4 -0
- package/dist/middle_layer/index.d.ts +4 -5
- package/dist/middle_layer/index.js +4 -0
- package/dist/middle_layer/middle_layer.cjs +216 -245
- package/dist/middle_layer/middle_layer.cjs.map +1 -1
- package/dist/middle_layer/middle_layer.d.ts +95 -91
- package/dist/middle_layer/middle_layer.js +215 -243
- package/dist/middle_layer/middle_layer.js.map +1 -1
- package/dist/middle_layer/navigation_states.cjs +45 -38
- package/dist/middle_layer/navigation_states.cjs.map +1 -1
- package/dist/middle_layer/navigation_states.js +44 -36
- package/dist/middle_layer/navigation_states.js.map +1 -1
- package/dist/middle_layer/ops.cjs +56 -57
- package/dist/middle_layer/ops.cjs.map +1 -1
- package/dist/middle_layer/ops.d.ts +86 -96
- package/dist/middle_layer/ops.js +54 -55
- package/dist/middle_layer/ops.js.map +1 -1
- package/dist/middle_layer/project.cjs +497 -527
- package/dist/middle_layer/project.cjs.map +1 -1
- package/dist/middle_layer/project.d.ts +155 -152
- package/dist/middle_layer/project.js +494 -525
- package/dist/middle_layer/project.js.map +1 -1
- package/dist/middle_layer/project_list.cjs +45 -43
- package/dist/middle_layer/project_list.cjs.map +1 -1
- package/dist/middle_layer/project_list.js +45 -41
- package/dist/middle_layer/project_list.js.map +1 -1
- package/dist/middle_layer/project_overview.cjs +202 -240
- package/dist/middle_layer/project_overview.cjs.map +1 -1
- package/dist/middle_layer/project_overview.js +201 -238
- package/dist/middle_layer/project_overview.js.map +1 -1
- package/dist/middle_layer/project_overview_light.cjs +11 -14
- package/dist/middle_layer/project_overview_light.cjs.map +1 -1
- package/dist/middle_layer/project_overview_light.js +10 -12
- package/dist/middle_layer/project_overview_light.js.map +1 -1
- package/dist/middle_layer/render.cjs +14 -18
- package/dist/middle_layer/render.cjs.map +1 -1
- package/dist/middle_layer/render.js +13 -16
- package/dist/middle_layer/render.js.map +1 -1
- package/dist/middle_layer/types.d.ts +7 -10
- package/dist/middle_layer/util.cjs +26 -21
- package/dist/middle_layer/util.cjs.map +1 -1
- package/dist/middle_layer/util.js +25 -19
- package/dist/middle_layer/util.js.map +1 -1
- package/dist/model/args.cjs +44 -53
- package/dist/model/args.cjs.map +1 -1
- package/dist/model/args.js +44 -51
- package/dist/model/args.js.map +1 -1
- package/dist/model/block_pack_spec.cjs +9 -5
- package/dist/model/block_pack_spec.cjs.map +1 -1
- package/dist/model/block_pack_spec.d.ts +34 -30
- package/dist/model/block_pack_spec.js +9 -4
- package/dist/model/block_pack_spec.js.map +1 -1
- package/dist/model/frontend.d.ts +8 -5
- package/dist/model/index.d.ts +2 -3
- package/dist/model/project_helper.cjs +154 -193
- package/dist/model/project_helper.cjs.map +1 -1
- package/dist/model/project_helper.d.ts +96 -92
- package/dist/model/project_helper.js +153 -191
- package/dist/model/project_helper.js.map +1 -1
- package/dist/model/project_model.cjs +33 -32
- package/dist/model/project_model.cjs.map +1 -1
- package/dist/model/project_model.d.ts +13 -64
- package/dist/model/project_model.js +34 -30
- package/dist/model/project_model.js.map +1 -1
- package/dist/model/project_model_util.cjs +119 -158
- package/dist/model/project_model_util.cjs.map +1 -1
- package/dist/model/project_model_util.js +120 -156
- package/dist/model/project_model_util.js.map +1 -1
- package/dist/model/project_model_v1.cjs +3 -2
- package/dist/model/project_model_v1.cjs.map +1 -1
- package/dist/model/project_model_v1.js +3 -1
- package/dist/model/project_model_v1.js.map +1 -1
- package/dist/model/template_spec.d.ts +20 -16
- package/dist/mutator/block-pack/block_pack.cjs +200 -223
- package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
- package/dist/mutator/block-pack/block_pack.d.ts +20 -19
- package/dist/mutator/block-pack/block_pack.js +199 -221
- package/dist/mutator/block-pack/block_pack.js.map +1 -1
- package/dist/mutator/block-pack/frontend.cjs +14 -16
- package/dist/mutator/block-pack/frontend.cjs.map +1 -1
- package/dist/mutator/block-pack/frontend.js +13 -14
- package/dist/mutator/block-pack/frontend.js.map +1 -1
- package/dist/mutator/context_export.cjs +18 -17
- package/dist/mutator/context_export.cjs.map +1 -1
- package/dist/mutator/context_export.js +17 -15
- package/dist/mutator/context_export.js.map +1 -1
- package/dist/mutator/migration.cjs +86 -112
- package/dist/mutator/migration.cjs.map +1 -1
- package/dist/mutator/migration.js +85 -110
- package/dist/mutator/migration.js.map +1 -1
- package/dist/mutator/project.cjs +903 -1240
- package/dist/mutator/project.cjs.map +1 -1
- package/dist/mutator/project.js +901 -1237
- package/dist/mutator/project.js.map +1 -1
- package/dist/mutator/template/direct_template_loader.cjs +104 -130
- package/dist/mutator/template/direct_template_loader.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader.js +103 -128
- package/dist/mutator/template/direct_template_loader.js.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.cjs +104 -124
- package/dist/mutator/template/direct_template_loader_v3.cjs.map +1 -1
- package/dist/mutator/template/direct_template_loader_v3.js +103 -122
- package/dist/mutator/template/direct_template_loader_v3.js.map +1 -1
- package/dist/mutator/template/render_block.cjs +26 -30
- package/dist/mutator/template/render_block.cjs.map +1 -1
- package/dist/mutator/template/render_block.js +26 -23
- package/dist/mutator/template/render_block.js.map +1 -1
- package/dist/mutator/template/render_template.cjs +25 -25
- package/dist/mutator/template/render_template.cjs.map +1 -1
- package/dist/mutator/template/render_template.d.ts +6 -3
- package/dist/mutator/template/render_template.js +24 -23
- package/dist/mutator/template/render_template.js.map +1 -1
- package/dist/mutator/template/template_loading.cjs +42 -46
- package/dist/mutator/template/template_loading.cjs.map +1 -1
- package/dist/mutator/template/template_loading.d.ts +16 -12
- package/dist/mutator/template/template_loading.js +40 -44
- package/dist/mutator/template/template_loading.js.map +1 -1
- package/dist/network_check/network_check.cjs +149 -194
- package/dist/network_check/network_check.cjs.map +1 -1
- package/dist/network_check/network_check.d.ts +50 -66
- package/dist/network_check/network_check.js +146 -190
- package/dist/network_check/network_check.js.map +1 -1
- package/dist/network_check/pings.cjs +71 -69
- package/dist/network_check/pings.cjs.map +1 -1
- package/dist/network_check/pings.js +71 -65
- package/dist/network_check/pings.js.map +1 -1
- package/dist/network_check/template.cjs +256 -273
- package/dist/network_check/template.cjs.map +1 -1
- package/dist/network_check/template.js +253 -265
- package/dist/network_check/template.js.map +1 -1
- package/dist/pool/data.cjs +205 -226
- package/dist/pool/data.cjs.map +1 -1
- package/dist/pool/data.d.ts +10 -27
- package/dist/pool/data.js +196 -209
- package/dist/pool/data.js.map +1 -1
- package/dist/pool/driver.cjs +180 -207
- package/dist/pool/driver.cjs.map +1 -1
- package/dist/pool/driver.d.ts +12 -17
- package/dist/pool/driver.js +178 -205
- package/dist/pool/driver.js.map +1 -1
- package/dist/pool/index.cjs +2 -0
- package/dist/pool/index.d.ts +2 -3
- package/dist/pool/index.js +2 -0
- package/dist/pool/p_object_collection.cjs +67 -79
- package/dist/pool/p_object_collection.cjs.map +1 -1
- package/dist/pool/p_object_collection.d.ts +7 -28
- package/dist/pool/p_object_collection.js +65 -77
- package/dist/pool/p_object_collection.js.map +1 -1
- package/dist/pool/result_pool.cjs +217 -262
- package/dist/pool/result_pool.cjs.map +1 -1
- package/dist/pool/result_pool.d.ts +4 -27
- package/dist/pool/result_pool.js +216 -260
- package/dist/pool/result_pool.js.map +1 -1
- package/dist/worker/WorkerManager.cjs +51 -49
- package/dist/worker/WorkerManager.cjs.map +1 -1
- package/dist/worker/WorkerManager.js +49 -47
- package/dist/worker/WorkerManager.js.map +1 -1
- package/dist/worker/worker.cjs +19 -15
- package/dist/worker/worker.cjs.map +1 -1
- package/dist/worker/worker.d.ts +1 -2
- package/dist/worker/worker.js +18 -13
- package/dist/worker/worker.js.map +1 -1
- package/dist/worker/workerApi.cjs +14 -18
- package/dist/worker/workerApi.cjs.map +1 -1
- package/dist/worker/workerApi.js +13 -16
- package/dist/worker/workerApi.js.map +1 -1
- package/package.json +24 -24
- package/src/mutator/template/template_render.test.ts +22 -18
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs +0 -77
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.cjs.map +0 -1
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js +0 -74
- package/dist/__external/.pnpm/@rollup_plugin-typescript@12.3.0_rollup@4.52.4_tslib@2.8.1_typescript@5.6.3/__external/tslib/tslib.es6.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.cjs +0 -162
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.js +0 -160
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/comparator.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.cjs +0 -576
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.js +0 -574
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/range.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.cjs +0 -337
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.js +0 -335
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/classes/semver.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.cjs +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.js +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/clean.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.cjs +0 -73
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.js +0 -71
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/cmp.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.cjs +0 -78
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.js +0 -76
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/coerce.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.cjs +0 -23
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.js +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-build.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare-loose.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.cjs +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.js +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/compare.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.cjs +0 -74
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.js +0 -72
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/diff.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/eq.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gt.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/gte.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.cjs +0 -35
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.js +0 -33
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/inc.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lt.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/lte.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/major.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/minor.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/neq.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.cjs +0 -32
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.js +0 -30
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/parse.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/patch.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.cjs +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.js +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/prerelease.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rcompare.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/rsort.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.cjs +0 -26
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.js +0 -24
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/satisfies.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.cjs +0 -19
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.js +0 -17
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/sort.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.cjs +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.js +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/functions/valid.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.cjs +0 -145
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.js +0 -143
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/index.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.cjs +0 -49
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.js +0 -47
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/constants.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.cjs +0 -23
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.js +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/debug.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.cjs +0 -37
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.js +0 -35
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/identifiers.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.cjs +0 -54
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.js +0 -52
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/lrucache.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.cjs +0 -29
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.js +0 -27
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/parse-options.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.cjs +0 -240
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.js +0 -238
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/internal/re.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.cjs +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.js +0 -18
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/gtr.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.cjs +0 -23
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.js +0 -21
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/intersects.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.cjs +0 -20
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.js +0 -18
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/ltr.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.cjs +0 -42
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.js +0 -40
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/max-satisfying.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.cjs +0 -41
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.js +0 -39
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-satisfying.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.cjs +0 -79
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.js +0 -77
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/min-version.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.cjs +0 -103
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.js +0 -101
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/outside.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.cjs +0 -64
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.js +0 -62
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/simplify.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.cjs +0 -266
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.js +0 -264
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/subset.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.cjs +0 -24
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.js +0 -22
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/to-comparators.js.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.cjs +0 -27
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.cjs.map +0 -1
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.js +0 -25
- package/dist/__external/.pnpm/semver@7.7.2/__external/semver/ranges/valid.js.map +0 -1
- package/dist/_virtual/index.cjs +0 -8
- package/dist/_virtual/index.cjs.map +0 -1
- package/dist/_virtual/index.js +0 -6
- package/dist/_virtual/index.js.map +0 -1
- package/dist/_virtual/re.cjs +0 -6
- package/dist/_virtual/re.cjs.map +0 -1
- package/dist/_virtual/re.js +0 -4
- package/dist/_virtual/re.js.map +0 -1
- package/dist/block_registry/index.d.ts.map +0 -1
- package/dist/block_registry/registry-v2-provider.d.ts.map +0 -1
- package/dist/block_registry/registry.d.ts.map +0 -1
- package/dist/block_registry/registry.test.d.ts +0 -2
- package/dist/block_registry/registry.test.d.ts.map +0 -1
- package/dist/block_registry/watcher.d.ts.map +0 -1
- package/dist/block_registry/well_known_registries.d.ts.map +0 -1
- package/dist/cfg_render/executor.d.ts +0 -9
- package/dist/cfg_render/executor.d.ts.map +0 -1
- package/dist/cfg_render/executor.test.d.ts +0 -2
- package/dist/cfg_render/executor.test.d.ts.map +0 -1
- package/dist/cfg_render/operation.d.ts +0 -29
- package/dist/cfg_render/operation.d.ts.map +0 -1
- package/dist/cfg_render/renderer.d.ts +0 -6
- package/dist/cfg_render/renderer.d.ts.map +0 -1
- package/dist/cfg_render/traverse.d.ts +0 -3
- package/dist/cfg_render/traverse.d.ts.map +0 -1
- package/dist/cfg_render/util.d.ts +0 -5
- package/dist/cfg_render/util.d.ts.map +0 -1
- package/dist/debug/index.d.ts +0 -9
- package/dist/debug/index.d.ts.map +0 -1
- package/dist/dev_env/index.d.ts +0 -21
- package/dist/dev_env/index.d.ts.map +0 -1
- package/dist/dev_env/util.d.ts +0 -3
- package/dist/dev_env/util.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/js_render/computable_context.d.ts +0 -74
- package/dist/js_render/computable_context.d.ts.map +0 -1
- package/dist/js_render/context.d.ts +0 -73
- package/dist/js_render/context.d.ts.map +0 -1
- package/dist/js_render/index.d.ts +0 -57
- package/dist/js_render/index.d.ts.map +0 -1
- package/dist/middle_layer/active_cfg.d.ts +0 -6
- package/dist/middle_layer/active_cfg.d.ts.map +0 -1
- package/dist/middle_layer/block.d.ts +0 -10
- package/dist/middle_layer/block.d.ts.map +0 -1
- package/dist/middle_layer/block_ctx.d.ts +0 -23
- package/dist/middle_layer/block_ctx.d.ts.map +0 -1
- package/dist/middle_layer/block_ctx_unsafe.d.ts +0 -16
- package/dist/middle_layer/block_ctx_unsafe.d.ts.map +0 -1
- package/dist/middle_layer/driver_kit.d.ts.map +0 -1
- package/dist/middle_layer/frontend_path.d.ts +0 -6
- package/dist/middle_layer/frontend_path.d.ts.map +0 -1
- package/dist/middle_layer/index.d.ts.map +0 -1
- package/dist/middle_layer/middle_layer.d.ts.map +0 -1
- package/dist/middle_layer/navigation_states.d.ts +0 -10
- package/dist/middle_layer/navigation_states.d.ts.map +0 -1
- package/dist/middle_layer/ops.d.ts.map +0 -1
- package/dist/middle_layer/project.d.ts.map +0 -1
- package/dist/middle_layer/project_list.d.ts +0 -11
- package/dist/middle_layer/project_list.d.ts.map +0 -1
- package/dist/middle_layer/project_overview.d.ts +0 -8
- package/dist/middle_layer/project_overview.d.ts.map +0 -1
- package/dist/middle_layer/project_overview_light.d.ts +0 -8
- package/dist/middle_layer/project_overview_light.d.ts.map +0 -1
- package/dist/middle_layer/render.d.ts +0 -7
- package/dist/middle_layer/render.d.ts.map +0 -1
- package/dist/middle_layer/render.test.d.ts +0 -5
- package/dist/middle_layer/render.test.d.ts.map +0 -1
- package/dist/middle_layer/types.d.ts.map +0 -1
- package/dist/middle_layer/util.d.ts +0 -16
- package/dist/middle_layer/util.d.ts.map +0 -1
- package/dist/model/args.d.ts +0 -14
- package/dist/model/args.d.ts.map +0 -1
- package/dist/model/block_pack.d.ts +0 -8
- package/dist/model/block_pack.d.ts.map +0 -1
- package/dist/model/block_pack_spec.d.ts.map +0 -1
- package/dist/model/frontend.d.ts.map +0 -1
- package/dist/model/index.d.ts.map +0 -1
- package/dist/model/project_helper.d.ts.map +0 -1
- package/dist/model/project_model.d.ts.map +0 -1
- package/dist/model/project_model.test.d.ts +0 -2
- package/dist/model/project_model.test.d.ts.map +0 -1
- package/dist/model/project_model_util.d.ts +0 -43
- package/dist/model/project_model_util.d.ts.map +0 -1
- package/dist/model/project_model_util.test.d.ts +0 -2
- package/dist/model/project_model_util.test.d.ts.map +0 -1
- package/dist/model/project_model_v1.d.ts +0 -8
- package/dist/model/project_model_v1.d.ts.map +0 -1
- package/dist/model/template_spec.d.ts.map +0 -1
- package/dist/mutator/block-pack/block_pack.d.ts.map +0 -1
- package/dist/mutator/block-pack/block_pack.test.d.ts +0 -2
- package/dist/mutator/block-pack/block_pack.test.d.ts.map +0 -1
- package/dist/mutator/block-pack/frontend.d.ts +0 -4
- package/dist/mutator/block-pack/frontend.d.ts.map +0 -1
- package/dist/mutator/context_export.d.ts +0 -9
- package/dist/mutator/context_export.d.ts.map +0 -1
- package/dist/mutator/migration.d.ts +0 -9
- package/dist/mutator/migration.d.ts.map +0 -1
- package/dist/mutator/project-v3.test.d.ts +0 -2
- package/dist/mutator/project-v3.test.d.ts.map +0 -1
- package/dist/mutator/project.d.ts +0 -211
- package/dist/mutator/project.d.ts.map +0 -1
- package/dist/mutator/project.test.d.ts +0 -2
- package/dist/mutator/project.test.d.ts.map +0 -1
- package/dist/mutator/template/direct_template_loader.d.ts +0 -5
- package/dist/mutator/template/direct_template_loader.d.ts.map +0 -1
- package/dist/mutator/template/direct_template_loader_v3.d.ts +0 -15
- package/dist/mutator/template/direct_template_loader_v3.d.ts.map +0 -1
- package/dist/mutator/template/render_block.d.ts +0 -32
- package/dist/mutator/template/render_block.d.ts.map +0 -1
- package/dist/mutator/template/render_template.d.ts.map +0 -1
- package/dist/mutator/template/template_loading.d.ts.map +0 -1
- package/dist/mutator/template/template_render.test.d.ts +0 -2
- package/dist/mutator/template/template_render.test.d.ts.map +0 -1
- package/dist/network_check/network_check.d.ts.map +0 -1
- package/dist/network_check/network_check.test.d.ts +0 -2
- package/dist/network_check/network_check.test.d.ts.map +0 -1
- package/dist/network_check/pings.d.ts +0 -32
- package/dist/network_check/pings.d.ts.map +0 -1
- package/dist/network_check/template.d.ts +0 -57
- package/dist/network_check/template.d.ts.map +0 -1
- package/dist/network_check/template.test.d.ts +0 -2
- package/dist/network_check/template.test.d.ts.map +0 -1
- package/dist/network_check/test_utils.d.ts +0 -6
- package/dist/network_check/test_utils.d.ts.map +0 -1
- package/dist/pool/data.d.ts.map +0 -1
- package/dist/pool/driver.d.ts.map +0 -1
- package/dist/pool/index.d.ts.map +0 -1
- package/dist/pool/p_object_collection.d.ts.map +0 -1
- package/dist/pool/result_pool.d.ts.map +0 -1
- package/dist/test/block_packs.d.ts +0 -6
- package/dist/test/block_packs.d.ts.map +0 -1
- package/dist/test/explicit_templates.d.ts +0 -3
- package/dist/test/explicit_templates.d.ts.map +0 -1
- package/dist/test/known_templates.d.ts +0 -6
- package/dist/test/known_templates.d.ts.map +0 -1
- package/dist/test_env.d.ts +0 -6
- package/dist/test_env.d.ts.map +0 -1
- package/dist/worker/WorkerManager.d.ts +0 -12
- package/dist/worker/WorkerManager.d.ts.map +0 -1
- package/dist/worker/worker.d.ts.map +0 -1
- package/dist/worker/workerApi.d.ts +0 -15
- package/dist/worker/workerApi.d.ts.map +0 -1
|
@@ -1,139 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var tsHelpers = require('@milaboratories/ts-helpers');
|
|
1
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
|
|
3
|
+
let node_crypto = require("node:crypto");
|
|
4
|
+
let _milaboratories_pl_model_backend = require("@milaboratories/pl-model-backend");
|
|
6
5
|
|
|
6
|
+
//#region src/mutator/template/direct_template_loader_v3.ts
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
* Renders the tree of templates by caching all resource ids
|
|
9
|
+
* by their cache keys.
|
|
10
|
+
* It's different from v2 version because we provide
|
|
11
|
+
* the hash map of the code of all sources everywhere.
|
|
12
|
+
* It does a double-dispatch on the node type (template, library etc),
|
|
13
|
+
* and creates resources.
|
|
14
|
+
*
|
|
15
|
+
* IMO, it'd be clearer to rewrite it with Visitor pattern, and separate
|
|
16
|
+
* tree traversing and operations on it, but I don't have time to do it now.
|
|
17
|
+
*/
|
|
18
18
|
function createTemplateV3Tree(tx, tplData) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
const resourceCache = /* @__PURE__ */ new Map();
|
|
20
|
+
const createResourceCached = (resource, renderer, hashToSource) => {
|
|
21
|
+
const key = (0, node_crypto.createHash)("sha256");
|
|
22
|
+
renderer.updateCacheKey(resource, key, hashToSource);
|
|
23
|
+
const rKey = key.digest("hex");
|
|
24
|
+
if (!resourceCache.has(rKey)) {
|
|
25
|
+
const rId = renderer.render(resource, tx, createResourceCached, hashToSource);
|
|
26
|
+
resourceCache.set(rKey, rId);
|
|
27
|
+
}
|
|
28
|
+
return resourceCache.get(rKey);
|
|
29
|
+
};
|
|
30
|
+
return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);
|
|
31
31
|
}
|
|
32
32
|
const LibRenderer = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
40
|
-
},
|
|
41
|
-
render(resource, tx, _creator, sources) {
|
|
42
|
-
return tx.createValue(plModelBackend.PlTemplateLibV1.type, JSON.stringify(plModelBackend.PlTemplateLibV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
|
|
43
|
-
},
|
|
33
|
+
updateCacheKey(resource, hash, sources) {
|
|
34
|
+
hash.update(_milaboratories_pl_model_backend.PlTemplateLibV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateLibV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
35
|
+
},
|
|
36
|
+
render(resource, tx, _creator, sources) {
|
|
37
|
+
return tx.createValue(_milaboratories_pl_model_backend.PlTemplateLibV1.type, JSON.stringify(_milaboratories_pl_model_backend.PlTemplateLibV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
|
|
38
|
+
}
|
|
44
39
|
};
|
|
45
40
|
const SoftwareInfoRenderer = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const ref = tx.createStruct(plModelBackend.PlTemplateSoftwareV1.type, sw.data);
|
|
57
|
-
tx.setKValue(ref, plModelBackend.PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));
|
|
58
|
-
tx.lock(ref);
|
|
59
|
-
return ref;
|
|
60
|
-
},
|
|
41
|
+
updateCacheKey(resource, hash, sources) {
|
|
42
|
+
hash.update(_milaboratories_pl_model_backend.PlTemplateSoftwareV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateSoftwareV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
43
|
+
},
|
|
44
|
+
render(resource, tx, _creator, sources) {
|
|
45
|
+
const sw = _milaboratories_pl_model_backend.PlTemplateSoftwareV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash));
|
|
46
|
+
const ref = tx.createStruct(_milaboratories_pl_model_backend.PlTemplateSoftwareV1.type, sw.data);
|
|
47
|
+
tx.setKValue(ref, _milaboratories_pl_model_backend.PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));
|
|
48
|
+
tx.lock(ref);
|
|
49
|
+
return ref;
|
|
50
|
+
}
|
|
61
51
|
};
|
|
62
52
|
const TemplateRenderer = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
tx.lock(tplRef);
|
|
118
|
-
if (!resource.hashOverride)
|
|
119
|
-
return tplRef;
|
|
120
|
-
// Override template hash with proxy resource, when hash override is configured for template
|
|
121
|
-
const overrideRef = tx.createStruct(plModelBackend.PlTemplateOverrideV1.type, JSON.stringify(plModelBackend.PlTemplateOverrideV1.fromV3Data(resource)));
|
|
122
|
-
const fld = plModelBackend.PlTemplateOverrideV1.tplField(overrideRef);
|
|
123
|
-
tx.createField(fld, "Service");
|
|
124
|
-
tx.setField(fld, tplRef);
|
|
125
|
-
tx.lock(overrideRef);
|
|
126
|
-
return overrideRef;
|
|
127
|
-
},
|
|
53
|
+
updateCacheKey(resource, hash, sources) {
|
|
54
|
+
hash.update(_milaboratories_pl_model_backend.PlTemplateV1.type.name).update(_milaboratories_pl_model_backend.PlTemplateV1.type.version).update(resource.hashOverride ?? "no-override").update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
55
|
+
const srt = (entries) => {
|
|
56
|
+
entries.sort((a, b) => a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1);
|
|
57
|
+
return entries;
|
|
58
|
+
};
|
|
59
|
+
for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {
|
|
60
|
+
hash.update("lib:" + libId);
|
|
61
|
+
LibRenderer.updateCacheKey(lib, hash, sources);
|
|
62
|
+
}
|
|
63
|
+
for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {
|
|
64
|
+
hash.update("soft:" + swId);
|
|
65
|
+
SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);
|
|
66
|
+
}
|
|
67
|
+
for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {
|
|
68
|
+
hash.update("asset:" + swId);
|
|
69
|
+
SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);
|
|
70
|
+
}
|
|
71
|
+
for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {
|
|
72
|
+
hash.update("tpl:" + tplId);
|
|
73
|
+
this.updateCacheKey(tpl, hash, sources);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
render(resource, tx, _creator, sources) {
|
|
77
|
+
const tplRef = tx.createStruct(_milaboratories_pl_model_backend.PlTemplateV1.type, JSON.stringify(_milaboratories_pl_model_backend.PlTemplateV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
|
|
78
|
+
for (const [libId, lib] of Object.entries(resource.libs ?? {})) {
|
|
79
|
+
const fld = _milaboratories_pl_model_backend.PlTemplateV1.libField(tplRef, libId);
|
|
80
|
+
tx.createField(fld, "Input");
|
|
81
|
+
tx.setField(fld, _creator(lib, LibRenderer, sources));
|
|
82
|
+
}
|
|
83
|
+
for (const [swId, sw] of Object.entries(resource.software ?? {})) {
|
|
84
|
+
const fld = _milaboratories_pl_model_backend.PlTemplateV1.swField(tplRef, swId);
|
|
85
|
+
tx.createField(fld, "Input");
|
|
86
|
+
tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));
|
|
87
|
+
}
|
|
88
|
+
for (const [swId, sw] of Object.entries(resource.assets ?? {})) {
|
|
89
|
+
const fld = _milaboratories_pl_model_backend.PlTemplateV1.swField(tplRef, swId);
|
|
90
|
+
tx.createField(fld, "Input");
|
|
91
|
+
tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));
|
|
92
|
+
}
|
|
93
|
+
for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {
|
|
94
|
+
const fld = _milaboratories_pl_model_backend.PlTemplateV1.tplField(tplRef, depTplId);
|
|
95
|
+
tx.createField(fld, "Input");
|
|
96
|
+
tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));
|
|
97
|
+
}
|
|
98
|
+
tx.lock(tplRef);
|
|
99
|
+
if (!resource.hashOverride) return tplRef;
|
|
100
|
+
const overrideRef = tx.createStruct(_milaboratories_pl_model_backend.PlTemplateOverrideV1.type, JSON.stringify(_milaboratories_pl_model_backend.PlTemplateOverrideV1.fromV3Data(resource)));
|
|
101
|
+
const fld = _milaboratories_pl_model_backend.PlTemplateOverrideV1.tplField(overrideRef);
|
|
102
|
+
tx.createField(fld, "Service");
|
|
103
|
+
tx.setField(fld, tplRef);
|
|
104
|
+
tx.lock(overrideRef);
|
|
105
|
+
return overrideRef;
|
|
106
|
+
}
|
|
128
107
|
};
|
|
129
108
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
109
|
+
* Gets a source code of the artifact by its source hash.
|
|
110
|
+
* the source hash was calculated and stored by tengo compiler
|
|
111
|
+
* and is different from the hash we're using for caching here.
|
|
112
|
+
*/
|
|
134
113
|
function getSourceCode(name, sources, sourceHash) {
|
|
135
|
-
|
|
114
|
+
return (0, _milaboratories_ts_helpers.notEmpty)(sources[sourceHash], `trying to get "${name}" source: sources map doesn't contain source hash ${sourceHash}`);
|
|
136
115
|
}
|
|
137
116
|
|
|
117
|
+
//#endregion
|
|
138
118
|
exports.createTemplateV3Tree = createTemplateV3Tree;
|
|
139
|
-
//# sourceMappingURL=direct_template_loader_v3.cjs.map
|
|
119
|
+
//# sourceMappingURL=direct_template_loader_v3.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct_template_loader_v3.cjs","sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"names":["createHash","PlTemplateLibV1","PlTemplateSoftwareV1","PlTemplateV1","PlTemplateOverrideV1","notEmpty"],"mappings":";;;;;;AAiBA;;;;;;;;;;AAUG;AACG,SAAU,oBAAoB,CAAC,EAAiB,EAAE,OAA2B,EAAA;AACjF,IAAA,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0B;IAEvD,MAAM,oBAAoB,GAAG,CAC3B,QAAW,EACX,QAAqB,EACrB,YAAoC,KAClB;AAClB,QAAA,MAAM,GAAG,GAASA,sBAAU,CAAC,QAAQ,CAAC;QACtC,QAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,YAAY,CAAC;QAEpD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;QAE9B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;AAC5B,YAAA,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,oBAAoB,EAAE,YAAY,CAAC;AAC7E,YAAA,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC;QAC9B;AAEA,QAAA,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAE;AACjC,IAAA,CAAC;AAED,IAAA,OAAO,oBAAoB,CAAC,OAAO,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,CAAC,YAAY,CAAC;AACvF;AAoBA,MAAM,WAAW,GAAgC;AAC/C,IAAA,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAA;QACpC;AACG,aAAA,MAAM,CAACC,8BAAe,CAAC,IAAI,CAAC,IAAI;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MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE;YACzE,MAAM,GAAG,GAAGA,2BAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;AACnD,YAAA,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC;AAC5B,YAAA,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC/D;AAEA,QAAA,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;QAEf,IAAI,CAAC,QAAQ,CAAC,YAAY;AAAE,YAAA,OAAO,MAAM;;QAGzC,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CACjCC,mCAAoB,CAAC,IAAI,EACzB,IAAI,CAAC,SAAS,CAACA,mCAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAC1D;QACD,MAAM,GAAG,GAAGA,mCAAoB,CAAC,QAAQ,CAAC,WAAW,CAAC;AACtD,QAAA,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC;AAC9B,QAAA,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;AACxB,QAAA,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;AACpB,QAAA,OAAO,WAAW;IACpB,CAAC;CACF;AAED;;;;AAIG;AACH,SAAS,aAAa,CAAC,IAAY,EAAE,OAA+B,EAAE,UAAkB,EAAA;AACtF,IAAA,OAAOC,kBAAQ,CACb,OAAO,CAAC,UAAU,CAAC,EACnB,CAAA,eAAA,EAAkB,IAAI,CAAA,kDAAA,EAAqD,UAAU,CAAA,CAAE,CACxF;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"direct_template_loader_v3.cjs","names":["PlTemplateLibV1","PlTemplateSoftwareV1","PlTemplateV1","PlTemplateOverrideV1"],"sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,SAAgB,qBAAqB,IAAmB,SAAqC;CAC3F,MAAM,gCAAgB,IAAI,KAA6B;CAEvD,MAAM,wBACJ,UACA,UACA,iBACmB;EACnB,MAAM,kCAAuB,SAAS;AACtC,WAAS,eAAe,UAAU,KAAK,aAAa;EAEpD,MAAM,OAAO,IAAI,OAAO,MAAM;AAE9B,MAAI,CAAC,cAAc,IAAI,KAAK,EAAE;GAC5B,MAAM,MAAM,SAAS,OAAO,UAAU,IAAI,sBAAsB,aAAa;AAC7E,iBAAc,IAAI,MAAM,IAAI;;AAG9B,SAAO,cAAc,IAAI,KAAK;;AAGhC,QAAO,qBAAqB,QAAQ,UAAU,kBAAkB,QAAQ,aAAa;;AAqBvF,MAAM,cAA2C;CAC/C,eAAe,UAAU,MAAM,SAAS;AACtC,OACG,OAAOA,iDAAgB,KAAK,KAAK,CACjC,OAAOA,iDAAgB,KAAK,QAAQ,CACpC,OAAO,SAAS,KAAK,CACrB,OAAO,SAAS,QAAQ,CACxB,OAAO,cAAc,SAAS,MAAM,SAAS,SAAS,WAAW,CAAC;;CAEvE,OAAO,UAAU,IAAI,UAAU,SAAS;AACtC,SAAO,GAAG,YACRA,iDAAgB,MAChB,KAAK,UACHA,iDAAgB,WACd,UACA,cAAc,SAAS,MAAM,SAAS,SAAS,WAAW,CAC3D,CAAC,KACH,CACF;;CAEJ;AAED,MAAM,uBAAyD;CAC7D,eAAe,UAAU,MAAM,SAAS;AACtC,OACG,OAAOC,sDAAqB,KAAK,KAAK,CACtC,OAAOA,sDAAqB,KAAK,QAAQ,CACzC,OAAO,SAAS,KAAK,CACrB,OAAO,SAAS,QAAQ,CACxB,OAAO,cAAc,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AAC,SAAS,aAAc,QAAO;EAGnC,MAAM,cAAc,GAAG,aACrBC,sDAAqB,MACrB,KAAK,UAAUA,sDAAqB,WAAW,SAAS,CAAC,CAC1D;EACD,MAAM,MAAMA,sDAAqB,SAAS,YAAY;AACtD,KAAG,YAAY,KAAK,UAAU;AAC9B,KAAG,SAAS,KAAK,OAAO;AACxB,KAAG,KAAK,YAAY;AACpB,SAAO;;CAEV;;;;;;AAOD,SAAS,cAAc,MAAc,SAAiC,YAA4B;AAChG,iDACE,QAAQ,aACR,kBAAkB,KAAK,oDAAoD,aAC5E"}
|
|
@@ -1,137 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { notEmpty } from "@milaboratories/ts-helpers";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { PlTemplateLibV1, PlTemplateOverrideV1, PlTemplateSoftwareV1, PlTemplateV1 } from "@milaboratories/pl-model-backend";
|
|
4
4
|
|
|
5
|
+
//#region src/mutator/template/direct_template_loader_v3.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
* Renders the tree of templates by caching all resource ids
|
|
8
|
+
* by their cache keys.
|
|
9
|
+
* It's different from v2 version because we provide
|
|
10
|
+
* the hash map of the code of all sources everywhere.
|
|
11
|
+
* It does a double-dispatch on the node type (template, library etc),
|
|
12
|
+
* and creates resources.
|
|
13
|
+
*
|
|
14
|
+
* IMO, it'd be clearer to rewrite it with Visitor pattern, and separate
|
|
15
|
+
* tree traversing and operations on it, but I don't have time to do it now.
|
|
16
|
+
*/
|
|
16
17
|
function createTemplateV3Tree(tx, tplData) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
const resourceCache = /* @__PURE__ */ new Map();
|
|
19
|
+
const createResourceCached = (resource, renderer, hashToSource) => {
|
|
20
|
+
const key = createHash("sha256");
|
|
21
|
+
renderer.updateCacheKey(resource, key, hashToSource);
|
|
22
|
+
const rKey = key.digest("hex");
|
|
23
|
+
if (!resourceCache.has(rKey)) {
|
|
24
|
+
const rId = renderer.render(resource, tx, createResourceCached, hashToSource);
|
|
25
|
+
resourceCache.set(rKey, rId);
|
|
26
|
+
}
|
|
27
|
+
return resourceCache.get(rKey);
|
|
28
|
+
};
|
|
29
|
+
return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);
|
|
29
30
|
}
|
|
30
31
|
const LibRenderer = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
38
|
-
},
|
|
39
|
-
render(resource, tx, _creator, sources) {
|
|
40
|
-
return tx.createValue(PlTemplateLibV1.type, JSON.stringify(PlTemplateLibV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
|
|
41
|
-
},
|
|
32
|
+
updateCacheKey(resource, hash, sources) {
|
|
33
|
+
hash.update(PlTemplateLibV1.type.name).update(PlTemplateLibV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
34
|
+
},
|
|
35
|
+
render(resource, tx, _creator, sources) {
|
|
36
|
+
return tx.createValue(PlTemplateLibV1.type, JSON.stringify(PlTemplateLibV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
|
|
37
|
+
}
|
|
42
38
|
};
|
|
43
39
|
const SoftwareInfoRenderer = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);
|
|
55
|
-
tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));
|
|
56
|
-
tx.lock(ref);
|
|
57
|
-
return ref;
|
|
58
|
-
},
|
|
40
|
+
updateCacheKey(resource, hash, sources) {
|
|
41
|
+
hash.update(PlTemplateSoftwareV1.type.name).update(PlTemplateSoftwareV1.type.version).update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
42
|
+
},
|
|
43
|
+
render(resource, tx, _creator, sources) {
|
|
44
|
+
const sw = PlTemplateSoftwareV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash));
|
|
45
|
+
const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);
|
|
46
|
+
tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));
|
|
47
|
+
tx.lock(ref);
|
|
48
|
+
return ref;
|
|
49
|
+
}
|
|
59
50
|
};
|
|
60
51
|
const TemplateRenderer = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
tx.lock(tplRef);
|
|
116
|
-
if (!resource.hashOverride)
|
|
117
|
-
return tplRef;
|
|
118
|
-
// Override template hash with proxy resource, when hash override is configured for template
|
|
119
|
-
const overrideRef = tx.createStruct(PlTemplateOverrideV1.type, JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)));
|
|
120
|
-
const fld = PlTemplateOverrideV1.tplField(overrideRef);
|
|
121
|
-
tx.createField(fld, "Service");
|
|
122
|
-
tx.setField(fld, tplRef);
|
|
123
|
-
tx.lock(overrideRef);
|
|
124
|
-
return overrideRef;
|
|
125
|
-
},
|
|
52
|
+
updateCacheKey(resource, hash, sources) {
|
|
53
|
+
hash.update(PlTemplateV1.type.name).update(PlTemplateV1.type.version).update(resource.hashOverride ?? "no-override").update(resource.name).update(resource.version).update(getSourceCode(resource.name, sources, resource.sourceHash));
|
|
54
|
+
const srt = (entries) => {
|
|
55
|
+
entries.sort((a, b) => a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1);
|
|
56
|
+
return entries;
|
|
57
|
+
};
|
|
58
|
+
for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {
|
|
59
|
+
hash.update("lib:" + libId);
|
|
60
|
+
LibRenderer.updateCacheKey(lib, hash, sources);
|
|
61
|
+
}
|
|
62
|
+
for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {
|
|
63
|
+
hash.update("soft:" + swId);
|
|
64
|
+
SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);
|
|
65
|
+
}
|
|
66
|
+
for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {
|
|
67
|
+
hash.update("asset:" + swId);
|
|
68
|
+
SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);
|
|
69
|
+
}
|
|
70
|
+
for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {
|
|
71
|
+
hash.update("tpl:" + tplId);
|
|
72
|
+
this.updateCacheKey(tpl, hash, sources);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
render(resource, tx, _creator, sources) {
|
|
76
|
+
const tplRef = tx.createStruct(PlTemplateV1.type, JSON.stringify(PlTemplateV1.fromV3Data(resource, getSourceCode(resource.name, sources, resource.sourceHash)).data));
|
|
77
|
+
for (const [libId, lib] of Object.entries(resource.libs ?? {})) {
|
|
78
|
+
const fld = PlTemplateV1.libField(tplRef, libId);
|
|
79
|
+
tx.createField(fld, "Input");
|
|
80
|
+
tx.setField(fld, _creator(lib, LibRenderer, sources));
|
|
81
|
+
}
|
|
82
|
+
for (const [swId, sw] of Object.entries(resource.software ?? {})) {
|
|
83
|
+
const fld = PlTemplateV1.swField(tplRef, swId);
|
|
84
|
+
tx.createField(fld, "Input");
|
|
85
|
+
tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));
|
|
86
|
+
}
|
|
87
|
+
for (const [swId, sw] of Object.entries(resource.assets ?? {})) {
|
|
88
|
+
const fld = PlTemplateV1.swField(tplRef, swId);
|
|
89
|
+
tx.createField(fld, "Input");
|
|
90
|
+
tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));
|
|
91
|
+
}
|
|
92
|
+
for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {
|
|
93
|
+
const fld = PlTemplateV1.tplField(tplRef, depTplId);
|
|
94
|
+
tx.createField(fld, "Input");
|
|
95
|
+
tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));
|
|
96
|
+
}
|
|
97
|
+
tx.lock(tplRef);
|
|
98
|
+
if (!resource.hashOverride) return tplRef;
|
|
99
|
+
const overrideRef = tx.createStruct(PlTemplateOverrideV1.type, JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)));
|
|
100
|
+
const fld = PlTemplateOverrideV1.tplField(overrideRef);
|
|
101
|
+
tx.createField(fld, "Service");
|
|
102
|
+
tx.setField(fld, tplRef);
|
|
103
|
+
tx.lock(overrideRef);
|
|
104
|
+
return overrideRef;
|
|
105
|
+
}
|
|
126
106
|
};
|
|
127
107
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
108
|
+
* Gets a source code of the artifact by its source hash.
|
|
109
|
+
* the source hash was calculated and stored by tengo compiler
|
|
110
|
+
* and is different from the hash we're using for caching here.
|
|
111
|
+
*/
|
|
132
112
|
function getSourceCode(name, sources, sourceHash) {
|
|
133
|
-
|
|
113
|
+
return notEmpty(sources[sourceHash], `trying to get "${name}" source: sources map doesn't contain source hash ${sourceHash}`);
|
|
134
114
|
}
|
|
135
115
|
|
|
116
|
+
//#endregion
|
|
136
117
|
export { createTemplateV3Tree };
|
|
137
|
-
//# sourceMappingURL=direct_template_loader_v3.js.map
|
|
118
|
+
//# sourceMappingURL=direct_template_loader_v3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct_template_loader_v3.js","sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"names":[],"mappings":";;;;AAiBA;;;;;;;;;;AAUG;AACG,SAAU,oBAAoB,CAAC,EAAiB,EAAE,OAA2B,EAAA;AACjF,IAAA,MAAM,aAAa,GAAG,IAAI,GAAG,EAA0B;IAEvD,MAAM,oBAAoB,GAAG,CAC3B,QAAW,EACX,QAAqB,EACrB,YAAoC,KAClB;AAClB,QAAA,MAAM,GAAG,GAAS,UAAU,CAAC,QAAQ,CAAC;QACtC,QAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,YAAY,CAAC;QAEpD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;QAE9B,IA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;AAC9B,QAAA,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;AACxB,QAAA,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC;AACpB,QAAA,OAAO,WAAW;IACpB,CAAC;CACF;AAED;;;;AAIG;AACH,SAAS,aAAa,CAAC,IAAY,EAAE,OAA+B,EAAE,UAAkB,EAAA;AACtF,IAAA,OAAO,QAAQ,CACb,OAAO,CAAC,UAAU,CAAC,EACnB,CAAA,eAAA,EAAkB,IAAI,CAAA,kDAAA,EAAqD,UAAU,CAAA,CAAE,CACxF;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"direct_template_loader_v3.js","names":[],"sources":["../../../src/mutator/template/direct_template_loader_v3.ts"],"sourcesContent":["import type { AnyRef, AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { Hash } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport type {\n CompiledTemplateV3,\n TemplateDataV3,\n TemplateLibDataV3,\n TemplateSoftwareDataV3,\n} from \"@milaboratories/pl-model-backend\";\nimport {\n PlTemplateLibV1,\n PlTemplateSoftwareV1,\n PlTemplateV1,\n PlTemplateOverrideV1,\n} from \"@milaboratories/pl-model-backend\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * Renders the tree of templates by caching all resource ids\n * by their cache keys.\n * It's different from v2 version because we provide\n * the hash map of the code of all sources everywhere.\n * It does a double-dispatch on the node type (template, library etc),\n * and creates resources.\n *\n * IMO, it'd be clearer to rewrite it with Visitor pattern, and separate\n * tree traversing and operations on it, but I don't have time to do it now.\n */\nexport function createTemplateV3Tree(tx: PlTransaction, tplData: CompiledTemplateV3): AnyRef {\n const resourceCache = new Map<string, AnyResourceRef>();\n\n const createResourceCached = <T>(\n resource: T,\n renderer: Renderer<T>,\n hashToSource: Record<string, string>,\n ): AnyResourceRef => {\n const key: Hash = createHash(\"sha256\");\n renderer.updateCacheKey(resource, key, hashToSource);\n\n const rKey = key.digest(\"hex\");\n\n if (!resourceCache.has(rKey)) {\n const rId = renderer.render(resource, tx, createResourceCached, hashToSource);\n resourceCache.set(rKey, rId);\n }\n\n return resourceCache.get(rKey)!;\n };\n\n return createResourceCached(tplData.template, TemplateRenderer, tplData.hashToSource);\n}\n\ntype Renderer<T> = {\n /** Updates the cache key by adding all info of the artifact. */\n updateCacheKey: CacheKey<T>;\n /** Create resources for all dependencies recursively and then for this artifact. */\n render: (\n resource: T,\n tx: PlTransaction,\n creator: Creator,\n sources: Record<string, string>,\n ) => AnyResourceRef;\n};\ntype CacheKey<T> = (resource: T, key: Hash, sources: Record<string, string>) => void;\ntype Creator = <T>(\n resource: T,\n renderer: Renderer<T>,\n sources: Record<string, string>,\n) => AnyResourceRef;\n\nconst LibRenderer: Renderer<TemplateLibDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateLibV1.type.name)\n .update(PlTemplateLibV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n return tx.createValue(\n PlTemplateLibV1.type,\n JSON.stringify(\n PlTemplateLibV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n },\n};\n\nconst SoftwareInfoRenderer: Renderer<TemplateSoftwareDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateSoftwareV1.type.name)\n .update(PlTemplateSoftwareV1.type.version)\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n },\n render(resource, tx, _creator, sources) {\n const sw = PlTemplateSoftwareV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n );\n const ref = tx.createStruct(PlTemplateSoftwareV1.type, sw.data);\n tx.setKValue(ref, PlTemplateSoftwareV1.metaNameKey, JSON.stringify(sw.name));\n tx.lock(ref);\n return ref;\n },\n};\n\nconst TemplateRenderer: Renderer<TemplateDataV3> = {\n updateCacheKey(resource, hash, sources) {\n hash\n .update(PlTemplateV1.type.name)\n .update(PlTemplateV1.type.version)\n .update(resource.hashOverride ?? \"no-override\")\n .update(resource.name)\n .update(resource.version)\n .update(getSourceCode(resource.name, sources, resource.sourceHash));\n\n const srt = <T>(entries: [string, T][]): [string, T][] => {\n entries.sort((a, b) => (a[0] === b[0] ? 0 : a[0] < b[0] ? -1 : 1));\n return entries;\n };\n\n for (const [libId, lib] of srt(Object.entries(resource.libs ?? {}))) {\n hash.update(\"lib:\" + libId);\n LibRenderer.updateCacheKey(lib, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.software ?? {}))) {\n hash.update(\"soft:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [swId, sw] of srt(Object.entries(resource.assets ?? {}))) {\n hash.update(\"asset:\" + swId);\n SoftwareInfoRenderer.updateCacheKey(sw, hash, sources);\n }\n for (const [tplId, tpl] of srt(Object.entries(resource.templates ?? {}))) {\n hash.update(\"tpl:\" + tplId);\n this.updateCacheKey(tpl, hash, sources);\n }\n },\n render(resource, tx, _creator, sources) {\n const tplRef = tx.createStruct(\n PlTemplateV1.type,\n JSON.stringify(\n PlTemplateV1.fromV3Data(\n resource,\n getSourceCode(resource.name, sources, resource.sourceHash),\n ).data,\n ),\n );\n // Render libraries\n for (const [libId, lib] of Object.entries(resource.libs ?? {})) {\n const fld = PlTemplateV1.libField(tplRef, libId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(lib, LibRenderer, sources));\n }\n\n // Render software and assets\n for (const [swId, sw] of Object.entries(resource.software ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n for (const [swId, sw] of Object.entries(resource.assets ?? {})) {\n const fld = PlTemplateV1.swField(tplRef, swId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(sw, SoftwareInfoRenderer, sources));\n }\n\n // Render dependency templates\n for (const [depTplId, depTpl] of Object.entries(resource.templates ?? {})) {\n const fld = PlTemplateV1.tplField(tplRef, depTplId);\n tx.createField(fld, \"Input\");\n tx.setField(fld, _creator(depTpl, TemplateRenderer, sources));\n }\n\n tx.lock(tplRef);\n\n if (!resource.hashOverride) return tplRef;\n\n // Override template hash with proxy resource, when hash override is configured for template\n const overrideRef = tx.createStruct(\n PlTemplateOverrideV1.type,\n JSON.stringify(PlTemplateOverrideV1.fromV3Data(resource)),\n );\n const fld = PlTemplateOverrideV1.tplField(overrideRef);\n tx.createField(fld, \"Service\");\n tx.setField(fld, tplRef);\n tx.lock(overrideRef);\n return overrideRef;\n },\n};\n\n/**\n * Gets a source code of the artifact by its source hash.\n * the source hash was calculated and stored by tengo compiler\n * and is different from the hash we're using for caching here.\n */\nfunction getSourceCode(name: string, sources: Record<string, string>, sourceHash: string): string {\n return notEmpty(\n sources[sourceHash],\n `trying to get \"${name}\" source: sources map doesn't contain source hash ${sourceHash}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,SAAgB,qBAAqB,IAAmB,SAAqC;CAC3F,MAAM,gCAAgB,IAAI,KAA6B;CAEvD,MAAM,wBACJ,UACA,UACA,iBACmB;EACnB,MAAM,MAAY,WAAW,SAAS;AACtC,WAAS,eAAe,UAAU,KAAK,aAAa;EAEpD,MAAM,OAAO,IAAI,OAAO,MAAM;AAE9B,MAAI,CAAC,cAAc,IAAI,KAAK,EAAE;GAC5B,MAAM,MAAM,SAAS,OAAO,UAAU,IAAI,sBAAsB,aAAa;AAC7E,iBAAc,IAAI,MAAM,IAAI;;AAG9B,SAAO,cAAc,IAAI,KAAK;;AAGhC,QAAO,qBAAqB,QAAQ,UAAU,kBAAkB,QAAQ,aAAa;;AAqBvF,MAAM,cAA2C;CAC/C,eAAe,UAAU,MAAM,SAAS;AACtC,OACG,OAAO,gBAAgB,KAAK,KAAK,CACjC,OAAO,gBAAgB,KAAK,QAAQ,CACpC,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