@webiny/db-dynamodb 5.41.4-beta.4 → 5.41.4-beta.5

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 (78) hide show
  1. package/README.md +81 -1
  2. package/index.d.ts +1 -1
  3. package/index.js +1 -9
  4. package/index.js.map +1 -1
  5. package/package.json +10 -11
  6. package/toolbox.d.ts +1 -1
  7. package/toolbox.js.map +1 -1
  8. package/utils/{batchRead.d.ts → batch/batchRead.d.ts} +1 -1
  9. package/utils/batch/batchWrite.d.ts +13 -0
  10. package/utils/batch/batchWrite.js.map +1 -0
  11. package/utils/batch/index.d.ts +3 -0
  12. package/utils/batch/index.js +40 -0
  13. package/utils/batch/index.js.map +1 -0
  14. package/utils/batch/types.d.ts +25 -0
  15. package/utils/batch/types.js +7 -0
  16. package/utils/batch/types.js.map +1 -0
  17. package/utils/delete.d.ts +7 -7
  18. package/utils/delete.js.map +1 -1
  19. package/utils/entity/Entity.d.ts +25 -0
  20. package/utils/entity/Entity.js +77 -0
  21. package/utils/entity/Entity.js.map +1 -0
  22. package/utils/entity/EntityReadBatch.d.ts +17 -0
  23. package/utils/entity/EntityReadBatch.js +41 -0
  24. package/utils/entity/EntityReadBatch.js.map +1 -0
  25. package/utils/entity/EntityReadBatchBuilder.d.ts +10 -0
  26. package/utils/entity/EntityReadBatchBuilder.js +29 -0
  27. package/utils/entity/EntityReadBatchBuilder.js.map +1 -0
  28. package/utils/entity/EntityWriteBatch.d.ts +22 -0
  29. package/utils/entity/EntityWriteBatch.js +59 -0
  30. package/utils/entity/EntityWriteBatch.js.map +1 -0
  31. package/utils/entity/EntityWriteBatchBuilder.d.ts +11 -0
  32. package/utils/entity/EntityWriteBatchBuilder.js +28 -0
  33. package/utils/entity/EntityWriteBatchBuilder.js.map +1 -0
  34. package/utils/entity/getEntity.d.ts +4 -0
  35. package/utils/entity/getEntity.js +19 -0
  36. package/utils/entity/getEntity.js.map +1 -0
  37. package/utils/entity/index.d.ts +7 -0
  38. package/utils/entity/index.js +84 -0
  39. package/utils/entity/index.js.map +1 -0
  40. package/utils/entity/types.d.ts +51 -0
  41. package/utils/entity/types.js +7 -0
  42. package/utils/entity/types.js.map +1 -0
  43. package/utils/get.d.ts +5 -4
  44. package/utils/get.js.map +1 -1
  45. package/utils/index.d.ts +3 -3
  46. package/utils/index.js +30 -30
  47. package/utils/index.js.map +1 -1
  48. package/utils/put.d.ts +8 -8
  49. package/utils/put.js +2 -1
  50. package/utils/put.js.map +1 -1
  51. package/utils/scan.d.ts +4 -4
  52. package/utils/scan.js.map +1 -1
  53. package/utils/table/Table.d.ts +10 -0
  54. package/utils/table/Table.js +34 -0
  55. package/utils/table/Table.js.map +1 -0
  56. package/utils/table/TableReadBatch.d.ts +19 -0
  57. package/utils/table/TableReadBatch.js +62 -0
  58. package/utils/table/TableReadBatch.js.map +1 -0
  59. package/utils/table/TableWriteBatch.d.ts +21 -0
  60. package/utils/table/TableWriteBatch.js +69 -0
  61. package/utils/table/TableWriteBatch.js.map +1 -0
  62. package/utils/table/index.d.ts +4 -0
  63. package/utils/table/index.js +51 -0
  64. package/utils/table/index.js.map +1 -0
  65. package/utils/table/types.d.ts +39 -0
  66. package/utils/table/types.js +7 -0
  67. package/utils/table/types.js.map +1 -0
  68. package/utils/update.d.ts +1 -0
  69. package/utils/update.js +2 -1
  70. package/utils/update.js.map +1 -1
  71. package/utils/batchWrite.d.ts +0 -29
  72. package/utils/batchWrite.js.map +0 -1
  73. package/utils/table.d.ts +0 -7
  74. package/utils/table.js +0 -24
  75. package/utils/table.js.map +0 -1
  76. /package/utils/{batchRead.js → batch/batchRead.js} +0 -0
  77. /package/utils/{batchRead.js.map → batch/batchRead.js.map} +0 -0
  78. /package/utils/{batchWrite.js → batch/batchWrite.js} +0 -0
