@webiny/db-dynamodb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (291) hide show
  1. package/DynamoDbDriver.d.ts +18 -32
  2. package/DynamoDbDriver.js +215 -261
  3. package/DynamoDbDriver.js.map +1 -1
  4. package/README.md +6 -62
  5. package/exports/api/db.d.ts +2 -0
  6. package/exports/api/db.js +2 -0
  7. package/feature/FilterUtil/FilterUtil.d.ts +11 -0
  8. package/feature/FilterUtil/FilterUtil.js +26 -0
  9. package/feature/FilterUtil/FilterUtil.js.map +1 -0
  10. package/feature/FilterUtil/abstractions/FilterUtil.d.ts +17 -0
  11. package/feature/FilterUtil/abstractions/FilterUtil.js +5 -0
  12. package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -0
  13. package/feature/FilterUtil/createFilters.d.ts +22 -0
  14. package/feature/FilterUtil/createFilters.js +92 -0
  15. package/feature/FilterUtil/createFilters.js.map +1 -0
  16. package/feature/FilterUtil/extractWhereArgs.d.ts +7 -0
  17. package/feature/FilterUtil/extractWhereArgs.js +20 -0
  18. package/feature/FilterUtil/extractWhereArgs.js.map +1 -0
  19. package/feature/FilterUtil/feature.d.ts +4 -0
  20. package/feature/FilterUtil/feature.js +11 -0
  21. package/feature/FilterUtil/feature.js.map +1 -0
  22. package/feature/FilterUtil/index.d.ts +2 -0
  23. package/feature/FilterUtil/index.js +2 -0
  24. package/feature/ValueFilter/ValueFilterRegistry.d.ts +12 -0
  25. package/feature/ValueFilter/ValueFilterRegistry.js +27 -0
  26. package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -0
  27. package/feature/ValueFilter/abstractions/ValueFilter.d.ts +22 -0
  28. package/feature/ValueFilter/abstractions/ValueFilter.js +5 -0
  29. package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -0
  30. package/feature/ValueFilter/abstractions/ValueFilterRegistry.d.ts +10 -0
  31. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +5 -0
  32. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -0
  33. package/feature/ValueFilter/feature.d.ts +4 -0
  34. package/feature/ValueFilter/feature.js +33 -0
  35. package/feature/ValueFilter/feature.js.map +1 -0
  36. package/feature/ValueFilter/filters/AndInFilter.d.ts +11 -0
  37. package/feature/ValueFilter/filters/AndInFilter.js +28 -0
  38. package/feature/ValueFilter/filters/AndInFilter.js.map +1 -0
  39. package/feature/ValueFilter/filters/BetweenFilter.d.ts +11 -0
  40. package/feature/ValueFilter/filters/BetweenFilter.js +31 -0
  41. package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -0
  42. package/feature/ValueFilter/filters/ContainsFilter.d.ts +11 -0
  43. package/feature/ValueFilter/filters/ContainsFilter.js +42 -0
  44. package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -0
  45. package/feature/ValueFilter/filters/EqFilter.d.ts +11 -0
  46. package/feature/ValueFilter/filters/EqFilter.js +24 -0
  47. package/feature/ValueFilter/filters/EqFilter.js.map +1 -0
  48. package/feature/ValueFilter/filters/FuzzyFilter.d.ts +11 -0
  49. package/feature/ValueFilter/filters/FuzzyFilter.js +37 -0
  50. package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -0
  51. package/feature/ValueFilter/filters/GtFilter.d.ts +11 -0
  52. package/feature/ValueFilter/filters/GtFilter.js +22 -0
  53. package/feature/ValueFilter/filters/GtFilter.js.map +1 -0
  54. package/feature/ValueFilter/filters/GteFilter.d.ts +11 -0
  55. package/feature/ValueFilter/filters/GteFilter.js +22 -0
  56. package/feature/ValueFilter/filters/GteFilter.js.map +1 -0
  57. package/feature/ValueFilter/filters/InFilter.d.ts +11 -0
  58. package/feature/ValueFilter/filters/InFilter.js +28 -0
  59. package/feature/ValueFilter/filters/InFilter.js.map +1 -0
  60. package/feature/ValueFilter/filters/LtFilter.d.ts +11 -0
  61. package/feature/ValueFilter/filters/LtFilter.js +22 -0
  62. package/feature/ValueFilter/filters/LtFilter.js.map +1 -0
  63. package/feature/ValueFilter/filters/LteFilter.d.ts +11 -0
  64. package/feature/ValueFilter/filters/LteFilter.js +22 -0
  65. package/feature/ValueFilter/filters/LteFilter.js.map +1 -0
  66. package/feature/ValueFilter/filters/StartsWithFilter.d.ts +11 -0
  67. package/feature/ValueFilter/filters/StartsWithFilter.js +29 -0
  68. package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -0
  69. package/feature/ValueFilter/index.d.ts +3 -0
  70. package/feature/ValueFilter/index.js +3 -0
  71. package/index.d.ts +5 -1
  72. package/index.js +12 -14
  73. package/index.js.map +1 -1
  74. package/package.json +32 -30
  75. package/plugins/definitions/DateTimeTransformPlugin.d.ts +2 -1
  76. package/plugins/definitions/DateTimeTransformPlugin.js +21 -50
  77. package/plugins/definitions/DateTimeTransformPlugin.js.map +1 -1
  78. package/plugins/definitions/FieldPlugin.d.ts +2 -2
  79. package/plugins/definitions/FieldPlugin.js +36 -68
  80. package/plugins/definitions/FieldPlugin.js.map +1 -1
  81. package/plugins/definitions/TimeTransformPlugin.d.ts +2 -1
  82. package/plugins/definitions/TimeTransformPlugin.js +29 -56
  83. package/plugins/definitions/TimeTransformPlugin.js.map +1 -1
  84. package/plugins/definitions/ValueTransformPlugin.d.ts +2 -7
  85. package/plugins/definitions/ValueTransformPlugin.js +20 -46
  86. package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
  87. package/plugins/definitions/assignFields.js +15 -34
  88. package/plugins/definitions/assignFields.js.map +1 -1
  89. package/plugins/index.d.ts +5 -2
  90. package/plugins/index.js +5 -19
  91. package/store/entity.d.ts +6 -0
  92. package/store/entity.js +8 -0
  93. package/store/entity.js.map +1 -0
  94. package/store/keys.d.ts +6 -0
  95. package/store/keys.js +9 -0
  96. package/store/keys.js.map +1 -0
  97. package/store/types.d.ts +6 -0
  98. package/store/types.js +0 -0
  99. package/toolbox.d.ts +60 -0
  100. package/toolbox.js +1 -0
  101. package/types.d.ts +10 -23
  102. package/types.js +0 -5
  103. package/utils/batch/batchRead.d.ts +15 -0
  104. package/utils/batch/batchRead.js +45 -0
  105. package/utils/batch/batchRead.js.map +1 -0
  106. package/utils/batch/batchWrite.d.ts +13 -0
  107. package/utils/batch/batchWrite.js +39 -0
  108. package/utils/batch/batchWrite.js.map +1 -0
  109. package/utils/batch/index.d.ts +3 -0
  110. package/utils/batch/index.js +3 -0
  111. package/utils/batch/types.d.ts +30 -0
  112. package/utils/batch/types.js +0 -0
  113. package/utils/cleanup.d.ts +3 -3
  114. package/utils/cleanup.js +36 -41
  115. package/utils/cleanup.js.map +1 -1
  116. package/utils/count.d.ts +2 -0
  117. package/utils/count.js +11 -0
  118. package/utils/count.js.map +1 -0
  119. package/utils/createEntity.d.ts +36 -0
  120. package/utils/createEntity.js +82 -0
  121. package/utils/createEntity.js.map +1 -0
  122. package/utils/createTable.d.ts +11 -0
  123. package/utils/createTable.js +29 -0
  124. package/utils/createTable.js.map +1 -0
  125. package/utils/cursor.js +8 -23
  126. package/utils/cursor.js.map +1 -1
  127. package/utils/delete.d.ts +10 -0
  128. package/utils/delete.js +9 -0
  129. package/utils/delete.js.map +1 -0
  130. package/utils/entity/Entity.d.ts +28 -0
  131. package/utils/entity/Entity.js +95 -0
  132. package/utils/entity/Entity.js.map +1 -0
  133. package/utils/entity/EntityReadBatch.d.ts +18 -0
  134. package/utils/entity/EntityReadBatch.js +31 -0
  135. package/utils/entity/EntityReadBatch.js.map +1 -0
  136. package/utils/entity/EntityReadBatchBuilder.d.ts +10 -0
  137. package/utils/entity/EntityReadBatchBuilder.js +18 -0
  138. package/utils/entity/EntityReadBatchBuilder.js.map +1 -0
  139. package/utils/entity/EntityWriteBatch.d.ts +23 -0
  140. package/utils/entity/EntityWriteBatch.js +44 -0
  141. package/utils/entity/EntityWriteBatch.js.map +1 -0
  142. package/utils/entity/EntityWriteBatchBuilder.d.ts +11 -0
  143. package/utils/entity/EntityWriteBatchBuilder.js +19 -0
  144. package/utils/entity/EntityWriteBatchBuilder.js.map +1 -0
  145. package/utils/entity/getEntity.d.ts +4 -0
  146. package/utils/entity/getEntity.js +11 -0
  147. package/utils/entity/getEntity.js.map +1 -0
  148. package/utils/entity/index.d.ts +7 -0
  149. package/utils/entity/index.js +7 -0
  150. package/utils/entity/types.d.ts +75 -0
  151. package/utils/entity/types.js +0 -0
  152. package/utils/get.d.ts +8 -6
  153. package/utils/get.js +15 -28
  154. package/utils/get.js.map +1 -1
  155. package/utils/index.d.ts +13 -0
  156. package/utils/index.js +13 -0
  157. package/utils/put.d.ts +12 -0
  158. package/utils/put.js +10 -0
  159. package/utils/put.js.map +1 -0
  160. package/utils/query.d.ts +20 -14
  161. package/utils/query.js +84 -108
  162. package/utils/query.js.map +1 -1
  163. package/utils/scan.d.ts +38 -0
  164. package/utils/scan.js +56 -0
  165. package/utils/scan.js.map +1 -0
  166. package/utils/sort.d.ts +1 -1
  167. package/utils/sort.js +38 -84
  168. package/utils/sort.js.map +1 -1
  169. package/utils/table/Table.d.ts +10 -0
  170. package/utils/table/Table.js +28 -0
  171. package/utils/table/Table.js.map +1 -0
  172. package/utils/table/TableReadBatch.d.ts +19 -0
  173. package/utils/table/TableReadBatch.js +46 -0
  174. package/utils/table/TableReadBatch.js.map +1 -0
  175. package/utils/table/TableWriteBatch.d.ts +21 -0
  176. package/utils/table/TableWriteBatch.js +52 -0
  177. package/utils/table/TableWriteBatch.js.map +1 -0
  178. package/utils/table/index.d.ts +4 -0
  179. package/utils/table/index.js +4 -0
  180. package/utils/table/types.d.ts +39 -0
  181. package/utils/table/types.js +0 -0
  182. package/BatchProcess.d.ts +0 -47
  183. package/BatchProcess.js +0 -198
  184. package/BatchProcess.js.map +0 -1
  185. package/QueryGenerator.d.ts +0 -21
  186. package/QueryGenerator.js +0 -78
  187. package/QueryGenerator.js.map +0 -1
  188. package/operators/comparison/beginsWith.d.ts +0 -3
  189. package/operators/comparison/beginsWith.js +0 -24
  190. package/operators/comparison/beginsWith.js.map +0 -1
  191. package/operators/comparison/between.d.ts +0 -3
  192. package/operators/comparison/between.js +0 -30
  193. package/operators/comparison/between.js.map +0 -1
  194. package/operators/comparison/eq.d.ts +0 -3
  195. package/operators/comparison/eq.js +0 -34
  196. package/operators/comparison/eq.js.map +0 -1
  197. package/operators/comparison/gt.d.ts +0 -3
  198. package/operators/comparison/gt.js +0 -24
  199. package/operators/comparison/gt.js.map +0 -1
  200. package/operators/comparison/gte.d.ts +0 -3
  201. package/operators/comparison/gte.js +0 -24
  202. package/operators/comparison/gte.js.map +0 -1
  203. package/operators/comparison/lt.d.ts +0 -3
  204. package/operators/comparison/lt.js +0 -24
  205. package/operators/comparison/lt.js.map +0 -1
  206. package/operators/comparison/lte.d.ts +0 -3
  207. package/operators/comparison/lte.js +0 -24
  208. package/operators/comparison/lte.js.map +0 -1
  209. package/operators/index.d.ts +0 -12
  210. package/operators/index.js +0 -39
  211. package/operators/index.js.map +0 -1
  212. package/operators/logical/and.d.ts +0 -3
  213. package/operators/logical/and.js +0 -63
  214. package/operators/logical/and.js.map +0 -1
  215. package/operators/logical/or.d.ts +0 -3
  216. package/operators/logical/or.js +0 -63
  217. package/operators/logical/or.js.map +0 -1
  218. package/plugins/definitions/AttributePlugin.d.ts +0 -20
  219. package/plugins/definitions/AttributePlugin.js +0 -61
  220. package/plugins/definitions/AttributePlugin.js.map +0 -1
  221. package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
  222. package/plugins/definitions/FieldPathPlugin.js +0 -46
  223. package/plugins/definitions/FieldPathPlugin.js.map +0 -1
  224. package/plugins/definitions/NumberTransformPlugin.d.ts +0 -4
  225. package/plugins/definitions/NumberTransformPlugin.js +0 -45
  226. package/plugins/definitions/NumberTransformPlugin.js.map +0 -1
  227. package/plugins/definitions/ValueFilterPlugin.d.ts +0 -20
  228. package/plugins/definitions/ValueFilterPlugin.js +0 -49
  229. package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
  230. package/plugins/filters/andIn.d.ts +0 -3
  231. package/plugins/filters/andIn.js +0 -35
  232. package/plugins/filters/andIn.js.map +0 -1
  233. package/plugins/filters/between.d.ts +0 -3
  234. package/plugins/filters/between.js +0 -36
  235. package/plugins/filters/between.js.map +0 -1
  236. package/plugins/filters/contains.d.ts +0 -3
  237. package/plugins/filters/contains.js +0 -32
  238. package/plugins/filters/contains.js.map +0 -1
  239. package/plugins/filters/eq.d.ts +0 -3
  240. package/plugins/filters/eq.js +0 -33
  241. package/plugins/filters/eq.js.map +0 -1
  242. package/plugins/filters/fuzzy.d.ts +0 -3
  243. package/plugins/filters/fuzzy.js +0 -30
  244. package/plugins/filters/fuzzy.js.map +0 -1
  245. package/plugins/filters/gt.d.ts +0 -3
  246. package/plugins/filters/gt.js +0 -20
  247. package/plugins/filters/gt.js.map +0 -1
  248. package/plugins/filters/gte.d.ts +0 -3
  249. package/plugins/filters/gte.js +0 -20
  250. package/plugins/filters/gte.js.map +0 -1
  251. package/plugins/filters/in.d.ts +0 -3
  252. package/plugins/filters/in.js +0 -35
  253. package/plugins/filters/in.js.map +0 -1
  254. package/plugins/filters/index.d.ts +0 -2
  255. package/plugins/filters/index.js +0 -34
  256. package/plugins/filters/index.js.map +0 -1
  257. package/plugins/filters/lt.d.ts +0 -3
  258. package/plugins/filters/lt.js +0 -20
  259. package/plugins/filters/lt.js.map +0 -1
  260. package/plugins/filters/lte.d.ts +0 -3
  261. package/plugins/filters/lte.js +0 -20
  262. package/plugins/filters/lte.js.map +0 -1
  263. package/plugins/filters/startsWith.d.ts +0 -3
  264. package/plugins/filters/startsWith.js +0 -33
  265. package/plugins/filters/startsWith.js.map +0 -1
  266. package/plugins/index.js.map +0 -1
  267. package/statements/createKeyConditionExpressionArgs.d.ts +0 -15
  268. package/statements/createKeyConditionExpressionArgs.js +0 -52
  269. package/statements/createKeyConditionExpressionArgs.js.map +0 -1
  270. package/statements/processStatement.d.ts +0 -3
  271. package/statements/processStatement.js +0 -42
  272. package/statements/processStatement.js.map +0 -1
  273. package/types.js.map +0 -1
  274. package/utils/attributes.d.ts +0 -10
  275. package/utils/attributes.js +0 -31
  276. package/utils/attributes.js.map +0 -1
  277. package/utils/batchRead.d.ts +0 -15
  278. package/utils/batchRead.js +0 -89
  279. package/utils/batchRead.js.map +0 -1
  280. package/utils/batchWrite.d.ts +0 -17
  281. package/utils/batchWrite.js +0 -30
  282. package/utils/batchWrite.js.map +0 -1
  283. package/utils/filter.d.ts +0 -12
  284. package/utils/filter.js +0 -213
  285. package/utils/filter.js.map +0 -1
  286. package/utils/listResponse.d.ts +0 -13
  287. package/utils/listResponse.js +0 -33
  288. package/utils/listResponse.js.map +0 -1
  289. package/utils/table.d.ts +0 -7
  290. package/utils/table.js +0 -27
  291. package/utils/table.js.map +0 -1
