@spine-event-engine/storage 2.0.0-snapshot.23 → 2.0.0-snapshot.25

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 (121) hide show
  1. package/README.md +12 -3
  2. package/REFERENCE.md +90 -63
  3. package/dist/entity/agent-history-record-spec.d.ts +8 -0
  4. package/dist/entity/agent-history-record-spec.d.ts.map +1 -1
  5. package/dist/entity/agent-history-record-spec.js +12 -1
  6. package/dist/entity/agent-history-record-spec.js.map +1 -1
  7. package/dist/entity/agent-history.d.ts +25 -0
  8. package/dist/entity/agent-history.d.ts.map +1 -1
  9. package/dist/entity/agent-history.js.map +1 -1
  10. package/dist/entity/history-conformance.d.ts +38 -8
  11. package/dist/entity/history-conformance.d.ts.map +1 -1
  12. package/dist/entity/history-conformance.js +103 -58
  13. package/dist/entity/history-conformance.js.map +1 -1
  14. package/dist/event/event-store.d.ts +80 -74
  15. package/dist/event/event-store.d.ts.map +1 -1
  16. package/dist/event/event-store.js +264 -264
  17. package/dist/event/event-store.js.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/internal/agent-model-preferences.d.ts +76 -0
  23. package/dist/internal/agent-model-preferences.d.ts.map +1 -0
  24. package/dist/internal/agent-model-preferences.js +133 -0
  25. package/dist/internal/agent-model-preferences.js.map +1 -0
  26. package/dist/internal/entity-commit.d.ts +92 -17
  27. package/dist/internal/entity-commit.d.ts.map +1 -1
  28. package/dist/internal/entity-commit.js +45 -2
  29. package/dist/internal/entity-commit.js.map +1 -1
  30. package/dist/internal/entity-history.d.ts +1 -7
  31. package/dist/internal/entity-history.d.ts.map +1 -1
  32. package/dist/internal/entity-history.js +0 -5
  33. package/dist/internal/entity-history.js.map +1 -1
  34. package/dist/internal/event-store.d.ts +1 -1
  35. package/dist/internal/event-store.d.ts.map +1 -1
  36. package/dist/internal/event-store.js +1 -1
  37. package/dist/internal/event-store.js.map +1 -1
  38. package/dist/internal/storage-preparation.d.ts +88 -0
  39. package/dist/internal/storage-preparation.d.ts.map +1 -0
  40. package/dist/internal/storage-preparation.js +41 -0
  41. package/dist/internal/storage-preparation.js.map +1 -0
  42. package/dist/internal/tenancy.d.ts +7 -0
  43. package/dist/internal/tenancy.d.ts.map +1 -1
  44. package/dist/memory/in-memory-agent-history.d.ts.map +1 -1
  45. package/dist/memory/in-memory-agent-history.js +22 -7
  46. package/dist/memory/in-memory-agent-history.js.map +1 -1
  47. package/dist/memory/in-memory-entity-commit.d.ts +237 -42
  48. package/dist/memory/in-memory-entity-commit.d.ts.map +1 -1
  49. package/dist/memory/in-memory-entity-commit.js +529 -325
  50. package/dist/memory/in-memory-entity-commit.js.map +1 -1
  51. package/dist/memory/in-memory-entity-history.d.ts.map +1 -1
  52. package/dist/memory/in-memory-entity-history.js +4 -3
  53. package/dist/memory/in-memory-entity-history.js.map +1 -1
  54. package/dist/memory/in-memory-storage-backend.d.ts +33 -1
  55. package/dist/memory/in-memory-storage-backend.d.ts.map +1 -1
  56. package/dist/memory/in-memory-storage-backend.js +118 -1
  57. package/dist/memory/in-memory-storage-backend.js.map +1 -1
  58. package/dist/memory/in-memory-storage-factory.d.ts +72 -13
  59. package/dist/memory/in-memory-storage-factory.d.ts.map +1 -1
  60. package/dist/memory/in-memory-storage-factory.js +199 -30
  61. package/dist/memory/in-memory-storage-factory.js.map +1 -1
  62. package/dist/memory/tenant-records.d.ts +1 -1
  63. package/dist/memory/tenant-records.d.ts.map +1 -1
  64. package/dist/memory/tenant-records.js +3 -2
  65. package/dist/memory/tenant-records.js.map +1 -1
  66. package/dist/provider.d.ts +2 -1
  67. package/dist/provider.d.ts.map +1 -1
  68. package/dist/provider.js +2 -1
  69. package/dist/provider.js.map +1 -1
  70. package/dist/record/record-query.d.ts +10 -2
  71. package/dist/record/record-query.d.ts.map +1 -1
  72. package/dist/record/record-query.js +9 -0
  73. package/dist/record/record-query.js.map +1 -1
  74. package/dist/storage/storage-factory.d.ts +27 -4
  75. package/dist/storage/storage-factory.d.ts.map +1 -1
  76. package/dist/storage/storage-factory.js +30 -1
  77. package/dist/storage/storage-factory.js.map +1 -1
  78. package/dist/storage/storage.d.ts +2 -1
  79. package/dist/storage/storage.d.ts.map +1 -1
  80. package/dist/tsconfig.tsbuildinfo +1 -1
  81. package/package.json +3 -3
  82. package/dist/entity/agent-execution-record-spec.d.ts +0 -87
  83. package/dist/entity/agent-execution-record-spec.d.ts.map +0 -1
  84. package/dist/entity/agent-execution-record-spec.js +0 -230
  85. package/dist/entity/agent-execution-record-spec.js.map +0 -1
  86. package/dist/entity/agent-execution-sizes.d.ts +0 -30
  87. package/dist/entity/agent-execution-sizes.d.ts.map +0 -1
  88. package/dist/entity/agent-execution-sizes.js +0 -51
  89. package/dist/entity/agent-execution-sizes.js.map +0 -1
  90. package/dist/entity/agent-execution-transitions.d.ts +0 -71
  91. package/dist/entity/agent-execution-transitions.d.ts.map +0 -1
  92. package/dist/entity/agent-execution-transitions.js +0 -182
  93. package/dist/entity/agent-execution-transitions.js.map +0 -1
  94. package/dist/entity/agent-execution-values.d.ts +0 -142
  95. package/dist/entity/agent-execution-values.d.ts.map +0 -1
  96. package/dist/entity/agent-execution-values.js +0 -250
  97. package/dist/entity/agent-execution-values.js.map +0 -1
  98. package/dist/entity/agent-execution.d.ts +0 -234
  99. package/dist/entity/agent-execution.d.ts.map +0 -1
  100. package/dist/entity/agent-execution.js +0 -15
  101. package/dist/entity/agent-execution.js.map +0 -1
  102. package/dist/internal/agent-execution.d.ts +0 -51
  103. package/dist/internal/agent-execution.d.ts.map +0 -1
  104. package/dist/internal/agent-execution.js +0 -53
  105. package/dist/internal/agent-execution.js.map +0 -1
  106. package/dist/internal/delivery-cleanup.d.ts +0 -99
  107. package/dist/internal/delivery-cleanup.d.ts.map +0 -1
  108. package/dist/internal/delivery-cleanup.js +0 -38
  109. package/dist/internal/delivery-cleanup.js.map +0 -1
  110. package/dist/memory/agent-execution-head-index.d.ts +0 -52
  111. package/dist/memory/agent-execution-head-index.d.ts.map +0 -1
  112. package/dist/memory/agent-execution-head-index.js +0 -91
  113. package/dist/memory/agent-execution-head-index.js.map +0 -1
  114. package/dist/memory/in-memory-agent-execution.d.ts +0 -21
  115. package/dist/memory/in-memory-agent-execution.d.ts.map +0 -1
  116. package/dist/memory/in-memory-agent-execution.js +0 -587
  117. package/dist/memory/in-memory-agent-execution.js.map +0 -1
  118. package/dist/memory/memory-delivery-cleanup.d.ts +0 -32
  119. package/dist/memory/memory-delivery-cleanup.d.ts.map +0 -1
  120. package/dist/memory/memory-delivery-cleanup.js +0 -61
  121. package/dist/memory/memory-delivery-cleanup.js.map +0 -1
