ag-common 0.0.801 → 0.0.803
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.
|
@@ -53,7 +53,7 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
53
53
|
var _a, e_1, _b, _c;
|
|
54
54
|
try {
|
|
55
55
|
const generator = (0, get_1.scanWithGenerator)(tableName, {
|
|
56
|
-
|
|
56
|
+
limit: 100, // Process in chunks of 100 items
|
|
57
57
|
maxRetries: null, // Always retry on 429 since we want to ensure complete deletion
|
|
58
58
|
});
|
|
59
59
|
try {
|
|
@@ -51,11 +51,5 @@ export declare const scan: <T>(tableName: string, options?: ScanOptions) => Prom
|
|
|
51
51
|
* @returns Promise resolving to query results or error
|
|
52
52
|
*/
|
|
53
53
|
export declare const batchQueryDynamo: <T>(params: DynamoBatchQueryParams) => Promise<DynamoDBResult<T[]>>;
|
|
54
|
-
export declare function queryWithGenerator<T>(params: DynamoQueryParams
|
|
55
|
-
|
|
56
|
-
BATCH_SIZE?: number;
|
|
57
|
-
}): AsyncGenerator<T[], void, unknown>;
|
|
58
|
-
export declare function scanWithGenerator<T>(tableName: string, options?: ScanOptions & {
|
|
59
|
-
/** how many to return in scan generator. default 100 */
|
|
60
|
-
BATCH_SIZE?: number;
|
|
61
|
-
}): AsyncGenerator<T[], void, unknown>;
|
|
54
|
+
export declare function queryWithGenerator<T>(params: DynamoQueryParams): AsyncGenerator<T[], void, unknown>;
|
|
55
|
+
export declare function scanWithGenerator<T>(tableName: string, options?: ScanOptions): AsyncGenerator<T[], void, unknown>;
|
|
@@ -33,7 +33,7 @@ const isError = (result) => 'error' in result;
|
|
|
33
33
|
* Helper function that builds the query parameters and executes the query
|
|
34
34
|
*/
|
|
35
35
|
const executeQuery = (params, exclusiveStartKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var _a, _b, _c, _d
|
|
36
|
+
var _a, _b, _c, _d;
|
|
37
37
|
let kce = `#${params.pkName.toLowerCase()} ${(_a = params.pkOperator) !== null && _a !== void 0 ? _a : '='} :${params.pkName.toLowerCase()}`;
|
|
38
38
|
const ean = {
|
|
39
39
|
[`#${params.pkName.toLowerCase()}`]: params.pkName,
|
|
@@ -61,7 +61,7 @@ const executeQuery = (params, exclusiveStartKey) => __awaiter(void 0, void 0, vo
|
|
|
61
61
|
eav[`:${skName.toLowerCase()}`] = skValue;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
const queryParams = Object.assign({ TableName: params.tableName, KeyConditionExpression: kce, ExpressionAttributeNames: Object.assign(Object.assign({}, ean), (_b = params.filter) === null || _b === void 0 ? void 0 : _b.attrNames), ExpressionAttributeValues: Object.assign(Object.assign({}, eav), (_c = params.filter) === null || _c === void 0 ? void 0 : _c.attrValues), ScanIndexForward: (_d = params.sortAscending) !== null && _d !== void 0 ? _d : true, Limit:
|
|
64
|
+
const queryParams = Object.assign({ TableName: params.tableName, KeyConditionExpression: kce, ExpressionAttributeNames: Object.assign(Object.assign({}, ean), (_b = params.filter) === null || _b === void 0 ? void 0 : _b.attrNames), ExpressionAttributeValues: Object.assign(Object.assign({}, eav), (_c = params.filter) === null || _c === void 0 ? void 0 : _c.attrValues), ScanIndexForward: (_d = params.sortAscending) !== null && _d !== void 0 ? _d : true, Limit: params.limit === null ? undefined : params.limit, IndexName: params.indexName, ExclusiveStartKey: exclusiveStartKey }, (params.filter && Object.assign({ FilterExpression: params.filter.filterExpression }, (params.filter.attrValues && {
|
|
65
65
|
ExpressionAttributeValues: Object.assign(Object.assign({}, eav), params.filter.attrValues),
|
|
66
66
|
}))));
|
|
67
67
|
return (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.QueryCommand(queryParams)), 'queryDynamo:' + JSON.stringify(params), {
|
|
@@ -78,7 +78,7 @@ const executeScan = (tableName, options, exclusiveStartKey) => __awaiter(void 0,
|
|
|
78
78
|
return acc;
|
|
79
79
|
}, {});
|
|
80
80
|
const expressionAttributeNames = Object.assign(Object.assign({}, projectionAttrs), (_b = options === null || options === void 0 ? void 0 : options.filter) === null || _b === void 0 ? void 0 : _b.attrNames);
|
|
81
|
-
const scanParams = Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName, IndexName: options === null || options === void 0 ? void 0 : options.indexName, Limit: options === null || options === void 0 ? void 0 : options.
|
|
81
|
+
const scanParams = Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName, IndexName: options === null || options === void 0 ? void 0 : options.indexName, Limit: (options === null || options === void 0 ? void 0 : options.limit) === null ? undefined : options === null || options === void 0 ? void 0 : options.limit }, ((options === null || options === void 0 ? void 0 : options.filter) && Object.assign({ FilterExpression: options.filter.filterExpression }, (options.filter.attrValues && {
|
|
82
82
|
ExpressionAttributeValues: options.filter.attrValues,
|
|
83
83
|
})))), (Object.keys(expressionAttributeNames).length > 0 && {
|
|
84
84
|
ExpressionAttributeNames: expressionAttributeNames,
|
|
@@ -281,7 +281,7 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
|
|
|
281
281
|
const executeParams = {
|
|
282
282
|
Statement: statement,
|
|
283
283
|
Parameters: parameters,
|
|
284
|
-
Limit: params.limit,
|
|
284
|
+
Limit: params.limit === null ? undefined : params.limit,
|
|
285
285
|
NextToken: nextToken,
|
|
286
286
|
};
|
|
287
287
|
const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ExecuteStatementCommand(executeParams)), 'batchQueryDynamo:' + JSON.stringify(params), {
|
|
@@ -309,7 +309,7 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
|
|
|
309
309
|
function queryWithGenerator(params) {
|
|
310
310
|
return __asyncGenerator(this, arguments, function* queryWithGenerator_1() {
|
|
311
311
|
var _a;
|
|
312
|
-
const
|
|
312
|
+
const limit = params.limit === null ? undefined : ((_a = params.limit) !== null && _a !== void 0 ? _a : 100);
|
|
313
313
|
let items = [];
|
|
314
314
|
let lastEvaluatedKey = params.exclusiveStartKey;
|
|
315
315
|
try {
|
|
@@ -318,9 +318,13 @@ function queryWithGenerator(params) {
|
|
|
318
318
|
if (result.Items) {
|
|
319
319
|
items.push(...result.Items);
|
|
320
320
|
// Process items in chunks of BATCH_SIZE
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
if (!limit) {
|
|
322
|
+
yield yield __await(items);
|
|
323
|
+
return yield __await(void 0);
|
|
324
|
+
}
|
|
325
|
+
while (items.length >= limit) {
|
|
326
|
+
const batch = items.slice(0, limit);
|
|
327
|
+
items = items.slice(limit);
|
|
324
328
|
yield yield __await(batch);
|
|
325
329
|
}
|
|
326
330
|
}
|
|
@@ -339,7 +343,7 @@ function queryWithGenerator(params) {
|
|
|
339
343
|
function scanWithGenerator(tableName, options) {
|
|
340
344
|
return __asyncGenerator(this, arguments, function* scanWithGenerator_1() {
|
|
341
345
|
var _a;
|
|
342
|
-
const
|
|
346
|
+
const limit = (options === null || options === void 0 ? void 0 : options.limit) === null ? undefined : ((_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 100);
|
|
343
347
|
let items = [];
|
|
344
348
|
let exclusiveStartKey;
|
|
345
349
|
try {
|
|
@@ -347,10 +351,14 @@ function scanWithGenerator(tableName, options) {
|
|
|
347
351
|
const result = yield __await(executeScan(tableName, options, exclusiveStartKey));
|
|
348
352
|
if (result.Items) {
|
|
349
353
|
items.push(...result.Items);
|
|
350
|
-
// Process items in chunks of
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
+
// Process items in chunks of limit
|
|
355
|
+
if (!limit) {
|
|
356
|
+
yield yield __await(items);
|
|
357
|
+
return yield __await(void 0);
|
|
358
|
+
}
|
|
359
|
+
while (items.length >= limit) {
|
|
360
|
+
const batch = items.slice(0, limit);
|
|
361
|
+
items = items.slice(limit);
|
|
354
362
|
yield yield __await(batch);
|
|
355
363
|
}
|
|
356
364
|
}
|
|
@@ -25,6 +25,7 @@ export interface ScanOptions {
|
|
|
25
25
|
filter?: DynamoFilter;
|
|
26
26
|
requiredAttributeList?: string[];
|
|
27
27
|
indexName?: string;
|
|
28
|
+
limit?: number | null;
|
|
28
29
|
maxRetries?: number | null;
|
|
29
30
|
}
|
|
30
31
|
export interface DynamoQueryParams {
|
|
@@ -36,7 +37,7 @@ export interface DynamoQueryParams {
|
|
|
36
37
|
skValue?: string | number | [string | number, string | number];
|
|
37
38
|
skOperator?: '=' | '<' | '>' | '<=' | '>=' | 'BETWEEN' | 'BEGINS_WITH';
|
|
38
39
|
indexName?: string;
|
|
39
|
-
limit?: number;
|
|
40
|
+
limit?: number | null;
|
|
40
41
|
filter?: DynamoFilter;
|
|
41
42
|
sortAscending?: boolean;
|
|
42
43
|
/** default 3, set to null to disable retries */
|
|
@@ -48,7 +49,7 @@ export interface DynamoBatchQueryParams {
|
|
|
48
49
|
pkName: string;
|
|
49
50
|
pkValues: (string | number)[];
|
|
50
51
|
indexName?: string;
|
|
51
|
-
limit?: number;
|
|
52
|
+
limit?: number | null;
|
|
52
53
|
filter?: DynamoFilter;
|
|
53
54
|
/** default 3, set to null to disable retries */
|
|
54
55
|
maxRetries?: number | null;
|
package/dist/api/types/aws.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AttributeValue } from '@aws-sdk/client-dynamodb/dist-types/models/models_0';
|
|
2
1
|
export interface APIGatewayProxyResult {
|
|
3
2
|
statusCode: number;
|
|
4
3
|
headers?: {
|
|
@@ -64,13 +63,13 @@ export interface DynamoDBStreamEvent {
|
|
|
64
63
|
dynamodb?: {
|
|
65
64
|
ApproximateCreationDateTime?: number | undefined;
|
|
66
65
|
Keys?: {
|
|
67
|
-
[key: string]:
|
|
66
|
+
[key: string]: any;
|
|
68
67
|
} | undefined;
|
|
69
68
|
NewImage?: {
|
|
70
|
-
[key: string]:
|
|
69
|
+
[key: string]: any;
|
|
71
70
|
} | undefined;
|
|
72
71
|
OldImage?: {
|
|
73
|
-
[key: string]:
|
|
72
|
+
[key: string]: any;
|
|
74
73
|
} | undefined;
|
|
75
74
|
SequenceNumber?: string | undefined;
|
|
76
75
|
SizeBytes?: number | undefined;
|
|
@@ -85,5 +84,5 @@ export interface DynamoDBStreamEvent {
|
|
|
85
84
|
}[];
|
|
86
85
|
}
|
|
87
86
|
export type Key = {
|
|
88
|
-
[key: string]:
|
|
87
|
+
[key: string]: any;
|
|
89
88
|
};
|
package/package.json
CHANGED