@milaboratories/pl-middle-layer 2.10.0 → 2.11.0

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 (181) hide show
  1. package/dist/block_registry/registry-v2-provider.cjs +8 -1
  2. package/dist/block_registry/registry-v2-provider.cjs.map +1 -1
  3. package/dist/block_registry/registry-v2-provider.d.ts.map +1 -1
  4. package/dist/block_registry/registry-v2-provider.js +8 -1
  5. package/dist/block_registry/registry-v2-provider.js.map +1 -1
  6. package/dist/index.cjs +25 -1
  7. package/dist/index.d.ts +12 -5
  8. package/dist/index.js +5 -3
  9. package/dist/js_render/bundle_bytecode_cache.cjs +6 -1
  10. package/dist/js_render/bundle_bytecode_cache.cjs.map +1 -1
  11. package/dist/js_render/bundle_bytecode_cache.js +6 -1
  12. package/dist/js_render/bundle_bytecode_cache.js.map +1 -1
  13. package/dist/js_render/column_registry.cjs +17 -0
  14. package/dist/js_render/column_registry.cjs.map +1 -1
  15. package/dist/js_render/column_registry.js +16 -1
  16. package/dist/js_render/column_registry.js.map +1 -1
  17. package/dist/js_render/computable_context.cjs +1 -1
  18. package/dist/js_render/computable_context.js +1 -1
  19. package/dist/js_render/context.cjs +3 -2
  20. package/dist/js_render/context.cjs.map +1 -1
  21. package/dist/js_render/context.js +3 -2
  22. package/dist/js_render/context.js.map +1 -1
  23. package/dist/js_render/index.cjs +1 -1
  24. package/dist/js_render/index.cjs.map +1 -1
  25. package/dist/js_render/index.js +1 -1
  26. package/dist/js_render/index.js.map +1 -1
  27. package/dist/js_render/service_injectors.cjs +2 -9
  28. package/dist/js_render/service_injectors.cjs.map +1 -1
  29. package/dist/js_render/service_injectors.js +2 -9
  30. package/dist/js_render/service_injectors.js.map +1 -1
  31. package/dist/middle_layer/block.cjs +48 -0
  32. package/dist/middle_layer/block.cjs.map +1 -1
  33. package/dist/middle_layer/block.js +51 -4
  34. package/dist/middle_layer/block.js.map +1 -1
  35. package/dist/middle_layer/block_pack_description.cjs +80 -0
  36. package/dist/middle_layer/block_pack_description.cjs.map +1 -0
  37. package/dist/middle_layer/block_pack_description.d.ts +36 -0
  38. package/dist/middle_layer/block_pack_description.d.ts.map +1 -0
  39. package/dist/middle_layer/block_pack_description.js +78 -0
  40. package/dist/middle_layer/block_pack_description.js.map +1 -0
  41. package/dist/middle_layer/build_stamp.cjs +1 -1
  42. package/dist/middle_layer/build_stamp.js +1 -1
  43. package/dist/middle_layer/index.cjs +11 -0
  44. package/dist/middle_layer/index.d.ts +8 -2
  45. package/dist/middle_layer/index.js +3 -1
  46. package/dist/middle_layer/legacy_project_holds.cjs +61 -0
  47. package/dist/middle_layer/legacy_project_holds.cjs.map +1 -0
  48. package/dist/middle_layer/legacy_project_holds.js +61 -0
  49. package/dist/middle_layer/legacy_project_holds.js.map +1 -0
  50. package/dist/middle_layer/middle_layer.cjs +22 -24
  51. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  52. package/dist/middle_layer/middle_layer.d.ts +13 -3
  53. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  54. package/dist/middle_layer/middle_layer.js +21 -23
  55. package/dist/middle_layer/middle_layer.js.map +1 -1
  56. package/dist/middle_layer/pool_columns.cjs +160 -0
  57. package/dist/middle_layer/pool_columns.cjs.map +1 -0
  58. package/dist/middle_layer/pool_columns.d.ts +59 -0
  59. package/dist/middle_layer/pool_columns.d.ts.map +1 -0
  60. package/dist/middle_layer/pool_columns.js +157 -0
  61. package/dist/middle_layer/pool_columns.js.map +1 -0
  62. package/dist/middle_layer/pool_frame.cjs +82 -0
  63. package/dist/middle_layer/pool_frame.cjs.map +1 -0
  64. package/dist/middle_layer/pool_frame.d.ts +37 -0
  65. package/dist/middle_layer/pool_frame.d.ts.map +1 -0
  66. package/dist/middle_layer/pool_frame.js +81 -0
  67. package/dist/middle_layer/pool_frame.js.map +1 -0
  68. package/dist/middle_layer/pool_table.cjs +66 -0
  69. package/dist/middle_layer/pool_table.cjs.map +1 -0
  70. package/dist/middle_layer/pool_table.d.ts +27 -0
  71. package/dist/middle_layer/pool_table.d.ts.map +1 -0
  72. package/dist/middle_layer/pool_table.js +66 -0
  73. package/dist/middle_layer/pool_table.js.map +1 -0
  74. package/dist/middle_layer/project.cjs +89 -23
  75. package/dist/middle_layer/project.cjs.map +1 -1
  76. package/dist/middle_layer/project.d.ts +70 -4
  77. package/dist/middle_layer/project.d.ts.map +1 -1
  78. package/dist/middle_layer/project.js +89 -22
  79. package/dist/middle_layer/project.js.map +1 -1
  80. package/dist/middle_layer/rich_column_query.cjs +180 -0
  81. package/dist/middle_layer/rich_column_query.cjs.map +1 -0
  82. package/dist/middle_layer/rich_column_query.d.ts +34 -0
  83. package/dist/middle_layer/rich_column_query.d.ts.map +1 -0
  84. package/dist/middle_layer/rich_column_query.js +176 -0
  85. package/dist/middle_layer/rich_column_query.js.map +1 -0
  86. package/dist/model/args.cjs +23 -0
  87. package/dist/model/args.cjs.map +1 -1
  88. package/dist/model/args.js +24 -2
  89. package/dist/model/args.js.map +1 -1
  90. package/dist/model/args_derivation.cjs +60 -2
  91. package/dist/model/args_derivation.cjs.map +1 -1
  92. package/dist/model/args_derivation.d.ts +73 -3
  93. package/dist/model/args_derivation.d.ts.map +1 -1
  94. package/dist/model/args_derivation.js +60 -3
  95. package/dist/model/args_derivation.js.map +1 -1
  96. package/dist/model/block_pack_spec.cjs.map +1 -1
  97. package/dist/model/block_pack_spec.d.ts +3 -3
  98. package/dist/model/block_pack_spec.d.ts.map +1 -1
  99. package/dist/model/block_pack_spec.js.map +1 -1
  100. package/dist/model/block_params_model.cjs +42 -0
  101. package/dist/model/block_params_model.cjs.map +1 -0
  102. package/dist/model/block_params_model.d.ts +45 -0
  103. package/dist/model/block_params_model.d.ts.map +1 -0
  104. package/dist/model/block_params_model.js +42 -0
  105. package/dist/model/block_params_model.js.map +1 -0
  106. package/dist/model/index.d.ts +3 -1
  107. package/dist/model/project_helper.cjs +50 -6
  108. package/dist/model/project_helper.cjs.map +1 -1
  109. package/dist/model/project_helper.d.ts +25 -1
  110. package/dist/model/project_helper.d.ts.map +1 -1
  111. package/dist/model/project_helper.js +51 -7
  112. package/dist/model/project_helper.js.map +1 -1
  113. package/dist/model/template_spec.d.ts +18 -0
  114. package/dist/model/template_spec.d.ts.map +1 -1
  115. package/dist/mutator/block-pack/block_pack.cjs +90 -3
  116. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  117. package/dist/mutator/block-pack/block_pack.d.ts +16 -0
  118. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  119. package/dist/mutator/block-pack/block_pack.js +91 -5
  120. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  121. package/dist/mutator/block-pack/required_capabilities.cjs +16 -0
  122. package/dist/mutator/block-pack/required_capabilities.cjs.map +1 -1
  123. package/dist/mutator/block-pack/required_capabilities.js +16 -1
  124. package/dist/mutator/block-pack/required_capabilities.js.map +1 -1
  125. package/dist/mutator/project.cjs +4 -0
  126. package/dist/mutator/project.cjs.map +1 -1
  127. package/dist/mutator/project.d.ts +1 -1
  128. package/dist/mutator/project.d.ts.map +1 -1
  129. package/dist/mutator/project.js +4 -0
  130. package/dist/mutator/project.js.map +1 -1
  131. package/dist/mutator/template/template_cache.cjs +8 -1
  132. package/dist/mutator/template/template_cache.cjs.map +1 -1
  133. package/dist/mutator/template/template_cache.d.ts +7 -3
  134. package/dist/mutator/template/template_cache.d.ts.map +1 -1
  135. package/dist/mutator/template/template_cache.js +8 -1
  136. package/dist/mutator/template/template_cache.js.map +1 -1
  137. package/package.json +9 -9
  138. package/src/block_registry/registry-v2-provider.test.ts +23 -0
  139. package/src/block_registry/registry-v2-provider.ts +11 -1
  140. package/src/index.ts +2 -0
  141. package/src/js_render/bundle_bytecode_cache.ts +15 -4
  142. package/src/js_render/column_registry.ts +24 -3
  143. package/src/js_render/context.ts +4 -3
  144. package/src/js_render/index.ts +3 -2
  145. package/src/js_render/service_injectors.ts +2 -11
  146. package/src/middle_layer/block.ts +61 -2
  147. package/src/middle_layer/block_pack_description.test.ts +235 -0
  148. package/src/middle_layer/block_pack_description.ts +143 -0
  149. package/src/middle_layer/index.ts +9 -1
  150. package/src/middle_layer/legacy_project_holds.test.ts +133 -0
  151. package/src/middle_layer/legacy_project_holds.ts +73 -0
  152. package/src/middle_layer/middle_layer.ts +27 -28
  153. package/src/middle_layer/pool_columns.test.ts +217 -0
  154. package/src/middle_layer/pool_columns.ts +250 -0
  155. package/src/middle_layer/pool_frame.test.ts +144 -0
  156. package/src/middle_layer/pool_frame.ts +127 -0
  157. package/src/middle_layer/pool_table.test.ts +182 -0
  158. package/src/middle_layer/pool_table.ts +98 -0
  159. package/src/middle_layer/project.ts +135 -32
  160. package/src/middle_layer/rich_column_query.test.ts +311 -0
  161. package/src/middle_layer/rich_column_query.ts +214 -0
  162. package/src/model/args.test.ts +23 -1
  163. package/src/model/args.ts +29 -1
  164. package/src/model/args_derivation.test.ts +129 -12
  165. package/src/model/args_derivation.ts +112 -8
  166. package/src/model/block_pack_spec.ts +3 -2
  167. package/src/model/block_params_model.test.ts +194 -0
  168. package/src/model/block_params_model.ts +117 -0
  169. package/src/model/index.ts +6 -0
  170. package/src/model/project_helper.ts +101 -20
  171. package/src/model/template_spec.ts +21 -0
  172. package/src/mutator/block-pack/block_pack.test.ts +10 -1
  173. package/src/mutator/block-pack/block_pack.ts +102 -2
  174. package/src/mutator/block-pack/block_pack_load.test.ts +52 -0
  175. package/src/mutator/block-pack/required_capabilities.ts +25 -0
  176. package/src/mutator/project-v3.test.ts +27 -16
  177. package/src/mutator/project.ts +5 -0
  178. package/src/mutator/template/template_cache.ts +26 -3
  179. package/src/pool/result_pool_markers.test.ts +47 -0
  180. package/src/test/block_packs.ts +12 -0
  181. package/src/test/fake_project.ts +33 -6
