effect-dynamodb 1.39.0 → 1.41.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.
Files changed (190) hide show
  1. package/README.md +1 -1
  2. package/dist/Aggregate.d.ts +138 -16
  3. package/dist/Aggregate.d.ts.map +1 -1
  4. package/dist/Aggregate.js +4298 -725
  5. package/dist/Aggregate.js.map +1 -1
  6. package/dist/Batch.d.ts +9 -5
  7. package/dist/Batch.d.ts.map +1 -1
  8. package/dist/Batch.js +28 -44
  9. package/dist/Batch.js.map +1 -1
  10. package/dist/Collection.d.ts.map +1 -1
  11. package/dist/Collection.js +16 -9
  12. package/dist/Collection.js.map +1 -1
  13. package/dist/ConsumedCapacity.js +1 -1
  14. package/dist/ConsumedCapacity.js.map +1 -1
  15. package/dist/DynamoClient.d.ts +44 -21
  16. package/dist/DynamoClient.d.ts.map +1 -1
  17. package/dist/DynamoClient.js +342 -124
  18. package/dist/DynamoClient.js.map +1 -1
  19. package/dist/Entity.d.ts +246 -41
  20. package/dist/Entity.d.ts.map +1 -1
  21. package/dist/Entity.js +6818 -1166
  22. package/dist/Entity.js.map +1 -1
  23. package/dist/EventStore.d.ts +37 -15
  24. package/dist/EventStore.d.ts.map +1 -1
  25. package/dist/EventStore.js +403 -163
  26. package/dist/EventStore.js.map +1 -1
  27. package/dist/Expression.d.ts.map +1 -1
  28. package/dist/Expression.js +40 -24
  29. package/dist/Expression.js.map +1 -1
  30. package/dist/Marshaller.d.ts +72 -11
  31. package/dist/Marshaller.d.ts.map +1 -1
  32. package/dist/Marshaller.js +625 -71
  33. package/dist/Marshaller.js.map +1 -1
  34. package/dist/Query.d.ts +103 -5
  35. package/dist/Query.d.ts.map +1 -1
  36. package/dist/Query.js +262 -15
  37. package/dist/Query.js.map +1 -1
  38. package/dist/StorageEncoding.d.ts +7 -1
  39. package/dist/StorageEncoding.d.ts.map +1 -1
  40. package/dist/StorageEncoding.js +8 -2
  41. package/dist/StorageEncoding.js.map +1 -1
  42. package/dist/Table.d.ts +338 -16
  43. package/dist/Table.d.ts.map +1 -1
  44. package/dist/Table.js +30 -2
  45. package/dist/Table.js.map +1 -1
  46. package/dist/Transaction.d.ts.map +1 -1
  47. package/dist/Transaction.js +70 -7
  48. package/dist/Transaction.js.map +1 -1
  49. package/dist/VectorSearchEmulation.d.ts.map +1 -1
  50. package/dist/VectorSearchEmulation.js +4 -3
  51. package/dist/VectorSearchEmulation.js.map +1 -1
  52. package/dist/change-feed/ChangeFeed.d.ts +8 -3
  53. package/dist/change-feed/ChangeFeed.d.ts.map +1 -1
  54. package/dist/change-feed/ChangeFeed.js +76 -9
  55. package/dist/change-feed/ChangeFeed.js.map +1 -1
  56. package/dist/change-feed/CheckpointStore.js +1 -1
  57. package/dist/change-feed/CheckpointStore.js.map +1 -1
  58. package/dist/change-feed/DynamoStreamsClient.d.ts +19 -10
  59. package/dist/change-feed/DynamoStreamsClient.d.ts.map +1 -1
  60. package/dist/change-feed/DynamoStreamsClient.js +24 -14
  61. package/dist/change-feed/DynamoStreamsClient.js.map +1 -1
  62. package/dist/index.d.ts +2 -2
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +1 -1
  65. package/dist/index.js.map +1 -1
  66. package/dist/internal/BoundCrud.d.ts +78 -32
  67. package/dist/internal/BoundCrud.d.ts.map +1 -1
  68. package/dist/internal/BoundCrud.js +25 -0
  69. package/dist/internal/BoundCrud.js.map +1 -1
  70. package/dist/internal/BoundQuery.d.ts +46 -3
  71. package/dist/internal/BoundQuery.d.ts.map +1 -1
  72. package/dist/internal/BoundQuery.js +402 -37
  73. package/dist/internal/BoundQuery.js.map +1 -1
  74. package/dist/internal/BoundVectorQuery.d.ts +6 -0
  75. package/dist/internal/BoundVectorQuery.d.ts.map +1 -1
  76. package/dist/internal/BoundVectorQuery.js +7 -4
  77. package/dist/internal/BoundVectorQuery.js.map +1 -1
  78. package/dist/internal/Capacity.d.ts +46 -5
  79. package/dist/internal/Capacity.d.ts.map +1 -1
  80. package/dist/internal/Capacity.js +177 -26
  81. package/dist/internal/Capacity.js.map +1 -1
  82. package/dist/internal/ClientOptions.d.ts +144 -0
  83. package/dist/internal/ClientOptions.d.ts.map +1 -0
  84. package/dist/internal/ClientOptions.js +290 -0
  85. package/dist/internal/ClientOptions.js.map +1 -0
  86. package/dist/internal/ConditionHolds.d.ts +29 -0
  87. package/dist/internal/ConditionHolds.d.ts.map +1 -0
  88. package/dist/internal/ConditionHolds.js +453 -0
  89. package/dist/internal/ConditionHolds.js.map +1 -0
  90. package/dist/internal/Cursor.d.ts +19 -10
  91. package/dist/internal/Cursor.d.ts.map +1 -1
  92. package/dist/internal/Cursor.js +25 -10
  93. package/dist/internal/Cursor.js.map +1 -1
  94. package/dist/internal/Digest.d.ts +20 -0
  95. package/dist/internal/Digest.d.ts.map +1 -0
  96. package/dist/internal/Digest.js +106 -0
  97. package/dist/internal/Digest.js.map +1 -0
  98. package/dist/internal/DynamoArithmetic.d.ts +33 -0
  99. package/dist/internal/DynamoArithmetic.d.ts.map +1 -0
  100. package/dist/internal/DynamoArithmetic.js +112 -0
  101. package/dist/internal/DynamoArithmetic.js.map +1 -0
  102. package/dist/internal/EntityCombinators.d.ts +23 -8
  103. package/dist/internal/EntityCombinators.d.ts.map +1 -1
  104. package/dist/internal/EntityCombinators.js +6 -2
  105. package/dist/internal/EntityCombinators.js.map +1 -1
  106. package/dist/internal/EntityOps.d.ts +69 -8
  107. package/dist/internal/EntityOps.d.ts.map +1 -1
  108. package/dist/internal/EntityOps.js.map +1 -1
  109. package/dist/internal/EventProjection.d.ts +18 -4
  110. package/dist/internal/EventProjection.d.ts.map +1 -1
  111. package/dist/internal/EventProjection.js +36 -8
  112. package/dist/internal/EventProjection.js.map +1 -1
  113. package/dist/internal/Expr.d.ts +72 -2
  114. package/dist/internal/Expr.d.ts.map +1 -1
  115. package/dist/internal/Expr.js +264 -5
  116. package/dist/internal/Expr.js.map +1 -1
  117. package/dist/internal/ExpressionLimits.d.ts +57 -1
  118. package/dist/internal/ExpressionLimits.d.ts.map +1 -1
  119. package/dist/internal/ExpressionLimits.js +97 -4
  120. package/dist/internal/ExpressionLimits.js.map +1 -1
  121. package/dist/internal/FormGuard.d.ts +52 -0
  122. package/dist/internal/FormGuard.d.ts.map +1 -0
  123. package/dist/internal/FormGuard.js +83 -0
  124. package/dist/internal/FormGuard.js.map +1 -0
  125. package/dist/internal/Hydrate.d.ts.map +1 -1
  126. package/dist/internal/Hydrate.js +2 -1
  127. package/dist/internal/Hydrate.js.map +1 -1
  128. package/dist/internal/InputForm.d.ts +24 -0
  129. package/dist/internal/InputForm.d.ts.map +1 -0
  130. package/dist/internal/InputForm.js +44 -0
  131. package/dist/internal/InputForm.js.map +1 -0
  132. package/dist/internal/InsertStatement.d.ts +15 -0
  133. package/dist/internal/InsertStatement.d.ts.map +1 -0
  134. package/dist/internal/InsertStatement.js +18 -0
  135. package/dist/internal/InsertStatement.js.map +1 -0
  136. package/dist/internal/ItemSize.d.ts +108 -4
  137. package/dist/internal/ItemSize.d.ts.map +1 -1
  138. package/dist/internal/ItemSize.js +190 -3
  139. package/dist/internal/ItemSize.js.map +1 -1
  140. package/dist/internal/MultiProjection.d.ts +7 -2
  141. package/dist/internal/MultiProjection.d.ts.map +1 -1
  142. package/dist/internal/MultiProjection.js +18 -12
  143. package/dist/internal/MultiProjection.js.map +1 -1
  144. package/dist/internal/OperandReaders.d.ts +36 -0
  145. package/dist/internal/OperandReaders.d.ts.map +1 -0
  146. package/dist/internal/OperandReaders.js +176 -0
  147. package/dist/internal/OperandReaders.js.map +1 -0
  148. package/dist/internal/Packed.d.ts.map +1 -1
  149. package/dist/internal/Packed.js +11 -10
  150. package/dist/internal/Packed.js.map +1 -1
  151. package/dist/internal/PathBuilder.d.ts +57 -8
  152. package/dist/internal/PathBuilder.d.ts.map +1 -1
  153. package/dist/internal/PathBuilder.js +98 -24
  154. package/dist/internal/PathBuilder.js.map +1 -1
  155. package/dist/internal/ProjectionEngine.d.ts +196 -3
  156. package/dist/internal/ProjectionEngine.d.ts.map +1 -1
  157. package/dist/internal/ProjectionEngine.js +1251 -86
  158. package/dist/internal/ProjectionEngine.js.map +1 -1
  159. package/dist/internal/Rekey.d.ts +187 -21
  160. package/dist/internal/Rekey.d.ts.map +1 -1
  161. package/dist/internal/Rekey.js +1349 -63
  162. package/dist/internal/Rekey.js.map +1 -1
  163. package/dist/internal/ReturnedItem.d.ts +23 -0
  164. package/dist/internal/ReturnedItem.d.ts.map +1 -0
  165. package/dist/internal/ReturnedItem.js +39 -0
  166. package/dist/internal/ReturnedItem.js.map +1 -0
  167. package/dist/internal/RoundTrip.d.ts +45 -0
  168. package/dist/internal/RoundTrip.d.ts.map +1 -0
  169. package/dist/internal/RoundTrip.js +106 -0
  170. package/dist/internal/RoundTrip.js.map +1 -0
  171. package/dist/internal/SentRequest.d.ts +14 -0
  172. package/dist/internal/SentRequest.d.ts.map +1 -0
  173. package/dist/internal/SentRequest.js +31 -0
  174. package/dist/internal/SentRequest.js.map +1 -0
  175. package/dist/internal/TransactPlan.d.ts.map +1 -1
  176. package/dist/internal/TransactPlan.js +4 -0
  177. package/dist/internal/TransactPlan.js.map +1 -1
  178. package/dist/internal/TransactWriteOps.d.ts +70 -15
  179. package/dist/internal/TransactWriteOps.d.ts.map +1 -1
  180. package/dist/internal/TransactWriteOps.js +166 -112
  181. package/dist/internal/TransactWriteOps.js.map +1 -1
  182. package/dist/internal/TransactableOps.d.ts +230 -27
  183. package/dist/internal/TransactableOps.d.ts.map +1 -1
  184. package/dist/internal/TransactableOps.js +549 -92
  185. package/dist/internal/TransactableOps.js.map +1 -1
  186. package/dist/internal/WriteDiagnosis.d.ts +66 -3
  187. package/dist/internal/WriteDiagnosis.d.ts.map +1 -1
  188. package/dist/internal/WriteDiagnosis.js +261 -15
  189. package/dist/internal/WriteDiagnosis.js.map +1 -1
  190. package/package.json +5 -5
