@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.
- package/README.md +1621 -288
- package/dist/backfill/backfill.d.ts +168 -0
- package/dist/backfill/backfill.js +393 -0
- package/dist/checkpointer/actions/delete-thread.d.ts +44 -4
- package/dist/checkpointer/actions/delete-thread.js +56 -22
- package/dist/checkpointer/actions/get-tuple.d.ts +29 -5
- package/dist/checkpointer/actions/get-tuple.js +41 -13
- package/dist/checkpointer/actions/list.d.ts +42 -10
- package/dist/checkpointer/actions/list.js +86 -57
- package/dist/checkpointer/actions/put-writes.d.ts +41 -9
- package/dist/checkpointer/actions/put-writes.js +62 -48
- package/dist/checkpointer/actions/put.d.ts +82 -10
- package/dist/checkpointer/actions/put.js +166 -44
- package/dist/checkpointer/internal/delta-history.d.ts +112 -0
- package/dist/checkpointer/internal/delta-history.js +252 -0
- package/dist/checkpointer/internal/listing.d.ts +149 -0
- package/dist/checkpointer/internal/listing.js +245 -0
- package/dist/checkpointer/internal/parse.d.ts +262 -0
- package/dist/checkpointer/internal/parse.js +372 -0
- package/dist/checkpointer/internal/pending-writes.d.ts +275 -0
- package/dist/checkpointer/internal/pending-writes.js +588 -0
- package/dist/checkpointer/internal/read.d.ts +130 -0
- package/dist/checkpointer/internal/read.js +264 -0
- package/dist/checkpointer/internal/rows.d.ts +571 -0
- package/dist/checkpointer/internal/rows.js +834 -0
- package/dist/checkpointer/internal/setup.d.ts +42 -21
- package/dist/checkpointer/internal/setup.js +65 -31
- package/dist/checkpointer/saver.d.ts +242 -42
- package/dist/checkpointer/saver.js +257 -53
- package/dist/checkpointer/types.d.ts +37 -44
- package/dist/checkpointer/types.js +10 -0
- package/dist/factory/factory.d.ts +120 -11
- package/dist/factory/factory.js +195 -16
- package/dist/factory/types.d.ts +23 -4
- package/dist/factory/types.js +8 -0
- package/dist/history/actions/add-messages.d.ts +30 -2
- package/dist/history/actions/add-messages.js +37 -57
- package/dist/history/actions/clear.d.ts +46 -4
- package/dist/history/actions/clear.js +64 -15
- package/dist/history/actions/get-messages.d.ts +41 -0
- package/dist/history/actions/get-messages.js +94 -32
- package/dist/history/actions/list-sessions.d.ts +52 -10
- package/dist/history/actions/list-sessions.js +141 -38
- package/dist/history/actions/reconcile-count.d.ts +41 -8
- package/dist/history/actions/reconcile-count.js +44 -57
- package/dist/history/chat-message-history.d.ts +200 -38
- package/dist/history/chat-message-history.js +218 -51
- package/dist/history/internal/append.d.ts +212 -0
- package/dist/history/internal/append.js +500 -0
- package/dist/history/internal/message-read.d.ts +84 -0
- package/dist/history/internal/message-read.js +204 -0
- package/dist/history/internal/parse.d.ts +153 -0
- package/dist/history/internal/parse.js +252 -0
- package/dist/history/internal/rows.d.ts +195 -0
- package/dist/history/internal/rows.js +250 -0
- package/dist/history/internal/session.d.ts +331 -0
- package/dist/history/internal/session.js +628 -0
- package/dist/history/internal/setup.d.ts +52 -19
- package/dist/history/internal/setup.js +90 -27
- package/dist/history/session-adapter.d.ts +95 -6
- package/dist/history/session-adapter.js +99 -8
- package/dist/history/types.d.ts +61 -31
- package/dist/history/types.js +10 -0
- package/dist/index.d.ts +38 -14
- package/dist/index.js +31 -12
- package/dist/shared/adapter.d.ts +135 -0
- package/dist/shared/adapter.js +143 -0
- package/dist/shared/clock.d.ts +48 -4
- package/dist/shared/clock.js +51 -4
- package/dist/shared/codec/codec.d.ts +275 -9
- package/dist/shared/codec/codec.js +394 -19
- package/dist/shared/codec/compression.d.ts +43 -6
- package/dist/shared/codec/compression.js +52 -11
- package/dist/shared/codec/json-serde.d.ts +76 -3
- package/dist/shared/codec/json-serde.js +181 -7
- package/dist/shared/codec/s3/client-types.d.ts +20 -1
- package/dist/shared/codec/s3/client-types.js +20 -1
- package/dist/shared/codec/s3/client.d.ts +35 -8
- package/dist/shared/codec/s3/client.js +61 -10
- package/dist/shared/codec/s3/config.d.ts +226 -22
- package/dist/shared/codec/s3/config.js +274 -24
- package/dist/shared/codec/s3/lifecycle.d.ts +163 -11
- package/dist/shared/codec/s3/lifecycle.js +328 -36
- package/dist/shared/codec/s3/offloader.d.ts +390 -19
- package/dist/shared/codec/s3/offloader.js +590 -50
- package/dist/shared/concurrency.d.ts +40 -3
- package/dist/shared/concurrency.js +55 -7
- package/dist/shared/dynamodb/abort.d.ts +45 -7
- package/dist/shared/dynamodb/abort.js +46 -14
- package/dist/shared/dynamodb/batch-write.d.ts +77 -13
- package/dist/shared/dynamodb/batch-write.js +146 -26
- package/dist/shared/dynamodb/cancellation.d.ts +121 -3
- package/dist/shared/dynamodb/cancellation.js +147 -2
- package/dist/shared/dynamodb/client.d.ts +159 -12
- package/dist/shared/dynamodb/client.js +135 -10
- package/dist/shared/dynamodb/idempotent-write.d.ts +551 -0
- package/dist/shared/dynamodb/idempotent-write.js +593 -0
- package/dist/shared/dynamodb/paginate.d.ts +105 -8
- package/dist/shared/dynamodb/paginate.js +175 -6
- package/dist/shared/dynamodb/partition-delete.d.ts +181 -16
- package/dist/shared/dynamodb/partition-delete.js +312 -43
- package/dist/shared/dynamodb/recency-index.d.ts +231 -0
- package/dist/shared/dynamodb/recency-index.js +377 -0
- package/dist/shared/dynamodb/retry.d.ts +265 -10
- package/dist/shared/dynamodb/retry.js +426 -20
- package/dist/shared/dynamodb/table-schema.d.ts +190 -0
- package/dist/shared/dynamodb/table-schema.js +209 -0
- package/dist/shared/errors/base-error.d.ts +174 -8
- package/dist/shared/errors/base-error.js +154 -7
- package/dist/shared/errors/boundary.d.ts +63 -10
- package/dist/shared/errors/boundary.js +110 -13
- package/dist/shared/errors/classify.d.ts +97 -0
- package/dist/shared/errors/classify.js +257 -0
- package/dist/shared/errors/error-code.d.ts +76 -1
- package/dist/shared/errors/error-code.js +83 -1
- package/dist/shared/errors/errors.d.ts +157 -58
- package/dist/shared/errors/errors.js +218 -93
- package/dist/shared/logging/logger.d.ts +63 -1
- package/dist/shared/logging/logger.js +97 -2
- package/dist/shared/logging/redaction.d.ts +86 -6
- package/dist/shared/logging/redaction.js +265 -24
- package/dist/shared/logging/secret-patterns.d.ts +136 -24
- package/dist/shared/logging/secret-patterns.js +165 -30
- package/dist/shared/logging/truncate.d.ts +197 -0
- package/dist/shared/logging/truncate.js +231 -0
- package/dist/shared/options.d.ts +52 -5
- package/dist/shared/options.js +9 -0
- package/dist/shared/ulid.d.ts +71 -14
- package/dist/shared/ulid.js +77 -14
- package/dist/shared/validation/collaborators.d.ts +141 -0
- package/dist/shared/validation/collaborators.js +188 -0
- package/dist/shared/validation/option-shape.d.ts +89 -0
- package/dist/shared/validation/option-shape.js +113 -0
- package/dist/shared/validation/options.d.ts +142 -5
- package/dist/shared/validation/options.js +284 -46
- package/dist/shared/validation/primitives.d.ts +287 -24
- package/dist/shared/validation/primitives.js +347 -42
- package/dist/shared/validation/ttl.d.ts +61 -12
- package/dist/shared/validation/ttl.js +102 -22
- package/dist/store/actions/list-namespaces.d.ts +76 -5
- package/dist/store/actions/list-namespaces.js +160 -22
- package/dist/store/actions/put.d.ts +33 -7
- package/dist/store/actions/put.js +53 -71
- package/dist/store/actions/reconcile-vector-index.d.ts +28 -8
- package/dist/store/actions/reconcile-vector-index.js +33 -13
- package/dist/store/actions/search.d.ts +34 -5
- package/dist/store/actions/search.js +52 -20
- package/dist/store/internal/batch-plan.d.ts +24 -9
- package/dist/store/internal/batch-plan.js +91 -34
- package/dist/store/internal/filter.d.ts +36 -2
- package/dist/store/internal/filter.js +66 -14
- package/dist/store/internal/get-item.d.ts +45 -0
- package/dist/store/internal/get-item.js +115 -0
- package/dist/store/internal/item-write.d.ts +230 -0
- package/dist/store/internal/item-write.js +463 -0
- package/dist/store/internal/parse.d.ts +225 -0
- package/dist/store/internal/parse.js +350 -0
- package/dist/store/internal/rows.d.ts +355 -0
- package/dist/store/internal/rows.js +447 -0
- package/dist/store/internal/semantic-search.d.ts +146 -12
- package/dist/store/internal/semantic-search.js +317 -15
- package/dist/store/internal/setup.d.ts +86 -21
- package/dist/store/internal/setup.js +209 -26
- package/dist/store/internal/table-search.d.ts +100 -0
- package/dist/store/internal/table-search.js +213 -0
- package/dist/store/internal/vector-index.d.ts +247 -0
- package/dist/store/internal/vector-index.js +546 -0
- package/dist/store/store.d.ts +258 -33
- package/dist/store/store.js +309 -53
- package/dist/store/types.d.ts +74 -28
- package/dist/store/types.js +13 -0
- package/dist/store/vector-backend.d.ts +64 -3
- package/dist/store/vector-backend.js +15 -0
- package/package.json +41 -25
- package/dist/checkpointer/internal/assemble.d.ts +0 -17
- package/dist/checkpointer/internal/assemble.js +0 -38
- package/dist/checkpointer/internal/checkpoint-write-verify.d.ts +0 -24
- package/dist/checkpointer/internal/checkpoint-write-verify.js +0 -67
- package/dist/checkpointer/internal/configurable.d.ts +0 -12
- package/dist/checkpointer/internal/configurable.js +0 -24
- package/dist/checkpointer/internal/fetch.d.ts +0 -19
- package/dist/checkpointer/internal/fetch.js +0 -88
- package/dist/checkpointer/internal/filter-match.d.ts +0 -13
- package/dist/checkpointer/internal/filter-match.js +0 -15
- package/dist/checkpointer/internal/item-reader.d.ts +0 -66
- package/dist/checkpointer/internal/item-reader.js +0 -113
- package/dist/checkpointer/internal/item-writer.d.ts +0 -35
- package/dist/checkpointer/internal/item-writer.js +0 -107
- package/dist/checkpointer/internal/keys.d.ts +0 -41
- package/dist/checkpointer/internal/keys.js +0 -117
- package/dist/checkpointer/internal/list-scope.d.ts +0 -61
- package/dist/checkpointer/internal/list-scope.js +0 -108
- package/dist/checkpointer/internal/pending-sends.d.ts +0 -13
- package/dist/checkpointer/internal/pending-sends.js +0 -29
- package/dist/checkpointer/internal/query.d.ts +0 -21
- package/dist/checkpointer/internal/query.js +0 -42
- package/dist/checkpointer/internal/regular-write.d.ts +0 -28
- package/dist/checkpointer/internal/regular-write.js +0 -66
- package/dist/checkpointer/internal/special-write-cas.d.ts +0 -29
- package/dist/checkpointer/internal/special-write-cas.js +0 -104
- package/dist/checkpointer/internal/special-write-cleanup.d.ts +0 -23
- package/dist/checkpointer/internal/special-write-cleanup.js +0 -50
- package/dist/checkpointer/internal/special-write-verify.d.ts +0 -53
- package/dist/checkpointer/internal/special-write-verify.js +0 -80
- package/dist/checkpointer/internal/stored-channels.d.ts +0 -31
- package/dist/checkpointer/internal/stored-channels.js +0 -70
- package/dist/checkpointer/internal/validation.d.ts +0 -18
- package/dist/checkpointer/internal/validation.js +0 -40
- package/dist/checkpointer/internal/write-guard.d.ts +0 -20
- package/dist/checkpointer/internal/write-guard.js +0 -48
- package/dist/checkpointer/internal/write-index.d.ts +0 -36
- package/dist/checkpointer/internal/write-index.js +0 -41
- package/dist/history/internal/append-saga.d.ts +0 -25
- package/dist/history/internal/append-saga.js +0 -79
- package/dist/history/internal/compensation.d.ts +0 -25
- package/dist/history/internal/compensation.js +0 -92
- package/dist/history/internal/item-mapper.d.ts +0 -9
- package/dist/history/internal/item-mapper.js +0 -27
- package/dist/history/internal/keys.d.ts +0 -16
- package/dist/history/internal/keys.js +0 -48
- package/dist/history/internal/message-chunker.d.ts +0 -13
- package/dist/history/internal/message-chunker.js +0 -67
- package/dist/history/internal/message-transaction.d.ts +0 -25
- package/dist/history/internal/message-transaction.js +0 -61
- package/dist/history/internal/message-window.d.ts +0 -17
- package/dist/history/internal/message-window.js +0 -49
- package/dist/history/internal/query.d.ts +0 -23
- package/dist/history/internal/query.js +0 -39
- package/dist/history/internal/session-count.d.ts +0 -47
- package/dist/history/internal/session-count.js +0 -115
- package/dist/history/internal/session-title.d.ts +0 -19
- package/dist/history/internal/session-title.js +0 -43
- package/dist/history/internal/session-update.d.ts +0 -27
- package/dist/history/internal/session-update.js +0 -69
- package/dist/history/internal/title-generator.d.ts +0 -12
- package/dist/history/internal/title-generator.js +0 -41
- package/dist/history/internal/ttl-anchor.d.ts +0 -24
- package/dist/history/internal/ttl-anchor.js +0 -38
- package/dist/history/internal/validation.d.ts +0 -25
- package/dist/history/internal/validation.js +0 -53
- package/dist/shared/codec/descriptor-keys.d.ts +0 -12
- package/dist/shared/codec/descriptor-keys.js +0 -14
- package/dist/shared/codec/encode.d.ts +0 -13
- package/dist/shared/codec/encode.js +0 -43
- package/dist/shared/codec/payload-loss.d.ts +0 -12
- package/dist/shared/codec/payload-loss.js +0 -38
- package/dist/shared/codec/s3/adapter-config.d.ts +0 -13
- package/dist/shared/codec/s3/adapter-config.js +0 -22
- package/dist/shared/codec/s3/bounded-body.d.ts +0 -14
- package/dist/shared/codec/s3/bounded-body.js +0 -47
- package/dist/shared/codec/s3/delete.d.ts +0 -7
- package/dist/shared/codec/s3/delete.js +0 -28
- package/dist/shared/codec/s3/key-scope.d.ts +0 -23
- package/dist/shared/codec/s3/key-scope.js +0 -44
- package/dist/shared/codec/s3/orphans.d.ts +0 -23
- package/dist/shared/codec/s3/orphans.js +0 -71
- package/dist/shared/codec/s3/read-write.d.ts +0 -18
- package/dist/shared/codec/s3/read-write.js +0 -51
- package/dist/shared/codec/s3/retry.d.ts +0 -5
- package/dist/shared/codec/s3/retry.js +0 -22
- package/dist/shared/constants.d.ts +0 -112
- package/dist/shared/constants.js +0 -115
- package/dist/shared/dynamodb/backoff.d.ts +0 -15
- package/dist/shared/dynamodb/backoff.js +0 -48
- package/dist/shared/dynamodb/conditional-put.d.ts +0 -67
- package/dist/shared/dynamodb/conditional-put.js +0 -76
- package/dist/shared/dynamodb/drain-unprocessed.d.ts +0 -21
- package/dist/shared/dynamodb/drain-unprocessed.js +0 -43
- package/dist/shared/dynamodb/expiry.d.ts +0 -16
- package/dist/shared/dynamodb/expiry.js +0 -29
- package/dist/shared/dynamodb/paginate-core.d.ts +0 -24
- package/dist/shared/dynamodb/paginate-core.js +0 -82
- package/dist/shared/dynamodb/retry-classifier.d.ts +0 -17
- package/dist/shared/dynamodb/retry-classifier.js +0 -118
- package/dist/shared/dynamodb/retry-policy.d.ts +0 -26
- package/dist/shared/dynamodb/retry-policy.js +0 -22
- package/dist/shared/dynamodb/scan.d.ts +0 -14
- package/dist/shared/dynamodb/scan.js +0 -19
- package/dist/shared/dynamodb/types.d.ts +0 -23
- package/dist/shared/dynamodb/types.js +0 -2
- package/dist/shared/errors/upstream-error.d.ts +0 -16
- package/dist/shared/errors/upstream-error.js +0 -27
- package/dist/shared/errors/wrap-error.d.ts +0 -7
- package/dist/shared/errors/wrap-error.js +0 -15
- package/dist/shared/logging/redaction-walk.d.ts +0 -23
- package/dist/shared/logging/redaction-walk.js +0 -112
- package/dist/store/actions/get.d.ts +0 -13
- package/dist/store/actions/get.js +0 -73
- package/dist/store/internal/backend-search.d.ts +0 -4
- package/dist/store/internal/backend-search.js +0 -74
- package/dist/store/internal/candidates.d.ts +0 -23
- package/dist/store/internal/candidates.js +0 -94
- package/dist/store/internal/index-reconcile.d.ts +0 -21
- package/dist/store/internal/index-reconcile.js +0 -118
- package/dist/store/internal/index-sync.d.ts +0 -10
- package/dist/store/internal/index-sync.js +0 -25
- package/dist/store/internal/item-mapper.d.ts +0 -27
- package/dist/store/internal/item-mapper.js +0 -61
- package/dist/store/internal/keys.d.ts +0 -17
- package/dist/store/internal/keys.js +0 -41
- package/dist/store/internal/namespace-match.d.ts +0 -11
- package/dist/store/internal/namespace-match.js +0 -40
- package/dist/store/internal/option-validation.d.ts +0 -13
- package/dist/store/internal/option-validation.js +0 -77
- package/dist/store/internal/overwrite-swap.d.ts +0 -32
- package/dist/store/internal/overwrite-swap.js +0 -68
- package/dist/store/internal/persist.d.ts +0 -28
- package/dist/store/internal/persist.js +0 -64
- package/dist/store/internal/query.d.ts +0 -11
- package/dist/store/internal/query.js +0 -48
- package/dist/store/internal/ranker.d.ts +0 -18
- package/dist/store/internal/ranker.js +0 -39
- package/dist/store/internal/read-existing.d.ts +0 -23
- package/dist/store/internal/read-existing.js +0 -41
- package/dist/store/internal/score-direction.d.ts +0 -31
- package/dist/store/internal/score-direction.js +0 -38
- package/dist/store/internal/search-filter.d.ts +0 -3
- package/dist/store/internal/search-filter.js +0 -10
- package/dist/store/internal/text-path.d.ts +0 -17
- package/dist/store/internal/text-path.js +0 -147
- package/dist/store/internal/validation.d.ts +0 -18
- package/dist/store/internal/validation.js +0 -51
- package/dist/store/internal/write-verify.d.ts +0 -42
- package/dist/store/internal/write-verify.js +0 -71
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hides how an append of any size commits all-or-nothing, as its caller sees it.
|
|
3
|
+
*
|
|
4
|
+
* One `TransactWriteItems` carries at most a hundred items and four megabytes,
|
|
5
|
+
* so a large append is several transactions, each writing its messages and the
|
|
6
|
+
* SESSION row's update together. When one of them fails the append is rolled
|
|
7
|
+
* back: committed chunks are deleted and their effect on the SESSION row
|
|
8
|
+
* reverted, and each S3 object is released only once no row can name it. An
|
|
9
|
+
* ambiguous failure is read back before anything is undone. This is also the
|
|
10
|
+
* one module that writes a message row, which is what lets a delete pin a
|
|
11
|
+
* message row to the SESSION row's `writeId`.
|
|
12
|
+
*/
|
|
13
|
+
import { type RowKey } from '../../shared/dynamodb/table-schema';
|
|
14
|
+
import type { SessionId, StorableMessages } from './parse';
|
|
15
|
+
import { type MessageRow } from './rows';
|
|
16
|
+
import { type SessionUpdateFields, type TtlAnchorResult } from './session';
|
|
17
|
+
import { type HistoryContext } from './setup';
|
|
18
|
+
/** One append, parsed: the session, its messages in stored form, and the session's ttl anchor. */
|
|
19
|
+
export interface AppendRequest {
|
|
20
|
+
readonly sessionId: SessionId;
|
|
21
|
+
readonly messages: StorableMessages;
|
|
22
|
+
/** The session's creation-anchored ttl, when the adapter has a ttl. */
|
|
23
|
+
readonly anchor: TtlAnchorResult | undefined;
|
|
24
|
+
readonly signal?: AbortSignal;
|
|
25
|
+
}
|
|
26
|
+
/** Shared per-append metadata applied to every chunk's session update. */
|
|
27
|
+
interface AppendFields {
|
|
28
|
+
now: string;
|
|
29
|
+
title?: string;
|
|
30
|
+
ttlTimestamp?: number;
|
|
31
|
+
forceTtlRefresh?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** An append cut into chunks, with the fields every chunk's SESSION update stamps. */
|
|
34
|
+
export interface ChunkedAppend {
|
|
35
|
+
readonly sessionId: SessionId;
|
|
36
|
+
readonly chunks: MessageRow[][];
|
|
37
|
+
readonly fields: AppendFields;
|
|
38
|
+
readonly signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
/** A chunk that committed, retained so it can be rolled back on a later failure. */
|
|
41
|
+
interface CommittedChunk {
|
|
42
|
+
keys: RowKey[];
|
|
43
|
+
count: number;
|
|
44
|
+
}
|
|
45
|
+
/** How far a failed append got, which decides what its rollback undoes. */
|
|
46
|
+
export interface FailedAppend {
|
|
47
|
+
readonly committed: CommittedChunk[];
|
|
48
|
+
readonly trigger: Error;
|
|
49
|
+
/** True when the failing chunk's own outcome could not be read back. */
|
|
50
|
+
readonly uncertain: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Append messages to a session: encode them, cut them into transactions, and
|
|
54
|
+
* commit them all or undo what committed.
|
|
55
|
+
*
|
|
56
|
+
* Accepts: `request` — the parsed session and messages, the ttl anchor, and
|
|
57
|
+
* the caller's signal.
|
|
58
|
+
*
|
|
59
|
+
* Returns: nothing, once every chunk has committed.
|
|
60
|
+
*
|
|
61
|
+
* Throws: the first chunk's failure after the append is rolled back;
|
|
62
|
+
* `COMPENSATION_FAILED` when the rollback itself fails; whatever encoding a
|
|
63
|
+
* message throws, after this call's own uploads are released.
|
|
64
|
+
*/
|
|
65
|
+
export declare function appendMessages(context: HistoryContext, request: AppendRequest): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Undo a failed batch. Always throws. S3 cleanup is split by commit status so
|
|
68
|
+
* no live row is ever left pointing at a deleted object: the never-committed
|
|
69
|
+
* suffix is cleaned immediately, the committed prefix only after its rows are
|
|
70
|
+
* confirmed deleted. If the rollback itself fails, the committed chunks' S3
|
|
71
|
+
* objects are deliberately left in place (their rows may survive) and it
|
|
72
|
+
* raises `COMPENSATION_FAILED` carrying both the trigger and the
|
|
73
|
+
* rollback error; otherwise it rethrows the trigger.
|
|
74
|
+
*
|
|
75
|
+
* `failure.uncertain` marks the failed chunk
|
|
76
|
+
* (`append.chunks[failure.committed.length]`) as one whose outcome could not be
|
|
77
|
+
* verified: its rows may be live, so its objects are leaked rather than
|
|
78
|
+
* deleted, while the never-attempted chunks after it are still cleaned.
|
|
79
|
+
*
|
|
80
|
+
* Accepts: `append` — the append that failed: its `sessionId`, its `chunks` in
|
|
81
|
+
* order, and the `fields.now` and `fields.title` its first chunk stamped on
|
|
82
|
+
* the session row. `failure.committed` — the chunks known to have landed, in
|
|
83
|
+
* order; empty means the very first chunk failed, and then the only thing to
|
|
84
|
+
* undo is the session row this call may have created. `failure.trigger` — the
|
|
85
|
+
* failure that started this. `failure.uncertain` — see above.
|
|
86
|
+
*
|
|
87
|
+
* Returns: never; the declared `Promise<never>` is the contract.
|
|
88
|
+
*
|
|
89
|
+
* Throws: `failure.trigger` when the rollback succeeded, `COMPENSATION_FAILED`
|
|
90
|
+
* when it did not.
|
|
91
|
+
*
|
|
92
|
+
* Guarantees: an object is deleted only once no row can reference it — the
|
|
93
|
+
* never-committed suffix immediately, the committed prefix only after its rows
|
|
94
|
+
* are confirmed gone, and an unverified chunk never. Storage is leaked in
|
|
95
|
+
* preference to leaving a live row pointing at a deleted object.
|
|
96
|
+
*
|
|
97
|
+
* Neither of its two log lines can stop it: both go through
|
|
98
|
+
* {@link reportStep}. Otherwise a throw from the first would skip the S3
|
|
99
|
+
* cleanup, the rollback, the count revert and the rethrow all at once, leaving
|
|
100
|
+
* every committed chunk in the table with `messageCount` still counting it,
|
|
101
|
+
* and handing the caller the logger's own error in place of the failure that
|
|
102
|
+
* started this. Announcing the rollback is not the rollback.
|
|
103
|
+
*/
|
|
104
|
+
export declare function compensate(context: HistoryContext, append: ChunkedAppend, failure: FailedAppend): Promise<never>;
|
|
105
|
+
/**
|
|
106
|
+
* Append message chunks with caller-observed atomicity. Each chunk commits its
|
|
107
|
+
* messages and count in one transaction; if a later chunk fails, every
|
|
108
|
+
* already-committed chunk is deleted and its count reverted, and the batch's
|
|
109
|
+
* S3 objects are cleaned once their rows are gone, restoring the pre-call
|
|
110
|
+
* state before the error is rethrown. Except on a failed rollback, which
|
|
111
|
+
* surfaces as `COMPENSATION_FAILED` and deliberately leaves the
|
|
112
|
+
* committed chunks' S3 objects behind, since their rows may survive.
|
|
113
|
+
*
|
|
114
|
+
* A `RETRY_EXHAUSTED` error is ambiguous — the transaction may have committed
|
|
115
|
+
* and lost its response — so the chunk is read back first: present means it
|
|
116
|
+
* committed (continue), absent means it did not (compensate), and a failed
|
|
117
|
+
* read compensates but leaks that chunk's objects rather than delete objects
|
|
118
|
+
* its possibly-live rows reference.
|
|
119
|
+
*
|
|
120
|
+
* Accepts: `append.sessionId` — the session every chunk writes to.
|
|
121
|
+
* `append.chunks` — in order, each already within the transaction's limits;
|
|
122
|
+
* no chunks is no work and no write. `append.fields` — the session update every
|
|
123
|
+
* chunk carries. `append.signal` — aborts between chunks.
|
|
124
|
+
*
|
|
125
|
+
* Returns: nothing, and only when every chunk is known to have committed.
|
|
126
|
+
*
|
|
127
|
+
* Throws: the first chunk's failure, after the rollback has restored the
|
|
128
|
+
* pre-call state; or `COMPENSATION_FAILED` carrying both that failure
|
|
129
|
+
* and the rollback's own, when the rollback could not finish.
|
|
130
|
+
*
|
|
131
|
+
* Guarantees: each message's S3 key carries its own ULID, so no two rows of any
|
|
132
|
+
* call can address the same object and the rollback's cleanup can never delete
|
|
133
|
+
* an object a surviving row still points at. What a caller observes is
|
|
134
|
+
* all-or-nothing; what the table holds is all-or-nothing only until a rollback
|
|
135
|
+
* fails, which is why that case is a distinct error and not a rethrow.
|
|
136
|
+
*/
|
|
137
|
+
export declare function appendChunks(context: HistoryContext, append: ChunkedAppend): Promise<void>;
|
|
138
|
+
/** Per-call retry seams (injected in tests to keep backoff instant). */
|
|
139
|
+
export interface ChunkRetryOptions {
|
|
140
|
+
rng?: () => number;
|
|
141
|
+
signal?: AbortSignal;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Atomically write a chunk of message items together with the session-metadata
|
|
145
|
+
* count update in one {@link https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html | TransactWriteItems}
|
|
146
|
+
* call, so `messageCount` can never disagree with the messages that landed. A
|
|
147
|
+
* single `ClientRequestToken` is used per attempt so a re-sent commit (e.g.
|
|
148
|
+
* after a lost response) is idempotent and never double-applies the count
|
|
149
|
+
* `ADD`. When `fields.forceTtlRefresh` is set, the session update carries a
|
|
150
|
+
* monotonic ConditionExpression (see session.ts); if — and only if —
|
|
151
|
+
* that specific condition loses a race against a concurrent caller who just
|
|
152
|
+
* healed the same anchor, this retries the identical chunk once with
|
|
153
|
+
* `forceTtlRefresh: false` (safe: `if_not_exists` then converges to whatever
|
|
154
|
+
* already won) rather than losing the message writes to a benign ttl race. A
|
|
155
|
+
* cancellation caused by any other item (a genuine message-row conflict) is
|
|
156
|
+
* not retried here — it propagates for the normal transient-conflict retry
|
|
157
|
+
* budget inside `withDynamoDBRetry` to handle, or to the caller otherwise.
|
|
158
|
+
*
|
|
159
|
+
* Accepts: `items` — one chunk, already within the transaction's limits.
|
|
160
|
+
* `fields` — the session-metadata update accompanying it; its `indexShards` and
|
|
161
|
+
* its `writeId` are taken from the adapter's context, never from the caller.
|
|
162
|
+
* `retry.signal` — aborts between attempts.
|
|
163
|
+
*
|
|
164
|
+
* Returns: nothing. The chunk and the count are committed together or not at
|
|
165
|
+
* all.
|
|
166
|
+
*
|
|
167
|
+
* Throws: whatever the transaction throws — including a
|
|
168
|
+
* `TransactionCanceledException` for a genuine conflict, after the retry budget
|
|
169
|
+
* is spent. The caller compensates; this function never partially succeeds.
|
|
170
|
+
*
|
|
171
|
+
* Guarantees: `messageCount` can never disagree with the messages that landed,
|
|
172
|
+
* because they land in one transaction. At most one extra attempt is spent on
|
|
173
|
+
* the benign ttl race, and it carries its own request token, so a retry can
|
|
174
|
+
* never double-apply the count — and its own deadline of
|
|
175
|
+
* `MAX_WRITE_LIFETIME_MS`, so the retrying stops while that token is
|
|
176
|
+
* still deduplicating rather than after it has expired. The SESSION row's
|
|
177
|
+
* `writeId` moves if and only if a message row was added: the update travels in
|
|
178
|
+
* the same transaction as the rows, and nothing else writes it.
|
|
179
|
+
*/
|
|
180
|
+
export declare function writeMessageChunk(context: HistoryContext, items: MessageRow[], fields: Omit<SessionUpdateFields, 'writeId'>, retry?: ChunkRetryOptions): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Conservatively estimate a message row's stored size.
|
|
183
|
+
*
|
|
184
|
+
* Accepts: any message row, inline or offloaded — an offloaded one measures
|
|
185
|
+
* its S3 key, since that is what the row actually carries.
|
|
186
|
+
*
|
|
187
|
+
* Returns: an estimate at or above the real marshalled size. Erring high is the
|
|
188
|
+
* whole point: an underestimate builds a transaction DynamoDB refuses, and the
|
|
189
|
+
* cost of erring high is one extra transaction.
|
|
190
|
+
*
|
|
191
|
+
* Throws: nothing.
|
|
192
|
+
*/
|
|
193
|
+
export declare function estimateRowBytes(item: MessageRow): number;
|
|
194
|
+
/**
|
|
195
|
+
* Split message items into transaction-sized chunks.
|
|
196
|
+
*
|
|
197
|
+
* Accepts: `items` — in order; empty yields no chunks, so an append of nothing
|
|
198
|
+
* issues no write. `maxItems` and `maxBytes` — the transaction's two limits,
|
|
199
|
+
* both binding.
|
|
200
|
+
*
|
|
201
|
+
* Returns: the chunks, in order, each within both limits — except that a single
|
|
202
|
+
* item larger than `maxBytes` is placed alone rather than dropped: refusing it
|
|
203
|
+
* here would lose a message that DynamoDB might still accept, and if it does
|
|
204
|
+
* not, the transaction says so.
|
|
205
|
+
*
|
|
206
|
+
* Throws: nothing.
|
|
207
|
+
*
|
|
208
|
+
* Guarantees: order is preserved across chunks, so messages keep the order the
|
|
209
|
+
* caller wrote them in, which is the order their ULIDs already encode.
|
|
210
|
+
*/
|
|
211
|
+
export declare function chunkBySize(items: MessageRow[], maxItems: number, maxBytes: number): MessageRow[][];
|
|
212
|
+
export {};
|