@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
@@ -6,7 +6,7 @@ import type {
6
6
  ResourceData,
7
7
  ResourceId,
8
8
  TxOps,
9
- } from '@milaboratories/pl-client';
9
+ } from "@milaboratories/pl-client";
10
10
  import {
11
11
  ensureResourceIdNotNull,
12
12
  field,
@@ -17,13 +17,14 @@ import {
17
17
  isResourceRef,
18
18
  Pl,
19
19
  PlClient,
20
- } from '@milaboratories/pl-client';
21
- import { createRenderHeavyBlock, createBContextFromUpstreams } from './template/render_block';
20
+ } from "@milaboratories/pl-client";
21
+ import { createRenderHeavyBlock, createBContextFromUpstreams } from "./template/render_block";
22
22
  import type {
23
23
  Block,
24
24
  ProjectStructure,
25
25
  ProjectField,
26
- ProjectRenderingState } from '../model/project_model';
26
+ ProjectRenderingState,
27
+ } from "../model/project_model";
27
28
  import {
28
29
  BlockRenderingStateKey,
29
30
  ProjectStructureKey,
@@ -42,37 +43,33 @@ import {
42
43
  ProjectStructureAuthorKey,
43
44
  getServiceTemplateField,
44
45
  FieldsToDuplicate,
45
- } from '../model/project_model';
46
- import { BlockPackTemplateField, createBlockPack } from './block-pack/block_pack';
47
- import type {
48
- BlockGraph,
49
- ProductionGraphBlockInfo } from '../model/project_model_util';
50
- import {
51
- allBlocks,
52
- graphDiff,
53
- productionGraph,
54
- stagingGraph,
55
- } from '../model/project_model_util';
56
- import type { BlockPackSpecPrepared } from '../model';
46
+ } from "../model/project_model";
47
+ import { BlockPackTemplateField, createBlockPack } from "./block-pack/block_pack";
48
+ import type { BlockGraph, ProductionGraphBlockInfo } from "../model/project_model_util";
49
+ import { allBlocks, graphDiff, productionGraph, stagingGraph } from "../model/project_model_util";
50
+ import type { BlockPackSpecPrepared } from "../model";
57
51
  import type {
58
52
  AuthorMarker,
59
53
  BlockPackSpec,
60
54
  BlockSettings,
61
55
  ProjectMeta,
62
- } from '@milaboratories/pl-model-middle-layer';
56
+ } from "@milaboratories/pl-model-middle-layer";
57
+ import { InitialBlockSettings } from "@milaboratories/pl-model-middle-layer";
58
+ import Denque from "denque";
59
+ import { exportContext, getPreparedExportTemplateEnvelope } from "./context_export";
60
+ import { loadTemplate } from "./template/template_loading";
63
61
  import {
64
- InitialBlockSettings,
65
- } from '@milaboratories/pl-model-middle-layer';
66
- import Denque from 'denque';
67
- import { exportContext, getPreparedExportTemplateEnvelope } from './context_export';
68
- import { loadTemplate } from './template/template_loading';
69
- import { cachedDeserialize, notEmpty, canonicalJsonBytes, cachedDecode } from '@milaboratories/ts-helpers';
70
- import type { ProjectHelper } from '../model/project_helper';
71
- import { extractConfig, UiError, type BlockConfig } from '@platforma-sdk/model';
72
- import { getDebugFlags } from '../debug';
73
- import type { BlockPackInfo } from '../model/block_pack';
74
-
75
- type FieldStatus = 'NotReady' | 'Ready' | 'Error';
62
+ cachedDeserialize,
63
+ notEmpty,
64
+ canonicalJsonBytes,
65
+ cachedDecode,
66
+ } from "@milaboratories/ts-helpers";
67
+ import type { ProjectHelper } from "../model/project_helper";
68
+ import { extractConfig, UiError, type BlockConfig } from "@platforma-sdk/model";
69
+ import { getDebugFlags } from "../debug";
70
+ import type { BlockPackInfo } from "../model/block_pack";
71
+
72
+ type FieldStatus = "NotReady" | "Ready" | "Error";
76
73
 
