@webiny/db-dynamodb 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.f6dc066313

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 (177) hide show
  1. package/DynamoDbDriver.d.ts +4 -8
  2. package/DynamoDbDriver.js +71 -102
  3. package/DynamoDbDriver.js.map +1 -1
  4. package/README.md +6 -142
  5. package/index.d.ts +4 -3
  6. package/index.js +4 -28
  7. package/index.js.map +1 -1
  8. package/package.json +18 -20
  9. package/plugins/definitions/AttributePlugin.d.ts +1 -1
  10. package/plugins/definitions/AttributePlugin.js +4 -12
  11. package/plugins/definitions/AttributePlugin.js.map +1 -1
  12. package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -2
  13. package/plugins/definitions/DateTimeTransformPlugin.js +6 -14
  14. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
  15. package/plugins/definitions/FieldPathPlugin.js +6 -14
  16. package/plugins/definitions/FieldPathPlugin.js.map +1 -1
  17. package/plugins/definitions/FieldPlugin.d.ts +1 -1
  18. package/plugins/definitions/FieldPlugin.js +2 -9
  19. package/plugins/definitions/FieldPlugin.js.map +1 -1
  20. package/plugins/definitions/TimeTransformPlugin.d.ts +2 -2
  21. package/plugins/definitions/TimeTransformPlugin.js +7 -15
  22. package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
  23. package/plugins/definitions/ValueFilterPlugin.js +5 -13
  24. package/plugins/definitions/ValueFilterPlugin.js.map +1 -1
  25. package/plugins/definitions/ValueTransformPlugin.js +6 -14
  26. package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
  27. package/plugins/definitions/assignFields.js +4 -12
  28. package/plugins/definitions/assignFields.js.map +1 -1
  29. package/plugins/filters/andIn.d.ts +1 -1
  30. package/plugins/filters/andIn.js +5 -12
  31. package/plugins/filters/andIn.js.map +1 -1
  32. package/plugins/filters/between.d.ts +1 -1
  33. package/plugins/filters/between.js +5 -12
  34. package/plugins/filters/between.js.map +1 -1
  35. package/plugins/filters/contains.d.ts +1 -1
  36. package/plugins/filters/contains.js +3 -9
  37. package/plugins/filters/contains.js.map +1 -1
  38. package/plugins/filters/eq.d.ts +1 -1
  39. package/plugins/filters/eq.js +3 -9
  40. package/plugins/filters/eq.js.map +1 -1
  41. package/plugins/filters/fuzzy.d.ts +1 -1
  42. package/plugins/filters/fuzzy.js +5 -12
  43. package/plugins/filters/fuzzy.js.map +1 -1
  44. package/plugins/filters/gt.d.ts +1 -1
  45. package/plugins/filters/gt.js +3 -9
  46. package/plugins/filters/gt.js.map +1 -1
  47. package/plugins/filters/gte.d.ts +1 -1
  48. package/plugins/filters/gte.js +3 -9
  49. package/plugins/filters/gte.js.map +1 -1
  50. package/plugins/filters/in.d.ts +1 -1
  51. package/plugins/filters/in.js +5 -12
  52. package/plugins/filters/in.js.map +1 -1
  53. package/plugins/filters/index.d.ts +1 -1
  54. package/plugins/filters/index.js +12 -20
  55. package/plugins/filters/index.js.map +1 -1
  56. package/plugins/filters/lt.d.ts +1 -1
  57. package/plugins/filters/lt.js +3 -9
  58. package/plugins/filters/lt.js.map +1 -1
  59. package/plugins/filters/lte.d.ts +1 -1
  60. package/plugins/filters/lte.js +3 -9
  61. package/plugins/filters/lte.js.map +1 -1
  62. package/plugins/filters/startsWith.d.ts +1 -1
  63. package/plugins/filters/startsWith.js +3 -9
  64. package/plugins/filters/startsWith.js.map +1 -1
  65. package/plugins/index.d.ts +9 -1
  66. package/plugins/index.js +11 -11
  67. package/plugins/index.js.map +1 -1
  68. package/store/entity.d.ts +4 -76
  69. package/store/entity.js +5 -35
  70. package/store/entity.js.map +1 -1
  71. package/store/keys.d.ts +1 -1
  72. package/store/keys.js +7 -13
  73. package/store/keys.js.map +1 -1
  74. package/store/types.d.ts +3 -4
  75. package/store/types.js +1 -5
  76. package/store/types.js.map +1 -1
  77. package/toolbox.d.ts +7 -2
  78. package/toolbox.js +2 -17
  79. package/toolbox.js.map +1 -1
  80. package/types.js +1 -5
  81. package/utils/attributes.d.ts +2 -2
  82. package/utils/attributes.js +4 -12
  83. package/utils/attributes.js.map +1 -1
  84. package/utils/batch/batchRead.d.ts +2 -2
  85. package/utils/batch/batchRead.js +5 -13
  86. package/utils/batch/batchRead.js.map +1 -1
  87. package/utils/batch/batchWrite.d.ts +2 -2
  88. package/utils/batch/batchWrite.js +3 -11
  89. package/utils/batch/batchWrite.js.map +1 -1
  90. package/utils/batch/index.d.ts +3 -3
  91. package/utils/batch/index.js +3 -38
  92. package/utils/batch/index.js.map +1 -1
  93. package/utils/batch/types.d.ts +7 -2
  94. package/utils/batch/types.js +1 -5
  95. package/utils/batch/types.js.map +1 -1
  96. package/utils/cleanup.d.ts +1 -1
  97. package/utils/cleanup.js +3 -10
  98. package/utils/cleanup.js.map +1 -1
  99. package/utils/count.d.ts +1 -1
  100. package/utils/count.js +1 -8
  101. package/utils/count.js.map +1 -1
  102. package/utils/createEntity.d.ts +36 -54
  103. package/utils/createEntity.js +75 -51
  104. package/utils/createEntity.js.map +1 -1
  105. package/utils/createTable.d.ts +10 -7
  106. package/utils/createTable.js +25 -15
  107. package/utils/createTable.js.map +1 -1
  108. package/utils/cursor.js +2 -10
  109. package/utils/cursor.js.map +1 -1
  110. package/utils/delete.d.ts +1 -1
  111. package/utils/delete.js +1 -8
  112. package/utils/delete.js.map +1 -1
  113. package/utils/entity/Entity.d.ts +23 -21
  114. package/utils/entity/Entity.js +56 -34
  115. package/utils/entity/Entity.js.map +1 -1
  116. package/utils/entity/EntityReadBatch.d.ts +9 -8
  117. package/utils/entity/EntityReadBatch.js +14 -16
  118. package/utils/entity/EntityReadBatch.js.map +1 -1
  119. package/utils/entity/EntityReadBatchBuilder.d.ts +4 -4
  120. package/utils/entity/EntityReadBatchBuilder.js +7 -15
  121. package/utils/entity/EntityReadBatchBuilder.js.map +1 -1
  122. package/utils/entity/EntityWriteBatch.d.ts +9 -8
  123. package/utils/entity/EntityWriteBatch.js +10 -18
  124. package/utils/entity/EntityWriteBatch.js.map +1 -1
  125. package/utils/entity/EntityWriteBatchBuilder.d.ts +4 -4
  126. package/utils/entity/EntityWriteBatchBuilder.js +4 -12
  127. package/utils/entity/EntityWriteBatchBuilder.js.map +1 -1
  128. package/utils/entity/getEntity.d.ts +2 -2
  129. package/utils/entity/getEntity.js +3 -10
  130. package/utils/entity/getEntity.js.map +1 -1
  131. package/utils/entity/index.d.ts +7 -7
  132. package/utils/entity/index.js +7 -82
  133. package/utils/entity/index.js.map +1 -1
  134. package/utils/entity/types.d.ts +46 -22
  135. package/utils/entity/types.js +2 -5
  136. package/utils/entity/types.js.map +1 -1
  137. package/utils/filter.d.ts +1 -1
  138. package/utils/filter.js +7 -14
  139. package/utils/filter.js.map +1 -1
  140. package/utils/get.d.ts +1 -1
  141. package/utils/get.js +4 -12
  142. package/utils/get.js.map +1 -1
  143. package/utils/index.d.ts +17 -17
  144. package/utils/index.js +17 -192
  145. package/utils/index.js.map +1 -1
  146. package/utils/listResponse.js +4 -10
  147. package/utils/listResponse.js.map +1 -1
  148. package/utils/put.d.ts +2 -2
  149. package/utils/put.js +1 -8
  150. package/utils/put.js.map +1 -1
  151. package/utils/query.d.ts +5 -12
  152. package/utils/query.js +13 -27
  153. package/utils/query.js.map +1 -1
  154. package/utils/scan.d.ts +2 -2
  155. package/utils/scan.js +5 -13
  156. package/utils/scan.js.map +1 -1
  157. package/utils/sort.d.ts +1 -1
  158. package/utils/sort.js +7 -14
  159. package/utils/sort.js.map +1 -1
  160. package/utils/table/Table.d.ts +4 -5
  161. package/utils/table/Table.js +9 -20
  162. package/utils/table/Table.js.map +1 -1
  163. package/utils/table/TableReadBatch.d.ts +4 -4
  164. package/utils/table/TableReadBatch.js +8 -16
  165. package/utils/table/TableReadBatch.js.map +1 -1
  166. package/utils/table/TableWriteBatch.d.ts +3 -3
  167. package/utils/table/TableWriteBatch.js +6 -14
  168. package/utils/table/TableWriteBatch.js.map +1 -1
  169. package/utils/table/index.d.ts +4 -4
  170. package/utils/table/index.js +4 -49
  171. package/utils/table/index.js.map +1 -1
  172. package/utils/table/types.d.ts +8 -8
  173. package/utils/table/types.js +1 -5
  174. package/utils/table/types.js.map +1 -1
  175. package/utils/update.d.ts +1 -1
  176. package/utils/update.js +1 -8
  177. package/utils/update.js.map +1 -1
