@milaboratories/pl-middle-layer 1.46.20 → 1.46.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (402) hide show
  1. package/dist/block_registry/index.d.ts +3 -3
  2. package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
  3. package/dist/block_registry/registry-v2-provider.d.ts +2 -2
  4. package/dist/block_registry/registry-v2-provider.js.map +1 -1
  5. package/dist/block_registry/registry.cjs +54 -53
  6. package/dist/block_registry/registry.cjs.map +1 -1
  7. package/dist/block_registry/registry.d.ts +4 -4
  8. package/dist/block_registry/registry.d.ts.map +1 -1
  9. package/dist/block_registry/registry.js +54 -53
  10. package/dist/block_registry/registry.js.map +1 -1
  11. package/dist/block_registry/watcher.cjs +12 -12
  12. package/dist/block_registry/watcher.cjs.map +1 -1
  13. package/dist/block_registry/watcher.d.ts +6 -6
  14. package/dist/block_registry/watcher.d.ts.map +1 -1
  15. package/dist/block_registry/watcher.js +12 -12
  16. package/dist/block_registry/watcher.js.map +1 -1
  17. package/dist/block_registry/well_known_registries.cjs +6 -6
  18. package/dist/block_registry/well_known_registries.cjs.map +1 -1
  19. package/dist/block_registry/well_known_registries.d.ts +1 -1
  20. package/dist/block_registry/well_known_registries.js +6 -6
  21. package/dist/block_registry/well_known_registries.js.map +1 -1
  22. package/dist/cfg_render/executor.cjs +11 -11
  23. package/dist/cfg_render/executor.cjs.map +1 -1
  24. package/dist/cfg_render/executor.d.ts +5 -5
  25. package/dist/cfg_render/executor.js +11 -11
  26. package/dist/cfg_render/executor.js.map +1 -1
  27. package/dist/cfg_render/operation.d.ts +5 -5
  28. package/dist/cfg_render/renderer.cjs +74 -75
  29. package/dist/cfg_render/renderer.cjs.map +1 -1
  30. package/dist/cfg_render/renderer.d.ts +2 -2
  31. package/dist/cfg_render/renderer.d.ts.map +1 -1
  32. package/dist/cfg_render/renderer.js +74 -75
  33. package/dist/cfg_render/renderer.js.map +1 -1
  34. package/dist/cfg_render/traverse.cjs +27 -27
  35. package/dist/cfg_render/traverse.cjs.map +1 -1
  36. package/dist/cfg_render/traverse.d.ts +1 -1
  37. package/dist/cfg_render/traverse.js +27 -27
  38. package/dist/cfg_render/traverse.js.map +1 -1
  39. package/dist/cfg_render/util.cjs +1 -1
  40. package/dist/cfg_render/util.cjs.map +1 -1
  41. package/dist/cfg_render/util.d.ts +1 -1
  42. package/dist/cfg_render/util.js +1 -1
  43. package/dist/cfg_render/util.js.map +1 -1
  44. package/dist/debug/index.cjs +4 -2
  45. package/dist/debug/index.cjs.map +1 -1
  46. package/dist/debug/index.d.ts +2 -2
  47. package/dist/debug/index.d.ts.map +1 -1
  48. package/dist/debug/index.js +4 -2
  49. package/dist/debug/index.js.map +1 -1
  50. package/dist/dev_env/index.cjs +8 -8
  51. package/dist/dev_env/index.cjs.map +1 -1
  52. package/dist/dev_env/index.js +8 -8
  53. package/dist/dev_env/index.js.map +1 -1
  54. package/dist/dev_env/util.cjs +1 -1
  55. package/dist/dev_env/util.cjs.map +1 -1
  56. package/dist/dev_env/util.d.ts +1 -1
  57. package/dist/dev_env/util.js +1 -1
  58. package/dist/dev_env/util.js.map +1 -1
  59. package/dist/index.d.ts +16 -16
  60. package/dist/js_render/computable_context.cjs +78 -78
  61. package/dist/js_render/computable_context.cjs.map +1 -1
  62. package/dist/js_render/computable_context.d.ts +9 -9
  63. package/dist/js_render/computable_context.d.ts.map +1 -1
  64. package/dist/js_render/computable_context.js +78 -78
  65. package/dist/js_render/computable_context.js.map +1 -1
  66. package/dist/js_render/context.cjs +33 -27
  67. package/dist/js_render/context.cjs.map +1 -1
  68. package/dist/js_render/context.d.ts +7 -7
  69. package/dist/js_render/context.d.ts.map +1 -1
  70. package/dist/js_render/context.js +33 -27
  71. package/dist/js_render/context.js.map +1 -1
  72. package/dist/js_render/index.cjs +10 -6
  73. package/dist/js_render/index.cjs.map +1 -1
  74. package/dist/js_render/index.d.ts +6 -6
  75. package/dist/js_render/index.d.ts.map +1 -1
  76. package/dist/js_render/index.js +10 -6
  77. package/dist/js_render/index.js.map +1 -1
  78. package/dist/middle_layer/active_cfg.cjs.map +1 -1
  79. package/dist/middle_layer/active_cfg.d.ts +3 -3
  80. package/dist/middle_layer/active_cfg.d.ts.map +1 -1
  81. package/dist/middle_layer/active_cfg.js.map +1 -1
  82. package/dist/middle_layer/block.cjs +1 -1
  83. package/dist/middle_layer/block.cjs.map +1 -1
  84. package/dist/middle_layer/block.d.ts +6 -6
  85. package/dist/middle_layer/block.d.ts.map +1 -1
  86. package/dist/middle_layer/block.js +1 -1
  87. package/dist/middle_layer/block.js.map +1 -1
  88. package/dist/middle_layer/block_ctx.cjs +9 -9
  89. package/dist/middle_layer/block_ctx.cjs.map +1 -1
  90. package/dist/middle_layer/block_ctx.d.ts +6 -6
  91. package/dist/middle_layer/block_ctx.d.ts.map +1 -1
  92. package/dist/middle_layer/block_ctx.js +9 -9
  93. package/dist/middle_layer/block_ctx.js.map +1 -1
  94. package/dist/middle_layer/block_ctx_unsafe.cjs +1 -1
  95. package/dist/middle_layer/block_ctx_unsafe.cjs.map +1 -1
  96. package/dist/middle_layer/block_ctx_unsafe.d.ts +5 -5
  97. package/dist/middle_layer/block_ctx_unsafe.js +1 -1
  98. package/dist/middle_layer/block_ctx_unsafe.js.map +1 -1
  99. package/dist/middle_layer/driver_kit.cjs +1 -2
  100. package/dist/middle_layer/driver_kit.cjs.map +1 -1
  101. package/dist/middle_layer/driver_kit.d.ts +7 -7
  102. package/dist/middle_layer/driver_kit.d.ts.map +1 -1
  103. package/dist/middle_layer/driver_kit.js +1 -2
  104. package/dist/middle_layer/driver_kit.js.map +1 -1
  105. package/dist/middle_layer/frontend_path.cjs +5 -5
  106. package/dist/middle_layer/frontend_path.cjs.map +1 -1
  107. package/dist/middle_layer/frontend_path.d.ts +4 -4
  108. package/dist/middle_layer/frontend_path.d.ts.map +1 -1
  109. package/dist/middle_layer/frontend_path.js +5 -5
  110. package/dist/middle_layer/frontend_path.js.map +1 -1
  111. package/dist/middle_layer/index.d.ts +4 -4
  112. package/dist/middle_layer/middle_layer.cjs +11 -11
  113. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  114. package/dist/middle_layer/middle_layer.d.ts +18 -18
  115. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  116. package/dist/middle_layer/middle_layer.js +11 -11
  117. package/dist/middle_layer/middle_layer.js.map +1 -1
  118. package/dist/middle_layer/navigation_states.cjs +2 -2
  119. package/dist/middle_layer/navigation_states.cjs.map +1 -1
  120. package/dist/middle_layer/navigation_states.d.ts +2 -2
  121. package/dist/middle_layer/navigation_states.js +2 -2
  122. package/dist/middle_layer/navigation_states.js.map +1 -1
  123. package/dist/middle_layer/ops.cjs +5 -5
  124. package/dist/middle_layer/ops.cjs.map +1 -1
  125. package/dist/middle_layer/ops.d.ts +11 -11
  126. package/dist/middle_layer/ops.d.ts.map +1 -1
  127. package/dist/middle_layer/ops.js +5 -5
  128. package/dist/middle_layer/ops.js.map +1 -1
  129. package/dist/middle_layer/project.cjs +71 -63
  130. package/dist/middle_layer/project.cjs.map +1 -1
  131. package/dist/middle_layer/project.d.ts +10 -10
  132. package/dist/middle_layer/project.d.ts.map +1 -1
  133. package/dist/middle_layer/project.js +71 -63
  134. package/dist/middle_layer/project.js.map +1 -1
  135. package/dist/middle_layer/project_list.cjs +2 -2
  136. package/dist/middle_layer/project_list.cjs.map +1 -1
  137. package/dist/middle_layer/project_list.d.ts +6 -6
  138. package/dist/middle_layer/project_list.d.ts.map +1 -1
  139. package/dist/middle_layer/project_list.js +2 -2
  140. package/dist/middle_layer/project_list.js.map +1 -1
  141. package/dist/middle_layer/project_overview.cjs +40 -40
  142. package/dist/middle_layer/project_overview.cjs.map +1 -1
  143. package/dist/middle_layer/project_overview.d.ts +5 -5
  144. package/dist/middle_layer/project_overview.d.ts.map +1 -1
  145. package/dist/middle_layer/project_overview.js +40 -40
  146. package/dist/middle_layer/project_overview.js.map +1 -1
  147. package/dist/middle_layer/project_overview_light.cjs.map +1 -1
  148. package/dist/middle_layer/project_overview_light.d.ts +2 -2
  149. package/dist/middle_layer/project_overview_light.d.ts.map +1 -1
  150. package/dist/middle_layer/project_overview_light.js.map +1 -1
  151. package/dist/middle_layer/render.cjs +1 -1
  152. package/dist/middle_layer/render.cjs.map +1 -1
  153. package/dist/middle_layer/render.d.ts +4 -4
  154. package/dist/middle_layer/render.js +1 -1
  155. package/dist/middle_layer/render.js.map +1 -1
  156. package/dist/middle_layer/render.test.d.ts +2 -2
  157. package/dist/middle_layer/types.d.ts +3 -3
  158. package/dist/middle_layer/util.cjs +9 -4
  159. package/dist/middle_layer/util.cjs.map +1 -1
  160. package/dist/middle_layer/util.d.ts +4 -4
  161. package/dist/middle_layer/util.d.ts.map +1 -1
  162. package/dist/middle_layer/util.js +9 -4
  163. package/dist/middle_layer/util.js.map +1 -1
  164. package/dist/model/args.cjs +19 -15
  165. package/dist/model/args.cjs.map +1 -1
  166. package/dist/model/args.d.ts +1 -1
  167. package/dist/model/args.d.ts.map +1 -1
  168. package/dist/model/args.js +19 -15
  169. package/dist/model/args.js.map +1 -1
  170. package/dist/model/block_pack.d.ts +2 -2
  171. package/dist/model/block_pack_spec.cjs +3 -3
  172. package/dist/model/block_pack_spec.cjs.map +1 -1
  173. package/dist/model/block_pack_spec.d.ts +8 -8
  174. package/dist/model/block_pack_spec.js +3 -3
  175. package/dist/model/block_pack_spec.js.map +1 -1
  176. package/dist/model/block_storage_helper.cjs +4 -4
  177. package/dist/model/block_storage_helper.cjs.map +1 -1
  178. package/dist/model/block_storage_helper.d.ts +2 -2
  179. package/dist/model/block_storage_helper.d.ts.map +1 -1
  180. package/dist/model/block_storage_helper.js +4 -4
  181. package/dist/model/block_storage_helper.js.map +1 -1
  182. package/dist/model/index.d.ts +3 -3
  183. package/dist/model/project_helper.cjs +30 -13
  184. package/dist/model/project_helper.cjs.map +1 -1
  185. package/dist/model/project_helper.d.ts +4 -4
  186. package/dist/model/project_helper.d.ts.map +1 -1
  187. package/dist/model/project_helper.js +30 -13
  188. package/dist/model/project_helper.js.map +1 -1
  189. package/dist/model/project_model.cjs +23 -23
  190. package/dist/model/project_model.cjs.map +1 -1
  191. package/dist/model/project_model.d.ts +6 -6
  192. package/dist/model/project_model.d.ts.map +1 -1
  193. package/dist/model/project_model.js +23 -23
  194. package/dist/model/project_model.js.map +1 -1
  195. package/dist/model/project_model_util.cjs +2 -2
  196. package/dist/model/project_model_util.cjs.map +1 -1
  197. package/dist/model/project_model_util.d.ts +3 -3
  198. package/dist/model/project_model_util.d.ts.map +1 -1
  199. package/dist/model/project_model_util.js +2 -2
  200. package/dist/model/project_model_util.js.map +1 -1
  201. package/dist/model/project_model_v1.cjs +2 -2
  202. package/dist/model/project_model_v1.cjs.map +1 -1
  203. package/dist/model/project_model_v1.js +2 -2
  204. package/dist/model/project_model_v1.js.map +1 -1
  205. package/dist/model/template_spec.d.ts +5 -5
  206. package/dist/mutator/block-pack/block_pack.cjs +43 -43
  207. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  208. package/dist/mutator/block-pack/block_pack.d.ts +6 -6
  209. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  210. package/dist/mutator/block-pack/block_pack.js +43 -43
  211. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  212. package/dist/mutator/block-pack/frontend.cjs +2 -2
  213. package/dist/mutator/block-pack/frontend.cjs.map +1 -1
  214. package/dist/mutator/block-pack/frontend.d.ts +2 -2
  215. package/dist/mutator/block-pack/frontend.d.ts.map +1 -1
  216. package/dist/mutator/block-pack/frontend.js +2 -2
  217. package/dist/mutator/block-pack/frontend.js.map +1 -1
  218. package/dist/mutator/context_export.cjs +5 -5
  219. package/dist/mutator/context_export.cjs.map +1 -1
  220. package/dist/mutator/context_export.d.ts +2 -2
  221. package/dist/mutator/context_export.d.ts.map +1 -1
  222. package/dist/mutator/context_export.js +5 -5
  223. package/dist/mutator/context_export.js.map +1 -1
  224. package/dist/mutator/migration.cjs +7 -7
  225. package/dist/mutator/migration.cjs.map +1 -1
  226. package/dist/mutator/migration.d.ts +1 -1
  227. package/dist/mutator/migration.d.ts.map +1 -1
  228. package/dist/mutator/migration.js +7 -7
  229. package/dist/mutator/migration.js.map +1 -1
  230. package/dist/mutator/project.cjs +147 -148
  231. package/dist/mutator/project.cjs.map +1 -1
  232. package/dist/mutator/project.d.ts +13 -13
  233. package/dist/mutator/project.d.ts.map +1 -1
  234. package/dist/mutator/project.js +147 -148
  235. package/dist/mutator/project.js.map +1 -1
  236. package/dist/mutator/template/direct_template_loader.cjs +16 -16
  237. package/dist/mutator/template/direct_template_loader.cjs.map +1 -1
  238. package/dist/mutator/template/direct_template_loader.d.ts +2 -2
  239. package/dist/mutator/template/direct_template_loader.d.ts.map +1 -1
  240. package/dist/mutator/template/direct_template_loader.js +16 -16
  241. package/dist/mutator/template/direct_template_loader.js.map +1 -1
  242. package/dist/mutator/template/direct_template_loader_v3.cjs +13 -13
  243. package/dist/mutator/template/direct_template_loader_v3.cjs.map +1 -1
  244. package/dist/mutator/template/direct_template_loader_v3.d.ts +3 -3
  245. package/dist/mutator/template/direct_template_loader_v3.d.ts.map +1 -1
  246. package/dist/mutator/template/direct_template_loader_v3.js +13 -13
  247. package/dist/mutator/template/direct_template_loader_v3.js.map +1 -1
  248. package/dist/mutator/template/render_block.cjs +7 -7
  249. package/dist/mutator/template/render_block.cjs.map +1 -1
  250. package/dist/mutator/template/render_block.d.ts +1 -1
  251. package/dist/mutator/template/render_block.d.ts.map +1 -1
  252. package/dist/mutator/template/render_block.js +7 -7
  253. package/dist/mutator/template/render_block.js.map +1 -1
  254. package/dist/mutator/template/render_template.cjs +10 -10
  255. package/dist/mutator/template/render_template.cjs.map +1 -1
  256. package/dist/mutator/template/render_template.d.ts +2 -2
  257. package/dist/mutator/template/render_template.js +10 -10
  258. package/dist/mutator/template/render_template.js.map +1 -1
  259. package/dist/mutator/template/template_loading.cjs +17 -17
  260. package/dist/mutator/template/template_loading.cjs.map +1 -1
  261. package/dist/mutator/template/template_loading.d.ts +2 -2
  262. package/dist/mutator/template/template_loading.js +17 -17
  263. package/dist/mutator/template/template_loading.js.map +1 -1
  264. package/dist/network_check/network_check.cjs +33 -32
  265. package/dist/network_check/network_check.cjs.map +1 -1
  266. package/dist/network_check/network_check.d.ts +6 -6
  267. package/dist/network_check/network_check.d.ts.map +1 -1
  268. package/dist/network_check/network_check.js +33 -32
  269. package/dist/network_check/network_check.js.map +1 -1
  270. package/dist/network_check/pings.cjs +3 -3
  271. package/dist/network_check/pings.cjs.map +1 -1
  272. package/dist/network_check/pings.d.ts +4 -4
  273. package/dist/network_check/pings.d.ts.map +1 -1
  274. package/dist/network_check/pings.js +3 -3
  275. package/dist/network_check/pings.js.map +1 -1
  276. package/dist/network_check/template.cjs +57 -44
  277. package/dist/network_check/template.cjs.map +1 -1
  278. package/dist/network_check/template.d.ts +8 -8
  279. package/dist/network_check/template.d.ts.map +1 -1
  280. package/dist/network_check/template.js +57 -44
  281. package/dist/network_check/template.js.map +1 -1
  282. package/dist/pool/data.cjs +45 -33
  283. package/dist/pool/data.cjs.map +1 -1
  284. package/dist/pool/data.d.ts +3 -3
  285. package/dist/pool/data.d.ts.map +1 -1
  286. package/dist/pool/data.js +45 -33
  287. package/dist/pool/data.js.map +1 -1
  288. package/dist/pool/driver.cjs +18 -16
  289. package/dist/pool/driver.cjs.map +1 -1
  290. package/dist/pool/driver.d.ts +5 -5
  291. package/dist/pool/driver.d.ts.map +1 -1
  292. package/dist/pool/driver.js +18 -16
  293. package/dist/pool/driver.js.map +1 -1
  294. package/dist/pool/index.d.ts +2 -2
  295. package/dist/pool/p_object_collection.cjs +5 -5
  296. package/dist/pool/p_object_collection.cjs.map +1 -1
  297. package/dist/pool/p_object_collection.d.ts +2 -2
  298. package/dist/pool/p_object_collection.d.ts.map +1 -1
  299. package/dist/pool/p_object_collection.js +5 -5
  300. package/dist/pool/p_object_collection.js.map +1 -1
  301. package/dist/pool/result_pool.cjs +6 -6
  302. package/dist/pool/result_pool.cjs.map +1 -1
  303. package/dist/pool/result_pool.d.ts +6 -6
  304. package/dist/pool/result_pool.d.ts.map +1 -1
  305. package/dist/pool/result_pool.js +6 -6
  306. package/dist/pool/result_pool.js.map +1 -1
  307. package/dist/test/block_packs.d.ts +2 -2
  308. package/dist/test/known_templates.d.ts +1 -1
  309. package/dist/worker/WorkerManager.cjs +7 -8
  310. package/dist/worker/WorkerManager.cjs.map +1 -1
  311. package/dist/worker/WorkerManager.d.ts +2 -2
  312. package/dist/worker/WorkerManager.d.ts.map +1 -1
  313. package/dist/worker/WorkerManager.js +7 -8
  314. package/dist/worker/WorkerManager.js.map +1 -1
  315. package/dist/worker/worker.cjs +6 -4
  316. package/dist/worker/worker.cjs.map +1 -1
  317. package/dist/worker/worker.js +6 -4
  318. package/dist/worker/worker.js.map +1 -1
  319. package/dist/worker/workerApi.cjs.map +1 -1
  320. package/dist/worker/workerApi.js.map +1 -1
  321. package/package.json +41 -41
  322. package/src/block_registry/index.ts +3 -3
  323. package/src/block_registry/registry-v2-provider.ts +2 -2
  324. package/src/block_registry/registry.test.ts +17 -17
  325. package/src/block_registry/registry.ts +55 -60
  326. package/src/block_registry/watcher.ts +24 -23
  327. package/src/block_registry/well_known_registries.ts +7 -7
  328. package/src/cfg_render/executor.test.ts +36 -36
  329. package/src/cfg_render/executor.ts +24 -24
  330. package/src/cfg_render/operation.ts +5 -5
  331. package/src/cfg_render/renderer.ts +96 -93
  332. package/src/cfg_render/traverse.ts +50 -50
  333. package/src/cfg_render/util.ts +3 -3
  334. package/src/debug/index.ts +6 -4
  335. package/src/dev_env/index.ts +16 -16
  336. package/src/dev_env/util.ts +3 -3
  337. package/src/index.ts +16 -16
  338. package/src/js_render/computable_context.ts +143 -126
  339. package/src/js_render/context.ts +72 -44
  340. package/src/js_render/index.ts +51 -24
  341. package/src/middle_layer/active_cfg.ts +14 -12
  342. package/src/middle_layer/block.ts +30 -23
  343. package/src/middle_layer/block_ctx.ts +27 -31
  344. package/src/middle_layer/block_ctx_unsafe.ts +9 -9
  345. package/src/middle_layer/driver_kit.ts +13 -19
  346. package/src/middle_layer/frontend_path.ts +18 -23
  347. package/src/middle_layer/index.ts +4 -4
  348. package/src/middle_layer/middle_layer.ts +57 -55
  349. package/src/middle_layer/navigation_states.ts +6 -6
  350. package/src/middle_layer/ops.ts +43 -42
  351. package/src/middle_layer/project.ts +274 -173
  352. package/src/middle_layer/project_list.ts +14 -15
  353. package/src/middle_layer/project_overview.ts +104 -113
  354. package/src/middle_layer/project_overview_light.ts +7 -9
  355. package/src/middle_layer/render.test.ts +49 -48
  356. package/src/middle_layer/render.ts +9 -9
  357. package/src/middle_layer/types.ts +3 -3
  358. package/src/middle_layer/util.ts +17 -12
  359. package/src/model/args.ts +22 -19
  360. package/src/model/block_pack.ts +2 -2
  361. package/src/model/block_pack_spec.ts +11 -11
  362. package/src/model/block_storage_helper.ts +11 -11
  363. package/src/model/index.ts +3 -3
  364. package/src/model/project_helper.ts +78 -32
  365. package/src/model/project_model.test.ts +5 -9
  366. package/src/model/project_model.ts +48 -49
  367. package/src/model/project_model_util.test.ts +86 -53
  368. package/src/model/project_model_util.ts +18 -14
  369. package/src/model/project_model_v1.ts +3 -3
  370. package/src/model/template_spec.ts +5 -5
  371. package/src/mutator/block-pack/block_pack.test.ts +25 -25
  372. package/src/mutator/block-pack/block_pack.ts +70 -68
  373. package/src/mutator/block-pack/frontend.ts +6 -13
  374. package/src/mutator/context_export.ts +12 -10
  375. package/src/mutator/migration.ts +20 -14
  376. package/src/mutator/project-v3.test.ts +123 -118
  377. package/src/mutator/project.test.ts +105 -94
  378. package/src/mutator/project.ts +357 -274
  379. package/src/mutator/template/direct_template_loader.ts +26 -32
  380. package/src/mutator/template/direct_template_loader_v3.ts +51 -25
  381. package/src/mutator/template/render_block.ts +14 -21
  382. package/src/mutator/template/render_template.ts +13 -13
  383. package/src/mutator/template/template_loading.ts +23 -23
  384. package/src/mutator/template/template_render.test.ts +87 -86
  385. package/src/network_check/network_check.test.ts +4 -4
  386. package/src/network_check/network_check.ts +102 -79
  387. package/src/network_check/pings.ts +35 -16
  388. package/src/network_check/template.test.ts +47 -44
  389. package/src/network_check/template.ts +151 -95
  390. package/src/network_check/test_utils.ts +1 -1
  391. package/src/pool/data.ts +81 -69
  392. package/src/pool/driver.ts +56 -51
  393. package/src/pool/index.ts +2 -2
  394. package/src/pool/p_object_collection.ts +16 -15
  395. package/src/pool/result_pool.ts +23 -34
  396. package/src/test/block_packs.ts +15 -15
  397. package/src/test/explicit_templates.ts +4 -4
  398. package/src/test/known_templates.ts +10 -10
  399. package/src/test_env.ts +1 -1
  400. package/src/worker/WorkerManager.ts +22 -18
  401. package/src/worker/worker.ts +11 -9
  402. package/src/worker/workerApi.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"block_pack.cjs","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { Code } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\nimport { z } from 'zod';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error('Invalid config content');\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error('parseStringConfig:No code bundle');\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString('utf8'));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent);\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return parseStringConfig(configContent);\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString('utf8'));\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n );\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(Buffer.from(configResponse).toString('utf8')) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":["z","Code","LRUCache","request","resolveDevPacket","loadPackDescription","RegistryV1","assertNever","__addDisposableResource","WorkerManager","getDevV2PacketMtime","field","loadTemplate","createFrontend"],"mappings":";;;;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAGA,KAAC,CAAC,MAAM,CAACA,KAAC,CAAC,MAAM,EAAE,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAElF,IAAA,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IAC3C;AAEA,IAAA,IAAI,CAACC,UAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;AAC1C,QAAA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;IACrD;IAEA,OAAO,GAAG,CAAC,IAA4B;AACzC;AAEA,SAAS,iBAAiB,CAAC,MAAmB,EAAA;AAC5C,IAAA,OAAO,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChE;MAEa,iBAAiB,CAAA;AAET,IAAA,kBAAA;AACA,IAAA,MAAA;AACA,IAAA,IAAA;AAHnB,IAAA,WAAA,CACm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IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAACD,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEE,uBAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAON,qBAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;;;;;"}
