@spine-event-engine/storage 2.0.0-snapshot.2
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.
- package/LICENSE +201 -0
- package/README.md +160 -0
- package/REFERENCE.md +120 -0
- package/dist/entity/entity-history-record-spec.d.ts +26 -0
- package/dist/entity/entity-history-record-spec.d.ts.map +1 -0
- package/dist/entity/entity-history-record-spec.js +77 -0
- package/dist/entity/entity-history-record-spec.js.map +1 -0
- package/dist/entity/entity-history-storage.d.ts +111 -0
- package/dist/entity/entity-history-storage.d.ts.map +1 -0
- package/dist/entity/entity-history-storage.js +40 -0
- package/dist/entity/entity-history-storage.js.map +1 -0
- package/dist/entity/entity-record.d.ts +31 -0
- package/dist/entity/entity-record.d.ts.map +1 -0
- package/dist/entity/entity-record.js +15 -0
- package/dist/entity/entity-record.js.map +1 -0
- package/dist/entity/history-conformance.d.ts +55 -0
- package/dist/entity/history-conformance.d.ts.map +1 -0
- package/dist/entity/history-conformance.js +165 -0
- package/dist/entity/history-conformance.js.map +1 -0
- package/dist/event/event-store.d.ts +141 -0
- package/dist/event/event-store.d.ts.map +1 -0
- package/dist/event/event-store.js +407 -0
- package/dist/event/event-store.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/delivery-cleanup.d.ts +99 -0
- package/dist/internal/delivery-cleanup.d.ts.map +1 -0
- package/dist/internal/delivery-cleanup.js +38 -0
- package/dist/internal/delivery-cleanup.js.map +1 -0
- package/dist/internal/entity-commit.d.ts +108 -0
- package/dist/internal/entity-commit.d.ts.map +1 -0
- package/dist/internal/entity-commit.js +32 -0
- package/dist/internal/entity-commit.js.map +1 -0
- package/dist/internal/entity-history.d.ts +12 -0
- package/dist/internal/entity-history.d.ts.map +1 -0
- package/dist/internal/entity-history.js +17 -0
- package/dist/internal/entity-history.js.map +1 -0
- package/dist/internal/event-store.d.ts +8 -0
- package/dist/internal/event-store.d.ts.map +1 -0
- package/dist/internal/event-store.js +21 -0
- package/dist/internal/event-store.js.map +1 -0
- package/dist/internal/query-values.d.ts +5 -0
- package/dist/internal/query-values.d.ts.map +1 -0
- package/dist/internal/query-values.js +18 -0
- package/dist/internal/query-values.js.map +1 -0
- package/dist/internal/tenancy.d.ts +89 -0
- package/dist/internal/tenancy.d.ts.map +1 -0
- package/dist/internal/tenancy.js +97 -0
- package/dist/internal/tenancy.js.map +1 -0
- package/dist/memory/canonical-utf8.d.ts +21 -0
- package/dist/memory/canonical-utf8.d.ts.map +1 -0
- package/dist/memory/canonical-utf8.js +65 -0
- package/dist/memory/canonical-utf8.js.map +1 -0
- package/dist/memory/in-memory-entity-commit.d.ts +35 -0
- package/dist/memory/in-memory-entity-commit.d.ts.map +1 -0
- package/dist/memory/in-memory-entity-commit.js +183 -0
- package/dist/memory/in-memory-entity-commit.js.map +1 -0
- package/dist/memory/in-memory-entity-history.d.ts +379 -0
- package/dist/memory/in-memory-entity-history.d.ts.map +1 -0
- package/dist/memory/in-memory-entity-history.js +756 -0
- package/dist/memory/in-memory-entity-history.js.map +1 -0
- package/dist/memory/in-memory-record-storage.d.ts +78 -0
- package/dist/memory/in-memory-record-storage.d.ts.map +1 -0
- package/dist/memory/in-memory-record-storage.js +127 -0
- package/dist/memory/in-memory-record-storage.js.map +1 -0
- package/dist/memory/in-memory-storage-backend.d.ts +38 -0
- package/dist/memory/in-memory-storage-backend.d.ts.map +1 -0
- package/dist/memory/in-memory-storage-backend.js +108 -0
- package/dist/memory/in-memory-storage-backend.js.map +1 -0
- package/dist/memory/in-memory-storage-factory.d.ts +58 -0
- package/dist/memory/in-memory-storage-factory.d.ts.map +1 -0
- package/dist/memory/in-memory-storage-factory.js +148 -0
- package/dist/memory/in-memory-storage-factory.js.map +1 -0
- package/dist/memory/memory-delivery-cleanup.d.ts +32 -0
- package/dist/memory/memory-delivery-cleanup.d.ts.map +1 -0
- package/dist/memory/memory-delivery-cleanup.js +61 -0
- package/dist/memory/memory-delivery-cleanup.js.map +1 -0
- package/dist/memory/tenant-records.d.ts +66 -0
- package/dist/memory/tenant-records.d.ts.map +1 -0
- package/dist/memory/tenant-records.js +573 -0
- package/dist/memory/tenant-records.js.map +1 -0
- package/dist/query/query-execution.d.ts +50 -0
- package/dist/query/query-execution.d.ts.map +1 -0
- package/dist/query/query-execution.js +222 -0
- package/dist/query/query-execution.js.map +1 -0
- package/dist/query/query-policy.d.ts +115 -0
- package/dist/query/query-policy.d.ts.map +1 -0
- package/dist/query/query-policy.js +294 -0
- package/dist/query/query-policy.js.map +1 -0
- package/dist/record/column-mapping.d.ts +41 -0
- package/dist/record/column-mapping.d.ts.map +1 -0
- package/dist/record/column-mapping.js +36 -0
- package/dist/record/column-mapping.js.map +1 -0
- package/dist/record/column-type.d.ts +75 -0
- package/dist/record/column-type.d.ts.map +1 -0
- package/dist/record/column-type.js +69 -0
- package/dist/record/column-type.js.map +1 -0
- package/dist/record/record-column.d.ts +23 -0
- package/dist/record/record-column.d.ts.map +1 -0
- package/dist/record/record-column.js +41 -0
- package/dist/record/record-column.js.map +1 -0
- package/dist/record/record-mask.d.ts +11 -0
- package/dist/record/record-mask.d.ts.map +1 -0
- package/dist/record/record-mask.js +82 -0
- package/dist/record/record-mask.js.map +1 -0
- package/dist/record/record-query.d.ts +102 -0
- package/dist/record/record-query.d.ts.map +1 -0
- package/dist/record/record-query.js +44 -0
- package/dist/record/record-query.js.map +1 -0
- package/dist/record/record-spec.d.ts +101 -0
- package/dist/record/record-spec.d.ts.map +1 -0
- package/dist/record/record-spec.js +159 -0
- package/dist/record/record-spec.js.map +1 -0
- package/dist/record/record-storage.d.ts +202 -0
- package/dist/record/record-storage.d.ts.map +1 -0
- package/dist/record/record-storage.js +234 -0
- package/dist/record/record-storage.js.map +1 -0
- package/dist/record/storage-group.d.ts +17 -0
- package/dist/record/storage-group.d.ts.map +1 -0
- package/dist/record/storage-group.js +37 -0
- package/dist/record/storage-group.js.map +1 -0
- package/dist/storage/storage-factory.d.ts +44 -0
- package/dist/storage/storage-factory.d.ts.map +1 -0
- package/dist/storage/storage-factory.js +54 -0
- package/dist/storage/storage-factory.js.map +1 -0
- package/dist/storage/storage.d.ts +62 -0
- package/dist/storage/storage.d.ts.map +1 -0
- package/dist/storage/storage.js +15 -0
- package/dist/storage/storage.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,407 @@
|
|
|
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
|
+
import { clone, create, ScalarType } from "@bufbuild/protobuf";
|
|
15
|
+
import { TimestampSchema } from "@bufbuild/protobuf/wkt";
|
|
16
|
+
import { EventIdSchema, EventSchema, TenantIdSchema } from "@spine-event-engine/proto";
|
|
17
|
+
import { RecordColumn } from "../record/record-column.js";
|
|
18
|
+
import { ColumnTypes } from "../record/column-type.js";
|
|
19
|
+
import { RecordSpec } from "../record/record-spec.js";
|
|
20
|
+
import { TenantBoundary } from "../internal/tenancy.js";
|
|
21
|
+
/**
|
|
22
|
+
* Framework event store backed by record storage.
|
|
23
|
+
*
|
|
24
|
+
* Snapshots input events before queued work, rejects missing, blank, and
|
|
25
|
+
* duplicate IDs in one batch, and rejects IDs already stored for the same
|
|
26
|
+
* captured storage context.
|
|
27
|
+
*/
|
|
28
|
+
export class EventStore {
|
|
29
|
+
#context;
|
|
30
|
+
#factory;
|
|
31
|
+
#open = true;
|
|
32
|
+
/**
|
|
33
|
+
* Creates an event store for one storage context.
|
|
34
|
+
*
|
|
35
|
+
* @param context Specifies the storage context.
|
|
36
|
+
* @param factory Creates the backing record storage.
|
|
37
|
+
*/
|
|
38
|
+
constructor(context, factory) {
|
|
39
|
+
this.#context = EventContexts.base(context);
|
|
40
|
+
this.#factory = factory;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns whether this Event Store still accepts operations.
|
|
44
|
+
*
|
|
45
|
+
* @returns Returns true until this Event Store is closed.
|
|
46
|
+
*/
|
|
47
|
+
isOpen() {
|
|
48
|
+
return this.#open;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Closes this Event Store. Operation-selected storage handles close after use.
|
|
52
|
+
*/
|
|
53
|
+
close() {
|
|
54
|
+
this.#open = false;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validates that one generated Spine event can be appended without storing it.
|
|
58
|
+
*
|
|
59
|
+
* @param event Supplies the event to validate.
|
|
60
|
+
* @returns Completes when the event is accepted.
|
|
61
|
+
*/
|
|
62
|
+
async accept(event) {
|
|
63
|
+
const record = clone(EventSchema, event);
|
|
64
|
+
const context = EventContexts.snapshotForEvent(this.#context, record);
|
|
65
|
+
await this.checkUnique([EventIds.require(record)], context);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Accepts one event, runs caller acceptance, and appends using one captured
|
|
69
|
+
* storage context.
|
|
70
|
+
*
|
|
71
|
+
* @param event Supplies the event to accept.
|
|
72
|
+
* @param onAccepted Runs after uniqueness validation and before append.
|
|
73
|
+
* @returns Resolves to the appended event snapshot.
|
|
74
|
+
*/
|
|
75
|
+
async acceptThenAppend(event, onAccepted) {
|
|
76
|
+
const record = clone(EventSchema, event);
|
|
77
|
+
const context = EventContexts.snapshotForEvent(this.#context, record);
|
|
78
|
+
await this.checkUnique([EventIds.require(record)], context);
|
|
79
|
+
await onAccepted(clone(EventSchema, record));
|
|
80
|
+
await this.appendUnique([record], context);
|
|
81
|
+
return clone(EventSchema, record);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Writes one generated Spine event, rejecting missing, blank, or duplicate IDs.
|
|
85
|
+
*
|
|
86
|
+
* @param event Supplies the event to append.
|
|
87
|
+
* @returns Completes when the event is appended.
|
|
88
|
+
*/
|
|
89
|
+
async append(event) {
|
|
90
|
+
const record = clone(EventSchema, event);
|
|
91
|
+
await this.appendUnique([record], EventContexts.snapshotForEvent(this.#context, record));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Writes generated Spine events in order, rejecting missing, blank, or duplicate IDs.
|
|
95
|
+
*
|
|
96
|
+
* @param events Supplies the events to append.
|
|
97
|
+
* @returns Completes when the events are appended.
|
|
98
|
+
*/
|
|
99
|
+
async appendAll(events) {
|
|
100
|
+
const records = [...events].map((event) => clone(EventSchema, event));
|
|
101
|
+
if (records.length > 0) {
|
|
102
|
+
await this.appendUnique(records, EventContexts.batch(this.#context, records));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Writes generated Spine events and returns a one-shot rollback token.
|
|
107
|
+
*
|
|
108
|
+
* @param events Supplies the events to append.
|
|
109
|
+
* @returns Resolves to the rollback token for this append.
|
|
110
|
+
*/
|
|
111
|
+
async appendAllWithRollback(events) {
|
|
112
|
+
const records = [...events].map((event) => clone(EventSchema, event));
|
|
113
|
+
const ids = records.map((record) => EventIds.require(record));
|
|
114
|
+
const context = records.length === 0 ? undefined : EventContexts.batch(this.#context, records);
|
|
115
|
+
if (context !== undefined) {
|
|
116
|
+
await this.appendUnique(records, context);
|
|
117
|
+
}
|
|
118
|
+
let used = false;
|
|
119
|
+
return Object.freeze({
|
|
120
|
+
rollback: async () => {
|
|
121
|
+
if (used) {
|
|
122
|
+
throw new Error("Event rollback token has already been used.");
|
|
123
|
+
}
|
|
124
|
+
used = true;
|
|
125
|
+
if (context !== undefined)
|
|
126
|
+
await this.deleteIds(ids, context);
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Reads persisted events through the underlying record-storage query seam.
|
|
132
|
+
*
|
|
133
|
+
* @param query Specifies the record query.
|
|
134
|
+
* @returns Resolves to matching events.
|
|
135
|
+
*/
|
|
136
|
+
async read(query = {}) {
|
|
137
|
+
this.requireOpen();
|
|
138
|
+
const storage = this.#factory.createRecordStorage(EventContexts.snapshot(this.#context), eventStoreRecordSpec);
|
|
139
|
+
try {
|
|
140
|
+
return await storage.query(query);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
storage.close();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async appendUnique(records, context) {
|
|
147
|
+
this.requireOpen();
|
|
148
|
+
const ids = records.map((record) => EventIds.require(record));
|
|
149
|
+
EventIds.rejectDuplicates(ids);
|
|
150
|
+
await eventStoreAccess.withLock(this.#factory, context, async () => {
|
|
151
|
+
const storage = this.#factory.createRecordStorage(context, eventStoreRecordSpec);
|
|
152
|
+
try {
|
|
153
|
+
await EventIds.insertUnique(storage, records);
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
storage.close();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async deleteIds(ids, context) {
|
|
161
|
+
this.requireOpen();
|
|
162
|
+
await eventStoreAccess.withLock(this.#factory, context, async () => {
|
|
163
|
+
const storage = this.#factory.createRecordStorage(context, eventStoreRecordSpec);
|
|
164
|
+
try {
|
|
165
|
+
for (const id of ids) {
|
|
166
|
+
await storage.delete(id);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
storage.close();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
async checkUnique(ids, context) {
|
|
175
|
+
this.requireOpen();
|
|
176
|
+
EventIds.rejectDuplicates(ids);
|
|
177
|
+
await eventStoreAccess.withLock(this.#factory, context, async () => {
|
|
178
|
+
const storage = this.#factory.createRecordStorage(context, eventStoreRecordSpec);
|
|
179
|
+
try {
|
|
180
|
+
await EventIds.rejectStored(storage, ids);
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
storage.close();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
requireOpen() {
|
|
188
|
+
if (!this.#open)
|
|
189
|
+
throw new Error("EventStore is closed.");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const EventStoreLocks = Object.freeze({
|
|
193
|
+
queues: new WeakMap(),
|
|
194
|
+
async withLock(factory, context, work) {
|
|
195
|
+
const queues = this.queueMap(factory);
|
|
196
|
+
const key = EventContexts.key(context);
|
|
197
|
+
const previous = queues.get(key) ?? Promise.resolve();
|
|
198
|
+
const next = previous.then(work, work);
|
|
199
|
+
const stored = next.then(() => undefined, () => undefined);
|
|
200
|
+
queues.set(key, stored);
|
|
201
|
+
try {
|
|
202
|
+
return await next;
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
if (queues.get(key) === stored) {
|
|
206
|
+
queues.delete(key);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
queueMap(factory) {
|
|
211
|
+
let queues = this.queues.get(factory);
|
|
212
|
+
if (queues === undefined) {
|
|
213
|
+
queues = new Map();
|
|
214
|
+
this.queues.set(factory, queues);
|
|
215
|
+
}
|
|
216
|
+
return queues;
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* Provider-only coordination access for the Event Store context lock.
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
223
|
+
export const eventStoreAccess = Object.freeze({
|
|
224
|
+
// prettier-ignore
|
|
225
|
+
/**
|
|
226
|
+
* Runs work under the same factory/context lock used by direct Event Store appends.
|
|
227
|
+
*
|
|
228
|
+
* @param factory The factory that owns the Event Store records.
|
|
229
|
+
* @param context The Event Store context to serialize.
|
|
230
|
+
* @param work The operation to run while holding the lock.
|
|
231
|
+
* @returns The operation result.
|
|
232
|
+
*/
|
|
233
|
+
withLock(factory, context, work) {
|
|
234
|
+
return EventStoreLocks.withLock(factory, context, work);
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
/**
|
|
238
|
+
* Validates event IDs before record-store operations.
|
|
239
|
+
*/
|
|
240
|
+
const EventIds = {
|
|
241
|
+
// prettier-ignore
|
|
242
|
+
/**
|
|
243
|
+
* Requires an event to have a non-blank ID.
|
|
244
|
+
*/
|
|
245
|
+
require(event) {
|
|
246
|
+
if (event.id === undefined)
|
|
247
|
+
throw new Error("EventStore requires event.id.");
|
|
248
|
+
if (event.id.value.trim().length === 0) {
|
|
249
|
+
throw new Error("EventStore requires a non-empty event.id.value.");
|
|
250
|
+
}
|
|
251
|
+
return event.id;
|
|
252
|
+
},
|
|
253
|
+
/**
|
|
254
|
+
* Rejects IDs that already exist in storage.
|
|
255
|
+
*/
|
|
256
|
+
async rejectStored(storage, ids) {
|
|
257
|
+
if ((await storage.index({ ids })).length > 0) {
|
|
258
|
+
throw new Error("EventStore requires unique event IDs.");
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
/**
|
|
262
|
+
* Atomically inserts each event ID and rolls back this batch on collision.
|
|
263
|
+
*/
|
|
264
|
+
async insertUnique(storage, records) {
|
|
265
|
+
if (!storage.atomicCompareAndSet) {
|
|
266
|
+
throw new Error("EventStore requires atomic record compare-and-set.");
|
|
267
|
+
}
|
|
268
|
+
const inserted = [];
|
|
269
|
+
try {
|
|
270
|
+
for (const record of records) {
|
|
271
|
+
const id = EventIds.require(record);
|
|
272
|
+
if (!(await storage.compareAndSet(id, undefined, record))) {
|
|
273
|
+
throw new Error("EventStore requires unique event IDs.");
|
|
274
|
+
}
|
|
275
|
+
inserted.push({ id, record });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
const failures = [];
|
|
280
|
+
for (const { id, record } of inserted.reverse()) {
|
|
281
|
+
try {
|
|
282
|
+
if (!(await storage.compareAndSet(id, record, undefined))) {
|
|
283
|
+
failures.push(new Error("EventStore append rollback lost its stored event."));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (rollbackError) {
|
|
287
|
+
failures.push(rollbackError);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (failures.length > 0) {
|
|
291
|
+
throw new AggregateError([error, ...failures], "EventStore append rollback failed.");
|
|
292
|
+
}
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
/**
|
|
297
|
+
* Rejects repeated IDs within one append operation.
|
|
298
|
+
*/
|
|
299
|
+
rejectDuplicates(ids) {
|
|
300
|
+
const seen = new Set();
|
|
301
|
+
for (const id of ids) {
|
|
302
|
+
if (seen.has(id.value))
|
|
303
|
+
throw new Error("EventStore requires unique event IDs.");
|
|
304
|
+
seen.add(id.value);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Captures tenant-aware event-store contexts and their lock keys.
|
|
310
|
+
*/
|
|
311
|
+
const EventContexts = {
|
|
312
|
+
// prettier-ignore
|
|
313
|
+
/**
|
|
314
|
+
* Captures one storage context.
|
|
315
|
+
*/
|
|
316
|
+
base(context) {
|
|
317
|
+
return context.multitenant
|
|
318
|
+
? Object.freeze({
|
|
319
|
+
name: context.name,
|
|
320
|
+
multitenant: true,
|
|
321
|
+
...(context.tenantId === undefined
|
|
322
|
+
? {}
|
|
323
|
+
: { tenantId: clone(TenantIdSchema, context.tenantId) }),
|
|
324
|
+
})
|
|
325
|
+
: Object.freeze({ name: context.name, multitenant: false });
|
|
326
|
+
},
|
|
327
|
+
snapshot(context) {
|
|
328
|
+
if (!context.multitenant)
|
|
329
|
+
return Object.freeze({ name: context.name, multitenant: false });
|
|
330
|
+
if (context.tenantId === undefined)
|
|
331
|
+
throw new Error("Multitenant EventStore reads require a complete tenant ID.");
|
|
332
|
+
const boundary = TenantBoundary.from(context.tenantId);
|
|
333
|
+
const tenantId = boundary.tenantId;
|
|
334
|
+
return Object.freeze({
|
|
335
|
+
name: context.name,
|
|
336
|
+
multitenant: true,
|
|
337
|
+
tenantId,
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
/**
|
|
341
|
+
* Captures one context using an event envelope tenant when present.
|
|
342
|
+
*/
|
|
343
|
+
snapshotForEvent(context, event) {
|
|
344
|
+
if (!context.multitenant)
|
|
345
|
+
return EventContexts.snapshot(context);
|
|
346
|
+
const tenantId = EventContexts.readEventTenant(event) ?? context.tenantId;
|
|
347
|
+
if (tenantId === undefined)
|
|
348
|
+
throw new Error("Multitenant EventStore append requires an event tenant ID.");
|
|
349
|
+
return EventContexts.snapshot({
|
|
350
|
+
name: context.name,
|
|
351
|
+
multitenant: true,
|
|
352
|
+
tenantId,
|
|
353
|
+
});
|
|
354
|
+
},
|
|
355
|
+
batch(context, events) {
|
|
356
|
+
const first = events[0];
|
|
357
|
+
if (first === undefined)
|
|
358
|
+
throw new Error("EventStore batch requires at least one event.");
|
|
359
|
+
const selected = EventContexts.snapshotForEvent(context, first);
|
|
360
|
+
const key = TenantBoundary.of(selected).key;
|
|
361
|
+
for (const event of events.slice(1)) {
|
|
362
|
+
if (TenantBoundary.of(EventContexts.snapshotForEvent(context, event)).key !== key)
|
|
363
|
+
throw new Error("One EventStore batch cannot contain events from different tenants.");
|
|
364
|
+
}
|
|
365
|
+
return selected;
|
|
366
|
+
},
|
|
367
|
+
/**
|
|
368
|
+
* Reads an explicit tenant from an event envelope.
|
|
369
|
+
*/
|
|
370
|
+
readEventTenant(event) {
|
|
371
|
+
switch (event.context?.origin.case) {
|
|
372
|
+
case "importContext":
|
|
373
|
+
return EventContexts.tenantValue(event.context.origin.value.tenantId);
|
|
374
|
+
case "pastMessage":
|
|
375
|
+
return EventContexts.tenantValue(event.context.origin.value.actorContext?.tenantId);
|
|
376
|
+
default:
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
/**
|
|
381
|
+
* Converts a typed tenant ID to its storage-scope value.
|
|
382
|
+
*/
|
|
383
|
+
tenantValue(tenantId) {
|
|
384
|
+
return tenantId === undefined ? undefined : clone(TenantIdSchema, tenantId);
|
|
385
|
+
},
|
|
386
|
+
/**
|
|
387
|
+
* Creates a deterministic key for a context-scoped append lock.
|
|
388
|
+
*/
|
|
389
|
+
key(context) {
|
|
390
|
+
return TenantBoundary.of(context).key;
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* Provides the canonical event-store record layout to provider-only internals.
|
|
395
|
+
*
|
|
396
|
+
* @internal
|
|
397
|
+
*/
|
|
398
|
+
export const eventStoreRecordSpec = new RecordSpec({
|
|
399
|
+
recordType: EventSchema,
|
|
400
|
+
idSchema: EventIdSchema,
|
|
401
|
+
extractId: (event) => EventIds.require(event),
|
|
402
|
+
columns: [
|
|
403
|
+
new RecordColumn("created", ColumnTypes.message(TimestampSchema), (event) => event.context?.timestamp ?? create(TimestampSchema)),
|
|
404
|
+
new RecordColumn("type", ColumnTypes.scalar(ScalarType.STRING), (event) => event.message?.typeUrl),
|
|
405
|
+
],
|
|
406
|
+
});
|
|
407
|
+
//# sourceMappingURL=event-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-store.js","sourceRoot":"","sources":["../../src/event/event-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAA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,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS,IAAI,MAAM,CAAC,eAAe,CAAC,CAC/D;QACD,IAAI,YAAY,CACd,MAAM,EACN,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EACrC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAClC;KACF;CACF,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { EventStore, type EventRollback, type EventStoreContext, type OnEventAccepted, } from "./event/event-store.js";
|
|
2
|
+
export type { EntityEventStorage, EntityStateHistoryStorage, } from "./entity/entity-history-storage.js";
|
|
3
|
+
export { InMemoryRecordStorage } from "./memory/in-memory-record-storage.js";
|
|
4
|
+
export { InMemoryStorageBackend } from "./memory/in-memory-storage-backend.js";
|
|
5
|
+
export { InMemoryStorageFactory } from "./memory/in-memory-storage-factory.js";
|
|
6
|
+
export { StorageQueryPolicy } from "./query/query-policy.js";
|
|
7
|
+
export { defaultQueryCandidateLimit, QueryCandidateLimitError, StorageQueryEvaluator, } from "./query/query-execution.js";
|
|
8
|
+
export type { NormalizedQueryEntry } from "./query/query-execution.js";
|
|
9
|
+
export type { NormalizedComparisonOperator, NormalizedQueryMask, NormalizedQueryOrder, NormalizedQueryPlan, NormalizedQueryPredicate, StorageQueryCapabilities, StorageQueryFeature, } from "./query/query-policy.js";
|
|
10
|
+
export { RecordColumn } from "./record/record-column.js";
|
|
11
|
+
export { ColumnTypes, type RecordColumnType } from "./record/column-type.js";
|
|
12
|
+
export { ColumnMappings, type ColumnMapping, type ColumnTypeMapping, } from "./record/column-mapping.js";
|
|
13
|
+
export { RecordMask } from "./record/record-mask.js";
|
|
14
|
+
export type { RecordContinuation, RecordContinuationValue, RecordFilter, RecordOrder, RecordReadOptions, } from "./record/record-query.js";
|
|
15
|
+
export { RecordQuery } from "./record/record-query.js";
|
|
16
|
+
export { RecordSpec, type RecordSpecOptions } from "./record/record-spec.js";
|
|
17
|
+
export { RecordStorage } from "./record/record-storage.js";
|
|
18
|
+
export { StorageGroup } from "./record/storage-group.js";
|
|
19
|
+
export type { RecordEntry } from "./record/record-storage.js";
|
|
20
|
+
export type { Storage, StorageContext, StorageMode } from "./storage/storage.js";
|
|
21
|
+
export { StorageFactory } from "./storage/storage-factory.js";
|
|
22
|
+
export { TenantBoundary, type TenantCatalog, type TenantCatalogProvider, } from "./internal/tenancy.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,UAAU,EACV,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,YAAY,EACV,4BAA4B,EAC5B,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EACL,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
export { EventStore, } from "./event/event-store.js";
|
|
15
|
+
export { InMemoryRecordStorage } from "./memory/in-memory-record-storage.js";
|
|
16
|
+
export { InMemoryStorageBackend } from "./memory/in-memory-storage-backend.js";
|
|
17
|
+
export { InMemoryStorageFactory } from "./memory/in-memory-storage-factory.js";
|
|
18
|
+
export { StorageQueryPolicy } from "./query/query-policy.js";
|
|
19
|
+
export { defaultQueryCandidateLimit, QueryCandidateLimitError, StorageQueryEvaluator, } from "./query/query-execution.js";
|
|
20
|
+
export { RecordColumn } from "./record/record-column.js";
|
|
21
|
+
export { ColumnTypes } from "./record/column-type.js";
|
|
22
|
+
export { ColumnMappings, } from "./record/column-mapping.js";
|
|
23
|
+
export { RecordMask } from "./record/record-mask.js";
|
|
24
|
+
export { RecordQuery } from "./record/record-query.js";
|
|
25
|
+
export { RecordSpec } from "./record/record-spec.js";
|
|
26
|
+
export { RecordStorage } from "./record/record-storage.js";
|
|
27
|
+
export { StorageGroup } from "./record/storage-group.js";
|
|
28
|
+
export { StorageFactory } from "./storage/storage-factory.js";
|
|
29
|
+
export { TenantBoundary, } from "./internal/tenancy.js";
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,UAAU,GAIX,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAWpC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAyB,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EACL,cAAc,GAGf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAQrD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAA0B,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACL,cAAc,GAGf,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Message } from "@bufbuild/protobuf";
|
|
2
|
+
import type { RecordSpec } from "../record/record-spec.js";
|
|
3
|
+
import type { StorageContext } from "../storage/storage.js";
|
|
4
|
+
import type { StorageFactory } from "../storage/storage-factory.js";
|
|
5
|
+
/**
|
|
6
|
+
* Describes cooperative operation state at a provider safe boundary.
|
|
7
|
+
*/
|
|
8
|
+
export interface CleanupOperation {
|
|
9
|
+
/**
|
|
10
|
+
* Indicates whether cancellation has been requested.
|
|
11
|
+
*/
|
|
12
|
+
readonly signal?: {
|
|
13
|
+
readonly aborted: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Carries the admitted non-negative timeout budget.
|
|
17
|
+
*/
|
|
18
|
+
readonly timeoutMs?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Determines whether the admission-relative deadline remains active.
|
|
21
|
+
*
|
|
22
|
+
* @returns Whether provider work remains within its admitted deadline.
|
|
23
|
+
*/
|
|
24
|
+
readonly isActive?: () => boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Determines whether a cleanup operation may proceed at a provider safe boundary.
|
|
28
|
+
*
|
|
29
|
+
* @param operation Supplies cooperative cancellation and deadline state.
|
|
30
|
+
* @returns Whether provider work may continue.
|
|
31
|
+
*/
|
|
32
|
+
export declare function cleanupOperationActive(operation: CleanupOperation | undefined): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Describes provider input for one fenced exact delivered-row removal.
|
|
35
|
+
*/
|
|
36
|
+
export interface DeliveryCleanupInput<InboxId, InboxRecord extends Message, SessionId, SessionRecord extends Message> {
|
|
37
|
+
/**
|
|
38
|
+
* Selects the tenant and storage group containing both records.
|
|
39
|
+
*/
|
|
40
|
+
readonly context: StorageContext;
|
|
41
|
+
/**
|
|
42
|
+
* Carries cooperative cancellation and an internal admission-relative activity predicate.
|
|
43
|
+
*/
|
|
44
|
+
readonly operation?: CleanupOperation;
|
|
45
|
+
/**
|
|
46
|
+
* Describes the exact delivered Inbox record expected for deletion.
|
|
47
|
+
*/
|
|
48
|
+
readonly inbox: {
|
|
49
|
+
readonly spec: RecordSpec<InboxId, InboxRecord>;
|
|
50
|
+
readonly id: InboxId;
|
|
51
|
+
readonly expected: InboxRecord;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Describes the current shard-session record that fences deletion.
|
|
55
|
+
*/
|
|
56
|
+
readonly session: {
|
|
57
|
+
readonly spec: RecordSpec<SessionId, SessionRecord>;
|
|
58
|
+
readonly id: SessionId;
|
|
59
|
+
readonly expected: SessionRecord;
|
|
60
|
+
readonly isCurrent: (record: SessionRecord) => boolean;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Defines a provider-owned handle for atomically deleting a fenced Inbox record.
|
|
65
|
+
*/
|
|
66
|
+
export interface DeliveryCleanupStorage {
|
|
67
|
+
/**
|
|
68
|
+
* Removes an exact Inbox record after validating the current session.
|
|
69
|
+
*
|
|
70
|
+
* @param input Describes the records and ownership predicate for deletion.
|
|
71
|
+
* @returns Whether the provider deleted the exact Inbox record.
|
|
72
|
+
*/
|
|
73
|
+
remove<InboxId, InboxRecord extends Message, SessionId, SessionRecord extends Message>(input: DeliveryCleanupInput<InboxId, InboxRecord, SessionId, SessionRecord>): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Closes this cleanup handle to further removal operations.
|
|
76
|
+
*/
|
|
77
|
+
close(): void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Defines a provider factory capability narrower than a general transaction API.
|
|
81
|
+
*/
|
|
82
|
+
export interface DeliveryCleanupStorageFactory {
|
|
83
|
+
/**
|
|
84
|
+
* Creates a provider-owned cleanup handle.
|
|
85
|
+
*
|
|
86
|
+
* @returns The cleanup handle bound to this provider.
|
|
87
|
+
*/
|
|
88
|
+
createDeliveryCleanupStorage(): DeliveryCleanupStorage;
|
|
89
|
+
}
|
|
90
|
+
interface DeliveryCleanupFactoryAccess {
|
|
91
|
+
register(factory: StorageFactory, creator: DeliveryCleanupStorageFactory): void;
|
|
92
|
+
create(factory: StorageFactory): DeliveryCleanupStorage;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Registers and resolves provider cleanup handles for direct delivery.
|
|
96
|
+
*/
|
|
97
|
+
export declare const DeliveryCleanupStorageFactories: DeliveryCleanupFactoryAccess;
|
|
98
|
+
export {};
|
|
99
|
+
//# sourceMappingURL=delivery-cleanup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery-cleanup.d.ts","sourceRoot":"","sources":["../../src/internal/delivery-cleanup.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAG/B;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,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,OAAO,CAAC,OAAO,CAAC,CAAC;IAGpB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAG5C;;;;OAIG;IACH,4BAA4B,IAAI,sBAAsB,CAAC;CACxD;AAED,UAAU,4BAA4B;IACpC,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,6BAA6B,GAAG,IAAI,CAAC;IAChF,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,sBAAsB,CAAC;CACzD;AAED;;GAEG;AACH,eAAO,MAAM,+BAA+B,EAAE,4BAU5C,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
/**
|
|
15
|
+
* Determines whether a cleanup operation may proceed at a provider safe boundary.
|
|
16
|
+
*
|
|
17
|
+
* @param operation Supplies cooperative cancellation and deadline state.
|
|
18
|
+
* @returns Whether provider work may continue.
|
|
19
|
+
*/
|
|
20
|
+
export function cleanupOperationActive(operation) {
|
|
21
|
+
return (!operation?.signal?.aborted && operation?.timeoutMs !== 0 && operation?.isActive?.() !== false);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Registers and resolves provider cleanup handles for direct delivery.
|
|
25
|
+
*/
|
|
26
|
+
export const DeliveryCleanupStorageFactories = Object.freeze({
|
|
27
|
+
register(factory, creator) {
|
|
28
|
+
creators.set(factory, creator);
|
|
29
|
+
},
|
|
30
|
+
create(factory) {
|
|
31
|
+
const creator = creators.get(factory);
|
|
32
|
+
if (creator === undefined)
|
|
33
|
+
throw new Error("StorageFactory does not provide atomic delivery cleanup storage.");
|
|
34
|
+
return creator.createDeliveryCleanupStorage();
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const creators = new WeakMap();
|
|
38
|
+
//# sourceMappingURL=delivery-cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery-cleanup.js","sourceRoot":"","sources":["../../src/internal/delivery-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgCH;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,SAAuC;IAC5E,OAAO,CACL,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,IAAI,SAAS,EAAE,SAAS,KAAK,CAAC,IAAI,SAAS,EAAE,QAAQ,EAAE,EAAE,KAAK,KAAK,CAC/F,CAAC;AACJ,CAAC;AAqFD;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAiC,MAAM,CAAC,MAAM,CAAC;IACzF,QAAQ,CAAC,OAAuB,EAAE,OAAsC;QACtE,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,CAAC,OAAuB;QAC5B,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,OAAO,KAAK,SAAS;YACvB,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACtF,OAAO,OAAO,CAAC,4BAA4B,EAAE,CAAC;IAChD,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAiD,CAAC"}
|