@contrail/util 1.0.52 → 1.0.54
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.
|
@@ -11,6 +11,16 @@ interface CacheOptions {
|
|
|
11
11
|
cacheName: string;
|
|
12
12
|
}
|
|
13
13
|
export declare function getAllWithCaching<T>(getAllFunc: () => Promise<T[]>, options: CacheOptions): Promise<T[]>;
|
|
14
|
+
declare type DyanmoQuery = {
|
|
15
|
+
TableName: string;
|
|
16
|
+
ExpressionAttributeValues: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
FilterExpression: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function scanDynamo(query: DyanmoQuery): AsyncGenerator<{
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}[]>;
|
|
14
24
|
export declare function pushData<T>(data: DynamoDBItem<T>[], tableName: string): Promise<void>;
|
|
15
25
|
export declare function flattenDynamoItem<T>(item: DynamoDBItem<T>): FlatDynamoItem<T>;
|
|
16
26
|
export {};
|
|
@@ -44,7 +44,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
44
44
|
return t;
|
|
45
45
|
};
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.flattenDynamoItem = exports.pushData = exports.getAllWithCaching = exports.getAll = void 0;
|
|
47
|
+
exports.flattenDynamoItem = exports.pushData = exports.scanDynamo = exports.getAllWithCaching = exports.getAll = void 0;
|
|
48
48
|
const aws = require('aws-sdk');
|
|
49
49
|
const ddt = require('dynamodb-data-types');
|
|
50
50
|
const fs_1 = require("fs");
|
|
@@ -146,6 +146,7 @@ function scanDynamo(query) {
|
|
|
146
146
|
} while (lastEvaluatedKey);
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
|
+
exports.scanDynamo = scanDynamo;
|
|
149
150
|
function pushData(data, tableName) {
|
|
150
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
152
|
const ddb = new aws.DynamoDB({ apiVersion: '2012-08-10', region: 'us-east-1' });
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -22,3 +22,4 @@ __exportStar(require("./app-util/app-util"), exports);
|
|
|
22
22
|
__exportStar(require("./timer-util/timer-util"), exports);
|
|
23
23
|
__exportStar(require("./dynamodb-util"), exports);
|
|
24
24
|
__exportStar(require("./file-util/file-util"), exports);
|
|
25
|
+
__exportStar(require("./promise-util/promise-util"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare class PromiseUtil {
|
|
2
|
+
static resolveInChunks(objects: Array<any>, chunksSize: number, asyncFunction: (chunk: any) => Promise<any>): Promise<any>;
|
|
3
|
+
static resolveInChunksAndLimit(objects: Array<any>, chunksSize: number, limitSize: number, asyncFunction: (chunk: any) => Promise<any>): Promise<any>;
|
|
4
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PromiseUtil = void 0;
|
|
13
|
+
const p_limit_1 = require("p-limit");
|
|
14
|
+
const lodash_1 = require("lodash");
|
|
15
|
+
class PromiseUtil {
|
|
16
|
+
static resolveInChunks(objects, chunksSize, asyncFunction) {
|
|
17
|
+
const chunks = (0, lodash_1.chunk)(objects, chunksSize);
|
|
18
|
+
const promises = [];
|
|
19
|
+
for (const chunk of chunks) {
|
|
20
|
+
promises.push(asyncFunction(chunk));
|
|
21
|
+
}
|
|
22
|
+
return Promise.all(promises).then((chunkedResults) => chunkedResults.flat());
|
|
23
|
+
}
|
|
24
|
+
static resolveInChunksAndLimit(objects, chunksSize, limitSize, asyncFunction) {
|
|
25
|
+
const limit = (0, p_limit_1.default)(limitSize);
|
|
26
|
+
const chunks = (0, lodash_1.chunk)(objects, chunksSize);
|
|
27
|
+
const promises = [];
|
|
28
|
+
for (const chunk of chunks) {
|
|
29
|
+
const promise = limit(() => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return yield asyncFunction(chunk);
|
|
31
|
+
}));
|
|
32
|
+
promises.push(promise);
|
|
33
|
+
}
|
|
34
|
+
return Promise.all(promises).then((chunkedResults) => chunkedResults.flat());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.PromiseUtil = PromiseUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.54",
|
|
4
4
|
"description": "General javascript utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@contrail/types": "^3.0.74",
|
|
42
42
|
"aws-sdk": "^2.1692.0",
|
|
43
|
-
"dynamodb-data-types": "^4.0.1"
|
|
43
|
+
"dynamodb-data-types": "^4.0.1",
|
|
44
|
+
"lodash": "^4.17.21"
|
|
44
45
|
}
|
|
45
46
|
}
|