ag-common 0.0.479 → 0.0.481

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.
@@ -23,7 +23,9 @@ const log_1 = require("../../common/helpers/log");
23
23
  const sleep_1 = require("../../common/helpers/sleep");
24
24
  const setDynamo = (region) => {
25
25
  let raw = new client_dynamodb_1.DynamoDBClient({ region });
26
- const ddbDocClient = lib_dynamodb_1.DynamoDBDocument.from(raw);
26
+ const ddbDocClient = lib_dynamodb_1.DynamoDBDocument.from(raw, {
27
+ marshallOptions: { removeUndefinedValues: true },
28
+ });
27
29
  return ddbDocClient;
28
30
  };
29
31
  exports.setDynamo = setDynamo;
@@ -10,4 +10,7 @@ export declare function asyncForEach<T>(array: T[], callback: (i: T, index: numb
10
10
  * @param callback
11
11
  * @returns
12
12
  */
13
- export declare function asyncMap<T, TY>(array: T[], callback: (i: T, index: number, array: T[]) => Promise<TY>): Promise<TY[]>;
13
+ export declare function asyncMap<T, TY>(array: T[], callback: (i: T, index: number, array: T[]) => Promise<TY>, opt?: {
14
+ /** default 1 */
15
+ maxConcurrency?: number;
16
+ }): Promise<TY[]>;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.asyncMap = exports.asyncForEach = void 0;
13
+ const array_1 = require("./array");
13
14
  /**
14
15
  * run async forEach over all array items
15
16
  * @param array
@@ -29,11 +30,20 @@ exports.asyncForEach = asyncForEach;
29
30
  * @param callback
30
31
  * @returns
31
32
  */
32
- function asyncMap(array, callback) {
33
+ function asyncMap(array, callback, opt) {
34
+ var _a;
33
35
  return __awaiter(this, void 0, void 0, function* () {
34
36
  const ret = [];
35
- for (let index = 0; index < array.length; index += 1) {
36
- ret.push(yield callback(array[index], index, array));
37
+ const maxConcurrency = (_a = opt === null || opt === void 0 ? void 0 : opt.maxConcurrency) !== null && _a !== void 0 ? _a : 1;
38
+ let rem = array;
39
+ let start = 0;
40
+ while (rem.length > 0) {
41
+ const { rest, part } = (0, array_1.take)(rem, maxConcurrency);
42
+ rem = rest;
43
+ const proms = part.map((p, i) => callback(p, start + i, array));
44
+ start += part.length;
45
+ const res = yield Promise.all(proms);
46
+ ret.push(...res);
37
47
  }
38
48
  return ret;
39
49
  });
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.479",
2
+ "version": "0.0.481",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",