@photon-grove/evt 0.1.0 → 0.1.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.
Files changed (96) hide show
  1. package/README.md +85 -9
  2. package/dist/aggregate.d.ts +26 -0
  3. package/dist/aggregate.d.ts.map +1 -1
  4. package/dist/aggregate.js.map +1 -1
  5. package/dist/dynamodb/client.d.ts +83 -0
  6. package/dist/dynamodb/client.d.ts.map +1 -0
  7. package/dist/dynamodb/client.js +6 -0
  8. package/dist/dynamodb/client.js.map +1 -0
  9. package/dist/dynamodb/index.d.ts +6 -1
  10. package/dist/dynamodb/index.d.ts.map +1 -1
  11. package/dist/dynamodb/index.js +8 -3
  12. package/dist/dynamodb/index.js.map +1 -1
  13. package/dist/dynamodb/item.d.ts +2 -0
  14. package/dist/dynamodb/item.d.ts.map +1 -1
  15. package/dist/dynamodb/item.js +5 -4
  16. package/dist/dynamodb/item.js.map +1 -1
  17. package/dist/dynamodb/marker.d.ts +11 -0
  18. package/dist/dynamodb/marker.d.ts.map +1 -0
  19. package/dist/dynamodb/marker.js +56 -0
  20. package/dist/dynamodb/marker.js.map +1 -0
  21. package/dist/dynamodb/repository.d.ts +61 -0
  22. package/dist/dynamodb/repository.d.ts.map +1 -0
  23. package/dist/dynamodb/repository.js +748 -0
  24. package/dist/dynamodb/repository.js.map +1 -0
  25. package/dist/dynamodb/requests.d.ts +68 -0
  26. package/dist/dynamodb/requests.d.ts.map +1 -0
  27. package/dist/dynamodb/requests.js +194 -0
  28. package/dist/dynamodb/requests.js.map +1 -0
  29. package/dist/dynamodb/views.d.ts +18 -0
  30. package/dist/dynamodb/views.d.ts.map +1 -0
  31. package/dist/dynamodb/views.js +56 -0
  32. package/dist/dynamodb/views.js.map +1 -0
  33. package/dist/errors.d.ts +109 -2
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +118 -2
  36. package/dist/errors.js.map +1 -1
  37. package/dist/features.d.ts +55 -0
  38. package/dist/features.d.ts.map +1 -0
  39. package/dist/features.js +126 -0
  40. package/dist/features.js.map +1 -0
  41. package/dist/index.d.ts +4 -3
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +2 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/memory/index.d.ts +1 -1
  46. package/dist/memory/index.d.ts.map +1 -1
  47. package/dist/memory/index.js +1 -1
  48. package/dist/memory/index.js.map +1 -1
  49. package/dist/memory/repository.d.ts +38 -2
  50. package/dist/memory/repository.d.ts.map +1 -1
  51. package/dist/memory/repository.js +95 -6
  52. package/dist/memory/repository.js.map +1 -1
  53. package/dist/postgres/client.d.ts +32 -0
  54. package/dist/postgres/client.d.ts.map +1 -0
  55. package/dist/postgres/client.js +4 -0
  56. package/dist/postgres/client.js.map +1 -0
  57. package/dist/postgres/index.d.ts +4 -0
  58. package/dist/postgres/index.d.ts.map +1 -0
  59. package/dist/postgres/index.js +6 -0
  60. package/dist/postgres/index.js.map +1 -0
  61. package/dist/postgres/repository.d.ts +55 -0
  62. package/dist/postgres/repository.d.ts.map +1 -0
  63. package/dist/postgres/repository.js +527 -0
  64. package/dist/postgres/repository.js.map +1 -0
  65. package/dist/postgres/schema.d.ts +81 -0
  66. package/dist/postgres/schema.d.ts.map +1 -0
  67. package/dist/postgres/schema.js +233 -0
  68. package/dist/postgres/schema.js.map +1 -0
  69. package/dist/repository.d.ts +56 -7
  70. package/dist/repository.d.ts.map +1 -1
  71. package/dist/repository.js +24 -9
  72. package/dist/repository.js.map +1 -1
  73. package/dist/store.d.ts +7 -5
  74. package/dist/store.d.ts.map +1 -1
  75. package/dist/store.js +34 -9
  76. package/dist/store.js.map +1 -1
  77. package/package.json +16 -3
  78. package/src/aggregate.ts +28 -0
  79. package/src/dynamodb/client.ts +102 -0
  80. package/src/dynamodb/index.ts +27 -2
  81. package/src/dynamodb/item.ts +6 -4
  82. package/src/dynamodb/marker.ts +64 -0
  83. package/src/dynamodb/repository.ts +1053 -0
  84. package/src/dynamodb/requests.ts +276 -0
  85. package/src/dynamodb/views.ts +67 -0
  86. package/src/errors.ts +176 -2
  87. package/src/features.ts +175 -0
  88. package/src/index.ts +28 -1
  89. package/src/memory/index.ts +9 -1
  90. package/src/memory/repository.ts +156 -6
  91. package/src/postgres/client.ts +37 -0
  92. package/src/postgres/index.ts +23 -0
  93. package/src/postgres/repository.ts +773 -0
  94. package/src/postgres/schema.ts +286 -0
  95. package/src/repository.ts +86 -13
  96. package/src/store.ts +61 -11
