@spine-event-engine/storage 2.0.0-snapshot.2 → 2.0.0-snapshot.21

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 (53) hide show
  1. package/README.md +47 -14
  2. package/REFERENCE.md +26 -18
  3. package/dist/index.d.ts +2 -4
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +0 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/internal/entity-commit.d.ts +28 -23
  8. package/dist/internal/entity-commit.d.ts.map +1 -1
  9. package/dist/internal/entity-commit.js +10 -1
  10. package/dist/internal/entity-commit.js.map +1 -1
  11. package/dist/internal/entity-history.d.ts +1 -1
  12. package/dist/internal/entity-history.d.ts.map +1 -1
  13. package/dist/memory/canonical-utf8.d.ts.map +1 -1
  14. package/dist/memory/canonical-utf8.js +13 -6
  15. package/dist/memory/canonical-utf8.js.map +1 -1
  16. package/dist/memory/in-memory-entity-commit.d.ts +38 -6
  17. package/dist/memory/in-memory-entity-commit.d.ts.map +1 -1
  18. package/dist/memory/in-memory-entity-commit.js +281 -68
  19. package/dist/memory/in-memory-entity-commit.js.map +1 -1
  20. package/dist/memory/in-memory-entity-history.d.ts +115 -1
  21. package/dist/memory/in-memory-entity-history.d.ts.map +1 -1
  22. package/dist/memory/in-memory-entity-history.js +186 -41
  23. package/dist/memory/in-memory-entity-history.js.map +1 -1
  24. package/dist/memory/in-memory-record-storage.d.ts +19 -0
  25. package/dist/memory/in-memory-record-storage.d.ts.map +1 -1
  26. package/dist/memory/in-memory-record-storage.js +25 -4
  27. package/dist/memory/in-memory-record-storage.js.map +1 -1
  28. package/dist/memory/tenant-records.d.ts +33 -7
  29. package/dist/memory/tenant-records.d.ts.map +1 -1
  30. package/dist/memory/tenant-records.js +297 -77
  31. package/dist/memory/tenant-records.js.map +1 -1
  32. package/dist/provider.d.ts +18 -0
  33. package/dist/provider.d.ts.map +1 -0
  34. package/dist/provider.js +23 -0
  35. package/dist/provider.js.map +1 -0
  36. package/dist/query/query-policy.d.ts +18 -14
  37. package/dist/query/query-policy.d.ts.map +1 -1
  38. package/dist/query/query-policy.js +55 -28
  39. package/dist/query/query-policy.js.map +1 -1
  40. package/dist/record/record-query.d.ts +12 -11
  41. package/dist/record/record-query.d.ts.map +1 -1
  42. package/dist/record/record-query.js +4 -1
  43. package/dist/record/record-query.js.map +1 -1
  44. package/dist/record/record-storage.d.ts +12 -5
  45. package/dist/record/record-storage.d.ts.map +1 -1
  46. package/dist/record/record-storage.js +14 -12
  47. package/dist/record/record-storage.js.map +1 -1
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/package.json +6 -27
  50. package/dist/record/record-mask.d.ts +0 -11
  51. package/dist/record/record-mask.d.ts.map +0 -1
  52. package/dist/record/record-mask.js +0 -82
  53. package/dist/record/record-mask.js.map +0 -1
