ag-common 0.0.803 → 0.0.804
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.
|
@@ -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: params.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 === -1 ? 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.limit) ===
|
|
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) === -1 ? 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,
|
|
@@ -128,24 +128,25 @@ const queryDynamo = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
128
128
|
try {
|
|
129
129
|
const items = [];
|
|
130
130
|
let lastEvaluatedKey = params.exclusiveStartKey;
|
|
131
|
+
const hasLimit = params.limit && params.limit > 0;
|
|
131
132
|
do {
|
|
132
133
|
const result = yield executeQuery(params, lastEvaluatedKey);
|
|
133
134
|
if (result.Items) {
|
|
134
135
|
items.push(...result.Items);
|
|
135
136
|
}
|
|
136
137
|
lastEvaluatedKey = result.LastEvaluatedKey;
|
|
137
|
-
// If we
|
|
138
|
-
|
|
138
|
+
// If limit is undefined, we stop after one query (default to single page).
|
|
139
|
+
// This satisfies: "other never endlessly query" (unless limit is -1).
|
|
140
|
+
if (params.limit === undefined || params.limit === null) {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
// If limit is > 0 and we've reached it, stop processing
|
|
144
|
+
if (hasLimit && items.length >= params.limit) {
|
|
139
145
|
return {
|
|
140
146
|
data: items.slice(0, params.limit),
|
|
141
147
|
lastEvaluatedKey,
|
|
142
148
|
};
|
|
143
149
|
}
|
|
144
|
-
// If a start key was provided but no limit, we don't want to endlessly page
|
|
145
|
-
// so we stop after the first batch
|
|
146
|
-
if (params.exclusiveStartKey && !params.limit) {
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
150
|
} while (lastEvaluatedKey && Object.keys(lastEvaluatedKey).length > 0);
|
|
150
151
|
return { data: items, lastEvaluatedKey };
|
|
151
152
|
}
|
|
@@ -164,8 +165,20 @@ const scan = (tableName, options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
164
165
|
Items.push(...result.Items);
|
|
165
166
|
}
|
|
166
167
|
ExclusiveStartKey = result.LastEvaluatedKey;
|
|
168
|
+
// If limit is undefined, we stop after one query (default to single page).
|
|
169
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) === undefined) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
if ((options === null || options === void 0 ? void 0 : options.limit) &&
|
|
173
|
+
options.limit > 0 &&
|
|
174
|
+
Items.length >= options.limit) {
|
|
175
|
+
return {
|
|
176
|
+
data: Items.slice(0, options.limit),
|
|
177
|
+
lastEvaluatedKey: ExclusiveStartKey,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
167
180
|
} while (ExclusiveStartKey);
|
|
168
|
-
return { data: Items };
|
|
181
|
+
return { data: Items, lastEvaluatedKey: ExclusiveStartKey };
|
|
169
182
|
}
|
|
170
183
|
catch (e) {
|
|
171
184
|
return { error: e.toString() };
|
|
@@ -281,7 +294,7 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
|
|
|
281
294
|
const executeParams = {
|
|
282
295
|
Statement: statement,
|
|
283
296
|
Parameters: parameters,
|
|
284
|
-
Limit: params.limit ===
|
|
297
|
+
Limit: params.limit === -1 ? undefined : params.limit,
|
|
285
298
|
NextToken: nextToken,
|
|
286
299
|
};
|
|
287
300
|
const result = yield (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.ExecuteStatementCommand(executeParams)), 'batchQueryDynamo:' + JSON.stringify(params), {
|
|
@@ -309,7 +322,7 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
|
|
|
309
322
|
function queryWithGenerator(params) {
|
|
310
323
|
return __asyncGenerator(this, arguments, function* queryWithGenerator_1() {
|
|
311
324
|
var _a;
|
|
312
|
-
const limit =
|
|
325
|
+
const limit = (_a = params.limit) !== null && _a !== void 0 ? _a : 100;
|
|
313
326
|
let items = [];
|
|
314
327
|
let lastEvaluatedKey = params.exclusiveStartKey;
|
|
315
328
|
try {
|
|
@@ -343,7 +356,7 @@ function queryWithGenerator(params) {
|
|
|
343
356
|
function scanWithGenerator(tableName, options) {
|
|
344
357
|
return __asyncGenerator(this, arguments, function* scanWithGenerator_1() {
|
|
345
358
|
var _a;
|
|
346
|
-
const limit = (
|
|
359
|
+
const limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 100;
|
|
347
360
|
let items = [];
|
|
348
361
|
let exclusiveStartKey;
|
|
349
362
|
try {
|
|
@@ -25,8 +25,17 @@ export interface ScanOptions {
|
|
|
25
25
|
filter?: DynamoFilter;
|
|
26
26
|
requiredAttributeList?: string[];
|
|
27
27
|
indexName?: string;
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* - number > 0: Limit the total number of items returned.
|
|
30
|
+
* - -1: Endlessly query until all items are retrieved.
|
|
31
|
+
* - null | undefined: Fetch only a single page (one network request).
|
|
32
|
+
*/
|
|
33
|
+
limit?: number;
|
|
29
34
|
maxRetries?: number | null;
|
|
35
|
+
/**
|
|
36
|
+
* The key to start/resume from.
|
|
37
|
+
*/
|
|
38
|
+
exclusiveStartKey?: Key;
|
|
30
39
|
}
|
|
31
40
|
export interface DynamoQueryParams {
|
|
32
41
|
tableName: string;
|
|
@@ -37,11 +46,19 @@ export interface DynamoQueryParams {
|
|
|
37
46
|
skValue?: string | number | [string | number, string | number];
|
|
38
47
|
skOperator?: '=' | '<' | '>' | '<=' | '>=' | 'BETWEEN' | 'BEGINS_WITH';
|
|
39
48
|
indexName?: string;
|
|
40
|
-
|
|
49
|
+
/**
|
|
50
|
+
* - number > 0: Limit the total number of items returned.
|
|
51
|
+
* - -1: Endlessly query until all items are retrieved.
|
|
52
|
+
* - null | undefined: Fetch only a single page (one network request).
|
|
53
|
+
*/
|
|
54
|
+
limit?: number;
|
|
41
55
|
filter?: DynamoFilter;
|
|
42
56
|
sortAscending?: boolean;
|
|
43
57
|
/** default 3, set to null to disable retries */
|
|
44
58
|
maxRetries?: number | null;
|
|
59
|
+
/**
|
|
60
|
+
* The key to start/resume from.
|
|
61
|
+
*/
|
|
45
62
|
exclusiveStartKey?: Key;
|
|
46
63
|
}
|
|
47
64
|
export interface DynamoBatchQueryParams {
|
|
@@ -49,7 +66,7 @@ export interface DynamoBatchQueryParams {
|
|
|
49
66
|
pkName: string;
|
|
50
67
|
pkValues: (string | number)[];
|
|
51
68
|
indexName?: string;
|
|
52
|
-
limit?: number
|
|
69
|
+
limit?: number;
|
|
53
70
|
filter?: DynamoFilter;
|
|
54
71
|
/** default 3, set to null to disable retries */
|
|
55
72
|
maxRetries?: number | null;
|
package/package.json
CHANGED