package/store/entity.js CHANGED
@@ -1,41 +1,11 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createEntity = void 0;
7
- var _toolbox = require("../toolbox");
8
- /**
9
- * TODO determine if GSIs are needed
10
- */
11
-
12
- const createEntity = ({
1
+ import { createGlobalEntity as baseCreateGlobalEntity } from "../utils/index.js";
2
+ export const createEntity = ({
13
3
  table
14
4
  }) => {
15
- return new _toolbox.Entity({
16
- table,
17
- name: "WebinyKeyValue",
18
- attributes: {
19
- PK: {
20
- partitionKey: true
21
- },
22
- SK: {
23
- sortKey: true
24
- },
25
- TYPE: {
26
- type: "string"
27
- },
28
- key: {
29
- type: "string"
30
- },
31
- value: {
32
- type: "string"
33
- }
34
- },
35
- autoExecute: true,
36
- autoParse: true
5
+ return baseCreateGlobalEntity({
6
+ table: table.table,
7
+ name: "WebinyKeyValue"
37
8
  });
38
9
  };
39
- exports.createEntity = createEntity;
40
10
 
41
11
  //# sourceMappingURL=entity.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_toolbox","require","createEntity","table","Entity","name","attributes","PK","partitionKey","SK","sortKey","TYPE","type","key","value","autoExecute","autoParse","exports"],"sources":["entity.ts"],"sourcesContent":["/**\n * TODO determine if GSIs are needed\n */\nimport { Entity } from \"~/toolbox\";\nimport type { Table } from \"~/utils\";\n\nexport interface ICreateEntityParams {\n table: Table;\n}\n\nexport const createEntity = ({ table }: ICreateEntityParams) => {\n return new Entity({\n table,\n name: \"WebinyKeyValue\",\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n TYPE: {\n type: \"string\"\n },\n key: {\n type: \"string\"\n },\n value: {\n type: \"string\"\n }\n },\n autoExecute: true,\n autoParse: true\n });\n};\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAQO,MAAMC,YAAY,GAAGA,CAAC;EAAEC;AAA2B,CAAC,KAAK;EAC5D,OAAO,IAAIC,eAAM,CAAC;IACdD,KAAK;IACLE,IAAI,EAAE,gBAAgB;IACtBC,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,IAAI,EAAE;QACFC,IAAI,EAAE;MACV,CAAC;MACDC,GAAG,EAAE;QACDD,IAAI,EAAE;MACV,CAAC;MACDE,KAAK,EAAE;QACHF,IAAI,EAAE;MACV;IACJ,CAAC;IACDG,WAAW,EAAE,IAAI;IACjBC,SAAS,EAAE;EACf,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAf,YAAA,GAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"names":["createGlobalEntity","baseCreateGlobalEntity","createEntity","table","name"],"sources":["entity.ts"],"sourcesContent":["import type { ITable } from \"~/utils/index.js\";\nimport { createGlobalEntity as baseCreateGlobalEntity } from \"~/utils/index.js\";\nimport type { IStoreEntity, IStoreEntityValue } from \"~/store/types.js\";\n\nexport interface ICreateEntityParams {\n table: ITable;\n}\n\nexport const createEntity = ({ table }: ICreateEntityParams): IStoreEntity => {\n return baseCreateGlobalEntity<IStoreEntityValue>({\n table: table.table,\n name: \"WebinyKeyValue\"\n });\n};\n"],"mappings":"AACA,SAASA,kBAAkB,IAAIC,sBAAsB;AAOrD,OAAO,MAAMC,YAAY,GAAGA,CAAC;EAAEC;AAA2B,CAAC,KAAmB;EAC1E,OAAOF,sBAAsB,CAAoB;IAC7CE,KAAK,EAAEA,KAAK,CAACA,KAAK;IAClBC,IAAI,EAAE;EACV,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
package/store/keys.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export interface IParams {
2
- key: string;
2
+ key: string | number | symbol;
3
3
  }
4
4
  export declare const createPartitionKey: () => string;
5
5
  export declare const createSortKey: ({ key }: IParams) => string;
package/store/keys.js CHANGED
@@ -1,22 +1,16 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createType = exports.createSortKey = exports.createPartitionKey = void 0;
7
- const createPartitionKey = () => {
1
+ export const createPartitionKey = () => {
8
2
  return `W#internal`;
9
3
  };
10
- exports.createPartitionKey = createPartitionKey;
11
- const createSortKey = ({
4
+ export const createSortKey = ({
12
5
  key
13
6
  }) => {
14
- return key;
7
+ if (typeof key === "symbol") {
8
+ return key.toString();
9
+ }
10
+ return String(key);
15
11
  };
16
- exports.createSortKey = createSortKey;
17
- const createType = () => {
12
+ export const createType = () => {
18
13
  return "internal";
19
14
  };
20
- exports.createType = createType;
21
15
 
22
16
  //# sourceMappingURL=keys.js.map
package/store/keys.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createPartitionKey","exports","createSortKey","key","createType"],"sources":["keys.ts"],"sourcesContent":["export interface IParams {\n key: string;\n}\n\nexport const createPartitionKey = () => {\n return `W#internal`;\n};\n\nexport const createSortKey = ({ key }: IParams) => {\n return key;\n};\n\nexport const createType = () => {\n return \"internal\";\n};\n"],"mappings":";;;;;;AAIO,MAAMA,kBAAkB,GAAGA,CAAA,KAAM;EACpC,OAAO,YAAY;AACvB,CAAC;AAACC,OAAA,CAAAD,kBAAA,GAAAA,kBAAA;AAEK,MAAME,aAAa,GAAGA,CAAC;EAAEC;AAAa,CAAC,KAAK;EAC/C,OAAOA,GAAG;AACd,CAAC;AAACF,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAME,UAAU,GAAGA,CAAA,KAAM;EAC5B,OAAO,UAAU;AACrB,CAAC;AAACH,OAAA,CAAAG,UAAA,GAAAA,UAAA","ignoreList":[]}
1
+ {"version":3,"names":["createPartitionKey","createSortKey","key","toString","String","createType"],"sources":["keys.ts"],"sourcesContent":["export interface IParams {\n key: string | number | symbol;\n}\n\nexport const createPartitionKey = () => {\n return `W#internal`;\n};\n\nexport const createSortKey = ({ key }: IParams) => {\n if (typeof key === \"symbol\") {\n return key.toString();\n }\n return String(key);\n};\n\nexport const createType = () => {\n return \"internal\";\n};\n"],"mappings":"AAIA,OAAO,MAAMA,kBAAkB,GAAGA,CAAA,KAAM;EACpC,OAAO,YAAY;AACvB,CAAC;AAED,OAAO,MAAMC,aAAa,GAAGA,CAAC;EAAEC;AAAa,CAAC,KAAK;EAC/C,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE;IACzB,OAAOA,GAAG,CAACC,QAAQ,CAAC,CAAC;EACzB;EACA,OAAOC,MAAM,CAACF,GAAG,CAAC;AACtB,CAAC;AAED,OAAO,MAAMG,UAAU,GAAGA,CAAA,KAAM;EAC5B,OAAO,UAAU;AACrB,CAAC","ignoreList":[]}
package/store/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- export interface IStoreItem {
2
- PK: string;
3
- SK: string;
4
- TYPE: string;
1
+ import type { IEntity, IGlobalEntityAttributes } from "../utils/index.js";
2
+ export interface IStoreEntityValue {
5
3
  key: string;
6
4
  value: string;
7
5
  }
6
+ export type IStoreEntity = IEntity<IGlobalEntityAttributes<IStoreEntityValue>>;
package/store/types.js CHANGED
@@ -1,7 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};
6
2
 
7
3
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface IStoreItem {\n PK: string;\n SK: string;\n TYPE: string;\n key: string;\n value: string;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntity, IGlobalEntityAttributes } from \"~/utils/index.js\";\n\nexport interface IStoreEntityValue {\n key: string;\n value: string;\n}\n\nexport type IStoreEntity = IEntity<IGlobalEntityAttributes<IStoreEntityValue>>;\n"],"mappings":"","ignoreList":[]}
package/toolbox.d.ts CHANGED
@@ -1,3 +1,8 @@
1
1
  export { Entity, Table } from "dynamodb-toolbox";
2
- export type { DynamoDBTypes, ScanOptions, TableDef, TableConstructor } from "dynamodb-toolbox/dist/cjs/classes/Table";
3
- export type { Readonly, EntityConstructor, AttributeDefinition, EntityQueryOptions, AttributeDefinitions } from "dynamodb-toolbox/dist/cjs/classes/Entity";
2
+ import { Entity, Table } from "dynamodb-toolbox";
3
+ export type ScanOptions = NonNullable<Parameters<Entity["scan"]>[0]>;
4
+ export type DynamoDBTypes = "string" | "boolean" | "number" | "bigint" | "list" | "map" | "binary" | "set";
5
+ type Key = string | number | symbol;
6
+ export type TableDef = Table<string, Key, Key | null>;
7
+ export type TableConstructor<A extends string, B extends Key, C extends Key> = ConstructorParameters<typeof Table<A, B, C>>[0];
8
+ export type { EntityConstructor, Readonly, AttributeDefinition, EntityQueryOptions, AttributeDefinitions } from "dynamodb-toolbox/dist/cjs/classes/Entity/index.js";
package/toolbox.js CHANGED
@@ -1,20 +1,5 @@
1
- "use strict";
1
+ export { Entity, Table } from "dynamodb-toolbox";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "Entity", {
7
- enumerable: true,
8
- get: function () {
9
- return _dynamodbToolbox.Entity;
10
- }
11
- });
12
- Object.defineProperty(exports, "Table", {
13
- enumerable: true,
14
- get: function () {
15
- return _dynamodbToolbox.Table;
16
- }
17
- });
18
- var _dynamodbToolbox = require("dynamodb-toolbox");
3
+ // TODO: this needs to be replaced with either inferred types, or manual cherry picked types.
19
4
 
20
5
  //# sourceMappingURL=toolbox.js.map
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 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
+ {"version":3,"names":["Entity","Table"],"sources":["toolbox.ts"],"sourcesContent":["export { Entity, Table } from \"dynamodb-toolbox\";\n\nimport { Entity, Table } from \"dynamodb-toolbox\";\n\nexport type ScanOptions = NonNullable<Parameters<Entity[\"scan\"]>[0]>;\nexport type DynamoDBTypes =\n | \"string\"\n | \"boolean\"\n | \"number\"\n | \"bigint\"\n | \"list\"\n | \"map\"\n | \"binary\"\n | \"set\";\n\ntype Key = string | number | symbol;\n\nexport type TableDef = Table<string, Key, Key | null>;\nexport type TableConstructor<\n A extends string,\n B extends Key,\n C extends Key\n> = ConstructorParameters<typeof Table<A, B, C>>[0];\n\n// TODO: this needs to be replaced with either inferred types, or manual cherry picked types.\nexport type {\n EntityConstructor,\n Readonly,\n AttributeDefinition,\n EntityQueryOptions,\n AttributeDefinitions\n} from \"dynamodb-toolbox/dist/cjs/classes/Entity/index.js\";\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,KAAK,QAAQ,kBAAkB;;AAwBhD","ignoreList":[]}
package/types.js CHANGED
@@ -1,7 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};
6
2
 
7
3
  //# sourceMappingURL=types.js.map
@@ -1,5 +1,5 @@
1
- import type { Context } from "@webiny/api/types";
2
- import { AttributePlugin } from "../plugins/definitions/AttributePlugin";
1
+ import type { Context } from "@webiny/api/types.js";
2
+ import { AttributePlugin } from "../plugins/definitions/AttributePlugin.js";
3
3
  import type { PluginsContainer } from "@webiny/plugins";
4
4
  /**
5
5
  * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
@@ -1,27 +1,19 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getExtraAttributesFromPlugins = exports.getExtraAttributes = void 0;
7
- var _AttributePlugin = require("../plugins/definitions/AttributePlugin");
1
+ import { AttributePlugin } from "../plugins/definitions/AttributePlugin.js";
8
2
  /**
9
3
  * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
10
4
  *
11
5
  * @deprecated
12
6
  */
13
- const getExtraAttributes = (context, entity) => {
7
+ export const getExtraAttributes = (context, entity) => {
14
8
  return getExtraAttributesFromPlugins(context.plugins, entity);
15
9
  };
16
- exports.getExtraAttributes = getExtraAttributes;
17
- const getExtraAttributesFromPlugins = (plugins, entity) => {
18
- return plugins.byType(_AttributePlugin.AttributePlugin.type).filter(plugin => plugin.entity === entity).reduce((attributes, plugin) => {
10
+ export const getExtraAttributesFromPlugins = (plugins, entity) => {
11
+ return plugins.byType(AttributePlugin.type).filter(plugin => plugin.entity === entity).reduce((attributes, plugin) => {
19
12
  return {
20
13
  ...attributes,
21
14
  ...plugin.getDefinition()
22
15
  };
23
16
  }, {});
24
17
  };
25
- exports.getExtraAttributesFromPlugins = getExtraAttributesFromPlugins;
26
18
 
27
19
  //# sourceMappingURL=attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_AttributePlugin","require","getExtraAttributes","context","entity","getExtraAttributesFromPlugins","plugins","exports","byType","AttributePlugin","type","filter","plugin","reduce","attributes","getDefinition"],"sources":["attributes.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types\";\nimport { AttributePlugin } from \"~/plugins/definitions/AttributePlugin\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.\n *\n * @deprecated\n */\nexport const getExtraAttributes = (\n context: Context,\n entity: string\n): Record<string, AttributePlugin[\"_params\"]> => {\n return getExtraAttributesFromPlugins(context.plugins, entity);\n};\n\nexport const getExtraAttributesFromPlugins = (\n plugins: PluginsContainer,\n entity: string\n): Record<string, AttributePlugin[\"_params\"]> => {\n return plugins\n .byType<AttributePlugin>(AttributePlugin.type)\n .filter(plugin => plugin.entity === entity)\n .reduce((attributes, plugin) => {\n return {\n ...attributes,\n ...plugin.getDefinition()\n };\n }, {});\n};\n"],"mappings":";;;;;;AACA,IAAAA,gBAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,GAAGA,CAC9BC,OAAgB,EAChBC,MAAc,KAC+B;EAC7C,OAAOC,6BAA6B,CAACF,OAAO,CAACG,OAAO,EAAEF,MAAM,CAAC;AACjE,CAAC;AAACG,OAAA,CAAAL,kBAAA,GAAAA,kBAAA;AAEK,MAAMG,6BAA6B,GAAGA,CACzCC,OAAyB,EACzBF,MAAc,KAC+B;EAC7C,OAAOE,OAAO,CACTE,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC,CAC7CC,MAAM,CAACC,MAAM,IAAIA,MAAM,CAACR,MAAM,KAAKA,MAAM,CAAC,CAC1CS,MAAM,CAAC,CAACC,UAAU,EAAEF,MAAM,KAAK;IAC5B,OAAO;MACH,GAAGE,UAAU;MACb,GAAGF,MAAM,CAACG,aAAa,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,CAAC,CAAC,CAAC;AACd,CAAC;AAACR,OAAA,CAAAF,6BAAA,GAAAA,6BAAA","ignoreList":[]}
1
+ {"version":3,"names":["AttributePlugin","getExtraAttributes","context","entity","getExtraAttributesFromPlugins","plugins","byType","type","filter","plugin","reduce","attributes","getDefinition"],"sources":["attributes.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { AttributePlugin } from \"~/plugins/definitions/AttributePlugin.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.\n *\n * @deprecated\n */\nexport const getExtraAttributes = (\n context: Context,\n entity: string\n): Record<string, AttributePlugin[\"_params\"]> => {\n return getExtraAttributesFromPlugins(context.plugins, entity);\n};\n\nexport const getExtraAttributesFromPlugins = (\n plugins: PluginsContainer,\n entity: string\n): Record<string, AttributePlugin[\"_params\"]> => {\n return plugins\n .byType<AttributePlugin>(AttributePlugin.type)\n .filter(plugin => plugin.entity === entity)\n .reduce((attributes, plugin) => {\n return {\n ...attributes,\n ...plugin.getDefinition()\n };\n }, {});\n};\n"],"mappings":"AACA,SAASA,eAAe;AAGxB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAC9BC,OAAgB,EAChBC,MAAc,KAC+B;EAC7C,OAAOC,6BAA6B,CAACF,OAAO,CAACG,OAAO,EAAEF,MAAM,CAAC;AACjE,CAAC;AAED,OAAO,MAAMC,6BAA6B,GAAGA,CACzCC,OAAyB,EACzBF,MAAc,KAC+B;EAC7C,OAAOE,OAAO,CACTC,MAAM,CAAkBN,eAAe,CAACO,IAAI,CAAC,CAC7CC,MAAM,CAACC,MAAM,IAAIA,MAAM,CAACN,MAAM,KAAKA,MAAM,CAAC,CAC1CO,MAAM,CAAC,CAACC,UAAU,EAAEF,MAAM,KAAK;IAC5B,OAAO;MACH,GAAGE,UAAU;MACb,GAAGF,MAAM,CAACG,aAAa,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,CAAC,CAAC,CAAC;AACd,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import type { TableDef } from "../../toolbox";
2
- import type { GenericRecord } from "@webiny/api/types";
1
+ import type { TableDef } from "../../toolbox.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
3
  export interface BatchReadItem {
4
4
  Table?: TableDef;
5
5
  Key: any;
@@ -1,12 +1,5 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.batchReadAll = void 0;
8
- var _chunk = _interopRequireDefault(require("lodash/chunk"));
9
- var _error = _interopRequireDefault(require("@webiny/error"));
1
+ import lodashChunk from "lodash/chunk.js";
2
+ import WebinyError from "@webiny/error";
10
3
  const MAX_BATCH_ITEMS = 100;
11
4
  const flatten = responses => {
12
5
  const entries = [];
@@ -48,16 +41,16 @@ const batchReadAllChunk = async params => {
48
41
  * This helper function is meant to be used to batch read from one table.
49
42
  * It will fetch all results, as there is a next() method call built in.
50
43
  */
51
- const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
44
+ export const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
52
45
  if (params.items.length === 0) {
53
46
  return [];
54
47
  } else if (maxChunk > MAX_BATCH_ITEMS) {
55
- throw new _error.default(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
48
+ throw new WebinyError(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
56
49
  maxChunk
57
50
  });
58
51
  }
59
52
  const records = [];
60
- const chunkItemsList = (0, _chunk.default)(params.items, maxChunk);
53
+ const chunkItemsList = lodashChunk(params.items, maxChunk);
61
54
  for (const chunkItems of chunkItemsList) {
62
55
  const results = await batchReadAllChunk({
63
56
  table: params.table,
@@ -67,6 +60,5 @@ const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
67
60
  }
68
61
  return records;
69
62
  };
70
- exports.batchReadAll = batchReadAll;
71
63
 
72
64
  //# sourceMappingURL=batchRead.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_chunk","_interopRequireDefault","require","_error","MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","push","batchReadAllChunk","params","table","records","result","batchGet","Responses","next","previous","nextResult","batchReadAll","maxChunk","length","WebinyError","chunkItemsList","lodashChunk","chunkItems","results","exports"],"sources":["batchRead.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk\";\nimport WebinyError from \"@webiny/error\";\nimport type { TableDef } from \"~/toolbox\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport interface BatchReadItem {\n Table?: TableDef;\n Key: any;\n}\nexport interface BatchReadParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\n\nconst MAX_BATCH_ITEMS = 100;\n\nconst flatten = (responses: Record<string, any[]>): any[] => {\n const entries = [];\n const values = Object.values(responses);\n for (const items of values) {\n entries.push(...items);\n }\n return entries;\n};\n\ninterface BatchReadAllChunkParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\nconst batchReadAllChunk = async <T = any>(params: BatchReadAllChunkParams): Promise<T[]> => {\n const { table, items } = params;\n const records: T[] = [];\n\n if (!table) {\n return records;\n }\n\n const result = await table.batchGet(items);\n if (!result || !result.Responses) {\n return records;\n }\n records.push(...flatten(result.Responses));\n if (!result.next || typeof result.next !== \"function\") {\n return records;\n }\n let previous = result;\n while (typeof previous.next === \"function\") {\n const nextResult = await previous.next();\n if (!nextResult) {\n return records;\n }\n records.push(...flatten(nextResult.Responses));\n previous = nextResult;\n }\n return records;\n};\n/**\n * This helper function is meant to be used to batch read from one table.\n * It will fetch all results, as there is a next() method call built in.\n */\nexport const batchReadAll = async <T = GenericRecord>(\n params: BatchReadParams,\n maxChunk = MAX_BATCH_ITEMS\n): Promise<T[]> => {\n if (params.items.length === 0) {\n return [];\n } else if (maxChunk > MAX_BATCH_ITEMS) {\n throw new WebinyError(\n `Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`,\n \"DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR\",\n {\n maxChunk\n }\n );\n }\n\n const records: T[] = [];\n\n const chunkItemsList = lodashChunk(params.items, maxChunk);\n\n for (const chunkItems of chunkItemsList) {\n const results = await batchReadAllChunk<T>({\n table: params.table,\n items: chunkItems\n });\n\n records.push(...results);\n }\n\n return records;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AAaA,MAAME,eAAe,GAAG,GAAG;AAE3B,MAAMC,OAAO,GAAIC,SAAgC,IAAY;EACzD,MAAMC,OAAO,GAAG,EAAE;EAClB,MAAMC,MAAM,GAAGC,MAAM,CAACD,MAAM,CAACF,SAAS,CAAC;EACvC,KAAK,MAAMI,KAAK,IAAIF,MAAM,EAAE;IACxBD,OAAO,CAACI,IAAI,CAAC,GAAGD,KAAK,CAAC;EAC1B;EACA,OAAOH,OAAO;AAClB,CAAC;AAMD,MAAMK,iBAAiB,GAAG,MAAgBC,MAA+B,IAAmB;EACxF,MAAM;IAAEC,KAAK;IAAEJ;EAAM,CAAC,GAAGG,MAAM;EAC/B,MAAME,OAAY,GAAG,EAAE;EAEvB,IAAI,CAACD,KAAK,EAAE;IACR,OAAOC,OAAO;EAClB;EAEA,MAAMC,MAAM,GAAG,MAAMF,KAAK,CAACG,QAAQ,CAACP,KAAK,CAAC;EAC1C,IAAI,CAACM,MAAM,IAAI,CAACA,MAAM,CAACE,SAAS,EAAE;IAC9B,OAAOH,OAAO;EAClB;EACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACW,MAAM,CAACE,SAAS,CAAC,CAAC;EAC1C,IAAI,CAACF,MAAM,CAACG,IAAI,IAAI,OAAOH,MAAM,CAACG,IAAI,KAAK,UAAU,EAAE;IACnD,OAAOJ,OAAO;EAClB;EACA,IAAIK,QAAQ,GAAGJ,MAAM;EACrB,OAAO,OAAOI,QAAQ,CAACD,IAAI,KAAK,UAAU,EAAE;IACxC,MAAME,UAAU,GAAG,MAAMD,QAAQ,CAACD,IAAI,CAAC,CAAC;IACxC,IAAI,CAACE,UAAU,EAAE;MACb,OAAON,OAAO;IAClB;IACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACgB,UAAU,CAACH,SAAS,CAAC,CAAC;IAC9CE,QAAQ,GAAGC,UAAU;EACzB;EACA,OAAON,OAAO;AAClB,CAAC;AACD;AACA;AACA;AACA;AACO,MAAMO,YAAY,GAAG,MAAAA,CACxBT,MAAuB,EACvBU,QAAQ,GAAGnB,eAAe,KACX;EACf,IAAIS,MAAM,CAACH,KAAK,CAACc,MAAM,KAAK,CAAC,EAAE;IAC3B,OAAO,EAAE;EACb,CAAC,MAAM,IAAID,QAAQ,GAAGnB,eAAe,EAAE;IACnC,MAAM,IAAIqB,cAAW,CACjB,gCAAgCrB,eAAe,mCAAmC,EAClF,oCAAoC,EACpC;MACImB;IACJ,CACJ,CAAC;EACL;EAEA,MAAMR,OAAY,GAAG,EAAE;EAEvB,MAAMW,cAAc,GAAG,IAAAC,cAAW,EAACd,MAAM,CAACH,KAAK,EAAEa,QAAQ,CAAC;EAE1D,KAAK,MAAMK,UAAU,IAAIF,cAAc,EAAE;IACrC,MAAMG,OAAO,GAAG,MAAMjB,iBAAiB,CAAI;MACvCE,KAAK,EAAED,MAAM,CAACC,KAAK;MACnBJ,KAAK,EAAEkB;IACX,CAAC,CAAC;IAEFb,OAAO,CAACJ,IAAI,CAAC,GAAGkB,OAAO,CAAC;EAC5B;EAEA,OAAOd,OAAO;AAClB,CAAC;AAACe,OAAA,CAAAR,YAAA,GAAAA,YAAA","ignoreList":[]}
1
+ {"version":3,"names":["lodashChunk","WebinyError","MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","push","batchReadAllChunk","params","table","records","result","batchGet","Responses","next","previous","nextResult","batchReadAll","maxChunk","length","chunkItemsList","chunkItems","results"],"sources":["batchRead.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface BatchReadItem {\n Table?: TableDef;\n Key: any;\n}\nexport interface BatchReadParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\n\nconst MAX_BATCH_ITEMS = 100;\n\nconst flatten = (responses: Record<string, any[]>): any[] => {\n const entries = [];\n const values = Object.values(responses);\n for (const items of values) {\n entries.push(...items);\n }\n return entries;\n};\n\ninterface BatchReadAllChunkParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\nconst batchReadAllChunk = async <T = any>(params: BatchReadAllChunkParams): Promise<T[]> => {\n const { table, items } = params;\n const records: T[] = [];\n\n if (!table) {\n return records;\n }\n\n const result = await table.batchGet(items);\n if (!result || !result.Responses) {\n return records;\n }\n records.push(...flatten(result.Responses));\n if (!result.next || typeof result.next !== \"function\") {\n return records;\n }\n let previous = result;\n while (typeof previous.next === \"function\") {\n const nextResult = await previous.next();\n if (!nextResult) {\n return records;\n }\n records.push(...flatten(nextResult.Responses));\n previous = nextResult;\n }\n return records;\n};\n/**\n * This helper function is meant to be used to batch read from one table.\n * It will fetch all results, as there is a next() method call built in.\n */\nexport const batchReadAll = async <T = GenericRecord>(\n params: BatchReadParams,\n maxChunk = MAX_BATCH_ITEMS\n): Promise<T[]> => {\n if (params.items.length === 0) {\n return [];\n } else if (maxChunk > MAX_BATCH_ITEMS) {\n throw new WebinyError(\n `Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`,\n \"DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR\",\n {\n maxChunk\n }\n );\n }\n\n const records: T[] = [];\n\n const chunkItemsList = lodashChunk(params.items, maxChunk);\n\n for (const chunkItems of chunkItemsList) {\n const results = await batchReadAllChunk<T>({\n table: params.table,\n items: chunkItems\n });\n\n records.push(...results);\n }\n\n return records;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,iBAAiB;AACzC,OAAOC,WAAW,MAAM,eAAe;AAavC,MAAMC,eAAe,GAAG,GAAG;AAE3B,MAAMC,OAAO,GAAIC,SAAgC,IAAY;EACzD,MAAMC,OAAO,GAAG,EAAE;EAClB,MAAMC,MAAM,GAAGC,MAAM,CAACD,MAAM,CAACF,SAAS,CAAC;EACvC,KAAK,MAAMI,KAAK,IAAIF,MAAM,EAAE;IACxBD,OAAO,CAACI,IAAI,CAAC,GAAGD,KAAK,CAAC;EAC1B;EACA,OAAOH,OAAO;AAClB,CAAC;AAMD,MAAMK,iBAAiB,GAAG,MAAgBC,MAA+B,IAAmB;EACxF,MAAM;IAAEC,KAAK;IAAEJ;EAAM,CAAC,GAAGG,MAAM;EAC/B,MAAME,OAAY,GAAG,EAAE;EAEvB,IAAI,CAACD,KAAK,EAAE;IACR,OAAOC,OAAO;EAClB;EAEA,MAAMC,MAAM,GAAG,MAAMF,KAAK,CAACG,QAAQ,CAACP,KAAK,CAAC;EAC1C,IAAI,CAACM,MAAM,IAAI,CAACA,MAAM,CAACE,SAAS,EAAE;IAC9B,OAAOH,OAAO;EAClB;EACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACW,MAAM,CAACE,SAAS,CAAC,CAAC;EAC1C,IAAI,CAACF,MAAM,CAACG,IAAI,IAAI,OAAOH,MAAM,CAACG,IAAI,KAAK,UAAU,EAAE;IACnD,OAAOJ,OAAO;EAClB;EACA,IAAIK,QAAQ,GAAGJ,MAAM;EACrB,OAAO,OAAOI,QAAQ,CAACD,IAAI,KAAK,UAAU,EAAE;IACxC,MAAME,UAAU,GAAG,MAAMD,QAAQ,CAACD,IAAI,CAAC,CAAC;IACxC,IAAI,CAACE,UAAU,EAAE;MACb,OAAON,OAAO;IAClB;IACAA,OAAO,CAACJ,IAAI,CAAC,GAAGN,OAAO,CAACgB,UAAU,CAACH,SAAS,CAAC,CAAC;IAC9CE,QAAQ,GAAGC,UAAU;EACzB;EACA,OAAON,OAAO;AAClB,CAAC;AACD;AACA;AACA;AACA;AACA,OAAO,MAAMO,YAAY,GAAG,MAAAA,CACxBT,MAAuB,EACvBU,QAAQ,GAAGnB,eAAe,KACX;EACf,IAAIS,MAAM,CAACH,KAAK,CAACc,MAAM,KAAK,CAAC,EAAE;IAC3B,OAAO,EAAE;EACb,CAAC,MAAM,IAAID,QAAQ,GAAGnB,eAAe,EAAE;IACnC,MAAM,IAAID,WAAW,CACjB,gCAAgCC,eAAe,mCAAmC,EAClF,oCAAoC,EACpC;MACImB;IACJ,CACJ,CAAC;EACL;EAEA,MAAMR,OAAY,GAAG,EAAE;EAEvB,MAAMU,cAAc,GAAGvB,WAAW,CAACW,MAAM,CAACH,KAAK,EAAEa,QAAQ,CAAC;EAE1D,KAAK,MAAMG,UAAU,IAAID,cAAc,EAAE;IACrC,MAAME,OAAO,GAAG,MAAMf,iBAAiB,CAAI;MACvCE,KAAK,EAAED,MAAM,CAACC,KAAK;MACnBJ,KAAK,EAAEgB;IACX,CAAC,CAAC;IAEFX,OAAO,CAACJ,IAAI,CAAC,GAAGgB,OAAO,CAAC;EAC5B;EAEA,OAAOZ,OAAO;AAClB,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import type { TableDef } from "../../toolbox";
2
- import type { BatchWriteItem, BatchWriteResult } from "./types";
1
+ import type { TableDef } from "../../toolbox.js";
2
+ import type { BatchWriteItem, BatchWriteResult } from "./types.js";
3
3
  export interface BatchWriteParams {
4
4
  table: TableDef | undefined;
5
5
  items: BatchWriteItem[];
@@ -1,11 +1,4 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.batchWriteAll = void 0;
8
- var _chunk = _interopRequireDefault(require("lodash/chunk"));
1
+ import lodashChunk from "lodash/chunk.js";
9
2
  const hasUnprocessedItems = result => {
10
3
  if (typeof result.next !== "function") {
11
4
  return false;
@@ -38,7 +31,7 @@ const retry = async (input, results) => {
38
31
  * It can either delete or put items
39
32
  * The method does not check items before actually sending them into the underlying library.
40
33
  */
41
- const batchWriteAll = async (params, maxChunk = 25) => {
34
+ export const batchWriteAll = async (params, maxChunk = 25) => {
42
35
  const {
43
36
  items: collection,
44
37
  table
@@ -49,7 +42,7 @@ const batchWriteAll = async (params, maxChunk = 25) => {
49
42
  } else if (collection.length === 0) {
50
43
  return [];
51
44
  }
52
- const chunkedItems = (0, _chunk.default)(collection, maxChunk);
45
+ const chunkedItems = lodashChunk(collection, maxChunk);
53
46
  const results = [];
54
47
  for (const items of chunkedItems) {
55
48
  const result = await table.batchWrite(items, {
@@ -60,6 +53,5 @@ const batchWriteAll = async (params, maxChunk = 25) => {
60
53
  }
61
54
  return results;
62
55
  };
63
- exports.batchWriteAll = batchWriteAll;
64
56
 
65
57
  //# sourceMappingURL=batchWrite.js.map
@@ -1 +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 type { TableDef } from \"~/toolbox\";\nimport type { BatchWriteItem, BatchWriteResponse, BatchWriteResult } from \"./types\";\n\nexport interface BatchWriteParams {\n table: TableDef | undefined;\n items: BatchWriteItem[];\n}\n\nconst hasUnprocessedItems = (result: BatchWriteResponse): boolean => {\n if (typeof result.next !== \"function\") {\n return false;\n }\n const items = result.UnprocessedItems;\n if (!items || typeof items !== \"object\") {\n return false;\n }\n const keys = Object.keys(items);\n return keys.some(key => {\n const value = items[key];\n if (!Array.isArray(value)) {\n return false;\n }\n return value.some(val => {\n return val.PutRequest || val.DeleteRequest;\n });\n });\n};\n\nconst retry = async (input: BatchWriteResponse, results: BatchWriteResult): Promise<void> => {\n if (!hasUnprocessedItems(input)) {\n return;\n }\n const result = await input.next!();\n await retry(result, results);\n};\n/**\n * Method is meant for batch writing to a single table.\n * It expects already prepared items for writing.\n * It can either delete or put items\n * The method does not check items before actually sending them into the underlying library.\n */\nexport const batchWriteAll = async (\n params: BatchWriteParams,\n maxChunk = 25\n): Promise<BatchWriteResult> => {\n const { items: collection, table } = params;\n if (!table) {\n console.log(\"No table provided.\");\n return [];\n } else if (collection.length === 0) {\n return [];\n }\n\n const chunkedItems: BatchWriteItem[][] = lodashChunk(collection, maxChunk);\n const results: BatchWriteResult = [];\n for (const items of chunkedItems) {\n const result = (await table.batchWrite(items, {\n execute: true\n })) as BatchWriteResponse;\n results.push(result);\n await retry(result, results);\n }\n return results;\n};\n"],"mappings":";;;;;;;AAAA,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":[]}
1
+ {"version":3,"names":["lodashChunk","hasUnprocessedItems","result","next","items","UnprocessedItems","keys","Object","some","key","value","Array","isArray","val","PutRequest","DeleteRequest","retry","input","results","batchWriteAll","params","maxChunk","collection","table","console","log","length","chunkedItems","batchWrite","execute","push"],"sources":["batchWrite.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { BatchWriteItem, BatchWriteResponse, BatchWriteResult } from \"./types.js\";\n\nexport interface BatchWriteParams {\n table: TableDef | undefined;\n items: BatchWriteItem[];\n}\n\nconst hasUnprocessedItems = (result: BatchWriteResponse): boolean => {\n if (typeof result.next !== \"function\") {\n return false;\n }\n const items = result.UnprocessedItems;\n if (!items || typeof items !== \"object\") {\n return false;\n }\n const keys = Object.keys(items);\n return keys.some(key => {\n const value = items[key];\n if (!Array.isArray(value)) {\n return false;\n }\n return value.some(val => {\n return val.PutRequest || val.DeleteRequest;\n });\n });\n};\n\nconst retry = async (input: BatchWriteResponse, results: BatchWriteResult): Promise<void> => {\n if (!hasUnprocessedItems(input)) {\n return;\n }\n const result = await input.next!();\n await retry(result, results);\n};\n/**\n * Method is meant for batch writing to a single table.\n * It expects already prepared items for writing.\n * It can either delete or put items\n * The method does not check items before actually sending them into the underlying library.\n */\nexport const batchWriteAll = async (\n params: BatchWriteParams,\n maxChunk = 25\n): Promise<BatchWriteResult> => {\n const { items: collection, table } = params;\n if (!table) {\n console.log(\"No table provided.\");\n return [];\n } else if (collection.length === 0) {\n return [];\n }\n\n const chunkedItems: BatchWriteItem[][] = lodashChunk(collection, maxChunk);\n const results: BatchWriteResult = [];\n for (const items of chunkedItems) {\n const result = (await table.batchWrite(items, {\n execute: true\n })) as BatchWriteResponse;\n results.push(result);\n await retry(result, results);\n }\n return results;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,iBAAiB;AASzC,MAAMC,mBAAmB,GAAIC,MAA0B,IAAc;EACjE,IAAI,OAAOA,MAAM,CAACC,IAAI,KAAK,UAAU,EAAE;IACnC,OAAO,KAAK;EAChB;EACA,MAAMC,KAAK,GAAGF,MAAM,CAACG,gBAAgB;EACrC,IAAI,CAACD,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IACrC,OAAO,KAAK;EAChB;EACA,MAAME,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,KAAK,CAAC;EAC/B,OAAOE,IAAI,CAACE,IAAI,CAACC,GAAG,IAAI;IACpB,MAAMC,KAAK,GAAGN,KAAK,CAACK,GAAG,CAAC;IACxB,IAAI,CAACE,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACvB,OAAO,KAAK;IAChB;IACA,OAAOA,KAAK,CAACF,IAAI,CAACK,GAAG,IAAI;MACrB,OAAOA,GAAG,CAACC,UAAU,IAAID,GAAG,CAACE,aAAa;IAC9C,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAED,MAAMC,KAAK,GAAG,MAAAA,CAAOC,KAAyB,EAAEC,OAAyB,KAAoB;EACzF,IAAI,CAACjB,mBAAmB,CAACgB,KAAK,CAAC,EAAE;IAC7B;EACJ;EACA,MAAMf,MAAM,GAAG,MAAMe,KAAK,CAACd,IAAI,CAAE,CAAC;EAClC,MAAMa,KAAK,CAACd,MAAM,EAAEgB,OAAO,CAAC;AAChC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAG,MAAAA,CACzBC,MAAwB,EACxBC,QAAQ,GAAG,EAAE,KACe;EAC5B,MAAM;IAAEjB,KAAK,EAAEkB,UAAU;IAAEC;EAAM,CAAC,GAAGH,MAAM;EAC3C,IAAI,CAACG,KAAK,EAAE;IACRC,OAAO,CAACC,GAAG,CAAC,oBAAoB,CAAC;IACjC,OAAO,EAAE;EACb,CAAC,MAAM,IAAIH,UAAU,CAACI,MAAM,KAAK,CAAC,EAAE;IAChC,OAAO,EAAE;EACb;EAEA,MAAMC,YAAgC,GAAG3B,WAAW,CAACsB,UAAU,EAAED,QAAQ,CAAC;EAC1E,MAAMH,OAAyB,GAAG,EAAE;EACpC,KAAK,MAAMd,KAAK,IAAIuB,YAAY,EAAE;IAC9B,MAAMzB,MAAM,GAAI,MAAMqB,KAAK,CAACK,UAAU,CAACxB,KAAK,EAAE;MAC1CyB,OAAO,EAAE;IACb,CAAC,CAAwB;IACzBX,OAAO,CAACY,IAAI,CAAC5B,MAAM,CAAC;IACpB,MAAMc,KAAK,CAACd,MAAM,EAAEgB,OAAO,CAAC;EAChC;EACA,OAAOA,OAAO;AAClB,CAAC","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- export * from "./batchRead";
2
- export * from "./batchWrite";
3
- export * from "./types";
1
+ export * from "./batchRead.js";
2
+ export * from "./batchWrite.js";
3
+ export * from "./types.js";
@@ -1,40 +1,5 @@
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
- });
1
+ export * from "./batchRead.js";
2
+ export * from "./batchWrite.js";
3
+ export * from "./types.js";
39
4
 
40
5
  //# sourceMappingURL=index.js.map
@@ -1 +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":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./batchRead.js\";\nexport * from \"./batchWrite.js\";\nexport * from \"./types.js\";\n"],"mappings":"AAAA;AACA;AACA","ignoreList":[]}
@@ -1,4 +1,5 @@
1
- import type { WriteRequest } from "@webiny/aws-sdk/client-dynamodb";
1
+ import type { WriteRequest } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
2
3
  export interface BatchWriteResponse {
3
4
  next?: () => Promise<BatchWriteResponse>;
4
5
  $metadata: {
@@ -16,10 +17,14 @@ export interface IDeleteBatchItem {
16
17
  PK: string;
17
18
  SK: string;
18
19
  }
19
- export type IPutBatchItem<T extends Record<string, any> = Record<string, any>> = {
20
+ export type IPutBatchItem<T = GenericRecord> = {
20
21
  PK: string;
21
22
  SK: string;
22
23
  } & T;
23
24
  export interface BatchWriteItem {
24
25
  [key: string]: WriteRequest;
25
26
  }
27
+ export interface IReadBatchItem {
28
+ PK: string;
29
+ SK: string;
30
+ }
@@ -1,7 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};
6
2
 
7
3
  //# sourceMappingURL=types.js.map
@@ -1 +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":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { WriteRequest } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\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 = GenericRecord> = {\n PK: string;\n SK: string;\n} & T;\n\nexport interface BatchWriteItem {\n [key: string]: WriteRequest;\n}\n\nexport interface IReadBatchItem {\n PK: string;\n SK: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import type { Entity } from "../toolbox";
1
+ import type { Entity } from "../toolbox.js";
2
2
  export declare function cleanupItem<T>(entity: Entity<any>, item?: T | null, removeAttributes?: string[]): T | null;
3
3
  export declare function cleanupItems<T>(entity: Entity<any>, items: T[], removeAttributes?: string[]): T[];
package/utils/cleanup.js CHANGED
@@ -1,16 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.cleanupItem = cleanupItem;
7
- exports.cleanupItems = cleanupItems;
8
1
  /**
9
2
  * The attributes defined by us or the dynamodb-toolbox library.
10
3
  * Add more attributes if necessary.
11
4
  */
12
- const attributesToRemove = ["PK", "SK", "created", "_ct", "modified", "_mt", "entity", "_et", "GSI1_PK", "GSI1_SK", "GSI2_PK", "GSI2_SK", "GSI3_PK", "GSI3_SK", "GSI4_PK", "GSI4_SK", "GSI5_PK", "GSI5_SK", "TYPE"];
13
- function cleanupItem(entity, item, removeAttributes = []) {
5
+ const attributesToRemove = ["PK", "SK", "created", "_ct", "modified", "_mt", "entity", "_et", "GSI1_PK", "GSI1_SK", "GSI2_PK", "GSI2_SK", "GSI3_PK", "GSI3_SK", "GSI4_PK", "GSI4_SK", "GSI5_PK", "GSI5_SK", "GSI_TENANT", "TYPE"];
6
+ export function cleanupItem(entity, item, removeAttributes = []) {
14
7
  if (!item) {
15
8
  return null;
16
9
  }
@@ -30,7 +23,7 @@ function cleanupItem(entity, item, removeAttributes = []) {
30
23
  }
31
24
  return newItem;
32
25
  }
33
- function cleanupItems(entity, items, removeAttributes = []) {
26
+ export function cleanupItems(entity, items, removeAttributes = []) {
34
27
  return items.map(item => cleanupItem(entity, item, removeAttributes));
35
28
  }
36
29
 
@@ -1 +1 @@
1
- {"version":3,"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","concat","attributes","schema","key","hasOwnProperty","includes","cleanupItems","items","map"],"sources":["cleanup.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox\";\n\n/**\n * The attributes defined by us or the dynamodb-toolbox library.\n * Add more attributes if necessary.\n */\nconst attributesToRemove = [\n \"PK\",\n \"SK\",\n \"created\",\n \"_ct\",\n \"modified\",\n \"_mt\",\n \"entity\",\n \"_et\",\n \"GSI1_PK\",\n \"GSI1_SK\",\n \"GSI2_PK\",\n \"GSI2_SK\",\n \"GSI3_PK\",\n \"GSI3_SK\",\n \"GSI4_PK\",\n \"GSI4_SK\",\n \"GSI5_PK\",\n \"GSI5_SK\",\n \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: T | null,\n removeAttributes: string[] = []\n): T | null {\n if (!item) {\n return null;\n }\n const newItem = {\n ...item\n };\n const targets = attributesToRemove.concat(removeAttributes);\n const attributes = entity.schema.attributes;\n for (const key in item) {\n if (item.hasOwnProperty(key) === false) {\n continue;\n }\n if (attributes[key] && targets.includes(key) === false) {\n continue;\n }\n delete newItem[key];\n }\n return newItem;\n}\n\nexport function cleanupItems<T>(\n entity: Entity<any>,\n items: T[],\n removeAttributes: string[] = []\n): T[] {\n return items.map(item => cleanupItem<T>(entity, item, removeAttributes) as T);\n}\n"],"mappings":";;;;;;;AAEA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CACvB,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,KAAK,EACL,UAAU,EACV,KAAK,EACL,QAAQ,EACR,KAAK,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,MAAM,CACT;AAEM,SAASC,WAAWA,CACvBC,MAAmB,EACnBC,IAAe,EACfC,gBAA0B,GAAG,EAAE,EACvB;EACR,IAAI,CAACD,IAAI,EAAE;IACP,OAAO,IAAI;EACf;EACA,MAAME,OAAO,GAAG;IACZ,GAAGF;EACP,CAAC;EACD,MAAMG,OAAO,GAAGN,kBAAkB,CAACO,MAAM,CAACH,gBAAgB,CAAC;EAC3D,MAAMI,UAAU,GAAGN,MAAM,CAACO,MAAM,CAACD,UAAU;EAC3C,KAAK,MAAME,GAAG,IAAIP,IAAI,EAAE;IACpB,IAAIA,IAAI,CAACQ,cAAc,CAACD,GAAG,CAAC,KAAK,KAAK,EAAE;MACpC;IACJ;IACA,IAAIF,UAAU,CAACE,GAAG,CAAC,IAAIJ,OAAO,CAACM,QAAQ,CAACF,GAAG,CAAC,KAAK,KAAK,EAAE;MACpD;IACJ;IACA,OAAOL,OAAO,CAACK,GAAG,CAAC;EACvB;EACA,OAAOL,OAAO;AAClB;AAEO,SAASQ,YAAYA,CACxBX,MAAmB,EACnBY,KAAU,EACVV,gBAA0B,GAAG,EAAE,EAC5B;EACH,OAAOU,KAAK,CAACC,GAAG,CAACZ,IAAI,IAAIF,WAAW,CAAIC,MAAM,EAAEC,IAAI,EAAEC,gBAAgB,CAAM,CAAC;AACjF","ignoreList":[]}
1
+ {"version":3,"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","concat","attributes","schema","key","hasOwnProperty","includes","cleanupItems","items","map"],"sources":["cleanup.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\n\n/**\n * The attributes defined by us or the dynamodb-toolbox library.\n * Add more attributes if necessary.\n */\nconst attributesToRemove = [\n \"PK\",\n \"SK\",\n \"created\",\n \"_ct\",\n \"modified\",\n \"_mt\",\n \"entity\",\n \"_et\",\n \"GSI1_PK\",\n \"GSI1_SK\",\n \"GSI2_PK\",\n \"GSI2_SK\",\n \"GSI3_PK\",\n \"GSI3_SK\",\n \"GSI4_PK\",\n \"GSI4_SK\",\n \"GSI5_PK\",\n \"GSI5_SK\",\n \"GSI_TENANT\",\n \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: T | null,\n removeAttributes: string[] = []\n): T | null {\n if (!item) {\n return null;\n }\n const newItem = {\n ...item\n };\n const targets = attributesToRemove.concat(removeAttributes);\n const attributes = entity.schema.attributes;\n for (const key in item) {\n if (item.hasOwnProperty(key) === false) {\n continue;\n }\n if (attributes[key] && targets.includes(key) === false) {\n continue;\n }\n delete newItem[key];\n }\n return newItem;\n}\n\nexport function cleanupItems<T>(\n entity: Entity<any>,\n items: T[],\n removeAttributes: string[] = []\n): T[] {\n return items.map(item => cleanupItem<T>(entity, item, removeAttributes) as T);\n}\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CACvB,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,KAAK,EACL,UAAU,EACV,KAAK,EACL,QAAQ,EACR,KAAK,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,YAAY,EACZ,MAAM,CACT;AAED,OAAO,SAASC,WAAWA,CACvBC,MAAmB,EACnBC,IAAe,EACfC,gBAA0B,GAAG,EAAE,EACvB;EACR,IAAI,CAACD,IAAI,EAAE;IACP,OAAO,IAAI;EACf;EACA,MAAME,OAAO,GAAG;IACZ,GAAGF;EACP,CAAC;EACD,MAAMG,OAAO,GAAGN,kBAAkB,CAACO,MAAM,CAACH,gBAAgB,CAAC;EAC3D,MAAMI,UAAU,GAAGN,MAAM,CAACO,MAAM,CAACD,UAAU;EAC3C,KAAK,MAAME,GAAG,IAAIP,IAAI,EAAE;IACpB,IAAIA,IAAI,CAACQ,cAAc,CAACD,GAAG,CAAC,KAAK,KAAK,EAAE;MACpC;IACJ;IACA,IAAIF,UAAU,CAACE,GAAG,CAAC,IAAIJ,OAAO,CAACM,QAAQ,CAACF,GAAG,CAAC,KAAK,KAAK,EAAE;MACpD;IACJ;IACA,OAAOL,OAAO,CAACK,GAAG,CAAC;EACvB;EACA,OAAOL,OAAO;AAClB;AAEA,OAAO,SAASQ,YAAYA,CACxBX,MAAmB,EACnBY,KAAU,EACVV,gBAA0B,GAAG,EAAE,EAC5B;EACH,OAAOU,KAAK,CAACC,GAAG,CAACZ,IAAI,IAAIF,WAAW,CAAIC,MAAM,EAAEC,IAAI,EAAEC,gBAAgB,CAAM,CAAC;AACjF","ignoreList":[]}
package/utils/count.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { QueryAllParams } from "./query";
1
+ import type { QueryAllParams } from "../utils/query.js";
2
2
  export declare const count: (params: QueryAllParams) => Promise<number>;
package/utils/count.js CHANGED
@@ -1,10 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.count = void 0;
7
- const count = async params => {
1
+ export const count = async params => {
8
2
  const {
9
3
  entity,
10
4
  partitionKey,
@@ -18,6 +12,5 @@ const count = async params => {
18
12
  });
19
13
  return Count || 0;
20
14
  };
21
- exports.count = count;
22
15
 
23
16
  //# sourceMappingURL=count.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["count","params","entity","partitionKey","options","Count","query","select","exports"],"sources":["count.ts"],"sourcesContent":["import type { QueryAllParams } from \"~/utils/query\";\n\nexport const count = async (params: QueryAllParams): Promise<number> => {\n const { entity, partitionKey, options = {} } = params;\n const { Count } = await entity.query(partitionKey, { ...options, select: \"count\" });\n return Count || 0;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,KAAK,GAAG,MAAOC,MAAsB,IAAsB;EACpE,MAAM;IAAEC,MAAM;IAAEC,YAAY;IAAEC,OAAO,GAAG,CAAC;EAAE,CAAC,GAAGH,MAAM;EACrD,MAAM;IAAEI;EAAM,CAAC,GAAG,MAAMH,MAAM,CAACI,KAAK,CAACH,YAAY,EAAE;IAAE,GAAGC,OAAO;IAAEG,MAAM,EAAE;EAAQ,CAAC,CAAC;EACnF,OAAOF,KAAK,IAAI,CAAC;AACrB,CAAC;AAACG,OAAA,CAAAR,KAAA,GAAAA,KAAA","ignoreList":[]}
1
+ {"version":3,"names":["count","params","entity","partitionKey","options","Count","query","select"],"sources":["count.ts"],"sourcesContent":["import type { QueryAllParams } from \"~/utils/query.js\";\n\nexport const count = async (params: QueryAllParams): Promise<number> => {\n const { entity, partitionKey, options = {} } = params;\n const { Count } = await entity.query(partitionKey, { ...options, select: \"count\" });\n return Count || 0;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,KAAK,GAAG,MAAOC,MAAsB,IAAsB;EACpE,MAAM;IAAEC,MAAM;IAAEC,YAAY;IAAEC,OAAO,GAAG,CAAC;EAAE,CAAC,GAAGH,MAAM;EACrD,MAAM;IAAEI;EAAM,CAAC,GAAG,MAAMH,MAAM,CAACI,KAAK,CAACH,YAAY,EAAE;IAAE,GAAGC,OAAO;IAAEG,MAAM,EAAE;EAAQ,CAAC,CAAC;EACnF,OAAOF,KAAK,IAAI,CAAC;AACrB,CAAC","ignoreList":[]}