@spine-event-engine/storage-datastore 2.0.0-snapshot.24 → 2.0.0-snapshot.26

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 (47) hide show
  1. package/README.md +22 -21
  2. package/REFERENCE.md +55 -50
  3. package/dist/datastore/agent-history.d.ts +36 -6
  4. package/dist/datastore/agent-history.d.ts.map +1 -1
  5. package/dist/datastore/agent-history.js +92 -6
  6. package/dist/datastore/agent-history.js.map +1 -1
  7. package/dist/datastore/column-mapping.d.ts.map +1 -1
  8. package/dist/datastore/column-mapping.js +6 -3
  9. package/dist/datastore/column-mapping.js.map +1 -1
  10. package/dist/datastore/entity-history.d.ts +197 -3
  11. package/dist/datastore/entity-history.d.ts.map +1 -1
  12. package/dist/datastore/entity-history.js +514 -33
  13. package/dist/datastore/entity-history.js.map +1 -1
  14. package/dist/datastore/id-column.d.ts +7 -0
  15. package/dist/datastore/id-column.d.ts.map +1 -1
  16. package/dist/datastore/id-column.js +27 -3
  17. package/dist/datastore/id-column.js.map +1 -1
  18. package/dist/datastore/record-kind.d.ts +8 -0
  19. package/dist/datastore/record-kind.d.ts.map +1 -0
  20. package/dist/datastore/record-kind.js +26 -0
  21. package/dist/datastore/record-kind.js.map +1 -0
  22. package/dist/datastore/record-storage.d.ts +11 -10
  23. package/dist/datastore/record-storage.d.ts.map +1 -1
  24. package/dist/datastore/record-storage.js +28 -28
  25. package/dist/datastore/record-storage.js.map +1 -1
  26. package/dist/datastore/storage-factory.d.ts +246 -40
  27. package/dist/datastore/storage-factory.d.ts.map +1 -1
  28. package/dist/datastore/storage-factory.js +672 -110
  29. package/dist/datastore/storage-factory.js.map +1 -1
  30. package/dist/datastore/tenant-catalog.d.ts +12 -25
  31. package/dist/datastore/tenant-catalog.d.ts.map +1 -1
  32. package/dist/datastore/tenant-catalog.js +43 -121
  33. package/dist/datastore/tenant-catalog.js.map +1 -1
  34. package/dist/datastore/transaction-rows.d.ts +30 -0
  35. package/dist/datastore/transaction-rows.d.ts.map +1 -0
  36. package/dist/datastore/transaction-rows.js +43 -0
  37. package/dist/datastore/transaction-rows.js.map +1 -0
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/index.yaml +0 -9
  43. package/package.json +5 -6
  44. package/dist/datastore/agent-execution.d.ts +0 -337
  45. package/dist/datastore/agent-execution.d.ts.map +0 -1
  46. package/dist/datastore/agent-execution.js +0 -789
  47. package/dist/datastore/agent-execution.js.map +0 -1
@@ -1,8 +1,10 @@
1
1
  import { type Message } from "@bufbuild/protobuf";
2
+ import { type ModelPreference } from "@spine-event-engine/proto/agent";
3
+ import { type AgentCommitInput } from "@spine-event-engine/storage/provider";
2
4
  import { type EntityCommitInput, type EntityCommitStorage, type EntityEventHistoryPort, type EntityRecordStorage, type EntityStateHistoryPort, type EntityStorageInput } from "@spine-event-engine/storage/provider";
3
5
  import { RecordSpec, type RecordStorage } from "@spine-event-engine/storage";
4
6
  /**
5
- * Opens one generated record family with its resolved Datastore layout.
7
+ * Acquires one generated record family with its resolved Datastore layout.
6
8
  *
7
9
  * @typeParam I Record identifier type.
8
10
  * @typeParam R Stored Protobuf message type.
@@ -56,13 +58,15 @@ export declare class DatastoreEntityCommitStorage implements EntityCommitStorage
56
58
  #private;
57
59
  private readonly input;
58
60
  private readonly openRecords;
61
+ private readonly onClose;
59
62
  /**
60
63
  * Creates commit storage for one Entity persistence contract.
61
64
  *
62
65
  * @param input Defines the Entity source and tenant boundary.
63
66
  * @param openRecords Opens each generated record family.
67
+ * @param onClose Releases factory tracking after terminal cleanup.
64
68
  */
