@farukada/aws-langgraph-dynamodb-ts 1.0.0-rc.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -193
- package/dist/{backfill → cjs/backfill}/backfill.d.ts +15 -12
- package/dist/cjs/backfill/backfill.js +177 -0
- package/dist/{checkpointer → cjs/checkpointer}/actions/delete-thread.d.ts +1 -1
- package/dist/cjs/checkpointer/actions/delete-thread.js +26 -0
- package/dist/{checkpointer → cjs/checkpointer}/actions/get-tuple.d.ts +4 -3
- package/dist/cjs/checkpointer/actions/get-tuple.js +22 -0
- package/dist/{checkpointer → cjs/checkpointer}/actions/list.d.ts +7 -4
- package/dist/cjs/checkpointer/actions/list.js +70 -0
- package/dist/{checkpointer → cjs/checkpointer}/actions/put-writes.d.ts +8 -6
- package/dist/cjs/checkpointer/actions/put-writes.js +21 -0
- package/dist/{checkpointer → cjs/checkpointer}/actions/put.d.ts +21 -15
- package/dist/cjs/checkpointer/actions/put.js +79 -0
- package/dist/{checkpointer → cjs/checkpointer}/internal/delta-history.d.ts +38 -26
- package/dist/cjs/checkpointer/internal/delta-history.js +131 -0
- package/dist/{checkpointer → cjs/checkpointer}/internal/listing.d.ts +4 -4
- package/dist/cjs/checkpointer/internal/listing.js +104 -0
- package/dist/{checkpointer → cjs/checkpointer}/internal/parse.d.ts +51 -15
- package/dist/cjs/checkpointer/internal/parse.js +184 -0
- package/dist/{checkpointer → cjs/checkpointer}/internal/pending-writes.d.ts +64 -25
- package/dist/cjs/checkpointer/internal/pending-writes.js +241 -0
- package/dist/{checkpointer → cjs/checkpointer}/internal/read.d.ts +15 -10
- package/dist/cjs/checkpointer/internal/read.js +132 -0
- package/dist/{checkpointer → cjs/checkpointer}/internal/rows.d.ts +94 -21
- package/dist/cjs/checkpointer/internal/rows.js +356 -0
- package/dist/{checkpointer → cjs/checkpointer}/internal/setup.d.ts +13 -20
- package/dist/cjs/checkpointer/internal/setup.js +25 -0
- package/dist/{checkpointer → cjs/checkpointer}/saver.d.ts +72 -36
- package/dist/cjs/checkpointer/saver.js +56 -0
- package/dist/{checkpointer → cjs/checkpointer}/types.d.ts +1 -1
- package/dist/cjs/checkpointer/types.js +2 -0
- package/dist/{factory → cjs/factory}/factory.d.ts +25 -20
- package/dist/cjs/factory/factory.js +137 -0
- package/dist/{factory → cjs/factory}/types.d.ts +12 -12
- package/dist/cjs/factory/types.js +2 -0
- package/dist/{history → cjs/history}/actions/add-messages.d.ts +18 -10
- package/dist/cjs/history/actions/add-messages.js +17 -0
- package/dist/{history → cjs/history}/actions/clear.d.ts +1 -1
- package/dist/cjs/history/actions/clear.js +29 -0
- package/dist/{history → cjs/history}/actions/get-messages.d.ts +11 -9
- package/dist/cjs/history/actions/get-messages.js +58 -0
- package/dist/{history → cjs/history}/actions/list-sessions.d.ts +3 -3
- package/dist/cjs/history/actions/list-sessions.js +67 -0
- package/dist/{history → cjs/history}/actions/reconcile-count.d.ts +13 -9
- package/dist/cjs/history/actions/reconcile-count.js +8 -0
- package/dist/{history → cjs/history}/chat-message-history.d.ts +62 -30
- package/dist/cjs/history/chat-message-history.js +61 -0
- package/dist/{history → cjs/history}/internal/append.d.ts +64 -32
- package/dist/cjs/history/internal/append.js +267 -0
- package/dist/{history → cjs/history}/internal/message-read.d.ts +3 -3
- package/dist/cjs/history/internal/message-read.js +93 -0
- package/dist/{history → cjs/history}/internal/parse.d.ts +2 -2
- package/dist/cjs/history/internal/parse.js +113 -0
- package/dist/{history → cjs/history}/internal/rows.d.ts +11 -10
- package/dist/cjs/history/internal/rows.js +96 -0
- package/dist/{history → cjs/history}/internal/session.d.ts +41 -22
- package/dist/cjs/history/internal/session.js +296 -0
- package/dist/{history → cjs/history}/internal/setup.d.ts +2 -2
- package/dist/cjs/history/internal/setup.js +60 -0
- package/dist/{history → cjs/history}/session-adapter.d.ts +0 -6
- package/dist/cjs/history/session-adapter.js +38 -0
- package/dist/{history → cjs/history}/types.d.ts +18 -15
- package/dist/cjs/history/types.js +2 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +27 -27
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/package.json +1 -0
- package/dist/{shared → cjs/shared}/adapter.d.ts +27 -16
- package/dist/cjs/shared/adapter.js +70 -0
- package/dist/cjs/shared/clock.js +14 -0
- package/dist/{shared → cjs/shared}/codec/codec.d.ts +37 -20
- package/dist/cjs/shared/codec/codec.js +162 -0
- package/dist/{shared → cjs/shared}/codec/compression.d.ts +9 -4
- package/dist/cjs/shared/codec/compression.js +45 -0
- package/dist/cjs/shared/codec/json-serde.js +58 -0
- package/dist/{shared → cjs/shared}/codec/s3/client-types.d.ts +2 -1
- package/dist/cjs/shared/codec/s3/client-types.js +6 -0
- package/dist/{shared → cjs/shared}/codec/s3/client.d.ts +25 -7
- package/dist/cjs/shared/codec/s3/client.js +78 -0
- package/dist/{shared → cjs/shared}/codec/s3/config.d.ts +12 -7
- package/dist/cjs/shared/codec/s3/config.js +92 -0
- package/dist/{shared → cjs/shared}/codec/s3/lifecycle.d.ts +71 -17
- package/dist/cjs/shared/codec/s3/lifecycle.js +223 -0
- package/dist/{shared → cjs/shared}/codec/s3/offloader.d.ts +42 -29
- package/dist/cjs/shared/codec/s3/offloader.js +289 -0
- package/dist/cjs/shared/concurrency.js +31 -0
- package/dist/{shared → cjs/shared}/dynamodb/abort.d.ts +2 -2
- package/dist/cjs/shared/dynamodb/abort.js +16 -0
- package/dist/{shared → cjs/shared}/dynamodb/batch-write.d.ts +2 -2
- package/dist/cjs/shared/dynamodb/batch-write.js +79 -0
- package/dist/cjs/shared/dynamodb/cancellation.js +37 -0
- package/dist/{shared → cjs/shared}/dynamodb/client.d.ts +24 -22
- package/dist/cjs/shared/dynamodb/client.js +40 -0
- package/dist/{shared → cjs/shared}/dynamodb/idempotent-write.d.ts +64 -19
- package/dist/cjs/shared/dynamodb/idempotent-write.js +173 -0
- package/dist/{shared → cjs/shared}/dynamodb/paginate.d.ts +2 -2
- package/dist/cjs/shared/dynamodb/paginate.js +90 -0
- package/dist/{shared → cjs/shared}/dynamodb/partition-delete.d.ts +6 -6
- package/dist/cjs/shared/dynamodb/partition-delete.js +177 -0
- package/dist/{shared → cjs/shared}/dynamodb/recency-index.d.ts +27 -15
- package/dist/cjs/shared/dynamodb/recency-index.js +146 -0
- package/dist/{shared → cjs/shared}/dynamodb/retry.d.ts +37 -6
- package/dist/cjs/shared/dynamodb/retry.js +193 -0
- package/dist/cjs/shared/dynamodb/row-size.d.ts +33 -0
- package/dist/cjs/shared/dynamodb/row-size.js +30 -0
- package/dist/{shared → cjs/shared}/dynamodb/table-schema.d.ts +27 -18
- package/dist/cjs/shared/dynamodb/table-schema.js +52 -0
- package/dist/{shared → cjs/shared}/errors/base-error.d.ts +42 -7
- package/dist/cjs/shared/errors/base-error.js +73 -0
- package/dist/{shared → cjs/shared}/errors/boundary.d.ts +29 -14
- package/dist/cjs/shared/errors/boundary.js +61 -0
- package/dist/cjs/shared/errors/classify.d.ts +206 -0
- package/dist/cjs/shared/errors/classify.js +232 -0
- package/dist/{shared → cjs/shared}/errors/error-code.d.ts +17 -10
- package/dist/cjs/shared/errors/error-code.js +27 -0
- package/dist/{shared → cjs/shared}/errors/errors.d.ts +75 -9
- package/dist/cjs/shared/errors/errors.js +123 -0
- package/dist/cjs/shared/logging/logger.js +30 -0
- package/dist/{shared → cjs/shared}/logging/redaction.d.ts +8 -4
- package/dist/cjs/shared/logging/redaction.js +145 -0
- package/dist/{shared → cjs/shared}/logging/secret-patterns.d.ts +30 -7
- package/dist/cjs/shared/logging/secret-patterns.js +93 -0
- package/dist/cjs/shared/logging/truncate.js +31 -0
- package/dist/{shared → cjs/shared}/options.d.ts +27 -11
- package/dist/cjs/shared/options.js +2 -0
- package/dist/cjs/shared/ulid.js +83 -0
- package/dist/{shared → cjs/shared}/validation/collaborators.d.ts +21 -2
- package/dist/cjs/shared/validation/collaborators.js +79 -0
- package/dist/{shared → cjs/shared}/validation/option-shape.d.ts +7 -5
- package/dist/cjs/shared/validation/option-shape.js +31 -0
- package/dist/{shared → cjs/shared}/validation/options.d.ts +4 -4
- package/dist/cjs/shared/validation/options.js +166 -0
- package/dist/cjs/shared/validation/primitives.js +114 -0
- package/dist/{shared → cjs/shared}/validation/ttl.d.ts +26 -9
- package/dist/cjs/shared/validation/ttl.js +52 -0
- package/dist/{store → cjs/store}/actions/list-namespaces.d.ts +5 -5
- package/dist/cjs/store/actions/list-namespaces.js +92 -0
- package/dist/{store → cjs/store}/actions/put.d.ts +11 -4
- package/dist/cjs/store/actions/put.js +49 -0
- package/dist/{store → cjs/store}/actions/reconcile-vector-index.d.ts +5 -5
- package/dist/cjs/store/actions/reconcile-vector-index.js +13 -0
- package/dist/{store → cjs/store}/actions/search.d.ts +2 -2
- package/dist/cjs/store/actions/search.js +26 -0
- package/dist/cjs/store/internal/batch-plan.d.ts +56 -0
- package/dist/cjs/store/internal/batch-plan.js +32 -0
- package/dist/{store → cjs/store}/internal/filter.d.ts +3 -3
- package/dist/cjs/store/internal/filter.js +64 -0
- package/dist/cjs/store/internal/get-item.d.ts +77 -0
- package/dist/cjs/store/internal/get-item.js +58 -0
- package/dist/{store → cjs/store}/internal/item-write.d.ts +72 -32
- package/dist/cjs/store/internal/item-write.js +181 -0
- package/dist/{store → cjs/store}/internal/parse.d.ts +15 -10
- package/dist/cjs/store/internal/parse.js +180 -0
- package/dist/{store → cjs/store}/internal/rows.d.ts +38 -34
- package/dist/cjs/store/internal/rows.js +166 -0
- package/dist/{store → cjs/store}/internal/semantic-search.d.ts +2 -2
- package/dist/cjs/store/internal/semantic-search.js +211 -0
- package/dist/{store → cjs/store}/internal/setup.d.ts +10 -15
- package/dist/cjs/store/internal/setup.js +103 -0
- package/dist/{store → cjs/store}/internal/table-search.d.ts +5 -5
- package/dist/cjs/store/internal/table-search.js +123 -0
- package/dist/{store → cjs/store}/internal/vector-index.d.ts +26 -15
- package/dist/cjs/store/internal/vector-index.js +269 -0
- package/dist/{store → cjs/store}/store.d.ts +82 -39
- package/dist/cjs/store/store.js +97 -0
- package/dist/{store → cjs/store}/types.d.ts +25 -10
- package/dist/cjs/store/types.js +2 -0
- package/dist/cjs/store/vector-backend.js +4 -0
- package/dist/esm/backfill/backfill.d.ts +171 -0
- package/dist/esm/backfill/backfill.js +170 -0
- package/dist/{checkpointer/actions/delete-thread.js → esm/checkpointer/actions/delete-thread.d.ts} +4 -26
- package/dist/esm/checkpointer/actions/delete-thread.js +23 -0
- package/dist/{checkpointer/actions/get-tuple.js → esm/checkpointer/actions/get-tuple.d.ts} +7 -24
- package/dist/esm/checkpointer/actions/get-tuple.js +19 -0
- package/dist/esm/checkpointer/actions/list.d.ts +55 -0
- package/dist/esm/checkpointer/actions/list.js +67 -0
- package/dist/{checkpointer/actions/put-writes.js → esm/checkpointer/actions/put-writes.d.ts} +10 -37
- package/dist/esm/checkpointer/actions/put-writes.js +18 -0
- package/dist/esm/checkpointer/actions/put.d.ts +95 -0
- package/dist/esm/checkpointer/actions/put.js +75 -0
- package/dist/esm/checkpointer/internal/delta-history.d.ts +124 -0
- package/dist/esm/checkpointer/internal/delta-history.js +126 -0
- package/dist/{checkpointer/internal/listing.js → esm/checkpointer/internal/listing.d.ts} +22 -118
- package/dist/esm/checkpointer/internal/listing.js +95 -0
- package/dist/esm/checkpointer/internal/parse.d.ts +298 -0
- package/dist/esm/checkpointer/internal/parse.js +169 -0
- package/dist/esm/checkpointer/internal/pending-writes.d.ts +314 -0
- package/dist/esm/checkpointer/internal/pending-writes.js +229 -0
- package/dist/esm/checkpointer/internal/read.d.ts +135 -0
- package/dist/esm/checkpointer/internal/read.js +125 -0
- package/dist/esm/checkpointer/internal/rows.d.ts +644 -0
- package/dist/esm/checkpointer/internal/rows.js +323 -0
- package/dist/esm/checkpointer/internal/setup.d.ts +47 -0
- package/dist/esm/checkpointer/internal/setup.js +21 -0
- package/dist/{checkpointer/saver.js → esm/checkpointer/saver.d.ts} +84 -87
- package/dist/esm/checkpointer/saver.js +52 -0
- package/dist/esm/checkpointer/types.d.ts +51 -0
- package/dist/esm/checkpointer/types.js +1 -0
- package/dist/esm/factory/factory.d.ts +154 -0
- package/dist/esm/factory/factory.js +133 -0
- package/dist/esm/factory/types.d.ts +76 -0
- package/dist/esm/factory/types.js +1 -0
- package/dist/{history/actions/add-messages.js → esm/history/actions/add-messages.d.ts} +20 -26
- package/dist/esm/history/actions/add-messages.js +14 -0
- package/dist/{history/actions/clear.js → esm/history/actions/clear.d.ts} +4 -35
- package/dist/esm/history/actions/clear.js +26 -0
- package/dist/esm/history/actions/get-messages.d.ts +60 -0
- package/dist/esm/history/actions/get-messages.js +55 -0
- package/dist/esm/history/actions/list-sessions.d.ts +55 -0
- package/dist/esm/history/actions/list-sessions.js +64 -0
- package/dist/{history/actions/reconcile-count.js → esm/history/actions/reconcile-count.d.ts} +14 -16
- package/dist/esm/history/actions/reconcile-count.js +5 -0
- package/dist/{history/chat-message-history.js → esm/history/chat-message-history.d.ts} +76 -87
- package/dist/esm/history/chat-message-history.js +57 -0
- package/dist/esm/history/internal/append.d.ts +244 -0
- package/dist/esm/history/internal/append.js +259 -0
- package/dist/esm/history/internal/message-read.d.ts +84 -0
- package/dist/esm/history/internal/message-read.js +89 -0
- package/dist/esm/history/internal/parse.d.ts +153 -0
- package/dist/esm/history/internal/parse.js +105 -0
- package/dist/{history/internal/rows.js → esm/history/internal/rows.d.ts} +58 -112
- package/dist/esm/history/internal/rows.js +83 -0
- package/dist/esm/history/internal/session.d.ts +350 -0
- package/dist/esm/history/internal/session.js +285 -0
- package/dist/esm/history/internal/setup.d.ts +64 -0
- package/dist/esm/history/internal/setup.js +56 -0
- package/dist/{history/session-adapter.js → esm/history/session-adapter.d.ts} +25 -39
- package/dist/esm/history/session-adapter.js +34 -0
- package/dist/esm/history/types.d.ts +102 -0
- package/dist/esm/history/types.js +1 -0
- package/dist/esm/index.d.ts +53 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/shared/adapter.d.ts +146 -0
- package/dist/esm/shared/adapter.js +65 -0
- package/dist/{shared/clock.js → esm/shared/clock.d.ts} +3 -14
- package/dist/esm/shared/clock.js +9 -0
- package/dist/esm/shared/codec/codec.d.ts +336 -0
- package/dist/esm/shared/codec/codec.js +150 -0
- package/dist/esm/shared/codec/compression.d.ts +66 -0
- package/dist/esm/shared/codec/compression.js +40 -0
- package/dist/esm/shared/codec/json-serde.d.ts +80 -0
- package/dist/esm/shared/codec/json-serde.js +54 -0
- package/dist/esm/shared/codec/s3/client-types.d.ts +54 -0
- package/dist/esm/shared/codec/s3/client-types.js +3 -0
- package/dist/esm/shared/codec/s3/client.d.ts +63 -0
- package/dist/esm/shared/codec/s3/client.js +40 -0
- package/dist/{shared/codec/s3/config.js → esm/shared/codec/s3/config.d.ts} +45 -93
- package/dist/esm/shared/codec/s3/config.js +79 -0
- package/dist/esm/shared/codec/s3/lifecycle.d.ts +220 -0
- package/dist/esm/shared/codec/s3/lifecycle.js +214 -0
- package/dist/esm/shared/codec/s3/offloader.d.ts +428 -0
- package/dist/esm/shared/codec/s3/offloader.js +278 -0
- package/dist/{shared/concurrency.js → esm/shared/concurrency.d.ts} +2 -37
- package/dist/esm/shared/concurrency.js +27 -0
- package/dist/{shared/dynamodb/abort.js → esm/shared/dynamodb/abort.d.ts} +4 -16
- package/dist/esm/shared/dynamodb/abort.js +12 -0
- package/dist/esm/shared/dynamodb/batch-write.d.ts +86 -0
- package/dist/esm/shared/dynamodb/batch-write.js +74 -0
- package/dist/{shared/dynamodb/cancellation.js → esm/shared/dynamodb/cancellation.d.ts} +25 -53
- package/dist/esm/shared/dynamodb/cancellation.js +30 -0
- package/dist/{shared/dynamodb/client.js → esm/shared/dynamodb/client.d.ts} +74 -64
- package/dist/esm/shared/dynamodb/client.js +35 -0
- package/dist/{shared/dynamodb/idempotent-write.js → esm/shared/dynamodb/idempotent-write.d.ts} +172 -169
- package/dist/esm/shared/dynamodb/idempotent-write.js +153 -0
- package/dist/esm/shared/dynamodb/paginate.d.ts +111 -0
- package/dist/esm/shared/dynamodb/paginate.js +84 -0
- package/dist/esm/shared/dynamodb/partition-delete.d.ts +204 -0
- package/dist/esm/shared/dynamodb/partition-delete.js +171 -0
- package/dist/esm/shared/dynamodb/recency-index.d.ts +243 -0
- package/dist/esm/shared/dynamodb/recency-index.js +136 -0
- package/dist/esm/shared/dynamodb/retry.d.ts +317 -0
- package/dist/esm/shared/dynamodb/retry.js +180 -0
- package/dist/esm/shared/dynamodb/row-size.d.ts +33 -0
- package/dist/esm/shared/dynamodb/row-size.js +26 -0
- package/dist/{shared/dynamodb/table-schema.js → esm/shared/dynamodb/table-schema.d.ts} +57 -67
- package/dist/esm/shared/dynamodb/table-schema.js +43 -0
- package/dist/esm/shared/errors/base-error.d.ts +231 -0
- package/dist/esm/shared/errors/base-error.js +64 -0
- package/dist/esm/shared/errors/boundary.d.ts +86 -0
- package/dist/esm/shared/errors/boundary.js +54 -0
- package/dist/esm/shared/errors/classify.d.ts +206 -0
- package/dist/esm/shared/errors/classify.js +220 -0
- package/dist/{shared/errors/error-code.js → esm/shared/errors/error-code.d.ts} +39 -43
- package/dist/esm/shared/errors/error-code.js +24 -0
- package/dist/{shared/errors/errors.js → esm/shared/errors/errors.d.ts} +92 -98
- package/dist/esm/shared/errors/errors.js +110 -0
- package/dist/{shared/logging/logger.js → esm/shared/logging/logger.d.ts} +22 -52
- package/dist/esm/shared/logging/logger.js +25 -0
- package/dist/esm/shared/logging/redaction.d.ts +123 -0
- package/dist/esm/shared/logging/redaction.js +140 -0
- package/dist/{shared/logging/secret-patterns.js → esm/shared/logging/secret-patterns.d.ts} +46 -87
- package/dist/esm/shared/logging/secret-patterns.js +83 -0
- package/dist/{shared/logging/truncate.js → esm/shared/logging/truncate.d.ts} +6 -40
- package/dist/esm/shared/logging/truncate.js +25 -0
- package/dist/esm/shared/options.d.ts +100 -0
- package/dist/esm/shared/options.js +1 -0
- package/dist/{shared/ulid.js → esm/shared/ulid.d.ts} +4 -84
- package/dist/esm/shared/ulid.js +77 -0
- package/dist/{shared/validation/collaborators.js → esm/shared/validation/collaborators.d.ts} +37 -65
- package/dist/esm/shared/validation/collaborators.js +70 -0
- package/dist/{shared/validation/option-shape.js → esm/shared/validation/option-shape.d.ts} +14 -36
- package/dist/esm/shared/validation/option-shape.js +24 -0
- package/dist/esm/shared/validation/options.d.ts +145 -0
- package/dist/esm/shared/validation/options.js +156 -0
- package/dist/{shared/validation/primitives.js → esm/shared/validation/primitives.d.ts} +30 -125
- package/dist/esm/shared/validation/primitives.js +100 -0
- package/dist/esm/shared/validation/ttl.d.ts +94 -0
- package/dist/esm/shared/validation/ttl.js +46 -0
- package/dist/esm/store/actions/list-namespaces.d.ts +79 -0
- package/dist/esm/store/actions/list-namespaces.js +86 -0
- package/dist/esm/store/actions/put.d.ts +43 -0
- package/dist/esm/store/actions/put.js +46 -0
- package/dist/{store/actions/reconcile-vector-index.js → esm/store/actions/reconcile-vector-index.d.ts} +8 -16
- package/dist/esm/store/actions/reconcile-vector-index.js +10 -0
- package/dist/esm/store/actions/search.d.ts +38 -0
- package/dist/esm/store/actions/search.js +23 -0
- package/dist/esm/store/internal/batch-plan.d.ts +56 -0
- package/dist/esm/store/internal/batch-plan.js +28 -0
- package/dist/esm/store/internal/filter.d.ts +43 -0
- package/dist/esm/store/internal/filter.js +60 -0
- package/dist/esm/store/internal/get-item.d.ts +77 -0
- package/dist/esm/store/internal/get-item.js +54 -0
- package/dist/esm/store/internal/item-write.d.ts +270 -0
- package/dist/esm/store/internal/item-write.js +173 -0
- package/dist/esm/store/internal/parse.d.ts +230 -0
- package/dist/esm/store/internal/parse.js +169 -0
- package/dist/{store/internal/rows.js → esm/store/internal/rows.d.ts} +111 -199
- package/dist/esm/store/internal/rows.js +147 -0
- package/dist/esm/store/internal/semantic-search.d.ts +168 -0
- package/dist/esm/store/internal/semantic-search.js +200 -0
- package/dist/esm/store/internal/setup.d.ts +96 -0
- package/dist/esm/store/internal/setup.js +98 -0
- package/dist/esm/store/internal/table-search.d.ts +100 -0
- package/dist/esm/store/internal/table-search.js +119 -0
- package/dist/esm/store/internal/vector-index.d.ts +258 -0
- package/dist/esm/store/internal/vector-index.js +256 -0
- package/dist/{store/store.js → esm/store/store.d.ts} +99 -133
- package/dist/esm/store/store.js +93 -0
- package/dist/esm/store/types.d.ts +111 -0
- package/dist/esm/store/types.js +1 -0
- package/dist/esm/store/vector-backend.d.ts +104 -0
- package/dist/esm/store/vector-backend.js +1 -0
- package/package.json +50 -44
- package/dist/backfill/backfill.js +0 -393
- package/dist/checkpointer/actions/list.js +0 -142
- package/dist/checkpointer/actions/put.js +0 -195
- package/dist/checkpointer/internal/delta-history.js +0 -252
- package/dist/checkpointer/internal/parse.js +0 -372
- package/dist/checkpointer/internal/pending-writes.js +0 -588
- package/dist/checkpointer/internal/read.js +0 -264
- package/dist/checkpointer/internal/rows.js +0 -834
- package/dist/checkpointer/internal/setup.js +0 -72
- package/dist/checkpointer/types.js +0 -12
- package/dist/factory/factory.js +0 -266
- package/dist/factory/types.js +0 -10
- package/dist/history/actions/get-messages.js +0 -141
- package/dist/history/actions/list-sessions.js +0 -156
- package/dist/history/internal/append.js +0 -500
- package/dist/history/internal/message-read.js +0 -204
- package/dist/history/internal/parse.js +0 -252
- package/dist/history/internal/session.js +0 -628
- package/dist/history/internal/setup.js +0 -106
- package/dist/history/types.js +0 -12
- package/dist/index.js +0 -51
- package/dist/shared/adapter.js +0 -143
- package/dist/shared/codec/codec.js +0 -441
- package/dist/shared/codec/compression.js +0 -89
- package/dist/shared/codec/json-serde.js +0 -191
- package/dist/shared/codec/s3/client-types.js +0 -26
- package/dist/shared/codec/s3/client.js +0 -97
- package/dist/shared/codec/s3/lifecycle.js +0 -355
- package/dist/shared/codec/s3/offloader.js +0 -658
- package/dist/shared/dynamodb/batch-write.js +0 -173
- package/dist/shared/dynamodb/paginate.js +0 -188
- package/dist/shared/dynamodb/partition-delete.js +0 -340
- package/dist/shared/dynamodb/recency-index.js +0 -377
- package/dist/shared/dynamodb/retry.js +0 -463
- package/dist/shared/errors/base-error.js +0 -174
- package/dist/shared/errors/boundary.js +0 -143
- package/dist/shared/errors/classify.d.ts +0 -97
- package/dist/shared/errors/classify.js +0 -257
- package/dist/shared/logging/redaction.js +0 -316
- package/dist/shared/options.js +0 -11
- package/dist/shared/validation/options.js +0 -328
- package/dist/shared/validation/ttl.js +0 -132
- package/dist/store/actions/list-namespaces.js +0 -197
- package/dist/store/actions/put.js +0 -78
- package/dist/store/actions/search.js +0 -66
- package/dist/store/internal/batch-plan.d.ts +0 -26
- package/dist/store/internal/batch-plan.js +0 -109
- package/dist/store/internal/filter.js +0 -137
- package/dist/store/internal/get-item.d.ts +0 -45
- package/dist/store/internal/get-item.js +0 -115
- package/dist/store/internal/item-write.js +0 -463
- package/dist/store/internal/parse.js +0 -350
- package/dist/store/internal/semantic-search.js +0 -389
- package/dist/store/internal/setup.js +0 -223
- package/dist/store/internal/table-search.js +0 -213
- package/dist/store/internal/vector-index.js +0 -546
- package/dist/store/types.js +0 -15
- package/dist/store/vector-backend.js +0 -17
- /package/dist/{shared → cjs/shared}/clock.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/codec/json-serde.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/concurrency.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/dynamodb/cancellation.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/logging/logger.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/logging/truncate.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/ulid.d.ts +0 -0
- /package/dist/{shared → cjs/shared}/validation/primitives.d.ts +0 -0
- /package/dist/{store → cjs/store}/vector-backend.d.ts +0 -0
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Hides when and how a failed request is retried (record 14).
|
|
4
|
-
*
|
|
5
|
-
* Which failures are transient — read from an error's whole cause chain, its
|
|
6
|
-
* HTTP status and its retryable trait, and from a cancelled transaction's
|
|
7
|
-
* reasons — the full-jitter backoff schedule, the attempt budget and the
|
|
8
|
-
* deadline that can cut it short, and the policy an adapter resolves from its
|
|
9
|
-
* options at construction are one decision. Every DynamoDB call goes through
|
|
10
|
-
* it, and so does an S3 object upload and download; the bucket lifecycle calls
|
|
11
|
-
* (`maxAttempts: 1` on the S3 client) and orphan release, which retries on its
|
|
12
|
-
* own loop, do not.
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.MAX_WRITE_LIFETIME_MS = exports.TOKEN_IDEMPOTENCY_WINDOW_MS = exports.DEFAULT_RETRY_MAX_ATTEMPTS = exports.MAX_BACKOFF_DELAY_MS = exports.INITIAL_BACKOFF_DELAY_MS = void 0;
|
|
16
|
-
exports.withRetry = withRetry;
|
|
17
|
-
exports.withDynamoDBRetry = withDynamoDBRetry;
|
|
18
|
-
exports.isRetryableError = isRetryableError;
|
|
19
|
-
exports.resolveRetryPolicy = resolveRetryPolicy;
|
|
20
|
-
exports.retryFor = retryFor;
|
|
21
|
-
exports.sleep = sleep;
|
|
22
|
-
exports.nextBackoffDelay = nextBackoffDelay;
|
|
23
|
-
exports.fullJitter = fullJitter;
|
|
24
|
-
exports.isTransientS3Error = isTransientS3Error;
|
|
25
|
-
const clock_1 = require("../clock");
|
|
26
|
-
const base_error_1 = require("../errors/base-error");
|
|
27
|
-
const classify_1 = require("../errors/classify");
|
|
28
|
-
const errors_1 = require("../errors/errors");
|
|
29
|
-
const secret_patterns_1 = require("../logging/secret-patterns");
|
|
30
|
-
const truncate_1 = require("../logging/truncate");
|
|
31
|
-
const abort_1 = require("./abort");
|
|
32
|
-
const cancellation_1 = require("./cancellation");
|
|
33
|
-
/** Starting delay for UnprocessedItems / UnprocessedKeys backoff loops. */
|
|
34
|
-
exports.INITIAL_BACKOFF_DELAY_MS = 100;
|
|
35
|
-
/** Maximum backoff delay for retry loops. */
|
|
36
|
-
exports.MAX_BACKOFF_DELAY_MS = 5000;
|
|
37
|
-
/** Default maximum attempts for transient-error retries. */
|
|
38
|
-
exports.DEFAULT_RETRY_MAX_ATTEMPTS = 5;
|
|
39
|
-
/**
|
|
40
|
-
* How long DynamoDB treats a repeated client request token as the same request
|
|
41
|
-
* rather than a new one, so re-sending a tokened write is deduplicated instead
|
|
42
|
-
* of applied twice (10 minutes). Recorded as its own constant so the margin
|
|
43
|
-
* {@link MAX_WRITE_LIFETIME_MS} keeps under it is legible.
|
|
44
|
-
*/
|
|
45
|
-
exports.TOKEN_IDEMPOTENCY_WINDOW_MS = 600_000;
|
|
46
|
-
/**
|
|
47
|
-
* Longest one token-carrying write may keep retrying (5 minutes): half of
|
|
48
|
-
* {@link TOKEN_IDEMPOTENCY_WINDOW_MS}. The other half absorbs the attempt
|
|
49
|
-
* still in flight when the budget ends, clock skew between this client's own
|
|
50
|
-
* clock and DynamoDB's timer, and SDK-internal queueing, so a write that
|
|
51
|
-
* retries to the end still finishes well inside the window its token is
|
|
52
|
-
* honoured for. Its own literal rather than a division of the window:
|
|
53
|
-
* aliasing them would move one whenever the other is retuned (see
|
|
54
|
-
* `LIST_SCAN_WARN_THRESHOLD` (`src/shared/dynamodb/paginate.ts`)).
|
|
55
|
-
*/
|
|
56
|
-
exports.MAX_WRITE_LIFETIME_MS = 300_000;
|
|
57
|
-
/**
|
|
58
|
-
* Whether sleeping `delayMs` now would carry the budget past `deadlineAt`.
|
|
59
|
-
* No deadline, no bound: the schedule is then exactly what it always was.
|
|
60
|
-
*/
|
|
61
|
-
function crossesDeadline(deadlineAt, delayMs) {
|
|
62
|
-
return deadlineAt !== undefined && (0, clock_1.nowMs)() + delayMs >= deadlineAt;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* End the operation the moment the caller's signal has fired.
|
|
66
|
-
*
|
|
67
|
-
* One function for both observation points — before the first attempt, and
|
|
68
|
-
* after every failed one — so the two can never answer a cancel differently.
|
|
69
|
-
*/
|
|
70
|
-
function assertNotAborted(signal) {
|
|
71
|
-
if (signal?.aborted)
|
|
72
|
-
throw (0, abort_1.abortErrorFrom)(signal);
|
|
73
|
-
}
|
|
74
|
-
function delayForAttempt(attempt, base, max, rng) {
|
|
75
|
-
const exponential = base * 2 ** (attempt - 1);
|
|
76
|
-
return fullJitter(Math.min(exponential, max), rng);
|
|
77
|
-
}
|
|
78
|
-
/** Apply defaults to {@link RetryOptions}. */
|
|
79
|
-
function resolveRetryOptions(options) {
|
|
80
|
-
return {
|
|
81
|
-
maxAttempts: options.maxAttempts ?? exports.DEFAULT_RETRY_MAX_ATTEMPTS,
|
|
82
|
-
baseDelayMs: options.baseDelayMs ?? exports.INITIAL_BACKOFF_DELAY_MS,
|
|
83
|
-
maxDelayMs: options.maxDelayMs ?? exports.MAX_BACKOFF_DELAY_MS,
|
|
84
|
-
isRetryable: options.isRetryable ??
|
|
85
|
-
((error) => isRetryableError(error, options.retryableErrors ?? classify_1.DEFAULT_RETRYABLE_ERRORS)),
|
|
86
|
-
rng: options.rng ?? Math.random,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Run `fn`, retrying transient failures with full-jitter exponential backoff.
|
|
91
|
-
*
|
|
92
|
-
* Accepts: `fn` — given the {@link SdkRequestOptions} for the attempt, to pass
|
|
93
|
-
* as the second argument of the SDK call it makes. That argument is what
|
|
94
|
-
* carries `options.signal` into the request, and it is the only way a call
|
|
95
|
-
* site can: `fn` closes over its own parameters, so nothing else reaches it.
|
|
96
|
-
* An `fn` that makes no cancellable call ignores the parameter and is written
|
|
97
|
-
* exactly as it was, since a zero-argument function still satisfies the type.
|
|
98
|
-
*
|
|
99
|
-
* Accepts: `options.maxAttempts` — total attempts including the first, default
|
|
100
|
-
* {@link DEFAULT_RETRY_MAX_ATTEMPTS}; at least 1, which `assertRetryPolicy`
|
|
101
|
-
* enforces for every caller-supplied policy. `options.baseDelayMs` /
|
|
102
|
-
* `maxDelayMs` — the backoff schedule. `options.isRetryable` — replaces
|
|
103
|
-
* `retryableErrors` entirely, so a call site can share one classifier with
|
|
104
|
-
* paths that do not go through here. `options.signal` — checked before the
|
|
105
|
-
* first attempt, handed to every attempt as `abortSignal` so the request in
|
|
106
|
-
* flight is cancelled rather than merely awaited, checked again when an
|
|
107
|
-
* attempt fails, and honoured during every backoff wait. `options.onRetry` —
|
|
108
|
-
* called synchronously before each wait; an exception from it is not caught
|
|
109
|
-
* and ends the operation. `options.deadlineAt` — an internal bound on the
|
|
110
|
-
* whole budget rather than on one attempt: the wait that would carry the
|
|
111
|
-
* operation past it is never started, and the budget ends there instead.
|
|
112
|
-
* Without it the schedule, the attempt count and every error are unchanged.
|
|
113
|
-
*
|
|
114
|
-
* Returns: whatever `fn` resolves to, from the first attempt that succeeds.
|
|
115
|
-
*
|
|
116
|
-
* Throws: the error itself, unchanged, when it is not retryable — a
|
|
117
|
-
* `ValidationException` or a permission failure is never retried;
|
|
118
|
-
* `ABORTED` when the signal fires, including during a wait and
|
|
119
|
-
* including while a request is in flight — the SDK rejects the cancelled
|
|
120
|
-
* request with an error of its own, and a failed attempt whose signal has
|
|
121
|
-
* fired is reported as the cancel it is rather than being classified, retried
|
|
122
|
-
* or wrapped; `RETRY_EXHAUSTED` once the budget ends, carrying the attempt
|
|
123
|
-
* actually reached — not the attempts configured — and the last error as
|
|
124
|
-
* `cause`. Its message quotes the last error **redacted**, because it reaches
|
|
125
|
-
* `err.message`, which an application may print without a redacting logger.
|
|
126
|
-
*
|
|
127
|
-
* A deadline that ends the budget is reported exactly as a spent one, by the
|
|
128
|
-
* same error with the same code: a caller cannot tell the two apart, and
|
|
129
|
-
* nothing needs to, since the handling of both is identical — read the row
|
|
130
|
-
* back, and release only what is confirmed not to have landed.
|
|
131
|
-
*
|
|
132
|
-
* A cancelled wait is also an abort no longer observed. The signal is read
|
|
133
|
-
* before the first attempt, after every failed one, and inside each wait, so
|
|
134
|
-
* ending the budget in place of a wait drops only that last observation point:
|
|
135
|
-
* a signal that fires *after* the deadline has already refused the wait, in
|
|
136
|
-
* the window where the wait would have been running, surfaces as
|
|
137
|
-
* `RETRY_EXHAUSTED` rather than `ABORTED`. One already set
|
|
138
|
-
* at entry, fired during an attempt, or fired during an earlier wait, is still
|
|
139
|
-
* caught.
|
|
140
|
-
*
|
|
141
|
-
* Guarantees: `fn` is called at least once and at most `maxAttempts` times. A
|
|
142
|
-
* thrown non-`Error` is wrapped, so what a caller catches is always an `Error`.
|
|
143
|
-
*/
|
|
144
|
-
async function withRetry(fn, options = {}) {
|
|
145
|
-
const { maxAttempts, baseDelayMs, maxDelayMs, isRetryable, rng } = resolveRetryOptions(options);
|
|
146
|
-
assertNotAborted(options.signal);
|
|
147
|
-
// Built once and handed to every attempt. The SDK reads it and keeps
|
|
148
|
-
// nothing, so one object costs one allocation per operation instead of one
|
|
149
|
-
// per attempt, and a re-send cannot differ from the send before it.
|
|
150
|
-
const request = { abortSignal: options.signal };
|
|
151
|
-
let lastError = new Error('Retry failed without error');
|
|
152
|
-
let attempts = 0;
|
|
153
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
154
|
-
attempts = attempt;
|
|
155
|
-
try {
|
|
156
|
-
return await fn(request);
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
// Read before the error is classified. A cancelled request rejects with
|
|
160
|
-
// whatever the transport produced — the SDK's own `AbortError` for one
|
|
161
|
-
// cut before the response, a socket error for one cut mid-body — and
|
|
162
|
-
// both would otherwise be classified, retried against a signal that has
|
|
163
|
-
// already fired, and finally reported as a transport failure. A caller
|
|
164
|
-
// who cancelled is owed `ABORTED`, not a diagnosis of its own stop.
|
|
165
|
-
assertNotAborted(options.signal);
|
|
166
|
-
lastError = (0, base_error_1.toError)(error);
|
|
167
|
-
if (!isRetryable(lastError))
|
|
168
|
-
throw lastError;
|
|
169
|
-
if (attempt === maxAttempts)
|
|
170
|
-
break;
|
|
171
|
-
const delayMs = delayForAttempt(attempt, baseDelayMs, maxDelayMs, rng);
|
|
172
|
-
if (crossesDeadline(options.deadlineAt, delayMs))
|
|
173
|
-
break;
|
|
174
|
-
options.onRetry?.({ attempt, delayMs, error: lastError });
|
|
175
|
-
await sleep(delayMs, options.signal);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
throw (0, errors_1.retryExhaustedError)(`Operation failed after ${attempts} attempts: ${(0, secret_patterns_1.redactedMessage)(lastError)}`, attempts, lastError);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* {@link withRetry} with this package's DynamoDB defaults.
|
|
182
|
-
*
|
|
183
|
-
* Accepts: `overrides` — merged over `maxAttempts:`
|
|
184
|
-
* {@link DEFAULT_RETRY_MAX_ATTEMPTS}, so an adapter's resolved policy wins.
|
|
185
|
-
*
|
|
186
|
-
* Returns: as {@link withRetry}.
|
|
187
|
-
*
|
|
188
|
-
* Throws: as {@link withRetry}.
|
|
189
|
-
*/
|
|
190
|
-
async function withDynamoDBRetry(fn, overrides) {
|
|
191
|
-
return withRetry(fn, { maxAttempts: exports.DEFAULT_RETRY_MAX_ATTEMPTS, ...overrides });
|
|
192
|
-
}
|
|
193
|
-
const MAX_CAUSE_DEPTH = 32;
|
|
194
|
-
/** Add one node's signal tokens, HTTP status and retryable trait to `evidence`. */
|
|
195
|
-
function recordNode(fields, evidence) {
|
|
196
|
-
for (const value of [fields.name, fields.code, fields.errno, fields.syscall]) {
|
|
197
|
-
if (typeof value === 'string')
|
|
198
|
-
evidence.signals.push(value);
|
|
199
|
-
}
|
|
200
|
-
if (typeof fields.$metadata?.httpStatusCode === 'number') {
|
|
201
|
-
evidence.statuses.push(fields.$metadata.httpStatusCode);
|
|
202
|
-
}
|
|
203
|
-
if (fields.$retryable !== undefined && fields.$retryable !== null)
|
|
204
|
-
evidence.retryableByTrait = true;
|
|
205
|
-
}
|
|
206
|
-
function collectEvidence(error) {
|
|
207
|
-
const seen = new WeakSet();
|
|
208
|
-
const evidence = { signals: [], statuses: [], retryableByTrait: false };
|
|
209
|
-
const walk = (node, depth) => {
|
|
210
|
-
if (depth > MAX_CAUSE_DEPTH || node === null || typeof node !== 'object' || seen.has(node)) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
seen.add(node);
|
|
214
|
-
const fields = node;
|
|
215
|
-
recordNode(fields, evidence);
|
|
216
|
-
if (fields.cause)
|
|
217
|
-
walk(fields.cause, depth + 1);
|
|
218
|
-
};
|
|
219
|
-
walk(error, 0);
|
|
220
|
-
return evidence;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Whether `error`, or any cause in its chain, is transient.
|
|
224
|
-
*
|
|
225
|
-
* Accepts: `error` — an `Error`; its `cause` chain is walked to
|
|
226
|
-
* {@link MAX_CAUSE_DEPTH}, and a cycle in it terminates the walk rather than
|
|
227
|
-
* looping. Anything else a `throw` can produce carries no node to walk and is
|
|
228
|
-
* not retryable. `retryableErrors` — the signal tokens to match; an empty list
|
|
229
|
-
* still admits the trait and status rules below.
|
|
230
|
-
*
|
|
231
|
-
* Returns: true when any of these holds, in this order —
|
|
232
|
-
* 1. the error is a transaction cancellation and **every** reason it carries is
|
|
233
|
-
* transient. This verdict is final either way: a permanent reason arrives
|
|
234
|
-
* with the same HTTP status as a transient one, so the later rules cannot be
|
|
235
|
-
* allowed to overturn it. A cancellation carrying no reasons is not retried.
|
|
236
|
-
* 2. any node carries the SDK's `$retryable` trait;
|
|
237
|
-
* 3. any node's HTTP status is in {@link TRANSIENT_HTTP_STATUSES} — which is
|
|
238
|
-
* what classifies a failure the SDK could not map to a modeled exception,
|
|
239
|
-
* arriving as `name: 'Unknown'` with only a status;
|
|
240
|
-
* 4. any node's `name`, `code`, `errno` or `syscall` equals a token in
|
|
241
|
-
* `retryableErrors`.
|
|
242
|
-
*
|
|
243
|
-
* The token match is exact, never substring: these fields are whole tokens, and
|
|
244
|
-
* a substring rule would let an unrelated name that merely contains one ride
|
|
245
|
-
* along.
|
|
246
|
-
*
|
|
247
|
-
* Throws: **nothing**, for any value a `throw` can produce — see
|
|
248
|
-
* {@link transientCancellation}, which the first rule reads through.
|
|
249
|
-
*/
|
|
250
|
-
function isRetryableError(error, retryableErrors) {
|
|
251
|
-
const cancellation = (0, cancellation_1.transientCancellation)(error);
|
|
252
|
-
if (cancellation !== undefined)
|
|
253
|
-
return cancellation;
|
|
254
|
-
const evidence = collectEvidence(error);
|
|
255
|
-
if (evidence.retryableByTrait)
|
|
256
|
-
return true;
|
|
257
|
-
if (evidence.statuses.some((status) => classify_1.TRANSIENT_HTTP_STATUSES.includes(status)))
|
|
258
|
-
return true;
|
|
259
|
-
return evidence.signals.some((signal) => retryableErrors.includes(signal));
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* The nominal worst case of a policy's backoff schedule, in milliseconds.
|
|
263
|
-
*
|
|
264
|
-
* `withRetry` sleeps *between* attempts, so a budget of `maxAttempts` attempts
|
|
265
|
-
* holds `maxAttempts - 1` sleeps, and full jitter draws the k-th of them from
|
|
266
|
-
* `[0, min(baseDelayMs * 2 ** (k - 1), maxDelayMs))`. The worst case is
|
|
267
|
-
* therefore the **sum of those caps**:
|
|
268
|
-
*
|
|
269
|
-
* `sum over k in 1..maxAttempts-1 of min(baseDelayMs * 2 ** (k - 1), maxDelayMs)`
|
|
270
|
-
*
|
|
271
|
-
* It is stated here because the reading a reader reaches for —
|
|
272
|
-
* `maxAttempts * maxDelayMs` — is wrong in both directions at once: it counts
|
|
273
|
-
* a sleep after the final attempt, which never happens, and it charges the cap
|
|
274
|
-
* for every early sleep the exponential has not yet climbed to. At the
|
|
275
|
-
* defaults - five attempts, so four sleeps - they total 1.5 s where the naive
|
|
276
|
-
* reading says 25 s.
|
|
277
|
-
*
|
|
278
|
-
* Nominal, not actual: each sleep is drawn uniformly below its cap, so a real
|
|
279
|
-
* budget averages about half of this and only approaches it in the limit. The
|
|
280
|
-
* cap is what a bound has to be measured against all the same.
|
|
281
|
-
*/
|
|
282
|
-
function nominalBudgetMs(policy) {
|
|
283
|
-
let total = 0;
|
|
284
|
-
for (let sleep = 1; sleep < policy.maxAttempts; sleep++) {
|
|
285
|
-
total += Math.min(policy.baseDelayMs * 2 ** (sleep - 1), policy.maxDelayMs);
|
|
286
|
-
}
|
|
287
|
-
return total;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Warn when a policy's nominal budget outlives {@link MAX_WRITE_LIFETIME_MS},
|
|
291
|
-
* the deadline every token-carrying write in this package runs under.
|
|
292
|
-
*
|
|
293
|
-
* Warn, never refuse. A long policy is the caller's own choice, it stays
|
|
294
|
-
* legal, and the deadline already makes it safe — what it is not, without this
|
|
295
|
-
* line, is visible: a deadline that ends a budget early and a budget that is
|
|
296
|
-
* simply spent both surface as the same `RETRY_EXHAUSTED` error, so the first
|
|
297
|
-
* evidence that a configured policy can never run to its end would otherwise
|
|
298
|
-
* be an incident. Said once, at construction, it is said before the first
|
|
299
|
-
* write rather than after.
|
|
300
|
-
*/
|
|
301
|
-
function warnIfOutlivesWriteLifetime(policy, logger) {
|
|
302
|
-
const budgetMs = nominalBudgetMs(policy);
|
|
303
|
-
if (budgetMs <= exports.MAX_WRITE_LIFETIME_MS)
|
|
304
|
-
return;
|
|
305
|
-
logger.warn('retry policy outlives the write lifetime; the budget will be cut short', {
|
|
306
|
-
budgetMs,
|
|
307
|
-
maxWriteLifetimeMs: exports.MAX_WRITE_LIFETIME_MS,
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Resolve an adapter's retry policy once, at construction.
|
|
312
|
-
*
|
|
313
|
-
* Accepts: `policy` — the caller's, already validated, or nothing. `logger` —
|
|
314
|
-
* the adapter's resolved logger.
|
|
315
|
-
*
|
|
316
|
-
* Returns: the options every DynamoDB call of that adapter uses, with each
|
|
317
|
-
* field defaulted and the logger attached, so every retry is visible at `debug`
|
|
318
|
-
* (the attempt, the delay about to be slept, the error's name) instead of only
|
|
319
|
-
* surfacing once the budget is exhausted.
|
|
320
|
-
*
|
|
321
|
-
* Accepts: `attemptFloor` — the lowest attempt count this adapter will actually
|
|
322
|
-
* use, when it raises a caller's below its own. The budget is warned about at
|
|
323
|
-
* that number rather than at the caller's, because it is the one the writes
|
|
324
|
-
* will really spend; an adapter that honours the caller's count passes none.
|
|
325
|
-
*
|
|
326
|
-
* Throws: nothing; the policy was validated where it was given. A policy whose
|
|
327
|
-
* nominal budget outlives {@link MAX_WRITE_LIFETIME_MS} is warned about rather
|
|
328
|
-
* than refused, once per adapter constructed — three adapters built from one
|
|
329
|
-
* long policy each say so for themselves — see
|
|
330
|
-
* {@link warnIfOutlivesWriteLifetime}. The defaults are far inside it and say
|
|
331
|
-
* nothing.
|
|
332
|
-
*/
|
|
333
|
-
function resolveRetryPolicy(policy, logger, attemptFloor = 0) {
|
|
334
|
-
const resolved = {
|
|
335
|
-
maxAttempts: policy?.maxAttempts ?? exports.DEFAULT_RETRY_MAX_ATTEMPTS,
|
|
336
|
-
baseDelayMs: policy?.baseDelayMs ?? exports.INITIAL_BACKOFF_DELAY_MS,
|
|
337
|
-
maxDelayMs: policy?.maxDelayMs ?? exports.MAX_BACKOFF_DELAY_MS,
|
|
338
|
-
};
|
|
339
|
-
// Measured at the attempts the adapter will really make, not at the ones the
|
|
340
|
-
// caller wrote. The history append raises a caller's count to its own floor
|
|
341
|
-
// while keeping the caller's delays, so a policy that only raises
|
|
342
|
-
// `maxDelayMs` produces a budget far past the deadline and would otherwise
|
|
343
|
-
// be warned about nowhere. An adapter with no floor passes none.
|
|
344
|
-
warnIfOutlivesWriteLifetime({ ...resolved, maxAttempts: Math.max(resolved.maxAttempts, attemptFloor) }, logger);
|
|
345
|
-
return {
|
|
346
|
-
...resolved,
|
|
347
|
-
// The name, never the message — and bounded: the transient failure came
|
|
348
|
-
// from the SDK, the transport or a caller's own collaborator, and nothing
|
|
349
|
-
// this package ran checked how long its name is. This line fires once per
|
|
350
|
-
// retry, so an unbounded one is paid for per attempt.
|
|
351
|
-
onRetry: ({ attempt, delayMs, error }) => logger.debug('retrying after a transient error', {
|
|
352
|
-
attempt,
|
|
353
|
-
delayMs,
|
|
354
|
-
error: (0, truncate_1.truncateForLog)((0, base_error_1.failureLabel)(error)),
|
|
355
|
-
}),
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* The context's retry options plus a per-call cancellation signal.
|
|
360
|
-
*
|
|
361
|
-
* Accepts: `context.retry` — the adapter's resolved policy. `signal` — the
|
|
362
|
-
* caller's, when the call takes one.
|
|
363
|
-
*
|
|
364
|
-
* Returns: the adapter's options untouched when there is no signal — the same
|
|
365
|
-
* object, so no per-call allocation on the common path — and a copy carrying it
|
|
366
|
-
* when there is.
|
|
367
|
-
*
|
|
368
|
-
* Throws: nothing.
|
|
369
|
-
*/
|
|
370
|
-
function retryFor(context, signal) {
|
|
371
|
-
return signal === undefined ? context.retry : { ...context.retry, signal };
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Wait `ms` milliseconds, cancellable.
|
|
375
|
-
*
|
|
376
|
-
* Accepts: `ms` — the delay. `signal` — omitted waits uninterruptibly; already
|
|
377
|
-
* aborted rejects before any timer is set; aborting while pending rejects at
|
|
378
|
-
* that moment and clears the timer.
|
|
379
|
-
*
|
|
380
|
-
* Returns: a promise resolving when the delay elapses.
|
|
381
|
-
*
|
|
382
|
-
* Throws: an `ABORTED` error however the signal was aborted —
|
|
383
|
-
* with a `DOMException`, a string or a custom reason (see
|
|
384
|
-
* {@link abortErrorFrom}).
|
|
385
|
-
*
|
|
386
|
-
* Guarantees: exactly one of resolve and reject runs, and neither the timer nor
|
|
387
|
-
* the abort listener outlives the call. The listener is attached before the
|
|
388
|
-
* timer is armed, so a signal whose `addEventListener` throws rejects the wait
|
|
389
|
-
* with nothing left behind — armed first, the timer outlived that rejection
|
|
390
|
-
* and later called `removeEventListener` outside any promise. A listener that
|
|
391
|
-
* runs while it is being attached settles the wait before any timer exists.
|
|
392
|
-
*/
|
|
393
|
-
function sleep(ms, signal) {
|
|
394
|
-
if (signal?.aborted) {
|
|
395
|
-
return Promise.reject((0, abort_1.abortErrorFrom)(signal));
|
|
396
|
-
}
|
|
397
|
-
return new Promise((resolve, reject) => {
|
|
398
|
-
// One holder for both flags, declared before `onAbort` reads the timer:
|
|
399
|
-
// the timer is assigned only once armed, after the listener is attached.
|
|
400
|
-
const wait = { settled: false };
|
|
401
|
-
const onAbort = () => {
|
|
402
|
-
if (wait.settled)
|
|
403
|
-
return;
|
|
404
|
-
wait.settled = true;
|
|
405
|
-
clearTimeout(wait.timer);
|
|
406
|
-
reject((0, abort_1.abortErrorFrom)(signal));
|
|
407
|
-
};
|
|
408
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
409
|
-
if (wait.settled)
|
|
410
|
-
return;
|
|
411
|
-
wait.timer = setTimeout(() => {
|
|
412
|
-
if (wait.settled)
|
|
413
|
-
return;
|
|
414
|
-
wait.settled = true;
|
|
415
|
-
signal?.removeEventListener('abort', onAbort);
|
|
416
|
-
resolve();
|
|
417
|
-
}, ms);
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* The next exponential-backoff delay.
|
|
422
|
-
*
|
|
423
|
-
* Accepts: `currentMs` — the delay just used; at least 1, since doubling 0
|
|
424
|
-
* never grows. `maxMs` — the ceiling, default {@link MAX_BACKOFF_DELAY_MS}.
|
|
425
|
-
*
|
|
426
|
-
* Returns: `min(currentMs * 2, maxMs)`.
|
|
427
|
-
*
|
|
428
|
-
* Throws: nothing.
|
|
429
|
-
*/
|
|
430
|
-
function nextBackoffDelay(currentMs, maxMs = exports.MAX_BACKOFF_DELAY_MS) {
|
|
431
|
-
return Math.min(currentMs * 2, maxMs);
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* AWS's full jitter over a backoff delay.
|
|
435
|
-
*
|
|
436
|
-
* Accepts: `delayMs` — the unjittered delay. `rng` — a seam returning
|
|
437
|
-
* `[0, 1)`, default `Math.random`; tests inject a fixed one.
|
|
438
|
-
*
|
|
439
|
-
* Returns: a value in `[0, delayMs)`, so two clients retrying the same failure
|
|
440
|
-
* do not retry together
|
|
441
|
-
* (https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/).
|
|
442
|
-
*
|
|
443
|
-
* Throws: nothing.
|
|
444
|
-
*/
|
|
445
|
-
function fullJitter(delayMs, rng = Math.random) {
|
|
446
|
-
return rng() * delayMs;
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Whether `error` is a transient S3 failure worth retrying.
|
|
450
|
-
*
|
|
451
|
-
* Accepts: `error` — any error, including one carrying no name or code, and
|
|
452
|
-
* equally anything else a `throw` can produce.
|
|
453
|
-
*
|
|
454
|
-
* Returns: {@link isRetryableError} over the shared default tokens, which hold
|
|
455
|
-
* S3's own transient names (`SlowDown`, `InternalError`,
|
|
456
|
-
* `ConditionalRequestConflict`) alongside DynamoDB's — one list, so the two
|
|
457
|
-
* services cannot drift apart on what is transient.
|
|
458
|
-
*
|
|
459
|
-
* Throws: **nothing**, for any value; {@link isRetryableError} is total.
|
|
460
|
-
*/
|
|
461
|
-
function isTransientS3Error(error) {
|
|
462
|
-
return isRetryableError(error, classify_1.DEFAULT_RETRYABLE_ERRORS);
|
|
463
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Hides the one error class and what counts as an error at all.
|
|
4
|
-
*
|
|
5
|
-
* Every failure this package raises is a `DynamoDBLangGraphError` told apart by
|
|
6
|
-
* its code (record 19), recognisable across copies of the package by a brand
|
|
7
|
-
* rather than by `instanceof`; and whatever a caller's code or a dependency
|
|
8
|
-
* throws — a string, `undefined`, an object — is turned into an `Error` before
|
|
9
|
-
* anything reads it.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DynamoDBLangGraphError = void 0;
|
|
13
|
-
exports.isDynamoDBLangGraphError = isDynamoDBLangGraphError;
|
|
14
|
-
exports.hasErrorCode = hasErrorCode;
|
|
15
|
-
exports.failureLabel = failureLabel;
|
|
16
|
-
exports.toError = toError;
|
|
17
|
-
const error_code_1 = require("./error-code");
|
|
18
|
-
const ERROR_BRAND = Symbol.for('@farukada/aws-langgraph-dynamodb-ts/error');
|
|
19
|
-
/**
|
|
20
|
-
* A shallow copy of `details` with every array copied too, so a caller reusing
|
|
21
|
-
* its request buffer or failure list cannot rewrite what the error reported.
|
|
22
|
-
* Anything that is not an object is returned as it is: building an error may
|
|
23
|
-
* not fail.
|
|
24
|
-
*/
|
|
25
|
-
function copyDetails(details) {
|
|
26
|
-
if (details === null || typeof details !== 'object')
|
|
27
|
-
return details;
|
|
28
|
-
return Object.fromEntries(Object.entries(details).map(([key, value]) => [key, Array.isArray(value) ? [...value] : value]));
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Base class for every error this library throws. Carries a branchable
|
|
32
|
-
* {@link ErrorCode}, structured {@link ErrorContext}, code-specific
|
|
33
|
-
* {@link details}, and a native `cause` chain. Detected via
|
|
34
|
-
* {@link isDynamoDBLangGraphError} (a symbol brand) rather than `instanceof`,
|
|
35
|
-
* which is banned repo-wide.
|
|
36
|
-
*/
|
|
37
|
-
class DynamoDBLangGraphError extends Error {
|
|
38
|
-
code;
|
|
39
|
-
context;
|
|
40
|
-
/**
|
|
41
|
-
* Accepts: `message` — already redacted by whoever composed it, since it reaches
|
|
42
|
-
* `err.message`, which an application may print without a redacting logger.
|
|
43
|
-
* `code` — the code this error branches on. `context` — identifiers and counts
|
|
44
|
-
* only, never a payload or a credential. It is **copied**, so a caller that
|
|
45
|
-
* reuses one builder object cannot rewrite the context of an error already in
|
|
46
|
-
* flight; `null` reads as an absent one. `cause` — the failure below this one,
|
|
47
|
-
* kept as the native `cause` chain. `details` — the code-specific record
|
|
48
|
-
* {@link ErrorDetailsByCode} names, copied like `context`. The parameter is
|
|
49
|
-
* optional for every code, including the two whose `details` property is
|
|
50
|
-
* typed as always present (`BATCH_WRITE_INCOMPLETE`, `COMPENSATION_FAILED`):
|
|
51
|
-
* nothing at compile time stops a direct `new` from leaving it out, and an
|
|
52
|
-
* error built that way has no `details` at runtime whatever its type says.
|
|
53
|
-
* Inside this package those two codes are only ever built by the factories
|
|
54
|
-
* that always pass them.
|
|
55
|
-
*
|
|
56
|
-
* Returns: the error, branded so {@link isDynamoDBLangGraphError} recognises it
|
|
57
|
-
* across realms and across two copies of this package. The brand is
|
|
58
|
-
* non-enumerable, so it never reaches a log or a JSON serialization.
|
|
59
|
-
*
|
|
60
|
-
* Throws: nothing; building an error may not fail.
|
|
61
|
-
*/
|
|
62
|
-
constructor(message, code, context = {}, cause, details) {
|
|
63
|
-
super(message, cause === undefined ? undefined : { cause });
|
|
64
|
-
this.name = 'DynamoDBLangGraphError';
|
|
65
|
-
this.code = code;
|
|
66
|
-
this.context = { ...context };
|
|
67
|
-
if (details !== undefined)
|
|
68
|
-
this.details = copyDetails(details);
|
|
69
|
-
Object.defineProperty(this, ERROR_BRAND, { value: true, enumerable: false });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.DynamoDBLangGraphError = DynamoDBLangGraphError;
|
|
73
|
-
/**
|
|
74
|
-
* Whether `value` is one of this library's errors.
|
|
75
|
-
*
|
|
76
|
-
* Accepts: any error, from any realm or any copy of this package — and, since
|
|
77
|
-
* the documented place to call this is inside a `catch`, any other value a
|
|
78
|
-
* `throw` can produce: `null`, `undefined`, a string, a number, a symbol.
|
|
79
|
-
*
|
|
80
|
-
* Returns: whether it carries the brand, narrowed to the union discriminated by
|
|
81
|
-
* `code`. A symbol registered by name, not `instanceof`: two copies of this
|
|
82
|
-
* package in one dependency tree produce two classes but one symbol, and an
|
|
83
|
-
* error crossing a realm boundary keeps its properties while losing its
|
|
84
|
-
* prototype. Anything that cannot carry a property answers `false`. Earlier
|
|
85
|
-
* releases set the same brand, so an older copy of this package installed
|
|
86
|
-
* beside this one has its errors recognised too — in that release's shape: no
|
|
87
|
-
* `details`, the counts as flat properties, and possibly a code this union
|
|
88
|
-
* does not list (`UPSTREAM`).
|
|
89
|
-
*
|
|
90
|
-
* Throws: nothing. The `in` operator raises a `TypeError` on a non-object, and
|
|
91
|
-
* a guard that throws inside the `catch` it was called from would replace the
|
|
92
|
-
* failure the caller is reporting with one of its own.
|
|
93
|
-
*/
|
|
94
|
-
function isDynamoDBLangGraphError(value) {
|
|
95
|
-
return typeof value === 'object' && value !== null && ERROR_BRAND in value;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Whether `value` is one of this library's errors carrying `code`.
|
|
99
|
-
*
|
|
100
|
-
* Accepts: anything a `catch` can bind. `code` — the code to test for.
|
|
101
|
-
*
|
|
102
|
-
* Returns: `true` only for a branded error whose `code` is `code`, narrowed so
|
|
103
|
-
* its `details` are typed. An unbranded object that merely carries a `code`
|
|
104
|
-
* property is not one: recognition is by brand and code together, never by a
|
|
105
|
-
* name or a shape.
|
|
106
|
-
*
|
|
107
|
-
* Throws: nothing, for any value.
|
|
108
|
-
*/
|
|
109
|
-
function hasErrorCode(value, code) {
|
|
110
|
-
return isDynamoDBLangGraphError(value) && value.code === code;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* What a log line calls a failure.
|
|
114
|
-
*
|
|
115
|
-
* Accepts: any error a `catch` bound.
|
|
116
|
-
*
|
|
117
|
-
* Returns: the `code` of one of this library's errors, and the `name` of any
|
|
118
|
-
* other. Every library error shares one name, so the name alone would log
|
|
119
|
-
* `DynamoDBLangGraphError` for a refused input and a spent retry budget alike;
|
|
120
|
-
* the code is what tells them apart, and like a name it is an identifier, never
|
|
121
|
-
* a payload.
|
|
122
|
-
*
|
|
123
|
-
* Throws: nothing for an error. A value that cannot carry a property raises
|
|
124
|
-
* the `TypeError` reading its `name` raises, as reading it directly would.
|
|
125
|
-
*/
|
|
126
|
-
function failureLabel(error) {
|
|
127
|
-
return isDynamoDBLangGraphError(error) ? error.code : error.name;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* A description of a thrown value that is not an `Error`, for its message.
|
|
131
|
-
*
|
|
132
|
-
* `JSON.stringify` is the best available rendering and it throws on a circular
|
|
133
|
-
* structure and on a `BigInt`, so it is guarded: this runs inside a `catch`,
|
|
134
|
-
* where throwing would replace the failure the caller is trying to report.
|
|
135
|
-
*/
|
|
136
|
-
function describeThrown(value) {
|
|
137
|
-
if (typeof value === 'string')
|
|
138
|
-
return value;
|
|
139
|
-
if (value === undefined || value === null)
|
|
140
|
-
return `${String(value)} was thrown`;
|
|
141
|
-
try {
|
|
142
|
-
return JSON.stringify(value) ?? `a ${typeof value} value was thrown`;
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
return `an unserializable ${typeof value} value was thrown`;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* A caught value as an `Error`.
|
|
150
|
-
*
|
|
151
|
-
* Kept in this module rather than in `boundary.ts`, which otherwise reads as
|
|
152
|
-
* its natural home: `shared/logging/secret-patterns.ts` calls this to
|
|
153
|
-
* normalise whatever a `catch` bound before redacting it, and `boundary.ts`
|
|
154
|
-
* itself calls `redactedMessage` while building the error it wraps a foreign
|
|
155
|
-
* failure into. Both edges are real, so the two modules cannot import each
|
|
156
|
-
* other without a cycle; this module depends on neither.
|
|
157
|
-
*
|
|
158
|
-
* Accepts: `value` — declared `Error` because callers narrow a catch clause
|
|
159
|
-
* with `toError(error as Error)`, but anything can be thrown in JavaScript:
|
|
160
|
-
* a string, `undefined`, a plain object, a `BigInt`, a symbol.
|
|
161
|
-
*
|
|
162
|
-
* Returns: the value itself when it is error-shaped — an object carrying a
|
|
163
|
-
* string `message`, which keeps an SDK error's own fields and `cause` intact;
|
|
164
|
-
* otherwise a fresh `Error` describing what was thrown.
|
|
165
|
-
*
|
|
166
|
-
* Throws: **nothing**. This runs inside `catch` blocks, so a throw here would
|
|
167
|
-
* discard the failure being reported and replace it with its own.
|
|
168
|
-
*/
|
|
169
|
-
function toError(value) {
|
|
170
|
-
if (value !== null && typeof value === 'object' && typeof value.message === 'string') {
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
|
-
return new Error(describeThrown(value));
|
|
174
|
-
}
|