package/dist/errors.js CHANGED
@@ -98,6 +98,113 @@ export class ReservedEntityIdError extends EvtError {
98
98
  this.entityId = entityId;
99
99
  }
100
100
  }
101
+ /**
102
+ * The store's feature manifest declares pairs this package doesn't model, so it refuses to write:
103
+ * a commit, a snapshot write, compaction or initialization. Nothing was written.
104
+ */
105
+ export class UnsupportedFeatureError extends EvtError {
106
+ name = 'UnsupportedFeatureError';
107
+ code = 'unsupportedFeature';
108
+ /** Every unsupported pair, sorted by name. */
109
+ unsupported;
110
+ constructor(unsupported) {
111
+ const pairs = unsupported.map((pair) => `${pair.name}@${pair.version}`).join(', ');
112
+ super('unsupportedFeature', `store declares unsupported features (${pairs}); refusing to write`);
113
+ this.unsupported = unsupported;
114
+ }
115
+ }
116
+ /**
117
+ * The store holds data but its feature manifest doesn't declare stream-heads: its streams may have
118
+ * no head items, so a head-aware write could fail every stream. Migrate the store with every older
119
+ * writer stopped. Nothing was written.
120
+ */
121
+ export class StreamHeadsNotMigratedError extends EvtError {
122
+ name = 'StreamHeadsNotMigratedError';
123
+ code = 'streamHeadsNotMigrated';
124
+ constructor() {
125
+ super('streamHeadsNotMigrated', 'store does not declare the stream-heads feature and holds data without per-stream head ' +
126
+ 'items; migrate it before writing');
127
+ }
128
+ }
129
+ /**
130
+ * The store's feature manifest doesn't declare stream-heads, and this writer doesn't initialize a
131
+ * store itself (the DynamoDB default), so it refuses rather than scan the table to learn whether
132
+ * it's fresh. Initialize a fresh store once, at deploy time, or migrate one written before stream
133
+ * heads. Nothing was written.
134
+ */
135
+ export class StoreNotInitializedError extends EvtError {
136
+ name = 'StoreNotInitializedError';
137
+ code = 'storeNotInitialized';
138
+ constructor() {
139
+ super('storeNotInitialized', 'store is not initialized: the feature manifest does not declare stream-heads; initialize ' +
140
+ 'a fresh store, or migrate one written before stream heads, before writing');
141
+ }
142
+ }
143
+ /**
144
+ * Another writer changed the store's feature manifest after this one validated it, so the commit's
145
+ * marker check failed. The writer has validated the new manifest, which it supports. Retryable.
146
+ * Nothing was written.
147
+ */
148
+ export class FeatureManifestChangedError extends EvtError {
149
+ name = 'FeatureManifestChangedError';
150
+ code = 'featureManifestChanged';
151
+ constructor(options) {
152
+ super('featureManifestChanged', 'feature manifest changed under this writer', options);
153
+ }
154
+ }
155
+ /**
156
+ * The backend refused the write for now, such as a DynamoDB transaction cancelled for throttling.
157
+ * Retryable, after a backoff. Nothing was written. The backend's error is its cause.
158
+ */
159
+ export class TransientError extends EvtError {
160
+ name = 'TransientError';
161
+ code = 'transient';
162
+ constructor(detail, options) {
163
+ super('transient', `transient failure: ${detail}`, options);
164
+ }
165
+ }
166
+ /**
167
+ * A projection rebuild holds the store, or one was force-released and no rebuild has finished
168
+ * since, so every commit is refused. Retryable: the command can run again once the rebuild ends.
169
+ */
170
+ export class RebuildInProgressError extends EvtError {
171
+ name = 'RebuildInProgressError';
172
+ code = 'rebuildInProgress';
173
+ constructor() {
174
+ super('rebuildInProgress', 'a projection rebuild is in progress');
175
+ }
176
+ }
177
+ /**
178
+ * Compaction was refused because the store declares the entity's type history-dependent: its
179
+ * projectors' rebuild replays the events compaction would delete. Nothing was deleted.
180
+ */
181
+ export class HistoryDependentProjectionError extends EvtError {
182
+ name = 'HistoryDependentProjectionError';
183
+ code = 'historyDependentProjection';
184
+ entityType;
185
+ entityId;
186
+ constructor(entityType, entityId) {
187
+ super('historyDependentProjection', `entity type ${entityType} is declared history-dependent; compaction would delete the ` +
188
+ `commits its rebuild replays (entity ${entityId})`);
189
+ this.entityType = entityType;
190
+ this.entityId = entityId;
191
+ }
192
+ }
193
+ /**
194
+ * A commit carried projector operations but no events. Views are projections of committed events,
195
+ * so operations with no event behind them are refused on every backend. Nothing was written.
196
+ */
197
+ export class ProjectorOnlyCommitError extends EvtError {
198
+ name = 'ProjectorOnlyCommitError';
199
+ code = 'projectorOnlyCommit';
200
+ /** How many projector operations the commit carried. */
201
+ operations;
202
+ constructor(operations) {
203
+ super('projectorOnlyCommit', `a commit carries ${operations} projector operations but no events; views need a ` +
204
+ 'backing event in the same commit');
205
+ this.operations = operations;
206
+ }
207
+ }
101
208
  /** A load failed closed on a stored event: an upcaster threw, or the payload didn't decode. */
