effect-dynamodb 1.45.0 → 1.46.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.
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @internal A structural fingerprint of a value, for `commandHandler`'s
3
+ * opt-in `checkStateUse` (#290). It is taken of a state before `decide` runs
4
+ * and again after, so a change made to the object `decide` was given is found
5
+ * and named by its path.
6
+ *
7
+ * A fingerprint is a pre-order list of entries, one per value reached. Each
8
+ * entry holds its path, its kind, an identity compared with `Object.is`, and a
9
+ * detail string. Two fingerprints of an unchanged value are equal entry for
10
+ * entry, and the first entry that differs is the first change met in walk
11
+ * order: a container's own entry (its keys, length or size) comes before its
12
+ * contents, so an added or removed member is reported at the container.
13
+ *
14
+ * What is read:
15
+ * - an object's prototype and its own enumerable string-keyed properties, and
16
+ * an array's elements, by their property descriptors: an accessor is
17
+ * recorded by its getter, never called. Symbol-keyed and non-enumerable
18
+ * properties, where Effect keeps its caches (`DateTime`'s parts, a hash),
19
+ * are not read;
20
+ * - `Map`, `Set`, `HashMap` and `HashSet` by iteration, and `Chunk` by index
21
+ * (`Chunk.getUnsafe`, which does not build the array form a `Chunk` caches
22
+ * in an own field), so its fields are not read;
23
+ * - `Date`, `DateTime` and `BigDecimal` by value (a `BigDecimal` from its
24
+ * digits and scale, without the normal form it caches in an own field),
25
+ * typed arrays and `ArrayBuffer`s by their bytes, `Option` and `Result` by
26
+ * tag and contents;
27
+ * - functions and symbols by identity.
28
+ *
29
+ * Nothing is written, so a frozen value reads as any other. A container
30
+ * (an array, a `Map` or `Set`, a `HashMap`, `HashSet` or `Chunk`, any other
31
+ * object) reached a second time, through a cycle or a second path to the same
32
+ * object, is recorded by the path it was first reached at and not walked
33
+ * again, so a fingerprint grows with the number of distinct values, not paths.
34
+ * Replacing such a reference with an equal copy is a change.
35
+ */
36
+ /** @internal One value reached by the walk. */
37
+ export interface Entry {
38
+ readonly path: string;
39
+ readonly kind: string;
40
+ /** Compared with `Object.is`: a primitive itself, a prototype, a function. */
41
+ readonly identity: unknown;
42
+ readonly detail: string;
43
+ }
44
+ /** @internal */
45
+ export type Fingerprint = ReadonlyArray<Entry>;
46
+ /** @internal The first change between two fingerprints of one value. */
47
+ export interface Difference {
48
+ /** `""` for the value itself. */
49
+ readonly path: string;
50
+ readonly before: string;
51
+ readonly after: string;
52
+ }
53
+ /** @internal Take the fingerprint of `value`. */
54
+ export declare const of: (value: unknown) => Fingerprint;
55
+ /** @internal The first entry at which `after` differs from `before`, if any. */
56
+ export declare const firstDifference: (before: Fingerprint, after: Fingerprint) => Difference | undefined;
57
+ /** @internal `innings[1].overs`, or `the state itself` for the root. */
58
+ export declare const formatPath: (path: string) => string;
59
+ //# sourceMappingURL=StateFingerprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateFingerprint.d.ts","sourceRoot":"","sources":["../../src/internal/StateFingerprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAIH,+CAA+C;AAC/C,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,gBAAgB;AAChB,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;AAE9C,wEAAwE;AACxE,MAAM,WAAW,UAAU;IACzB,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,iDAAiD;AACjD,eAAO,MAAM,EAAE,GAAI,OAAO,OAAO,KAAG,WAInC,CAAA;AAED,gFAAgF;AAChF,eAAO,MAAM,eAAe,GAC1B,QAAQ,WAAW,EACnB,OAAO,WAAW,KACjB,UAAU,GAAG,SAqBf,CAAA;AAED,wEAAwE;AACxE,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,MAAmD,CAAA"}
@@ -0,0 +1,332 @@
1
+ /**
2
+ * @internal A structural fingerprint of a value, for `commandHandler`'s
3
+ * opt-in `checkStateUse` (#290). It is taken of a state before `decide` runs
4
+ * and again after, so a change made to the object `decide` was given is found
5
+ * and named by its path.
6
+ *
7
+ * A fingerprint is a pre-order list of entries, one per value reached. Each
8
+ * entry holds its path, its kind, an identity compared with `Object.is`, and a
9
+ * detail string. Two fingerprints of an unchanged value are equal entry for
10
+ * entry, and the first entry that differs is the first change met in walk
11
+ * order: a container's own entry (its keys, length or size) comes before its
12
+ * contents, so an added or removed member is reported at the container.
13
+ *
14
+ * What is read:
15
+ * - an object's prototype and its own enumerable string-keyed properties, and
16
+ * an array's elements, by their property descriptors: an accessor is
17
+ * recorded by its getter, never called. Symbol-keyed and non-enumerable
18
+ * properties, where Effect keeps its caches (`DateTime`'s parts, a hash),
19
+ * are not read;
20
+ * - `Map`, `Set`, `HashMap` and `HashSet` by iteration, and `Chunk` by index
21
+ * (`Chunk.getUnsafe`, which does not build the array form a `Chunk` caches
22
+ * in an own field), so its fields are not read;
23
+ * - `Date`, `DateTime` and `BigDecimal` by value (a `BigDecimal` from its
24
+ * digits and scale, without the normal form it caches in an own field),
25
+ * typed arrays and `ArrayBuffer`s by their bytes, `Option` and `Result` by
26
+ * tag and contents;
27
+ * - functions and symbols by identity.
28
+ *
29
+ * Nothing is written, so a frozen value reads as any other. A container
30
+ * (an array, a `Map` or `Set`, a `HashMap`, `HashSet` or `Chunk`, any other
31
+ * object) reached a second time, through a cycle or a second path to the same
32
+ * object, is recorded by the path it was first reached at and not walked
33
+ * again, so a fingerprint grows with the number of distinct values, not paths.
34
+ * Replacing such a reference with an equal copy is a change.
35
+ */
36
+ import { BigDecimal, Chunk, DateTime, HashMap, HashSet, Option, Result } from "effect";
37
+ /** @internal Take the fingerprint of `value`. */
38
+ export const of = (value) => {
39
+ const entries = [];
40
+ walk(value, "", new Map(), entries);
41
+ return entries;
42
+ };
43
+ /** @internal The first entry at which `after` differs from `before`, if any. */
44
+ export const firstDifference = (before, after) => {
45
+ const length = Math.max(before.length, after.length);
46
+ for (let i = 0; i < length; i++) {
47
+ const was = before[i];
48
+ const now = after[i];
49
+ if (was === undefined ||
50
+ now === undefined ||
51
+ was.path !== now.path ||
52
+ was.kind !== now.kind ||
53
+ !Object.is(was.identity, now.identity) ||
54
+ was.detail !== now.detail) {
55
+ return {
56
+ path: (was ?? now)?.path ?? "",
57
+ before: describe(was),
58
+ after: describe(now),
59
+ };
60
+ }
61
+ }
62
+ return undefined;
63
+ };
64
+ /** @internal `innings[1].overs`, or `the state itself` for the root. */
65
+ export const formatPath = (path) => (path === "" ? "the state itself" : path);
66
+ // ---------------------------------------------------------------------------
67
+ // The walk
68
+ // ---------------------------------------------------------------------------
69
+ const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
70
+ const child = (path, suffix) => path === "" && suffix.startsWith(".") ? suffix.slice(1) : `${path}${suffix}`;
71
+ const propertyPath = (path, key) => IDENTIFIER.test(key) ? child(path, `.${key}`) : `${path}[${JSON.stringify(key)}]`;
72
+ const isPrimitive = (value) => value === null || (typeof value !== "object" && typeof value !== "function");
73
+ const MAX_TEXT = 40;
74
+ const truncate = (text) => text.length > MAX_TEXT ? `${text.slice(0, MAX_TEXT)}…` : text;
75
+ /** A primitive as it reads in a message. */
76
+ const primitiveLabel = (value) => typeof value === "string" ? JSON.stringify(truncate(value)) : keyLabel(value);
77
+ /** A primitive in full, as a path names a `Map` key. */
78
+ const keyLabel = (value) => {
79
+ switch (typeof value) {
80
+ case "string":
81
+ return JSON.stringify(value);
82
+ case "bigint":
83
+ return `${value}n`;
84
+ case "symbol":
85
+ return value.toString();
86
+ default:
87
+ return String(value);
88
+ }
89
+ };
90
+ const hex = (bytes) => {
91
+ let text = "";
92
+ for (const byte of bytes)
93
+ text += byte.toString(16).padStart(2, "0");
94
+ return text;
95
+ };
96
+ /** The decimal text of a `BigDecimal`, read from its fields without normalising it. */
97
+ const decimalText = (value) => {
98
+ let digits = value.value;
99
+ let scale = value.scale;
100
+ if (digits === 0n)
101
+ return "0";
102
+ while (digits % 10n === 0n) {
103
+ digits /= 10n;
104
+ scale--;
105
+ }
106
+ if (scale <= 0)
107
+ return scale === 0 ? `${digits}` : `${digits}e${-scale}`;
108
+ const negative = digits < 0n;
109
+ const text = (negative ? -digits : digits).toString().padStart(scale + 1, "0");
110
+ return `${negative ? "-" : ""}${text.slice(0, -scale)}.${text.slice(-scale)}`;
111
+ };
112
+ const walk = (value, path, seen, out) => {
113
+ if (value === null) {
114
+ out.push({ path, kind: "null", identity: null, detail: "" });
115
+ return;
116
+ }
117
+ if (typeof value === "function") {
118
+ out.push({ path, kind: "function", identity: value, detail: "" });
119
+ return;
120
+ }
121
+ if (typeof value !== "object") {
122
+ out.push({ path, kind: typeof value, identity: value, detail: "" });
123
+ return;
124
+ }
125
+ walkObject(value, path, seen, out);
126
+ };
127
+ /** A property or an element, by its descriptor: an accessor is never called. */
128
+ const walkProperty = (owner, key, at, seen, out) => {
129
+ const descriptor = Object.getOwnPropertyDescriptor(owner, key);
130
+ if (descriptor === undefined) {
131
+ // An array hole, or gone between `Object.keys` and here (a proxy).
132
+ out.push({ path: at, kind: "absent", identity: undefined, detail: "" });
133
+ }
134
+ else if ("value" in descriptor) {
135
+ walk(descriptor.value, at, seen, out);
136
+ }
137
+ else {
138
+ out.push({ path: at, kind: "accessor", identity: descriptor.get, detail: "" });
139
+ }
140
+ };
141
+ const walkIterable = (items, path, seen, out) => {
142
+ let i = 0;
143
+ for (const item of items) {
144
+ walk(item, `${path}[${i}]`, seen, out);
145
+ i++;
146
+ }
147
+ };
148
+ const walkEntries = (entries, path, seen, out) => {
149
+ let i = 0;
150
+ for (const [key, member] of entries) {
151
+ if (isPrimitive(key) && typeof key !== "symbol") {
152
+ walk(member, child(path, `.get(${keyLabel(key)})`), seen, out);
153
+ }
154
+ else {
155
+ walk(key, child(path, `.keys()[${i}]`), seen, out);
156
+ walk(member, child(path, `.values()[${i}]`), seen, out);
157
+ }
158
+ i++;
159
+ }
160
+ };
161
+ const walkObject = (value, path, seen, out) => {
162
+ if (value instanceof Date) {
163
+ const time = value.getTime();
164
+ const detail = Number.isNaN(time) ? "Invalid Date" : new Date(time).toISOString();
165
+ out.push({ path, kind: "Date", identity: undefined, detail });
166
+ return;
167
+ }
168
+ if (DateTime.isDateTime(value)) {
169
+ const zone = DateTime.isZoned(value) ? ` ${DateTime.zoneToString(value.zone)}` : "";
170
+ out.push({
171
+ path,
172
+ kind: "DateTime",
173
+ identity: undefined,
174
+ detail: `${DateTime.formatIso(value)}${zone}`,
175
+ });
176
+ return;
177
+ }
178
+ if (BigDecimal.isBigDecimal(value)) {
179
+ out.push({ path, kind: "BigDecimal", identity: undefined, detail: decimalText(value) });
180
+ return;
181
+ }
182
+ if (Option.isOption(value)) {
183
+ out.push({ path, kind: "Option", identity: undefined, detail: value._tag });
184
+ if (Option.isSome(value))
185
+ walk(value.value, child(path, ".value"), seen, out);
186
+ return;
187
+ }
188
+ if (Result.isResult(value)) {
189
+ out.push({ path, kind: "Result", identity: undefined, detail: value._tag });
190
+ if (Result.isSuccess(value))
191
+ walk(value.success, child(path, ".success"), seen, out);
192
+ else
193
+ walk(value.failure, child(path, ".failure"), seen, out);
194
+ return;
195
+ }
196
+ if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {
197
+ const bytes = ArrayBuffer.isView(value)
198
+ ? new Uint8Array(value.buffer, value.byteOffset, value.byteLength)
199
+ : new Uint8Array(value);
200
+ out.push({
201
+ path,
202
+ kind: value.constructor?.name ?? "bytes",
203
+ identity: undefined,
204
+ detail: hex(bytes),
205
+ });
206
+ return;
207
+ }
208
+ // A container: walked once, however many paths reach it.
209
+ const first = seen.get(value);
210
+ if (first !== undefined) {
211
+ out.push({ path, kind: "seen", identity: undefined, detail: first });
212
+ return;
213
+ }
214
+ seen.set(value, path);
215
+ if (Array.isArray(value)) {
216
+ out.push({
217
+ path,
218
+ kind: "Array",
219
+ identity: Object.getPrototypeOf(value),
220
+ detail: `length ${value.length}`,
221
+ });
222
+ for (let i = 0; i < value.length; i++)
223
+ walkProperty(value, String(i), `${path}[${i}]`, seen, out);
224
+ return;
225
+ }
226
+ if (value instanceof Map) {
227
+ out.push({
228
+ path,
229
+ kind: "Map",
230
+ identity: Object.getPrototypeOf(value),
231
+ detail: `size ${value.size}`,
232
+ });
233
+ walkEntries(value, path, seen, out);
234
+ return;
235
+ }
236
+ if (HashMap.isHashMap(value)) {
237
+ out.push({ path, kind: "HashMap", identity: undefined, detail: `size ${HashMap.size(value)}` });
238
+ walkEntries(value, path, seen, out);
239
+ return;
240
+ }
241
+ if (value instanceof Set) {
242
+ out.push({
243
+ path,
244
+ kind: "Set",
245
+ identity: Object.getPrototypeOf(value),
246
+ detail: `size ${value.size}`,
247
+ });
248
+ walkIterable(value, path, seen, out);
249
+ return;
250
+ }
251
+ if (HashSet.isHashSet(value)) {
252
+ out.push({ path, kind: "HashSet", identity: undefined, detail: `size ${HashSet.size(value)}` });
253
+ walkIterable(value, path, seen, out);
254
+ return;
255
+ }
256
+ if (Chunk.isChunk(value)) {
257
+ const length = Chunk.size(value);
258
+ out.push({ path, kind: "Chunk", identity: undefined, detail: `length ${length}` });
259
+ for (let i = 0; i < length; i++)
260
+ walk(Chunk.getUnsafe(value, i), `${path}[${i}]`, seen, out);
261
+ return;
262
+ }
263
+ const keys = Object.keys(value);
264
+ out.push({
265
+ path,
266
+ kind: "object",
267
+ identity: Object.getPrototypeOf(value),
268
+ detail: JSON.stringify(keys),
269
+ });
270
+ for (const key of keys)
271
+ walkProperty(value, key, propertyPath(path, key), seen, out);
272
+ };
273
+ // ---------------------------------------------------------------------------
274
+ // Describing an entry in a message
275
+ // ---------------------------------------------------------------------------
276
+ const constructorName = (prototype) => {
277
+ if (prototype === null)
278
+ return "null-prototype object";
279
+ const name = prototype
280
+ ?.constructor?.name;
281
+ return typeof name === "string" && name !== "" && name !== "Object" ? name : undefined;
282
+ };
283
+ const describe = (entry) => {
284
+ if (entry === undefined)
285
+ return "absent";
286
+ switch (entry.kind) {
287
+ case "null":
288
+ return "null";
289
+ case "undefined":
290
+ case "boolean":
291
+ case "number":
292
+ case "string":
293
+ case "bigint":
294
+ case "symbol":
295
+ return primitiveLabel(entry.identity);
296
+ case "function": {
297
+ const name = entry.identity.name;
298
+ return typeof name === "string" && name !== "" ? `function ${name}` : "a function";
299
+ }
300
+ case "seen":
301
+ return entry.detail === ""
302
+ ? "a reference to the state itself"
303
+ : `the same object as at ${truncate(entry.detail)}`;
304
+ case "accessor":
305
+ return "an accessor property";
306
+ case "absent":
307
+ return "absent";
308
+ case "object": {
309
+ const keys = JSON.parse(entry.detail);
310
+ const name = constructorName(entry.identity);
311
+ return truncate(`${name === undefined ? "" : `${name} `}{ ${keys.join(", ")} }`);
312
+ }
313
+ case "Array":
314
+ case "Map":
315
+ case "Set":
316
+ case "HashMap":
317
+ case "HashSet":
318
+ case "Chunk":
319
+ return `${entry.kind} of ${entry.detail}`;
320
+ case "Option":
321
+ case "Result":
322
+ return `${entry.kind}.${entry.detail}`;
323
+ case "Date":
324
+ case "DateTime":
325
+ case "BigDecimal":
326
+ return `${entry.kind}(${truncate(entry.detail)})`;
327
+ default:
328
+ // Typed arrays and ArrayBuffers: the kind is the constructor's name.
329
+ return `${entry.kind} of ${entry.detail.length / 2} bytes`;
330
+ }
331
+ };
332
+ //# sourceMappingURL=StateFingerprint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateFingerprint.js","sourceRoot":"","sources":["../../src/internal/StateFingerprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE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D,KAAK,UAAU;YACb,OAAO,sBAAsB,CAAA;QAC/B,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAA;QACjB,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAA0B,CAAA;YAC9D,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;YAC5C,OAAO,QAAQ,CAAC,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClF,CAAC;QACD,KAAK,OAAO,CAAC;QACb,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,CAAC;QACX,KAAK,SAAS,CAAC;QACf,KAAK,SAAS,CAAC;QACf,KAAK,OAAO;YACV,OAAO,GAAG,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,MAAM,EAAE,CAAA;QAC3C,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,CAAA;QACxC,KAAK,MAAM,CAAC;QACZ,KAAK,UAAU,CAAC;QAChB,KAAK,YAAY;YACf,OAAO,GAAG,KAAK,CAAC,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAA;QACnD;YACE,qEAAqE;YACrE,OAAO,GAAG,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAA;IAC9D,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @internal `commandHandler`'s opt-in `checkStateUse` (#290): the two checks
3
+ * that the state contract holds for one command.
4
+ *
5
+ * - **`decide` only reads its state (EDD-9183).** The state is fingerprinted
6
+ * before `decide` is called and again once it has finished (succeeded or
7
+ * failed with its own error), and a difference is a defect naming the stream,
8
+ * the command and the first changed path. A defect or an interruption of
9
+ * `decide` passes through unchecked.
10
+ * - **A shared `initialState` stays as declared (EDD-9184).** When
11
+ * `decider.initialState` reads as the same object twice (a value, not a
12
+ * getter), it is fingerprinted when an attempt starts and checked after the
13
+ * load and after the new events are folded, before the append: an `evolve`
14
+ * that changes its state in place changes this object, and every later new
15
+ * stream would start from it.
16
+ *
17
+ * With an encoder (the stream's snapshot state schema), a state is compared as
18
+ * the snapshot would store it, so a value is compared by what it means, not by
19
+ * the fields a class keeps. The plain walk is the fallback, for a stream
20
+ * without a snapshot schema or a state that does not encode on either side.
21
+ *
22
+ * Nothing here runs unless the option is on: `commandHandler` does not build
23
+ * a check otherwise.
24
+ */
25
+ import { Effect } from "effect";
26
+ /** @internal Encodes a state as the stream's snapshot would store it. */
27
+ export type StateEncoder = (state: unknown) => Effect.Effect<unknown, unknown>;
28
+ /** @internal What a defect names: the stream and the command. */
29
+ export interface Subject {
30
+ readonly streamName: string;
31
+ readonly streamId: string;
32
+ readonly command: unknown;
33
+ }
34
+ /** @internal A shared `initialState` object, watched over one attempt. */
35
+ export interface InitialStateWatch {
36
+ readonly object: object;
37
+ /** Dies with EDD-9184 when the object changed since the watch began. */
38
+ readonly check: (moment: "load" | "fold") => Effect.Effect<void>;
39
+ }
40
+ /** @internal */
41
+ export interface StateUseCheck {
42
+ /**
43
+ * Run `decide` (the thunk calls it, so a change made before its `Effect` is
44
+ * returned is seen too) and die with EDD-9183 when `state` changed.
45
+ */
46
+ readonly decide: <A, E>(subject: Subject, state: unknown, initial: InitialStateWatch | undefined, run: () => Effect.Effect<A, E>) => Effect.Effect<A, E>;
47
+ /**
48
+ * Begin watching `decider.initialState` (`read` reads the property), or
49
+ * `undefined` when it is a getter or not an object.
50
+ */
51
+ readonly watchInitialState: (subject: Subject, read: () => unknown) => Effect.Effect<InitialStateWatch | undefined>;
52
+ }
53
+ /** @internal */
54
+ export declare const make: (encode: StateEncoder | undefined) => StateUseCheck;
55
+ //# sourceMappingURL=StateUseCheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateUseCheck.d.ts","sourceRoot":"","sources":["../../src/internal/StateUseCheck.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAGvC,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAE9E,iEAAiE;AACjE,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CACjE;AAED,gBAAgB;AAChB,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EACpB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,GAAG,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,EAAE,CAC1B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,OAAO,KAChB,MAAM,CAAC,MAAM,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAA;CAClD;AAQD,gBAAgB;AAChB,eAAO,MAAM,IAAI,GAAI,QAAQ,YAAY,GAAG,SAAS,KAAG,aA+DvD,CAAA"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @internal `commandHandler`'s opt-in `checkStateUse` (#290): the two checks
3
+ * that the state contract holds for one command.
4
+ *
5
+ * - **`decide` only reads its state (EDD-9183).** The state is fingerprinted
6
+ * before `decide` is called and again once it has finished (succeeded or
7
+ * failed with its own error), and a difference is a defect naming the stream,
8
+ * the command and the first changed path. A defect or an interruption of
9
+ * `decide` passes through unchecked.
10
+ * - **A shared `initialState` stays as declared (EDD-9184).** When
11
+ * `decider.initialState` reads as the same object twice (a value, not a
12
+ * getter), it is fingerprinted when an attempt starts and checked after the
13
+ * load and after the new events are folded, before the append: an `evolve`
14
+ * that changes its state in place changes this object, and every later new
15
+ * stream would start from it.
16
+ *
17
+ * With an encoder (the stream's snapshot state schema), a state is compared as
18
+ * the snapshot would store it, so a value is compared by what it means, not by
19
+ * the fields a class keeps. The plain walk is the fallback, for a stream
20
+ * without a snapshot schema or a state that does not encode on either side.
21
+ *
22
+ * Nothing here runs unless the option is on: `commandHandler` does not build
23
+ * a check otherwise.
24
+ */
25
+ import { Effect, Result } from "effect";
26
+ import * as StateFingerprint from "./StateFingerprint.js";
27
+ /** @internal */
28
+ export const make = (encode) => {
29
+ const take = (state) => {
30
+ const raw = Effect.sync(() => StateFingerprint.of(state));
31
+ if (encode === undefined)
32
+ return Effect.map(raw, (fingerprint) => ({ raw: fingerprint, encoded: undefined }));
33
+ // Encode first: an encoding can fill a cache the state keeps (a getter
34
+ // that memoises), and the walk must see that on both sides, or the check's
35
+ // own encoding would be reported as a change `decide` made.
36
+ return Effect.flatMap(Effect.result(encode(state)), (encoded) => Effect.map(raw, (fingerprint) => ({
37
+ raw: fingerprint,
38
+ encoded: Result.isSuccess(encoded) ? StateFingerprint.of(encoded.success) : undefined,
39
+ })));
40
+ };
41
+ const compare = (before, after) => before.encoded !== undefined && after.encoded !== undefined
42
+ ? StateFingerprint.firstDifference(before.encoded, after.encoded)
43
+ : StateFingerprint.firstDifference(before.raw, after.raw);
44
+ const decide = (subject, state, initial, run) => Effect.gen(function* () {
45
+ const before = yield* take(state);
46
+ const result = yield* Effect.result(Effect.suspend(run));
47
+ const difference = compare(before, yield* take(state));
48
+ if (difference !== undefined) {
49
+ const shared = initial !== undefined && initial.object === state;
50
+ return yield* Effect.die(new Error(decideMessage(subject, difference, shared)));
51
+ }
52
+ return Result.isSuccess(result) ? result.success : yield* Effect.fail(result.failure);
53
+ });
54
+ const watchInitialState = (subject, read) => Effect.gen(function* () {
55
+ const object = read();
56
+ if (object === null || typeof object !== "object")
57
+ return undefined;
58
+ // A getter returns a fresh value on every read, so no change can carry
59
+ // over to another stream: only a shared object needs watching.
60
+ if (read() !== object)
61
+ return undefined;
62
+ const before = yield* take(object);
63
+ const watch = {
64
+ object,
65
+ check: (moment) => Effect.gen(function* () {
66
+ const difference = compare(before, yield* take(object));
67
+ if (difference !== undefined) {
68
+ return yield* Effect.die(new Error(initialStateMessage(subject, difference, moment)));
69
+ }
70
+ }),
71
+ };
72
+ return watch;
73
+ });
74
+ return { decide, watchInitialState };
75
+ };
76
+ // ---------------------------------------------------------------------------
77
+ // Messages
78
+ // ---------------------------------------------------------------------------
79
+ const commandLabel = (command) => {
80
+ if (command !== null && typeof command === "object") {
81
+ const tag = command._tag;
82
+ return typeof tag === "string" ? `command "${tag}"` : "an untagged command";
83
+ }
84
+ if (typeof command === "string") {
85
+ return `command ${JSON.stringify(command.length > 40 ? `${command.slice(0, 40)}…` : command)}`;
86
+ }
87
+ return typeof command === "function" ? "a function command" : `command ${String(command)}`;
88
+ };
89
+ const where = (difference) => `at ${StateFingerprint.formatPath(difference.path)} (was ${difference.before}, now ${difference.after})`;
90
+ const subjectLabel = (subject) => `EventStream "${subject.streamName}" (${subject.streamId}), ${commandLabel(subject.command)}`;
91
+ const decideMessage = (subject, difference, shared) => `[EDD-9183] ${subjectLabel(subject)}: decide changed the state it was given, ${where(difference)}. ` +
92
+ "checkStateUse checks that decide only reads its state: the state is handed to decide as is, " +
93
+ "not copied, and the fold of the new events starts from that same object, so the change " +
94
+ "would be in the state the handler returns, projects and snapshots. Copy the state in decide " +
95
+ "before changing it." +
96
+ (shared
97
+ ? " This state is decider.initialState itself, so every later new stream would start from " +
98
+ "the change too."
99
+ : "");
100
+ const initialStateMessage = (subject, difference, moment) => `[EDD-9184] ${subjectLabel(subject)}: decider.initialState is one shared object, and it ` +
101
+ `changed while this command ran, ${where(difference)}, ` +
102
+ (moment === "load"
103
+ ? "while the stored events were folded on load. "
104
+ : "while the new events were folded. ") +
105
+ "An evolve that changes its state in place changes this object when a fold starts from it, " +
106
+ "so every later new stream would start from the change. Declare initialState as a getter " +
107
+ "that returns a fresh value (get initialState() { return { … } }), or have evolve return " +
108
+ "new state.";
109
+ //# sourceMappingURL=StateUseCheck.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateUseCheck.js","sourceRoot":"","sources":["../../src/internal/StateUseCheck.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AA+CzD,gBAAgB;AAChB,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,MAAgC,EAAiB,EAAE;IACtE,MAAM,IAAI,GAAG,CAAC,KAAc,EAAwB,EAAE;QACpD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;QACzD,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,EAAE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MAAM,OAAO,CAAC,QAAQ,MAAM,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAA;AAE/F,MAAM,aAAa,GAAG,CACpB,OAAgB,EAChB,UAAuC,EACvC,MAAe,EACP,EAAE,CACV,cAAc,YAAY,CAAC,OAAO,CAAC,4CAA4C,KAAK,CAAC,UAAU,CAAC,IAAI;IACpG,8FAA8F;IAC9F,yFAAyF;IACzF,8FAA8F;IAC9F,qBAAqB;IACrB,CAAC,MAAM;QACL,CAAC,CAAC,yFAAyF;YACzF,iBAAiB;QACnB,CAAC,CAAC,EAAE,CAAC,CAAA;AAET,MAAM,mBAAmB,GAAG,CAC1B,OAAgB,EAChB,UAAuC,EACvC,MAAuB,EACf,EAAE,CACV,cAAc,YAAY,CAAC,OAAO,CAAC,sDAAsD;IACzF,mCAAmC,KAAK,CAAC,UAAU,CAAC,IAAI;IACxD,CAAC,MAAM,KAAK,MAAM;QAChB,CAAC,CAAC,+CAA+C;QACjD,CAAC,CAAC,oCAAoC,CAAC;IACzC,4FAA4F;IAC5F,0FAA0F;IAC1F,0FAA0F;IAC1F,YAAY,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-dynamodb",
3
- "version": "1.45.0",
3
+ "version": "1.46.0",
4
4
  "description": "Effect TS ORM for DynamoDB — schema-driven entity modeling, single-table design, composite keys, transactions, and Stream-based pagination",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -60,7 +60,7 @@
60
60
  "dependencies": {
61
61
  "@aws-sdk/client-dynamodb": "^3.1104.0",
62
62
  "@aws-sdk/util-dynamodb": "^3.700.0",
63
- "@effect-dynamodb/schema": "1.45.0"
63
+ "@effect-dynamodb/schema": "1.46.0"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@aws-sdk/client-dynamodb-streams": "^3.1104.0",