package/toolbox.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ export { Entity, Table } from "dynamodb-toolbox";
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 Readonly<T> = T extends ((...args: any[]) => any) | undefined ? T : T extends object ? {
9
+ readonly [P in keyof T]: Readonly<T[P]>;
10
+ } : T;
11
+ export type AttributeDefinition = DynamoDBTypes | Partial<{
12
+ type: DynamoDBTypes;
13
+ coerce: boolean;
14
+ default: unknown;
15
+ dependsOn: string | string[];
16
+ required: boolean | "always";
17
+ hidden: boolean;
18
+ prefix: string;
19
+ suffix: string;
20
+ delimiter: string;
21
+ map: string;
22
+ alias: string;
23
+ onlyMap: boolean;
24
+ partitionKey: boolean;
25
+ sortKey: boolean;
26
+ [key: string]: unknown;
27
+ }> | [string, number] | [string, number, string] | [string, number, Record<string, unknown>];
28
+ export type AttributeDefinitions = Record<PropertyKey, AttributeDefinition>;
29
+ export interface EntityConstructor<T extends Readonly<AttributeDefinitions> = Readonly<AttributeDefinitions>> {
30
+ name: string;
31
+ attributes: T;
32
+ table?: TableDef;
33
+ timestamps?: boolean;
34
+ createdAlias?: string;
35
+ modifiedAlias?: string;
36
+ typeAlias?: string;
37
+ typeHidden?: boolean;
38
+ autoExecute?: boolean;
39
+ autoParse?: boolean;
40
+ }
41
+ export interface EntityQueryOptions {
42
+ index?: string;
43
+ limit?: number;
44
+ reverse?: boolean;
45
+ consistent?: boolean;
46
+ capacity?: "indexes" | "total" | "none";
47
+ select?: "all_attributes" | "all_projected_attributes" | "count" | "specific_attributes";
48
+ eq?: string | number;
49
+ lt?: string | number;
50
+ lte?: string | number;
51
+ gt?: string | number;
52
+ gte?: string | number;
53
+ between?: [string, string] | [number, number] | [bigint, bigint];
54
+ beginsWith?: string;
55
+ startKey?: Record<string, unknown>;
56
+ filters?: Record<string, unknown>;
57
+ attributes?: string[];
58
+ execute?: boolean;
59
+ parse?: boolean;
60
+ }
package/toolbox.js ADDED
@@ -0,0 +1 @@
1
+ export { Entity, Table } from "dynamodb-toolbox";
package/types.d.ts CHANGED
@@ -1,23 +1,3 @@
1
- export interface OperatorArgs {
2
- expression: string;
3
- attributeNames: Record<string, any>;
4
- attributeValues: Record<string, any>;
5
- }
6
- interface CanProcessArgs {
7
- key: string;
8
- value: any;
9
- args: OperatorArgs;
10
- }
11
- interface ProcessArgs {
12
- key: string;
13
- value: any;
14
- args: OperatorArgs;
15
- processStatement: any;
16
- }
17
- export interface Operator {
18
- canProcess: ({ key }: CanProcessArgs) => boolean;
19
- process: ({ key, value, args }: ProcessArgs) => void;
20
- }
21
1
  /**
22
2
  * We use this definition to search for a value in any given field that was passed.
23
3
  * It works as an "OR" condition.
@@ -53,6 +33,13 @@ export interface QueryKey {
53
33
  unique?: boolean;
54
34
  name: string;
55
35
  }
56
- export declare type QueryKeys = QueryKey[];
57
- export declare type QuerySort = Record<string, -1 | 1>;
58
- export {};
36
+ export type QueryKeys = QueryKey[];
37
+ export type QuerySort = Record<string, -1 | 1>;
38
+ export type DbItem<TData extends Record<string, any> = Record<string, any>> = {
39
+ PK: string;
40
+ SK: string;
41
+ GSI1_PK: string;
42
+ GSI1_SK: string;
43
+ TYPE: string;
44
+ data: TData;
45
+ };
package/types.js CHANGED
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -0,0 +1,15 @@
1
+ import type { TableDef } from "../../toolbox.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ export interface BatchReadItem {
4
+ Table?: TableDef;
5
+ Key: any;
6
+ }
7
+ export interface BatchReadParams {
8
+ table?: TableDef;
9
+ items: BatchReadItem[];
10
+ }
11
+ /**
12
+ * This helper function is meant to be used to batch read from one table.
13
+ * It will fetch all results, as there is a next() method call built in.
14
+ */
15
+ export declare const batchReadAll: <T = GenericRecord>(params: BatchReadParams, maxChunk?: number) => Promise<T[]>;
@@ -0,0 +1,45 @@
1
+ import chunk from "lodash/chunk.js";
2
+ import error from "@webiny/error";
3
+ const MAX_BATCH_ITEMS = 100;
4
+ const flatten = (responses)=>{
5
+ const entries = [];
6
+ const values = Object.values(responses);
7
+ for (const items of values)entries.push(...items);
8
+ return entries;
9
+ };
10
+ const batchReadAllChunk = async (params)=>{
11
+ const { table, items } = params;
12
+ const records = [];
13
+ if (!table) return records;
14
+ const result = await table.batchGet(items);
15
+ if (!result || !result.Responses) return records;
16
+ records.push(...flatten(result.Responses));
17
+ if (!result.next || "function" != typeof result.next) return records;
18
+ let previous = result;
19
+ while("function" == typeof previous.next){
20
+ const nextResult = await previous.next();
21
+ if (!nextResult) break;
22
+ records.push(...flatten(nextResult.Responses));
23
+ previous = nextResult;
24
+ }
25
+ return records;
26
+ };
27
+ const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS)=>{
28
+ if (0 === params.items.length) return [];
29
+ if (maxChunk > MAX_BATCH_ITEMS) throw new error(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
30
+ maxChunk
31
+ });
32
+ const records = [];
33
+ const chunkItemsList = chunk(params.items, maxChunk);
34
+ for (const chunkItems of chunkItemsList){
35
+ const results = await batchReadAllChunk({
36
+ table: params.table,
37
+ items: chunkItems
38
+ });
39
+ records.push(...results);
40
+ }
41
+ return records;
42
+ };
43
+ export { batchReadAll };
44
+
45
+ //# sourceMappingURL=batchRead.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/batch/batchRead.js","sources":["../../../src/utils/batch/batchRead.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface BatchReadItem {\n Table?: TableDef;\n Key: any;\n}\nexport interface BatchReadParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\n\nconst MAX_BATCH_ITEMS = 100;\n\nconst flatten = (responses: Record<string, any[]>): any[] => {\n const entries = [];\n const values = Object.values(responses);\n for (const items of values) {\n entries.push(...items);\n }\n return entries;\n};\n\ninterface BatchReadAllChunkParams {\n table?: TableDef;\n items: BatchReadItem[];\n}\nconst batchReadAllChunk = async <T = any>(params: BatchReadAllChunkParams): Promise<T[]> => {\n const { table, items } = params;\n const records: T[] = [];\n\n if (!table) {\n return records;\n }\n\n const result = await table.batchGet(items);\n if (!result || !result.Responses) {\n return records;\n }\n records.push(...flatten(result.Responses));\n if (!result.next || typeof result.next !== \"function\") {\n return records;\n }\n let previous = result;\n while (typeof previous.next === \"function\") {\n const nextResult = await previous.next();\n if (!nextResult) {\n return records;\n }\n records.push(...flatten(nextResult.Responses));\n previous = nextResult;\n }\n return records;\n};\n/**\n * This helper function is meant to be used to batch read from one table.\n * It will fetch all results, as there is a next() method call built in.\n */\nexport const batchReadAll = async <T = GenericRecord>(\n params: BatchReadParams,\n maxChunk = MAX_BATCH_ITEMS\n): Promise<T[]> => {\n if (params.items.length === 0) {\n return [];\n } else if (maxChunk > MAX_BATCH_ITEMS) {\n throw new WebinyError(\n `Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`,\n \"DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR\",\n {\n maxChunk\n }\n );\n }\n\n const records: T[] = [];\n\n const chunkItemsList = lodashChunk(params.items, maxChunk);\n\n for (const chunkItems of chunkItemsList) {\n const results = await batchReadAllChunk<T>({\n table: params.table,\n items: chunkItems\n });\n\n records.push(...results);\n }\n\n return records;\n};\n"],"names":["MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","batchReadAllChunk","params","table","records","result","previous","nextResult","batchReadAll","maxChunk","WebinyError","chunkItemsList","lodashChunk","chunkItems","results"],"mappings":";;AAcA,MAAMA,kBAAkB;AAExB,MAAMC,UAAU,CAACC;IACb,MAAMC,UAAU,EAAE;IAClB,MAAMC,SAASC,OAAO,MAAM,CAACH;IAC7B,KAAK,MAAMI,SAASF,OAChBD,QAAQ,IAAI,IAAIG;IAEpB,OAAOH;AACX;AAMA,MAAMI,oBAAoB,OAAgBC;IACtC,MAAM,EAAEC,KAAK,EAAEH,KAAK,EAAE,GAAGE;IACzB,MAAME,UAAe,EAAE;IAEvB,IAAI,CAACD,OACD,OAAOC;IAGX,MAAMC,SAAS,MAAMF,MAAM,QAAQ,CAACH;IACpC,IAAI,CAACK,UAAU,CAACA,OAAO,SAAS,EAC5B,OAAOD;IAEXA,QAAQ,IAAI,IAAIT,QAAQU,OAAO,SAAS;IACxC,IAAI,CAACA,OAAO,IAAI,IAAI,AAAuB,cAAvB,OAAOA,OAAO,IAAI,EAClC,OAAOD;IAEX,IAAIE,WAAWD;IACf,MAAO,AAAyB,cAAzB,OAAOC,SAAS,IAAI,CAAiB;QACxC,MAAMC,aAAa,MAAMD,SAAS,IAAI;QACtC,IAAI,CAACC,YACD;QAEJH,QAAQ,IAAI,IAAIT,QAAQY,WAAW,SAAS;QAC5CD,WAAWC;IACf;IACA,OAAOH;AACX;AAKO,MAAMI,eAAe,OACxBN,QACAO,WAAWf,eAAe;IAE1B,IAAIQ,AAAwB,MAAxBA,OAAO,KAAK,CAAC,MAAM,EACnB,OAAO,EAAE;IACN,IAAIO,WAAWf,iBAClB,MAAM,IAAIgB,MACN,CAAC,6BAA6B,EAAEhB,gBAAgB,iCAAiC,CAAC,EAClF,sCACA;QACIe;IACJ;IAIR,MAAML,UAAe,EAAE;IAEvB,MAAMO,iBAAiBC,MAAYV,OAAO,KAAK,EAAEO;IAEjD,KAAK,MAAMI,cAAcF,eAAgB;QACrC,MAAMG,UAAU,MAAMb,kBAAqB;YACvC,OAAOC,OAAO,KAAK;YACnB,OAAOW;QACX;QAEAT,QAAQ,IAAI,IAAIU;IACpB;IAEA,OAAOV;AACX"}
@@ -0,0 +1,13 @@
1
+ import type { TableDef } from "../../toolbox.js";
2
+ import type { BatchWriteItem, BatchWriteResult } from "./types.js";
3
+ export interface BatchWriteParams {
4
+ table: TableDef | undefined;
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,39 @@
1
+ import chunk from "lodash/chunk.js";
2
+ const hasUnprocessedItems = (result)=>{
3
+ if ("function" != typeof result.next) return false;
4
+ const items = result.UnprocessedItems;
5
+ if (!items || "object" != typeof items) return false;
6
+ const keys = Object.keys(items);
7
+ return keys.some((key)=>{
8
+ const value = items[key];
9
+ if (!Array.isArray(value)) return false;
10
+ return value.some((val)=>val.PutRequest || val.DeleteRequest);
11
+ });
12
+ };
13
+ const retry = async (input, results)=>{
14
+ if (!hasUnprocessedItems(input)) return;
15
+ const result = await input.next();
16
+ await retry(result, results);
17
+ };
18
+ const batchWriteAll = async (params, maxChunk = 25)=>{
19
+ const { items: collection, table } = params;
20
+ if (table) {
21
+ if (0 === collection.length) return [];
22
+ } else {
23
+ console.log("No table provided.");
24
+ return [];
25
+ }
26
+ const chunkedItems = chunk(collection, maxChunk);
27
+ const results = [];
28
+ for (const items of chunkedItems){
29
+ const result = await table.batchWrite(items, {
30
+ execute: true
31
+ });
32
+ results.push(result);
33
+ await retry(result, results);
34
+ }
35
+ return results;
36
+ };
37
+ export { batchWriteAll };
38
+
39
+ //# sourceMappingURL=batchWrite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/batch/batchWrite.js","sources":["../../../src/utils/batch/batchWrite.ts"],"sourcesContent":["import lodashChunk from \"lodash/chunk.js\";\nimport type { TableDef } from \"~/toolbox.js\";\nimport type { BatchWriteItem, BatchWriteResponse, BatchWriteResult } from \"./types.js\";\n\nexport interface BatchWriteParams {\n table: TableDef | undefined;\n items: BatchWriteItem[];\n}\n\nconst hasUnprocessedItems = (result: BatchWriteResponse): boolean => {\n if (typeof result.next !== \"function\") {\n return false;\n }\n const items = result.UnprocessedItems;\n if (!items || typeof items !== \"object\") {\n return false;\n }\n const keys = Object.keys(items);\n return keys.some(key => {\n const value = items[key];\n if (!Array.isArray(value)) {\n return false;\n }\n return value.some(val => {\n return val.PutRequest || val.DeleteRequest;\n });\n });\n};\n\nconst retry = async (input: BatchWriteResponse, results: BatchWriteResult): Promise<void> => {\n if (!hasUnprocessedItems(input)) {\n return;\n }\n const result = await input.next!();\n await retry(result, results);\n};\n/**\n * Method is meant for batch writing to a single table.\n * It expects already prepared items for writing.\n * It can either delete or put items\n * The method does not check items before actually sending them into the underlying library.\n */\nexport const batchWriteAll = async (\n params: BatchWriteParams,\n maxChunk = 25\n): Promise<BatchWriteResult> => {\n const { items: collection, table } = params;\n if (!table) {\n console.log(\"No table provided.\");\n return [];\n } else if (collection.length === 0) {\n return [];\n }\n\n const chunkedItems: BatchWriteItem[][] = lodashChunk(collection, maxChunk);\n const results: BatchWriteResult = [];\n for (const items of chunkedItems) {\n const result = (await table.batchWrite(items, {\n execute: true\n })) as BatchWriteResponse;\n results.push(result);\n await retry(result, results);\n }\n return results;\n};\n"],"names":["hasUnprocessedItems","result","items","keys","Object","key","value","Array","val","retry","input","results","batchWriteAll","params","maxChunk","collection","table","console","chunkedItems","lodashChunk"],"mappings":";AASA,MAAMA,sBAAsB,CAACC;IACzB,IAAI,AAAuB,cAAvB,OAAOA,OAAO,IAAI,EAClB,OAAO;IAEX,MAAMC,QAAQD,OAAO,gBAAgB;IACrC,IAAI,CAACC,SAAS,AAAiB,YAAjB,OAAOA,OACjB,OAAO;IAEX,MAAMC,OAAOC,OAAO,IAAI,CAACF;IACzB,OAAOC,KAAK,IAAI,CAACE,CAAAA;QACb,MAAMC,QAAQJ,KAAK,CAACG,IAAI;QACxB,IAAI,CAACE,MAAM,OAAO,CAACD,QACf,OAAO;QAEX,OAAOA,MAAM,IAAI,CAACE,CAAAA,MACPA,IAAI,UAAU,IAAIA,IAAI,aAAa;IAElD;AACJ;AAEA,MAAMC,QAAQ,OAAOC,OAA2BC;IAC5C,IAAI,CAACX,oBAAoBU,QACrB;IAEJ,MAAMT,SAAS,MAAMS,MAAM,IAAI;IAC/B,MAAMD,MAAMR,QAAQU;AACxB;AAOO,MAAMC,gBAAgB,OACzBC,QACAC,WAAW,EAAE;IAEb,MAAM,EAAE,OAAOC,UAAU,EAAEC,KAAK,EAAE,GAAGH;IACrC,IAAKG,OAGE;QAAA,IAAID,AAAsB,MAAtBA,WAAW,MAAM,EACxB,OAAO,EAAE;IACb,OALY;QACRE,QAAQ,GAAG,CAAC;QACZ,OAAO,EAAE;IACb;IAIA,MAAMC,eAAmCC,MAAYJ,YAAYD;IACjE,MAAMH,UAA4B,EAAE;IACpC,KAAK,MAAMT,SAASgB,aAAc;QAC9B,MAAMjB,SAAU,MAAMe,MAAM,UAAU,CAACd,OAAO;YAC1C,SAAS;QACb;QACAS,QAAQ,IAAI,CAACV;QACb,MAAMQ,MAAMR,QAAQU;IACxB;IACA,OAAOA;AACX"}
@@ -0,0 +1,3 @@
1
+ export * from "./batchRead.js";
2
+ export * from "./batchWrite.js";
3
+ export * from "./types.js";
@@ -0,0 +1,3 @@
1
+ export * from "./batchRead.js";
2
+ export * from "./batchWrite.js";
3
+ export * from "./types.js";
@@ -0,0 +1,30 @@
1
+ import type { WriteRequest } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ export interface BatchWriteResponse {
4
+ next?: () => Promise<BatchWriteResponse>;
5
+ $metadata: {
6
+ httpStatusCode: number;
7
+ requestId: string;
8
+ attempts: number;
9
+ totalRetryDelay: number;
10
+ };
11
+ UnprocessedItems?: {
12
+ [table: string]: WriteRequest[];
13
+ };
14
+ }
15
+ export type BatchWriteResult = BatchWriteResponse[];
16
+ export interface IDeleteBatchItem {
17
+ PK: string;
18
+ SK: string;
19
+ }
20
+ export type IPutBatchItem<T = GenericRecord> = {
21
+ PK: string;
22
+ SK: string;
23
+ } & T;
24
+ export interface BatchWriteItem {
25
+ [key: string]: WriteRequest;
26
+ }
27
+ export interface IReadBatchItem {
28
+ PK: string;
29
+ SK: string;
30
+ }
File without changes
@@ -1,3 +1,3 @@
1
- import { Entity } from "dynamodb-toolbox";
2
- export declare function cleanupItem<T>(entity: Entity<any>, item?: (T & Record<string, any>) | null, removeAttributes?: string[]): T | null;
3
- export declare function cleanupItems<T>(entity: Entity<any>, items: (T & Record<string, any>)[], removeAttributes?: string[]): T[];
1
+ import type { Entity } from "../toolbox.js";
2
+ export declare function cleanupItem<T>(entity: Entity<any>, item?: T | null, removeAttributes?: string[]): T | null;
3
+ export declare function cleanupItems<T>(entity: Entity<any>, items: T[], removeAttributes?: string[]): T[];
package/utils/cleanup.js CHANGED
@@ -1,45 +1,40 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.cleanupItem = cleanupItem;
9
- exports.cleanupItems = cleanupItems;
10
-
11
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
-
13
- /**
14
- * The attributes defined by us or the dynamodb-toolbox library.
15
- * Add more attributes if necessary.
16
- */
17
- const attributesToRemove = ["PK", "SK", "created", "_ct", "modified", "_mt", "entity", "_et", "GSI1_PK", "GSI1_SK", "TYPE"];
18
-
1
+ const attributesToRemove = [
2
+ "PK",
3
+ "SK",
4
+ "created",
5
+ "_ct",
6
+ "modified",
7
+ "_mt",
8
+ "entity",
9
+ "_et",
10
+ "GSI1_PK",
11
+ "GSI1_SK",
12
+ "GSI2_PK",
13
+ "GSI2_SK",
14
+ "GSI3_PK",
15
+ "GSI3_SK",
16
+ "GSI4_PK",
17
+ "GSI4_SK",
18
+ "GSI5_PK",
19
+ "GSI5_SK",
20
+ "GSI_TENANT",
21
+ "TYPE"
22
+ ];
19
23
  function cleanupItem(entity, item, removeAttributes = []) {
20
- if (!item) {
21
- return null;
22
- }
23
-
24
- const newItem = (0, _objectSpread2.default)({}, item);
25
- const targets = attributesToRemove.concat(removeAttributes);
26
- const attributes = entity.schema.attributes;
27
-
28
- for (const key in item) {
29
- if (item.hasOwnProperty(key) === false) {
30
- continue;
24
+ if (!item) return null;
25
+ const newItem = {
26
+ ...item
27
+ };
28
+ const targets = attributesToRemove.concat(removeAttributes);
29
+ const attributes = entity.schema.attributes;
30
+ for(const key in item)if (false !== item.hasOwnProperty(key)) {
31
+ if (!attributes[key] || false !== targets.includes(key)) delete newItem[key];
31
32
  }
32
-
33
- if (attributes[key] && targets.includes(key) === false) {
34
- continue;
35
- }
36
-
37
- delete newItem[key];
38
- }
39
-
40
- return newItem;
33
+ return newItem;
41
34
  }
42
-
43
35
  function cleanupItems(entity, items, removeAttributes = []) {
44
- return items.map(item => cleanupItem(entity, item, removeAttributes));
45
- }
36
+ return items.map((item)=>cleanupItem(entity, item, removeAttributes));
37
+ }
38
+ export { cleanupItem, cleanupItems };
39
+
40
+ //# sourceMappingURL=cleanup.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","concat","attributes","schema","key","hasOwnProperty","includes","cleanupItems","items","map"],"sources":["cleanup.ts"],"sourcesContent":["import { Entity } from \"dynamodb-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 \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: (T & Record<string, any>) | 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 & Record<string, any>)[],\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,IADuB,EAEvB,IAFuB,EAGvB,SAHuB,EAIvB,KAJuB,EAKvB,UALuB,EAMvB,KANuB,EAOvB,QAPuB,EAQvB,KARuB,EASvB,SATuB,EAUvB,SAVuB,EAWvB,MAXuB,CAA3B;;AAcO,SAASC,WAAT,CACHC,MADG,EAEHC,IAFG,EAGHC,gBAA0B,GAAG,EAH1B,EAIK;EACR,IAAI,CAACD,IAAL,EAAW;IACP,OAAO,IAAP;EACH;;EACD,MAAME,OAAO,mCACNF,IADM,CAAb;EAGA,MAAMG,OAAO,GAAGN,kBAAkB,CAACO,MAAnB,CAA0BH,gBAA1B,CAAhB;EACA,MAAMI,UAAU,GAAGN,MAAM,CAACO,MAAP,CAAcD,UAAjC;;EACA,KAAK,MAAME,GAAX,IAAkBP,IAAlB,EAAwB;IACpB,IAAIA,IAAI,CAACQ,cAAL,CAAoBD,GAApB,MAA6B,KAAjC,EAAwC;MACpC;IACH;;IACD,IAAIF,UAAU,CAACE,GAAD,CAAV,IAAmBJ,OAAO,CAACM,QAAR,CAAiBF,GAAjB,MAA0B,KAAjD,EAAwD;MACpD;IACH;;IACD,OAAOL,OAAO,CAACK,GAAD,CAAd;EACH;;EACD,OAAOL,OAAP;AACH;;AAEM,SAASQ,YAAT,CACHX,MADG,EAEHY,KAFG,EAGHV,gBAA0B,GAAG,EAH1B,EAIA;EACH,OAAOU,KAAK,CAACC,GAAN,CAAUZ,IAAI,IAAIF,WAAW,CAAIC,MAAJ,EAAYC,IAAZ,EAAkBC,gBAAlB,CAA7B,CAAP;AACH"}
1
+ {"version":3,"file":"utils/cleanup.js","sources":["../../src/utils/cleanup.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\n\n/**\n * The attributes defined by us or the dynamodb-toolbox library.\n * Add more attributes if necessary.\n */\nconst attributesToRemove = [\n \"PK\",\n \"SK\",\n \"created\",\n \"_ct\",\n \"modified\",\n \"_mt\",\n \"entity\",\n \"_et\",\n \"GSI1_PK\",\n \"GSI1_SK\",\n \"GSI2_PK\",\n \"GSI2_SK\",\n \"GSI3_PK\",\n \"GSI3_SK\",\n \"GSI4_PK\",\n \"GSI4_SK\",\n \"GSI5_PK\",\n \"GSI5_SK\",\n \"GSI_TENANT\",\n \"TYPE\"\n];\n\nexport function cleanupItem<T>(\n entity: Entity<any>,\n item?: T | null,\n removeAttributes: string[] = []\n): T | null {\n if (!item) {\n return null;\n }\n const newItem = {\n ...item\n };\n const targets = attributesToRemove.concat(removeAttributes);\n const attributes = entity.schema.attributes;\n for (const key in item) {\n if (item.hasOwnProperty(key) === false) {\n continue;\n }\n if (attributes[key] && targets.includes(key) === false) {\n continue;\n }\n delete newItem[key];\n }\n return newItem;\n}\n\nexport function cleanupItems<T>(\n entity: Entity<any>,\n items: T[],\n removeAttributes: string[] = []\n): T[] {\n return items.map(item => cleanupItem<T>(entity, item, removeAttributes) as T);\n}\n"],"names":["attributesToRemove","cleanupItem","entity","item","removeAttributes","newItem","targets","attributes","key","cleanupItems","items"],"mappings":"AAMA,MAAMA,qBAAqB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAEM,SAASC,YACZC,MAAmB,EACnBC,IAAe,EACfC,mBAA6B,EAAE;IAE/B,IAAI,CAACD,MACD,OAAO;IAEX,MAAME,UAAU;QACZ,GAAGF,IAAI;IACX;IACA,MAAMG,UAAUN,mBAAmB,MAAM,CAACI;IAC1C,MAAMG,aAAaL,OAAO,MAAM,CAAC,UAAU;IAC3C,IAAK,MAAMM,OAAOL,KACd,IAAIA,AAA6B,UAA7BA,KAAK,cAAc,CAACK,MAGxB;QAAA,IAAID,CAAAA,UAAU,CAACC,IAAI,IAAIF,AAA0B,UAA1BA,QAAQ,QAAQ,CAACE,MAGxC,OAAOH,OAAO,CAACG,IAAI;IADnB;IAGJ,OAAOH;AACX;AAEO,SAASI,aACZP,MAAmB,EACnBQ,KAAU,EACVN,mBAA6B,EAAE;IAE/B,OAAOM,MAAM,GAAG,CAACP,CAAAA,OAAQF,YAAeC,QAAQC,MAAMC;AAC1D"}
@@ -0,0 +1,2 @@
1
+ import type { QueryAllParams } from "../utils/query.js";
2
+ export declare const count: (params: QueryAllParams) => Promise<number>;
package/utils/count.js ADDED
@@ -0,0 +1,11 @@
1
+ const count = async (params)=>{
2
+ const { entity, partitionKey, options = {} } = params;
3
+ const { Count } = await entity.query(partitionKey, {
4
+ ...options,
5
+ select: "count"
6
+ });
7
+ return Count || 0;
8
+ };
9
+ export { count };
10
+
11
+ //# sourceMappingURL=count.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/count.js","sources":["../../src/utils/count.ts"],"sourcesContent":["import type { QueryAllParams } from \"~/utils/query.js\";\n\nexport const count = async (params: QueryAllParams): Promise<number> => {\n const { entity, partitionKey, options = {} } = params;\n // @ts-expect-error\n const { Count } = await entity.query(partitionKey, { ...options, select: \"count\" });\n return Count || 0;\n};\n"],"names":["count","params","entity","partitionKey","options","Count"],"mappings":"AAEO,MAAMA,QAAQ,OAAOC;IACxB,MAAM,EAAEC,MAAM,EAAEC,YAAY,EAAEC,UAAU,CAAC,CAAC,EAAE,GAAGH;IAE/C,MAAM,EAAEI,KAAK,EAAE,GAAG,MAAMH,OAAO,KAAK,CAACC,cAAc;QAAE,GAAGC,OAAO;QAAE,QAAQ;IAAQ;IACjF,OAAOC,SAAS;AACpB"}
@@ -0,0 +1,36 @@
1
+ import type { AttributeDefinitions } from "../toolbox.js";
2
+ import { type EntityConstructor } from "../utils/entity/index.js";
3
+ import type { GenericRecord } from "@webiny/api/types.js";
4
+ export type IGlobalEntityAttributes<T = undefined> = {
5
+ PK: string;
6
+ SK: string;
7
+ TYPE: string;
8
+ GSI1_PK?: string;
9
+ GSI1_SK?: string;
10
+ GSI2_PK?: string;
11
+ GSI2_SK?: string;
12
+ expiresAt?: number | null;
13
+ } & (T extends undefined ? {
14
+ data?: undefined;
15
+ } : {
16
+ data: T;
17
+ });
18
+ export declare const globalEntityAttributes: AttributeDefinitions;
19
+ export declare const createGlobalEntity: <T extends GenericRecord = GenericRecord>(params: Omit<EntityConstructor, "attributes"> & Partial<Pick<EntityConstructor, "attributes">>) => import("~/utils/entity/index.js").IEntity<IGlobalEntityAttributes<T>>;
20
+ export type IStandardEntityAttributes<T = undefined> = {
21
+ PK: string;
22
+ SK: string;
23
+ GSI_TENANT: string;
24
+ TYPE: string;
25
+ GSI1_PK?: string;
26
+ GSI1_SK?: string;
27
+ GSI2_PK?: string;
28
+ GSI2_SK?: string;
29
+ expiresAt?: number | null;
30
+ } & (T extends undefined ? {
31
+ data?: undefined;
32
+ } : {
33
+ data: T;
34
+ });
35
+ export declare const standardEntityAttributes: AttributeDefinitions;
36
+ export declare const createStandardEntity: <T extends GenericRecord = GenericRecord>(params: Omit<EntityConstructor, "attributes"> & Partial<Pick<EntityConstructor, "attributes">>) => import("~/utils/entity/index.js").IEntity<IStandardEntityAttributes<T>>;
@@ -0,0 +1,82 @@
1
+ import { createEntity } from "./entity/index.js";
2
+ const globalEntityAttributes = {
3
+ PK: {
4
+ partitionKey: true
5
+ },
6
+ SK: {
7
+ sortKey: true
8
+ },
9
+ GSI1_PK: {
10
+ type: "string"
11
+ },
12
+ GSI1_SK: {
13
+ type: "string"
14
+ },
15
+ GSI2_PK: {
16
+ type: "string"
17
+ },
18
+ GSI2_SK: {
19
+ type: "string"
20
+ },
21
+ TYPE: {
22
+ type: "string",
23
+ required: true
24
+ },
25
+ data: {
26
+ type: "map"
27
+ },
28
+ expiresAt: {
29
+ type: "number"
30
+ }
31
+ };
32
+ const createGlobalEntity = (params)=>createEntity({
33
+ ...params,
34
+ attributes: {
35
+ ...globalEntityAttributes,
36
+ ...params.attributes
37
+ }
38
+ });
39
+ const standardEntityAttributes = {
40
+ PK: {
41
+ partitionKey: true
42
+ },
43
+ SK: {
44
+ sortKey: true
45
+ },
46
+ GSI_TENANT: {
47
+ type: "string",
48
+ required: true
49
+ },
50
+ GSI1_PK: {
51
+ type: "string"
52
+ },
53
+ GSI1_SK: {
54
+ type: "string"
55
+ },
56
+ GSI2_PK: {
57
+ type: "string"
58
+ },
59
+ GSI2_SK: {
60
+ type: "string"
61
+ },
62
+ TYPE: {
63
+ type: "string",
64
+ required: true
65
+ },
66
+ data: {
67
+ type: "map"
68
+ },
69
+ expiresAt: {
70
+ type: "number"
71
+ }
72
+ };
73
+ const createStandardEntity = (params)=>createEntity({
74
+ ...params,
75
+ attributes: {
76
+ ...standardEntityAttributes,
77
+ ...params.attributes
78
+ }
79
+ });
80
+ export { createGlobalEntity, createStandardEntity, globalEntityAttributes, standardEntityAttributes };
81
+
82
+ //# sourceMappingURL=createEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/createEntity.js","sources":["../../src/utils/createEntity.ts"],"sourcesContent":["import type { AttributeDefinitions } from \"~/toolbox.js\";\nimport { createEntity, type EntityConstructor } from \"~/utils/entity/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport type IGlobalEntityAttributes<T = undefined> = {\n PK: string;\n SK: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n GSI2_PK?: string;\n GSI2_SK?: string;\n expiresAt?: number | null;\n} & (T extends undefined ? { data?: undefined } : { data: T });\n\nexport const globalEntityAttributes: AttributeDefinitions = {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n GSI2_PK: {\n type: \"string\"\n },\n GSI2_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\",\n required: true\n },\n data: {\n type: \"map\"\n },\n expiresAt: {\n type: \"number\"\n }\n};\n\nexport const createGlobalEntity = <T extends GenericRecord = GenericRecord>(\n params: Omit<EntityConstructor, \"attributes\"> & Partial<Pick<EntityConstructor, \"attributes\">>\n) => {\n return createEntity<IGlobalEntityAttributes<T>>({\n ...params,\n attributes: {\n ...globalEntityAttributes,\n ...params.attributes\n }\n });\n};\n\nexport type IStandardEntityAttributes<T = undefined> = {\n PK: string;\n SK: string;\n GSI_TENANT: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n GSI2_PK?: string;\n GSI2_SK?: string;\n expiresAt?: number | null;\n} & (T extends undefined ? { data?: undefined } : { data: T });\n\nexport const standardEntityAttributes: AttributeDefinitions = {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI_TENANT: {\n type: \"string\",\n required: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n GSI2_PK: {\n type: \"string\"\n },\n GSI2_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\",\n required: true\n },\n data: {\n type: \"map\"\n },\n expiresAt: {\n type: \"number\"\n }\n};\n\nexport const createStandardEntity = <T extends GenericRecord = GenericRecord>(\n params: Omit<EntityConstructor, \"attributes\"> & Partial<Pick<EntityConstructor, \"attributes\">>\n) => {\n return createEntity<IStandardEntityAttributes<T>>({\n ...params,\n attributes: {\n ...standardEntityAttributes,\n ...params.attributes\n }\n });\n};\n"],"names":["globalEntityAttributes","createGlobalEntity","params","createEntity","standardEntityAttributes","createStandardEntity"],"mappings":";AAeO,MAAMA,yBAA+C;IACxD,IAAI;QACA,cAAc;IAClB;IACA,IAAI;QACA,SAAS;IACb;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,MAAM;QACF,MAAM;QACN,UAAU;IACd;IACA,MAAM;QACF,MAAM;IACV;IACA,WAAW;QACP,MAAM;IACV;AACJ;AAEO,MAAMC,qBAAqB,CAC9BC,SAEOC,aAAyC;QAC5C,GAAGD,MAAM;QACT,YAAY;YACR,GAAGF,sBAAsB;YACzB,GAAGE,OAAO,UAAU;QACxB;IACJ;AAeG,MAAME,2BAAiD;IAC1D,IAAI;QACA,cAAc;IAClB;IACA,IAAI;QACA,SAAS;IACb;IACA,YAAY;QACR,MAAM;QACN,UAAU;IACd;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,SAAS;QACL,MAAM;IACV;IACA,MAAM;QACF,MAAM;QACN,UAAU;IACd;IACA,MAAM;QACF,MAAM;IACV;IACA,WAAW;QACP,MAAM;IACV;AACJ;AAEO,MAAMC,uBAAuB,CAChCH,SAEOC,aAA2C;QAC9C,GAAGD,MAAM;QACT,YAAY;YACR,GAAGE,wBAAwB;YAC3B,GAAGF,OAAO,UAAU;QACxB;IACJ"}
@@ -0,0 +1,11 @@
1
+ import type { ITable } from "../utils/table/index.js";
2
+ import type { TableConstructor } from "../toolbox.js";
3
+ export interface ICreateTableParamsIndexDefinition {
4
+ partitionKey: string;
5
+ sortKey?: string;
6
+ }
7
+ export type ICreateTableParams = Partial<Omit<TableConstructor<string, string, string>, "DocumentClient">> & {
8
+ name: string;
9
+ documentClient: Pick<TableConstructor<string, string, string>, "DocumentClient">["DocumentClient"];
10
+ };
11
+ export declare const createTable: (params: ICreateTableParams) => ITable<string, "PK", "SK">;
@@ -0,0 +1,29 @@
1
+ import { Table } from "./table/index.js";
2
+ const createTable = (params)=>{
3
+ const { documentClient, indexes = {}, ...rest } = params;
4
+ return new Table({
5
+ partitionKey: "PK",
6
+ sortKey: "SK",
7
+ DocumentClient: documentClient,
8
+ indexes: {
9
+ GSI_TENANT: {
10
+ partitionKey: "GSI_TENANT"
11
+ },
12
+ GSI1: {
13
+ partitionKey: "GSI1_PK",
14
+ sortKey: "GSI1_SK"
15
+ },
16
+ GSI2: {
17
+ partitionKey: "GSI2_PK",
18
+ sortKey: "GSI2_SK"
19
+ },
20
+ ...indexes
21
+ },
22
+ autoExecute: true,
23
+ autoParse: true,
24
+ ...rest
25
+ });
26
+ };
27
+ export { createTable };
28
+
29
+ //# sourceMappingURL=createTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/createTable.js","sources":["../../src/utils/createTable.ts"],"sourcesContent":["import type { ITable } from \"~/utils/table/index.js\";\nimport { Table } from \"~/utils/table/index.js\";\nimport type { TableConstructor } from \"~/toolbox.js\";\n\nexport interface ICreateTableParamsIndexDefinition {\n partitionKey: string;\n sortKey?: string;\n}\n\n// export interface ICreateTableParams {\n// name?: string;\n// documentClient: DynamoDBDocument;\n// indexes?: GenericRecord<string, ICreateTableParamsIndexDefinition>;\n// }\n\nexport type ICreateTableParams = Partial<\n Omit<TableConstructor<string, string, string>, \"DocumentClient\">\n> & {\n name: string;\n documentClient: Pick<\n TableConstructor<string, string, string>,\n \"DocumentClient\"\n >[\"DocumentClient\"];\n};\n\nexport const createTable = (params: ICreateTableParams): ITable<string, \"PK\", \"SK\"> => {\n const { documentClient, indexes = {}, ...rest } = params;\n return new Table({\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: documentClient,\n indexes: {\n GSI_TENANT: {\n partitionKey: \"GSI_TENANT\"\n },\n GSI1: {\n partitionKey: \"GSI1_PK\",\n sortKey: \"GSI1_SK\"\n },\n GSI2: {\n partitionKey: \"GSI2_PK\",\n sortKey: \"GSI2_SK\"\n },\n ...indexes\n },\n autoExecute: true,\n autoParse: true,\n ...rest\n });\n};\n"],"names":["createTable","params","documentClient","indexes","rest","Table"],"mappings":";AAyBO,MAAMA,cAAc,CAACC;IACxB,MAAM,EAAEC,cAAc,EAAEC,UAAU,CAAC,CAAC,EAAE,GAAGC,MAAM,GAAGH;IAClD,OAAO,IAAII,MAAM;QACb,cAAc;QACd,SAAS;QACT,gBAAgBH;QAChB,SAAS;YACL,YAAY;gBACR,cAAc;YAClB;YACA,MAAM;gBACF,cAAc;gBACd,SAAS;YACb;YACA,MAAM;gBACF,cAAc;gBACd,SAAS;YACb;YACA,GAAGC,OAAO;QACd;QACA,aAAa;QACb,WAAW;QACX,GAAGC,IAAI;IACX;AACJ"}
package/utils/cursor.js CHANGED
@@ -1,26 +1,11 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.encodeCursor = exports.decodeCursor = void 0;
7
-
8
- const encodeCursor = cursor => {
9
- if (!cursor) {
10
- return null;
11
- }
12
-
13
- return Buffer.from(JSON.stringify(cursor)).toString("base64");
1
+ const encodeCursor = (cursor)=>{
2
+ if (!cursor) return null;
3
+ return Buffer.from(JSON.stringify(cursor)).toString("base64");
14
4
  };
15
-
16
- exports.encodeCursor = encodeCursor;
17
-
18
- const decodeCursor = cursor => {
19
- if (!cursor) {
20
- return null;
21
- }
22
-
23
- return JSON.parse(Buffer.from(cursor, "base64").toString("ascii"));
5
+ const decodeCursor = (cursor)=>{
6
+ if (!cursor) return null;
7
+ return JSON.parse(Buffer.from(cursor, "base64").toString("ascii"));
24
8
  };
9
+ export { decodeCursor, encodeCursor };
25
10
 
26
- exports.decodeCursor = decodeCursor;
11
+ //# sourceMappingURL=cursor.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["encodeCursor","cursor","Buffer","from","JSON","stringify","toString","decodeCursor","parse"],"sources":["cursor.ts"],"sourcesContent":["export const encodeCursor = (cursor?: any): string | null => {\n if (!cursor) {\n return null;\n }\n\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n};\n\nexport const decodeCursor = (cursor?: string | null): string | null => {\n if (!cursor) {\n return null;\n }\n\n return JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n};\n"],"mappings":";;;;;;;AAAO,MAAMA,YAAY,GAAIC,MAAD,IAAiC;EACzD,IAAI,CAACA,MAAL,EAAa;IACT,OAAO,IAAP;EACH;;EAED,OAAOC,MAAM,CAACC,IAAP,CAAYC,IAAI,CAACC,SAAL,CAAeJ,MAAf,CAAZ,EAAoCK,QAApC,CAA6C,QAA7C,CAAP;AACH,CANM;;;;AAQA,MAAMC,YAAY,GAAIN,MAAD,IAA2C;EACnE,IAAI,CAACA,MAAL,EAAa;IACT,OAAO,IAAP;EACH;;EAED,OAAOG,IAAI,CAACI,KAAL,CAAWN,MAAM,CAACC,IAAP,CAAYF,MAAZ,EAAoB,QAApB,EAA8BK,QAA9B,CAAuC,OAAvC,CAAX,CAAP;AACH,CANM"}
1
+ {"version":3,"file":"utils/cursor.js","sources":["../../src/utils/cursor.ts"],"sourcesContent":["export const encodeCursor = (cursor?: any): string | null => {\n if (!cursor) {\n return null;\n }\n\n return Buffer.from(JSON.stringify(cursor)).toString(\"base64\");\n};\n\nexport const decodeCursor = (cursor?: string | null): string | null => {\n if (!cursor) {\n return null;\n }\n\n return JSON.parse(Buffer.from(cursor, \"base64\").toString(\"ascii\"));\n};\n"],"names":["encodeCursor","cursor","Buffer","JSON","decodeCursor"],"mappings":"AAAO,MAAMA,eAAe,CAACC;IACzB,IAAI,CAACA,QACD,OAAO;IAGX,OAAOC,OAAO,IAAI,CAACC,KAAK,SAAS,CAACF,SAAS,QAAQ,CAAC;AACxD;AAEO,MAAMG,eAAe,CAACH;IACzB,IAAI,CAACA,QACD,OAAO;IAGX,OAAOE,KAAK,KAAK,CAACD,OAAO,IAAI,CAACD,QAAQ,UAAU,QAAQ,CAAC;AAC7D"}