package/dist/Entity.d.ts CHANGED
@@ -7,30 +7,32 @@
7
7
  * Key, Item, Marshalled).
8
8
  */
9
9
  import type { AttributeValue, TransactWriteItem } from "@aws-sdk/client-dynamodb";
10
- import { type ConfiguredModel, type ExtractIdentifier, type ExtractPackedFields } from "@effect-dynamodb/schema/DynamoModel.js";
10
+ import { type ConfiguredModel, type ExtractIdentifier, type ExtractPackedFields, type ExtractUnremovableFields } from "@effect-dynamodb/schema/DynamoModel.js";
11
11
  import * as DynamoSchema from "@effect-dynamodb/schema/DynamoSchema.js";
12
- import { ConcurrentModification, ConditionalCheckFailed, DeleteAppliedButUnreadable, ItemNotDeleted, ItemNotFound, OptimisticLockError, RefNotFound, StaleAppend, TransactionOverflow, UniqueConstraintViolation, UpdateAppliedButUnreadable, ValidationError } from "@effect-dynamodb/schema/Errors.js";
12
+ import { ConcurrentModification, ConditionalCheckFailed, DeleteAppliedButUnreadable, ItemAlreadyExists, ItemNotDeleted, ItemNotFound, OptimisticLockError, RefNotFound, StaleAppend, TransactionOverflow, UniqueConstraintViolation, UpdateAppliedButUnreadable, ValidationError } from "@effect-dynamodb/schema/Errors.js";
13
13
  import type { IndexDefinition, KeyPart } from "@effect-dynamodb/schema/KeyComposer.js";
14
14
  import type { VectorIndexConfig, VectorIndexDefinition } from "@effect-dynamodb/schema/VectorIndex.js";
15
15
  import { DateTime, Effect, Option, Schema, Stream } from "effect";
16
16
  import type { DynamoClient, DynamoClientError } from "./DynamoClient.js";
17
17
  import type { ConditionInput } from "./Expression.js";
18
- import { type Expr } from "./internal/Expr.js";
18
+ import { type Expr, type StoredFormAt } from "./internal/Expr.js";
19
19
  import { countOperators } from "./internal/ExpressionLimits.js";
20
20
  import { type PackedAttributeGuard, type StreamImage } from "./internal/Packed.js";
21
- import { type PathModel } from "./internal/PathBuilder.js";
21
+ import { type PathModel, type StoredBelow } from "./internal/PathBuilder.js";
22
22
  import * as Rekey from "./internal/Rekey.js";
23
+ import { type RawCondition } from "./internal/TransactableOps.js";
23
24
  import { type TransactPlan } from "./internal/TransactPlan.js";
25
+ import { UnstorableValue } from "./Marshaller.js";
24
26
  import * as Query from "./Query.js";
25
27
  import { type TableConfig } from "./Table.js";
26
28
  export type { CascadeIndexConfig, GeneratedIdConfig, RefValue, SoftDeleteConfig, TimeSeriesConfig, TimestampFieldConfig, TimestampsConfig, UniqueConfig, UniqueConstraintDef, UniqueFieldsDef, VersionedConfig, } from "@effect-dynamodb/schema/internal/EntityConfig.js";
