effect-dynamodb 1.42.2 → 1.44.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 (221) hide show
  1. package/dist/Aggregate.d.ts +157 -20
  2. package/dist/Aggregate.d.ts.map +1 -1
  3. package/dist/Aggregate.js +1219 -286
  4. package/dist/Aggregate.js.map +1 -1
  5. package/dist/Batch.d.ts +17 -4
  6. package/dist/Batch.d.ts.map +1 -1
  7. package/dist/Batch.js +129 -62
  8. package/dist/Batch.js.map +1 -1
  9. package/dist/BlobGc.d.ts +243 -0
  10. package/dist/BlobGc.d.ts.map +1 -0
  11. package/dist/BlobGc.js +961 -0
  12. package/dist/BlobGc.js.map +1 -0
  13. package/dist/BlobStore.d.ts +83 -0
  14. package/dist/BlobStore.d.ts.map +1 -0
  15. package/dist/BlobStore.js +70 -0
  16. package/dist/BlobStore.js.map +1 -0
  17. package/dist/Collection.d.ts +88 -8
  18. package/dist/Collection.d.ts.map +1 -1
  19. package/dist/Collection.js +22 -26
  20. package/dist/Collection.js.map +1 -1
  21. package/dist/Collections.d.ts +0 -7
  22. package/dist/Collections.d.ts.map +1 -1
  23. package/dist/Collections.js +0 -16
  24. package/dist/Collections.js.map +1 -1
  25. package/dist/DynamoClient.d.ts +68 -35
  26. package/dist/DynamoClient.d.ts.map +1 -1
  27. package/dist/DynamoClient.js +58 -12
  28. package/dist/DynamoClient.js.map +1 -1
  29. package/dist/Entity.d.ts +403 -104
  30. package/dist/Entity.d.ts.map +1 -1
  31. package/dist/Entity.js +1771 -382
  32. package/dist/Entity.js.map +1 -1
  33. package/dist/EventStore.d.ts +323 -77
  34. package/dist/EventStore.d.ts.map +1 -1
  35. package/dist/EventStore.js +473 -96
  36. package/dist/EventStore.js.map +1 -1
  37. package/dist/Offload.d.ts +199 -0
  38. package/dist/Offload.d.ts.map +1 -0
  39. package/dist/Offload.js +120 -0
  40. package/dist/Offload.js.map +1 -0
  41. package/dist/Query.d.ts +132 -59
  42. package/dist/Query.d.ts.map +1 -1
  43. package/dist/Query.js +95 -31
  44. package/dist/Query.js.map +1 -1
  45. package/dist/StorageEncoding.d.ts +62 -15
  46. package/dist/StorageEncoding.d.ts.map +1 -1
  47. package/dist/StorageEncoding.js +108 -24
  48. package/dist/StorageEncoding.js.map +1 -1
  49. package/dist/Table.d.ts +1 -1
  50. package/dist/Table.d.ts.map +1 -1
  51. package/dist/Transaction.d.ts +16 -3
  52. package/dist/Transaction.d.ts.map +1 -1
  53. package/dist/Transaction.js +28 -9
  54. package/dist/Transaction.js.map +1 -1
  55. package/dist/blob/S3BlobStore.d.ts +178 -0
  56. package/dist/blob/S3BlobStore.d.ts.map +1 -0
  57. package/dist/blob/S3BlobStore.js +770 -0
  58. package/dist/blob/S3BlobStore.js.map +1 -0
  59. package/dist/blob/s3.d.ts +122 -0
  60. package/dist/blob/s3.d.ts.map +1 -0
  61. package/dist/blob/s3.js +143 -0
  62. package/dist/blob/s3.js.map +1 -0
  63. package/dist/index.d.ts +9 -3
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +4 -1
  66. package/dist/index.js.map +1 -1
  67. package/dist/internal/AggregateWrite.d.ts +130 -0
  68. package/dist/internal/AggregateWrite.d.ts.map +1 -0
  69. package/dist/internal/AggregateWrite.js +341 -0
  70. package/dist/internal/AggregateWrite.js.map +1 -0
  71. package/dist/internal/BlobCalls.d.ts +70 -0
  72. package/dist/internal/BlobCalls.d.ts.map +1 -0
  73. package/dist/internal/BlobCalls.js +105 -0
  74. package/dist/internal/BlobCalls.js.map +1 -0
  75. package/dist/internal/BlobKeys.d.ts +100 -0
  76. package/dist/internal/BlobKeys.d.ts.map +1 -0
  77. package/dist/internal/BlobKeys.js +135 -0
  78. package/dist/internal/BlobKeys.js.map +1 -0
  79. package/dist/internal/BlobLedger.d.ts +323 -0
  80. package/dist/internal/BlobLedger.d.ts.map +1 -0
  81. package/dist/internal/BlobLedger.js +1012 -0
  82. package/dist/internal/BlobLedger.js.map +1 -0
  83. package/dist/internal/BlobMetadata.d.ts +109 -0
  84. package/dist/internal/BlobMetadata.d.ts.map +1 -0
  85. package/dist/internal/BlobMetadata.js +249 -0
  86. package/dist/internal/BlobMetadata.js.map +1 -0
  87. package/dist/internal/BlobResolver.d.ts +146 -0
  88. package/dist/internal/BlobResolver.d.ts.map +1 -0
  89. package/dist/internal/BlobResolver.js +417 -0
  90. package/dist/internal/BlobResolver.js.map +1 -0
  91. package/dist/internal/BlobStoreContract.d.ts +214 -0
  92. package/dist/internal/BlobStoreContract.d.ts.map +1 -0
  93. package/dist/internal/BlobStoreContract.js +181 -0
  94. package/dist/internal/BlobStoreContract.js.map +1 -0
  95. package/dist/internal/BoundCrud.d.ts +153 -53
  96. package/dist/internal/BoundCrud.d.ts.map +1 -1
  97. package/dist/internal/BoundCrud.js +27 -5
  98. package/dist/internal/BoundCrud.js.map +1 -1
  99. package/dist/internal/BoundQuery.d.ts +49 -33
  100. package/dist/internal/BoundQuery.d.ts.map +1 -1
  101. package/dist/internal/BoundQuery.js +8 -2
  102. package/dist/internal/BoundQuery.js.map +1 -1
  103. package/dist/internal/BoundVectorQuery.d.ts +59 -25
  104. package/dist/internal/BoundVectorQuery.d.ts.map +1 -1
  105. package/dist/internal/BoundVectorQuery.js +38 -17
  106. package/dist/internal/BoundVectorQuery.js.map +1 -1
  107. package/dist/internal/Capacity.d.ts +17 -2
  108. package/dist/internal/Capacity.d.ts.map +1 -1
  109. package/dist/internal/Capacity.js +47 -9
  110. package/dist/internal/Capacity.js.map +1 -1
  111. package/dist/internal/ConditionHolds.d.ts.map +1 -1
  112. package/dist/internal/ConditionHolds.js +2 -8
  113. package/dist/internal/ConditionHolds.js.map +1 -1
  114. package/dist/internal/CredentialRefusal.d.ts.map +1 -1
  115. package/dist/internal/CredentialRefusal.js +4 -0
  116. package/dist/internal/CredentialRefusal.js.map +1 -1
  117. package/dist/internal/Digest.d.ts +4 -3
  118. package/dist/internal/Digest.d.ts.map +1 -1
  119. package/dist/internal/Digest.js +25 -82
  120. package/dist/internal/Digest.js.map +1 -1
  121. package/dist/internal/EntityCombinators.d.ts +93 -45
  122. package/dist/internal/EntityCombinators.d.ts.map +1 -1
  123. package/dist/internal/EntityCombinators.js +42 -7
  124. package/dist/internal/EntityCombinators.js.map +1 -1
  125. package/dist/internal/EntityOps.d.ts +47 -6
  126. package/dist/internal/EntityOps.d.ts.map +1 -1
  127. package/dist/internal/EntityOps.js +30 -10
  128. package/dist/internal/EntityOps.js.map +1 -1
  129. package/dist/internal/EventProjection.d.ts +99 -25
  130. package/dist/internal/EventProjection.d.ts.map +1 -1
  131. package/dist/internal/EventProjection.js +124 -33
  132. package/dist/internal/EventProjection.js.map +1 -1
  133. package/dist/internal/ExpressionLimits.d.ts +22 -3
  134. package/dist/internal/ExpressionLimits.d.ts.map +1 -1
  135. package/dist/internal/ExpressionLimits.js +46 -7
  136. package/dist/internal/ExpressionLimits.js.map +1 -1
  137. package/dist/internal/GcSupport.d.ts +258 -0
  138. package/dist/internal/GcSupport.d.ts.map +1 -0
  139. package/dist/internal/GcSupport.js +284 -0
  140. package/dist/internal/GcSupport.js.map +1 -0
  141. package/dist/internal/ItemSize.d.ts +7 -1
  142. package/dist/internal/ItemSize.d.ts.map +1 -1
  143. package/dist/internal/ItemSize.js +13 -5
  144. package/dist/internal/ItemSize.js.map +1 -1
  145. package/dist/internal/MemoryBlobStore.d.ts +203 -0
  146. package/dist/internal/MemoryBlobStore.d.ts.map +1 -0
  147. package/dist/internal/MemoryBlobStore.js +623 -0
  148. package/dist/internal/MemoryBlobStore.js.map +1 -0
  149. package/dist/internal/MultiProjection.d.ts +56 -28
  150. package/dist/internal/MultiProjection.d.ts.map +1 -1
  151. package/dist/internal/MultiProjection.js +9 -3
  152. package/dist/internal/MultiProjection.js.map +1 -1
  153. package/dist/internal/Multipart.d.ts +96 -0
  154. package/dist/internal/Multipart.d.ts.map +1 -0
  155. package/dist/internal/Multipart.js +143 -0
  156. package/dist/internal/Multipart.js.map +1 -0
  157. package/dist/internal/OffloadChange.d.ts +187 -0
  158. package/dist/internal/OffloadChange.d.ts.map +1 -0
  159. package/dist/internal/OffloadChange.js +391 -0
  160. package/dist/internal/OffloadChange.js.map +1 -0
  161. package/dist/internal/OffloadInput.d.ts +141 -0
  162. package/dist/internal/OffloadInput.d.ts.map +1 -0
  163. package/dist/internal/OffloadInput.js +236 -0
  164. package/dist/internal/OffloadInput.js.map +1 -0
  165. package/dist/internal/OffloadRead.d.ts +140 -0
  166. package/dist/internal/OffloadRead.d.ts.map +1 -0
  167. package/dist/internal/OffloadRead.js +369 -0
  168. package/dist/internal/OffloadRead.js.map +1 -0
  169. package/dist/internal/OffloadTypes.d.ts +182 -0
  170. package/dist/internal/OffloadTypes.d.ts.map +1 -0
  171. package/dist/internal/OffloadTypes.js +15 -0
  172. package/dist/internal/OffloadTypes.js.map +1 -0
  173. package/dist/internal/OffloadValues.d.ts +87 -0
  174. package/dist/internal/OffloadValues.d.ts.map +1 -0
  175. package/dist/internal/OffloadValues.js +114 -0
  176. package/dist/internal/OffloadValues.js.map +1 -0
  177. package/dist/internal/OffloadWrite.d.ts +267 -0
  178. package/dist/internal/OffloadWrite.d.ts.map +1 -0
  179. package/dist/internal/OffloadWrite.js +766 -0
  180. package/dist/internal/OffloadWrite.js.map +1 -0
  181. package/dist/internal/Packed.d.ts +58 -23
  182. package/dist/internal/Packed.d.ts.map +1 -1
  183. package/dist/internal/Packed.js +108 -33
  184. package/dist/internal/Packed.js.map +1 -1
  185. package/dist/internal/ProjectionEngine.d.ts +28 -3
  186. package/dist/internal/ProjectionEngine.d.ts.map +1 -1
  187. package/dist/internal/ProjectionEngine.js +47 -9
  188. package/dist/internal/ProjectionEngine.js.map +1 -1
  189. package/dist/internal/RangePlanner.d.ts +3 -6
  190. package/dist/internal/RangePlanner.d.ts.map +1 -1
  191. package/dist/internal/RangePlanner.js +3 -29
  192. package/dist/internal/RangePlanner.js.map +1 -1
  193. package/dist/internal/Rekey.d.ts +16 -0
  194. package/dist/internal/Rekey.d.ts.map +1 -1
  195. package/dist/internal/Rekey.js +31 -2
  196. package/dist/internal/Rekey.js.map +1 -1
  197. package/dist/internal/StoredPointer.d.ts +19 -0
  198. package/dist/internal/StoredPointer.d.ts.map +1 -0
  199. package/dist/internal/StoredPointer.js +59 -0
  200. package/dist/internal/StoredPointer.js.map +1 -0
  201. package/dist/internal/TransactPlan.d.ts +18 -1
  202. package/dist/internal/TransactPlan.d.ts.map +1 -1
  203. package/dist/internal/TransactPlan.js +50 -10
  204. package/dist/internal/TransactPlan.js.map +1 -1
  205. package/dist/internal/TransactWriteOps.d.ts +33 -12
  206. package/dist/internal/TransactWriteOps.d.ts.map +1 -1
  207. package/dist/internal/TransactWriteOps.js +49 -19
  208. package/dist/internal/TransactWriteOps.js.map +1 -1
  209. package/dist/internal/TransactableOps.d.ts +58 -11
  210. package/dist/internal/TransactableOps.d.ts.map +1 -1
  211. package/dist/internal/TransactableOps.js +95 -19
  212. package/dist/internal/TransactableOps.js.map +1 -1
  213. package/dist/internal/Utf8Order.d.ts +21 -0
  214. package/dist/internal/Utf8Order.d.ts.map +1 -0
  215. package/dist/internal/Utf8Order.js +44 -0
  216. package/dist/internal/Utf8Order.js.map +1 -0
  217. package/dist/internal/WriteDiagnosis.d.ts +7 -1
  218. package/dist/internal/WriteDiagnosis.d.ts.map +1 -1
  219. package/dist/internal/WriteDiagnosis.js +12 -16
  220. package/dist/internal/WriteDiagnosis.js.map +1 -1
  221. package/package.json +15 -4