@@ -27,6 +27,8 @@ export declare class MemoryEntityStorageFactory {
27
27
  /**
28
28
  * Creates one scoped entity-storage handle.
29
29
  *
30
+ * @typeParam I Entity identifier type used by this storage scope.
31
+ * @typeParam S Generated Entity state message type.
30
32
  * @param input Supplies the entity storage configuration.
31
33
  * @returns Returns the scoped in-memory entity storage.
32
34
  */
@@ -34,6 +36,8 @@ export declare class MemoryEntityStorageFactory {
34
36
  /**
35
37
  * Opens the provider-owned maps used by an atomic in-memory commit.
36
38
  *
39
+ * @typeParam I Entity identifier type used by this storage scope.
40
+ * @typeParam S Generated Entity state message type.
37
41
  * @param input Supplies the Entity storage configuration.
38
42
  * @returns The compatible backend maps for this Entity scope.
39
43
  */
@@ -41,6 +45,9 @@ export declare class MemoryEntityStorageFactory {
41
45
  }
42
46
  /**
43
47
  * One scoped in-memory current/state/event storage handle.
48
+ *
49
+ * @typeParam I Entity identifier type used by this storage scope.
50
+ * @typeParam S Generated Entity state message type.
44
51
  */
45
52
  export declare class InMemoryEntityStorage<I, S extends Message> {
46
53
  /**
@@ -69,6 +76,9 @@ export declare class InMemoryEntityStorage<I, S extends Message> {
69
76
  }
70
77
  /**
71
78
  * Configures one in-memory entity storage scope.
79
+ *
80
+ * @typeParam I Entity identifier type used by this storage scope.
81
+ * @typeParam S Generated Entity state message type.
72
82
  */
73
83
  export interface EntityStorageInput<I, S extends Message> {
74
84
  /**
@@ -114,6 +124,8 @@ export interface EntityStorageInput<I, S extends Message> {
114
124
  }
115
125
  /**
116
126
  * Internal provider ID canonicalization and clone contract.
127
+ *
128
+ * @typeParam I Entity identifier type encoded by this codec.
117
129
  */
118
130
  export interface EntityIdCodec<I> {
119
131
  /**
@@ -164,6 +176,8 @@ export interface EntityBackend {
164
176
  export declare const ENTITY_SCOPE_MUTATION_KEY = "entity-storage-scope";
165
177
  /**
166
178
  * In-memory latest-state storage used by all entity families.
179
+ *
180
+ * @typeParam I Entity identifier type accepted by this adapter.
167
181
  */
168
182
  export declare class MemoryEntityRecordStorage<I> implements EntityRecordStorage<I> {
169
183
  #private;
@@ -195,7 +209,7 @@ export declare class MemoryEntityRecordStorage<I> implements EntityRecordStorage
195
209
  */
196
210
  write(record: EntityRecord): Promise<void>;
197
211
  /**
198
- * Returns non-deleted current records matching the normalized plan.
212
+ * Returns matching current records; exhaustive plans may select deleted records.
199
213
  *
200
214
  * @param plan Supplies the normalized record-query plan.
201
215
  * @returns Resolves to ordered matching current-record entries.
@@ -204,6 +218,8 @@ export declare class MemoryEntityRecordStorage<I> implements EntityRecordStorage
204
218
  }
205
219
  /**
206
220
  * In-memory immutable diagnostic event-history adapter.
221
+ *
222
+ * @typeParam I Producer Entity identifier type used to select events.
207
223
  */
208
224
  export declare class MemoryEntityEventHistory<I> implements EntityEventHistoryPort<I> {
209
225
  #private;
@@ -251,17 +267,62 @@ export declare class MemoryEntityEventHistory<I> implements EntityEventHistoryPo
251
267
  * @returns Returns true while the adapter is open.
252
268
  */
253
269
  isOpen(): boolean;
270
+ /**
271
+ * Returns a nonempty generated event ID or throws.
272
+ *
273
+ * @param event Event inspected for its ID.
274
+ * @returns Present generated event ID.
275
+ */
254
276
  private eventIdIn;
277
+ /**
278
+ * Decodes the producer Entity ID from an event context.
279
+ *
280
+ * @param event Event whose producer is inspected.
281
+ * @returns Entity ID matching the configured codec.
282
+ */
255
283
  private producerIdIn;
284
+ /**
285
+ * Validates required event history fields and removes transient enrichment.
286
+ *
287
+ * @param event Event proposed for durable history.
288
+ * @returns Cloned event without context enrichment.
289
+ */
256
290
  private validatedEvent;
291
+ /**
292
+ * Rejects an operation after this event-history handle closes.
293
+ */
257
294
  private requireOpen;
295
+ /**
296
+ * Invokes the maintenance selection hook and checks that the handle remains open.
297
+ *
298
+ * @returns Completes after the selection hook.
299
+ */
258
300
  private afterSelection;
301
+ /**
302
+ * Reads the configured maintenance deletion chunk size.
303
+ *
304
+ * @returns Configured or default chunk size.
305
+ */
259
306
  private batchSize;
307
+ /**
308
+ * Reads the configured history query page size.
309
+ *
310
+ * @returns Configured or default page size.
311
+ */
260
312
  private pageSize;
313
+ /**
314
+ * Deletes selected event IDs in bounded maintenance chunks.
315
+ *
316
+ * @param entries Event IDs selected for deletion.
317
+ * @returns Completes after all chunks have been deleted.
318
+ */
261
319
  private deleteEntries;
262
320
  }
263
321
  /**
264
322
  * In-memory immutable, versioned state-history adapter.
323
+ *
324
+ * @typeParam I Entity identifier type used to select state records.
325
+ * @typeParam S Generated Entity state message type decoded from records.
265
326
  */
266
327
  export declare class InMemoryEntityHistory<I, S extends Message> implements EntityStateHistoryPort<I, S> {
267
328
  #private;
@@ -326,15 +387,67 @@ export declare class InMemoryEntityHistory<I, S extends Message> implements Enti
326
387
  * @returns Returns true while the adapter is open.
327
388
  */
328
389
  isOpen(): boolean;
390
+ /**
391
+ * Deletes selected state-record keys in bounded maintenance chunks.
392
+ *
393
+ * @param entries State-record keys selected for deletion.
394
+ * @returns Completes after all chunks have been deleted.
395
+ */
329
396
  private deleteEntries;
397
+ /**
398
+ * Builds a state-history key from an Entity ID and version.
399
+ *
400
+ * @param record Generated Entity record to identify.
401
+ * @returns Composite state-history key.
402
+ */
330
403
  private keyFor;
404
+ /**
405
+ * Decodes the Entity ID stored in a generated record.
406
+ *
407
+ * @param record Generated Entity record to inspect.
408
+ * @returns Entity ID matching the configured codec.
409
+ */
331
410
  private entityIdIn;
411
+ /**
412
+ * Checks an Entity record's ID, timestamp, and state schema before storage.
413
+ *
414
+ * @param record Generated Entity record proposed for history.
415
+ */
332
416
  private validateRecord;
417
+ /**
418
+ * Decodes a state whose type URL matches the configured state schema.
419
+ *
420
+ * @param record Generated Entity record containing a packed state.
421
+ * @returns Frozen decoded Entity state.
422
+ */
333
423
  private unpackState;
424
+ /**
425
+ * Rejects an operation after this state-history handle closes.
426
+ */
334
427
  private requireOpen;
428
+ /**
429
+ * Invokes the maintenance selection hook and checks that the handle remains open.
430
+ *
431
+ * @returns Completes after the selection hook.
432
+ */
335
433
  private afterSelection;
434
+ /**
435
+ * Invokes the maintenance chunk hook and checks that the handle remains open.
436
+ *
437
+ * @returns Completes after the chunk hook.
438
+ */
336
439
  private afterMaintenanceChunk;
440
+ /**
441
+ * Reads the configured maintenance deletion chunk size.
442
+ *
443
+ * @returns Configured or default chunk size.
444
+ */
337
445
  private batchSize;
446
+ /**
447
+ * Reads the configured history query page size.
448
+ *
449
+ * @returns Configured or default page size.
450
+ */
338
451
  private pageSize;
339
452
  }
340
453
  /**
@@ -370,6 +483,7 @@ export declare class KeyedSerialQueue {
370
483
  /**
371
484
  * Queues an operation after earlier operations with the same key finish.
372
485
  *
486
+ * @typeParam T Result type returned by the queued operation.
373
487
  * @param key Identifies the serialized operation sequence.
374
488
  * @param operation Supplies the operation to run.
375
489
  * @returns Resolves to the operation result.
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-entity-history.d.ts","sourceRoot":"","sources":["../../src/memory/in-memory-entity-history.ts"],"names":[],"mappings":"AAcA,OAAO,EAAuC,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAA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,CAAC,MAAM;IAUd;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAWlB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAUtB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAUnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;;;OAIG;YACW,cAAc;IAK5B;;;;OAIG;YACW,qBAAqB;IAKnC;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;CAGjB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAGlC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,gBAAgB;;IAG3B;;;;;;;OAOG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAenE"}
@@ -40,6 +40,8 @@ export class MemoryEntityStorageFactory {
40
40
  /**
41
41
  * Creates one scoped entity-storage handle.
42
42
  *
43
+ * @typeParam I Entity identifier type used by this storage scope.
44
+ * @typeParam S Generated Entity state message type.
43
45
  * @param input Supplies the entity storage configuration.
44
46
  * @returns Returns the scoped in-memory entity storage.
45
47
  */
@@ -49,6 +51,8 @@ export class MemoryEntityStorageFactory {
49
51
  /**
50
52
  * Opens the provider-owned maps used by an atomic in-memory commit.
51
53
  *
54
+ * @typeParam I Entity identifier type used by this storage scope.
55
+ * @typeParam S Generated Entity state message type.
52
56
  * @param input Supplies the Entity storage configuration.
53
57
  * @returns The compatible backend maps for this Entity scope.
54
58
  */
@@ -62,6 +66,9 @@ export class MemoryEntityStorageFactory {
62
66
  }
63
67
  /**
64
68
  * One scoped in-memory current/state/event storage handle.
69
+ *
70
+ * @typeParam I Entity identifier type used by this storage scope.
71
+ * @typeParam S Generated Entity state message type.
65
72
  */
66
73
  export class InMemoryEntityStorage {
67
74
  // prettier-ignore
@@ -128,13 +135,20 @@ export const ENTITY_SCOPE_MUTATION_KEY = "entity-storage-scope";
128
135
  const EntitySnapshots = {
129
136
  // prettier-ignore
130
137
  /**
131
- * Clones one entity ID with the platform structured-clone operation.
138
+ * Copies one entity ID with the platform structured-clone operation.
139
+ *
140
+ * @typeParam I Entity identifier type to clone.
141
+ * @param id Entity identifier to copy.
142
+ * @returns Independent identifier copy.
132
143
  */
133
144
  cloneId(id) {
134
145
  return storageHost.structuredClone(id);
135
146
  },
136
147
  /**
137
148
  * Copies an immutable latest-state record.
149
+ *
150
+ * @param record Generated current-state record to copy.
151
+ * @returns Independent generated record.
138
152
  */
139
153
  copyCurrent(record) {
140
154
  return clone(EntityRecordSchema, record);
@@ -142,6 +156,8 @@ const EntitySnapshots = {
142
156
  };
143
157
  /**
144
158
  * In-memory latest-state storage used by all entity families.
159
+ *
160
+ * @typeParam I Entity identifier type accepted by this adapter.
145
161
  */
146
162
  export class MemoryEntityRecordStorage {
147
163
  #idKey;
@@ -194,55 +210,46 @@ export class MemoryEntityRecordStorage {
194
210
  : this.#queue.run(ENTITY_SCOPE_MUTATION_KEY, write);
195
211
  }
196
212
  /**
197
- * Returns non-deleted current records matching the normalized plan.
213
+ * Returns matching current records; exhaustive plans may select deleted records.
198
214
  *
199
215
  * @param plan Supplies the normalized record-query plan.
200
216
  * @returns Resolves to ordered matching current-record entries.
201
217
  */
202
- query(plan) {
203
- return Promise.resolve().then(() => {
204
- StorageQueryPolicy.validate(plan, {
205
- comparisons: ["equal", "greaterThan", "lessThan", "greaterOrEqual", "lessOrEqual"],
206
- features: ["either", "nested", "order", "mask", "limit"],
207
- });
208
- const limit = plan.candidateLimit ?? 10_000;
209
- const candidates = [];
210
- for (const record of this.#records.values()) {
211
- if (record.lifecycleFlags?.deleted)
212
- continue;
213
- candidates.push(record);
214
- if (candidates.length > limit)
215
- break;
216
- }
217
- if (candidates.length > limit) {
218
- throw new Error(`Storage query exceeded the candidate limit of ${String(limit)}.`);
219
- }
220
- const entries = candidates.flatMap((record) => {
221
- const copied = EntitySnapshots.copyCurrent(record);
222
- const id = copied.entityId === undefined ? undefined : this.#unpackId(copied.entityId);
223
- if (id === undefined)
224
- throw new Error("Entity current record ID does not match its Entity ID schema.");
225
- return copied.lifecycleFlags?.deleted
226
- ? []
227
- : [
228
- {
229
- id: this.#idClone(id),
230
- record: copied,
231
- columns: new Map([
232
- ...this.#columns.map((column) => [
233
- column.name,
234
- column.valueIn(copied),
235
- ]),
236
- ]),
237
- },
238
- ];
239
- });
240
- return StorageQueryEvaluator.evaluate(entries, plan);
218
+ async query(plan) {
219
+ StorageQueryPolicy.validate(plan, {
220
+ comparisons: ["equal", "greaterThan", "lessThan", "greaterOrEqual", "lessOrEqual"],
221
+ features: ["either", "nested", "order", "limit"],
241
222
  });
223
+ const limit = plan.exhaustive ? Number.POSITIVE_INFINITY : (plan.candidateLimit ?? 10_000);
224
+ const candidates = [];
225
+ for (const record of this.#records.values()) {
226
+ if (!plan.exhaustive && record.lifecycleFlags?.deleted)
227
+ continue;
228
+ candidates.push(record);
229
+ if (candidates.length > limit)
230
+ break;
231
+ }
232
+ if (candidates.length > limit) {
233
+ throw new Error(`Storage query exceeded the candidate limit of ${String(limit)}.`);
234
+ }
235
+ const entries = candidates.map((record) => {
236
+ const copied = EntitySnapshots.copyCurrent(record);
237
+ const id = copied.entityId === undefined ? undefined : this.#unpackId(copied.entityId);
238
+ if (id === undefined)
239
+ throw new Error("Entity current record ID does not match its Entity ID schema.");
240
+ return {
241
+ id: this.#idClone(id),
242
+ record: copied,
243
+ columns: new Map(this.#columns.map((column) => [column.name, column.valueIn(copied)])),
244
+ };
245
+ });
246
+ return await Promise.resolve(StorageQueryEvaluator.evaluate(entries, plan));
242
247
  }
243
248
  }
244
249
  /**
245
250
  * In-memory immutable diagnostic event-history adapter.
251
+ *
252
+ * @typeParam I Producer Entity identifier type used to select events.
246
253
  */
247
254
  export class MemoryEntityEventHistory {
248
255
  #id;
@@ -357,12 +364,24 @@ export class MemoryEntityEventHistory {
357
364
  isOpen() {
358
365
  return this.#records.isOpen();
359
366
  }
367
+ /**
368
+ * Returns a nonempty generated event ID or throws.
369
+ *
370
+ * @param event Event inspected for its ID.
371
+ * @returns Present generated event ID.
372
+ */
360
373
  eventIdIn(event) {
361
374
  if (event.id === undefined || event.id.value.trim().length === 0) {
362
375
  throw new Error("Event history requires an event ID.");
363
376
  }
364
377
  return event.id;
365
378
  }
379
+ /**
380
+ * Decodes the producer Entity ID from an event context.
381
+ *
382
+ * @param event Event whose producer is inspected.
383
+ * @returns Entity ID matching the configured codec.
384
+ */
366
385
  producerIdIn(event) {
367
386
  const producerId = event.context?.producerId;
368
387
  if (producerId === undefined)
@@ -373,6 +392,12 @@ export class MemoryEntityEventHistory {
373
392
  }
374
393
  return entityId;
375
394
  }
395
+ /**
396
+ * Validates required event history fields and removes transient enrichment.
397
+ *
398
+ * @param event Event proposed for durable history.
399
+ * @returns Cloned event without context enrichment.
400
+ */
376
401
  validatedEvent(event) {
377
402
  this.eventIdIn(event);
378
403
  this.producerIdIn(event);
@@ -388,20 +413,44 @@ export class MemoryEntityEventHistory {
388
413
  stored.context.enrichment = undefined;
389
414
  return stored;
390
415
  }
416
+ /**
417
+ * Rejects an operation after this event-history handle closes.
418
+ */
391
419
  requireOpen() {
392
420
  if (!this.isOpen())
393
421
  throw new Error("Entity history storage is closed.");
394
422
  }
423
+ /**
424
+ * Invokes the maintenance selection hook and checks that the handle remains open.
425
+ *
426
+ * @returns Completes after the selection hook.
427
+ */
395
428
  async afterSelection() {
396
429
  await this.#maintenance?.afterSelection?.();
397
430
  this.requireOpen();
398
431
  }
432
+ /**
433
+ * Reads the configured maintenance deletion chunk size.
434
+ *
435
+ * @returns Configured or default chunk size.
436
+ */
399
437
  batchSize() {
400
438
  return this.#maintenance?.batchSize ?? MAINTENANCE_BATCH_SIZE;
401
439
  }
440
+ /**
441
+ * Reads the configured history query page size.
442
+ *
443
+ * @returns Configured or default page size.
444
+ */
402
445
  pageSize() {
403
446
  return this.#maintenance?.pageSize ?? HISTORY_PAGE_SIZE;
404
447
  }
448
+ /**
449
+ * Deletes selected event IDs in bounded maintenance chunks.
450
+ *
451
+ * @param entries Event IDs selected for deletion.
452
+ * @returns Completes after all chunks have been deleted.
453
+ */
405
454
  async deleteEntries(entries) {
406
455
  for (let start = 0; start < entries.length; start += this.batchSize()) {
407
456
  for (const entry of entries.slice(start, start + this.batchSize()))
@@ -413,6 +462,9 @@ export class MemoryEntityEventHistory {
413
462
  }
414
463
  /**
415
464
  * In-memory immutable, versioned state-history adapter.
465
+ *
466
+ * @typeParam I Entity identifier type used to select state records.
467
+ * @typeParam S Generated Entity state message type decoded from records.
416
468
  */
417
469
  export class InMemoryEntityHistory {
418
470
  #id;
@@ -575,6 +627,12 @@ export class InMemoryEntityHistory {
575
627
  isOpen() {
576
628
  return this.#records.isOpen();
577
629
  }
630
+ /**
631
+ * Deletes selected state-record keys in bounded maintenance chunks.
632
+ *
633
+ * @param entries State-record keys selected for deletion.
634
+ * @returns Completes after all chunks have been deleted.
635
+ */
578
636
  async deleteEntries(entries) {
579
637
  for (let start = 0; start < entries.length; start += this.batchSize()) {
580
638
  for (const entry of entries.slice(start, start + this.batchSize())) {
@@ -583,6 +641,12 @@ export class InMemoryEntityHistory {
583
641
  await this.afterMaintenanceChunk();
584
642
  }
585
643
  }
644
+ /**
645
+ * Builds a state-history key from an Entity ID and version.
646
+ *
647
+ * @param record Generated Entity record to identify.
648
+ * @returns Composite state-history key.
649
+ */
586
650
  keyFor(record) {
587
651
  if (record.entityId === undefined || record.version === undefined) {
588
652
  throw new Error("State history requires EntityRecord.entityId and EntityRecord.version.");
@@ -592,6 +656,12 @@ export class InMemoryEntityHistory {
592
656
  version: record.version.number,
593
657
  });
594
658
  }
659
+ /**
660
+ * Decodes the Entity ID stored in a generated record.
661
+ *
662
+ * @param record Generated Entity record to inspect.
663
+ * @returns Entity ID matching the configured codec.
664
+ */
595
665
  entityIdIn(record) {
596
666
  if (record.entityId === undefined) {
597
667
  throw new Error("State history requires EntityRecord.entityId.");
@@ -602,6 +672,11 @@ export class InMemoryEntityHistory {
602
672
  }
603
673
  return entityId;
604
674
  }
675
+ /**
676
+ * Checks an Entity record's ID, timestamp, and state schema before storage.
677
+ *
678
+ * @param record Generated Entity record proposed for history.
679
+ */
605
680
  validateRecord(record) {
606
681
  this.entityIdIn(record);
607
682
  if (record.version?.timestamp === undefined) {
@@ -609,6 +684,12 @@ export class InMemoryEntityHistory {
609
684
  }
610
685
  this.unpackState(record);
611
686
  }
687
+ /**
688
+ * Decodes a state whose type URL matches the configured state schema.
689
+ *
690
+ * @param record Generated Entity record containing a packed state.
691
+ * @returns Frozen decoded Entity state.
692
+ */
612
693
  unpackState(record) {
613
694
  const state = record.state;
614
695
  if (!state?.typeUrl.endsWith(`/${this.#stateSchema.typeName}`)) {
@@ -616,21 +697,44 @@ export class InMemoryEntityHistory {
616
697
  }
617
698
  return Object.freeze(fromBinary(this.#stateSchema, state.value));
618
699
  }
700
+ /**
701
+ * Rejects an operation after this state-history handle closes.
702
+ */
619
703
  requireOpen() {
620
704
  if (!this.isOpen())
621
705
  throw new Error("Entity history storage is closed.");
622
706
  }
707
+ /**
708
+ * Invokes the maintenance selection hook and checks that the handle remains open.
709
+ *
710
+ * @returns Completes after the selection hook.
711
+ */
623
712
  async afterSelection() {
624
713
  await this.#maintenance?.afterSelection?.();
625
714
  this.requireOpen();
626
715
  }
716
+ /**
717
+ * Invokes the maintenance chunk hook and checks that the handle remains open.
718
+ *
719
+ * @returns Completes after the chunk hook.
720
+ */
627
721
  async afterMaintenanceChunk() {
628
722
  await this.#maintenance?.onChunk?.();
629
723
  this.requireOpen();
630
724
  }
725
+ /**
726
+ * Reads the configured maintenance deletion chunk size.
727
+ *
728
+ * @returns Configured or default chunk size.
729
+ */
631
730
  batchSize() {
632
731
  return this.#maintenance?.batchSize ?? MAINTENANCE_BATCH_SIZE;
633
732
  }
733
+ /**
734
+ * Reads the configured history query page size.
735
+ *
736
+ * @returns Configured or default page size.
737
+ */
634
738
  pageSize() {
635
739
  return this.#maintenance?.pageSize ?? HISTORY_PAGE_SIZE;
636
740
  }
@@ -643,6 +747,7 @@ export class KeyedSerialQueue {
643
747
  /**
644
748
  * Queues an operation after earlier operations with the same key finish.
645
749
  *
750
+ * @typeParam T Result type returned by the queued operation.
646
751
  * @param key Identifies the serialized operation sequence.
647
752
  * @param operation Supplies the operation to run.
648
753
  * @returns Resolves to the operation result.
@@ -673,6 +778,10 @@ const HistoryOrdering = {
673
778
  // prettier-ignore
674
779
  /**
675
780
  * Compares timestamps by seconds and nanos.
781
+ *
782
+ * @param left First timestamp to compare.
783
+ * @param right Second timestamp to compare.
784
+ * @returns Signed chronological comparison.
676
785
  */
677
786
  compareTime(left, right) {
678
787
  return Number(left.seconds - right.seconds) || left.nanos - right.nanos;
@@ -682,6 +791,19 @@ const HistoryOrdering = {
682
791
  * Traverses finite RecordStorage windows with an exact stable keyset continuation.
683
792
  */
684
793
  const HistoryPaging = {
794
+ /**
795
+ * Reads finite record pages and visits each page using stable keyset continuation.
796
+ *
797
+ * @typeParam I Record identifier type used by the storage query.
798
+ * @typeParam R Generated record message type in each page.
799
+ * @param records Storage queried in pages.
800
+ * @param query Filters applied to every page.
801
+ * @param sort Stable field order used by the continuation.
802
+ * @param pageSize Maximum records requested per page.
803
+ * @param valueIn Reads an ordered field from a record.
804
+ * @param visit Processes a page and returns whether scanning should continue.
805
+ * @returns Completes after all pages or an early visitor stop.
806
+ */
685
807
  async scan(records, query, sort, pageSize, valueIn, visit) {
686
808
  let after;
687
809
  do {
@@ -714,6 +836,10 @@ const HistoryIdentity = {
714
836
  // prettier-ignore
715
837
  /**
716
838
  * Determines whether two generated Entity records have identical binary content.
839
+ *
840
+ * @param left First generated Entity record.
841
+ * @param right Second generated Entity record.
842
+ * @returns True when their serialized bytes match.
717
843
  */
718
844
  sameEntityRecord(left, right) {
719
845
  return CanonicalBytes.equal(toBinary(EntityRecordSchema, left), toBinary(EntityRecordSchema, right));
@@ -723,16 +849,31 @@ const HistoryIdentity = {
723
849
  * Validates bounded history requests.
724
850
  */
725
851
  const HistoryLimits = {
852
+ /**
853
+ * Rejects a history depth that is not a positive safe integer.
854
+ *
855
+ * @param depth Requested number of history entries.
856
+ */
726
857
  requireDepth(depth) {
727
858
  if (!Number.isSafeInteger(depth) || depth <= 0) {
728
859
  throw new Error("History depth must be a positive safe integer.");
729
860
  }
730
861
  },
862
+ /**
863
+ * Rejects an invalid optional maintenance deletion chunk size.
864
+ *
865
+ * @param batchSize Requested records per deletion chunk.
866
+ */
731
867
  requireBatchSize(batchSize) {
732
868
  if (batchSize !== undefined && (!Number.isSafeInteger(batchSize) || batchSize <= 0)) {
733
869
  throw new Error("In-memory maintenance batch size must be a positive safe integer.");
734
870
  }
735
871
  },
872
+ /**
873
+ * Rejects an invalid optional history query page size.
874
+ *
875
+ * @param pageSize Requested records per query page.
876
+ */
736
877
  requirePageSize(pageSize) {
737
878
  if (pageSize !== undefined && (!Number.isSafeInteger(pageSize) || pageSize <= 0)) {
738
879
  throw new Error("In-memory history page size must be a positive safe integer.");
@@ -748,6 +889,10 @@ const CanonicalBytes = {
748
889
  // prettier-ignore
749
890
  /**
750
891
  * Compares two durable byte sequences.
892
+ *
893
+ * @param left First byte sequence.
894
+ * @param right Second byte sequence.
895
+ * @returns True when lengths and bytes match.
751
896
  */
752
897
  equal(left, right) {
753
898
  return left.length === right.length && left.every((value, index) => value === right[index]);