27
- export { type CascadeConfig, type CascadeTarget, type DecodeMode, type EntityBase, type EntityDelete, EntityDeleteImpl, EntityDeleteTypeId, type EntityGet, EntityGetImpl, type EntityGetOpts, type EntityOp, EntityOpTypeId, type EntityPut, EntityPutImpl, type EntityPutOpts, type EntityUpdate, EntityUpdateImpl, EntityUpdateTypeId, emptyUpdateState, type PutKind, type ReturnValuesMode, returnValuesMap, type UpdateReturn, type UpdateState, type WithVectors, } from "./internal/EntityOps.js";
28
- import { type EntityDelete, type EntityGet, type EntityPut, type EntityUpdate, type PutKind, type ReturnValuesMode, type UpdateState } from "./internal/EntityOps.js";
29
+ export { type CascadeConfig, type CascadeTarget, type DecodeMode, type EntityBase, type EntityDelete, EntityDeleteImpl, EntityDeleteTypeId, type EntityGet, EntityGetImpl, type EntityGetOpts, type EntityInsert, type EntityOp, EntityOpTypeId, type EntityPut, EntityPutImpl, type EntityPutOpts, type EntityUpdate, EntityUpdateImpl, EntityUpdateTypeId, emptyUpdateState, type PutKind, type ReturnValuesMode, returnValuesMap, type UpdateReturn, type UpdateState, type WithVectors, } from "./internal/EntityOps.js";
30
+ import { type EntityDelete, type EntityGet, type EntityInsert, type EntityPut, type EntityUpdate, type PutKind, type ReturnValuesMode, type UpdateState } from "./internal/EntityOps.js";
29
31
  export { add, append, asItem, asModel, asNative, asRecord, type ConditionPipeable, cascade, clearMap, consistentRead, deleteFromSet, expectedVersion, pathAdd, pathAppend, pathDelete, pathIfNotExists, pathPrepend, pathRemove, pathSet, pathSubtract, project, remove, removeEntries, returnValues, set, subtract, } from "./internal/EntityCombinators.js";
30
32
  import type { GeneratedIdConfig, SoftDeleteConfig, TimeSeriesConfig, TimestampsConfig, UniqueConfig, VersionedConfig } from "@effect-dynamodb/schema/internal/EntityConfig.js";
31
33
  import { type DerivedSchemas, type ResolvedSystemFields } from "@effect-dynamodb/schema/internal/EntitySchemas.js";
32
- import type { AppendInputType, AppendSuccess as AppendSuccessType, EntityInputType, EntityKeyType, EntityRecordType, EntityRefCreateType, EntityRefInputType, EntityRefUpdateType, EntityUpdateType, IndexPkInput, ModelType, PrimaryKeyComposites, RefErrors, VectorErrors, WithGeneratedId } from "@effect-dynamodb/schema/internal/EntityTypes.js";
33
- import { type ConditionPipeable } from "./internal/EntityCombinators.js";
34
+ import type { AppendInputType, AppendRemovableFields, AppendSuccess as AppendSuccessType, EntityInputType, EntityKeyType, EntityRecordType, EntityRefCreateType, EntityRefInputType, EntityRefUpdateType, EntityUpdateType, IndexPkInput, ModelType, PrimaryKeyComposites, RefErrors, RemovableFields, VectorErrors, WithGeneratedId } from "@effect-dynamodb/schema/internal/EntityTypes.js";
35
+ import { type ConditionPipeable, type Removable } from "./internal/EntityCombinators.js";
34
36
  export type { IndexDefinition, KeyPart };
35
37
  /**
36
38
  * Compose a unique-constraint sentinel key, returning `undefined` when any
@@ -72,7 +74,7 @@ export { countOperators };
72
74
  * @typeParam TUnique - Unique constraint definitions
73
75
  * @typeParam TIdentifier - Identifier field name (auto-generated, omitted from Create type)
74
76
  */