package/dist/Entity.d.ts CHANGED
@@ -7,31 +7,38 @@
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, type ExtractUnremovableFields } from "@effect-dynamodb/schema/DynamoModel.js";
10
+ import { type ConfiguredModel, type ExtractIdentifier, type ExtractOffloadFields, type ExtractPackedFields, type ExtractUnremovableFields, type NoOffload, type OffloadFields } from "@effect-dynamodb/schema/DynamoModel.js";
11
11
  import * as DynamoSchema from "@effect-dynamodb/schema/DynamoSchema.js";
12
- import { ConcurrentModification, ConditionalCheckFailed, DeleteAppliedButUnreadable, ItemAlreadyExists, ItemNotDeleted, ItemNotFound, OptimisticLockError, RefNotFound, StaleAppend, TransactionOverflow, UniqueConstraintViolation, UpdateAppliedButUnreadable, ValidationError } from "@effect-dynamodb/schema/Errors.js";
12
+ import { type BlobStoreError, 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
- import { DateTime, Effect, Option, Schema, Stream } from "effect";
15
+ import { Context, DateTime, Effect, Option, Schema, type Semaphore, Stream } from "effect";
16
+ import { SecureRandom } from "effect/crypto";
16
17
  import type { DynamoClient, DynamoClientError } from "./DynamoClient.js";
17
18
  import type { ConditionInput } from "./Expression.js";
18
19
  import { type Expr, type StoredFormAt } from "./internal/Expr.js";
19
20
  import { countOperators } from "./internal/ExpressionLimits.js";
21
+ import type { StreamRecordLike } from "./internal/OffloadChange.js";
22
+ import * as OffloadChange from "./internal/OffloadChange.js";
23
+ import * as OffloadRead from "./internal/OffloadRead.js";
24
+ import type { DeleteOpStateOf, OpStateOf, StateOf, WithBinaryInput } from "./internal/OffloadTypes.js";
25
+ import * as OffloadWrite from "./internal/OffloadWrite.js";
20
26
  import { type PackedAttributeGuard, type StreamImage } from "./internal/Packed.js";
21
27
  import { type PathModel, type StoredBelow } from "./internal/PathBuilder.js";
22
28
  import * as Rekey from "./internal/Rekey.js";
23
29
  import { type RawCondition } from "./internal/TransactableOps.js";
24
30
  import { type TransactPlan } from "./internal/TransactPlan.js";
25
31
  import { UnstorableValue } from "./Marshaller.js";
32
+ import type { NoOffloadState, OffloadModes, OffloadState, ResolveModes, View } from "./Offload.js";
26
33
  import * as Query from "./Query.js";
27
34
  import { type TableConfig } from "./Table.js";
28
- export type { CascadeIndexConfig, GeneratedIdConfig, RefValue, SoftDeleteConfig, TimeSeriesConfig, TimestampFieldConfig, TimestampsConfig, UniqueConfig, UniqueConstraintDef, UniqueFieldsDef, VersionedConfig, } from "@effect-dynamodb/schema/internal/EntityConfig.js";
35
+ export type { CascadeIndexConfig, GeneratedIdConfig, OffloadConfig, RefValue, ResolvedOffload, SoftDeleteConfig, TimeSeriesConfig, TimestampFieldConfig, TimestampsConfig, UniqueConfig, UniqueConstraintDef, UniqueFieldsDef, VersionedConfig, } from "@effect-dynamodb/schema/internal/EntityConfig.js";
29
36
  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
37
  import { type EntityDelete, type EntityGet, type EntityInsert, type EntityPut, type EntityUpdate, type PutKind, type ReturnValuesMode, type UpdateState } from "./internal/EntityOps.js";
31
- export { add, append, asItem, asModel, asNative, asRecord, type ConditionPipeable, cascade, clearMap, consistentRead, deleteFromSet, expectedVersion, keepRefs, pathAdd, pathAppend, pathDelete, pathIfNotExists, pathPrepend, pathRemove, pathSet, pathSubtract, project, remove, removeEntries, returnValues, set, subtract, } from "./internal/EntityCombinators.js";
32
- import type { GeneratedIdConfig, SoftDeleteConfig, TimeSeriesConfig, TimestampsConfig, UniqueConfig, VersionedConfig } from "@effect-dynamodb/schema/internal/EntityConfig.js";
38
+ export { add, append, asItem, asModel, asNative, asRecord, type ConditionPipeable, cascade, clearMap, consistentRead, deleteFromSet, expectedVersion, keepRefs, offloaded, pathAdd, pathAppend, pathDelete, pathIfNotExists, pathPrepend, pathRemove, pathSet, pathSubtract, project, remove, removeEntries, returnValues, set, subtract, } from "./internal/EntityCombinators.js";
39
+ import type { GeneratedIdConfig, OffloadConfig, ResolvedOffload, SoftDeleteConfig, TimeSeriesConfig, TimestampsConfig, UniqueConfig, VersionedConfig } from "@effect-dynamodb/schema/internal/EntityConfig.js";
33
40
  import { type DerivedSchemas, type ResolvedSystemFields } from "@effect-dynamodb/schema/internal/EntitySchemas.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";
41
+ import type { AppendInputType, AppendRemovableFields, AppendSuccess as AppendSuccessType, DefaultOffloadModes, EntityInputType, EntityKeyType, EntityRecordType, EntityRefCreateType, EntityRefInputType, EntityRefUpdateType, EntityUpdateType, IndexPkInput, ModelType, OffloadMode, PrimaryKeyComposites, ReadBlobErrors, RefErrors, RemovableFields, ResolvedOffloadModes, VectorErrors, WithGeneratedId, WriteBlobErrors } from "@effect-dynamodb/schema/internal/EntityTypes.js";
35
42
  import { type ConditionPipeable, type Removable } from "./internal/EntityCombinators.js";
36
43
  export type { IndexDefinition, KeyPart };
37
44
  /**
@@ -74,7 +81,7 @@ export { countOperators };
74
81
  * @typeParam TUnique - Unique constraint definitions
75
82
  * @typeParam TIdentifier - Identifier field name (auto-generated, omitted from Create type)
76
83
  */
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> {
84
+ 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, TOffload extends OffloadFields = NoOffload> {
78
85
  readonly _tag: "Entity";
79
86
  readonly model: TModel;
80
87
  readonly entityType: TEntityType;
@@ -88,6 +95,19 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
88
95
  readonly generatedId: TGeneratedId;
89
96
  /** Vector index declarations as authored (see `DESIGN.md §14`). */
90
97
  readonly vectorIndexes: TVectorIndexes;
98
+ /**
99
+ * The resolved offload settings (#179): `itemBudget` and `prefix` from
100
+ * `Entity.make({ offload })`, and the domain names of the `overflow`
101
+ * (`Packed({ external })`) and `binary` (`External()`) fields. `undefined`
102
+ * when the entity offloads nothing.
103
+ */
104
+ readonly offload: ResolvedOffload | undefined;
105
+ /**
106
+ * @internal Type-only (never set at runtime): the domain names of the fields
107
+ * this entity offloads, by kind ({@link NoOffload} when none) — what the
108
+ * operation types add `BlobStoreError` from (#179, §9.1, §9.3).
109
+ */
110
+ readonly _offloadFields?: TOffload | undefined;
91
111
  /** @internal Normalized vector index definitions keyed by logical name. */
92
112
  readonly _vectorIndexes: globalThis.Record<string, VectorIndexDefinition>;
93
113
  /**
@@ -108,9 +128,10 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
108
128
  */
109
129
  readonly _refuseTableAttributes: (tableConfig: TableConfig) => void;
110
130
  /**
111
- * The domain fields stored packed (`storedAs: DynamoModel.Packed(...)`).
112
- * Carries the `TPackedFields` type, which narrows expression path builders:
113
- * a packed field can be tested only with `exists` / `notExists` as a whole.
131
+ * The domain fields stored packed (`storedAs: DynamoModel.Packed(...)`) or
132
+ * External (`storedAs: DynamoModel.External(...)`). Carries the
133
+ * `TPackedFields` type, which narrows expression path builders: such a field
134
+ * can be tested only with `exists` / `notExists` as a whole.
114
135
  */
115
136
  readonly _packedFields: ReadonlyArray<TPackedFields>;
116
137
  /**
@@ -155,7 +176,70 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
155
176
  * or base64, or an unmarshalled item) into an item record — the
156
177
  * implementation of {@link decodeMarshalledItem}.
157
178
  */
158
- readonly _decodeImage: (image: StreamImage) => Effect.Effect<unknown, ValidationError>;
179
+ readonly _decodeImage: (image: StreamImage, modes?: OffloadRead.Modes) => Effect.Effect<unknown, ValidationError | BlobStoreError>;
180
+ /**
181
+ * @internal Decode a DynamoDB Streams record — both images, and the change
182
+ * to each offloaded field (#179, design §10.3) — the implementation of
183
+ * {@link decodeStreamRecord}.
184
+ */
185
+ readonly _decodeStreamRecord: (record: StreamRecordLike, modes: OffloadRead.Modes) => Effect.Effect<Option.Option<EntityChange<unknown>>, ValidationError | BlobStoreError>;
186
+ /**
187
+ * @internal Load, in place, a batch of stored-name rows (#179): unpack every
188
+ * stored-form attribute and resolve blob pointers per `options.modes` — see
189
+ * `OffloadRead.loadRows`. A query's page prefetch runs it over a window.
190
+ * `permits`: store-read permits shared with the caller's other loads running
191
+ * at the same time (`GeoIndex.nearby`'s parallel queries), so their reads in
192
+ * flight stay within the store's `readConcurrency`.
193
+ */
194
+ readonly _loadRows: (rows: ReadonlyArray<globalThis.Record<string, unknown>>, options: {
195
+ readonly operation: string;
196
+ readonly modes: OffloadRead.Modes;
197
+ readonly raw?: boolean | undefined;
198
+ readonly permits?: Semaphore.Semaphore | undefined;
199
+ }) => Effect.Effect<void, ValidationError | BlobStoreError>;
200
+ /** @internal The stored attributes {@link _loadRows} may rewrite. */
201
+ readonly _readAttributes: ReadonlyArray<string>;
202
+ /** @internal True iff the entity offloads a field (#179). */
203
+ readonly _offloads: boolean;
204
+ /**
205
+ * @internal The context this entity's operations run in when it is bound in
206
+ * `context` — by {@link bind}, or by a binding over the entity from another
207
+ * package (`GeoIndex.bind`). First the configuration checks where its
208
+ * registries are first resolvable (#147, #179): a codec its `Packed` fields
209
+ * name must be registered (`[EDD-9078]`), an offloaded field needs a schema
210
+ * setting `escapeKeys: true` (`[EDD-9146]`) and a blob store (`[EDD-9115]`),
211
+ * each thrown as the defect naming `where`. Then a default `SecureRandom`
212
+ * service is bundled when `context` has none, which a `generatedId` put
213
+ * draws its UUID from.
214
+ */
215
+ readonly _bindContext: <R>(where: string, context: Context.Context<R>) => Context.Context<R | SecureRandom.SecureRandom>;
216
+ /** @internal The domain fields the entity offloads (#179), both kinds. */
217
+ readonly _offloadedFields: ReadonlyArray<string>;
218
+ /**
219
+ * @internal Route and upload, in place, the offloaded attributes of a
220
+ * packed, stored-name item built outside the entity's own `put`
221
+ * (`TransactableOps.validateAndBuildPutItem`, #179, design §6.6): the
222
+ * `Batch.write`, transaction, `additionalItems` and projection puts.
223
+ * `operation` is the name the uploads record. With `reuse` (a projection's
224
+ * row rewrite, §6.11), an attribute whose new content is what the read
225
+ * row's pointer named keeps that pointer instead of uploading; the write
226
+ * must then be conditioned on the returned pins (`OffloadWrite.withPins`).
227
+ * Nothing when the entity offloads nothing.
228
+ */
229
+ readonly _offloadItem: (item: globalThis.Record<string, unknown>, table: string, operation: string, reuse?: OffloadWrite.ReadPointers | undefined) => Effect.Effect<ReadonlyArray<OffloadWrite.Pin>, BlobStoreError | ValidationError>;
230
+ /**
231
+ * @internal Read a stored-name row that is about to be folded and rewritten
232
+ * (an EventStore projection's read model, design §6.11): loaded eagerly
233
+ * (both kinds) and decoded as an item — `Entity.Item`, Hidden fields
234
+ * included, as {@link decodeMarshalledItem} decodes one, since the row is
235
+ * written back whole — with the pointers it held and the content each named
236
+ * as fetched, which {@link _offloadItem}'s `reuse` compares. `raw` is
237
+ * consumed.
238
+ */
239
+ readonly _loadForReuse: (raw: globalThis.Record<string, unknown>, operation: string) => Effect.Effect<{
240
+ readonly item: unknown;
241
+ readonly pointers: OffloadWrite.ReadPointers;
242
+ }, ValidationError | BlobStoreError>;
159
243
  /** @internal Resolved ref metadata — used by cascade to inspect target entities */
160
244
  readonly _resolvedRefs: ReadonlyArray<{
161
245
  readonly fieldName: string;
@@ -170,8 +254,12 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
170
254
  };
171
255
  };
172
256
  }>;
173
- /** @internal Full decode pipeline: unpack + sparse + rename + schema decode. Used by Batch/Aggregate. */
174
- readonly _decodeRecord: (raw: globalThis.Record<string, unknown>) => Effect.Effect<any, ValidationError>;
257
+ /**
258
+ * @internal Full decode pipeline: load (unpack + resolve per `modes`, eager
259
+ * when omitted) + sparse + rename + schema decode. Used by queries,
260
+ * collections, Batch and transactions.
261
+ */
262
+ readonly _decodeRecord: (raw: globalThis.Record<string, unknown>, modes?: OffloadRead.Modes, operation?: string) => Effect.Effect<any, ValidationError | BlobStoreError>;
175
263
  /** @internal Domain field name → stored DynamoDB attribute name (`storedAs` renames). */
176
264
  readonly _resolveDbName: (domainName: string) => string;
177
265
  /**
@@ -276,13 +364,6 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
276
364
  readonly _versionCorruption: (item: Readonly<globalThis.Record<string, unknown>> | undefined, operation: string) => ValidationError | undefined;
277
365
  /** @internal Fill omitted decoding-default fields of a put's input (see `put`). */
278
366
  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
367
  /**
287
368
  * @internal The schema a put written whole composes its keys under (#242, `EDD-9162`): an object
288
369
  * composing `[object Object]` into a key it composes is refused where it's composed.
@@ -293,6 +374,16 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
293
374
  * an object there before anything is sent (`EDD-9162`); throws what `composeKeysOrFail` takes.
294
375
  */
295
376
  readonly _composeUniqueSentinels: (under: DynamoSchema.DynamoSchema, record: globalThis.Record<string, unknown>) => void;
377
+ /**
378
+ * @internal Encode a put input through `inputSchema` exactly as `put` does,
379
+ * for the batch, transaction and projection write paths: its binary inputs
380
+ * replaced by their placeholders first (#179, design §3.8 — `[EDD-9120]`
381
+ * for an unusable one), then through `encodeForWrite`: the input's stored
382
+ * form (`InputForm`), refusing a value that wouldn't read back (`EDD-9126`)
383
+ * and a key value read back as the other numeric kind (`EDD-9128`). A
384
+ * failure carries the domain form's issue, under `operation`.
385
+ */
386
+ readonly _encodeInput: (input: unknown, operation: string) => Effect.Effect<unknown, ValidationError>;
296
387
  /** @internal Unique fields a put's input leaves to an index-stored default. */
297
388
  readonly _unsentineledDefaults: (input: unknown) => ReadonlyArray<string>;
298
389
  /**
@@ -471,7 +562,7 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
471
562
  */
472
563
  readonly updateSchema: Schema.Codec<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>>;
473
564
  /** Fetch an item by primary key. Returns a lazy {@link EntityGet} intermediate. */
474
- readonly get: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
565
+ readonly get: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, ItemNotFound | DynamoClientError | ValidationError | ReadBlobErrors<TOffload, DefaultOffloadModes>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "read">>;
475
566
  /**
476
567
  * Create or replace an item. Returns a lazy {@link EntityPut} intermediate.
477
568
  *
@@ -483,42 +574,43 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
483
574
  * so the last writer wins; a race lost on every attempt is an
484
575
  * `OptimisticLockError` (versioned) or `ConcurrentModification`.
485
576
  */
486
- readonly put: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => EntityPut<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, DynamoClient | TableConfig>;
577
+ readonly put: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => EntityPut<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "write">>;
487
578
  /**
488
579
  * Begin an update operation on an existing item. Returns a lazy {@link EntityUpdate} intermediate.
489
580
  * Pipe to {@link set} to provide update fields and {@link expectedVersion} for optimistic locking.
490
581
  */
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>;
582
+ readonly update: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityUpdate<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, WithBinaryInput<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, TOffload> & Removable<RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "write">>;
492
583
  /**
493
584
  * Delete an item by primary key. Returns a lazy {@link EntityDelete} intermediate.
494
585
  * A unique-constrained entity releases only the sentinels the item owns.
495
586
  */
496
- readonly delete: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable, DynamoClient | TableConfig, void, ModelType<TModel>>;
587
+ readonly delete: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, void, ModelType<TModel>, DeleteOpStateOf<TOffload, ModelType<TModel>>>;
497
588
  /**
498
589
  * Create a new item. Fails with `ConditionalCheckFailed` if an item with the same
499
590
  * primary key already exists. Equivalent to `put(input)` with an `attribute_not_exists`
500
591
  * condition — it never reads the item (a `retain` entity reads only the highest
501
592
  * version retained for the key, to continue after it).
502
593
  */
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>;
594
+ readonly create: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => EntityPut<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "write">>;
504
595
  /**
505
596
  * Add an item through a PartiQL `INSERT`, which cannot replace one, so a role
506
597
  * holding only `dynamodb:PartiQLInsert` can add items and nothing else. Fails
507
598
  * with `ItemAlreadyExists` if the key is taken. Sends one write and no reads;
508
599
  * a `unique` entity sends an `INSERT`-only transaction. It takes no condition,
509
600
  * cannot join a transaction or batch, and is refused on `versioned: { retain: true }`.
601
+ * Offloaded fields are uploaded first, as `put` uploads them (#179).
510
602
  */
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>;
603
+ readonly insert: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => EntityInsert<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ItemAlreadyExists | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "write">>;
512
604
  /**
513
605
  * Update an existing item. Fails with `ConditionalCheckFailed` if the item doesn't exist.
514
606
  * Equivalent to `update(key)` with an automatic `attribute_exists` condition on the PK field.
515
607
  */
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>;
608
+ readonly patch: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityUpdate<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, WithBinaryInput<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, TOffload> & Removable<RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "write">>;
517
609
  /**
518
610
  * Delete an existing item. Fails with `ConditionalCheckFailed` if the item doesn't exist.
519
611
  * Equivalent to `delete(key)` with an automatic `attribute_exists` condition on the PK field.
520
612
  */
521
- readonly deleteIfExists: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | ConditionalCheckFailed, DynamoClient | TableConfig, void, ModelType<TModel>>;
613
+ readonly deleteIfExists: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | ConditionalCheckFailed | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, void, ModelType<TModel>, DeleteOpStateOf<TOffload, ModelType<TModel>>>;
522
614
  /**
523
615
  * Create an item, or update the fields the input supplies on an existing one —
524
616
  * immutable fields, `createdAt` and fields the input omits keep their stored
@@ -534,26 +626,30 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
534
626
  * create or delete in between is retried the other way; a race lost on every
535
627
  * attempt is an `OptimisticLockError` (versioned) or `ConcurrentModification`.
536
628
  */
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>;
629
+ readonly upsert: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => EntityPut<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | ItemNotFound | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "write">>;
538
630
  /** Fetch a specific version snapshot by version number. */
539
- readonly getVersion: (key: EntityKeyType<TModel, TIndexes, TRefs>, version: number) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
631
+ readonly getVersion: (key: EntityKeyType<TModel, TIndexes, TRefs>, version: number) => EntityGet<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, ItemNotFound | DynamoClientError | ValidationError | ReadBlobErrors<TOffload, DefaultOffloadModes>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "read">>;
540
632
  /** Query version history for an item. Returns a Query for piping with limit, reverse, collect. */
541
- readonly versions: (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<EntityRecordType<TModel, TTimestamps, TVersioned>>;
633
+ readonly versions: (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, EntityRecordType<TModel, TTimestamps, TVersioned>>>;
542
634
  /** Restore a soft-deleted item. Recomposes index keys and re-establishes unique sentinels. */
543
- readonly restore: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | ItemNotDeleted | DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ConcurrentModification, DynamoClient | TableConfig>;
635
+ readonly restore: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, ItemNotFound | ItemNotDeleted | DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ConcurrentModification | WriteBlobErrors<TOffload>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "write">>;
544
636
  /**
545
637
  * Permanently remove an item plus all version history and sentinels. Deletes
546
638
  * in `BatchWriteItem` chunks of 25, retrying `UnprocessedItems` with
547
639
  * backoff; not atomic, so a failure says exactly how many items it had
548
- * already deleted.
640
+ * already deleted. With `unique`, the live row and the sentinels it owns are
641
+ * deleted first, in one transaction guarded on the row as read (as `delete`
642
+ * sends it); a race with a concurrent write is retried from a fresh read, and
643
+ * once every attempt has lost it fails `OptimisticLockError` (versioned) or
644
+ * `ConcurrentModification`, having deleted nothing (#132).
549
645
  */
550
- readonly purge: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | ValidationError, DynamoClient | TableConfig>;
646
+ readonly purge: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityDelete<DynamoClientError | ValidationError | OptimisticLockError | ConcurrentModification | WriteBlobErrors<TOffload>, DynamoClient | TableConfig>;
551
647
  /** Soft-deleted item accessors. */
552
648
  readonly deleted: {
553
649
  /** Get a specific soft-deleted item. */
554
- readonly get: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, ItemNotFound | DynamoClientError | ValidationError, DynamoClient | TableConfig>;
650
+ readonly get: (key: EntityKeyType<TModel, TIndexes, TRefs>) => EntityGet<View<ModelType<TModel>, TOffload>, View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, ItemNotFound | DynamoClientError | ValidationError | ReadBlobErrors<TOffload, DefaultOffloadModes>, DynamoClient | TableConfig, OpStateOf<TOffload, ModelType<TModel>, EntityRecordType<TModel, TTimestamps, TVersioned>, "read">>;
555
651
  /** List soft-deleted items within a partition. */
556
- readonly list: (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<EntityRecordType<TModel, TTimestamps, TVersioned>>;
652
+ readonly list: (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<View<EntityRecordType<TModel, TTimestamps, TVersioned>, TOffload>, ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, EntityRecordType<TModel, TTimestamps, TVersioned>>>;
557
653
  };
558
654
  /**
559
655
  * Append an event to a time-series entity. Atomically updates the "current"
@@ -575,10 +671,10 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
575
671
  * Only available when the entity was built with `timeSeries: { ... }`.
576
672
  */
577
673
  readonly append: [TTimeSeries] extends [TimeSeriesConfig<infer TAI extends Schema.Top>] ? {
578
- (input: AppendInputType<TAI>, condition?: Expr | ConditionInput, skipFollowUp?: false, removeAttrs?: ReadonlyArray<AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>>): Effect.Effect<{
579
- readonly current: ModelType<TModel>;
580
- }, DynamoClientError | ValidationError | StaleAppend | ConditionalCheckFailed | 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>;
674
+ (input: WithBinaryInput<AppendInputType<TAI>, TOffload>, condition?: Expr | ConditionInput, skipFollowUp?: false, removeAttrs?: ReadonlyArray<AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>>): Effect.Effect<{
675
+ readonly current: View<ModelType<TModel>, TOffload>;
676
+ }, DynamoClientError | ValidationError | StaleAppend | ConditionalCheckFailed | ConcurrentModification | WriteBlobErrors<TOffload>, DynamoClient | TableConfig>;
677
+ (input: WithBinaryInput<AppendInputType<TAI>, TOffload>, condition: Expr | ConditionInput | undefined, skipFollowUp: true, removeAttrs?: ReadonlyArray<AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>>): Effect.Effect<void, DynamoClientError | ValidationError | StaleAppend | ConcurrentModification | WriteBlobErrors<TOffload>, DynamoClient | TableConfig>;
582
678
  } : never;
583
679
  /**
584
680
  * Query the event history of a time-series entity partition. Returns a
@@ -586,7 +682,7 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
586
682
  *
587
683
  * Only available when the entity was built with `timeSeries: { ... }`.
588
684
  */
589
- readonly history: [TTimeSeries] extends [TimeSeriesConfig<any>] ? (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<ModelType<TModel>> : never;
685
+ readonly history: [TTimeSeries] extends [TimeSeriesConfig<any>] ? (key: EntityKeyType<TModel, TIndexes, TRefs>) => Query.Query<View<ModelType<TModel>, TOffload>, ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, ModelType<TModel>>> : never;
590
686
  /**
591
687
  * Set combinator pre-bound to this entity's update type.
592
688
  *
@@ -607,8 +703,8 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
607
703
  * ```
608
704
  */
609
705
  readonly set: {
610
- (updates: EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>): <A, Rec, U, E, R>(self: EntityUpdate<A, Rec, U, E, R>) => EntityUpdate<A, Rec, U, E, R>;
611
- <A, Rec, U, E, R>(self: EntityUpdate<A, Rec, U, E, R>, updates: EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>): EntityUpdate<A, Rec, U, E, R>;
706
+ (updates: WithBinaryInput<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, TOffload>): <A, Rec, U, E, R, O extends OffloadState>(self: EntityUpdate<A, Rec, U, E, R, O>) => EntityUpdate<A, Rec, U, E, R, O>;
707
+ <A, Rec, U, E, R, O extends OffloadState>(self: EntityUpdate<A, Rec, U, E, R, O>, updates: WithBinaryInput<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, TOffload>): EntityUpdate<A, Rec, U, E, R, O>;
612
708
  };
613
709
  /**
614
710
  * Set expected version for optimistic locking.
@@ -618,12 +714,20 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
618
714
  (version: number): <A, Rec, U, E, R>(self: EntityUpdate<A, Rec, U, E, R>) => EntityUpdate<A, Rec, U, E, R>;
619
715
  <A, Rec, U, E, R>(self: EntityUpdate<A, Rec, U, E, R>, version: number): EntityUpdate<A, Rec, U, E, R>;
620
716
  };
621
- /** Index query accessors. Each non-primary index becomes a method that accepts PK composites and returns a {@link Query.Query}. */
717
+ /**
718
+ * Index query accessors. Each non-primary index becomes a method that
719
+ * accepts PK composites and returns a {@link Query.Query}. Offloaded fields
720
+ * read in the default modes (overflow eager, binary lazy) until
721
+ * `Query.offloaded` sets others (#179).
722
+ */
622
723
  readonly query: {
623
- readonly [K in Exclude<keyof TIndexes, "primary">]: (pk: IndexPkInput<TModel, TIndexes, K, TRefs>) => Query.Query<ModelType<TModel>>;
724
+ readonly [K in Exclude<keyof TIndexes, "primary">]: (pk: IndexPkInput<TModel, TIndexes, K, TRefs>) => Query.Query<View<ModelType<TModel>, TOffload>, ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, ModelType<TModel>>>;
624
725
  };
625
- /** Scan all items of this entity type. Returns a {@link Query.Query} that uses DynamoDB Scan. */
626
- readonly scan: () => Query.Query<ModelType<TModel>>;
726
+ /**
727
+ * Scan all items of this entity type. Returns a {@link Query.Query} that
728
+ * uses DynamoDB Scan; offloaded fields read as {@link query}'s do.
729
+ */
730
+ readonly scan: () => Query.Query<View<ModelType<TModel>, TOffload>, ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, ModelType<TModel>>>;
627
731
  /**
628
732
  * Build a condition expression combinator.
629
733
  * Callback receives `(t, ops)` where `t` is a PathBuilder and `ops` provides comparison functions.
@@ -655,8 +759,8 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
655
759
  * ```
656
760
  */
657
761
  readonly filter: {
658
- (cb: (t: import("./internal/PathBuilder.js").PathBuilder<PathModel<ModelType<TModel>, TPackedFields>, PathModel<ModelType<TModel>, TPackedFields>>, ops: import("./internal/Expr.js").ConditionOps<PathModel<ModelType<TModel>, TPackedFields>>) => import("./internal/Expr.js").Expr): <A>(self: Query.Query<A>) => Query.Query<A>;
659
- (shorthand: globalThis.Record<string, unknown>): <A>(self: Query.Query<A>) => Query.Query<A>;
762
+ (cb: (t: import("./internal/PathBuilder.js").PathBuilder<PathModel<ModelType<TModel>, TPackedFields>, PathModel<ModelType<TModel>, TPackedFields>>, ops: import("./internal/Expr.js").ConditionOps<PathModel<ModelType<TModel>, TPackedFields>>) => import("./internal/Expr.js").Expr): <A, E = never, O extends OffloadState = NoOffloadState>(self: Query.Query<A, E, O>) => Query.Query<A, E, O>;
763
+ (shorthand: globalThis.Record<string, unknown>): <A, E = never, O extends OffloadState = NoOffloadState>(self: Query.Query<A, E, O>) => Query.Query<A, E, O>;
660
764
  };
661
765
  /**
662
766
  * Build a select (projection) combinator for get/query/scan operations.
@@ -670,8 +774,8 @@ export interface Entity<TModel extends Schema.Top = Schema.Top, TEntityType exte
670
774
  * ```
671
775
  */
672
776
  readonly select: {
673
- (cb: (t: import("./internal/PathBuilder.js").PathBuilder<PathModel<ModelType<TModel>, TPackedFields>, PathModel<ModelType<TModel>, TPackedFields>>) => ReadonlyArray<import("./internal/PathBuilder.js").Path<PathModel<ModelType<TModel>, TPackedFields>, any> | import("./internal/PathBuilder.js").PackedPath<PathModel<ModelType<TModel>, TPackedFields>, any>>): (self: Query.Query<any>) => Query.Query<any>;
674
- (attributes: ReadonlyArray<string>): (self: Query.Query<any>) => Query.Query<any>;
777
+ (cb: (t: import("./internal/PathBuilder.js").PathBuilder<PathModel<ModelType<TModel>, TPackedFields>, PathModel<ModelType<TModel>, TPackedFields>>) => ReadonlyArray<import("./internal/PathBuilder.js").Path<PathModel<ModelType<TModel>, TPackedFields>, any> | import("./internal/PathBuilder.js").PackedPath<PathModel<ModelType<TModel>, TPackedFields>, any>>): (self: Query.Query<any, any, any>) => Query.Query<any, any, any>;
778
+ (attributes: ReadonlyArray<string>): (self: Query.Query<any, any, any>) => Query.Query<any, any, any>;
675
779
  };
676
780
  }
677
781
  /**
@@ -720,7 +824,7 @@ export type VectorIndexNames<TVectorIndexes> = TVectorIndexes extends globalThis
720
824
  export type KeptRefIds<TRefs, TUpdate> = [TRefs] extends [undefined] ? never : {
721
825
  [K in keyof Pick<TUpdate, `${keyof TRefs & string}Id` & keyof TUpdate>]: Exclude<TUpdate[K], null>;
722
826
  };
723
- 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> {
827
+ 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, TOffload extends OffloadFields = NoOffload> {
724
828
  /**
725
829
  * Fetch an item by primary key.
726
830
  *
@@ -738,7 +842,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
738
842
  * ])
739
843
  * ```
740
844
  */
741
- readonly get: (key: TKey) => import("./internal/BoundCrud.js").BoundGet<ModelType<TModel>, ItemNotFound | DynamoClientError | ValidationError>;
845
+ readonly get: (key: TKey) => import("./internal/BoundCrud.js").BoundGet<View<ModelType<TModel>, TOffload>, ItemNotFound | DynamoClientError | ValidationError | ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, ModelType<TModel>>>;
742
846
  /**
743
847
  * Create or replace an item. Returns a fluent {@link BoundPut} — yield to execute,
744
848
  * chain `.condition(...)` to add a condition expression.
@@ -748,20 +852,21 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
748
852
  * yield* db.entities.Users.put(input).condition({ status: "active" })
749
853
  * ```
750
854
  */
751
- readonly put: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => import("./internal/BoundCrud.js").BoundPut<ModelType<TModel>, ModelType<TModel>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>, TPackedFields>;
855
+ readonly put: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => import("./internal/BoundCrud.js").BoundPut<ModelType<TModel>, View<ModelType<TModel>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, VectorIndexNames<TVectorIndexes>, TPackedFields, StateOf<TOffload, ModelType<TModel>>>;
752
856
  /**
753
857
  * Create a new item. Fails with {@link ConditionalCheckFailed} if an item with the same
754
858
  * primary key already exists. Returns a fluent {@link BoundPut}.
755
859
  */
756
- 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>;
860
+ readonly create: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => import("./internal/BoundCrud.js").BoundPut<ModelType<TModel>, View<ModelType<TModel>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, VectorIndexNames<TVectorIndexes>, TPackedFields, StateOf<TOffload, ModelType<TModel>>>;
757
861
  /**
758
862
  * Add an item through a PartiQL `INSERT`, which cannot replace one, so a role
759
863
  * holding only `dynamodb:PartiQLInsert` can add items and nothing else. Fails
760
864
  * with `ItemAlreadyExists` if the key is taken. Sends one write and no reads;
761
865
  * a `unique` entity sends an `INSERT`-only transaction. It takes no condition,
762
866
  * cannot join a transaction or batch, and is refused on `versioned: { retain: true }`.
867
+ * Offloaded fields are uploaded first, as `put` uploads them (#179).
763
868
  */
764
- 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>>;
869
+ readonly insert: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => import("./internal/BoundCrud.js").BoundInsert<View<ModelType<TModel>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ItemAlreadyExists | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, VectorIndexNames<TVectorIndexes>, StateOf<TOffload, ModelType<TModel>>>;
765
870
  /**
766
871
  * Begin an update on an existing item. Returns a fluent {@link BoundUpdate} — chain
767
872
  * `.set(...)`, `.remove(...)`, `.add(...)`, `.condition(...)`, `.expectedVersion(...)`,
@@ -771,7 +876,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
771
876
  * yield* db.entities.Tasks.update({ id }).set(updates).expectedVersion(3)
772
877
  * ```
773
878
  */
774
- 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>, KeptRefIds<TRefs, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>>>;
879
+ readonly update: (key: TKey) => import("./internal/BoundCrud.js").BoundUpdate<ModelType<TModel>, View<ModelType<TModel>, TOffload>, WithBinaryInput<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, TOffload>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, VectorIndexNames<TVectorIndexes>, TPackedFields, RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>, KeptRefIds<TRefs, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>>, StateOf<TOffload, ModelType<TModel>>>;
775
880
  /**
776
881
  * Delete an item by primary key. Returns a fluent {@link BoundDelete} — yield to execute,
777
882
  * chain `.condition(...)` and/or `.returnValues(...)`.
@@ -781,7 +886,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
781
886
  * yield* db.entities.Tasks.delete(key).condition({ status: "archived" })
782
887
  * ```
783
888
  */
784
- readonly delete: (key: TKey) => import("./internal/BoundCrud.js").BoundDelete<ModelType<TModel>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable, void, TPackedFields>;
889
+ readonly delete: (key: TKey) => import("./internal/BoundCrud.js").BoundDelete<ModelType<TModel>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | WriteBlobErrors<TOffload>, void, TPackedFields, StateOf<TOffload, undefined>>;
785
890
  /**
786
891
  * Create an item, or update the fields the input supplies on an existing one.
787
892
  * Returns a fluent {@link BoundPut}. See `Entity.upsert`: a plain entity is one
@@ -789,7 +894,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
789
894
  * version; a `unique` or `retain` entity (or an input omitting a defaulted index
790
895
  * composite) reads the item once and creates or updates it.
791
896
  */
792
- readonly upsert: (input: WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>) => import("./internal/BoundCrud.js").BoundPut<ModelType<TModel>, ModelType<TModel>, DynamoClientError | TransactionOverflow | ValidationError | ItemNotFound | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes>, VectorIndexNames<TVectorIndexes>, TPackedFields>;
897
+ readonly upsert: (input: WithBinaryInput<WithGeneratedId<EntityRefInputType<TModel, TRefs, TTimestamps, TVersioned, TTimeSeries>, TGeneratedId>, TOffload>) => import("./internal/BoundCrud.js").BoundPut<ModelType<TModel>, View<ModelType<TModel>, TOffload>, DynamoClientError | TransactionOverflow | ValidationError | ItemNotFound | UniqueConstraintViolation | OptimisticLockError | ConcurrentModification | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, VectorIndexNames<TVectorIndexes>, TPackedFields, StateOf<TOffload, ModelType<TModel>>>;
793
898
  /**
794
899
  * Update an existing item. Fails with {@link ConditionalCheckFailed} if the item doesn't exist.
795
900
  * Returns a fluent {@link BoundUpdate}.
@@ -798,11 +903,11 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
798
903
  * yield* db.entities.Tasks.patch({ id }).set(updates)
799
904
  * ```
800
905
  */
801
- 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>, KeptRefIds<TRefs, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>>>;
906
+ readonly patch: (key: TKey) => import("./internal/BoundCrud.js").BoundUpdate<ModelType<TModel>, View<ModelType<TModel>, TOffload>, WithBinaryInput<EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>, TOffload>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | UpdateAppliedButUnreadable | UniqueConstraintViolation | ValidationError | ConditionalCheckFailed | RefErrors<TRefs> | VectorErrors<TVectorIndexes> | WriteBlobErrors<TOffload>, VectorIndexNames<TVectorIndexes>, TPackedFields, RemovableFields<TModel, TIndexes, TRefs, TTimestamps, TVersioned, TUnremovable>, KeptRefIds<TRefs, EntityRefUpdateType<TModel, TIndexes, TRefs, TTimestamps, TVersioned>>, StateOf<TOffload, ModelType<TModel>>>;
802
907
  /** Delete an existing item, fails if not found. Returns a fluent {@link BoundDelete}. */
803
- readonly deleteIfExists: (key: TKey) => import("./internal/BoundCrud.js").BoundDelete<ModelType<TModel>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | ConditionalCheckFailed, void, TPackedFields>;
908
+ readonly deleteIfExists: (key: TKey) => import("./internal/BoundCrud.js").BoundDelete<ModelType<TModel>, DynamoClientError | TransactionOverflow | ItemNotFound | OptimisticLockError | ConcurrentModification | ValidationError | DeleteAppliedButUnreadable | ConditionalCheckFailed | WriteBlobErrors<TOffload>, void, TPackedFields, StateOf<TOffload, undefined>>;
804
909
  /** Fetch a specific version snapshot by version number. */
805
- readonly getVersion: (key: TKey, version: number) => Effect.Effect<ModelType<TModel>, ItemNotFound | DynamoClientError | ValidationError, never>;
910
+ readonly getVersion: (key: TKey, version: number) => Effect.Effect<View<ModelType<TModel>, TOffload>, ItemNotFound | DynamoClientError | ValidationError | ReadBlobErrors<TOffload, DefaultOffloadModes>, never>;
806
911
  /**
807
912
  * List all version snapshots for an item as a fluent BoundQuery.
808
913
  * Requires `versioned: { retain: true }` on the entity definition.
@@ -816,20 +921,24 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
816
921
  * .collect()
817
922
  * ```
818
923
  */
819
- readonly versions: (key: TKey) => import("./internal/BoundQuery.js").BoundQuery<PathModel<ModelType<TModel>, TPackedFields>, never, ModelType<TModel>>;
924
+ readonly versions: (key: TKey) => import("./internal/BoundQuery.js").BoundQuery<PathModel<ModelType<TModel>, TPackedFields>, never, View<ModelType<TModel>, TOffload>, never, StateOf<TOffload, ModelType<TModel>>>;
820
925
  /** Restore a soft-deleted item. */
821
- readonly restore: (key: TKey) => Effect.Effect<ModelType<TModel>, ItemNotFound | ItemNotDeleted | DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ConcurrentModification, never>;
926
+ readonly restore: (key: TKey) => Effect.Effect<View<ModelType<TModel>, TOffload>, ItemNotFound | ItemNotDeleted | DynamoClientError | TransactionOverflow | ValidationError | UniqueConstraintViolation | ConcurrentModification | WriteBlobErrors<TOffload>, never>;
822
927
  /**
823
928
  * Permanently remove an item plus all version history and sentinels. Deletes
824
929
  * in `BatchWriteItem` chunks of 25, retrying `UnprocessedItems` with
825
930
  * backoff; not atomic, so a failure says exactly how many items it had
826
- * already deleted.
931
+ * already deleted. With `unique`, the live row and the sentinels it owns are
932
+ * deleted first, in one transaction guarded on the row as read (as `delete`
933
+ * sends it); a race with a concurrent write is retried from a fresh read, and
934
+ * once every attempt has lost it fails `OptimisticLockError` (versioned) or
935
+ * `ConcurrentModification`, having deleted nothing (#132).
827
936
  */
828
- readonly purge: (key: TKey) => Effect.Effect<void, DynamoClientError | ValidationError, never>;
937
+ readonly purge: (key: TKey) => Effect.Effect<void, DynamoClientError | ValidationError | OptimisticLockError | ConcurrentModification | WriteBlobErrors<TOffload>, never>;
829
938
  /** Soft-deleted item accessors. */
830
939
  readonly deleted: {
831
940
  /** Get a specific soft-deleted item. */
832
- readonly get: (key: TKey) => Effect.Effect<ModelType<TModel>, ItemNotFound | DynamoClientError | ValidationError, never>;
941
+ readonly get: (key: TKey) => Effect.Effect<View<ModelType<TModel>, TOffload>, ItemNotFound | DynamoClientError | ValidationError | ReadBlobErrors<TOffload, DefaultOffloadModes>, never>;
833
942
  /**
834
943
  * List all soft-deleted items in this partition as a fluent BoundQuery.
835
944
  * Requires `softDelete` on the entity definition.
@@ -840,7 +949,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
840
949
  * .collect()
841
950
  * ```
842
951
  */
843
- readonly list: (key: TKey) => import("./internal/BoundQuery.js").BoundQuery<PathModel<ModelType<TModel>, TPackedFields>, never, ModelType<TModel>>;
952
+ readonly list: (key: TKey) => import("./internal/BoundQuery.js").BoundQuery<PathModel<ModelType<TModel>, TPackedFields>, never, View<ModelType<TModel>, TOffload>, never, StateOf<TOffload, ModelType<TModel>>>;
844
953
  };
845
954
  /**
846
955
  * Append an event to a time-series entity. Atomically updates the "current"
@@ -864,9 +973,9 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
864
973
  *
865
974
  * Only available when the entity was built with `timeSeries: { ... }`.
866
975
  */
867
- readonly append: [TTimeSeries] extends [TimeSeriesConfig<infer TAI extends Schema.Top>] ? (input: AppendInputType<TAI>) => import("./internal/BoundCrud.js").BoundAppend<ModelType<TModel>, {
868
- readonly current: ModelType<TModel>;
869
- }, DynamoClientError | ValidationError | StaleAppend | ConditionalCheckFailed | ConcurrentModification, DynamoClientError | ValidationError | StaleAppend | ConcurrentModification, TPackedFields, AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>> : never;
976
+ readonly append: [TTimeSeries] extends [TimeSeriesConfig<infer TAI extends Schema.Top>] ? (input: WithBinaryInput<AppendInputType<TAI>, TOffload>) => import("./internal/BoundCrud.js").BoundAppend<ModelType<TModel>, {
977
+ readonly current: View<ModelType<TModel>, TOffload>;
978
+ }, DynamoClientError | ValidationError | StaleAppend | ConditionalCheckFailed | ConcurrentModification | WriteBlobErrors<TOffload>, DynamoClientError | ValidationError | StaleAppend | ConcurrentModification | WriteBlobErrors<TOffload>, TPackedFields, AppendRemovableFields<TModel, TIndexes, TRefs, TTimeSeries, TTimestamps, TVersioned, TUnremovable>, StateOf<TOffload, ModelType<TModel>>> : never;
870
979
  /**
871
980
  * Query the event history of a time-series entity partition. Returns a
872
981
  * {@link import("./internal/BoundQuery.js").BoundQuery} auto-scoped to event
@@ -878,7 +987,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
878
987
  */
879
988
  readonly history: [TTimeSeries] extends [TimeSeriesConfig<any>] ? (key: TKey) => import("./internal/BoundQuery.js").BoundQuery<PathModel<ModelType<TModel>, TPackedFields>, {
880
989
  readonly [K in NonNullable<TTimeSeries>["orderBy"] & string]: HistoryOrderByOperand<ModelType<TModel>, K>;
881
- }, ModelType<TModel>> : never;
990
+ }, View<ModelType<TModel>, TOffload>, never, StateOf<TOffload, ModelType<TModel>>> : never;
882
991
  /**
883
992
  * Execute a query and return a lazy Stream of items. Automatically paginates through all pages.
884
993
  * Accepts optional query combinators (e.g. `Query.limit(...)`, `Query.reverse`).
@@ -887,7 +996,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
887
996
  * const stream = teams.paginate(Teams.query.byRole({ role: "admin" }), Query.limit(10))
888
997
  * ```
889
998
  */
890
- readonly paginate: <A>(query: Query.Query<A>, ...combinators: ReadonlyArray<(q: Query.Query<A>) => Query.Query<A>>) => Stream.Stream<A, DynamoClientError | ValidationError, never>;
999
+ readonly paginate: <A, E = never, O extends OffloadState = NoOffloadState>(query: Query.Query<A, E, O>, ...combinators: ReadonlyArray<(q: Query.Query<A, E, O>) => Query.Query<A, E, O>>) => Stream.Stream<A, DynamoClientError | ValidationError | E, never>;
891
1000
  /**
892
1001
  * Execute a query and collect all pages into a single array.
893
1002
  * Accepts optional query combinators (e.g. `Query.limit(...)`, `Query.reverse`).
@@ -896,7 +1005,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
896
1005
  * const items = yield* teams.collect(Teams.query.byRole({ role: "admin" }), Query.limit(10))
897
1006
  * ```
898
1007
  */
899
- readonly collect: <A>(query: Query.Query<A>, ...combinators: ReadonlyArray<(q: Query.Query<A>) => Query.Query<A>>) => Effect.Effect<Array<A>, DynamoClientError | ValidationError, never>;
1008
+ readonly collect: <A, E = never, O extends OffloadState = NoOffloadState>(query: Query.Query<A, E, O>, ...combinators: ReadonlyArray<(q: Query.Query<A, E, O>) => Query.Query<A, E, O>>) => Effect.Effect<Array<A>, DynamoClientError | ValidationError | E, never>;
900
1009
  /**
901
1010
  * Execute a single DynamoDB page and return a {@link Query.Page} with an opaque cursor.
902
1011
  * Use `Query.startFrom(cursor)` to iterate through subsequent pages.
@@ -912,7 +1021,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
912
1021
  * )
913
1022
  * ```
914
1023
  */
915
- readonly fetch: <A>(query: Query.Query<A>, ...combinators: ReadonlyArray<(q: Query.Query<A>) => Query.Query<A>>) => Effect.Effect<Query.Page<A>, DynamoClientError | ValidationError, never>;
1024
+ readonly fetch: <A, E = never, O extends OffloadState = NoOffloadState>(query: Query.Query<A, E, O>, ...combinators: ReadonlyArray<(q: Query.Query<A, E, O>) => Query.Query<A, E, O>>) => Effect.Effect<Query.Page<A>, DynamoClientError | ValidationError | E, never>;
916
1025
  /**
917
1026
  * Execute a single DynamoDB scan page and return a {@link Query.Page} with an opaque cursor.
918
1027
  * Convenience for `fetch(Entity.scan(), ...)`. Use `Query.startFrom(cursor)` for subsequent pages.
@@ -925,7 +1034,7 @@ export interface BoundEntity<TModel extends Schema.Top, TIndexes extends globalT
925
1034
  * )
926
1035
  * ```
927
1036
  */
928
- readonly scanFetch: (...combinators: ReadonlyArray<(q: Query.Query<ModelType<TModel>>) => Query.Query<ModelType<TModel>>>) => Effect.Effect<Query.Page<ModelType<TModel>>, DynamoClientError | ValidationError, never>;
1037
+ readonly scanFetch: (...combinators: ReadonlyArray<(q: Query.Query<View<ModelType<TModel>, TOffload>, ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, ModelType<TModel>>>) => Query.Query<View<ModelType<TModel>, TOffload>, ReadBlobErrors<TOffload, DefaultOffloadModes>, StateOf<TOffload, ModelType<TModel>>>>) => Effect.Effect<Query.Page<View<ModelType<TModel>, TOffload>>, DynamoClientError | ValidationError | ReadBlobErrors<TOffload, DefaultOffloadModes>, never>;
929
1038
  }
930
1039
  /** @internal One positional reason of a cancelled (or conditional) write. */
931
1040
  export interface WriteCancellationReason {
@@ -1033,7 +1142,14 @@ export declare const make: <TModel extends Schema.Top, const TEntityType extends
1033
1142
  readonly timeSeries?: TTimeSeries & AppendInputFields<TModel, TTimeSeries>;
1034
1143
  readonly generatedId?: TGeneratedId;
1035
1144
  readonly vectorIndexes?: TVectorIndexes;
1036
- }) => 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>>>;
1145
+ /**
1146
+ * Item-level offload settings (#179) — `itemBudget` (stored item bytes the
1147
+ * library keeps the item under by offloading overflow fields, largest
1148
+ * first) and `prefix` (replaces the blob store's prefix for this entity's
1149
+ * objects). Only for an entity with offloaded fields (`[EDD-9114]`).
1150
+ */
1151
+ readonly offload?: OffloadConfig | undefined;
1152
+ }) => Entity<TModel, TEntityType, NormalizedIndexes<TPrimaryKey, TGsiIndexes>, TTimestamps, TVersioned, TSoftDelete, TUnique, RefsOrNone<TRefs>, ExtractIdentifier<ConfiguredModel<TModel, TAttrs>>, TTimeSeries, TGeneratedId, TVectorIndexes, ExtractPackedFields<ConfiguredModel<TModel, TAttrs>> | ExtractOffloadFields<ConfiguredModel<TModel, TAttrs>>["binary"], ExtractUnremovableFields<ConfiguredModel<TModel, TAttrs>>, ExtractOffloadFields<ConfiguredModel<TModel, TAttrs>>>;
1037
1153
  /**
1038
1154
  * @internal A ref's id as the stored ref holds it, as a value of the referenced entity's key (#241).
1039
1155
  * The stored ref is the referenced item in its entity's stored form ({@link refDataOf}), while a
@@ -1079,13 +1195,14 @@ export declare const fromDefinition: (def: EntityDefinition) => Entity;
1079
1195
  *
1080
1196
  * @internal Used by `DynamoClient.make()` to bind entities.
1081
1197
  */
