ag-common 0.0.805 → 0.0.807

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.
@@ -136,8 +136,7 @@ const queryDynamo = (params) => __awaiter(void 0, void 0, void 0, function* () {
136
136
  }
137
137
  lastEvaluatedKey = result.LastEvaluatedKey;
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) {
139
+ if (params.limit === undefined) {
141
140
  break;
142
141
  }
143
142
  // If limit is > 0 and we've reached it, stop processing
@@ -169,9 +168,8 @@ const scan = (tableName, options) => __awaiter(void 0, void 0, void 0, function*
169
168
  if ((options === null || options === void 0 ? void 0 : options.limit) === undefined) {
170
169
  break;
171
170
  }
172
- if ((options === null || options === void 0 ? void 0 : options.limit) &&
173
- options.limit > 0 &&
174
- Items.length >= options.limit) {
171
+ const limit = options.limit;
172
+ if (limit > 0 && Items.length >= limit) {
175
173
  return {
176
174
  data: Items.slice(0, options.limit),
177
175
  lastEvaluatedKey: ExclusiveStartKey,
@@ -245,7 +243,7 @@ const batchQueryDynamo = (params) => __awaiter(void 0, void 0, void 0, function*
245
243
  allItems.push(...result.data);
246
244
  totalProcessed += result.data.length;
247
245
  // If we have a limit and we've reached it, stop processing
248
- if (params.limit && totalProcessed >= params.limit) {
246
+ if (params.limit && params.limit > 0 && totalProcessed >= params.limit) {
249
247
  return {
250
248
  data: allItems.slice(0, params.limit),
251
249
  };
@@ -305,7 +303,7 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
305
303
  }
306
304
  nextToken = result.NextToken;
307
305
  // If we have a limit and we've reached it, stop processing
308
- if (params.limit && allItems.length >= params.limit) {
306
+ if (params.limit && params.limit > 0 && allItems.length >= params.limit) {
309
307
  return {
310
308
  data: allItems.slice(0, params.limit),
311
309
  };
@@ -321,8 +319,10 @@ const executePartiQLQuery = (params) => __awaiter(void 0, void 0, void 0, functi
321
319
  });
322
320
  function queryWithGenerator(params) {
323
321
  return __asyncGenerator(this, arguments, function* queryWithGenerator_1() {
324
- var _a;
325
- const limit = (_a = params.limit) !== null && _a !== void 0 ? _a : 100;
322
+ let limit = undefined;
323
+ if (params.limit && params.limit !== -1) {
324
+ limit = params.limit;
325
+ }
326
326
  let items = [];
327
327
  let lastEvaluatedKey = params.exclusiveStartKey;
328
328
  try {
@@ -333,12 +333,17 @@ function queryWithGenerator(params) {
333
333
  // Process items in chunks of BATCH_SIZE
334
334
  if (!limit) {
335
335
  yield yield __await(items);
336
- return yield __await(void 0);
336
+ items = [];
337
+ if (params.limit !== -1) {
338
+ return yield __await(void 0);
339
+ }
337
340
  }
338
- while (items.length >= limit) {
339
- const batch = items.slice(0, limit);
340
- items = items.slice(limit);
341
- yield yield __await(batch);
341
+ else {
342
+ while (items.length >= limit) {
343
+ const batch = items.slice(0, limit);
344
+ items = items.slice(limit);
345
+ yield yield __await(batch);
346
+ }
342
347
  }
343
348
  }
344
349
  lastEvaluatedKey = result.LastEvaluatedKey;
@@ -355,8 +360,10 @@ function queryWithGenerator(params) {
355
360
  }
356
361
  function scanWithGenerator(tableName, options) {
357
362
  return __asyncGenerator(this, arguments, function* scanWithGenerator_1() {
358
- var _a;
359
- const limit = (_a = options === null || options === void 0 ? void 0 : options.limit) !== null && _a !== void 0 ? _a : 100;
363
+ let limit = undefined;
364
+ if ((options === null || options === void 0 ? void 0 : options.limit) && options.limit !== -1) {
365
+ limit = options.limit;
366
+ }
360
367
  let items = [];
361
368
  let exclusiveStartKey;
362
369
  try {
@@ -367,12 +374,17 @@ function scanWithGenerator(tableName, options) {
367
374
  // Process items in chunks of limit
368
375
  if (!limit) {
369
376
  yield yield __await(items);
370
- return yield __await(void 0);
377
+ items = [];
378
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== -1) {
379
+ return yield __await(void 0);
380
+ }
371
381
  }
372
- while (items.length >= limit) {
373
- const batch = items.slice(0, limit);
374
- items = items.slice(limit);
375
- yield yield __await(batch);
382
+ else {
383
+ while (items.length >= limit) {
384
+ const batch = items.slice(0, limit);
385
+ items = items.slice(limit);
386
+ yield yield __await(batch);
387
+ }
376
388
  }
377
389
  }
378
390
  exclusiveStartKey = result.LastEvaluatedKey;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.805",
2
+ "version": "0.0.807",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",