@farukada/aws-langgraph-dynamodb-ts 1.0.0-rc.1 → 1.0.0-rc.2

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 (324) hide show
  1. package/README.md +1621 -288
  2. package/dist/backfill/backfill.d.ts +168 -0
  3. package/dist/backfill/backfill.js +393 -0
  4. package/dist/checkpointer/actions/delete-thread.d.ts +44 -4
  5. package/dist/checkpointer/actions/delete-thread.js +56 -22
  6. package/dist/checkpointer/actions/get-tuple.d.ts +29 -5
  7. package/dist/checkpointer/actions/get-tuple.js +41 -13
  8. package/dist/checkpointer/actions/list.d.ts +42 -10
  9. package/dist/checkpointer/actions/list.js +86 -57
  10. package/dist/checkpointer/actions/put-writes.d.ts +41 -9
  11. package/dist/checkpointer/actions/put-writes.js +62 -48
  12. package/dist/checkpointer/actions/put.d.ts +82 -10
  13. package/dist/checkpointer/actions/put.js +166 -44
  14. package/dist/checkpointer/internal/delta-history.d.ts +112 -0
  15. package/dist/checkpointer/internal/delta-history.js +252 -0
  16. package/dist/checkpointer/internal/listing.d.ts +149 -0
  17. package/dist/checkpointer/internal/listing.js +245 -0
  18. package/dist/checkpointer/internal/parse.d.ts +262 -0
  19. package/dist/checkpointer/internal/parse.js +372 -0
  20. package/dist/checkpointer/internal/pending-writes.d.ts +275 -0
  21. package/dist/checkpointer/internal/pending-writes.js +588 -0
  22. package/dist/checkpointer/internal/read.d.ts +130 -0
  23. package/dist/checkpointer/internal/read.js +264 -0
  24. package/dist/checkpointer/internal/rows.d.ts +571 -0
  25. package/dist/checkpointer/internal/rows.js +834 -0
  26. package/dist/checkpointer/internal/setup.d.ts +42 -21
  27. package/dist/checkpointer/internal/setup.js +65 -31
  28. package/dist/checkpointer/saver.d.ts +242 -42
  29. package/dist/checkpointer/saver.js +257 -53
  30. package/dist/checkpointer/types.d.ts +37 -44
  31. package/dist/checkpointer/types.js +10 -0
  32. package/dist/factory/factory.d.ts +120 -11
  33. package/dist/factory/factory.js +195 -16
  34. package/dist/factory/types.d.ts +23 -4
  35. package/dist/factory/types.js +8 -0
  36. package/dist/history/actions/add-messages.d.ts +30 -2
  37. package/dist/history/actions/add-messages.js +37 -57
  38. package/dist/history/actions/clear.d.ts +46 -4
  39. package/dist/history/actions/clear.js +64 -15
  40. package/dist/history/actions/get-messages.d.ts +41 -0
  41. package/dist/history/actions/get-messages.js +94 -32
  42. package/dist/history/actions/list-sessions.d.ts +52 -10
  43. package/dist/history/actions/list-sessions.js +141 -38
  44. package/dist/history/actions/reconcile-count.d.ts +41 -8
  45. package/dist/history/actions/reconcile-count.js +44 -57
  46. package/dist/history/chat-message-history.d.ts +200 -38
  47. package/dist/history/chat-message-history.js +218 -51
  48. package/dist/history/internal/append.d.ts +212 -0
  49. package/dist/history/internal/append.js +500 -0
  50. package/dist/history/internal/message-read.d.ts +84 -0
  51. package/dist/history/internal/message-read.js +204 -0
  52. package/dist/history/internal/parse.d.ts +153 -0
  53. package/dist/history/internal/parse.js +252 -0
  54. package/dist/history/internal/rows.d.ts +195 -0
  55. package/dist/history/internal/rows.js +250 -0
  56. package/dist/history/internal/session.d.ts +331 -0
  57. package/dist/history/internal/session.js +628 -0
  58. package/dist/history/internal/setup.d.ts +52 -19
  59. package/dist/history/internal/setup.js +90 -27
  60. package/dist/history/session-adapter.d.ts +95 -6
  61. package/dist/history/session-adapter.js +99 -8
  62. package/dist/history/types.d.ts +61 -31
  63. package/dist/history/types.js +10 -0
  64. package/dist/index.d.ts +38 -14
  65. package/dist/index.js +31 -12
  66. package/dist/shared/adapter.d.ts +135 -0
  67. package/dist/shared/adapter.js +143 -0
  68. package/dist/shared/clock.d.ts +48 -4
  69. package/dist/shared/clock.js +51 -4
  70. package/dist/shared/codec/codec.d.ts +275 -9
  71. package/dist/shared/codec/codec.js +394 -19
  72. package/dist/shared/codec/compression.d.ts +43 -6
  73. package/dist/shared/codec/compression.js +52 -11
  74. package/dist/shared/codec/json-serde.d.ts +76 -3
  75. package/dist/shared/codec/json-serde.js +181 -7
  76. package/dist/shared/codec/s3/client-types.d.ts +20 -1
  77. package/dist/shared/codec/s3/client-types.js +20 -1
  78. package/dist/shared/codec/s3/client.d.ts +35 -8
  79. package/dist/shared/codec/s3/client.js +61 -10
  80. package/dist/shared/codec/s3/config.d.ts +226 -22
  81. package/dist/shared/codec/s3/config.js +274 -24
  82. package/dist/shared/codec/s3/lifecycle.d.ts +163 -11
  83. package/dist/shared/codec/s3/lifecycle.js +328 -36
  84. package/dist/shared/codec/s3/offloader.d.ts +390 -19
  85. package/dist/shared/codec/s3/offloader.js +590 -50
  86. package/dist/shared/concurrency.d.ts +40 -3
  87. package/dist/shared/concurrency.js +55 -7
  88. package/dist/shared/dynamodb/abort.d.ts +45 -7
  89. package/dist/shared/dynamodb/abort.js +46 -14
  90. package/dist/shared/dynamodb/batch-write.d.ts +77 -13
  91. package/dist/shared/dynamodb/batch-write.js +146 -26
  92. package/dist/shared/dynamodb/cancellation.d.ts +121 -3
  93. package/dist/shared/dynamodb/cancellation.js +147 -2
  94. package/dist/shared/dynamodb/client.d.ts +159 -12
  95. package/dist/shared/dynamodb/client.js +135 -10
  96. package/dist/shared/dynamodb/idempotent-write.d.ts +551 -0
  97. package/dist/shared/dynamodb/idempotent-write.js +593 -0
  98. package/dist/shared/dynamodb/paginate.d.ts +105 -8
  99. package/dist/shared/dynamodb/paginate.js +175 -6
  100. package/dist/shared/dynamodb/partition-delete.d.ts +181 -16
  101. package/dist/shared/dynamodb/partition-delete.js +312 -43
  102. package/dist/shared/dynamodb/recency-index.d.ts +231 -0
  103. package/dist/shared/dynamodb/recency-index.js +377 -0
  104. package/dist/shared/dynamodb/retry.d.ts +265 -10
  105. package/dist/shared/dynamodb/retry.js +426 -20
  106. package/dist/shared/dynamodb/table-schema.d.ts +190 -0
  107. package/dist/shared/dynamodb/table-schema.js +209 -0
  108. package/dist/shared/errors/base-error.d.ts +174 -8
  109. package/dist/shared/errors/base-error.js +154 -7
  110. package/dist/shared/errors/boundary.d.ts +63 -10
  111. package/dist/shared/errors/boundary.js +110 -13
  112. package/dist/shared/errors/classify.d.ts +97 -0
  113. package/dist/shared/errors/classify.js +257 -0
  114. package/dist/shared/errors/error-code.d.ts +76 -1
  115. package/dist/shared/errors/error-code.js +83 -1
  116. package/dist/shared/errors/errors.d.ts +157 -58
  117. package/dist/shared/errors/errors.js +218 -93
  118. package/dist/shared/logging/logger.d.ts +63 -1
  119. package/dist/shared/logging/logger.js +97 -2
  120. package/dist/shared/logging/redaction.d.ts +86 -6
  121. package/dist/shared/logging/redaction.js +265 -24
  122. package/dist/shared/logging/secret-patterns.d.ts +136 -24
  123. package/dist/shared/logging/secret-patterns.js +165 -30
  124. package/dist/shared/logging/truncate.d.ts +197 -0
  125. package/dist/shared/logging/truncate.js +231 -0
  126. package/dist/shared/options.d.ts +52 -5
  127. package/dist/shared/options.js +9 -0
  128. package/dist/shared/ulid.d.ts +71 -14
  129. package/dist/shared/ulid.js +77 -14
  130. package/dist/shared/validation/collaborators.d.ts +141 -0
  131. package/dist/shared/validation/collaborators.js +188 -0
  132. package/dist/shared/validation/option-shape.d.ts +89 -0
  133. package/dist/shared/validation/option-shape.js +113 -0
  134. package/dist/shared/validation/options.d.ts +142 -5
  135. package/dist/shared/validation/options.js +284 -46
  136. package/dist/shared/validation/primitives.d.ts +287 -24
  137. package/dist/shared/validation/primitives.js +347 -42
  138. package/dist/shared/validation/ttl.d.ts +61 -12
  139. package/dist/shared/validation/ttl.js +102 -22
  140. package/dist/store/actions/list-namespaces.d.ts +76 -5
  141. package/dist/store/actions/list-namespaces.js +160 -22
  142. package/dist/store/actions/put.d.ts +33 -7
  143. package/dist/store/actions/put.js +53 -71
  144. package/dist/store/actions/reconcile-vector-index.d.ts +28 -8
  145. package/dist/store/actions/reconcile-vector-index.js +33 -13
  146. package/dist/store/actions/search.d.ts +34 -5
  147. package/dist/store/actions/search.js +52 -20
  148. package/dist/store/internal/batch-plan.d.ts +24 -9
  149. package/dist/store/internal/batch-plan.js +91 -34
  150. package/dist/store/internal/filter.d.ts +36 -2
  151. package/dist/store/internal/filter.js +66 -14
  152. package/dist/store/internal/get-item.d.ts +45 -0
  153. package/dist/store/internal/get-item.js +115 -0
  154. package/dist/store/internal/item-write.d.ts +230 -0
  155. package/dist/store/internal/item-write.js +463 -0
  156. package/dist/store/internal/parse.d.ts +225 -0
  157. package/dist/store/internal/parse.js +350 -0
  158. package/dist/store/internal/rows.d.ts +355 -0
  159. package/dist/store/internal/rows.js +447 -0
  160. package/dist/store/internal/semantic-search.d.ts +146 -12
  161. package/dist/store/internal/semantic-search.js +317 -15
  162. package/dist/store/internal/setup.d.ts +86 -21
  163. package/dist/store/internal/setup.js +209 -26
  164. package/dist/store/internal/table-search.d.ts +100 -0
  165. package/dist/store/internal/table-search.js +213 -0
  166. package/dist/store/internal/vector-index.d.ts +247 -0
  167. package/dist/store/internal/vector-index.js +546 -0
  168. package/dist/store/store.d.ts +258 -33
  169. package/dist/store/store.js +309 -53
  170. package/dist/store/types.d.ts +74 -28
  171. package/dist/store/types.js +13 -0
  172. package/dist/store/vector-backend.d.ts +64 -3
  173. package/dist/store/vector-backend.js +15 -0
  174. package/package.json +41 -25
  175. package/dist/checkpointer/internal/assemble.d.ts +0 -17
  176. package/dist/checkpointer/internal/assemble.js +0 -38
  177. package/dist/checkpointer/internal/checkpoint-write-verify.d.ts +0 -24
  178. package/dist/checkpointer/internal/checkpoint-write-verify.js +0 -67
  179. package/dist/checkpointer/internal/configurable.d.ts +0 -12
  180. package/dist/checkpointer/internal/configurable.js +0 -24
  181. package/dist/checkpointer/internal/fetch.d.ts +0 -19
  182. package/dist/checkpointer/internal/fetch.js +0 -88
  183. package/dist/checkpointer/internal/filter-match.d.ts +0 -13
  184. package/dist/checkpointer/internal/filter-match.js +0 -15
  185. package/dist/checkpointer/internal/item-reader.d.ts +0 -66
  186. package/dist/checkpointer/internal/item-reader.js +0 -113
  187. package/dist/checkpointer/internal/item-writer.d.ts +0 -35
  188. package/dist/checkpointer/internal/item-writer.js +0 -107
  189. package/dist/checkpointer/internal/keys.d.ts +0 -41
  190. package/dist/checkpointer/internal/keys.js +0 -117
  191. package/dist/checkpointer/internal/list-scope.d.ts +0 -61
  192. package/dist/checkpointer/internal/list-scope.js +0 -108
  193. package/dist/checkpointer/internal/pending-sends.d.ts +0 -13
  194. package/dist/checkpointer/internal/pending-sends.js +0 -29
  195. package/dist/checkpointer/internal/query.d.ts +0 -21
  196. package/dist/checkpointer/internal/query.js +0 -42
  197. package/dist/checkpointer/internal/regular-write.d.ts +0 -28
  198. package/dist/checkpointer/internal/regular-write.js +0 -66
  199. package/dist/checkpointer/internal/special-write-cas.d.ts +0 -29
  200. package/dist/checkpointer/internal/special-write-cas.js +0 -104
  201. package/dist/checkpointer/internal/special-write-cleanup.d.ts +0 -23
  202. package/dist/checkpointer/internal/special-write-cleanup.js +0 -50
  203. package/dist/checkpointer/internal/special-write-verify.d.ts +0 -53
  204. package/dist/checkpointer/internal/special-write-verify.js +0 -80
  205. package/dist/checkpointer/internal/stored-channels.d.ts +0 -31
  206. package/dist/checkpointer/internal/stored-channels.js +0 -70
  207. package/dist/checkpointer/internal/validation.d.ts +0 -18
  208. package/dist/checkpointer/internal/validation.js +0 -40
  209. package/dist/checkpointer/internal/write-guard.d.ts +0 -20
  210. package/dist/checkpointer/internal/write-guard.js +0 -48
  211. package/dist/checkpointer/internal/write-index.d.ts +0 -36
  212. package/dist/checkpointer/internal/write-index.js +0 -41
  213. package/dist/history/internal/append-saga.d.ts +0 -25
  214. package/dist/history/internal/append-saga.js +0 -79
  215. package/dist/history/internal/compensation.d.ts +0 -25
  216. package/dist/history/internal/compensation.js +0 -92
  217. package/dist/history/internal/item-mapper.d.ts +0 -9
  218. package/dist/history/internal/item-mapper.js +0 -27
  219. package/dist/history/internal/keys.d.ts +0 -16
  220. package/dist/history/internal/keys.js +0 -48
  221. package/dist/history/internal/message-chunker.d.ts +0 -13
  222. package/dist/history/internal/message-chunker.js +0 -67
  223. package/dist/history/internal/message-transaction.d.ts +0 -25
  224. package/dist/history/internal/message-transaction.js +0 -61
  225. package/dist/history/internal/message-window.d.ts +0 -17
  226. package/dist/history/internal/message-window.js +0 -49
  227. package/dist/history/internal/query.d.ts +0 -23
  228. package/dist/history/internal/query.js +0 -39
  229. package/dist/history/internal/session-count.d.ts +0 -47
  230. package/dist/history/internal/session-count.js +0 -115
  231. package/dist/history/internal/session-title.d.ts +0 -19
  232. package/dist/history/internal/session-title.js +0 -43
  233. package/dist/history/internal/session-update.d.ts +0 -27
  234. package/dist/history/internal/session-update.js +0 -69
  235. package/dist/history/internal/title-generator.d.ts +0 -12
  236. package/dist/history/internal/title-generator.js +0 -41
  237. package/dist/history/internal/ttl-anchor.d.ts +0 -24
  238. package/dist/history/internal/ttl-anchor.js +0 -38
  239. package/dist/history/internal/validation.d.ts +0 -25
  240. package/dist/history/internal/validation.js +0 -53
  241. package/dist/shared/codec/descriptor-keys.d.ts +0 -12
  242. package/dist/shared/codec/descriptor-keys.js +0 -14
  243. package/dist/shared/codec/encode.d.ts +0 -13
  244. package/dist/shared/codec/encode.js +0 -43
  245. package/dist/shared/codec/payload-loss.d.ts +0 -12
  246. package/dist/shared/codec/payload-loss.js +0 -38
  247. package/dist/shared/codec/s3/adapter-config.d.ts +0 -13
  248. package/dist/shared/codec/s3/adapter-config.js +0 -22
  249. package/dist/shared/codec/s3/bounded-body.d.ts +0 -14
  250. package/dist/shared/codec/s3/bounded-body.js +0 -47
  251. package/dist/shared/codec/s3/delete.d.ts +0 -7
  252. package/dist/shared/codec/s3/delete.js +0 -28
  253. package/dist/shared/codec/s3/key-scope.d.ts +0 -23
  254. package/dist/shared/codec/s3/key-scope.js +0 -44
  255. package/dist/shared/codec/s3/orphans.d.ts +0 -23
  256. package/dist/shared/codec/s3/orphans.js +0 -71
  257. package/dist/shared/codec/s3/read-write.d.ts +0 -18
  258. package/dist/shared/codec/s3/read-write.js +0 -51
  259. package/dist/shared/codec/s3/retry.d.ts +0 -5
  260. package/dist/shared/codec/s3/retry.js +0 -22
  261. package/dist/shared/constants.d.ts +0 -112
  262. package/dist/shared/constants.js +0 -115
  263. package/dist/shared/dynamodb/backoff.d.ts +0 -15
  264. package/dist/shared/dynamodb/backoff.js +0 -48
  265. package/dist/shared/dynamodb/conditional-put.d.ts +0 -67
  266. package/dist/shared/dynamodb/conditional-put.js +0 -76
  267. package/dist/shared/dynamodb/drain-unprocessed.d.ts +0 -21
  268. package/dist/shared/dynamodb/drain-unprocessed.js +0 -43
  269. package/dist/shared/dynamodb/expiry.d.ts +0 -16
  270. package/dist/shared/dynamodb/expiry.js +0 -29
  271. package/dist/shared/dynamodb/paginate-core.d.ts +0 -24
  272. package/dist/shared/dynamodb/paginate-core.js +0 -82
  273. package/dist/shared/dynamodb/retry-classifier.d.ts +0 -17
  274. package/dist/shared/dynamodb/retry-classifier.js +0 -118
  275. package/dist/shared/dynamodb/retry-policy.d.ts +0 -26
  276. package/dist/shared/dynamodb/retry-policy.js +0 -22
  277. package/dist/shared/dynamodb/scan.d.ts +0 -14
  278. package/dist/shared/dynamodb/scan.js +0 -19
  279. package/dist/shared/dynamodb/types.d.ts +0 -23
  280. package/dist/shared/dynamodb/types.js +0 -2
  281. package/dist/shared/errors/upstream-error.d.ts +0 -16
  282. package/dist/shared/errors/upstream-error.js +0 -27
  283. package/dist/shared/errors/wrap-error.d.ts +0 -7
  284. package/dist/shared/errors/wrap-error.js +0 -15
  285. package/dist/shared/logging/redaction-walk.d.ts +0 -23
  286. package/dist/shared/logging/redaction-walk.js +0 -112
  287. package/dist/store/actions/get.d.ts +0 -13
  288. package/dist/store/actions/get.js +0 -73
  289. package/dist/store/internal/backend-search.d.ts +0 -4
  290. package/dist/store/internal/backend-search.js +0 -74
  291. package/dist/store/internal/candidates.d.ts +0 -23
  292. package/dist/store/internal/candidates.js +0 -94
  293. package/dist/store/internal/index-reconcile.d.ts +0 -21
  294. package/dist/store/internal/index-reconcile.js +0 -118
  295. package/dist/store/internal/index-sync.d.ts +0 -10
  296. package/dist/store/internal/index-sync.js +0 -25
  297. package/dist/store/internal/item-mapper.d.ts +0 -27
  298. package/dist/store/internal/item-mapper.js +0 -61
  299. package/dist/store/internal/keys.d.ts +0 -17
  300. package/dist/store/internal/keys.js +0 -41
  301. package/dist/store/internal/namespace-match.d.ts +0 -11
  302. package/dist/store/internal/namespace-match.js +0 -40
  303. package/dist/store/internal/option-validation.d.ts +0 -13
  304. package/dist/store/internal/option-validation.js +0 -77
  305. package/dist/store/internal/overwrite-swap.d.ts +0 -32
  306. package/dist/store/internal/overwrite-swap.js +0 -68
  307. package/dist/store/internal/persist.d.ts +0 -28
  308. package/dist/store/internal/persist.js +0 -64
  309. package/dist/store/internal/query.d.ts +0 -11
  310. package/dist/store/internal/query.js +0 -48
  311. package/dist/store/internal/ranker.d.ts +0 -18
  312. package/dist/store/internal/ranker.js +0 -39
  313. package/dist/store/internal/read-existing.d.ts +0 -23
  314. package/dist/store/internal/read-existing.js +0 -41
  315. package/dist/store/internal/score-direction.d.ts +0 -31
  316. package/dist/store/internal/score-direction.js +0 -38
  317. package/dist/store/internal/search-filter.d.ts +0 -3
  318. package/dist/store/internal/search-filter.js +0 -10
  319. package/dist/store/internal/text-path.d.ts +0 -17
  320. package/dist/store/internal/text-path.js +0 -147
  321. package/dist/store/internal/validation.d.ts +0 -18
  322. package/dist/store/internal/validation.js +0 -51
  323. package/dist/store/internal/write-verify.d.ts +0 -42
  324. package/dist/store/internal/write-verify.js +0 -71
