@webiny/db-dynamodb 5.18.3-beta.0 → 5.19.0-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/db-dynamodb",
3
- "version": "5.18.3-beta.0",
3
+ "version": "5.19.0-beta.2",
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.18.3-beta.0",
14
- "@webiny/error": "5.18.3-beta.0",
15
- "@webiny/handler": "5.18.3-beta.0",
16
- "@webiny/handler-db": "5.18.3-beta.0",
17
- "@webiny/plugins": "5.18.3-beta.0",
13
+ "@webiny/db": "5.19.0-beta.2",
14
+ "@webiny/error": "5.19.0-beta.2",
15
+ "@webiny/handler": "5.19.0-beta.2",
16
+ "@webiny/handler-db": "5.19.0-beta.2",
17
+ "@webiny/plugins": "5.19.0-beta.2",
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.18.3-beta.0",
28
- "@webiny/project-utils": "^5.18.3-beta.0",
27
+ "@webiny/cli": "^5.19.0-beta.2",
28
+ "@webiny/project-utils": "^5.19.0-beta.2",
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": "eb7a008ad4f5b01f01b7c84d291d1fa0b5ced25b"
44
+ "gitHead": "6817702cc537405b7288c1fc63ee5d40531b4122"
45
45
  }
@@ -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
  });
@@ -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 {};
@@ -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
- const batchReadAll = async params => {
25
- if (params.items.length === 0) {
26
- return [];
35
+ if (!result || !result.Responses) {
36
+ return records;
27
37
  }
28
38
 
29
- const items = [];
30
- const result = await params.table.batchGet(params.items);
39
+ records.push(...flatten(result.Responses));
31
40
 
32
- if (result.Responses) {
33
- items.push(...flatten(result.Responses));
41
+ if (!result.next || typeof result.next !== "function") {
42
+ return records;
34
43
  }
35
44
 
36
- if (typeof result.next === "function") {
37
- let previous = result;
38
- let nextResult;
45
+ let previous = result;
39
46
 
40
- while (nextResult = await previous.next()) {
41
- if (!nextResult) {
42
- return items;
43
- }
47
+ while (typeof previous.next === "function") {
48
+ const nextResult = await previous.next();
44
49
 
45
- items.push(...flatten(nextResult.Responses));
50
+ if (!nextResult) {
51
+ return records;
52
+ }
46
53
 
47
- if (!nextResult || typeof nextResult.next !== "function") {
48
- return items;
49
- }
54
+ records.push(...flatten(nextResult.Responses));
55
+ previous = nextResult;
56
+ }
50
57
 
51
- previous = nextResult;
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 items;
86
+ return records;
56
87
  };
57
88
 
58
89
  exports.batchReadAll = batchReadAll;