75
- export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType extends string = string, TIndexes extends globalThis.Record<string, IndexDefinition> = globalThis.Record<string, IndexDefinition>, TTimestamps extends TimestampsConfig | undefined = TimestampsConfig | undefined, TVersioned extends VersionedConfig | undefined = VersionedConfig | undefined, TSoftDelete extends SoftDeleteConfig | undefined = SoftDeleteConfig | undefined, TUnique extends UniqueConfig | undefined = UniqueConfig | undefined, TRefs extends globalThis.Record<string, AnyRefValue> | undefined = undefined, TIdentifier extends string | undefined = undefined, TTimeSeries extends TimeSeriesConfig<any> | undefined = undefined, TGeneratedId extends GeneratedIdConfig | undefined = undefined, TVectorIndexes extends globalThis.Record<string, VectorIndexConfig> | undefined = undefined, TPackedFields extends string = never> {
77
+ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType extends string = string, TIndexes extends globalThis.Record<string, IndexDefinition> = globalThis.Record<string, IndexDefinition>, TTimestamps extends TimestampsConfig | undefined = TimestampsConfig | undefined, TVersioned extends VersionedConfig | undefined = VersionedConfig | undefined, TSoftDelete extends SoftDeleteConfig | undefined = SoftDeleteConfig | undefined, TUnique extends UniqueConfig | undefined = UniqueConfig | undefined, TRefs extends globalThis.Record<string, AnyRefValue> | undefined = undefined, TIdentifier extends string | undefined = undefined, TTimeSeries extends TimeSeriesConfig<any> | undefined = undefined, TGeneratedId extends GeneratedIdConfig | undefined = undefined, TVectorIndexes extends globalThis.Record<string, VectorIndexConfig> | undefined = undefined, TPackedFields extends string = never, TUnremovable extends string = never> {
76
78
  readonly _tag: "Entity";
77
79
  readonly model: TModel;
78
80
  readonly entityType: TEntityType;
@@ -88,12 +90,34 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
88
90
  readonly vectorIndexes: TVectorIndexes;
89
91
  /** @internal Normalized vector index definitions keyed by logical name. */
90
92
  readonly _vectorIndexes: globalThis.Record<string, VectorIndexDefinition>;
93
+ /**
94
+ * @internal `reembed`'s condition that its inputs are as it read them, or undefined when no
95
+ * condition proving it fits one expression.
96
+ */
97
+ readonly _reembedGuard: (read: globalThis.Record<string, AttributeValue>, definitions: ReadonlyArray<VectorIndexDefinition>, update: {
98
+ readonly names: globalThis.Record<string, string>;
99
+ readonly values: globalThis.Record<string, AttributeValue>;
100
+ }) => {
101
+ readonly expression: string;
102
+ readonly names: globalThis.Record<string, string>;
103
+ readonly values: globalThis.Record<string, AttributeValue>;
104
+ } | undefined;
105
+ /**
106
+ * @internal `[EDD-9140]` for the attributes a table's configuration names (its TTL attribute):
107
+ * throws when a row's reader would take one this entity writes as a sparse map's entry.
108
+ */
109
+ readonly _refuseTableAttributes: (tableConfig: TableConfig) => void;
91
110
  /**
92
111
  * The domain fields stored packed (`storedAs: DynamoModel.Packed(...)`).
93
112
  * Carries the `TPackedFields` type, which narrows expression path builders:
94
113
  * a packed field can be tested only with `exists` / `notExists` as a whole.
95
114
  */
96
115
  readonly _packedFields: ReadonlyArray<TPackedFields>;
116
+ /**
117
+ * @internal Phantom — never read at runtime. Carries the fields
118
+ * `.remove()` refuses by configuration (immutable, sparse map).
119
+ */
120
+ _unremovableFields?(field: TUnremovable): void;
97
121
  /**
98
122
  * @internal Pack, in place, the packed attributes of an item keyed by stored
99
123
  * names (after renames and sparse flattening), before `toAttributeMap`.
@@ -117,6 +141,15 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
117
141
  * inside (`[EDD-9076]`), by domain AND stored name.
118
142
  */
119
143
  readonly _packedGuards: ReadonlyArray<PackedAttributeGuard>;
144
+ /**
145
+ * @internal What a caller's key gives of `names` (the composites it can't be composed without),
146
+ * as a plain object to add to and hand on to a key composition (a geo index's `nearby` filter):
147
+ * its own enumerable properties, and, only where those lack one of `names` (where 1.40.0
148
+ * failed), each it lacks read by name (`keyEntries`). A name whose read threw from a getter the
149
+ * key inherits is held as a property that throws it again when read, so the query it's handed to
150
+ * fails with a `ValidationError` naming it (`UnreadableName`).
151
+ */
152
+ readonly _givenValues: (record: object, names: ReadonlyArray<string>) => globalThis.Record<string, unknown>;
120
153
  /**
121
154
  * @internal Decode a DynamoDB Streams image (DynamoDB JSON with `B` as bytes
122
155
  * or base64, or an unmarshalled item) into an item record — the
@@ -127,13 +160,57 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
127
160
  readonly _resolvedRefs: ReadonlyArray<{
128
161
  readonly fieldName: string;
129
162
  readonly idFieldName: string;
130
- readonly identifierField: string;
163
+ /** The attribute of the referenced entity an id names (`refIdAttribute`). */
164
+ readonly keyField: string;
131
165
  readonly refEntityType: string;
166
+ /** The referenced entity: its `modelSchema` encodes what the ref stores (`refDataOf`). */
167
+ readonly refEntity: {
168
+ readonly schemas: {
169
+ readonly modelSchema: Schema.Top;
170
+ };
171
+ };
132
172
  }>;
133
173
  /** @internal Full decode pipeline: unpack + sparse + rename + schema decode. Used by Batch/Aggregate. */
134
174
  readonly _decodeRecord: (raw: globalThis.Record<string, unknown>) => Effect.Effect<any, ValidationError>;
135
175
  /** @internal Domain field name → stored DynamoDB attribute name (`storedAs` renames). */
136
176
  readonly _resolveDbName: (domainName: string) => string;
177
+ /**
178
+ * @internal What a write of a value at a path stores (#242): a condition's or filter's operand
179
+ * is put in this form (`operandsAsStored`).
180
+ */
181
+ readonly _storedFormAt: StoredFormAt;
182
+ /**
183
+ * @internal The fields stored as sparse maps, one attribute per entry: a `.select()` naming one
184
+ * reads whole rows, since no projection can name them (#238).
185
+ */
186
+ readonly _sparseFieldNames: ReadonlyArray<string>;
187
+ /**
188
+ * @internal A stored row as every read sees it, as a copy: its sparse maps rebuilt, then each
189
+ * renamed field under its domain name (`toDomainView`).
190
+ */
191
+ readonly _toDomainView: (raw: globalThis.Record<string, unknown>) => globalThis.Record<string, unknown>;
192
+ /**
193
+ * @internal The sparse map field a read takes a stored attribute for: an entry's attribute
194
+ * (`<prefix>#<key>`), or the attribute a `field:` rename stores a map under whole.
195
+ */
196
+ readonly _sparseMapOf: (attribute: string) => string | undefined;
197
+ /** @internal The attribute entry `key` of sparse map `field` is stored under (`<prefix>#<key>`, #238). */
198
+ readonly _sparseEntryAttribute: (field: string, key: string) => string;
199
+ /**
200
+ * @internal The attribute a `field:` rename stores sparse map `field` under whole, as `put`
201
+ * stores it, if it's renamed (#238): a read takes it in place of the entries when a row holds it.
202
+ */
203
+ readonly _sparseWholeAttribute: (field: string) => string | undefined;
204
+ /**
205
+ * @internal A condition or filter (domain-named) whose conditions on an entry of a sparse map a
206
+ * `field:` rename stores whole ask the row where it holds the map (#238); any other as given.
207
+ */
208
+ readonly _entryForms: (expr: Expr) => Expr;
209
+ /**
210
+ * @internal The segments below a path's first as they're stored, given the path as written: a
211
+ * property of a struct that renames its keys as it's stored, by its stored name (#238).
212
+ */
213
+ readonly _storedBelow: StoredBelow;
137
214
  /** @internal Entity schema version baked into composed keys. */
138
215
  readonly _entityVersion: number;
139
216
  /**
@@ -154,6 +231,25 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
154
231
  * enforces it across all of them.
155
232
  */
156
233
  readonly _keyForm: (record: globalThis.Record<string, unknown>) => globalThis.Record<string, unknown>;
234
+ /**
235
+ * @internal {@link _keyForm} of a caller's key record, a DOMAIN record: each
236
+ * composite first put into the form `Entity.put` stores it in
237
+ * (`makeCompositeStoredForm`), so the key is the one `put` wrote for that value,
238
+ * the key this entity's own `get` composes. For the key-taking multi-item ops
239
+ * (`Batch.get`, `Batch.write` deletes, `transactGet`, `transactWrite` deletes and
240
+ * condition checks), which hold the caller's key.
241
+ */
242
+ readonly _domainKeyForm: (record: globalThis.Record<string, unknown>) => globalThis.Record<string, unknown>;
243
+ /**
244
+ * @internal What in a caller's DOMAIN key record DynamoDB can't store, as `put` decides it for
245
+ * an item holding those values: each encoded through `inputSchema`'s own field as `put` encodes
246
+ * its input (`encodeOrDecodeEncode`), then judged by the check `put` runs on what it encoded
247
+ * (`unstorableOf`), a `NaN` left to key composition (`EDD-9096`). `undefined` when it all stores;
248
+ * a value that doesn't encode fails with the `ValidationError` `put` fails with. For a path
249
+ * holding an id it fetches by (aggregate ref hydration): no item can be keyed by a value `put`
250
+ * refuses, and its key text may name an item of another value.
251
+ */
252
+ readonly _unstorableKey: (record: globalThis.Record<string, unknown>) => Effect.Effect<UnstorableValue | undefined, ValidationError>;
157
253
  /**
158
254
  * @internal Rename domain field names to their stored DynamoDB attribute
159
255
  * names (`storedAs`), in place. `Entity.put` applies this; the transact/batch
@@ -161,6 +257,16 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
161
257
  * differently-shaped item depending on which API wrote it.
162
258
  */
163
259
  readonly _renameToDynamo: (item: globalThis.Record<string, unknown>) => void;
260
+ /**
261
+ * @internal A whole field as an `UpdateItem` SET writes it: the attribute it's stored in and its
262
+ * stored form (packed where the field is). A cascade writes a target's ref through it (#241).
263
+ */
264
+ readonly _setOf: (field: string, wire: unknown, operation: string) => Effect.Effect<{
265
+ readonly attribute: string;
266
+ readonly value: AttributeValue;
267
+ }, ValidationError>;
268
+ /** @internal The model field a stored attribute holds, for a message naming it. */
269
+ readonly _fieldOfAttribute: (attribute: string) => string;
164
270
  /**
165
271
  * @internal Whether a created item carries the hidden incarnation token
166
272
  * (`__edd_i__`) — every versioned entity.
@@ -170,6 +276,23 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
170
276
  readonly _versionCorruption: (item: Readonly<globalThis.Record<string, unknown>> | undefined, operation: string) => ValidationError | undefined;
171
277
  /** @internal Fill omitted decoding-default fields of a put's input (see `put`). */
172
278
  readonly _fillDecodingDefaults: (input: unknown) => Effect.Effect<unknown, ValidationError>;
279
+ /**
280
+ * Refuses an encoded payload holding a value of a custom declaration that wouldn't read back
281
+ * (`EDD-9126`), or a key value of a field taking both numeric kinds that reads back as the other
282
+ * (`EDD-9128`). For a write path outside this entity's own operations.
283
+ * @internal
284
+ */
285
+ readonly _refuseNotReadBack: (encoded: unknown, operation: string) => Effect.Effect<void, ValidationError>;
286
+ /**
287
+ * @internal The schema a put written whole composes its keys under (#242, `EDD-9162`): an object
288
+ * composing `[object Object]` into a key it composes is refused where it's composed.
289
+ */
290
+ readonly _ownSchema: () => DynamoSchema.DynamoSchema;
291
+ /**
292
+ * @internal Composes each unique sentinel `record` holds every value of under `under`, to refuse
293
+ * an object there before anything is sent (`EDD-9162`); throws what `composeKeysOrFail` takes.
294
+ */
295
+ readonly _composeUniqueSentinels: (under: DynamoSchema.DynamoSchema, record: globalThis.Record<string, unknown>) => void;
173
296
  /** @internal Unique fields a put's input leaves to an index-stored default. */
174
297
  readonly _unsentineledDefaults: (input: unknown) => ReadonlyArray<string>;
175
298
  /**
@@ -193,7 +316,8 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
193
316
  } | undefined;
194
317
  readonly create: boolean;
195
318
  readonly operation: string;
196
- readonly key: globalThis.Record<string, unknown>;
319
+ /** The item's keys, were these system fields what the plan carries over. */
320
+ readonly composeKeys: (carried: globalThis.Record<string, unknown>) => Effect.Effect<globalThis.Record<string, unknown>, ValidationError>;
197
321
  }) => Effect.Effect<PutPlan, ValidationError | DynamoClientError, DynamoClient>;
