@photon-grove/evt 0.1.2 → 0.2.0
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/README.md +15 -3
- package/dist/dynamodb/head.d.ts +6 -0
- package/dist/dynamodb/head.d.ts.map +1 -1
- package/dist/dynamodb/head.js +11 -0
- package/dist/dynamodb/head.js.map +1 -1
- package/dist/dynamodb/index.d.ts +1 -1
- package/dist/dynamodb/index.d.ts.map +1 -1
- package/dist/dynamodb/index.js +1 -1
- package/dist/dynamodb/index.js.map +1 -1
- package/dist/dynamodb/repository.d.ts +9 -2
- package/dist/dynamodb/repository.d.ts.map +1 -1
- package/dist/dynamodb/repository.js +114 -35
- package/dist/dynamodb/repository.js.map +1 -1
- package/dist/dynamodb/requests.d.ts +36 -5
- package/dist/dynamodb/requests.d.ts.map +1 -1
- package/dist/dynamodb/requests.js +56 -13
- package/dist/dynamodb/requests.js.map +1 -1
- package/dist/errors.d.ts +38 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +45 -4
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/memory/repository.d.ts +3 -2
- package/dist/memory/repository.d.ts.map +1 -1
- package/dist/memory/repository.js +78 -29
- package/dist/memory/repository.js.map +1 -1
- package/dist/postgres/repository.d.ts +9 -2
- package/dist/postgres/repository.d.ts.map +1 -1
- package/dist/postgres/repository.js +107 -36
- package/dist/postgres/repository.js.map +1 -1
- package/dist/postgres/schema.d.ts.map +1 -1
- package/dist/postgres/schema.js +16 -0
- package/dist/postgres/schema.js.map +1 -1
- package/dist/repository.d.ts +75 -0
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +89 -3
- package/dist/repository.js.map +1 -1
- package/dist/staging.d.ts +28 -0
- package/dist/staging.d.ts.map +1 -0
- package/dist/staging.js +89 -0
- package/dist/staging.js.map +1 -0
- package/dist/store.d.ts +11 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +30 -71
- package/dist/store.js.map +1 -1
- package/dist/transaction.d.ts +113 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +207 -0
- package/dist/transaction.js.map +1 -0
- package/package.json +1 -1
- package/src/dynamodb/head.ts +15 -0
- package/src/dynamodb/index.ts +1 -0
- package/src/dynamodb/repository.ts +162 -41
- package/src/dynamodb/requests.ts +98 -14
- package/src/errors.ts +63 -4
- package/src/index.ts +16 -7
- package/src/memory/repository.ts +93 -32
- package/src/postgres/repository.ts +133 -48
- package/src/postgres/schema.ts +16 -0
- package/src/repository.ts +169 -2
- package/src/staging.ts +138 -0
- package/src/store.ts +47 -96
- package/src/transaction.ts +322 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// The `TransactWriteItems` actions of a commit and of a snapshot write, built from the storage
|
|
2
2
|
// format alone (storage format, "Writes"). Every commit opens with the two control checks, the
|
|
3
|
-
// feature marker's and the rebuild lock's, then its projector operations, then writes
|
|
4
|
-
// its head update, its event puts, and its snapshot put when it has one.
|
|
3
|
+
// feature marker's and the rebuild lock's, then its projector operations, then writes each stream:
|
|
4
|
+
// its head update, its event puts, and its snapshot put when it has one. A transaction then checks
|
|
5
|
+
// the head of every stream it fenced.
|
|
5
6
|
import { int64Argument, safeIntegerArgument } from '../fields.js';
|
|
6
7
|
import { EvtError } from '../errors.js';
|
|
7
|
-
import { headUpdate } from './head.js';
|
|
8
|
+
import { headFence, headUpdate } from './head.js';
|
|
8
9
|
import { HEAD_SORT_KEY, SNAPSHOT_SORT_KEY, eventItem, snapshotItem } from './item.js';
|
|
9
10
|
import { FEATURES_PK, REBUILD_LOCK_PK } from './marker.js';
|
|
10
11
|
import { DYNAMODB_BACKEND } from './views.js';
|
|
@@ -60,19 +61,48 @@ export function rebuildLockCheck(table) {
|
|
|
60
61
|
/**
|
|
61
62
|
* The actions of a commit with at least one event, in order, by a writer that validated the
|
|
62
63
|
* feature manifest at `markerVersion`. `ttl` is given only for a stream with retention. A projector
|
|
63
|
-
* group for any backend but DynamoDB is refused. Exported for the compatibility fixtures
|
|
64
|
-
* signature changes when commits span streams.
|
|
64
|
+
* group for any backend but DynamoDB is refused. Exported for the compatibility fixtures.
|
|
65
65
|
*/
|
|
66
66
|
export function commitTransaction(table, commit, markerVersion, ttl) {
|
|
67
|
-
|
|
68
|
-
const last = commit.events.at(-1);
|
|
69
|
-
if (first === undefined || last === undefined) {
|
|
67
|
+
if (commit.events.length === 0) {
|
|
70
68
|
throw new RangeError('a commit transaction needs at least one event');
|
|
71
69
|
}
|
|
70
|
+
const transaction = { streams: [commit], fences: [], projections: commit.projections ?? [] };
|
|
71
|
+
return transactionItems(table, transaction, markerVersion, () => ttl);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The actions of a normalized transaction that writes or fences at least one stream, in order:
|
|
75
|
+
* the control checks, the projector operations in declaration order, every written stream's head
|
|
76
|
+
* update, event puts and snapshot put, then a check on every fenced stream's head. `ttl` gives a
|
|
77
|
+
* written stream's `ttl`s when it has retention. Exported for the compatibility fixtures.
|
|
78
|
+
*/
|
|
79
|
+
export function transactionItems(table, transaction, markerVersion, ttl) {
|
|
80
|
+
return buildTransaction(table, transaction, markerVersion, ttl).items;
|
|
81
|
+
}
|
|
82
|
+
/** {@link transactionItems}, with where each stream's and fence's actions sit. */
|
|
83
|
+
export function buildTransaction(table, transaction, markerVersion, ttl) {
|
|
72
84
|
const items = [markerCheck(table, markerVersion), rebuildLockCheck(table)];
|
|
73
|
-
items.push(...projectorItems(
|
|
85
|
+
items.push(...projectorItems(transaction.projections));
|
|
86
|
+
const projectorEnd = items.length;
|
|
87
|
+
const streams = [];
|
|
88
|
+
for (const commit of transaction.streams) {
|
|
89
|
+
const head = items.length;
|
|
90
|
+
items.push(...streamItems(table, commit, ttl(commit)));
|
|
91
|
+
const eventsEnd = head + 1 + commit.events.length;
|
|
92
|
+
streams.push({ commit, head, eventsEnd, snapshot: items.length > eventsEnd ? eventsEnd : null });
|
|
93
|
+
}
|
|
94
|
+
const fences = transaction.fences.map((fence) => {
|
|
95
|
+
items.push(fenceCheck(table, fence));
|
|
96
|
+
return { index: items.length - 1, fence };
|
|
97
|
+
});
|
|
98
|
+
return { items, layout: { projectorEnd, streams, fences } };
|
|
99
|
+
}
|
|
100
|
+
// A written stream's actions: its head update, its event puts and its snapshot put.
|
|
101
|
+
function streamItems(table, commit, ttl) {
|
|
102
|
+
const first = commit.events[0];
|
|
103
|
+
const last = commit.events.at(-1);
|
|
74
104
|
const head = headUpdate(commit.entityId, first.sequence, last.sequence, ttl?.head);
|
|
75
|
-
items
|
|
105
|
+
const items = [headUpdateItem(table, head)];
|
|
76
106
|
for (const event of commit.events) {
|
|
77
107
|
items.push(eventPut(table, event, ttl?.items));
|
|
78
108
|
}
|
|
@@ -89,6 +119,19 @@ export function commitTransaction(table, commit, markerVersion, ttl) {
|
|
|
89
119
|
}
|
|
90
120
|
return items;
|
|
91
121
|
}
|
|
122
|
+
// The check on a fenced stream's head item: it still has the head the transaction read.
|
|
123
|
+
function fenceCheck(table, fence) {
|
|
124
|
+
const action = headFence(fence.entityId, fence.head);
|
|
125
|
+
const check = {
|
|
126
|
+
TableName: table,
|
|
127
|
+
Key: headKey(fence.entityId),
|
|
128
|
+
ConditionExpression: action.conditionExpression,
|
|
129
|
+
};
|
|
130
|
+
if (action.values.length > 0) {
|
|
131
|
+
check.ExpressionAttributeValues = Object.fromEntries(action.values.map(([placeholder, value]) => [placeholder, number(value)]));
|
|
132
|
+
}
|
|
133
|
+
return { ConditionCheck: check };
|
|
134
|
+
}
|
|
92
135
|
/**
|
|
93
136
|
* The actions of a snapshot written outside a commit: the marker check, the head guard, and the
|
|
94
137
|
* put, which never lowers the stored snapshot. It carries no rebuild-lock check. `ttl` is given
|
|
@@ -137,10 +180,10 @@ function snapshotGuard(table, entityId, eventSequence, ttl) {
|
|
|
137
180
|
},
|
|
138
181
|
};
|
|
139
182
|
}
|
|
140
|
-
/** The DynamoDB actions of
|
|
141
|
-
export function projectorItems(
|
|
183
|
+
/** The DynamoDB actions of projector groups, in order. */
|
|
184
|
+
export function projectorItems(groups) {
|
|
142
185
|
const items = [];
|
|
143
|
-
for (const group of
|
|
186
|
+
for (const group of groups) {
|
|
144
187
|
if (group.backend !== DYNAMODB_BACKEND) {
|
|
145
188
|
throw new EvtError('invalidCommit', `invalid commit: a DynamoDB repository can't write a ${group.backend} projector group`);
|
|
146
189
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../src/dynamodb/requests.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,+FAA+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../src/dynamodb/requests.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,+FAA+F;AAC/F,mGAAmG;AACnG,mGAAmG;AACnG,sCAAsC;AAGtC,OAAO,EAAC,aAAa,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAA;AAC/D,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAA;AAGrC,OAAO,EAAkB,SAAS,EAAE,UAAU,EAAC,MAAM,WAAW,CAAA;AAChE,OAAO,EAAC,aAAa,EAAa,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,WAAW,CAAA;AAC9F,OAAO,EAAC,WAAW,EAAE,eAAe,EAAC,MAAM,aAAa,CAAA;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,YAAY,CAAA;AAE3C,gFAAgF;AAChF,MAAM,CAAC,MAAM,sBAAsB,GAAG,0CAA0C,CAAA;AAEhF,iFAAiF;AACjF,MAAM,CAAC,MAAM,sBAAsB,GAAG,0BAA0B,CAAA;AAEhE,0DAA0D;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAA;AAE7D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,w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`: optimistic concurrency failed. Another writer committed since the stream was
|
|
12
12
|
* read. Reload and run the command again.
|
|
13
13
|
* - `sequenceGap`: a commit or a load skips a sequence. A conflict.
|
|
14
|
+
* - `fenceConflict`: another writer moved a stream the transaction read but didn't write. A
|
|
15
|
+
* conflict, retryable when the engine observed the fenced head.
|
|
16
|
+
* - `retentionConflict`: a transaction fenced a stream whose entity type has retention, which a
|
|
17
|
+
* fence can't protect. Nothing was written.
|
|
14
18
|
* - `streamHeadDrift`: a stream's head disagrees with its events or snapshot. Never retried.
|
|
15
19
|
* - `commitTooLarge`: the commit is over the transaction budget. Nothing was written.
|
|
16
20
|
* - `compactionUncovered`: no snapshot covers the events compaction was asked to delete.
|
|
@@ -31,7 +35,7 @@
|
|
|
31
35
|
* - `replay`: a stored event failed to upcast or decode while an aggregate loaded.
|
|
32
36
|
* - `snapshot`: a stored snapshot failed to decode while an aggregate loaded.
|
|
33
37
|
*/
|
|
34
|
-
export type EvtErrorCode = 'invalidJson' | 'invalidRecord' | 'invalidArgument' | 'invalidCommit' | 'conflict' | 'sequenceGap' | 'streamHeadDrift' | 'commitTooLarge' | 'compactionUncovered' | 'reservedEntityId' | 'unsupportedFeature' | 'streamHeadsNotMigrated' | 'storeNotInitialized' | 'featureManifestChanged' | 'transient' | 'rebuildInProgress' | 'historyDependentProjection' | 'projectorOnlyCommit' | 'replay' | 'snapshot';
|
|
38
|
+
export type EvtErrorCode = 'invalidJson' | 'invalidRecord' | 'invalidArgument' | 'invalidCommit' | 'conflict' | 'sequenceGap' | 'fenceConflict' | 'retentionConflict' | 'streamHeadDrift' | 'commitTooLarge' | 'compactionUncovered' | 'reservedEntityId' | 'unsupportedFeature' | 'streamHeadsNotMigrated' | 'storeNotInitialized' | 'featureManifestChanged' | 'transient' | 'rebuildInProgress' | 'historyDependentProjection' | 'projectorOnlyCommit' | 'replay' | 'snapshot';
|
|
35
39
|
export declare class EvtError extends Error {
|
|
36
40
|
readonly name: string;
|
|
37
41
|
readonly code: EvtErrorCode;
|
|
@@ -167,6 +171,32 @@ export declare class RebuildInProgressError extends EvtError {
|
|
|
167
171
|
readonly code = "rebuildInProgress";
|
|
168
172
|
constructor();
|
|
169
173
|
}
|
|
174
|
+
/** Where a read fence's head came from (ADR 0004): the engine's own read, or the caller. */
|
|
175
|
+
export type FenceProvenance = 'engine' | 'caller';
|
|
176
|
+
/**
|
|
177
|
+
* A read fence failed: another writer moved a stream the transaction read but didn't write past
|
|
178
|
+
* the head it observed. A fence the engine filled is retryable, since loading again observes the
|
|
179
|
+
* new head. A caller-stamped one isn't: the caller's input is stale. Nothing was written.
|
|
180
|
+
*/
|
|
181
|
+
export declare class FenceConflictError extends EvtError {
|
|
182
|
+
readonly name = "FenceConflictError";
|
|
183
|
+
readonly code = "fenceConflict";
|
|
184
|
+
readonly entityId: string;
|
|
185
|
+
/** The head the transaction fenced the stream at. */
|
|
186
|
+
readonly head: bigint;
|
|
187
|
+
readonly provenance: FenceProvenance;
|
|
188
|
+
constructor(entityId: string, head: bigint, provenance: FenceProvenance);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* A transaction fenced a stream whose entity type has retention: TTL deletes items in no order, so
|
|
192
|
+
* a fence on a retained stream protects nothing. Nothing was written.
|
|
193
|
+
*/
|
|
194
|
+
export declare class RetentionConflictError extends EvtError {
|
|
195
|
+
readonly name = "RetentionConflictError";
|
|
196
|
+
readonly code = "retentionConflict";
|
|
197
|
+
readonly entityType: string;
|
|
198
|
+
constructor(entityType: string);
|
|
199
|
+
}
|
|
170
200
|
/**
|
|
171
201
|
* Compaction was refused because the store declares the entity's type history-dependent: its
|
|
172
202
|
* projectors' rebuild replays the events compaction would delete. Nothing was deleted.
|
|
@@ -206,11 +236,15 @@ export declare class SnapshotError extends EvtError {
|
|
|
206
236
|
readonly entityId: string;
|
|
207
237
|
constructor(entityId: string, cause: unknown);
|
|
208
238
|
}
|
|
209
|
-
/**
|
|
239
|
+
/**
|
|
240
|
+
* Whether an error is an optimistic-concurrency conflict: a `conflict`, a `sequenceGap` or a
|
|
241
|
+
* `fenceConflict`.
|
|
242
|
+
*/
|
|
210
243
|
export declare function isConflict(error: unknown): boolean;
|
|
211
244
|
/**
|
|
212
|
-
* Whether reloading and running the command again may succeed: after a conflict
|
|
213
|
-
* holds the store, after the feature manifest changed
|
|
245
|
+
* Whether reloading and running the command again may succeed: after a conflict (a fence the
|
|
246
|
+
* caller stamped excepted), while a rebuild holds the store, after the feature manifest changed
|
|
247
|
+
* under the writer, or after throttling.
|
|
214
248
|
*/
|
|
215
249
|
export declare function isRetryable(error: unknown): boolean;
|
|
216
250
|
/** An error's message, or the value itself as text. */
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,MAAM,YAAY,GACpB,aAAa,GACb,eAAe,GACf,iBAAiB,GACjB,eAAe,GACf,UAAU,GACV,aAAa,GACb,eAAe,GACf,mBAAmB,GACnB,iBAAiB,GACjB,gBAAgB,GAChB,qBAAqB,GACrB,kBAAkB,GAClB,oBAAoB,GACpB,wBAAwB,GACxB,qBAAqB,GACrB,wBAAwB,GACxB,WAAW,GACX,mBAAmB,GACnB,4BAA4B,GAC5B,qBAAqB,GACrB,QAAQ,GACR,UAAU,CAAA;AAEd,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAkB,IAAI,EAAE,MAAM,CAAa;IAC3C,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAE3B,YAAY,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAC,EAG3E;CACF;AAED,yFAA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HANGED
|
@@ -174,6 +174,38 @@ export class RebuildInProgressError extends EvtError {
|
|
|
174
174
|
super('rebuildInProgress', 'a projection rebuild is in progress');
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* A read fence failed: another writer moved a stream the transaction read but didn't write past
|
|
179
|
+
* the head it observed. A fence the engine filled is retryable, since loading again observes the
|
|
180
|
+
* new head. A caller-stamped one isn't: the caller's input is stale. Nothing was written.
|
|
181
|
+
*/
|
|
182
|
+
export class FenceConflictError extends EvtError {
|
|
183
|
+
name = 'FenceConflictError';
|
|
184
|
+
code = 'fenceConflict';
|
|
185
|
+
entityId;
|
|
186
|
+
/** The head the transaction fenced the stream at. */
|
|
187
|
+
head;
|
|
188
|
+
provenance;
|
|
189
|
+
constructor(entityId, head, provenance) {
|
|
190
|
+
super('fenceConflict', `read fence failed for ${entityId} at head ${head} (${provenance})`);
|
|
191
|
+
this.entityId = entityId;
|
|
192
|
+
this.head = head;
|
|
193
|
+
this.provenance = provenance;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* A transaction fenced a stream whose entity type has retention: TTL deletes items in no order, so
|
|
198
|
+
* a fence on a retained stream protects nothing. Nothing was written.
|
|
199
|
+
*/
|
|
200
|
+
export class RetentionConflictError extends EvtError {
|
|
201
|
+
name = 'RetentionConflictError';
|
|
202
|
+
code = 'retentionConflict';
|
|
203
|
+
entityType;
|
|
204
|
+
constructor(entityType) {
|
|
205
|
+
super('retentionConflict', `read fences refused for retention-enabled entity type ${entityType}`);
|
|
206
|
+
this.entityType = entityType;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
177
209
|
/**
|
|
178
210
|
* Compaction was refused because the store declares the entity's type history-dependent: its
|
|
179
211
|
* projectors' rebuild replays the events compaction would delete. Nothing was deleted.
|
|
@@ -231,15 +263,24 @@ export class SnapshotError extends EvtError {
|
|
|
231
263
|
this.entityId = entityId;
|
|
232
264
|
}
|
|
233
265
|
}
|
|
234
|
-
/**
|
|
266
|
+
/**
|
|
267
|
+
* Whether an error is an optimistic-concurrency conflict: a `conflict`, a `sequenceGap` or a
|
|
268
|
+
* `fenceConflict`.
|
|
269
|
+
*/
|
|
235
270
|
export function isConflict(error) {
|
|
236
|
-
return error instanceof EvtError &&
|
|
271
|
+
return (error instanceof EvtError &&
|
|
272
|
+
(error.code === 'conflict' || error.code === 'sequenceGap' || error.code === 'fenceConflict'));
|
|
237
273
|
}
|
|
238
274
|
/**
|
|
239
|
-
* Whether reloading and running the command again may succeed: after a conflict
|
|
240
|
-
* holds the store, after the feature manifest changed
|
|
275
|
+
* Whether reloading and running the command again may succeed: after a conflict (a fence the
|
|
276
|
+
* caller stamped excepted), while a rebuild holds the store, after the feature manifest changed
|
|
277
|
+
* under the writer, or after throttling.
|
|
241
278
|
*/
|
|
242
279
|
export function isRetryable(error) {
|
|
280
|
+
// A caller-stamped fence stays stale however often the command runs again.
|
|
281
|
+
if (error instanceof FenceConflictError) {
|
|
282
|
+
return error.provenance === 'engine';
|
|
283
|
+
}
|
|
243
284
|
if (isConflict(error)) {
|
|
244
285
|
return true;
|
|
245
286
|
}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,6FAA6F;AAC7F,uEAAuE;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,6FAA6F;AAC7F,uEAAuE;AA+DvE,MAAM,OAAO,QAAS,SAAQ,KAAK;IACf,IAAI,GAAW,UAAU,CAAA;IAClC,IAAI,CAAc;IAE3B,YAAY,IAAkB,EAAE,OAAe,EAAE,OAA2B;QAC1E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED,y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A;AAC/D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,14 +2,15 @@ export { type Aggregate, type AggregateDefinition, type Decision, type EventDefi
|
|
|
2
2
|
export { base64Decode, base64Encode } from './base64.js';
|
|
3
3
|
export { type Codec, type JsonOptions, type StandardResult, type StandardSchemaV1, json, } from './codec.js';
|
|
4
4
|
export { encodeEnvelope, decodeEnvelope, messageAttributes } from './envelope.js';
|
|
5
|
-
export { CommitTooLargeError, CompactionUncoveredError, ConflictError, EvtError, type EvtErrorCode, FeatureManifestChangedError, HistoryDependentProjectionError, ProjectorOnlyCommitError, RebuildInProgressError, ReplayError, ReservedEntityIdError, SequenceGapError, SnapshotError, StoreNotInitializedError, StreamHeadDriftError, StreamHeadsNotMigratedError, TransientError, UnsupportedFeatureError, type FeaturePair, isConflict, isRetryable, } from './errors.js';
|
|
5
|
+
export { CommitTooLargeError, CompactionUncoveredError, ConflictError, EvtError, type EvtErrorCode, FeatureManifestChangedError, FenceConflictError, type FenceProvenance, HistoryDependentProjectionError, ProjectorOnlyCommitError, RebuildInProgressError, ReplayError, ReservedEntityIdError, RetentionConflictError, SequenceGapError, SnapshotError, StoreNotInitializedError, StreamHeadDriftError, StreamHeadsNotMigratedError, TransientError, UnsupportedFeatureError, type FeaturePair, isConflict, isRetryable, } from './errors.js';
|
|
6
6
|
export { type SerializedEvent, type SerializedSnapshot, decodeEvent, decodeSnapshot, encodeEvent, encodeSnapshot, eventId, } from './event.js';
|
|
7
7
|
export { type FeatureManifest, type ManifestTexts, STREAM_HEADS_FEATURE, STREAM_HEADS_VERSION, SUPPORTED_FEATURES, decodeManifest, encodeManifest, } from './features.js';
|
|
8
8
|
export { JsonNumber, type JsonValue, parseJson, stringifyJson } from './json.js';
|
|
9
9
|
export { type Metadata, type Origin, decodeMetadata, effectiveCausationId, emptyMetadata, encodeMetadata, } from './metadata.js';
|
|
10
|
-
export type
|
|
10
|
+
export { type CallOptions, type Commit, type NewSnapshot, type NormalizedTransaction, type ProjectorGroup, type ReadFence, type Repository, type StoreInitializer, type TransactionCommit, type TransactionalRepository, normalizeTransaction, } from './repository.js';
|
|
11
11
|
export { DEFAULT_RETRY_POLICY, type RetryPolicy, retryDelay, } from './retry.js';
|
|
12
12
|
export { MAX_COMMIT_ITEM_BYTES, snapshotCommitSize, snapshotEventsDue } from './snapshots.js';
|
|
13
13
|
export { compareUtf8, utf8Length } from './utf8.js';
|
|
14
|
+
export { type CallerFence, StreamRead, Transaction, type TransactionResult } from './transaction.js';
|
|
14
15
|
export { DEFAULT_SNAPSHOT_INTERVAL, type ExecuteOptions, type ExecuteResult, type Loaded, type RetryOptions, Store, type StoreOptions, } from './store.js';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,aAAa,CAAA;AACtD,OAAO,EACL,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,IAAI,GACL,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAA;AAC/E,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,QAAQ,EACR,KAAK,YAAY,EACjB,2BAA2B,EAC3B,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,uBAAuB,EACvB,KAAK,WAAW,EAChB,UAAU,EACV,WAAW,GACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,WAAW,EACX,cAAc,EACd,WAAW,EACX,cAAc,EACd,OAAO,GACR,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,cAAc,GACf,MAAM,eAAe,CAAA;AACtB,OAAO,EAAC,UAAU,EAAE,KAAK,SAAS,EAAE,SAAS,EAAE,aAAa,EAAC,MAAM,WAAW,CAAA;AAC9E,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,cAAc,GACf,MAAM,eAAe,CAAA;AACtB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,aAAa,CAAA;AACtD,OAAO,EACL,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,IAAI,GACL,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAA;AAC/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gB,CAAA;AAC3F,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,WAAW,CAAA;AACjD,OAAO,EAAC,KAAK,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,iBAAiB,EAAC,MAAM,kBAAkB,CAAA;AAClG,OAAO,EACL,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,EACL,KAAK,YAAY,GAClB,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -5,13 +5,15 @@ export { defineAggregate, defineEvents, jsonUpcaster, } from './aggregate.js';
|
|
|
5
5
|
export { base64Decode, base64Encode } from './base64.js';
|
|
6
6
|
export { json, } from './codec.js';
|
|
7
7
|
export { encodeEnvelope, decodeEnvelope, messageAttributes } from './envelope.js';
|
|
8
|
-
export { CommitTooLargeError, CompactionUncoveredError, ConflictError, EvtError, FeatureManifestChangedError, HistoryDependentProjectionError, ProjectorOnlyCommitError, RebuildInProgressError, ReplayError, ReservedEntityIdError, SequenceGapError, SnapshotError, StoreNotInitializedError, StreamHeadDriftError, StreamHeadsNotMigratedError, TransientError, UnsupportedFeatureError, isConflict, isRetryable, } from './errors.js';
|
|
8
|
+
export { CommitTooLargeError, CompactionUncoveredError, ConflictError, EvtError, FeatureManifestChangedError, FenceConflictError, HistoryDependentProjectionError, ProjectorOnlyCommitError, RebuildInProgressError, ReplayError, ReservedEntityIdError, RetentionConflictError, SequenceGapError, SnapshotError, StoreNotInitializedError, StreamHeadDriftError, StreamHeadsNotMigratedError, TransientError, UnsupportedFeatureError, isConflict, isRetryable, } from './errors.js';
|
|
9
9
|
export { decodeEvent, decodeSnapshot, encodeEvent, encodeSnapshot, eventId, } from './event.js';
|
|
10
10
|
export { STREAM_HEADS_FEATURE, STREAM_HEADS_VERSION, SUPPORTED_FEATURES, decodeManifest, encodeManifest, } from './features.js';
|
|
11
11
|
export { JsonNumber, parseJson, stringifyJson } from './json.js';
|
|
12
12
|
export { decodeMetadata, effectiveCausationId, emptyMetadata, encodeMetadata, } from './metadata.js';
|
|
13
|
+
export { normalizeTransaction, } from './repository.js';
|
|
13
14
|
export { DEFAULT_RETRY_POLICY, retryDelay, } from './retry.js';
|
|
14
15
|
export { MAX_COMMIT_ITEM_BYTES, snapshotCommitSize, snapshotEventsDue } from './snapshots.js';
|
|
15
16
|
export { compareUtf8, utf8Length } from './utf8.js';
|
|
17
|
+
export { StreamRead, Transaction } from './transaction.js';
|
|
16
18
|
export { DEFAULT_SNAPSHOT_INTERVAL, Store, } from './store.js';
|
|
17
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,wFAAwF;AACxF,mFAAmF;AAEnF,OAAO,EAWL,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,aAAa,CAAA;AACtD,OAAO,EAKL,IAAI,GACL,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAA;AAC/E,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,QAAQ,EAER,2BAA2B,EAC3B,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,2BAA2B,EAC3B,cAAc,EACd,uBAAuB,EAEvB,UAAU,EACV,WAAW,GACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EAGL,WAAW,EACX,cAAc,EACd,WAAW,EACX,cAAc,EACd,OAAO,GACR,MAAM,YAAY,CAAA;AACnB,OAAO,EAGL,oBAAoB,EACpB,oB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b,cAAc,GACf,MAAM,eAAe,CAAA;AACtB,OAAO,EAWL,oBAAoB,GACrB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,oBAAoB,EAEpB,UAAU,GACX,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,qBAAqB,EAAE,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,gBAAgB,CAAA;AAC3F,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,WAAW,CAAA;AACjD,OAAO,EAAmB,UAAU,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAA;AAClG,OAAO,EACL,yBAAyB,EAKzB,KAAK,GAEN,MAAM,YAAY,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SerializedEvent, SerializedSnapshot } from '../event.js';
|
|
2
2
|
import { type FeatureManifest } from '../features.js';
|
|
3
|
-
import { type CallOptions, type Commit, type
|
|
3
|
+
import { type CallOptions, type Commit, type StoreInitializer, type TransactionCommit, type TransactionalRepository } from '../repository.js';
|
|
4
4
|
/** The state of the rebuild fence's two rows that a commit's lock check reads. */
|
|
5
5
|
export interface RebuildState {
|
|
6
6
|
/** The generation counter: odd while a rebuild holds the store or after a force-release. */
|
|
@@ -22,10 +22,11 @@ export interface RebuildState {
|
|
|
22
22
|
* on its feature manifest, so {@link initialize} is needed only where code treats every backend
|
|
23
23
|
* alike.
|
|
24
24
|
*/
|
|
25
|
-
export declare class MemRepository implements
|
|
25
|
+
export declare class MemRepository implements TransactionalRepository, StoreInitializer {
|
|
26
26
|
#private;
|
|
27
27
|
initialize(options?: CallOptions): Promise<boolean>;
|
|
28
28
|
commit(commit: Commit, options?: CallOptions): Promise<void>;
|
|
29
|
+
commitTransaction(transaction: TransactionCommit, options?: CallOptions): Promise<void>;
|
|
29
30
|
events(entityId: string, options?: CallOptions): Promise<SerializedEvent[]>;
|
|
30
31
|
eventsAfter(entityId: string, after: bigint, options?: CallOptions): Promise<SerializedEvent[]>;
|
|
31
32
|
latest(entityId: string, n: number, options?: CallOptions): Promise<SerializedEvent[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/memory/repository.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/memory/repository.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAC,eAAe,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAA;AACpE,OAAO,EACL,KAAK,eAAe,EAMrB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,MAAM,EAGX,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAQ7B,MAAM,kBAAkB,CAAA;AAUzB,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,4FAA4F;IAC5F,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAAA;CACtC;AAYD;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,YAAW,uBAAuB,EAAE,gBAAgB;;IAIvE,UAAU,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAUxD;IAEK,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjE;IAEK,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAM5F;IAiEK,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAEhF;IAEK,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,eA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,GAAG,eAAe,CAAA;IAChE,qEAAqE;IACrE,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,eAAe,CA8BpE"}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// per stream that every commit raises, optimistic concurrency against it, the feature marker and
|
|
3
3
|
// the rebuild-lock check, and the same failure classification and transaction budget. It's for
|
|
4
4
|
// tests and local development.
|
|
5
|
-
import { ConflictError, CompactionUncoveredError, EvtError, HistoryDependentProjectionError, RebuildInProgressError, SequenceGapError, StreamHeadDriftError, StreamHeadsNotMigratedError, } from '../errors.js';
|
|
5
|
+
import { ConflictError, CompactionUncoveredError, EvtError, FenceConflictError, HistoryDependentProjectionError, RebuildInProgressError, SequenceGapError, StreamHeadDriftError, StreamHeadsNotMigratedError, } from '../errors.js';
|
|
6
6
|
import { checkSupported, checkWritable, declaresStreamHeads, entityTypeSet, withStreamHeads, } from '../features.js';
|
|
7
7
|
import { int64Argument } from '../fields.js';
|
|
8
|
-
import { checkBudget, checkNotReserved,
|
|
8
|
+
import { checkBudget, checkFenceRetention, checkNotReserved, normalizeTransaction, rankFailures, transactionSizes, validateCommit, } from '../repository.js';
|
|
9
9
|
// Read a repository's private state, for the fixtures. The class's static block sets them.
|
|
10
10
|
let streamsOf;
|
|
11
11
|
let controlsOf;
|
|
@@ -36,38 +36,73 @@ export class MemRepository {
|
|
|
36
36
|
options?.signal?.throwIfAborted();
|
|
37
37
|
validateCommit(commit);
|
|
38
38
|
checkNotReserved(commit.entityId);
|
|
39
|
-
if (commit.events.length
|
|
40
|
-
|
|
39
|
+
if (commit.events.length > 0) {
|
|
40
|
+
this.#write(normalizeTransaction({ streams: [commit] }));
|
|
41
41
|
}
|
|
42
|
+
}
|
|
43
|
+
async commitTransaction(transaction, options) {
|
|
44
|
+
options?.signal?.throwIfAborted();
|
|
45
|
+
const normalized = normalizeTransaction(transaction);
|
|
46
|
+
if (normalized.streams.length > 0 || normalized.fences.length > 0) {
|
|
47
|
+
this.#write(normalized);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Writes a transaction, or refuses it with nothing written, in the order the live backends
|
|
51
|
+
// check: the budget, the marker and the fences' retention, the rebuild lock, then every stream
|
|
52
|
+
// and fence, ranked.
|
|
53
|
+
#write(transaction) {
|
|
42
54
|
// Every backend budgets a commit the same way, so an oversized one fails before any write.
|
|
43
|
-
checkBudget(
|
|
55
|
+
checkBudget(transactionSizes(transaction, () => undefined));
|
|
44
56
|
// The control rows come first, as the two checks that open every live commit: the marker,
|
|
45
57
|
// then the rebuild lock, which an unsettled generation fails, a force-released one included.
|
|
46
58
|
this.#checkManifest();
|
|
59
|
+
const retention = this.#controls.manifest?.retention ?? [];
|
|
60
|
+
checkFenceRetention(transaction, (entityType) => retention.includes(entityType));
|
|
47
61
|
const { rebuild } = this.#controls;
|
|
48
62
|
if (rebuild.lock !== null || rebuild.generation % 2n !== 0n) {
|
|
49
63
|
throw new RebuildInProgressError();
|
|
50
64
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
const failures = [];
|
|
66
|
+
for (const stream of transaction.streams) {
|
|
67
|
+
const failure = checkWrite(stream, this.#streams.get(stream.entityId) ?? emptyStream());
|
|
68
|
+
if (failure !== null) {
|
|
69
|
+
failures.push(failure);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const fence of transaction.fences) {
|
|
73
|
+
const failure = checkFence(fence, this.#streams.get(fence.entityId) ?? emptyStream());
|
|
74
|
+
if (failure !== null) {
|
|
75
|
+
failures.push(failure);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const failure = rankFailures(failures);
|
|
79
|
+
if (failure !== undefined) {
|
|
80
|
+
throw failure;
|
|
65
81
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
// Copy everything before the first write, so a copy that throws leaves every stream as it was.
|
|
83
|
+
const writes = transaction.streams.map((commit) => {
|
|
84
|
+
const events = commit.events.map(cloneEvent);
|
|
85
|
+
const last = events.at(-1).sequence;
|
|
86
|
+
const snapshot = commit.snapshot && {
|
|
87
|
+
entityType: commit.snapshot.entityType,
|
|
88
|
+
entityId: commit.entityId,
|
|
89
|
+
sequence: commit.snapshot.sequence,
|
|
90
|
+
eventSequence: last,
|
|
91
|
+
payload: copy(commit.snapshot.payload),
|
|
92
|
+
};
|
|
93
|
+
return { entityId: commit.entityId, events, last, snapshot };
|
|
94
|
+
});
|
|
95
|
+
for (const { entityId, events, last, snapshot } of writes) {
|
|
96
|
+
const held = this.#streams.get(entityId) ?? emptyStream();
|
|
97
|
+
for (const event of events) {
|
|
98
|
+
held.events.set(event.sequence, event);
|
|
99
|
+
}
|
|
100
|
+
held.head = held.head > last ? held.head : last;
|
|
101
|
+
if (snapshot) {
|
|
102
|
+
held.snapshot = snapshot;
|
|
103
|
+
}
|
|
104
|
+
this.#streams.set(entityId, held);
|
|
69
105
|
}
|
|
70
|
-
this.#streams.set(commit.entityId, held);
|
|
71
106
|
}
|
|
72
107
|
async events(entityId, options) {
|
|
73
108
|
return this.eventsAfter(entityId, 0n, options);
|
|
@@ -169,24 +204,38 @@ export class MemRepository {
|
|
|
169
204
|
return events;
|
|
170
205
|
}
|
|
171
206
|
}
|
|
172
|
-
//
|
|
173
|
-
// head update needs no head for a create and the head to be the sequence before
|
|
174
|
-
// for an append. Then no event may exist already, and a snapshot must follow the
|
|
207
|
+
// The failure of a commit the stored stream doesn't accept, as the live backends' conditions find
|
|
208
|
+
// it, or null. The head update needs no head for a create and the head to be the sequence before
|
|
209
|
+
// the first event for an append. Then no event may exist already, and a snapshot must follow the
|
|
210
|
+
// stored one.
|
|
175
211
|
function checkWrite(commit, held) {
|
|
176
212
|
const first = commit.events[0].sequence;
|
|
177
213
|
const headPasses = first <= 1n ? held.head === 0n : held.head === first - 1n;
|
|
178
214
|
if (!headPasses) {
|
|
179
|
-
|
|
215
|
+
return probe(commit.entityId, held, first);
|
|
180
216
|
}
|
|
181
217
|
// The head update passed and an event put would fail: an event sits above the head.
|
|
182
218
|
if (commit.events.some((event) => held.events.has(event.sequence))) {
|
|
183
|
-
|
|
219
|
+
return drift(commit.entityId, held.head, derivedHead(held));
|
|
184
220
|
}
|
|
185
221
|
const snapshot = commit.snapshot;
|
|
186
222
|
const stored = held.snapshot?.sequence ?? 0n;
|
|
187
223
|
if (snapshot && snapshot.sequence !== stored + 1n) {
|
|
188
|
-
|
|
224
|
+
return new ConflictError(commit.entityId, `snapshot sequence moved: stored ${stored}, commit writes ${snapshot.sequence}`);
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
// The failure of a fence whose stream's head moved, or null: drift when the head disagrees with
|
|
229
|
+
// the log, and otherwise a fence conflict.
|
|
230
|
+
function checkFence(fence, held) {
|
|
231
|
+
if (held.head === fence.head) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
const derived = derivedHead(held);
|
|
235
|
+
if (held.head !== derived) {
|
|
236
|
+
return drift(fence.entityId, held.head, derived);
|
|
189
237
|
}
|
|
238
|
+
return new FenceConflictError(fence.entityId, fence.head, fence.provenance);
|
|
190
239
|
}
|
|
191
240
|
// Classifies a failed head update the way the live backends' failure-path probe does: a stored
|
|
192
241
|
// head that disagrees with the head derived from the log is drift. Memory has no concurrent
|