@webiny/db-dynamodb 6.3.0-beta.4 → 6.4.0-beta.0
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/DynamoDbDriver.js +204 -209
- package/DynamoDbDriver.js.map +1 -1
- package/exports/api/db.js +0 -2
- package/feature/FilterUtil/FilterUtil.js +18 -20
- package/feature/FilterUtil/FilterUtil.js.map +1 -1
- package/feature/FilterUtil/abstractions/FilterUtil.js +2 -1
- package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -1
- package/feature/FilterUtil/createFilters.js +82 -120
- package/feature/FilterUtil/createFilters.js.map +1 -1
- package/feature/FilterUtil/extractWhereArgs.js +15 -19
- package/feature/FilterUtil/extractWhereArgs.js.map +1 -1
- package/feature/FilterUtil/feature.js +6 -5
- package/feature/FilterUtil/feature.js.map +1 -1
- package/feature/FilterUtil/index.js +0 -2
- package/feature/ValueFilter/ValueFilterRegistry.js +21 -17
- package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -1
- package/feature/ValueFilter/abstractions/ValueFilter.js +2 -1
- package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -1
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +2 -1
- package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -1
- package/feature/ValueFilter/feature.js +17 -16
- package/feature/ValueFilter/feature.js.map +1 -1
- package/feature/ValueFilter/filters/AndInFilter.js +19 -23
- package/feature/ValueFilter/filters/AndInFilter.js.map +1 -1
- package/feature/ValueFilter/filters/BetweenFilter.js +23 -25
- package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -1
- package/feature/ValueFilter/filters/ContainsFilter.js +34 -53
- package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -1
- package/feature/ValueFilter/filters/EqFilter.js +17 -27
- package/feature/ValueFilter/filters/EqFilter.js.map +1 -1
- package/feature/ValueFilter/filters/FuzzyFilter.js +30 -30
- package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -1
- package/feature/ValueFilter/filters/GtFilter.js +16 -16
- package/feature/ValueFilter/filters/GtFilter.js.map +1 -1
- package/feature/ValueFilter/filters/GteFilter.js +16 -16
- package/feature/ValueFilter/filters/GteFilter.js.map +1 -1
- package/feature/ValueFilter/filters/InFilter.js +19 -23
- package/feature/ValueFilter/filters/InFilter.js.map +1 -1
- package/feature/ValueFilter/filters/LtFilter.js +16 -16
- package/feature/ValueFilter/filters/LtFilter.js.map +1 -1
- package/feature/ValueFilter/filters/LteFilter.js +16 -16
- package/feature/ValueFilter/filters/LteFilter.js.map +1 -1
- package/feature/ValueFilter/filters/StartsWithFilter.js +20 -36
- package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -1
- package/feature/ValueFilter/index.js +0 -2
- package/index.js +7 -9
- package/index.js.map +1 -1
- package/package.json +13 -13
- package/plugins/definitions/DateTimeTransformPlugin.js +18 -30
- package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/FieldPlugin.js +34 -37
- package/plugins/definitions/FieldPlugin.js.map +1 -1
- package/plugins/definitions/TimeTransformPlugin.js +25 -37
- package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
- package/plugins/definitions/ValueTransformPlugin.js +18 -17
- package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
- package/plugins/definitions/assignFields.js +14 -18
- package/plugins/definitions/assignFields.js.map +1 -1
- package/plugins/index.js +0 -2
- package/store/entity.js +6 -9
- package/store/entity.js.map +1 -1
- package/store/keys.js +6 -13
- package/store/keys.js.map +1 -1
- package/store/types.js +0 -3
- package/toolbox.js +0 -5
- package/types.js +0 -3
- package/utils/batch/batchRead.js +37 -56
- package/utils/batch/batchRead.js.map +1 -1
- package/utils/batch/batchWrite.js +33 -51
- package/utils/batch/batchWrite.js.map +1 -1
- package/utils/batch/index.js +0 -2
- package/utils/batch/types.js +0 -3
- package/utils/cleanup.js +35 -25
- package/utils/cleanup.js.map +1 -1
- package/utils/count.js +8 -14
- package/utils/count.js.map +1 -1
- package/utils/createEntity.d.ts +1 -1
- package/utils/createEntity.js +75 -78
- package/utils/createEntity.js.map +1 -1
- package/utils/createTable.js +25 -35
- package/utils/createTable.js.map +1 -1
- package/utils/cursor.js +7 -10
- package/utils/cursor.js.map +1 -1
- package/utils/delete.js +6 -8
- package/utils/delete.js.map +1 -1
- package/utils/entity/Entity.js +85 -90
- package/utils/entity/Entity.js.map +1 -1
- package/utils/entity/EntityReadBatch.js +23 -31
- package/utils/entity/EntityReadBatch.js.map +1 -1
- package/utils/entity/EntityReadBatchBuilder.js +12 -15
- package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
- package/utils/entity/EntityWriteBatch.js +34 -41
- package/utils/entity/EntityWriteBatch.js.map +1 -1
- package/utils/entity/EntityWriteBatchBuilder.js +15 -16
- package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
- package/utils/entity/getEntity.js +8 -9
- package/utils/entity/getEntity.js.map +1 -1
- package/utils/entity/index.js +0 -2
- package/utils/entity/types.js +0 -4
- package/utils/get.js +12 -26
- package/utils/get.js.map +1 -1
- package/utils/index.js +1 -3
- package/utils/put.js +7 -9
- package/utils/put.js.map +1 -1
- package/utils/query.js +77 -129
- package/utils/query.js.map +1 -1
- package/utils/scan.js +47 -73
- package/utils/scan.js.map +1 -1
- package/utils/sort.js +37 -61
- package/utils/sort.js.map +1 -1
- package/utils/table/Table.js +22 -21
- package/utils/table/Table.js.map +1 -1
- package/utils/table/TableReadBatch.js +37 -45
- package/utils/table/TableReadBatch.js.map +1 -1
- package/utils/table/TableWriteBatch.js +47 -56
- package/utils/table/TableWriteBatch.js.map +1 -1
- package/utils/table/index.js +0 -2
- package/utils/table/types.js +0 -3
- package/exports/api/db.js.map +0 -1
- package/feature/FilterUtil/index.js.map +0 -1
- package/feature/ValueFilter/index.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/store/types.js.map +0 -1
- package/toolbox.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/batch/index.js.map +0 -1
- package/utils/batch/types.js.map +0 -1
- package/utils/entity/index.js.map +0 -1
- package/utils/entity/types.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/table/index.js.map +0 -1
- package/utils/table/types.js.map +0 -1
package/store/keys.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
key
|
|
6
|
-
}) => {
|
|
7
|
-
if (typeof key === "symbol") {
|
|
8
|
-
return key.toString();
|
|
9
|
-
}
|
|
10
|
-
return String(key);
|
|
11
|
-
};
|
|
12
|
-
export const createType = () => {
|
|
13
|
-
return "internal";
|
|
1
|
+
const createPartitionKey = ()=>"W#internal";
|
|
2
|
+
const createSortKey = ({ key })=>{
|
|
3
|
+
if ("symbol" == typeof key) return key.toString();
|
|
4
|
+
return String(key);
|
|
14
5
|
};
|
|
6
|
+
const createType = ()=>"internal";
|
|
7
|
+
export { createPartitionKey, createSortKey, createType };
|
|
15
8
|
|
|
16
9
|
//# sourceMappingURL=keys.js.map
|
package/store/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"store/keys.js","sources":["../../src/store/keys.ts"],"sourcesContent":["export interface IParams {\n key: string | number | symbol;\n}\n\nexport const createPartitionKey = () => {\n return `W#internal`;\n};\n\nexport const createSortKey = ({ key }: IParams) => {\n if (typeof key === \"symbol\") {\n return key.toString();\n }\n return String(key);\n};\n\nexport const createType = () => {\n return \"internal\";\n};\n"],"names":["createPartitionKey","createSortKey","key","String","createType"],"mappings":"AAIO,MAAMA,qBAAqB,IACvB;AAGJ,MAAMC,gBAAgB,CAAC,EAAEC,GAAG,EAAW;IAC1C,IAAI,AAAe,YAAf,OAAOA,KACP,OAAOA,IAAI,QAAQ;IAEvB,OAAOC,OAAOD;AAClB;AAEO,MAAME,aAAa,IACf"}
|
package/store/types.js
CHANGED
package/toolbox.js
CHANGED
package/types.js
CHANGED
package/utils/batch/batchRead.js
CHANGED
|
@@ -1,64 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import chunk from "lodash/chunk.js";
|
|
2
|
+
import error from "@webiny/error";
|
|
3
3
|
const MAX_BATCH_ITEMS = 100;
|
|
4
|
-
const flatten = responses
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
entries
|
|
9
|
-
}
|
|
10
|
-
return entries;
|
|
4
|
+
const flatten = (responses)=>{
|
|
5
|
+
const entries = [];
|
|
6
|
+
const values = Object.values(responses);
|
|
7
|
+
for (const items of values)entries.push(...items);
|
|
8
|
+
return entries;
|
|
11
9
|
};
|
|
12
|
-
const batchReadAllChunk = async params
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return records;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!result.next || typeof result.next !== "function") {
|
|
27
|
-
return records;
|
|
28
|
-
}
|
|
29
|
-
let previous = result;
|
|
30
|
-
while (typeof previous.next === "function") {
|
|
31
|
-
const nextResult = await previous.next();
|
|
32
|
-
if (!nextResult) {
|
|
33
|
-
return records;
|
|
10
|
+
const batchReadAllChunk = async (params)=>{
|
|
11
|
+
const { table, items } = params;
|
|
12
|
+
const records = [];
|
|
13
|
+
if (!table) return records;
|
|
14
|
+
const result = await table.batchGet(items);
|
|
15
|
+
if (!result || !result.Responses) return records;
|
|
16
|
+
records.push(...flatten(result.Responses));
|
|
17
|
+
if (!result.next || "function" != typeof result.next) return records;
|
|
18
|
+
let previous = result;
|
|
19
|
+
while("function" == typeof previous.next){
|
|
20
|
+
const nextResult = await previous.next();
|
|
21
|
+
if (!nextResult) break;
|
|
22
|
+
records.push(...flatten(nextResult.Responses));
|
|
23
|
+
previous = nextResult;
|
|
34
24
|
}
|
|
35
|
-
records
|
|
36
|
-
previous = nextResult;
|
|
37
|
-
}
|
|
38
|
-
return records;
|
|
25
|
+
return records;
|
|
39
26
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
|
|
45
|
-
if (params.items.length === 0) {
|
|
46
|
-
return [];
|
|
47
|
-
} else if (maxChunk > MAX_BATCH_ITEMS) {
|
|
48
|
-
throw new WebinyError(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
|
|
49
|
-
maxChunk
|
|
27
|
+
const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS)=>{
|
|
28
|
+
if (0 === params.items.length) return [];
|
|
29
|
+
if (maxChunk > MAX_BATCH_ITEMS) throw new error(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
|
|
30
|
+
maxChunk
|
|
50
31
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return records;
|
|
32
|
+
const records = [];
|
|
33
|
+
const chunkItemsList = chunk(params.items, maxChunk);
|
|
34
|
+
for (const chunkItems of chunkItemsList){
|
|
35
|
+
const results = await batchReadAllChunk({
|
|
36
|
+
table: params.table,
|
|
37
|
+
items: chunkItems
|
|
38
|
+
});
|
|
39
|
+
records.push(...results);
|
|
40
|
+
}
|
|
41
|
+
return records;
|
|
62
42
|
};
|
|
43
|
+
export { batchReadAll };
|
|
63
44
|
|
|
64
45
|
//# sourceMappingURL=batchRead.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/batch/batchRead.js","sources":["../../../src/utils/batch/batchRead.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface BatchReadItem {\n Table?: TableDef;\n Key: any;\n}\nexport interface BatchReadParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\n\nconst MAX_BATCH_ITEMS = 100;\n\nconst flatten = (responses: Record<string, any[]>): any[] => {\n const entries = [];\n const values = Object.values(responses);\n for (const items of values) {\n entries.push(...items);\n }\n return entries;\n};\n\ninterface BatchReadAllChunkParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\nconst batchReadAllChunk = async <T = any>(params: BatchReadAllChunkParams): Promise<T[]> => {\n const { table, items } = params;\n const records: T[] = [];\n\n if (!table) {\n return records;\n }\n\n const result = await table.batchGet(items);\n if (!result || !result.Responses) {\n return records;\n }\n records.push(...flatten(result.Responses));\n if (!result.next || typeof result.next !== \"function\") {\n return records;\n }\n let previous = result;\n while (typeof previous.next === \"function\") {\n const nextResult = await previous.next();\n if (!nextResult) {\n return records;\n }\n records.push(...flatten(nextResult.Responses));\n previous = nextResult;\n }\n return records;\n};\n/**\n * This helper function is meant to be used to batch read from one table.\n * It will fetch all results, as there is a next() method call built in.\n */\nexport const batchReadAll = async <T = GenericRecord>(\n params: BatchReadParams,\n maxChunk = MAX_BATCH_ITEMS\n): Promise<T[]> => {\n if (params.items.length === 0) {\n return [];\n } else if (maxChunk > MAX_BATCH_ITEMS) {\n throw new WebinyError(\n `Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`,\n \"DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR\",\n {\n maxChunk\n }\n );\n }\n\n const records: T[] = [];\n\n const chunkItemsList = lodashChunk(params.items, maxChunk);\n\n for (const chunkItems of chunkItemsList) {\n const results = await batchReadAllChunk<T>({\n table: params.table,\n items: chunkItems\n });\n\n records.push(...results);\n }\n\n return records;\n};\n"],"names":["MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","batchReadAllChunk","params","table","records","result","previous","nextResult","batchReadAll","maxChunk","WebinyError","chunkItemsList","lodashChunk","chunkItems","results"],"mappings":";;AAcA,MAAMA,kBAAkB;AAExB,MAAMC,UAAU,CAACC;IACb,MAAMC,UAAU,EAAE;IAClB,MAAMC,SAASC,OAAO,MAAM,CAACH;IAC7B,KAAK,MAAMI,SAASF,OAChBD,QAAQ,IAAI,IAAIG;IAEpB,OAAOH;AACX;AAMA,MAAMI,oBAAoB,OAAgBC;IACtC,MAAM,EAAEC,KAAK,EAAEH,KAAK,EAAE,GAAGE;IACzB,MAAME,UAAe,EAAE;IAEvB,IAAI,CAACD,OACD,OAAOC;IAGX,MAAMC,SAAS,MAAMF,MAAM,QAAQ,CAACH;IACpC,IAAI,CAACK,UAAU,CAACA,OAAO,SAAS,EAC5B,OAAOD;IAEXA,QAAQ,IAAI,IAAIT,QAAQU,OAAO,SAAS;IACxC,IAAI,CAACA,OAAO,IAAI,IAAI,AAAuB,cAAvB,OAAOA,OAAO,IAAI,EAClC,OAAOD;IAEX,IAAIE,WAAWD;IACf,MAAO,AAAyB,cAAzB,OAAOC,SAAS,IAAI,CAAiB;QACxC,MAAMC,aAAa,MAAMD,SAAS,IAAI;QACtC,IAAI,CAACC,YACD;QAEJH,QAAQ,IAAI,IAAIT,QAAQY,WAAW,SAAS;QAC5CD,WAAWC;IACf;IACA,OAAOH;AACX;AAKO,MAAMI,eAAe,OACxBN,QACAO,WAAWf,eAAe;IAE1B,IAAIQ,AAAwB,MAAxBA,OAAO,KAAK,CAAC,MAAM,EACnB,OAAO,EAAE;IACN,IAAIO,WAAWf,iBAClB,MAAM,IAAIgB,MACN,CAAC,6BAA6B,EAAEhB,gBAAgB,iCAAiC,CAAC,EAClF,sCACA;QACIe;IACJ;IAIR,MAAML,UAAe,EAAE;IAEvB,MAAMO,iBAAiBC,MAAYV,OAAO,KAAK,EAAEO;IAEjD,KAAK,MAAMI,cAAcF,eAAgB;QACrC,MAAMG,UAAU,MAAMb,kBAAqB;YACvC,OAAOC,OAAO,KAAK;YACnB,OAAOW;QACX;QAEAT,QAAQ,IAAI,IAAIU;IACpB;IAEA,OAAOV;AACX"}
|
|
@@ -1,57 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
const hasUnprocessedItems = result
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return keys.some(key => {
|
|
12
|
-
const value = items[key];
|
|
13
|
-
if (!Array.isArray(value)) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return value.some(val => {
|
|
17
|
-
return val.PutRequest || val.DeleteRequest;
|
|
1
|
+
import chunk from "lodash/chunk.js";
|
|
2
|
+
const hasUnprocessedItems = (result)=>{
|
|
3
|
+
if ("function" != typeof result.next) return false;
|
|
4
|
+
const items = result.UnprocessedItems;
|
|
5
|
+
if (!items || "object" != typeof items) return false;
|
|
6
|
+
const keys = Object.keys(items);
|
|
7
|
+
return keys.some((key)=>{
|
|
8
|
+
const value = items[key];
|
|
9
|
+
if (!Array.isArray(value)) return false;
|
|
10
|
+
return value.some((val)=>val.PutRequest || val.DeleteRequest);
|
|
18
11
|
});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const retry = async (input, results) => {
|
|
22
|
-
if (!hasUnprocessedItems(input)) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const result = await input.next();
|
|
26
|
-
await retry(result, results);
|
|
27
12
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* It can either delete or put items
|
|
32
|
-
* The method does not check items before actually sending them into the underlying library.
|
|
33
|
-
*/
|
|
34
|
-
export const batchWriteAll = async (params, maxChunk = 25) => {
|
|
35
|
-
const {
|
|
36
|
-
items: collection,
|
|
37
|
-
table
|
|
38
|
-
} = params;
|
|
39
|
-
if (!table) {
|
|
40
|
-
console.log("No table provided.");
|
|
41
|
-
return [];
|
|
42
|
-
} else if (collection.length === 0) {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
const chunkedItems = lodashChunk(collection, maxChunk);
|
|
46
|
-
const results = [];
|
|
47
|
-
for (const items of chunkedItems) {
|
|
48
|
-
const result = await table.batchWrite(items, {
|
|
49
|
-
execute: true
|
|
50
|
-
});
|
|
51
|
-
results.push(result);
|
|
13
|
+
const retry = async (input, results)=>{
|
|
14
|
+
if (!hasUnprocessedItems(input)) return;
|
|
15
|
+
const result = await input.next();
|
|
52
16
|
await retry(result, results);
|
|
53
|
-
}
|
|
54
|
-
return results;
|
|
55
17
|
};
|
|
18
|
+
const batchWriteAll = async (params, maxChunk = 25)=>{
|
|
19
|
+
const { items: collection, table } = params;
|
|
20
|
+
if (table) {
|
|
21
|
+
if (0 === collection.length) return [];
|
|
22
|
+
} else {
|
|
23
|
+
console.log("No table provided.");
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const chunkedItems = chunk(collection, maxChunk);
|
|
27
|
+
const results = [];
|
|
28
|
+
for (const items of chunkedItems){
|
|
29
|
+
const result = await table.batchWrite(items, {
|
|
30
|
+
execute: true
|
|
31
|
+
});
|
|
32
|
+
results.push(result);
|
|
33
|
+
await retry(result, results);
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
36
|
+
};
|
|
37
|
+
export { batchWriteAll };
|
|
56
38
|
|
|
57
39
|
//# sourceMappingURL=batchWrite.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/batch/batchWrite.js","sources":["../../../src/utils/batch/batchWrite.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { BatchWriteItem, BatchWriteResponse, BatchWriteResult } from \"./types.js\";\n\nexport interface BatchWriteParams {\n table: TableDef | undefined;\n items: BatchWriteItem[];\n}\n\nconst hasUnprocessedItems = (result: BatchWriteResponse): boolean => {\n if (typeof result.next !== \"function\") {\n return false;\n }\n const items = result.UnprocessedItems;\n if (!items || typeof items !== \"object\") {\n return false;\n }\n const keys = Object.keys(items);\n return keys.some(key => {\n const value = items[key];\n if (!Array.isArray(value)) {\n return false;\n }\n return value.some(val => {\n return val.PutRequest || val.DeleteRequest;\n });\n });\n};\n\nconst retry = async (input: BatchWriteResponse, results: BatchWriteResult): Promise<void> => {\n if (!hasUnprocessedItems(input)) {\n return;\n }\n const result = await input.next!();\n await retry(result, results);\n};\n/**\n * Method is meant for batch writing to a single table.\n * It expects already prepared items for writing.\n * It can either delete or put items\n * The method does not check items before actually sending them into the underlying library.\n */\nexport const batchWriteAll = async (\n params: BatchWriteParams,\n maxChunk = 25\n): Promise<BatchWriteResult> => {\n const { items: collection, table } = params;\n if (!table) {\n console.log(\"No table provided.\");\n return [];\n } else if (collection.length === 0) {\n return [];\n }\n\n const chunkedItems: BatchWriteItem[][] = lodashChunk(collection, maxChunk);\n const results: BatchWriteResult = [];\n for (const items of chunkedItems) {\n const result = (await table.batchWrite(items, {\n execute: true\n })) as BatchWriteResponse;\n results.push(result);\n await retry(result, results);\n }\n return results;\n};\n"],"names":["hasUnprocessedItems","result","items","keys","Object","key","value","Array","val","retry","input","results","batchWriteAll","params","maxChunk","collection","table","console","chunkedItems","lodashChunk"],"mappings":";AASA,MAAMA,sBAAsB,CAACC;IACzB,IAAI,AAAuB,cAAvB,OAAOA,OAAO,IAAI,EAClB,OAAO;IAEX,MAAMC,QAAQD,OAAO,gBAAgB;IACrC,IAAI,CAACC,SAAS,AAAiB,YAAjB,OAAOA,OACjB,OAAO;IAEX,MAAMC,OAAOC,OAAO,IAAI,CAACF;IACzB,OAAOC,KAAK,IAAI,CAACE,CAAAA;QACb,MAAMC,QAAQJ,KAAK,CAACG,IAAI;QACxB,IAAI,CAACE,MAAM,OAAO,CAACD,QACf,OAAO;QAEX,OAAOA,MAAM,IAAI,CAACE,CAAAA,MACPA,IAAI,UAAU,IAAIA,IAAI,aAAa;IAElD;AACJ;AAEA,MAAMC,QAAQ,OAAOC,OAA2BC;IAC5C,IAAI,CAACX,oBAAoBU,QACrB;IAEJ,MAAMT,SAAS,MAAMS,MAAM,IAAI;IAC/B,MAAMD,MAAMR,QAAQU;AACxB;AAOO,MAAMC,gBAAgB,OACzBC,QACAC,WAAW,EAAE;IAEb,MAAM,EAAE,OAAOC,UAAU,EAAEC,KAAK,EAAE,GAAGH;IACrC,IAAKG,OAGE;QAAA,IAAID,AAAsB,MAAtBA,WAAW,MAAM,EACxB,OAAO,EAAE;IACb,OALY;QACRE,QAAQ,GAAG,CAAC;QACZ,OAAO,EAAE;IACb;IAIA,MAAMC,eAAmCC,MAAYJ,YAAYD;IACjE,MAAMH,UAA4B,EAAE;IACpC,KAAK,MAAMT,SAASgB,aAAc;QAC9B,MAAMjB,SAAU,MAAMe,MAAM,UAAU,CAACd,OAAO;YAC1C,SAAS;QACb;QACAS,QAAQ,IAAI,CAACV;QACb,MAAMQ,MAAMR,QAAQU;IACxB;IACA,OAAOA;AACX"}
|
package/utils/batch/index.js
CHANGED
package/utils/batch/types.js
CHANGED
package/utils/cleanup.js
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
const attributesToRemove = [
|
|
2
|
+
"PK",
|
|
3
|
+
"SK",
|
|
4
|
+
"created",
|
|
5
|
+
"_ct",
|
|
6
|
+
"modified",
|
|
7
|
+
"_mt",
|
|
8
|
+
"entity",
|
|
9
|
+
"_et",
|
|
10
|
+
"GSI1_PK",
|
|
11
|
+
"GSI1_SK",
|
|
12
|
+
"GSI2_PK",
|
|
13
|
+
"GSI2_SK",
|
|
14
|
+
"GSI3_PK",
|
|
15
|
+
"GSI3_SK",
|
|
16
|
+
"GSI4_PK",
|
|
17
|
+
"GSI4_SK",
|
|
18
|
+
"GSI5_PK",
|
|
19
|
+
"GSI5_SK",
|
|
20
|
+
"GSI_TENANT",
|
|
21
|
+
"TYPE"
|
|
22
|
+
];
|
|
23
|
+
function cleanupItem(entity, item, removeAttributes = []) {
|
|
24
|
+
if (!item) return null;
|
|
25
|
+
const newItem = {
|
|
26
|
+
...item
|
|
27
|
+
};
|
|
28
|
+
const targets = attributesToRemove.concat(removeAttributes);
|
|
29
|
+
const attributes = entity.schema.attributes;
|
|
30
|
+
for(const key in item)if (false !== item.hasOwnProperty(key)) {
|
|
31
|
+
if (!attributes[key] || false !== targets.includes(key)) delete newItem[key];
|
|
18
32
|
}
|
|
19
|
-
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
delete newItem[key];
|
|
23
|
-
}
|
|
24
|
-
return newItem;
|
|
33
|
+
return newItem;
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
function cleanupItems(entity, items, removeAttributes = []) {
|
|
36
|
+
return items.map((item)=>cleanupItem(entity, item, removeAttributes));
|
|
28
37
|
}
|
|
38
|
+
export { cleanupItem, cleanupItems };
|
|
29
39
|
|
|
30
40
|
//# sourceMappingURL=cleanup.js.map
|
package/utils/cleanup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/cleanup.js","sources":["../../src/utils/cleanup.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\n\n/**\n * The attributes defined by us or the dynamodb-toolbox library.\n * Add more attributes if necessary.\n */\nconst attributesToRemove = [\n \"PK\",\n \"SK\",\n \"created\",\n \"_ct\",\n \"modified\",\n \"_mt\",\n \"entity\",\n \"_et\",\n \"GSI1_PK\",\n \"GSI1_SK\",\n \"GSI2_PK\",\n \"GSI2_SK\",\n \"GSI3_PK\",\n \"GSI3_SK\",\n \"GSI4_PK\",\n \"GSI4_SK\",\n \"GSI5_PK\",\n \"GSI5_SK\",\n \"GSI_TENANT\",\n \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: T | null,\n removeAttributes: string[] = []\n): T | null {\n if (!item) {\n return null;\n }\n const newItem = {\n ...item\n };\n const targets = attributesToRemove.concat(removeAttributes);\n const attributes = entity.schema.attributes;\n for (const key in item) {\n if (item.hasOwnProperty(key) === false) {\n continue;\n }\n if (attributes[key] && targets.includes(key) === false) {\n continue;\n }\n delete newItem[key];\n }\n return newItem;\n}\n\nexport function cleanupItems<T>(\n entity: Entity<any>,\n items: T[],\n removeAttributes: string[] = []\n): T[] {\n return items.map(item => cleanupItem<T>(entity, item, removeAttributes) as T);\n}\n"],"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","attributes","key","cleanupItems","items"],"mappings":"AAMA,MAAMA,qBAAqB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAEM,SAASC,YACZC,MAAmB,EACnBC,IAAe,EACfC,mBAA6B,EAAE;IAE/B,IAAI,CAACD,MACD,OAAO;IAEX,MAAME,UAAU;QACZ,GAAGF,IAAI;IACX;IACA,MAAMG,UAAUN,mBAAmB,MAAM,CAACI;IAC1C,MAAMG,aAAaL,OAAO,MAAM,CAAC,UAAU;IAC3C,IAAK,MAAMM,OAAOL,KACd,IAAIA,AAA6B,UAA7BA,KAAK,cAAc,CAACK,MAGxB;QAAA,IAAID,CAAAA,UAAU,CAACC,IAAI,IAAIF,AAA0B,UAA1BA,QAAQ,QAAQ,CAACE,MAGxC,OAAOH,OAAO,CAACG,IAAI;IADnB;IAGJ,OAAOH;AACX;AAEO,SAASI,aACZP,MAAmB,EACnBQ,KAAU,EACVN,mBAA6B,EAAE;IAE/B,OAAOM,MAAM,GAAG,CAACP,CAAAA,OAAQF,YAAeC,QAAQC,MAAMC;AAC1D"}
|
package/utils/count.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
entity,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
Count
|
|
10
|
-
} = await entity.query(partitionKey, {
|
|
11
|
-
...options,
|
|
12
|
-
select: "count"
|
|
13
|
-
});
|
|
14
|
-
return Count || 0;
|
|
1
|
+
const count = async (params)=>{
|
|
2
|
+
const { entity, partitionKey, options = {} } = params;
|
|
3
|
+
const { Count } = await entity.query(partitionKey, {
|
|
4
|
+
...options,
|
|
5
|
+
select: "count"
|
|
6
|
+
});
|
|
7
|
+
return Count || 0;
|
|
15
8
|
};
|
|
9
|
+
export { count };
|
|
16
10
|
|
|
17
11
|
//# sourceMappingURL=count.js.map
|
package/utils/count.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/count.js","sources":["../../src/utils/count.ts"],"sourcesContent":["import type { QueryAllParams } from \"~/utils/query.js\";\n\nexport const count = async (params: QueryAllParams): Promise<number> => {\n const { entity, partitionKey, options = {} } = params;\n // @ts-expect-error\n const { Count } = await entity.query(partitionKey, { ...options, select: \"count\" });\n return Count || 0;\n};\n"],"names":["count","params","entity","partitionKey","options","Count"],"mappings":"AAEO,MAAMA,QAAQ,OAAOC;IACxB,MAAM,EAAEC,MAAM,EAAEC,YAAY,EAAEC,UAAU,CAAC,CAAC,EAAE,GAAGH;IAE/C,MAAM,EAAEI,KAAK,EAAE,GAAG,MAAMH,OAAO,KAAK,CAACC,cAAc;QAAE,GAAGC,OAAO;QAAE,QAAQ;IAAQ;IACjF,OAAOC,SAAS;AACpB"}
|
package/utils/createEntity.d.ts
CHANGED
package/utils/createEntity.js
CHANGED
|
@@ -1,85 +1,82 @@
|
|
|
1
1
|
import { createEntity } from "./entity/index.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
export const createGlobalEntity = params => {
|
|
33
|
-
return createEntity({
|
|
34
|
-
...params,
|
|
35
|
-
attributes: {
|
|
36
|
-
...globalEntityAttributes,
|
|
37
|
-
...params.attributes
|
|
2
|
+
const globalEntityAttributes = {
|
|
3
|
+
PK: {
|
|
4
|
+
partitionKey: true
|
|
5
|
+
},
|
|
6
|
+
SK: {
|
|
7
|
+
sortKey: true
|
|
8
|
+
},
|
|
9
|
+
GSI1_PK: {
|
|
10
|
+
type: "string"
|
|
11
|
+
},
|
|
12
|
+
GSI1_SK: {
|
|
13
|
+
type: "string"
|
|
14
|
+
},
|
|
15
|
+
GSI2_PK: {
|
|
16
|
+
type: "string"
|
|
17
|
+
},
|
|
18
|
+
GSI2_SK: {
|
|
19
|
+
type: "string"
|
|
20
|
+
},
|
|
21
|
+
TYPE: {
|
|
22
|
+
type: "string",
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
data: {
|
|
26
|
+
type: "map"
|
|
27
|
+
},
|
|
28
|
+
expiresAt: {
|
|
29
|
+
type: "number"
|
|
38
30
|
}
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
export const standardEntityAttributes = {
|
|
42
|
-
PK: {
|
|
43
|
-
partitionKey: true
|
|
44
|
-
},
|
|
45
|
-
SK: {
|
|
46
|
-
sortKey: true
|
|
47
|
-
},
|
|
48
|
-
GSI_TENANT: {
|
|
49
|
-
type: "string",
|
|
50
|
-
required: true
|
|
51
|
-
},
|
|
52
|
-
GSI1_PK: {
|
|
53
|
-
type: "string"
|
|
54
|
-
},
|
|
55
|
-
GSI1_SK: {
|
|
56
|
-
type: "string"
|
|
57
|
-
},
|
|
58
|
-
GSI2_PK: {
|
|
59
|
-
type: "string"
|
|
60
|
-
},
|
|
61
|
-
GSI2_SK: {
|
|
62
|
-
type: "string"
|
|
63
|
-
},
|
|
64
|
-
TYPE: {
|
|
65
|
-
type: "string",
|
|
66
|
-
required: true
|
|
67
|
-
},
|
|
68
|
-
data: {
|
|
69
|
-
type: "map"
|
|
70
|
-
},
|
|
71
|
-
expiresAt: {
|
|
72
|
-
type: "number"
|
|
73
|
-
}
|
|
74
31
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
32
|
+
const createGlobalEntity = (params)=>createEntity({
|
|
33
|
+
...params,
|
|
34
|
+
attributes: {
|
|
35
|
+
...globalEntityAttributes,
|
|
36
|
+
...params.attributes
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const standardEntityAttributes = {
|
|
40
|
+
PK: {
|
|
41
|
+
partitionKey: true
|
|
42
|
+
},
|
|
43
|
+
SK: {
|
|
44
|
+
sortKey: true
|
|
45
|
+
},
|
|
46
|
+
GSI_TENANT: {
|
|
47
|
+
type: "string",
|
|
48
|
+
required: true
|
|
49
|
+
},
|
|
50
|
+
GSI1_PK: {
|
|
51
|
+
type: "string"
|
|
52
|
+
},
|
|
53
|
+
GSI1_SK: {
|
|
54
|
+
type: "string"
|
|
55
|
+
},
|
|
56
|
+
GSI2_PK: {
|
|
57
|
+
type: "string"
|
|
58
|
+
},
|
|
59
|
+
GSI2_SK: {
|
|
60
|
+
type: "string"
|
|
61
|
+
},
|
|
62
|
+
TYPE: {
|
|
63
|
+
type: "string",
|
|
64
|
+
required: true
|
|
65
|
+
},
|
|
66
|
+
data: {
|
|
67
|
+
type: "map"
|
|
68
|
+
},
|
|
69
|
+
expiresAt: {
|
|
70
|
+
type: "number"
|
|
81
71
|
}
|
|
82
|
-
});
|
|
83
72
|
};
|
|
73
|
+
const createStandardEntity = (params)=>createEntity({
|
|
74
|
+
...params,
|
|
75
|
+
attributes: {
|
|
76
|
+
...standardEntityAttributes,
|
|
77
|
+
...params.attributes
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
export { createGlobalEntity, createStandardEntity, globalEntityAttributes, standardEntityAttributes };
|
|
84
81
|
|
|
85
82
|
//# sourceMappingURL=createEntity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/createEntity.js","sources":["../../src/utils/createEntity.ts"],"sourcesContent":["import type { AttributeDefinitions } from \"~/toolbox.js\";\nimport { createEntity, type EntityConstructor } from \"~/utils/entity/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport type IGlobalEntityAttributes<T = undefined> = {\n PK: string;\n SK: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n GSI2_PK?: string;\n GSI2_SK?: string;\n expiresAt?: number | null;\n} & (T extends undefined ? { data?: undefined } : { data: T });\n\nexport const globalEntityAttributes: AttributeDefinitions = {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n GSI2_PK: {\n type: \"string\"\n },\n GSI2_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\",\n required: true\n },\n data: {\n type: \"map\"\n },\n expiresAt: {\n type: \"number\"\n }\n};\n\nexport const createGlobalEntity = <T extends GenericRecord = GenericRecord>(\n params: Omit<EntityConstructor, \"attributes\"> & Partial<Pick<EntityConstructor, \"attributes\">>\n) => {\n return createEntity<IGlobalEntityAttributes<T>>({\n ...params,\n attributes: {\n ...globalEntityAttributes,\n ...params.attributes\n }\n });\n};\n\nexport type IStandardEntityAttributes<T = undefined> = {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n GSI2_PK?: string;\n GSI2_SK?: string;\n expiresAt?: number | null;\n} & (T extends undefined ? { data?: undefined } : { data: T });\n\nexport const standardEntityAttributes: AttributeDefinitions = {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI_TENANT: {\n type: \"string\",\n required: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n GSI2_PK: {\n type: \"string\"\n },\n GSI2_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\",\n required: true\n },\n data: {\n type: \"map\"\n },\n expiresAt: {\n type: \"number\"\n }\n};\n\nexport const createStandardEntity = <T extends GenericRecord = GenericRecord>(\n params: Omit<EntityConstructor, \"attributes\"> & Partial<Pick<EntityConstructor, \"attributes\">>\n) => {\n return createEntity<IStandardEntityAttributes<T>>({\n ...params,\n attributes: {\n ...standardEntityAttributes,\n ...params.attributes\n }\n });\n};\n"],"names":["globalEntityAttributes","createGlobalEntity","params","createEntity","standardEntityAttributes","createStandardEntity"],"mappings":";AAeO,MAAMA,yBAA+C;IACxD,IAAI;QACA,cAAc;IAClB;IACA,IAAI;QACA,SAAS;IACb;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,MAAM;QACF,MAAM;QACN,UAAU;IACd;IACA,MAAM;QACF,MAAM;IACV;IACA,WAAW;QACP,MAAM;IACV;AACJ;AAEO,MAAMC,qBAAqB,CAC9BC,SAEOC,aAAyC;QAC5C,GAAGD,MAAM;QACT,YAAY;YACR,GAAGF,sBAAsB;YACzB,GAAGE,OAAO,UAAU;QACxB;IACJ;AAeG,MAAME,2BAAiD;IAC1D,IAAI;QACA,cAAc;IAClB;IACA,IAAI;QACA,SAAS;IACb;IACA,YAAY;QACR,MAAM;QACN,UAAU;IACd;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,MAAM;QACF,MAAM;QACN,UAAU;IACd;IACA,MAAM;QACF,MAAM;IACV;IACA,WAAW;QACP,MAAM;IACV;AACJ;AAEO,MAAMC,uBAAuB,CAChCH,SAEOC,aAA2C;QAC9C,GAAGD,MAAM;QACT,YAAY;YACR,GAAGE,wBAAwB;YAC3B,GAAGF,OAAO,UAAU;QACxB;IACJ"}
|