@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/utils/put.js ADDED
@@ -0,0 +1,10 @@
1
+ const put = async (params)=>{
2
+ const { entity, item } = params;
3
+ return await entity.put(item, {
4
+ execute: true,
5
+ strictSchemaCheck: false
6
+ });
7
+ };
8
+ export { put };
9
+
10
+ //# sourceMappingURL=put.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/put.js","sources":["../../src/utils/put.ts"],"sourcesContent":["import type { Entity } from \"~/toolbox.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport type IPutParamsItem<T extends GenericRecord = GenericRecord> = {\n PK: string;\n SK: string;\n [key: string]: any;\n} & T;\n\nexport interface IPutParams<T extends GenericRecord = GenericRecord> {\n entity: Entity;\n item: IPutParamsItem<T>;\n}\n\nexport const put = async <T extends GenericRecord = GenericRecord>(params: IPutParams<T>) => {\n const { entity, item } = params;\n\n return await entity.put(item, {\n execute: true,\n strictSchemaCheck: false\n });\n};\n"],"names":["put","params","entity","item"],"mappings":"AAcO,MAAMA,MAAM,OAAgDC;IAC/D,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGF;IAEzB,OAAO,MAAMC,OAAO,GAAG,CAACC,MAAM;QAC1B,SAAS;QACT,mBAAmB;IACvB;AACJ"}
package/utils/query.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { queryOptions as DynamoDBToolboxQueryOptions } from "dynamodb-toolbox/dist/classes/Table";
2
- import { Entity } from "dynamodb-toolbox";
1
+ import type { Entity, EntityQueryOptions } from "../toolbox.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
3
  export interface QueryAllParams {
4
4
  entity: Entity<any>;
5
5
  partitionKey: string;
6
- options?: DynamoDBToolboxQueryOptions;
6
+ options?: EntityQueryOptions;
7
7
  }
8
8
  export interface QueryOneParams extends QueryAllParams {
9
- options?: Omit<DynamoDBToolboxQueryOptions, "limit">;
9
+ options?: Omit<EntityQueryOptions, "limit">;
10
10
  }