198
322
  /**
199
323
  * @internal Whether this entity's write contract needs items beyond the one
@@ -212,7 +336,16 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
212
336
  * the standalone update does, which is why the read's outcomes
213
337
  * (`ItemNotFound`, `OptimisticLockError`, …) can surface here.
214
338
  */
215
- readonly _planUpdate: (key: unknown, state: UpdateState) => Effect.Effect<TransactPlan, PlanUpdateError, DynamoClient | TableConfig>;
339
+ readonly _planUpdate: (key: unknown, state: UpdateState,
340
+ /** What {@link _prepareUpdate} decided of `state`. */
341
+ prepared: PreparedUpdate) => Effect.Effect<TransactPlan, PlanUpdateError, DynamoClient | TableConfig>;
342
+ /**
343
+ * @internal What an `update` decides from its own operands, reading nothing: every refusal of
344
+ * its names, operands, payload and the keys the payload composes, and its encoded payload. Run by
345
+ * `Transaction.transactWrite` for every op before any op reads; {@link _planUpdate} plans the
346
+ * update from it. `encoded` is `key` through {@link _encodeKey}.
347
+ */
348
+ readonly _prepareUpdate: (key: unknown, state: UpdateState, encoded: globalThis.Record<string, unknown>) => Effect.Effect<PreparedUpdate, ValidationError, TableConfig>;
216
349
  /**
217
350
  * @internal Compile a `delete` into the transact items it would issue — the
218
351
  * `delete` counterpart of `_planUpdate`. For an entity with `unique`,
@@ -224,7 +357,15 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
224
357
  readonly _planDelete: (key: unknown, opts: {
225
358
  readonly condition: Expr | ConditionInput | undefined;
226
359
  readonly mustExist: boolean;
227
- }) => Effect.Effect<TransactPlan, PlanDeleteError, DynamoClient | TableConfig>;
360
+ },
361
+ /** `key` through {@link _encodeKey}: refused before any op of the transaction reads. */
362
+ encoded: globalThis.Record<string, unknown>) => Effect.Effect<TransactPlan, PlanDeleteError, DynamoClient | TableConfig>;
363
+ /**
364
+ * @internal A key as the entity's own ops take it: encoded through its key schema, and its
365
+ * primary key composed, a composite with no key text a `ValidationError`. What
366
+ * `Transaction.transactWrite` checks of a planned op before any op reads.
367
+ */
368
+ readonly _encodeKey: (key: unknown, operation: string) => Effect.Effect<globalThis.Record<string, unknown>, ValidationError>;
228
369
  /**
229
370
  * @internal Which of this entity's rows are items: a row is live iff the
230
371
  * sort key composed from its own stored composites is its stored sort key.
@@ -243,9 +384,30 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
243
384
  readonly pk: string;
244
385
  readonly sk: string;
245
386
  } | undefined) => Effect.Effect<Rekey.RekeyTally | undefined, DynamoClientError, DynamoClient | TableConfig>;
387
+ /**
388
+ * @internal Where `rekey` moves a projection's outbox item of this read model, without moving it
389
+ * (`keys`: its table's key attributes): `"current"` at its key now, `to` with the read-model
390
+ * row's key now (`rowTo`) for one under other key text, `undefined` for a key this read model's
391
+ * reader doesn't read back.
392
+ */
393
+ readonly _valuelessMove: (row: globalThis.Record<string, AttributeValue>, keys: {
394
+ readonly pk: string;
395
+ readonly sk: string;
396
+ }) => "current" | {
397
+ readonly to: globalThis.Record<string, string>;
398
+ readonly rowTo: {
399
+ readonly pk: string;
400
+ readonly sk: string;
401
+ };
402
+ } | undefined;
403
+ /**
404
+ * @internal Whether `row`, read from this entity's table, is one of its items stored where its
405
+ * own values put it under some key text: its key now or one `rekey` moves from.
406
+ */
407
+ readonly _ownsRow: (row: globalThis.Record<string, AttributeValue>) => boolean;
246
408
  /**
247
409
  * @internal The mark (`__edd_kt__`) a projection's row tombstone or outbox item takes for the
248
- * read-model row at `key` (key form): `KeyText136.markOf`.
410
+ * read-model row at `key` (a domain key record, `_domainKeyForm`): `KeyText136.markOf`.
249
411
  */
250
412
  readonly _keyTextMark: (key: globalThis.Record<string, unknown>) => 2 | undefined;
251
413
  /** @internal Attach model class prototype to a decoded plain object (no-op for Schema.Struct models). */