1082
- 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>;
1198
+ 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, TOffload extends OffloadFields = NoOffload>(entity: Entity<TModel, TEntityType, TIndexes, TTimestamps, TVersioned, TSoftDelete, TUnique, TRefs, TIdentifier, TTimeSeries, TGeneratedId, TVectorIndexes, TPackedFields, TUnremovable, TOffload>) => Effect.Effect<BoundEntity<TModel, TIndexes, TRefs, EntityKeyType<TModel, TIndexes, TRefs>, TTimeSeries, TTimestamps, TVersioned, TGeneratedId, TVectorIndexes, TPackedFields, TUnremovable, TOffload>, never, DynamoClient | TableConfig>;
1083
1199
  /**
1084
1200
  * What planning an update for a transaction can fail with: everything the
1085
1201
  * update raises before it writes — its reads (`DynamoClientError`, `ItemNotFound`,
1086
1202
  * `RefNotFound`), a stale `expectedVersion`, `patch` of a missing row
1087
- * (`ConditionalCheckFailed`), an op too large for one transaction, and a refused op
1088
- * (`ValidationError`).
1203
+ * (`ConditionalCheckFailed`), an op too large for one transaction, a refused op
1204
+ * (`ValidationError`), and the blob store's failures of its uploads and reads
1205
+ * (`BlobStoreError`, #179).
1089
1206
  */