11
11
  export interface QueryParams extends QueryAllParams {
12
12
  previous?: any;
@@ -15,18 +15,24 @@ export interface QueryResult<T> {
15
15
  result: any | null;
16
16
  items: T[];
17
17
  }
18
- export declare type DbItem<T> = T & {
19
- PK: string;
20
- SK: string;
21
- TYPE: string;
22
- GSI1_PK?: string;
23
- GSI1_SK?: string;
24
- };
25
18
  /**
26
19
  * Will run the query to fetch the first possible item from the database.
27
20
  */
28
- export declare const queryOne: <T>(params: QueryOneParams) => Promise<DbItem<T> | null>;
21
+ export declare const queryOne: <T>(params: QueryOneParams) => Promise<T | null>;
22
+ export declare const queryOneClean: <T>(params: QueryOneParams) => Promise<T | null>;
29
23
  /**
30
- * Will run the query to fetch the results no matter how much iterations it needs to go through.
24
+ * Will run the query to fetch the results no matter how many iterations it needs to go through.
31
25
  */
32
- export declare const queryAll: <T>(params: QueryAllParams) => Promise<DbItem<T>[]>;
26
+ export declare const queryAll: <T>(params: QueryAllParams) => Promise<T[]>;
27
+ export declare const queryAllClean: <T>(params: QueryAllParams) => Promise<T[]>;
28
+ export interface IQueryPageResponse<T> {
29
+ items: T[];
30
+ lastEvaluatedKey: GenericRecord;
31
+ }
32
+ export declare const queryPerPage: <T>(params: QueryAllParams) => Promise<IQueryPageResponse<T>>;
33
+ export declare const queryPerPageClean: <T>(params: QueryAllParams) => Promise<IQueryPageResponse<T>>;
34
+ /**
35
+ * Will run the query to fetch the results no matter how many iterations it needs to go through.
36
+ * Results of each iteration will be passed to the provided callback
37
+ */
38
+ export declare const queryAllWithCallback: <T>(params: QueryAllParams, callback: (items: T[]) => Promise<void>) => Promise<void>;
package/utils/query.js CHANGED
@@ -1,119 +1,95 @@
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.queryOne = exports.queryAll = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- /**
15
- * Will run query only once. Pass the previous to run the query again to fetch new data.
16
- * It returns the result and the items it found.
17
- * Result is required to fetch the items that were not fetched in the previous run.
18
- */
19
- const query = async params => {
20
- const {
21
- entity,
22
- previous,
23
- partitionKey,
24
- options
25
- } = params;
26
- let result;
27
- /**
28
- * In case there is no previous result we must make a new query.
29
- * This is the first query on the given partition key.
30
- */
31
-
32
- if (!previous) {
33
- result = await entity.query(partitionKey, options);
34
- } else if (typeof previous.next === "function") {
35
- /**
36
- * In case we have a previous result and it has a next method, we run it.
37
- * In case result of the next method is false, it means it has nothing else to read
38
- * and we return a null to keep the query from repeating.
39
- */
40
- result = await previous.next();
41
-
42
- if (result === false) {
43
- return {
1
+ import error from "@webiny/error";
2
+ import { cleanupItem, cleanupItems } from "./cleanup.js";
3
+ const query = async (params)=>{
4
+ const { entity, previous, partitionKey, options } = params;
5
+ let result;
6
+ if (previous) if ("function" != typeof previous.next) return {
44
7
  result: null,
45
8
  items: []
46
- };
9
+ };
10
+ else {
11
+ result = await previous.next();
12
+ if (false === result) return {
13
+ result: null,
14
+ items: []
15
+ };
47
16
  }
48
- } else {
49
- /**
50
- * This could probably never happen but keep it here just in case to break the query loop.
51
- * Basically, either previous does not exist or it exists and it does not have the next method
52
- * and at that point a result returned will be null and loop should not start again.
53
- */
17
+ else result = await entity.query(partitionKey, options);
18
+ if (!result || !result.Items || !Array.isArray(result.Items)) throw new error("Error when querying for content entries - no result.", "QUERY_ERROR", {
19
+ partitionKey,
20
+ options
21
+ });
54
22
  return {
55
- result: null,
56
- items: []
23
+ result,
24
+ items: result.Items
57
25
  };
58
- }
59
- /**
60
- * We expect the result to contain an Items array and if not, something went wrong, very wrong.
61
- */
62
-
63
-
64
- if (!result || !result.Items || !Array.isArray(result.Items)) {
65
- throw new _error.default("Error when querying for content entries - no result.", "QUERY_ERROR", {
66
- partitionKey,
67
- options
26
+ };
27
+ const queryOne = async (params)=>{
28
+ const { items } = await query({
29
+ ...params,
30
+ options: {
31
+ ...params.options || {},
32
+ limit: 1
33
+ }
68
34
  });
69
- }
70
-
71
- return {
72
- result,
73
- items: result.Items
74
- };
35
+ const item = items.shift();
36
+ return item ? item : null;
75
37
  };
76
- /**
77
- * Will run the query to fetch the first possible item from the database.
78
- */
79
-
80
-
81
- const queryOne = async params => {
82
- const {
83
- items
84
- } = await query((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
85
- options: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.options || {}), {}, {
86
- limit: 1
87
- })
88
- }));
89
- const item = items.shift();
90
- return item ? item : null;
38
+ const queryOneClean = async (params)=>{
39
+ const result = await queryOne(params);
40
+ if (!result) return null;
41
+ return cleanupItem(params.entity, result);
91
42
  };
92
- /**
93
- * Will run the query to fetch the results no matter how much iterations it needs to go through.
94
- */
95
-
96
-
97
- exports.queryOne = queryOne;
98
-
99
- const queryAll = async params => {
100
- const items = [];
101
- let results;
102
- let previousResult = undefined;
103
-
104
- while (results = await query((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
105
- previous: previousResult
106
- }))) {
107
- items.push(...results.items);
108
-
109
- if (!results.result) {
110
- return items;
43
+ const queryAll = async (params)=>{
44
+ const items = [];
45
+ let results;
46
+ let previousResult;
47
+ while(results = await query({
48
+ ...params,
49
+ previous: previousResult
50
+ })){
51
+ items.push(...results.items);
52
+ if (!results.result) break;
53
+ previousResult = results.result;
54
+ }
55
+ return items;
56
+ };
57
+ const queryAllClean = async (params)=>{
58
+ const results = await queryAll(params);
59
+ return cleanupItems(params.entity, results);
60
+ };
61
+ const queryPerPage = async (params)=>{
62
+ const result = await query({
63
+ ...params,
64
+ options: {
65
+ ...params.options,
66
+ limit: params.options?.limit || 50
67
+ }
68
+ });
69
+ return {
70
+ items: result.items,
71
+ lastEvaluatedKey: result.result?.LastEvaluatedKey
72
+ };
73
+ };
74
+ const queryPerPageClean = async (params)=>{
75
+ const result = await queryPerPage(params);
76
+ return {
77
+ items: cleanupItems(params.entity, result.items),
78
+ lastEvaluatedKey: result.lastEvaluatedKey
79
+ };
80
+ };
81
+ const queryAllWithCallback = async (params, callback)=>{
82
+ let results;
83
+ let previousResult;
84
+ while(results = await query({
85
+ ...params,
86
+ previous: previousResult
87
+ })){
88
+ if (!results.result) break;
89
+ await callback(results.items);
90
+ previousResult = results.result;
111
91
  }
112
-
113
- previousResult = results.result;
114
- }
115
-
116
- return items;
117
92
  };
93
+ export { queryAll, queryAllClean, queryAllWithCallback, queryOne, queryOneClean, queryPerPage, queryPerPageClean };
118
94
 
119
- exports.queryAll = queryAll;
95
+ //# sourceMappingURL=query.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["query","params","entity","previous","partitionKey","options","result","next","items","Items","Array","isArray","WebinyError","queryOne","limit","item","shift","queryAll","results","previousResult","undefined","push"],"sources":["query.ts"],"sourcesContent":["import { queryOptions as DynamoDBToolboxQueryOptions } from \"dynamodb-toolbox/dist/classes/Table\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\n\nexport interface QueryAllParams {\n entity: Entity<any>;\n partitionKey: string;\n options?: DynamoDBToolboxQueryOptions;\n}\n\nexport interface QueryOneParams extends QueryAllParams {\n options?: Omit<DynamoDBToolboxQueryOptions, \"limit\">;\n}\n\nexport interface QueryParams extends QueryAllParams {\n previous?: any;\n}\n\nexport interface QueryResult<T> {\n result: any | null;\n items: T[];\n}\n\nexport type DbItem<T> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n GSI1_PK?: string;\n GSI1_SK?: string;\n};\n\n/**\n * Will run query only once. Pass the previous to run the query again to fetch new data.\n * It returns the result and the items it found.\n * Result is required to fetch the items that were not fetched in the previous run.\n */\nconst query = async <T>(params: QueryParams): Promise<QueryResult<T>> => {\n const { entity, previous, partitionKey, options } = params;\n let result;\n /**\n * In case there is no previous result we must make a new query.\n * This is the first query on the given partition key.\n */\n if (!previous) {\n result = await entity.query(partitionKey, options);\n } else if (typeof previous.next === \"function\") {\n /**\n * In case we have a previous result and it has a next method, we run it.\n * In case result of the next method is false, it means it has nothing else to read\n * and we return a null to keep the query from repeating.\n */\n result = await previous.next();\n if (result === false) {\n return {\n result: null,\n items: []\n };\n }\n } else {\n /**\n * This could probably never happen but keep it here just in case to break the query loop.\n * Basically, either previous does not exist or it exists and it does not have the next method\n * and at that point a result returned will be null and loop should not start again.\n */\n return {\n result: null,\n items: []\n };\n }\n /**\n * We expect the result to contain an Items array and if not, something went wrong, very wrong.\n */\n if (!result || !result.Items || !Array.isArray(result.Items)) {\n throw new WebinyError(\n \"Error when querying for content entries - no result.\",\n \"QUERY_ERROR\",\n {\n partitionKey,\n options\n }\n );\n }\n return {\n result,\n items: result.Items\n };\n};\n/**\n * Will run the query to fetch the first possible item from the database.\n */\nexport const queryOne = async <T>(params: QueryOneParams): Promise<DbItem<T> | null> => {\n const { items } = await query<DbItem<T>>({\n ...params,\n options: {\n ...(params.options || {}),\n limit: 1\n }\n });\n const item = items.shift();\n return item ? item : null;\n};\n/**\n * Will run the query to fetch the results no matter how much iterations it needs to go through.\n */\nexport const queryAll = async <T>(params: QueryAllParams): Promise<DbItem<T>[]> => {\n const items: DbItem<T>[] = [];\n let results: QueryResult<DbItem<T>>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n items.push(...results.items);\n if (!results.result) {\n return items;\n }\n previousResult = results.result;\n }\n return items;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AA8BA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,MAAUC,MAAV,IAA2D;EACrE,MAAM;IAAEC,MAAF;IAAUC,QAAV;IAAoBC,YAApB;IAAkCC;EAAlC,IAA8CJ,MAApD;EACA,IAAIK,MAAJ;EACA;AACJ;AACA;AACA;;EACI,IAAI,CAACH,QAAL,EAAe;IACXG,MAAM,GAAG,MAAMJ,MAAM,CAACF,KAAP,CAAaI,YAAb,EAA2BC,OAA3B,CAAf;EACH,CAFD,MAEO,IAAI,OAAOF,QAAQ,CAACI,IAAhB,KAAyB,UAA7B,EAAyC;IAC5C;AACR;AACA;AACA;AACA;IACQD,MAAM,GAAG,MAAMH,QAAQ,CAACI,IAAT,EAAf;;IACA,IAAID,MAAM,KAAK,KAAf,EAAsB;MAClB,OAAO;QACHA,MAAM,EAAE,IADL;QAEHE,KAAK,EAAE;MAFJ,CAAP;IAIH;EACJ,CAbM,MAaA;IACH;AACR;AACA;AACA;AACA;IACQ,OAAO;MACHF,MAAM,EAAE,IADL;MAEHE,KAAK,EAAE;IAFJ,CAAP;EAIH;EACD;AACJ;AACA;;;EACI,IAAI,CAACF,MAAD,IAAW,CAACA,MAAM,CAACG,KAAnB,IAA4B,CAACC,KAAK,CAACC,OAAN,CAAcL,MAAM,CAACG,KAArB,CAAjC,EAA8D;IAC1D,MAAM,IAAIG,cAAJ,CACF,sDADE,EAEF,aAFE,EAGF;MACIR,YADJ;MAEIC;IAFJ,CAHE,CAAN;EAQH;;EACD,OAAO;IACHC,MADG;IAEHE,KAAK,EAAEF,MAAM,CAACG;EAFX,CAAP;AAIH,CAlDD;AAmDA;AACA;AACA;;;AACO,MAAMI,QAAQ,GAAG,MAAUZ,MAAV,IAAgE;EACpF,MAAM;IAAEO;EAAF,IAAY,MAAMR,KAAK,6DACtBC,MADsB;IAEzBI,OAAO,8DACCJ,MAAM,CAACI,OAAP,IAAkB,EADnB;MAEHS,KAAK,EAAE;IAFJ;EAFkB,GAA7B;EAOA,MAAMC,IAAI,GAAGP,KAAK,CAACQ,KAAN,EAAb;EACA,OAAOD,IAAI,GAAGA,IAAH,GAAU,IAArB;AACH,CAVM;AAWP;AACA;AACA;;;;;AACO,MAAME,QAAQ,GAAG,MAAUhB,MAAV,IAA2D;EAC/E,MAAMO,KAAkB,GAAG,EAA3B;EACA,IAAIU,OAAJ;EACA,IAAIC,cAAmB,GAAGC,SAA1B;;EACA,OAAQF,OAAO,GAAG,MAAMlB,KAAK,6DAAMC,MAAN;IAAcE,QAAQ,EAAEgB;EAAxB,GAA7B,EAAyE;IACrEX,KAAK,CAACa,IAAN,CAAW,GAAGH,OAAO,CAACV,KAAtB;;IACA,IAAI,CAACU,OAAO,CAACZ,MAAb,EAAqB;MACjB,OAAOE,KAAP;IACH;;IACDW,cAAc,GAAGD,OAAO,CAACZ,MAAzB;EACH;;EACD,OAAOE,KAAP;AACH,CAZM"}
1
+ {"version":3,"file":"utils/query.js","sources":["../../src/utils/query.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Entity, EntityQueryOptions } from \"~/toolbox.js\";\nimport { cleanupItem, cleanupItems } from \"~/utils/cleanup.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface QueryAllParams {\n entity: Entity<any>;\n partitionKey: string;\n options?: EntityQueryOptions;\n}\n\nexport interface QueryOneParams extends QueryAllParams {\n options?: Omit<EntityQueryOptions, \"limit\">;\n}\n\nexport interface QueryParams extends QueryAllParams {\n previous?: any;\n}\n\nexport interface QueryResult<T> {\n result: any | null;\n items: T[];\n}\n\n/**\n * Will run query only once. Pass the previous to run the query again to fetch new data.\n * It returns the result and the items it found.\n * Result is required to fetch the items that were not fetched in the previous run.\n */\nconst query = async <T>(params: QueryParams): Promise<QueryResult<T>> => {\n const { entity, previous, partitionKey, options } = params;\n let result;\n /**\n * In case there is no previous result we must make a new query.\n * This is the first query on the given partition key.\n */\n if (!previous) {\n // @ts-expect-error\n result = await entity.query(partitionKey, options);\n } else if (typeof previous.next === \"function\") {\n /**\n * In case we have a previous result and it has a next method, we run it.\n * In case result of the next method is false, it means it has nothing else to read\n * and we return a null to keep the query from repeating.\n */\n result = await previous.next();\n if (result === false) {\n return {\n result: null,\n items: []\n };\n }\n } else {\n /**\n * This could probably never happen but keep it here just in case to break the query loop.\n * Basically, either previous does not exist or it exists and it does not have the next method\n * and at that point a result returned will be null and loop should not start again.\n */\n return {\n result: null,\n items: []\n };\n }\n /**\n * We expect the result to contain an Items array and if not, something went wrong, very wrong.\n */\n if (!result || !result.Items || !Array.isArray(result.Items)) {\n throw new WebinyError(\n \"Error when querying for content entries - no result.\",\n \"QUERY_ERROR\",\n {\n partitionKey,\n options\n }\n );\n }\n return {\n result,\n items: result.Items\n };\n};\n/**\n * Will run the query to fetch the first possible item from the database.\n */\nexport const queryOne = async <T>(params: QueryOneParams): Promise<T | null> => {\n const { items } = await query<T>({\n ...params,\n options: {\n ...(params.options || {}),\n limit: 1\n }\n });\n const item = items.shift();\n return item ? item : null;\n};\n\nexport const queryOneClean = async <T>(params: QueryOneParams): Promise<T | null> => {\n const result = await queryOne<T>(params);\n if (!result) {\n return null;\n }\n return cleanupItem(params.entity, result);\n};\n/**\n * Will run the query to fetch the results no matter how many iterations it needs to go through.\n */\nexport const queryAll = async <T>(params: QueryAllParams): Promise<T[]> => {\n const items: T[] = [];\n let results: QueryResult<T>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n items.push(...results.items);\n if (!results.result) {\n return items;\n }\n previousResult = results.result;\n }\n return items;\n};\n\nexport const queryAllClean = async <T>(params: QueryAllParams): Promise<T[]> => {\n const results = await queryAll<T>(params);\n return cleanupItems(params.entity, results);\n};\n\nexport interface IQueryPageResponse<T> {\n items: T[];\n lastEvaluatedKey: GenericRecord;\n}\n\nexport const queryPerPage = async <T>(params: QueryAllParams): Promise<IQueryPageResponse<T>> => {\n const result = await query<T>({\n ...params,\n options: {\n ...params.options,\n limit: params.options?.limit || 50\n }\n });\n\n return {\n items: result.items,\n lastEvaluatedKey: result.result?.LastEvaluatedKey\n };\n};\n\nexport const queryPerPageClean = async <T>(\n params: QueryAllParams\n): Promise<IQueryPageResponse<T>> => {\n const result = await queryPerPage<T>(params);\n return {\n items: cleanupItems<T>(params.entity, result.items),\n lastEvaluatedKey: result.lastEvaluatedKey\n };\n};\n\n/**\n * Will run the query to fetch the results no matter how many iterations it needs to go through.\n * Results of each iteration will be passed to the provided callback\n */\nexport const queryAllWithCallback = async <T>(\n params: QueryAllParams,\n callback: (items: T[]) => Promise<void>\n): Promise<void> => {\n let results: QueryResult<T>;\n let previousResult: any = undefined;\n while ((results = await query({ ...params, previous: previousResult }))) {\n if (!results.result) {\n break;\n }\n await callback(results.items);\n previousResult = results.result;\n }\n};\n"],"names":["query","params","entity","previous","partitionKey","options","result","Array","WebinyError","queryOne","items","item","queryOneClean","cleanupItem","queryAll","results","previousResult","queryAllClean","cleanupItems","queryPerPage","queryPerPageClean","queryAllWithCallback","callback"],"mappings":";;AA6BA,MAAMA,QAAQ,OAAUC;IACpB,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,OAAO,EAAE,GAAGJ;IACpD,IAAIK;IAKJ,IAAKH,UAGE,IAAI,AAAyB,cAAzB,OAAOA,SAAS,IAAI,EAmB3B,OAAO;QACH,QAAQ;QACR,OAAO,EAAE;IACb;SAtB4C;QAM5CG,SAAS,MAAMH,SAAS,IAAI;QAC5B,IAAIG,AAAW,UAAXA,QACA,OAAO;YACH,QAAQ;YACR,OAAO,EAAE;QACb;IAER;SAdIA,SAAS,MAAMJ,OAAO,KAAK,CAACE,cAAcC;IA4B9C,IAAI,CAACC,UAAU,CAACA,OAAO,KAAK,IAAI,CAACC,MAAM,OAAO,CAACD,OAAO,KAAK,GACvD,MAAM,IAAIE,MACN,wDACA,eACA;QACIJ;QACAC;IACJ;IAGR,OAAO;QACHC;QACA,OAAOA,OAAO,KAAK;IACvB;AACJ;AAIO,MAAMG,WAAW,OAAUR;IAC9B,MAAM,EAAES,KAAK,EAAE,GAAG,MAAMV,MAAS;QAC7B,GAAGC,MAAM;QACT,SAAS;YACL,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YACxB,OAAO;QACX;IACJ;IACA,MAAMU,OAAOD,MAAM,KAAK;IACxB,OAAOC,OAAOA,OAAO;AACzB;AAEO,MAAMC,gBAAgB,OAAUX;IACnC,MAAMK,SAAS,MAAMG,SAAYR;IACjC,IAAI,CAACK,QACD,OAAO;IAEX,OAAOO,YAAYZ,OAAO,MAAM,EAAEK;AACtC;AAIO,MAAMQ,WAAW,OAAUb;IAC9B,MAAMS,QAAa,EAAE;IACrB,IAAIK;IACJ,IAAIC;IACJ,MAAQD,UAAU,MAAMf,MAAM;QAAE,GAAGC,MAAM;QAAE,UAAUe;IAAe,GAAK;QACrEN,MAAM,IAAI,IAAIK,QAAQ,KAAK;QAC3B,IAAI,CAACA,QAAQ,MAAM,EACf;QAEJC,iBAAiBD,QAAQ,MAAM;IACnC;IACA,OAAOL;AACX;AAEO,MAAMO,gBAAgB,OAAUhB;IACnC,MAAMc,UAAU,MAAMD,SAAYb;IAClC,OAAOiB,aAAajB,OAAO,MAAM,EAAEc;AACvC;AAOO,MAAMI,eAAe,OAAUlB;IAClC,MAAMK,SAAS,MAAMN,MAAS;QAC1B,GAAGC,MAAM;QACT,SAAS;YACL,GAAGA,OAAO,OAAO;YACjB,OAAOA,OAAO,OAAO,EAAE,SAAS;QACpC;IACJ;IAEA,OAAO;QACH,OAAOK,OAAO,KAAK;QACnB,kBAAkBA,OAAO,MAAM,EAAE;IACrC;AACJ;AAEO,MAAMc,oBAAoB,OAC7BnB;IAEA,MAAMK,SAAS,MAAMa,aAAgBlB;IACrC,OAAO;QACH,OAAOiB,aAAgBjB,OAAO,MAAM,EAAEK,OAAO,KAAK;QAClD,kBAAkBA,OAAO,gBAAgB;IAC7C;AACJ;AAMO,MAAMe,uBAAuB,OAChCpB,QACAqB;IAEA,IAAIP;IACJ,IAAIC;IACJ,MAAQD,UAAU,MAAMf,MAAM;QAAE,GAAGC,MAAM;QAAE,UAAUe;IAAe,GAAK;QACrE,IAAI,CAACD,QAAQ,MAAM,EACf;QAEJ,MAAMO,SAASP,QAAQ,KAAK;QAC5BC,iBAAiBD,QAAQ,MAAM;IACnC;AACJ"}
@@ -0,0 +1,38 @@
1
+ import type { ScanInput, ScanOutput } from "@webiny/aws-sdk/client-dynamodb/index.js";
2
+ import type { Entity, ScanOptions, TableDef } from "../toolbox.js";
3
+ import type { ExecuteWithRetryOptions } from "@webiny/utils";
4
+ export type { ScanOptions, ScanInput, ScanOutput };
5
+ export interface BaseScanParams {
6
+ options?: ScanOptions;
7
+ params?: Partial<ScanInput>;
8
+ }
9
+ export interface ScanWithTable extends BaseScanParams {
10
+ table: TableDef;
11
+ entity?: never;
12
+ }
13
+ export interface ScanWithEntity extends BaseScanParams {
14
+ entity: Entity;
15
+ table?: never;
16
+ }
17
+ export type ScanParams = ScanWithTable | ScanWithEntity;
18
+ export interface ScanResponse<T = any> {
19
+ items: T[];
20
+ count?: number;
21
+ scannedCount?: number;
22
+ lastEvaluatedKey?: ScanOutput["LastEvaluatedKey"];
23
+ next?: () => Promise<ScanResponse<T>>;
24
+ requestId: string;
25
+ error: any;
26
+ }
27
+ export type ScanDbItem<T> = T & {
28
+ PK: string;
29
+ SK: string;
30
+ GSI1_PK: string;
31
+ GSI1_SK: string;
32
+ TYPE: string;
33
+ };
34
+ export declare const scan: <T>(params: ScanParams) => Promise<ScanResponse<T>>;
35
+ interface ScanWithCallbackOptions {
36
+ retry?: true | ExecuteWithRetryOptions;
37
+ }
38
+ export declare const scanWithCallback: <T>(params: ScanParams, callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>, options?: ScanWithCallbackOptions) => Promise<void>;
package/utils/scan.js ADDED
@@ -0,0 +1,56 @@
1
+ import { executeWithRetry } from "@webiny/utils";
2
+ const createNext = (result)=>{
3
+ if (!result?.LastEvaluatedKey || !result.next) return;
4
+ return async ()=>{
5
+ const response = await result.next();
6
+ return convertResult(response);
7
+ };
8
+ };
9
+ const convertResult = (result)=>({
10
+ items: result.Items || [],
11
+ count: result.Count,
12
+ scannedCount: result.ScannedCount,
13
+ lastEvaluatedKey: result.LastEvaluatedKey || void 0,
14
+ next: createNext(result),
15
+ error: result.error,
16
+ requestId: result.$response?.requestId || ""
17
+ });
18
+ const scan = async (params)=>{
19
+ const { options } = params;
20
+ const table = params.table ? params.table : params.entity.table;
21
+ if (!table) throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);
22
+ const result = await table.scan({
23
+ ...options,
24
+ execute: true
25
+ }, params.params);
26
+ return convertResult(result);
27
+ };
28
+ const scanWithCallback = async (params, callback, options)=>{
29
+ const usingRetry = Boolean(options?.retry);
30
+ const retryOptions = options?.retry === true ? {} : options?.retry;
31
+ const executeScan = ()=>scan(params);
32
+ const getInitialResult = ()=>{
33
+ if (usingRetry) return executeWithRetry(executeScan, retryOptions);
34
+ return executeScan();
35
+ };
36
+ let result = await getInitialResult();
37
+ if (!result.items?.length && !result.lastEvaluatedKey) return;
38
+ const callbackResult = await callback(result);
39
+ const mustBreak = false === callbackResult;
40
+ if (mustBreak) return;
41
+ while(result.next){
42
+ const executeNext = ()=>result.next();
43
+ const getNextResult = ()=>{
44
+ if (usingRetry) return executeWithRetry(executeNext, retryOptions);
45
+ return executeNext();
46
+ };
47
+ result = await getNextResult();
48
+ const callbackResult = await callback(result);
49
+ const mustBreak = false === callbackResult;
50
+ if (mustBreak) break;
51
+ if (!result.next) return;
52
+ }
53
+ };
54
+ export { scan, scanWithCallback };
55
+
56
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/scan.js","sources":["../../src/utils/scan.ts"],"sourcesContent":["import type { ScanInput, ScanOutput } from \"@webiny/aws-sdk/client-dynamodb/index.js\";\nimport type { Entity, ScanOptions, TableDef } from \"~/toolbox.js\";\nimport type { ExecuteWithRetryOptions } from \"@webiny/utils\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nexport type { ScanOptions, ScanInput, ScanOutput };\n\nexport interface BaseScanParams {\n options?: ScanOptions;\n params?: Partial<ScanInput>;\n}\n\nexport interface ScanWithTable extends BaseScanParams {\n table: TableDef;\n entity?: never;\n}\n\nexport interface ScanWithEntity extends BaseScanParams {\n entity: Entity;\n table?: never;\n}\n\nexport type ScanParams = ScanWithTable | ScanWithEntity;\n\nexport interface ScanResponse<T = any> {\n items: T[];\n count?: number;\n scannedCount?: number;\n lastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<ScanResponse<T>>;\n requestId: string;\n error: any;\n}\n\ninterface DdbScanResult<T> {\n Items?: T[];\n Count?: number;\n ScannedCount?: number;\n LastEvaluatedKey?: ScanOutput[\"LastEvaluatedKey\"];\n next?: () => Promise<DdbScanResult<T>>;\n error?: any;\n $response?: {\n requestId: string;\n };\n}\n\ntype NextCb<T> = () => Promise<ScanResponse<T>>;\n\nconst createNext = <T>(result: DdbScanResult<T>): NextCb<T> | undefined => {\n if (!result?.LastEvaluatedKey || !result.next) {\n return undefined;\n }\n return async () => {\n const response = await result!.next!();\n return convertResult(response);\n };\n};\n\nconst convertResult = <T>(result: DdbScanResult<T>): ScanResponse<T> => {\n return {\n items: result.Items || [],\n count: result.Count,\n scannedCount: result.ScannedCount,\n lastEvaluatedKey: result.LastEvaluatedKey || undefined,\n next: createNext<T>(result),\n error: result.error,\n requestId: result.$response?.requestId || \"\"\n };\n};\n\nexport type ScanDbItem<T> = T & {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n TYPE: string;\n};\n\nexport const scan = async <T>(params: ScanParams): Promise<ScanResponse<T>> => {\n const { options } = params;\n\n const table = params.table ? params.table : params.entity.table;\n if (!table) {\n throw new Error(`Missing table for scan: ${JSON.stringify(options)}`);\n }\n\n const result = await table.scan(\n {\n ...options,\n execute: true\n },\n params.params\n );\n\n return convertResult(result) as ScanResponse<T>;\n};\n\ninterface ScanWithCallbackOptions {\n retry?: true | ExecuteWithRetryOptions;\n}\n\nexport const scanWithCallback = async <T>(\n params: ScanParams,\n callback: (result: ScanResponse<ScanDbItem<T>>) => Promise<void | boolean>,\n options?: ScanWithCallbackOptions\n): Promise<void> => {\n // For backwards compatibility, we still allow for executing the scan without retries.\n const usingRetry = Boolean(options?.retry);\n const retryOptions = options?.retry === true ? {} : options?.retry;\n\n const executeScan = () => scan<ScanDbItem<T>>(params);\n const getInitialResult = () => {\n if (usingRetry) {\n return executeWithRetry(executeScan, retryOptions);\n }\n return executeScan();\n };\n\n let result = await getInitialResult();\n\n if (!result.items?.length && !result.lastEvaluatedKey) {\n return;\n }\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n return;\n }\n\n while (result.next) {\n const executeNext = () => result.next!();\n const getNextResult = () => {\n if (usingRetry) {\n return executeWithRetry(executeNext, retryOptions);\n }\n return executeNext();\n };\n\n result = await getNextResult();\n\n // If the result of the callback was `false`, that means the\n // user's intention was to stop further table scanning.\n const callbackResult = await callback(result);\n const mustBreak = callbackResult === false;\n if (mustBreak) {\n break;\n }\n\n if (!result.next) {\n return;\n }\n }\n};\n"],"names":["createNext","result","response","convertResult","undefined","scan","params","options","table","Error","JSON","scanWithCallback","callback","usingRetry","Boolean","retryOptions","executeScan","getInitialResult","executeWithRetry","callbackResult","mustBreak","executeNext","getNextResult"],"mappings":";AAgDA,MAAMA,aAAa,CAAIC;IACnB,IAAI,CAACA,QAAQ,oBAAoB,CAACA,OAAO,IAAI,EACzC;IAEJ,OAAO;QACH,MAAMC,WAAW,MAAMD,OAAQ,IAAI;QACnC,OAAOE,cAAcD;IACzB;AACJ;AAEA,MAAMC,gBAAgB,CAAIF,SACf;QACH,OAAOA,OAAO,KAAK,IAAI,EAAE;QACzB,OAAOA,OAAO,KAAK;QACnB,cAAcA,OAAO,YAAY;QACjC,kBAAkBA,OAAO,gBAAgB,IAAIG;QAC7C,MAAMJ,WAAcC;QACpB,OAAOA,OAAO,KAAK;QACnB,WAAWA,OAAO,SAAS,EAAE,aAAa;IAC9C;AAWG,MAAMI,OAAO,OAAUC;IAC1B,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAME,QAAQF,OAAO,KAAK,GAAGA,OAAO,KAAK,GAAGA,OAAO,MAAM,CAAC,KAAK;IAC/D,IAAI,CAACE,OACD,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAEC,KAAK,SAAS,CAACH,UAAU;IAGxE,MAAMN,SAAS,MAAMO,MAAM,IAAI,CAC3B;QACI,GAAGD,OAAO;QACV,SAAS;IACb,GACAD,OAAO,MAAM;IAGjB,OAAOH,cAAcF;AACzB;AAMO,MAAMU,mBAAmB,OAC5BL,QACAM,UACAL;IAGA,MAAMM,aAAaC,QAAQP,SAAS;IACpC,MAAMQ,eAAeR,SAAS,UAAU,OAAO,CAAC,IAAIA,SAAS;IAE7D,MAAMS,cAAc,IAAMX,KAAoBC;IAC9C,MAAMW,mBAAmB;QACrB,IAAIJ,YACA,OAAOK,iBAAiBF,aAAaD;QAEzC,OAAOC;IACX;IAEA,IAAIf,SAAS,MAAMgB;IAEnB,IAAI,CAAChB,OAAO,KAAK,EAAE,UAAU,CAACA,OAAO,gBAAgB,EACjD;IAKJ,MAAMkB,iBAAiB,MAAMP,SAASX;IACtC,MAAMmB,YAAYD,AAAmB,UAAnBA;IAClB,IAAIC,WACA;IAGJ,MAAOnB,OAAO,IAAI,CAAE;QAChB,MAAMoB,cAAc,IAAMpB,OAAO,IAAI;QACrC,MAAMqB,gBAAgB;YAClB,IAAIT,YACA,OAAOK,iBAAiBG,aAAaN;YAEzC,OAAOM;QACX;QAEApB,SAAS,MAAMqB;QAIf,MAAMH,iBAAiB,MAAMP,SAASX;QACtC,MAAMmB,YAAYD,AAAmB,UAAnBA;QAClB,IAAIC,WACA;QAGJ,IAAI,CAACnB,OAAO,IAAI,EACZ;IAER;AACJ"}
package/utils/sort.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FieldPlugin } from "../plugins/definitions/FieldPlugin";
1
+ import type { FieldPlugin } from "../plugins/definitions/FieldPlugin.js";
2
2
  interface Params<T> {
3
3
  /**
4
4
  * The items we are sorting.
package/utils/sort.js CHANGED
@@ -1,91 +1,45 @@
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.sortItems = sortItems;
9
-
10
- var _orderBy = _interopRequireDefault(require("lodash/orderBy"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- const extractSort = (sortBy, fields) => {
15
- const result = sortBy.split("_");
16
-
17
- if (result.length !== 2) {
18
- throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
19
- sortBy
1
+ import orderBy from "lodash/orderBy.js";
2
+ import error from "@webiny/error";
3
+ const extractSort = (sortBy, fields)=>{
4
+ const result = sortBy.split("_");
5
+ if (2 !== result.length) throw new error("Problem in determining the sorting for the entry items.", "SORT_ERROR", {
6
+ sortBy
20
7
  });
21
- }
22
-
23
- const [field, order] = result;
24
-
25
- if (!field) {
26
- throw new _error.default("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
27
- field,
28
- order,
29
- fields
8
+ const [field, order] = result;
9
+ if (!field) throw new error("Sorting field does not exist.", "SORTING_FIELD_ERROR", {
10
+ field,
11
+ order,
12
+ fields
30
13
  });
31
- }
32
-
33
- const fieldPlugin = fields.find(f => f.getField() === field);
34
- const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
35
-
36
- if (isSortable === false) {
37
- throw new _error.default(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
38
- fields,
39
- field
14
+ const fieldPlugin = fields.find((f)=>f.getField() === field);
15
+ const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;
16
+ if (false === isSortable) throw new error(`Cannot sort by given field: "${field}".`, "UNSUPPORTED_SORT_ERROR", {
17
+ fields,
18
+ field
40
19
  });
41
- }
42
-
43
- return {
44
- field,
45
- reverse: order.toUpperCase() === "DESC"
46
- };
20
+ return {
21
+ field,
22
+ reverse: "DESC" === order.toUpperCase()
23
+ };
47
24
  };
48
-
49
25
  function sortItems(params) {
50
- const {
51
- items,
52
- sort: initialSort = [],
53
- fields = []
54
- } = params;
55
- /**
56
- * Skip sorting if nothing was passed to sort by or nothing to sort.
57
- */
58
-
59
- if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {
60
- return items;
61
- }
62
-
63
- const info = {
64
- sorters: [],
65
- orders: []
66
- };
67
-
68
- for (const sort of initialSort) {
69
- /**
70
- * Possibly empty array item was passed.
71
- */
72
- if (!sort) {
73
- continue;
26
+ const { items, sort: initialSort = [], fields = [] } = params;
27
+ if (items.length <= 1 || false === Array.isArray(initialSort) || 0 === initialSort.length) return items;
28
+ const info = {
29
+ sorters: [],
30
+ orders: []
31
+ };
32
+ for (const sort of initialSort){
33
+ if (!sort) continue;
34
+ const { field, reverse } = extractSort(sort, fields);
35
+ const fieldPlugin = fields.find((f)=>f.getField() === field);
36
+ const path = fieldPlugin ? fieldPlugin.getPath() : field;
37
+ info.sorters.push(path);
38
+ info.orders.push(true === reverse ? "desc" : "asc");
74
39
  }
40
+ if (0 === info.sorters.length) return items;
41
+ return orderBy(items, info.sorters, info.orders);
42
+ }
43
+ export { sortItems };
75
44
 
76
- const {
77
- field,
78
- reverse
79
- } = extractSort(sort, fields);
80
- const fieldPlugin = fields.find(f => f.getField() === field);
81
- const path = fieldPlugin ? fieldPlugin.getPath() : field;
82
- info.sorters.push(path);
83
- info.orders.push(reverse === true ? "desc" : "asc");
84
- }
85
-
86
- if (info.sorters.length === 0) {
87
- return items;
88
- }
89
-
90
- return (0, _orderBy.default)(items, info.sorters, info.orders);
91
- }
45
+ //# sourceMappingURL=sort.js.map
package/utils/sort.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["extractSort","sortBy","fields","result","split","length","WebinyError","field","order","fieldPlugin","find","f","getField","isSortable","reverse","toUpperCase","sortItems","params","items","sort","initialSort","Array","isArray","info","sorters","orders","path","getPath","push","lodashOrderBy"],"sources":["sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy\";\nimport WebinyError from \"@webiny/error\";\nimport { FieldPlugin } from \"~/plugins/definitions/FieldPlugin\";\n\ninterface Info {\n sorters: string[];\n orders: (boolean | \"asc\" | \"desc\")[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort?: string[];\n /**\n * Fields we can sort by.\n */\n fields?: FieldPlugin[];\n}\n\nexport function sortItems<T = any>(params: Params<T>): T[] {\n const { items, sort: initialSort = [], fields = [] } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n}\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAaA,MAAMA,WAAW,GAAG,CAACC,MAAD,EAAiBC,MAAjB,KAAqD;EACrE,MAAMC,MAAM,GAAGF,MAAM,CAACG,KAAP,CAAa,GAAb,CAAf;;EACA,IAAID,MAAM,CAACE,MAAP,KAAkB,CAAtB,EAAyB;IACrB,MAAM,IAAIC,cAAJ,CACF,yDADE,EAEF,YAFE,EAGF;MACIL;IADJ,CAHE,CAAN;EAOH;;EACD,MAAM,CAACM,KAAD,EAAQC,KAAR,IAAiBL,MAAvB;;EAEA,IAAI,CAACI,KAAL,EAAY;IACR,MAAM,IAAID,cAAJ,CAAgB,+BAAhB,EAAiD,qBAAjD,EAAwE;MAC1EC,KAD0E;MAE1EC,KAF0E;MAG1EN;IAH0E,CAAxE,CAAN;EAKH;;EACD,MAAMO,WAAW,GAAGP,MAAM,CAACQ,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACC,QAAF,OAAiBL,KAAlC,CAApB;EACA,MAAMM,UAAU,GAAGJ,WAAW,GAAGA,WAAW,CAACI,UAAZ,EAAH,GAA8B,IAA5D;;EACA,IAAIA,UAAU,KAAK,KAAnB,EAA0B;IACtB,MAAM,IAAIP,cAAJ,CAAiB,gCAA+BC,KAAM,IAAtD,EAA2D,wBAA3D,EAAqF;MACvFL,MADuF;MAEvFK;IAFuF,CAArF,CAAN;EAIH;;EAED,OAAO;IACHA,KADG;IAEHO,OAAO,EAAEN,KAAK,CAACO,WAAN,OAAwB;EAF9B,CAAP;AAIH,CAjCD;;AAkDO,SAASC,SAAT,CAA4BC,MAA5B,EAAoD;EACvD,MAAM;IAAEC,KAAF;IAASC,IAAI,EAAEC,WAAW,GAAG,EAA7B;IAAiClB,MAAM,GAAG;EAA1C,IAAiDe,MAAvD;EACA;AACJ;AACA;;EACI,IAAIC,KAAK,CAACb,MAAN,IAAgB,CAAhB,IAAqBgB,KAAK,CAACC,OAAN,CAAcF,WAAd,MAA+B,KAApD,IAA6DA,WAAW,CAACf,MAAZ,KAAuB,CAAxF,EAA2F;IACvF,OAAOa,KAAP;EACH;;EAED,MAAMK,IAAU,GAAG;IACfC,OAAO,EAAE,EADM;IAEfC,MAAM,EAAE;EAFO,CAAnB;;EAKA,KAAK,MAAMN,IAAX,IAAmBC,WAAnB,EAAgC;IAC5B;AACR;AACA;IACQ,IAAI,CAACD,IAAL,EAAW;MACP;IACH;;IACD,MAAM;MAAEZ,KAAF;MAASO;IAAT,IAAqBd,WAAW,CAACmB,IAAD,EAAOjB,MAAP,CAAtC;IACA,MAAMO,WAAW,GAAGP,MAAM,CAACQ,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACC,QAAF,OAAiBL,KAAlC,CAApB;IACA,MAAMmB,IAAI,GAAGjB,WAAW,GAAGA,WAAW,CAACkB,OAAZ,EAAH,GAA2BpB,KAAnD;IAEAgB,IAAI,CAACC,OAAL,CAAaI,IAAb,CAAkBF,IAAlB;IACAH,IAAI,CAACE,MAAL,CAAYG,IAAZ,CAAiBd,OAAO,KAAK,IAAZ,GAAmB,MAAnB,GAA4B,KAA7C;EACH;;EAED,IAAIS,IAAI,CAACC,OAAL,CAAanB,MAAb,KAAwB,CAA5B,EAA+B;IAC3B,OAAOa,KAAP;EACH;;EAED,OAAO,IAAAW,gBAAA,EAAcX,KAAd,EAAqBK,IAAI,CAACC,OAA1B,EAAmCD,IAAI,CAACE,MAAxC,CAAP;AACH"}
1
+ {"version":3,"file":"utils/sort.js","sources":["../../src/utils/sort.ts"],"sourcesContent":["import lodashOrderBy from \"lodash/orderBy.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\ninterface Info {\n sorters: string[];\n orders: (boolean | \"asc\" | \"desc\")[];\n}\n\ninterface Response {\n reverse: boolean;\n field: string;\n}\n\nconst extractSort = (sortBy: string, fields: FieldPlugin[]): Response => {\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [field, order] = result;\n\n if (!field) {\n throw new WebinyError(\"Sorting field does not exist.\", \"SORTING_FIELD_ERROR\", {\n field,\n order,\n fields\n });\n }\n const fieldPlugin = fields.find(f => f.getField() === field);\n const isSortable = fieldPlugin ? fieldPlugin.isSortable() : true;\n if (isSortable === false) {\n throw new WebinyError(`Cannot sort by given field: \"${field}\".`, \"UNSUPPORTED_SORT_ERROR\", {\n fields,\n field\n });\n }\n\n return {\n field,\n reverse: order.toUpperCase() === \"DESC\"\n };\n};\n\ninterface Params<T> {\n /**\n * The items we are sorting.\n */\n items: T[];\n /**\n * Sort options. For example: [\"id_ASC\"]\n */\n sort?: string[];\n /**\n * Fields we can sort by.\n */\n fields?: FieldPlugin[];\n}\n\nexport function sortItems<T = any>(params: Params<T>): T[] {\n const { items, sort: initialSort = [], fields = [] } = params;\n /**\n * Skip sorting if nothing was passed to sort by or nothing to sort.\n */\n if (items.length <= 1 || Array.isArray(initialSort) === false || initialSort.length === 0) {\n return items;\n }\n\n const info: Info = {\n sorters: [],\n orders: []\n };\n\n for (const sort of initialSort) {\n /**\n * Possibly empty array item was passed.\n */\n if (!sort) {\n continue;\n }\n const { field, reverse } = extractSort(sort, fields);\n const fieldPlugin = fields.find(f => f.getField() === field);\n const path = fieldPlugin ? fieldPlugin.getPath() : field;\n\n info.sorters.push(path);\n info.orders.push(reverse === true ? \"desc\" : \"asc\");\n }\n\n if (info.sorters.length === 0) {\n return items;\n }\n\n return lodashOrderBy(items, info.sorters, info.orders);\n}\n"],"names":["extractSort","sortBy","fields","result","WebinyError","field","order","fieldPlugin","f","isSortable","sortItems","params","items","initialSort","Array","info","sort","reverse","path","lodashOrderBy"],"mappings":";;AAcA,MAAMA,cAAc,CAACC,QAAgBC;IACjC,MAAMC,SAASF,OAAO,KAAK,CAAC;IAC5B,IAAIE,AAAkB,MAAlBA,OAAO,MAAM,EACb,MAAM,IAAIC,MACN,2DACA,cACA;QACIH;IACJ;IAGR,MAAM,CAACI,OAAOC,MAAM,GAAGH;IAEvB,IAAI,CAACE,OACD,MAAM,IAAID,MAAY,iCAAiC,uBAAuB;QAC1EC;QACAC;QACAJ;IACJ;IAEJ,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;IACtD,MAAMI,aAAaF,cAAcA,YAAY,UAAU,KAAK;IAC5D,IAAIE,AAAe,UAAfA,YACA,MAAM,IAAIL,MAAY,CAAC,6BAA6B,EAAEC,MAAM,EAAE,CAAC,EAAE,0BAA0B;QACvFH;QACAG;IACJ;IAGJ,OAAO;QACHA;QACA,SAASC,AAAwB,WAAxBA,MAAM,WAAW;IAC9B;AACJ;AAiBO,SAASI,UAAmBC,MAAiB;IAChD,MAAM,EAAEC,KAAK,EAAE,MAAMC,cAAc,EAAE,EAAEX,SAAS,EAAE,EAAE,GAAGS;IAIvD,IAAIC,MAAM,MAAM,IAAI,KAAKE,AAA+B,UAA/BA,MAAM,OAAO,CAACD,gBAA0BA,AAAuB,MAAvBA,YAAY,MAAM,EAC/E,OAAOD;IAGX,MAAMG,OAAa;QACf,SAAS,EAAE;QACX,QAAQ,EAAE;IACd;IAEA,KAAK,MAAMC,QAAQH,YAAa;QAI5B,IAAI,CAACG,MACD;QAEJ,MAAM,EAAEX,KAAK,EAAEY,OAAO,EAAE,GAAGjB,YAAYgB,MAAMd;QAC7C,MAAMK,cAAcL,OAAO,IAAI,CAACM,CAAAA,IAAKA,EAAE,QAAQ,OAAOH;QACtD,MAAMa,OAAOX,cAAcA,YAAY,OAAO,KAAKF;QAEnDU,KAAK,OAAO,CAAC,IAAI,CAACG;QAClBH,KAAK,MAAM,CAAC,IAAI,CAACE,AAAY,SAAZA,UAAmB,SAAS;IACjD;IAEA,IAAIF,AAAwB,MAAxBA,KAAK,OAAO,CAAC,MAAM,EACnB,OAAOH;IAGX,OAAOO,QAAcP,OAAOG,KAAK,OAAO,EAAEA,KAAK,MAAM;AACzD"}
@@ -0,0 +1,10 @@
1
+ import type { TableConstructor } from "../../toolbox.js";
2
+ import { Table as BaseTable } from "../../toolbox.js";
3
+ import type { ITable, ITableReadBatch, ITableScanParams, ITableScanResponse, ITableWriteBatch } from "./types.js";
4
+ export declare class Table<Name extends string = string, PartitionKey extends string = string, SortKey extends string = string> implements ITable<Name, PartitionKey, SortKey> {
5
+ readonly table: BaseTable<Name, PartitionKey, SortKey>;
6
+ constructor(params: TableConstructor<Name, PartitionKey, SortKey>);
7
+ createWriter(): ITableWriteBatch;
8
+ createReader(): ITableReadBatch;
9
+ scan<T>(params: ITableScanParams): Promise<ITableScanResponse<T>>;
10
+ }
@@ -0,0 +1,28 @@
1
+ import { Table } from "../../toolbox.js";
2
+ import { createTableWriteBatch } from "./TableWriteBatch.js";
3
+ import { createTableReadBatch } from "./TableReadBatch.js";
4
+ import { scan } from "../scan.js";
5
+ class Table_Table {
6
+ constructor(params){
7
+ this.table = new Table(params);
8
+ }
9
+ createWriter() {
10
+ return createTableWriteBatch({
11
+ table: this.table
12
+ });
13
+ }
14
+ createReader() {
15
+ return createTableReadBatch({
16
+ table: this.table
17
+ });
18
+ }
19
+ async scan(params) {
20
+ return scan({
21
+ ...params,
22
+ table: this.table
23
+ });
24
+ }
25
+ }
26
+ export { Table_Table as Table };
27
+
28
+ //# sourceMappingURL=Table.js.map