@@ -254,7 +416,10 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
254
416
  * @internal `create` over a projection tombstone (#154), for the transaction
255
417
  * path — see `overTombstone`.
256
418
  */
257
- readonly _overTombstone: (tableName: string, item: globalThis.Record<string, unknown>) => Effect.Effect<Option.Option<ConditionInput>, DynamoClientError, DynamoClient>;
419
+ readonly _overTombstone: (item: globalThis.Record<string, unknown>) => Effect.Effect<Option.Option<{
420
+ readonly guard: ConditionInput;
421
+ readonly term: RawCondition | undefined;
422
+ }>, DynamoClientError | ValidationError, DynamoClient | TableConfig>;
258
423
  /**
259
424
  * @internal Configure the entity with table schema and tag.
260
425
  * Called by DynamoClient.make() when binding entities to a table.
@@ -306,7 +471,7 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
306
471
  */
307
472
  readonly updateSchema: Schema.Codec<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>>;
308
473
  /** Fetch an item by primary key. Returns a lazy {@link EntityGet} intermediate. */
309
- readonly get: (key: EntityKeyType<TModel, TIndexes>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
474
+ readonly get: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
310
475
  /**
311
476
  * Create or replace an item. Returns a lazy {@link EntityPut} intermediate.
312
477
  *
@@ -323,12 +488,12 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
323
488
  * Begin an update operation on an existing item. Returns a lazy {@link EntityUpdate} intermediate.
324
489
  * Pipe to {@link set} to provide update fields and {@link expectedVersion} for optimistic locking.
325
490
  */
326
- readonly update: (key: EntityKeyType<TModel, TIndexes>) => EntityUpdate<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
491
+ readonly update: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityUpdate<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned> & Removable<RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
327
492
  /**
328
493
  * Delete an item by primary key. Returns a lazy {@link EntityDelete} intermediate.
329
494
  * A unique-constrained entity releases only the sentinels the item owns.
330
495
  */
331
- readonly delete: (key: EntityKeyType<TModel, TIndexes>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable, DynamoClient | TableConfig, void, ModelType<TModel>>;
496
+ readonly delete: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable, DynamoClient | TableConfig, void, ModelType<TModel>>;
332
497
  /**
333
498
  * Create a new item. Fails with `ConditionalCheckFailed` if an item with the same
334
499
  * primary key already exists. Equivalent to `put(input)` with an `attribute_not_exists`
@@ -336,16 +501,24 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
336
501
  * version retained for the key, to continue after it).
337
502
  */
338
503
  readonly create: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => EntityPut<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
504
+ /**
505
+ * Add an item through a PartiQL `INSERT`, which cannot replace one, so a role
506
+ * holding only `dynamodb:PartiQLInsert` can add items and nothing else. Fails
507
+ * with `ItemAlreadyExists` if the key is taken. Sends one write and no reads;
508
+ * a `unique` entity sends an `INSERT`-only transaction. It takes no condition,
509
+ * cannot join a transaction or batch, and is refused on `versioned: { retain: true }`.
510
+ */
511
+ readonly insert: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => EntityInsert<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ItemAlreadyExists | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
339
512
  /**
340
513
  * Update an existing item. Fails with `ConditionalCheckFailed` if the item doesn't exist.
341
514
  * Equivalent to `update(key)` with an automatic `attribute_exists` condition on the PK field.
342
515
  */
343
- readonly patch: (key: EntityKeyType<TModel, TIndexes>) => EntityUpdate<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
516
+ readonly patch: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityUpdate<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned> & Removable<RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
344
517
  /**
345
518
  * Delete an existing item. Fails with `ConditionalCheckFailed` if the item doesn't exist.
346
519
  * Equivalent to `delete(key)` with an automatic `attribute_exists` condition on the PK field.
347
520
  */
348
- readonly deleteIfExists: (key: EntityKeyType<TModel, TIndexes>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | ConditionalCheckFailed, DynamoClient | TableConfig, void, ModelType<TModel>>;
521
+ readonly deleteIfExists: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | ConditionalCheckFailed, DynamoClient | TableConfig, void, ModelType<TModel>>;
349
522
  /**
350
523
  * Create an item, or update the fields the input supplies on an existing one —
351
524
  * immutable fields, `createdAt` and fields the input omits keep their stored
@@ -363,24 +536,24 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
363
536
  */
364
537
  readonly upsert: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => EntityPut<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ValidationError | ItemNotFound | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
365
538
  /** Fetch a specific version snapshot by version number. */
366
- readonly getVersion: (key: EntityKeyType<TModel, TIndexes>, version: number) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
539
+ readonly getVersion: (key: EntityKeyType<TModel, TIndexes, TRefs>, version: number) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
367
540
  /** Query version history for an item. Returns a Query for piping with limit, reverse, collect. */
368
- readonly versions: (key: EntityKeyType<TModel, TIndexes>) => Query.Query<EntityRecordType<TModel, TTimestamps, TVersioned>>;
541
+ readonly versions: (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<EntityRecordType<TModel, TTimestamps, TVersioned>>;
369
542
  /** Restore a soft-deleted item. Recomposes index keys and re-establishes unique sentinels. */
370
- readonly restore: (key: EntityKeyType<TModel, TIndexes>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | ItemNotDeleted | DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ConcurrentModification, DynamoClient | TableConfig>;
543
+ readonly restore: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | ItemNotDeleted | DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ConcurrentModification, DynamoClient | TableConfig>;
371
544
  /**
372
545
  * Permanently remove an item plus all version history and sentinels. Deletes
373
546
  * in `BatchWriteItem` chunks of 25, retrying `UnprocessedItems` with
374
547
  * backoff; not atomic, so a failure says exactly how many items it had
375
548
  * already deleted.
376
549
  */
377
- readonly purge: (key: EntityKeyType<TModel, TIndexes>) => EntityDelete<DynamoClientError | ValidationError, DynamoClient | TableConfig>;
550
+ readonly purge: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | ValidationError, DynamoClient | TableConfig>;
378
551
  /** Soft-deleted item accessors. */
379
552
  readonly deleted: {
380
553
  /** Get a specific soft-deleted item. */
381
- readonly get: (key: EntityKeyType<TModel, TIndexes>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
554
+ readonly get: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
382
555
  /** List soft-deleted items within a partition. */
383
- readonly list: (key: EntityKeyType<TModel, TIndexes>) => Query.Query<EntityRecordType<TModel, TTimestamps, TVersioned>>;
556
+ readonly list: (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<EntityRecordType<TModel, TTimestamps, TVersioned>>;
384
557
  };
385
558
  /**
386
559
  * Append an event to a time-series entity. Atomically updates the "current"
@@ -402,10 +575,10 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
402
575
  * Only available when the entity was built with `timeSeries: { ... }`.
403
576
  */
404
577
  readonly append: [TTimeSeries] extends [TimeSeriesConfig<infer TAI extends Schema.Top>] ? {
405
- (input: AppendInputType<TAI>, condition?: Expr | ConditionInput, skipFollowUp?: false, removeAttrs?: ReadonlyArray<string>): Effect.Effect<{
578
+ (input: AppendInputType<TAI>, condition?: Expr | ConditionInput, skipFollowUp?: false, removeAttrs?: ReadonlyArray<AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>>): Effect.Effect<{
406
579
  readonly current: ModelType<TModel>;
407
580
  }, DynamoClientError | ValidationError | StaleAppend | ConditionalCheckFailed | ConcurrentModification, DynamoClient | TableConfig>;
408
- (input: AppendInputType<TAI>, condition: Expr | ConditionInput | undefined, skipFollowUp: true, removeAttrs?: ReadonlyArray<string>): Effect.Effect<void, DynamoClientError | ValidationError | StaleAppend | ConcurrentModification, DynamoClient | TableConfig>;
581
+ (input: AppendInputType<TAI>, condition: Expr | ConditionInput | undefined, skipFollowUp: true, removeAttrs?: ReadonlyArray<AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>>): Effect.Effect<void, DynamoClientError | ValidationError | StaleAppend | ConcurrentModification, DynamoClient | TableConfig>;
409
582
  } : never;
410
583
  /**
411
584
  * Query the event history of a time-series entity partition. Returns a
@@ -413,7 +586,7 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
413
586
  *
414
587
  * Only available when the entity was built with `timeSeries: { ... }`.
415
588
  */
416
- readonly history: [TTimeSeries] extends [TimeSeriesConfig<any>] ? (key: EntityKeyType<TModel, TIndexes>) => Query.Query<ModelType<TModel>> : never;
589
+ readonly history: [TTimeSeries] extends [TimeSeriesConfig<any>] ? (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<ModelType<TModel>> : never;
417
590
  /**
418
591
  * Set combinator pre-bound to this entity's update type.
419
592
  *
@@ -539,7 +712,7 @@ type HistoryOrderByOperand<M, K extends string> = K extends keyof M ? [M[K]] ext
539
712
  * silently does nothing.
540
713
  */
541
714
  export type VectorIndexNames<TVectorIndexes> = TVectorIndexes extends globalThis.Record<string, VectorIndexConfig> ? keyof TVectorIndexes & string : never;
542
- export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalThis.Record<string, IndexDefinition>, TRefs extends globalThis.Record<string, AnyRefValue> | undefined, TKey = EntityKeyType<TModel, TIndexes>, TTimeSeries extends TimeSeriesConfig<any> | undefined = undefined, TTimestamps extends TimestampsConfig | undefined = undefined, TVersioned extends VersionedConfig | undefined = undefined, TGeneratedId extends GeneratedIdConfig | undefined = undefined, TVectorIndexes extends globalThis.Record<string, VectorIndexConfig> | undefined = undefined, TPackedFields extends string = never> {
715
+ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalThis.Record<string, IndexDefinition>, TRefs extends globalThis.Record<string, AnyRefValue> | undefined, TKey = EntityKeyType<TModel, TIndexes, TRefs>, TTimeSeries extends TimeSeriesConfig<any> | undefined = undefined, TTimestamps extends TimestampsConfig | undefined = undefined, TVersioned extends VersionedConfig | undefined = undefined, TGeneratedId extends GeneratedIdConfig | undefined = undefined, TVectorIndexes extends globalThis.Record<string, VectorIndexConfig> | undefined = undefined, TPackedFields extends string = never, TUnremovable extends string = never> {
543
716
  /**
544
717
  * Fetch an item by primary key.
545
718
  *
@@ -573,6 +746,14 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
573
746
  * primary key already exists. Returns a fluent {@link BoundPut}.
574
747
  */
575
748
  readonly create: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => import("./internal/BoundCrud.js").BoundPut<ModelType<TModel>, ModelType<TModel>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>, TPackedFields>;
749
+ /**
750
+ * Add an item through a PartiQL `INSERT`, which cannot replace one, so a role
751
+ * holding only `dynamodb:PartiQLInsert` can add items and nothing else. Fails
752
+ * with `ItemAlreadyExists` if the key is taken. Sends one write and no reads;
753
+ * a `unique` entity sends an `INSERT`-only transaction. It takes no condition,
754
+ * cannot join a transaction or batch, and is refused on `versioned: { retain: true }`.
755
+ */
756
+ readonly insert: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => import("./internal/BoundCrud.js").BoundInsert<ModelType<TModel>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ItemAlreadyExists | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>>;
576
757
  /**
577
758
  * Begin an update on an existing item. Returns a fluent {@link BoundUpdate} — chain
578
759
  * `.set(...)`, `.remove(...)`, `.add(...)`, `.condition(...)`, `.expectedVersion(...)`,
@@ -582,7 +763,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
582
763
  * yield* db.entities.Tasks.update({ id }).set(updates).expectedVersion(3)
583
764
  * ```
584
765
  */
585
- readonly update: (key: TKey) => import("./internal/BoundCrud.js").BoundUpdate<ModelType<TModel>, ModelType<TModel>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>, TPackedFields>;
766
+ readonly update: (key: TKey) => import("./internal/BoundCrud.js").BoundUpdate<ModelType<TModel>, ModelType<TModel>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>, TPackedFields, RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>>;
586
767
  /**
587
768
  * Delete an item by primary key. Returns a fluent {@link BoundDelete} — yield to execute,
588
769
  * chain `.condition(...)` and/or `.returnValues(...)`.
@@ -609,7 +790,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
609
790
  * yield* db.entities.Tasks.patch({ id }).set(updates)
610
791
  * ```
611
792
  */
612
- readonly patch: (key: TKey) => import("./internal/BoundCrud.js").BoundUpdate<ModelType<TModel>, ModelType<TModel>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>, TPackedFields>;
793
+ readonly patch: (key: TKey) => import("./internal/BoundCrud.js").BoundUpdate<ModelType<TModel>, ModelType<TModel>, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>, TPackedFields, RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>>;
613
794
  /** Delete an existing item, fails if not found. Returns a fluent {@link BoundDelete}. */
614
795
  readonly deleteIfExists: (key: TKey) => import("./internal/BoundCrud.js").BoundDelete<ModelType<TModel>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | ConditionalCheckFailed, void, TPackedFields>;
615
796
  /** Fetch a specific version snapshot by version number. */
@@ -677,7 +858,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
677
858
  */
678
859
  readonly append: [TTimeSeries] extends [TimeSeriesConfig<infer TAI extends Schema.Top>] ? (input: AppendInputType<TAI>) => import("./internal/BoundCrud.js").BoundAppend<ModelType<TModel>, {
679
860
  readonly current: ModelType<TModel>;
680
- }, DynamoClientError | ValidationError | StaleAppend | ConditionalCheckFailed | ConcurrentModification, DynamoClientError | ValidationError | StaleAppend | ConcurrentModification, TPackedFields> : never;
861
+ }, DynamoClientError | ValidationError | StaleAppend | ConditionalCheckFailed | ConcurrentModification, DynamoClientError | ValidationError | StaleAppend | ConcurrentModification, TPackedFields, AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>> : never;
681
862
  /**
682
863
  * Query the event history of a time-series entity partition. Returns a
683
864
  * {@link import("./internal/BoundQuery.js").BoundQuery} auto-scoped to event
@@ -835,7 +1016,7 @@ export declare const make: <TModel extends Schema.Top, const TEntityType extends
835
1016
  readonly model: TModel | ConfiguredModel<TModel, TAttrs>;
836
1017
  readonly entityType: TEntityType;
837
1018
  readonly primaryKey: TPrimaryKey;
838
- readonly indexes?: TGsiIndexes & EntityIndexesGuard<TModel, TRefs, TGsiIndexes, TPrimaryKey>;
1019
+ readonly indexes?: TGsiIndexes & EntityIndexesGuard<TModel, TRefs, TGsiIndexes, TPrimaryKey, TVersioned>;
839
1020
  readonly timestamps?: TTimestamps;
840
1021
  readonly versioned?: TVersioned;
841
1022
  readonly softDelete?: TSoftDelete;
@@ -844,7 +1025,24 @@ export declare const make: <TModel extends Schema.Top, const TEntityType extends
844
1025
  readonly timeSeries?: TTimeSeries & AppendInputFields<TModel, TTimeSeries>;
845
1026
  readonly generatedId?: TGeneratedId;
846
1027
  readonly vectorIndexes?: TVectorIndexes;
847
- }) => Entity<TModel, TEntityType, NormalizedIndexes<TPrimaryKey, TGsiIndexes>, TTimestamps, TVersioned, TSoftDelete, TUnique, RefsOrNone<TRefs>, ExtractIdentifier<ConfiguredModel<TModel, TAttrs>>, TTimeSeries, TGeneratedId, TVectorIndexes, ExtractPackedFields<ConfiguredModel<TModel, TAttrs>>>;
1028
+ }) => Entity<TModel, TEntityType, NormalizedIndexes<TPrimaryKey, TGsiIndexes>, TTimestamps, TVersioned, TSoftDelete, TUnique, RefsOrNone<TRefs>, ExtractIdentifier<ConfiguredModel<TModel, TAttrs>>, TTimeSeries, TGeneratedId, TVectorIndexes, ExtractPackedFields<ConfiguredModel<TModel, TAttrs>>, ExtractUnremovableFields<ConfiguredModel<TModel, TAttrs>>>;
1029
+ /**
1030
+ * @internal A ref's id as the stored ref holds it, as a value of the referenced entity's key (#241).
1031
+ * The stored ref is the referenced item in its entity's stored form ({@link refDataOf}), while a
1032
+ * `${field}Id` is keyed as it's given, so a key stored in another form (a date stored as epoch
1033
+ * milliseconds) is read back through that entity's own field. `None` when the stored value is no
1034
+ * value of the key (a row written otherwise), which a caller reads as it's stored. What `rekey`
1035
+ * judges a row's index keys by ({@link storedRefId}) and a `.within()` row check reads a stored
1036
+ * ref's id by.
1037
+ */
1038
+ export declare const storedRefIdOf: (ref: {
1039
+ readonly keyField: string;
1040
+ readonly refEntity: {
1041
+ readonly schemas: {
1042
+ readonly modelSchema: Schema.Top;
1043
+ };
1044
+ };
1045
+ }, stored: unknown) => Option.Option<unknown>;
848
1046
  /**
849
1047
  * Promote a pure `@effect-dynamodb/schema` {@link EntityDefinition} into a full
850
1048
  * operational runtime {@link Entity}, attaching CRUD/query operations. The
@@ -873,7 +1071,7 @@ export declare const fromDefinition: (def: EntityDefinition) => Entity;
873
1071
  *
874
1072
  * @internal Used by `DynamoClient.make()` to bind entities.
875
1073
  */
876
- export declare const bind: <TModel extends Schema.Top, TEntityType extends string, TIndexes extends globalThis.Record<string, IndexDefinition>, TTimestamps extends TimestampsConfig | undefined, TVersioned extends VersionedConfig | undefined, TSoftDelete extends SoftDeleteConfig | undefined, TUnique extends UniqueConfig | undefined, TRefs extends globalThis.Record<string, AnyRefValue> | undefined, TIdentifier extends string | undefined, TTimeSeries extends TimeSeriesConfig<any> | undefined = undefined, TGeneratedId extends GeneratedIdConfig | undefined = undefined, TVectorIndexes extends globalThis.Record<string, VectorIndexConfig> | undefined = undefined, TPackedFields extends string = never>(entity: Entity<TModel, TEntityType, TIndexes, TTimestamps, TVersioned, TSoftDelete, TUnique, TRefs, TIdentifier, TTimeSeries, TGeneratedId, TVectorIndexes, TPackedFields>) => Effect.Effect<BoundEntity<TModel, TIndexes, TRefs, EntityKeyType<TModel, TIndexes>, TTimeSeries, TTimestamps, TVersioned, TGeneratedId, TVectorIndexes, TPackedFields>, never, DynamoClient | TableConfig>;
1074
+ export declare const bind: <TModel extends Schema.Top, TEntityType extends string, TIndexes extends globalThis.Record<string, IndexDefinition>, TTimestamps extends TimestampsConfig | undefined, TVersioned extends VersionedConfig | undefined, TSoftDelete extends SoftDeleteConfig | undefined, TUnique extends UniqueConfig | undefined, TRefs extends globalThis.Record<string, AnyRefValue> | undefined, TIdentifier extends string | undefined, TTimeSeries extends TimeSeriesConfig<any> | undefined = undefined, TGeneratedId extends GeneratedIdConfig | undefined = undefined, TVectorIndexes extends globalThis.Record<string, VectorIndexConfig> | undefined = undefined, TPackedFields extends string = never, TUnremovable extends string = never>(entity: Entity<TModel, TEntityType, TIndexes, TTimestamps, TVersioned, TSoftDelete, TUnique, TRefs, TIdentifier, TTimeSeries, TGeneratedId, TVectorIndexes, TPackedFields, TUnremovable>) => Effect.Effect<BoundEntity<TModel, TIndexes, TRefs, EntityKeyType<TModel, TIndexes, TRefs>, TTimeSeries, TTimestamps, TVersioned, TGeneratedId, TVectorIndexes, TPackedFields, TUnremovable>, never, DynamoClient | TableConfig>;
877
1075
  /**
878
1076
  * What planning an update for a transaction can fail with: everything the
879
1077
  * update raises before it writes — its reads (`DynamoClientError`, `ItemNotFound`,
@@ -881,6 +1079,13 @@ export declare const bind: <TModel extends Schema.Top, TEntityType extends strin
881
1079
  * (`ConditionalCheckFailed`), an op too large for one transaction, and a refused op
882
1080
  * (`ValidationError`).
883
1081
  */
1082
+ /**
1083
+ * @internal What `Entity._prepareUpdate` decided of an update, opaque outside the entity that
1084
+ * made it: handed back to its `_planUpdate`.
1085
+ */
1086
+ export interface PreparedUpdate {
1087
+ readonly _preparedUpdate: unique symbol;
1088
+ }
884
1089
  export type PlanUpdateError = DynamoClientError | ValidationError | ConditionalCheckFailed | ItemNotFound | TransactionOverflow | OptimisticLockError | RefNotFound | UniqueConstraintViolation;
885
1090
  /** What planning a delete for a transaction can fail with — see {@link PlanUpdateError}. */
886
1091
  export type PlanDeleteError = DynamoClientError | ValidationError | ConditionalCheckFailed | ItemNotFound | TransactionOverflow;
@@ -986,7 +1191,7 @@ export type Record<E extends {
986
1191
  */
987
1192
  export type Input<E extends {
988
1193
  readonly model: Schema.Top;
989
- }> = E extends Entity<infer M extends Schema.Top, any, any, any, any, any, any, infer R, any, undefined, undefined, undefined, infer _P extends string> ? EntityRefInputType<M, R> : EntityInputType<E["model"]>;
1194
+ }> = E extends Entity<infer M extends Schema.Top, any, any, any, any, any, any, infer R, any, undefined, undefined, undefined, infer _P extends string, any> ? EntityRefInputType<M, R> : EntityInputType<E["model"]>;
990
1195
  /**
991
1196
  * Extract the create type from an Entity — input fields minus the identifier.
992
1197
  * Uses the `identifier` config to determine which field to omit.
@@ -997,7 +1202,7 @@ export type Input<E extends {
997
1202
  export type Create<E extends {
998
1203
  readonly model: Schema.Top;
999
1204
  readonly indexes: any;
1000
- }> = E extends Entity<infer M extends Schema.Top, any, infer I, any, any, any, any, infer R, infer Id, undefined, undefined, undefined, infer _P extends string> ? EntityRefCreateType<M, I, R, Id extends string ? Id : undefined> : Omit<EntityInputType<E["model"]>, PrimaryKeyComposites<E["indexes"]>>;
1205
+ }> = E extends Entity<infer M extends Schema.Top, any, infer I, any, any, any, any, infer R, infer Id, undefined, undefined, undefined, infer _P extends string, any> ? EntityRefCreateType<M, I, R, Id extends string ? Id : undefined> : Omit<EntityInputType<E["model"]>, PrimaryKeyComposites<E["indexes"]>>;
1001
1206
  /**
1002
1207
  * Extract the update type from an Entity. Ref-aware: when refs are present,
1003
1208
  * ref fields are replaced with optional `${field}Id?: string`.
@@ -1007,17 +1212,17 @@ export type Create<E extends {
1007
1212
  export type Update<E extends {
1008
1213
  readonly model: Schema.Top;
1009
1214
  readonly indexes: any;
1010
- }> = E extends Entity<infer M extends Schema.Top, any, infer I, any, any, any, any, infer R, any, undefined, undefined, undefined, infer _P extends string> ? EntityRefUpdateType<M, I, R> : EntityUpdateType<E["model"], E["indexes"]>;
1215
+ }> = E extends Entity<infer M extends Schema.Top, any, infer I, any, any, any, any, infer R, any, undefined, undefined, undefined, infer _P extends string, any> ? EntityRefUpdateType<M, I, R> : EntityUpdateType<E["model"], E["indexes"]>;
1011
1216
  /**
1012
1217
  * Extract the key type from an Entity.
1013
- * Primary index pk + sk composite attributes only.
1218
+ * Primary index pk + sk composite attributes only, a ref's id among them (`projectId`).
1014
1219
  *
1015
1220
  * `Entity.Key<typeof Users>` = `{ userId: string }`
1016
1221
  */
1017
1222
  export type Key<E extends {
1018
1223
  readonly model: Schema.Top;
1019
1224
  readonly indexes: any;
1020
- }> = EntityKeyType<E["model"], E["indexes"]>;
1225
+ }> = E extends Entity<infer M extends Schema.Top, any, infer I, any, any, any, any, infer R, any, any, any, any, infer _P extends string, any> ? EntityKeyType<M, I, R> : EntityKeyType<E["model"], E["indexes"]>;
1021
1226
  /**
1022
1227
  * Extract the full DynamoDB item type (unmarshalled).
1023
1228
  * Record + key attributes + __edd_e__.