@webiny/db-dynamodb 6.3.0 → 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.
Files changed (132) hide show
  1. package/DynamoDbDriver.js +204 -209
  2. package/DynamoDbDriver.js.map +1 -1
  3. package/exports/api/db.js +0 -2
  4. package/feature/FilterUtil/FilterUtil.js +18 -20
  5. package/feature/FilterUtil/FilterUtil.js.map +1 -1
  6. package/feature/FilterUtil/abstractions/FilterUtil.js +2 -1
  7. package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -1
  8. package/feature/FilterUtil/createFilters.js +82 -120
  9. package/feature/FilterUtil/createFilters.js.map +1 -1
  10. package/feature/FilterUtil/extractWhereArgs.js +15 -19
  11. package/feature/FilterUtil/extractWhereArgs.js.map +1 -1
  12. package/feature/FilterUtil/feature.js +6 -5
  13. package/feature/FilterUtil/feature.js.map +1 -1
  14. package/feature/FilterUtil/index.js +0 -2
  15. package/feature/ValueFilter/ValueFilterRegistry.js +21 -17
  16. package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -1
  17. package/feature/ValueFilter/abstractions/ValueFilter.js +2 -1
  18. package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -1
  19. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +2 -1
  20. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -1
  21. package/feature/ValueFilter/feature.js +17 -16
  22. package/feature/ValueFilter/feature.js.map +1 -1
  23. package/feature/ValueFilter/filters/AndInFilter.js +19 -23
  24. package/feature/ValueFilter/filters/AndInFilter.js.map +1 -1
  25. package/feature/ValueFilter/filters/BetweenFilter.js +23 -25
  26. package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -1
  27. package/feature/ValueFilter/filters/ContainsFilter.js +34 -53
  28. package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -1
  29. package/feature/ValueFilter/filters/EqFilter.js +17 -27
  30. package/feature/ValueFilter/filters/EqFilter.js.map +1 -1
  31. package/feature/ValueFilter/filters/FuzzyFilter.js +30 -30
  32. package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -1
  33. package/feature/ValueFilter/filters/GtFilter.js +16 -16
  34. package/feature/ValueFilter/filters/GtFilter.js.map +1 -1
  35. package/feature/ValueFilter/filters/GteFilter.js +16 -16
  36. package/feature/ValueFilter/filters/GteFilter.js.map +1 -1
  37. package/feature/ValueFilter/filters/InFilter.js +19 -23
  38. package/feature/ValueFilter/filters/InFilter.js.map +1 -1
  39. package/feature/ValueFilter/filters/LtFilter.js +16 -16
  40. package/feature/ValueFilter/filters/LtFilter.js.map +1 -1
  41. package/feature/ValueFilter/filters/LteFilter.js +16 -16
  42. package/feature/ValueFilter/filters/LteFilter.js.map +1 -1
  43. package/feature/ValueFilter/filters/StartsWithFilter.js +20 -36
  44. package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -1
  45. package/feature/ValueFilter/index.js +0 -2
  46. package/index.js +7 -9
  47. package/index.js.map +1 -1
  48. package/package.json +13 -13
  49. package/plugins/definitions/DateTimeTransformPlugin.js +18 -30
  50. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
  51. package/plugins/definitions/FieldPlugin.js +34 -37
  52. package/plugins/definitions/FieldPlugin.js.map +1 -1
  53. package/plugins/definitions/TimeTransformPlugin.js +25 -37
  54. package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
  55. package/plugins/definitions/ValueTransformPlugin.js +18 -17
  56. package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
  57. package/plugins/definitions/assignFields.js +14 -18
  58. package/plugins/definitions/assignFields.js.map +1 -1
  59. package/plugins/index.js +0 -2
  60. package/store/entity.js +6 -9
  61. package/store/entity.js.map +1 -1
  62. package/store/keys.js +6 -13
  63. package/store/keys.js.map +1 -1
  64. package/store/types.js +0 -3
  65. package/toolbox.js +0 -5
  66. package/types.js +0 -3
  67. package/utils/batch/batchRead.js +37 -56
  68. package/utils/batch/batchRead.js.map +1 -1
  69. package/utils/batch/batchWrite.js +33 -51
  70. package/utils/batch/batchWrite.js.map +1 -1
  71. package/utils/batch/index.js +0 -2
  72. package/utils/batch/types.js +0 -3
  73. package/utils/cleanup.js +35 -25
  74. package/utils/cleanup.js.map +1 -1
  75. package/utils/count.js +8 -14
  76. package/utils/count.js.map +1 -1
  77. package/utils/createEntity.d.ts +1 -1
  78. package/utils/createEntity.js +75 -78
  79. package/utils/createEntity.js.map +1 -1
  80. package/utils/createTable.js +25 -35
  81. package/utils/createTable.js.map +1 -1
  82. package/utils/cursor.js +7 -10
  83. package/utils/cursor.js.map +1 -1
  84. package/utils/delete.js +6 -8
  85. package/utils/delete.js.map +1 -1
  86. package/utils/entity/Entity.js +85 -90
  87. package/utils/entity/Entity.js.map +1 -1
  88. package/utils/entity/EntityReadBatch.js +23 -31
  89. package/utils/entity/EntityReadBatch.js.map +1 -1
  90. package/utils/entity/EntityReadBatchBuilder.js +12 -15
  91. package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
  92. package/utils/entity/EntityWriteBatch.js +34 -41
  93. package/utils/entity/EntityWriteBatch.js.map +1 -1
  94. package/utils/entity/EntityWriteBatchBuilder.js +15 -16
  95. package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
  96. package/utils/entity/getEntity.js +8 -9
  97. package/utils/entity/getEntity.js.map +1 -1
  98. package/utils/entity/index.js +0 -2
  99. package/utils/entity/types.js +0 -4
  100. package/utils/get.js +12 -26
  101. package/utils/get.js.map +1 -1
  102. package/utils/index.js +1 -3
  103. package/utils/put.js +7 -9
  104. package/utils/put.js.map +1 -1
  105. package/utils/query.js +77 -129
  106. package/utils/query.js.map +1 -1
  107. package/utils/scan.js +47 -73
  108. package/utils/scan.js.map +1 -1
  109. package/utils/sort.js +37 -61
  110. package/utils/sort.js.map +1 -1
  111. package/utils/table/Table.js +22 -21
  112. package/utils/table/Table.js.map +1 -1
  113. package/utils/table/TableReadBatch.js +37 -45
  114. package/utils/table/TableReadBatch.js.map +1 -1
  115. package/utils/table/TableWriteBatch.js +47 -56
  116. package/utils/table/TableWriteBatch.js.map +1 -1
  117. package/utils/table/index.js +0 -2
  118. package/utils/table/types.js +0 -3
  119. package/exports/api/db.js.map +0 -1
  120. package/feature/FilterUtil/index.js.map +0 -1
  121. package/feature/ValueFilter/index.js.map +0 -1
  122. package/plugins/index.js.map +0 -1
  123. package/store/types.js.map +0 -1
  124. package/toolbox.js.map +0 -1
  125. package/types.js.map +0 -1
  126. package/utils/batch/index.js.map +0 -1
  127. package/utils/batch/types.js.map +0 -1
  128. package/utils/entity/index.js.map +0 -1
  129. package/utils/entity/types.js.map +0 -1
  130. package/utils/index.js.map +0 -1
  131. package/utils/table/index.js.map +0 -1
  132. package/utils/table/types.js.map +0 -1
