@milaboratories/pl-middle-layer 2.9.1 → 2.10.1

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 (66) hide show
  1. package/dist/index.cjs +5 -1
  2. package/dist/index.d.ts +3 -2
  3. package/dist/index.js +3 -2
  4. package/dist/middle_layer/build_stamp.cjs +1 -1
  5. package/dist/middle_layer/build_stamp.js +1 -1
  6. package/dist/middle_layer/index.cjs +4 -0
  7. package/dist/middle_layer/index.d.ts +2 -1
  8. package/dist/middle_layer/index.js +2 -1
  9. package/dist/middle_layer/middle_layer.cjs +100 -31
  10. package/dist/middle_layer/middle_layer.cjs.map +1 -1
  11. package/dist/middle_layer/middle_layer.d.ts +54 -8
  12. package/dist/middle_layer/middle_layer.d.ts.map +1 -1
  13. package/dist/middle_layer/middle_layer.js +99 -30
  14. package/dist/middle_layer/middle_layer.js.map +1 -1
  15. package/dist/middle_layer/project.cjs +45 -38
  16. package/dist/middle_layer/project.cjs.map +1 -1
  17. package/dist/middle_layer/project.d.ts +18 -3
  18. package/dist/middle_layer/project.d.ts.map +1 -1
  19. package/dist/middle_layer/project.js +44 -36
  20. package/dist/middle_layer/project.js.map +1 -1
  21. package/dist/middle_layer/project_holds.cjs +266 -0
  22. package/dist/middle_layer/project_holds.cjs.map +1 -0
  23. package/dist/middle_layer/project_holds.d.ts +50 -0
  24. package/dist/middle_layer/project_holds.d.ts.map +1 -0
  25. package/dist/middle_layer/project_holds.js +262 -0
  26. package/dist/middle_layer/project_holds.js.map +1 -0
  27. package/dist/model/block_pack_spec.cjs.map +1 -1
  28. package/dist/model/block_pack_spec.d.ts +3 -3
  29. package/dist/model/block_pack_spec.d.ts.map +1 -1
  30. package/dist/model/block_pack_spec.js.map +1 -1
  31. package/dist/model/template_spec.d.ts +18 -0
  32. package/dist/model/template_spec.d.ts.map +1 -1
  33. package/dist/mutator/block-pack/block_pack.cjs +89 -2
  34. package/dist/mutator/block-pack/block_pack.cjs.map +1 -1
  35. package/dist/mutator/block-pack/block_pack.d.ts +16 -0
  36. package/dist/mutator/block-pack/block_pack.d.ts.map +1 -1
  37. package/dist/mutator/block-pack/block_pack.js +90 -4
  38. package/dist/mutator/block-pack/block_pack.js.map +1 -1
  39. package/dist/mutator/block-pack/required_capabilities.cjs +16 -0
  40. package/dist/mutator/block-pack/required_capabilities.cjs.map +1 -1
  41. package/dist/mutator/block-pack/required_capabilities.js +16 -1
  42. package/dist/mutator/block-pack/required_capabilities.js.map +1 -1
  43. package/dist/mutator/template/template_cache.cjs +8 -1
  44. package/dist/mutator/template/template_cache.cjs.map +1 -1
  45. package/dist/mutator/template/template_cache.d.ts +7 -3
  46. package/dist/mutator/template/template_cache.d.ts.map +1 -1
  47. package/dist/mutator/template/template_cache.js +8 -1
  48. package/dist/mutator/template/template_cache.js.map +1 -1
  49. package/package.json +6 -6
  50. package/src/middle_layer/index.ts +2 -0
  51. package/src/middle_layer/middle_layer.ts +121 -40
  52. package/src/middle_layer/project.ts +47 -42
  53. package/src/middle_layer/project_close_during_write.test.ts +142 -0
  54. package/src/middle_layer/project_handles.test.ts +168 -0
  55. package/src/middle_layer/project_holds.ts +359 -0
  56. package/src/middle_layer/project_slots.test.ts +331 -0
  57. package/src/model/block_pack_spec.ts +3 -2
  58. package/src/model/template_spec.ts +21 -0
  59. package/src/mutator/block-pack/block_pack.test.ts +10 -1
  60. package/src/mutator/block-pack/block_pack.ts +102 -2
  61. package/src/mutator/block-pack/block_pack_load.test.ts +52 -0
  62. package/src/mutator/block-pack/required_capabilities.ts +25 -0
  63. package/src/mutator/project-v3.test.ts +27 -16
  64. package/src/mutator/template/template_cache.ts +26 -3
  65. package/src/test/block_packs.ts +12 -0
  66. package/src/test/write_tx_hooks.ts +75 -0
