@webiny/db-dynamodb 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f

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 (222) hide show
  1. package/DynamoDbDriver.d.ts +23 -25
  2. package/DynamoDbDriver.js +232 -240
  3. package/DynamoDbDriver.js.map +1 -0
  4. package/README.md +81 -1
  5. package/index.d.ts +2 -0
  6. package/index.js +18 -3
  7. package/index.js.map +1 -0
  8. package/package.json +19 -22
  9. package/plugins/definitions/AttributePlugin.d.ts +6 -8
  10. package/plugins/definitions/AttributePlugin.js +5 -20
  11. package/plugins/definitions/AttributePlugin.js.map +1 -0
  12. package/plugins/definitions/DateTimeTransformPlugin.d.ts +3 -2
  13. package/plugins/definitions/DateTimeTransformPlugin.js +16 -28
  14. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -0
  15. package/plugins/definitions/FieldPathPlugin.d.ts +3 -3
  16. package/plugins/definitions/FieldPathPlugin.js +7 -21
  17. package/plugins/definitions/FieldPathPlugin.js.map +1 -0
  18. package/plugins/definitions/FieldPlugin.d.ts +5 -5
  19. package/plugins/definitions/FieldPlugin.js +2 -24
  20. package/plugins/definitions/FieldPlugin.js.map +1 -0
  21. package/plugins/definitions/TimeTransformPlugin.d.ts +3 -2
  22. package/plugins/definitions/TimeTransformPlugin.js +19 -30
  23. package/plugins/definitions/TimeTransformPlugin.js.map +1 -0
  24. package/plugins/definitions/ValueFilterPlugin.d.ts +13 -11
  25. package/plugins/definitions/ValueFilterPlugin.js +10 -16
  26. package/plugins/definitions/ValueFilterPlugin.js.map +1 -0
  27. package/plugins/definitions/ValueTransformPlugin.d.ts +9 -9
  28. package/plugins/definitions/ValueTransformPlugin.js +7 -22
  29. package/plugins/definitions/ValueTransformPlugin.js.map +1 -0
  30. package/plugins/definitions/assignFields.js +3 -10
  31. package/plugins/definitions/assignFields.js.map +1 -0
  32. package/plugins/filters/andIn.d.ts +2 -2
  33. package/plugins/filters/andIn.js +5 -9
  34. package/plugins/filters/andIn.js.map +1 -0
  35. package/plugins/filters/between.d.ts +2 -2
  36. package/plugins/filters/between.js +5 -9
  37. package/plugins/filters/between.js.map +1 -0
  38. package/plugins/filters/contains.d.ts +2 -2
  39. package/plugins/filters/contains.js +44 -17
  40. package/plugins/filters/contains.js.map +1 -0
  41. package/plugins/filters/eq.d.ts +2 -2
  42. package/plugins/filters/eq.js +17 -5
  43. package/plugins/filters/eq.js.map +1 -0
  44. package/plugins/filters/fuzzy.d.ts +2 -2
  45. package/plugins/filters/fuzzy.js +18 -12
  46. package/plugins/filters/fuzzy.js.map +1 -0
  47. package/plugins/filters/gt.d.ts +2 -2
  48. package/plugins/filters/gt.js +4 -4
  49. package/plugins/filters/gt.js.map +1 -0
  50. package/plugins/filters/gte.d.ts +2 -2
  51. package/plugins/filters/gte.js +4 -4
  52. package/plugins/filters/gte.js.map +1 -0
  53. package/plugins/filters/in.d.ts +2 -2
  54. package/plugins/filters/in.js +5 -9
  55. package/plugins/filters/in.js.map +1 -0
  56. package/plugins/filters/index.d.ts +1 -1
  57. package/plugins/filters/index.js +5 -15
  58. package/plugins/filters/index.js.map +1 -0
  59. package/plugins/filters/lt.d.ts +2 -2
  60. package/plugins/filters/lt.js +4 -4
  61. package/plugins/filters/lt.js.map +1 -0
  62. package/plugins/filters/lte.d.ts +2 -2
  63. package/plugins/filters/lte.js +4 -4
  64. package/plugins/filters/lte.js.map +1 -0
  65. package/plugins/filters/startsWith.d.ts +3 -0
  66. package/plugins/filters/startsWith.js +40 -0
  67. package/plugins/filters/startsWith.js.map +1 -0
  68. package/plugins/index.d.ts +1 -1
  69. package/plugins/index.js +3 -5
  70. package/plugins/index.js.map +1 -0
  71. package/store/entity.d.ts +78 -0
  72. package/store/entity.js +41 -0
  73. package/store/entity.js.map +1 -0
  74. package/store/keys.d.ts +6 -0
  75. package/store/keys.js +22 -0
  76. package/store/keys.js.map +1 -0
  77. package/store/types.d.ts +7 -0
  78. package/store/types.js +7 -0
  79. package/store/types.js.map +1 -0
  80. package/toolbox.d.ts +3 -0
  81. package/toolbox.js +20 -0
  82. package/toolbox.js.map +1 -0
  83. package/types.d.ts +37 -21
  84. package/types.js +3 -1
  85. package/types.js.map +1 -0
  86. package/utils/attributes.d.ts +5 -5
  87. package/utils/attributes.js +6 -14
  88. package/utils/attributes.js.map +1 -0
  89. package/utils/batch/batchRead.d.ts +15 -0
  90. package/utils/batch/batchRead.js +72 -0
  91. package/utils/batch/batchRead.js.map +1 -0
  92. package/utils/batch/batchWrite.d.ts +13 -0
  93. package/utils/batch/batchWrite.js +65 -0
  94. package/utils/batch/batchWrite.js.map +1 -0
  95. package/utils/batch/index.d.ts +3 -0
  96. package/utils/batch/index.js +40 -0
  97. package/utils/batch/index.js.map +1 -0
  98. package/utils/batch/types.d.ts +25 -0
  99. package/utils/batch/types.js +7 -0
  100. package/utils/batch/types.js.map +1 -0
  101. package/utils/cleanup.d.ts +3 -3
  102. package/utils/cleanup.js +11 -27
  103. package/utils/cleanup.js.map +1 -0
  104. package/utils/count.d.ts +2 -0
  105. package/utils/count.js +23 -0
  106. package/utils/count.js.map +1 -0
  107. package/utils/createEntity.d.ts +54 -0
  108. package/utils/createEntity.js +61 -0
  109. package/utils/createEntity.js.map +1 -0
  110. package/utils/createTable.d.ts +8 -0
  111. package/utils/createTable.js +29 -0
  112. package/utils/createTable.js.map +1 -0
  113. package/utils/cursor.d.ts +2 -2
  114. package/utils/cursor.js +2 -6
  115. package/utils/cursor.js.map +1 -0
  116. package/utils/delete.d.ts +10 -0
  117. package/utils/delete.js +18 -0
  118. package/utils/delete.js.map +1 -0
  119. package/utils/entity/Entity.d.ts +26 -0
  120. package/utils/entity/Entity.js +77 -0
  121. package/utils/entity/Entity.js.map +1 -0
  122. package/utils/entity/EntityReadBatch.d.ts +17 -0
  123. package/utils/entity/EntityReadBatch.js +41 -0
  124. package/utils/entity/EntityReadBatch.js.map +1 -0
  125. package/utils/entity/EntityReadBatchBuilder.d.ts +10 -0
  126. package/utils/entity/EntityReadBatchBuilder.js +29 -0
  127. package/utils/entity/EntityReadBatchBuilder.js.map +1 -0
  128. package/utils/entity/EntityWriteBatch.d.ts +22 -0
  129. package/utils/entity/EntityWriteBatch.js +59 -0
  130. package/utils/entity/EntityWriteBatch.js.map +1 -0
  131. package/utils/entity/EntityWriteBatchBuilder.d.ts +11 -0
  132. package/utils/entity/EntityWriteBatchBuilder.js +28 -0
  133. package/utils/entity/EntityWriteBatchBuilder.js.map +1 -0
  134. package/utils/entity/getEntity.d.ts +4 -0
  135. package/utils/entity/getEntity.js +19 -0
  136. package/utils/entity/getEntity.js.map +1 -0
  137. package/utils/entity/index.d.ts +7 -0
  138. package/utils/entity/index.js +84 -0
  139. package/utils/entity/index.js.map +1 -0
  140. package/utils/entity/types.d.ts +51 -0
  141. package/utils/entity/types.js +7 -0
  142. package/utils/entity/types.js.map +1 -0
  143. package/utils/filter.d.ts +4 -4
  144. package/utils/filter.js +12 -43
  145. package/utils/filter.js.map +1 -0
  146. package/utils/get.d.ts +10 -8
  147. package/utils/get.js +16 -7
  148. package/utils/get.js.map +1 -0
  149. package/utils/index.d.ts +17 -0
  150. package/utils/index.js +194 -0
  151. package/utils/index.js.map +1 -0
  152. package/utils/listResponse.d.ts +1 -1
  153. package/utils/listResponse.js +8 -7
  154. package/utils/listResponse.js.map +1 -0
  155. package/utils/put.d.ts +12 -0
  156. package/utils/put.js +19 -0
  157. package/utils/put.js.map +1 -0
  158. package/utils/query.d.ts +20 -8
  159. package/utils/query.js +71 -38
  160. package/utils/query.js.map +1 -0
  161. package/utils/scan.d.ts +38 -0
  162. package/utils/scan.js +90 -0
  163. package/utils/scan.js.map +1 -0
  164. package/utils/sort.d.ts +3 -3
  165. package/utils/sort.js +5 -22
  166. package/utils/sort.js.map +1 -0
  167. package/utils/table/Table.d.ts +11 -0
  168. package/utils/table/Table.js +38 -0
  169. package/utils/table/Table.js.map +1 -0
  170. package/utils/table/TableReadBatch.d.ts +19 -0
  171. package/utils/table/TableReadBatch.js +62 -0
  172. package/utils/table/TableReadBatch.js.map +1 -0
  173. package/utils/table/TableWriteBatch.d.ts +21 -0
  174. package/utils/table/TableWriteBatch.js +69 -0
  175. package/utils/table/TableWriteBatch.js.map +1 -0
  176. package/utils/table/index.d.ts +4 -0
  177. package/utils/table/index.js +51 -0
  178. package/utils/table/index.js.map +1 -0
  179. package/utils/table/types.d.ts +39 -0
  180. package/utils/table/types.js +7 -0
  181. package/utils/table/types.js.map +1 -0
  182. package/utils/update.d.ts +12 -0
  183. package/utils/update.js +19 -0
  184. package/utils/update.js.map +1 -0
  185. package/BatchProcess.d.ts +0 -31
  186. package/BatchProcess.js +0 -196
  187. package/QueryGenerator.d.ts +0 -19
  188. package/QueryGenerator.js +0 -79
  189. package/operators/comparison/beginsWith.d.ts +0 -3
  190. package/operators/comparison/beginsWith.js +0 -24
  191. package/operators/comparison/between.d.ts +0 -3
  192. package/operators/comparison/between.js +0 -30
  193. package/operators/comparison/eq.d.ts +0 -3
  194. package/operators/comparison/eq.js +0 -34
  195. package/operators/comparison/gt.d.ts +0 -3
  196. package/operators/comparison/gt.js +0 -24
  197. package/operators/comparison/gte.d.ts +0 -3
  198. package/operators/comparison/gte.js +0 -24
  199. package/operators/comparison/lt.d.ts +0 -3
  200. package/operators/comparison/lt.js +0 -24
  201. package/operators/comparison/lte.d.ts +0 -3
  202. package/operators/comparison/lte.js +0 -24
  203. package/operators/index.d.ts +0 -12
  204. package/operators/index.js +0 -39
  205. package/operators/logical/and.d.ts +0 -3
  206. package/operators/logical/and.js +0 -63
  207. package/operators/logical/or.d.ts +0 -3
  208. package/operators/logical/or.js +0 -63
  209. package/plugins/definitions/NumberTransformPlugin.d.ts +0 -4
  210. package/plugins/definitions/NumberTransformPlugin.js +0 -49
  211. package/statements/createKeyConditionExpressionArgs.d.ts +0 -12
  212. package/statements/createKeyConditionExpressionArgs.js +0 -48
  213. package/statements/processStatement.d.ts +0 -4
  214. package/statements/processStatement.js +0 -39
  215. package/utils/batchRead.d.ts +0 -15
  216. package/utils/batchRead.js +0 -58
  217. package/utils/batchWrite.d.ts +0 -17
  218. package/utils/batchWrite.js +0 -30
  219. package/utils/documentClient.d.ts +0 -8
  220. package/utils/documentClient.js +0 -33
  221. package/utils/table.d.ts +0 -7
  222. package/utils/table.js +0 -27
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createStandardEntity = exports.createLegacyEntity = void 0;
7
+ var _toolbox = require("../toolbox");
8
+ const createStandardEntity = params => {
9
+ return new _toolbox.Entity({
10
+ name: params.name,
11
+ table: params.table,
12
+ attributes: {
13
+ PK: {
14
+ partitionKey: true
15
+ },
16
+ SK: {
17
+ sortKey: true
18
+ },
19
+ GSI1_PK: {
20
+ type: "string"
21
+ },
22
+ GSI1_SK: {
23
+ type: "string"
24
+ },
25
+ TYPE: {
26
+ type: "string"
27
+ },
28
+ data: {
29
+ type: "map"
30
+ }
31
+ }
32
+ });
33
+ };
34
+ exports.createStandardEntity = createStandardEntity;
35
+ const createLegacyEntity = params => {
36
+ return new _toolbox.Entity({
37
+ table: params.table,
38
+ name: params.name,
39
+ attributes: {
40
+ PK: {
41
+ partitionKey: true
42
+ },
43
+ SK: {
44
+ sortKey: true
45
+ },
46
+ GSI1_PK: {
47
+ type: "string"
48
+ },
49
+ GSI1_SK: {
50
+ type: "string"
51
+ },
52
+ TYPE: {
53
+ type: "string"
54
+ },
55
+ ...(params.attributes || {})
56
+ }
57
+ });
58
+ };
59
+ exports.createLegacyEntity = createLegacyEntity;
60
+
61
+ //# sourceMappingURL=createEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_toolbox","require","createStandardEntity","params","Entity","name","table","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data","exports","createLegacyEntity"],"sources":["createEntity.ts"],"sourcesContent":["import type { AttributeDefinitions, Table } from \"~/toolbox\";\nimport { Entity } from \"~/toolbox\";\n\ninterface CreateStandardEntityParams {\n table: Table<string, string, string>;\n name: string;\n}\n\nexport const createStandardEntity = (params: CreateStandardEntityParams): Entity<any> => {\n return new Entity({\n name: params.name,\n table: params.table,\n attributes: {\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 TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n }\n }\n });\n};\n\ninterface CreateLegacyEntityParams {\n table: Table<string, string, string>;\n name: string;\n attributes?: AttributeDefinitions;\n}\n\nexport const createLegacyEntity = (params: CreateLegacyEntityParams) => {\n return new Entity({\n table: params.table,\n name: params.name,\n attributes: {\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 TYPE: {\n type: \"string\"\n },\n ...(params.attributes || {})\n }\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAOO,MAAMC,oBAAoB,GAAIC,MAAkC,IAAkB;EACrF,OAAO,IAAIC,eAAM,CAAC;IACdC,IAAI,EAAEF,MAAM,CAACE,IAAI;IACjBC,KAAK,EAAEH,MAAM,CAACG,KAAK;IACnBC,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,OAAO,EAAE;QACLD,IAAI,EAAE;MACV,CAAC;MACDE,IAAI,EAAE;QACFF,IAAI,EAAE;MACV,CAAC;MACDG,IAAI,EAAE;QACFH,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAACI,OAAA,CAAAf,oBAAA,GAAAA,oBAAA;AAQK,MAAMgB,kBAAkB,GAAIf,MAAgC,IAAK;EACpE,OAAO,IAAIC,eAAM,CAAC;IACdE,KAAK,EAAEH,MAAM,CAACG,KAAK;IACnBD,IAAI,EAAEF,MAAM,CAACE,IAAI;IACjBE,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,OAAO,EAAE;QACLD,IAAI,EAAE;MACV,CAAC;MACDE,IAAI,EAAE;QACFF,IAAI,EAAE;MACV,CAAC;MACD,IAAIV,MAAM,CAACI,UAAU,IAAI,CAAC,CAAC;IAC/B;EACJ,CAAC,CAAC;AACN,CAAC;AAACU,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
2
+ import { Table as BaseTable } from "../toolbox";
3
+ export interface CreateTableParams {
4
+ name?: string;
5
+ documentClient: DynamoDBDocument;
6
+ }
7
+ export type Table = BaseTable<string, "PK", "SK">;
8
+ export declare const createTable: ({ name, documentClient }: CreateTableParams) => Table;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createTable = void 0;
7
+ var _toolbox = require("../toolbox");
8
+ const createTable = ({
9
+ name,
10
+ documentClient
11
+ }) => {
12
+ return new _toolbox.Table({
13
+ name: name || String(process.env.DB_TABLE),
14
+ partitionKey: "PK",
15
+ sortKey: "SK",
16
+ DocumentClient: documentClient,
17
+ indexes: {
18
+ GSI1: {
19
+ partitionKey: "GSI1_PK",
20
+ sortKey: "GSI1_SK"
21
+ }
22
+ },
23
+ autoExecute: true,
24
+ autoParse: true
25
+ });
26
+ };
27
+ exports.createTable = createTable;
28
+
29
+ //# sourceMappingURL=createTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_toolbox","require","createTable","name","documentClient","BaseTable","String","process","env","DB_TABLE","partitionKey","sortKey","DocumentClient","indexes","GSI1","autoExecute","autoParse","exports"],"sources":["createTable.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { Table as BaseTable } from \"~/toolbox\";\n\nexport interface CreateTableParams {\n name?: string;\n documentClient: DynamoDBDocument;\n}\n\nexport type Table = BaseTable<string, \"PK\", \"SK\">;\n\nexport const createTable = ({ name, documentClient }: CreateTableParams): Table => {\n return new BaseTable({\n name: name || String(process.env.DB_TABLE),\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: documentClient,\n indexes: {\n GSI1: {\n partitionKey: \"GSI1_PK\",\n sortKey: \"GSI1_SK\"\n }\n },\n autoExecute: true,\n autoParse: true\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AASO,MAAMC,WAAW,GAAGA,CAAC;EAAEC,IAAI;EAAEC;AAAkC,CAAC,KAAY;EAC/E,OAAO,IAAIC,cAAS,CAAC;IACjBF,IAAI,EAAEA,IAAI,IAAIG,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,QAAQ,CAAC;IAC1CC,YAAY,EAAE,IAAI;IAClBC,OAAO,EAAE,IAAI;IACbC,cAAc,EAAER,cAAc;IAC9BS,OAAO,EAAE;MACLC,IAAI,EAAE;QACFJ,YAAY,EAAE,SAAS;QACvBC,OAAO,EAAE;MACb;IACJ,CAAC;IACDI,WAAW,EAAE,IAAI;IACjBC,SAAS,EAAE;EACf,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAf,WAAA,GAAAA,WAAA","ignoreList":[]}
package/utils/cursor.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const encodeCursor: (cursor?: any) => string;
2
- export declare const decodeCursor: (cursor?: string) => any;
1
+ export declare const encodeCursor: (cursor?: any) => string | null;
2
+ export declare const decodeCursor: (cursor?: string | null) => string | null;
package/utils/cursor.js CHANGED
@@ -4,23 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.encodeCursor = exports.decodeCursor = void 0;
7
-
8
7
  const encodeCursor = cursor => {
9
8
  if (!cursor) {
10
9
  return null;
11
10
  }
12
-
13
11
  return Buffer.from(JSON.stringify(cursor)).toString("base64");
14
12
  };