package/store/keys.js CHANGED
@@ -1,16 +1,9 @@
1
- export const createPartitionKey = () => {
2
- return `W#internal`;
3
- };
4
- export const createSortKey = ({
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,"names":["createPartitionKey","createSortKey","key","toString","String","createType"],"sources":["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"],"mappings":"AAIA,OAAO,MAAMA,kBAAkB,GAAGA,CAAA,KAAM;EACpC,OAAO,YAAY;AACvB,CAAC;AAED,OAAO,MAAMC,aAAa,GAAGA,CAAC;EAAEC;AAAa,CAAC,KAAK;EAC/C,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE;IACzB,OAAOA,GAAG,CAACC,QAAQ,CAAC,CAAC;EACzB;EACA,OAAOC,MAAM,CAACF,GAAG,CAAC;AACtB,CAAC;AAED,OAAO,MAAMG,UAAU,GAAGA,CAAA,KAAM;EAC5B,OAAO,UAAU;AACrB,CAAC","ignoreList":[]}
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
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
package/toolbox.js CHANGED
@@ -1,6 +1 @@
1
1
  export { Entity, Table } from "dynamodb-toolbox";
2
-
3
- // Types previously imported from dynamodb-toolbox internals.
4
- // Declared locally to avoid deep path imports blocked by moduleResolution: bundler.
5
-
6
- //# sourceMappingURL=toolbox.js.map
package/types.js CHANGED
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -1,64 +1,45 @@
1
- import lodashChunk from "lodash/chunk.js";
2
- import WebinyError from "@webiny/error";
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
- const entries = [];
6
- const values = Object.values(responses);
7
- for (const items of values) {
8
- entries.push(...items);
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
- const {
14
- table,
15
- items
16
- } = params;
17
- const records = [];
18
- if (!table) {
19
- return records;
20
- }
21
- const result = await table.batchGet(items);
22
- if (!result || !result.Responses) {
23
- return records;
24
- }
25
- records.push(...flatten(result.Responses));
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.push(...flatten(nextResult.Responses));
36
- previous = nextResult;
37
- }
38
- return records;
25
+ return records;
39
26
  };
