@milaboratories/pl-middle-layer 1.74.11 → 1.74.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/dist/_virtual/{_@oxc-project_runtime@0.137.0 → _@oxc-project_runtime@0.155.0}/helpers/esm/usingCtx.cjs +1 -2
  2. package/dist/_virtual/{_@oxc-project_runtime@0.137.0 → _@oxc-project_runtime@0.155.0}/helpers/esm/usingCtx.js +1 -2
  3. package/dist/_virtual/_rolldown/runtime.cjs +2 -3
  4. package/dist/block_registry/location_provider.cjs +1 -2
  5. package/dist/block_registry/location_provider.cjs.map +1 -1
  6. package/dist/block_registry/location_provider.js +1 -2
  7. package/dist/block_registry/registry-v2-provider.cjs +1 -2
  8. package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
  9. package/dist/block_registry/registry-v2-provider.d.ts +0 -2
  10. package/dist/block_registry/registry-v2-provider.d.ts.map +1 -1
  11. package/dist/block_registry/registry-v2-provider.js +1 -2
  12. package/dist/block_registry/registry.cjs +3 -3
  13. package/dist/block_registry/registry.cjs.map +1 -1
  14. package/dist/block_registry/registry.d.ts +0 -2
  15. package/dist/block_registry/registry.d.ts.map +1 -1
  16. package/dist/block_registry/registry.js +3 -3
  17. package/dist/block_registry/registry.js.map +1 -1
  18. package/dist/block_registry/template_provider.cjs +1 -2
  19. package/dist/block_registry/template_provider.cjs.map +1 -1
  20. package/dist/block_registry/template_provider.d.ts +0 -2
  21. package/dist/block_registry/template_provider.d.ts.map +1 -1
  22. package/dist/block_registry/template_provider.js +1 -2
  23. package/dist/block_registry/watcher.cjs +15 -14
  24. package/dist/block_registry/watcher.cjs.map +1 -1
  25. package/dist/block_registry/watcher.d.ts +0 -2
  26. package/dist/block_registry/watcher.d.ts.map +1 -1
  27. package/dist/block_registry/watcher.js +15 -14
  28. package/dist/block_registry/watcher.js.map +1 -1
  29. package/dist/block_registry/well_known_registries.cjs +1 -2
  30. package/dist/block_registry/well_known_registries.d.ts +0 -2
  31. package/dist/block_registry/well_known_registries.d.ts.map +1 -1
  32. package/dist/block_registry/well_known_registries.js +1 -2
  33. package/dist/cfg_render/executor.cjs +1 -2
  34. package/dist/cfg_render/executor.cjs.map +1 -1
  35. package/dist/cfg_render/executor.js +1 -2
  36. package/dist/cfg_render/renderer.cjs +1 -2
  37. package/dist/cfg_render/renderer.cjs.map +1 -1
  38. package/dist/cfg_render/renderer.js +1 -2
  39. package/dist/cfg_render/traverse.cjs +1 -2
  40. package/dist/cfg_render/traverse.js +1 -2
  41. package/dist/cfg_render/util.cjs +1 -2
  42. package/dist/cfg_render/util.js +1 -2
  43. package/dist/debug/index.cjs +1 -2
  44. package/dist/debug/index.js +1 -2
  45. package/dist/dev_env/index.cjs +1 -2
  46. package/dist/dev_env/index.cjs.map +1 -1
  47. package/dist/dev_env/index.js +1 -2
  48. package/dist/dev_env/util.cjs +1 -2
  49. package/dist/dev_env/util.js +1 -2
  50. package/dist/js_render/column_registry.cjs +1 -2
  51. package/dist/js_render/column_registry.cjs.map +1 -1
  52. package/dist/js_render/column_registry.js +1 -2
  53. package/dist/js_render/computable_context.cjs +4 -4
  54. package/dist/js_render/computable_context.cjs.map +1 -1
  55. package/dist/js_render/computable_context.js +4 -4
  56. package/dist/js_render/computable_context.js.map +1 -1
  57. package/dist/js_render/context.cjs +1 -2
  58. package/dist/js_render/context.cjs.map +1 -1
  59. package/dist/js_render/context.js +1 -2
  60. package/dist/js_render/index.cjs +12 -9
  61. package/dist/js_render/index.cjs.map +1 -1
  62. package/dist/js_render/index.js +12 -9
  63. package/dist/js_render/index.js.map +1 -1
  64. package/dist/js_render/service_injectors.cjs +2 -3
  65. package/dist/js_render/service_injectors.js +2 -3
  66. package/dist/js_render/spec_override_collapse.cjs +1 -2
  67. package/dist/js_render/spec_override_collapse.cjs.map +1 -1
  68. package/dist/js_render/spec_override_collapse.js +1 -2
  69. package/dist/middle_layer/active_cfg.cjs +1 -2
  70. package/dist/middle_layer/active_cfg.cjs.map +1 -1
  71. package/dist/middle_layer/active_cfg.js +1 -2
  72. package/dist/middle_layer/block.cjs +1 -2
  73. package/dist/middle_layer/block.cjs.map +1 -1
  74. package/dist/middle_layer/block.js +1 -2
  75. package/dist/middle_layer/block_ctx.cjs +3 -3
  76. package/dist/middle_layer/block_ctx.cjs.map +1 -1
  77. package/dist/middle_layer/block_ctx.js +3 -3
  78. package/dist/middle_layer/block_ctx.js.map +1 -1
  79. package/dist/middle_layer/block_ctx_unsafe.cjs +1 -2
  80. package/dist/middle_layer/block_ctx_unsafe.js +1 -2
  81. package/dist/middle_layer/build_stamp.cjs +2 -3
  82. package/dist/middle_layer/build_stamp.js +2 -3
  83. package/dist/middle_layer/driver_kit.cjs +1 -2
  84. package/dist/middle_layer/driver_kit.cjs.map +1 -1
  85. package/dist/middle_layer/driver_kit.d.ts +0 -2
  86. package/dist/middle_layer/driver_kit.d.ts.map +1 -1
  87. package/dist/middle_layer/driver_kit.js +1 -2
  88. package/dist/middle_layer/finality_stop_rules.cjs +1 -2
  89. package/dist/middle_layer/finality_stop_rules.js +1 -2
  90. package/dist/middle_layer/folders.cjs +12 -8
  91. package/dist/middle_layer/folders.cjs.map +1 -1
  92. package/dist/middle_layer/folders.d.ts +0 -2
  93. package/dist/middle_layer/folders.d.ts.map +1 -1
  94. package/dist/middle_layer/folders.js +12 -8
  95. package/dist/middle_layer/folders.js.map +1 -1
  96. package/dist/middle_layer/frontend_path.cjs +1 -2
  97. package/dist/middle_layer/frontend_path.cjs.map +1 -1
  98. package/dist/middle_layer/frontend_path.js +1 -2
  99. package/dist/middle_layer/middle_layer.cjs +7 -6
  100. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  101. package/dist/middle_layer/middle_layer.d.ts +0 -2
  102. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  103. package/dist/middle_layer/middle_layer.js +7 -6
  104. package/dist/middle_layer/middle_layer.js.map +1 -1
  105. package/dist/middle_layer/navigation_states.cjs +1 -2
  106. package/dist/middle_layer/navigation_states.js +1 -2
  107. package/dist/middle_layer/ops.cjs +10 -11
  108. package/dist/middle_layer/ops.cjs.map +1 -1
  109. package/dist/middle_layer/ops.d.ts +0 -2
  110. package/dist/middle_layer/ops.d.ts.map +1 -1
  111. package/dist/middle_layer/ops.js +10 -11
  112. package/dist/middle_layer/ops.js.map +1 -1
  113. package/dist/middle_layer/project.cjs +3 -3
  114. package/dist/middle_layer/project.cjs.map +1 -1
  115. package/dist/middle_layer/project.d.ts +3 -5
  116. package/dist/middle_layer/project.d.ts.map +1 -1
  117. package/dist/middle_layer/project.js +3 -3
  118. package/dist/middle_layer/project.js.map +1 -1
  119. package/dist/middle_layer/project_list.cjs +1 -2
  120. package/dist/middle_layer/project_list.cjs.map +1 -1
  121. package/dist/middle_layer/project_list.d.ts +0 -2
  122. package/dist/middle_layer/project_list.d.ts.map +1 -1
  123. package/dist/middle_layer/project_list.js +1 -2
  124. package/dist/middle_layer/project_overview.cjs +8 -5
  125. package/dist/middle_layer/project_overview.cjs.map +1 -1
  126. package/dist/middle_layer/project_overview.js +8 -5
  127. package/dist/middle_layer/project_overview.js.map +1 -1
  128. package/dist/middle_layer/project_overview_light.cjs +4 -3
  129. package/dist/middle_layer/project_overview_light.cjs.map +1 -1
  130. package/dist/middle_layer/project_overview_light.js +4 -3
  131. package/dist/middle_layer/project_overview_light.js.map +1 -1
  132. package/dist/middle_layer/render.cjs +1 -2
  133. package/dist/middle_layer/render.cjs.map +1 -1
  134. package/dist/middle_layer/render.js +1 -2
  135. package/dist/middle_layer/sharing_list.cjs +1 -2
  136. package/dist/middle_layer/sharing_list.cjs.map +1 -1
  137. package/dist/middle_layer/sharing_list.d.ts +0 -2
  138. package/dist/middle_layer/sharing_list.d.ts.map +1 -1
  139. package/dist/middle_layer/sharing_list.js +1 -2
  140. package/dist/middle_layer/sharing_list.js.map +1 -1
  141. package/dist/middle_layer/template_list.cjs +1 -2
  142. package/dist/middle_layer/template_list.cjs.map +1 -1
  143. package/dist/middle_layer/template_list.d.ts +0 -2
  144. package/dist/middle_layer/template_list.d.ts.map +1 -1
  145. package/dist/middle_layer/template_list.js +1 -2
  146. package/dist/middle_layer/tree_snapshot_store.cjs +3 -3
  147. package/dist/middle_layer/tree_snapshot_store.cjs.map +1 -1
  148. package/dist/middle_layer/tree_snapshot_store.d.ts +0 -2
  149. package/dist/middle_layer/tree_snapshot_store.d.ts.map +1 -1
  150. package/dist/middle_layer/tree_snapshot_store.js +3 -3
  151. package/dist/middle_layer/tree_snapshot_store.js.map +1 -1
  152. package/dist/middle_layer/types.d.ts +0 -2
  153. package/dist/middle_layer/types.d.ts.map +1 -1
  154. package/dist/middle_layer/util.cjs +1 -2
  155. package/dist/middle_layer/util.cjs.map +1 -1
  156. package/dist/middle_layer/util.js +1 -2
  157. package/dist/model/args.cjs +1 -2
  158. package/dist/model/args.cjs.map +1 -1
  159. package/dist/model/args.js +1 -2
  160. package/dist/model/block_pack_spec.cjs +1 -2
  161. package/dist/model/block_pack_spec.d.ts +0 -2
  162. package/dist/model/block_pack_spec.d.ts.map +1 -1
  163. package/dist/model/block_pack_spec.js +1 -2
  164. package/dist/model/frontend.d.ts +0 -2
  165. package/dist/model/frontend.d.ts.map +1 -1
  166. package/dist/model/project_helper.cjs +1 -2
  167. package/dist/model/project_helper.cjs.map +1 -1
  168. package/dist/model/project_helper.d.ts +0 -2
  169. package/dist/model/project_helper.d.ts.map +1 -1
  170. package/dist/model/project_helper.js +1 -2
  171. package/dist/model/project_model.cjs +1 -2
  172. package/dist/model/project_model.d.ts +0 -2
  173. package/dist/model/project_model.d.ts.map +1 -1
  174. package/dist/model/project_model.js +1 -2
  175. package/dist/model/project_model_util.cjs +1 -2
  176. package/dist/model/project_model_util.js +1 -2
  177. package/dist/model/project_model_v1.cjs +1 -2
  178. package/dist/model/project_model_v1.js +1 -2
  179. package/dist/model/sharing_model.cjs +1 -2
  180. package/dist/model/sharing_model.cjs.map +1 -1
  181. package/dist/model/sharing_model.d.ts +0 -2
  182. package/dist/model/sharing_model.d.ts.map +1 -1
  183. package/dist/model/sharing_model.js +1 -2
  184. package/dist/model/template_apply.cjs +1 -2
  185. package/dist/model/template_apply.cjs.map +1 -1
  186. package/dist/model/template_apply.d.ts +0 -2
  187. package/dist/model/template_apply.d.ts.map +1 -1
  188. package/dist/model/template_apply.js +1 -2
  189. package/dist/model/template_export.cjs +1 -2
  190. package/dist/model/template_export.d.ts +0 -2
  191. package/dist/model/template_export.d.ts.map +1 -1
  192. package/dist/model/template_export.js +1 -2
  193. package/dist/model/template_parser.cjs +1 -2
  194. package/dist/model/template_parser.cjs.map +1 -1
  195. package/dist/model/template_parser.d.ts +0 -2
  196. package/dist/model/template_parser.d.ts.map +1 -1
  197. package/dist/model/template_parser.js +1 -2
  198. package/dist/model/template_resolve.cjs +1 -2
  199. package/dist/model/template_resolve.cjs.map +1 -1
  200. package/dist/model/template_resolve.d.ts +0 -2
  201. package/dist/model/template_resolve.d.ts.map +1 -1
  202. package/dist/model/template_resolve.js +1 -2
  203. package/dist/model/template_serializer.cjs +1 -2
  204. package/dist/model/template_serializer.cjs.map +1 -1
  205. package/dist/model/template_serializer.d.ts +0 -2
  206. package/dist/model/template_serializer.d.ts.map +1 -1
  207. package/dist/model/template_serializer.js +1 -2
  208. package/dist/model/template_spec.d.ts +0 -2
  209. package/dist/model/template_spec.d.ts.map +1 -1
  210. package/dist/mutator/block-pack/block_pack.cjs +7 -6
  211. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  212. package/dist/mutator/block-pack/block_pack.d.ts +0 -2
  213. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  214. package/dist/mutator/block-pack/block_pack.js +7 -6
  215. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  216. package/dist/mutator/block-pack/frontend.cjs +1 -2
  217. package/dist/mutator/block-pack/frontend.cjs.map +1 -1
  218. package/dist/mutator/block-pack/frontend.js +1 -2
  219. package/dist/mutator/block-pack/required_capabilities.cjs +1 -2
  220. package/dist/mutator/block-pack/required_capabilities.cjs.map +1 -1
  221. package/dist/mutator/block-pack/required_capabilities.js +1 -2
  222. package/dist/mutator/context_export.cjs +1 -2
  223. package/dist/mutator/context_export.cjs.map +1 -1
  224. package/dist/mutator/context_export.js +1 -2
  225. package/dist/mutator/list.cjs +1 -2
  226. package/dist/mutator/list.cjs.map +1 -1
  227. package/dist/mutator/list.js +1 -2
  228. package/dist/mutator/migration.cjs +1 -2
  229. package/dist/mutator/migration.cjs.map +1 -1
  230. package/dist/mutator/migration.js +1 -2
  231. package/dist/mutator/project.cjs +30 -22
  232. package/dist/mutator/project.cjs.map +1 -1
  233. package/dist/mutator/project.d.ts +0 -2
  234. package/dist/mutator/project.d.ts.map +1 -1
  235. package/dist/mutator/project.js +30 -22
  236. package/dist/mutator/project.js.map +1 -1
  237. package/dist/mutator/sharing.cjs +1 -2
  238. package/dist/mutator/sharing.cjs.map +1 -1
  239. package/dist/mutator/sharing.js +1 -2
  240. package/dist/mutator/template/direct_template_loader.cjs +1 -2
  241. package/dist/mutator/template/direct_template_loader.cjs.map +1 -1
  242. package/dist/mutator/template/direct_template_loader.js +1 -2
  243. package/dist/mutator/template/direct_template_loader_v3.cjs +1 -2
  244. package/dist/mutator/template/direct_template_loader_v3.cjs.map +1 -1
  245. package/dist/mutator/template/direct_template_loader_v3.js +1 -2
  246. package/dist/mutator/template/render_block.cjs +1 -2
  247. package/dist/mutator/template/render_block.cjs.map +1 -1
  248. package/dist/mutator/template/render_block.js +1 -2
  249. package/dist/mutator/template/render_template.cjs +1 -2
  250. package/dist/mutator/template/render_template.cjs.map +1 -1
  251. package/dist/mutator/template/render_template.d.ts +0 -2
  252. package/dist/mutator/template/render_template.d.ts.map +1 -1
  253. package/dist/mutator/template/render_template.js +1 -2
  254. package/dist/mutator/template/template_cache.cjs +6 -5
  255. package/dist/mutator/template/template_cache.cjs.map +1 -1
  256. package/dist/mutator/template/template_cache.d.ts +1 -2
  257. package/dist/mutator/template/template_cache.d.ts.map +1 -1
  258. package/dist/mutator/template/template_cache.js +6 -5
  259. package/dist/mutator/template/template_cache.js.map +1 -1
  260. package/dist/mutator/template/template_loading.cjs +1 -2
  261. package/dist/mutator/template/template_loading.cjs.map +1 -1
  262. package/dist/mutator/template/template_loading.d.ts +0 -2
  263. package/dist/mutator/template/template_loading.d.ts.map +1 -1
  264. package/dist/mutator/template/template_loading.js +1 -2
  265. package/dist/mutator/template.cjs +1 -2
  266. package/dist/mutator/template.cjs.map +1 -1
  267. package/dist/mutator/template.js +1 -2
  268. package/dist/mutator/template_construct.cjs +1 -2
  269. package/dist/mutator/template_construct.cjs.map +1 -1
  270. package/dist/mutator/template_construct.js +1 -2
  271. package/dist/network_check/network_check.cjs +2 -3
  272. package/dist/network_check/network_check.cjs.map +1 -1
  273. package/dist/network_check/network_check.d.ts +0 -2
  274. package/dist/network_check/network_check.d.ts.map +1 -1
  275. package/dist/network_check/network_check.js +2 -3
  276. package/dist/network_check/network_check.js.map +1 -1
  277. package/dist/network_check/pings.cjs +1 -2
  278. package/dist/network_check/pings.cjs.map +1 -1
  279. package/dist/network_check/pings.js +1 -2
  280. package/dist/network_check/template.cjs +5 -4
  281. package/dist/network_check/template.cjs.map +1 -1
  282. package/dist/network_check/template.js +5 -4
  283. package/dist/network_check/template.js.map +1 -1
  284. package/dist/pool/data.cjs +1 -2
  285. package/dist/pool/data.cjs.map +1 -1
  286. package/dist/pool/data.d.ts +0 -2
  287. package/dist/pool/data.d.ts.map +1 -1
  288. package/dist/pool/data.js +1 -2
  289. package/dist/pool/driver.cjs +5 -4
  290. package/dist/pool/driver.cjs.map +1 -1
  291. package/dist/pool/driver.d.ts +0 -2
  292. package/dist/pool/driver.d.ts.map +1 -1
  293. package/dist/pool/driver.js +5 -4
  294. package/dist/pool/driver.js.map +1 -1
  295. package/dist/pool/p_object_collection.cjs +9 -8
  296. package/dist/pool/p_object_collection.cjs.map +1 -1
  297. package/dist/pool/p_object_collection.d.ts +0 -2
  298. package/dist/pool/p_object_collection.d.ts.map +1 -1
  299. package/dist/pool/p_object_collection.js +9 -8
  300. package/dist/pool/p_object_collection.js.map +1 -1
  301. package/dist/pool/result_pool.cjs +8 -7
  302. package/dist/pool/result_pool.cjs.map +1 -1
  303. package/dist/pool/result_pool.js +8 -7
  304. package/dist/pool/result_pool.js.map +1 -1
  305. package/dist/pool/upstream_block_ctx.cjs +1 -2
  306. package/dist/pool/upstream_block_ctx.cjs.map +1 -1
  307. package/dist/pool/upstream_block_ctx.js +1 -2
  308. package/dist/service_factories.cjs +1 -2
  309. package/dist/service_factories.js +1 -2
  310. package/dist/worker/WorkerManager.cjs +1 -2
  311. package/dist/worker/WorkerManager.js +1 -2
  312. package/dist/worker/WorkerManager.js.map +1 -1
  313. package/dist/worker/worker.cjs +1 -2
  314. package/dist/worker/worker.js +1 -2
  315. package/dist/worker/workerApi.cjs +1 -2
  316. package/dist/worker/workerApi.cjs.map +1 -1
  317. package/dist/worker/workerApi.js +1 -2
  318. package/package.json +33 -33
  319. package/src/middle_layer/middle_layer.ts +4 -6
  320. package/src/middle_layer/tree_snapshot_store.test.ts +4 -1