102
209
  export class ReplayError extends EvtError {
103
210
  name = 'ReplayError';
@@ -128,9 +235,18 @@ export class SnapshotError extends EvtError {
128
235
  export function isConflict(error) {
129
236
  return error instanceof EvtError && (error.code === 'conflict' || error.code === 'sequenceGap');
130
237
  }
131
- /** Whether reloading and running the command again may succeed. So far, only after a conflict. */
238
+ /**
239
+ * Whether reloading and running the command again may succeed: after a conflict, while a rebuild
240
+ * holds the store, after the feature manifest changed under the writer, or after throttling.
241
+ */
132
242
  export function isRetryable(error) {
133
- return isConflict(error);
243
+ if (isConflict(error)) {
244
+ return true;
245
+ }
246
+ return (error instanceof EvtError &&
247
+ (error.code === 'rebuildInProgress' ||
248
+ error.code === 'featureManifestChanged' ||
249
+ error.code === 'transient'));
134
250
  }
135
251
  /** An error's message, or the value itself as text. */
136
252
  export function messageOf(error) {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,6FAA6F;AAC7F,uEAAuE;AAoCvE,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,G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B,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,OAAO,aAAc,SAAQ,QAAQ;IACvB,IAAI,GAAG,eAAe,CAAA;IACtB,IAAI,GAAG,UAAU,CAAA;IAC1B,QAAQ,CAAQ;IAEzB,YAAY,QAAgB,EAAE,KAAc;QAC1C,KAAK,CAAC,UAAU,EAAE,gCAAgC,QAAQ,KAAK,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,EAAC,KAAK,EAAC,CAAC,CAAA;QAC3F,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,YAAY,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,CAAC,CAAA;AACjG,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CACL,KAAK,YAAY,QAAQ;QACzB,CAAC,KAAK,CAAC,IAAI,KAAK,mBAAmB;YACjC,KAAK,CAAC,IAAI,KAAK,wBAAwB;YACvC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAC9B,CAAA;AACH,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { type FeaturePair } from './errors.js';
2
+ /** The feature every writer models and requires: per-stream head items (ADR 0007). */
3
+ export declare const STREAM_HEADS_FEATURE = "stream-heads";
4
+ /** The stored-format version of {@link STREAM_HEADS_FEATURE} this package reads and writes. */
5
+ export declare const STREAM_HEADS_VERSION = 1;
6
+ /**
7
+ * The `(feature, stored-format version)` pairs this package models. The other features the
8
+ * storage format defines (`journal`, `journal-compaction`, `postgres-views`) are Rust-first, so a
9
+ * store that declares any of them is refused.
10
+ */
11
+ export declare const SUPPORTED_FEATURES: readonly FeaturePair[];
12
+ /** The parsed marker row. A store with no marker row has no manifest. */
13
+ export interface FeatureManifest {
14
+ /** Bumped by exactly one on every declaration. */
15
+ readonly version: bigint;
16
+ /** Each declared feature's stored-format version. */
17
+ readonly features: ReadonlyMap<string, number>;
18
+ /** The entity types whose commit-wide projectors are history-dependent: never compacted. */
19
+ readonly historyDependent: readonly string[];
20
+ /** The entity types configured with retention: never fenced. */
21
+ readonly retention: readonly string[];
22
+ }
23
+ /**
24
+ * Refuses a manifest that declares a pair this package doesn't model, listing every such pair,
25
+ * with an {@link UnsupportedFeatureError}.
26
+ */
27
+ export declare function checkSupported(manifest: FeatureManifest | null): void;
28
+ /** Whether the manifest declares stream-heads at the version this package models. */
29
+ export declare function declaresStreamHeads(manifest: FeatureManifest | null): boolean;
30
+ /**
31
+ * Refuses a write to a store whose manifest declares an unsupported pair, or doesn't declare
32
+ * stream-heads, without declaring anything.
33
+ */
34
+ export declare function checkWritable(manifest: FeatureManifest | null): void;
35
+ /** The manifest with stream-heads declared and its version bumped: a first writer's declaration. */
36
+ export declare function withStreamHeads(manifest: FeatureManifest | null): FeatureManifest;
37
+ /** A manifest's stored JSON texts, as the marker row holds them. */
38
+ export interface ManifestTexts {
39
+ /** A JSON object, feature name to stored-format version, keys sorted. `{}` when empty. */
40
+ features: string;
41
+ /** A JSON array of entity types, sorted by UTF-8 bytes and deduplicated. `[]` when empty. */
42
+ historyDependent: string;
43
+ /** Like `historyDependent`. */
44
+ retention: string;
45
+ }
46
+ /** Encodes a manifest's declarable parts as the marker row stores them. */
47
+ export declare function encodeManifest(manifest: FeatureManifest): ManifestTexts;
48
+ /**
49
+ * Decodes a marker row's stored texts. An empty text is an empty map or set, as an absent
50
+ * attribute is.
51
+ */
52
+ export declare function decodeManifest(version: bigint, texts: ManifestTexts): FeatureManifest;
53
+ /** An entity-type set in its stored order: sorted by UTF-8 bytes and deduplicated. */
54
+ export declare function entityTypeSet(types: readonly string[]): string[];
55
+ //# sourceMappingURL=features.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,WAAW,EAGjB,MAAM,aAAa,CAAA;AAKpB,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,iBAAiB,CAAA;AAElD,+FAA+F;AAC/F,eAAO,MAAM,oBAAoB,IAAI,CAAA;AAErC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,WAAW,EAEnD,CAAA;AAKF,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9C,4FAA4F;IAC5F,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAA;IAC5C,gEAAgE;IAChE,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;CACtC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAWrE;AAED,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,GAAG,OAAO,CAE7E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAKpE;AAED,oGAAoG;AACpG,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,GAAG,eAAe,CAUjF;AAED,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,CAAA;IAChB,6FAA6F;IAC7F,gBAAgB,EAAE,MAAM,CAAA;IACxB,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,aAAa,CAMvE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,eAAe,CAOrF;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAMhE"}
@@ -0,0 +1,126 @@
1
+ // The feature manifest a store keeps on its SYSTEM#FEATURES marker row (storage format, "Feature
2
+ // marker"): the extensions it declares, each at a stored-format version, and the entity types
3
+ // declared history-dependent or retained. A writer refuses a store that declares a pair it doesn't
4
+ // model, and every writer requires stream-heads.
5
+ import { EvtError, StreamHeadsNotMigratedError, UnsupportedFeatureError, } from './errors.js';
6
+ import { DOCUMENT, int64, invalid } from './fields.js';
7
+ import { parseJson, stringifyJson } from './json.js';
8
+ import { compareUtf8 } from './utf8.js';
9
+ /** The feature every writer models and requires: per-stream head items (ADR 0007). */
10
+ export const STREAM_HEADS_FEATURE = 'stream-heads';
11
+ /** The stored-format version of {@link STREAM_HEADS_FEATURE} this package reads and writes. */
12
+ export const STREAM_HEADS_VERSION = 1;
13
+ /**
14
+ * The `(feature, stored-format version)` pairs this package models. The other features the
15
+ * storage format defines (`journal`, `journal-compaction`, `postgres-views`) are Rust-first, so a
16
+ * store that declares any of them is refused.
17
+ */
18
+ export const SUPPORTED_FEATURES = Object.freeze([
19
+ Object.freeze({ name: STREAM_HEADS_FEATURE, version: STREAM_HEADS_VERSION }),
20
+ ]);
21
+ // What validation reads. Private, so no caller can add a pair to it.
22
+ const supported = new Map(SUPPORTED_FEATURES.map((pair) => [pair.name, pair.version]));
23
+ /**
24
+ * Refuses a manifest that declares a pair this package doesn't model, listing every such pair,
25
+ * with an {@link UnsupportedFeatureError}.
26
+ */
27
+ export function checkSupported(manifest) {
28
+ const unsupported = [];
29
+ for (const [name, version] of sortedFeatures(manifest?.features ?? new Map())) {
30
+ if (supported.get(name) !== version) {
31
+ unsupported.push({ name, version });
32
+ }
33
+ }
34
+ if (unsupported.length > 0) {
35
+ throw new UnsupportedFeatureError(unsupported);
36
+ }
37
+ }
38
+ /** Whether the manifest declares stream-heads at the version this package models. */
39
+ export function declaresStreamHeads(manifest) {
40
+ return manifest?.features.get(STREAM_HEADS_FEATURE) === STREAM_HEADS_VERSION;
41
+ }
42
+ /**
43
+ * Refuses a write to a store whose manifest declares an unsupported pair, or doesn't declare
44
+ * stream-heads, without declaring anything.
45
+ */
46
+ export function checkWritable(manifest) {
47
+ checkSupported(manifest);
48
+ if (!declaresStreamHeads(manifest)) {
49
+ throw new StreamHeadsNotMigratedError();
50
+ }
51
+ }
52
+ /** The manifest with stream-heads declared and its version bumped: a first writer's declaration. */
53
+ export function withStreamHeads(manifest) {
54
+ const features = new Map(manifest?.features);
55
+ features.set(STREAM_HEADS_FEATURE, STREAM_HEADS_VERSION);
56
+ return {
57
+ version: (manifest?.version ?? 0n) + 1n,
58
+ features,
59
+ historyDependent: manifest?.historyDependent ?? [],
60
+ retention: manifest?.retention ?? [],
61
+ };
62
+ }
63
+ /** Encodes a manifest's declarable parts as the marker row stores them. */
64
+ export function encodeManifest(manifest) {
65
+ return {
66
+ features: stringifyJson(new Map(manifest.features)),
67
+ historyDependent: stringifyJson(entityTypeSet(manifest.historyDependent)),
68
+ retention: stringifyJson(entityTypeSet(manifest.retention)),
69
+ };
70
+ }
71
+ /**
72
+ * Decodes a marker row's stored texts. An empty text is an empty map or set, as an absent
73
+ * attribute is.
74
+ */
75
+ export function decodeManifest(version, texts) {
76
+ return {
77
+ version,
78
+ features: texts.features === '' ? new Map() : parseFeatures(texts.features),
79
+ historyDependent: parseEntityTypes(texts.historyDependent, 'historyDependent'),
80
+ retention: parseEntityTypes(texts.retention, 'retention'),
81
+ };
82
+ }
83
+ /** An entity-type set in its stored order: sorted by UTF-8 bytes and deduplicated. */
84
+ export function entityTypeSet(types) {
85
+ // A fresh array, sorted in place: ES2022 has no toSorted.
86
+ const set = Array.from(new Set(types));
87
+ set.sort(compareUtf8);
88
+ return set;
89
+ }
90
+ function parseFeatures(text) {
91
+ const parsed = parseStored(text, 'features');
92
+ if (!(parsed instanceof Map)) {
93
+ throw invalid('the feature manifest is not a JSON object');
94
+ }
95
+ // Go and Rust read a version as an int64. One past the safe integers is no version this
96
+ // package models, so rounding it changes only the refusal's text.
97
+ const features = new Map();
98
+ for (const [name, version] of parsed) {
99
+ features.set(name, Number(int64(version, `the feature manifest's ${name} version`)));
100
+ }
101
+ return features;
102
+ }
103
+ function parseEntityTypes(text, what) {
104
+ if (text.trim() === '') {
105
+ return [];
106
+ }
107
+ const parsed = parseStored(text, what);
108
+ if (!Array.isArray(parsed) || parsed.some((entry) => typeof entry !== 'string')) {
109
+ throw invalid(`the ${what} set is not a JSON array of strings`);
110
+ }
111
+ return entityTypeSet(parsed);
112
+ }
113
+ function parseStored(text, what) {
114
+ try {
115
+ return parseJson(text, DOCUMENT);
116
+ }
117
+ catch (error) {
118
+ throw new EvtError('invalidRecord', `the stored ${what} is not JSON`, { cause: error });
119
+ }
120
+ }
121
+ function sortedFeatures(features) {
122
+ const sorted = Array.from(features);
123
+ sorted.sort(([a], [b]) => compareUtf8(a, b));
124
+ return sorted;
125
+ }
126
+ //# sourceMappingURL=features.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features.js","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,8FAA8F;AAC9F,mGAAmG;AACnG,iDAAiD;AAEjD,OAAO,EACL,QAAQ,EAER,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,QAAQ,EAAE,KAAK,EAA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AI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE,CAAC;QAChF,MAAM,OAAO,CAAC,OAAO,IAAI,qCAAqC,CAAC,CAAA;IACjE,CAAC;IAED,OAAO,aAAa,CAAC,MAAkB,CAAC,CAAA;AAC1C,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAY;IAC7C,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,QAAQ,CAAC,eAAe,EAAE,cAAc,IAAI,cAAc,EAAE,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC,CAAA;IACvF,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,QAAqC;IAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACnC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAE5C,OAAO,MAAM,CAAA;AACf,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- export { type Aggregate, type AggregateDefinition, type Decision, type EventDefinition, type EventDefinitions, type EventOf, type Rejection, type Upcaster, defineAggregate, defineEvents, jsonUpcaster, } from './aggregate.js';
1
+ export { type Aggregate, type AggregateDefinition, type Decision, type EventDefinition, type EventDefinitions, type EventOf, type Projection, type Projector, type Rejection, type Upcaster, defineAggregate, defineEvents, jsonUpcaster, } from './aggregate.js';
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, ReplayError, ReservedEntityIdError, SequenceGapError, SnapshotError, StreamHeadDriftError, isConflict, isRetryable, } from './errors.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';
6
6
  export { type SerializedEvent, type SerializedSnapshot, decodeEvent, decodeSnapshot, encodeEvent, encodeSnapshot, eventId, } from './event.js';
7
+ export { type FeatureManifest, type ManifestTexts, STREAM_HEADS_FEATURE, STREAM_HEADS_VERSION, SUPPORTED_FEATURES, decodeManifest, encodeManifest, } from './features.js';
7
8
  export { JsonNumber, type JsonValue, parseJson, stringifyJson } from './json.js';
8
9
  export { type Metadata, type Origin, decodeMetadata, effectiveCausationId, emptyMetadata, encodeMetadata, } from './metadata.js';
9
- export type { CallOptions, Commit, NewSnapshot, Repository } from './repository.js';
10
+ export type { CallOptions, Commit, NewSnapshot, ProjectorGroup, Repository, StoreInitializer, } from './repository.js';
10
11
  export { DEFAULT_RETRY_POLICY, type RetryPolicy, retryDelay, } from './retry.js';
11
12
  export { MAX_COMMIT_ITEM_BYTES, snapshotCommitSize, snapshotEventsDue } from './snapshots.js';
12
13
  export { compareUtf8, utf8Length } from './utf8.js';
@@ -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,SAAS,EACd,KAAK,QAAQ,EACb,eAAe,EACf,YAAY,EACZ,YAAY,G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K,YAAY,GAClB,MAAM,YAAY,CAAA"}
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,YAAY,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,cAAc,EACd,UAAU,EACV,gBAAgB,GACjB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,oBAAoB,EACpB,KAAK,WAAW,EAChB,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,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,8 +5,9 @@ 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, ReplayError, ReservedEntityIdError, SequenceGapError, SnapshotError, StreamHeadDriftError, isConflict, isRetryable, } from './errors.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';
9
9
  export { decodeEvent, decodeSnapshot, encodeEvent, encodeSnapshot, eventId, } from './event.js';
10
+ export { STREAM_HEADS_FEATURE, STREAM_HEADS_VERSION, SUPPORTED_FEATURES, decodeManifest, encodeManifest, } from './features.js';
10
11
  export { JsonNumber, parseJson, stringifyJson } from './json.js';
11
12
  export { decodeMetadata, effectiveCausationId, emptyMetadata, encodeMetadata, } from './metadata.js';
12
13
  export { DEFAULT_RETRY_POLICY, retryDelay, } from './retry.js';
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,EASL,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,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,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,EAAC,UAAU,EAAkB,SAAS,EAAE,aAAa,EAAC,MAAM,WAAW,CAAA;AAC9E,OAAO,EAGL,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,cAAc,GACf,MAAM,eAAe,CAAA;AAEtB,OAAO,EACL,oBAAoB,EAEpB,UAAU,GACX,MAAM,YAAY,CAAA;AACnB,OAAO,EAAC,qBAAqB,EAAE,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,gBAAgB,CAAA;AAC3F,OAAO,EAAC,WAA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M,gBAAgB,CAAA;AAC3F,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,WAAW,CAAA;AACjD,OAAO,EACL,yBAAyB,EAKzB,KAAK,GAEN,MAAM,YAAY,CAAA"}
@@ -1,2 +1,2 @@
1
- export { type HeadFixtures, MemRepository, headFixtures } from './repository.js';
1
+ export { type ControlFixtures, type HeadFixtures, type ManifestDraft, MemRepository, type RebuildState, controlFixtures, headFixtures, } from './repository.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,YAAY,EAAE,aAAa,EAAE,YAAY,EAAC,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,YAAY,EACjB,eAAe,EACf,YAAY,GACb,MAAM,iBAAiB,CAAA"}
@@ -1,3 +1,3 @@
1
1
  // @photon-grove/evt/memory: the in-memory repository, for tests and local development.
2
- export { MemRepository, headFixtures } from './repository.js';
2
+ export { MemRepository, controlFixtures, headFixtures, } from './repository.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAEvF,OAAO,EAAoB,aAAa,EAAE,YAAY,EAAC,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAEvF,OAAO,EAIL,aAAa,EAEb,eAAe,EACf,YAAY,GACb,MAAM,iBAAiB,CAAA"}
@@ -1,14 +1,30 @@
1
1
  import type { SerializedEvent, SerializedSnapshot } from '../event.js';
2
- import { type CallOptions, type Commit, type Repository } from '../repository.js';
2
+ import { type FeatureManifest } from '../features.js';
3
+ import { type CallOptions, type Commit, type Repository, type StoreInitializer } from '../repository.js';
4
+ /** The state of the rebuild fence's two rows that a commit's lock check reads. */
5
+ export interface RebuildState {
6
+ /** The generation counter: odd while a rebuild holds the store or after a force-release. */
7
+ generation: bigint;
8
+ /**
9
+ * The lock row: a rebuild's lease, the item a force-release leaves in its place, or none. A
10
+ * commit is refused while either exists, and while the generation is odd.
11
+ */
12
+ lock: 'held' | 'forceReleased' | null;
13
+ }
3
14
  /**
4
15
  * An in-memory {@link Repository}. Every call copies what it stores and what it returns, so a
5
16
  * caller that changes an event after committing it, or one it read, changes nothing stored.
6
17
  *
7
18
  * Each call runs to completion before another starts, so concurrent commits to one stream behave
8
19
  * like racing writers on a live backend: one wins and the rest fail with a conflict.
20
+ *
21
+ * A fresh store is initialized by its first commit or snapshot write, which declares stream-heads
22
+ * on its feature manifest, so {@link initialize} is needed only where code treats every backend
23
+ * alike.
9
24
  */
10
- export declare class MemRepository implements Repository {
25
+ export declare class MemRepository implements Repository, StoreInitializer {
11
26
  #private;
27
+ initialize(options?: CallOptions): Promise<boolean>;
12
28
  commit(commit: Commit, options?: CallOptions): Promise<void>;
13
29
  events(entityId: string, options?: CallOptions): Promise<SerializedEvent[]>;
14
30
  eventsAfter(entityId: string, after: bigint, options?: CallOptions): Promise<SerializedEvent[]>;
@@ -31,4 +47,24 @@ export interface HeadFixtures {
31
47
  * drifts, and every later write to it fails.
32
48
  */
33
49
  export declare function headFixtures(repo: MemRepository): HeadFixtures;
50
+ /** A feature manifest's declarable parts, which a declaration changes in place. */
51
+ export interface ManifestDraft {
52
+ features: Map<string, number>;
53
+ historyDependent: string[];
54
+ retention: string[];
55
+ }
56
+ /** What a conformance suite needs to declare features and hold the rebuild lock. */
57
+ export interface ControlFixtures {
58
+ /** The stored manifest, or null when the store has no marker row. */
59
+ manifest(): FeatureManifest | null;
60
+ /** Changes the manifest in one declaration, bumping its version by one, and returns it. */
61
+ declare(change: (draft: ManifestDraft) => void): FeatureManifest;
62
+ /** Sets the rebuild fence's rows, as a rebuild's lifecycle would. */
63
+ setRebuild(state: RebuildState): void;
64
+ }
65
+ /**
66
+ * Hooks that change a repository's control rows, for conformance suites only. A declaration may
67
+ * declare features this package doesn't model, which then refuse every write.
68
+ */
69
+ export declare function controlFixtures(repo: MemRepository): ControlFixtures;
34
70
  //# sourceMappingURL=repository.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/memory/repository.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAC,eAAe,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAA;AAGpE,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,UAAU,EAKhB,MAAM,kBAAkB,CAAA;AAazB;;;;;;GAMG;AACH,qBAAa,aAAc,YAAW,UAAU;;IAGxC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCjE;IAEK,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,eAAe,EAAE,CAAC,CAO5B;IAEK,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAU3F;IAEK,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAK1F;IAEK,WAAW,CAAC,QAAQ,EAAE,kBAAk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