1090
1207
  /**
1091
1208
  * @internal What `Entity._prepareUpdate` decided of an update, opaque outside the entity that
@@ -1094,9 +1211,9 @@ export declare const bind: <TModel extends Schema.Top, TEntityType extends strin
1094
1211
  export interface PreparedUpdate {
1095
1212
  readonly _preparedUpdate: unique symbol;
1096
1213
  }
1097
- export type PlanUpdateError = DynamoClientError | ValidationError | ConditionalCheckFailed | ItemNotFound | TransactionOverflow | OptimisticLockError | RefNotFound | UniqueConstraintViolation;
1214
+ export type PlanUpdateError = DynamoClientError | ValidationError | ConditionalCheckFailed | ItemNotFound | TransactionOverflow | OptimisticLockError | RefNotFound | UniqueConstraintViolation | BlobStoreError;
1098
1215
  /** What planning a delete for a transaction can fail with — see {@link PlanUpdateError}. */
1099
- export type PlanDeleteError = DynamoClientError | ValidationError | ConditionalCheckFailed | ItemNotFound | TransactionOverflow;
1216
+ export type PlanDeleteError = DynamoClientError | ValidationError | ConditionalCheckFailed | ItemNotFound | TransactionOverflow | BlobStoreError;
1100
1217
  export interface TransactableInfo {
1101
1218
  readonly opType: "get" | "put" | "update" | "delete";
1102
1219
  readonly entity: Entity;
@@ -1131,21 +1248,20 @@ export interface TransactableInfo {
1131
1248
  readonly mustExist: boolean;
1132
1249
  readonly returnValues: ReturnValuesMode | undefined;
1133
1250
  } | undefined;
1251
+ /**
1252
+ * For `opType: "get"` — the read modes `.offloaded()` set on it (#179), the
1253
+ * defaults when unset: `Batch.get` and `transactGet` decode each get's item
1254
+ * in its own modes.
1255
+ */
1256
+ readonly offloadModes?: OffloadRead.Modes | undefined;
1257
+ /**
1258
+ * A bound builder's captured blob store and compressor registry (#179,
1259
+ * design §3.6): the multi-item entry points build, upload and read this
1260
+ * op's item under them (`TransactableOps.underCaptured`). `undefined` for
1261
+ * an unbound op, and for a binding that captured neither.
1262
+ */
1263
+ readonly captured?: Context.Context<never> | undefined;
1134
1264
  }