15
-
16
13
  exports.encodeCursor = encodeCursor;
17
-
18
14
  const decodeCursor = cursor => {
19
15
  if (!cursor) {
20
16
  return null;
21
17
  }
22
-
23
18
  return JSON.parse(Buffer.from(cursor, "base64").toString("ascii"));
24
19
  };
20
+ exports.decodeCursor = decodeCursor;
25
21
 
26
- exports.decodeCursor = decodeCursor;
22
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["encodeCursor","cursor","Buffer","from","JSON","stringify","toString","exports","decodeCursor","parse"],"sources":["cursor.ts"],"sourcesContent":["export const encodeCursor = (cursor?: any): string | null => {\n if (!cursor) {\n return null;\n }\n\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n};\n\nexport const decodeCursor = (cursor?: string | null): string | null => {\n if (!cursor) {\n return null;\n }\n\n return JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n};\n"],"mappings":";;;;;;AAAO,MAAMA,YAAY,GAAIC,MAAY,IAAoB;EACzD,IAAI,CAACA,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,OAAOC,MAAM,CAACC,IAAI,CAACC,IAAI,CAACC,SAAS,CAACJ,MAAM,CAAC,CAAC,CAACK,QAAQ,CAAC,QAAQ,CAAC;AACjE,CAAC;AAACC,OAAA,CAAAP,YAAA,GAAAA,YAAA;AAEK,MAAMQ,YAAY,GAAIP,MAAsB,IAAoB;EACnE,IAAI,CAACA,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,OAAOG,IAAI,CAACK,KAAK,CAACP,MAAM,CAACC,IAAI,CAACF,MAAM,EAAE,QAAQ,CAAC,CAACK,QAAQ,CAAC,OAAO,CAAC,CAAC;AACtE,CAAC;AAACC,OAAA,CAAAC,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import type { Entity } from "../toolbox";
2
+ export interface IDeleteItemKeys {
3
+ PK: string;
4
+ SK: string;
5
+ }
6
+ export interface IDeleteItemParams {
7
+ entity: Entity;
8
+ keys: IDeleteItemKeys;
9
+ }
10
+ export declare const deleteItem: (params: IDeleteItemParams) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deleteItem = void 0;
7
+ const deleteItem = async params => {
8
+ const {
9
+ entity,
10
+ keys
11
+ } = params;
12
+ return await entity.delete(keys, {
13
+ execute: true
14
+ });
15
+ };
16
+ exports.deleteItem = deleteItem;
17
+
18
+ //# sourceMappingURL=delete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["deleteItem","params","entity","keys","delete","execute","exports"],"sources":["delete.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox\";\nexport interface IDeleteItemKeys {\n PK: string;\n SK: string;\n}\nexport interface IDeleteItemParams {\n entity: Entity;\n keys: IDeleteItemKeys;\n}\n\nexport const deleteItem = async (params: IDeleteItemParams) => {\n const { entity, keys } = params;\n\n return await entity.delete(keys, {\n execute: true\n });\n};\n"],"mappings":";;;;;;AAUO,MAAMA,UAAU,GAAG,MAAOC,MAAyB,IAAK;EAC3D,MAAM;IAAEC,MAAM;IAAEC;EAAK,CAAC,GAAGF,MAAM;EAE/B,OAAO,MAAMC,MAAM,CAACE,MAAM,CAACD,IAAI,EAAE;IAC7BE,OAAO,EAAE;EACb,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAN,UAAA,GAAAA,UAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import type { AttributeDefinitions, EntityConstructor as BaseEntityConstructor, Readonly, TableDef } from "../../toolbox";
2
+ import { Entity as BaseEntity } from "../../toolbox";
3
+ import type { ITableWriteBatch } from "../table/types";
4
+ import type { IEntity, IEntityQueryAllParams, IEntityQueryOneParams, IEntityReadBatch, IEntityWriteBatch } from "./types";
5
+ import type { IPutParamsItem } from "../put";
6
+ import { put } from "../put";
7
+ import type { GetRecordParamsKeys } from "../get";
8
+ import { get, getClean } from "../get";
9
+ import type { IDeleteItemKeys } from "../delete";
10
+ import { deleteItem } from "../delete";
11
+ import type { GenericRecord } from "@webiny/api/types";
12
+ export type EntityConstructor<T extends Readonly<AttributeDefinitions> = Readonly<AttributeDefinitions>> = BaseEntityConstructor<TableDef, string, true, true, true, "created", "modified", "entity", false, T>;
13
+ export declare class Entity implements IEntity {
14
+ readonly entity: BaseEntity;
15
+ constructor(params: EntityConstructor);
16
+ createEntityReader(): IEntityReadBatch;
17
+ createEntityWriter(): IEntityWriteBatch;
18
+ createTableWriter(): ITableWriteBatch;
19
+ put<T extends GenericRecord = GenericRecord>(item: IPutParamsItem<T>): ReturnType<typeof put>;
20
+ get<T>(keys: GetRecordParamsKeys): ReturnType<typeof get<T>>;
21
+ getClean<T>(keys: GetRecordParamsKeys): ReturnType<typeof getClean<T>>;
22
+ delete(keys: IDeleteItemKeys): ReturnType<typeof deleteItem>;
23
+ queryOne<T>(params: IEntityQueryOneParams): Promise<T | null>;
24
+ queryAll<T>(params: IEntityQueryAllParams): Promise<T[]>;
25
+ }
26
+ export declare const createEntity: (params: EntityConstructor) => IEntity;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEntity = exports.Entity = void 0;
7
+ var _toolbox = require("../../toolbox");
8
+ var _put = require("../put");
9
+ var _get = require("../get");
10
+ var _delete = require("../delete");
11
+ var _EntityReadBatch = require("./EntityReadBatch");
12
+ var _EntityWriteBatch = require("./EntityWriteBatch");
13
+ var _TableWriteBatch = require("../table/TableWriteBatch");
14
+ var _query = require("../query");
15
+ class Entity {
16
+ constructor(params) {
17
+ this.entity = new _toolbox.Entity(params);
18
+ }
19
+ createEntityReader() {
20
+ return (0, _EntityReadBatch.createEntityReadBatch)({
21
+ entity: this.entity
22
+ });
23
+ }
24
+ createEntityWriter() {
25
+ return (0, _EntityWriteBatch.createEntityWriteBatch)({
26
+ entity: this.entity
27
+ });
28
+ }
29
+ createTableWriter() {
30
+ return (0, _TableWriteBatch.createTableWriteBatch)({
31
+ table: this.entity.table
32
+ });
33
+ }
34
+ async put(item) {
35
+ return (0, _put.put)({
36
+ entity: this.entity,
37
+ item
38
+ });
39
+ }
40
+ async get(keys) {
41
+ return (0, _get.get)({
42
+ entity: this.entity,
43
+ keys
44
+ });
45
+ }
46
+ async getClean(keys) {
47
+ return (0, _get.getClean)({
48
+ entity: this.entity,
49
+ keys
50
+ });
51
+ }
52
+ async delete(keys) {
53
+ return (0, _delete.deleteItem)({
54
+ entity: this.entity,
55
+ keys
56
+ });
57
+ }
58
+ queryOne(params) {
59
+ return (0, _query.queryOneClean)({
60
+ ...params,
61
+ entity: this.entity
62
+ });
63
+ }
64
+ queryAll(params) {
65
+ return (0, _query.queryAllClean)({
66
+ ...params,
67
+ entity: this.entity
68
+ });
69
+ }
70
+ }
71
+ exports.Entity = Entity;
72
+ const createEntity = params => {
73
+ return new Entity(params);
74
+ };
75
+ exports.createEntity = createEntity;
76
+
77
+ //# sourceMappingURL=Entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_toolbox","require","_put","_get","_delete","_EntityReadBatch","_EntityWriteBatch","_TableWriteBatch","_query","Entity","constructor","params","entity","BaseEntity","createEntityReader","createEntityReadBatch","createEntityWriter","createEntityWriteBatch","createTableWriter","createTableWriteBatch","table","put","item","get","keys","getClean","delete","deleteItem","queryOne","queryOneClean","queryAll","queryAllClean","exports","createEntity"],"sources":["Entity.ts"],"sourcesContent":["import type {\n AttributeDefinitions,\n EntityConstructor as BaseEntityConstructor,\n Readonly,\n TableDef\n} from \"~/toolbox\";\nimport { Entity as BaseEntity } from \"~/toolbox\";\nimport type { ITableWriteBatch } from \"../table/types\";\nimport type {\n IEntity,\n IEntityQueryAllParams,\n IEntityQueryOneParams,\n IEntityReadBatch,\n IEntityWriteBatch\n} from \"./types\";\nimport type { IPutParamsItem } from \"../put\";\nimport { put } from \"../put\";\nimport type { GetRecordParamsKeys } from \"../get\";\nimport { get, getClean } from \"../get\";\nimport type { IDeleteItemKeys } from \"../delete\";\nimport { deleteItem } from \"../delete\";\nimport { createEntityReadBatch } from \"./EntityReadBatch\";\nimport { createEntityWriteBatch } from \"./EntityWriteBatch\";\nimport { createTableWriteBatch } from \"~/utils/table/TableWriteBatch\";\nimport { queryAllClean, queryOneClean } from \"../query\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport type EntityConstructor<\n T extends Readonly<AttributeDefinitions> = Readonly<AttributeDefinitions>\n> = BaseEntityConstructor<\n TableDef,\n string,\n true,\n true,\n true,\n \"created\",\n \"modified\",\n \"entity\",\n false,\n T\n>;\n\nexport class Entity implements IEntity {\n public readonly entity: BaseEntity;\n\n public constructor(params: EntityConstructor) {\n this.entity = new BaseEntity(params);\n }\n\n public createEntityReader(): IEntityReadBatch {\n return createEntityReadBatch({\n entity: this.entity\n });\n }\n\n public createEntityWriter(): IEntityWriteBatch {\n return createEntityWriteBatch({\n entity: this.entity\n });\n }\n\n public createTableWriter(): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.entity.table as TableDef\n });\n }\n\n public async put<T extends GenericRecord = GenericRecord>(\n item: IPutParamsItem<T>\n ): ReturnType<typeof put> {\n return put({\n entity: this.entity,\n item\n });\n }\n\n public async get<T>(keys: GetRecordParamsKeys): ReturnType<typeof get<T>> {\n return get<T>({\n entity: this.entity,\n keys\n });\n }\n\n public async getClean<T>(keys: GetRecordParamsKeys): ReturnType<typeof getClean<T>> {\n return getClean<T>({\n entity: this.entity,\n keys\n });\n }\n\n public async delete(keys: IDeleteItemKeys): ReturnType<typeof deleteItem> {\n return deleteItem({\n entity: this.entity,\n keys\n });\n }\n\n public queryOne<T>(params: IEntityQueryOneParams): Promise<T | null> {\n return queryOneClean<T>({\n ...params,\n entity: this.entity\n });\n }\n\n public queryAll<T>(params: IEntityQueryAllParams): Promise<T[]> {\n return queryAllClean<T>({\n ...params,\n entity: this.entity\n });\n }\n}\n\nexport const createEntity = (params: EntityConstructor): IEntity => {\n return new Entity(params);\n};\n"],"mappings":";;;;;;AAMA,IAAAA,QAAA,GAAAC,OAAA;AAUA,IAAAC,IAAA,GAAAD,OAAA;AAEA,IAAAE,IAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAkBO,MAAMQ,MAAM,CAAoB;EAG5BC,WAAWA,CAACC,MAAyB,EAAE;IAC1C,IAAI,CAACC,MAAM,GAAG,IAAIC,eAAU,CAACF,MAAM,CAAC;EACxC;EAEOG,kBAAkBA,CAAA,EAAqB;IAC1C,OAAO,IAAAC,sCAAqB,EAAC;MACzBH,MAAM,EAAE,IAAI,CAACA;IACjB,CAAC,CAAC;EACN;EAEOI,kBAAkBA,CAAA,EAAsB;IAC3C,OAAO,IAAAC,wCAAsB,EAAC;MAC1BL,MAAM,EAAE,IAAI,CAACA;IACjB,CAAC,CAAC;EACN;EAEOM,iBAAiBA,CAAA,EAAqB;IACzC,OAAO,IAAAC,sCAAqB,EAAC;MACzBC,KAAK,EAAE,IAAI,CAACR,MAAM,CAACQ;IACvB,CAAC,CAAC;EACN;EAEA,MAAaC,GAAGA,CACZC,IAAuB,EACD;IACtB,OAAO,IAAAD,QAAG,EAAC;MACPT,MAAM,EAAE,IAAI,CAACA,MAAM;MACnBU;IACJ,CAAC,CAAC;EACN;EAEA,MAAaC,GAAGA,CAAIC,IAAyB,EAA6B;IACtE,OAAO,IAAAD,QAAG,EAAI;MACVX,MAAM,EAAE,IAAI,CAACA,MAAM;MACnBY;IACJ,CAAC,CAAC;EACN;EAEA,MAAaC,QAAQA,CAAID,IAAyB,EAAkC;IAChF,OAAO,IAAAC,aAAQ,EAAI;MACfb,MAAM,EAAE,IAAI,CAACA,MAAM;MACnBY;IACJ,CAAC,CAAC;EACN;EAEA,MAAaE,MAAMA,CAACF,IAAqB,EAAiC;IACtE,OAAO,IAAAG,kBAAU,EAAC;MACdf,MAAM,EAAE,IAAI,CAACA,MAAM;MACnBY;IACJ,CAAC,CAAC;EACN;EAEOI,QAAQA,CAAIjB,MAA6B,EAAqB;IACjE,OAAO,IAAAkB,oBAAa,EAAI;MACpB,GAAGlB,MAAM;MACTC,MAAM,EAAE,IAAI,CAACA;IACjB,CAAC,CAAC;EACN;EAEOkB,QAAQA,CAAInB,MAA6B,EAAgB;IAC5D,OAAO,IAAAoB,oBAAa,EAAI;MACpB,GAAGpB,MAAM;MACTC,MAAM,EAAE,IAAI,CAACA;IACjB,CAAC,CAAC;EACN;AACJ;AAACoB,OAAA,CAAAvB,MAAA,GAAAA,MAAA;AAEM,MAAMwB,YAAY,GAAItB,MAAyB,IAAc;EAChE,OAAO,IAAIF,MAAM,CAACE,MAAM,CAAC;AAC7B,CAAC;AAACqB,OAAA,CAAAC,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ import type { IPutBatchItem } from "../batch/types";
2
+ import type { IEntityReadBatch, IEntityReadBatchKey } from "./types";
3
+ import type { GenericRecord } from "@webiny/api/types";
4
+ import type { EntityOption } from "./getEntity";
5
+ export interface IEntityReadBatchParams {
6
+ entity: EntityOption;
7
+ read?: IPutBatchItem[];
8
+ }
9
+ export declare class EntityReadBatch implements IEntityReadBatch {
10
+ private readonly entity;
11
+ private readonly builder;
12
+ private readonly _items;
13
+ constructor(params: IEntityReadBatchParams);
14
+ get(input: IEntityReadBatchKey | IEntityReadBatchKey[]): void;
15
+ execute<T = GenericRecord>(): Promise<T[]>;
16
+ }
17
+ export declare const createEntityReadBatch: (params: IEntityReadBatchParams) => IEntityReadBatch;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEntityReadBatch = exports.EntityReadBatch = void 0;
7
+ var _batchRead = require("../batch/batchRead");
8
+ var _EntityReadBatchBuilder = require("./EntityReadBatchBuilder");
9
+ var _getEntity = require("./getEntity");
10
+ class EntityReadBatch {
11
+ _items = [];
12
+ constructor(params) {
13
+ this.entity = (0, _getEntity.getEntity)(params.entity);
14
+ this.builder = (0, _EntityReadBatchBuilder.createEntityReadBatchBuilder)(this.entity);
15
+ for (const item of params.read || []) {
16
+ this.get(item);
17
+ }
18
+ }
19
+ get(input) {
20
+ if (Array.isArray(input)) {
21
+ this._items.push(...input.map(item => {
22
+ return this.builder.get(item);
23
+ }));
24
+ return;
25
+ }
26
+ this._items.push(this.builder.get(input));
27
+ }
28
+ async execute() {
29
+ return await (0, _batchRead.batchReadAll)({
30
+ table: this.entity.table,
31
+ items: this._items
32
+ });
33
+ }
34
+ }
35
+ exports.EntityReadBatch = EntityReadBatch;
36
+ const createEntityReadBatch = params => {
37
+ return new EntityReadBatch(params);
38
+ };
39
+ exports.createEntityReadBatch = createEntityReadBatch;
40
+
41
+ //# sourceMappingURL=EntityReadBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_batchRead","require","_EntityReadBatchBuilder","_getEntity","EntityReadBatch","_items","constructor","params","entity","getEntity","builder","createEntityReadBatchBuilder","item","read","get","input","Array","isArray","push","map","execute","batchReadAll","table","items","exports","createEntityReadBatch"],"sources":["EntityReadBatch.ts"],"sourcesContent":["import type { IPutBatchItem } from \"~/utils/batch/types\";\nimport type {\n IEntityReadBatch,\n IEntityReadBatchBuilder,\n IEntityReadBatchBuilderGetResponse,\n IEntityReadBatchKey\n} from \"./types\";\nimport type { TableDef } from \"~/toolbox\";\nimport type { Entity as ToolboxEntity } from \"~/toolbox\";\nimport { batchReadAll } from \"~/utils/batch/batchRead\";\nimport type { GenericRecord } from \"@webiny/api/types\";\nimport { createEntityReadBatchBuilder } from \"./EntityReadBatchBuilder\";\nimport type { EntityOption } from \"./getEntity\";\nimport { getEntity } from \"./getEntity\";\n\nexport interface IEntityReadBatchParams {\n entity: EntityOption;\n read?: IPutBatchItem[];\n}\n\nexport class EntityReadBatch implements IEntityReadBatch {\n private readonly entity: ToolboxEntity;\n private readonly builder: IEntityReadBatchBuilder;\n private readonly _items: IEntityReadBatchBuilderGetResponse[] = [];\n\n public constructor(params: IEntityReadBatchParams) {\n this.entity = getEntity(params.entity);\n this.builder = createEntityReadBatchBuilder(this.entity);\n for (const item of params.read || []) {\n this.get(item);\n }\n }\n public get(input: IEntityReadBatchKey | IEntityReadBatchKey[]): void {\n if (Array.isArray(input)) {\n this._items.push(\n ...input.map(item => {\n return this.builder.get(item);\n })\n );\n return;\n }\n this._items.push(this.builder.get(input));\n }\n\n public async execute<T = GenericRecord>() {\n return await batchReadAll<T>({\n table: this.entity.table as TableDef,\n items: this._items\n });\n }\n}\n\nexport const createEntityReadBatch = (params: IEntityReadBatchParams): IEntityReadBatch => {\n return new EntityReadBatch(params);\n};\n"],"mappings":";;;;;;AASA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,uBAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAOO,MAAMG,eAAe,CAA6B;EAGpCC,MAAM,GAAyC,EAAE;EAE3DC,WAAWA,CAACC,MAA8B,EAAE;IAC/C,IAAI,CAACC,MAAM,GAAG,IAAAC,oBAAS,EAACF,MAAM,CAACC,MAAM,CAAC;IACtC,IAAI,CAACE,OAAO,GAAG,IAAAC,oDAA4B,EAAC,IAAI,CAACH,MAAM,CAAC;IACxD,KAAK,MAAMI,IAAI,IAAIL,MAAM,CAACM,IAAI,IAAI,EAAE,EAAE;MAClC,IAAI,CAACC,GAAG,CAACF,IAAI,CAAC;IAClB;EACJ;EACOE,GAAGA,CAACC,KAAkD,EAAQ;IACjE,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACtB,IAAI,CAACV,MAAM,CAACa,IAAI,CACZ,GAAGH,KAAK,CAACI,GAAG,CAACP,IAAI,IAAI;QACjB,OAAO,IAAI,CAACF,OAAO,CAACI,GAAG,CAACF,IAAI,CAAC;MACjC,CAAC,CACL,CAAC;MACD;IACJ;IACA,IAAI,CAACP,MAAM,CAACa,IAAI,CAAC,IAAI,CAACR,OAAO,CAACI,GAAG,CAACC,KAAK,CAAC,CAAC;EAC7C;EAEA,MAAaK,OAAOA,CAAA,EAAsB;IACtC,OAAO,MAAM,IAAAC,uBAAY,EAAI;MACzBC,KAAK,EAAE,IAAI,CAACd,MAAM,CAACc,KAAiB;MACpCC,KAAK,EAAE,IAAI,CAAClB;IAChB,CAAC,CAAC;EACN;AACJ;AAACmB,OAAA,CAAApB,eAAA,GAAAA,eAAA;AAEM,MAAMqB,qBAAqB,GAAIlB,MAA8B,IAAuB;EACvF,OAAO,IAAIH,eAAe,CAACG,MAAM,CAAC;AACtC,CAAC;AAACiB,OAAA,CAAAC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import type { Entity as ToolboxEntity } from "../../toolbox";
2
+ import type { IEntityReadBatchBuilder, IEntityReadBatchBuilderGetResponse, IEntityReadBatchKey } from "./types";
3
+ import type { Entity } from "./Entity";
4
+ import type { EntityOption } from "./getEntity";
5
+ export declare class EntityReadBatchBuilder implements IEntityReadBatchBuilder {
6
+ private readonly entity;
7
+ constructor(entity: EntityOption);
8
+ get(item: IEntityReadBatchKey): IEntityReadBatchBuilderGetResponse;
9
+ }
10
+ export declare const createEntityReadBatchBuilder: (entity: ToolboxEntity | Entity) => IEntityReadBatchBuilder;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEntityReadBatchBuilder = exports.EntityReadBatchBuilder = void 0;
7
+ var _error = require("@webiny/error");
8
+ var _getEntity = require("./getEntity");
9
+ class EntityReadBatchBuilder {
10
+ constructor(entity) {
11
+ this.entity = (0, _getEntity.getEntity)(entity);
12
+ }
13
+ get(item) {
14
+ const result = this.entity.getBatch(item);
15
+ if (!result.Table) {
16
+ throw new _error.WebinyError(`No table provided for entity ${this.entity.name}.`);
17
+ } else if (!result.Key) {
18
+ throw new _error.WebinyError(`No key provided for entity ${this.entity.name}.`);
19
+ }
20
+ return result;
21
+ }
22
+ }
23
+ exports.EntityReadBatchBuilder = EntityReadBatchBuilder;
24
+ const createEntityReadBatchBuilder = entity => {
25
+ return new EntityReadBatchBuilder(entity);
26
+ };
27
+ exports.createEntityReadBatchBuilder = createEntityReadBatchBuilder;
28
+
29
+ //# sourceMappingURL=EntityReadBatchBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","require","_getEntity","EntityReadBatchBuilder","constructor","entity","getEntity","get","item","result","getBatch","Table","WebinyError","name","Key","exports","createEntityReadBatchBuilder"],"sources":["EntityReadBatchBuilder.ts"],"sourcesContent":["import type { Entity as ToolboxEntity } from \"~/toolbox\";\nimport type {\n IEntityReadBatchBuilder,\n IEntityReadBatchBuilderGetResponse,\n IEntityReadBatchKey\n} from \"./types\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { Entity } from \"./Entity\";\nimport type { EntityOption } from \"./getEntity\";\nimport { getEntity } from \"./getEntity\";\n\nexport class EntityReadBatchBuilder implements IEntityReadBatchBuilder {\n private readonly entity: ToolboxEntity;\n\n public constructor(entity: EntityOption) {\n this.entity = getEntity(entity);\n }\n\n public get(item: IEntityReadBatchKey): IEntityReadBatchBuilderGetResponse {\n const result = this.entity.getBatch(item);\n if (!result.Table) {\n throw new WebinyError(`No table provided for entity ${this.entity.name}.`);\n } else if (!result.Key) {\n throw new WebinyError(`No key provided for entity ${this.entity.name}.`);\n }\n return result as IEntityReadBatchBuilderGetResponse;\n }\n}\n\nexport const createEntityReadBatchBuilder = (\n entity: ToolboxEntity | Entity\n): IEntityReadBatchBuilder => {\n return new EntityReadBatchBuilder(entity);\n};\n"],"mappings":";;;;;;AAMA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AAEO,MAAME,sBAAsB,CAAoC;EAG5DC,WAAWA,CAACC,MAAoB,EAAE;IACrC,IAAI,CAACA,MAAM,GAAG,IAAAC,oBAAS,EAACD,MAAM,CAAC;EACnC;EAEOE,GAAGA,CAACC,IAAyB,EAAsC;IACtE,MAAMC,MAAM,GAAG,IAAI,CAACJ,MAAM,CAACK,QAAQ,CAACF,IAAI,CAAC;IACzC,IAAI,CAACC,MAAM,CAACE,KAAK,EAAE;MACf,MAAM,IAAIC,kBAAW,CAAC,gCAAgC,IAAI,CAACP,MAAM,CAACQ,IAAI,GAAG,CAAC;IAC9E,CAAC,MAAM,IAAI,CAACJ,MAAM,CAACK,GAAG,EAAE;MACpB,MAAM,IAAIF,kBAAW,CAAC,8BAA8B,IAAI,CAACP,MAAM,CAACQ,IAAI,GAAG,CAAC;IAC5E;IACA,OAAOJ,MAAM;EACjB;AACJ;AAACM,OAAA,CAAAZ,sBAAA,GAAAA,sBAAA;AAEM,MAAMa,4BAA4B,GACrCX,MAA8B,IACJ;EAC1B,OAAO,IAAIF,sBAAsB,CAACE,MAAM,CAAC;AAC7C,CAAC;AAACU,OAAA,CAAAC,4BAAA,GAAAA,4BAAA","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ import type { BatchWriteItem, BatchWriteResult, IDeleteBatchItem, IPutBatchItem } from "../batch/types";
2
+ import type { IEntityWriteBatch } from "./types";
3
+ import type { ITableWriteBatch } from "../table/types";
4
+ import type { EntityOption } from "./getEntity";
5
+ export interface IEntityWriteBatchParams {
6
+ entity: EntityOption;
7
+ put?: IPutBatchItem[];
8
+ delete?: IDeleteBatchItem[];
9
+ }
10
+ export declare class EntityWriteBatch implements IEntityWriteBatch {
11
+ private readonly entity;
12
+ private readonly _items;
13
+ private readonly builder;
14
+ get total(): number;
15
+ get items(): BatchWriteItem[];
16
+ constructor(params: IEntityWriteBatchParams);
17
+ put<T extends Record<string, any>>(item: IPutBatchItem<T>): void;
18
+ delete(item: IDeleteBatchItem): void;
19
+ combine(items: BatchWriteItem[]): ITableWriteBatch;
20
+ execute(): Promise<BatchWriteResult>;
21
+ }
22
+ export declare const createEntityWriteBatch: (params: IEntityWriteBatchParams) => IEntityWriteBatch;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEntityWriteBatch = exports.EntityWriteBatch = void 0;
7
+ var _batchWrite = require("../batch/batchWrite");
8
+ var _TableWriteBatch = require("../table/TableWriteBatch");
9
+ var _EntityWriteBatchBuilder = require("./EntityWriteBatchBuilder");
10
+ var _getEntity = require("./getEntity");
11
+ class EntityWriteBatch {
12
+ _items = [];
13
+ get total() {
14
+ return this._items.length;
15
+ }
16
+ get items() {
17
+ return Array.from(this._items);
18
+ }
19
+ constructor(params) {
20
+ this.entity = (0, _getEntity.getEntity)(params.entity);
21
+ this.builder = (0, _EntityWriteBatchBuilder.createEntityWriteBatchBuilder)(this.entity);
22
+ for (const item of params.put || []) {
23
+ this.put(item);
24
+ }
25
+ for (const item of params.delete || []) {
26
+ this.delete(item);
27
+ }
28
+ }
29
+ put(item) {
30
+ this._items.push(this.builder.put(item));
31
+ }
32
+ delete(item) {
33
+ this._items.push(this.builder.delete(item));
34
+ }
35
+ combine(items) {
36
+ return (0, _TableWriteBatch.createTableWriteBatch)({
37
+ table: this.entity.table,
38
+ items: this._items.concat(items)
39
+ });
40
+ }
41
+ async execute() {
42
+ if (this._items.length === 0) {
43
+ return [];
44
+ }
45
+ const items = Array.from(this._items);
46
+ this._items.length = 0;
47
+ return await (0, _batchWrite.batchWriteAll)({
48
+ items,
49
+ table: this.entity.table
50
+ });
51
+ }
52
+ }
53
+ exports.EntityWriteBatch = EntityWriteBatch;
54
+ const createEntityWriteBatch = params => {
55
+ return new EntityWriteBatch(params);
56
+ };
57
+ exports.createEntityWriteBatch = createEntityWriteBatch;
58
+
59
+ //# sourceMappingURL=EntityWriteBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_batchWrite","require","_TableWriteBatch","_EntityWriteBatchBuilder","_getEntity","EntityWriteBatch","_items","total","length","items","Array","from","constructor","params","entity","getEntity","builder","createEntityWriteBatchBuilder","item","put","delete","push","combine","createTableWriteBatch","table","concat","execute","batchWriteAll","exports","createEntityWriteBatch"],"sources":["EntityWriteBatch.ts"],"sourcesContent":["import type { TableDef } from \"~/toolbox\";\nimport type { Entity as ToolboxEntity } from \"~/toolbox\";\nimport { batchWriteAll } from \"~/utils/batch/batchWrite\";\nimport type {\n BatchWriteItem,\n BatchWriteResult,\n IDeleteBatchItem,\n IPutBatchItem\n} from \"~/utils/batch/types\";\nimport type { IEntityWriteBatch, IEntityWriteBatchBuilder } from \"./types\";\nimport type { ITableWriteBatch } from \"~/utils/table/types\";\nimport { createTableWriteBatch } from \"~/utils/table/TableWriteBatch\";\nimport { createEntityWriteBatchBuilder } from \"./EntityWriteBatchBuilder\";\nimport type { EntityOption } from \"./getEntity\";\nimport { getEntity } from \"./getEntity\";\n\nexport interface IEntityWriteBatchParams {\n entity: EntityOption;\n put?: IPutBatchItem[];\n delete?: IDeleteBatchItem[];\n}\n\nexport class EntityWriteBatch implements IEntityWriteBatch {\n private readonly entity: ToolboxEntity;\n private readonly _items: BatchWriteItem[] = [];\n private readonly builder: IEntityWriteBatchBuilder;\n\n public get total(): number {\n return this._items.length;\n }\n\n public get items(): BatchWriteItem[] {\n return Array.from(this._items);\n }\n\n public constructor(params: IEntityWriteBatchParams) {\n this.entity = getEntity(params.entity);\n this.builder = createEntityWriteBatchBuilder(this.entity);\n for (const item of params.put || []) {\n this.put(item);\n }\n for (const item of params.delete || []) {\n this.delete(item);\n }\n }\n\n public put<T extends Record<string, any>>(item: IPutBatchItem<T>): void {\n this._items.push(this.builder.put(item));\n }\n\n public delete(item: IDeleteBatchItem): void {\n this._items.push(this.builder.delete(item));\n }\n\n public combine(items: BatchWriteItem[]): ITableWriteBatch {\n return createTableWriteBatch({\n table: this.entity!.table as TableDef,\n items: this._items.concat(items)\n });\n }\n\n public async execute(): Promise<BatchWriteResult> {\n if (this._items.length === 0) {\n return [];\n }\n const items = Array.from(this._items);\n this._items.length = 0;\n return await batchWriteAll({\n items,\n table: this.entity.table\n });\n }\n}\n\nexport const createEntityWriteBatch = (params: IEntityWriteBatchParams): IEntityWriteBatch => {\n return new EntityWriteBatch(params);\n};\n"],"mappings":";;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AASA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,wBAAA,GAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAH,OAAA;AAQO,MAAMI,gBAAgB,CAA8B;EAEtCC,MAAM,GAAqB,EAAE;EAG9C,IAAWC,KAAKA,CAAA,EAAW;IACvB,OAAO,IAAI,CAACD,MAAM,CAACE,MAAM;EAC7B;EAEA,IAAWC,KAAKA,CAAA,EAAqB;IACjC,OAAOC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACL,MAAM,CAAC;EAClC;EAEOM,WAAWA,CAACC,MAA+B,EAAE;IAChD,IAAI,CAACC,MAAM,GAAG,IAAAC,oBAAS,EAACF,MAAM,CAACC,MAAM,CAAC;IACtC,IAAI,CAACE,OAAO,GAAG,IAAAC,sDAA6B,EAAC,IAAI,CAACH,MAAM,CAAC;IACzD,KAAK,MAAMI,IAAI,IAAIL,MAAM,CAACM,GAAG,IAAI,EAAE,EAAE;MACjC,IAAI,CAACA,GAAG,CAACD,IAAI,CAAC;IAClB;IACA,KAAK,MAAMA,IAAI,IAAIL,MAAM,CAACO,MAAM,IAAI,EAAE,EAAE;MACpC,IAAI,CAACA,MAAM,CAACF,IAAI,CAAC;IACrB;EACJ;EAEOC,GAAGA,CAAgCD,IAAsB,EAAQ;IACpE,IAAI,CAACZ,MAAM,CAACe,IAAI,CAAC,IAAI,CAACL,OAAO,CAACG,GAAG,CAACD,IAAI,CAAC,CAAC;EAC5C;EAEOE,MAAMA,CAACF,IAAsB,EAAQ;IACxC,IAAI,CAACZ,MAAM,CAACe,IAAI,CAAC,IAAI,CAACL,OAAO,CAACI,MAAM,CAACF,IAAI,CAAC,CAAC;EAC/C;EAEOI,OAAOA,CAACb,KAAuB,EAAoB;IACtD,OAAO,IAAAc,sCAAqB,EAAC;MACzBC,KAAK,EAAE,IAAI,CAACV,MAAM,CAAEU,KAAiB;MACrCf,KAAK,EAAE,IAAI,CAACH,MAAM,CAACmB,MAAM,CAAChB,KAAK;IACnC,CAAC,CAAC;EACN;EAEA,MAAaiB,OAAOA,CAAA,EAA8B;IAC9C,IAAI,IAAI,CAACpB,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;MAC1B,OAAO,EAAE;IACb;IACA,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACL,MAAM,CAAC;IACrC,IAAI,CAACA,MAAM,CAACE,MAAM,GAAG,CAAC;IACtB,OAAO,MAAM,IAAAmB,yBAAa,EAAC;MACvBlB,KAAK;MACLe,KAAK,EAAE,IAAI,CAACV,MAAM,CAACU;IACvB,CAAC,CAAC;EACN;AACJ;AAACI,OAAA,CAAAvB,gBAAA,GAAAA,gBAAA;AAEM,MAAMwB,sBAAsB,GAAIhB,MAA+B,IAAwB;EAC1F,OAAO,IAAIR,gBAAgB,CAACQ,MAAM,CAAC;AACvC,CAAC;AAACe,OAAA,CAAAC,sBAAA,GAAAA,sBAAA","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import type { Entity } from "../../toolbox";
2
+ import type { BatchWriteItem, IDeleteBatchItem, IPutBatchItem } from "../batch/types";
3
+ import type { IEntityWriteBatchBuilder } from "./types";
4
+ import type { EntityOption } from "./getEntity";
5
+ export declare class EntityWriteBatchBuilder implements IEntityWriteBatchBuilder {
6
+ private readonly entity;
7
+ constructor(entity: EntityOption);
8
+ put<T extends Record<string, any>>(item: IPutBatchItem<T>): BatchWriteItem;
9
+ delete(item: IDeleteBatchItem): BatchWriteItem;
10
+ }
11
+ export declare const createEntityWriteBatchBuilder: (entity: Entity) => IEntityWriteBatchBuilder;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEntityWriteBatchBuilder = exports.EntityWriteBatchBuilder = void 0;
7
+ var _getEntity = require("./getEntity");
8
+ class EntityWriteBatchBuilder {
9
+ constructor(entity) {
10
+ this.entity = (0, _getEntity.getEntity)(entity);
11
+ }
12
+ put(item) {
13
+ return this.entity.putBatch(item, {
14
+ execute: true,
15
+ strictSchemaCheck: false
16
+ });
17
+ }
18
+ delete(item) {
19
+ return this.entity.deleteBatch(item);
20
+ }
21
+ }
22
+ exports.EntityWriteBatchBuilder = EntityWriteBatchBuilder;
23
+ const createEntityWriteBatchBuilder = entity => {
24
+ return new EntityWriteBatchBuilder(entity);
25
+ };
26
+ exports.createEntityWriteBatchBuilder = createEntityWriteBatchBuilder;
27
+
28
+ //# sourceMappingURL=EntityWriteBatchBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_getEntity","require","EntityWriteBatchBuilder","constructor","entity","getEntity","put","item","putBatch","execute","strictSchemaCheck","delete","deleteBatch","exports","createEntityWriteBatchBuilder"],"sources":["EntityWriteBatchBuilder.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox\";\nimport type { BatchWriteItem, IDeleteBatchItem, IPutBatchItem } from \"~/utils/batch/types\";\nimport type { IEntityWriteBatchBuilder } from \"./types\";\nimport type { EntityOption } from \"./getEntity\";\nimport { getEntity } from \"./getEntity\";\n\nexport class EntityWriteBatchBuilder implements IEntityWriteBatchBuilder {\n private readonly entity: Entity;\n\n public constructor(entity: EntityOption) {\n this.entity = getEntity(entity);\n }\n\n public put<T extends Record<string, any>>(item: IPutBatchItem<T>): BatchWriteItem {\n return this.entity.putBatch(item, {\n execute: true,\n strictSchemaCheck: false\n });\n }\n\n public delete(item: IDeleteBatchItem): BatchWriteItem {\n return this.entity.deleteBatch(item);\n }\n}\n\nexport const createEntityWriteBatchBuilder = (entity: Entity): IEntityWriteBatchBuilder => {\n return new EntityWriteBatchBuilder(entity);\n};\n"],"mappings":";;;;;;AAIA,IAAAA,UAAA,GAAAC,OAAA;AAEO,MAAMC,uBAAuB,CAAqC;EAG9DC,WAAWA,CAACC,MAAoB,EAAE;IACrC,IAAI,CAACA,MAAM,GAAG,IAAAC,oBAAS,EAACD,MAAM,CAAC;EACnC;EAEOE,GAAGA,CAAgCC,IAAsB,EAAkB;IAC9E,OAAO,IAAI,CAACH,MAAM,CAACI,QAAQ,CAACD,IAAI,EAAE;MAC9BE,OAAO,EAAE,IAAI;MACbC,iBAAiB,EAAE;IACvB,CAAC,CAAC;EACN;EAEOC,MAAMA,CAACJ,IAAsB,EAAkB;IAClD,OAAO,IAAI,CAACH,MAAM,CAACQ,WAAW,CAACL,IAAI,CAAC;EACxC;AACJ;AAACM,OAAA,CAAAX,uBAAA,GAAAA,uBAAA;AAEM,MAAMY,6BAA6B,GAAIV,MAAc,IAA+B;EACvF,OAAO,IAAIF,uBAAuB,CAACE,MAAM,CAAC;AAC9C,CAAC;AAACS,OAAA,CAAAC,6BAAA,GAAAA,6BAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import { Entity as ToolboxEntity } from "../../toolbox";
2
+ import type { Entity } from "./Entity";
3
+ export type EntityOption = ToolboxEntity | Entity;
4
+ export declare const getEntity: (entity: EntityOption) => ToolboxEntity;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getEntity = void 0;
7
+ var _toolbox = require("../../toolbox");
8
+ const getEntity = entity => {
9
+ const result = entity instanceof _toolbox.Entity ? entity : entity.entity;
10
+ if (!result.name) {
11
+ throw new Error(`No name provided for entity.`);
12
+ } else if (!result.table) {
13
+ throw new Error(`No table provided for entity ${result.name}.`);
14
+ }
15
+ return result;
16
+ };
17
+ exports.getEntity = getEntity;
18
+
19
+ //# sourceMappingURL=getEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_toolbox","require","getEntity","entity","result","ToolboxEntity","name","Error","table","exports"],"sources":["getEntity.ts"],"sourcesContent":["import { Entity as ToolboxEntity } from \"~/toolbox\";\nimport type { Entity } from \"./Entity\";\n\nexport type EntityOption = ToolboxEntity | Entity;\n\nexport const getEntity = (entity: EntityOption): ToolboxEntity => {\n const result = entity instanceof ToolboxEntity ? entity : entity.entity;\n if (!result.name) {\n throw new Error(`No name provided for entity.`);\n } else if (!result.table) {\n throw new Error(`No table provided for entity ${result.name}.`);\n }\n return result;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAKO,MAAMC,SAAS,GAAIC,MAAoB,IAAoB;EAC9D,MAAMC,MAAM,GAAGD,MAAM,YAAYE,eAAa,GAAGF,MAAM,GAAGA,MAAM,CAACA,MAAM;EACvE,IAAI,CAACC,MAAM,CAACE,IAAI,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,8BAA8B,CAAC;EACnD,CAAC,MAAM,IAAI,CAACH,MAAM,CAACI,KAAK,EAAE;IACtB,MAAM,IAAID,KAAK,CAAC,gCAAgCH,MAAM,CAACE,IAAI,GAAG,CAAC;EACnE;EACA,OAAOF,MAAM;AACjB,CAAC;AAACK,OAAA,CAAAP,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ export * from "./Entity";
2
+ export * from "./EntityReadBatch";
3
+ export * from "./EntityReadBatchBuilder";
4
+ export * from "./EntityWriteBatch";
5
+ export * from "./EntityWriteBatchBuilder";
6
+ export * from "./getEntity";
7
+ export * from "./types";