@@ -17,5 +17,5 @@
17
17
  * Storage adapters use this subpath to address the same durable records as the
18
18
  * framework Event Store without adding the layout to the end-user package root.
19
19
  */
20
- export { eventStoreAccess, eventStoreRecordSpec } from "../event/event-store.js";
20
+ export { eventStoreAccess, eventStoreRecordSpec, EventStoreGroups } from "../event/event-store.js";
21
21
  //# sourceMappingURL=event-store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"event-store.js","sourceRoot":"","sources":["../../src/internal/event-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"event-store.js","sourceRoot":"","sources":["../../src/internal/event-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,88 @@
1
+ import type { Message } from "@bufbuild/protobuf";
2
+ import type { AgentHistoryStorageInput } from "../entity/agent-history.js";
3
+ import type { EntityStorageInput } from "../memory/in-memory-entity-history.js";
4
+ import type { RecordSpec } from "../record/record-spec.js";
5
+ import type { StorageGroup } from "../record/storage-group.js";
6
+ import type { StorageFactory } from "../storage/storage-factory.js";
7
+ import type { StorageContext } from "../storage/storage.js";
8
+ /**
9
+ * Selects creation or read-only compatibility checking.
10
+ */
11
+ export type StoragePreparationMode = "create" | "check";
12
+ /**
13
+ * Declares an Entity without borrowed history handles.
14
+ *
15
+ * @typeParam I Entity identifier type.
16
+ * @typeParam S Entity state type.
17
+ */
18
+ export type EntityStoragePreparationInput<I, S extends Message> = Omit<EntityStorageInput<I, S>, "stateHistoryStorage" | "eventHistoryStorage">;
19
+ /**
20
+ * Provider-only operations that establish physical storage requirements.
21
+ */
22
+ export interface StoragePreparation {
23
+ /**
24
+ * Prepares one ordinary record family.
25
+ *
26
+ * @typeParam I Record identifier type.
27
+ * @typeParam R Record message type.
28
+ * @param context Complete storage scope.
29
+ * @param spec Declarative record layout.
30
+ * @param group Optional physical group.
31
+ * @param mode Creation or read-only compatibility check.
32
+ * @returns Completion after the requirement is established.
33
+ */
34
+ prepareRecord<I, R extends Message>(context: StorageContext, spec: RecordSpec<I, R>, group: StorageGroup | undefined, mode: StoragePreparationMode): Promise<void>;
35
+ /**
36
+ * Prepares current Entity records and enabled history families.
37
+ *
38
+ * @typeParam I Entity identifier type.
39
+ * @typeParam S Entity state type.
40
+ * @param input Complete declarative Entity layout.
41
+ * @param mode Creation or read-only compatibility check.
42
+ * @returns Completion after the requirements are established.
43
+ */
44
+ prepareEntity<I, S extends Message>(input: EntityStoragePreparationInput<I, S>, mode: StoragePreparationMode): Promise<void>;
45
+ /**
46
+ * Prepares the surviving Agent audit history family.
47
+ *
48
+ * @typeParam I Agent identifier type.
49
+ * @param input Agent history scope and codec.
50
+ * @param mode Creation or read-only compatibility check.
51
+ * @returns Completion after the audit requirement is established.
52
+ */
53
+ prepareAgentHistory<I>(input: AgentHistoryStorageInput<I>, mode: StoragePreparationMode): Promise<void>;
54
+ /**
55
+ * Prepares current Entity, enabled histories, final Agent audit, and model preferences.
56
+ * @typeParam I Typed Agent identifier.
57
+ * @typeParam S Generated Agent state.
58
+ * @param input Declarative Agent Entity layout.
59
+ * @param mode Creation or read-only compatibility check.
60
+ * @returns Completion after native transactional requirements are checked.
61
+ */
62
+ prepareAgentCommit<I, S extends Message>(input: EntityStoragePreparationInput<I, S>, mode: StoragePreparationMode): Promise<void>;
63
+ }
64
+ /**
65
+ * Registers and finds provider preparation capabilities.
66
+ */
67
+ interface StoragePreparationAccess {
68
+ /**
69
+ * Registers a provider preparation port.
70
+ *
71
+ * @param factory The provider factory.
72
+ * @param preparation Its preparation implementation.
73
+ */
74
+ register(factory: StorageFactory, preparation: StoragePreparation): void;
75
+ /**
76
+ * Finds a registered preparation port.
77
+ *
78
+ * @param factory The provider factory.
79
+ * @returns Its preparation port.
80
+ */
81
+ for(factory: StorageFactory): StoragePreparation;
82
+ }
83
+ /**
84
+ * Framework lookup for a provider's registered preparation capability.
85
+ */
86
+ export declare const StoragePreparations: StoragePreparationAccess;
87
+ export {};
88
+ //# sourceMappingURL=storage-preparation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-preparation.d.ts","sourceRoot":"","sources":["../../src/internal/storage-preparation.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,OAAO,CAAC;AAExD;;;;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,mBAAmB,EAAE,wBAuBhC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright 2026, CodeMatters. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * https://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ const preparations = new WeakMap();
15
+ /**
16
+ * Framework lookup for a provider's registered preparation capability.
17
+ */
18
+ export const StoragePreparations = Object.freeze({
19
+ /**
20
+ * Registers a provider preparation port.
21
+ *
22
+ * @param factory The provider factory.
23
+ * @param preparation Its preparation implementation.
24
+ */
25
+ register(factory, preparation) {
26
+ preparations.set(factory, preparation);
27
+ },
28
+ /**
29
+ * Finds a registered preparation port, rejecting unsupported providers.
30
+ *
31
+ * @param factory The provider factory.
32
+ * @returns Its preparation port.
33
+ */
34
+ for(factory) {
35
+ const preparation = preparations.get(factory);
36
+ if (preparation === undefined)
37
+ throw new Error("StorageFactory does not support storage preparation.");
38
+ return preparation;
39
+ },
40
+ });
41
+ //# sourceMappingURL=storage-preparation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-preparation.js","sourceRoot":"","sources":["../../src/internal/storage-preparation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0FH,MAAM,YAAY,GAAG,IAAI,OAAO,EAAsC,CAAC;AAuBvE;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA6B,MAAM,CAAC,MAAM,CAAC;IACzE;;;;;OAKG;IACH,QAAQ,CAAC,OAAuB,EAAE,WAA+B;QAC/D,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,OAAuB;QACzB,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,WAAW,KAAK,SAAS;YAC3B,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC,CAAC"}
@@ -131,6 +131,13 @@ export declare const TenantCatalogReads: Readonly<{
131
131
  * @internal
132
132
  */
133
133
  export interface TenantCatalog {
134
+ /**
135
+ * Checks current membership without registering or preparing storage.
136
+ *
137
+ * @param boundary Complete tenant boundary to inspect.
138
+ * @returns Whether this catalog currently includes the boundary.
139
+ */
140
+ contains(boundary: TenantBoundary): Promise<boolean>;
134
141
  /**
135
142
  * Lists the boundaries available for storage-backed startup work.
136
143
  *
@@ -1 +1 @@
1
- {"version":3,"file":"tenancy.d.ts","sourceRoot":"","sources":["../../src/internal/tenancy.ts"],"names":[],"mappings":"AAeA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI5D;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAG7B;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;CACzC;AAED,UAAU,yBAA0B,SAAQ,cAAc;IACxD,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,yBAAyB,CA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CAYnF,CAAC;AAEL;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAG5B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAErD;;;;OAIG;IACH,GAAG,IAAI,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAAC;IAE1C;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE7D;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IAGpC;;;;OAIG;IACH,aAAa,IAAI,aAAa,CAAC;CAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-agent-history.d.ts","sourceRoot":"","sources":["../../src/memory/in-memory-agent-history.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAGV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAGxE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,EACL,OAAO,EAAE,sBAAsB,EAC/B,KAAK,EAAE,wBAAwB,CAAC,EAAE,CAAC,GAClC,mBAAmB,CAAC,EAAE,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,wBA2B/B,CAAC"}
1
+ {"version":3,"file":"in-memory-agent-history.d.ts","sourceRoot":"","sources":["../../src/memory/in-memory-agent-history.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAGV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAGxE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,EACL,OAAO,EAAE,sBAAsB,EAC/B,KAAK,EAAE,wBAAwB,CAAC,EAAE,CAAC,GAClC,mBAAmB,CAAC,EAAE,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,wBA2B/B,CAAC"}
@@ -11,6 +11,8 @@
11
11
  * or implied. See the License for the specific language governing permissions and limitations under
12
12
  * the License.
13
13
  */
14
+ import { clone } from "@bufbuild/protobuf";
15
+ import { AgentHistoryEntrySchema } from "@spine-event-engine/proto/agent";
14
16
  import { TenantBoundary } from "../internal/tenancy.js";
15
17
  import { AgentHistoryIndex } from "./agent-history-index.js";
16
18
  import { AgentHistoryMutationQueue } from "./agent-history-mutation-queue.js";
@@ -40,6 +42,7 @@ export const MemoryAgentHistory = Object.freeze({
40
42
  * @typeParam Id Typed Agent identifier.
41
43
  */
42
44
  class MemoryAgentHistoryHandle {
45
+ capacity = Object.freeze({});
43
46
  #idKey;
44
47
  #records;
45
48
  #queue;
@@ -64,15 +67,27 @@ class MemoryAgentHistoryHandle {
64
67
  * @returns Resolves after the entry is indexed.
65
68
  */
66
69
  append(entityId, entry) {
70
+ return this.appendAll(entityId, [entry]);
71
+ }
72
+ /**
73
+ * Writes atomically adds an immutable group after validating all rows and indexes.
74
+ *
75
+ * @param entityId Typed Entity identifier.
76
+ * @param entries Complete immutable history group.
77
+ * @returns Completion after the immutable audit group commits atomically.
78
+ */
79
+ async appendAll(entityId, entries) {
80
+ this.#requireOpen();
67
81
  const key = this.#key(entityId);
68
- return this.#queue.run(key, () => {
69
- this.#requireOpen();
70
- let index = this.#records.get(key);
71
- if (index === undefined) {
72
- index = new AgentHistoryIndex();
82
+ const captured = entries.map((entry) => clone(AgentHistoryEntrySchema, entry));
83
+ if (captured.length === 0)
84
+ return;
85
+ await this.#queue.run(key, () => {
86
+ const existing = this.#records.get(key);
87
+ const index = existing ?? new AgentHistoryIndex();
88
+ index.withEntries(captured).apply();
89
+ if (existing === undefined)
73
90
  this.#records.set(key, index);
74
- }
75
- index.append(entry);
76
91
  });
77
92
  }
78
93
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-agent-history.js","sourceRoot":"","sources":["../../src/memory/in-memory-agent-history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAqBxE;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA6B,MAAM,CAAC,MAAM,CAAC;IACxE;;;;;;;OAOG;IACH,IAAI,CACF,OAA+B,EAC/B,KAAmC;QAEnC,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAC;QAC9F,MAAM,OAAO,GAAG,sBAAsB,CAAC,IAAI,CACzC,OAAO,EACP,QAAQ,EACR,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAChC,iBAAiB,KAAK,CAAC,SAAS,EAAE,EAClC,GAAG,EAAE,CAAC,IAAI,GAAG,EAA6B,CAC3C,CAAC;QACF,OAAO,IAAI,wBAAwB,CACjC,KAAK,CAAC,EAAE,CAAC,GAAG,EACZ,OAAO,EACP,yBAAyB,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAC1E,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,wB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C,QAAY;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;QAClF,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;OAEG;IACH,YAAY;QACV,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC9E,CAAC;CACF"}
@@ -1,84 +1,279 @@
1
1
  import { type Message } from "@bufbuild/protobuf";
2
- import type { EntityCommitInput, EntityCommitStorage } from "../internal/entity-commit.js";
2
+ import { type ModelPreference } from "@spine-event-engine/proto/agent";
3
+ import { type AgentCommitInput, type EntityCommitInput, type EntityCommitStorage } from "../internal/entity-commit.js";
3
4
  import type { RecordSpec } from "../record/record-spec.js";
4
5
  import type { StorageGroup } from "../record/storage-group.js";
5
6
  import type { StorageContext } from "../storage/storage.js";
6
- import type { StorageFactory } from "../storage/storage-factory.js";
7
7
  import { MemoryEntityStorageFactory, type EntityStorageInput } from "./in-memory-entity-history.js";
8
8
  import { TenantRecords } from "./tenant-records.js";
9
+ import { InMemoryStorageBackend } from "./in-memory-storage-backend.js";
9
10
  /**
10
- * Opens the in-memory tenant slice for a generated record family.
11
+ * Acquires one tenant slice for a generated record family.
11
12
  *
12
13
  * @typeParam I Record identifier type.
13
- * @typeParam R Record message type.
14
- * @param context Supplies the storage and tenant context.
15
- * @param spec Supplies the materialized record layout.
16
- * @param group Selects a grouped history family when present.
17
- * @returns The tenant record slice.
14
+ * @typeParam R Stored message type.
18
15
  */
19
16
  type OpenRecords = <I, R extends Message>(context: StorageContext, spec: RecordSpec<I, R>, group?: StorageGroup) => TenantRecords<I, R>;
20
17
  /**
21
- * Implements provider Entity commits for one shared in-memory backend.
18
+ * Writes in-memory Entity records in order and retains a completed prefix.
22
19
  */
23
20
  export declare class MemoryEntityCommitStorage implements EntityCommitStorage {
24
21
  #private;
22
+ private readonly entities;
23
+ private readonly openRecords;
24
+ private readonly input;
25
+ private readonly backend;
26
+ private readonly onClose;
25
27
  /**
26
- * Creates a commit handle bound to one Entity source type.
28
+ * Creates one source- and tenant-bound commit handle.
27
29
  *
28
- * @param entities Opens the matching current Entity storage.
29
- * @param factory Provides the Event Store coordination lock.
30
- * @param openRecords Opens exact generic-record backing slices.
31
- * @param input Defines the Entity storage source type.
30
+ * @param entities Opens current Entity storage.
31
+ * @param openRecords Opens generated history and Event record slices.
32
+ * @param input Captures the Entity source and tenant boundary.
33
+ * @param backend Shared tenant memory families for preferences and audit.
34
+ * @param onClose Releases factory tracking after terminal cleanup.
32
35
  */
33
- constructor(entities: MemoryEntityStorageFactory, factory: StorageFactory, openRecords: OpenRecords, input: EntityStorageInput<unknown, Message>);
36
+ constructor(entities: MemoryEntityStorageFactory, openRecords: OpenRecords, input: EntityStorageInput<unknown, Message>, backend: InMemoryStorageBackend, onClose?: () => void);
34
37
  /**
35
- * Applies one fully preflighted in-memory Entity commit.
38
+ * Binds shared Agent families only when this handle performs Agent work.
39
+ * @returns Cached preference, audit, and mutation-queue families.
40
+ */
41
+ private agentFamilies;
42
+ /**
43
+ * Writes history, diagnostics, delivery Events, then current state.
36
44
  *
37
45
  * @typeParam I Entity identifier type.
38
46
  * @typeParam S Entity state type.
39
- * @param input Defines the current record, retained histories, and delivery events.
40
- * @returns Completion after the in-memory commit.
47
+ * @param input Supplies the proposed mutation.
48
+ * @returns Completion after every record has been stored.
41
49
  */
42
50
  commit<I, S extends Message>(input: EntityCommitInput<I, S>): Promise<void>;
43
51
  /**
44
- * Applies an Agent completion only while the current Entity Version matches.
52
+ * Reads a detached current preference image from the retained tenant family.
53
+ * @param entityId Typed Agent identifier.
54
+ * @returns Complete selections or absent record.
55
+ */
56
+ readAgentPreferences(entityId: unknown): Promise<readonly ModelPreference[] | undefined>;
57
+ /**
58
+ * Commits Agent state, final audit, and preferences under shared memory queues.
59
+ * @param input Captured initial images and prepared transition.
60
+ * @returns Completion after one conditional group.
61
+ * @typeParam I Typed Agent identifier.
62
+ * @typeParam S Generated Agent state.
63
+ */
64
+ commitAgent<I, S extends Message>(input: AgentCommitInput<I, S>): Promise<void>;
65
+ /**
66
+ * Validates the fixed Entity identity and one-version transition.
67
+ * @param entityId Captured Agent identifier.
68
+ * @param expectedVersion Initial Entity Version.
69
+ * @param entityCommit Optional prepared current-state mutation.
70
+ */
71
+ private validateAgentCommit;
72
+ /**
73
+ * Records final audit and preference replacements inside the Entity mutation.
74
+ * @param entityId Captured Agent identifier.
75
+ * @param slot Bounded preference record slot.
76
+ * @param expectedVersion Initial Entity Version.
77
+ * @param expected Initial preference image.
78
+ * @param next Complete next preference record.
79
+ * @param entityCommit Optional prepared current-state mutation.
80
+ * @param history Captured final audit rows.
81
+ * @returns Completion after one conditional group.
82
+ */
83
+ private commitAgentLocked;
84
+ /**
85
+ * Replaces preference and final audit rows with rollback for failed Entity work.
86
+ * @param slot Bounded preference record slot.
87
+ * @param next Complete next preference record.
88
+ * @param expected Initial preference image.
89
+ * @param prior Previously retained preference record.
90
+ * @param agentKey Canonical Agent identifier.
91
+ * @param index Current or new audit index.
92
+ * @param priorIndex Previously retained audit index.
93
+ * @param staged Reversible final audit batch.
94
+ * @returns Reversible publication callbacks.
95
+ */
96
+ private agentPublication;
97
+ /**
98
+ * Calculates a bounded v1 slot from complete preference identity evidence.
99
+ * @param key Complete generated Agent identity.
100
+ * @returns Fixed 67-character provider slot.
101
+ */
102
+ private preferenceSlot;
103
+ /**
104
+ * Performs the captured conditional Agent change.
105
+ *
106
+ * @param entity The Entity persistence contract.
107
+ * @param entityId The captured Entity identifier.
108
+ * @param expectedVersion The required prior Entity version.
109
+ * @param extra The additional conditional records.
110
+ * @param input The captured Entity persistence input.
111
+ * @returns Completion after the conditional Agent change settles.
112
+ * @typeParam I Entity identifier or record type.
113
+ * @typeParam S Generated Entity state message type.
114
+ */
115
+ private runAgentConditional;
116
+ /**
117
+ * Applies one prepared Agent transition and restores affected rows on failure.
118
+ *
119
+ * @typeParam I Entity identifier type.
120
+ * @typeParam S Entity state type.
121
+ * @param entity Configured Entity storage layout.
122
+ * @param backend Shared current records for this Entity scope.
123
+ * @param key Canonical Entity ID key.
124
+ * @param expectedVersion Version read before handler execution.
125
+ * @param snapshot Optional captured Entity state transition.
126
+ * @param extra Applies or restores Agent audit records and model preferences.
127
+ * @returns Completion after the transition is stored.
128
+ */
129
+ private applyAgentConditional;
130
+ /**
131
+ * Writes immutable Agent state history after checking each Version slot.
132
+ *
133
+ * @param states State-history records when that family is configured.
134
+ * @param prepared Materialized state rows from the captured transition.
135
+ */
136
+ private writeAgentStates;
137
+ /**
138
+ * Closes retained resources after admitted work settles.
139
+ *
140
+ * @returns The repeatable close outcome.
141
+ */
142
+ close(): Promise<void>;
143
+ /**
144
+ * Closes retained adapters only when no commit is admitted.
145
+ */
146
+ closeIdle(): void;
147
+ /**
148
+ * Applies one captured mutation without cross-record compensation.
149
+ *
150
+ * @typeParam I Entity identifier type.
151
+ * @typeParam S Entity state type.
152
+ * @param input Supplies immutable record snapshots.
153
+ * @returns Completion after every requested record write.
154
+ */
155
+ private apply;
156
+ /**
157
+ * Acquires only missing record families and retains them for this handle.
158
+ *
159
+ * @typeParam I Entity identifier type.
160
+ * @typeParam S Entity state type.
161
+ * @param input Supplies requested history and delivery records.
162
+ * @returns Retained Entity and requested family handles.
163
+ */
164
+ private openCommit;
165
+ /**
166
+ * Acquires the current Entity adapter once.
167
+ *
168
+ * @param acquired Newly acquired handles to close on failure.
169
+ * @param input The captured Entity persistence input.
170
+ * @returns The retained current Entity record handle.
171
+ * @typeParam I Entity identifier or record type.
172
+ * @typeParam S Generated Entity state message type.
173
+ */
174
+ private openCurrent;
175
+ /**
176
+ * Acquires retained state-history storage and its adapter.
177
+ *
178
+ * @param acquired Newly acquired handles to close on failure.
179
+ * @param input The captured Entity persistence input.
180
+ * @returns The retained state-history record handle.
181
+ * @typeParam I Entity identifier or record type.
182
+ * @typeParam S Generated Entity state message type.
183
+ */
184
+ private openStates;
185
+ /**
186
+ * Acquires retained diagnostic history storage and its adapter.
187
+ *
188
+ * @param acquired Newly acquired handles to close on failure.
189
+ * @param input The captured Entity persistence input.
190
+ * @returns The retained diagnostic Event record handle.
191
+ * @typeParam I Entity identifier or record type.
192
+ * @typeParam S Generated Entity state message type.
193
+ */
194
+ private openDiagnostics;
195
+ /**
196
+ * Acquires retained delivery Event storage.
197
+ *
198
+ * @param acquired Newly acquired handles to close on failure.
199
+ * @param input The captured Entity persistence input.
200
+ * @returns The retained delivery Event record handle.
201
+ * @typeParam I Entity identifier or record type.
202
+ * @typeParam S Generated Entity state message type.
203
+ */
204
+ private openDelivery;
205
+ /**
206
+ * Registers provider work before invoking the operation.
207
+ *
208
+ * @param action The admitted provider operation.
209
+ * @returns The admitted provider operation completion.
210
+ * @typeParam Value Result type of the admitted provider operation.
211
+ */
212
+ private track;
213
+ /**
214
+ * Waits for admitted commits and reports every retained close failure.
215
+ *
216
+ * @returns Completion after admitted work and cleanup settle.
217
+ */
218
+ private drain;
219
+ /**
220
+ * Closes retained adapters once after no commit remains active.
221
+ *
222
+ * @returns A cleanup failure, if any.
223
+ */
224
+ private closeRetained;
225
+ /**
226
+ * Closes every newly acquired handle and collects cleanup failures.
227
+ *
228
+ * @param ports The acquired record handles.
229
+ * @returns Cleanup failures from acquired handles.
230
+ */
231
+ private closeGroup;
232
+ /**
233
+ * Writes one immutable delivery Event or accepts an identical retry.
45
234
  *
46
- * @typeParam I Typed Entity identifier.
47
- * @typeParam S Generated Entity state.
48
- * @param entity Existing Entity layout.
49
- * @param entityId Typed Entity identifier.
50
- * @param expectedVersion Version observed before Agent handlers ran.
51
- * @param input Current-state mutation, absent for a no-op.
52
- * @param extra Staged execution and history publication with restoration.
53
- * @returns Completion after conditional Entity and execution publication.
235
+ * @param storage Supplies atomic single-record insertion.
236
+ * @param id Identifies the delivery Event.
237
+ * @param event Supplies the captured Event.
238
+ * @returns Completion after an identical Event is stored.
54
239
  */
55
- commitConditional<I, S extends Message>(entity: EntityStorageInput<I, S>, entityId: I, expectedVersion: number, input: EntityCommitInput<I, S> | undefined, extra: {
56
- apply(): void;
57
- restore(): void;
58
- }): Promise<void>;
240
+ private appendEvent;
59
241
  /**
60
- * Closes this commit handle without closing sibling handles.
242
+ * Compares two stored Protobuf byte sequences.
243
+ *
244
+ * @param left First byte sequence.
245
+ * @param right Second byte sequence.
246
+ * @returns Whether every byte matches.
61
247
  */
62
- close(): void;
248
+ private sameBytes;
63
249
  /**
64
- * Opens only record families used by one commit.
250
+ * Validates current identity and duplicate delivery IDs before writes.
65
251
  *
66
252
  * @typeParam I Entity identifier type.
67
253
  * @typeParam S Entity state type.
68
- * @param input Supplies configured histories and delivery Events.
69
- * @returns Live affected record families and their layouts.
254
+ * @param input Supplies the captured mutation.
70
255
  */
71
- private live;
256
+ private validateRows;
72
257
  /**
73
- * Captures affected rows and creates isolated adapters for preparation.
258
+ * Rejects disabled history families.
74
259
  *
75
260
  * @typeParam I Entity identifier type.
76
261
  * @typeParam S Entity state type.
77
- * @param input Supplies the proposed record changes.
78
- * @param backend Supplies the live current-record map.
79
- * @returns The prepared affected-record workspace.
262
+ * @param input Supplies the proposed histories.
263
+ */
264
+ private requireEnabledHistories;
265
+ /**
266
+ * Checks the tenant and source captured by this handle.
267
+ *
268
+ * @typeParam I Entity identifier type.
269
+ * @typeParam S Entity state type.
270
+ * @param input Supplies the requested scope.
271
+ */
272
+ private requireCompatible;
273
+ /**
274
+ * Rejects commits after this handle closes.
80
275
  */
81
- private stage;
276
+ private requireOpen;
82
277
  }
83
278
  export {};
84
279
  //# sourceMappingURL=in-memory-entity-commit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-entity-commit.d.ts","sourceRoot":"","sources":["../../src/memory/in-memory-entity-commit.ts"],"names":[],"mappings":"AAcA,OAAO,EAAS,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAOz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