@@ -6,7 +6,7 @@ import { outputRef } from "../model/args";
6
6
  import { argsFingerprint } from "../model/args_derivation";
7
7
  import { ProjectHelper } from "../model/project_helper";
8
8
  import { blockArgsAuthorKey, projectFieldName } from "../model/project_model";
9
- import { TestBPPreparer } from "../test/block_packs";
9
+ import { prepareInstalled } from "../test/block_packs";
10
10
  import { createProject, ProjectMutator } from "./project";
11
11
  import type { AuthorMarker, BlockPackSpec } from "@milaboratories/pl-model-middle-layer";
12
12
  import { createBlockStorage } from "@platforma-sdk/model";
@@ -31,6 +31,9 @@ test("v3 blocks: basic test with unified state", async () => {
31
31
  const quickJs = await getQuickJS();
32
32
 
33
33
  await TestHelpers.withTempRoot(async (pl) => {
34
+ // Installed before any transaction opens: an open transaction cannot see it.
35
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
36
+ const installedBPSpecSumV3 = await prepareInstalled(pl, BPSpecSumV3);
34
37
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
35
38
  const prjRef = await createProject(tx);
36
39
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -46,7 +49,7 @@ test("v3 blocks: basic test with unified state", async () => {
46
49
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
47
50
  {
48
51
  storageMode: "fromModel",
49
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
52
+ blockPack: installedBPSpecEnterV3,
50
53
  },
51
54
  );
52
55
  // Set initial test data
@@ -79,7 +82,7 @@ test("v3 blocks: basic test with unified state", async () => {
79
82
  { id: "enter2", label: "Enter Numbers V3 #2", renderingMode: "Heavy" },
80
83
  {
81
84
  storageMode: "fromModel",
82
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
85
+ blockPack: installedBPSpecEnterV3,
83
86
  },
84
87
  );
85
88
  mut.setStates([
@@ -104,7 +107,7 @@ test("v3 blocks: basic test with unified state", async () => {
104
107
  { id: "sum1", label: "Sum Numbers V3", renderingMode: "Heavy" },
105
108
  {
106
109
  storageMode: "fromModel",
107
- blockPack: await TestBPPreparer.prepare(BPSpecSumV3),
110
+ blockPack: installedBPSpecSumV3,
108
111
  },
109
112
  );
110
113
  // Set sources to reference upstream blocks
@@ -164,6 +167,7 @@ test("v3 blocks: prerunArgs skip test", async () => {
164
167
  const quickJs = await getQuickJS();
165
168
 
166
169
  await TestHelpers.withTempRoot(async (pl) => {
170
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
167
171
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
168
172
  const prjRef = await createProject(tx);
169
173
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -178,7 +182,7 @@ test("v3 blocks: prerunArgs skip test", async () => {
178
182
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
179
183
  {
180
184
  storageMode: "fromModel",
181
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
185
+ blockPack: installedBPSpecEnterV3,
182
186
  },
183
187
  );
184
188
  // Set initial state: [3, 1, 2] - has one even number (2)
@@ -293,6 +297,7 @@ test("v3 blocks: migrateBlockPack preserves state and re-derives args and prerun
293
297
  const quickJs = await getQuickJS();
294
298
 
295
299
  await TestHelpers.withTempRoot(async (pl) => {
300
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
296
301
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
297
302
  const prjRef = await createProject(tx);
298
303
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -307,7 +312,7 @@ test("v3 blocks: migrateBlockPack preserves state and re-derives args and prerun
307
312
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
308
313
  {
309
314
  storageMode: "fromModel",
310
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
315
+ blockPack: installedBPSpecEnterV3,
311
316
  },
312
317
  );
313
318
  mut.setStates([
@@ -337,7 +342,7 @@ test("v3 blocks: migrateBlockPack preserves state and re-derives args and prerun
337
342
  // Call migrateBlockPack without newClearState (state-preserved path)
338
343
  await pl.withWriteTx("MigrateBlockPack", async (tx) => {
339
344
  const mut = await ProjectMutator.load(new ProjectHelper(quickJs), tx, prj);
340
- mut.migrateBlockPack("enter1", await TestBPPreparer.prepare(BPSpecEnterV3));
345
+ mut.migrateBlockPack("enter1", installedBPSpecEnterV3);
341
346
  mut.save();
342
347
  await tx.commit();
343
348
  });
@@ -365,6 +370,7 @@ test("v3 blocks: migrateBlockPack with storage migration re-derives args and pre
365
370
  const quickJs = await getQuickJS();
366
371
 
367
372
  await TestHelpers.withTempRoot(async (pl) => {
373
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
368
374
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
369
375
  const prjRef = await createProject(tx);
370
376
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -379,7 +385,7 @@ test("v3 blocks: migrateBlockPack with storage migration re-derives args and pre
379
385
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
380
386
  {
381
387
  storageMode: "fromModel",
382
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
388
+ blockPack: installedBPSpecEnterV3,
383
389
  },
384
390
  );
385
391
  mut.setStates([
@@ -405,7 +411,7 @@ test("v3 blocks: migrateBlockPack with storage migration re-derives args and pre
405
411
  // Call migrateBlockPack (state-preserved) — triggers v1→v2→v3 migration
406
412
  await pl.withWriteTx("MigrateBlockPack", async (tx) => {
407
413
  const mut = await ProjectMutator.load(new ProjectHelper(quickJs), tx, prj);
408
- mut.migrateBlockPack("enter1", await TestBPPreparer.prepare(BPSpecEnterV3));
414
+ mut.migrateBlockPack("enter1", installedBPSpecEnterV3);
409
415
  mut.save();
410
416
  await tx.commit();
411
417
  });
@@ -441,6 +447,7 @@ test("v3 blocks: resetToInitialStorage derives prerunArgs even when args() throw
441
447
  const quickJs = await getQuickJS();
442
448
 
443
449
  await TestHelpers.withTempRoot(async (pl) => {
450
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
444
451
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
445
452
  const prjRef = await createProject(tx);
446
453
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -455,7 +462,7 @@ test("v3 blocks: resetToInitialStorage derives prerunArgs even when args() throw
455
462
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
456
463
  {
457
464
  storageMode: "fromModel",
458
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
465
+ blockPack: installedBPSpecEnterV3,
459
466
  },
460
467
  );
461
468
  mut.setStates([
@@ -512,6 +519,7 @@ test("v3 blocks: migrateBlockPack assigns author marker", async () => {
512
519
  const quickJs = await getQuickJS();
513
520
 
514
521
  await TestHelpers.withTempRoot(async (pl) => {
522
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
515
523
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
516
524
  const prjRef = await createProject(tx);
517
525
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -526,7 +534,7 @@ test("v3 blocks: migrateBlockPack assigns author marker", async () => {
526
534
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
527
535
  {
528
536
  storageMode: "fromModel",
529
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
537
+ blockPack: installedBPSpecEnterV3,
530
538
  },
531
539
  );
532
540
  mut.setStates([
@@ -544,7 +552,7 @@ test("v3 blocks: migrateBlockPack assigns author marker", async () => {
544
552
  const testAuthor: AuthorMarker = { authorId: "test-author-123", localVersion: 1 };
545
553
  await pl.withWriteTx("MigrateWithAuthor", async (tx) => {
546
554
  const mut = await ProjectMutator.load(new ProjectHelper(quickJs), tx, prj, testAuthor);
547
- mut.migrateBlockPack("enter1", await TestBPPreparer.prepare(BPSpecEnterV3));
555
+ mut.migrateBlockPack("enter1", installedBPSpecEnterV3);
548
556
  mut.save();
549
557
  await tx.commit();
550
558
  });
@@ -568,6 +576,7 @@ test("v3 blocks: migrateBlockPack does not crash when args() returns undefined",
568
576
  const quickJs = await getQuickJS();
569
577
 
570
578
  await TestHelpers.withTempRoot(async (pl) => {
579
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
571
580
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
572
581
  const prjRef = await createProject(tx);
573
582
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -582,7 +591,7 @@ test("v3 blocks: migrateBlockPack does not crash when args() returns undefined",
582
591
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
583
592
  {
584
593
  storageMode: "fromModel",
585
- blockPack: await TestBPPreparer.prepare(BPSpecEnterV3),
594
+ blockPack: installedBPSpecEnterV3,
586
595
  },
587
596
  );
588
597
  mut.setStates([
@@ -600,7 +609,7 @@ test("v3 blocks: migrateBlockPack does not crash when args() returns undefined",
600
609
  // args() returns undefined (previously crashed inside createJsonFieldValue).
601
610
  await pl.withWriteTx("MigrateBlockPack", async (tx) => {
602
611
  const mut = await ProjectMutator.load(new ProjectHelper(quickJs), tx, prj);
603
- mut.migrateBlockPack("enter1", await TestBPPreparer.prepare(BPSpecEnterV3));
612
+ mut.migrateBlockPack("enter1", installedBPSpecEnterV3);
604
613
  mut.save();
605
614
  await tx.commit();
606
615
  });
@@ -629,6 +638,7 @@ test("v3 blocks: every args derivation records the errors found in the args, non
629
638
  const quickJs = await getQuickJS();
630
639
 
631
640
  await TestHelpers.withTempRoot(async (pl) => {
641
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
632
642
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
633
643
  const prjRef = await createProject(tx);
634
644
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -640,7 +650,7 @@ test("v3 blocks: every args derivation records the errors found in the args, non
640
650
  const mut = await ProjectMutator.load(new ProjectHelper(quickJs), tx, prj);
641
651
  mut.addBlock(
642
652
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
643
- { storageMode: "fromModel", blockPack: await TestBPPreparer.prepare(BPSpecEnterV3) },
653
+ { storageMode: "fromModel", blockPack: installedBPSpecEnterV3 },
644
654
  );
645
655
  mut.setStates([
646
656
  {
@@ -668,6 +678,7 @@ test("v3 blocks: args without an args errors record of their own are kept and ru
668
678
  const quickJs = await getQuickJS();
669
679
 
670
680
  await TestHelpers.withTempRoot(async (pl) => {
681
+ const installedBPSpecEnterV3 = await prepareInstalled(pl, BPSpecEnterV3);
671
682
  const prj = await pl.withWriteTx("CreatingProject", async (tx) => {
672
683
  const prjRef = await createProject(tx);
673
684
  tx.createField(field(tx.clientRoot, "prj"), "Dynamic", prjRef);
@@ -679,7 +690,7 @@ test("v3 blocks: args without an args errors record of their own are kept and ru
679
690
  const mut = await ProjectMutator.load(new ProjectHelper(quickJs), tx, prj);
680
691
  mut.addBlock(
681
692
  { id: "enter1", label: "Enter Numbers V3", renderingMode: "Heavy" },
682
- { storageMode: "fromModel", blockPack: await TestBPPreparer.prepare(BPSpecEnterV3) },
693
+ { storageMode: "fromModel", blockPack: installedBPSpecEnterV3 },
683
694
  );
684
695
  mut.setStates([
685
696
  {
@@ -721,6 +721,11 @@ export class ProjectMutator {
721
721
  return info;
722
722
  }
723
723
 
724
+ /** The model of the block's current pack, as this transaction sees it. */
725
+ public getBlockConfig(blockId: BlockId): BlockConfig {
726
+ return this.getBlockInfo(blockId).config;
727
+ }
728
+
724
729
  /** Create a plain JSON resource value from a JS object (no compression). */
725
730
  private createJsonFieldValue(obj: unknown): BlockFieldStateValue {
726
731
  const value = Buffer.from(JSON.stringify(obj));
@@ -32,7 +32,9 @@ import type {
32
32
  } from "@milaboratories/pl-model-backend";
33
33
  import { notEmpty } from "@milaboratories/ts-helpers";
34
34
  import type { BlockPackSpecPrepared } from "../../model";
35
- import type { TemplateSpecPrepared } from "../../model/template_spec";
35
+ import type { InstallablePackTemplate, TemplateSpecPrepared } from "../../model/template_spec";
36
+ import type { BlockPackPreparer } from "../block-pack/block_pack";
37
+ import { throwIfMissingServerCapabilities } from "../block-pack/required_capabilities";
36
38
  import { getDebugFlags } from "../../debug";
37
39
 
38
40
  export const TemplateCacheType = resourceType("TemplateCache", "1");
@@ -776,6 +778,12 @@ export async function loadTemplateCached(
776
778
  }
777
779
  }
778
780
 
781
+ type CacheBlockPackOptions = {
782
+ cacheResourceId?: SignedResourceId;
783
+ /** Loads registry and local packs. */
784
+ preparer?: BlockPackPreparer;
785
+ };
786
+
779
787
  /**
780
788
  * Pre-materialize a block pack's template via cache.
781
789
  * Returns a copy of the spec with the template replaced by a cached reference.
@@ -784,13 +792,28 @@ export async function loadTemplateCached(
784
792
  export async function cacheBlockPackTemplate(
785
793
  pl: PlClient,
786
794
  spec: BlockPackSpecPrepared,
787
- options?: { cacheResourceId?: SignedResourceId },
795
+ options?: CacheBlockPackOptions,
788
796
  ): Promise<BlockPackSpecPrepared> {
789
797
  if (spec.template.type === "cached") return spec;
790
798
 
791
- const resourceId = await loadTemplateCached(pl, spec.template, options);
799
+ const resourceId =
800
+ spec.template.type === "registry-pack" || spec.template.type === "local-pack"
801
+ ? await installPackOnClient(pl, spec.template, options)
802
+ : await loadTemplateCached(pl, spec.template, options);
792
803
  return {
793
804
  ...spec,
794
805
  template: { type: "cached", resourceId },
795
806
  };
796
807
  }
808
+
809
+ async function installPackOnClient(
810
+ pl: PlClient,
811
+ template: InstallablePackTemplate,
812
+ options?: CacheBlockPackOptions,
813
+ ): Promise<SignedResourceId> {
814
+ if (options?.preparer === undefined) throw new Error("BUG: a pack needs a preparer to load it");
815
+ const loaded = await options.preparer.loadPack(template);
816
+ // The manifest may predate the requiredCapabilities field: check what the pack declares.
817
+ throwIfMissingServerCapabilities(pl, loaded.requiredCapabilities);
818
+ return await loadTemplateCached(pl, loaded.template, options);
819
+ }
@@ -0,0 +1,47 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { RawPObjectCollection } from "./p_object_collection";
3
+ import { ResultPool } from "./result_pool";
4
+
5
+ /**
6
+ * The instability markers the result pool puts on a computable are read outside the middle layer:
7
+ * the MCP server parses `prod_not_locked:<blockId>` and `no_data:<blockId>:<export>` to tell which
8
+ * block above an output waits for (pl-mcp-server `upstreamOfMarker`). These tests pin both
9
+ * strings, so a rename fails here and not, silently, in the server's waits.
10
+ */
11
+
12
+ /**
13
+ * A pool over `blocks` (block id → its prod context) whose computable context records the markers.
14
+ * The constructor is private; the pool reads only `markUnstable` of the context and the contexts
15
+ * of the blocks, so that is all it is given.
16
+ */
17
+ function poolOver(blocks: Record<string, RawPObjectCollection>) {
18
+ const markers: string[] = [];
19
+ const ctx = { markUnstable: (marker: string) => markers.push(marker) };
20
+ const poolBlocks = new Map(Object.entries(blocks).map(([id, prod]) => [id, { prod }]));
21
+ const pool: ResultPool = Reflect.construct(ResultPool, [ctx, poolBlocks]);
22
+ return { pool, markers };
23
+ }
24
+
25
+ describe("result pool instability markers", () => {
26
+ it("marks an export of an unlocked prod as prod_not_locked:<blockId>", () => {
27
+ const { pool, markers } = poolOver({ up: { locked: false, results: new Map() } });
28
+ expect(pool.getSpecByRef("up", "main")).toBeUndefined();
29
+ expect(markers).toEqual(["prod_not_locked:up"]);
30
+ });
31
+
32
+ it("marks an export without data yet as no_data:<blockId>:<export>", () => {
33
+ const { pool, markers } = poolOver({
34
+ up: { locked: true, results: new Map([["main", { hasData: true, data: () => undefined }]]) },
35
+ });
36
+ expect(pool.getDataOrErrorByRef("up", "main")).toBeUndefined();
37
+ expect(markers).toEqual(["no_data:up:main"]);
38
+ });
39
+
40
+ it("gives both markers for an export without data in an unlocked prod", () => {
41
+ const { pool, markers } = poolOver({
42
+ up: { locked: false, results: new Map([["main", { hasData: true, data: () => undefined }]]) },
43
+ });
44
+ pool.getDataOrErrorByRef("up", "main");
45
+ expect(markers).toEqual(["no_data:up:main", "prod_not_locked:up"]);
46
+ });
47
+ });
@@ -3,12 +3,24 @@ import { HmacSha256Signer } from "@milaboratories/ts-helpers";
3
3
  import type { BlockPackSpec } from "@milaboratories/pl-model-middle-layer";
4
4
  import { V2RegistryProvider } from "../block_registry/registry-v2-provider";
5
5
  import { defaultHttpDispatcher } from "@milaboratories/pl-http";
6
+ import type { PlClient } from "@milaboratories/pl-client";
7
+ import type { BlockPackSpecPrepared } from "../model";
8
+ import { cacheBlockPackTemplate } from "../mutator/template/template_cache";
6
9
 
7
10
  export const TestBPPreparer = new BlockPackPreparer(
8
11
  new V2RegistryProvider(defaultHttpDispatcher()),
9
12
  new HmacSha256Signer(HmacSha256Signer.generateSecret()),
10
13
  );
11
14
 
15
+ /** Prepares a block pack and installs its template, as `Project.addBlock` does. */
16
+ export async function prepareInstalled(
17
+ pl: PlClient,
18
+ spec: BlockPackSpec,
19
+ ): Promise<BlockPackSpecPrepared> {
20
+ const prepared = await TestBPPreparer.prepare(spec);
21
+ return await cacheBlockPackTemplate(pl, prepared, { preparer: TestBPPreparer });
22
+ }
23
+
12
24
  export const BPSpecEnterV041NotPrepared: BlockPackSpec = {
13
25
  type: "from-registry-v1",
14
26
  registryUrl: "https://block.registry.platforma.bio/releases",
@@ -19,8 +19,15 @@ import {
19
19
  /** What a project field holds: a resource, an error, or nothing yet. */
20
20
  export type FieldContent = SignedResourceId | { error: SignedResourceId } | "unresolved";
21
21
 
22
- /** Columns of a result list by name: the spec of each and the cells of its data. */
23
- export type Columns = Record<string, { spec: PColumnSpec; cells: string[] }>;
22
+ /**
23
+ * Columns of a result list by name: the spec of each and the cells of its data. `data` says what
24
+ * the column's data field holds: a ready resource (the default), nothing (`missing`), a resource
25
+ * still being calculated (`notReady`) or an error (`failed`).
26
+ */
27
+ export type Columns = Record<
28
+ string,
29
+ { spec: PColumnSpec; cells: string[]; data?: "ready" | "missing" | "notReady" | "failed" }
30
+ >;
24
31
 
25
32
  /**
26
33
  * State of a result list: `locked` — complete; `open` — more columns may come; `failed` — it has
@@ -77,6 +84,13 @@ export class FakeProject {
77
84
  return id;
78
85
  }
79
86
 
87
+ /** Marks a resource made by this project as still being calculated. */
88
+ private notReady(id: SignedResourceId): void {
89
+ const i = this.nodes.findIndex((n) => n.id === id);
90
+ if (i < 0) throw new Error("Not a resource of this project");
91
+ this.nodes[i] = { ...this.nodes[i], resourceReady: false, final: false };
92
+ }
93
+
80
94
  /** An error a resource or field can hold. */
81
95
  error(message: string): SignedResourceId {
82
96
  return this.value("json/resourceError", { message });
@@ -94,12 +108,14 @@ export class FakeProject {
94
108
  extend(id: SignedResourceId, columns: Columns, { state }: FrameState): void {
95
109
  const fields = this.frameFields.get(id);
96
110
  if (fields === undefined) throw new Error("Not a result list of this project");
97
- for (const [name, { spec, cells }] of Object.entries(columns)) {
111
+ for (const [name, { spec, cells, data: state = "ready" }] of Object.entries(columns)) {
98
112
  const data = Object.fromEntries(cells.map((cell, i) => [`["s${i}"]`, cell]));
99
113
  fields.push(field("Input", `${name}.spec`, this.value("PColumnSpec", spec)));
100
- fields.push(
101
- field("Input", `${name}.data`, this.value("PColumnData/Json", { keyLength: 1, data })),
102
- );
114
+ if (state === "missing") continue;
115
+ const value = this.value("PColumnData/Json", { keyLength: 1, data });
116
+ if (state === "notReady") this.notReady(value);
117
+ if (state === "failed") fields.push(fieldError("Input", `${name}.data`, this.error("boom")));
118
+ else fields.push(field("Input", `${name}.data`, value));
103
119
  }
104
120
  const error = state === "failed" ? this.error("render failed") : NullSignedResourceId;
105
121
  this.nodes.push({
@@ -198,6 +214,17 @@ function field(type: FieldType, name: string, value: SignedResourceId): FieldDat
198
214
  return { name, type, value, error: NullSignedResourceId, status: "Resolved", valueIsFinal: true };
199
215
  }
200
216
 
217
+ function fieldError(type: FieldType, name: string, error: SignedResourceId): FieldData {
218
+ return {
219
+ name,
220
+ type,
221
+ value: NullSignedResourceId,
222
+ error,
223
+ status: "Resolved",
224
+ valueIsFinal: true,
225
+ };
226
+ }
227
+
201
228
  function projectField(name: string, content: FieldContent): FieldData {
202
229
  if (content === "unresolved") {
203
230
  return {