@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/README.md CHANGED
@@ -1,67 +1,11 @@
1
1
  # @webiny/db-dynamodb
2
- [![](https://img.shields.io/npm/dw/webiny-data-dynamodb.svg)](https://www.npmjs.com/package/webiny-data-dynamodb)
3
- [![](https://img.shields.io/npm/v/webiny-data-dynamodb.svg)](https://www.npmjs.com/package/webiny-data-dynamodb)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
2
 
7
- A set of frequently used data-dynamodb higher order functions.
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
8
6
 
9
- For more information, please visit
10
- [the official docs](https://github.com/doitadrian/data-dynamodb).
11
-
12
- ## Install
13
- ```
14
- yarn add @webiny/db-dynamodb
15
- ```
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
16
8
 
9
+ ---
17
10
 
18
- ### Helper functions
19
- We have a number [helper](./src/utils) functions that ease the use of either dynamodb-toolbox, filtering, sorting or just creating proper response.
20
-
21
- #### [batchRead](./src/utils/batchRead.ts)
22
- Read a batch of records from the DynamoDB table.
23
-
24
- This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.getBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L313).
25
-
26
- Internally it reads records until there are no more to read and returns a list of read records.
27
-
28
- #### [batchWrite](./src/utils/batchWrite.ts)
29
- Write a batch of records to the DynamoDB table.
30
-
31
- This function accepts [table](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts) and items, an array of objects created by [Entity.putBatch()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L989).
32
- It also accepts a number which defines a number of items to be written in one request. DO NOT put that number over the official DynamoDB maximum.
33
-
34
- Internally it loops through the items received (in chunks of `maxChunks` parameter) and does not return anything.
35
-
36
-
37
- #### [cleanupItem and cleanupItems](./src/utils/cleanup.ts)
38
- Clean up records received from the DynamoDB table.
39
-
40
- This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and item to be cleaned up, in case of the cleanupItem.
41
- In case of `cleanupItems` it accepts an array of items to clean up.
42
-
43
- We use this to remove the properties that dynamodb-toolbox puts on the record automatically.
44
-
45
- #### [get](./src/utils/get.ts)
46
- Get a single record from the DynamoDB table with given keys.
47
-
48
- This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) and keys to fetch the record by.
49
-
50
- It returns either record or null. By default, [entity.get()](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts#L281) returns a object with some meta data and `Item` property, which contains the record (or null if no record).
51
-
52
- #### [queryOne and queryAll](./src/utils/query.ts)
53
- Query the DynamoDB table for record(s) by given partition key and query options.
54
-
55
- This function accepts [entity](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Entity.ts) to perform the query on, `partitionKey` to query by and [options](https://github.com/jeremydaly/dynamodb-toolbox/blob/main/src/classes/Table.ts#L65) to define the query parameters with.
56
-
57
- The `queryAll` method accepts `limit`, a number with which you can load only a certain amount of records. The `queryOne` method does not have that property.
58
-
59
- #### [filter](./src/utils/filter.ts)
60
- Filter the DynamoDB records by given where condition.
61
-
62
- This function accepts items (records) to be filtered, a definition of fields to filter by (not required by default if no field modification is required), where conditions (eg. `{published: true, date_gte: "2021-01-01"}`) and filtering plugins.
63
-
64
- #### [sort](./src/utils/sort.ts)
65
- Sort the DynamoDB records by given sort condition.
66
-
67
- This function accepts items (records) to be sorted, sort options (eg. createdBy_ASC, id_DESC, etc.) and a definitions of fields to sort by (not required by default if no field modification is required).
11
+ _This README file is automatically generated during the publish process._
@@ -0,0 +1,2 @@
1
+ export { ValueFilter, ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
2
+ export { FilterUtil } from "../../feature/FilterUtil/index.js";
@@ -0,0 +1,2 @@
1
+ export { ValueFilter, ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
2
+ export { FilterUtil } from "../../feature/FilterUtil/index.js";
@@ -0,0 +1,11 @@
1
+ import { FilterUtil as Abstraction } from "./abstractions/FilterUtil.js";
2
+ import { ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
3
+ declare class FilterUtilImpl implements Abstraction.Interface {
4
+ private readonly filterRegistry;
5
+ constructor(filterRegistry: ValueFilterRegistry.Interface);
6
+ filter<T = any>(params: Abstraction.Params<T>): T[];
7
+ }
8
+ export declare const FilterUtil: typeof FilterUtilImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions/FilterUtil.js").IFilterUtil>;
10
+ };
11
+ export {};
@@ -0,0 +1,26 @@
1
+ import { FilterUtil } from "./abstractions/FilterUtil.js";
2
+ import { ValueFilterRegistry } from "../ValueFilter/index.js";
3
+ import { createFilterCallable } from "./createFilters.js";
4
+ class FilterUtilImpl {
5
+ constructor(filterRegistry){
6
+ this.filterRegistry = filterRegistry;
7
+ }
8
+ filter(params) {
9
+ const filterFn = createFilterCallable({
10
+ filterRegistry: this.filterRegistry,
11
+ where: params.where,
12
+ fields: params.fields
13
+ });
14
+ if (!filterFn) return params.items;
15
+ return params.items.filter(filterFn);
16
+ }
17
+ }
18
+ const FilterUtil_FilterUtil = FilterUtil.createImplementation({
19
+ implementation: FilterUtilImpl,
20
+ dependencies: [
21
+ ValueFilterRegistry
22
+ ]
23
+ });
24
+ export { FilterUtil_FilterUtil as FilterUtil };
25
+
26
+ //# sourceMappingURL=FilterUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/FilterUtil/FilterUtil.js","sources":["../../../src/feature/FilterUtil/FilterUtil.ts"],"sourcesContent":["import { FilterUtil as Abstraction } from \"./abstractions/FilterUtil.js\";\nimport { ValueFilterRegistry } from \"~/feature/ValueFilter/index.js\";\nimport { createFilterCallable } from \"./createFilters.js\";\n\nclass FilterUtilImpl implements Abstraction.Interface {\n public constructor(private readonly filterRegistry: ValueFilterRegistry.Interface) {}\n\n public filter<T = any>(params: Abstraction.Params<T>): T[] {\n const filterFn = createFilterCallable({\n filterRegistry: this.filterRegistry,\n where: params.where,\n fields: params.fields\n });\n /**\n * No point in going through all the items when there are no filters to be applied.\n */\n if (!filterFn) {\n return params.items;\n }\n return params.items.filter(filterFn);\n }\n}\n\nexport const FilterUtil = Abstraction.createImplementation({\n implementation: FilterUtilImpl,\n dependencies: [ValueFilterRegistry]\n});\n"],"names":["FilterUtilImpl","filterRegistry","params","filterFn","createFilterCallable","FilterUtil","Abstraction","ValueFilterRegistry"],"mappings":";;;AAIA,MAAMA;IACF,YAAoCC,cAA6C,CAAE;aAA/CA,cAAc,GAAdA;IAAgD;IAE7E,OAAgBC,MAA6B,EAAO;QACvD,MAAMC,WAAWC,qBAAqB;YAClC,gBAAgB,IAAI,CAAC,cAAc;YACnC,OAAOF,OAAO,KAAK;YACnB,QAAQA,OAAO,MAAM;QACzB;QAIA,IAAI,CAACC,UACD,OAAOD,OAAO,KAAK;QAEvB,OAAOA,OAAO,KAAK,CAAC,MAAM,CAACC;IAC/B;AACJ;AAEO,MAAME,wBAAaC,WAAAA,oBAAgC,CAAC;IACvD,gBAAgBN;IAChB,cAAc;QAACO;KAAoB;AACvC"}
@@ -0,0 +1,17 @@
1
+ import type { FieldPlugin } from "../../../plugins/definitions/FieldPlugin.js";
2
+ export interface IFilterUtilParams<T = any> {
3
+ items: T[];
4
+ where: Record<string, any>;
5
+ /**
6
+ * An array of fields that require some special operation.
7
+ */
8
+ fields: FieldPlugin[];
9
+ }
10
+ export interface IFilterUtil {
11
+ filter<T = any>(params: IFilterUtilParams<T>): T[];
12
+ }
13
+ export declare const FilterUtil: import("@webiny/di").Abstraction<IFilterUtil>;
14
+ export declare namespace FilterUtil {
15
+ type Interface = IFilterUtil;
16
+ type Params<T = any> = IFilterUtilParams<T>;
17
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const FilterUtil = createAbstraction("Db/DynamoDB/FilterUtil");
3
+ export { FilterUtil };
4
+
5
+ //# sourceMappingURL=FilterUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/FilterUtil/abstractions/FilterUtil.js","sources":["../../../../src/feature/FilterUtil/abstractions/FilterUtil.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\n\nexport interface IFilterUtilParams<T = any> {\n items: T[];\n where: Record<string, any>;\n /**\n * An array of fields that require some special operation.\n */\n fields: FieldPlugin[];\n}\n\nexport interface IFilterUtil {\n filter<T = any>(params: IFilterUtilParams<T>): T[];\n}\n\nexport const FilterUtil = createAbstraction<IFilterUtil>(\"Db/DynamoDB/FilterUtil\");\n\nexport namespace FilterUtil {\n export type Interface = IFilterUtil;\n export type Params<T = any> = IFilterUtilParams<T>;\n}\n"],"names":["FilterUtil","createAbstraction"],"mappings":";AAgBO,MAAMA,aAAaC,kBAA+B"}
@@ -0,0 +1,22 @@
1
+ import type { FieldPlugin } from "../../plugins/definitions/FieldPlugin.js";
2
+ import type { ValueFilter, ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
3
+ type TransformValue = (value: any) => any;
4
+ interface Filter {
5
+ operation: string;
6
+ compareValue: any;
7
+ filter: ValueFilter.Interface;
8
+ transformValue?: TransformValue;
9
+ paths: string[];
10
+ negate: boolean;
11
+ }
12
+ interface CreateFiltersParams {
13
+ filterRegistry: ValueFilterRegistry.Interface;
14
+ where: Record<string, any>;
15
+ fields: FieldPlugin[];
16
+ }
17
+ export declare const createFilters: (params: CreateFiltersParams) => Filter[];
18
+ /**
19
+ * Creates a filter callable that we can send to the .filter() method of the array.
20
+ */
21
+ export declare const createFilterCallable: (params: CreateFiltersParams) => ((item: any) => boolean) | null;
22
+ export {};
@@ -0,0 +1,92 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { extractWhereArgs } from "./extractWhereArgs.js";
3
+ import * as __rspack_external_dot_prop_de53db47 from "dot-prop";
4
+ const findFilter = (registry, operation)=>{
5
+ const filter = registry.get(operation);
6
+ if (filter) return filter;
7
+ throw new WebinyError("Missing filter plugin definition.", "FILTER_PLUGIN_ERROR", {
8
+ operation
9
+ });
10
+ };
11
+ const multiSearchFieldOperations = [
12
+ "contains",
13
+ "fuzzy"
14
+ ];
15
+ const createFilters = (params)=>{
16
+ const { where, fields, filterRegistry } = params;
17
+ const keys = Object.keys(where);
18
+ if (0 === keys.length) return [];
19
+ return keys.reduce((filters, key)=>{
20
+ const compareValue = where[key];
21
+ if (void 0 === compareValue) return filters;
22
+ if (true === multiSearchFieldOperations.includes(key)) {
23
+ const data = compareValue;
24
+ let transformValue;
25
+ const paths = data.fields.map((field)=>{
26
+ const fieldPlugin = fields.find((plugin)=>plugin.getField() === field);
27
+ if (fieldPlugin) {
28
+ transformValue = (value)=>fieldPlugin.transformValue(value);
29
+ return fieldPlugin.getPath();
30
+ }
31
+ return field;
32
+ });
33
+ const filter = findFilter(filterRegistry, key);
34
+ filters.push({
35
+ operation: filter.operation,
36
+ compareValue: data.value,
37
+ filter,
38
+ transformValue,
39
+ paths,
40
+ negate: false
41
+ });
42
+ return filters;
43
+ }
44
+ const { field, operation, negate } = extractWhereArgs(key);
45
+ const filter = findFilter(filterRegistry, operation);
46
+ const fieldPlugin = fields.find((plugin)=>plugin.getField() === field);
47
+ let path = field;
48
+ let transformValue;
49
+ if (fieldPlugin) {
50
+ transformValue = (value)=>fieldPlugin.transformValue(value);
51
+ path = fieldPlugin.getPath();
52
+ }
53
+ filters.push({
54
+ operation: filter.operation,
55
+ compareValue,
56
+ filter,
57
+ transformValue,
58
+ paths: [
59
+ path
60
+ ],
61
+ negate
62
+ });
63
+ return filters;
64
+ }, []);
65
+ };
66
+ const transform = (value, transformValue)=>{
67
+ if (!transformValue) return value;
68
+ if (Array.isArray(value)) return value.map((v)=>transformValue(v));
69
+ return transformValue(value);
70
+ };
71
+ const createFilterCallable = (params)=>{
72
+ const filters = createFilters(params);
73
+ if (0 === filters.length) return null;
74
+ return (item)=>{
75
+ for (const filter of filters){
76
+ const result = filter.paths.some((path)=>{
77
+ const value = transform(__rspack_external_dot_prop_de53db47.getProperty(item, path), filter.transformValue);
78
+ const compareValue = transform(filter.compareValue, filter.transformValue);
79
+ const matched = filter.filter.matches({
80
+ value,
81
+ compareValue
82
+ });
83
+ return filter.negate ? !matched : matched;
84
+ });
85
+ if (false === result) return false;
86
+ }
87
+ return true;
88
+ };
89
+ };
90
+ export { createFilterCallable, createFilters };
91
+
92
+ //# sourceMappingURL=createFilters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/FilterUtil/createFilters.js","sources":["../../../src/feature/FilterUtil/createFilters.ts"],"sourcesContent":["import * as dotProp from \"dot-prop\";\nimport { WebinyError } from \"@webiny/error\";\nimport type { FieldPlugin } from \"~/plugins/definitions/FieldPlugin.js\";\nimport type { DynamoDbContainsFilter } from \"~/types.js\";\nimport type { ValueFilter, ValueFilterRegistry } from \"~/feature/ValueFilter/index.js\";\nimport { extractWhereArgs } from \"./extractWhereArgs.js\";\n\ntype TransformValue = (value: any) => any;\n\ninterface Filter {\n operation: string;\n compareValue: any;\n filter: ValueFilter.Interface;\n transformValue?: TransformValue;\n paths: string[];\n negate: boolean;\n}\n\ninterface CreateFiltersParams {\n filterRegistry: ValueFilterRegistry.Interface;\n where: Record<string, any>;\n fields: FieldPlugin[];\n}\n\nconst findFilter = (\n registry: ValueFilterRegistry.Interface,\n operation: string\n): ValueFilter.Interface => {\n const filter = registry.get(operation);\n if (filter) {\n return filter;\n }\n throw new WebinyError(`Missing filter plugin definition.`, \"FILTER_PLUGIN_ERROR\", {\n operation\n });\n};\n\nconst multiSearchFieldOperations = [\"contains\", \"fuzzy\"];\n\nexport const createFilters = (params: CreateFiltersParams): Filter[] => {\n const { where, fields, filterRegistry } = params;\n\n const keys = Object.keys(where);\n /**\n * Skip everything if there are no conditions to be applied.\n */\n if (keys.length === 0) {\n return [];\n }\n\n return keys.reduce((filters, key) => {\n const compareValue = where[key];\n if (compareValue === undefined) {\n return filters;\n }\n /**\n * @see DynamoDbContainsFilter\n */\n if (multiSearchFieldOperations.includes(key) === true) {\n const data: DynamoDbContainsFilter = compareValue;\n let transformValue: TransformValue | undefined = undefined;\n const paths = data.fields.map(field => {\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n if (fieldPlugin) {\n transformValue = (value: any) => {\n return fieldPlugin.transformValue(value);\n };\n return fieldPlugin.getPath();\n }\n return field;\n });\n\n const filter = findFilter(filterRegistry, key);\n filters.push({\n operation: filter.operation,\n compareValue: data.value,\n filter,\n transformValue,\n paths,\n negate: false\n });\n return filters;\n }\n\n const { field, operation, negate } = extractWhereArgs(key);\n\n const filter = findFilter(filterRegistry, operation);\n\n const fieldPlugin = fields.find(plugin => plugin.getField() === field);\n let path: string = field;\n let transformValue: TransformValue | undefined = undefined;\n if (fieldPlugin) {\n transformValue = (value: any) => {\n return fieldPlugin.transformValue(value);\n };\n path = fieldPlugin.getPath();\n }\n\n filters.push({\n operation: filter.operation,\n compareValue,\n filter,\n transformValue,\n paths: [path],\n negate\n });\n\n return filters;\n }, [] as Filter[]);\n};\n\n/**\n * Transforms the value with given transformer callable.\n */\nconst transform = (value: any, transformValue?: TransformValue): any => {\n if (!transformValue) {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(v => transformValue(v));\n }\n return transformValue(value);\n};\n\n/**\n * Creates a filter callable that we can send to the .filter() method of the array.\n */\nexport const createFilterCallable = (\n params: CreateFiltersParams\n): ((item: any) => boolean) | null => {\n const filters = createFilters(params);\n /**\n * Just return null so there are no filters to be applied.\n * Later in the code we check for null so we do not loop through the items.\n */\n if (filters.length === 0) {\n return null;\n }\n\n return (item: any) => {\n for (const filter of filters) {\n const result = filter.paths.some(path => {\n const value = transform(dotProp.getProperty(item, path), filter.transformValue);\n const compareValue = transform(filter.compareValue, filter.transformValue);\n const matched = filter.filter.matches({\n value,\n compareValue\n });\n\n return filter.negate ? !matched : matched;\n });\n if (result === false) {\n return false;\n }\n }\n return true;\n };\n};\n"],"names":["findFilter","registry","operation","filter","WebinyError","multiSearchFieldOperations","createFilters","params","where","fields","filterRegistry","keys","Object","filters","key","compareValue","undefined","data","transformValue","paths","field","fieldPlugin","plugin","value","negate","extractWhereArgs","path","transform","Array","v","createFilterCallable","item","result","dotProp","matched"],"mappings":";;;AAwBA,MAAMA,aAAa,CACfC,UACAC;IAEA,MAAMC,SAASF,SAAS,GAAG,CAACC;IAC5B,IAAIC,QACA,OAAOA;IAEX,MAAM,IAAIC,YAAY,qCAAqC,uBAAuB;QAC9EF;IACJ;AACJ;AAEA,MAAMG,6BAA6B;IAAC;IAAY;CAAQ;AAEjD,MAAMC,gBAAgB,CAACC;IAC1B,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,cAAc,EAAE,GAAGH;IAE1C,MAAMI,OAAOC,OAAO,IAAI,CAACJ;IAIzB,IAAIG,AAAgB,MAAhBA,KAAK,MAAM,EACX,OAAO,EAAE;IAGb,OAAOA,KAAK,MAAM,CAAC,CAACE,SAASC;QACzB,MAAMC,eAAeP,KAAK,CAACM,IAAI;QAC/B,IAAIC,AAAiBC,WAAjBD,cACA,OAAOF;QAKX,IAAIR,AAA6C,SAA7CA,2BAA2B,QAAQ,CAACS,MAAe;YACnD,MAAMG,OAA+BF;YACrC,IAAIG;YACJ,MAAMC,QAAQF,KAAK,MAAM,CAAC,GAAG,CAACG,CAAAA;gBAC1B,MAAMC,cAAcZ,OAAO,IAAI,CAACa,CAAAA,SAAUA,OAAO,QAAQ,OAAOF;gBAChE,IAAIC,aAAa;oBACbH,iBAAiB,CAACK,QACPF,YAAY,cAAc,CAACE;oBAEtC,OAAOF,YAAY,OAAO;gBAC9B;gBACA,OAAOD;YACX;YAEA,MAAMjB,SAASH,WAAWU,gBAAgBI;YAC1CD,QAAQ,IAAI,CAAC;gBACT,WAAWV,OAAO,SAAS;gBAC3B,cAAcc,KAAK,KAAK;gBACxBd;gBACAe;gBACAC;gBACA,QAAQ;YACZ;YACA,OAAON;QACX;QAEA,MAAM,EAAEO,KAAK,EAAElB,SAAS,EAAEsB,MAAM,EAAE,GAAGC,iBAAiBX;QAEtD,MAAMX,SAASH,WAAWU,gBAAgBR;QAE1C,MAAMmB,cAAcZ,OAAO,IAAI,CAACa,CAAAA,SAAUA,OAAO,QAAQ,OAAOF;QAChE,IAAIM,OAAeN;QACnB,IAAIF;QACJ,IAAIG,aAAa;YACbH,iBAAiB,CAACK,QACPF,YAAY,cAAc,CAACE;YAEtCG,OAAOL,YAAY,OAAO;QAC9B;QAEAR,QAAQ,IAAI,CAAC;YACT,WAAWV,OAAO,SAAS;YAC3BY;YACAZ;YACAe;YACA,OAAO;gBAACQ;aAAK;YACbF;QACJ;QAEA,OAAOX;IACX,GAAG,EAAE;AACT;AAKA,MAAMc,YAAY,CAACJ,OAAYL;IAC3B,IAAI,CAACA,gBACD,OAAOK;IAEX,IAAIK,MAAM,OAAO,CAACL,QACd,OAAOA,MAAM,GAAG,CAACM,CAAAA,IAAKX,eAAeW;IAEzC,OAAOX,eAAeK;AAC1B;AAKO,MAAMO,uBAAuB,CAChCvB;IAEA,MAAMM,UAAUP,cAAcC;IAK9B,IAAIM,AAAmB,MAAnBA,QAAQ,MAAM,EACd,OAAO;IAGX,OAAO,CAACkB;QACJ,KAAK,MAAM5B,UAAUU,QAAS;YAC1B,MAAMmB,SAAS7B,OAAO,KAAK,CAAC,IAAI,CAACuB,CAAAA;gBAC7B,MAAMH,QAAQI,UAAUM,oCAAAA,WAAmB,CAACF,MAAML,OAAOvB,OAAO,cAAc;gBAC9E,MAAMY,eAAeY,UAAUxB,OAAO,YAAY,EAAEA,OAAO,cAAc;gBACzE,MAAM+B,UAAU/B,OAAO,MAAM,CAAC,OAAO,CAAC;oBAClCoB;oBACAR;gBACJ;gBAEA,OAAOZ,OAAO,MAAM,GAAG,CAAC+B,UAAUA;YACtC;YACA,IAAIF,AAAW,UAAXA,QACA,OAAO;QAEf;QACA,OAAO;IACX;AACJ"}
@@ -0,0 +1,7 @@
1
+ interface ExtractWhereArgsResult {
2
+ field: string;
3
+ operation: string;
4
+ negate: boolean;
5
+ }
6
+ export declare const extractWhereArgs: (key: string) => ExtractWhereArgsResult;
7
+ export {};
@@ -0,0 +1,20 @@
1
+ const extractWhereArgs = (key)=>{
2
+ const result = key.split("_");
3
+ const field = result.shift();
4
+ const rawOp = 0 === result.length ? "eq" : result.join("_");
5
+ if ("not" === rawOp) return {
6
+ field,
7
+ operation: "eq",
8
+ negate: true
9
+ };
10
+ const negate = null !== rawOp.match("not_");
11
+ const operation = rawOp.replace("not_", "");
12
+ return {
13
+ field,
14
+ operation,
15
+ negate
16
+ };
17
+ };
18
+ export { extractWhereArgs };
19
+
20
+ //# sourceMappingURL=extractWhereArgs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/FilterUtil/extractWhereArgs.js","sources":["../../../src/feature/FilterUtil/extractWhereArgs.ts"],"sourcesContent":["interface ExtractWhereArgsResult {\n field: string;\n operation: string;\n negate: boolean;\n}\n\nexport const extractWhereArgs = (key: string): ExtractWhereArgsResult => {\n const result = key.split(\"_\");\n const field = result.shift() as string;\n const rawOp = result.length === 0 ? \"eq\" : result.join(\"_\");\n /**\n * When rawOp is not, it means it is equal negated so just return that.\n */\n if (rawOp === \"not\") {\n return {\n field,\n operation: \"eq\",\n negate: true\n };\n }\n const negate = rawOp.match(\"not_\") !== null;\n const operation = rawOp.replace(\"not_\", \"\");\n return {\n field,\n operation,\n negate\n };\n};\n"],"names":["extractWhereArgs","key","result","field","rawOp","negate","operation"],"mappings":"AAMO,MAAMA,mBAAmB,CAACC;IAC7B,MAAMC,SAASD,IAAI,KAAK,CAAC;IACzB,MAAME,QAAQD,OAAO,KAAK;IAC1B,MAAME,QAAQF,AAAkB,MAAlBA,OAAO,MAAM,GAAS,OAAOA,OAAO,IAAI,CAAC;IAIvD,IAAIE,AAAU,UAAVA,OACA,OAAO;QACHD;QACA,WAAW;QACX,QAAQ;IACZ;IAEJ,MAAME,SAASD,AAAwB,SAAxBA,MAAM,KAAK,CAAC;IAC3B,MAAME,YAAYF,MAAM,OAAO,CAAC,QAAQ;IACxC,OAAO;QACHD;QACAG;QACAD;IACJ;AACJ"}
@@ -0,0 +1,4 @@
1
+ export declare const FilterUtilFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { FilterUtil } from "./FilterUtil.js";
3
+ const FilterUtilFeature = createFeature({
4
+ name: "Db/DynamoDB/FilterUtilFeature",
5
+ register: (container)=>{
6
+ container.register(FilterUtil);
7
+ }
8
+ });
9
+ export { FilterUtilFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/FilterUtil/feature.js","sources":["../../../src/feature/FilterUtil/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FilterUtil } from \"./FilterUtil.js\";\n\nexport const FilterUtilFeature = createFeature({\n name: \"Db/DynamoDB/FilterUtilFeature\",\n register: container => {\n container.register(FilterUtil);\n }\n});\n"],"names":["FilterUtilFeature","createFeature","container","FilterUtil"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { FilterUtil } from "./abstractions/FilterUtil.js";
2
+ export { FilterUtilFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { FilterUtil } from "./abstractions/FilterUtil.js";
2
+ export { FilterUtilFeature } from "./feature.js";
@@ -0,0 +1,12 @@
1
+ import { ValueFilterRegistry as Abstraction } from "./abstractions/ValueFilterRegistry.js";
2
+ import { ValueFilter } from "./abstractions/ValueFilter.js";
3
+ declare class ValueFilterRegistryImpl implements Abstraction.Interface {
4
+ private readonly filters;
5
+ constructor(filters: ValueFilter.Interface[]);
6
+ get(operation: string): ValueFilter.Interface | undefined;
7
+ getAll(): ValueFilter.Interface[];
8
+ }
9
+ export declare const ValueFilterRegistry: typeof ValueFilterRegistryImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions/ValueFilterRegistry.js").IValueFilterRegistry>;
11
+ };
12
+ export {};
@@ -0,0 +1,27 @@
1
+ import { ValueFilterRegistry } from "./abstractions/ValueFilterRegistry.js";
2
+ import { ValueFilter } from "./abstractions/ValueFilter.js";
3
+ class ValueFilterRegistryImpl {
4
+ constructor(filters){
5
+ this.filters = filters;
6
+ }
7
+ get(operation) {
8
+ return this.filters.find((filter)=>filter.is(operation));
9
+ }
10
+ getAll() {
11
+ return this.filters;
12
+ }
13
+ }
14
+ const ValueFilterRegistry_ValueFilterRegistry = ValueFilterRegistry.createImplementation({
15
+ implementation: ValueFilterRegistryImpl,
16
+ dependencies: [
17
+ [
18
+ ValueFilter,
19
+ {
20
+ multiple: true
21
+ }
22
+ ]
23
+ ]
24
+ });
25
+ export { ValueFilterRegistry_ValueFilterRegistry as ValueFilterRegistry };
26
+
27
+ //# sourceMappingURL=ValueFilterRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/ValueFilter/ValueFilterRegistry.js","sources":["../../../src/feature/ValueFilter/ValueFilterRegistry.ts"],"sourcesContent":["import { ValueFilterRegistry as Abstraction } from \"./abstractions/ValueFilterRegistry.js\";\nimport { ValueFilter } from \"./abstractions/ValueFilter.js\";\n\nclass ValueFilterRegistryImpl implements Abstraction.Interface {\n public constructor(private readonly filters: ValueFilter.Interface[]) {}\n\n public get(operation: string): ValueFilter.Interface | undefined {\n return this.filters.find(filter => {\n return filter.is(operation);\n });\n }\n\n public getAll(): ValueFilter.Interface[] {\n return this.filters;\n }\n}\n\nexport const ValueFilterRegistry = Abstraction.createImplementation({\n implementation: ValueFilterRegistryImpl,\n dependencies: [[ValueFilter, { multiple: true }]]\n});\n"],"names":["ValueFilterRegistryImpl","filters","operation","filter","ValueFilterRegistry","Abstraction","ValueFilter"],"mappings":";;AAGA,MAAMA;IACF,YAAoCC,OAAgC,CAAE;aAAlCA,OAAO,GAAPA;IAAmC;IAEhE,IAAIC,SAAiB,EAAqC;QAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAACC,CAAAA,SACdA,OAAO,EAAE,CAACD;IAEzB;IAEO,SAAkC;QACrC,OAAO,IAAI,CAAC,OAAO;IACvB;AACJ;AAEO,MAAME,0CAAsBC,oBAAAA,oBAAgC,CAAC;IAChE,gBAAgBL;IAChB,cAAc;QAAC;YAACM;YAAa;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrD"}
@@ -0,0 +1,22 @@
1
+ export interface IValueFilterCanUseParams<TValue = any, TCompareValue = any> {
2
+ value: TValue;
3
+ compareValue: TCompareValue;
4
+ }
5
+ export interface IValueFilterMatchesParams<TValue = any, TCompareValue = any> {
6
+ value: TValue;
7
+ compareValue: TCompareValue;
8
+ }
9
+ export type IValueFilterMatchesResult = boolean;
10
+ export interface IValueFilter<TValue = any, TCompareValue = any> {
11
+ readonly operation: string;
12
+ is(operation: string): boolean;
13
+ canUse(params: IValueFilterCanUseParams): boolean;
14
+ matches(params: IValueFilterMatchesParams<TValue, TCompareValue>): IValueFilterMatchesResult;
15
+ }
16
+ export declare const ValueFilter: import("@webiny/di").Abstraction<IValueFilter<any, any>>;
17
+ export declare namespace ValueFilter {
18
+ type Interface<TValue = any, TCompareValue = any> = IValueFilter<TValue, TCompareValue>;
19
+ type CanUseParams = IValueFilterCanUseParams;
20
+ type MatchesParams = IValueFilterMatchesParams;
21
+ type Result = IValueFilterMatchesResult;
22
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const ValueFilter = createAbstraction("Db/DynamoDB/ValueFilter");
3
+ export { ValueFilter };
4
+
5
+ //# sourceMappingURL=ValueFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/ValueFilter/abstractions/ValueFilter.js","sources":["../../../../src/feature/ValueFilter/abstractions/ValueFilter.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IValueFilterCanUseParams<TValue = any, TCompareValue = any> {\n value: TValue;\n compareValue: TCompareValue;\n}\n\nexport interface IValueFilterMatchesParams<TValue = any, TCompareValue = any> {\n value: TValue;\n compareValue: TCompareValue;\n}\n\nexport type IValueFilterMatchesResult = boolean;\n\nexport interface IValueFilter<TValue = any, TCompareValue = any> {\n readonly operation: string;\n is(operation: string): boolean;\n canUse(params: IValueFilterCanUseParams): boolean;\n matches(params: IValueFilterMatchesParams<TValue, TCompareValue>): IValueFilterMatchesResult;\n}\n\nexport const ValueFilter = createAbstraction<IValueFilter>(\"Db/DynamoDB/ValueFilter\");\n\nexport namespace ValueFilter {\n export type Interface<TValue = any, TCompareValue = any> = IValueFilter<TValue, TCompareValue>;\n export type CanUseParams = IValueFilterCanUseParams;\n export type MatchesParams = IValueFilterMatchesParams;\n export type Result = IValueFilterMatchesResult;\n}\n"],"names":["ValueFilter","createAbstraction"],"mappings":";AAqBO,MAAMA,cAAcC,kBAAgC"}
@@ -0,0 +1,10 @@
1
+ import type { ValueFilter } from "./ValueFilter.js";
2
+ export interface IValueFilterRegistry {
3
+ get(operation: string): ValueFilter.Interface | undefined;
4
+ getAll(): ValueFilter.Interface[];
5
+ }
6
+ export declare const ValueFilterRegistry: import("@webiny/di").Abstraction<IValueFilterRegistry>;
7
+ export declare namespace ValueFilterRegistry {
8
+ type Interface = IValueFilterRegistry;
9
+ type Filter = ValueFilter.Interface;
10
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const ValueFilterRegistry = createAbstraction("Db/DynamoDB/ValueFilterRegistry");
3
+ export { ValueFilterRegistry };
4
+
5
+ //# sourceMappingURL=ValueFilterRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/ValueFilter/abstractions/ValueFilterRegistry.js","sources":["../../../../src/feature/ValueFilter/abstractions/ValueFilterRegistry.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { ValueFilter } from \"./ValueFilter.js\";\n\nexport interface IValueFilterRegistry {\n get(operation: string): ValueFilter.Interface | undefined;\n getAll(): ValueFilter.Interface[];\n}\n\nexport const ValueFilterRegistry = createAbstraction<IValueFilterRegistry>(\n \"Db/DynamoDB/ValueFilterRegistry\"\n);\n\nexport namespace ValueFilterRegistry {\n export type Interface = IValueFilterRegistry;\n export type Filter = ValueFilter.Interface;\n}\n"],"names":["ValueFilterRegistry","createAbstraction"],"mappings":";AAQO,MAAMA,sBAAsBC,kBAC/B"}
@@ -0,0 +1,4 @@
1
+ export declare const ValueFilterFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,33 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { EqFilter } from "./filters/EqFilter.js";
3
+ import { GtFilter } from "./filters/GtFilter.js";
4
+ import { GteFilter } from "./filters/GteFilter.js";
5
+ import { LtFilter } from "./filters/LtFilter.js";
6
+ import { LteFilter } from "./filters/LteFilter.js";
7
+ import { BetweenFilter } from "./filters/BetweenFilter.js";
8
+ import { InFilter } from "./filters/InFilter.js";
9
+ import { AndInFilter } from "./filters/AndInFilter.js";
10
+ import { ContainsFilter } from "./filters/ContainsFilter.js";
11
+ import { FuzzyFilter } from "./filters/FuzzyFilter.js";
12
+ import { StartsWithFilter } from "./filters/StartsWithFilter.js";
13
+ import { ValueFilterRegistry } from "./ValueFilterRegistry.js";
14
+ const ValueFilterFeature = createFeature({
15
+ name: "Db/DynamoDB/ValueFilterFeature",
16
+ register: (container)=>{
17
+ container.register(EqFilter);
18
+ container.register(GtFilter);
19
+ container.register(GteFilter);
20
+ container.register(LtFilter);
21
+ container.register(LteFilter);
22
+ container.register(BetweenFilter);
23
+ container.register(InFilter);
24
+ container.register(AndInFilter);
25
+ container.register(ContainsFilter);
26
+ container.register(FuzzyFilter);
27
+ container.register(StartsWithFilter);
28
+ container.register(ValueFilterRegistry);
29
+ }
30
+ });
31
+ export { ValueFilterFeature };
32
+
33
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/ValueFilter/feature.js","sources":["../../../src/feature/ValueFilter/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { EqFilter } from \"./filters/EqFilter.js\";\nimport { GtFilter } from \"./filters/GtFilter.js\";\nimport { GteFilter } from \"./filters/GteFilter.js\";\nimport { LtFilter } from \"./filters/LtFilter.js\";\nimport { LteFilter } from \"./filters/LteFilter.js\";\nimport { BetweenFilter } from \"./filters/BetweenFilter.js\";\nimport { InFilter } from \"./filters/InFilter.js\";\nimport { AndInFilter } from \"./filters/AndInFilter.js\";\nimport { ContainsFilter } from \"./filters/ContainsFilter.js\";\nimport { FuzzyFilter } from \"./filters/FuzzyFilter.js\";\nimport { StartsWithFilter } from \"./filters/StartsWithFilter.js\";\nimport { ValueFilterRegistry } from \"./ValueFilterRegistry.js\";\n\nexport const ValueFilterFeature = createFeature({\n name: \"Db/DynamoDB/ValueFilterFeature\",\n register: container => {\n container.register(EqFilter);\n container.register(GtFilter);\n container.register(GteFilter);\n container.register(LtFilter);\n container.register(LteFilter);\n container.register(BetweenFilter);\n container.register(InFilter);\n container.register(AndInFilter);\n container.register(ContainsFilter);\n container.register(FuzzyFilter);\n container.register(StartsWithFilter);\n container.register(ValueFilterRegistry);\n }\n});\n"],"names":["ValueFilterFeature","createFeature","container","EqFilter","GtFilter","GteFilter","LtFilter","LteFilter","BetweenFilter","InFilter","AndInFilter","ContainsFilter","FuzzyFilter","StartsWithFilter","ValueFilterRegistry"],"mappings":";;;;;;;;;;;;;AAcO,MAAMA,qBAAqBC,cAAc;IAC5C,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;IACvB;AACJ"}
@@ -0,0 +1,11 @@
1
+ import { ValueFilter } from "../abstractions/ValueFilter.js";
2
+ declare class AndInFilterImpl implements ValueFilter.Interface {
3
+ readonly operation = "and_in";
4
+ is(operation: string): boolean;
5
+ canUse(): boolean;
6
+ matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result;
7
+ }
8
+ export declare const AndInFilter: typeof AndInFilterImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../abstractions/ValueFilter.js").IValueFilter<any, any>>;
10
+ };
11
+ export {};
@@ -0,0 +1,28 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { ValueFilter } from "../abstractions/ValueFilter.js";
3
+ class AndInFilterImpl {
4
+ is(operation) {
5
+ return this.operation === operation;
6
+ }
7
+ canUse() {
8
+ return true;
9
+ }
10
+ matches({ value, compareValue }) {
11
+ if (!compareValue || false === Array.isArray(compareValue)) throw new WebinyError('The value given as "compareValue" must be an array!', "COMPARE_VALUE_ERROR", {
12
+ value,
13
+ compareValue
14
+ });
15
+ if (true === Array.isArray(value)) return compareValue.every((c)=>value.includes(c));
16
+ return compareValue.includes(value);
17
+ }
18
+ constructor(){
19
+ this.operation = "and_in";
20
+ }
21
+ }
22
+ const AndInFilter = ValueFilter.createImplementation({
23
+ implementation: AndInFilterImpl,
24
+ dependencies: []
25
+ });
26
+ export { AndInFilter };
27
+
28
+ //# sourceMappingURL=AndInFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/ValueFilter/filters/AndInFilter.js","sources":["../../../../src/feature/ValueFilter/filters/AndInFilter.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { ValueFilter } from \"../abstractions/ValueFilter.js\";\n\nclass AndInFilterImpl implements ValueFilter.Interface {\n public readonly operation = \"and_in\";\n\n public is(operation: string): boolean {\n return this.operation === operation;\n }\n\n public canUse(): boolean {\n return true;\n }\n\n public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {\n if (!compareValue || Array.isArray(compareValue) === false) {\n throw new WebinyError(\n `The value given as \"compareValue\" must be an array!`,\n \"COMPARE_VALUE_ERROR\",\n {\n value,\n compareValue\n }\n );\n }\n if (Array.isArray(value) === true) {\n return compareValue.every((c: any) => value.includes(c));\n }\n return compareValue.includes(value);\n }\n}\n\nexport const AndInFilter = ValueFilter.createImplementation({\n implementation: AndInFilterImpl,\n dependencies: []\n});\n"],"names":["AndInFilterImpl","operation","value","compareValue","Array","WebinyError","c","AndInFilter","ValueFilter"],"mappings":";;AAGA,MAAMA;IAGK,GAAGC,SAAiB,EAAW;QAClC,OAAO,IAAI,CAAC,SAAS,KAAKA;IAC9B;IAEO,SAAkB;QACrB,OAAO;IACX;IAEO,QAAQ,EAAEC,KAAK,EAAEC,YAAY,EAA6B,EAAsB;QACnF,IAAI,CAACA,gBAAgBC,AAAgC,UAAhCA,MAAM,OAAO,CAACD,eAC/B,MAAM,IAAIE,YACN,uDACA,uBACA;YACIH;YACAC;QACJ;QAGR,IAAIC,AAAyB,SAAzBA,MAAM,OAAO,CAACF,QACd,OAAOC,aAAa,KAAK,CAAC,CAACG,IAAWJ,MAAM,QAAQ,CAACI;QAEzD,OAAOH,aAAa,QAAQ,CAACD;IACjC;;aAzBgB,SAAS,GAAG;;AA0BhC;AAEO,MAAMK,cAAcC,YAAY,oBAAoB,CAAC;IACxD,gBAAgBR;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,11 @@
1
+ import { ValueFilter } from "../abstractions/ValueFilter.js";
2
+ declare class BetweenFilterImpl implements ValueFilter.Interface {
3
+ readonly operation = "between";
4
+ is(operation: string): boolean;
5
+ canUse(): boolean;
6
+ matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result;
7
+ }
8
+ export declare const BetweenFilter: typeof BetweenFilterImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../abstractions/ValueFilter.js").IValueFilter<any, any>>;
10
+ };
11
+ export {};
@@ -0,0 +1,31 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { ValueFilter } from "../abstractions/ValueFilter.js";
3
+ class BetweenFilterImpl {
4
+ is(operation) {
5
+ return this.operation === operation;
6
+ }
7
+ canUse() {
8
+ return true;
9
+ }
10
+ matches({ value, compareValue }) {
11
+ if (Array.isArray(compareValue)) {
12
+ if (2 !== compareValue.length) throw new WebinyError("When comparing between and you give an array, there must be two items in it.", "FILTER_ERROR", {
13
+ value,
14
+ compareValue
15
+ });
16
+ const [from, to] = compareValue;
17
+ return value >= from && value <= to;
18
+ }
19
+ return value >= compareValue && value <= compareValue;
20
+ }
21
+ constructor(){
22
+ this.operation = "between";
23
+ }
24
+ }
25
+ const BetweenFilter = ValueFilter.createImplementation({
26
+ implementation: BetweenFilterImpl,
27
+ dependencies: []
28
+ });
29
+ export { BetweenFilter };
30
+
31
+ //# sourceMappingURL=BetweenFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature/ValueFilter/filters/BetweenFilter.js","sources":["../../../../src/feature/ValueFilter/filters/BetweenFilter.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { ValueFilter } from \"../abstractions/ValueFilter.js\";\n\nclass BetweenFilterImpl implements ValueFilter.Interface {\n public readonly operation = \"between\";\n\n public is(operation: string): boolean {\n return this.operation === operation;\n }\n\n public canUse(): boolean {\n return true;\n }\n\n public matches({ value, compareValue }: ValueFilter.MatchesParams): ValueFilter.Result {\n if (Array.isArray(compareValue)) {\n if (compareValue.length !== 2) {\n throw new WebinyError(\n \"When comparing between and you give an array, there must be two items in it.\",\n \"FILTER_ERROR\",\n {\n value,\n compareValue\n }\n );\n }\n const [from, to] = compareValue;\n return value >= from && value <= to;\n }\n return value >= compareValue && value <= compareValue;\n }\n}\n\nexport const BetweenFilter = ValueFilter.createImplementation({\n implementation: BetweenFilterImpl,\n dependencies: []\n});\n"],"names":["BetweenFilterImpl","operation","value","compareValue","Array","WebinyError","from","to","BetweenFilter","ValueFilter"],"mappings":";;AAGA,MAAMA;IAGK,GAAGC,SAAiB,EAAW;QAClC,OAAO,IAAI,CAAC,SAAS,KAAKA;IAC9B;IAEO,SAAkB;QACrB,OAAO;IACX;IAEO,QAAQ,EAAEC,KAAK,EAAEC,YAAY,EAA6B,EAAsB;QACnF,IAAIC,MAAM,OAAO,CAACD,eAAe;YAC7B,IAAIA,AAAwB,MAAxBA,aAAa,MAAM,EACnB,MAAM,IAAIE,YACN,gFACA,gBACA;gBACIH;gBACAC;YACJ;YAGR,MAAM,CAACG,MAAMC,GAAG,GAAGJ;YACnB,OAAOD,SAASI,QAAQJ,SAASK;QACrC;QACA,OAAOL,SAASC,gBAAgBD,SAASC;IAC7C;;aA1BgB,SAAS,GAAG;;AA2BhC;AAEO,MAAMK,gBAAgBC,YAAY,oBAAoB,CAAC;IAC1D,gBAAgBT;IAChB,cAAc,EAAE;AACpB"}