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
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Offload — the vocabulary of offloaded storage (#179): read modes, the lazy
3
+ * forms of offloaded values, the type-level view a read returns, and what a
4
+ * binary field takes on a write.
5
+ *
6
+ * - **Read modes.** An overflow field (`DynamoModel.Packed({ external })`) is
7
+ * read `"eager"` by default — its domain value, resolved from the store; a
8
+ * binary field (`DynamoModel.External()`) `"lazy"` — a {@link BlobHandle}.
9
+ * `.offloaded(mode)` on a read chooses per kind ({@link OffloadModes}).
10
+ * - **Lazy values.** {@link OffloadedValue} (overflow) and {@link BlobHandle}
11
+ * (binary) carry the ref, size and content checksum, and read on demand
12
+ * with `R = never`.
13
+ * - **{@link View}** is the type of a read's result: the model with each
14
+ * offloaded field typed by its mode. For a member that offloads nothing it
15
+ * is the model itself.
16
+ * - **Binary inputs.** A binary field takes a {@link BinaryInput} on a write:
17
+ * its bytes, a `Stream` of them (single-use: one target object, run once),
18
+ * a {@link BlobHandle} (content to copy into a new version) or
19
+ * {@link source}`(bytes | stream, { contentType, contentLength })`.
20
+ * - **{@link layerObserver}** reports every upload the library could not
21
+ * settle (an unknown DynamoDB outcome, a failed rollback delete, a lost
22
+ * multipart completion), so the application can queue the item for
23
+ * `gc.sweep`.
24
+ * - **{@link compareStored}** classifies what a change did to one offloaded
25
+ * field from its stored old and new attribute values, without the blob
26
+ * store ({@link OffloadChange}) — the raw form of
27
+ * `Entity.decodeStreamRecord`'s `offloaded`.
28
+ *
29
+ * See `DESIGN.md §7 "Offloaded Storage"`.
30
+ */
31
+ import type { NoOffload, OffloadFields } from "@effect-dynamodb/schema/DynamoModel.js";
32
+ import type { ValidationError } from "@effect-dynamodb/schema/Errors.js";
33
+ import type { DefaultOffloadModes, OffloadMode, ResolvedOffloadModes } from "@effect-dynamodb/schema/internal/EntityTypes.js";
34
+ import type { Effect, Layer } from "effect";
35
+ import { type ObserverOptions } from "./internal/BlobLedger.js";
36
+ import * as OffloadChange from "./internal/OffloadChange.js";
37
+ import type { BlobHandle, OffloadedValue, OffloadKind } from "./internal/OffloadValues.js";
38
+ export type { ExternalConfig, ExternalPackedConfig, ExtractOffloadFields, NoOffload, OffloadFields, } from "@effect-dynamodb/schema/DynamoModel.js";
39
+ export type { BlobChecksum, BlobRef } from "@effect-dynamodb/schema/internal/BlobPointer.js";
40
+ export type { DefaultOffloadModes, OffloadMode, OpBlobErrors, ReadBlobErrors, ResolvedOffloadModes, WriteBlobErrors, } from "@effect-dynamodb/schema/internal/EntityTypes.js";
41
+ export type { ObserverOptions, UnsettledReason, UnsettledUpload, } from "./internal/BlobLedger.js";
42
+ export type { ByteRange } from "./internal/BlobStoreContract.js";
43
+ export type { OffloadChange, StoredAttributeValue, } from "./internal/OffloadChange.js";
44
+ export type { BinaryInput, BlobSource, BlobSourceOptions } from "./internal/OffloadInput.js";
45
+ export { BlobSourceTypeId, isBlobSource, source } from "./internal/OffloadInput.js";
46
+ export type { BlobHandle, OffloadedValue, OffloadKind, OffloadLocation, } from "./internal/OffloadValues.js";
47
+ export { BlobHandleTypeId, isBlobHandle, isOffloadedValue, OffloadedValueTypeId, } from "./internal/OffloadValues.js";
48
+ /**
49
+ * The read modes `.offloaded(...)` takes per kind: a string sets both kinds,
50
+ * an object the kinds it names.
51
+ */
52
+ export interface OffloadModes {
53
+ readonly overflow?: OffloadMode | undefined;
54
+ readonly binary?: OffloadMode | undefined;
55
+ }
56
+ /**
57
+ * One kind's mode: `V` (the argument's property) when it is surely a mode,
58
+ * `Base` when it is surely absent, and the union of the two when it may be
59
+ * either (an optional property, a widened `OffloadModes`) — so a view or an
60
+ * error union over the result never under-reports.
61
+ */
62
+ type ResolveKind<V, Base extends OffloadMode> = [V] extends [OffloadMode] ? V : Extract<V, OffloadMode> | Base;
63
+ /**
64
+ * The {@link ResolvedOffloadModes} of `M` over `Base` (the modes in effect
65
+ * before it; default {@link DefaultOffloadModes}): a string sets both kinds,
66
+ * an object overrides the kinds it names. A kind the object may or may not
67
+ * set (an optional property, `OffloadModes` itself) resolves to its mode or
68
+ * `Base`'s, which `View` types as either form and `ReadBlobErrors` counts as
69
+ * eager.
70
+ */
71
+ export type ResolveModes<M extends OffloadMode | OffloadModes, Base extends ResolvedOffloadModes = DefaultOffloadModes> = M extends OffloadMode ? {
72
+ readonly overflow: M;
73
+ readonly binary: M;
74
+ } : M extends OffloadModes ? {
75
+ readonly overflow: ResolveKind<M["overflow"], Base["overflow"]>;
76
+ readonly binary: ResolveKind<M["binary"], Base["binary"]>;
77
+ } : never;
78
+ /** A lazily read value's type: `null` / `undefined` members stay as they are. */
79
+ export type Lazy<V, H> = V extends null | undefined ? V : H;
80
+ /**
81
+ * One field's type under mode `Mode`: the value when eager, the handle when
82
+ * lazy, either when the mode is not a single literal.
83
+ */
84
+ type ByMode<V, H, Mode> = [Mode] extends ["eager"] ? V : [Mode] extends ["lazy"] ? Lazy<V, H> : V | Lazy<V, H>;
85
+ /**
86
+ * A read's result type: `A` with each offloaded field of `T` typed by the
87
+ * modes `M` — an eager field its value, a lazy overflow field
88
+ * `OffloadedValue<value>`, a lazy binary field `BlobHandle`. Optional and
89
+ * nullable fields keep their `undefined` / `null`. For a member that
90
+ * offloads nothing — and for `T = any` (type-erased code, as `ReadBlobErrors`
91
+ * reads it) — exactly `A`.
92
+ */
93
+ export type View<A, T extends OffloadFields, M extends ResolvedOffloadModes = DefaultOffloadModes> = 0 extends 1 & T ? A : [T["overflow"] | T["binary"]] extends [never] ? A : {
94
+ readonly [K in keyof A]: K extends T["overflow"] ? ByMode<A[K], OffloadedValue<NonNullable<A[K]>>, M["overflow"]> : K extends T["binary"] ? ByMode<A[K], BlobHandle, M["binary"]> : A[K];
95
+ };
96
+ /**
97
+ * What a builder needs to re-type its result under other modes: the
98
+ * member's offloaded fields, the builder's effective modes, and the pre-view
99
+ * item (the model, a record, a selected partial, an update's return).
100
+ */
101
+ export interface OffloadState {
102
+ readonly fields: OffloadFields;
103
+ readonly modes: ResolvedOffloadModes;
104
+ readonly item: unknown;
105
+ }
106
+ /** The state of a builder over a member that offloads nothing. */
107
+ export type NoOffloadState = {
108
+ readonly fields: NoOffload;
109
+ readonly modes: DefaultOffloadModes;
110
+ readonly item: never;
111
+ };
112
+ /** The result type a builder in state `O` returns. */
113
+ export type ViewOf<O extends OffloadState> = View<O["item"], O["fields"], O["modes"]>;
114
+ /**
115
+ * Report every upload the library could not settle — for everything run
116
+ * under this layer, and for every client bound (`DynamoClient.make`,
117
+ * `EventStore.bind`, …) while it was in context.
118
+ *
119
+ * A write uploads its offloaded values before it reaches DynamoDB, and keeps
120
+ * a version only when DynamoDB committed the write, or may have. The
121
+ * library deletes a version only when DynamoDB provably did not commit the
122
+ * write; the rest it cannot settle, and reports here once the operation
123
+ * exits:
124
+ *
125
+ * - `inDoubt` — the write's outcome is unknown (a timeout, an
126
+ * `InternalServerError`, an interruption while it was in flight, a refusal
127
+ * after an SDK retry): the version is kept;
128
+ * - `rollbackFailed` — DynamoDB rejected the write but the delete of its
129
+ * version failed: the version is left behind;
130
+ * - `completeLost` — a multipart upload completed but its response was lost:
131
+ * the version it made has no pointer;
132
+ * - `interrupted` — the operation was interrupted while an upload was in
133
+ * flight: a version the store may have written has no pointer (reported
134
+ * for every interrupted upload, since the library cannot tell);
135
+ * - `answerRefused` — the store's answer to an upload broke the `BlobStore`
136
+ * contract (no ref, a ref outside the requested key, a ref it had already
137
+ * returned) and was refused: the version it wrote, if any, has no pointer.
138
+ *
139
+ * The last three name the requested `key` with `ref: Option.none()`; the
140
+ * others carry the version as `Option.some(ref)`.
141
+ *
142
+ * Each is also logged at `Warning`. Queue the item (`rowKey`) for `gc.sweep`;
143
+ * `gc.sweepStore` finds what no process could report. A failing observer is
144
+ * logged and never changes the operation's result. Off by default.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * // `enqueueSweep` is the application's own: e.g. a queue a sweeper drains.
149
+ * const AppLayer = Layer.mergeAll(
150
+ * DynamoClient.layer({ region: "eu-west-1" }),
151
+ * BlobStore.layer(store),
152
+ * Offload.layerObserver({
153
+ * onUnsettled: (upload) => enqueueSweep({ table: upload.table, key: upload.rowKey }),
154
+ * }),
155
+ * )
156
+ * ```
157
+ */
158
+ export declare const layerObserver: (options: ObserverOptions) => Layer.Layer<never>;
159
+ /**
160
+ * What a change did to one offloaded field (design §10.3), read from the
161
+ * stored attribute values of its old and new images — DynamoDB JSON, `B` as
162
+ * bytes or base64 text as Lambda and EventBridge Pipes deliver it;
163
+ * `undefined` when an image has no such attribute. `kind` is the field's:
164
+ * `"overflow"` (`Packed({ external })`) or `"binary"` (`External`).
165
+ *
166
+ * - `unchanged` — a pointer to the same object version, or inline values
167
+ * with the same content;
168
+ * - `rewritten` — another version, or another stored form, with the same
169
+ * checksum algorithm, content checksum and content size: **probably** the
170
+ * same content (a CRC can be matched by crafted content — a consumer that
171
+ * must not miss a change treats it as `changed`, or compares the content);
172
+ * - `changed` — different content, or no canonical bytes to compare (a
173
+ * legacy native map against any other form);
174
+ * - `added` / `removed` — only in the new / old image (both absent:
175
+ * `unchanged`).
176
+ *
177
+ * Never touches the blob store. An inline compressed value is decompressed
178
+ * with the `Compression` service in scope to checksum its content (without
179
+ * its codec: a `ValidationError` whose `cause` is a `CompressorNotRegistered`).
180
+ * A value that is not a stored form of `kind` — a malformed pointer, an `S`
181
+ * value on a binary attribute that is not a pointer, a binary field's
182
+ * `~edbp:` text on an overflow attribute — fails with a `ValidationError`.
183
+ * A member set to `undefined` is no member: `{ S: "…", B: undefined }` is an
184
+ * `S` value. `Entity.decodeStreamRecord` applies it to every offloaded field
185
+ * of a record.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * // `record` is a DynamoDB Streams record of a NEW_AND_OLD_IMAGES stream.
190
+ * const change = yield* Offload.compareStored(
191
+ * record.dynamodb.OldImage?.body,
192
+ * record.dynamodb.NewImage?.body,
193
+ * "overflow",
194
+ * )
195
+ * if (change !== "unchanged") yield* reindex(record)
196
+ * ```
197
+ */
198
+ export declare const compareStored: (oldValue: OffloadChange.StoredAttributeValue | undefined, newValue: OffloadChange.StoredAttributeValue | undefined, kind: OffloadKind) => Effect.Effect<OffloadChange.OffloadChange, ValidationError>;
199
+ //# sourceMappingURL=Offload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Offload.d.ts","sourceRoot":"","sources":["../src/Offload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;A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AAA;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,aAAa,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,KAAK,CAAC,KAAK,CAAC,KAAK,CAAqB,CAAA;AAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,aAAa,EAAE,CAC1B,QAAQ,EAAE,aAAa,CAAC,oBAAoB,GAAG,SAAS,EACxD,QAAQ,EAAE,aAAa,CAAC,oBAAoB,GAAG,SAAS,EACxD,IAAI,EAAE,WAAW,KACd,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,EAAE,eAAe,CAA+B,CAAA"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Offload — the vocabulary of offloaded storage (#179): read modes, the lazy
3
+ * forms of offloaded values, the type-level view a read returns, and what a
4
+ * binary field takes on a write.
5
+ *
6
+ * - **Read modes.** An overflow field (`DynamoModel.Packed({ external })`) is
7
+ * read `"eager"` by default — its domain value, resolved from the store; a
8
+ * binary field (`DynamoModel.External()`) `"lazy"` — a {@link BlobHandle}.
9
+ * `.offloaded(mode)` on a read chooses per kind ({@link OffloadModes}).
10
+ * - **Lazy values.** {@link OffloadedValue} (overflow) and {@link BlobHandle}
11
+ * (binary) carry the ref, size and content checksum, and read on demand
12
+ * with `R = never`.
13
+ * - **{@link View}** is the type of a read's result: the model with each
14
+ * offloaded field typed by its mode. For a member that offloads nothing it
15
+ * is the model itself.
16
+ * - **Binary inputs.** A binary field takes a {@link BinaryInput} on a write:
17
+ * its bytes, a `Stream` of them (single-use: one target object, run once),
18
+ * a {@link BlobHandle} (content to copy into a new version) or
19
+ * {@link source}`(bytes | stream, { contentType, contentLength })`.
20
+ * - **{@link layerObserver}** reports every upload the library could not
21
+ * settle (an unknown DynamoDB outcome, a failed rollback delete, a lost
22
+ * multipart completion), so the application can queue the item for
23
+ * `gc.sweep`.
24
+ * - **{@link compareStored}** classifies what a change did to one offloaded
25
+ * field from its stored old and new attribute values, without the blob
26
+ * store ({@link OffloadChange}) — the raw form of
27
+ * `Entity.decodeStreamRecord`'s `offloaded`.
28
+ *
29
+ * See `DESIGN.md §7 "Offloaded Storage"`.
30
+ */
31
+ import { layerObserver as makeObserverLayer } from "./internal/BlobLedger.js";
32
+ import * as OffloadChange from "./internal/OffloadChange.js";
33
+ export { BlobSourceTypeId, isBlobSource, source } from "./internal/OffloadInput.js";
34
+ export { BlobHandleTypeId, isBlobHandle, isOffloadedValue, OffloadedValueTypeId, } from "./internal/OffloadValues.js";
35
+ /**
36
+ * Report every upload the library could not settle — for everything run
37
+ * under this layer, and for every client bound (`DynamoClient.make`,
38
+ * `EventStore.bind`, …) while it was in context.
39
+ *
40
+ * A write uploads its offloaded values before it reaches DynamoDB, and keeps
41
+ * a version only when DynamoDB committed the write, or may have. The
42
+ * library deletes a version only when DynamoDB provably did not commit the
43
+ * write; the rest it cannot settle, and reports here once the operation
44
+ * exits:
45
+ *
46
+ * - `inDoubt` — the write's outcome is unknown (a timeout, an
47
+ * `InternalServerError`, an interruption while it was in flight, a refusal
48
+ * after an SDK retry): the version is kept;
49
+ * - `rollbackFailed` — DynamoDB rejected the write but the delete of its
50
+ * version failed: the version is left behind;
51
+ * - `completeLost` — a multipart upload completed but its response was lost:
52
+ * the version it made has no pointer;
53
+ * - `interrupted` — the operation was interrupted while an upload was in
54
+ * flight: a version the store may have written has no pointer (reported
55
+ * for every interrupted upload, since the library cannot tell);
56
+ * - `answerRefused` — the store's answer to an upload broke the `BlobStore`
57
+ * contract (no ref, a ref outside the requested key, a ref it had already
58
+ * returned) and was refused: the version it wrote, if any, has no pointer.
59
+ *
60
+ * The last three name the requested `key` with `ref: Option.none()`; the
61
+ * others carry the version as `Option.some(ref)`.
62
+ *
63
+ * Each is also logged at `Warning`. Queue the item (`rowKey`) for `gc.sweep`;
64
+ * `gc.sweepStore` finds what no process could report. A failing observer is
65
+ * logged and never changes the operation's result. Off by default.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * // `enqueueSweep` is the application's own: e.g. a queue a sweeper drains.
70
+ * const AppLayer = Layer.mergeAll(
71
+ * DynamoClient.layer({ region: "eu-west-1" }),
72
+ * BlobStore.layer(store),
73
+ * Offload.layerObserver({
74
+ * onUnsettled: (upload) => enqueueSweep({ table: upload.table, key: upload.rowKey }),
75
+ * }),
76
+ * )
77
+ * ```
78
+ */
79
+ export const layerObserver = makeObserverLayer;
80
+ /**
81
+ * What a change did to one offloaded field (design §10.3), read from the
82
+ * stored attribute values of its old and new images — DynamoDB JSON, `B` as
83
+ * bytes or base64 text as Lambda and EventBridge Pipes deliver it;
84
+ * `undefined` when an image has no such attribute. `kind` is the field's:
85
+ * `"overflow"` (`Packed({ external })`) or `"binary"` (`External`).
86
+ *
87
+ * - `unchanged` — a pointer to the same object version, or inline values
88
+ * with the same content;
89
+ * - `rewritten` — another version, or another stored form, with the same
90
+ * checksum algorithm, content checksum and content size: **probably** the
91
+ * same content (a CRC can be matched by crafted content — a consumer that
92
+ * must not miss a change treats it as `changed`, or compares the content);
93
+ * - `changed` — different content, or no canonical bytes to compare (a
94
+ * legacy native map against any other form);
95
+ * - `added` / `removed` — only in the new / old image (both absent:
96
+ * `unchanged`).
97
+ *
98
+ * Never touches the blob store. An inline compressed value is decompressed
99
+ * with the `Compression` service in scope to checksum its content (without
100
+ * its codec: a `ValidationError` whose `cause` is a `CompressorNotRegistered`).
101
+ * A value that is not a stored form of `kind` — a malformed pointer, an `S`
102
+ * value on a binary attribute that is not a pointer, a binary field's
103
+ * `~edbp:` text on an overflow attribute — fails with a `ValidationError`.
104
+ * A member set to `undefined` is no member: `{ S: "…", B: undefined }` is an
105
+ * `S` value. `Entity.decodeStreamRecord` applies it to every offloaded field
106
+ * of a record.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * // `record` is a DynamoDB Streams record of a NEW_AND_OLD_IMAGES stream.
111
+ * const change = yield* Offload.compareStored(
112
+ * record.dynamodb.OldImage?.body,
113
+ * record.dynamodb.NewImage?.body,
114
+ * "overflow",
115
+ * )
116
+ * if (change !== "unchanged") yield* reindex(record)
117
+ * ```
118
+ */
119
+ export const compareStored = OffloadChange.compareStored;
120
+ //# sourceMappingURL=Offload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Offload.js","sourceRoot":"","sources":["../src/Offload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAUH,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAwB,MAAM,0BAA0B,CAAA;AACnG,OAAO,KAAK,aAAa,MAAM,6BAA6B,CAAA;AA8B5D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAOnF,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,6BAA6B,CAAA;AAmGpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,CAAC,MAAM,aAAa,GAAqD,iBAAiB,CAAA;AAEhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,MAAM,aAAa,GAIyC,aAAa,CAAC,aAAa,CAAA"}