@farukada/aws-langgraph-dynamodb-ts 0.6.0 → 0.8.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 +63 -9
- package/dist/checkpointer/actions/delete-thread.d.ts +3 -4
- package/dist/checkpointer/actions/delete-thread.d.ts.map +1 -1
- package/dist/checkpointer/actions/delete-thread.js +21 -41
- package/dist/checkpointer/actions/delete-thread.js.map +1 -1
- package/dist/checkpointer/actions/list.d.ts.map +1 -1
- package/dist/checkpointer/actions/list.js +31 -4
- package/dist/checkpointer/actions/list.js.map +1 -1
- package/dist/checkpointer/actions/put-writes.d.ts.map +1 -1
- package/dist/checkpointer/actions/put-writes.js +14 -24
- package/dist/checkpointer/actions/put-writes.js.map +1 -1
- package/dist/checkpointer/actions/put.d.ts.map +1 -1
- package/dist/checkpointer/actions/put.js +2 -0
- package/dist/checkpointer/actions/put.js.map +1 -1
- package/dist/checkpointer/internal/item-reader.d.ts +31 -0
- package/dist/checkpointer/internal/item-reader.d.ts.map +1 -1
- package/dist/checkpointer/internal/item-reader.js +49 -1
- package/dist/checkpointer/internal/item-reader.js.map +1 -1
- package/dist/checkpointer/internal/item-writer.d.ts +0 -8
- package/dist/checkpointer/internal/item-writer.d.ts.map +1 -1
- package/dist/checkpointer/internal/item-writer.js +15 -21
- package/dist/checkpointer/internal/item-writer.js.map +1 -1
- package/dist/checkpointer/internal/keys.d.ts +19 -3
- package/dist/checkpointer/internal/keys.d.ts.map +1 -1
- package/dist/checkpointer/internal/keys.js +41 -6
- package/dist/checkpointer/internal/keys.js.map +1 -1
- package/dist/checkpointer/internal/special-write-cleanup.d.ts.map +1 -1
- package/dist/checkpointer/internal/special-write-cleanup.js +6 -12
- package/dist/checkpointer/internal/special-write-cleanup.js.map +1 -1
- package/dist/checkpointer/internal/validation.d.ts +8 -4
- package/dist/checkpointer/internal/validation.d.ts.map +1 -1
- package/dist/checkpointer/internal/validation.js +12 -10
- package/dist/checkpointer/internal/validation.js.map +1 -1
- package/dist/checkpointer/internal/write-guard.d.ts +21 -0
- package/dist/checkpointer/internal/write-guard.d.ts.map +1 -0
- package/dist/checkpointer/internal/write-guard.js +48 -0
- package/dist/checkpointer/internal/write-guard.js.map +1 -0
- package/dist/checkpointer/internal/write-index.d.ts +29 -0
- package/dist/checkpointer/internal/write-index.d.ts.map +1 -0
- package/dist/checkpointer/internal/write-index.js +38 -0
- package/dist/checkpointer/internal/write-index.js.map +1 -0
- package/dist/checkpointer/types.d.ts +2 -0
- package/dist/checkpointer/types.d.ts.map +1 -1
- package/dist/history/actions/add-messages.d.ts.map +1 -1
- package/dist/history/actions/add-messages.js +24 -4
- package/dist/history/actions/add-messages.js.map +1 -1
- package/dist/history/actions/clear.d.ts +4 -6
- package/dist/history/actions/clear.d.ts.map +1 -1
- package/dist/history/actions/clear.js +18 -33
- package/dist/history/actions/clear.js.map +1 -1
- package/dist/history/actions/get-messages.d.ts +2 -1
- package/dist/history/actions/get-messages.d.ts.map +1 -1
- package/dist/history/actions/get-messages.js +28 -2
- package/dist/history/actions/get-messages.js.map +1 -1
- package/dist/history/actions/list-sessions.d.ts +2 -1
- package/dist/history/actions/list-sessions.d.ts.map +1 -1
- package/dist/history/actions/list-sessions.js +21 -2
- package/dist/history/actions/list-sessions.js.map +1 -1
- package/dist/history/actions/reconcile-count.d.ts.map +1 -1
- package/dist/history/actions/reconcile-count.js +2 -2
- package/dist/history/actions/reconcile-count.js.map +1 -1
- package/dist/history/internal/append-saga.d.ts.map +1 -1
- package/dist/history/internal/append-saga.js +2 -78
- package/dist/history/internal/append-saga.js.map +1 -1
- package/dist/history/internal/compensation.d.ts +21 -0
- package/dist/history/internal/compensation.d.ts.map +1 -0
- package/dist/history/internal/compensation.js +84 -0
- package/dist/history/internal/compensation.js.map +1 -0
- package/dist/history/internal/keys.d.ts +10 -2
- package/dist/history/internal/keys.d.ts.map +1 -1
- package/dist/history/internal/keys.js +32 -5
- package/dist/history/internal/keys.js.map +1 -1
- package/dist/history/internal/message-chunker.d.ts.map +1 -1
- package/dist/history/internal/message-chunker.js +13 -5
- package/dist/history/internal/message-chunker.js.map +1 -1
- package/dist/history/internal/session-count.d.ts +21 -0
- package/dist/history/internal/session-count.d.ts.map +1 -1
- package/dist/history/internal/session-count.js +51 -0
- package/dist/history/internal/session-count.js.map +1 -1
- package/dist/history/internal/session-title.d.ts +20 -0
- package/dist/history/internal/session-title.d.ts.map +1 -0
- package/dist/history/internal/session-title.js +44 -0
- package/dist/history/internal/session-title.js.map +1 -0
- package/dist/history/internal/setup.d.ts +2 -1
- package/dist/history/internal/setup.d.ts.map +1 -1
- package/dist/history/internal/setup.js +1 -0
- package/dist/history/internal/setup.js.map +1 -1
- package/dist/history/internal/title-generator.d.ts +8 -2
- package/dist/history/internal/title-generator.d.ts.map +1 -1
- package/dist/history/internal/title-generator.js +12 -3
- package/dist/history/internal/title-generator.js.map +1 -1
- package/dist/history/internal/validation.d.ts +9 -0
- package/dist/history/internal/validation.d.ts.map +1 -0
- package/dist/history/internal/validation.js +16 -0
- package/dist/history/internal/validation.js.map +1 -0
- package/dist/history/types.d.ts +12 -0
- package/dist/history/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/shared/codec/s3/offloader.d.ts +7 -1
- package/dist/shared/codec/s3/offloader.d.ts.map +1 -1
- package/dist/shared/codec/s3/offloader.js +14 -1
- package/dist/shared/codec/s3/offloader.js.map +1 -1
- package/dist/shared/dynamodb/batch-write.d.ts.map +1 -1
- package/dist/shared/dynamodb/batch-write.js +8 -6
- package/dist/shared/dynamodb/batch-write.js.map +1 -1
- package/dist/shared/dynamodb/drain-unprocessed.d.ts +5 -1
- package/dist/shared/dynamodb/drain-unprocessed.d.ts.map +1 -1
- package/dist/shared/dynamodb/drain-unprocessed.js +20 -11
- package/dist/shared/dynamodb/drain-unprocessed.js.map +1 -1
- package/dist/shared/dynamodb/partition-delete.d.ts +33 -0
- package/dist/shared/dynamodb/partition-delete.d.ts.map +1 -0
- package/dist/shared/dynamodb/partition-delete.js +70 -0
- package/dist/shared/dynamodb/partition-delete.js.map +1 -0
- package/dist/shared/dynamodb/retry-classifier.d.ts.map +1 -1
- package/dist/shared/dynamodb/retry-classifier.js +9 -1
- package/dist/shared/dynamodb/retry-classifier.js.map +1 -1
- package/dist/shared/errors/errors.d.ts +5 -2
- package/dist/shared/errors/errors.d.ts.map +1 -1
- package/dist/shared/errors/errors.js +6 -3
- package/dist/shared/errors/errors.js.map +1 -1
- package/dist/shared/logging/redaction-walk.d.ts +23 -0
- package/dist/shared/logging/redaction-walk.d.ts.map +1 -0
- package/dist/shared/logging/redaction-walk.js +92 -0
- package/dist/shared/logging/redaction-walk.js.map +1 -0
- package/dist/shared/logging/redaction.d.ts +22 -10
- package/dist/shared/logging/redaction.d.ts.map +1 -1
- package/dist/shared/logging/redaction.js +24 -36
- package/dist/shared/logging/redaction.js.map +1 -1
- package/dist/shared/logging/secret-patterns.d.ts +41 -0
- package/dist/shared/logging/secret-patterns.d.ts.map +1 -0
- package/dist/shared/logging/secret-patterns.js +74 -0
- package/dist/shared/logging/secret-patterns.js.map +1 -0
- package/dist/shared/validation/primitives.d.ts +9 -1
- package/dist/shared/validation/primitives.d.ts.map +1 -1
- package/dist/shared/validation/primitives.js +13 -0
- package/dist/shared/validation/primitives.js.map +1 -1
- package/dist/store/actions/get.d.ts.map +1 -1
- package/dist/store/actions/get.js +15 -1
- package/dist/store/actions/get.js.map +1 -1
- package/dist/store/actions/list-namespaces.d.ts.map +1 -1
- package/dist/store/actions/list-namespaces.js +1 -0
- package/dist/store/actions/list-namespaces.js.map +1 -1
- package/dist/store/actions/put.d.ts.map +1 -1
- package/dist/store/actions/put.js +20 -2
- package/dist/store/actions/put.js.map +1 -1
- package/dist/store/actions/search.d.ts.map +1 -1
- package/dist/store/actions/search.js +4 -35
- package/dist/store/actions/search.js.map +1 -1
- package/dist/store/internal/backend-search.d.ts +5 -0
- package/dist/store/internal/backend-search.d.ts.map +1 -0
- package/dist/store/internal/backend-search.js +67 -0
- package/dist/store/internal/backend-search.js.map +1 -0
- package/dist/store/internal/filter.d.ts.map +1 -1
- package/dist/store/internal/filter.js +26 -5
- package/dist/store/internal/filter.js.map +1 -1
- package/dist/store/internal/index-reconcile.d.ts.map +1 -1
- package/dist/store/internal/index-reconcile.js +33 -3
- package/dist/store/internal/index-reconcile.js.map +1 -1
- package/dist/store/internal/keys.d.ts +1 -1
- package/dist/store/internal/keys.d.ts.map +1 -1
- package/dist/store/internal/keys.js +8 -2
- package/dist/store/internal/keys.js.map +1 -1
- package/dist/store/internal/persist.d.ts.map +1 -1
- package/dist/store/internal/persist.js +1 -5
- package/dist/store/internal/persist.js.map +1 -1
- package/dist/store/internal/search-filter.d.ts +4 -0
- package/dist/store/internal/search-filter.d.ts.map +1 -0
- package/dist/store/internal/search-filter.js +11 -0
- package/dist/store/internal/search-filter.js.map +1 -0
- package/dist/store/internal/setup.d.ts +11 -1
- package/dist/store/internal/setup.d.ts.map +1 -1
- package/dist/store/internal/setup.js +17 -1
- package/dist/store/internal/setup.js.map +1 -1
- package/dist/store/internal/validation.d.ts +8 -2
- package/dist/store/internal/validation.d.ts.map +1 -1
- package/dist/store/internal/validation.js +15 -6
- package/dist/store/internal/validation.js.map +1 -1
- package/dist/store/internal/write-verify.d.ts +12 -0
- package/dist/store/internal/write-verify.d.ts.map +1 -1
- package/dist/store/internal/write-verify.js +27 -0
- package/dist/store/internal/write-verify.js.map +1 -1
- package/dist/store/vector-backend.d.ts +17 -0
- package/dist/store/vector-backend.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -8,7 +8,11 @@ const retry_1 = require("./retry");
|
|
|
8
8
|
/**
|
|
9
9
|
* Submit `requests` via BatchWriteItem and re-submit UnprocessedItems with
|
|
10
10
|
* full-jitter backoff until the batch drains. Throws
|
|
11
|
-
* {@link BatchWriteIncompleteError} if it cannot drain within the retry budget
|
|
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`.
|
|
12
16
|
*/
|
|
13
17
|
async function drainUnprocessedWrites(client, tableName, requests, options = {}) {
|
|
14
18
|
if (requests.length === 0)
|
|
@@ -19,17 +23,22 @@ async function drainUnprocessedWrites(client, tableName, requests, options = {})
|
|
|
19
23
|
let delay = constants_1.INITIAL_BACKOFF_DELAY_MS;
|
|
20
24
|
let retries = 0;
|
|
21
25
|
while (pending.length > 0) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
try {
|
|
27
|
+
const result = await (0, retry_1.withDynamoDBRetry)(() => client.batchWrite({ RequestItems: { [tableName]: pending } }), { 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);
|
|
29
40
|
}
|
|
30
|
-
await (0, backoff_1.sleep)((0, backoff_1.fullJitter)(delay, options.rng), options.signal);
|
|
31
|
-
delay = (0, backoff_1.nextBackoffDelay)(delay);
|
|
32
|
-
pending = leftover;
|
|
33
41
|
}
|
|
42
|
+
throw new errors_1.BatchWriteIncompleteError(initialCount - pending.length, pending, maxRetries);
|
|
34
43
|
}
|
|
35
44
|
//# sourceMappingURL=drain-unprocessed.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drain-unprocessed.js","sourceRoot":"","sources":["../../../src/shared/dynamodb/drain-unprocessed.ts"],"names":[],"mappings":";;;AAEA,4CAAiF;AACjF,6CAA6D;AAC7D,uCAAgE;AAChE,mCAA4C;AAU5C
|
|
1
|
+
{"version":3,"file":"drain-unprocessed.js","sourceRoot":"","sources":["../../../src/shared/dynamodb/drain-unprocessed.ts"],"names":[],"mappings":";;;AAEA,4CAAiF;AACjF,6CAA6D;AAC7D,uCAAgE;AAChE,mCAA4C;AAU5C;;;;;;;;GAQG;AACI,KAAK,iCACV,MAAwB,EACxB,SAAiB,EACjB,QAAwB,EACxB,OAAO,GAAiB,EAAE;IAE1B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAClC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mCAAuB,CAAC;IACjE,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC;IACrC,IAAI,OAAO,GAAG,QAAQ,CAAC;IACvB,IAAI,KAAK,GAAG,oCAAwB,CAAC;IACrC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAA,yBAAiB,EACpC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,YAAY,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,EACnE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAC3B,CAAC;YACF,MAAM,QAAQ,GAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC,SAAS,CAAgC,IAAI,EAAE,CAAC;YAC5F,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO;YAClC,OAAO,GAAG,QAAQ,CAAC;YACnB,OAAO,IAAI,CAAC,CAAC;YACb,IAAI,OAAO,GAAG,UAAU;gBAAE,MAAM;YAChC,MAAM,IAAA,eAAK,EAAC,IAAA,oBAAU,EAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YAC5D,KAAK,GAAG,IAAA,0BAAgB,EAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,kCAAyB,CACjC,YAAY,GAAG,OAAO,CAAC,MAAM,EAC7B,OAAO,EACP,OAAO,EACP,KAAc,CACf,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,IAAI,kCAAyB,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DynamoDBDocument, QueryCommandInput } from '@aws-sdk/lib-dynamodb';
|
|
2
|
+
import type { PayloadDescriptor } from '../codec/codec';
|
|
3
|
+
import type { S3Offloader } from '../codec/s3/offloader';
|
|
4
|
+
import type { Logger } from '../logging/logger';
|
|
5
|
+
import type { DocItem } from './types';
|
|
6
|
+
/** Collaborators and per-adapter policy for one partition-wide delete. */
|
|
7
|
+
export interface PartitionDeleteOptions {
|
|
8
|
+
client: DynamoDBDocument;
|
|
9
|
+
tableName: string;
|
|
10
|
+
params: QueryCommandInput;
|
|
11
|
+
logger: Logger;
|
|
12
|
+
offloader?: S3Offloader;
|
|
13
|
+
/** Label for log lines and S3-cleanup diagnostics, e.g. `deleteThread`. */
|
|
14
|
+
operation: string;
|
|
15
|
+
/**
|
|
16
|
+
* True when a sort key belongs to the calling adapter. A partition query
|
|
17
|
+
* carries no sort-key condition, so without this a shared-table partition
|
|
18
|
+
* holding a foreign row would have that row deleted too.
|
|
19
|
+
*/
|
|
20
|
+
ownsSortKey: (sortKey: string) => boolean;
|
|
21
|
+
/** The offloaded payload descriptors a row references, if any. */
|
|
22
|
+
descriptorsOf: (row: DocItem) => (PayloadDescriptor | undefined)[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Delete every row in a partition that belongs to the calling adapter,
|
|
26
|
+
* best-effort deleting any offloaded S3 objects. Streams the partition with
|
|
27
|
+
* unbounded pagination and flushes in batches, so a partition of any size is
|
|
28
|
+
* deleted to completion with bounded memory — never silently truncated at the
|
|
29
|
+
* in-memory page caps, and never discarding already-flushed progress if a
|
|
30
|
+
* later batch fails. Returns the number of rows deleted.
|
|
31
|
+
*/
|
|
32
|
+
export declare function deletePartitionRows(options: PartitionDeleteOptions): Promise<number>;
|
|
33
|
+
//# sourceMappingURL=partition-delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partition-delete.d.ts","sourceRoot":"","sources":["../../../src/shared/dynamodb/partition-delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,0EAA0E;AAC1E,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,2EAA2E;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1C,kEAAkE;IAClE,aAAa,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,CAAC,iBAAiB,GAAG,SAAS,CAAC,EAAE,CAAC;CACpE;AA2DD;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CA2B1F"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deletePartitionRows = deletePartitionRows;
|
|
4
|
+
const descriptor_keys_1 = require("../codec/descriptor-keys");
|
|
5
|
+
const orphans_1 = require("../codec/s3/orphans");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const errors_1 = require("../errors/errors");
|
|
8
|
+
const batch_write_1 = require("./batch-write");
|
|
9
|
+
const paginate_1 = require("./paginate");
|
|
10
|
+
/** Delete the buffered keys, best-effort clean their S3 objects, then clear it. */
|
|
11
|
+
async function flushBuffer(options, buffer, progress) {
|
|
12
|
+
if (buffer.keys.length === 0)
|
|
13
|
+
return;
|
|
14
|
+
const chunks = Math.ceil(buffer.keys.length / constants_1.BATCH_WRITE_MAX);
|
|
15
|
+
try {
|
|
16
|
+
await (0, batch_write_1.batchWriteAll)(options.client, options.tableName, buffer.keys.map((Key) => ({ DeleteRequest: { Key } })));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
/** batchWriteAll's only throw is a BatchWriteAllIncompleteError (see batch-write.ts). */
|
|
20
|
+
const failure = error;
|
|
21
|
+
throw new errors_1.BatchWriteAllIncompleteError(progress.succeededChunks + failure.succeededChunks, progress.totalChunks + failure.totalChunks, failure.failedChunks, progress.writes + failure.succeededCount);
|
|
22
|
+
}
|
|
23
|
+
progress.writes += buffer.keys.length;
|
|
24
|
+
progress.succeededChunks += chunks;
|
|
25
|
+
progress.totalChunks += chunks;
|
|
26
|
+
if (options.offloader) {
|
|
27
|
+
await (0, orphans_1.cleanUpS3Orphans)(options.offloader, (0, descriptor_keys_1.collectS3Keys)(buffer.descriptors), options.operation, options.logger);
|
|
28
|
+
}
|
|
29
|
+
buffer.keys = [];
|
|
30
|
+
buffer.descriptors = [];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Delete every row in a partition that belongs to the calling adapter,
|
|
34
|
+
* best-effort deleting any offloaded S3 objects. Streams the partition with
|
|
35
|
+
* unbounded pagination and flushes in batches, so a partition of any size is
|
|
36
|
+
* deleted to completion with bounded memory — never silently truncated at the
|
|
37
|
+
* in-memory page caps, and never discarding already-flushed progress if a
|
|
38
|
+
* later batch fails. Returns the number of rows deleted.
|
|
39
|
+
*/
|
|
40
|
+
async function deletePartitionRows(options) {
|
|
41
|
+
const buffer = { keys: [], descriptors: [] };
|
|
42
|
+
const progress = { writes: 0, succeededChunks: 0, totalChunks: 0 };
|
|
43
|
+
let skipped = 0;
|
|
44
|
+
const pages = (0, paginate_1.paginateQuery)({
|
|
45
|
+
client: options.client,
|
|
46
|
+
params: options.params,
|
|
47
|
+
maxItems: Number.POSITIVE_INFINITY,
|
|
48
|
+
maxIterations: Number.POSITIVE_INFINITY,
|
|
49
|
+
});
|
|
50
|
+
for await (const row of pages) {
|
|
51
|
+
if (!options.ownsSortKey(row.SK)) {
|
|
52
|
+
skipped += 1;
|
|
53
|
+
options.logger.warn(`${options.operation}: left a foreign row in place`, {
|
|
54
|
+
sortKey: row.SK,
|
|
55
|
+
});
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
buffer.keys.push({ PK: row.PK, SK: row.SK });
|
|
59
|
+
for (const descriptor of options.descriptorsOf(row)) {
|
|
60
|
+
if (descriptor)
|
|
61
|
+
buffer.descriptors.push(descriptor);
|
|
62
|
+
}
|
|
63
|
+
if (buffer.keys.length >= constants_1.BATCH_WRITE_MAX)
|
|
64
|
+
await flushBuffer(options, buffer, progress);
|
|
65
|
+
}
|
|
66
|
+
await flushBuffer(options, buffer, progress);
|
|
67
|
+
options.logger.info(`${options.operation}: deleted rows`, { deleted: progress.writes, skipped });
|
|
68
|
+
return progress.writes;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=partition-delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partition-delete.js","sourceRoot":"","sources":["../../../src/shared/dynamodb/partition-delete.ts"],"names":[],"mappings":";;;AAGA,8DAAyD;AAEzD,iDAAuD;AACvD,4CAA+C;AAC/C,6CAAgE;AAEhE,+CAA8C;AAC9C,yCAA2C;AAwC3C,mFAAmF;AACnF,KAAK,UAAU,WAAW,CACxB,OAA+B,EAC/B,MAAoB,EACpB,QAAwB;IAExB,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,2BAAe,CAAC,CAAC;IAC/D,IAAI,CAAC;QACH,MAAM,IAAA,2BAAa,EACjB,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,SAAS,EACjB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CACvD,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yFAAyF;QACzF,MAAM,OAAO,GAAG,KAAqC,CAAC;QACtD,MAAM,IAAI,qCAA4B,CACpC,QAAQ,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,EAClD,QAAQ,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,EAC1C,OAAO,CAAC,YAAY,EACpB,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,cAAc,CACzC,CAAC;IACJ,CAAC;IACD,QAAQ,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;IACtC,QAAQ,CAAC,eAAe,IA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E,EAAE,EAAE,GAAG,CAAC,EAAY,EAAE,EAAE,EAAE,GAAG,CAAC,EAAY,EAAE,CAAC,CAAC;QACjE,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;YACpD,IAAI,UAAU;gBAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,2BAAe;YAAE,MAAM,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1F,CAAC;IACD,MAAM,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7C,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,gBAAgB,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACjG,OAAO,QAAQ,CAAC,MAAM,CAAC;AACzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-classifier.d.ts","sourceRoot":"","sources":["../../../src/shared/dynamodb/retry-classifier.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAiBrD,CAAC;
|
|
1
|
+
{"version":3,"file":"retry-classifier.d.ts","sourceRoot":"","sources":["../../../src/shared/dynamodb/retry-classifier.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAiBrD,CAAC;AA6DF,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAK1F"}
|
|
@@ -47,7 +47,15 @@ function transactionCancellationRetryable(error) {
|
|
|
47
47
|
const reasons = (0, cancellation_1.getCancellationReasons)(error);
|
|
48
48
|
if (!reasons)
|
|
49
49
|
return undefined;
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* `length > 0` is load-bearing: `.every()` is vacuously true on an empty
|
|
52
|
+
* array, which would make a reason-less cancellation retryable — the exact
|
|
53
|
+
* opposite of what this function documents. AWS populates one reason per
|
|
54
|
+
* `TransactItems` entry, so an empty array should not occur; if it ever
|
|
55
|
+
* does, the conservative answer is not to retry.
|
|
56
|
+
*/
|
|
57
|
+
return (reasons.length > 0 &&
|
|
58
|
+
reasons.every((reason) => reason.Code === undefined || TRANSIENT_CANCELLATION_REASONS.includes(reason.Code)));
|
|
51
59
|
}
|
|
52
60
|
function collectSignals(error) {
|
|
53
61
|
const seen = new WeakSet();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry-classifier.js","sourceRoot":"","sources":["../../../src/shared/dynamodb/retry-classifier.ts"],"names":[],"mappings":";;;;AAAA,iDAAwD;AAExD,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;;GAIG;AACU,QAAA,wBAAwB,GAAsB;IACzD,wCAAwC;IACxC,qBAAqB;IACrB,sBAAsB;IACtB,qBAAqB;IACrB,oBAAoB;IACpB,8BAA8B;IAC9B,gCAAgC;IAChC,gBAAgB;IAChB,yBAAyB;IACzB,YAAY;IACZ,cAAc;IACd,WAAW;IACX,OAAO;IACP,WAAW;IACX,iBAAiB;IACjB,cAAc;CACf,CAAC;AAEF;;;;GAIG;AACH,MAAM,8BAA8B,GAAsB;IACxD,MAAM;IACN,qBAAqB;IACrB,iBAAiB;IACjB,+BAA+B;CAChC,CAAC;AAEF;;;;GAIG;AACH,SAAS,gCAAgC,CAAC,KAAY;IACpD,MAAM,OAAO,GAAG,IAAA,qCAAsB,EAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,OAAO,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"retry-classifier.js","source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AI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,MAAM,MAAM,GAAG,IAMd,CAAC;QACF,KAAK,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7E,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC;QACD,IAAI,MAAM,CAAC,KAAK;YAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC;IACF,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,gFAAgF;AAChF,0BAAiC,KAAY,EAAE,eAAkC;IAC/E,MAAM,YAAY,GAAG,gCAAgC,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC;IACpD,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -27,12 +27,15 @@ export declare class AbortError extends DynamoDbLangGraphError {
|
|
|
27
27
|
/**
|
|
28
28
|
* A BatchWriteItem sequence could not drain its UnprocessedItems. Items NOT
|
|
29
29
|
* listed in {@link unprocessed} were acked by DynamoDB and persist — there is
|
|
30
|
-
* no rollback (drive reconciliation from `unprocessed`).
|
|
30
|
+
* no rollback (drive reconciliation from `unprocessed`). `cause`, when given,
|
|
31
|
+
* is the underlying failure that interrupted the drain (e.g. a thrown,
|
|
32
|
+
* non-UnprocessedItems error from a retry round) rather than a clean exhaustion
|
|
33
|
+
* of the UnprocessedItems retry budget.
|
|
31
34
|
*/
|
|
32
35
|
export declare class BatchWriteIncompleteError extends DynamoDbLangGraphError {
|
|
33
36
|
readonly succeededCount: number;
|
|
34
37
|
readonly unprocessed: WriteRequest[];
|
|
35
|
-
constructor(succeededCount: number, unprocessed: WriteRequest[], retries: number);
|
|
38
|
+
constructor(succeededCount: number, unprocessed: WriteRequest[], retries: number, cause?: Error);
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* batchWriteAll attempts every chunk rather than stopping at the first
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/shared/errors/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,mEAAmE;AACnE,qBAAa,eAAgB,SAAQ,sBAAsB;IACzD,YAAY,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAG1C;CACF;AAED,2EAA2E;AAC3E,qBAAa,aAAc,SAAQ,sBAAsB;IACvD,YAAY,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAGzC;CACF;AAED,wDAAwD;AACxD,qBAAa,mBAAoB,SAAQ,sBAAsB;IAC7D,YAAY,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAG5D;CACF;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,sBAAsB;IAC9D,YAAY,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAOrC;CACF;AAED,sDAAsD;AACtD,qBAAa,UAAW,SAAQ,sBAAsB;IACpD,YAAY,OAAO,SAAsB,EAGxC;CACF;AAED
|
|
1
|
+
{"version":3,"file":"errors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AAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,YACE,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,KAAK,EAAE,EACrB,cAAc,SAAI,EAcnB;CACF;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,SAAQ,sBAAsB;IACjE,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC;IAE9B,YAAY,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAS7C;CACF"}
|
|
@@ -50,14 +50,17 @@ exports.AbortError = AbortError;
|
|
|
50
50
|
/**
|
|
51
51
|
* A BatchWriteItem sequence could not drain its UnprocessedItems. Items NOT
|
|
52
52
|
* listed in {@link unprocessed} were acked by DynamoDB and persist — there is
|
|
53
|
-
* no rollback (drive reconciliation from `unprocessed`).
|
|
53
|
+
* no rollback (drive reconciliation from `unprocessed`). `cause`, when given,
|
|
54
|
+
* is the underlying failure that interrupted the drain (e.g. a thrown,
|
|
55
|
+
* non-UnprocessedItems error from a retry round) rather than a clean exhaustion
|
|
56
|
+
* of the UnprocessedItems retry budget.
|
|
54
57
|
*/
|
|
55
58
|
class BatchWriteIncompleteError extends base_error_1.DynamoDbLangGraphError {
|
|
56
59
|
succeededCount;
|
|
57
60
|
unprocessed;
|
|
58
|
-
constructor(succeededCount, unprocessed, retries) {
|
|
61
|
+
constructor(succeededCount, unprocessed, retries, cause) {
|
|
59
62
|
super(`batchWrite did not drain after ${retries} UnprocessedItems retries: ` +
|
|
60
|
-
`${succeededCount} item(s) persisted, ${unprocessed.length} still un-acked.`, error_code_1.ErrorCode.BATCH_WRITE_INCOMPLETE);
|
|
63
|
+
`${succeededCount} item(s) persisted, ${unprocessed.length} still un-acked.`, error_code_1.ErrorCode.BATCH_WRITE_INCOMPLETE, {}, cause);
|
|
61
64
|
this.name = 'BatchWriteIncompleteError';
|
|
62
65
|
this.succeededCount = succeededCount;
|
|
63
66
|
this.unprocessed = unprocessed;
|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B,CAAC;QAC3C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;CACF;;AAED;;;;;GAKG;AACH,6BAAqC,SAAQ,mCAAsB;IACxD,aAAa,CAAQ;IAE9B,YAAY,KAAY,EAAE,aAAoB;QAC5C,KAAK,CACH,8CAA8C,KAAK,CAAC,OAAO,eAAe,aAAa,CAAC,OAAO,GAAG,EAClG,sBAAS,CAAC,mBAAmB,EAC7B,EAAE,EACF,KAAK,CACN,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** A value that {@link redactSecrets} can recurse through. */
|
|
2
|
+
export type Redactable = string | number | boolean | null | undefined | Redactable[] | {
|
|
3
|
+
[key: string]: Redactable;
|
|
4
|
+
};
|
|
5
|
+
/** Any `Redactable` that is a non-null object — what the walk dispatches on. */
|
|
6
|
+
export type RedactableObject = Redactable[] | {
|
|
7
|
+
[key: string]: Redactable;
|
|
8
|
+
};
|
|
9
|
+
/** One step of the recursive walk, threaded into the entry helpers. */
|
|
10
|
+
export type Walk = (value: Redactable) => Redactable;
|
|
11
|
+
/** Collaborators threaded through the recursive walk. */
|
|
12
|
+
export interface WalkDeps {
|
|
13
|
+
keyPatterns: readonly string[];
|
|
14
|
+
valuePatterns: readonly RegExp[];
|
|
15
|
+
walk: Walk;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Dispatch one non-null object by its shape: arrays and plain objects recurse,
|
|
19
|
+
* binary views collapse to a label, `Date`/`RegExp` pass through by reference,
|
|
20
|
+
* `Set`/`Map` render as their contents, and an Error takes the path above.
|
|
21
|
+
*/
|
|
22
|
+
export declare function walkObject(current: RedactableObject, deps: WalkDeps): Redactable;
|
|
23
|
+
//# sourceMappingURL=redaction-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction-walk.d.ts","sourceRoot":"","sources":["../../../src/shared/logging/redaction-walk.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,MAAM,UAAU,GACpB,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC;AAE9F,gFAAgF;AAChF,MAAM,MAAM,gBAAgB,GAAG,UAAU,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC;AAE5E,uEAAuE;AACvE,MAAM,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,UAAU,CAAC;AAErD,yDAAyD;AACzD,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,IAAI,EAAE,IAAI,CAAC;CACZ;AAiFD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,GAAG,UAAU,CAShF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walkObject = walkObject;
|
|
4
|
+
const secret_patterns_1 = require("./secret-patterns");
|
|
5
|
+
/** True when `value` is a Set, tested by tag so a cross-realm Set still matches. */
|
|
6
|
+
function isSetValue(value) {
|
|
7
|
+
return Object.prototype.toString.call(value) === '[object Set]';
|
|
8
|
+
}
|
|
9
|
+
/** True when `value` is a Map, tested by tag so a cross-realm Map still matches. */
|
|
10
|
+
function isMapValue(value) {
|
|
11
|
+
return Object.prototype.toString.call(value) === '[object Map]';
|
|
12
|
+
}
|
|
13
|
+
/** True when `value` is an Error (or subclass), tested by tag not `instanceof`. */
|
|
14
|
+
function isErrorValue(value) {
|
|
15
|
+
return Object.prototype.toString.call(value) === '[object Error]';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* True for a value whose identity matters more than its own properties.
|
|
19
|
+
* `Date` and `RegExp` have none, so recursing either would yield a bare `{}`.
|
|
20
|
+
*/
|
|
21
|
+
function isOpaqueValue(value) {
|
|
22
|
+
const tag = Object.prototype.toString.call(value);
|
|
23
|
+
return tag === '[object Date]' || tag === '[object RegExp]';
|
|
24
|
+
}
|
|
25
|
+
/** Rebuild entries into a plain object, redacting values at secret-looking keys. */
|
|
26
|
+
function redactEntries(entries, keyPatterns, walk) {
|
|
27
|
+
const out = {};
|
|
28
|
+
for (const [key, value] of entries) {
|
|
29
|
+
out[key] = (0, secret_patterns_1.isSecretKey)(key, keyPatterns) ? secret_patterns_1.REDACTED : walk(value);
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A Map's entries as an object. Keys are stringified so a non-string key is
|
|
35
|
+
* still reported rather than dropped, and each is checked against the
|
|
36
|
+
* secret-key patterns exactly as a plain object's own keys are.
|
|
37
|
+
*/
|
|
38
|
+
function redactMap(value, deps) {
|
|
39
|
+
const entries = [...value].map(([key, entry]) => [String(key), entry]);
|
|
40
|
+
return redactEntries(entries, deps.keyPatterns, deps.walk);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Rebuild an Error as a plain object carrying its redacted text alongside its
|
|
44
|
+
* redacted own properties. The one exception is an Error with no own
|
|
45
|
+
* enumerable data whose text holds no secret: it is returned by reference so
|
|
46
|
+
* its identity and stack trace survive, which is what keeps a caught error
|
|
47
|
+
* useful in a log.
|
|
48
|
+
*
|
|
49
|
+
* `cause` is copied explicitly because `new Error(msg, { cause })` defines it
|
|
50
|
+
* as *non-enumerable* per spec, so `Object.entries` never sees it. Without
|
|
51
|
+
* this the whole chain vanished on every rebuild — and the rebuild always
|
|
52
|
+
* fires for this library's own error types, since each attaches an enumerable
|
|
53
|
+
* `code`/`context`. A redacted `RetryExhaustedError` would then no longer say
|
|
54
|
+
* whether the underlying failure was a throttle, a validation error or a
|
|
55
|
+
* network fault, which is the entire reason it carries a cause. Recursing it
|
|
56
|
+
* through `walk` redacts the chain too, and the cycle guard handles a cause
|
|
57
|
+
* that points back at its own wrapper.
|
|
58
|
+
*/
|
|
59
|
+
function redactError(current, entries, deps) {
|
|
60
|
+
const text = (0, secret_patterns_1.redactErrorText)(current, deps.valuePatterns);
|
|
61
|
+
if (entries.length === 0 && !text.changed)
|
|
62
|
+
return current;
|
|
63
|
+
const out = redactEntries(entries, deps.keyPatterns, deps.walk);
|
|
64
|
+
out.name = text.name;
|
|
65
|
+
out.message = text.message;
|
|
66
|
+
out.stack = text.stack;
|
|
67
|
+
if (current.cause !== undefined)
|
|
68
|
+
out.cause = deps.walk(current.cause);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Dispatch one non-null object by its shape: arrays and plain objects recurse,
|
|
73
|
+
* binary views collapse to a label, `Date`/`RegExp` pass through by reference,
|
|
74
|
+
* `Set`/`Map` render as their contents, and an Error takes the path above.
|
|
75
|
+
*/
|
|
76
|
+
function walkObject(current, deps) {
|
|
77
|
+
if (Array.isArray(current))
|
|
78
|
+
return current.map(deps.walk);
|
|
79
|
+
if (ArrayBuffer.isView(current))
|
|
80
|
+
return (0, secret_patterns_1.binaryLabel)(current);
|
|
81
|
+
if (isOpaqueValue(current))
|
|
82
|
+
return current;
|
|
83
|
+
if (isSetValue(current))
|
|
84
|
+
return [...current].map(deps.walk);
|
|
85
|
+
if (isMapValue(current))
|
|
86
|
+
return redactMap(current, deps);
|
|
87
|
+
const entries = Object.entries(current);
|
|
88
|
+
if (isErrorValue(current))
|
|
89
|
+
return redactError(current, entries, deps);
|
|
90
|
+
return redactEntries(entries, deps.keyPatterns, deps.walk);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=redaction-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction-walk.js","sourceRoot":"","sources":["../../../src/shared/logging/redaction-walk.ts"],"names":[],"mappings":";;;AAAA,uDAAwF;AAmBxF,oFAAoF;AACpF,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,cAAc,CAAC;AAClE,CAAC;AAED,oFAAoF;AACpF,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,cAAc,CAAC;AAClE,CAAC;AAED,mFAAmF;AACnF,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,gBAAgB,CAAC;AACpE,CAAC;AAED;;;GAGG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,GAAG,KAAK,eAAe,IAAI,GAAG,KAAK,iBAAiB,CAAC;AAC9D,CAAC;AAED,oFAAoF;AACpF,SAAS,aAAa,CACpB,OAAmD,EACnD,WAA8B,EAC9B,IAAU;IAEV,MAAM,GAAG,GAAkC,EAAE,CAAC;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACnC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAA,6BAAW,EAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,0BAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,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AC,IAAI,CAAC,CAAC;IAC1D,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,OAAO,IAAA,6BAAW,EAAC,OAAO,CAAC,CAAC;IAC7D,IAAI,aAAa,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC3C,IAAI,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,IAAI,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,YAAY,CAAC,OAAO,CAAC;QAAE,OAAO,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACtE,OAAO,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import type { Logger } from './logger';
|
|
2
|
-
|
|
3
|
-
export type Redactable = string | number | boolean | null | undefined | Redactable[] | {
|
|
4
|
-
[key: string]: Redactable;
|
|
5
|
-
};
|
|
2
|
+
import { type Redactable } from './redaction-walk';
|
|
6
3
|
/**
|
|
7
4
|
* Recursively clone `value`, replacing any value at a secret-looking key with
|
|
8
|
-
* `[REDACTED]
|
|
9
|
-
* stack
|
|
5
|
+
* `[REDACTED]` and any recognised secret *shape* inside a string — including an
|
|
6
|
+
* error's `message`/`stack` text, which key-name matching cannot reach — with
|
|
7
|
+
* the same marker. Cycles become `[Circular]`.
|
|
8
|
+
*
|
|
9
|
+
* An Error with no own enumerable properties whose text holds no secret is
|
|
10
|
+
* passed through by reference, so its identity and stack trace survive; one
|
|
11
|
+
* carrying own data (this library's error types all attach `code`/`context`
|
|
12
|
+
* this way) or a secret in its text is rebuilt instead, with `name`/`message`/
|
|
13
|
+
* `stack` redacted and every other own property recursed like a plain object.
|
|
14
|
+
* `Date`/`RegExp` keep their identity rather than collapsing to `{}`,
|
|
15
|
+
* `Set`/`Map` render as their contents, and binary views become a short label.
|
|
16
|
+
* Does not mutate the input.
|
|
10
17
|
*/
|
|
11
|
-
export declare function redactSecrets(value: Redactable, patterns?: readonly string[]): Redactable;
|
|
18
|
+
export declare function redactSecrets(value: Redactable, patterns?: readonly string[], valuePatterns?: readonly RegExp[]): Redactable;
|
|
19
|
+
/** Options controlling {@link redactLogger}. */
|
|
20
|
+
export interface RedactLoggerOptions {
|
|
21
|
+
/** Additional key names (matched case-insensitively as substrings) to redact. */
|
|
22
|
+
extraKeys?: readonly string[];
|
|
23
|
+
/** Additional secret shapes to redact wherever they appear inside a string. */
|
|
24
|
+
extraValuePatterns?: readonly RegExp[];
|
|
25
|
+
}
|
|
12
26
|
/**
|
|
13
27
|
* Wrap a logger so object args are redacted before delegation. The message
|
|
14
28
|
* string is passed through unchanged (never interpolate secrets into it).
|
|
15
29
|
*/
|
|
16
|
-
export declare function redactLogger(inner: Logger, options?:
|
|
17
|
-
extraKeys?: readonly string[];
|
|
18
|
-
}): Logger;
|
|
30
|
+
export declare function redactLogger(inner: Logger, options?: RedactLoggerOptions): Logger;
|
|
19
31
|
//# sourceMappingURL=redaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redaction.d.ts","sourceRoot":"","sources":["../../../src/shared/logging/redaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"redaction.d.ts","sourceRoot":"","sources":["../../../src/shared/logging/redaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,MAAM,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,kBAAkB,CAAC;AAO/D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,UAAU,EACjB,QAAQ,GAAE,SAAS,MAAM,EAAgC,EACzD,aAAa,GAAE,SAAS,MAAM,EAAkC,GAC/D,UAAU,CAcZ;AAED,gDAAgD;AAChD,MAAM,WAAW,mBAAmB;IAClC,iFAAiF;IACjF,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,+EAA+E;IAC/E,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAerF"}
|
|
@@ -2,50 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.redactSecrets = redactSecrets;
|
|
4
4
|
exports.redactLogger = redactLogger;
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
'secretkey',
|
|
8
|
-
'secret',
|
|
9
|
-
'sessiontoken',
|
|
10
|
-
'securitytoken',
|
|
11
|
-
'authorization',
|
|
12
|
-
'password',
|
|
13
|
-
'apikey',
|
|
14
|
-
'bearer',
|
|
15
|
-
'token',
|
|
16
|
-
'privatekey',
|
|
17
|
-
];
|
|
18
|
-
const REDACTED = '[REDACTED]';
|
|
19
|
-
function isSecretKey(key, patterns) {
|
|
20
|
-
const lower = key.toLowerCase();
|
|
21
|
-
return patterns.some((pattern) => lower.includes(pattern));
|
|
22
|
-
}
|
|
23
|
-
function isErrorShaped(value) {
|
|
24
|
-
return Object.prototype.toString.call(value) === '[object Error]';
|
|
25
|
-
}
|
|
5
|
+
const redaction_walk_1 = require("./redaction-walk");
|
|
6
|
+
const secret_patterns_1 = require("./secret-patterns");
|
|
26
7
|
/**
|
|
27
8
|
* Recursively clone `value`, replacing any value at a secret-looking key with
|
|
28
|
-
* `[REDACTED]
|
|
29
|
-
* stack
|
|
9
|
+
* `[REDACTED]` and any recognised secret *shape* inside a string — including an
|
|
10
|
+
* error's `message`/`stack` text, which key-name matching cannot reach — with
|
|
11
|
+
* the same marker. Cycles become `[Circular]`.
|
|
12
|
+
*
|
|
13
|
+
* An Error with no own enumerable properties whose text holds no secret is
|
|
14
|
+
* passed through by reference, so its identity and stack trace survive; one
|
|
15
|
+
* carrying own data (this library's error types all attach `code`/`context`
|
|
16
|
+
* this way) or a secret in its text is rebuilt instead, with `name`/`message`/
|
|
17
|
+
* `stack` redacted and every other own property recursed like a plain object.
|
|
18
|
+
* `Date`/`RegExp` keep their identity rather than collapsing to `{}`,
|
|
19
|
+
* `Set`/`Map` render as their contents, and binary views become a short label.
|
|
20
|
+
* Does not mutate the input.
|
|
30
21
|
*/
|
|
31
|
-
function redactSecrets(value, patterns = DEFAULT_SECRET_KEY_PATTERNS) {
|
|
22
|
+
function redactSecrets(value, patterns = secret_patterns_1.DEFAULT_SECRET_KEY_PATTERNS, valuePatterns = secret_patterns_1.DEFAULT_SECRET_VALUE_PATTERNS) {
|
|
32
23
|
const seen = new WeakSet();
|
|
33
24
|
const walk = (current) => {
|
|
25
|
+
if (typeof current === 'string')
|
|
26
|
+
return (0, secret_patterns_1.redactText)(current, valuePatterns);
|
|
34
27
|
if (current === null || typeof current !== 'object')
|
|
35
28
|
return current;
|
|
36
29
|
if (seen.has(current))
|
|
37
30
|
return '[Circular]';
|
|
38
31
|
seen.add(current);
|
|
39
32
|
try {
|
|
40
|
-
|
|
41
|
-
return current.map(walk);
|
|
42
|
-
if (isErrorShaped(current))
|
|
43
|
-
return current;
|
|
44
|
-
const out = {};
|
|
45
|
-
for (const [key, val] of Object.entries(current)) {
|
|
46
|
-
out[key] = isSecretKey(key, patterns) ? REDACTED : walk(val);
|
|
47
|
-
}
|
|
48
|
-
return out;
|
|
33
|
+
return (0, redaction_walk_1.walkObject)(current, { keyPatterns: patterns, valuePatterns, walk });
|
|
49
34
|
}
|
|
50
35
|
finally {
|
|
51
36
|
seen.delete(current);
|
|
@@ -59,9 +44,12 @@ function redactSecrets(value, patterns = DEFAULT_SECRET_KEY_PATTERNS) {
|
|
|
59
44
|
*/
|
|
60
45
|
function redactLogger(inner, options = {}) {
|
|
61
46
|
const patterns = options.extraKeys
|
|
62
|
-
? [...DEFAULT_SECRET_KEY_PATTERNS, ...options.extraKeys.map((key) => key.toLowerCase())]
|
|
63
|
-
: DEFAULT_SECRET_KEY_PATTERNS;
|
|
64
|
-
const
|
|
47
|
+
? [...secret_patterns_1.DEFAULT_SECRET_KEY_PATTERNS, ...options.extraKeys.map((key) => key.toLowerCase())]
|
|
48
|
+
: secret_patterns_1.DEFAULT_SECRET_KEY_PATTERNS;
|
|
49
|
+
const valuePatterns = options.extraValuePatterns
|
|
50
|
+
? [...secret_patterns_1.DEFAULT_SECRET_VALUE_PATTERNS, ...options.extraValuePatterns]
|
|
51
|
+
: secret_patterns_1.DEFAULT_SECRET_VALUE_PATTERNS;
|
|
52
|
+
const wrap = (args) => args.map((arg) => redactSecrets(arg, patterns, valuePatterns));
|
|
65
53
|
return {
|
|
66
54
|
info: (message, ...args) => inner.info(message, ...wrap(args)),
|
|
67
55
|
warn: (message, ...args) => inner.warn(message, ...wrap(args)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../../../src/shared/logging/redaction.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../../../src/shared/logging/redaction.ts"],"names":[],"mappings":";;;;AACA,qDAA+D;AAC/D,uDAI2B;AAE3B;;;;;;;;;;;;;;GAcG;AACH,uBACE,KAAiB,EACjB,QAAQ,GAAsB,6CAA2B,EACzD,aAAa,GAAsB,+CAA6B;IAEhE,MAAM,IAAI,GAAG,IAAI,OAAO,EAAU,CAAC;IACnC,MAAM,IAAI,GAAG,CAAC,OAAmB,EAAc,EAAE;QAC/C,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,IAAA,4B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K,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9D,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9D,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAChE,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;KACjE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Marker substituted for anything recognised as secret. */
|
|
2
|
+
export declare const REDACTED = "[REDACTED]";
|
|
3
|
+
/** Key names (matched case-insensitively as substrings) whose value is a secret. */
|
|
4
|
+
export declare const DEFAULT_SECRET_KEY_PATTERNS: readonly string[];
|
|
5
|
+
/**
|
|
6
|
+
* Secret shapes recognisable in free text, where key-name matching cannot
|
|
7
|
+
* reach: an error's `message`/`stack`, or any other string value. Deliberately
|
|
8
|
+
* high-confidence — each pattern describes a credential *format* rather than a
|
|
9
|
+
* word that merely sounds sensitive — so ordinary operational text survives
|
|
10
|
+
* redaction unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_SECRET_VALUE_PATTERNS: readonly RegExp[];
|
|
13
|
+
/** True when `key` matches any secret-key pattern. */
|
|
14
|
+
export declare function isSecretKey(key: string, patterns: readonly string[]): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Replace every recognised secret shape inside `value` with {@link REDACTED},
|
|
17
|
+
* leaving the surrounding text intact so a redacted message stays readable.
|
|
18
|
+
* Each pattern is rebuilt per call so a `g` flag's `lastIndex` never leaks
|
|
19
|
+
* between invocations.
|
|
20
|
+
*/
|
|
21
|
+
export declare function redactText(value: string, patterns: readonly RegExp[]): string;
|
|
22
|
+
/**
|
|
23
|
+
* A short label for a binary view. Recursing one would explode it into a
|
|
24
|
+
* per-index numeric map, both unreadable and far larger than the value itself.
|
|
25
|
+
*/
|
|
26
|
+
export declare function binaryLabel(value: ArrayBufferView): string;
|
|
27
|
+
/** An Error's redacted non-enumerable text, plus whether redaction changed it. */
|
|
28
|
+
export interface RedactedErrorText {
|
|
29
|
+
name: string;
|
|
30
|
+
message: string;
|
|
31
|
+
stack: string | undefined;
|
|
32
|
+
changed: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Redact an Error's `name`/`message`/`stack`. `changed` reports whether any
|
|
36
|
+
* secret was actually found, which is what decides between passing a bare
|
|
37
|
+
* Error through by reference (preserving its identity and stack trace) and
|
|
38
|
+
* rebuilding it so the secret cannot escape.
|
|
39
|
+
*/
|
|
40
|
+
export declare function redactErrorText(error: Error, patterns: readonly RegExp[]): RedactedErrorText;
|
|
41
|
+
//# sourceMappingURL=secret-patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-patterns.d.ts","sourceRoot":"","sources":["../../../src/shared/logging/secret-patterns.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,eAAO,MAAM,QAAQ,eAAe,CAAC;AAErC,oFAAoF;AACpF,eAAO,MAAM,2BAA2B,EAAE,SAAS,MAAM,EAYxD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,MAAM,EAK1D,CAAC;AAEF,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAG7E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAK7E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAE1D;AAED,kFAAkF;AAClF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,iBAAiB,CAS5F"}
|