ag-common 0.0.802 → 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
- BATCH_SIZE: 100, // Process in chunks of 100 items
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
- /** how many to return in query generator. default 100 */
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, _e;
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: (_e = params.BATCH_SIZE) !== null && _e !== void 0 ? _e : params.limit, IndexName: params.indexName, ExclusiveStartKey: exclusiveStartKey }, (params.filter && Object.assign({ FilterExpression: params.filter.filterExpression }, (params.filter.attrValues && {
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.BATCH_SIZE }, ((options === null || options === void 0 ? void 0 : options.filter) && Object.assign({ FilterExpression: options.filter.filterExpression }, (options.filter.attrValues && {
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 BATCH_SIZE = (_a = params.BATCH_SIZE) !== null && _a !== void 0 ? _a : 100;
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
- while (items.length >= BATCH_SIZE) {
322
- const batch = items.slice(0, BATCH_SIZE);
323
- items = items.slice(BATCH_SIZE);
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 BATCH_SIZE = (_a = options === null || options === void 0 ? void 0 : options.BATCH_SIZE) !== null && _a !== void 0 ? _a : 100;
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 BATCH_SIZE
351
- while (items.length >= BATCH_SIZE) {
352
- const batch = items.slice(0, BATCH_SIZE);
353
- items = items.slice(BATCH_SIZE);
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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.802",
2
+ "version": "0.0.803",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",