1
+ {"version":3,"file":"block_pack.cjs","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport fs from \"node:fs\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport { loadPackDescription, RegistryV1 } from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: await workerManager.process(\"parseTemplate\", explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":["z","Code","LRUCache","request","resolveDevPacket","loadPackDescription","RegistryV1","assertNever","__addDisposableResource","WorkerManager","getDevV2PacketMtime","field","loadTemplate","createFrontend"],"mappings":";;;;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAGA,KAAC,CAAC,MAAM,CAACA,KAAC,CAAC,MAAM,EAAE,EAAEA,KAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;AAElF,IAAA,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IAC3C;AAEA,IAAA,IAAI,CAACC,UAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;AAC1C,QAAA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC;IACrD;IAEA,OAAO,GAAG,CAAC,IAA4B;AACzC;AAEA,SAAS,iBAAiB,CAAC,MAAmB,EAAA;AAC5C,IAAA,OAAO,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,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CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9E,EAAE,CAAC,WAAW,CAACI,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEC,6BAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAACD,cAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAEE,uBAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAON,qBAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;;;;;"}
@@ -1,9 +1,9 @@
1
- import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';
2
- import type { BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';
3
- import type { Signer } from '@milaboratories/ts-helpers';
4
- import type { Dispatcher } from 'undici';
5
- import type { BlockConfigContainer } from '@platforma-sdk/model';
6
- import type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';
1
+ import type { AnyResourceRef, PlTransaction, ResourceType } from "@milaboratories/pl-client";
2
+ import type { BlockPackSpecAny, BlockPackSpecPrepared } from "../../model";
3
+ import type { Signer } from "@milaboratories/ts-helpers";
4
+ import type { Dispatcher } from "undici";
5
+ import type { BlockConfigContainer } from "@platforma-sdk/model";
6
+ import type { V2RegistryProvider } from "../../block_registry/registry-v2-provider";
7
7
  export declare const BlockPackCustomType: ResourceType;
8
8
  export declare const BlockPackTemplateField = "template";
9
9
  export declare const BlockPackFrontendField = "frontend";
@@ -1 +1 @@
1
- {"version":3,"file":"block_pack.d.ts","sourceRoot":"","sources":["../../../src/mutator/block-pack/block_pack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG7F,OAAO,KAAK,EAAqB,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAMjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAMpF,eAAO,MAAM,mBAAmB,EAAE,YAAwD,CAAC;AAC3F,eAAO,MAAM,sBAAsB,aAAa,CAAC;AACjD,eAAO,MAAM,sBAAsB,aAAa,CAAC;AA0BjD,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAFL,kBAAkB,EAAE,kBAAkB,EACtC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,UAAU,YAAA;IAGpC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAQhC;IAEU,uBAAuB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAyC9E,OAAO,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAmB9D,uBAAuB;CA0HtC;AAYD,wBAAgB,eAAe,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,qBAAqB,GAAG,cAAc,CAO9F"}
1
+ {"version":3,"file":"block_pack.d.ts","sourceRoot":"","sources":["../../../src/mutator/block-pack/block_pack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG7F,OAAO,KAAK,EAAqB,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAMjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAMpF,eAAO,MAAM,mBAAmB,EAAE,YAAwD,CAAC;AAC3F,eAAO,MAAM,sBAAsB,aAAa,CAAC;AACjD,eAAO,MAAM,sBAAsB,aAAa,CAAC;AA0BjD,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAFL,kBAAkB,EAAE,kBAAkB,EACtC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,UAAU,YAAA;IAGpC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAQhC;IAEU,uBAAuB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAyC9E,OAAO,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAmB9D,uBAAuB;CA4HtC;AAYD,wBAAgB,eAAe,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,qBAAqB,GAAG,cAAc,CAO9F"}
@@ -13,12 +13,12 @@ import { LRUCache } from 'lru-cache';
13
13
  import { WorkerManager } from '../../worker/WorkerManager.js';
14
14
  import { z } from 'zod';
15
15
 
16
- const BlockPackCustomType = { name: 'BlockPackCustom', version: '1' };
17
- const BlockPackTemplateField = 'template';
18
- const BlockPackFrontendField = 'frontend';
16
+ const BlockPackCustomType = { name: "BlockPackCustom", version: "1" };
17
+ const BlockPackTemplateField = "template";
18
+ const BlockPackFrontendField = "frontend";
19
19
  /** Ensure trailing slash */
20
20
  function tSlash(str) {
21
- if (str.endsWith('/'))
21
+ if (str.endsWith("/"))
22
22
  return str;
23
23
  else
24
24
  return `${str}/`;
@@ -26,15 +26,15 @@ function tSlash(str) {
26
26
  function parseStringConfig(configContent) {
27
27
  const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));
28
28
  if (!res.success) {
29
- throw new Error('Invalid config content');
29
+ throw new Error("Invalid config content");
30
30
  }
31
31
  if (!Code.safeParse(res.data.code).success) {
32
- throw new Error('parseStringConfig:No code bundle');
32
+ throw new Error("parseStringConfig:No code bundle");
33
33
  }
34
34
  return res.data;
35
35
  }
36
36
  function parseBufferConfig(buffer) {
37
- return parseStringConfig(Buffer.from(buffer).toString('utf8'));
37
+ return parseStringConfig(Buffer.from(buffer).toString("utf8"));
38
38
  }
39
39
  class BlockPackPreparer {
40
40
  v2RegistryProvider;
@@ -56,28 +56,28 @@ class BlockPackPreparer {
56
56
  });
57
57
  async getBlockConfigContainer(spec) {
58
58
  switch (spec.type) {
59
- case 'explicit':
59
+ case "explicit":
60
60
  return spec.config;
61
- case 'prepared':
61
+ case "prepared":
62
62
  return spec.config;
63
- case 'dev-v1': {
63
+ case "dev-v1": {
64
64
  const devPaths = await resolveDevPacket(spec.folder);
65
- const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });
65
+ const configContent = await fs.promises.readFile(devPaths.config, { encoding: "utf-8" });
66
66
  return JSON.parse(configContent);
67
67
  }
68
- case 'dev-v2': {
68
+ case "dev-v2": {
69
69
  const description = await loadPackDescription(spec.folder);
70
70
  const configContent = await fs.promises.readFile(description.components.model.file, {
71
- encoding: 'utf-8',
71
+ encoding: "utf-8",
72
72
  });
73
73
  return parseStringConfig(configContent);
74
74
  }
75
- case 'from-registry-v1': {
75
+ case "from-registry-v1": {
76
76
  const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;
77
77
  const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
78
- return JSON.parse(Buffer.from(configResponse).toString('utf8'));
78
+ return JSON.parse(Buffer.from(configResponse).toString("utf8"));
79
79
  }
80
- case 'from-registry-v2': {
80
+ case "from-registry-v2": {
81
81
  const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
82
82
  const components = await registry.getComponents(spec.id);
83
83
  const configResponse = await this.remoteContentCache.forceFetch(components.model.url);
@@ -90,17 +90,17 @@ class BlockPackPreparer {
90
90
  async prepare(spec) {
91
91
  const env_1 = { stack: [], error: void 0, hasError: false };
92
92
  try {
93
- if (spec.type === 'prepared') {
93
+ if (spec.type === "prepared") {
94
94
  return spec;
95
95
  }
96
96
  const explicit = await this.prepareWithoutUnpacking(spec);
97
97
  const workerManager = __addDisposableResource(env_1, new WorkerManager(), true);
98
98
  return {
99
99
  ...explicit,
100
- type: 'prepared',
100
+ type: "prepared",
101
101
  template: {
102
- type: 'prepared',
103
- data: await workerManager.process('parseTemplate', explicit.template.content),
102
+ type: "prepared",
103
+ data: await workerManager.process("parseTemplate", explicit.template.content),
104
104
  },
105
105
  };
106
106
  }
@@ -116,35 +116,35 @@ class BlockPackPreparer {
116
116
  }
117
117
  async prepareWithoutUnpacking(spec) {
118
118
  switch (spec.type) {
119
- case 'explicit':
119
+ case "explicit":
120
120
  return spec;
121
- case 'dev-v1': {
121
+ case "dev-v1": {
122
122
  const devPaths = await resolveDevPacket(spec.folder);
123
123
  // template
124
124
  const templateContent = await fs.promises.readFile(devPaths.workflow);
125
125
  // config
126
- const config = JSON.parse(await fs.promises.readFile(devPaths.config, 'utf-8'));
126
+ const config = JSON.parse(await fs.promises.readFile(devPaths.config, "utf-8"));
127
127
  // frontend
128
128
  const frontendPath = devPaths.ui;
129
129
  return {
130
- type: 'explicit',
130
+ type: "explicit",
131
131
  template: {
132
- type: 'explicit',
132
+ type: "explicit",
133
133
  content: templateContent,
134
134
  },
135
135
  config,
136
136
  frontend: {
137
- type: 'local',
137
+ type: "local",
138
138
  path: frontendPath,
139
139
  signature: this.signer.sign(frontendPath),
140
140
  },
141
141
  source: spec,
142
142
  };
143
143
  }
144
- case 'dev-v2': {
144
+ case "dev-v2": {
145
145
  const description = await loadPackDescription(spec.folder);
146
146
  const config = parseStringConfig(await fs.promises.readFile(description.components.model.file, {
147
- encoding: 'utf-8',
147
+ encoding: "utf-8",
148
148
  }));
149
149
  const workflowContent = await fs.promises.readFile(description.components.workflow.main.file);
150
150
  const frontendPath = description.components.ui.folder;
@@ -153,21 +153,21 @@ class BlockPackPreparer {
153
153
  // if absent, calculating the mtime here, so the block will correctly show whether it can be updated
154
154
  source.mtime = await getDevV2PacketMtime(description);
155
155
  return {
156
- type: 'explicit',
156
+ type: "explicit",
157
157
  template: {
158
- type: 'explicit',
158
+ type: "explicit",
159
159
  content: workflowContent,
160
160
  },
161
161
  config,
162
162
  frontend: {
163
- type: 'local',
163
+ type: "local",
164
164
  path: frontendPath,
165
165
  signature: this.signer.sign(frontendPath),
166
166
  },
167
167
  source,
168
168
  };
169
169
  }
170
- case 'from-registry-v1': {
170
+ case "from-registry-v1": {
171
171
  const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;
172
172
  const templateUrl = `${urlPrefix}/template.plj.gz`;
173
173
  // template
@@ -175,36 +175,36 @@ class BlockPackPreparer {
175
175
  const templateContent = new Uint8Array(templateResponse);
176
176
  // config
177
177
  const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);
178
- const config = JSON.parse(Buffer.from(configResponse).toString('utf8'));
178
+ const config = JSON.parse(Buffer.from(configResponse).toString("utf8"));
179
179
  return {
180
- type: 'explicit',
180
+ type: "explicit",
181
181
  template: {
182
- type: 'explicit',
182
+ type: "explicit",
183
183
  content: templateContent,
184
184
  },
185
185
  config,
186
186
  frontend: {
187
- type: 'url',
187
+ type: "url",
188
188
  url: `${urlPrefix}/frontend.tgz`,
189
189
  },
190
190
  source: spec,
191
191
  };
192
192
  }
193
- case 'from-registry-v2': {
193
+ case "from-registry-v2": {
194
194
  const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);
195
195
  const components = await registry.getComponents(spec.id);
196
196
  const getModel = async () => parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));
197
197
  const getWorkflow = async () => await this.remoteContentCache.forceFetch(components.workflow.main.url);
198
198
  const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);
199
199
  return {
200
- type: 'explicit',
200
+ type: "explicit",
201
201
  template: {
202
- type: 'explicit',
202
+ type: "explicit",
203
203
  content: Buffer.from(workflow),
204
204
  },
205
205
  config: model,
206
206
  frontend: {
207
- type: 'url',
207
+ type: "url",
208
208
  url: components.ui.url,
209
209
  },
210
210
  source: spec,
@@ -218,14 +218,14 @@ class BlockPackPreparer {
218
218
  function createCustomBlockPack(tx, spec) {
219
219
  const blockPackInfo = { config: spec.config, source: spec.source };
220
220
  const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));
221
- tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));
222
- tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));
221
+ tx.createField(field(bp, BlockPackTemplateField), "Input", loadTemplate(tx, spec.template));
222
+ tx.createField(field(bp, BlockPackFrontendField), "Input", createFrontend(tx, spec.frontend));
223
223
  tx.lock(bp);
224
224
  return bp;
225
225
  }
226
226
  function createBlockPack(tx, spec) {
227
227
  switch (spec.type) {
228
- case 'prepared':
228
+ case "prepared":
229
229
  return createCustomBlockPack(tx, spec);
230
230
  default:
231
231
  return assertNever(spec.type);
@@ -1 +1 @@
1
- {"version":3,"file":"block_pack.js","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from '@milaboratories/pl-client';\nimport { field } from '@milaboratories/pl-client';\nimport { loadTemplate } from '../template/template_loading';\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from '../../model';\nimport type { Signer } from '@milaboratories/ts-helpers';\nimport { assertNever } from '@milaboratories/ts-helpers';\nimport fs from 'node:fs';\nimport type { Dispatcher } from 'undici';\nimport { request } from 'undici';\nimport { createFrontend } from './frontend';\nimport type { BlockConfigContainer } from '@platforma-sdk/model';\nimport { Code } from '@platforma-sdk/model';\nimport { loadPackDescription, RegistryV1 } from '@platforma-sdk/block-tools';\nimport type { BlockPackInfo } from '../../model/block_pack';\nimport { resolveDevPacket } from '../../dev_env';\nimport { getDevV2PacketMtime } from '../../block_registry';\nimport type { V2RegistryProvider } from '../../block_registry/registry-v2-provider';\nimport { LRUCache } from 'lru-cache';\nimport type { BlockPackSpec } from '@milaboratories/pl-model-middle-layer';\nimport { WorkerManager } from '../../worker/WorkerManager';\nimport { z } from 'zod';\n\nexport const BlockPackCustomType: ResourceType = { name: 'BlockPackCustom', version: '1' };\nexport const BlockPackTemplateField = 'template';\nexport const BlockPackFrontendField = 'frontend';\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith('/')) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error('Invalid config content');\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error('parseStringConfig:No code bundle');\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString('utf8'));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case 'explicit':\n return spec.config;\n\n case 'prepared':\n return spec.config;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: 'utf-8' });\n return JSON.parse(configContent);\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n });\n return parseStringConfig(configContent);\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString('utf8'));\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === 'prepared') {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: 'prepared',\n template: {\n type: 'prepared',\n data: await workerManager.process('parseTemplate', explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(spec: BlockPackExplicit | BlockPackSpec): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case 'explicit':\n return spec;\n\n case 'dev-v1': {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(\n await fs.promises.readFile(devPaths.config, 'utf-8'),\n );\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case 'dev-v2': {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: 'utf-8',\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: workflowContent,\n },\n config,\n frontend: {\n type: 'local',\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case 'from-registry-v1': {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(Buffer.from(configResponse).toString('utf8')) as BlockConfigContainer;\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: templateContent,\n },\n config,\n frontend: {\n type: 'url',\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case 'from-registry-v2': {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: 'explicit',\n template: {\n type: 'explicit',\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: 'url',\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), 'Input', loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), 'Input', createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case 'prepared':\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CA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ACR,wBAAA,IAAI,EAAE,KAAK;AACX,wBAAA,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC,GAAG;AACvB,qBAAA;AACD,oBAAA,MAAM,EAAE,IAAI;iBACb;YACH;AAEA,YAAA;AACE,gBAAA,OAAO,WAAW,CAAC,IAAI,CAAC;;IAE9B;AACD;AAED,SAAS,qBAAqB,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC3E,IAAA,MAAM,aAAa,GAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;AACjF,IAAA,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9E,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;"}
1
+ {"version":3,"file":"block_pack.js","sources":["../../../src/mutator/block-pack/block_pack.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction, ResourceType } from \"@milaboratories/pl-client\";\nimport { field } from \"@milaboratories/pl-client\";\nimport { loadTemplate } from \"../template/template_loading\";\nimport type { BlockPackExplicit, BlockPackSpecAny, BlockPackSpecPrepared } from \"../../model\";\nimport type { Signer } from \"@milaboratories/ts-helpers\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\nimport fs from \"node:fs\";\nimport type { Dispatcher } from \"undici\";\nimport { request } from \"undici\";\nimport { createFrontend } from \"./frontend\";\nimport type { BlockConfigContainer } from \"@platforma-sdk/model\";\nimport { Code } from \"@platforma-sdk/model\";\nimport { loadPackDescription, RegistryV1 } from \"@platforma-sdk/block-tools\";\nimport type { BlockPackInfo } from \"../../model/block_pack\";\nimport { resolveDevPacket } from \"../../dev_env\";\nimport { getDevV2PacketMtime } from \"../../block_registry\";\nimport type { V2RegistryProvider } from \"../../block_registry/registry-v2-provider\";\nimport { LRUCache } from \"lru-cache\";\nimport type { BlockPackSpec } from \"@milaboratories/pl-model-middle-layer\";\nimport { WorkerManager } from \"../../worker/WorkerManager\";\nimport { z } from \"zod\";\n\nexport const BlockPackCustomType: ResourceType = { name: \"BlockPackCustom\", version: \"1\" };\nexport const BlockPackTemplateField = \"template\";\nexport const BlockPackFrontendField = \"frontend\";\n\n/** Ensure trailing slash */\nfunction tSlash(str: string): string {\n if (str.endsWith(\"/\")) return str;\n else return `${str}/`;\n}\n\nfunction parseStringConfig(configContent: string): BlockConfigContainer {\n const res = z.record(z.string(), z.unknown()).safeParse(JSON.parse(configContent));\n\n if (!res.success) {\n throw new Error(\"Invalid config content\");\n }\n\n if (!Code.safeParse(res.data.code).success) {\n throw new Error(\"parseStringConfig:No code bundle\");\n }\n\n return res.data as BlockConfigContainer;\n}\n\nfunction parseBufferConfig(buffer: ArrayBuffer): BlockConfigContainer {\n return parseStringConfig(Buffer.from(buffer).toString(\"utf8\"));\n}\n\nexport class BlockPackPreparer {\n constructor(\n private readonly v2RegistryProvider: V2RegistryProvider,\n private readonly signer: Signer,\n private readonly http?: Dispatcher,\n ) {}\n\n private readonly remoteContentCache = new LRUCache<string, ArrayBuffer>({\n max: 500,\n maxSize: 128 * 1024 * 1024,\n fetchMethod: async (key) => {\n const httpOptions = this.http !== undefined ? { dispatcher: this.http } : {};\n return await (await request(key, httpOptions)).body.arrayBuffer();\n },\n sizeCalculation: (value) => value.byteLength,\n });\n\n public async getBlockConfigContainer(spec: BlockPackSpecAny): Promise<BlockConfigContainer> {\n switch (spec.type) {\n case \"explicit\":\n return spec.config;\n\n case \"prepared\":\n return spec.config;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n const configContent = await fs.promises.readFile(devPaths.config, { encoding: \"utf-8\" });\n return JSON.parse(configContent);\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const configContent = await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n });\n return parseStringConfig(configContent);\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n return JSON.parse(Buffer.from(configResponse).toString(\"utf8\"));\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const configResponse = await this.remoteContentCache.forceFetch(components.model.url);\n return parseBufferConfig(configResponse);\n }\n\n default:\n return assertNever(spec);\n }\n }\n\n public async prepare(spec: BlockPackSpecAny): Promise<BlockPackSpecPrepared> {\n if (spec.type === \"prepared\") {\n return spec;\n }\n\n const explicit = await this.prepareWithoutUnpacking(spec);\n\n await using workerManager = new WorkerManager();\n\n return {\n ...explicit,\n type: \"prepared\",\n template: {\n type: \"prepared\",\n data: await workerManager.process(\"parseTemplate\", explicit.template.content),\n },\n };\n }\n\n private async prepareWithoutUnpacking(\n spec: BlockPackExplicit | BlockPackSpec,\n ): Promise<BlockPackExplicit> {\n switch (spec.type) {\n case \"explicit\":\n return spec;\n\n case \"dev-v1\": {\n const devPaths = await resolveDevPacket(spec.folder, false);\n\n // template\n const templateContent = await fs.promises.readFile(devPaths.workflow);\n\n // config\n const config = JSON.parse(await fs.promises.readFile(devPaths.config, \"utf-8\"));\n\n // frontend\n const frontendPath = devPaths.ui;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source: spec,\n };\n }\n\n case \"dev-v2\": {\n const description = await loadPackDescription(spec.folder);\n const config = parseStringConfig(\n await fs.promises.readFile(description.components.model.file, {\n encoding: \"utf-8\",\n }),\n );\n const workflowContent = await fs.promises.readFile(\n description.components.workflow.main.file,\n );\n const frontendPath = description.components.ui.folder;\n const source = { ...spec };\n if (spec.mtime === undefined)\n // if absent, calculating the mtime here, so the block will correctly show whether it can be updated\n source.mtime = await getDevV2PacketMtime(description);\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: workflowContent,\n },\n config,\n frontend: {\n type: \"local\",\n path: frontendPath,\n signature: this.signer.sign(frontendPath),\n },\n source,\n };\n }\n\n case \"from-registry-v1\": {\n const urlPrefix = `${tSlash(spec.registryUrl)}${RegistryV1.packageContentPrefix({ organization: spec.id.organization, package: spec.id.name, version: spec.id.version })}`;\n\n const templateUrl = `${urlPrefix}/template.plj.gz`;\n // template\n const templateResponse = await this.remoteContentCache.forceFetch(templateUrl);\n const templateContent = new Uint8Array(templateResponse);\n\n // config\n const configResponse = await this.remoteContentCache.forceFetch(`${urlPrefix}/config.json`);\n const config = JSON.parse(\n Buffer.from(configResponse).toString(\"utf8\"),\n ) as BlockConfigContainer;\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: templateContent,\n },\n config,\n frontend: {\n type: \"url\",\n url: `${urlPrefix}/frontend.tgz`,\n },\n source: spec,\n };\n }\n\n case \"from-registry-v2\": {\n const registry = this.v2RegistryProvider.getRegistry(spec.registryUrl);\n const components = await registry.getComponents(spec.id);\n const getModel = async () =>\n parseBufferConfig(await this.remoteContentCache.forceFetch(components.model.url));\n const getWorkflow = async () =>\n await this.remoteContentCache.forceFetch(components.workflow.main.url);\n\n const [model, workflow] = await Promise.all([getModel(), getWorkflow()]);\n\n return {\n type: \"explicit\",\n template: {\n type: \"explicit\",\n content: Buffer.from(workflow),\n },\n config: model,\n frontend: {\n type: \"url\",\n url: components.ui.url,\n },\n source: spec,\n };\n }\n\n default:\n return assertNever(spec);\n }\n }\n}\n\nfunction createCustomBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n const blockPackInfo: BlockPackInfo = { config: spec.config, source: spec.source };\n const bp = tx.createStruct(BlockPackCustomType, JSON.stringify(blockPackInfo));\n tx.createField(field(bp, BlockPackTemplateField), \"Input\", loadTemplate(tx, spec.template));\n tx.createField(field(bp, BlockPackFrontendField), \"Input\", createFrontend(tx, spec.frontend));\n tx.lock(bp);\n\n return bp;\n}\n\nexport function createBlockPack(tx: PlTransaction, spec: BlockPackSpecPrepared): AnyResourceRef {\n switch (spec.type) {\n case \"prepared\":\n return createCustomBlockPack(tx, spec);\n default:\n return assertNever(spec.type);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAsBO,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG;AACjF,MAAM,sBAAsB,GAAG;AAC/B,MAAM,sBAAsB,GAAG;AAEtC;AACA,SAAS,MAAM,CAAC,GAAW,EAAA;AACzB,IAAA,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,QAAA,OAAO,GAAG;;QAC5B,OAAO,CAAA,EAAG,GAAG,CAAA,CAAA,CAAG;AACvB;AAEA,SAAS,iBAAiB,CAAC,aAAqB,EAAA;IAC9C,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,E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EAAE;AACR,wBAAA,IAAI,EAAE,KAAK;AACX,wBAAA,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC,GAAG;AACvB,qBAAA;AACD,oBAAA,MAAM,EAAE,IAAI;iBACb;YACH;AAEA,YAAA;AACE,gBAAA,OAAO,WAAW,CAAC,IAAI,CAAC;;IAE9B;AACD;AAED,SAAS,qBAAqB,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC3E,IAAA,MAAM,aAAa,GAAkB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;AACjF,IAAA,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC9E,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3F,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7F,IAAA,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;AAEX,IAAA,OAAO,EAAE;AACX;AAEM,SAAU,eAAe,CAAC,EAAiB,EAAE,IAA2B,EAAA;AAC5E,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,UAAU;AACb,YAAA,OAAO,qBAAqB,CAAC,EAAE,EAAE,IAAI,CAAC;AACxC,QAAA;AACE,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;AAEnC;;;;"}
@@ -6,9 +6,9 @@ var tsHelpers = require('@milaboratories/ts-helpers');
6
6
 
7
7
  function createFrontend(tx, spec) {
8
8
  switch (spec.type) {
9
- case 'url':
9
+ case "url":
10
10
  return tx.createValue(block_pack_spec.FrontendFromUrlResourceType, JSON.stringify({ url: spec.url }));
11
- case 'local':
11
+ case "local":
12
12
  return tx.createValue(block_pack_spec.FrontendFromFolderResourceType, JSON.stringify({
13
13
  path: spec.path,
14
14
  signature: spec.signature,
@@ -1 +1 @@
1
- {"version":3,"file":"frontend.cjs","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from '@milaboratories/pl-client';\nimport type {\n FrontendFromFolderData,\n FrontendFromUrlData,\n FrontendSpec,\n} from '../../model';\nimport {\n FrontendFromFolderResourceType,\n FrontendFromUrlResourceType,\n} from '../../model';\nimport { assertNever } from '@milaboratories/ts-helpers';\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case 'url':\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case 'local':\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"names":["FrontendFromUrlResourceType","FrontendFromFolderResourceType","assertNever"],"mappings":";;;;;;AAYM,SAAU,cAAc,CAAC,EAAiB,EAAE,IAAkB,EAAA;AAClE,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,EAAE,CAAC,WAAW,CACnBA,2CAA2B,EAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAyB,CAAC,CACzD;AACH,QAAA,KAAK,OAAO;YACV,OAAO,EAAE,CAAC,WAAW,CACnBC,8CAA8B,EAC9B,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,SAAS,EAAE,IAAI,CAAC,SAAS;AACA,aAAA,CAAC,CAC7B;AACH,QAAA;AACE,YAAA,OAAOC,qBAAW,CAAC,IAAI,CAAC;;AAE9B;;;;"}
1
+ {"version":3,"file":"frontend.cjs","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { FrontendFromFolderData, FrontendFromUrlData, FrontendSpec } from \"../../model\";\nimport { FrontendFromFolderResourceType, FrontendFromUrlResourceType } from \"../../model\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case \"url\":\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case \"local\":\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"names":["FrontendFromUrlResourceType","FrontendFromFolderResourceType","assertNever"],"mappings":";;;;;;AAKM,SAAU,cAAc,CAAC,EAAiB,EAAE,IAAkB,EAAA;AAClE,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,EAAE,CAAC,WAAW,CACnBA,2CAA2B,EAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAyB,CAAC,CACzD;AACH,QAAA,KAAK,OAAO;YACV,OAAO,EAAE,CAAC,WAAW,CACnBC,8CAA8B,EAC9B,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,SAAS,EAAE,IAAI,CAAC,SAAS;AACA,aAAA,CAAC,CAC7B;AACH,QAAA;AACE,YAAA,OAAOC,qBAAW,CAAC,IAAI,CAAC;;AAE9B;;;;"}
@@ -1,4 +1,4 @@
1
- import type { AnyResourceRef, PlTransaction } from '@milaboratories/pl-client';
2
- import type { FrontendSpec } from '../../model';
1
+ import type { AnyResourceRef, PlTransaction } from "@milaboratories/pl-client";
2
+ import type { FrontendSpec } from "../../model";
3
3
  export declare function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef;
4
4
  //# sourceMappingURL=frontend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../../../src/mutator/block-pack/frontend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAGV,YAAY,EACb,MAAM,aAAa,CAAC;AAOrB,wBAAgB,cAAc,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,cAAc,CAkBpF"}
1
+ {"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../../../src/mutator/block-pack/frontend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAA+C,YAAY,EAAE,MAAM,aAAa,CAAC;AAI7F,wBAAgB,cAAc,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,cAAc,CAkBpF"}
@@ -4,9 +4,9 @@ import { assertNever } from '@milaboratories/ts-helpers';
4
4
 
5
5
  function createFrontend(tx, spec) {
6
6
  switch (spec.type) {
7
- case 'url':
7
+ case "url":
8
8
  return tx.createValue(FrontendFromUrlResourceType, JSON.stringify({ url: spec.url }));
9
- case 'local':
9
+ case "local":
10
10
  return tx.createValue(FrontendFromFolderResourceType, JSON.stringify({
11
11
  path: spec.path,
12
12
  signature: spec.signature,
@@ -1 +1 @@
1
- {"version":3,"file":"frontend.js","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from '@milaboratories/pl-client';\nimport type {\n FrontendFromFolderData,\n FrontendFromUrlData,\n FrontendSpec,\n} from '../../model';\nimport {\n FrontendFromFolderResourceType,\n FrontendFromUrlResourceType,\n} from '../../model';\nimport { assertNever } from '@milaboratories/ts-helpers';\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case 'url':\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case 'local':\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"names":[],"mappings":";;;;AAYM,SAAU,cAAc,CAAC,EAAiB,EAAE,IAAkB,EAAA;AAClE,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,EAAE,CAAC,WAAW,CACnB,2BAA2B,EAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAyB,CAAC,CACzD;AACH,QAAA,KAAK,OAAO;YACV,OAAO,EAAE,CAAC,WAAW,CACnB,8BAA8B,EAC9B,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,SAAS,EAAE,IAAI,CAAC,SAAS;AACA,aAAA,CAAC,CAC7B;AACH,QAAA;AACE,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC;;AAE9B;;;;"}
1
+ {"version":3,"file":"frontend.js","sources":["../../../src/mutator/block-pack/frontend.ts"],"sourcesContent":["import type { AnyResourceRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport type { FrontendFromFolderData, FrontendFromUrlData, FrontendSpec } from \"../../model\";\nimport { FrontendFromFolderResourceType, FrontendFromUrlResourceType } from \"../../model\";\nimport { assertNever } from \"@milaboratories/ts-helpers\";\n\nexport function createFrontend(tx: PlTransaction, spec: FrontendSpec): AnyResourceRef {\n switch (spec.type) {\n case \"url\":\n return tx.createValue(\n FrontendFromUrlResourceType,\n JSON.stringify({ url: spec.url } as FrontendFromUrlData),\n );\n case \"local\":\n return tx.createValue(\n FrontendFromFolderResourceType,\n JSON.stringify({\n path: spec.path,\n signature: spec.signature,\n } as FrontendFromFolderData),\n );\n default:\n return assertNever(spec);\n }\n}\n"],"names":[],"mappings":";;;;AAKM,SAAU,cAAc,CAAC,EAAiB,EAAE,IAAkB,EAAA;AAClE,IAAA,QAAQ,IAAI,CAAC,IAAI;AACf,QAAA,KAAK,KAAK;AACR,YAAA,OAAO,EAAE,CAAC,WAAW,CACnB,2BAA2B,EAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAyB,CAAC,CACzD;AACH,QAAA,KAAK,OAAO;YACV,OAAO,EAAE,CAAC,WAAW,CACnB,8BAA8B,EAC9B,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,SAAS,EAAE,IAAI,CAAC,SAAS;AACA,aAAA,CAAC,CAC7B;AACH,QAAA;AACE,YAAA,OAAO,WAAW,CAAC,IAAI,CAAC;;AAE9B;;;;"}
@@ -9,16 +9,16 @@ let preparedTemplateEnvelop;
9
9
  async function getPreparedExportTemplateEnvelope() {
10
10
  if (preparedTemplateEnvelop === undefined) {
11
11
  // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']
12
- const preparedTemplate = await template_loading.prepareTemplateSpec(workflowTengo.Templates['pframes.export-pframe-for-ui']);
13
- if (preparedTemplate.type !== 'explicit')
14
- throw new Error('Unexpected prepared template type.');
15
- const hash = node_crypto.createHash('sha256').update(preparedTemplate.content).digest('hex');
12
+ const preparedTemplate = await template_loading.prepareTemplateSpec(workflowTengo.Templates["pframes.export-pframe-for-ui"]);
13
+ if (preparedTemplate.type !== "explicit")
14
+ throw new Error("Unexpected prepared template type.");
15
+ const hash = node_crypto.createHash("sha256").update(preparedTemplate.content).digest("hex");
16
16
  preparedTemplateEnvelop = { spec: preparedTemplate, hash };
17
17
  }
18
18
  return preparedTemplateEnvelop;
19
19
  }
20
20
  function exportContext(tx, exportTpl, ctx) {
21
- return render_template.createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ['result']).result;
21
+ return render_template.createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ["result"]).result;
22
22
  }
23
23
 
24
24
  exports.exportContext = exportContext;
@@ -1 +1 @@
1
- {"version":3,"file":"context_export.cjs","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from '@milaboratories/pl-client';\nimport { createRenderTemplate } from './template/render_template';\nimport { prepareTemplateSpec } from './template/template_loading';\nimport type { TemplateSpecPrepared } from '../model/template_spec';\nimport { createHash } from 'node:crypto';\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from '@platforma-sdk/workflow-tengo';\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(SdkTemplates['pframes.export-pframe-for-ui']);\n if (preparedTemplate.type !== 'explicit') throw new Error('Unexpected prepared template type.');\n const hash = createHash('sha256').update(preparedTemplate.content).digest('hex');\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ['result']).result;\n}\n"],"names":["prepareTemplateSpec","SdkTemplates","createHash","createRenderTemplate"],"mappings":";;;;;;;AAgBA,IAAI,uBAAoD;AAEjD,eAAe,iCAAiC,GAAA;AACrD,IAAA,IAAI,uBAAuB,KAAK,SAAS,EAAE;;QAEzC,MAAM,gBAAgB,GAAG,MAAMA,oCAAmB,CAACC,uBAAY,CAAC,8BAA8B,CAAC,CAAC;AAChG,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;AAC/F,QAAA,MAAM,IAAI,GAAGC,sBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAChF,uBAAuB,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC5D;AAEA,IAAA,OAAO,uBAAuB;AAChC;SAEgB,aAAa,CAAC,EAAiB,EAAE,SAAiB,EAAE,GAAW,EAAA;IAC7E,OAAOC,oCAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;AAClF;;;;;"}
1
+ {"version":3,"file":"context_export.cjs","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport { createRenderTemplate } from \"./template/render_template\";\nimport { prepareTemplateSpec } from \"./template/template_loading\";\nimport type { TemplateSpecPrepared } from \"../model/template_spec\";\nimport { createHash } from \"node:crypto\";\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from \"@platforma-sdk/workflow-tengo\";\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(\n SdkTemplates[\"pframes.export-pframe-for-ui\"],\n );\n if (preparedTemplate.type !== \"explicit\") throw new Error(\"Unexpected prepared template type.\");\n const hash = createHash(\"sha256\").update(preparedTemplate.content).digest(\"hex\");\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [\"result\"]).result;\n}\n"],"names":["prepareTemplateSpec","SdkTemplates","createHash","createRenderTemplate"],"mappings":";;;;;;;AAgBA,IAAI,uBAAoD;AAEjD,eAAe,iCAAiC,GAAA;AACrD,IAAA,IAAI,uBAAuB,KAAK,SAAS,EAAE;;QAEzC,MAAM,gBAAgB,GAAG,MAAMA,oCAAmB,CAChDC,uBAAY,CAAC,8BAA8B,CAAC,CAC7C;AACD,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;AAC/F,QAAA,MAAM,IAAI,GAAGC,sBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAChF,uBAAuB,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC5D;AAEA,IAAA,OAAO,uBAAuB;AAChC;SAEgB,aAAa,CAAC,EAAiB,EAAE,SAAiB,EAAE,GAAW,EAAA;IAC7E,OAAOC,oCAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;AAClF;;;;;"}
@@ -1,5 +1,5 @@
1
- import type { AnyRef, PlTransaction } from '@milaboratories/pl-client';
2
- import type { TemplateSpecPrepared } from '../model/template_spec';
1
+ import type { AnyRef, PlTransaction } from "@milaboratories/pl-client";
2
+ import type { TemplateSpecPrepared } from "../model/template_spec";
3
3
  export type TemplateEnvelop = {
4
4
  spec: TemplateSpecPrepared;
5
5
  hash: string;
@@ -1 +1 @@
1
- {"version":3,"file":"context_export.d.ts","sourceRoot":"","sources":["../../src/mutator/context_export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAWnE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI3E,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,eAAe,CAAC,CAUlF;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gDAE9E"}
1
+ {"version":3,"file":"context_export.d.ts","sourceRoot":"","sources":["../../src/mutator/context_export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAWnE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI3E,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,eAAe,CAAC,CAYlF;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gDAE9E"}
@@ -7,16 +7,16 @@ let preparedTemplateEnvelop;
7
7
  async function getPreparedExportTemplateEnvelope() {
8
8
  if (preparedTemplateEnvelop === undefined) {
9
9
  // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']
10
- const preparedTemplate = await prepareTemplateSpec(Templates['pframes.export-pframe-for-ui']);
11
- if (preparedTemplate.type !== 'explicit')
12
- throw new Error('Unexpected prepared template type.');
13
- const hash = createHash('sha256').update(preparedTemplate.content).digest('hex');
10
+ const preparedTemplate = await prepareTemplateSpec(Templates["pframes.export-pframe-for-ui"]);
11
+ if (preparedTemplate.type !== "explicit")
12
+ throw new Error("Unexpected prepared template type.");
13
+ const hash = createHash("sha256").update(preparedTemplate.content).digest("hex");
14
14
  preparedTemplateEnvelop = { spec: preparedTemplate, hash };
15
15
  }
16
16
  return preparedTemplateEnvelop;
17
17
  }
18
18
  function exportContext(tx, exportTpl, ctx) {
19
- return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ['result']).result;
19
+ return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ["result"]).result;
20
20
  }
21
21
 
22
22
  export { exportContext, getPreparedExportTemplateEnvelope };
@@ -1 +1 @@
1
- {"version":3,"file":"context_export.js","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from '@milaboratories/pl-client';\nimport { createRenderTemplate } from './template/render_template';\nimport { prepareTemplateSpec } from './template/template_loading';\nimport type { TemplateSpecPrepared } from '../model/template_spec';\nimport { createHash } from 'node:crypto';\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from '@platforma-sdk/workflow-tengo';\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(SdkTemplates['pframes.export-pframe-for-ui']);\n if (preparedTemplate.type !== 'explicit') throw new Error('Unexpected prepared template type.');\n const hash = createHash('sha256').update(preparedTemplate.content).digest('hex');\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, ['result']).result;\n}\n"],"names":["SdkTemplates"],"mappings":";;;;;AAgBA,IAAI,uBAAoD;AAEjD,eAAe,iCAAiC,GAAA;AACrD,IAAA,IAAI,uBAAuB,KAAK,SAAS,EAAE;;QAEzC,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAACA,SAAY,CAAC,8BAA8B,CAAC,CAAC;AAChG,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;AAC/F,QAAA,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAChF,uBAAuB,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC5D;AAEA,IAAA,OAAO,uBAAuB;AAChC;SAEgB,aAAa,CAAC,EAAiB,EAAE,SAAiB,EAAE,GAAW,EAAA;IAC7E,OAAO,oBAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;AAClF;;;;"}
1
+ {"version":3,"file":"context_export.js","sources":["../../src/mutator/context_export.ts"],"sourcesContent":["import type { AnyRef, PlTransaction } from \"@milaboratories/pl-client\";\nimport { createRenderTemplate } from \"./template/render_template\";\nimport { prepareTemplateSpec } from \"./template/template_loading\";\nimport type { TemplateSpecPrepared } from \"../model/template_spec\";\nimport { createHash } from \"node:crypto\";\n\n// Workaround to prevent bundling of @platforma-sdk/workflow-tengo\n// if bundling happens import.meta.dirname will be transfered as is without transferring corresponding assets\n// Construct like new URL(…, import.meta.url) also does not work properly.\n// const require = createRequire(import.meta.url);\n// const SdkTemplates = require('@platforma-sdk/workflow-tengo').Templates;\n\nimport { Templates as SdkTemplates } from \"@platforma-sdk/workflow-tengo\";\n\nexport type TemplateEnvelop = { spec: TemplateSpecPrepared; hash: string };\n\nlet preparedTemplateEnvelop: TemplateEnvelop | undefined;\n\nexport async function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop> {\n if (preparedTemplateEnvelop === undefined) {\n // (await import('@platforma-sdk/workflow-tengo')).Templates['pframes.export-pframe']\n const preparedTemplate = await prepareTemplateSpec(\n SdkTemplates[\"pframes.export-pframe-for-ui\"],\n );\n if (preparedTemplate.type !== \"explicit\") throw new Error(\"Unexpected prepared template type.\");\n const hash = createHash(\"sha256\").update(preparedTemplate.content).digest(\"hex\");\n preparedTemplateEnvelop = { spec: preparedTemplate, hash };\n }\n\n return preparedTemplateEnvelop;\n}\n\nexport function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef) {\n return createRenderTemplate(tx, exportTpl, true, { pf: ctx }, [\"result\"]).result;\n}\n"],"names":["SdkTemplates"],"mappings":";;;;;AAgBA,IAAI,uBAAoD;AAEjD,eAAe,iCAAiC,GAAA;AACrD,IAAA,IAAI,uBAAuB,KAAK,SAAS,EAAE;;QAEzC,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAChDA,SAAY,CAAC,8BAA8B,CAAC,CAC7C;AACD,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,UAAU;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC;AAC/F,QAAA,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QAChF,uBAAuB,GAAG,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE;IAC5D;AAEA,IAAA,OAAO,uBAAuB;AAChC;SAEgB,aAAa,CAAC,EAAiB,EAAE,SAAiB,EAAE,GAAW,EAAA;IAC7E,OAAO,oBAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;AAClF;;;;"}