1135
- /**
1136
- * Extract transactable metadata from an Entity operation intermediate.
1137
- * Returns undefined if the value is not a recognized entity operation.
1138
- *
1139
- * Bound ops (`db.entities.X.put(...)`, `.create(...)`, `.delete(...)`,
1140
- * `.get(...)`, …) are unwrapped to the `EntityOp` / `EntityDelete` they wrap.
1141
- * That unwrapping is what lets entities authored with the pure, AWS-free
1142
- * `@effect-dynamodb/schema` `Entity.make` take part in `Batch.write`,
1143
- * `Transaction.transactWrite`, `EventStore.append({ additionalItems })` (#100)
1144
- * and — through the same one protocol, not a second one — `Batch.get`,
1145
- * `Transaction.transactGet` and `Transaction.check` (#108). A pure definition
1146
- * carries no operations, so the bound op is the only descriptor its author can
1147
- * ever hold.
1148
- */
1149
1265
  /**
1150
1266
  * @internal `create`'s guard: the item must not exist. (Over a projection
1151
1267
  * tombstone, `create` reads it and guards on it instead — `overTombstone`.)
@@ -1162,6 +1278,23 @@ export declare const createGuard: (entity: {
1162
1278
  };
1163
1279
  };
1164
1280
  }) => ConditionInput;
1281
+ /**
1282
+ * Extract transactable metadata from an Entity operation intermediate.
1283
+ * Returns undefined if the value is not a recognized entity operation.
1284
+ *
1285
+ * Bound ops (`db.entities.X.put(...)`, `.create(...)`, `.delete(...)`,
1286
+ * `.get(...)`, …) are unwrapped to the `EntityOp` / `EntityDelete` they wrap.
1287
+ * That unwrapping is what lets entities authored with the pure, AWS-free
1288
+ * `@effect-dynamodb/schema` `Entity.make` take part in `Batch.write`,
1289
+ * `Transaction.transactWrite`, `EventStore.append({ additionalItems })` (#100)
1290
+ * and — through the same one protocol, not a second one — `Batch.get`,
1291
+ * `Transaction.transactGet` and `Transaction.check` (#108). A pure definition
1292
+ * carries no operations, so the bound op is the only descriptor its author can
1293
+ * ever hold.
1294
+ *
1295
+ * A bound op also carries its binding's captured blob store and compressor
1296
+ * registry (`captured`, #179): the entry points build its item under them.
1297
+ */
1165
1298
  export declare const extractTransactable: (op: unknown) => TransactableInfo | undefined;