@@ -9,7 +9,7 @@ import { AuthorMarker, BlockSettings, BlockStateInternalV3, BlockStatusSummary,
9
9
  import { MiLogger } from "@milaboratories/ts-helpers";
10
10
  import { BlockId, NavigationState } from "@milaboratories/pl-model-common";
11
11
  import { Computable, ComputableStableDefined } from "@milaboratories/computable";
12
- import { PlClient, SignedResourceId } from "@milaboratories/pl-client";
12
+ import { SignedResourceId } from "@milaboratories/pl-client";
13
13
  import { ExtendedResourceData, SynchronizedTreeState } from "@milaboratories/pl-tree";
14
14
  /** Options of {@link Project.addBlock}. */
15
15
  export type AddBlockOps = {
@@ -37,6 +37,9 @@ export declare class Project {
37
37
  readonly id: ProjectId$1;
38
38
  readonly rid: SignedResourceId;
39
39
  private readonly projectTree;
40
+ /** Called once, from the maintenance loop, when the loop finds the project was deleted
41
+ * elsewhere. The loop has stopped by then; the owner is expected to destroy the project. */
42
+ private readonly onGone?;
40
43
  /** Data for the left panel, contain basic information about block status. */
41
44
  readonly overview: ComputableStableDefined<ProjectOverview>;
42
45
  private readonly overviewLight;
@@ -66,7 +69,10 @@ export declare class Project {
66
69
  constructor(env: MiddleLayerEnvironment, id: ProjectId$1, rid: SignedResourceId, projectTree: SynchronizedTreeState,
67
70
  /** Whether this tree was seeded from a snapshot. When it was, the file on disk already
68
71
  * holds generation 0, so an idle warm reopen writes nothing at all. */
69
- restoredFromSnapshot?: boolean);
72
+ restoredFromSnapshot?: boolean,
73
+ /** Called once, from the maintenance loop, when the loop finds the project was deleted
74
+ * elsewhere. The loop has stopped by then; the owner is expected to destroy the project. */
75
+ onGone?: ((project: Project) => void) | undefined);
70
76
  get projectLockId(): string;
71
77
  /**
72
78
  * Periodic snapshot write, carried on the maintenance loop rather than a timer of its own.
@@ -102,6 +108,15 @@ export declare class Project {
102
108
  /** Captures and writes, never throwing: a snapshot is an optimisation and must not fail
103
109
  * whatever triggered it. */
104
110
  private captureAndWrite;
111
+ /**
112
+ * Brings the project tree up to a write that has just committed.
113
+ *
114
+ * The write is already on the backend when this runs, so a project destroyed meanwhile (closed
115
+ * by its last holder, or deleted) must not turn it into a failure: a caller told it failed would
116
+ * retry it and apply it twice. `destroy` marks the project destroyed before it terminates the
117
+ * tree, so a refresh failing on a terminated tree always finds the mark set.
118
+ */
119
+ private refreshAfterWrite;
105
120
  private refreshLoop;
106
121
  /**
107
122
  * Adds new block to the project.
@@ -280,6 +295,6 @@ export declare class Project {
280
295
  /** @deprecated */
281
296
  destroyAndAwaitTermination(): Promise<void>;
282
297
  dumpState(): ExtendedResourceData[];
283
- static init(env: MiddleLayerEnvironment, id: ProjectId$1, rid: SignedResourceId): Promise<Project>;
298
+ static init(env: MiddleLayerEnvironment, id: ProjectId$1, rid: SignedResourceId, onGone?: (project: Project) => void): Promise<Project>;
284
299
  }
285
300
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","names":["ProjectId"],"sources":["../../src/middle_layer/project.ts"],"mappings":";;;;;;;;;;;;;;YAoIY;;;;;;EAMV;;IAEE;;;;;;IAMA,WAAW,SAAS,eAAe;;;EAGrC;;;qBAIW;mBAuCQ;WACD,IAAIA;WACX,KAAK;mBACG;;WAxCH,UAAU,wBAAwB;mBACjC;mBAEA;mBAEA;mBAEA;;;mBAIA;mBACA;mBACA;mBAEA;;;;UAKT;;;;;;;;;UAUA;cAEI;EAIZ,YACmB,KAAK,wBACN,IAAIA,aACX,KAAK,kBACG,aAAa;;;EAG9B;MAgBE;;;;;;;;UAWU;;;;;;;;;;;;;;;;;EA2BP,mBAAmB;;;;UAoClB;;UAGM;;;UAkBA;UAmBA;;;;;;;;;;;;;;;;;EA2FD,SACX,oBACA,eAAe,kBACf,iBACA,SAAQ,0BACR,kBACA,MAAK,cACJ;;;;;;;;;;;;;EAyGU,eACX,yBACA,iBACA,SAAQ,0BACR,sBACC;;;;;EAkBU,gBACX,iBACA,eAAe,kBACf,qBACA,SAAS,eACR;;EAiCU,YAAY,iBAAiB,SAAS,eAAe;;;;;;;EAmBrD,cAAc,kBAAkB,SAAS,eAAe;;;;;;EAuCxD,SAAS,kBAAkB;;;;;;EAgB3B,UAAU,kBAAkB;;;;;;;;EAkB5B,aAAa,iBAAiB,eAAe,SAAS,eAAY;;;;;;;;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,aACJ,KAAK,kBACL,UAAU,SAAS,mBAClB,QAAQ"}
@@ -1,5 +1,7 @@
1
+ import { throwIfMissingServerCapabilities } from "../mutator/block-pack/required_capabilities.js";
1
2
  import { ProjectStatusFieldPattern, projectFieldName, projectStatusFieldRegex } from "../model/project_model.js";
2
3
  import { withProject, withProjectAuthored } from "../mutator/project.js";
4
+ import { cacheBlockPackTemplate } from "../mutator/template/template_cache.js";
3
5
  import { finalityStopRules } from "./finality_stop_rules.js";
4
6
  import { getBlockPackInfo } from "./util.js";
5
7
  import { projectOverview } from "./project_overview.js";
@@ -12,7 +14,6 @@ import { activeConfigs } from "./active_cfg.js";
12
14
  import { NavigationStates } from "./navigation_states.js";
13
15
  import { projectOverviewLight } from "./project_overview_light.js";
14
16
  import { applyProjectMigrations } from "../mutator/migration.js";
15
- import { cacheBlockPackTemplate } from "../mutator/template/template_cache.js";
16
17
  import { BLOCK_STORAGE_FACADE_VERSION, BlockStorageFacadeCallbacks, checkBlockFlag, extractConfig } from "@platforma-sdk/model";
17
18
  import { cachedDeserialize, createInfiniteRetryState, nextInfiniteRetryState, notEmpty } from "@milaboratories/ts-helpers";
18
19
  import fsp from "node:fs/promises";
@@ -44,6 +45,7 @@ var Project = class Project {
44
45
  id;
45
46
  rid;
46
47
  projectTree;
48
+ onGone;
47
49
  /** Data for the left panel, contain basic information about block status. */
48
50
  overview;
49
51
  overviewLight;
@@ -72,11 +74,12 @@ var Project = class Project {
72
74
  get destroyed() {
73
75
  return this.abortController.signal.aborted;
74
76
  }
75
- constructor(env, id, rid, projectTree, restoredFromSnapshot = false) {
77
+ constructor(env, id, rid, projectTree, restoredFromSnapshot = false, onGone) {
76
78
  this.env = env;
77
79
  this.id = id;
78
80
  this.rid = rid;
79
81
  this.projectTree = projectTree;
82
+ this.onGone = onGone;
80
83
  this.snapshotGeneration = restoredFromSnapshot ? 0 : -1;
81
84
  this.overview = projectOverview(projectTree.entry(), this.navigationStates, env).withPreCalculatedValueTree();
82
85
  this.overviewLight = projectOverviewLight(projectTree.entry()).withPreCalculatedValueTree();
@@ -168,8 +171,26 @@ var Project = class Project {
168
171
  this.env.logger.warn(new Error(`failed to capture tree snapshot for project ${this.id}`, { cause: e }));
169
172
  }
170
173
  }
174
+ /**
175
+ * Brings the project tree up to a write that has just committed.
176
+ *
177
+ * The write is already on the backend when this runs, so a project destroyed meanwhile (closed
178
+ * by its last holder, or deleted) must not turn it into a failure: a caller told it failed would
179
+ * retry it and apply it twice. `destroy` marks the project destroyed before it terminates the
180
+ * tree, so a refresh failing on a terminated tree always finds the mark set.
181
+ */
182
+ async refreshAfterWrite() {
183
+ if (this.destroyed) return;
184
+ try {
185
+ await this.projectTree.refreshState();
186
+ } catch (e) {
187
+ if (this.destroyed) return;
188
+ throw e;
189
+ }
190
+ }
171
191
  async refreshLoop() {
172
192
  let retryState;
193
+ let gone = false;
173
194
  while (!this.destroyed) try {
174
195
  await withProject(this.env.projectHelper, this.env.pl, this.rid, (prj) => {
175
196
  prj.doRefresh();
@@ -193,6 +214,7 @@ var Project = class Project {
193
214
  if (this.destroyed) break;
194
215
  if (isNotFoundError(error)) {
195
216
  this.env.logger.warn("project refresh routine terminated, because project was externally deleted");
217
+ gone = true;
196
218
  break;
197
219
  } else if (isTimeoutOrCancelError(error)) {} else {
198
220
  retryState = retryState ? nextInfiniteRetryState(retryState) : createInfiniteRetryState({
@@ -210,6 +232,7 @@ var Project = class Project {
210
232
  }
211
233
  }
212
234
  }
235
+ if (gone) this.onGone?.(this);
213
236
  }
214
237
  /**
215
238
  * Adds new block to the project.
@@ -241,7 +264,7 @@ var Project = class Project {
241
264
  if (storage.error !== void 0) throw new BlockInitParamsRejectedError(storage.error.message);
242
265
  initialStorage = storage.value;
243
266
  }
244
- const cachedBp = await cacheBlockPackTemplate(this.env.pl, preparedBp);
267
+ const cachedBp = await cacheBlockPackTemplate(this.env.pl, preparedBp, { preparer: this.env.bpPreparer });
245
268
  const newBlockSpec = blockCfg.modelAPIVersion === BLOCK_STORAGE_FACADE_VERSION ? {
246
269
  storageMode: "fromModel",
247
270
  blockPack: cachedBp,
@@ -268,7 +291,7 @@ var Project = class Project {
268
291
  name: "addBlock",
269
292
  lockId: this.projectLockId
270
293
  });
271
- await this.projectTree.refreshState();
294
+ await this.refreshAfterWrite();
272
295
  return blockId;
273
296
  }
274
297
  /**
@@ -288,7 +311,7 @@ var Project = class Project {
288
311
  name: "duplicateBlock",
289
312
  lockId: this.projectLockId
290
313
  });
291
- await this.projectTree.refreshState();
314
+ await this.refreshAfterWrite();
292
315
  return newBlockId;
293
316
  }
294
317
  /**
@@ -300,7 +323,7 @@ var Project = class Project {
300
323
  const blockCfg = extractConfig(preparedBp.config);
301
324
  this.env.runtimeCapabilities.throwIfIncompatible(blockCfg.featureFlags);
302
325
  throwIfMissingServerCapabilities(this.env.pl, preparedBp.requiredCapabilities);
303
- const cachedBp = await cacheBlockPackTemplate(this.env.pl, preparedBp);
326
+ const cachedBp = await cacheBlockPackTemplate(this.env.pl, preparedBp, { preparer: this.env.bpPreparer });
304
327
  const resetState = resetArgs ? { state: blockCfg.modelAPIVersion === 1 ? {
305
328
  args: blockCfg.initialArgs,
306
329
  uiState: blockCfg.initialUiState
@@ -309,7 +332,7 @@ var Project = class Project {
309
332
  name: "updateBlockPack",
310
333
  lockId: this.projectLockId
311
334
  });
312
- await this.projectTree.refreshState();
335
+ await this.refreshAfterWrite();
313
336
  }
314
337
  /** Deletes a block with all associated data. */
315
338
  async deleteBlock(blockId, author) {
@@ -318,7 +341,7 @@ var Project = class Project {
318
341
  lockId: this.projectLockId
319
342
  });
320
343
  this.navigationStates.deleteBlock(blockId);
321
- await this.projectTree.refreshState();
344
+ await this.refreshAfterWrite();
322
345
  }
323
346
  /**
324
347
  * Updates block order according to the given array of block ids.
@@ -347,7 +370,7 @@ var Project = class Project {
347
370
  name: "reorderBlocks",
348
371
  lockId: this.projectLockId
349
372
  });
350
- await this.projectTree.refreshState();
373
+ await this.refreshAfterWrite();
351
374
  }
352
375
  /**
353
376
  * Renders production part of the block starting all connected heavy computations.
@@ -359,7 +382,7 @@ var Project = class Project {
359
382
  name: "runBlock",
360
383
  lockId: this.projectLockId
361
384
  });
362
- await this.projectTree.refreshState();
385
+ await this.refreshAfterWrite();
363
386
  }
364
387
  /**
365
388
  * Stops the block if it is running by destroying its production state. All
@@ -371,7 +394,7 @@ var Project = class Project {
371
394
  name: "stopBlock",
372
395
  lockId: this.projectLockId
373
396
  });
374
- await this.projectTree.refreshState();
397
+ await this.refreshAfterWrite();
375
398
  }
376
399
  /**
377
400
  * @deprecated Use mutateBlockStorage() for V3 blocks.
@@ -392,7 +415,7 @@ var Project = class Project {
392
415
  name: "setBlockArgs",
393
416
  lockId: this.projectLockId
394
417
  });
395
- await this.projectTree.refreshState();
418
+ await this.refreshAfterWrite();
396
419
  }
397
420
  /**
398
421
  * @deprecated Use mutateBlockStorage() for V3 blocks.
@@ -413,7 +436,7 @@ var Project = class Project {
413
436
  name: "setUiState",
414
437
  lockId: this.projectLockId
415
438
  });
416
- await this.projectTree.refreshState();
439
+ await this.refreshAfterWrite();
417
440
  }
418
441
  /**
419
442
  * @deprecated Use mutateBlockStorage() for V3 blocks.
@@ -437,7 +460,7 @@ var Project = class Project {
437
460
  name: "setBlockArgsAndUiState",
438
461
  lockId: this.projectLockId
439
462
  });
440
- await this.projectTree.refreshState();
463
+ await this.refreshAfterWrite();
441
464
  }
442
465
  /**
443
466
  * Sets navigation state.
@@ -464,7 +487,7 @@ var Project = class Project {
464
487
  name: "mutateBlockStorage",
465
488
  lockId: this.projectLockId
466
489
  });
467
- await this.projectTree.refreshState();
490
+ await this.refreshAfterWrite();
468
491
  }
469
492
  /**
470
493
  * Reads the block's initialization params as its own model projects them from the current
@@ -487,7 +510,7 @@ var Project = class Project {
487
510
  await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, void 0, (mut) => {
488
511
  mut.setBlockSettings(blockId, newValue);
489
512
  }, { name: "setBlockSettings" });
490
- await this.projectTree.refreshState();
513
+ await this.refreshAfterWrite();
491
514
  }
492
515
  /**
493
516
  * Sets raw block storage content directly.
@@ -500,7 +523,7 @@ var Project = class Project {
500
523
  await withProjectAuthored(this.env.projectHelper, this.env.pl, this.rid, void 0, (mut) => {
501
524
  mut.setBlockStorageRaw(blockId, rawStorageJson);
502
525
  }, { name: "setBlockStorageRaw" });
503
- await this.projectTree.refreshState();
526
+ await this.refreshAfterWrite();
504
527
  }
505
528
  /** Resets arguments and ui state of the block to initial state */
506
529
  async resetBlockArgsAndUiState(blockId, author) {
@@ -528,7 +551,7 @@ var Project = class Project {
528
551
  });
529
552
  await tx.commit();
530
553
  });
531
- await this.projectTree.refreshState();
554
+ await this.refreshAfterWrite();
532
555
  }
533
556
  getBlockComputables(blockId) {
534
557
  const cached = this.blockComputables.get(blockId);
@@ -706,7 +729,7 @@ var Project = class Project {
706
729
  dumpState() {
707
730
  return this.projectTree.dumpState();
708
731
  }
709
- static async init(env, id, rid) {
732
+ static async init(env, id, rid, onGone) {
710
733
  await applyProjectMigrations(env.pl, rid);
711
734
  await withProject(env.projectHelper, env.pl, rid, (_) => {}, { name: "init" });
712
735
  const { tree: projectTree, restored } = await loadProjectTree(env, rid);
@@ -717,7 +740,7 @@ var Project = class Project {
717
740
  await fsp.writeFile(`${resourceIdToString(rid)}.json`, stringifyForDump(state));
718
741
  await fsp.writeFile(`${resourceIdToString(rid)}.stats.json`, stringifyForDump(stats));
719
742
  }
720
- return new Project(env, id, rid, projectTree, restored);
743
+ return new Project(env, id, rid, projectTree, restored, onGone);
721
744
  }
722
745
  };
723
746
  /**
@@ -847,21 +870,6 @@ function convertErrorsToStrings(outputs) {
847
870
  }
848
871
  return result;
849
872
  }
850
- /** Throws when the connected backend doesn't advertise every capability the
851
- * block-pack requires (as declared in `meta.requiredCapabilities`).
852
- *
853
- * The matching set is the desktop's install gate moved server-side so both
854
- * the UI (`AddBlockModal`) and direct middle-layer callers (the MCP server's
855
- * `add_block` tool, programmatic block installs, tests) reject incompatible
856
- * blocks consistently. */
857
- function throwIfMissingServerCapabilities(pl, requiredCapabilities) {
858
- if (!requiredCapabilities || requiredCapabilities.length === 0) return;
859
- const advertised = pl.serverInfo.capabilities ?? [];
860
- const filterFn = (c) => !advertised.includes(c);
861
- if (!requiredCapabilities.some(filterFn)) return;
862
- const missing = requiredCapabilities.filter(filterFn);
863
- throw new Error(`Block cannot be added: connected backend does not advertise capabilities ${JSON.stringify(missing)}. Backend advertises ${JSON.stringify(advertised)}. Upgrade the backend or remove the requirement from the block manifest.`);
864
- }
865
- export { Project, isSnapshotFailsafeError, projectTreeFieldFilter, projectTreePruning, projectTreeTraverseStopRules, throwIfMissingServerCapabilities };
873
+ export { Project, isSnapshotFailsafeError, projectTreeFieldFilter, projectTreePruning, projectTreeTraverseStopRules };
866
874
 
867
875
  //# sourceMappingURL=project.js.map