65
- constructor(input: EntityStorageInput<unknown, Message>, openRecords: OpenEntityRecords);
69
+ constructor(input: EntityStorageInput<unknown, Message>, openRecords: OpenEntityRecords, onClose?: () => void);
66
70
  /**
67
71
  * Writes histories and delivery Events before the current Entity record.
68
72
  *
@@ -75,6 +79,167 @@ export declare class DatastoreEntityCommitStorage implements EntityCommitStorage
75
79
  * @returns Completion after every requested record write.
76
80
  */
77
81
  commit<I, S extends Message>(input: EntityCommitInput<I, S>): Promise<void>;
82
+ /**
83
+ * Registers a commit before invoking provider construction callbacks.
84
+ *
85
+ * @param action The admitted provider operation.
86
+ * @returns The admitted provider operation completion.
87
+ * @typeParam T Result type of the admitted provider operation.
88
+ */
89
+ private track;
90
+ /**
91
+ * Reads a detached current preference image from native storage.
92
+ * @param entityId Typed Agent identifier.
93
+ * @returns Complete selections or absent record.
94
+ */
95
+ readAgentPreferences(entityId: unknown): Promise<readonly ModelPreference[] | undefined>;
96
+ /**
97
+ * Commits Agent state, final audit, and preferences in one native transaction.
98
+ * @param input Captured live Agent transition.
99
+ * @returns Completion after a conditional group commits.
100
+ * @typeParam I Typed Agent identifier.
101
+ * @typeParam S Generated Agent state.
102
+ */
103
+ commitAgent<I, S extends Message>(input: AgentCommitInput<I, S>): Promise<void>;
104
+ /**
105
+ * Acquires every missing native family before publishing retained references.
106
+ * @param mutation Optional Entity mutation requiring history families.
107
+ * @returns Native handles for one Agent commit.
108
+ */
109
+ private agentRows;
110
+ /**
111
+ * Acquires only missing native Agent families without publishing partial acquisition.
112
+ * @param mutation Optional Entity mutation.
113
+ * @param acquired Collects newly opened handles for rollback.
114
+ * @returns Complete native family group.
115
+ */
116
+ private acquireAgentRows;
117
+ /**
118
+ * Acquires mutation families needed by the admitted Agent turn.
119
+ * @param mutation Optional changed Entity mutation.
120
+ * @param acquired Newly opened handles retained for rollback.
121
+ * @returns Optional mutation families.
122
+ */
123
+ private agentMutationRows;
124
+ /**
125
+ * Acquires one native record family and records its rollback obligation.
126
+ * @param spec Declarative record layout.
127
+ * @param group Optional physical family.
128
+ * @param acquired Newly opened handles.
129
+ * @returns Native record family.
130
+ * @typeParam Id Typed record identifier.
131
+ * @typeParam R Generated record.
132
+ */
133
+ private openAgentRecord;
134
+ /**
135
+ * Stores the complete acquired Agent group after every family succeeds.
136
+ * @param rows Complete native family group.
137
+ */
138
+ private retainAgentRows;
139
+ /**
140
+ * Checks the built-in native transaction capability.
141
+ * @param port Selected record family.
142
+ * @returns Native record family.
143
+ * @typeParam Id Typed record identifier.
144
+ * @typeParam R Generated record.
145
+ */
146
+ private native;
147
+ /**
148
+ * Validates the Entity scope and exactly one next Version before I/O.
149
+ * @param id Captured Agent ID.
150
+ * @param version Initial Entity Version.
151
+ * @param mutation Optional prepared Entity mutation.
152
+ * @typeParam I Typed Entity identifier.
153
+ * @typeParam S Generated Entity state.
154
+ */
155
+ private validateAgent;
156
+ /**
157
+ * Executes a captured Agent transition in one native transaction.
158
+ * @param rows Retained native families.
159
+ * @param id Captured Agent ID.
160
+ * @param version Initial Entity version.
161
+ * @param expected Initial preference image.
162
+ * @param next Complete replacement preferences.
163
+ * @param mutation Optional Entity mutation.
164
+ * @param history Final audit entries.
165
+ * @typeParam I Typed Entity identifier.
166
+ * @typeParam S Generated Entity state.
167
+ * @returns Completion after the native transaction settles.
168
+ */
169
+ private agentTransaction;
170
+ /**
171
+ * Checks both current images and stages the complete final group.
172
+ * @param tx Native transaction.
173
+ * @param staged Rows saved only after all checks pass.
174
+ * @param rows Retained native families.
175
+ * @param id Captured Agent identifier.
176
+ * @param version Initial Entity Version.
177
+ * @param expected Initial preference image.
178
+ * @param next Replacement preference record.
179
+ * @param mutation Optional Entity mutation.
180
+ * @param history Final audit entries.
181
+ * @typeParam I Typed Entity identifier.
182
+ * @typeParam S Generated Entity state.
183
+ * @returns Completion after all conditional rows are staged.
184
+ */
185
+ private agentLocked;
186
+ /**
187
+ * Records final Agent audit rows in the admitted native transaction.
188
+ * @param history Final Agent audit entries.
189
+ * @param id Captured typed Agent identifier.
190
+ * @param staged Rows staged for atomic commit.
191
+ * @param storage Retained provider record family.
192
+ * @param tx Active native transaction.
193
+ * @returns Completion after final audit rows are staged.
194
+ */
195
+ private appendAgentAudit;
196
+ /**
197
+ * Reads a native row within the Agent transaction.
198
+ * @param tx Active native transaction.
199
+ * @param storage Retained record family.
200
+ * @param id Typed record identifier.
201
+ * @returns Decoded row or absence.
202
+ * @typeParam Id Typed record identifier.
203
+ * @typeParam R Generated record.
204
+ */
205
+ private agentRead;
206
+ /**
207
+ * Checks one immutable final record before staging it.
208
+ * @param tx Active native transaction.
209
+ * @param staged Collected native rows.
210
+ * @param storage Retained record family.
211
+ * @param record Proposed immutable record.
212
+ * @typeParam Id Typed record identifier.
213
+ * @typeParam R Generated record.
214
+ * @returns Completion after the immutable row is checked and staged.
215
+ */
216
+ private agentImmutable;
217
+ /**
218
+ * Checks an enabled native history family.
219
+ * @param storage Optional native family.
220
+ * @returns Enabled native record family.
221
+ * @typeParam Id Typed record ID.
222
+ * @typeParam R Generated record.
223
+ */
224
+ private requiredNative;
225
+ /**
226
+ * Persists an admitted captured mutation and one safe retry.
227
+ *
228
+ * @param prepared The immutable prepared mutation.
229
+ * @returns Completion after the captured mutation is persisted.
230
+ * @typeParam I Entity identifier or record type.
231
+ * @typeParam S Generated Entity state message type.
232
+ */
233
+ private persist;
234
+ /**
235
+ * Acquires only missing requested families and rolls back a failed group.
236
+ *
237
+ * @param input The captured Entity persistence input.
238
+ * @returns The retained records required by this commit.
239
+ * @typeParam I Entity identifier or record type.
240
+ * @typeParam S Generated Entity state message type.
241
+ */
242
+ private openCommit;
78
243
  /**
79
244
  * Writes independent record families in Entity commit order.
80
245
  *
@@ -97,8 +262,37 @@ export declare class DatastoreEntityCommitStorage implements EntityCommitStorage
97
262
  private retryable;
98
263
  /**
99
264
  * Closes this commit storage to further commits.
265
+ *
266
+ * @returns Completion after admitted work and record cleanup settle.
100
267
  */