@@ -1,5 +1,4 @@
1
1
  import { ProjectTemplateV1 } from "@milaboratories/pl-model-common";
2
- //#region src/model/template_parser.d.ts
3
2
  /**
4
3
  * A template file read, or why it could not be.
5
4
  *
@@ -37,5 +36,4 @@ export type TemplateParseOutcome = {
37
36
  * those are later stages, and both need more than the file to answer.
38
37
  */
39
38
  export declare function parseProjectTemplateV1Yaml(text: string): TemplateParseOutcome;
40
- //#endregion
41
39
  //# sourceMappingURL=template_parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"template_parser.d.ts","names":[],"sources":["../../src/model/template_parser.ts"],"mappings":";;;;;;;;;;;YAiBY;WACG;WAAmB,UAAU;;WAC7B;WAAoB;;;;;;;;;;;;;;;;;;;;;;wBAsBnB,2BAA2B,eAAe"}
1
+ {"version":3,"file":"template_parser.d.ts","names":[],"sources":["../../src/model/template_parser.ts"],"mappings":";;;;;;;;;;YAiBY;WACG;WAAmB,UAAU;;WAC7B;WAAoB;;;;;;;;;;;;;;;;;;;;;;wBAsBnB,2BAA2B,eAAe"}
@@ -1,6 +1,6 @@
1
1
  import YAML from "yaml";
2
2
  import { PROJECT_TEMPLATE_SCHEMA_V1, formatTemplateParseIssue, readProjectTemplateV1 } from "@milaboratories/pl-model-common";