1166
1299
  /**
1167
1300
  * Success type of `BoundEntity.append()` on the default path — carries the
@@ -1190,16 +1323,35 @@ export type Record<E extends {
1190
1323
  readonly versioned: any;
1191
1324
  readonly timeSeries?: any;
1192
1325
  }> = EntityRecordType<E["model"], E["timestamps"], E["versioned"], E["timeSeries"]>;
1326
+ /**
1327
+ * The record type a read of `E` returns (#179, design §9.2): `Record<E>` with
1328
+ * each offloaded field typed by the read's modes `M` (default: overflow
1329
+ * eager, binary lazy) — an eager field its value, a lazy overflow field
1330
+ * `OffloadedValue<value>`, a lazy binary field `BlobHandle`. Exactly
1331
+ * `Record<E>` for an entity that offloads nothing.
1332
+ *
1333
+ * `Entity.Record<E>` / `Entity.Model<E>` keep the domain types the schema
1334
+ * describes; this names the view.
1335
+ */
1336
+ export type Read<E extends {
1337
+ readonly model: Schema.Top;
1338
+ readonly timestamps: any;
1339
+ readonly versioned: any;
1340
+ readonly timeSeries?: any;
1341
+ }, M extends ResolvedOffloadModes = DefaultOffloadModes> = View<Record<E>, OffloadFieldsOf<E>, M>;
1193
1342
  /**
1194
1343
  * Extract the input type from an Entity. Ref-aware: when refs are present,
1195
1344
  * ref fields are replaced with `${field}Id: string`.
1196
1345
  *
1197
1346
  * `Entity.Input<typeof Users>` = model fields only
1198
1347
  * `Entity.Input<typeof TeamPlayerSelection>` = `{ teamId: string, playerId: string, ... }`
1348
+ *
1349
+ * A binary field (`DynamoModel.External()`) takes any `Offload.BinaryInput`
1350
+ * (#179): its bytes, a `Stream` of them, a `BlobHandle` or `Offload.source(...)`.
1199
1351
  */