77
74
  interface BlockFieldState {
78
75
  modCount: number;
@@ -81,8 +78,8 @@ interface BlockFieldState {
81
78
  value?: Uint8Array;
82
79
  }
83
80
 
84
- type BlockFieldStates = Partial<Record<ProjectField['fieldName'], BlockFieldState>>;
85
- type BlockFieldStateValue = Omit<BlockFieldState, 'modCount'>;
81
+ type BlockFieldStates = Partial<Record<ProjectField["fieldName"], BlockFieldState>>;
82
+ type BlockFieldStateValue = Omit<BlockFieldState, "modCount">;
86
83
 
87
84
  interface BlockInfoState {
88
85
  readonly id: string;
@@ -123,26 +120,26 @@ class BlockInfo {
123
120
  // state assertions
124
121
 
125
122
  if ((this.fields.prodOutput === undefined) !== (this.fields.prodCtx === undefined))
126
- throw new Error('inconsistent prod fields');
123
+ throw new Error("inconsistent prod fields");
127
124
 
128
125
  if ((this.fields.stagingOutput === undefined) !== (this.fields.stagingCtx === undefined))
129
- throw new Error('inconsistent stage fields');
126
+ throw new Error("inconsistent stage fields");
130
127
 
131
128
  if (
132
- (this.fields.prodOutputPrevious === undefined)
133
- !== (this.fields.prodCtxPrevious === undefined)
129
+ (this.fields.prodOutputPrevious === undefined) !==
130
+ (this.fields.prodCtxPrevious === undefined)
134
131
  )
135
- throw new Error('inconsistent prod cache fields');
132
+ throw new Error("inconsistent prod cache fields");
136
133
 
137
134
  if (
138
- (this.fields.stagingOutputPrevious === undefined)
139
- !== (this.fields.stagingCtxPrevious === undefined)
135
+ (this.fields.stagingOutputPrevious === undefined) !==
136
+ (this.fields.stagingCtxPrevious === undefined)
140
137
  )
141
- throw new Error('inconsistent stage cache fields');
138
+ throw new Error("inconsistent stage cache fields");
142
139
 
143
- if (this.fields.blockPack === undefined) throw new Error('no block pack field');
140
+ if (this.fields.blockPack === undefined) throw new Error("no block pack field");
144
141
 
145
- if (this.fields.blockStorage === undefined) throw new Error('no block storage field');
142
+ if (this.fields.blockStorage === undefined) throw new Error("no block storage field");
146
143
  }
147
144
 
148
145
  private readonly currentArgsC = cached(
@@ -198,7 +195,7 @@ class BlockInfo {
198
195
  try {
199
196
  return this.blockStorageC();
200
197
  } catch (e) {
201
- console.error('Error getting blockStorage:', e);
198
+ console.error("Error getting blockStorage:", e);
202
199
  return undefined;
203
200
  }
204
201
  }
@@ -220,14 +217,14 @@ class BlockInfo {
220
217
  }
221
218
 
222
219
  get productionHasErrors(): boolean {
223
- return this.fields.prodUiCtx?.status === 'Error';
220
+ return this.fields.prodUiCtx?.status === "Error";
224
221
  }
225
222
 
226
223
  private readonly productionStaleC: () => boolean = cached(
227
224
  () => `${this.fields.currentArgs!.modCount}_${this.fields.prodArgs?.modCount}`,
228
225
  () =>
229
- this.fields.prodArgs === undefined
230
- || Buffer.compare(this.fields.currentArgs!.value!, this.fields.prodArgs.value!) !== 0,
226
+ this.fields.prodArgs === undefined ||
227
+ Buffer.compare(this.fields.currentArgs!.value!, this.fields.prodArgs.value!) !== 0,
231
228
  );
232
229
 
233
230
  get requireProductionRendering(): boolean {
@@ -249,7 +246,7 @@ class BlockInfo {
249
246
  return tx.getFutureFieldValue(
250
247
  Pl.unwrapHolder(tx, this.fields.blockPack!.ref!),
251
248
  BlockPackTemplateField,
252
- 'Input',
249
+ "Input",
253
250
  );
254
251
  }
255
252
  }
@@ -260,8 +257,8 @@ class BlockInfo {
260
257
  */
261
258
  /** Specification for creating a new block. Discriminated union based on `storageMode`. */
262
259
  export type NewBlockSpec =
263
- | { storageMode: 'fromModel'; blockPack: BlockPackSpecPrepared }
264
- | { storageMode: 'legacy'; blockPack: BlockPackSpecPrepared; legacyState: string };
260
+ | { storageMode: "fromModel"; blockPack: BlockPackSpecPrepared }
261
+ | { storageMode: "legacy"; blockPack: BlockPackSpecPrepared; legacyState: string };
265
262
 
266
263
  const NoNewBlocks = (blockId: string) => {
267
264
  throw new Error(`No new block info for ${blockId}`);
@@ -272,17 +269,19 @@ const NoNewBlocks = (blockId: string) => {
272
269
  * For v3 blocks: state is the block's state
273
270
  * For v1/v2 blocks: state should be { args, uiState } format
274
271
  */
275
- export type SetStatesRequest = {
276
- blockId: string;
277
- /** The unified state to set */
278
- state: unknown;
279
- modelAPIVersion: 1;
280
- } | {
281
- blockId: string;
282
- /** Storage operation payload - middle layer is agnostic to specific operations */
283
- payload: { operation: string; value: unknown };
284
- modelAPIVersion: 2;
285
- };
272
+ export type SetStatesRequest =
273
+ | {
274
+ blockId: string;
275
+ /** The unified state to set */
276
+ state: unknown;
277
+ modelAPIVersion: 1;
278
+ }
279
+ | {
280
+ blockId: string;
281
+ /** Storage operation payload - middle layer is agnostic to specific operations */
282
+ payload: { operation: string; value: unknown };
283
+ modelAPIVersion: 2;
284
+ };
286
285
 
287
286
  export type ClearState = {
288
287
  state: unknown;
@@ -312,7 +311,7 @@ export class ProjectMutator {
312
311
  private lastModified: number,
313
312
  private meta: ProjectMeta,
314
313
  private struct: ProjectStructure,
315
- private readonly renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>,
314
+ private readonly renderingState: Omit<ProjectRenderingState, "blocksInLimbo">,
316
315
  private readonly blocksInLimbo: Set<string>,
317
316
  private readonly blockInfos: Map<string, BlockInfo>,
318
317
  private readonly ctxExportTplHolder: AnyResourceRef,
@@ -323,31 +322,31 @@ export class ProjectMutator {
323
322
  // Fixing problems introduced by old code
324
323
  this.blockInfos.forEach((blockInfo) => {
325
324
  if (
326
- blockInfo.fields.prodArgs === undefined
327
- || blockInfo.fields.prodOutput === undefined
328
- || blockInfo.fields.prodCtx === undefined
325
+ blockInfo.fields.prodArgs === undefined ||
326
+ blockInfo.fields.prodOutput === undefined ||
327
+ blockInfo.fields.prodCtx === undefined
329
328
  )
330
- this.deleteBlockFields(blockInfo.id, 'prodArgs', 'prodOutput', 'prodCtx');
329
+ this.deleteBlockFields(blockInfo.id, "prodArgs", "prodOutput", "prodCtx");
331
330
  });
332
331
 
333
332
  // Migration for addition of block settings field
334
- let initialBlockSettings: Omit<BlockFieldState, 'modCount'> | undefined;
333
+ let initialBlockSettings: Omit<BlockFieldState, "modCount"> | undefined;
335
334
  this.blockInfos.forEach((blockInfo) => {
336
335
  if (blockInfo.fields.blockSettings === undefined) {
337
336
  if (initialBlockSettings === undefined)
338
337
  initialBlockSettings = this.createJsonFieldValue(InitialBlockSettings);
339
- this.setBlockFieldObj(blockInfo.id, 'blockSettings', initialBlockSettings);
338
+ this.setBlockFieldObj(blockInfo.id, "blockSettings", initialBlockSettings);
340
339
  }
341
340
  });
342
341
  }
343
342
 
344
343
  get wasModified(): boolean {
345
344
  return (
346
- this.lastModifiedChanged
347
- || this.structureChanged
348
- || this.fieldsChanged
349
- || this.metaChanged
350
- || this.renderingStateChanged
345
+ this.lastModifiedChanged ||
346
+ this.structureChanged ||
347
+ this.fieldsChanged ||
348
+ this.metaChanged ||
349
+ this.renderingStateChanged
351
350
  );
352
351
  }
353
352
 
@@ -368,7 +367,10 @@ export class ProjectMutator {
368
367
  return this.stagingGraph;
369
368
  }
370
369
 
371
- private getProductionGraphBlockInfo(blockId: string, prod: boolean): ProductionGraphBlockInfo | undefined {
370
+ private getProductionGraphBlockInfo(
371
+ blockId: string,
372
+ prod: boolean,
373
+ ): ProductionGraphBlockInfo | undefined {
372
374
  const bInfo = this.getBlockInfo(blockId);
373
375
 
374
376
  let argsField: BlockFieldState | undefined;
@@ -393,30 +395,34 @@ export class ProjectMutator {
393
395
  if (isResourceId(argsField.ref!) && isResourceId(blockPackField.ref!))
394
396
  return {
395
397
  args,
396
- enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args,
397
- { argsRid: argsField.ref, blockPackRid: blockPackField.ref }),
398
+ enrichmentTargets: this.projectHelper.getEnrichmentTargets(
399
+ () => bInfo.config,
400
+ () => args,
401
+ { argsRid: argsField.ref, blockPackRid: blockPackField.ref },
402
+ ),
398
403
  };
399
404
  else
400
405
  return {
401
406
  args,
402
- enrichmentTargets: this.projectHelper.getEnrichmentTargets(() => bInfo.config, () => args),
407
+ enrichmentTargets: this.projectHelper.getEnrichmentTargets(
408
+ () => bInfo.config,
409
+ () => args,
410
+ ),
403
411
  };
404
412
  }
405
413
 
406
414
  private getPendingProductionGraph(): BlockGraph {
407
415
  if (this.pendingProductionGraph === undefined)
408
- this.pendingProductionGraph = productionGraph(
409
- this.struct,
410
- (blockId) => this.getProductionGraphBlockInfo(blockId, false),
416
+ this.pendingProductionGraph = productionGraph(this.struct, (blockId) =>
417
+ this.getProductionGraphBlockInfo(blockId, false),
411
418
  );
412
419
  return this.pendingProductionGraph;
413
420
  }
414
421
 
415
422
  private getActualProductionGraph(): BlockGraph {
416
423
  if (this.actualProductionGraph === undefined)
417
- this.actualProductionGraph = productionGraph(
418
- this.struct,
419
- (blockId) => this.getProductionGraphBlockInfo(blockId, true),
424
+ this.actualProductionGraph = productionGraph(this.struct, (blockId) =>
425
+ this.getProductionGraphBlockInfo(blockId, true),
420
426
  );
421
427
  return this.actualProductionGraph;
422
428
  }
@@ -432,10 +438,10 @@ export class ProjectMutator {
432
438
  }
433
439
 
434
440
  private createJsonFieldValueByContent(content: string): BlockFieldStateValue {
435
- if (content === undefined) throw new Error('content is undefined');
441
+ if (content === undefined) throw new Error("content is undefined");
436
442
  const value = Buffer.from(content);
437
443
  const ref = this.tx.createValue(Pl.JsonObject, value);
438
- return { ref, value, status: 'Ready' };
444
+ return { ref, value, status: "Ready" };
439
445
  }
440
446
 
441
447
  private createJsonFieldValue(obj: unknown): BlockFieldStateValue {
@@ -444,7 +450,7 @@ export class ProjectMutator {
444
450
 
445
451
  private getBlock(blockId: string): Block {
446
452
  for (const block of allBlocks(this.struct)) if (block.id === blockId) return block;
447
- throw new Error('block not found');
453
+ throw new Error("block not found");
448
454
  }
449
455
 
450
456
  private setBlockFieldObj(
@@ -454,10 +460,10 @@ export class ProjectMutator {
454
460
  ) {
455
461
  const fid = field(this.rid, projectFieldName(blockId, fieldName));
456
462
 
457
- if (state.ref === undefined) throw new Error('Can\'t set value with empty ref');
463
+ if (state.ref === undefined) throw new Error("Can't set value with empty ref");
458
464
 
459
465
  if (this.getBlockInfo(blockId).fields[fieldName] === undefined)
460
- this.tx.createField(fid, 'Dynamic', state.ref);
466
+ this.tx.createField(fid, "Dynamic", state.ref);
461
467
  else this.tx.setField(fid, state.ref);
462
468
 
463
469
  this.getBlockInfo(blockId).fields[fieldName] = {
@@ -509,30 +515,30 @@ export class ProjectMutator {
509
515
  private resetStaging(blockId: string): void {
510
516
  const fields = this.getBlockInfo(blockId).fields;
511
517
  if (
512
- fields.stagingOutput?.status === 'Ready'
513
- && fields.stagingCtx?.status === 'Ready'
514
- && fields.stagingUiCtx?.status === 'Ready'
518
+ fields.stagingOutput?.status === "Ready" &&
519
+ fields.stagingCtx?.status === "Ready" &&
520
+ fields.stagingUiCtx?.status === "Ready"
515
521
  ) {
516
- this.setBlockFieldObj(blockId, 'stagingOutputPrevious', fields.stagingOutput);
517
- this.setBlockFieldObj(blockId, 'stagingCtxPrevious', fields.stagingCtx);
518
- this.setBlockFieldObj(blockId, 'stagingUiCtxPrevious', fields.stagingUiCtx);
522
+ this.setBlockFieldObj(blockId, "stagingOutputPrevious", fields.stagingOutput);
523
+ this.setBlockFieldObj(blockId, "stagingCtxPrevious", fields.stagingCtx);
524
+ this.setBlockFieldObj(blockId, "stagingUiCtxPrevious", fields.stagingUiCtx);
519
525
  }
520
- if (this.deleteBlockFields(blockId, 'stagingOutput', 'stagingCtx', 'stagingUiCtx'))
526
+ if (this.deleteBlockFields(blockId, "stagingOutput", "stagingCtx", "stagingUiCtx"))
521
527
  this.resetStagingRefreshTimestamp();
522
528
  }
523
529
 
524
530
  private resetProduction(blockId: string): void {
525
531
  const fields = this.getBlockInfo(blockId).fields;
526
532
  if (
527
- fields.prodOutput?.status === 'Ready'
528
- && fields.prodCtx?.status === 'Ready'
529
- && fields.prodUiCtx?.status === 'Ready'
533
+ fields.prodOutput?.status === "Ready" &&
534
+ fields.prodCtx?.status === "Ready" &&
535
+ fields.prodUiCtx?.status === "Ready"
530
536
  ) {
531
- this.setBlockFieldObj(blockId, 'prodOutputPrevious', fields.prodOutput);
532
- this.setBlockFieldObj(blockId, 'prodCtxPrevious', fields.prodCtx);
533
- this.setBlockFieldObj(blockId, 'prodUiCtxPrevious', fields.prodUiCtx);
537
+ this.setBlockFieldObj(blockId, "prodOutputPrevious", fields.prodOutput);
538
+ this.setBlockFieldObj(blockId, "prodCtxPrevious", fields.prodCtx);
539
+ this.setBlockFieldObj(blockId, "prodUiCtxPrevious", fields.prodUiCtx);
534
540
  }
535
- this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs');
541
+ this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs");
536
542
  }
537
543
 
538
544
  /** Running blocks are reset, already computed moved to limbo. Returns if
@@ -542,7 +548,7 @@ export class ProjectMutator {
542
548
  const fields = this.getBlockInfo(blockId).fields;
543
549
 
544
550
  // Check if we can safely move to limbo (both core production fields are ready)
545
- if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {
551
+ if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready") {
546
552
  if (this.blocksInLimbo.has(blockId))
547
553
  // we are already in limbo
548
554
  return false;
@@ -552,20 +558,20 @@ export class ProjectMutator {
552
558
  this.renderingStateChanged = true;
553
559
 
554
560
  // doing some gc - clean up previous cache fields
555
- this.deleteBlockFields(blockId, 'prodOutputPrevious', 'prodCtxPrevious', 'prodUiCtxPrevious');
561
+ this.deleteBlockFields(blockId, "prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious");
556
562
 
557
563
  return true;
558
564
  } else {
559
565
  // reset - clean up any partial/inconsistent production stat
560
566
  return this.deleteBlockFields(
561
567
  blockId,
562
- 'prodOutput',
563
- 'prodCtx',
564
- 'prodUiCtx',
565
- 'prodArgs',
566
- 'prodOutputPrevious',
567
- 'prodCtxPrevious',
568
- 'prodUiCtxPrevious',
568
+ "prodOutput",
569
+ "prodCtx",
570
+ "prodUiCtx",
571
+ "prodArgs",
572
+ "prodOutputPrevious",
573
+ "prodCtxPrevious",
574
+ "prodUiCtxPrevious",
569
575
  );
570
576
  }
571
577
  }
@@ -595,7 +601,11 @@ export class ProjectMutator {
595
601
  * @param rawStorageJson Raw storage as JSON string
596
602
  */
597
603
  public setBlockStorageRaw(blockId: string, rawStorageJson: string): void {
598
- this.setBlockFieldObj(blockId, 'blockStorage', this.createJsonFieldValueByContent(rawStorageJson));
604
+ this.setBlockFieldObj(
605
+ blockId,
606
+ "blockStorage",
607
+ this.createJsonFieldValueByContent(rawStorageJson),
608
+ );
599
609
  this.blocksWithChangedInputs.add(blockId);
600
610
  this.updateLastModified();
601
611
  }
@@ -613,7 +623,7 @@ export class ProjectMutator {
613
623
  const blockConfig = info.config;
614
624
 
615
625
  if (blockConfig.modelAPIVersion !== 2) {
616
- throw new Error('resetToInitialStorage is only supported for model API version 2');
626
+ throw new Error("resetToInitialStorage is only supported for model API version 2");
617
627
  }
618
628
 
619
629
  // Get initial storage from VM
@@ -621,16 +631,26 @@ export class ProjectMutator {
621
631
  this.setBlockStorageRaw(blockId, initialStorageJson);
622
632
 
623
633
  // Derive args from storage - set or clear currentArgs based on derivation result
624
- const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, initialStorageJson);
634
+ const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(
635
+ blockConfig,
636
+ initialStorageJson,
637
+ );
625
638
  if (!deriveArgsResult.error) {
626
- this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValue(deriveArgsResult.value));
639
+ this.setBlockFieldObj(
640
+ blockId,
641
+ "currentArgs",
642
+ this.createJsonFieldValue(deriveArgsResult.value),
643
+ );
627
644
  // Derive prerunArgs from storage
628
- const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, initialStorageJson);
645
+ const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(
646
+ blockConfig,
647
+ initialStorageJson,
648
+ );
629
649
  if (prerunArgs !== undefined) {
630
- this.setBlockFieldObj(blockId, 'currentPrerunArgs', this.createJsonFieldValue(prerunArgs));
650
+ this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
631
651
  }
632
652
  } else {
633
- this.deleteBlockFields(blockId, 'currentArgs');
653
+ this.deleteBlockFields(blockId, "currentArgs");
634
654
  }
635
655
  }
636
656
 
@@ -646,7 +666,9 @@ export class ProjectMutator {
646
666
  // modelAPIVersion === 2 means BlockModelV3 with .args() lambda for deriving args
647
667
 
648
668
  if (req.modelAPIVersion !== blockConfig.modelAPIVersion) {
649
- throw new Error(`Model API version mismatch for block ${req.blockId}: ${req.modelAPIVersion} !== ${blockConfig.modelAPIVersion}`);
669
+ throw new Error(
670
+ `Model API version mismatch for block ${req.blockId}: ${req.modelAPIVersion} !== ${blockConfig.modelAPIVersion}`,
671
+ );
650
672
  }
651
673
 
652
674
  // Derive args from storage using the block's config.args() callback
@@ -666,21 +688,31 @@ export class ProjectMutator {
666
688
  req.payload,
667
689
  );
668
690
 
669
- this.setBlockFieldObj(req.blockId, 'blockStorage', this.createJsonFieldValueByContent(updatedStorageJson));
691
+ this.setBlockFieldObj(
692
+ req.blockId,
693
+ "blockStorage",
694
+ this.createJsonFieldValueByContent(updatedStorageJson),
695
+ );
670
696
 
671
697
  // Derive args directly from storage (VM extracts data internally)
672
- const derivedArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, updatedStorageJson);
698
+ const derivedArgsResult = this.projectHelper.deriveArgsFromStorage(
699
+ blockConfig,
700
+ updatedStorageJson,
701
+ );
673
702
  if (derivedArgsResult.error) {
674
703
  args = undefined;
675
704
  prerunArgs = undefined;
676
705
  } else {
677
706
  args = derivedArgsResult.value;
678
707
  // Derive prerunArgs from storage, or fall back to args
679
- prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, updatedStorageJson);
708
+ prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(
709
+ blockConfig,
710
+ updatedStorageJson,
711
+ );
680
712
  }
681
713
  } else {
682
- this.setBlockFieldObj(req.blockId, 'blockStorage', this.createJsonFieldValue(req.state));
683
- if (req.state !== null && typeof req.state === 'object' && 'args' in req.state) {
714
+ this.setBlockFieldObj(req.blockId, "blockStorage", this.createJsonFieldValue(req.state));
715
+ if (req.state !== null && typeof req.state === "object" && "args" in req.state) {
684
716
  args = (req.state as { args: unknown }).args;
685
717
  } else {
686
718
  args = req.state;
@@ -693,9 +725,9 @@ export class ProjectMutator {
693
725
  if (args !== undefined) {
694
726
  const currentArgsData = canonicalJsonBytes(args);
695
727
  const argsPartRef = this.tx.createValue(Pl.JsonObject, currentArgsData);
696
- this.setBlockField(req.blockId, 'currentArgs', argsPartRef, 'Ready', currentArgsData);
728
+ this.setBlockField(req.blockId, "currentArgs", argsPartRef, "Ready", currentArgsData);
697
729
  } else {
698
- this.deleteBlockFields(req.blockId, 'currentArgs');
730
+ this.deleteBlockFields(req.blockId, "currentArgs");
699
731
  }
700
732
 
701
733
  // Set currentPrerunArgs field and check if it actually changed
@@ -704,11 +736,20 @@ export class ProjectMutator {
704
736
  const prerunArgsData = canonicalJsonBytes(prerunArgs);
705
737
  const oldPrerunArgsData = info.fields.currentPrerunArgs?.value;
706
738
  // Check if prerunArgs actually changed
707
- if (oldPrerunArgsData === undefined || Buffer.compare(oldPrerunArgsData, prerunArgsData) !== 0) {
739
+ if (
740
+ oldPrerunArgsData === undefined ||
741
+ Buffer.compare(oldPrerunArgsData, prerunArgsData) !== 0
742
+ ) {
708
743
  prerunArgsChanged = true;
709
744
  }
710
745
  const prerunArgsRef = this.tx.createValue(Pl.JsonObject, prerunArgsData);
711
- this.setBlockField(req.blockId, 'currentPrerunArgs', prerunArgsRef, 'Ready', prerunArgsData);
746
+ this.setBlockField(
747
+ req.blockId,
748
+ "currentPrerunArgs",
749
+ prerunArgsRef,
750
+ "Ready",
751
+ prerunArgsData,
752
+ );
712
753
  } else {
713
754
  // prerunArgs is undefined - check if we previously had one
714
755
  if (info.fields.currentPrerunArgs !== undefined) {
@@ -730,13 +771,13 @@ export class ProjectMutator {
730
771
  }
731
772
 
732
773
  // resetting staging outputs for all downstream blocks
733
- this.getStagingGraph().traverse('downstream', changedArgs, ({ id }) => this.resetStaging(id));
774
+ this.getStagingGraph().traverse("downstream", changedArgs, ({ id }) => this.resetStaging(id));
734
775
 
735
776
  if (somethingChanged) this.updateLastModified();
736
777
  }
737
778
 
738
779
  public setBlockSettings(blockId: string, newValue: BlockSettings): void {
739
- this.setBlockFieldObj(blockId, 'blockSettings', this.createJsonFieldValue(newValue));
780
+ this.setBlockFieldObj(blockId, "blockSettings", this.createJsonFieldValue(newValue));
740
781
  this.updateLastModified();
741
782
  }
742
783
 
@@ -744,9 +785,9 @@ export class ProjectMutator {
744
785
  const upstreamContexts: AnyRef[] = [];
745
786
  upstream.forEach((id) => {
746
787
  const info = this.getBlockInfo(id);
747
- if (info.fields['prodCtx']?.ref === undefined)
748
- throw new Error('One of the upstreams staging is not rendered.');
749
- upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));
788
+ if (info.fields["prodCtx"]?.ref === undefined)
789
+ throw new Error("One of the upstreams staging is not rendered.");
790
+ upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["prodCtx"].ref));
750
791
  });
751
792
  return createBContextFromUpstreams(this.tx, upstreamContexts);
752
793
  }
@@ -755,11 +796,11 @@ export class ProjectMutator {
755
796
  const upstreamContexts: AnyRef[] = [];
756
797
  upstream.forEach((id) => {
757
798
  const info = this.getBlockInfo(id);
758
- if (info.fields['stagingCtx']?.ref === undefined)
759
- throw new Error('One of the upstreams staging is not rendered.');
760
- upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['stagingCtx'].ref));
761
- if (info.fields['prodCtx']?.ref !== undefined)
762
- upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields['prodCtx'].ref));
799
+ if (info.fields["stagingCtx"]?.ref === undefined)
800
+ throw new Error("One of the upstreams staging is not rendered.");
801
+ upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["stagingCtx"].ref));
802
+ if (info.fields["prodCtx"]?.ref !== undefined)
803
+ upstreamContexts.push(Pl.unwrapHolder(this.tx, info.fields["prodCtx"].ref));
763
804
  });
764
805
  return createBContextFromUpstreams(this.tx, upstreamContexts);
765
806
  }
@@ -785,7 +826,7 @@ export class ProjectMutator {
785
826
 
786
827
  const ctx = this.createStagingCtx(this.getStagingGraph().nodes.get(blockId)!.upstream);
787
828
 
788
- if (this.getBlock(blockId).renderingMode !== 'Heavy') throw new Error('not supported yet');
829
+ if (this.getBlock(blockId).renderingMode !== "Heavy") throw new Error("not supported yet");
789
830
 
790
831
  const tpl = info.getTemplate(this.tx);
791
832
 
@@ -800,17 +841,12 @@ export class ProjectMutator {
800
841
  // Here we set the staging ctx to the input context of the staging workflow, not the output because exports
801
842
  // of one staging context should stay within the same block, and not travel downstream.
802
843
  // We may change this decision in the future if wanted to support traveling staging exports downstream.
803
- this.setBlockField(
804
- blockId,
805
- 'stagingCtx',
806
- Pl.wrapInEphHolder(this.tx, ctx),
807
- 'NotReady',
808
- );
844
+ this.setBlockField(blockId, "stagingCtx", Pl.wrapInEphHolder(this.tx, ctx), "NotReady");
809
845
 
810
846
  // Yet the staging UI Ctx is the output context of the staging workflow, because it is used to form the result pool
811
847
  // thus creating a certain discrepancy between staging workflow context behavior and desktop's result pool.
812
- this.setBlockField(blockId, 'stagingUiCtx', this.exportCtx(results.context), 'NotReady');
813
- this.setBlockField(blockId, 'stagingOutput', results.result, 'NotReady');
848
+ this.setBlockField(blockId, "stagingUiCtx", this.exportCtx(results.context), "NotReady");
849
+ this.setBlockField(blockId, "stagingOutput", results.result, "NotReady");
814
850
  }
815
851
 
816
852
  private renderProductionFor(blockId: string) {
@@ -825,8 +861,8 @@ export class ProjectMutator {
825
861
 
826
862
  const ctx = this.createProdCtx(this.getPendingProductionGraph().nodes.get(blockId)!.upstream);
827
863
 
828
- if (this.getBlock(blockId).renderingMode === 'Light')
829
- throw new Error('Can\'t render production for light block.');
864
+ if (this.getBlock(blockId).renderingMode === "Light")
865
+ throw new Error("Can't render production for light block.");
830
866
 
831
867
  const tpl = info.getTemplate(this.tx);
832
868
 
@@ -838,15 +874,15 @@ export class ProjectMutator {
838
874
  });
839
875
  this.setBlockField(
840
876
  blockId,
841
- 'prodCtx',
877
+ "prodCtx",
842
878
  Pl.wrapInEphHolder(this.tx, results.context),
843
- 'NotReady',
879
+ "NotReady",
844
880
  );
845
- this.setBlockField(blockId, 'prodUiCtx', this.exportCtx(results.context), 'NotReady');
846
- this.setBlockField(blockId, 'prodOutput', results.result, 'NotReady');
881
+ this.setBlockField(blockId, "prodUiCtx", this.exportCtx(results.context), "NotReady");
882
+ this.setBlockField(blockId, "prodOutput", results.result, "NotReady");
847
883
 
848
884
  // saving inputs for which we rendered the production
849
- this.setBlockFieldObj(blockId, 'prodArgs', info.fields.currentArgs);
885
+ this.setBlockFieldObj(blockId, "prodArgs", info.fields.currentArgs);
850
886
 
851
887
  // removing block from limbo as we juts rendered fresh production for it
852
888
  if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;
@@ -857,17 +893,22 @@ export class ProjectMutator {
857
893
  //
858
894
 
859
895
  private initializeNewBlock(blockId: string, spec: NewBlockSpec): void {
860
- const info = new BlockInfo(blockId, {}, extractConfig(spec.blockPack.config), spec.blockPack.source);
896
+ const info = new BlockInfo(
897
+ blockId,
898
+ {},
899
+ extractConfig(spec.blockPack.config),
900
+ spec.blockPack.source,
901
+ );
861
902
  this.blockInfos.set(blockId, info);
862
903
 
863
904
  // block pack
864
905
  const bp = createBlockPack(this.tx, spec.blockPack);
865
- this.setBlockField(blockId, 'blockPack', Pl.wrapInHolder(this.tx, bp), 'NotReady');
906
+ this.setBlockField(blockId, "blockPack", Pl.wrapInHolder(this.tx, bp), "NotReady");
866
907
 
867
908
  // settings
868
909
  this.setBlockFieldObj(
869
910
  blockId,
870
- 'blockSettings',
911
+ "blockSettings",
871
912
  this.createJsonFieldValue(InitialBlockSettings),
872
913
  );
873
914
 
@@ -877,12 +918,15 @@ export class ProjectMutator {
877
918
  let prerunArgs: unknown;
878
919
  let storageToWrite: string;
879
920
 
880
- if (spec.storageMode === 'fromModel') {
921
+ if (spec.storageMode === "fromModel") {
881
922
  // Model API v2+: get initial storage and derive args from it
882
923
  storageToWrite = this.projectHelper.getInitialStorageInVM(blockConfig);
883
924
 
884
925
  // Derive args directly from storage (VM extracts data internally)
885
- const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(blockConfig, storageToWrite);
926
+ const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(
927
+ blockConfig,
928
+ storageToWrite,
929
+ );
886
930
  if (deriveArgsResult.error) {
887
931
  args = undefined;
888
932
  prerunArgs = undefined;
@@ -890,12 +934,12 @@ export class ProjectMutator {
890
934
  args = deriveArgsResult.value;
891
935
  prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(blockConfig, storageToWrite);
892
936
  }
893
- } else if (spec.storageMode === 'legacy') {
937
+ } else if (spec.storageMode === "legacy") {
894
938
  // Model API v1: use legacyState from spec
895
939
  const parsedState = JSON.parse(spec.legacyState);
896
940
  args = parsedState.args;
897
941
  if (args === undefined) {
898
- throw new Error('args is undefined in legacyState');
942
+ throw new Error("args is undefined in legacyState");
899
943
  }
900
944
  prerunArgs = args;
901
945
  storageToWrite = spec.legacyState;
@@ -905,57 +949,59 @@ export class ProjectMutator {
905
949
 
906
950
  // currentArgs
907
951
  if (args !== undefined) {
908
- this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValue(args));
952
+ this.setBlockFieldObj(blockId, "currentArgs", this.createJsonFieldValue(args));
909
953
  }
910
954
 
911
955
  // currentPrerunArgs
912
956
  if (prerunArgs !== undefined) {
913
- this.setBlockFieldObj(blockId, 'currentPrerunArgs', this.createJsonFieldValue(prerunArgs));
957
+ this.setBlockFieldObj(blockId, "currentPrerunArgs", this.createJsonFieldValue(prerunArgs));
914
958
  }
915
959
 
916
960
  // blockStorage
917
- this.setBlockFieldObj(blockId, 'blockStorage', this.createJsonFieldValueByContent(storageToWrite));
961
+ this.setBlockFieldObj(
962
+ blockId,
963
+ "blockStorage",
964
+ this.createJsonFieldValueByContent(storageToWrite),
965
+ );
918
966
 
919
967
  // checking structure
920
968
  info.check();
921
969
  }
922
970
 
923
- private getFieldNamesToDuplicate(blockId: string): Set<ProjectField['fieldName']> {
971
+ private getFieldNamesToDuplicate(blockId: string): Set<ProjectField["fieldName"]> {
924
972
  const fields = this.getBlockInfo(blockId).fields;
925
973
 
926
- const diff = <T>(setA: Set<T>, setB: Set<T>): Set<T> => new Set([...setA].filter((x) => !setB.has(x)));
974
+ const diff = <T>(setA: Set<T>, setB: Set<T>): Set<T> =>
975
+ new Set([...setA].filter((x) => !setB.has(x)));
927
976
 
928
977
  // Check if we can safely move to limbo (both core production fields are ready)
929
- if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready') {
978
+ if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready") {
930
979
  if (this.blocksInLimbo.has(blockId))
931
980
  // we are already in limbo
932
981
  return FieldsToDuplicate;
933
982
 
934
- return diff(FieldsToDuplicate, new Set([
935
- 'prodOutputPrevious',
936
- 'prodCtxPrevious',
937
- 'prodUiCtxPrevious',
938
- ]));
983
+ return diff(
984
+ FieldsToDuplicate,
985
+ new Set(["prodOutputPrevious", "prodCtxPrevious", "prodUiCtxPrevious"]),
986
+ );
939
987
  } else {
940
- return diff(FieldsToDuplicate, new Set([
941
- 'prodOutput',
942
- 'prodCtx',
943
- 'prodUiCtx',
944
- 'prodArgs',
945
- 'prodOutputPrevious',
946
- 'prodCtxPrevious',
947
- 'prodUiCtxPrevious',
948
- ]));
988
+ return diff(
989
+ FieldsToDuplicate,
990
+ new Set([
991
+ "prodOutput",
992
+ "prodCtx",
993
+ "prodUiCtx",
994
+ "prodArgs",
995
+ "prodOutputPrevious",
996
+ "prodCtxPrevious",
997
+ "prodUiCtxPrevious",
998
+ ]),
999
+ );
949
1000
  }
950
1001
  }
951
1002
 
952
1003
  private initializeBlockDuplicate(blockId: string, originalBlockInfo: BlockInfo) {
953
- const info = new BlockInfo(
954
- blockId,
955
- {},
956
- originalBlockInfo.config,
957
- originalBlockInfo.source,
958
- );
1004
+ const info = new BlockInfo(blockId, {}, originalBlockInfo.config, originalBlockInfo.source);
959
1005
 
960
1006
  this.blockInfos.set(blockId, info);
961
1007
 
@@ -963,7 +1009,11 @@ export class ProjectMutator {
963
1009
 
964
1010
  // Copy all fields from original block to new block by sharing references
965
1011
  for (const [fieldName, fieldState] of Object.entries(originalBlockInfo.fields)) {
966
- if (fieldNamesToDuplicate.has(fieldName as ProjectField['fieldName']) && fieldState && fieldState.ref) {
1012
+ if (
1013
+ fieldNamesToDuplicate.has(fieldName as ProjectField["fieldName"]) &&
1014
+ fieldState &&
1015
+ fieldState.ref
1016
+ ) {
967
1017
  this.setBlockFieldObj(blockId, fieldName as keyof BlockFieldStates, {
968
1018
  ref: fieldState.ref,
969
1019
  status: fieldState.status,
@@ -992,7 +1042,7 @@ export class ProjectMutator {
992
1042
  // removing blocks
993
1043
  for (const blockId of stagingDiff.onlyInA) {
994
1044
  const { fields } = this.getBlockInfo(blockId);
995
- this.deleteBlockFields(blockId, ...(Object.keys(fields) as ProjectField['fieldName'][]));
1045
+ this.deleteBlockFields(blockId, ...(Object.keys(fields) as ProjectField["fieldName"][]));
996
1046
  this.blockInfos.delete(blockId);
997
1047
  if (this.blocksInLimbo.delete(blockId)) this.renderingStateChanged = true;
998
1048
  }
@@ -1006,23 +1056,22 @@ export class ProjectMutator {
1006
1056
  for (const blockId of stagingDiff.different) this.resetStaging(blockId);
1007
1057
 
1008
1058
  // new actual production graph without new blocks
1009
- const newActualProductionGraph = productionGraph(
1010
- newStructure,
1011
- (blockId) => this.getProductionGraphBlockInfo(blockId, true),
1059
+ const newActualProductionGraph = productionGraph(newStructure, (blockId) =>
1060
+ this.getProductionGraphBlockInfo(blockId, true),
1012
1061
  );
1013
1062
 
1014
1063
  const prodDiff = graphDiff(currentActualProductionGraph, newActualProductionGraph);
1015
1064
 
1016
1065
  // applying changes due to topology change in production to affected nodes and
1017
1066
  // all their downstreams
1018
- currentActualProductionGraph.traverse('downstream', [...prodDiff.different], (node) => {
1067
+ currentActualProductionGraph.traverse("downstream", [...prodDiff.different], (node) => {
1019
1068
  this.resetOrLimboProduction(node.id);
1020
1069
  });
1021
1070
 
1022
1071
  if (
1023
- stagingDiff.onlyInB.size > 0
1024
- || stagingDiff.onlyInA.size > 0
1025
- || stagingDiff.different.size > 0
1072
+ stagingDiff.onlyInB.size > 0 ||
1073
+ stagingDiff.onlyInA.size > 0 ||
1074
+ stagingDiff.different.size > 0
1026
1075
  )
1027
1076
  this.resetStagingRefreshTimestamp();
1028
1077
 
@@ -1056,7 +1105,7 @@ export class ProjectMutator {
1056
1105
  if (!done) throw new Error(`Can't find element with id: ${before}`);
1057
1106
  }
1058
1107
  this.updateStructure(newStruct, (blockId) => {
1059
- if (blockId !== block.id) throw new Error('Unexpected');
1108
+ if (blockId !== block.id) throw new Error("Unexpected");
1060
1109
  this.initializeNewBlock(blockId, spec);
1061
1110
  });
1062
1111
  }
@@ -1099,7 +1148,7 @@ export class ProjectMutator {
1099
1148
  }
1100
1149
 
1101
1150
  this.updateStructure(newStruct, (blockId) => {
1102
- if (blockId !== newBlockId) throw new Error('Unexpected');
1151
+ if (blockId !== newBlockId) throw new Error("Unexpected");
1103
1152
  this.initializeBlockDuplicate(blockId, originalBlockInfo);
1104
1153
  });
1105
1154
  }
@@ -1122,15 +1171,19 @@ export class ProjectMutator {
1122
1171
  // Block-pack migration
1123
1172
  //
1124
1173
 
1125
- public migrateBlockPack(blockId: string, spec: BlockPackSpecPrepared, newClearState?: ClearState): void {
1174
+ public migrateBlockPack(
1175
+ blockId: string,
1176
+ spec: BlockPackSpecPrepared,
1177
+ newClearState?: ClearState,
1178
+ ): void {
1126
1179
  const info = this.getBlockInfo(blockId);
1127
1180
  const newConfig = extractConfig(spec.config);
1128
1181
 
1129
1182
  this.setBlockField(
1130
1183
  blockId,
1131
- 'blockPack',
1184
+ "blockPack",
1132
1185
  Pl.wrapInHolder(this.tx, createBlockPack(this.tx, spec)),
1133
- 'NotReady',
1186
+ "NotReady",
1134
1187
  );
1135
1188
 
1136
1189
  if (newClearState !== undefined) {
@@ -1143,13 +1196,27 @@ export class ProjectMutator {
1143
1196
  this.setBlockStorageRaw(blockId, initialStorageJson);
1144
1197
 
1145
1198
  // Derive args from storage - only set currentArgs if derivation succeeds
1146
- const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(newConfig, initialStorageJson);
1199
+ const deriveArgsResult = this.projectHelper.deriveArgsFromStorage(
1200
+ newConfig,
1201
+ initialStorageJson,
1202
+ );
1147
1203
  if (!deriveArgsResult.error) {
1148
- this.setBlockFieldObj(blockId, 'currentArgs', this.createJsonFieldValue(deriveArgsResult.value));
1204
+ this.setBlockFieldObj(
1205
+ blockId,
1206
+ "currentArgs",
1207
+ this.createJsonFieldValue(deriveArgsResult.value),
1208
+ );
1149
1209
  // Derive prerunArgs from storage
1150
- const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(newConfig, initialStorageJson);
1210
+ const prerunArgs = this.projectHelper.derivePrerunArgsFromStorage(
1211
+ newConfig,
1212
+ initialStorageJson,
1213
+ );
1151
1214
  if (prerunArgs !== undefined) {
1152
- this.setBlockFieldObj(blockId, 'currentPrerunArgs', this.createJsonFieldValue(prerunArgs));
1215
+ this.setBlockFieldObj(
1216
+ blockId,
1217
+ "currentPrerunArgs",
1218
+ this.createJsonFieldValue(prerunArgs),
1219
+ );
1153
1220
  }
1154
1221
  }
1155
1222
  this.blocksWithChangedInputs.add(blockId);
@@ -1166,26 +1233,33 @@ export class ProjectMutator {
1166
1233
  if (supportsStateMigrations) {
1167
1234
  const currentStorageJson = info.blockStorageJson;
1168
1235
 
1169
- const migrationResult = this.projectHelper.migrateStorageInVM(newConfig, currentStorageJson);
1236
+ const migrationResult = this.projectHelper.migrateStorageInVM(
1237
+ newConfig,
1238
+ currentStorageJson,
1239
+ );
1170
1240
 
1171
1241
  if (migrationResult.error !== undefined) {
1172
- console.error(`[migrateBlockPack] Block ${blockId} migration error: ${migrationResult.error}`);
1242
+ console.error(
1243
+ `[migrateBlockPack] Block ${blockId} migration error: ${migrationResult.error}`,
1244
+ );
1173
1245
  } else {
1174
1246
  console.log(`[migrateBlockPack] Block ${blockId}: ${migrationResult.info}`);
1175
1247
  if (migrationResult.warn) {
1176
- console.warn(`[migrateBlockPack] Block ${blockId} migration warning: ${migrationResult.warn}`);
1248
+ console.warn(
1249
+ `[migrateBlockPack] Block ${blockId} migration warning: ${migrationResult.warn}`,
1250
+ );
1177
1251
  }
1178
1252
  this.setBlockStorageRaw(blockId, migrationResult.newStorageJson);
1179
1253
  }
1180
1254
  }
1181
1255
 
1182
1256
  // resetting staging outputs for all downstream blocks
1183
- this.getStagingGraph().traverse('downstream', [blockId], ({ id }) => this.resetStaging(id));
1257
+ this.getStagingGraph().traverse("downstream", [blockId], ({ id }) => this.resetStaging(id));
1184
1258
  }
1185
1259
 
1186
1260
  // also reset or limbo all downstream productions
1187
1261
  if (info.productionRendered)
1188
- this.getActualProductionGraph().traverse('downstream', [blockId], ({ id }) =>
1262
+ this.getActualProductionGraph().traverse("downstream", [blockId], ({ id }) =>
1189
1263
  this.resetOrLimboProduction(id),
1190
1264
  );
1191
1265
 
@@ -1202,16 +1276,17 @@ export class ProjectMutator {
1202
1276
  const prodGraph = this.getPendingProductionGraph();
1203
1277
  if (addUpstreams)
1204
1278
  // adding all upstreams automatically
1205
- prodGraph.traverse('upstream', blockIds, (node) => {
1279
+ prodGraph.traverse("upstream", blockIds, (node) => {
1206
1280
  blockIdsSet.add(node.id);
1207
1281
  });
1208
- else // checking that targets contain all upstreams
1282
+ else
1283
+ // checking that targets contain all upstreams
1209
1284
  for (const blockId of blockIdsSet) {
1210
1285
  const node = prodGraph.nodes.get(blockId);
1211
1286
  if (node === undefined) throw new Error(`Can't find block with id: ${blockId}`);
1212
1287
  for (const upstream of node.upstream)
1213
1288
  if (!blockIdsSet.has(upstream))
1214
- throw new Error('Can\'t render blocks not including all upstreams.');
1289
+ throw new Error("Can't render blocks not including all upstreams.");
1215
1290
  }
1216
1291
 
1217
1292
  // traversing in topological order and rendering target blocks
@@ -1219,8 +1294,8 @@ export class ProjectMutator {
1219
1294
  for (const block of allBlocks(this.structure)) {
1220
1295
  if (!blockIdsSet.has(block.id)) continue;
1221
1296
 
1222
- let render
1223
- = this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);
1297
+ let render =
1298
+ this.getBlockInfo(block.id).requireProductionRendering || this.blocksInLimbo.has(block.id);
1224
1299
 
1225
1300
  if (!render)
1226
1301
  for (const upstream of prodGraph.nodes.get(block.id)!.upstream)
@@ -1238,7 +1313,7 @@ export class ProjectMutator {
1238
1313
  const renderedArray = [...rendered];
1239
1314
 
1240
1315
  // sending to limbo all downstream blocks
1241
- prodGraph.traverse('downstream', renderedArray, (node) => {
1316
+ prodGraph.traverse("downstream", renderedArray, (node) => {
1242
1317
  if (rendered.has(node.id))
1243
1318
  // don't send to limbo blocks that were just rendered
1244
1319
  return;
@@ -1246,7 +1321,7 @@ export class ProjectMutator {
1246
1321
  });
1247
1322
 
1248
1323
  // resetting staging outputs for all downstream blocks
1249
- this.getStagingGraph().traverse('downstream', renderedArray, ({ id }) => {
1324
+ this.getStagingGraph().traverse("downstream", renderedArray, ({ id }) => {
1250
1325
  // don't reset staging of the first rendered block
1251
1326
  if (renderedArray[0] !== id) this.resetStaging(id);
1252
1327
  });
@@ -1270,16 +1345,16 @@ export class ProjectMutator {
1270
1345
  const blockId = queue.shift()!;
1271
1346
  const fields = this.getBlockInfo(blockId).fields;
1272
1347
 
1273
- if (fields.prodOutput?.status === 'Ready' && fields.prodCtx?.status === 'Ready')
1348
+ if (fields.prodOutput?.status === "Ready" && fields.prodCtx?.status === "Ready")
1274
1349
  // skipping finished blocks
1275
1350
  continue;
1276
1351
 
1277
- if (this.deleteBlockFields(blockId, 'prodOutput', 'prodCtx', 'prodUiCtx', 'prodArgs')) {
1352
+ if (this.deleteBlockFields(blockId, "prodOutput", "prodCtx", "prodUiCtx", "prodArgs")) {
1278
1353
  // was actually stopped
1279
1354
  stopped.push(blockId);
1280
1355
 
1281
1356
  // will try to stop all its downstreams
1282
- for (const downstream of activeProdGraph.traverseIdsExcludingRoots('downstream', blockId)) {
1357
+ for (const downstream of activeProdGraph.traverseIdsExcludingRoots("downstream", blockId)) {
1283
1358
  if (queued.has(downstream)) continue;
1284
1359
  queue.push(downstream);
1285
1360
  queued.add(downstream);
@@ -1288,11 +1363,11 @@ export class ProjectMutator {
1288
1363
  }
1289
1364
 
1290
1365
  // blocks under stopped blocks, but having finished production results, goes to limbo
1291
- for (const blockId of activeProdGraph.traverseIdsExcludingRoots('downstream', ...stopped))
1366
+ for (const blockId of activeProdGraph.traverseIdsExcludingRoots("downstream", ...stopped))
1292
1367
  this.resetOrLimboProduction(blockId);
1293
1368
 
1294
1369
  // reset staging outputs for all downstream blocks
1295
- this.getStagingGraph().traverse('downstream', stopped, ({ id }) => this.resetStaging(id));
1370
+ this.getStagingGraph().traverse("downstream", stopped, ({ id }) => this.resetStaging(id));
1296
1371
  }
1297
1372
 
1298
1373
  private traverseWithStagingLag(cb: (blockId: string, lag: number) => void) {
@@ -1319,8 +1394,8 @@ export class ProjectMutator {
1319
1394
  /** @param stagingRenderingRate rate in blocks per second */
1320
1395
  private refreshStagings(stagingRenderingRate?: number) {
1321
1396
  const elapsed = Date.now() - this.renderingState.stagingRefreshTimestamp;
1322
- const lagThreshold
1323
- = stagingRenderingRate === undefined
1397
+ const lagThreshold =
1398
+ stagingRenderingRate === undefined
1324
1399
  ? undefined
1325
1400
  : 1 + Math.max(0, (elapsed * stagingRenderingRate) / 1000);
1326
1401
  let rendered = 0;
@@ -1357,24 +1432,24 @@ export class ProjectMutator {
1357
1432
  this.refreshStagings(stagingRenderingRate);
1358
1433
  this.blockInfos.forEach((blockInfo) => {
1359
1434
  if (
1360
- blockInfo.fields.prodCtx?.status === 'Ready'
1361
- && blockInfo.fields.prodOutput?.status === 'Ready'
1435
+ blockInfo.fields.prodCtx?.status === "Ready" &&
1436
+ blockInfo.fields.prodOutput?.status === "Ready"
1362
1437
  )
1363
1438
  this.deleteBlockFields(
1364
1439
  blockInfo.id,
1365
- 'prodOutputPrevious',
1366
- 'prodCtxPrevious',
1367
- 'prodUiCtxPrevious',
1440
+ "prodOutputPrevious",
1441
+ "prodCtxPrevious",
1442
+ "prodUiCtxPrevious",
1368
1443
  );
1369
1444
  if (
1370
- blockInfo.fields.stagingCtx?.status === 'Ready'
1371
- && blockInfo.fields.stagingOutput?.status === 'Ready'
1445
+ blockInfo.fields.stagingCtx?.status === "Ready" &&
1446
+ blockInfo.fields.stagingOutput?.status === "Ready"
1372
1447
  )
1373
1448
  this.deleteBlockFields(
1374
1449
  blockInfo.id,
1375
- 'stagingOutputPrevious',
1376
- 'stagingCtxPrevious',
1377
- 'stagingUiCtxPrevious',
1450
+ "stagingOutputPrevious",
1451
+ "stagingCtxPrevious",
1452
+ "stagingUiCtxPrevious",
1378
1453
  );
1379
1454
  });
1380
1455
  }
@@ -1463,41 +1538,42 @@ export class ProjectMutator {
1463
1538
  // (start of round-trip #2)
1464
1539
  //
1465
1540
 
1466
- const blockFieldRequests: [BlockInfoState, ProjectField['fieldName'], BlockFieldState, Promise<BasicResourceData | ResourceData>][] = [];
1541
+ const blockFieldRequests: [
1542
+ BlockInfoState,
1543
+ ProjectField["fieldName"],
1544
+ BlockFieldState,
1545
+ Promise<BasicResourceData | ResourceData>,
1546
+ ][] = [];
1467
1547
  blockInfoStates.forEach((info) => {
1468
1548
  const fields = info.fields;
1469
1549
  for (const [fName, state] of Object.entries(fields)) {
1470
1550
  if (state.ref === undefined) continue;
1471
1551
  if (!isResource(state.ref) || isResourceRef(state.ref))
1472
- throw new Error('unexpected behaviour');
1473
- const fieldName = fName as ProjectField['fieldName'];
1552
+ throw new Error("unexpected behaviour");
1553
+ const fieldName = fName as ProjectField["fieldName"];
1474
1554
  blockFieldRequests.push([
1475
- info, fieldName,
1476
- state, tx.getResourceData(state.ref, fieldName == 'blockPack')]);
1555
+ info,
1556
+ fieldName,
1557
+ state,
1558
+ tx.getResourceData(state.ref, fieldName == "blockPack"),
1559
+ ]);
1477
1560
  }
1478
1561
  });
1479
1562
 
1480
1563
  // loading jsons
1481
- const [
1482
- schema,
1483
- lastModified,
1484
- meta,
1485
- structure,
1486
- { stagingRefreshTimestamp, blocksInLimbo },
1487
- ] = await Promise.all([
1488
- schemaP,
1489
- lastModifiedP,
1490
- metaP,
1491
- structureP,
1492
- renderingStateP,
1493
- ]);
1564
+ const [schema, lastModified, meta, structure, { stagingRefreshTimestamp, blocksInLimbo }] =
1565
+ await Promise.all([schemaP, lastModifiedP, metaP, structureP, renderingStateP]);
1494
1566
 
1495
1567
  // Checking schema version of the project
1496
1568
  if (schema !== SchemaVersionCurrent) {
1497
1569
  if (Number(schema) < Number(SchemaVersionCurrent))
1498
- throw new UiError(`Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`);
1570
+ throw new UiError(
1571
+ `Can't perform this action on this project because it has older schema. Try (re)loading the project to update it.`,
1572
+ );
1499
1573
  else
1500
- throw new UiError(`Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`);
1574
+ throw new UiError(
1575
+ `Can't perform this action on this project because it has newer schema. Upgrade your desktop app to the latest version.`,
1576
+ );
1501
1577
  }
1502
1578
 
1503
1579
  //
@@ -1513,17 +1589,19 @@ export class ProjectMutator {
1513
1589
  for (const [info, fieldName, state, response] of blockFieldRequests) {
1514
1590
  const result = await response;
1515
1591
  state.value = result.data;
1516
- if (isNotNullResourceId(result.error)) state.status = 'Error';
1592
+ if (isNotNullResourceId(result.error)) state.status = "Error";
1517
1593
  else if (result.resourceReady || isNotNullResourceId(result.originalResourceId))
1518
- state.status = 'Ready';
1519
- else state.status = 'NotReady';
1594
+ state.status = "Ready";
1595
+ else state.status = "NotReady";
1520
1596
 
1521
1597
  // For block pack we need to traverse the ref field from the resource data
1522
- if (fieldName === 'blockPack') {
1598
+ if (fieldName === "blockPack") {
1523
1599
  const refField = (result as ResourceData).fields.find((f) => f.name === Pl.HolderRefField);
1524
- if (refField === undefined)
1525
- throw new Error('Block pack ref field is missing');
1526
- blockPackRequests.push([info, tx.getResourceData(ensureResourceIdNotNull(refField.value), false)]);
1600
+ if (refField === undefined) throw new Error("Block pack ref field is missing");
1601
+ blockPackRequests.push([
1602
+ info,
1603
+ tx.getResourceData(ensureResourceIdNotNull(refField.value), false),
1604
+ ]);
1527
1605
  }
1528
1606
  }
1529
1607
 
@@ -1557,7 +1635,7 @@ export class ProjectMutator {
1557
1635
  ctxExportTplHolder = Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec));
1558
1636
  tx.createField(
1559
1637
  field(rid, getServiceTemplateField(ctxExportTplEnvelope.hash)),
1560
- 'Dynamic',
1638
+ "Dynamic",
1561
1639
  ctxExportTplHolder,
1562
1640
  );
1563
1641
  }
@@ -1566,8 +1644,9 @@ export class ProjectMutator {
1566
1644
  const blocksInLimboSet = new Set(blocksInLimbo);
1567
1645
 
1568
1646
  const blockInfos = new Map<string, BlockInfo>();
1569
- blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) => blockInfos.set(id,
1570
- new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))));
1647
+ blockInfoStates.forEach(({ id, fields, blockConfig, blockPack }) =>
1648
+ blockInfos.set(id, new BlockInfo(id, fields, notEmpty(blockConfig), notEmpty(blockPack))),
1649
+ );
1571
1650
 
1572
1651
  // check consistency of project state
1573
1652
  const blockInStruct = new Set<string>();
@@ -1607,7 +1686,7 @@ export class ProjectMutator {
1607
1686
  export interface ProjectState {
1608
1687
  schema: string;
1609
1688
  structure: ProjectStructure;
1610
- renderingState: Omit<ProjectRenderingState, 'blocksInLimbo'>;
1689
+ renderingState: Omit<ProjectRenderingState, "blocksInLimbo">;
1611
1690
  blocksInLimbo: Set<string>;
1612
1691
  blockInfos: Map<string, BlockInfo>;
1613
1692
  }
@@ -1628,7 +1707,7 @@ export async function createProject(
1628
1707
  const ctxExportTplEnvelope = await getPreparedExportTemplateEnvelope();
1629
1708
  tx.createField(
1630
1709
  field(prj, getServiceTemplateField(ctxExportTplEnvelope.hash)),
1631
- 'Dynamic',
1710
+ "Dynamic",
1632
1711
  Pl.wrapInHolder(tx, loadTemplate(tx, ctxExportTplEnvelope.spec)),
1633
1712
  );
1634
1713
  return prj;
@@ -1653,17 +1732,21 @@ export async function withProjectAuthored<T>(
1653
1732
  ops: Partial<TxOps> = {},
1654
1733
  ): Promise<T> {
1655
1734
  if (txOrPl instanceof PlClient) {
1656
- return await txOrPl.withWriteTx('ProjectAction' + (ops.name ? `: ${ops.name}` : ''), async (tx) => {
1657
- const mut = await ProjectMutator.load(projectHelper, tx, rid, author);
1658
- const result = await cb(mut);
1659
- if (!mut.wasModified)
1660
- // skipping save and commit altogether if no modifications were actually made
1735
+ return await txOrPl.withWriteTx(
1736
+ "ProjectAction" + (ops.name ? `: ${ops.name}` : ""),
1737
+ async (tx) => {
1738
+ const mut = await ProjectMutator.load(projectHelper, tx, rid, author);
1739
+ const result = await cb(mut);
1740
+ if (!mut.wasModified)
1741
+ // skipping save and commit altogether if no modifications were actually made
1742
+ return result;
1743
+ mut.save();
1744
+ await tx.commit();
1745
+ if (getDebugFlags().logProjectMutationStat) console.log(JSON.stringify(tx.stat));
1661
1746
  return result;
1662
- mut.save();
1663
- await tx.commit();
1664
- if (getDebugFlags().logProjectMutationStat) console.log(JSON.stringify(tx.stat));
1665
- return result;
1666
- }, ops);
1747
+ },
1748
+ ops,
1749
+ );
1667
1750
  } else {
1668
1751
  const mut = await ProjectMutator.load(projectHelper, txOrPl, rid, author);
1669
1752
  const result = await cb(mut);