effect-dynamodb 1.39.0 → 1.40.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/dist/Aggregate.d.ts +119 -15
- package/dist/Aggregate.d.ts.map +1 -1
- package/dist/Aggregate.js +2021 -379
- package/dist/Aggregate.js.map +1 -1
- package/dist/Batch.d.ts +9 -5
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +28 -44
- package/dist/Batch.js.map +1 -1
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +12 -5
- package/dist/Collection.js.map +1 -1
- package/dist/ConsumedCapacity.js +1 -1
- package/dist/ConsumedCapacity.js.map +1 -1
- package/dist/DynamoClient.d.ts +22 -8
- package/dist/DynamoClient.d.ts.map +1 -1
- package/dist/DynamoClient.js +243 -87
- package/dist/DynamoClient.js.map +1 -1
- package/dist/Entity.d.ts +87 -22
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +2750 -514
- package/dist/Entity.js.map +1 -1
- package/dist/EventStore.d.ts +37 -15
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +215 -79
- package/dist/EventStore.js.map +1 -1
- package/dist/Marshaller.d.ts +39 -9
- package/dist/Marshaller.d.ts.map +1 -1
- package/dist/Marshaller.js +421 -70
- package/dist/Marshaller.js.map +1 -1
- package/dist/Query.d.ts +23 -0
- package/dist/Query.d.ts.map +1 -1
- package/dist/Query.js +49 -3
- package/dist/Query.js.map +1 -1
- package/dist/StorageEncoding.d.ts +7 -1
- package/dist/StorageEncoding.d.ts.map +1 -1
- package/dist/StorageEncoding.js +8 -2
- package/dist/StorageEncoding.js.map +1 -1
- package/dist/Table.d.ts +69 -8
- package/dist/Table.d.ts.map +1 -1
- package/dist/Transaction.d.ts.map +1 -1
- package/dist/Transaction.js +10 -4
- package/dist/Transaction.js.map +1 -1
- package/dist/change-feed/ChangeFeed.d.ts +8 -3
- package/dist/change-feed/ChangeFeed.d.ts.map +1 -1
- package/dist/change-feed/ChangeFeed.js +76 -9
- package/dist/change-feed/ChangeFeed.js.map +1 -1
- package/dist/change-feed/CheckpointStore.js +1 -1
- package/dist/change-feed/CheckpointStore.js.map +1 -1
- package/dist/change-feed/DynamoStreamsClient.d.ts +12 -5
- package/dist/change-feed/DynamoStreamsClient.d.ts.map +1 -1
- package/dist/change-feed/DynamoStreamsClient.js +15 -9
- package/dist/change-feed/DynamoStreamsClient.js.map +1 -1
- package/dist/internal/BoundCrud.d.ts +40 -32
- package/dist/internal/BoundCrud.d.ts.map +1 -1
- package/dist/internal/BoundCrud.js.map +1 -1
- package/dist/internal/BoundQuery.d.ts +1 -1
- package/dist/internal/BoundQuery.d.ts.map +1 -1
- package/dist/internal/BoundQuery.js +22 -12
- package/dist/internal/BoundQuery.js.map +1 -1
- package/dist/internal/BoundVectorQuery.d.ts.map +1 -1
- package/dist/internal/BoundVectorQuery.js +2 -1
- package/dist/internal/BoundVectorQuery.js.map +1 -1
- package/dist/internal/Capacity.d.ts +44 -4
- package/dist/internal/Capacity.d.ts.map +1 -1
- package/dist/internal/Capacity.js +89 -15
- package/dist/internal/Capacity.js.map +1 -1
- package/dist/internal/ClientOptions.d.ts +72 -0
- package/dist/internal/ClientOptions.d.ts.map +1 -0
- package/dist/internal/ClientOptions.js +79 -0
- package/dist/internal/ClientOptions.js.map +1 -0
- package/dist/internal/Cursor.d.ts +19 -10
- package/dist/internal/Cursor.d.ts.map +1 -1
- package/dist/internal/Cursor.js +25 -10
- package/dist/internal/Cursor.js.map +1 -1
- package/dist/internal/EntityCombinators.d.ts +22 -7
- package/dist/internal/EntityCombinators.d.ts.map +1 -1
- package/dist/internal/EntityCombinators.js +6 -2
- package/dist/internal/EntityCombinators.js.map +1 -1
- package/dist/internal/EntityOps.d.ts +11 -1
- package/dist/internal/EntityOps.d.ts.map +1 -1
- package/dist/internal/EntityOps.js.map +1 -1
- package/dist/internal/EventProjection.d.ts +15 -3
- package/dist/internal/EventProjection.d.ts.map +1 -1
- package/dist/internal/EventProjection.js +27 -8
- package/dist/internal/EventProjection.js.map +1 -1
- package/dist/internal/Expr.d.ts.map +1 -1
- package/dist/internal/Expr.js +53 -2
- package/dist/internal/Expr.js.map +1 -1
- package/dist/internal/ExpressionLimits.d.ts +57 -1
- package/dist/internal/ExpressionLimits.d.ts.map +1 -1
- package/dist/internal/ExpressionLimits.js +90 -1
- package/dist/internal/ExpressionLimits.js.map +1 -1
- package/dist/internal/ItemSize.d.ts +108 -4
- package/dist/internal/ItemSize.d.ts.map +1 -1
- package/dist/internal/ItemSize.js +190 -3
- package/dist/internal/ItemSize.js.map +1 -1
- package/dist/internal/MultiProjection.d.ts +7 -2
- package/dist/internal/MultiProjection.d.ts.map +1 -1
- package/dist/internal/MultiProjection.js +9 -3
- package/dist/internal/MultiProjection.js.map +1 -1
- package/dist/internal/PathBuilder.d.ts +15 -4
- package/dist/internal/PathBuilder.d.ts.map +1 -1
- package/dist/internal/PathBuilder.js +20 -10
- package/dist/internal/PathBuilder.js.map +1 -1
- package/dist/internal/ProjectionEngine.d.ts +76 -2
- package/dist/internal/ProjectionEngine.d.ts.map +1 -1
- package/dist/internal/ProjectionEngine.js +358 -28
- package/dist/internal/ProjectionEngine.js.map +1 -1
- package/dist/internal/Rekey.d.ts +21 -1
- package/dist/internal/Rekey.d.ts.map +1 -1
- package/dist/internal/Rekey.js +67 -0
- package/dist/internal/Rekey.js.map +1 -1
- package/dist/internal/RoundTrip.d.ts +36 -0
- package/dist/internal/RoundTrip.d.ts.map +1 -0
- package/dist/internal/RoundTrip.js +79 -0
- package/dist/internal/RoundTrip.js.map +1 -0
- package/dist/internal/SentRequest.d.ts +14 -0
- package/dist/internal/SentRequest.d.ts.map +1 -0
- package/dist/internal/SentRequest.js +31 -0
- package/dist/internal/SentRequest.js.map +1 -0
- package/dist/internal/TransactWriteOps.d.ts +69 -15
- package/dist/internal/TransactWriteOps.d.ts.map +1 -1
- package/dist/internal/TransactWriteOps.js +144 -107
- package/dist/internal/TransactWriteOps.js.map +1 -1
- package/dist/internal/TransactableOps.d.ts +115 -23
- package/dist/internal/TransactableOps.d.ts.map +1 -1
- package/dist/internal/TransactableOps.js +244 -80
- package/dist/internal/TransactableOps.js.map +1 -1
- package/dist/internal/WriteDiagnosis.d.ts +31 -3
- package/dist/internal/WriteDiagnosis.d.ts.map +1 -1
- package/dist/internal/WriteDiagnosis.js +128 -11
- package/dist/internal/WriteDiagnosis.js.map +1 -1
- package/package.json +2 -2
|
@@ -11,6 +11,7 @@ import { DateTime, Effect, Option, Schema } from "effect";
|
|
|
11
11
|
import type { DynamoClientError, DynamoClientService } from "../DynamoClient.js";
|
|
12
12
|
import type { Entity } from "../Entity.js";
|
|
13
13
|
import type { ConditionInput } from "../Expression.js";
|
|
14
|
+
import { type TableConfig } from "../Table.js";
|
|
14
15
|
import type { ReturnValuesMode, UpdateState } from "./EntityOps.js";
|
|
15
16
|
/**
|
|
16
17
|
* @internal Hidden per-incarnation token of a versioned entity (#133): set
|
|
@@ -19,23 +20,76 @@ import type { ReturnValuesMode, UpdateState } from "./EntityOps.js";
|
|
|
19
20
|
* `__edd_e__` so it cannot collide with a model field; never decoded.
|
|
20
21
|
*/
|
|
21
22
|
export declare const INCARNATION_TOKEN = "__edd_i__";
|
|
23
|
+
/** @internal What an attribute a projection keeps on its read model's rows is for. */
|
|
24
|
+
export type ProjectionRole = "checkpoint" | "checkpoint map" | "checkpoint owner" | "revision";
|
|
22
25
|
/**
|
|
23
|
-
* @internal What a projection
|
|
24
|
-
*
|
|
26
|
+
* @internal What a projection records on its read model (#154): each attribute its rows hold for
|
|
27
|
+
* it (domain field names), with its role, in the order its tombstone stores them (its revision
|
|
28
|
+
* last), whether it has `removal` (its rows may become tombstones), and whether its tombstones set
|
|
29
|
+
* the table's TTL attribute (`removal.ttl`). `label` names the projection in a refusal. A field
|
|
30
|
+
* the projection gives two roles is listed once per role.
|
|
25
31
|
*/
|
|
26
|
-
export interface
|
|
27
|
-
readonly
|
|
28
|
-
readonly
|
|
32
|
+
export interface ProjectionLayout {
|
|
33
|
+
readonly label: string;
|
|
34
|
+
readonly roles: ReadonlyArray<readonly [field: string, role: ProjectionRole]>;
|
|
35
|
+
readonly removal: boolean;
|
|
36
|
+
readonly ttl: boolean;
|
|
29
37
|
}
|
|
30
|
-
/** @internal */
|
|
31
|
-
export declare const projectionTombstonesOf: (entity: object) => ProjectionTombstones | undefined;
|
|
32
38
|
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* `
|
|
39
|
+
* @internal The layout of every projection defined on the read model, one entry per distinct
|
|
40
|
+
* layout; `undefined` when none is.
|
|
41
|
+
*/
|
|
42
|
+
export declare const projectionLayoutsOf: (entity: object) => ReadonlyArray<ProjectionLayout> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* @internal Whether a projection defined on the read model has `removal`: its rows may be
|
|
45
|
+
* tombstones, which `create` takes the place of (`overTombstone`), so `create` reads first.
|
|
46
|
+
*/
|
|
47
|
+
export declare const hasProjectionTombstones: (entity: object) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* @internal Record a projection's layout on its read model, beside those of the other projections
|
|
50
|
+
* defined on it, and whether it has `removal`. On a read model one of whose projections has
|
|
51
|
+
* `removal`, a stored attribute one projection names in two roles is refused (`[EDD-9133]`), before
|
|
52
|
+
* anything is recorded: its tombstone carries a checkpoint as it is and raises a revision, so the
|
|
53
|
+
* two would overwrite each other's values. The refusal comes at whichever definition completes the
|
|
54
|
+
* conflict (the projection's own, or the first `removal`), so the order projections are defined in
|
|
55
|
+
* doesn't decide it. Without `removal` nothing is refused: rows are never tombstones. Two
|
|
56
|
+
* projections naming one attribute in different roles are not refused (`roleConflict`). A layout
|
|
57
|
+
* already there moves to the end rather than being added again, so a projection defined over and
|
|
58
|
+
* over (in a function, say) doesn't grow the list.
|
|
59
|
+
*/
|
|
60
|
+
export declare const addProjectionLayout: (entity: {
|
|
61
|
+
readonly entityType: string;
|
|
62
|
+
readonly _renameToDynamo: (item: Record<string, unknown>) => void;
|
|
63
|
+
}, layout: ProjectionLayout) => void;
|
|
64
|
+
/**
|
|
65
|
+
* @internal Whether the read model's TTL attribute must be checked against the attributes its
|
|
66
|
+
* projections keep (`projectionTtlConflict`): a projection's tombstones set it (`removal.ttl`).
|
|
67
|
+
* Only then is the table resolved for it.
|
|
68
|
+
*/
|
|
69
|
+
export declare const projectionTtlChecked: (entity: object) => boolean;
|
|
70
|
+
/**
|
|
71
|
+
* @internal `[EDD-9133]` at run time, once the table's TTL attribute is known: an attribute a
|
|
72
|
+
* projection keeps on the read model's rows that is stored as the TTL attribute, which another's
|
|
73
|
+
* tombstones set (`removal.ttl`). The problem, or `undefined` when there is none. Like the
|
|
74
|
+
* definition's refusal, only on a read model one of whose projections has `removal`.
|
|
75
|
+
*/
|
|
76
|
+
export declare const projectionTtlConflict: (entity: {
|
|
77
|
+
readonly entityType: string;
|
|
78
|
+
readonly _renameToDynamo: (item: Record<string, unknown>) => void;
|
|
79
|
+
}, ttlAttribute: string) => string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* @internal `create` over a projection tombstone (#154): read the key, and when it holds the
|
|
82
|
+
* entity's tombstone, carry what the projections with `removal` keep on one over into `item`
|
|
83
|
+
* (stored names, wire values), and return the guard naming that very tombstone. `None` when there
|
|
84
|
+
* is no tombstone: `create`'s own guard applies. A tombstone holds the attributes of the projection
|
|
85
|
+
* that wrote it, which may be any of those with `removal`: each one's checkpoints (and map, and
|
|
86
|
+
* owners) the tombstone holds are carried as they are, so a late redelivery is still recognised,
|
|
87
|
+
* and its revision one higher. An attribute two of them name is taken in the role the one defined
|
|
88
|
+
* last gives it, as 1.39.0 took every attribute from that one. A projection without `removal`
|
|
89
|
+
* writes no tombstone, and isn't consulted. When a projection's tombstones set the table's TTL
|
|
90
|
+
* attribute, it is never carried, so the row doesn't expire with the tombstone: a projection
|
|
91
|
+
* naming it is refused when it writes (`projectionTtlConflict`), and one defined after a tombstone
|
|
92
|
+
* was written would otherwise carry its expiry onto the row.
|
|
39
93
|
*/
|
|
40
94
|
export declare const overTombstone: (entity: {
|
|
41
95
|
readonly entityType: string;
|
|
@@ -50,7 +104,18 @@ export declare const overTombstone: (entity: {
|
|
|
50
104
|
};
|
|
51
105
|
};
|
|
52
106
|
readonly _renameToDynamo: (item: Record<string, unknown>) => void;
|
|
53
|
-
}, client: Pick<DynamoClientService, "getItem">,
|
|
107
|
+
}, client: Pick<DynamoClientService, "getItem">, table: TableConfig, item: Record<string, unknown>) => Effect.Effect<Option.Option<ConditionInput>, DynamoClientError>;
|
|
108
|
+
/**
|
|
109
|
+
* @internal Flatten `entity`'s sparse-map fields on `item` (stored names) into per-entry
|
|
110
|
+
* attributes, refusing a key it can't store with a `ValidationError` for `operation`. The
|
|
111
|
+
* transactional put and a projection's tombstone (on a copy) go through it, and `Entity.put`
|
|
112
|
+
* refuses through the same `_serializeSparseFields`, so each refuses the same key the same way,
|
|
113
|
+
* before sending anything.
|
|
114
|
+
*/
|
|
115
|
+
export declare const serializeSparseOrFail: (entity: {
|
|
116
|
+
readonly entityType: string;
|
|
117
|
+
readonly _serializeSparseFields: (item: Record<string, unknown>) => void;
|
|
118
|
+
}, item: Record<string, unknown>, operation: string) => Effect.Effect<void, ValidationError>;
|
|
54
119
|
/**
|
|
55
120
|
* A projection tombstone (#154) of `entityType` — written at a removed row's
|
|
56
121
|
* own key to keep its checkpoints. Every read by key reports it as absent.
|
|
@@ -194,7 +259,7 @@ input?: unknown, details?: {
|
|
|
194
259
|
*/
|
|
195
260
|
export declare const resolveTableNames: (infos: ReadonlyArray<{
|
|
196
261
|
readonly entity: Entity;
|
|
197
|
-
}>) => Effect.Effect<Map<Entity<Schema.Top, string, Record<string, KeyComposer.IndexDefinition>, import("@effect-dynamodb/schema/internal/EntityConfig.js").TimestampsConfig | undefined, import("@effect-dynamodb/schema/internal/EntityConfig.js").VersionedConfig | undefined, import("@effect-dynamodb/schema/internal/EntityConfig.js").SoftDeleteConfig | undefined, import("@effect-dynamodb/schema/internal/EntityConfig.js").UniqueConfig | undefined, undefined, undefined, undefined, undefined, undefined, never>, string>, never,
|
|
262
|
+
}>) => Effect.Effect<Map<Entity<Schema.Top, string, Record<string, KeyComposer.IndexDefinition>, import("@effect-dynamodb/schema/internal/EntityConfig.js").TimestampsConfig | undefined, import("@effect-dynamodb/schema/internal/EntityConfig.js").VersionedConfig | undefined, import("@effect-dynamodb/schema/internal/EntityConfig.js").SoftDeleteConfig | undefined, import("@effect-dynamodb/schema/internal/EntityConfig.js").UniqueConfig | undefined, undefined, undefined, undefined, undefined, undefined, never, never>, string>, never, TableConfig>;
|
|
198
263
|
/**
|
|
199
264
|
* @internal Run a key composer, turning a value it can't place into a
|
|
200
265
|
* `ValidationError` for `operation`: a Z-order value (`[EDD-9092]`,
|
|
@@ -207,15 +272,37 @@ export declare const resolveTableNames: (infos: ReadonlyArray<{
|
|
|
207
272
|
*/
|
|
208
273
|
export declare const composeKeysOrFail: <A>(entityType: string, operation: string, compose: () => A) => Effect.Effect<A, ValidationError>;
|
|
209
274
|
/**
|
|
210
|
-
*
|
|
275
|
+
* Marshal an item holding a caller's values. A value DynamoDB can't store (an
|
|
276
|
+
* empty set in a list, `NaN`, a number past `Number.MAX_SAFE_INTEGER`, …) fails with
|
|
277
|
+
* a `ValidationError` naming the field; `fieldOf` names a stored attribute by its
|
|
278
|
+
* model field. So does a value it composes into a key and can't place, as
|
|
279
|
+
* {@link composeKeysOrFail} says. Any other throw stays a defect.
|
|
280
|
+
*/
|
|
281
|
+
export declare const marshalOrFail: <A>(entityType: string, operation: string, marshal: () => A, options?: {
|
|
282
|
+
readonly fieldOf?: (attribute: string) => string;
|
|
283
|
+
readonly outcome?: string;
|
|
284
|
+
}) => Effect.Effect<A, ValidationError>;
|
|
285
|
+
/**
|
|
286
|
+
* The primary key of the row a caller's DOMAIN key record names: the key
|
|
287
|
+
* `Entity.put` wrote for it (`_domainKeyForm`). The projection engine reads a
|
|
288
|
+
* read-model row, writes its tombstone and keys its outbox items through this,
|
|
289
|
+
* as the row itself is written by the read model's own `put`.
|
|
211
290
|
*/
|
|
212
291
|
export declare const composePrimaryKey: (entity: Entity, key: Record<string, unknown>) => Record<string, unknown>;
|
|
213
292
|
/**
|
|
214
|
-
*
|
|
215
|
-
* where a composite has no key text (`NaN`,
|
|
216
|
-
* multi-item ops (`Batch.get`, `Batch.write`
|
|
217
|
-
* `transactWrite` deletes and condition checks), as an
|
|
218
|
-
* `delete` do.
|
|
293
|
+
* The primary key of the item a caller's key names, failing with a
|
|
294
|
+
* `ValidationError` for `operation` where a composite has no key text (`NaN`,
|
|
295
|
+
* `[EDD-9096]`) — the key-taking multi-item ops (`Batch.get`, `Batch.write`
|
|
296
|
+
* deletes, `transactGet`, `transactWrite` deletes and condition checks), as an
|
|
297
|
+
* entity's own `get` and `delete` do.
|
|
298
|
+
*
|
|
299
|
+
* The caller's key is a DOMAIN record (`{ takenAt: DateTime }`), as an entity's
|
|
300
|
+
* own `get` takes it, so it goes through `_domainKeyForm`: the key `Entity.put`
|
|
301
|
+
* wrote for it, the key that `get` composes. For a codec `encode` takes on its
|
|
302
|
+
* own output (`x:` prepended), that is the key of the stored text: a domain
|
|
303
|
+
* value that is also such a text (`"x:MiX"`) is encoded first, as `put` does.
|
|
304
|
+
* It sends the key it sent on 1.39.0, whose `put` keyed the stored text encoded
|
|
305
|
+
* once more, so it found nothing there.
|
|
219
306
|
*/
|
|
220
307
|
export declare const composePrimaryKeyOrFail: (entity: Entity, key: Record<string, unknown>, operation: string) => Effect.Effect<Record<string, unknown>, ValidationError>;
|
|
221
308
|
/**
|
|
@@ -231,13 +318,18 @@ export declare const composePrimaryKeyOrFail: (entity: Entity, key: Record<strin
|
|
|
231
318
|
* `createdAt`. `Entity._planPut` needs them to derive uniqueness sentinels and
|
|
232
319
|
* the retain snapshot from the same values that were written (#113), and to
|
|
233
320
|
* keep a replaced item's `createdAt` (#133); re-deriving `now` there would risk
|
|
234
|
-
* a skew between an item's `createdAt` and its snapshot's TTL.
|
|
321
|
+
* a skew between an item's `createdAt` and its snapshot's TTL. `options.createdAt`
|
|
322
|
+
* is the `createdAt` of a row being rewritten, which no input supplies.
|
|
235
323
|
*/
|
|
236
|
-
export declare const validateAndBuildPutItem: (entity: Entity, input: Record<string, unknown>, operation: string
|
|
324
|
+
export declare const validateAndBuildPutItem: (entity: Entity, input: Record<string, unknown>, operation: string, options?: {
|
|
325
|
+
readonly createdAt?: DateTime.Utc | undefined;
|
|
326
|
+
}) => Effect.Effect<{
|
|
237
327
|
readonly item: Record<string, unknown>;
|
|
238
328
|
readonly marshalled: Record<string, import("@aws-sdk/client-dynamodb").AttributeValue>;
|
|
239
329
|
readonly now: DateTime.Utc;
|
|
240
330
|
/** Whether the input supplied `createdAt` (a replacing put keeps the stored one otherwise). */
|
|
241
331
|
readonly createdAtSupplied: boolean;
|
|
332
|
+
/** The item's keys, were these system fields what a guarded put carries over from the stored item. */
|
|
333
|
+
readonly composeKeys: (carried: Record<string, unknown>) => Effect.Effect<Record<string, unknown>, ValidationError>;
|
|
242
334
|
}, ValidationError>;
|
|
243
335
|
//# sourceMappingURL=TransactableOps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactableOps.d.ts","sourceRoot":"","sources":["../../src/internal/TransactableOps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"TransactableOps.d.ts","sourceRoot":"","sources":["../../src/internal/TransactableOps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAA;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAInE,OAAO,KAAK,WAAW,MAAM,wCAAwC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js";
|
|
9
9
|
import { resolveUniqueFields } from "@effect-dynamodb/schema/internal/EntitySchemas.js";
|
|
10
|
-
import { isKeyValueError } from "@effect-dynamodb/schema/internal/NumericKey.js";
|
|
11
|
-
import { isShardSourceError } from "@effect-dynamodb/schema/internal/Shards.js";
|
|
12
|
-
import { isZOrderValueError } from "@effect-dynamodb/schema/internal/ZOrderCurve.js";
|
|
13
10
|
import * as KeyComposer from "@effect-dynamodb/schema/KeyComposer.js";
|
|
14
11
|
import { DateTime, Effect, Option, Schema } from "effect";
|
|
15
|
-
import { fromAttributeMap, toAttributeMap } from "../Marshaller.js";
|
|
12
|
+
import { fromAttributeMap, isUnstorableValue, toAttributeMap } from "../Marshaller.js";
|
|
13
|
+
import { resolveTtlAttributeName } from "../Table.js";
|
|
14
|
+
import { isRefusedValue } from "./Capacity.js";
|
|
16
15
|
/**
|
|
17
16
|
* @internal Hidden per-incarnation token of a versioned entity (#133): set
|
|
18
17
|
* when an item is created, it tells an item apart from a deleted-and-recreated
|
|
@@ -20,23 +19,133 @@ import { fromAttributeMap, toAttributeMap } from "../Marshaller.js";
|
|
|
20
19
|
* `__edd_e__` so it cannot collide with a model field; never decoded.
|
|
21
20
|
*/
|
|
22
21
|
export const INCARNATION_TOKEN = "__edd_i__";
|
|
23
|
-
/** @internal */
|
|
24
|
-
export const projectionTombstonesOf = (entity) => entity._projectionTombstones;
|
|
25
22
|
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*
|
|
28
|
-
* over into `item` (stored names, wire values) — its checkpoints, so a late
|
|
29
|
-
* redelivery is still recognised — with the revision one higher, and return
|
|
30
|
-
* the guard naming that very tombstone. `None` when there is no tombstone:
|
|
31
|
-
* `create`'s own guard applies.
|
|
23
|
+
* @internal The layout of every projection defined on the read model, one entry per distinct
|
|
24
|
+
* layout; `undefined` when none is.
|
|
32
25
|
*/
|
|
33
|
-
export const
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
export const projectionLayoutsOf = (entity) => entity._projectionLayouts;
|
|
27
|
+
/**
|
|
28
|
+
* @internal Whether a projection defined on the read model has `removal`: its rows may be
|
|
29
|
+
* tombstones, which `create` takes the place of (`overTombstone`), so `create` reads first.
|
|
30
|
+
*/
|
|
31
|
+
export const hasProjectionTombstones = (entity) => entity._projectionTombstones === true;
|
|
32
|
+
/** A domain field's stored attribute name on `entity`. */
|
|
33
|
+
const storedName = (entity, field) => {
|
|
34
|
+
const probe = { [field]: 1 };
|
|
35
|
+
entity._renameToDynamo(probe);
|
|
36
|
+
return Object.keys(probe)[0] ?? field;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* `[EDD-9133]` among `layouts`: a stored attribute one projection names in two roles. The problem,
|
|
40
|
+
* or `undefined`. `current` is the layout being defined, named "this projection". Two projections
|
|
41
|
+
* may name one attribute in different roles: each writes its own, so two that never write one
|
|
42
|
+
* row (rows of disjoint keys) work as on 1.39.0. Two that share rows and swap names can't be told
|
|
43
|
+
* apart from them, and are as broken as on 1.39.0.
|
|
44
|
+
*/
|
|
45
|
+
const roleConflict = (entity, layouts, current) => {
|
|
46
|
+
const whose = (layout) => layout === current ? "this projection's" : `${layout.label}'s`;
|
|
47
|
+
const as = (field, stored) => field === stored ? `"${field}"` : `"${field}" (stored as "${stored}")`;
|
|
48
|
+
for (const layout of layouts) {
|
|
49
|
+
const first = new Map();
|
|
50
|
+
for (const [field, role] of layout.roles) {
|
|
51
|
+
const stored = storedName(entity, field);
|
|
52
|
+
const held = first.get(stored);
|
|
53
|
+
if (held === undefined) {
|
|
54
|
+
first.set(stored, { layout, field, role });
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (held.role === role)
|
|
58
|
+
continue;
|
|
59
|
+
const second = held.field === field ? `its ${role}` : `${as(field, stored)} its ${role}`;
|
|
60
|
+
return (`[EDD-9133] ${current.label}: on read model "${entity.entityType}", ` +
|
|
61
|
+
`${as(held.field, stored)} is ${whose(held.layout)} ${held.role}, and ${second}. A ` +
|
|
62
|
+
"projection of the read model has `removal`, and a tombstone carries a checkpoint as it " +
|
|
63
|
+
"is and raises a revision: an attribute holds one role in a projection. Give each its " +
|
|
64
|
+
"own field.");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* @internal Record a projection's layout on its read model, beside those of the other projections
|
|
71
|
+
* defined on it, and whether it has `removal`. On a read model one of whose projections has
|
|
72
|
+
* `removal`, a stored attribute one projection names in two roles is refused (`[EDD-9133]`), before
|
|
73
|
+
* anything is recorded: its tombstone carries a checkpoint as it is and raises a revision, so the
|
|
74
|
+
* two would overwrite each other's values. The refusal comes at whichever definition completes the
|
|
75
|
+
* conflict (the projection's own, or the first `removal`), so the order projections are defined in
|
|
76
|
+
* doesn't decide it. Without `removal` nothing is refused: rows are never tombstones. Two
|
|
77
|
+
* projections naming one attribute in different roles are not refused (`roleConflict`). A layout
|
|
78
|
+
* already there moves to the end rather than being added again, so a projection defined over and
|
|
79
|
+
* over (in a function, say) doesn't grow the list.
|
|
80
|
+
*/
|
|
81
|
+
export const addProjectionLayout = (entity, layout) => {
|
|
82
|
+
const holder = entity;
|
|
83
|
+
const same = (other) => other.removal === layout.removal &&
|
|
84
|
+
other.ttl === layout.ttl &&
|
|
85
|
+
other.roles.length === layout.roles.length &&
|
|
86
|
+
other.roles.every(([field, role], i) => {
|
|
87
|
+
const [f, r] = layout.roles[i];
|
|
88
|
+
return field === f && role === r;
|
|
89
|
+
});
|
|
90
|
+
const layouts = [...(holder._projectionLayouts ?? []).filter((other) => !same(other)), layout];
|
|
91
|
+
if (layout.removal || hasProjectionTombstones(entity)) {
|
|
92
|
+
const problem = roleConflict(entity, layouts, layout);
|
|
93
|
+
if (problem !== undefined)
|
|
94
|
+
throw new Error(problem);
|
|
95
|
+
}
|
|
96
|
+
holder._projectionLayouts = layouts;
|
|
97
|
+
if (layout.removal)
|
|
98
|
+
holder._projectionTombstones = true;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* @internal Whether the read model's TTL attribute must be checked against the attributes its
|
|
102
|
+
* projections keep (`projectionTtlConflict`): a projection's tombstones set it (`removal.ttl`).
|
|
103
|
+
* Only then is the table resolved for it.
|
|
104
|
+
*/
|
|
105
|
+
export const projectionTtlChecked = (entity) => hasProjectionTombstones(entity) &&
|
|
106
|
+
(projectionLayoutsOf(entity) ?? []).some((layout) => layout.ttl);
|
|
107
|
+
/**
|
|
108
|
+
* @internal `[EDD-9133]` at run time, once the table's TTL attribute is known: an attribute a
|
|
109
|
+
* projection keeps on the read model's rows that is stored as the TTL attribute, which another's
|
|
110
|
+
* tombstones set (`removal.ttl`). The problem, or `undefined` when there is none. Like the
|
|
111
|
+
* definition's refusal, only on a read model one of whose projections has `removal`.
|
|
112
|
+
*/
|
|
113
|
+
export const projectionTtlConflict = (entity, ttlAttribute) => {
|
|
114
|
+
if (!projectionTtlChecked(entity))
|
|
115
|
+
return undefined;
|
|
116
|
+
for (const layout of projectionLayoutsOf(entity) ?? []) {
|
|
117
|
+
for (const [field, role] of layout.roles) {
|
|
118
|
+
if (storedName(entity, field) === ttlAttribute) {
|
|
119
|
+
return (`[EDD-9133] "${field}" is a projection's ${role} on read model "${entity.entityType}", ` +
|
|
120
|
+
`stored as "${ttlAttribute}", the table's TTL attribute, which a projection's ` +
|
|
121
|
+
"tombstones set (`removal.ttl`). An attribute holds one role: give the " +
|
|
122
|
+
`${role} its own field.`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* @internal `create` over a projection tombstone (#154): read the key, and when it holds the
|
|
130
|
+
* entity's tombstone, carry what the projections with `removal` keep on one over into `item`
|
|
131
|
+
* (stored names, wire values), and return the guard naming that very tombstone. `None` when there
|
|
132
|
+
* is no tombstone: `create`'s own guard applies. A tombstone holds the attributes of the projection
|
|
133
|
+
* that wrote it, which may be any of those with `removal`: each one's checkpoints (and map, and
|
|
134
|
+
* owners) the tombstone holds are carried as they are, so a late redelivery is still recognised,
|
|
135
|
+
* and its revision one higher. An attribute two of them name is taken in the role the one defined
|
|
136
|
+
* last gives it, as 1.39.0 took every attribute from that one. A projection without `removal`
|
|
137
|
+
* writes no tombstone, and isn't consulted. When a projection's tombstones set the table's TTL
|
|
138
|
+
* attribute, it is never carried, so the row doesn't expire with the tombstone: a projection
|
|
139
|
+
* naming it is refused when it writes (`projectionTtlConflict`), and one defined after a tombstone
|
|
140
|
+
* was written would otherwise carry its expiry onto the row.
|
|
141
|
+
*/
|
|
142
|
+
export const overTombstone = (entity, client, table, item) => Effect.gen(function* () {
|
|
143
|
+
if (!hasProjectionTombstones(entity))
|
|
36
144
|
return Option.none();
|
|
145
|
+
const layouts = projectionLayoutsOf(entity) ?? [];
|
|
37
146
|
const primary = entity.indexes.primary;
|
|
38
147
|
const { Item } = yield* client.getItem({
|
|
39
|
-
TableName:
|
|
148
|
+
TableName: table.name,
|
|
40
149
|
Key: toAttributeMap({
|
|
41
150
|
[primary.pk.field]: item[primary.pk.field],
|
|
42
151
|
[primary.sk.field]: item[primary.sk.field],
|
|
@@ -46,25 +155,47 @@ export const overTombstone = (entity, client, tableName, item) => Effect.gen(fun
|
|
|
46
155
|
if (Item === undefined || !isProjectionTombstone(Item, entity.entityType))
|
|
47
156
|
return Option.none();
|
|
48
157
|
const tomb = fromAttributeMap(Item);
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
158
|
+
const ttl = layouts.some((layout) => layout.ttl) ? resolveTtlAttributeName(table) : undefined;
|
|
159
|
+
// An attribute is the tombstone's own, never a member it inherits.
|
|
160
|
+
const held = (name) => (Object.hasOwn(tomb, name) ? tomb[name] : undefined);
|
|
161
|
+
// The projections with `removal`, the one defined last first. Each attribute once, in the role
|
|
162
|
+
// of the first that names it: its checkpoints, then its revision, as with one layout.
|
|
163
|
+
const taken = new Set();
|
|
164
|
+
for (const layout of [...layouts].reverse()) {
|
|
165
|
+
if (!layout.removal)
|
|
166
|
+
continue;
|
|
167
|
+
const mine = layout.roles
|
|
168
|
+
.map(([field, role]) => [storedName(entity, field), role])
|
|
169
|
+
.filter(([name]) => name !== ttl && !taken.has(name));
|
|
170
|
+
for (const [name, role] of mine) {
|
|
171
|
+
taken.add(name);
|
|
172
|
+
if (role !== "revision" && held(name) !== undefined)
|
|
173
|
+
item[name] = held(name);
|
|
174
|
+
}
|
|
175
|
+
for (const [name, role] of mine) {
|
|
176
|
+
if (role === "revision" && held(name) !== undefined)
|
|
177
|
+
item[name] = Number(held(name)) + 1;
|
|
178
|
+
}
|
|
63
179
|
}
|
|
64
180
|
return Option.some({
|
|
65
181
|
eq: { __edd_e__: `${entity.entityType}#tombstone`, __edd_removed__: tomb.__edd_removed__ },
|
|
66
182
|
});
|
|
67
183
|
});
|
|
184
|
+
/**
|
|
185
|
+
* @internal Flatten `entity`'s sparse-map fields on `item` (stored names) into per-entry
|
|
186
|
+
* attributes, refusing a key it can't store with a `ValidationError` for `operation`. The
|
|
187
|
+
* transactional put and a projection's tombstone (on a copy) go through it, and `Entity.put`
|
|
188
|
+
* refuses through the same `_serializeSparseFields`, so each refuses the same key the same way,
|
|
189
|
+
* before sending anything.
|
|
190
|
+
*/
|
|
191
|
+
export const serializeSparseOrFail = (entity, item, operation) => Effect.try({
|
|
192
|
+
try: () => entity._serializeSparseFields(item),
|
|
193
|
+
catch: (e) => new ValidationError({
|
|
194
|
+
entityType: entity.entityType,
|
|
195
|
+
operation,
|
|
196
|
+
cause: e instanceof Error ? e.message : String(e),
|
|
197
|
+
}),
|
|
198
|
+
});
|
|
68
199
|
/**
|
|
69
200
|
* A projection tombstone (#154) of `entityType` — written at a removed row's
|
|
70
201
|
* own key to keep its checkpoints. Every read by key reports it as absent.
|
|
@@ -317,34 +448,62 @@ export const resolveTableNames = (infos) => Effect.gen(function* () {
|
|
|
317
448
|
* that composes an item's keys goes through this, so the failure is typed instead
|
|
318
449
|
* of a defect. Any other throw stays a defect.
|
|
319
450
|
*/
|
|
320
|
-
export const composeKeysOrFail = (entityType, operation, compose) => Effect.try({ try: compose, catch: (error) => error }).pipe(Effect.catch((error) =>
|
|
451
|
+
export const composeKeysOrFail = (entityType, operation, compose) => Effect.try({ try: compose, catch: (error) => error }).pipe(Effect.catch((error) => isRefusedValue(error)
|
|
321
452
|
? Effect.fail(new ValidationError({ entityType, operation, cause: error }))
|
|
322
453
|
: Effect.die(error)));
|
|
323
454
|
/**
|
|
324
|
-
*
|
|
455
|
+
* Marshal an item holding a caller's values. A value DynamoDB can't store (an
|
|
456
|
+
* empty set in a list, `NaN`, a number past `Number.MAX_SAFE_INTEGER`, …) fails with
|
|
457
|
+
* a `ValidationError` naming the field; `fieldOf` names a stored attribute by its
|
|
458
|
+
* model field. So does a value it composes into a key and can't place, as
|
|
459
|
+
* {@link composeKeysOrFail} says. Any other throw stays a defect.
|
|
325
460
|
*/
|
|
326
|
-
export const
|
|
461
|
+
export const marshalOrFail = (entityType, operation, marshal, options = {}) => Effect.try({ try: marshal, catch: (error) => error }).pipe(Effect.catch((error) => isUnstorableValue(error)
|
|
462
|
+
? Effect.fail(new ValidationError({
|
|
463
|
+
entityType,
|
|
464
|
+
operation,
|
|
465
|
+
cause: `${error.describe(options.fieldOf)} ${options.outcome ?? "Nothing was written."}`,
|
|
466
|
+
}))
|
|
467
|
+
: isRefusedValue(error)
|
|
468
|
+
? Effect.fail(new ValidationError({ entityType, operation, cause: error }))
|
|
469
|
+
: Effect.die(error)));
|
|
470
|
+
/** An entity item's primary key, from a record already in the composite key form. */
|
|
471
|
+
const primaryKeyOf = (entity, recordKeyForm) => {
|
|
327
472
|
const primary = entity.indexes.primary;
|
|
328
473
|
const schema = entity._schema;
|
|
329
|
-
// The caller's key is a DOMAIN record (`{ takenAt: DateTime }`), and every
|
|
330
|
-
// `KeyComposer` input must first go through the composite key-form rule or it
|
|
331
|
-
// composes a different string than `Entity.put` wrote — a `DateEpochMs` PK
|
|
332
|
-
// composite made `Batch.get` return null and `Batch.write(delete)` report
|
|
333
|
-
// success against a row it never touched (#111).
|
|
334
|
-
const recordKeyForm = entity._keyForm(key);
|
|
335
474
|
return {
|
|
336
475
|
[primary.pk.field]: KeyComposer.composePk(schema, entity.entityType, primary, recordKeyForm),
|
|
337
476
|
[primary.sk.field]: KeyComposer.composeSk(schema, entity.entityType, 1, primary, recordKeyForm),
|
|
338
477
|
};
|
|
339
478
|
};
|
|
340
479
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
|
|
480
|
+
* The primary key of the row a caller's DOMAIN key record names: the key
|
|
481
|
+
* `Entity.put` wrote for it (`_domainKeyForm`). The projection engine reads a
|
|
482
|
+
* read-model row, writes its tombstone and keys its outbox items through this,
|
|
483
|
+
* as the row itself is written by the read model's own `put`.
|
|
484
|
+
*/
|
|
485
|
+
export const composePrimaryKey = (entity, key) =>
|
|
486
|
+
// Every `KeyComposer` input must first go through the composite key-form rule
|
|
487
|
+
// or it composes a different string than `Entity.put` wrote — a `DateEpochMs`
|
|
488
|
+
// PK composite made `Batch.get` return null and `Batch.write(delete)` report
|
|
489
|
+
// success against a row it never touched (#111).
|
|
490
|
+
primaryKeyOf(entity, entity._domainKeyForm(key));
|
|
491
|
+
/**
|
|
492
|
+
* The primary key of the item a caller's key names, failing with a
|
|
493
|
+
* `ValidationError` for `operation` where a composite has no key text (`NaN`,
|
|
494
|
+
* `[EDD-9096]`) — the key-taking multi-item ops (`Batch.get`, `Batch.write`
|
|
495
|
+
* deletes, `transactGet`, `transactWrite` deletes and condition checks), as an
|
|
496
|
+
* entity's own `get` and `delete` do.
|
|
497
|
+
*
|
|
498
|
+
* The caller's key is a DOMAIN record (`{ takenAt: DateTime }`), as an entity's
|
|
499
|
+
* own `get` takes it, so it goes through `_domainKeyForm`: the key `Entity.put`
|
|
500
|
+
* wrote for it, the key that `get` composes. For a codec `encode` takes on its
|
|
501
|
+
* own output (`x:` prepended), that is the key of the stored text: a domain
|
|
502
|
+
* value that is also such a text (`"x:MiX"`) is encoded first, as `put` does.
|
|
503
|
+
* It sends the key it sent on 1.39.0, whose `put` keyed the stored text encoded
|
|
504
|
+
* once more, so it found nothing there.
|
|
346
505
|
*/
|
|
347
|
-
export const composePrimaryKeyOrFail = (entity, key, operation) => composeKeysOrFail(entity.entityType, operation, () =>
|
|
506
|
+
export const composePrimaryKeyOrFail = (entity, key, operation) => composeKeysOrFail(entity.entityType, operation, () => primaryKeyOf(entity, entity._domainKeyForm(key)));
|
|
348
507
|
/**
|
|
349
508
|
* Validate input, compose all keys, and build a marshalled put item.
|
|
350
509
|
*
|
|
@@ -358,9 +517,10 @@ export const composePrimaryKeyOrFail = (entity, key, operation) => composeKeysOr
|
|
|
358
517
|
* `createdAt`. `Entity._planPut` needs them to derive uniqueness sentinels and
|
|
359
518
|
* the retain snapshot from the same values that were written (#113), and to
|
|
360
519
|
* keep a replaced item's `createdAt` (#133); re-deriving `now` there would risk
|
|
361
|
-
* a skew between an item's `createdAt` and its snapshot's TTL.
|
|
520
|
+
* a skew between an item's `createdAt` and its snapshot's TTL. `options.createdAt`
|
|
521
|
+
* is the `createdAt` of a row being rewritten, which no input supplies.
|
|
362
522
|
*/
|
|
363
|
-
export const validateAndBuildPutItem = (entity, input, operation) => Effect.gen(function* () {
|
|
523
|
+
export const validateAndBuildPutItem = (entity, input, operation, options) => Effect.gen(function* () {
|
|
364
524
|
// Clock-backed time source resolved once per op; threaded into the sync
|
|
365
525
|
// timestamp builder so the value is deterministic under `TestClock`.
|
|
366
526
|
const now = yield* DateTime.now;
|
|
@@ -374,16 +534,46 @@ export const validateAndBuildPutItem = (entity, input, operation) => Effect.gen(
|
|
|
374
534
|
operation,
|
|
375
535
|
cause,
|
|
376
536
|
})));
|
|
537
|
+
yield* entity._refuseNotReadBack(encoded, operation);
|
|
377
538
|
const item = { ...encoded };
|
|
378
539
|
item.__edd_e__ = entity.entityType;
|
|
379
540
|
if (unsentineled.length > 0)
|
|
380
541
|
item[UNSENTINELED_DEFAULTS] = new Set(unsentineled);
|
|
542
|
+
// System fields (collision-aware), stamped before the keys are composed,
|
|
543
|
+
// as `Entity.put` does: an index may be composed from one. When a
|
|
544
|
+
// timestamp field collides with a model-declared field, the user may have
|
|
545
|
+
// supplied their own value (already encoded to wire by `Schema.encode`);
|
|
546
|
+
// else generate a wire primitive directly. They are placed in the item
|
|
547
|
+
// after the keys, where 1.39.0 placed them, so the request is the same.
|
|
548
|
+
const sf = entity.systemFields;
|
|
549
|
+
const createdAtSupplied = sf.createdAt !== null && item[sf.createdAt] !== undefined;
|
|
550
|
+
const stamps = {};
|
|
551
|
+
if (sf.createdAt) {
|
|
552
|
+
if (options?.createdAt !== undefined) {
|
|
553
|
+
stamps[sf.createdAt] = generateTimestampPrimitive(options.createdAt, sf.createdAtEncoding);
|
|
554
|
+
}
|
|
555
|
+
else if (item[sf.createdAt] === undefined) {
|
|
556
|
+
stamps[sf.createdAt] = generateTimestampPrimitive(now, sf.createdAtEncoding);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (sf.updatedAt) {
|
|
560
|
+
if (item[sf.updatedAt] === undefined) {
|
|
561
|
+
stamps[sf.updatedAt] = generateTimestampPrimitive(now, sf.updatedAtEncoding);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (sf.version)
|
|
565
|
+
stamps[sf.version] = 1;
|
|
381
566
|
// Same normalisation `Entity.put` applies. Without it a `BigIntFromString`
|
|
382
567
|
// composite composed `txn_420` here and `txn_000…0420` there, so the two
|
|
383
568
|
// APIs wrote two different rows for the same logical item and neither
|
|
384
569
|
// accessor could read the transact-written one (#111).
|
|
385
|
-
const
|
|
386
|
-
|
|
570
|
+
const composed = { ...encoded };
|
|
571
|
+
for (const field of [sf.createdAt, sf.updatedAt, sf.version]) {
|
|
572
|
+
if (field)
|
|
573
|
+
composed[field] = Object.hasOwn(stamps, field) ? stamps[field] : item[field];
|
|
574
|
+
}
|
|
575
|
+
const composeKeys = (carried) => composeKeysOrFail(entity.entityType, operation, () => KeyComposer.composeAllKeys(entity._schema, entity.entityType, 1, entity.indexes, entity._keyForm({ ...composed, ...carried })));
|
|
576
|
+
Object.assign(item, yield* composeKeys({}));
|
|
387
577
|
// A unique field's sentinel key is composed from its value later, on the
|
|
388
578
|
// guarded path, after this item is marshalled. One with no key text
|
|
389
579
|
// (`NaN`, `[EDD-9096]`) is refused here, as `Entity.put` refuses it, not
|
|
@@ -398,24 +588,7 @@ export const validateAndBuildPutItem = (entity, input, operation) => Effect.gen(
|
|
|
398
588
|
}
|
|
399
589
|
}
|
|
400
590
|
});
|
|
401
|
-
|
|
402
|
-
// model-declared field, the user may have supplied their own value
|
|
403
|
-
// (already encoded to wire by `Schema.encode`); else generate a wire
|
|
404
|
-
// primitive directly.
|
|
405
|
-
const sf = entity.systemFields;
|
|
406
|
-
const createdAtSupplied = sf.createdAt !== null && item[sf.createdAt] !== undefined;
|
|
407
|
-
if (sf.createdAt) {
|
|
408
|
-
if (item[sf.createdAt] === undefined) {
|
|
409
|
-
item[sf.createdAt] = generateTimestampPrimitive(now, sf.createdAtEncoding);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
if (sf.updatedAt) {
|
|
413
|
-
if (item[sf.updatedAt] === undefined) {
|
|
414
|
-
item[sf.updatedAt] = generateTimestampPrimitive(now, sf.updatedAtEncoding);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
if (sf.version)
|
|
418
|
-
item[sf.version] = 1;
|
|
591
|
+
Object.assign(item, stamps);
|
|
419
592
|
if (entity._incarnationToken)
|
|
420
593
|
item[INCARNATION_TOKEN] = yield* freshIncarnationToken;
|
|
421
594
|
// Rename domain fields to their stored attribute names, in the same
|
|
@@ -425,20 +598,11 @@ export const validateAndBuildPutItem = (entity, input, operation) => Effect.gen(
|
|
|
425
598
|
// `_planPut` derives the retain snapshot from this same item,
|
|
426
599
|
// so the snapshot inherited the wrong shape too (#111).
|
|
427
600
|
entity._renameToDynamo(item);
|
|
428
|
-
// Flatten sparse-map fields into per-entry top-level attributes.
|
|
429
|
-
|
|
430
|
-
try {
|
|
431
|
-
entity._serializeSparseFields(item);
|
|
432
|
-
}
|
|
433
|
-
catch (e) {
|
|
434
|
-
return yield* new ValidationError({
|
|
435
|
-
entityType: entity.entityType,
|
|
436
|
-
operation,
|
|
437
|
-
cause: e instanceof Error ? e.message : String(e),
|
|
438
|
-
});
|
|
439
|
-
}
|
|
601
|
+
// Flatten sparse-map fields into per-entry top-level attributes.
|
|
602
|
+
yield* serializeSparseOrFail(entity, item, operation);
|
|
440
603
|
// Pack `storedAs: DynamoModel.Packed` fields, as `Entity.put` does (#147).
|
|
441
604
|
yield* entity._packFields(item, operation);
|
|
442
|
-
|
|
605
|
+
const marshalled = yield* marshalOrFail(entity.entityType, operation, () => toAttributeMap(item), { fieldOf: entity._fieldOfAttribute });
|
|
606
|
+
return { item, marshalled, now, createdAtSupplied, composeKeys };
|
|
443
607
|
});
|
|
444
608
|
//# sourceMappingURL=TransactableOps.js.map
|