1200
1352
  export type Input<E extends {
1201
1353
  readonly model: Schema.Top;
1202
- }> = 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"]>;
1354
+ }> = E extends Entity<infer M extends Schema.Top, any, any, any, any, any, any, infer R, any, undefined, undefined, undefined, infer _P extends string, infer _Un extends string, infer _O extends OffloadFields> ? WithBinaryInput<EntityRefInputType<M, R>, OffloadFieldsOf<E>> : WithBinaryInput<EntityInputType<E["model"]>, OffloadFieldsOf<E>>;
1203
1355
  /**
1204
1356
  * Extract the create type from an Entity — input fields minus the identifier.
1205
1357
  * Uses the `identifier` config to determine which field to omit.
@@ -1210,7 +1362,7 @@ export type Input<E extends {
1210
1362
  export type Create<E extends {
1211
1363
  readonly model: Schema.Top;
1212
1364
  readonly indexes: any;
1213
- }> = 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"]>>;
1365
+ }> = 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, infer _Un extends string, infer _O extends OffloadFields> ? WithBinaryInput<EntityRefCreateType<M, I, R, Id extends string ? Id : undefined>, OffloadFieldsOf<E>> : WithBinaryInput<Omit<EntityInputType<E["model"]>, PrimaryKeyComposites<E["indexes"]>>, OffloadFieldsOf<E>>;
1214
1366
  /**
1215
1367
  * Extract the update type from an Entity. Ref-aware: when refs are present,
1216
1368
  * ref fields are replaced with optional `${field}Id?: string`.
@@ -1220,7 +1372,7 @@ export type Create<E extends {
1220
1372
  export type Update<E extends {
1221
1373
  readonly model: Schema.Top;
1222
1374
  readonly indexes: any;
1223
- }> = 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"]>;
1375
+ }> = 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, infer _Un extends string, infer _O extends OffloadFields> ? WithBinaryInput<EntityRefUpdateType<M, I, R>, OffloadFieldsOf<E>> : WithBinaryInput<EntityUpdateType<E["model"], E["indexes"]>, OffloadFieldsOf<E>>;
1224
1376
  /**
1225
1377
  * Extract the key type from an Entity.
1226
1378
  * Primary index pk + sk composite attributes only, a ref's id among them (`projectId`).
@@ -1230,7 +1382,7 @@ export type Update<E extends {
1230
1382
  export type Key<E extends {
1231
1383
  readonly model: Schema.Top;
1232
1384
  readonly indexes: any;
1233
- }> = 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"]>;
1385
+ }> = 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, infer _Un extends string, infer _O extends OffloadFields> ? EntityKeyType<M, I, R> : EntityKeyType<E["model"], E["indexes"]>;
1234
1386
  /**
1235
1387
  * Extract the full DynamoDB item type (unmarshalled).
1236
1388
  * Record + key attributes + __edd_e__.
@@ -1297,6 +1449,19 @@ export declare const itemSchema: (entity: EntityWithSchemas) => Schema.Codec<any
1297
1449
  * binary (`B`). Lambda and EventBridge Pipes deliver `B` / `BS` members as
1298
1450
  * base64 text; they are decoded at any depth.
1299
1451
  * - Sparse-map fields are rebuilt and `field:` renames reversed.
1452
+ * - **Offloaded fields** (#179) are lazy by default: an overflow field is an
1453
+ * `OffloadedValue` and a binary field a `BlobHandle`, each fetching from the
1454
+ * ambient `BlobStore` only when read, so the decode itself does no store
1455
+ * I/O. `{ offloaded: "eager" }` (or per kind, `{ overflow, binary }`)
1456
+ * resolves them as the decode runs; a store failure is then a
1457
+ * `BlobStoreError`. A value stored inline is wrapped too when lazy (its
1458
+ * `location` is `"inline"`; reading it does no I/O), and is the value
1459
+ * itself when eager.
1460
+ *
1461
+ * The result is typed {@link DecodedImage}: `unknown` for an entity that
1462
+ * offloads nothing, as before; for one that offloads, its record with each
1463
+ * offloaded field typed by the decode's modes. The error channel carries
1464
+ * `BlobStoreError` only when a mode is eager.
1300
1465
  *
1301
1466
  * Accepts DynamoDB JSON (`{ pk: { S: "…" }, … }`, `B` as bytes or base64) or
1302
1467
  * an already-unmarshalled item. Fails with `ValidationError` if the item does
@@ -1307,8 +1472,142 @@ export declare const itemSchema: (entity: EntityWithSchemas) => Schema.Codec<any
1307
1472
  * Note: {@link itemSchema} is a pure schema over unmarshalled items and does
1308
1473
  * not unpack — use this for entities with packed fields.
1309
1474
  */