40
- /**
41
- * This helper function is meant to be used to batch read from one table.
42
- * It will fetch all results, as there is a next() method call built in.
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
- const records = [];
53
- const chunkItemsList = lodashChunk(params.items, maxChunk);
54
- for (const chunkItems of chunkItemsList) {
55
- const results = await batchReadAllChunk({
56
- table: params.table,
57
- items: chunkItems
58
- });
59
- records.push(...results);
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,"names":["lodashChunk","WebinyError","MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","push","batchReadAllChunk","params","table","records","result","batchGet","Responses","next","previous","nextResult","batchReadAll","maxChunk","length","chunkItemsList","chunkItems","results"],"sources":["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"],"mappings":"AAAA,OAAOA,WAAW,MAAM,iBAAiB;AACzC,OAAOC,WAAW,MAAM,eAAe;AAavC,MAAMC,eAAe,GAAG,GAAG;AAE3B,MAAMC,OAAO,GAAIC,SAAgC,IAAY;EACzD,MAAMC,OAAO,GAAG,EAAE;EAClB,MAAMC,MAAM,GAAGC,MAAM,CAACD,MAAM,CAACF,SAAS,CAAC;EACvC,KAAK,MAAMI,KAAK,IAAIF,MAAM,EAAE;IACxBD,OAAO,CAACI,IAAI,CAAC,GAAGD,KAAK,CAAC;EAC1B;EACA,OAAOH,OAAO;AAClB,CAAC;AAMD,MAAMK,iBAAiB,GAAG,MAAgBC,MAA+B,IAAmB;EACxF,MAAM;IAAEC,KAAK;IAAEJ;EAAM,CAAC,GAAGG,MAAM;EAC/B,MAAME,OAAY,GAAG,EAAE;EAEvB,IAAI,CAACD,KAAK,EAAE;IACR,OAAOC,OAAO;EAClB;EAEA,MAAMC,MAAM,GAAG,MAAMF,KAAK,CAACG,QAAQ,CAACP,KAAK,CAAC;EAC1C,IAAI,CAACM,MAAM,IAAI,CAACA,MAAM,CAACE,SAAS,EAAE;IAC9B,OAAOH,OAAO;EAClB;EACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACW,MAAM,CAACE,SAAS,CAAC,CAAC;EAC1C,IAAI,CAACF,MAAM,CAACG,IAAI,IAAI,OAAOH,MAAM,CAACG,IAAI,KAAK,UAAU,EAAE;IACnD,OAAOJ,OAAO;EAClB;EACA,IAAIK,QAAQ,GAAGJ,MAAM;EACrB,OAAO,OAAOI,QAAQ,CAACD,IAAI,KAAK,UAAU,EAAE;IACxC,MAAME,UAAU,GAAG,MAAMD,QAAQ,CAACD,IAAI,CAAC,CAAC;IACxC,IAAI,CAACE,UAAU,EAAE;MACb,OAAON,OAAO;IAClB;IACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACgB,UAAU,CAACH,SAAS,CAAC,CAAC;IAC9CE,QAAQ,GAAGC,UAAU;EACzB;EACA,OAAON,OAAO;AAClB,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMO,YAAY,GAAG,MAAAA,CACxBT,MAAuB,EACvBU,QAAQ,GAAGnB,eAAe,KACX;EACf,IAAIS,MAAM,CAACH,KAAK,CAACc,MAAM,KAAK,CAAC,EAAE;IAC3B,OAAO,EAAE;EACb,CAAC,MAAM,IAAID,QAAQ,GAAGnB,eAAe,EAAE;IACnC,MAAM,IAAID,WAAW,CACjB,gCAAgCC,eAAe,mCAAmC,EAClF,oCAAoC,EACpC;MACImB;IACJ,CACJ,CAAC;EACL;EAEA,MAAMR,OAAY,GAAG,EAAE;EAEvB,MAAMU,cAAc,GAAGvB,WAAW,CAACW,MAAM,CAACH,KAAK,EAAEa,QAAQ,CAAC;EAE1D,KAAK,MAAMG,UAAU,IAAID,cAAc,EAAE;IACrC,MAAME,OAAO,GAAG,MAAMf,iBAAiB,CAAI;MACvCE,KAAK,EAAED,MAAM,CAACC,KAAK;MACnBJ,KAAK,EAAEgB;IACX,CAAC,CAAC;IAEFX,OAAO,CAACJ,IAAI,CAAC,GAAGgB,OAAO,CAAC;EAC5B;EAEA,OAAOZ,OAAO;AAClB,CAAC","ignoreList":[]}
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 lodashChunk from "lodash/chunk.js";
2
- const hasUnprocessedItems = result => {
3
- if (typeof result.next !== "function") {
4
- return false;
5
- }
6
- const items = result.UnprocessedItems;
7
- if (!items || typeof items !== "object") {
8
- return false;
9
- }
10
- const keys = Object.keys(items);
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
- * Method is meant for batch writing to a single table.
30
- * It expects already prepared items for writing.
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,"names":["lodashChunk","hasUnprocessedItems","result","next","items","UnprocessedItems","keys","Object","some","key","value","Array","isArray","val","PutRequest","DeleteRequest","retry","input","results","batchWriteAll","params","maxChunk","collection","table","console","log","length","chunkedItems","batchWrite","execute","push"],"sources":["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"],"mappings":"AAAA,OAAOA,WAAW,MAAM,iBAAiB;AASzC,MAAMC,mBAAmB,GAAIC,MAA0B,IAAc;EACjE,IAAI,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU,EAAE;IACnC,OAAO,KAAK;EAChB;EACA,MAAMC,KAAK,GAAGF,MAAM,CAACG,gBAAgB;EACrC,IAAI,CAACD,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IACrC,OAAO,KAAK;EAChB;EACA,MAAME,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,KAAK,CAAC;EAC/B,OAAOE,IAAI,CAACE,IAAI,CAACC,GAAG,IAAI;IACpB,MAAMC,KAAK,GAAGN,KAAK,CAACK,GAAG,CAAC;IACxB,IAAI,CAACE,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACvB,OAAO,KAAK;IAChB;IACA,OAAOA,KAAK,CAACF,IAAI,CAACK,GAAG,IAAI;MACrB,OAAOA,GAAG,CAACC,UAAU,IAAID,GAAG,CAACE,aAAa;IAC9C,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAED,MAAMC,KAAK,GAAG,MAAAA,CAAOC,KAAyB,EAAEC,OAAyB,KAAoB;EACzF,IAAI,CAACjB,mBAAmB,CAACgB,KAAK,CAAC,EAAE;IAC7B;EACJ;EACA,MAAMf,MAAM,GAAG,MAAMe,KAAK,CAACd,IAAI,CAAE,CAAC;EAClC,MAAMa,KAAK,CAACd,MAAM,EAAEgB,OAAO,CAAC;AAChC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAG,MAAAA,CACzBC,MAAwB,EACxBC,QAAQ,GAAG,EAAE,KACe;EAC5B,MAAM;IAAEjB,KAAK,EAAEkB,UAAU;IAAEC;EAAM,CAAC,GAAGH,MAAM;EAC3C,IAAI,CAACG,KAAK,EAAE;IACRC,OAAO,CAACC,GAAG,CAAC,oBAAoB,CAAC;IACjC,OAAO,EAAE;EACb,CAAC,MAAM,IAAIH,UAAU,CAACI,MAAM,KAAK,CAAC,EAAE;IAChC,OAAO,EAAE;EACb;EAEA,MAAMC,YAAgC,GAAG3B,WAAW,CAACsB,UAAU,EAAED,QAAQ,CAAC;EAC1E,MAAMH,OAAyB,GAAG,EAAE;EACpC,KAAK,MAAMd,KAAK,IAAIuB,YAAY,EAAE;IAC9B,MAAMzB,MAAM,GAAI,MAAMqB,KAAK,CAACK,UAAU,CAACxB,KAAK,EAAE;MAC1CyB,OAAO,EAAE;IACb,CAAC,CAAwB;IACzBX,OAAO,CAACY,IAAI,CAAC5B,MAAM,CAAC;IACpB,MAAMc,KAAK,CAACd,MAAM,EAAEgB,OAAO,CAAC;EAChC;EACA,OAAOA,OAAO;AAClB,CAAC","ignoreList":[]}
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"}
@@ -1,5 +1,3 @@
1
1
  export * from "./batchRead.js";
2
2
  export * from "./batchWrite.js";
3
3
  export * from "./types.js";
4
-
5
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
package/utils/cleanup.js CHANGED
@@ -1,30 +1,40 @@
1
- /**
2
- * The attributes defined by us or the dynamodb-toolbox library.
3
- * Add more attributes if necessary.
4
- */
5
- const attributesToRemove = ["PK", "SK", "created", "_ct", "modified", "_mt", "entity", "_et", "GSI1_PK", "GSI1_SK", "GSI2_PK", "GSI2_SK", "GSI3_PK", "GSI3_SK", "GSI4_PK", "GSI4_SK", "GSI5_PK", "GSI5_SK", "GSI_TENANT", "TYPE"];
6
- export function cleanupItem(entity, item, removeAttributes = []) {
7
- if (!item) {
8
- return null;
9
- }
10
- const newItem = {
11
- ...item
12
- };
13
- const targets = attributesToRemove.concat(removeAttributes);
14
- const attributes = entity.schema.attributes;
15
- for (const key in item) {
16
- if (item.hasOwnProperty(key) === false) {
17
- continue;
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
- if (attributes[key] && targets.includes(key) === false) {
20
- continue;
21
- }
22
- delete newItem[key];
23
- }
24
- return newItem;
33
+ return newItem;
25
34
  }
26
- export function cleanupItems(entity, items, removeAttributes = []) {
27
- return items.map(item => cleanupItem(entity, item, removeAttributes));
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
@@ -1 +1 @@
1
- {"version":3,"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","concat","attributes","schema","key","hasOwnProperty","includes","cleanupItems","items","map"],"sources":["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"],"mappings":"AAEA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CACvB,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,KAAK,EACL,UAAU,EACV,KAAK,EACL,QAAQ,EACR,KAAK,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,YAAY,EACZ,MAAM,CACT;AAED,OAAO,SAASC,WAAWA,CACvBC,MAAmB,EACnBC,IAAe,EACfC,gBAA0B,GAAG,EAAE,EACvB;EACR,IAAI,CAACD,IAAI,EAAE;IACP,OAAO,IAAI;EACf;EACA,MAAME,OAAO,GAAG;IACZ,GAAGF;EACP,CAAC;EACD,MAAMG,OAAO,GAAGN,kBAAkB,CAACO,MAAM,CAACH,gBAAgB,CAAC;EAC3D,MAAMI,UAAU,GAAGN,MAAM,CAACO,MAAM,CAACD,UAAU;EAC3C,KAAK,MAAME,GAAG,IAAIP,IAAI,EAAE;IACpB,IAAIA,IAAI,CAACQ,cAAc,CAACD,GAAG,CAAC,KAAK,KAAK,EAAE;MACpC;IACJ;IACA,IAAIF,UAAU,CAACE,GAAG,CAAC,IAAIJ,OAAO,CAACM,QAAQ,CAACF,GAAG,CAAC,KAAK,KAAK,EAAE;MACpD;IACJ;IACA,OAAOL,OAAO,CAACK,GAAG,CAAC;EACvB;EACA,OAAOL,OAAO;AAClB;AAEA,OAAO,SAASQ,YAAYA,CACxBX,MAAmB,EACnBY,KAAU,EACVV,gBAA0B,GAAG,EAAE,EAC5B;EACH,OAAOU,KAAK,CAACC,GAAG,CAACZ,IAAI,IAAIF,WAAW,CAAIC,MAAM,EAAEC,IAAI,EAAEC,gBAAgB,CAAM,CAAC;AACjF","ignoreList":[]}
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
- export const count = async params => {
2
- const {
3
- entity,
4
- partitionKey,
5
- options = {}
6
- } = params;
7
- // @ts-expect-error
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
@@ -1 +1 @@
1
- {"version":3,"names":["count","params","entity","partitionKey","options","Count","query","select"],"sources":["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"],"mappings":"AAEA,OAAO,MAAMA,KAAK,GAAG,MAAOC,MAAsB,IAAsB;EACpE,MAAM;IAAEC,MAAM;IAAEC,YAAY;IAAEC,OAAO,GAAG,CAAC;EAAE,CAAC,GAAGH,MAAM;EACrD;EACA,MAAM;IAAEI;EAAM,CAAC,GAAG,MAAMH,MAAM,CAACI,KAAK,CAACH,YAAY,EAAE;IAAE,GAAGC,OAAO;IAAEG,MAAM,EAAE;EAAQ,CAAC,CAAC;EACnF,OAAOF,KAAK,IAAI,CAAC;AACrB,CAAC","ignoreList":[]}
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"}
@@ -9,7 +9,7 @@ export type IGlobalEntityAttributes<T = undefined> = {
9
9
  GSI1_SK?: string;
10
10
  GSI2_PK?: string;
11
11
  GSI2_SK?: string;
12
- expiresAt?: string | null;
12
+ expiresAt?: number | null;
13
13
  } & (T extends undefined ? {
14
14
  data?: undefined;
15
15
  } : {
@@ -1,85 +1,82 @@
1
1
  import { createEntity } from "./entity/index.js";
2
- export 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"
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
- export const createStandardEntity = params => {
76
- return createEntity({
77
- ...params,
78
- attributes: {
79
- ...standardEntityAttributes,
80
- ...params.attributes
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,"names":["createEntity","globalEntityAttributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","GSI2_PK","GSI2_SK","TYPE","required","data","expiresAt","createGlobalEntity","params","attributes","standardEntityAttributes","GSI_TENANT","createStandardEntity"],"sources":["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?: string | 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"],"mappings":"AACA,SAASA,YAAY;AAcrB,OAAO,MAAMC,sBAA4C,GAAG;EACxDC,EAAE,EAAE;IACAC,YAAY,EAAE;EAClB,CAAC;EACDC,EAAE,EAAE;IACAC,OAAO,EAAE;EACb,CAAC;EACDC,OAAO,EAAE;IACLC,IAAI,EAAE;EACV,CAAC;EACDC,OAAO,EAAE;IACLD,IAAI,EAAE;EACV,CAAC;EACDE,OAAO,EAAE;IACLF,IAAI,EAAE;EACV,CAAC;EACDG,OAAO,EAAE;IACLH,IAAI,EAAE;EACV,CAAC;EACDI,IAAI,EAAE;IACFJ,IAAI,EAAE,QAAQ;IACdK,QAAQ,EAAE;EACd,CAAC;EACDC,IAAI,EAAE;IACFN,IAAI,EAAE;EACV,CAAC;EACDO,SAAS,EAAE;IACPP,IAAI,EAAE;EACV;AACJ,CAAC;AAED,OAAO,MAAMQ,kBAAkB,GAC3BC,MAA8F,IAC7F;EACD,OAAOhB,YAAY,CAA6B;IAC5C,GAAGgB,MAAM;IACTC,UAAU,EAAE;MACR,GAAGhB,sBAAsB;MACzB,GAAGe,MAAM,CAACC;IACd;EACJ,CAAC,CAAC;AACN,CAAC;AAcD,OAAO,MAAMC,wBAA8C,GAAG;EAC1DhB,EAAE,EAAE;IACAC,YAAY,EAAE;EAClB,CAAC;EACDC,EAAE,EAAE;IACAC,OAAO,EAAE;EACb,CAAC;EACDc,UAAU,EAAE;IACRZ,IAAI,EAAE,QAAQ;IACdK,QAAQ,EAAE;EACd,CAAC;EACDN,OAAO,EAAE;IACLC,IAAI,EAAE;EACV,CAAC;EACDC,OAAO,EAAE;IACLD,IAAI,EAAE;EACV,CAAC;EACDE,OAAO,EAAE;IACLF,IAAI,EAAE;EACV,CAAC;EACDG,OAAO,EAAE;IACLH,IAAI,EAAE;EACV,CAAC;EACDI,IAAI,EAAE;IACFJ,IAAI,EAAE,QAAQ;IACdK,QAAQ,EAAE;EACd,CAAC;EACDC,IAAI,EAAE;IACFN,IAAI,EAAE;EACV,CAAC;EACDO,SAAS,EAAE;IACPP,IAAI,EAAE;EACV;AACJ,CAAC;AAED,OAAO,MAAMa,oBAAoB,GAC7BJ,MAA8F,IAC7F;EACD,OAAOhB,YAAY,CAA+B;IAC9C,GAAGgB,MAAM;IACTC,UAAU,EAAE;MACR,GAAGC,wBAAwB;MAC3B,GAAGF,MAAM,CAACC;IACd;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
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"}