@webiny/db-dynamodb 5.18.2 → 5.19.0-beta.1
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.
- package/BatchProcess.d.ts +1 -1
- package/package.json +9 -9
- package/plugins/filters/eq.js +13 -0
- package/utils/batchRead.d.ts +1 -1
- package/utils/batchRead.js +56 -25
package/BatchProcess.d.ts
CHANGED
|
@@ -26,6 +26,6 @@ declare class BatchProcess {
|
|
|
26
26
|
addBatchDelete(args: any): () => any;
|
|
27
27
|
addBatchGet(args: any): () => any;
|
|
28
28
|
allOperationsAdded(): boolean;
|
|
29
|
-
startExecution(): import("aws-sdk/lib/request").Request<DocumentClient.
|
|
29
|
+
startExecution(): import("aws-sdk/lib/request").Request<DocumentClient.BatchWriteItemOutput, import("aws-sdk/lib/error").AWSError> | import("aws-sdk/lib/request").Request<DocumentClient.BatchGetItemOutput, import("aws-sdk/lib/error").AWSError>;
|
|
30
30
|
}
|
|
31
31
|
export default BatchProcess;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/db-dynamodb",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.19.0-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/db": "5.
|
|
14
|
-
"@webiny/error": "5.
|
|
15
|
-
"@webiny/handler": "5.
|
|
16
|
-
"@webiny/handler-db": "5.
|
|
17
|
-
"@webiny/plugins": "5.
|
|
13
|
+
"@webiny/db": "5.19.0-beta.1",
|
|
14
|
+
"@webiny/error": "5.19.0-beta.1",
|
|
15
|
+
"@webiny/handler": "5.19.0-beta.1",
|
|
16
|
+
"@webiny/handler-db": "5.19.0-beta.1",
|
|
17
|
+
"@webiny/plugins": "5.19.0-beta.1",
|
|
18
18
|
"date-fns": "2.25.0",
|
|
19
19
|
"dot-prop": "6.0.1",
|
|
20
20
|
"fuse.js": "6.4.6",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "^7.5.5",
|
|
26
26
|
"@babel/core": "^7.5.5",
|
|
27
|
-
"@webiny/cli": "^5.
|
|
28
|
-
"@webiny/project-utils": "^5.
|
|
27
|
+
"@webiny/cli": "^5.19.0-beta.1",
|
|
28
|
+
"@webiny/project-utils": "^5.19.0-beta.1",
|
|
29
29
|
"dynamodb-toolbox": "^0.3.4",
|
|
30
30
|
"jest": "^26.6.3",
|
|
31
31
|
"jest-dynalite": "^3.2.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"build": "yarn webiny run build",
|
|
42
42
|
"watch": "yarn webiny run watch"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "dd406fbad0620ecce47063e9afbff40c502c3844"
|
|
45
45
|
}
|
package/plugins/filters/eq.js
CHANGED
|
@@ -13,6 +13,19 @@ var _default = new _ValueFilterPlugin.ValueFilterPlugin({
|
|
|
13
13
|
value,
|
|
14
14
|
compareValue
|
|
15
15
|
}) => {
|
|
16
|
+
/**
|
|
17
|
+
* Possibility that either input value or one from the system is array.
|
|
18
|
+
*/
|
|
19
|
+
if (Array.isArray(value) === true) {
|
|
20
|
+
return value.some(v => {
|
|
21
|
+
return Array.isArray(compareValue) ? compareValue.includes(v) : compareValue === v;
|
|
22
|
+
});
|
|
23
|
+
} else if (Array.isArray(compareValue) === true) {
|
|
24
|
+
return compareValue.every(v => {
|
|
25
|
+
return value === v;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
return value === compareValue;
|
|
17
30
|
}
|
|
18
31
|
});
|
package/utils/batchRead.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ interface Params {
|
|
|
11
11
|
* This helper function is meant to be used to batch read from one table.
|
|
12
12
|
* It will fetch all results, as there is a next() method call built in.
|
|
13
13
|
*/
|
|
14
|
-
export declare const batchReadAll: <T = any>(params: Params) => Promise<T[]>;
|
|
14
|
+
export declare const batchReadAll: <T = any>(params: Params, maxChunk?: number) => Promise<T[]>;
|
|
15
15
|
export {};
|
package/utils/batchRead.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.batchReadAll = void 0;
|
|
7
9
|
|
|
10
|
+
var _chunk = _interopRequireDefault(require("lodash/chunk"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
const MAX_BATCH_ITEMS = 100;
|
|
15
|
+
|
|
8
16
|
const flatten = responses => {
|
|
9
17
|
const entries = [];
|
|
10
18
|
const values = Object.values(responses);
|
|
@@ -15,44 +23,67 @@ const flatten = responses => {
|
|
|
15
23
|
|
|
16
24
|
return entries;
|
|
17
25
|
};
|
|
18
|
-
/**
|
|
19
|
-
* This helper function is meant to be used to batch read from one table.
|
|
20
|
-
* It will fetch all results, as there is a next() method call built in.
|
|
21
|
-
*/
|
|
22
26
|
|
|
27
|
+
const batchReadAllChunk = async params => {
|
|
28
|
+
const {
|
|
29
|
+
table,
|
|
30
|
+
items
|
|
31
|
+
} = params;
|
|
32
|
+
const records = [];
|
|
33
|
+
const result = await table.batchGet(items);
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return [];
|
|
35
|
+
if (!result || !result.Responses) {
|
|
36
|
+
return records;
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
const result = await params.table.batchGet(params.items);
|
|
39
|
+
records.push(...flatten(result.Responses));
|
|
31
40
|
|
|
32
|
-
if (result.
|
|
33
|
-
|
|
41
|
+
if (!result.next || typeof result.next !== "function") {
|
|
42
|
+
return records;
|
|
34
43
|
}
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
let previous = result;
|
|
38
|
-
let nextResult;
|
|
45
|
+
let previous = result;
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return items;
|
|
43
|
-
}
|
|
47
|
+
while (typeof previous.next === "function") {
|
|
48
|
+
const nextResult = await previous.next();
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
if (!nextResult) {
|
|
51
|
+
return records;
|
|
52
|
+
}
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
records.push(...flatten(nextResult.Responses));
|
|
55
|
+
previous = nextResult;
|
|
56
|
+
}
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
return records;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* This helper function is meant to be used to batch read from one table.
|
|
62
|
+
* It will fetch all results, as there is a next() method call built in.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
|
|
67
|
+
if (params.items.length === 0) {
|
|
68
|
+
return [];
|
|
69
|
+
} else if (maxChunk > MAX_BATCH_ITEMS) {
|
|
70
|
+
throw new _error.default(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
|
|
71
|
+
maxChunk
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const records = [];
|
|
76
|
+
const chunkItemsList = (0, _chunk.default)(params.items, maxChunk);
|
|
77
|
+
|
|
78
|
+
for (const chunkItems of chunkItemsList) {
|
|
79
|
+
const results = await batchReadAllChunk({
|
|
80
|
+
table: params.table,
|
|
81
|
+
items: chunkItems
|
|
82
|
+
});
|
|
83
|
+
records.push(...results);
|
|
53
84
|
}
|
|
54
85
|
|
|
55
|
-
return
|
|
86
|
+
return records;
|
|
56
87
|
};
|
|
57
88
|
|
|
58
89
|
exports.batchReadAll = batchReadAll;
|