1310
- export declare const decodeMarshalledItem: (entity: EntityWithSchemas & {
1475
+ export declare const decodeMarshalledItem: <E extends DecodableEntity, const M extends OffloadMode | OffloadModes = "lazy">(entity: E, marshalledItem: StreamImage, options?: DecodeMarshalledItemOptions<M>) => Effect.Effect<DecodedImage<E, M>, ValidationError | ImageBlobErrors<E, M>>;
1476
+ /**
1477
+ * What {@link decodeMarshalledItem} accepts: an entity, a pure definition, or
1478
+ * any object with its schemas (decoded by its item schema alone).
1479
+ */
1480
+ type DecodableEntity = EntityWithSchemas & {
1311
1481
  readonly entityType: string;
1312
- readonly _decodeImage?: (image: StreamImage) => Effect.Effect<unknown, ValidationError>;
1313
- }, marshalledItem: StreamImage) => Effect.Effect<unknown, ValidationError>;
1482
+ readonly _decodeImage?: ((image: StreamImage, modes?: OffloadRead.Modes) => Effect.Effect<unknown, ValidationError | BlobStoreError>) | undefined;
1483
+ readonly _decodeStreamRecord?: Entity["_decodeStreamRecord"] | undefined;
1484
+ };
1485
+ /**
1486
+ * What {@link decodeStreamRecord} accepts: an entity (`Entity.make`), which
1487
+ * carries its record decoder, or a pure definition (the schema package's
1488
+ * `Entity.make`), which carries what builds one — not a bare
1489
+ * `{ schemas, entityType }`, which knows neither its keys nor its offloaded
1490
+ * fields.
1491
+ */
1492
+ type StreamRecordEntity = DecodableEntity & ({
1493
+ readonly _decodeStreamRecord: Entity["_decodeStreamRecord"];
1494
+ } | {
1495
+ readonly _config: object;
1496
+ readonly _data: object;
1497
+ });
1498
+ /** {@link decodeMarshalledItem}'s options. */
1499
+ export interface DecodeMarshalledItemOptions<M extends OffloadMode | OffloadModes> {
1500
+ /**
1501
+ * The read modes of the item's offloaded fields (#179): lazy by default —
1502
+ * a pointer becomes a handle that fetches when read, an inline value one
1503
+ * that reads with no I/O. `"eager"` resolves them (a store failure is a
1504
+ * `BlobStoreError`). An entity that offloads nothing ignores it.
1505
+ */
1506
+ readonly offloaded?: M | undefined;
1507
+ }
1508
+ /** The fields an entity type offloads, by kind — {@link NoOffload} when none. */
1509
+ type OffloadFieldsOf<E> = E extends {
1510
+ readonly _offloadFields?: infer T;
1511
+ } ? Exclude<T, undefined> extends infer F extends OffloadFields ? F : NoOffload : NoOffload;
1512
+ /** Both kinds lazy: what a stream image decodes in by default. */
1513
+ type LazyOffloadModes = {
1514
+ readonly overflow: "lazy";
1515
+ readonly binary: "lazy";
1516
+ };
1517
+ /**
1518
+ * What {@link decodeMarshalledItem} returns: `unknown` for an entity that
1519
+ * offloads nothing (as before #179); for one that does, its record with each
1520
+ * offloaded field typed by the decode's modes ({@link Read}).
1521
+ */
1522
+ export type DecodedImage<E, M extends OffloadMode | OffloadModes> = [
1523
+ OffloadFieldsOf<E>["overflow"] | OffloadFieldsOf<E>["binary"]
1524
+ ] extends [never] ? unknown : E extends {
1525
+ readonly model: Schema.Top;
1526
+ readonly timestamps: any;
1527
+ readonly versioned: any;
1528
+ readonly timeSeries?: any;
1529
+ } ? Read<E, ResolveModes<M, LazyOffloadModes>> : unknown;
1530
+ /** The blob errors decoding an image of `E` in modes `M` raises. */
1531
+ type ImageBlobErrors<E, M extends OffloadMode | OffloadModes> = ReadBlobErrors<OffloadFieldsOf<E>, ResolveModes<M, LazyOffloadModes>>;
1532
+ export type { StreamRecordLike };
1533
+ /**
1534
+ * A DynamoDB Streams record of an entity, decoded by
1535
+ * {@link decodeStreamRecord}: the event, both images as items (each
1536
+ * `Option.none()` when the record has no image of the entity on that side —
1537
+ * an `INSERT`'s old item, a `REMOVE`'s new one), and what the change did to
1538
+ * each offloaded field present in either image, by domain name (`F`: the
1539
+ * entity's offloaded field names).
1540
+ */
1541
+ export interface EntityChange<A, F extends string = string> {
1542
+ readonly eventName: "INSERT" | "MODIFY" | "REMOVE";
1543
+ readonly oldItem: Option.Option<A>;
1544
+ readonly newItem: Option.Option<A>;
1545
+ /**
1546
+ * Each offloaded field present in either image — `unchanged`, `rewritten`
1547
+ * (probably identical: same checksum and size elsewhere), `changed`,
1548
+ * `added` or `removed` (see `Offload.OffloadChange`). Read from the stored
1549
+ * forms, with no store I/O. Empty for an entity that offloads nothing.
1550
+ */
1551
+ readonly offloaded: {
1552
+ readonly [K in F]?: OffloadChange.OffloadChange;
1553
+ };
1554
+ }
1555
+ /** {@link decodeStreamRecord}'s options. */
1556
+ export interface DecodeStreamRecordOptions<M extends OffloadMode | OffloadModes> {
1557
+ /**
1558
+ * The read modes of the images' offloaded fields (#179): lazy by default —
1559
+ * a pointer becomes a handle that fetches when read (its errors name the
1560
+ * operation `decodeStreamRecord.read`), an inline value one that reads with
1561
+ * no I/O. `"eager"` resolves them (a store failure is a `BlobStoreError`).
1562
+ * The classification in `offloaded` never reads the store, whatever the
1563
+ * mode. An entity that offloads nothing ignores it.
1564
+ */
1565
+ readonly offloaded?: M | undefined;
1566
+ }
1567
+ /** The item type of {@link decodeStreamRecord}'s images: the entity's record under modes `M`. */
1568
+ export type StreamRecordItem<E, M extends OffloadMode | OffloadModes> = E extends {
1569
+ readonly model: Schema.Top;
1570
+ readonly timestamps: any;
1571
+ readonly versioned: any;
1572
+ readonly timeSeries?: any;
1573
+ } ? Read<E, ResolveModes<M, LazyOffloadModes>> : unknown;
1574
+ /** The domain names of the fields an entity offloads (`never` when none). */
1575
+ export type OffloadedFieldNames<E> = OffloadFieldsOf<E>["overflow"] | OffloadFieldsOf<E>["binary"];
1576
+ /**
1577
+ * Decode a DynamoDB Streams record of an entity (#179, design §3.9, §10.3) —
1578
+ * both images, and what the change did to each offloaded field — as a
1579
+ * change-feed consumer needs it: to index, scan or forward only what changed.
1580
+ *
1581
+ * - **Records.** Structural ({@link StreamRecordLike}): the SDK's `_Record`
1582
+ * (the change feed's), a Lambda `DynamoDBRecord` and an EventBridge Pipes
1583
+ * record fit; images in DynamoDB JSON (`B` as bytes or base64) or
1584
+ * unmarshalled. The stream must be `NEW_AND_OLD_IMAGES`: a record whose
1585
+ * `StreamViewType` is another, or that lacks an image its event has (a
1586
+ * `MODIFY` / `REMOVE` without `OldImage`, a `MODIFY` / `INSERT` without
1587
+ * `NewImage`), fails with a `ValidationError` carrying `[EDD-9119]` —
1588
+ * checked on every record, whatever its entity type.
1589
+ * - **Other types.** `Option.none()` when no image is of this entity type
1590
+ * (another entity's item, a unique-constraint sentinel, an untyped item).
1591
+ * - **Items** decode exactly as {@link decodeMarshalledItem} decodes an image
1592
+ * (packed fields unpacked, renames reversed, sparse maps rebuilt) — lazy by
1593
+ * default: an offloaded field is an `OffloadedValue` / `BlobHandle` that
1594
+ * fetches only when read; `{ offloaded: "eager" }` resolves them.
1595
+ * - **`offloaded`** classifies each offloaded field present in either image
1596
+ * (see {@link EntityChange}) from the stored forms alone — no store I/O in
1597
+ * any mode. `rewritten` means probably identical: treat it as `changed`
1598
+ * where a change must never be missed.
1599
+ *
1600
+ * A handle read long after its record (a lagging consumer) may fail with
1601
+ * `NotFound` once its version was superseded and reaped: the newer record
1602
+ * carries the newer pointer, so treat it as superseded (design §8.7).
1603
+ *
1604
+ * @example
1605
+ * ```ts
1606
+ * const change = yield* Entity.decodeStreamRecord(Documents, record)
1607
+ * if (Option.isSome(change) && change.value.offloaded.body !== "unchanged") {
1608
+ * yield* reindex(change.value.newItem)
1609
+ * }
1610
+ * ```
1611
+ */
1612
+ export declare const decodeStreamRecord: <E extends StreamRecordEntity, const M extends OffloadMode | OffloadModes = "lazy">(entity: E, record: StreamRecordLike, options?: DecodeStreamRecordOptions<M>) => Effect.Effect<Option.Option<EntityChange<StreamRecordItem<E, M>, OffloadedFieldNames<E>>>, ValidationError | ImageBlobErrors<E, M>>;
1314
1613
  //# sourceMappingURL=Entity.d.ts.map