package/README.md CHANGED
@@ -14,6 +14,86 @@ For more information, please visit
14
14
  yarn add @webiny/db-dynamodb
15
15
  ```
16
16
 
17
+ ### Helper classes
18
+ We have some classes that ease the use of dynamodb-toolbox.
19
+ #### [Table](./src/utils/table/Table.ts)
20
+ ```typescript
21
+ import { createTable } from "@webiny/db-dynamodb";
22
+
23
+ const table = createTable({...params});
24
+ const writer = table.createWriter(); // see TableWriteBatch
25
+ const reader = table.createReader(); // see TableReadBatch
26
+
27
+ const result = await table.scan({...params}); // see scan
28
+ ```
29
+
30
+ #### [Entity](./src/utils/entity/Entity.ts)
31
+ ```typescript
32
+
33
+ import { createEntity } from "@webiny/db-dynamodb";
34
+
35
+ const entity = createEntity({...params});
36
+ const writer = entity.createWriter(); // see EntityWriteBatch
37
+ const reader = entity.createReader(); // see EntityReadBatch
38
+ const tableWriter = entity.createTableWriter(); // see TableWriteBatch
39
+
40
+ const getResult = await entity.get({...params}); // see get
41
+ const getCleanResult = await entity.getClean({...params}); // see get
42
+ const queryAllResult = await entity.queryAll({...params}); // see queryAllClean
43
+ const queryOneResult = await entity.queryOne({...params}); // see queryOneClean
44
+ const putResult = await entity.put({...params}); // see put
45
+
46
+ ```
47
+
48
+ #### [EntityWriteBatch](./src/utils/entity/EntityWriteBatch.ts)
49
+ ```typescript
50
+ import { createEntityWriteBatch } from "@webiny/db-dynamodb";
51
+
52
+ const writer = createEntityWriteBatch({...params});
53
+
54
+ writer.put({...item});
55
+ writer.delete({...keys});
56
+ writer.delete({...moreKeys});
57
+
58
+ await writer.execute();
59
+ ```
60
+
61
+ #### [EntityReadBatch](./src/utils/entity/EntityReadBatch.ts)
62
+ ```typescript
63
+ import { createEntityReadBatch } from "@webiny/db-dynamodb";
64
+
65
+ const reader = createEntityReadBatch({...params});
66
+
67
+ reader.get({...keys});
68
+ reader.get({...moreKeys});
69
+
70
+ const result = await reader.execute();
71
+ ```
72
+ #### [TableWriteBatch](./src/utils/table/TableWriteBatch.ts)
73
+ ```typescript
74
+ import { createTableWriteBatch } from "@webiny/db-dynamodb";
75
+
76
+ const writer = createTableWriteBatch({...params});
77
+
78
+ writer.put(entity, {...item});
79
+ writer.delete(entity, {...keys});
80
+ writer.delete(entity, {...moreKeys});
81
+
82
+ await writer.execute();
83
+ ```
84
+ #### [TableReadBatch](./src/utils/table/TableReadBatch.ts)
85
+ ```typescript
86
+ import {createTableReadBatch} from "@webiny/db-dynamodb";
87
+
88
+ const reader = createTableReadBatch({...params});
89
+
90
+ writer.get(entity, {...keys});
91
+ writer.get(entity, {...moreKeys});
92
+
93
+ const result = await reader.execute();
94
+ ```
95
+
96
+
17
97
 
18
98
  ### Helper functions
19
99
  We have a number [helper](./src/utils) functions that ease the use of either dynamodb-toolbox, filtering, sorting or just creating proper response.
@@ -64,4 +144,4 @@ This function accepts items (records) to be filtered, a definition of fields to
64
144
  #### [sort](./src/utils/sort.ts)
65
145
  Sort the DynamoDB records by given sort condition.
66
146
 
67
- This function accepts items (records) to be sorted, sort options (eg. createdBy_ASC, id_DESC, etc.) and a definitions of fields to sort by (not required by default if no field modification is required).
147
+ This function accepts items (records) to be sorted, sort options (eg. createdBy_ASC, id_DESC, etc.) and a definitions of fields to sort by (not required by default if no field modification is required).
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { default as DynamoDbDriver } from "./DynamoDbDriver";
2
2
  export * from "./utils";
3
- export { DbItem } from "./types";
3
+ export type { DbItem } from "./types";
4
4
  export { DynamoDbDriver };
package/index.js CHANGED
@@ -5,15 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  var _exportNames = {
8
- DynamoDbDriver: true,
9
- DbItem: true
8
+ DynamoDbDriver: true
10
9
  };
11
- Object.defineProperty(exports, "DbItem", {
12
- enumerable: true,
13
- get: function () {
14
- return _types.DbItem;
15
- }
16
- });
17
10
  Object.defineProperty(exports, "DynamoDbDriver", {
18
11
  enumerable: true,
19
12
  get: function () {
@@ -33,6 +26,5 @@ Object.keys(_utils).forEach(function (key) {
33
26
  }
34
27
  });
35
28
  });
36
- var _types = require("./types");
37
29
 
38
30
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_DynamoDbDriver","_interopRequireDefault","require","_utils","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_types"],"sources":["index.ts"],"sourcesContent":["import { default as DynamoDbDriver } from \"./DynamoDbDriver\";\n\nexport * from \"./utils\";\nexport { DbItem } from \"./types\";\n\nexport { DynamoDbDriver };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,MAAA,GAAAd,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_DynamoDbDriver","_interopRequireDefault","require","_utils","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["import { default as DynamoDbDriver } from \"./DynamoDbDriver\";\n\nexport * from \"./utils\";\nexport type { DbItem } from \"./types\";\n\nexport { DynamoDbDriver };\n"],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/db-dynamodb",
3
- "version": "5.41.4-beta.4",
3
+ "version": "5.41.4-beta.5",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,13 +10,12 @@
10
10
  "author": "Webiny Ltd",
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@webiny/api": "5.41.4-beta.4",
14
- "@webiny/aws-sdk": "5.41.4-beta.4",
15
- "@webiny/db": "5.41.4-beta.4",
16
- "@webiny/error": "5.41.4-beta.4",
17
- "@webiny/handler-db": "5.41.4-beta.4",
18
- "@webiny/plugins": "5.41.4-beta.4",
19
- "@webiny/utils": "5.41.4-beta.4",
13
+ "@webiny/api": "5.41.4-beta.5",
14
+ "@webiny/aws-sdk": "5.41.4-beta.5",
15
+ "@webiny/db": "5.41.4-beta.5",
16
+ "@webiny/error": "5.41.4-beta.5",
17
+ "@webiny/plugins": "5.41.4-beta.5",
18
+ "@webiny/utils": "5.41.4-beta.5",
20
19
  "date-fns": "2.29.3",
21
20
  "dot-prop": "6.0.1",
22
21
  "dynamodb-toolbox": "0.9.2",
@@ -27,8 +26,8 @@
27
26
  "@babel/cli": "7.24.1",
28
27
  "@babel/core": "7.24.3",
29
28
  "@types/is-number": "7.0.3",
30
- "@webiny/cli": "5.41.4-beta.4",
31
- "@webiny/project-utils": "5.41.4-beta.4",
29
+ "@webiny/cli": "5.41.4-beta.5",
30
+ "@webiny/project-utils": "5.41.4-beta.5",
32
31
  "jest": "29.7.0",
33
32
  "jest-dynalite": "3.6.1",
34
33
  "rimraf": "5.0.5",
@@ -43,5 +42,5 @@
43
42
  "build": "yarn webiny run build",
44
43
  "watch": "yarn webiny run watch"
45
44
  },
46
- "gitHead": "1bd23a34dd4fa6095946a1eb433741ac7da7cbee"
45
+ "gitHead": "e3f273ea63f0c426c2ddde0794d303bc8ffaa6c4"
47
46
  }
package/toolbox.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { Entity, Table } from "dynamodb-toolbox";
2
2
  export type { DynamoDBTypes, ScanOptions, TableDef, TableConstructor } from "dynamodb-toolbox/dist/cjs/classes/Table";
3
- export type { AttributeDefinition, EntityQueryOptions, AttributeDefinitions } from "dynamodb-toolbox/dist/cjs/classes/Entity";
3
+ export type { Readonly, EntityConstructor, AttributeDefinition, EntityQueryOptions, AttributeDefinitions } from "dynamodb-toolbox/dist/cjs/classes/Entity";
package/toolbox.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_dynamodbToolbox","require"],"sources":["toolbox.ts"],"sourcesContent":["export { Entity, Table } from \"dynamodb-toolbox\";\nexport type {\n DynamoDBTypes,\n ScanOptions,\n TableDef,\n TableConstructor\n} from \"dynamodb-toolbox/dist/cjs/classes/Table\";\nexport type {\n AttributeDefinition,\n EntityQueryOptions,\n AttributeDefinitions\n} from \"dynamodb-toolbox/dist/cjs/classes/Entity\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_dynamodbToolbox","require"],"sources":["toolbox.ts"],"sourcesContent":["export { Entity, Table } from \"dynamodb-toolbox\";\nexport type {\n DynamoDBTypes,\n ScanOptions,\n TableDef,\n TableConstructor\n} from \"dynamodb-toolbox/dist/cjs/classes/Table\";\nexport type {\n Readonly,\n EntityConstructor,\n AttributeDefinition,\n EntityQueryOptions,\n AttributeDefinitions\n} from \"dynamodb-toolbox/dist/cjs/classes/Entity\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { TableDef } from "../toolbox";
1
+ import { TableDef } from "../../toolbox";
2
2
  import { GenericRecord } from "@webiny/api/types";
3
3
  export interface BatchReadItem {
4
4
  Table?: TableDef;
@@ -0,0 +1,13 @@
1
+ import { TableDef } from "../../toolbox";
2
+ import { BatchWriteItem, BatchWriteResult } from "./types";
3
+ export interface BatchWriteParams {
4
+ table?: TableDef;
5
+ items: BatchWriteItem[];
6
+ }
7
+ /**
8
+ * Method is meant for batch writing to a single table.
9
+ * It expects already prepared items for writing.
10
+ * It can either delete or put items
11
+ * The method does not check items before actually sending them into the underlying library.
12
+ */
13
+ export declare const batchWriteAll: (params: BatchWriteParams, maxChunk?: number) => Promise<BatchWriteResult>;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_chunk","_interopRequireDefault","require","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","lodashChunk","batchWrite","execute","push","exports"],"sources":["batchWrite.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk\";\nimport { TableDef } from \"~/toolbox\";\nimport { BatchWriteItem, BatchWriteResponse, BatchWriteResult } from \"./types\";\n\nexport interface BatchWriteParams {\n table?: TableDef;\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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AASA,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;AACO,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,GAAG,IAAAC,cAAW,EAACN,UAAU,EAAED,QAAQ,CAAC;EAC1E,MAAMH,OAAyB,GAAG,EAAE;EACpC,KAAK,MAAMd,KAAK,IAAIuB,YAAY,EAAE;IAC9B,MAAMzB,MAAM,GAAI,MAAMqB,KAAK,CAACM,UAAU,CAACzB,KAAK,EAAE;MAC1C0B,OAAO,EAAE;IACb,CAAC,CAAwB;IACzBZ,OAAO,CAACa,IAAI,CAAC7B,MAAM,CAAC;IACpB,MAAMc,KAAK,CAACd,MAAM,EAAEgB,OAAO,CAAC;EAChC;EACA,OAAOA,OAAO;AAClB,CAAC;AAACc,OAAA,CAAAb,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from "./batchRead";
2
+ export * from "./batchWrite";
3
+ export * from "./types";
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _batchRead = require("./batchRead");
7
+ Object.keys(_batchRead).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _batchRead[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _batchRead[key];
14
+ }
15
+ });
16
+ });
17
+ var _batchWrite = require("./batchWrite");
18
+ Object.keys(_batchWrite).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _batchWrite[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _batchWrite[key];
25
+ }
26
+ });
27
+ });
28
+ var _types = require("./types");
29
+ Object.keys(_types).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _types[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _types[key];
36
+ }
37
+ });
38
+ });
39
+
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_batchRead","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_batchWrite","_types"],"sources":["index.ts"],"sourcesContent":["export * from \"./batchRead\";\nexport * from \"./batchWrite\";\nexport * from \"./types\";\n"],"mappings":";;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,UAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,UAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,UAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,WAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,WAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,WAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,WAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,MAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,MAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,MAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,MAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,25 @@
1
+ import type { WriteRequest } from "@webiny/aws-sdk/client-dynamodb";
2
+ export interface BatchWriteResponse {
3
+ next?: () => Promise<BatchWriteResponse>;
4
+ $metadata: {
5
+ httpStatusCode: number;
6
+ requestId: string;
7
+ attempts: number;
8
+ totalRetryDelay: number;
9
+ };
10
+ UnprocessedItems?: {
11
+ [table: string]: WriteRequest[];
12
+ };
13
+ }
14
+ export type BatchWriteResult = BatchWriteResponse[];
15
+ export interface IDeleteBatchItem {
16
+ PK: string;
17
+ SK: string;
18
+ }
19
+ export type IPutBatchItem<T extends Record<string, any> = Record<string, any>> = {
20
+ PK: string;
21
+ SK: string;
22
+ } & T;
23
+ export interface BatchWriteItem {
24
+ [key: string]: WriteRequest;
25
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { WriteRequest } from \"@webiny/aws-sdk/client-dynamodb\";\n\nexport interface BatchWriteResponse {\n next?: () => Promise<BatchWriteResponse>;\n $metadata: {\n httpStatusCode: number;\n requestId: string;\n attempts: number;\n totalRetryDelay: number;\n };\n UnprocessedItems?: {\n [table: string]: WriteRequest[];\n };\n}\n\nexport type BatchWriteResult = BatchWriteResponse[];\n\nexport interface IDeleteBatchItem {\n PK: string;\n SK: string;\n}\n\nexport type IPutBatchItem<T extends Record<string, any> = Record<string, any>> = {\n PK: string;\n SK: string;\n} & T;\n\nexport interface BatchWriteItem {\n [key: string]: WriteRequest;\n}\n"],"mappings":"","ignoreList":[]}
package/utils/delete.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Entity } from "../toolbox";
2
- interface Params {
2
+ export interface IDeleteItemKeys {
3
+ PK: string;
4
+ SK: string;
5
+ }
6
+ export interface IDeleteItemParams {
3
7
  entity: Entity;
4
- keys: {
5
- PK: string;
6
- SK: string;
7
- };
8
+ keys: IDeleteItemKeys;
8
9
  }
9
- export declare const deleteItem: (params: Params) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
10
- export {};
10
+ export declare const deleteItem: (params: IDeleteItemParams) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
@@ -1 +1 @@
1
- {"version":3,"names":["deleteItem","params","entity","keys","delete","execute","exports"],"sources":["delete.ts"],"sourcesContent":["import { Entity } from \"~/toolbox\";\n\ninterface Params {\n entity: Entity;\n keys: {\n PK: string;\n SK: string;\n };\n}\n\nexport const deleteItem = async (params: Params) => {\n const { entity, keys } = params;\n\n return await entity.delete(keys, {\n execute: true\n });\n};\n"],"mappings":";;;;;;AAUO,MAAMA,UAAU,GAAG,MAAOC,MAAc,IAAK;EAChD,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":[]}
1
+ {"version":3,"names":["deleteItem","params","entity","keys","delete","execute","exports"],"sources":["delete.ts"],"sourcesContent":["import { 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,25 @@
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
+ export type EntityConstructor<T extends Readonly<AttributeDefinitions> = Readonly<AttributeDefinitions>> = BaseEntityConstructor<TableDef, string, true, true, true, "created", "modified", "entity", false, T>;
12
+ export declare class Entity implements IEntity {
13
+ readonly entity: BaseEntity;
14
+ constructor(params: EntityConstructor);
15
+ createEntityReader(): IEntityReadBatch;
16
+ createEntityWriter(): IEntityWriteBatch;
17
+ createTableWriter(): ITableWriteBatch;
18
+ put(item: IPutParamsItem): ReturnType<typeof put>;
19
+ get<T>(keys: GetRecordParamsKeys): ReturnType<typeof get<T>>;
20
+ getClean<T>(keys: GetRecordParamsKeys): ReturnType<typeof getClean<T>>;
21
+ delete(keys: IDeleteItemKeys): ReturnType<typeof deleteItem>;
22
+ queryOne<T>(params: IEntityQueryOneParams): Promise<T | null>;
23
+ queryAll<T>(params: IEntityQueryAllParams): Promise<T[]>;
24
+ }
25
+ 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\";\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(item: IPutParamsItem): 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;AAiBO,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,CAACC,IAAoB,EAA0B;IAC3D,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 { 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 { 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 { 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 { 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,CAAE,gCAA+B,IAAI,CAACP,MAAM,CAACQ,IAAK,GAAE,CAAC;IAC9E,CAAC,MAAM,IAAI,CAACJ,MAAM,CAACK,GAAG,EAAE;MACpB,MAAM,IAAIF,kBAAW,CAAE,8BAA6B,IAAI,CAACP,MAAM,CAACQ,IAAK,GAAE,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;