@@ -1,112 +0,0 @@
1
- /** Maximum TTL expressed in days (5 years). */
2
- export declare const MAX_TTL_DAYS: number;
3
- /** Maximum TTL expressed in seconds: the same five years as {@link MAX_TTL_DAYS}. */
4
- export declare const MAX_TTL_SECONDS: number;
5
- /** Hard cap on query-pagination loop iterations (runaway-loop guard). */
6
- export declare const MAX_LOOP_ITERATIONS = 1000;
7
- /** Hard cap on items collected into memory across a paginated query. */
8
- export declare const MAX_TOTAL_ITEMS_IN_MEMORY = 10000;
9
- /** DynamoDB BatchWriteItem maximum requests per call. */
10
- export declare const BATCH_WRITE_MAX = 25;
11
- /** DynamoDB BatchGetItem maximum keys per call. */
12
- export declare const BATCH_GET_MAX = 100;
13
- /** Maximum retries draining UnprocessedItems / UnprocessedKeys. */
14
- export declare const MAX_UNPROCESSED_RETRIES = 10;
15
- /** Starting delay for UnprocessedItems / UnprocessedKeys backoff loops. */
16
- export declare const INITIAL_BACKOFF_DELAY_MS = 100;
17
- /** Maximum backoff delay for retry loops. */
18
- export declare const MAX_BACKOFF_DELAY_MS = 5000;
19
- /** S3 DeleteObjects maximum keys per request. */
20
- export declare const S3_DELETE_BATCH_MAX = 1000;
21
- /** Default payload size that triggers S3 offload (350 KB; 50 KB under the DDB 400 KB cap). */
22
- export declare const DEFAULT_S3_THRESHOLD_BYTES: number;
23
- /**
24
- * Largest serialized payload stored inline when no S3 offloader is configured:
25
- * DynamoDB's 400 KB item cap less 8 KB of headroom for the item's keys,
26
- * attribute names and descriptor fields. Exceeding it fails before the write
27
- * with a typed error instead of a raw `ValidationException` after it.
28
- */
29
- export declare const MAX_INLINE_PAYLOAD_BYTES: number;
30
- /** Default S3 key prefix for offloaded payloads. */
31
- export declare const DEFAULT_S3_KEY_PREFIX = "langgraph-checkpoints/";
32
- /** Default S3 server-side encryption algorithm. */
33
- export declare const DEFAULT_S3_SSE = "AES256";
34
- /** Default minimum payload size before gzip compression is attempted. */
35
- export declare const DEFAULT_COMPRESSION_MIN_BYTES = 1024;
36
- /** Default gzip compression level (balanced speed/ratio). */
37
- export declare const DEFAULT_COMPRESSION_LEVEL = 6;
38
- /** Default gzip-bomb guard: maximum decompressed output (50 MiB). */
39
- export declare const DEFAULT_MAX_DECOMPRESSED_BYTES: number;
40
- /**
41
- * Default cap on an offloaded object buffered from S3 (50 MiB), checked against
42
- * `ContentLength` before the body is read and enforced while streaming when
43
- * the length is unknown. Together with {@link DEFAULT_MAX_DECOMPRESSED_BYTES}
44
- * it bounds the memory any single payload can claim.
45
- */
46
- export declare const DEFAULT_MAX_S3_DOWNLOAD_BYTES: number;
47
- /** Default maximum attempts for transient-error retries. */
48
- export declare const DEFAULT_RETRY_MAX_ATTEMPTS = 5;
49
- /** Largest `retry.maxAttempts` an adapter accepts; beyond it a retry loop is a hang, not a policy. */
50
- export declare const MAX_RETRY_ATTEMPTS = 100;
51
- /**
52
- * Max attempts for the message-append transaction. It shares one session's
53
- * metadata row across every concurrent `addMessages` caller on that session,
54
- * so a burst of concurrent appends can collide repeatedly; combined with the
55
- * existing 100ms base / 5000ms cap backoff, this keeps worst-case retrying
56
- * within AWS's documented guidance to bound conflict retries to "around one
57
- * minute" (see DynamoDB's "Error retries and exponential backoff" guide).
58
- * This bound is exact for clients this library constructs, which disable the
59
- * AWS SDK's own internal retries (`maxAttempts: 1`, see
60
- * `resolveDynamoDBClient`). An injected client that keeps SDK retries stacks
61
- * them inside each attempt; construction warns about that.
62
- */
63
- export declare const MESSAGE_APPEND_RETRY_MAX_ATTEMPTS = 18;
64
- /**
65
- * Offloaded payloads decoded at once by one read (`getTuple` pending writes,
66
- * `search` candidates, `getMessages`). Each offloaded row costs one S3 GET, so
67
- * a serial loop scaled latency linearly with the row count; eight in flight
68
- * keeps the win without bursting a bucket.
69
- */
70
- export declare const DEFAULT_READ_CONCURRENCY = 8;
71
- /** Default cap on candidates the in-DB semantic ranker will score. */
72
- export declare const DEFAULT_MAX_SEARCH_CANDIDATES = 1000;
73
- /**
74
- * Raw rows a single `listCheckpoints` call may pull before it warns. The read
75
- * itself is deliberately unbounded — capping it counted raw rows rather than
76
- * filter-matched ones, which turned a caller asking for a handful of rare
77
- * matches over a large thread into a hard error instead of the true answer.
78
- * The warning restores the operational signal without restoring the wrong
79
- * error.
80
- *
81
- * Its own literal, deliberately: this is the point at which a scan is worth
82
- * telling an operator about, which is independent of
83
- * {@link MAX_TOTAL_ITEMS_IN_MEMORY}'s hard collection cap. Aliasing the two
84
- * meant retuning the memory cap silently moved the warning as well, and it
85
- * left the pair reported as a duplicate export.
86
- */
87
- export declare const LIST_SCAN_WARN_THRESHOLD = 10000;
88
- /**
89
- * Byte caps on caller-supplied identifiers, measured as UTF-8. DynamoDB caps a
90
- * partition key at 2048 bytes and a sort key at 1024; S3 caps an object key at
91
- * 1024. These leave room for the adapter prefixes and separators that compose
92
- * the stored keys, so a value that passes validation fails as a typed error
93
- * here rather than as a raw AWS ValidationException on the write.
94
- *
95
- * Partition-key identifiers: `thread_id` and `sessionId`.
96
- */
97
- export declare const MAX_PARTITION_ID_BYTES = 1024;
98
- /**
99
- * Sort-key segments: `checkpoint_ns`, `checkpoint_id`, `taskId`, a pending-write
100
- * channel, a store namespace element and a store `key`.
101
- */
102
- export declare const MAX_KEY_SEGMENT_BYTES = 256;
103
- /** DynamoDB cap on a whole sort key; composed keys are checked against it too. */
104
- export declare const MAX_SORT_KEY_BYTES = 1024;
105
- /** S3 cap on an object key, applied to the produced offload key. */
106
- export declare const MAX_S3_KEY_BYTES = 1024;
107
- /**
108
- * Extra days an S3 lifecycle rule adds over the TTL it backs. DynamoDB's TTL
109
- * sweep can lag up to ~48 h past the `ttl` timestamp; the offloaded object
110
- * must outlive its row, never the other way round.
111
- */
112
- export declare const S3_LIFECYCLE_SWEEP_MARGIN_DAYS = 2;
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.S3_LIFECYCLE_SWEEP_MARGIN_DAYS = exports.MAX_S3_KEY_BYTES = exports.MAX_SORT_KEY_BYTES = exports.MAX_KEY_SEGMENT_BYTES = exports.MAX_PARTITION_ID_BYTES = exports.LIST_SCAN_WARN_THRESHOLD = exports.DEFAULT_MAX_SEARCH_CANDIDATES = exports.DEFAULT_READ_CONCURRENCY = exports.MESSAGE_APPEND_RETRY_MAX_ATTEMPTS = exports.MAX_RETRY_ATTEMPTS = exports.DEFAULT_RETRY_MAX_ATTEMPTS = exports.DEFAULT_MAX_S3_DOWNLOAD_BYTES = exports.DEFAULT_MAX_DECOMPRESSED_BYTES = exports.DEFAULT_COMPRESSION_LEVEL = exports.DEFAULT_COMPRESSION_MIN_BYTES = exports.DEFAULT_S3_SSE = exports.DEFAULT_S3_KEY_PREFIX = exports.MAX_INLINE_PAYLOAD_BYTES = exports.DEFAULT_S3_THRESHOLD_BYTES = exports.S3_DELETE_BATCH_MAX = exports.MAX_BACKOFF_DELAY_MS = exports.INITIAL_BACKOFF_DELAY_MS = exports.MAX_UNPROCESSED_RETRIES = exports.BATCH_GET_MAX = exports.BATCH_WRITE_MAX = exports.MAX_TOTAL_ITEMS_IN_MEMORY = exports.MAX_LOOP_ITERATIONS = exports.MAX_TTL_SECONDS = exports.MAX_TTL_DAYS = void 0;
4
- /** Maximum TTL expressed in days (5 years). */
5
- exports.MAX_TTL_DAYS = 365 * 5;
6
- /** Maximum TTL expressed in seconds: the same five years as {@link MAX_TTL_DAYS}. */
7
- exports.MAX_TTL_SECONDS = exports.MAX_TTL_DAYS * 24 * 60 * 60;
8
- /** Hard cap on query-pagination loop iterations (runaway-loop guard). */
9
- exports.MAX_LOOP_ITERATIONS = 1000;
10
- /** Hard cap on items collected into memory across a paginated query. */
11
- exports.MAX_TOTAL_ITEMS_IN_MEMORY = 10000;
12
- /** DynamoDB BatchWriteItem maximum requests per call. */
13
- exports.BATCH_WRITE_MAX = 25;
14
- /** DynamoDB BatchGetItem maximum keys per call. */
15
- exports.BATCH_GET_MAX = 100;
16
- /** Maximum retries draining UnprocessedItems / UnprocessedKeys. */
17
- exports.MAX_UNPROCESSED_RETRIES = 10;
18
- /** Starting delay for UnprocessedItems / UnprocessedKeys backoff loops. */
19
- exports.INITIAL_BACKOFF_DELAY_MS = 100;
20
- /** Maximum backoff delay for retry loops. */
21
- exports.MAX_BACKOFF_DELAY_MS = 5000;
22
- /** S3 DeleteObjects maximum keys per request. */
23
- exports.S3_DELETE_BATCH_MAX = 1000;
24
- /** Default payload size that triggers S3 offload (350 KB; 50 KB under the DDB 400 KB cap). */
25
- exports.DEFAULT_S3_THRESHOLD_BYTES = 350 * 1024;
26
- /**
27
- * Largest serialized payload stored inline when no S3 offloader is configured:
28
- * DynamoDB's 400 KB item cap less 8 KB of headroom for the item's keys,
29
- * attribute names and descriptor fields. Exceeding it fails before the write
30
- * with a typed error instead of a raw `ValidationException` after it.
31
- */
32
- exports.MAX_INLINE_PAYLOAD_BYTES = 400 * 1024 - 8 * 1024;
33
- /** Default S3 key prefix for offloaded payloads. */
34
- exports.DEFAULT_S3_KEY_PREFIX = 'langgraph-checkpoints/';
35
- /** Default S3 server-side encryption algorithm. */
36
- exports.DEFAULT_S3_SSE = 'AES256';
37
- /** Default minimum payload size before gzip compression is attempted. */
38
- exports.DEFAULT_COMPRESSION_MIN_BYTES = 1024;
39
- /** Default gzip compression level (balanced speed/ratio). */
40
- exports.DEFAULT_COMPRESSION_LEVEL = 6;
41
- /** Default gzip-bomb guard: maximum decompressed output (50 MiB). */
42
- exports.DEFAULT_MAX_DECOMPRESSED_BYTES = 50 * 1024 * 1024;
43
- /**
44
- * Default cap on an offloaded object buffered from S3 (50 MiB), checked against
45
- * `ContentLength` before the body is read and enforced while streaming when
46
- * the length is unknown. Together with {@link DEFAULT_MAX_DECOMPRESSED_BYTES}
47
- * it bounds the memory any single payload can claim.
48
- */
49
- exports.DEFAULT_MAX_S3_DOWNLOAD_BYTES = 50 * 1024 * 1024;
50
- /** Default maximum attempts for transient-error retries. */
51
- exports.DEFAULT_RETRY_MAX_ATTEMPTS = 5;
52
- /** Largest `retry.maxAttempts` an adapter accepts; beyond it a retry loop is a hang, not a policy. */
53
- exports.MAX_RETRY_ATTEMPTS = 100;
54
- /**
55
- * Max attempts for the message-append transaction. It shares one session's
56
- * metadata row across every concurrent `addMessages` caller on that session,
57
- * so a burst of concurrent appends can collide repeatedly; combined with the
58
- * existing 100ms base / 5000ms cap backoff, this keeps worst-case retrying
59
- * within AWS's documented guidance to bound conflict retries to "around one
60
- * minute" (see DynamoDB's "Error retries and exponential backoff" guide).
61
- * This bound is exact for clients this library constructs, which disable the
62
- * AWS SDK's own internal retries (`maxAttempts: 1`, see
63
- * `resolveDynamoDBClient`). An injected client that keeps SDK retries stacks
64
- * them inside each attempt; construction warns about that.
65
- */
66
- exports.MESSAGE_APPEND_RETRY_MAX_ATTEMPTS = 18;
67
- /**
68
- * Offloaded payloads decoded at once by one read (`getTuple` pending writes,
69
- * `search` candidates, `getMessages`). Each offloaded row costs one S3 GET, so
70
- * a serial loop scaled latency linearly with the row count; eight in flight
71
- * keeps the win without bursting a bucket.
72
- */
73
- exports.DEFAULT_READ_CONCURRENCY = 8;
74
- /** Default cap on candidates the in-DB semantic ranker will score. */
75
- exports.DEFAULT_MAX_SEARCH_CANDIDATES = 1000;
76
- /**
77
- * Raw rows a single `listCheckpoints` call may pull before it warns. The read
78
- * itself is deliberately unbounded — capping it counted raw rows rather than
79
- * filter-matched ones, which turned a caller asking for a handful of rare
80
- * matches over a large thread into a hard error instead of the true answer.
81
- * The warning restores the operational signal without restoring the wrong
82
- * error.
83
- *
84
- * Its own literal, deliberately: this is the point at which a scan is worth
85
- * telling an operator about, which is independent of
86
- * {@link MAX_TOTAL_ITEMS_IN_MEMORY}'s hard collection cap. Aliasing the two
87
- * meant retuning the memory cap silently moved the warning as well, and it
88
- * left the pair reported as a duplicate export.
89
- */
90
- exports.LIST_SCAN_WARN_THRESHOLD = 10000;
91
- /**
92
- * Byte caps on caller-supplied identifiers, measured as UTF-8. DynamoDB caps a
93
- * partition key at 2048 bytes and a sort key at 1024; S3 caps an object key at
94
- * 1024. These leave room for the adapter prefixes and separators that compose
95
- * the stored keys, so a value that passes validation fails as a typed error
96
- * here rather than as a raw AWS ValidationException on the write.
97
- *
98
- * Partition-key identifiers: `thread_id` and `sessionId`.
99
- */
100
- exports.MAX_PARTITION_ID_BYTES = 1024;
101
- /**
102
- * Sort-key segments: `checkpoint_ns`, `checkpoint_id`, `taskId`, a pending-write
103
- * channel, a store namespace element and a store `key`.
104
- */
105
- exports.MAX_KEY_SEGMENT_BYTES = 256;
106
- /** DynamoDB cap on a whole sort key; composed keys are checked against it too. */
107
- exports.MAX_SORT_KEY_BYTES = 1024;
108
- /** S3 cap on an object key, applied to the produced offload key. */
109
- exports.MAX_S3_KEY_BYTES = 1024;
110
- /**
111
- * Extra days an S3 lifecycle rule adds over the TTL it backs. DynamoDB's TTL
112
- * sweep can lag up to ~48 h past the `ttl` timestamp; the offloaded object
113
- * must outlive its row, never the other way round.
114
- */
115
- exports.S3_LIFECYCLE_SWEEP_MARGIN_DAYS = 2;
@@ -1,15 +0,0 @@
1
- /**
2
- * Sleep for `ms` milliseconds, cancellable via `signal`. An already-aborted
3
- * signal rejects at once and an abort while pending rejects the moment it fires; both
4
- * reject with the library's `AbortError` (see `abortErrorFrom`), so a caller
5
- * branching on `code === 'ABORTED'` sees it however the signal was aborted.
6
- */
7
- export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
8
- /** Next exponential-backoff delay: double `currentMs`, capped at `maxMs`. */
9
- export declare function nextBackoffDelay(currentMs: number, maxMs?: number): number;
10
- /**
11
- * Apply AWS-recommended full jitter: a uniform random value in `[0, delayMs)`.
12
- *
13
- * @param rng - RNG seam returning `[0, 1)`. Defaults to `Math.random`.
14
- */
15
- export declare function fullJitter(delayMs: number, rng?: () => number): number;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleep = sleep;
4
- exports.nextBackoffDelay = nextBackoffDelay;
5
- exports.fullJitter = fullJitter;
6
- const constants_1 = require("../constants");
7
- const abort_1 = require("./abort");
8
- /**
9
- * Sleep for `ms` milliseconds, cancellable via `signal`. An already-aborted
10
- * signal rejects at once and an abort while pending rejects the moment it fires; both
11
- * reject with the library's `AbortError` (see `abortErrorFrom`), so a caller
12
- * branching on `code === 'ABORTED'` sees it however the signal was aborted.
13
- */
14
- function sleep(ms, signal) {
15
- if (signal?.aborted) {
16
- return Promise.reject((0, abort_1.abortErrorFrom)(signal));
17
- }
18
- return new Promise((resolve, reject) => {
19
- let settled = false;
20
- const onAbort = () => {
21
- if (settled)
22
- return;
23
- settled = true;
24
- clearTimeout(timer);
25
- reject((0, abort_1.abortErrorFrom)(signal));
26
- };
27
- const timer = setTimeout(() => {
28
- if (settled)
29
- return;
30
- settled = true;
31
- signal?.removeEventListener('abort', onAbort);
32
- resolve();
33
- }, ms);
34
- signal?.addEventListener('abort', onAbort, { once: true });
35
- });
36
- }
37
- /** Next exponential-backoff delay: double `currentMs`, capped at `maxMs`. */
38
- function nextBackoffDelay(currentMs, maxMs = constants_1.MAX_BACKOFF_DELAY_MS) {
39
- return Math.min(currentMs * 2, maxMs);
40
- }
41
- /**
42
- * Apply AWS-recommended full jitter: a uniform random value in `[0, delayMs)`.
43
- *
44
- * @param rng - RNG seam returning `[0, 1)`. Defaults to `Math.random`.
45
- */
46
- function fullJitter(delayMs, rng = Math.random) {
47
- return rng() * delayMs;
48
- }
@@ -1,67 +0,0 @@
1
- import type { DocItem } from './types';
2
- /**
3
- * Attribute holding a row's revision token on adapters that need one. The
4
- * checkpointer's special writes reuse their existing per-call `writeGroup`
5
- * instead, so `revisionGuard` takes the attribute name rather than assuming it.
6
- */
7
- export declare const REVISION_ATTRIBUTE = "rev";
8
- /**
9
- * Compare-and-swap attempts before a caller gives up and overwrites
10
- * unconditionally. Kept small on purpose: DynamoDB charges write capacity for a
11
- * *failed* conditional write too, sized on the existing item, so an aggressive
12
- * loop turns contention into cost. Three attempts settle every realistic race,
13
- * and the fallback is exactly the pre-0.9.0 behaviour rather than an error.
14
- */
15
- export declare const OVERWRITE_CAS_MAX_ATTEMPTS = 3;
16
- /** What a caller saw at the row before it tried to overwrite it. */
17
- export interface ObservedRow {
18
- exists: boolean;
19
- revision?: string;
20
- }
21
- /**
22
- * Condition fragments to spread into a `PutCommand` input. Every guard asks
23
- * DynamoDB to attach the existing row to a rejection, so a compare-and-swap
24
- * that loses can re-pin from the exception (see {@link rejectedItem}) instead
25
- * of spending a second strongly-consistent read.
26
- */
27
- export interface RevisionGuard {
28
- ConditionExpression: string;
29
- ExpressionAttributeNames?: Record<string, string>;
30
- ExpressionAttributeValues?: Record<string, string>;
31
- ReturnValuesOnConditionCheckFailure: 'ALL_OLD';
32
- }
33
- /**
34
- * Build the condition admitting a write only while the row still holds the
35
- * revision this caller observed.
36
- *
37
- * Without it, two concurrent overwrites both read the same previous payload
38
- * descriptor, both commit their own nonced upload, and both delete that same
39
- * previous object — leaving the loser's upload orphaned with nothing left
40
- * recording that it ever existed. A post-commit read-back cannot repair that,
41
- * because neither writer can learn of an object it never saw; only refusing the
42
- * second write until it re-reads can.
43
- *
44
- * A row with no revision attribute was written before 0.9.0. Pinning its
45
- * *absence* is what makes the swap correct across an upgrade: the first writer
46
- * to touch such a row stamps one, and any racer still holding the pre-upgrade
47
- * observation is turned away.
48
- */
49
- export declare function revisionGuard(attribute: string, observed: ObservedRow): RevisionGuard;
50
- /**
51
- * True when the guard rejected a write — NOT evidence a competitor won: a
52
- * `PutCommand` retried after its response was lost can re-hit its own
53
- * committed row and fail identically; the two cases are indistinguishable.
54
- */
55
- export declare function isConditionalCheckFailed(error: {
56
- name?: string;
57
- }): boolean;
58
- /**
59
- * The row that turned a conditional write away, when DynamoDB attached it
60
- * (`ReturnValuesOnConditionCheckFailure: 'ALL_OLD'`). Verified against real
61
- * DynamoDB: the document client does not unmarshall an *error* payload the way
62
- * it unmarshalls a response, so the item arrives in raw AttributeValue form and
63
- * is unmarshalled here. Undefined when the rejection carries no item — the row
64
- * was deleted between the observation and the write — in which case the caller
65
- * falls back to a read.
66
- */
67
- export declare function rejectedItem(error: Error): DocItem | undefined;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OVERWRITE_CAS_MAX_ATTEMPTS = exports.REVISION_ATTRIBUTE = void 0;
4
- exports.revisionGuard = revisionGuard;
5
- exports.isConditionalCheckFailed = isConditionalCheckFailed;
6
- exports.rejectedItem = rejectedItem;
7
- const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
8
- /**
9
- * Attribute holding a row's revision token on adapters that need one. The
10
- * checkpointer's special writes reuse their existing per-call `writeGroup`
11
- * instead, so `revisionGuard` takes the attribute name rather than assuming it.
12
- */
13
- exports.REVISION_ATTRIBUTE = 'rev';
14
- /**
15
- * Compare-and-swap attempts before a caller gives up and overwrites
16
- * unconditionally. Kept small on purpose: DynamoDB charges write capacity for a
17
- * *failed* conditional write too, sized on the existing item, so an aggressive
18
- * loop turns contention into cost. Three attempts settle every realistic race,
19
- * and the fallback is exactly the pre-0.9.0 behaviour rather than an error.
20
- */
21
- exports.OVERWRITE_CAS_MAX_ATTEMPTS = 3;
22
- const RETURN_REJECTED_ROW = { ReturnValuesOnConditionCheckFailure: 'ALL_OLD' };
23
- /**
24
- * Build the condition admitting a write only while the row still holds the
25
- * revision this caller observed.
26
- *
27
- * Without it, two concurrent overwrites both read the same previous payload
28
- * descriptor, both commit their own nonced upload, and both delete that same
29
- * previous object — leaving the loser's upload orphaned with nothing left
30
- * recording that it ever existed. A post-commit read-back cannot repair that,
31
- * because neither writer can learn of an object it never saw; only refusing the
32
- * second write until it re-reads can.
33
- *
34
- * A row with no revision attribute was written before 0.9.0. Pinning its
35
- * *absence* is what makes the swap correct across an upgrade: the first writer
36
- * to touch such a row stamps one, and any racer still holding the pre-upgrade
37
- * observation is turned away.
38
- */
39
- function revisionGuard(attribute, observed) {
40
- if (!observed.exists)
41
- return { ...RETURN_REJECTED_ROW, ConditionExpression: 'attribute_not_exists(PK)' };
42
- if (observed.revision === undefined) {
43
- return {
44
- ...RETURN_REJECTED_ROW,
45
- ConditionExpression: 'attribute_not_exists(#rev)',
46
- ExpressionAttributeNames: { '#rev': attribute },
47
- };
48
- }
49
- return {
50
- ...RETURN_REJECTED_ROW,
51
- ConditionExpression: '#rev = :rev',
52
- ExpressionAttributeNames: { '#rev': attribute },
53
- ExpressionAttributeValues: { ':rev': observed.revision },
54
- };
55
- }
56
- /**
57
- * True when the guard rejected a write — NOT evidence a competitor won: a
58
- * `PutCommand` retried after its response was lost can re-hit its own
59
- * committed row and fail identically; the two cases are indistinguishable.
60
- */
61
- function isConditionalCheckFailed(error) {
62
- return error.name === 'ConditionalCheckFailedException';
63
- }
64
- /**
65
- * The row that turned a conditional write away, when DynamoDB attached it
66
- * (`ReturnValuesOnConditionCheckFailure: 'ALL_OLD'`). Verified against real
67
- * DynamoDB: the document client does not unmarshall an *error* payload the way
68
- * it unmarshalls a response, so the item arrives in raw AttributeValue form and
69
- * is unmarshalled here. Undefined when the rejection carries no item — the row
70
- * was deleted between the observation and the write — in which case the caller
71
- * falls back to a read.
72
- */
73
- function rejectedItem(error) {
74
- const raw = error.Item;
75
- return raw === undefined ? undefined : (0, util_dynamodb_1.unmarshall)(raw);
76
- }
@@ -1,21 +0,0 @@
1
- import type { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
2
- import { type RetryOptions } from './retry';
3
- import type { WriteRequest } from './types';
4
- /** Backoff/abort options shared by the drain helpers. */
5
- export interface DrainOptions {
6
- /** The adapter's retry options, applied to every BatchWriteItem round. */
7
- retry?: RetryOptions;
8
- signal?: AbortSignal;
9
- rng?: () => number;
10
- maxRetries?: number;
11
- }
12
- /**
13
- * Submit `requests` via BatchWriteItem and re-submit UnprocessedItems with
14
- * full-jitter backoff until the batch drains. Throws
15
- * {@link BatchWriteIncompleteError} if it cannot drain within the retry budget,
16
- * or if a round's write call or backoff wait throws outright (SDK failure, or
17
- * the caller's signal aborting) — in every case `succeededCount` reflects
18
- * every earlier round's confirmed persists, and the triggering error is
19
- * attached as `cause`.
20
- */
21
- export declare function drainUnprocessedWrites(client: DynamoDBDocument, tableName: string, requests: WriteRequest[], options?: DrainOptions): Promise<void>;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.drainUnprocessedWrites = drainUnprocessedWrites;
4
- const constants_1 = require("../constants");
5
- const errors_1 = require("../errors/errors");
6
- const backoff_1 = require("./backoff");
7
- const retry_1 = require("./retry");
8
- /**
9
- * Submit `requests` via BatchWriteItem and re-submit UnprocessedItems with
10
- * full-jitter backoff until the batch drains. Throws
11
- * {@link BatchWriteIncompleteError} if it cannot drain within the retry budget,
12
- * or if a round's write call or backoff wait throws outright (SDK failure, or
13
- * the caller's signal aborting) — in every case `succeededCount` reflects
14
- * every earlier round's confirmed persists, and the triggering error is
15
- * attached as `cause`.
16
- */
17
- async function drainUnprocessedWrites(client, tableName, requests, options = {}) {
18
- if (requests.length === 0)
19
- return;
20
- const maxRetries = options.maxRetries ?? constants_1.MAX_UNPROCESSED_RETRIES;
21
- const initialCount = requests.length;
22
- let pending = requests;
23
- let delay = constants_1.INITIAL_BACKOFF_DELAY_MS;
24
- let retries = 0;
25
- while (pending.length > 0) {
26
- try {
27
- const result = await (0, retry_1.withDynamoDBRetry)(() => client.batchWrite({ RequestItems: { [tableName]: pending } }), { ...options.retry, signal: options.signal });
28
- const leftover = result.UnprocessedItems?.[tableName] ?? [];
29
- if (leftover.length === 0)
30
- return;
31
- pending = leftover;
32
- retries += 1;
33
- if (retries > maxRetries)
34
- break;
35
- await (0, backoff_1.sleep)((0, backoff_1.fullJitter)(delay, options.rng), options.signal);
36
- delay = (0, backoff_1.nextBackoffDelay)(delay);
37
- }
38
- catch (error) {
39
- throw new errors_1.BatchWriteIncompleteError(initialCount - pending.length, pending, retries, error);
40
- }
41
- }
42
- throw new errors_1.BatchWriteIncompleteError(initialCount - pending.length, pending, maxRetries);
43
- }
@@ -1,16 +0,0 @@
1
- import type { QueryCommandInput, ScanCommandInput } from '@aws-sdk/lib-dynamodb';
2
- /**
3
- * True when a row carrying a DynamoDB TTL is at or past it. DynamoDB's sweep
4
- * can lag up to ~48 h, so every read path applies this itself; the value is
5
- * epoch seconds, the unit the `ttl` attribute uses.
6
- */
7
- export declare function isExpiredRow(row: {
8
- ttl?: number;
9
- }, nowSeconds: number): boolean;
10
- /**
11
- * Exclude expired rows server-side, ANDing any filter the query already has.
12
- * A filter never replaces the in-process {@link isExpiredRow} check — it only
13
- * trims transfer — because the two clocks (query build, row iteration) are
14
- * not the same instant and DynamoDB applies filters after `Limit`.
15
- */
16
- export declare function withoutExpired<T extends QueryCommandInput | ScanCommandInput>(params: T, nowSeconds: number): T;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isExpiredRow = isExpiredRow;
4
- exports.withoutExpired = withoutExpired;
5
- /**
6
- * True when a row carrying a DynamoDB TTL is at or past it. DynamoDB's sweep
7
- * can lag up to ~48 h, so every read path applies this itself; the value is
8
- * epoch seconds, the unit the `ttl` attribute uses.
9
- */
10
- function isExpiredRow(row, nowSeconds) {
11
- return row.ttl !== undefined && row.ttl <= nowSeconds;
12
- }
13
- const TTL_FILTER = 'attribute_not_exists(#ttl) OR #ttl > :now';
14
- /**
15
- * Exclude expired rows server-side, ANDing any filter the query already has.
16
- * A filter never replaces the in-process {@link isExpiredRow} check — it only
17
- * trims transfer — because the two clocks (query build, row iteration) are
18
- * not the same instant and DynamoDB applies filters after `Limit`.
19
- */
20
- function withoutExpired(params, nowSeconds) {
21
- return {
22
- ...params,
23
- FilterExpression: params.FilterExpression
24
- ? `(${params.FilterExpression}) AND (${TTL_FILTER})`
25
- : TTL_FILTER,
26
- ExpressionAttributeNames: { ...params.ExpressionAttributeNames, '#ttl': 'ttl' },
27
- ExpressionAttributeValues: { ...params.ExpressionAttributeValues, ':now': nowSeconds },
28
- };
29
- }
@@ -1,24 +0,0 @@
1
- import type { RetryOptions } from './retry';
2
- import type { DocItem } from './types';
3
- /** One page of results plus the key to resume from (undefined when exhausted). */
4
- export interface PageResult {
5
- items: DocItem[];
6
- lastKey: DocItem | undefined;
7
- }
8
- /** Options shared by the paginators built on {@link paginatePages}. */
9
- export interface PaginateCoreOptions {
10
- /** The adapter's retry options, applied to every page read. */
11
- retry?: RetryOptions;
12
- signal?: AbortSignal;
13
- maxItems?: number;
14
- maxIterations?: number;
15
- }
16
- /**
17
- * Drive a paged DynamoDB read to completion, yielding each item. Continues past
18
- * empty pages, honors the abort signal before each fetch, and enforces iteration
19
- * + in-memory item caps. `fetchPage` performs one page read. When a cap is hit
20
- * while more data actually remains, throws {@link ResultTruncatedError} rather
21
- * than silently returning a partial result; pass `Infinity` caps to read to true
22
- * completion (e.g. for deletes).
23
- */
24
- export declare function paginatePages(fetchPage: (startKey: DocItem | undefined) => Promise<PageResult>, options?: PaginateCoreOptions): AsyncGenerator<DocItem>;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.paginatePages = paginatePages;
4
- const constants_1 = require("../constants");
5
- const errors_1 = require("../errors/errors");
6
- const abort_1 = require("./abort");
7
- /** Read the next page, honouring the abort signal and the iteration cap first. */
8
- async function readPage(reader, startKey) {
9
- if (reader.iterations >= reader.maxIterations) {
10
- throw new errors_1.ResultTruncatedError('maxIterations', reader.maxIterations);
11
- }
12
- if (reader.signal?.aborted)
13
- throw (0, abort_1.abortErrorFrom)(reader.signal);
14
- reader.iterations += 1;
15
- return reader.fetchPage(startKey);
16
- }
17
- /**
18
- * Yield one page's items, counting toward the shared `state.yielded` budget.
19
- * Reaching the cap with unyielded items still on the page is a truncation;
20
- * reaching it on the last item is reported as `capped` for the caller to settle.
21
- */
22
- async function* yieldPageItems(page, state, maxItems) {
23
- for (let index = 0; index < page.items.length; index++) {
24
- yield page.items[index];
25
- state.yielded += 1;
26
- if (state.yielded >= maxItems) {
27
- if (index < page.items.length - 1)
28
- throw new errors_1.ResultTruncatedError('maxItems', maxItems);
29
- return 'capped';
30
- }
31
- }
32
- return 'exhausted';
33
- }
34
- /**
35
- * Whether anything remains past `startKey`. DynamoDB returns a
36
- * `LastEvaluatedKey` whenever it stopped *evaluating* at the 1 MB boundary,
37
- * whether or not a later item passes the filter, so a trailing key alone proves
38
- * nothing: the keys are followed until a page carries an item (truncated) or
39
- * they run out (the result was complete). The probe is charged against the same
40
- * iteration budget and honours the same signal as the read itself.
41
- */
42
- async function dataRemains(reader, startKey) {
43
- let key = startKey;
44
- while (key !== undefined) {
45
- const page = await readPage(reader, key);
46
- if (page.items.length > 0)
47
- return true;
48
- key = page.lastKey;
49
- }
50
- return false;
51
- }
52
- /**
53
- * Drive a paged DynamoDB read to completion, yielding each item. Continues past
54
- * empty pages, honors the abort signal before each fetch, and enforces iteration
55
- * + in-memory item caps. `fetchPage` performs one page read. When a cap is hit
56
- * while more data actually remains, throws {@link ResultTruncatedError} rather
57
- * than silently returning a partial result; pass `Infinity` caps to read to true
58
- * completion (e.g. for deletes).
59
- */
60
- async function* paginatePages(fetchPage, options = {}) {
61
- const maxItems = options.maxItems ?? constants_1.MAX_TOTAL_ITEMS_IN_MEMORY;
62
- const reader = {
63
- fetchPage,
64
- maxIterations: options.maxIterations ?? constants_1.MAX_LOOP_ITERATIONS,
65
- iterations: 0,
66
- signal: options.signal,
67
- };
68
- const state = { yielded: 0 };
69
- let startKey;
70
- for (;;) {
71
- const page = await readPage(reader, startKey);
72
- const outcome = yield* yieldPageItems(page, state, maxItems);
73
- if (outcome === 'capped') {
74
- if (await dataRemains(reader, page.lastKey))
75
- throw new errors_1.ResultTruncatedError('maxItems', maxItems);
76
- return;
77
- }
78
- startKey = page.lastKey;
79
- if (startKey === undefined)
80
- return;
81
- }
82
- }