3
- //#region src/model/template_parser.ts
3
+ // src/model/template_parser.ts
4
4
  /**
5
5
  * Read `template-v1` YAML text into a document.
6
6
  *
@@ -66,7 +66,6 @@ function describeIssues(issues) {
66
66
  const lines = issues.map((issue) => `- ${formatTemplateParseIssue(issue)}`);
67
67
  return [lines.length === 1 ? "The template file has a problem:" : `The template file has ${lines.length} problems:`, ...lines].join("\n");
68
68
  }
69
- //#endregion
70
69
  export { parseProjectTemplateV1Yaml };
71
70
 
72
71
  //# sourceMappingURL=template_parser.js.map
@@ -1,5 +1,5 @@
1
1
  let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
2
- //#region src/model/template_resolve.ts
2
+ // src/model/template_resolve.ts
3
3
  /**
4
4
  * Resolve every entry in a template document to a concrete block pack.
5
5
  *
@@ -127,7 +127,6 @@ function parseBlockPackName(npmName) {
127
127
  function messageOf(e) {
128
128
  return e instanceof Error ? e.message : String(e);
129
129
  }
130
- //#endregion
131
130
  exports.parseBlockPackName = parseBlockPackName;
132
131
  exports.resolveTemplateEntries = resolveTemplateEntries;
133
132
 
@@ -1 +1 @@
1
- {"version":3,"file":"template_resolve.cjs","names":[],"sources":["../../src/model/template_resolve.ts"],"sourcesContent":["import type {\n BlockKindSelectorReference,\n BlockPackLocationReference,\n ProjectTemplateV1,\n ProjectTemplateV1Entry,\n} from \"@milaboratories/pl-model-common\";\nimport {\n parseBlockPackReference,\n parseKindSelectorReference,\n} from \"@milaboratories/pl-model-common\";\nimport type { BlockPackId, BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport type { TemplateApplyProblem } from \"./template_apply\";\n\n/**\n * Where a template entry's block comes from.\n *\n * All three of an entry's paths to an implementation go through this one interface, and\n * all three come back as the same `BlockPackSpec` — the shape the existing add-block\n * path already consumes — plus the block's published title. That convergence is the\n * point: everything downstream of resolution treats a kind-resolved entry, a\n * version-pinned one and a filesystem-located one identically, which is why a locally\n * built block travels the same preparation and construction path as a published one.\n *\n * Registry knowledge sits deliberately on the far side of this interface. A template\n * file names no registry, so choosing which one (or ones) to consult is a property\n * of the environment applying the file, not of the file — and keeping it out here is\n * what lets resolution be tested with no registry at all.\n *\n * The title is required rather than optional for the same reason: an implementation\n * always has one to hand — a registry adapter reads it off the block's manifest, and\n * anything else names the blocks it serves — while a caller downstream has no source\n * for it at all, and the fallbacks it could invent are all wrong. See\n * {@link ResolvedEntry}'s `title`.\n */\nexport type BlockPackProvider = {\n /**\n * Find the block implementing a kind selector.\n *\n * @param kind The entry's `{name}@{selector}` reference\n * @param options `allowUnstable` widens the search from stable implementations to\n * every published one, for the whole apply\n */\n byKind: (\n kind: BlockKindSelectorReference,\n options: { allowUnstable: boolean },\n ) => Promise<KindResolution>;\n\n /**\n * Find one exact block package version, named directly.\n *\n * This is the `block` override's path, and it bypasses kinds entirely — the\n * override exists precisely to pin an implementation that resolution would not\n * have chosen.\n */\n byExactVersion: (id: BlockPackId) => Promise<ExactResolution>;\n\n /**\n * Read the implementation sitting at one location.\n *\n * The `location` override's path, for a block that no registry knows because it was\n * built and never published. Nothing is searched: the entry says where, so either\n * that place holds a block or the entry is wrong.\n *\n * Answers \"is there a block here\", not \"is it the right one\". Whether the block found\n * implements the kind the entry asks for is settled once it has been prepared, from the\n * compiled model — the one place all three routes have it. This reader could answer it\n * too, since it reads the block's description anyway, and answering it here as well would\n * make two homes for one invariant while leaving the pinned-version route uncovered.\n */\n byLocation: (location: BlockPackLocationReference) => Promise<LocationResolution>;\n};\n\n/**\n * The outcome of resolving one kind selector.\n *\n * The three failure reasons are distinct because each has a different way out, and\n * a caller that collapsed them would leave the reader guessing which:\n *\n * - `no-matching-kind-version` — the selector matches no published version of the\n * kind at all. The file, or the registry, is wrong.\n * - `no-implementation` — the kind version exists, but nothing implements it. The\n * kind was published ahead of any block.\n * - `no-stable-implementation` — implementations exist but none is stable, and the\n * apply did not allow unstable ones. This is the only reason the user can act on\n * without editing anything.\n */\nexport type KindResolution =\n | { readonly ok: true; readonly spec: BlockPackSpec; readonly title: string }\n | {\n readonly ok: false;\n readonly reason:\n | \"no-matching-kind-version\"\n | \"no-implementation\"\n | \"no-stable-implementation\";\n };\n\n/** The outcome of locating one exact block version. */\nexport type ExactResolution =\n | { readonly ok: true; readonly spec: BlockPackSpec; readonly title: string }\n | { readonly ok: false; readonly reason: \"no-such-block-version\" };\n\n/**\n * The outcome of reading the implementation at one location.\n *\n * The three failure reasons separate three different mistakes, and each is fixed\n * differently:\n *\n * - `unsupported-scheme` — the URI is well-formed but names a way of fetching that\n * this environment has no reader for. A property of the environment, not the file.\n * - `not-found` — nothing is at that location. Usually a template carried to another\n * machine, or a folder that moved.\n * - `not-a-block` — something is there, but it is not a block. Usually a path pointing\n * one directory off, which is why the message has to say what was looked for.\n */\nexport type LocationResolution =\n | {\n readonly ok: true;\n readonly spec: BlockPackSpec;\n readonly title: string;\n }\n | {\n readonly ok: false;\n readonly reason: \"unsupported-scheme\" | \"not-found\" | \"not-a-block\";\n };\n\n/** Where one entry's block will come from. */\nexport type ResolvedEntry = {\n /** The entry's template-local id. */\n readonly entryId: string;\n readonly spec: BlockPackSpec;\n /**\n * The block package's own title, as its author published it — `meta.title` for a\n * registry block.\n *\n * Carried here because resolution is the only stage that talks to a registry, and a\n * registry is the only thing that knows it. Nothing downstream can recover it: a\n * prepared block pack holds the model, the workflow and the frontend, none of which\n * names the block.\n *\n * It becomes the created block's label, which is what the user sees for any block\n * whose model derives no title of its own — `graph-maker`, `table` and seven other\n * shipped blocks. Deriving it from the entry instead is specifically wrong: an\n * exported template names its entries by the source project's block ids, so a\n * round-tripped project would show UUIDs in the sidebar.\n */\n readonly title: string;\n /**\n * True when the entry named its own implementation — an exact version or a location —\n * rather than letting its kind choose one.\n *\n * Both overrides count, because what this records is that the choice was the file's\n * and not the registry's, which is the same fact for either of them.\n */\n readonly pinned: boolean;\n};\n\n/**\n * What resolution found for a whole document.\n *\n * `resolved` is in file order and holds only the entries that resolved, so\n * `problems.length > 0` means it is incomplete. A caller must not apply a partial\n * resolution: the point of resolving before construction is that nothing is created\n * until every entry has an implementation.\n */\nexport type TemplateResolveOutcome = {\n readonly resolved: readonly ResolvedEntry[];\n readonly problems: readonly TemplateApplyProblem[];\n};\n\n/**\n * Resolve every entry in a template document to a concrete block pack.\n *\n * The first stage of an apply, and the only one that touches the network. It runs\n * before the project exists, which is what makes \"no block for this entry\" a message\n * about a file rather than a half-built project — and it is also why the whole\n * construction API downstream can be synchronous.\n *\n * Every entry is attempted, and every failure collected: an unapplicable file should\n * take one pass to fix, not one pass per bad entry. The one exception is that a\n * problem short-circuits nothing, so `resolved` may be shorter than the document.\n *\n * @param document A parsed template document\n * @param provider Where blocks come from\n * @param options `allowUnstable` applies to the whole document, not per entry\n */\nexport async function resolveTemplateEntries(\n document: ProjectTemplateV1,\n provider: BlockPackProvider,\n options: { allowUnstable: boolean },\n): Promise<TemplateResolveOutcome> {\n const resolved: ResolvedEntry[] = [];\n const problems: TemplateApplyProblem[] = [];\n\n // Sequential, not concurrent. Entries commonly share a kind, and a provider\n // caching its reads can only dedupe them if the second request happens after the\n // first has landed. A template holds a handful of entries, so there is nothing to\n // win by overlapping the reads.\n for (const entry of document.blocks) {\n const outcome = await resolveEntry(entry, provider, options);\n if (outcome.ok) resolved.push(outcome.entry);\n else problems.push(outcome.problem);\n }\n\n return { resolved, problems };\n}\n\ntype EntryOutcome =\n | { ok: true; entry: ResolvedEntry }\n | { ok: false; problem: TemplateApplyProblem };\n\nasync function resolveEntry(\n entry: ProjectTemplateV1Entry,\n provider: BlockPackProvider,\n options: { allowUnstable: boolean },\n): Promise<EntryOutcome> {\n const problem = (error: string): EntryOutcome => ({\n ok: false,\n problem: { entryId: entry.id, error },\n });\n\n if (entry.location !== undefined) {\n const outcome = await provider.byLocation(entry.location);\n\n if (!outcome.ok) {\n switch (outcome.reason) {\n case \"unsupported-scheme\":\n return problem(\n `This entry says its block is at '${entry.location}', which this application ` +\n `cannot read. Only a local path ('file:') is supported here.`,\n );\n case \"not-found\":\n return problem(\n `Nothing is at '${entry.location}', where this entry says its block is. A ` +\n `template that pins a folder only works on the machine that folder is on.`,\n );\n case \"not-a-block\":\n return problem(\n `'${entry.location}' is not a block: it holds neither a built block package ` +\n `nor a block's manifest. Point the entry at the folder holding the block's ` +\n `package.json.`,\n );\n }\n }\n\n return {\n ok: true,\n entry: { entryId: entry.id, spec: outcome.spec, title: outcome.title, pinned: true },\n };\n }\n\n if (entry.block !== undefined) {\n let id: BlockPackId;\n try {\n const { name, version } = parseBlockPackReference(entry.block);\n id = { ...parseBlockPackName(name), version };\n } catch (e) {\n // The document's parser already checked the `{name}@X.Y.Z` grammar, but not\n // that the name carries an organization, so this is reachable from a\n // hand-written file. Reported rather than thrown, so one malformed entry cannot\n // hide the state of the rest.\n return problem(`Pinned block version is not readable: ${messageOf(e)}`);\n }\n\n const outcome = await provider.byExactVersion(id);\n if (outcome.ok)\n return {\n ok: true,\n entry: { entryId: entry.id, spec: outcome.spec, title: outcome.title, pinned: true },\n };\n\n return problem(\n `Block '${id.organization}/${id.name}' version ${id.version} was not found. Correct ` +\n `the pinned version in this entry, or remove it so a version is chosen ` +\n `automatically.`,\n );\n }\n\n let kindName: string;\n try {\n kindName = parseKindSelectorReference(entry.kind).name;\n } catch (e) {\n return problem(`Block kind is not readable: ${messageOf(e)}`);\n }\n\n const outcome = await provider.byKind(entry.kind, options);\n if (outcome.ok)\n return {\n ok: true,\n entry: { entryId: entry.id, spec: outcome.spec, title: outcome.title, pinned: false },\n };\n\n switch (outcome.reason) {\n case \"no-matching-kind-version\":\n return problem(\n `No published version of '${kindName}' matches what this entry asks for ` +\n `(${entry.kind}). Check the version, or update the block registry.`,\n );\n case \"no-implementation\":\n return problem(\n `'${kindName}' has no block implementing the version this entry asks for ` +\n `(${entry.kind}). Nothing can be installed for it yet.`,\n );\n case \"no-stable-implementation\":\n // The one failure with a way out that changes nothing in the file, so the\n // message names it.\n return problem(\n `The only blocks implementing '${kindName}' for this entry (${entry.kind}) are ` +\n `pre-release versions. Import again with unstable versions allowed to use them.`,\n );\n }\n}\n\n/**\n * Split a block package's npm name into the organization and name a registry knows\n * it by: `@npm-scope/organization.name` → `{ organization, name }`.\n *\n * The npm scope and the organization are different things, and only the second one\n * reaches the registry — `@milaboratories/milaboratories.test-download-file` is\n * published as organization `milaboratories`, name `test-download-file`. The split is\n * on the FIRST dot, so a name may contain further dots.\n *\n * Kind names follow the same convention, which is why a template can carry both in\n * the same npm-ish form.\n *\n * @throws if the name has no npm scope or no organization segment\n */\nexport function parseBlockPackName(npmName: string): { organization: string; name: string } {\n const slash = npmName.indexOf(\"/\");\n if (!npmName.startsWith(\"@\") || slash < 0) {\n throw new Error(`expected '@npm-scope/organization.name', got '${npmName}'`);\n }\n\n const base = npmName.slice(slash + 1);\n const dot = base.indexOf(\".\");\n if (dot <= 0 || dot === base.length - 1) {\n throw new Error(\n `'${base}' does not separate an organization from a name with '.' in '${npmName}'`,\n );\n }\n\n return { organization: base.slice(0, dot), name: base.slice(dot + 1) };\n}\n\nfunction messageOf(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyLA,eAAsB,uBACpB,UACA,UACA,SACiC;CACjC,MAAM,WAA4B,CAAC;CACnC,MAAM,WAAmC,CAAC;CAM1C,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,MAAM,UAAU,MAAM,aAAa,OAAO,UAAU,OAAO;EAC3D,IAAI,QAAQ,IAAI,SAAS,KAAK,QAAQ,KAAK;OACtC,SAAS,KAAK,QAAQ,OAAO;CACpC;CAEA,OAAO;EAAE;EAAU;CAAS;AAC9B;AAMA,eAAe,aACb,OACA,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,MAAM,MAAM,OAAO;CACzD,IAAI,QAAQ,IACV,OAAO;EACL,IAAI;EACJ,OAAO;GAAE,SAAS,MAAM;GAAI,MAAM,QAAQ;GAAM,OAAO,QAAQ;GAAO,QAAQ;EAAM;CACtF;CAEF,QAAQ,QAAQ,QAAhB;EACE,KAAK,4BACH,OAAO,QACL,4BAA4B,SAAS,sCAC/B,MAAM,KAAK,oDACnB;EACF,KAAK,qBACH,OAAO,QACL,IAAI,SAAS,+DACP,MAAM,KAAK,wCACnB;EACF,KAAK,4BAGH,OAAO,QACL,iCAAiC,SAAS,oBAAoB,MAAM,KAAK,qFAE3E;CACJ;AACF;;;;;;;;;;;;;;;AAgBA,SAAgB,mBAAmB,SAAyD;CAC1F,MAAM,QAAQ,QAAQ,QAAQ,GAAG;CACjC,IAAI,CAAC,QAAQ,WAAW,GAAG,KAAK,QAAQ,GACtC,MAAM,IAAI,MAAM,iDAAiD,QAAQ,EAAE;CAG7E,MAAM,OAAO,QAAQ,MAAM,QAAQ,CAAC;CACpC,MAAM,MAAM,KAAK,QAAQ,GAAG;CAC5B,IAAI,OAAO,KAAK,QAAQ,KAAK,SAAS,GACpC,MAAM,IAAI,MACR,IAAI,KAAK,+DAA+D,QAAQ,EAClF;CAGF,OAAO;EAAE,cAAc,KAAK,MAAM,GAAG,GAAG;EAAG,MAAM,KAAK,MAAM,MAAM,CAAC;CAAE;AACvE;AAEA,SAAS,UAAU,GAAoB;CACrC,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AAClD"}
1
+ {"version":3,"file":"template_resolve.cjs","names":["parseBlockPackReference","parseKindSelectorReference"],"sources":["../../src/model/template_resolve.ts"],"sourcesContent":["import type {\n BlockKindSelectorReference,\n BlockPackLocationReference,\n ProjectTemplateV1,\n ProjectTemplateV1Entry,\n} from \"@milaboratories/pl-model-common\";\nimport {\n parseBlockPackReference,\n parseKindSelectorReference,\n} from \"@milaboratories/pl-model-common\";\nimport type { BlockPackId, BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport type { TemplateApplyProblem } from \"./template_apply\";\n\n/**\n * Where a template entry's block comes from.\n *\n * All three of an entry's paths to an implementation go through this one interface, and\n * all three come back as the same `BlockPackSpec` — the shape the existing add-block\n * path already consumes — plus the block's published title. That convergence is the\n * point: everything downstream of resolution treats a kind-resolved entry, a\n * version-pinned one and a filesystem-located one identically, which is why a locally\n * built block travels the same preparation and construction path as a published one.\n *\n * Registry knowledge sits deliberately on the far side of this interface. A template\n * file names no registry, so choosing which one (or ones) to consult is a property\n * of the environment applying the file, not of the file — and keeping it out here is\n * what lets resolution be tested with no registry at all.\n *\n * The title is required rather than optional for the same reason: an implementation\n * always has one to hand — a registry adapter reads it off the block's manifest, and\n * anything else names the blocks it serves — while a caller downstream has no source\n * for it at all, and the fallbacks it could invent are all wrong. See\n * {@link ResolvedEntry}'s `title`.\n */\nexport type BlockPackProvider = {\n /**\n * Find the block implementing a kind selector.\n *\n * @param kind The entry's `{name}@{selector}` reference\n * @param options `allowUnstable` widens the search from stable implementations to\n * every published one, for the whole apply\n */\n byKind: (\n kind: BlockKindSelectorReference,\n options: { allowUnstable: boolean },\n ) => Promise<KindResolution>;\n\n /**\n * Find one exact block package version, named directly.\n *\n * This is the `block` override's path, and it bypasses kinds entirely — the\n * override exists precisely to pin an implementation that resolution would not\n * have chosen.\n */\n byExactVersion: (id: BlockPackId) => Promise<ExactResolution>;\n\n /**\n * Read the implementation sitting at one location.\n *\n * The `location` override's path, for a block that no registry knows because it was\n * built and never published. Nothing is searched: the entry says where, so either\n * that place holds a block or the entry is wrong.\n *\n * Answers \"is there a block here\", not \"is it the right one\". Whether the block found\n * implements the kind the entry asks for is settled once it has been prepared, from the\n * compiled model — the one place all three routes have it. This reader could answer it\n * too, since it reads the block's description anyway, and answering it here as well would\n * make two homes for one invariant while leaving the pinned-version route uncovered.\n */\n byLocation: (location: BlockPackLocationReference) => Promise<LocationResolution>;\n};\n\n/**\n * The outcome of resolving one kind selector.\n *\n * The three failure reasons are distinct because each has a different way out, and\n * a caller that collapsed them would leave the reader guessing which:\n *\n * - `no-matching-kind-version` — the selector matches no published version of the\n * kind at all. The file, or the registry, is wrong.\n * - `no-implementation` — the kind version exists, but nothing implements it. The\n * kind was published ahead of any block.\n * - `no-stable-implementation` — implementations exist but none is stable, and the\n * apply did not allow unstable ones. This is the only reason the user can act on\n * without editing anything.\n */\nexport type KindResolution =\n | { readonly ok: true; readonly spec: BlockPackSpec; readonly title: string }\n | {\n readonly ok: false;\n readonly reason:\n | \"no-matching-kind-version\"\n | \"no-implementation\"\n | \"no-stable-implementation\";\n };\n\n/** The outcome of locating one exact block version. */\nexport type ExactResolution =\n | { readonly ok: true; readonly spec: BlockPackSpec; readonly title: string }\n | { readonly ok: false; readonly reason: \"no-such-block-version\" };\n\n/**\n * The outcome of reading the implementation at one location.\n *\n * The three failure reasons separate three different mistakes, and each is fixed\n * differently:\n *\n * - `unsupported-scheme` — the URI is well-formed but names a way of fetching that\n * this environment has no reader for. A property of the environment, not the file.\n * - `not-found` — nothing is at that location. Usually a template carried to another\n * machine, or a folder that moved.\n * - `not-a-block` — something is there, but it is not a block. Usually a path pointing\n * one directory off, which is why the message has to say what was looked for.\n */\nexport type LocationResolution =\n | {\n readonly ok: true;\n readonly spec: BlockPackSpec;\n readonly title: string;\n }\n | {\n readonly ok: false;\n readonly reason: \"unsupported-scheme\" | \"not-found\" | \"not-a-block\";\n };\n\n/** Where one entry's block will come from. */\nexport type ResolvedEntry = {\n /** The entry's template-local id. */\n readonly entryId: string;\n readonly spec: BlockPackSpec;\n /**\n * The block package's own title, as its author published it — `meta.title` for a\n * registry block.\n *\n * Carried here because resolution is the only stage that talks to a registry, and a\n * registry is the only thing that knows it. Nothing downstream can recover it: a\n * prepared block pack holds the model, the workflow and the frontend, none of which\n * names the block.\n *\n * It becomes the created block's label, which is what the user sees for any block\n * whose model derives no title of its own — `graph-maker`, `table` and seven other\n * shipped blocks. Deriving it from the entry instead is specifically wrong: an\n * exported template names its entries by the source project's block ids, so a\n * round-tripped project would show UUIDs in the sidebar.\n */\n readonly title: string;\n /**\n * True when the entry named its own implementation — an exact version or a location —\n * rather than letting its kind choose one.\n *\n * Both overrides count, because what this records is that the choice was the file's\n * and not the registry's, which is the same fact for either of them.\n */\n readonly pinned: boolean;\n};\n\n/**\n * What resolution found for a whole document.\n *\n * `resolved` is in file order and holds only the entries that resolved, so\n * `problems.length > 0` means it is incomplete. A caller must not apply a partial\n * resolution: the point of resolving before construction is that nothing is created\n * until every entry has an implementation.\n */\nexport type TemplateResolveOutcome = {\n readonly resolved: readonly ResolvedEntry[];\n readonly problems: readonly TemplateApplyProblem[];\n};\n\n/**\n * Resolve every entry in a template document to a concrete block pack.\n *\n * The first stage of an apply, and the only one that touches the network. It runs\n * before the project exists, which is what makes \"no block for this entry\" a message\n * about a file rather than a half-built project — and it is also why the whole\n * construction API downstream can be synchronous.\n *\n * Every entry is attempted, and every failure collected: an unapplicable file should\n * take one pass to fix, not one pass per bad entry. The one exception is that a\n * problem short-circuits nothing, so `resolved` may be shorter than the document.\n *\n * @param document A parsed template document\n * @param provider Where blocks come from\n * @param options `allowUnstable` applies to the whole document, not per entry\n */\nexport async function resolveTemplateEntries(\n document: ProjectTemplateV1,\n provider: BlockPackProvider,\n options: { allowUnstable: boolean },\n): Promise<TemplateResolveOutcome> {\n const resolved: ResolvedEntry[] = [];\n const problems: TemplateApplyProblem[] = [];\n\n // Sequential, not concurrent. Entries commonly share a kind, and a provider\n // caching its reads can only dedupe them if the second request happens after the\n // first has landed. A template holds a handful of entries, so there is nothing to\n // win by overlapping the reads.\n for (const entry of document.blocks) {\n const outcome = await resolveEntry(entry, provider, options);\n if (outcome.ok) resolved.push(outcome.entry);\n else problems.push(outcome.problem);\n }\n\n return { resolved, problems };\n}\n\ntype EntryOutcome =\n | { ok: true; entry: ResolvedEntry }\n | { ok: false; problem: TemplateApplyProblem };\n\nasync function resolveEntry(\n entry: ProjectTemplateV1Entry,\n provider: BlockPackProvider,\n options: { allowUnstable: boolean },\n): Promise<EntryOutcome> {\n const problem = (error: string): EntryOutcome => ({\n ok: false,\n problem: { entryId: entry.id, error },\n });\n\n if (entry.location !== undefined) {\n const outcome = await provider.byLocation(entry.location);\n\n if (!outcome.ok) {\n switch (outcome.reason) {\n case \"unsupported-scheme\":\n return problem(\n `This entry says its block is at '${entry.location}', which this application ` +\n `cannot read. Only a local path ('file:') is supported here.`,\n );\n case \"not-found\":\n return problem(\n `Nothing is at '${entry.location}', where this entry says its block is. A ` +\n `template that pins a folder only works on the machine that folder is on.`,\n );\n case \"not-a-block\":\n return problem(\n `'${entry.location}' is not a block: it holds neither a built block package ` +\n `nor a block's manifest. Point the entry at the folder holding the block's ` +\n `package.json.`,\n );\n }\n }\n\n return {\n ok: true,\n entry: { entryId: entry.id, spec: outcome.spec, title: outcome.title, pinned: true },\n };\n }\n\n if (entry.block !== undefined) {\n let id: BlockPackId;\n try {\n const { name, version } = parseBlockPackReference(entry.block);\n id = { ...parseBlockPackName(name), version };\n } catch (e) {\n // The document's parser already checked the `{name}@X.Y.Z` grammar, but not\n // that the name carries an organization, so this is reachable from a\n // hand-written file. Reported rather than thrown, so one malformed entry cannot\n // hide the state of the rest.\n return problem(`Pinned block version is not readable: ${messageOf(e)}`);\n }\n\n const outcome = await provider.byExactVersion(id);\n if (outcome.ok)\n return {\n ok: true,\n entry: { entryId: entry.id, spec: outcome.spec, title: outcome.title, pinned: true },\n };\n\n return problem(\n `Block '${id.organization}/${id.name}' version ${id.version} was not found. Correct ` +\n `the pinned version in this entry, or remove it so a version is chosen ` +\n `automatically.`,\n );\n }\n\n let kindName: string;\n try {\n kindName = parseKindSelectorReference(entry.kind).name;\n } catch (e) {\n return problem(`Block kind is not readable: ${messageOf(e)}`);\n }\n\n const outcome = await provider.byKind(entry.kind, options);\n if (outcome.ok)\n return {\n ok: true,\n entry: { entryId: entry.id, spec: outcome.spec, title: outcome.title, pinned: false },\n };\n\n switch (outcome.reason) {\n case \"no-matching-kind-version\":\n return problem(\n `No published version of '${kindName}' matches what this entry asks for ` +\n `(${entry.kind}). Check the version, or update the block registry.`,\n );\n case \"no-implementation\":\n return problem(\n `'${kindName}' has no block implementing the version this entry asks for ` +\n `(${entry.kind}). Nothing can be installed for it yet.`,\n );\n case \"no-stable-implementation\":\n // The one failure with a way out that changes nothing in the file, so the\n // message names it.\n return problem(\n `The only blocks implementing '${kindName}' for this entry (${entry.kind}) are ` +\n `pre-release versions. Import again with unstable versions allowed to use them.`,\n );\n }\n}\n\n/**\n * Split a block package's npm name into the organization and name a registry knows\n * it by: `@npm-scope/organization.name` → `{ organization, name }`.\n *\n * The npm scope and the organization are different things, and only the second one\n * reaches the registry — `@milaboratories/milaboratories.test-download-file` is\n * published as organization `milaboratories`, name `test-download-file`. The split is\n * on the FIRST dot, so a name may contain further dots.\n *\n * Kind names follow the same convention, which is why a template can carry both in\n * the same npm-ish form.\n *\n * @throws if the name has no npm scope or no organization segment\n */\nexport function parseBlockPackName(npmName: string): { organization: string; name: string } {\n const slash = npmName.indexOf(\"/\");\n if (!npmName.startsWith(\"@\") || slash < 0) {\n throw new Error(`expected '@npm-scope/organization.name', got '${npmName}'`);\n }\n\n const base = npmName.slice(slash + 1);\n const dot = base.indexOf(\".\");\n if (dot <= 0 || dot === base.length - 1) {\n throw new Error(\n `'${base}' does not separate an organization from a name with '.' in '${npmName}'`,\n );\n }\n\n return { organization: base.slice(0, dot), name: base.slice(dot + 1) };\n}\n\nfunction messageOf(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyLA,eAAsB,uBACpB,UACA,UACA,SACiC;CACjC,MAAM,WAA4B,CAAC;CACnC,MAAM,WAAmC,CAAC;CAM1C,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,MAAM,UAAU,MAAM,aAAa,OAAO,UAAU,OAAO;EAC3D,IAAI,QAAQ,IAAI,SAAS,KAAK,QAAQ,KAAK;OACtC,SAAS,KAAK,QAA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OAAO,QAAQ,+BAA+B,UAAU,CAAC,GAAG;CAC9D;CAEA,MAAM,UAAU,MAAM,SAAS,OAAO,MAAM,MAAM,OAAO;CACzD,IAAI,QAAQ,IACV,OAAO;EACL,IAAI;EACJ,OAAO;GAAE,SAAS,MAAM;GAAI,MAAM,QAAQ;GAAM,OAAO,QAAQ;GAAO,QAAQ;EAAM;CACtF;CAEF,QAAQ,QAAQ,QAAhB;EACE,KAAK,4BACH,OAAO,QACL,4BAA4B,SAAS,sCAC/B,MAAM,KAAK,oDACnB;EACF,KAAK,qBACH,OAAO,QACL,IAAI,SAAS,+DACP,MAAM,KAAK,wCACnB;EACF,KAAK,4BAGH,OAAO,QACL,iCAAiC,SAAS,oBAAoB,MAAM,KAAK,qFAE3E;CACJ;AACF;;;;;;;;;;;;;;;AAgBA,SAAgB,mBAAmB,SAAyD;CAC1F,MAAM,QAAQ,QAAQ,QAAQ,GAAG;CACjC,IAAI,CAAC,QAAQ,WAAW,GAAG,KAAK,QAAQ,GACtC,MAAM,IAAI,MAAM,iDAAiD,QAAQ,EAAE;CAG7E,MAAM,OAAO,QAAQ,MAAM,QAAQ,CAAC;CACpC,MAAM,MAAM,KAAK,QAAQ,GAAG;CAC5B,IAAI,OAAO,KAAK,QAAQ,KAAK,SAAS,GACpC,MAAM,IAAI,MACR,IAAI,KAAK,+DAA+D,QAAQ,EAClF;CAGF,OAAO;EAAE,cAAc,KAAK,MAAM,GAAG,GAAG;EAAG,MAAM,KAAK,MAAM,MAAM,CAAC;CAAE;AACvE;AAEA,SAAS,UAAU,GAAoB;CACrC,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AAClD"}
@@ -1,7 +1,6 @@
1
1
  import { TemplateApplyProblem } from "./template_apply.js";
2
2
  import { BlockPackId, BlockPackSpec } from "@milaboratories/pl-model-middle-layer";
3
3
  import { BlockKindSelectorReference, BlockPackLocationReference, ProjectTemplateV1 } from "@milaboratories/pl-model-common";
4
- //#region src/model/template_resolve.d.ts
5
4
  /**
6
5
  * Where a template entry's block comes from.
7
6
  *
@@ -188,5 +187,4 @@ export declare function parseBlockPackName(npmName: string): {
188
187
  organization: string;
189
188
  name: string;
190
189
  };
191
- //#endregion
192
190
  //# sourceMappingURL=template_resolve.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"template_resolve.d.ts","names":[],"sources":["../../src/model/template_resolve.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;YAkCY;;;;;;;;EAQV,SACE,MAAM,4BACN;IAAW;QACR,QAAQ;;;;;;;;EASb,iBAAiB,IAAI,gBAAgB,QAAQ;;;;;;;;;;;;;;EAe7C,aAAa,UAAU,+BAA+B,QAAQ;;;;;;;;;;;;;;;;YAiBpD;WACG;WAAmB,MAAM;WAAwB;;WAEjD;WACA;;;YAOH;WACG;WAAmB,MAAM;WAAwB;;WACjD;WAAoB;;;;;;;;;;;;;;;YAevB;WAEG;WACA,MAAM;WACN;;WAGA;WACA;;;YAIH;;WAED;WACA,MAAM;;;;;;;;;;;;;;;;WAgBN;;;;;;;;WAQA;;;;;;;;;;YAWC;WACD,mBAAmB;WACnB,mBAAmB;;;;;;;;;;;;;;;;;;wBAmBR,uBACpB,UAAU,mBACV,UAAU,mBACV;EAAW;IACV,QAAQ;;;;;;;;;;;;;;;wBAyIK,mBAAmB;EAAoB;EAAsB"}
1
+ {"version":3,"file":"template_resolve.d.ts","names":[],"sources":["../../src/model/template_resolve.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;YAkCY;;;;;;;;EAQV,SACE,MAAM,4BACN;IAAW;QACR,QAAQ;;;;;;;;EASb,iBAAiB,IAAI,gBAAgB,QAAQ;;;;;;;;;;;;;;EAe7C,aAAa,UAAU,+BAA+B,QAAQ;;;;;;;;;;;;;;;;YAiBpD;WACG;WAAmB,MAAM;WAAwB;;WAEjD;WACA;;;YAOH;WACG;WAAmB,MAAM;WAAwB;;WACjD;WAAoB;;;;;;;;;;;;;;;YAevB;WAEG;WACA,MAAM;WACN;;WAGA;WACA;;;YAIH;;WAED;WACA,MAAM;;;;;;;;;;;;;;;;WAgBN;;;;;;;;WAQA;;;;;;;;;;YAWC;WACD,mBAAmB;WACnB,mBAAmB;;;;;;;;;;;;;;;;;;wBAmBR,uBACpB,UAAU,mBACV,UAAU,mBACV;EAAW;IACV,QAAQ;;;;;;;;;;;;;;;wBAyIK,mBAAmB;EAAoB;EAAsB"}
@@ -1,5 +1,5 @@
1
1
  import { parseBlockPackReference, parseKindSelectorReference } from "@milaboratories/pl-model-common";
2
- //#region src/model/template_resolve.ts
2
+ // src/model/template_resolve.ts
3
3
  /**
4
4
  * Resolve every entry in a template document to a concrete block pack.
5
5
  *
@@ -127,7 +127,6 @@ function parseBlockPackName(npmName) {
127
127
  function messageOf(e) {
128
128
  return e instanceof Error ? e.message : String(e);
129
129
  }
130
- //#endregion
131
130
  export { parseBlockPackName, resolveTemplateEntries };
132
131
 
133
132
  //# sourceMappingURL=template_resolve.js.map
@@ -4,7 +4,7 @@ let yaml = require("yaml");
4
4
  yaml = require_runtime.__toESM(yaml, 1);
5
5
  let node_url = require("node:url");
6
6
  let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
7
- //#region src/model/template_serializer.ts
7
+ // src/model/template_serializer.ts
8
8
  /**
9
9
  * The `location` to write for a block installed from the filesystem, or `undefined`
10
10
  * for one that came from a registry and therefore needs no locator.
@@ -155,7 +155,6 @@ function exportProjectAsTemplateV1(structure, paramsProvider, kindProvider, spec
155
155
  document
156
156
  };
157
157
  }
158
- //#endregion
159
158
  exports.assembleProjectTemplateV1 = assembleProjectTemplateV1;
160
159
  exports.exportProjectAsTemplateV1 = exportProjectAsTemplateV1;
161
160
  exports.locationOf = locationOf;
@@ -1 +1 @@
1
- {"version":3,"file":"template_serializer.cjs","names":["PROJECT_TEMPLATE_SCHEMA_V1","YAML","walkProjectForTemplateExport"],"sources":["../../src/model/template_serializer.ts"],"sourcesContent":["import YAML from \"yaml\";\nimport { pathToFileURL } from \"node:url\";\nimport type {\n BlockKindReference,\n BlockKindSelectorReference,\n BlockPackLocationReference,\n ProjectTemplateV1,\n ProjectTemplateV1Entry,\n} from \"@milaboratories/pl-model-common\";\nimport {\n PROJECT_TEMPLATE_SCHEMA_V1,\n kindReferenceToSelectorReference,\n parseProjectTemplateV1,\n} from \"@milaboratories/pl-model-common\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport type { ProjectStructure } from \"./project_model\";\nimport type {\n TemplateExportProblem,\n TemplateExportWalk,\n TemplateParamsResult,\n} from \"./template_export\";\nimport { walkProjectForTemplateExport } from \"./template_export\";\n\n/** A block's exact kind reference, or `undefined` for a block that declares no kind. */\nexport type BlockKindProvider = (blockId: string) => BlockKindReference | undefined;\n\n/**\n * A block's origin spec — where the installed block came from — or `undefined` when\n * it is not known for that block.\n *\n * The project stores this next to the kind reference, so both are read from the same\n * place and neither costs an extra round-trip.\n */\nexport type BlockPackSpecProvider = (blockId: string) => BlockPackSpec | undefined;\n\n/** What the caller gets back for a whole project. */\nexport type ProjectTemplateExportOutcome =\n | {\n readonly ok: true;\n readonly yaml: string;\n /** The document the YAML was rendered from, already validated. */\n readonly document: ProjectTemplateV1;\n }\n | {\n readonly ok: false;\n /** Every block that stands in the way, not just the first. */\n readonly problems: readonly TemplateExportProblem[];\n };\n\n/**\n * The `location` to write for a block installed from the filesystem, or `undefined`\n * for one that came from a registry and therefore needs no locator.\n *\n * Both filesystem spec shapes are emitted, and they anchor at different directories\n * — a dev block at its facade package, an npm-consumed one at its block-pack folder.\n * The document does not distinguish them: one URI is written either way, and telling\n * the two layouts apart is done by looking at what is actually there, by the side\n * that has the filesystem anyway. Encoding the layout in the file instead would\n * freeze today's two shapes into the format.\n *\n * A dev spec carries an OS path and is converted here, which also percent-encodes a\n * path containing spaces. An npm-consumed spec already carries a `file:` URL and is\n * passed through: it is the locator the block itself emitted, and reconstructing one\n * from it could only lose information.\n */\nexport function locationOf(spec: BlockPackSpec): BlockPackLocationReference | undefined {\n switch (spec.type) {\n case \"dev-v2\":\n return pathToFileURL(spec.folder).href as BlockPackLocationReference;\n case \"from-pack-v2\":\n return spec.packUrl as BlockPackLocationReference;\n // A registry block is found by name, which is what makes the entry portable —\n // writing where this machine happened to cache it would take that away. `dev-v1`\n // predates kinds entirely, so such a block has no kind and never reaches here.\n case \"dev-v1\":\n case \"from-registry-v1\":\n case \"from-registry-v2\":\n return undefined;\n }\n}\n\n/**\n * Turn a project into a template document.\n *\n * Assembly is deliberately dull — the entry is the block's id, its widened kind\n * reference, and the params the walk already collected. The interesting decisions\n * were made upstream; what is left here is the two things only this layer can\n * check, both of which produce problems rather than a broken file:\n *\n * - **A block with no kind cannot be written.** An entry's `kind` is required — it\n * is the params contract the entry is typed against — while a block's kind is\n * optional, so a block that predates kinds, or that uses the deprecated\n * kind-less model overload, has no legal entry. Reported per block. This is not\n * an edge case today: it is what most existing projects will hit until their\n * blocks are republished.\n * - **References must point at an entry declared earlier.** Verbatim id reuse\n * means a reference to a deleted block survives into the file naming nothing:\n * deleting a block only removes it from the structure and does not rewrite\n * downstream args, so a live project holds such references routinely.\n *\n * `block` is never emitted. That override exists to pin an implementation against\n * a kind's version range, and export always writes the exact version the block\n * implements, so there is nothing left for it to pin.\n *\n * `location` IS emitted, for every block that was installed from the filesystem. Such\n * a block is not in any registry, so the kind reference alone names nothing the\n * importer could find, and a file that omitted the one usable answer would describe a\n * project that cannot be recreated. It costs portability, and nothing says so: such a\n * file is the debugging path, read by the developer who wrote it on the machine that\n * wrote it.\n *\n * Problems from `walk` are carried through, so a caller can hand a walk straight\n * in and get one combined list.\n */\nexport function assembleProjectTemplateV1(\n walk: TemplateExportWalk,\n kindProvider: BlockKindProvider,\n specProvider: BlockPackSpecProvider,\n): { document: ProjectTemplateV1; problems: readonly TemplateExportProblem[] } {\n const problems: TemplateExportProblem[] = [...walk.problems];\n const blocks: ProjectTemplateV1Entry[] = [];\n\n for (const entry of walk.entries) {\n const kind = kindProvider(entry.blockId);\n\n if (kind === undefined) {\n problems.push({\n blockId: entry.blockId,\n blockLabel: entry.blockLabel,\n error:\n \"Block declares no kind, so it cannot be written to a template: an entry's kind \" +\n \"carries the params contract the entry is typed against\",\n });\n continue;\n }\n\n let selector: BlockKindSelectorReference;\n try {\n // Widening validates, and therefore throws — which is why it happens here\n // and not where the reference is read: every read site sits inside a\n // recomputed project overview, where one malformed stored reference must not\n // be able to break unrelated blocks.\n selector = kindReferenceToSelectorReference(kind);\n } catch (e) {\n problems.push({\n blockId: entry.blockId,\n blockLabel: entry.blockLabel,\n error: `Block's stored kind reference is malformed: ${e instanceof Error ? e.message : String(e)}`,\n });\n continue;\n }\n\n const spec = specProvider(entry.blockId);\n const location = spec === undefined ? undefined : locationOf(spec);\n\n blocks.push({\n id: entry.blockId,\n kind: selector,\n params: entry.params,\n ...(location !== undefined ? { location } : {}),\n });\n }\n\n // References are not examined. A project's structure is topological by construction, so an\n // entry cannot legally reference one below it — and checking would mean reading the params,\n // which only the block that wrote them can do.\n const document: ProjectTemplateV1 = { schema: PROJECT_TEMPLATE_SCHEMA_V1, blocks };\n\n return { document, problems };\n}\n\n/**\n * Render a template document to YAML text.\n *\n * Two non-default emitter settings, both about the file being read by someone\n * else's code:\n *\n * - **No line folding.** A wrapped scalar still parses, but it makes a diff between\n * two exported templates unreadable, which is most of the reason to prefer YAML\n * over JSON here.\n * - **Quote as if the reader were YAML 1.1**, while still parsing as 1.2. YAML 1.2\n * dropped `yes`/`no`/`on`/`off`/`y`/`n` as booleans and dropped sexagesimal\n * integers, so a 1.2 emitter leaves a params value of `\"yes\"` or `\"1:30\"` bare —\n * which a 1.1 reader (PyYAML's default, and Go's yaml.v2) turns into `true` and\n * `90`. A template is a contract for a second implementation, so the safe\n * combination is to quote against the stricter ruleset and read with the looser\n * one: a quoted scalar means the same thing under both. This adds no `%YAML`\n * directive — it only changes which scalars get quotes.\n */\nexport function stringifyProjectTemplateV1(document: ProjectTemplateV1): string {\n return YAML.stringify(document, { lineWidth: 0, version: \"1.1\" });\n}\n\n/**\n * Export a project as `template-v1` YAML, or report every reason it cannot be.\n *\n * All-or-nothing on purpose. A partial template silently drops blocks and the\n * surviving entries may reference the dropped ones, so what looks like a\n * successful export would produce a project missing pieces the user never chose\n * to leave out. Reporting everything at once instead of failing on the first\n * problem is the other half of that: fixing an export should take one pass.\n *\n * @param structure The project structure, which supplies both membership and order\n * @param paramsProvider A block's derived template params, in live form\n * @param kindProvider A block's exact kind reference, read from its stored config\n * @param specProvider A block's origin spec, read from the same stored container\n */\nexport function exportProjectAsTemplateV1(\n structure: ProjectStructure,\n paramsProvider: (blockId: string) => TemplateParamsResult | undefined,\n kindProvider: BlockKindProvider,\n specProvider: BlockPackSpecProvider,\n): ProjectTemplateExportOutcome {\n const walk = walkProjectForTemplateExport(structure, paramsProvider);\n const { document, problems } = assembleProjectTemplateV1(walk, kindProvider, specProvider);\n\n if (problems.length > 0) return { ok: false, problems };\n\n // Export must emit exactly what import parses, so that is asserted on every\n // export rather than only in tests — running the import-side parser over the\n // document we are about to write is the cheapest possible proof of it. Nothing\n // user-facing is expected to fail here: the kind grammar was checked by the\n // widening above, params were checked to be a mapping by the walk, and the\n // reference rules by the assembler. A throw means a bug in the assembler, with\n // one known exception: a project structure holding two blocks with the same id,\n // which is reachable through the mutator and produces duplicate entry ids.\n parseProjectTemplateV1(document);\n\n return {\n ok: true,\n yaml: stringifyProjectTemplateV1(document),\n document,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,WAAW,MAA6D;CACtF,QAAQ,KAAK,MAAb;EACE,KAAK,UACH,QAAA,GAAA,SAAA,cAAA,CAAqB,KAAK,MAAM,CAAC,CAAC;EACpC,KAAK,gBACH,OAAO,KAAK;EAId,KAAK;EACL,KAAK;EACL,KAAK,oBACH;CACJ;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,0BACd,MACA,cACA,cAC6E;CAC7E,MAAM,WAAoC,CAAC,GA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version":3,"file":"template_serializer.cjs","names":["pathToFileURL","kindReferenceToSelectorReference","PROJECT_TEMPLATE_SCHEMA_V1","YAML","walkProjectForTemplateExport"],"sources":["../../src/model/template_serializer.ts"],"sourcesContent":["import YAML from \"yaml\";\nimport { pathToFileURL } from \"node:url\";\nimport type {\n BlockKindReference,\n BlockKindSelectorReference,\n BlockPackLocationReference,\n ProjectTemplateV1,\n ProjectTemplateV1Entry,\n} from \"@milaboratories/pl-model-common\";\nimport {\n PROJECT_TEMPLATE_SCHEMA_V1,\n kindReferenceToSelectorReference,\n parseProjectTemplateV1,\n} from \"@milaboratories/pl-model-common\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport type { ProjectStructure } from \"./project_model\";\nimport type {\n TemplateExportProblem,\n TemplateExportWalk,\n TemplateParamsResult,\n} from \"./template_export\";\nimport { walkProjectForTemplateExport } from \"./template_export\";\n\n/** A block's exact kind reference, or `undefined` for a block that declares no kind. */\nexport type BlockKindProvider = (blockId: string) => BlockKindReference | undefined;\n\n/**\n * A block's origin spec — where the installed block came from — or `undefined` when\n * it is not known for that block.\n *\n * The project stores this next to the kind reference, so both are read from the same\n * place and neither costs an extra round-trip.\n */\nexport type BlockPackSpecProvider = (blockId: string) => BlockPackSpec | undefined;\n\n/** What the caller gets back for a whole project. */\nexport type ProjectTemplateExportOutcome =\n | {\n readonly ok: true;\n readonly yaml: string;\n /** The document the YAML was rendered from, already validated. */\n readonly document: ProjectTemplateV1;\n }\n | {\n readonly ok: false;\n /** Every block that stands in the way, not just the first. */\n readonly problems: readonly TemplateExportProblem[];\n };\n\n/**\n * The `location` to write for a block installed from the filesystem, or `undefined`\n * for one that came from a registry and therefore needs no locator.\n *\n * Both filesystem spec shapes are emitted, and they anchor at different directories\n * — a dev block at its facade package, an npm-consumed one at its block-pack folder.\n * The document does not distinguish them: one URI is written either way, and telling\n * the two layouts apart is done by looking at what is actually there, by the side\n * that has the filesystem anyway. Encoding the layout in the file instead would\n * freeze today's two shapes into the format.\n *\n * A dev spec carries an OS path and is converted here, which also percent-encodes a\n * path containing spaces. An npm-consumed spec already carries a `file:` URL and is\n * passed through: it is the locator the block itself emitted, and reconstructing one\n * from it could only lose information.\n */\nexport function locationOf(spec: BlockPackSpec): BlockPackLocationReference | undefined {\n switch (spec.type) {\n case \"dev-v2\":\n return pathToFileURL(spec.folder).href as BlockPackLocationReference;\n case \"from-pack-v2\":\n return spec.packUrl as BlockPackLocationReference;\n // A registry block is found by name, which is what makes the entry portable —\n // writing where this machine happened to cache it would take that away. `dev-v1`\n // predates kinds entirely, so such a block has no kind and never reaches here.\n case \"dev-v1\":\n case \"from-registry-v1\":\n case \"from-registry-v2\":\n return undefined;\n }\n}\n\n/**\n * Turn a project into a template document.\n *\n * Assembly is deliberately dull — the entry is the block's id, its widened kind\n * reference, and the params the walk already collected. The interesting decisions\n * were made upstream; what is left here is the two things only this layer can\n * check, both of which produce problems rather than a broken file:\n *\n * - **A block with no kind cannot be written.** An entry's `kind` is required — it\n * is the params contract the entry is typed against — while a block's kind is\n * optional, so a block that predates kinds, or that uses the deprecated\n * kind-less model overload, has no legal entry. Reported per block. This is not\n * an edge case today: it is what most existing projects will hit until their\n * blocks are republished.\n * - **References must point at an entry declared earlier.** Verbatim id reuse\n * means a reference to a deleted block survives into the file naming nothing:\n * deleting a block only removes it from the structure and does not rewrite\n * downstream args, so a live project holds such references routinely.\n *\n * `block` is never emitted. That override exists to pin an implementation against\n * a kind's version range, and export always writes the exact version the block\n * implements, so there is nothing left for it to pin.\n *\n * `location` IS emitted, for every block that was installed from the filesystem. Such\n * a block is not in any registry, so the kind reference alone names nothing the\n * importer could find, and a file that omitted the one usable answer would describe a\n * project that cannot be recreated. It costs portability, and nothing says so: such a\n * file is the debugging path, read by the developer who wrote it on the machine that\n * wrote it.\n *\n * Problems from `walk` are carried through, so a caller can hand a walk straight\n * in and get one combined list.\n */\nexport function assembleProjectTemplateV1(\n walk: TemplateExportWalk,\n kindProvider: BlockKindProvider,\n specProvider: BlockPackSpecProvider,\n): { document: ProjectTemplateV1; problems: readonly TemplateExportProblem[] } {\n const problems: TemplateExportProblem[] = [...walk.problems];\n const blocks: ProjectTemplateV1Entry[] = [];\n\n for (const entry of walk.entries) {\n const kind = kindProvider(entry.blockId);\n\n if (kind === undefined) {\n problems.push({\n blockId: entry.blockId,\n blockLabel: entry.blockLabel,\n error:\n \"Block declares no kind, so it cannot be written to a template: an entry's kind \" +\n \"carries the params contract the entry is typed against\",\n });\n continue;\n }\n\n let selector: BlockKindSelectorReference;\n try {\n // Widening validates, and therefore throws — which is why it happens here\n // and not where the reference is read: every read site sits inside a\n // recomputed project overview, where one malformed stored reference must not\n // be able to break unrelated blocks.\n selector = kindReferenceToSelectorReference(kind);\n } catch (e) {\n problems.push({\n blockId: entry.blockId,\n blockLabel: entry.blockLabel,\n error: `Block's stored kind reference is malformed: ${e instanceof Error ? e.message : String(e)}`,\n });\n continue;\n }\n\n const spec = specProvider(entry.blockId);\n const location = spec === undefined ? undefined : locationOf(spec);\n\n blocks.push({\n id: entry.blockId,\n kind: selector,\n params: entry.params,\n ...(location !== undefined ? { location } : {}),\n });\n }\n\n // References are not examined. A project's structure is topological by construction, so an\n // entry cannot legally reference one below it — and checking would mean reading the params,\n // which only the block that wrote them can do.\n const document: ProjectTemplateV1 = { schema: PROJECT_TEMPLATE_SCHEMA_V1, blocks };\n\n return { document, problems };\n}\n\n/**\n * Render a template document to YAML text.\n *\n * Two non-default emitter settings, both about the file being read by someone\n * else's code:\n *\n * - **No line folding.** A wrapped scalar still parses, but it makes a diff between\n * two exported templates unreadable, which is most of the reason to prefer YAML\n * over JSON here.\n * - **Quote as if the reader were YAML 1.1**, while still parsing as 1.2. YAML 1.2\n * dropped `yes`/`no`/`on`/`off`/`y`/`n` as booleans and dropped sexagesimal\n * integers, so a 1.2 emitter leaves a params value of `\"yes\"` or `\"1:30\"` bare —\n * which a 1.1 reader (PyYAML's default, and Go's yaml.v2) turns into `true` and\n * `90`. A template is a contract for a second implementation, so the safe\n * combination is to quote against the stricter ruleset and read with the looser\n * one: a quoted scalar means the same thing under both. This adds no `%YAML`\n * directive — it only changes which scalars get quotes.\n */\nexport function stringifyProjectTemplateV1(document: ProjectTemplateV1): string {\n return YAML.stringify(document, { lineWidth: 0, version: \"1.1\" });\n}\n\n/**\n * Export a project as `template-v1` YAML, or report every reason it cannot be.\n *\n * All-or-nothing on purpose. A partial template silently drops blocks and the\n * surviving entries may reference the dropped ones, so what looks like a\n * successful export would produce a project missing pieces the user never chose\n * to leave out. Reporting everything at once instead of failing on the first\n * problem is the other half of that: fixing an export should take one pass.\n *\n * @param structure The project structure, which supplies both membership and order\n * @param paramsProvider A block's derived template params, in live form\n * @param kindProvider A block's exact kind reference, read from its stored config\n * @param specProvider A block's origin spec, read from the same stored container\n */\nexport function exportProjectAsTemplateV1(\n structure: ProjectStructure,\n paramsProvider: (blockId: string) => TemplateParamsResult | undefined,\n kindProvider: BlockKindProvider,\n specProvider: BlockPackSpecProvider,\n): ProjectTemplateExportOutcome {\n const walk = walkProjectForTemplateExport(structure, paramsProvider);\n const { document, problems } = assembleProjectTemplateV1(walk, kindProvider, specProvider);\n\n if (problems.length > 0) return { ok: false, problems };\n\n // Export must emit exactly what import parses, so that is asserted on every\n // export rather than only in tests — running the import-side parser over the\n // document we are about to write is the cheapest possible proof of it. Nothing\n // user-facing is expected to fail here: the kind grammar was checked by the\n // widening above, params were checked to be a mapping by the walk, and the\n // reference rules by the assembler. A throw means a bug in the assembler, with\n // one known exception: a project structure holding two blocks with the same id,\n // which is reachable through the mutator and produces duplicate entry ids.\n parseProjectTemplateV1(document);\n\n return {\n ok: true,\n yaml: stringifyProjectTemplateV1(document),\n document,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,WAAW,MAA6D;CACtF,QAAQ,KAAK,MAAb;EACE,KAAK,UACH,QAAA,GAAOA,SAAAA,cAAAA,CAAc,KAAK,MAAM,CAAC,CAAC;EACpC,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zF,IAAI,SAAS,SAAS,GAAG,OAAO;EAAE,IAAI;EAAO;CAAS;CAUtD,CAAA,GAAA,gCAAA,uBAAA,CAAuB,QAAQ;CAE/B,OAAO;EACL,IAAI;EACJ,MAAM,2BAA2B,QAAQ;EACzC;CACF;AACF"}
@@ -2,7 +2,6 @@ import "./project_model.js";
2
2
  import { TemplateExportProblem } from "./template_export.js";
3
3
  import { BlockPackSpec } from "@milaboratories/pl-model-middle-layer";
4
4
  import { BlockKindReference, BlockPackLocationReference, ProjectTemplateV1 } from "@milaboratories/pl-model-common";
5
- //#region src/model/template_serializer.d.ts
6
5
  /** What the caller gets back for a whole project. */
7
6
  export type ProjectTemplateExportOutcome = {
8
7
  readonly ok: true;
@@ -50,5 +49,4 @@ export declare function locationOf(spec: BlockPackSpec): BlockPackLocationRefere
50
49
  * directive — it only changes which scalars get quotes.
51
50
  */
52
51
  export declare function stringifyProjectTemplateV1(document: ProjectTemplateV1): string;
53
- //#endregion
54
52
  //# sourceMappingURL=template_serializer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"template_serializer.d.ts","names":[],"sources":["../../src/model/template_serializer.ts"],"mappings":";;;;;;YAoCY;WAEG;WACA;;WAEA,UAAU;;WAGV;;WAEA,mBAAmB;;;;;;;;;;;;;;;;;;wBAmBlB,WAAW,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;wBA4HjC,2BAA2B,UAAU"}
1
+ {"version":3,"file":"template_serializer.d.ts","names":[],"sources":["../../src/model/template_serializer.ts"],"mappings":";;;;;YAoCY;WAEG;WACA;;WAEA,UAAU;;WAGV;;WAEA,mBAAmB;;;;;;;;;;;;;;;;;;wBAmBlB,WAAW,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;wBA4HjC,2BAA2B,UAAU"}
@@ -2,7 +2,7 @@ import { walkProjectForTemplateExport } from "./template_export.js";
2
2
  import YAML from "yaml";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import { PROJECT_TEMPLATE_SCHEMA_V1, kindReferenceToSelectorReference, parseProjectTemplateV1 } from "@milaboratories/pl-model-common";
5
- //#region src/model/template_serializer.ts
5
+ // src/model/template_serializer.ts
6
6
  /**
7
7
  * The `location` to write for a block installed from the filesystem, or `undefined`
8
8
  * for one that came from a registry and therefore needs no locator.
@@ -153,7 +153,6 @@ function exportProjectAsTemplateV1(structure, paramsProvider, kindProvider, spec
153
153
  document
154
154
  };
155
155
  }
156
- //#endregion
157
156
  export { assembleProjectTemplateV1, exportProjectAsTemplateV1, locationOf, stringifyProjectTemplateV1 };
158
157
 
159
158
  //# sourceMappingURL=template_serializer.js.map
@@ -1,6 +1,5 @@
1
1
  import { SignedResourceId } from "@milaboratories/pl-client";
2
2
  import { CompiledTemplateV3, TemplateData } from "@milaboratories/pl-model-backend";
3
- //#region src/model/template_spec.d.ts
4
3
  export interface TemplateFromRegistry {
5
4
  readonly type: "from-registry";
6
5
  registry: string;
@@ -24,5 +23,4 @@ export interface TemplateFromFile {
24
23
  }
25
24
  export type TemplateSpecPrepared = TemplateFromRegistry | ExplicitTemplate | PreparedTemplate | CachedTemplate;
26
25
  export type TemplateSpecAny = TemplateSpecPrepared | TemplateFromFile;
27
- //#endregion
28
26
  //# sourceMappingURL=template_spec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"template_spec.d.ts","names":[],"sources":["../../src/model/template_spec.ts"],"mappings":";;;iBAGiB;WACN;EACT;EACA;;iBAGe;WACN;EACT,SAAS;;iBAGM;WACN;EACT,MAAM,eAAe;;iBAGN;WACN;WACA,YAAY;;iBAGN;WACN;EACT;;YAGU,uBACR,uBACA,mBACA,mBACA;YACQ,kBAAkB,uBAAuB"}
1
+ {"version":3,"file":"template_spec.d.ts","names":[],"sources":["../../src/model/template_spec.ts"],"mappings":";;iBAGiB;WACN;EACT;EACA;;iBAGe;WACN;EACT,SAAS;;iBAGM;WACN;EACT,MAAM,eAAe;;iBAGN;WACN;WACA,YAAY;;iBAGN;WACN;EACT;;YAGU,uBACR,uBACA,mBACA,mBACA;YACQ,kBAAkB,uBAAuB"}
@@ -6,7 +6,7 @@ require("../../block_registry/index.cjs");
6
6
  const require_template_loading = require("../template/template_loading.cjs");
7
7
  const require_frontend = require("./frontend.cjs");
8
8
  const require_WorkerManager = require("../../worker/WorkerManager.cjs");
9
- const require_usingCtx = require("../../_virtual/_@oxc-project_runtime@0.137.0/helpers/esm/usingCtx.cjs");
9
+ const require_usingCtx = require("../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/usingCtx.cjs");
10
10
  let _platforma_sdk_model = require("@platforma-sdk/model");
11
11
  let undici = require("undici");
12
12
  let _platforma_sdk_block_tools = require("@platforma-sdk/block-tools");
@@ -19,7 +19,7 @@ let lru_cache = require("lru-cache");
19
19
  let canonicalize = require("canonicalize");
20
20
  canonicalize = require_runtime.__toESM(canonicalize, 1);
21
21
  let zod = require("zod");
22
- //#region src/mutator/block-pack/block_pack.ts
22
+ // src/mutator/block-pack/block_pack.ts
23
23
  const BlockPackCustomType = {
24
24
  name: "BlockPackCustom",
25
25
  version: "1"
@@ -51,9 +51,10 @@ var BlockPackPreparer = class {
51
51
  }
52
52
  remoteContentCache = new lru_cache.LRUCache({
53
53
  max: 500,
54
- maxSize: 128 * 1024 * 1024,
54
+ maxSize: 134217728,
55
55
  fetchMethod: async (key) => {
56
- return await (await (0, undici.request)(key, this.http !== void 0 ? { dispatcher: this.http } : {})).body.arrayBuffer();
56
+ const httpOptions = this.http !== void 0 ? { dispatcher: this.http } : {};
57
+ return await (await (0, undici.request)(key, httpOptions)).body.arrayBuffer();
57
58
  },
58
59
  sizeCalculation: (value) => value.byteLength
59
60
  });
@@ -73,7 +74,8 @@ var BlockPackPreparer = class {
73
74
  return parseStringConfig(await node_fs.default.promises.readFile(description.components.model.file, { encoding: "utf-8" }));
74
75
  }
75
76
  case "from-pack-v2": {
76
- const description = await (0, _platforma_sdk_block_tools.loadPackDescriptionFromManifest)((0, node_url.fileURLToPath)(spec.packUrl));
77
+ const packDir = (0, node_url.fileURLToPath)(spec.packUrl);
78
+ const description = await (0, _platforma_sdk_block_tools.loadPackDescriptionFromManifest)(packDir);
77
79
  return parseStringConfig(await node_fs.default.promises.readFile(description.components.model.file, { encoding: "utf-8" }));
78
80
  }
79
81
  case "from-registry-v1": {
@@ -266,7 +268,6 @@ function createBlockPack(tx, spec) {
266
268
  default: return (0, _milaboratories_ts_helpers.assertNever)(spec.type);
267
269
  }
268
270
  }
269
- //#endregion
270
271
  exports.BlockPackCustomType = BlockPackCustomType;
271
272
  exports.BlockPackFrontendField = BlockPackFrontendField;
272
273
  exports.BlockPackPreparer = BlockPackPreparer;
@@ -1 +1 @@
1
- {"version":3,"file":"block_pack.cjs","names":["z","Code","LRUCache","resolveDevPacket","fs","RegistryV1","WorkerManager","requiredCapabilitiesFromTemplate","getDevV2PacketMtime","getFromPackV2Mtime","loadTemplate","createFrontend"],"sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport type { Branded } from \"@milaboratories/pl-model-common\";\nimport fs from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport { requiredCapabilitiesFromTemplate } from \"./required_capabilities\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport {\n loadPackDescription,\n loadPackDescriptionFromManifest,\n RegistryV1,\n} from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime, getFromPackV2Mtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport canonicalize from \"canonicalize\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\ntype PreparedCacheKey = Branded<string, \"PreparedCacheKey\">;\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n /** Cache of prepared block packs for registry specs (immutable by version). */\n private readonly preparedCache = new LRUCache<PreparedCacheKey, BlockPackSpecPrepared>({\n max: 50,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n /** Returns a stable cache key for registry specs (immutable by version). Dev specs return undefined. */\n private specKey(spec: BlockPackSpecAny): PreparedCacheKey | undefined {\n switch (spec.type) {\n case \"from-registry-v1\":\n return `v1:${spec.registryUrl}:${spec.id.organization}:${spec.id.name}:${spec.id.version}` as PreparedCacheKey;\n case \"from-registry-v2\":\n return `v2:${spec.registryUrl}:${canonicalize(spec.id)}` as PreparedCacheKey;\n default:\n return undefined; // dev, explicit, prepared — not cacheable\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n // Check prepare cache for registry specs\n const key = this.specKey(spec);\n if (key) {\n const cached = this.preparedCache.get(key);\n if (cached) return cached;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n const parsed = await workerManager.process(\"parseTemplate\", explicit.template.content);\n\n const result: BlockPackSpecPrepared = {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: parsed,\n },\n requiredCapabilities: requiredCapabilitiesFromTemplate(parsed),\n };\n\n if (key) {\n this.preparedCache.set(key, result);\n }\n\n return result;\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n // UI ships as ui.tgz inside block-pack/; its absolute path is carried\n // in the ui folder slot. The tarball is unpacked lazily at serve-time by\n // the download driver (local-tgz frontend), not eagerly here — so it\n // inherits the driver's usage-tracking and space recycling.\n const uiTgzPath = description.components.ui.folder;\n const source = { ...spec };\n let mtime = spec.mtime;\n if (mtime === undefined) {\n // No explicit mtime: derive one so the frontend cache key invalidates\n // when the block changes.\n mtime = await getFromPackV2Mtime(packDir, uiTgzPath);\n source.mtime = mtime;\n }\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local-tgz\",\n path: uiTgzPath,\n mtime,\n signature: this.signer.sign(`${uiTgzPath}:${mtime}`),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n const workflowContent = Buffer.from(workflow);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,sBAAoC;CAAE,MAAM;CAAmB,SAAS;AAAI;AACzF,MAAa,yBAAyB;AACtC,MAAa,yBAAyB;;AAGtC,SAAS,OAAO,KAAqB;CACnC,IAAI,IAAI,SAAS,GAAG,GAAG,OAAO;MACzB,OAAO,GAAG,IAAI;AACrB;AAEA,SAAS,kBAAkB,eAA6C;CACtE,MAAM,MAAMA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,GAAGA,IAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,KAAK,MAAM,aAAa,CAAC;CAEjF,IAAI,CAAC,IAAI,SACP,MAAM,IAAI,MAAM,wBAAwB;CAG1C,IAAI,CAACC,qBAAAA,KAAK,UAAU,IAAI,KAAK,IAAI,CAAC,CAAC,SACjC,MAAM,IAAI,MAAM,kCAAkC;CAGpD,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;EACE,KAAK,YACH,OAAO,sBAAsB,IAAI,IAAI;EACvC,SACE,QAAA,GAAA,2BAAA,YAAA,CAAmB,KAAK,IAAI;CAChC;AACF"}
1
+ {"version":3,"file":"block_pack.cjs","names":["z","Code","LRUCache","request","resolveDevPacket","fs","loadPackDescription","fileURLToPath","loadPackDescriptionFromManifest","RegistryV1","assertNever","WorkerManager","requiredCapabilitiesFromTemplate","getDevV2PacketMtime","getFromPackV2Mtime","field","loadTemplate","createFrontend"],"sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport type { Branded } from \"@milaboratories/pl-model-common\";\nimport fs from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport { requiredCapabilitiesFromTemplate } from \"./required_capabilities\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport {\n loadPackDescription,\n loadPackDescriptionFromManifest,\n RegistryV1,\n} from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime, getFromPackV2Mtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport canonicalize from \"canonicalize\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\ntype PreparedCacheKey = Branded<string, \"PreparedCacheKey\">;\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n /** Cache of prepared block packs for registry specs (immutable by version). */\n private readonly preparedCache = new LRUCache<PreparedCacheKey, BlockPackSpecPrepared>({\n max: 50,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n /** Returns a stable cache key for registry specs (immutable by version). Dev specs return undefined. */\n private specKey(spec: BlockPackSpecAny): PreparedCacheKey | undefined {\n switch (spec.type) {\n case \"from-registry-v1\":\n return `v1:${spec.registryUrl}:${spec.id.organization}:${spec.id.name}:${spec.id.version}` as PreparedCacheKey;\n case \"from-registry-v2\":\n return `v2:${spec.registryUrl}:${canonicalize(spec.id)}` as PreparedCacheKey;\n default:\n return undefined; // dev, explicit, prepared — not cacheable\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n // Check prepare cache for registry specs\n const key = this.specKey(spec);\n if (key) {\n const cached = this.preparedCache.get(key);\n if (cached) return cached;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n const parsed = await workerManager.process(\"parseTemplate\", explicit.template.content);\n\n const result: BlockPackSpecPrepared = {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: parsed,\n },\n requiredCapabilities: requiredCapabilitiesFromTemplate(parsed),\n };\n\n if (key) {\n this.preparedCache.set(key, result);\n }\n\n return result;\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-pack-v2\": {\n // packUrl is a file: URL (the facade emits URLs, not paths); convert at\n // this Node boundary before touching the filesystem.\n const packDir = fileURLToPath(spec.packUrl);\n const description = await loadPackDescriptionFromManifest(packDir);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n // UI ships as ui.tgz inside block-pack/; its absolute path is carried\n // in the ui folder slot. The tarball is unpacked lazily at serve-time by\n // the download driver (local-tgz frontend), not eagerly here — so it\n // inherits the driver's usage-tracking and space recycling.\n const uiTgzPath = description.components.ui.folder;\n const source = { ...spec };\n let mtime = spec.mtime;\n if (mtime === undefined) {\n // No explicit mtime: derive one so the frontend cache key invalidates\n // when the block changes.\n mtime = await getFromPackV2Mtime(packDir, uiTgzPath);\n source.mtime = mtime;\n }\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local-tgz\",\n path: uiTgzPath,\n mtime,\n signature: this.signer.sign(`${uiTgzPath}:${mtime}`),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n const workflowContent = Buffer.from(workflow);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,sBAAoC;CAAE,MAAM;CAAmB,SAAS;AAAI;AACzF,MAAa,yBAAyB;AACtC,MAAa,yBAAyB;;AAGtC,SAAS,OAAO,KAAqB;CACnC,IAAI,IAAI,SAAS,GAAG,GAAG,OAAO;MACzB,OAAO,GAAG,IAAI;AACrB;AAEA,SAAS,kBAAkB,eAA6C;CACtE,MAAM,MAAMA,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,GAAGA,IAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,KAAK,MAAM,aAAa,CAAC;CAEjF,IAAI,CAAC,IAAI,SACP,MAAM,IAAI,MAAM,wBAAwB;CAG1C,IAAI,CAACC,qBAAAA,KAAK,UAAU,IAAI,KAAK,IAAI,CAAC,CAAC,SACjC,MAAM,IAAI,MAAM,kCAAkC;CAGpD,OAAO,IAAI;AACb;AAEA,SAAS,kBAAkB,QAA2C;CACpE,OAAO,kBAAkB,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC;AAC/D;AAEA,IAAa,oBAAb,MAA+B;CAEV;CACA;CACA;CAHnB,YACE,oBACA,QACA,MACA;EAHiB,KAAA,qBAAA;EACA,KAAA,SAAA;EACA,KAAA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from "undici";
6
6
  import { Signer } from "@milaboratories/ts-helpers";
7
7
  import { AnyResourceRef, PlTransaction, ResourceType } from "@milaboratories/pl-client";
8
- //#region src/mutator/block-pack/block_pack.d.ts
9
8
  export declare class BlockPackPreparer {
10
9
  private readonly v2RegistryProvider;
11
10
  private readonly signer;
@@ -20,5 +19,4 @@ export declare class BlockPackPreparer {
20
19
  prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared>;
21
20
  private prepareWithoutUnpacking;
22
21
  }
23
- //#endregion
24
22
  //# sourceMappingURL=block_pack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"block_pack.d.ts","names":[],"sources":["../../../src/mutator/block-pack/block_pack.ts"],"mappings":";;;;;;;;qBA4Da;mBAEQ;mBACA;mBACA;EAHnB,YACmB,oBAAoB,oBACpB,QAAQ,QACR,OAAO;mBAGT;;mBAWA;EAIJ,wBAAwB,MAAM,mBAAmB,QAAQ;;UAqD9D;EAWK,QAAQ,MAAM,mBAAmB,QAAQ;UAmCxC"}
1
+ {"version":3,"file":"block_pack.d.ts","names":[],"sources":["../../../src/mutator/block-pack/block_pack.ts"],"mappings":";;;;;;;qBA4Da;mBAEQ;mBACA;mBACA;EAHnB,YACmB,oBAAoB,oBACpB,QAAQ,QACR,OAAO;mBAGT;;mBAWA;EAIJ,wBAAwB,MAAM,mBAAmB,QAAQ;;UAqD9D;EAWK,QAAQ,MAAM,mBAAmB,QAAQ;UAmCxC"}
@@ -5,7 +5,7 @@ import "../../block_registry/index.js";
5
5
  import { loadTemplate } from "../template/template_loading.js";
6
6
  import { createFrontend } from "./frontend.js";
7
7
  import { WorkerManager } from "../../worker/WorkerManager.js";
8
- import _usingCtx from "../../_virtual/_@oxc-project_runtime@0.137.0/helpers/esm/usingCtx.js";
8
+ import _usingCtx from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/usingCtx.js";
9
9
  import { Code } from "@platforma-sdk/model";
10
10
  import { request } from "undici";
11
11
  import { RegistryV1, loadPackDescription, loadPackDescriptionFromManifest } from "@platforma-sdk/block-tools";
@@ -16,7 +16,7 @@ import { field } from "@milaboratories/pl-client";
16
16
  import { LRUCache } from "lru-cache";
17
17
  import canonicalize from "canonicalize";
18
18
  import { z } from "zod";
19
- //#region src/mutator/block-pack/block_pack.ts
19
+ // src/mutator/block-pack/block_pack.ts
20
20
  const BlockPackCustomType = {
21
21
  name: "BlockPackCustom",
22
22
  version: "1"
@@ -48,9 +48,10 @@ var BlockPackPreparer = class {
48
48
  }
49
49
  remoteContentCache = new LRUCache({
50
50
  max: 500,
51
- maxSize: 128 * 1024 * 1024,
51
+ maxSize: 134217728,
52
52
  fetchMethod: async (key) => {
53
- return await (await request(key, this.http !== void 0 ? { dispatcher: this.http } : {})).body.arrayBuffer();
53
+ const httpOptions = this.http !== void 0 ? { dispatcher: this.http } : {};
54
+ return await (await request(key, httpOptions)).body.arrayBuffer();
54
55
  },
55
56
  sizeCalculation: (value) => value.byteLength
56
57
  });
@@ -70,7 +71,8 @@ var BlockPackPreparer = class {
70
71
  return parseStringConfig(await fs.promises.readFile(description.components.model.file, { encoding: "utf-8" }));
71
72
  }
72
73
  case "from-pack-v2": {
73
- const description = await loadPackDescriptionFromManifest(fileURLToPath(spec.packUrl));
74
+ const packDir = fileURLToPath(spec.packUrl);
75
+ const description = await loadPackDescriptionFromManifest(packDir);
74
76
  return parseStringConfig(await fs.promises.readFile(description.components.model.file, { encoding: "utf-8" }));
75
77
  }
76
78
  case "from-registry-v1": {
@@ -263,7 +265,6 @@ function createBlockPack(tx, spec) {
263
265
  default: return assertNever(spec.type);
264
266
  }
265
267
  }
266
- //#endregion
267
268
  export { BlockPackCustomType, BlockPackFrontendField, BlockPackPreparer, BlockPackTemplateField, createBlockPack };
268
269
 
269
270
  //# sourceMappingURL=block_pack.js.map