101
- close(): void;
268
+ close(): Promise<void>;
269
+ /**
270
+ * Closes only when no commit remains admitted.
271
+ */
272
+ closeIdle(): void;
273
+ /**
274
+ * Rejects synchronous disposal while asynchronous work remains admitted.
275
+ */
276
+ assertIdle(): void;
277
+ /**
278
+ * Waits for every admitted commit before completing close.
279
+ *
280
+ * @returns Completion after admitted work and cleanup settle.
281
+ */
282
+ private drain;
283
+ /**
284
+ * Closes every retained record once after admitted work settles.
285
+ *
286
+ * @returns A cleanup failure, if any.
287
+ */
288
+ private closeRetained;
289
+ /**
290
+ * Closes every newly acquired handle and collects cleanup failures.
291
+ *
292
+ * @param ports The acquired record handles.
293
+ * @returns Cleanup failures from acquired handles.
294
+ */
295
+ private closeGroup;
102
296
  /**
103
297
  * Validates the Entity, tenant, history, and Event boundaries of a commit.
104
298
  *
@@ -1 +1 @@
1
- {"version":3,"file":"entity-history.d.ts","sourceRoot":"","sources":["../../src/datastore/entity-history.ts"],"names":[],"mappings":"AAcA,OAAO,EAA+B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQ/E,OAAO,EAML,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACxB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAK7E;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EACnD,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,KAAK,CAAC,EAAE,OAAO,6BAA6B,EAAE,YAAY,KACvD,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEzB;;;;;GAKG;AACH,qBAAa,sBAAsB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO;;IAGtD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAEzC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAE3C;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,CA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