@spine-event-engine/storage 2.0.0-snapshot.10
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 +190 -0
- package/REFERENCE.md +122 -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 +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -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/provider.d.ts +18 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +23 -0
- package/dist/provider.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 +35 -0
|
@@ -0,0 +1,183 @@
|
|
|
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, toBinary } from "@bufbuild/protobuf";
|
|
15
|
+
import { EntityRecordSchema } from "@spine-event-engine/proto/generated/spine/server/entity/entity_pb.js";
|
|
16
|
+
import { eventStoreAccess, eventStoreRecordSpec } from "../event/event-store.js";
|
|
17
|
+
import { eventHistorySpec, stateHistorySpec } from "../entity/entity-history-record-spec.js";
|
|
18
|
+
import { TenantBoundary } from "../internal/tenancy.js";
|
|
19
|
+
import { InMemoryEntityStorage, KeyedSerialQueue, MemoryEntityStorageFactory, ENTITY_SCOPE_MUTATION_KEY, } from "./in-memory-entity-history.js";
|
|
20
|
+
import { InMemoryRecordStorage } from "./in-memory-record-storage.js";
|
|
21
|
+
import { TenantRecords } from "./tenant-records.js";
|
|
22
|
+
const commitHost = globalThis;
|
|
23
|
+
/**
|
|
24
|
+
* Implements provider-owned Entity commits for one shared in-memory backend.
|
|
25
|
+
*/
|
|
26
|
+
export class MemoryEntityCommitStorage {
|
|
27
|
+
#entities;
|
|
28
|
+
#factory;
|
|
29
|
+
#openRecords;
|
|
30
|
+
#input;
|
|
31
|
+
#open = true;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a commit handle bound to one Entity source type.
|
|
34
|
+
*
|
|
35
|
+
* @param entities Opens the matching current Entity storage.
|
|
36
|
+
* @param factory Owns the Event Store coordination lock.
|
|
37
|
+
* @param openRecords Opens exact generic-record backing slices.
|
|
38
|
+
* @param input Defines the Entity storage source type.
|
|
39
|
+
*/
|
|
40
|
+
constructor(entities, factory, openRecords, input) {
|
|
41
|
+
this.#entities = entities;
|
|
42
|
+
this.#factory = factory;
|
|
43
|
+
this.#openRecords = openRecords;
|
|
44
|
+
this.#input = input;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Applies one fully preflighted in-memory Entity commit.
|
|
48
|
+
*
|
|
49
|
+
* @param input Defines the current record, retained histories, and delivery events.
|
|
50
|
+
* @returns The durable in-memory commit outcome.
|
|
51
|
+
*/
|
|
52
|
+
commit(input) {
|
|
53
|
+
this.#requireOpen();
|
|
54
|
+
this.#requireCompatible(input);
|
|
55
|
+
const backend = this.#entities.backend(input.entity);
|
|
56
|
+
const work = () => backend.mutationQueue.run(ENTITY_SCOPE_MUTATION_KEY, () => this.#commit(input, backend));
|
|
57
|
+
return input.events === undefined || input.events.length === 0
|
|
58
|
+
? work()
|
|
59
|
+
: eventStoreAccess.withLock(this.#factory, input.context, work);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Closes this commit handle without closing sibling handles.
|
|
63
|
+
*/
|
|
64
|
+
close() {
|
|
65
|
+
this.#open = false;
|
|
66
|
+
}
|
|
67
|
+
async #commit(input, liveBackend) {
|
|
68
|
+
this.#requireEnabledHistories(input);
|
|
69
|
+
const stateLayout = input.states === undefined || input.states.length === 0
|
|
70
|
+
? undefined
|
|
71
|
+
: stateHistorySpec(input.entity.stateSchema);
|
|
72
|
+
const eventLayout = input.diagnostics === undefined || input.diagnostics.length === 0
|
|
73
|
+
? undefined
|
|
74
|
+
: eventHistorySpec(input.entity.stateSchema);
|
|
75
|
+
const liveStates = stateLayout === undefined
|
|
76
|
+
? undefined
|
|
77
|
+
: this.#openRecords(input.context, stateLayout.spec, stateLayout.group);
|
|
78
|
+
const liveDiagnostics = eventLayout === undefined
|
|
79
|
+
? undefined
|
|
80
|
+
: this.#openRecords(input.context, eventLayout.spec, eventLayout.group);
|
|
81
|
+
const liveEvents = input.events === undefined || input.events.length === 0
|
|
82
|
+
? undefined
|
|
83
|
+
: this.#openRecords(input.context, eventStoreRecordSpec);
|
|
84
|
+
const stagedBackend = {
|
|
85
|
+
current: commitHost.structuredClone(liveBackend.current),
|
|
86
|
+
mutationQueue: new KeyedSerialQueue(),
|
|
87
|
+
};
|
|
88
|
+
const stagedStates = InMemoryCommitValues.stage(liveStates);
|
|
89
|
+
const stagedDiagnostics = InMemoryCommitValues.stage(liveDiagnostics);
|
|
90
|
+
const stagedEvents = InMemoryCommitValues.stage(liveEvents);
|
|
91
|
+
const stagedEntity = new InMemoryEntityStorage(this.#stagedInput(input.entity, stateLayout, stagedStates, eventLayout, stagedDiagnostics), stagedBackend);
|
|
92
|
+
try {
|
|
93
|
+
const current = await stagedEntity.current.read(input.entityId);
|
|
94
|
+
if (!InMemoryCommitValues.sameCurrent(current, input.expected))
|
|
95
|
+
return "conflict";
|
|
96
|
+
const delivery = [...(input.events ?? [])].map((event) => clone(eventStoreRecordSpec.recordType, event));
|
|
97
|
+
const materialized = delivery.map((event) => eventStoreRecordSpec.materialize(event));
|
|
98
|
+
const ids = materialized.map((record) => record.id);
|
|
99
|
+
if (new Set(ids.map((id) => id.value)).size !== ids.length ||
|
|
100
|
+
ids.some((id) => stagedEvents?.read(id) !== undefined)) {
|
|
101
|
+
throw new Error("Entity commit requires unique delivery-event IDs.");
|
|
102
|
+
}
|
|
103
|
+
await stagedEntity.current.write(input.next);
|
|
104
|
+
for (const state of input.states ?? [])
|
|
105
|
+
await stagedEntity.states.append(state);
|
|
106
|
+
for (const diagnostic of input.diagnostics ?? [])
|
|
107
|
+
await stagedEntity.events.append(diagnostic);
|
|
108
|
+
stagedEvents?.writeAll(materialized);
|
|
109
|
+
InMemoryCommitValues.replace(liveBackend.current, stagedBackend.current);
|
|
110
|
+
InMemoryCommitValues.publish(liveStates, stagedStates);
|
|
111
|
+
InMemoryCommitValues.publish(liveDiagnostics, stagedDiagnostics);
|
|
112
|
+
InMemoryCommitValues.publish(liveEvents, stagedEvents);
|
|
113
|
+
return "committed";
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
stagedEntity.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
#stagedInput(entity, stateLayout, states, eventLayout, diagnostics) {
|
|
120
|
+
const base = { ...entity };
|
|
121
|
+
delete base.stateHistoryStorage;
|
|
122
|
+
delete base.eventHistoryStorage;
|
|
123
|
+
return {
|
|
124
|
+
...base,
|
|
125
|
+
...(stateLayout === undefined || states === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: {
|
|
128
|
+
stateHistoryStorage: new InMemoryRecordStorage(entity.context, stateLayout.spec, () => states),
|
|
129
|
+
}),
|
|
130
|
+
...(eventLayout === undefined || diagnostics === undefined
|
|
131
|
+
? {}
|
|
132
|
+
: {
|
|
133
|
+
eventHistoryStorage: new InMemoryRecordStorage(entity.context, eventLayout.spec, () => diagnostics),
|
|
134
|
+
}),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
#requireEnabledHistories(input) {
|
|
138
|
+
if ((input.states?.length ?? 0) > 0 && !input.entity.stateHistory) {
|
|
139
|
+
throw new Error("Entity commit cannot append state history when it is disabled.");
|
|
140
|
+
}
|
|
141
|
+
if ((input.diagnostics?.length ?? 0) > 0 && !input.entity.eventHistory) {
|
|
142
|
+
throw new Error("Entity commit cannot append event history when it is disabled.");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
#requireCompatible(input) {
|
|
146
|
+
if (input.context.multitenant !== this.#input.context.multitenant ||
|
|
147
|
+
TenantBoundary.of(input.context).key !== TenantBoundary.of(this.#input.context).key ||
|
|
148
|
+
input.entity.sourceType.typeName !== this.#input.sourceType.typeName) {
|
|
149
|
+
throw new Error("Entity commit handle cannot commit another Entity storage scope.");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
#requireOpen() {
|
|
153
|
+
if (!this.#open)
|
|
154
|
+
throw new Error("Entity commit storage is closed.");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const InMemoryCommitValues = Object.freeze({
|
|
158
|
+
sameCurrent(actual, expected) {
|
|
159
|
+
if (actual === undefined || expected === undefined)
|
|
160
|
+
return actual === expected;
|
|
161
|
+
return InMemoryCommitValues.equal(toBinary(EntityRecordSchema, actual), toBinary(EntityRecordSchema, expected));
|
|
162
|
+
},
|
|
163
|
+
stage(live) {
|
|
164
|
+
if (live === undefined)
|
|
165
|
+
return undefined;
|
|
166
|
+
const staged = new TenantRecords();
|
|
167
|
+
staged.replace(live.snapshot());
|
|
168
|
+
return staged;
|
|
169
|
+
},
|
|
170
|
+
publish(live, staged) {
|
|
171
|
+
if (live !== undefined && staged !== undefined)
|
|
172
|
+
live.replace(staged.snapshot());
|
|
173
|
+
},
|
|
174
|
+
equal(left, right) {
|
|
175
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
176
|
+
},
|
|
177
|
+
replace(target, source) {
|
|
178
|
+
target.clear();
|
|
179
|
+
for (const [key, value] of source)
|
|
180
|
+
target.set(key, value);
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=in-memory-entity-commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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AAC;IAChB,CAAC;IAED,OAAO,CACL,IAAqC,EACrC,MAAuC;QAEvC,IAAI,IAAI,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,KAAK,CAAC,IAAgB,EAAE,KAAiB;QACvC,OAAO,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9F,CAAC;IAED,OAAO,CAAO,MAAiB,EAAE,MAAiB;QAChD,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { type Message } from "@bufbuild/protobuf";
|
|
2
|
+
import type { GenMessage } from "@bufbuild/protobuf/codegenv2";
|
|
3
|
+
import { type Timestamp } from "@bufbuild/protobuf/wkt";
|
|
4
|
+
import type { Any } from "@bufbuild/protobuf/wkt";
|
|
5
|
+
import type { Event } from "@spine-event-engine/proto";
|
|
6
|
+
import { type EntityRecord } from "@spine-event-engine/proto/generated/spine/server/entity/entity_pb.js";
|
|
7
|
+
import { type EntityStateKey } from "@spine-event-engine/proto/generated/spine/server/entity/state_key_pb.js";
|
|
8
|
+
import type { EntityEventHistoryPort, EntityStateHistoryPort } from "../entity/entity-history-storage.js";
|
|
9
|
+
import type { EntityRecordStorage } from "../entity/entity-record.js";
|
|
10
|
+
import type { RecordStorage } from "../record/record-storage.js";
|
|
11
|
+
import type { RecordSpec } from "../record/record-spec.js";
|
|
12
|
+
import type { StorageContext } from "../storage/storage.js";
|
|
13
|
+
import { InMemoryStorageBackend } from "./in-memory-storage-backend.js";
|
|
14
|
+
import { RecordColumn } from "../record/record-column.js";
|
|
15
|
+
import { type NormalizedQueryPlan } from "../query/query-policy.js";
|
|
16
|
+
/**
|
|
17
|
+
* Shared in-memory entity-storage factory for adapter conformance.
|
|
18
|
+
*/
|
|
19
|
+
export declare class MemoryEntityStorageFactory {
|
|
20
|
+
#private;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a factory with a fresh backend, or deliberately shares `backend`.
|
|
23
|
+
*
|
|
24
|
+
* @param backend Supplies the backend to share between factory handles.
|
|
25
|
+
*/
|
|
26
|
+
constructor(backend?: InMemoryStorageBackend);
|
|
27
|
+
/**
|
|
28
|
+
* Creates one scoped entity-storage handle.
|
|
29
|
+
*
|
|
30
|
+
* @param input Supplies the entity storage configuration.
|
|
31
|
+
* @returns Returns the scoped in-memory entity storage.
|
|
32
|
+
*/
|
|
33
|
+
create<I, S extends Message>(input: EntityStorageInput<I, S>): InMemoryEntityStorage<I, S>;
|
|
34
|
+
/**
|
|
35
|
+
* Opens the provider-owned maps used by an atomic in-memory commit.
|
|
36
|
+
*
|
|
37
|
+
* @param input Supplies the Entity storage configuration.
|
|
38
|
+
* @returns The compatible backend maps for this Entity scope.
|
|
39
|
+
*/
|
|
40
|
+
backend<I, S extends Message>(input: EntityStorageInput<I, S>): EntityBackend;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* One scoped in-memory current/state/event storage handle.
|
|
44
|
+
*/
|
|
45
|
+
export declare class InMemoryEntityStorage<I, S extends Message> {
|
|
46
|
+
/**
|
|
47
|
+
* Provides current-record storage for this entity scope.
|
|
48
|
+
*/
|
|
49
|
+
readonly current: MemoryEntityRecordStorage<I>;
|
|
50
|
+
/**
|
|
51
|
+
* Provides event-history storage for this entity scope.
|
|
52
|
+
*/
|
|
53
|
+
readonly events: EntityEventHistoryPort<I>;
|
|
54
|
+
/**
|
|
55
|
+
* Provides state-history storage for this entity scope.
|
|
56
|
+
*/
|
|
57
|
+
readonly states: EntityStateHistoryPort<I, S>;
|
|
58
|
+
/**
|
|
59
|
+
* Creates the current, event, and state storage adapters over `backend`.
|
|
60
|
+
*
|
|
61
|
+
* @param input Supplies the entity storage configuration.
|
|
62
|
+
* @param backend Supplies the scoped in-memory data structures.
|
|
63
|
+
*/
|
|
64
|
+
constructor(input: EntityStorageInput<I, S>, backend: EntityBackend);
|
|
65
|
+
/**
|
|
66
|
+
* Closes this independently owned provider handle without affecting siblings.
|
|
67
|
+
*/
|
|
68
|
+
close(): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Configures one in-memory entity storage scope.
|
|
72
|
+
*/
|
|
73
|
+
export interface EntityStorageInput<I, S extends Message> {
|
|
74
|
+
/**
|
|
75
|
+
* Identifies the storage context for this entity scope.
|
|
76
|
+
*/
|
|
77
|
+
readonly context: StorageContext;
|
|
78
|
+
/**
|
|
79
|
+
* Supplies canonicalization and defensive-copy operations for entity IDs.
|
|
80
|
+
*/
|
|
81
|
+
readonly id: EntityIdCodec<I>;
|
|
82
|
+
/**
|
|
83
|
+
* Descriptor-owned current-record columns, including lifecycle and state fields.
|
|
84
|
+
*/
|
|
85
|
+
readonly columns: readonly RecordColumn<EntityRecord>[];
|
|
86
|
+
/**
|
|
87
|
+
* Declares the provider ID type and current EntityRecord layout.
|
|
88
|
+
*/
|
|
89
|
+
readonly recordSpec: RecordSpec<I, EntityRecord>;
|
|
90
|
+
/**
|
|
91
|
+
* Identifies the Entity source type represented by these records.
|
|
92
|
+
*/
|
|
93
|
+
readonly sourceType: GenMessage<Message>;
|
|
94
|
+
/**
|
|
95
|
+
* Describes the generated entity state message.
|
|
96
|
+
*/
|
|
97
|
+
readonly stateSchema: GenMessage<S>;
|
|
98
|
+
/**
|
|
99
|
+
* Enables grouped retained state history for this Entity storage handle.
|
|
100
|
+
*/
|
|
101
|
+
readonly stateHistory?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Enables grouped retained diagnostic event history for this Entity storage handle.
|
|
104
|
+
*/
|
|
105
|
+
readonly eventHistory?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Supplies the enabled grouped state-history storage opened by the outer factory.
|
|
108
|
+
*/
|
|
109
|
+
readonly stateHistoryStorage?: RecordStorage<EntityStateKey, EntityRecord>;
|
|
110
|
+
/**
|
|
111
|
+
* Supplies the enabled grouped event-history storage opened by the outer factory.
|
|
112
|
+
*/
|
|
113
|
+
readonly eventHistoryStorage?: RecordStorage<import("@spine-event-engine/proto").EventId, Event>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Internal provider ID canonicalization and clone contract.
|
|
117
|
+
*/
|
|
118
|
+
export interface EntityIdCodec<I> {
|
|
119
|
+
/**
|
|
120
|
+
* Copies an entity identifier before returning it to callers.
|
|
121
|
+
*
|
|
122
|
+
* @param id Supplies the identifier to copy.
|
|
123
|
+
* @returns Returns an independent identifier copy.
|
|
124
|
+
*/
|
|
125
|
+
readonly clone: (id: I) => I;
|
|
126
|
+
/**
|
|
127
|
+
* Packs an Entity identifier into the generated persistence envelope.
|
|
128
|
+
*
|
|
129
|
+
* @param id Supplies the Entity identifier to pack.
|
|
130
|
+
* @returns The packed identifier.
|
|
131
|
+
*/
|
|
132
|
+
readonly pack: (id: I) => Any;
|
|
133
|
+
/**
|
|
134
|
+
* Unpacks one JVM EntityRecord ID envelope into the Entity identifier.
|
|
135
|
+
*
|
|
136
|
+
* @param id The packed EntityRecord ID.
|
|
137
|
+
* @returns The unpacked entity ID, when it matches the configured schema.
|
|
138
|
+
*/
|
|
139
|
+
readonly unpack: (id: NonNullable<EntityRecord["entityId"]>) => I | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Converts an entity identifier into its storage-map key.
|
|
142
|
+
*
|
|
143
|
+
* @param id Supplies the identifier to canonicalize.
|
|
144
|
+
* @returns Returns the stable storage-map key.
|
|
145
|
+
*/
|
|
146
|
+
readonly key: (id: I) => string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The shared maps and write queue behind one in-memory Entity storage.
|
|
150
|
+
*/
|
|
151
|
+
export interface EntityBackend {
|
|
152
|
+
/**
|
|
153
|
+
* The latest record for each Entity identifier.
|
|
154
|
+
*/
|
|
155
|
+
readonly current: Map<string, unknown>;
|
|
156
|
+
/**
|
|
157
|
+
* Serializes mutations for this Entity storage scope.
|
|
158
|
+
*/
|
|
159
|
+
readonly mutationQueue: KeyedSerialQueue;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Identifies the single mutation sequence for one physical Entity storage scope.
|
|
163
|
+
*/
|
|
164
|
+
export declare const ENTITY_SCOPE_MUTATION_KEY = "entity-storage-scope";
|
|
165
|
+
/**
|
|
166
|
+
* In-memory latest-state storage used by all entity families.
|
|
167
|
+
*/
|
|
168
|
+
export declare class MemoryEntityRecordStorage<I> implements EntityRecordStorage<I> {
|
|
169
|
+
#private;
|
|
170
|
+
/**
|
|
171
|
+
* Creates a current-record adapter over supplied or fresh record storage.
|
|
172
|
+
*
|
|
173
|
+
* @param input Supplies state, ID, column, and record-storage configuration.
|
|
174
|
+
*/
|
|
175
|
+
constructor(input: {
|
|
176
|
+
readonly idKey: (id: I) => string;
|
|
177
|
+
readonly idClone?: (id: I) => I;
|
|
178
|
+
readonly records?: Map<string, EntityRecord>;
|
|
179
|
+
readonly unpackId: (id: NonNullable<EntityRecord["entityId"]>) => I | undefined;
|
|
180
|
+
readonly columns: readonly RecordColumn<EntityRecord>[];
|
|
181
|
+
readonly queue?: KeyedSerialQueue;
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* Reads the current record for one entity identifier.
|
|
185
|
+
*
|
|
186
|
+
* @param id Supplies the entity identifier to read.
|
|
187
|
+
* @returns Resolves to an independent current record, when present.
|
|
188
|
+
*/
|
|
189
|
+
read(id: I): Promise<EntityRecord | undefined>;
|
|
190
|
+
/**
|
|
191
|
+
* Stores an independent copy of one current entity record.
|
|
192
|
+
*
|
|
193
|
+
* @param record Supplies the current record to store.
|
|
194
|
+
* @returns Completes when the record is stored.
|
|
195
|
+
*/
|
|
196
|
+
write(record: EntityRecord): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Returns non-deleted current records matching the normalized plan.
|
|
199
|
+
*
|
|
200
|
+
* @param plan Supplies the normalized record-query plan.
|
|
201
|
+
* @returns Resolves to ordered matching current-record entries.
|
|
202
|
+
*/
|
|
203
|
+
query(plan: NormalizedQueryPlan<I>): Promise<readonly import("../query/query-execution.js").NormalizedQueryEntry<I, EntityRecord>[]>;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* In-memory immutable diagnostic event-history adapter.
|
|
207
|
+
*/
|
|
208
|
+
export declare class MemoryEntityEventHistory<I> implements EntityEventHistoryPort<I> {
|
|
209
|
+
#private;
|
|
210
|
+
/**
|
|
211
|
+
* Creates an event-history adapter over grouped generated record storage.
|
|
212
|
+
*
|
|
213
|
+
* @param input Supplies the ID codec, generated record storage, and maintenance seam.
|
|
214
|
+
*/
|
|
215
|
+
constructor(input: {
|
|
216
|
+
readonly id: EntityIdCodec<I>;
|
|
217
|
+
readonly records: RecordStorage<import("@spine-event-engine/proto").EventId, Event>;
|
|
218
|
+
readonly maintenance?: InMemoryMaintenance;
|
|
219
|
+
readonly queue?: KeyedSerialQueue;
|
|
220
|
+
});
|
|
221
|
+
/**
|
|
222
|
+
* Stores one immutable event-history record idempotently.
|
|
223
|
+
*
|
|
224
|
+
* @param record Supplies the event-history record to append.
|
|
225
|
+
* @returns Completes when the record is stored.
|
|
226
|
+
*/
|
|
227
|
+
append(record: Event): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* Reads recent events in descending producer-version order.
|
|
230
|
+
*
|
|
231
|
+
* @param entityId Supplies the entity identifier to inspect.
|
|
232
|
+
* @param depth Limits the number of events returned.
|
|
233
|
+
* @param startingFromVersion Excludes events at or after this producer version.
|
|
234
|
+
* @returns Resolves to immutable event snapshots.
|
|
235
|
+
*/
|
|
236
|
+
backward(entityId: I, depth: number, startingFromVersion?: bigint): Promise<readonly Event[]>;
|
|
237
|
+
/**
|
|
238
|
+
* Deletes events created before the supplied timestamp in maintenance chunks.
|
|
239
|
+
*
|
|
240
|
+
* @param olderThan Specifies the exclusive event creation-time boundary.
|
|
241
|
+
* @returns Completes when maintenance finishes.
|
|
242
|
+
*/
|
|
243
|
+
truncate(olderThan: Timestamp): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* Closes this event-history adapter.
|
|
246
|
+
*/
|
|
247
|
+
close(): void;
|
|
248
|
+
/**
|
|
249
|
+
* Returns whether this event-history adapter remains open.
|
|
250
|
+
*
|
|
251
|
+
* @returns Returns true while the adapter is open.
|
|
252
|
+
*/
|
|
253
|
+
isOpen(): boolean;
|
|
254
|
+
private eventIdIn;
|
|
255
|
+
private producerIdIn;
|
|
256
|
+
private validatedEvent;
|
|
257
|
+
private requireOpen;
|
|
258
|
+
private afterSelection;
|
|
259
|
+
private batchSize;
|
|
260
|
+
private pageSize;
|
|
261
|
+
private deleteEntries;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* In-memory immutable, versioned state-history adapter.
|
|
265
|
+
*/
|
|
266
|
+
export declare class InMemoryEntityHistory<I, S extends Message> implements EntityStateHistoryPort<I, S> {
|
|
267
|
+
#private;
|
|
268
|
+
/**
|
|
269
|
+
* Creates a state-history adapter over grouped generated record storage.
|
|
270
|
+
*
|
|
271
|
+
* @param input Supplies the generated record storage, ID codec, state schema, and maintenance seam.
|
|
272
|
+
*/
|
|
273
|
+
constructor(input: {
|
|
274
|
+
readonly id: EntityIdCodec<I>;
|
|
275
|
+
readonly records: RecordStorage<EntityStateKey, EntityRecord>;
|
|
276
|
+
readonly stateSchema: GenMessage<S>;
|
|
277
|
+
readonly maintenance?: InMemoryMaintenance;
|
|
278
|
+
readonly queue?: KeyedSerialQueue;
|
|
279
|
+
});
|
|
280
|
+
/**
|
|
281
|
+
* Stores one generated Entity record in the grouped state history.
|
|
282
|
+
*
|
|
283
|
+
* @param record Supplies the Entity record to append.
|
|
284
|
+
* @returns Completes when the record is stored.
|
|
285
|
+
*/
|
|
286
|
+
append(record: EntityRecord): Promise<void>;
|
|
287
|
+
/**
|
|
288
|
+
* Reads recent state records in descending version and creation-time order.
|
|
289
|
+
*
|
|
290
|
+
* @param entityId Supplies the entity identifier to inspect.
|
|
291
|
+
* @param depth Limits the number of state records returned.
|
|
292
|
+
* @param startingFromVersion Excludes records at or after this version.
|
|
293
|
+
* @returns Resolves to cloned generated Entity records.
|
|
294
|
+
*/
|
|
295
|
+
backward(entityId: I, depth: number, startingFromVersion?: bigint): Promise<readonly EntityRecord[]>;
|
|
296
|
+
/**
|
|
297
|
+
* Reads the latest retained state at or before a timestamp.
|
|
298
|
+
*
|
|
299
|
+
* @param entityId Supplies the entity identifier to inspect.
|
|
300
|
+
* @param time Specifies the inclusive state creation-time boundary.
|
|
301
|
+
* @returns Resolves to a cloned state, when a compatible record is retained.
|
|
302
|
+
*/
|
|
303
|
+
stateAt(entityId: I, time: Timestamp): Promise<S | undefined>;
|
|
304
|
+
/**
|
|
305
|
+
* Deletes all but the requested number of newest records for one Entity.
|
|
306
|
+
*
|
|
307
|
+
* @param entityId Supplies the entity identifier to trim.
|
|
308
|
+
* @param keepMostRecent Specifies how many newest records to retain.
|
|
309
|
+
* @returns Completes when bounded deletion chunks finish.
|
|
310
|
+
*/
|
|
311
|
+
trim(entityId: I, keepMostRecent: number): Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Deletes records created before the supplied timestamp.
|
|
314
|
+
*
|
|
315
|
+
* @param olderThan Specifies the exclusive state creation-time boundary.
|
|
316
|
+
* @returns Completes when bounded deletion chunks finish.
|
|
317
|
+
*/
|
|
318
|
+
truncate(olderThan: Timestamp): Promise<void>;
|
|
319
|
+
/**
|
|
320
|
+
* Closes the grouped record-storage handle.
|
|
321
|
+
*/
|
|
322
|
+
close(): void;
|
|
323
|
+
/**
|
|
324
|
+
* Returns whether the grouped record-storage handle remains open.
|
|
325
|
+
*
|
|
326
|
+
* @returns Returns true while the adapter is open.
|
|
327
|
+
*/
|
|
328
|
+
isOpen(): boolean;
|
|
329
|
+
private deleteEntries;
|
|
330
|
+
private keyFor;
|
|
331
|
+
private entityIdIn;
|
|
332
|
+
private validateRecord;
|
|
333
|
+
private unpackState;
|
|
334
|
+
private requireOpen;
|
|
335
|
+
private afterSelection;
|
|
336
|
+
private afterMaintenanceChunk;
|
|
337
|
+
private batchSize;
|
|
338
|
+
private pageSize;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Adapter-internal deterministic maintenance test seam; not a storage API.
|
|
342
|
+
*/
|
|
343
|
+
export interface InMemoryMaintenance {
|
|
344
|
+
/**
|
|
345
|
+
* Completes after maintenance selects its fixed deletion boundary.
|
|
346
|
+
*
|
|
347
|
+
* @returns Completes after the test seam finishes.
|
|
348
|
+
*/
|
|
349
|
+
readonly afterSelection?: () => void | Promise<void>;
|
|
350
|
+
/**
|
|
351
|
+
* Completes after each maintenance deletion chunk.
|
|
352
|
+
*
|
|
353
|
+
* @returns Completes after the test seam finishes.
|
|
354
|
+
*/
|
|
355
|
+
readonly onChunk?: () => void | Promise<void>;
|
|
356
|
+
/**
|
|
357
|
+
* Test-only override for deterministic in-memory maintenance chunking.
|
|
358
|
+
*/
|
|
359
|
+
readonly batchSize?: number;
|
|
360
|
+
/**
|
|
361
|
+
* Test-only override for deterministic in-memory history query paging.
|
|
362
|
+
*/
|
|
363
|
+
readonly pageSize?: number;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Async FIFO mutexes shared by all history handles for one in-memory backend.
|
|
367
|
+
*/
|
|
368
|
+
export declare class KeyedSerialQueue {
|
|
369
|
+
#private;
|
|
370
|
+
/**
|
|
371
|
+
* Queues an operation after earlier operations with the same key finish.
|
|
372
|
+
*
|
|
373
|
+
* @param key Identifies the serialized operation sequence.
|
|
374
|
+
* @param operation Supplies the operation to run.
|
|
375
|
+
* @returns Resolves to the operation result.
|
|
376
|
+
*/
|
|
377
|
+
run<T>(key: string, operation: () => Promise<T>): Promise<T>;
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=in-memory-entity-history.d.ts.map
|
|
@@ -0,0 +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,EAAmB,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,sEAAsE,CAAC;AAC9E,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,yEAAyE,CAAC;AAEjF,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,qCAAqC,CAAC;AAK7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAGjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAMxF;;GAEG;AACH,qBAAa,0BAA0B;;IAGrC;;;;OAIG;gBACS,OAAO,GAAE,sBAAqD;IAI1E;;;;;OA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