ag-common 0.0.726 → 0.0.727
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.
|
@@ -27,7 +27,6 @@ interface ScanOptions {
|
|
|
27
27
|
*/
|
|
28
28
|
filter?: DynamoFilter;
|
|
29
29
|
requiredAttributeList?: string[];
|
|
30
|
-
limit?: number;
|
|
31
30
|
}
|
|
32
31
|
interface DynamoQueryParams {
|
|
33
32
|
tableName: string;
|
|
@@ -57,7 +56,10 @@ export declare const batchDelete: (params: {
|
|
|
57
56
|
pkName: string;
|
|
58
57
|
}) => Promise<DynamoDBResult<void>>;
|
|
59
58
|
export declare const scan: <T>(tableName: string, options?: ScanOptions) => Promise<DynamoDBResult<T[]>>;
|
|
60
|
-
export declare function scanWithGenerator<T>(tableName: string, options?: ScanOptions
|
|
59
|
+
export declare function scanWithGenerator<T>(tableName: string, options?: ScanOptions & {
|
|
60
|
+
/** how many to return in scan generator. default 100 */
|
|
61
|
+
BATCH_SIZE?: number;
|
|
62
|
+
}): AsyncGenerator<T[], void, unknown>;
|
|
61
63
|
export declare const getItemsDynamo: <T>(params: {
|
|
62
64
|
tableName: string;
|
|
63
65
|
items: {
|
|
@@ -131,7 +131,7 @@ const scan = (tableName, options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
131
131
|
}, {});
|
|
132
132
|
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);
|
|
133
133
|
do {
|
|
134
|
-
const params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign(Object.assign(
|
|
134
|
+
const params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName }, ((options === null || options === void 0 ? void 0 : options.filter) && Object.assign({ FilterExpression: options.filter.filterExpression }, (options.filter.attrValues && {
|
|
135
135
|
ExpressionAttributeValues: options.filter.attrValues,
|
|
136
136
|
})))), (Object.keys(expressionAttributeNames).length > 0 && {
|
|
137
137
|
ExpressionAttributeNames: expressionAttributeNames,
|
|
@@ -139,22 +139,14 @@ const scan = (tableName, options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
139
139
|
ProjectionExpression: options.requiredAttributeList
|
|
140
140
|
.map((_, index) => `#proj${index}`)
|
|
141
141
|
.join(', '),
|
|
142
|
-
})), { ExclusiveStartKey })
|
|
143
|
-
Items.length < options.limit && {
|
|
144
|
-
Limit: options.limit - Items.length,
|
|
145
|
-
})));
|
|
142
|
+
})), { ExclusiveStartKey }));
|
|
146
143
|
const result = yield withRetry(() => exports.dynamoDb.send(params), 'scan');
|
|
147
144
|
if (result.Items) {
|
|
148
145
|
Items.push(...result.Items);
|
|
149
146
|
}
|
|
150
147
|
ExclusiveStartKey = result.LastEvaluatedKey;
|
|
151
|
-
if ((options === null || options === void 0 ? void 0 : options.limit) && Items.length >= options.limit) {
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
148
|
} while (ExclusiveStartKey);
|
|
155
|
-
return {
|
|
156
|
-
data: (options === null || options === void 0 ? void 0 : options.limit) ? Items.slice(0, options.limit) : Items,
|
|
157
|
-
};
|
|
149
|
+
return { data: Items };
|
|
158
150
|
}
|
|
159
151
|
catch (e) {
|
|
160
152
|
return { error: e.toString() };
|
|
@@ -163,17 +155,16 @@ const scan = (tableName, options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
163
155
|
exports.scan = scan;
|
|
164
156
|
function scanWithGenerator(tableName, options) {
|
|
165
157
|
return __asyncGenerator(this, arguments, function* scanWithGenerator_1() {
|
|
166
|
-
var _a, _b;
|
|
167
|
-
const BATCH_SIZE =
|
|
158
|
+
var _a, _b, _c;
|
|
159
|
+
const BATCH_SIZE = (_a = options === null || options === void 0 ? void 0 : options.BATCH_SIZE) !== null && _a !== void 0 ? _a : 100;
|
|
168
160
|
let items = [];
|
|
169
161
|
let exclusiveStartKey;
|
|
170
|
-
let totalItems = 0;
|
|
171
162
|
try {
|
|
172
|
-
const projectionAttrs = (
|
|
163
|
+
const projectionAttrs = (_b = options === null || options === void 0 ? void 0 : options.requiredAttributeList) === null || _b === void 0 ? void 0 : _b.reduce((acc, attr, index) => {
|
|
173
164
|
acc[`#proj${index}`] = attr;
|
|
174
165
|
return acc;
|
|
175
166
|
}, {});
|
|
176
|
-
const expressionAttributeNames = Object.assign(Object.assign({}, projectionAttrs), (
|
|
167
|
+
const expressionAttributeNames = Object.assign(Object.assign({}, projectionAttrs), (_c = options === null || options === void 0 ? void 0 : options.filter) === null || _c === void 0 ? void 0 : _c.attrNames);
|
|
177
168
|
do {
|
|
178
169
|
const params = new lib_dynamodb_1.ScanCommand(Object.assign(Object.assign(Object.assign(Object.assign({ TableName: tableName, Limit: BATCH_SIZE }, ((options === null || options === void 0 ? void 0 : options.filter) && Object.assign({ FilterExpression: options.filter.filterExpression }, (options.filter.attrValues && {
|
|
179
170
|
ExpressionAttributeValues: options.filter.attrValues,
|
|
@@ -191,30 +182,14 @@ function scanWithGenerator(tableName, options) {
|
|
|
191
182
|
while (items.length >= BATCH_SIZE) {
|
|
192
183
|
const batch = items.slice(0, BATCH_SIZE);
|
|
193
184
|
items = items.slice(BATCH_SIZE);
|
|
194
|
-
totalItems += batch.length;
|
|
195
|
-
// If we've reached the limit, yield the final batch and return
|
|
196
|
-
if ((options === null || options === void 0 ? void 0 : options.limit) && totalItems >= options.limit) {
|
|
197
|
-
const remainingCount = options.limit - (totalItems - batch.length);
|
|
198
|
-
yield yield __await(batch.slice(0, remainingCount));
|
|
199
|
-
return yield __await(void 0);
|
|
200
|
-
}
|
|
201
185
|
yield yield __await(batch);
|
|
202
186
|
}
|
|
203
187
|
}
|
|
204
188
|
exclusiveStartKey = result.LastEvaluatedKey;
|
|
205
|
-
} while (exclusiveStartKey
|
|
206
|
-
(!(options === null || options === void 0 ? void 0 : options.limit) || totalItems < options.limit));
|
|
189
|
+
} while (exclusiveStartKey);
|
|
207
190
|
// Yield any remaining items
|
|
208
191
|
if (items.length > 0) {
|
|
209
|
-
|
|
210
|
-
const remainingCount = options.limit - totalItems;
|
|
211
|
-
if (remainingCount > 0) {
|
|
212
|
-
yield yield __await(items.slice(0, remainingCount));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
yield yield __await(items);
|
|
217
|
-
}
|
|
192
|
+
yield yield __await(items);
|
|
218
193
|
}
|
|
219
194
|
}
|
|
220
195
|
catch (e) {
|
package/package.json
CHANGED