@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
@@ -1,52 +0,0 @@
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.default = void 0;
9
-
10
- var _processStatement = _interopRequireDefault(require("./processStatement"));
11
-
12
- /**
13
- * Remove this when no apps are using our internal db drivers anymore
14
- */
15
- // @ts-nocheck
16
- var _default = ({
17
- query,
18
- sort,
19
- key
20
- }) => {
21
- const args = {
22
- expression: "",
23
- attributeNames: {},
24
- attributeValues: {}
25
- };
26
- (0, _processStatement.default)({
27
- args,
28
- query: {
29
- $and: query
30
- }
31
- });
32
- const output = {
33
- KeyConditionExpression: args.expression,
34
- ExpressionAttributeNames: args.attributeNames,
35
- ExpressionAttributeValues: args.attributeValues,
36
- ScanIndexForward: true,
37
- IndexName: null
38
- };
39
- const sortKey = key.fields && key.fields[1];
40
-
41
- if (sort && sort[sortKey.name] === -1) {
42
- output.ScanIndexForward = false;
43
- }
44
-
45
- if (!key.primary) {
46
- output.IndexName = key.name;
47
- }
48
-
49
- return output;
50
- };
51
-
52
- exports.default = _default;
@@ -1 +0,0 @@
1
- {"version":3,"names":["query","sort","key","args","expression","attributeNames","attributeValues","processStatement","$and","output","KeyConditionExpression","ExpressionAttributeNames","ExpressionAttributeValues","ScanIndexForward","IndexName","sortKey","fields","name","primary"],"sources":["createKeyConditionExpressionArgs.ts"],"sourcesContent":["/**\n * Remove this when no apps are using our internal db drivers anymore\n */\n// @ts-nocheck\nimport processStatement from \"./processStatement\";\nimport { ProcessStatementArgsParam, Query, QueryKey, QuerySort } from \"~/types\";\n\ninterface Output {\n KeyConditionExpression: string;\n ExpressionAttributeNames: Record<string, any>;\n ExpressionAttributeValues: Record<string, any>;\n ScanIndexForward: boolean;\n IndexName: string;\n}\ninterface Params {\n query: Query;\n sort: QuerySort;\n key: QueryKey;\n}\nexport default ({ query, sort, key }: Params): Output => {\n const args: ProcessStatementArgsParam = {\n expression: \"\",\n attributeNames: {},\n attributeValues: {}\n };\n\n processStatement({ args, query: { $and: query } });\n\n const output: Output = {\n KeyConditionExpression: args.expression,\n ExpressionAttributeNames: args.attributeNames,\n ExpressionAttributeValues: args.attributeValues,\n ScanIndexForward: true,\n IndexName: null\n };\n\n const sortKey = key.fields && key.fields[1];\n if (sort && sort[sortKey.name] === -1) {\n output.ScanIndexForward = false;\n }\n\n if (!key.primary) {\n output.IndexName = key.name;\n }\n\n return output;\n};\n"],"mappings":";;;;;;;;;AAIA;;AAJA;AACA;AACA;AACA;eAgBe,CAAC;EAAEA,KAAF;EAASC,IAAT;EAAeC;AAAf,CAAD,KAA0C;EACrD,MAAMC,IAA+B,GAAG;IACpCC,UAAU,EAAE,EADwB;IAEpCC,cAAc,EAAE,EAFoB;IAGpCC,eAAe,EAAE;EAHmB,CAAxC;EAMA,IAAAC,yBAAA,EAAiB;IAAEJ,IAAF;IAAQH,KAAK,EAAE;MAAEQ,IAAI,EAAER;IAAR;EAAf,CAAjB;EAEA,MAAMS,MAAc,GAAG;IACnBC,sBAAsB,EAAEP,IAAI,CAACC,UADV;IAEnBO,wBAAwB,EAAER,IAAI,CAACE,cAFZ;IAGnBO,yBAAyB,EAAET,IAAI,CAACG,eAHb;IAInBO,gBAAgB,EAAE,IAJC;IAKnBC,SAAS,EAAE;EALQ,CAAvB;EAQA,MAAMC,OAAO,GAAGb,GAAG,CAACc,MAAJ,IAAcd,GAAG,CAACc,MAAJ,CAAW,CAAX,CAA9B;;EACA,IAAIf,IAAI,IAAIA,IAAI,CAACc,OAAO,CAACE,IAAT,CAAJ,KAAuB,CAAC,CAApC,EAAuC;IACnCR,MAAM,CAACI,gBAAP,GAA0B,KAA1B;EACH;;EAED,IAAI,CAACX,GAAG,CAACgB,OAAT,EAAkB;IACdT,MAAM,CAACK,SAAP,GAAmBZ,GAAG,CAACe,IAAvB;EACH;;EAED,OAAOR,MAAP;AACH,C"}
@@ -1,3 +0,0 @@
1
- import { ProcessStatementCallable } from "../types";
2
- declare const processStatement: ProcessStatementCallable;
3
- export default processStatement;
@@ -1,42 +0,0 @@
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.default = void 0;
9
-
10
- var _operators = _interopRequireDefault(require("./../operators"));
11
-
12
- const processStatement = ({
13
- args,
14
- query
15
- }) => {
16
- outerLoop: for (const [key, value] of Object.entries(query)) {
17
- const operators = Object.values(_operators.default);
18
-
19
- for (let i = 0; i < operators.length; i++) {
20
- const operator = operators[i];
21
-
22
- if (operator.canProcess({
23
- key,
24
- value,
25
- args
26
- })) {
27
- operator.process({
28
- key,
29
- value,
30
- args,
31
- processStatement
32
- });
33
- continue outerLoop;
34
- }
35
- }
36
-
37
- throw new Error(`Invalid operator {${key} : ${value}}.`);
38
- }
39
- };
40
-
41
- var _default = processStatement;
42
- exports.default = _default;
@@ -1 +0,0 @@
1
- {"version":3,"names":["processStatement","args","query","outerLoop","key","value","Object","entries","operators","values","allOperators","i","length","operator","canProcess","process","Error"],"sources":["processStatement.ts"],"sourcesContent":["import allOperators from \"./../operators\";\nimport { ProcessStatementCallable } from \"~/types\";\n\nconst processStatement: ProcessStatementCallable = ({ args, query }) => {\n outerLoop: for (const [key, value] of Object.entries(query)) {\n const operators = Object.values(allOperators);\n for (let i = 0; i < operators.length; i++) {\n const operator = operators[i];\n if (operator.canProcess({ key, value, args })) {\n operator.process({ key, value, args, processStatement });\n continue outerLoop;\n }\n }\n throw new Error(`Invalid operator {${key} : ${value}}.`);\n }\n};\nexport default processStatement;\n"],"mappings":";;;;;;;;;AAAA;;AAGA,MAAMA,gBAA0C,GAAG,CAAC;EAAEC,IAAF;EAAQC;AAAR,CAAD,KAAqB;EACpEC,SAAS,EAAE,KAAK,MAAM,CAACC,GAAD,EAAMC,KAAN,CAAX,IAA2BC,MAAM,CAACC,OAAP,CAAeL,KAAf,CAA3B,EAAkD;IACzD,MAAMM,SAAS,GAAGF,MAAM,CAACG,MAAP,CAAcC,kBAAd,CAAlB;;IACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,SAAS,CAACI,MAA9B,EAAsCD,CAAC,EAAvC,EAA2C;MACvC,MAAME,QAAQ,GAAGL,SAAS,CAACG,CAAD,CAA1B;;MACA,IAAIE,QAAQ,CAACC,UAAT,CAAoB;QAAEV,GAAF;QAAOC,KAAP;QAAcJ;MAAd,CAApB,CAAJ,EAA+C;QAC3CY,QAAQ,CAACE,OAAT,CAAiB;UAAEX,GAAF;UAAOC,KAAP;UAAcJ,IAAd;UAAoBD;QAApB,CAAjB;QACA,SAASG,SAAT;MACH;IACJ;;IACD,MAAM,IAAIa,KAAJ,CAAW,qBAAoBZ,GAAI,MAAKC,KAAM,IAA9C,CAAN;EACH;AACJ,CAZD;;eAaeL,gB"}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface OperatorArgs {\n expression: string;\n attributeNames: Record<string, any>;\n attributeValues: Record<string, any>;\n}\n\ninterface CanProcessArgs {\n key: string;\n value: any;\n args: OperatorArgs;\n}\n\ninterface ProcessArgs {\n key: string;\n value: any;\n args: OperatorArgs;\n processStatement: any;\n}\n\nexport interface Operator {\n canProcess: ({ key }: CanProcessArgs) => boolean;\n process: ({ key, value, args }: ProcessArgs) => void;\n}\n\n/**\n * We use this definition to search for a value in any given field that was passed.\n * It works as an \"OR\" condition.\n */\nexport interface DynamoDbContainsFilter {\n fields: string[];\n value: string;\n}\n\nexport interface ProcessStatementArgsParam {\n expression: string;\n attributeNames: Record<string, any>;\n attributeValues: Record<string, any>;\n}\nexport interface ProcessStatementQueryParam {\n [key: string]: any;\n}\nexport interface ProcessStatementParams {\n args: ProcessStatementArgsParam;\n query: ProcessStatementQueryParam;\n}\n\nexport interface ProcessStatementCallable {\n (params: ProcessStatementParams): void;\n}\n\nexport interface Query {\n [key: string]: string;\n}\nexport interface QueryKeyField {\n name: string;\n}\nexport interface QueryKey {\n fields: QueryKeyField[];\n primary?: boolean;\n unique?: boolean;\n name: string;\n}\nexport type QueryKeys = QueryKey[];\n\nexport type QuerySort = Record<string, -1 | 1>;\n"],"mappings":""}
@@ -1,10 +0,0 @@
1
- import { Context } from "@webiny/api/types";
2
- import { DefinitionParams } from "../plugins/definitions/AttributePlugin";
3
- import { PluginsContainer } from "@webiny/plugins";
4
- /**
5
- * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
6
- *
7
- * @deprecated
8
- */
9
- export declare const getExtraAttributes: (context: Context, entity: string) => Record<string, DefinitionParams>;
10
- export declare const getExtraAttributesFromPlugins: (plugins: PluginsContainer, entity: string) => Record<string, DefinitionParams>;
@@ -1,31 +0,0 @@
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.getExtraAttributesFromPlugins = exports.getExtraAttributes = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _AttributePlugin = require("../plugins/definitions/AttributePlugin");
13
-
14
- /**
15
- * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.
16
- *
17
- * @deprecated
18
- */
19
- const getExtraAttributes = (context, entity) => {
20
- return getExtraAttributesFromPlugins(context.plugins, entity);
21
- };
22
-
23
- exports.getExtraAttributes = getExtraAttributes;
24
-
25
- const getExtraAttributesFromPlugins = (plugins, entity) => {
26
- return plugins.byType(_AttributePlugin.AttributePlugin.type).filter(plugin => plugin.entity === entity).reduce((attributes, plugin) => {
27
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attributes), plugin.getDefinition());
28
- }, {});
29
- };
30
-
31
- exports.getExtraAttributesFromPlugins = getExtraAttributesFromPlugins;
@@ -1 +0,0 @@
1
- {"version":3,"names":["getExtraAttributes","context","entity","getExtraAttributesFromPlugins","plugins","byType","AttributePlugin","type","filter","plugin","reduce","attributes","getDefinition"],"sources":["attributes.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { AttributePlugin, DefinitionParams } from \"~/plugins/definitions/AttributePlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * Will be removed in favor of directly assigning attributes to a certain entity when creating the storage operations.\n *\n * @deprecated\n */\nexport const getExtraAttributes = (\n context: Context,\n entity: string\n): Record<string, DefinitionParams> => {\n return getExtraAttributesFromPlugins(context.plugins, entity);\n};\n\nexport const getExtraAttributesFromPlugins = (\n plugins: PluginsContainer,\n entity: string\n): Record<string, DefinitionParams> => {\n return plugins\n .byType<AttributePlugin>(AttributePlugin.type)\n .filter(plugin => plugin.entity === entity)\n .reduce((attributes, plugin) => {\n return {\n ...attributes,\n ...plugin.getDefinition()\n };\n }, {});\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAGA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAC9BC,OAD8B,EAE9BC,MAF8B,KAGK;EACnC,OAAOC,6BAA6B,CAACF,OAAO,CAACG,OAAT,EAAkBF,MAAlB,CAApC;AACH,CALM;;;;AAOA,MAAMC,6BAA6B,GAAG,CACzCC,OADyC,EAEzCF,MAFyC,KAGN;EACnC,OAAOE,OAAO,CACTC,MADE,CACsBC,gCAAA,CAAgBC,IADtC,EAEFC,MAFE,CAEKC,MAAM,IAAIA,MAAM,CAACP,MAAP,KAAkBA,MAFjC,EAGFQ,MAHE,CAGK,CAACC,UAAD,EAAaF,MAAb,KAAwB;IAC5B,mEACOE,UADP,GAEOF,MAAM,CAACG,aAAP,EAFP;EAIH,CARE,EAQA,EARA,CAAP;AASH,CAbM"}
@@ -1,15 +0,0 @@
1
- import { Table } from "dynamodb-toolbox";
2
- interface Item {
3
- Table: Table;
4
- Key: any;
5
- }
6
- interface Params {
7
- table: Table;
8
- items: Item[];
9
- }
10
- /**
11
- * This helper function is meant to be used to batch read from one table.
12
- * It will fetch all results, as there is a next() method call built in.
13
- */
14
- export declare const batchReadAll: <T = any>(params: Params, maxChunk?: number) => Promise<T[]>;
15
- export {};
@@ -1,89 +0,0 @@
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.batchReadAll = void 0;
9
-
10
- var _chunk = _interopRequireDefault(require("lodash/chunk"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- const MAX_BATCH_ITEMS = 100;
15
-
16
- const flatten = responses => {
17
- const entries = [];
18
- const values = Object.values(responses);
19
-
20
- for (const items of values) {
21
- entries.push(...items);
22
- }
23
-
24
- return entries;
25
- };
26
-
27
- const batchReadAllChunk = async params => {
28
- const {
29
- table,
30
- items
31
- } = params;
32
- const records = [];
33
- const result = await table.batchGet(items);
34
-
35
- if (!result || !result.Responses) {
36
- return records;
37
- }
38
-
39
- records.push(...flatten(result.Responses));
40
-
41
- if (!result.next || typeof result.next !== "function") {
42
- return records;
43
- }
44
-
45
- let previous = result;
46
-
47
- while (typeof previous.next === "function") {
48
- const nextResult = await previous.next();
49
-
50
- if (!nextResult) {
51
- return records;
52
- }
53
-
54
- records.push(...flatten(nextResult.Responses));
55
- previous = nextResult;
56
- }
57
-
58
- return records;
59
- };
60
- /**
61
- * This helper function is meant to be used to batch read from one table.
62
- * It will fetch all results, as there is a next() method call built in.
63
- */
64
-
65
-
66
- const batchReadAll = async (params, maxChunk = MAX_BATCH_ITEMS) => {
67
- if (params.items.length === 0) {
68
- return [];
69
- } else if (maxChunk > MAX_BATCH_ITEMS) {
70
- throw new _error.default(`Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`, "DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR", {
71
- maxChunk
72
- });
73
- }
74
-
75
- const records = [];
76
- const chunkItemsList = (0, _chunk.default)(params.items, maxChunk);
77
-
78
- for (const chunkItems of chunkItemsList) {
79
- const results = await batchReadAllChunk({
80
- table: params.table,
81
- items: chunkItems
82
- });
83
- records.push(...results);
84
- }
85
-
86
- return records;
87
- };
88
-
89
- exports.batchReadAll = batchReadAll;
@@ -1 +0,0 @@
1
- {"version":3,"names":["MAX_BATCH_ITEMS","flatten","responses","entries","values","Object","items","push","batchReadAllChunk","params","table","records","result","batchGet","Responses","next","previous","nextResult","batchReadAll","maxChunk","length","WebinyError","chunkItemsList","lodashChunk","chunkItems","results"],"sources":["batchRead.ts"],"sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport lodashChunk from \"lodash/chunk\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Item {\n Table: Table;\n Key: any;\n}\ninterface Params {\n table: Table;\n items: Item[];\n}\n\nconst MAX_BATCH_ITEMS = 100;\n\nconst flatten = (responses: Record<string, any[]>): any[] => {\n const entries = [];\n const values = Object.values(responses);\n for (const items of values) {\n entries.push(...items);\n }\n return entries;\n};\n\ninterface BatchReadAllChunkParams {\n table: Table;\n items: Item[];\n}\nconst batchReadAllChunk = async <T = any>(params: BatchReadAllChunkParams): Promise<T[]> => {\n const { table, items } = params;\n const records: T[] = [];\n\n const result = await table.batchGet(items);\n if (!result || !result.Responses) {\n return records;\n }\n records.push(...flatten(result.Responses));\n if (!result.next || typeof result.next !== \"function\") {\n return records;\n }\n let previous = result;\n while (typeof previous.next === \"function\") {\n const nextResult = await previous.next();\n if (!nextResult) {\n return records;\n }\n records.push(...flatten(nextResult.Responses));\n previous = nextResult;\n }\n return records;\n};\n/**\n * This helper function is meant to be used to batch read from one table.\n * It will fetch all results, as there is a next() method call built in.\n */\nexport const batchReadAll = async <T = any>(\n params: Params,\n maxChunk = MAX_BATCH_ITEMS\n): Promise<T[]> => {\n if (params.items.length === 0) {\n return [];\n } else if (maxChunk > MAX_BATCH_ITEMS) {\n throw new WebinyError(\n `Cannot set to load more than ${MAX_BATCH_ITEMS} items from the DynamoDB at once.`,\n \"DYNAMODB_MAX_BATCH_GET_LIMIT_ERROR\",\n {\n maxChunk\n }\n );\n }\n\n const records: T[] = [];\n\n const chunkItemsList: Item[][] = lodashChunk(params.items, maxChunk);\n\n for (const chunkItems of chunkItemsList) {\n const results = await batchReadAllChunk<T>({\n table: params.table,\n items: chunkItems\n });\n\n records.push(...results);\n }\n\n return records;\n};\n"],"mappings":";;;;;;;;;AACA;;AACA;;AAWA,MAAMA,eAAe,GAAG,GAAxB;;AAEA,MAAMC,OAAO,GAAIC,SAAD,IAA6C;EACzD,MAAMC,OAAO,GAAG,EAAhB;EACA,MAAMC,MAAM,GAAGC,MAAM,CAACD,MAAP,CAAcF,SAAd,CAAf;;EACA,KAAK,MAAMI,KAAX,IAAoBF,MAApB,EAA4B;IACxBD,OAAO,CAACI,IAAR,CAAa,GAAGD,KAAhB;EACH;;EACD,OAAOH,OAAP;AACH,CAPD;;AAaA,MAAMK,iBAAiB,GAAG,MAAgBC,MAAhB,IAAkE;EACxF,MAAM;IAAEC,KAAF;IAASJ;EAAT,IAAmBG,MAAzB;EACA,MAAME,OAAY,GAAG,EAArB;EAEA,MAAMC,MAAM,GAAG,MAAMF,KAAK,CAACG,QAAN,CAAeP,KAAf,CAArB;;EACA,IAAI,CAACM,MAAD,IAAW,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CAAvC;IAKAb,OAAO,CAACJ,IAAR,CAAa,GAAGkB,OAAhB;EACH;;EAED,OAAOd,OAAP;AACH,CA9BM"}
@@ -1,17 +0,0 @@
1
- import { Table } from "dynamodb-toolbox";
2
- import { DocumentClient } from "aws-sdk/clients/dynamodb";
3
- interface Item {
4
- [key: string]: DocumentClient.WriteRequest;
5
- }
6
- interface Params {
7
- table: Table;
8
- items: Item[];
9
- }
10
- /**
11
- * Method is meant for batch writing to a single table.
12
- * It expects already prepared items for the write.
13
- * It can either delete or put items
14
- * The method does not check items before actually sending them into the underlying library.
15
- */
16
- export declare const batchWriteAll: (params: Params, maxChunk?: number) => Promise<void>;
17
- export {};
@@ -1,30 +0,0 @@
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.batchWriteAll = void 0;
9
-
10
- var _chunk = _interopRequireDefault(require("lodash/chunk"));
11
-
12
- /**
13
- * Method is meant for batch writing to a single table.
14
- * It expects already prepared items for the write.
15
- * It can either delete or put items
16
- * The method does not check items before actually sending them into the underlying library.
17
- */
18
- const batchWriteAll = async (params, maxChunk = 25) => {
19
- if (params.items.length === 0) {
20
- return;
21
- }
22
-
23
- const chunkedItems = (0, _chunk.default)(params.items, maxChunk);
24
-
25
- for (const items of chunkedItems) {
26
- await params.table.batchWrite(items);
27
- }
28
- };
29
-
30
- exports.batchWriteAll = batchWriteAll;
@@ -1 +0,0 @@
1
- {"version":3,"names":["batchWriteAll","params","maxChunk","items","length","chunkedItems","lodashChunk","table","batchWrite"],"sources":["batchWrite.ts"],"sourcesContent":["import { Table } from \"dynamodb-toolbox\";\nimport lodashChunk from \"lodash/chunk\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\n\ninterface Item {\n [key: string]: DocumentClient.WriteRequest;\n}\ninterface Params {\n table: Table;\n items: Item[];\n}\n\n/**\n * Method is meant for batch writing to a single table.\n * It expects already prepared items for the write.\n * It can either delete or put items\n * The method does not check items before actually sending them into the underlying library.\n */\nexport const batchWriteAll = async (params: Params, maxChunk = 25): Promise<void> => {\n if (params.items.length === 0) {\n return;\n }\n const chunkedItems: Item[][] = lodashChunk(params.items, maxChunk);\n for (const items of chunkedItems) {\n await params.table.batchWrite(items);\n }\n};\n"],"mappings":";;;;;;;;;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,aAAa,GAAG,OAAOC,MAAP,EAAuBC,QAAQ,GAAG,EAAlC,KAAwD;EACjF,IAAID,MAAM,CAACE,KAAP,CAAaC,MAAb,KAAwB,CAA5B,EAA+B;IAC3B;EACH;;EACD,MAAMC,YAAsB,GAAG,IAAAC,cAAA,EAAYL,MAAM,CAACE,KAAnB,EAA0BD,QAA1B,CAA/B;;EACA,KAAK,MAAMC,KAAX,IAAoBE,YAApB,EAAkC;IAC9B,MAAMJ,MAAM,CAACM,KAAP,CAAaC,UAAb,CAAwBL,KAAxB,CAAN;EACH;AACJ,CARM"}
package/utils/filter.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { PluginsContainer } from "@webiny/plugins";
2
- import { FieldPlugin } from "../plugins/definitions/FieldPlugin";
3
- export interface Params<T = any> {
4
- plugins: PluginsContainer;
5
- items: T[];
6
- where: Record<string, any>;
7
- /**
8
- * An array of fields that require some special operation.
9
- */
10
- fields: FieldPlugin[];
11
- }
12
- export declare function filterItems<T = any>(params: Params<T>): T[];
package/utils/filter.js DELETED
@@ -1,213 +0,0 @@
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.filterItems = filterItems;
9
-
10
- var _dotProp = _interopRequireDefault(require("dot-prop"));
11
-
12
- var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
- var _ValueFilterPlugin = require("../plugins/definitions/ValueFilterPlugin");
15
-
16
- const getMappedPlugins = params => {
17
- return params.plugins.byType(params.type).reduce((plugins, plugin) => {
18
- /**
19
- * We expect op to be a string, that is why we cast.
20
- */
21
- const op = plugin[params.property];
22
- plugins[op] = plugin;
23
- return plugins;
24
- }, {});
25
- };
26
-
27
- const extractWhereArgs = key => {
28
- const result = key.split("_");
29
- const field = result.shift();
30
- const rawOp = result.length === 0 ? "eq" : result.join("_");
31
- /**
32
- * When rawOp is not, it means it is equal negated so just return that.
33
- */
34
-
35
- if (rawOp === "not") {
36
- return {
37
- field,
38
- operation: "eq",
39
- negate: true
40
- };
41
- }
42
-
43
- const negate = rawOp.match("not_") !== null;
44
- const operation = rawOp.replace("not_", "");
45
- return {
46
- field,
47
- operation,
48
- negate
49
- };
50
- };
51
-
52
- const findFilterPlugin = (plugins, operation) => {
53
- if (plugins[operation]) {
54
- return plugins[operation];
55
- }
56
-
57
- throw new _error.default(`Missing filter plugin definition.`, "FILTER_PLUGIN_ERROR", {
58
- operation
59
- });
60
- };
61
-
62
- const multiSearchFieldOperations = ["contains", "fuzzy"];
63
-
64
- const createFilters = params => {
65
- const {
66
- plugins,
67
- where,
68
- fields
69
- } = params;
70
- const keys = Object.keys(where);
71
- /**
72
- * Skip everything if there are no conditions to be applied.
73
- */
74
-
75
- if (keys.length === 0) {
76
- return [];
77
- }
78
-
79
- const filterPlugins = getMappedPlugins({
80
- plugins,
81
- type: _ValueFilterPlugin.ValueFilterPlugin.type,
82
- property: "operation"
83
- });
84
- return keys.reduce((filters, key) => {
85
- const compareValue = where[key];
86
-
87
- if (compareValue === undefined) {
88
- return filters;
89
- }
90
- /**
91
- * @see DynamoDbContainsFilter
92
- */
93
-
94
-
95
- if (multiSearchFieldOperations.includes(key) === true) {
96
- const data = compareValue;
97
- let transformValue = undefined;
98
- const paths = data.fields.map(field => {
99
- const fieldPlugin = fields.find(plugin => plugin.getField() === field);
100
-
101
- if (fieldPlugin) {
102
- transformValue = value => {
103
- return fieldPlugin.transformValue(value);
104
- };
105
-
106
- return fieldPlugin.getPath();
107
- }
108
-
109
- return field;
110
- });
111
- filters.push({
112
- compareValue: data.value,
113
- filterPlugin: findFilterPlugin(filterPlugins, key),
114
- transformValue,
115
- paths,
116
- negate: false
117
- });
118
- return filters;
119
- }
120
-
121
- const {
122
- field,
123
- operation,
124
- negate
125
- } = extractWhereArgs(key);
126
- const filterPlugin = findFilterPlugin(filterPlugins, operation);
127
- const fieldPlugin = fields.find(plugin => plugin.getField() === field);
128
- let path = field;
129
- let transformValue = undefined;
130
-
131
- if (fieldPlugin) {
132
- transformValue = value => {
133
- return fieldPlugin.transformValue(value);
134
- };
135
-
136
- path = fieldPlugin.getPath();
137
- }
138
-
139
- filters.push({
140
- compareValue,
141
- filterPlugin,
142
- transformValue,
143
- paths: [path],
144
- negate
145
- });
146
- return filters;
147
- }, []);
148
- };
149
- /**
150
- * Transforms the value with given transformer callable.
151
- */
152
-
153
-
154
- const transform = (value, transformValue) => {
155
- if (!transformValue) {
156
- return value;
157
- }
158
-
159
- if (Array.isArray(value)) {
160
- return value.map(v => transformValue(v));
161
- }
162
-
163
- return transformValue(value);
164
- };
165
- /**
166
- * Creates a filter callable that we can send to the .filter() method of the array.
167
- */
168
-
169
-
170
- const createFilterCallable = params => {
171
- const filters = createFilters(params);
172
- /**
173
- * Just return null so there are no filters to be applied.
174
- * Later in the code we check for null so we do not loop through the items.
175
- */
176
-
177
- if (filters.length === 0) {
178
- return null;
179
- }
180
-
181
- return item => {
182
- for (const filter of filters) {
183
- const result = filter.paths.some(path => {
184
- const value = transform(_dotProp.default.get(item, path), filter.transformValue);
185
- const compareValue = transform(filter.compareValue, filter.transformValue);
186
- const matched = filter.filterPlugin.matches({
187
- value,
188
- compareValue
189
- });
190
- return filter.negate ? !matched : matched;
191
- });
192
-
193
- if (result === false) {
194
- return false;
195
- }
196
- }
197
-
198
- return true;
199
- };
200
- };
201
-
202
- function filterItems(params) {
203
- const filter = createFilterCallable(params);
204
- /**
205
- * No point in going through all the items when there are no filters to be applied.
206
- */
207
-
208
- if (!filter) {
209
- return params.items;
210
- }
211
-
212
- return params.items.filter(filter);
213
- }
@@ -1 +0,0 @@
1
- {"version":3,"names":["getMappedPlugins","params","plugins","byType","type","reduce","plugin","op","property","extractWhereArgs","key","result","split","field","shift","rawOp","length","join","operation","negate","match","replace","findFilterPlugin","WebinyError","multiSearchFieldOperations","createFilters","where","fields","keys","Object","filterPlugins","ValueFilterPlugin","filters","compareValue","undefined","includes","data","transformValue","paths","map","fieldPlugin","find","getField","value","getPath","push","filterPlugin","path","transform","Array","isArray","v","createFilterCallable","item","filter","some","dotProp","get","matched","matches","filterItems","items"],"sources":["filter.ts"],"sourcesContent":["import dotProp from \"dot-prop\";\nimport WebinyError from \"@webiny/error\";\nimport { Plugin, PluginsContainer } from \"@webiny/plugins\";\nimport { ValueFilterPlugin } from \"~/plugins/definitions/ValueFilterPlugin\";\nimport { FieldPlugin } from \"~/plugins/definitions/FieldPlugin\";\nimport { DynamoDbContainsFilter } from \"~/types\";\n\ntype TransformValue = (value: any) => any;\n\nexport interface Params<T = any> {\n plugins: PluginsContainer;\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\ninterface MappedPluginParams<T extends Plugin = Plugin> {\n plugins: PluginsContainer;\n type: string;\n property: keyof T;\n}\n\ninterface Filter {\n compareValue: any;\n filterPlugin: ValueFilterPlugin;\n transformValue?: TransformValue;\n paths: string[];\n negate: boolean;\n}\n\nconst getMappedPlugins = <T extends Plugin>(params: MappedPluginParams<T>): Record<string, T> => {\n return params.plugins.byType<T>(params.type).reduce((plugins, plugin) => {\n /**\n * We expect op to be a string, that is why we cast.\n */\n const op = plugin[params.property] as unknown as string;\n plugins[op] = plugin;\n return plugins;\n }, {} as Record<string, T>);\n};\n\ninterface ExtractWhereArgsResult {\n field: string;\n operation: string;\n negate: boolean;\n}\nconst 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\nconst findFilterPlugin = (\n plugins: Record<string, ValueFilterPlugin>,\n operation: string\n): ValueFilterPlugin => {\n if (plugins[operation]) {\n return plugins[operation];\n }\n throw new WebinyError(`Missing filter plugin definition.`, \"FILTER_PLUGIN_ERROR\", {\n operation\n });\n};\n\nconst multiSearchFieldOperations = [\"contains\", \"fuzzy\"];\n\nconst createFilters = (params: Omit<Params, \"items\">): Filter[] => {\n const { plugins, where, fields } = 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 const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\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 filters.push({\n compareValue: data.value,\n filterPlugin: findFilterPlugin(filterPlugins, key),\n transformValue,\n paths,\n negate: false\n });\n return filters;\n }\n\n const { field, operation, negate } = extractWhereArgs(key);\n\n const filterPlugin = findFilterPlugin(filterPlugins, 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 compareValue,\n filterPlugin,\n transformValue,\n paths: [path],\n negate\n });\n\n return filters;\n }, [] as Filter[]);\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 * Creates a filter callable that we can send to the .filter() method of the array.\n */\nconst createFilterCallable = (params: Omit<Params, \"items\">): ((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.get(item, path), filter.transformValue);\n const compareValue = transform(filter.compareValue, filter.transformValue);\n const matched = filter.filterPlugin.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\nexport function filterItems<T = any>(params: Params<T>): T[] {\n const filter = createFilterCallable(params);\n /**\n * No point in going through all the items when there are no filters to be applied.\n */\n if (!filter) {\n return params.items;\n }\n return params.items.filter(filter);\n}\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AA8BA,MAAMA,gBAAgB,GAAsBC,MAAnB,IAAwE;EAC7F,OAAOA,MAAM,CAACC,OAAP,CAAeC,MAAf,CAAyBF,MAAM,CAACG,IAAhC,EAAsCC,MAAtC,CAA6C,CAACH,OAAD,EAAUI,MAAV,KAAqB;IACrE;AACR;AACA;IACQ,MAAMC,EAAE,GAAGD,MAAM,CAACL,MAAM,CAACO,QAAR,CAAjB;IACAN,OAAO,CAACK,EAAD,CAAP,GAAcD,MAAd;IACA,OAAOJ,OAAP;EACH,CAPM,EAOJ,EAPI,CAAP;AAQH,CATD;;AAgBA,MAAMO,gBAAgB,GAAIC,GA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CAAkBR,IAAI,IAAI;QACrC,MAAMJ,KAAK,GAAGK,SAAS,CAACQ,gBAAA,CAAQC,GAAR,CAAYJ,IAAZ,EAAkBN,IAAlB,CAAD,EAA0BO,MAAM,CAACjB,cAAjC,CAAvB;QACA,MAAMJ,YAAY,GAAGe,SAAS,CAACM,MAAM,CAACrB,YAAR,EAAsBqB,MAAM,CAACjB,cAA7B,CAA9B;QACA,MAAMqB,OAAO,GAAGJ,MAAM,CAACR,YAAP,CAAoBa,OAApB,CAA4B;UACxChB,KADwC;UAExCV;QAFwC,CAA5B,CAAhB;QAKA,OAAOqB,MAAM,CAACnC,MAAP,GAAgB,CAACuC,OAAjB,GAA2BA,OAAlC;MACH,CATc,CAAf;;MAUA,IAAI/C,MAAM,KAAK,KAAf,EAAsB;QAClB,OAAO,KAAP;MACH;IACJ;;IACD,OAAO,IAAP;EACH,CAjBD;AAkBH,CA5BD;;AA8BO,SAASiD,WAAT,CAA8B3D,MAA9B,EAAsD;EACzD,MAAMqD,MAAM,GAAGF,oBAAoB,CAACnD,MAAD,CAAnC;EACA;AACJ;AACA;;EACI,IAAI,CAACqD,MAAL,EAAa;IACT,OAAOrD,MAAM,CAAC4D,KAAd;EACH;;EACD,OAAO5D,MAAM,CAAC4D,KAAP,CAAaP,MAAb,CAAoBA,MAApB,CAAP;AACH"}
@@ -1,13 +0,0 @@
1
- interface MetaResponse {
2
- cursor: string | null;
3
- totalCount: number;
4
- hasMoreItems: boolean;
5
- }
6
- interface CreateListResponseParams<T> {
7
- items: T[];
8
- after?: string | null;
9
- totalCount: number;
10
- limit: number;
11
- }
12
- export declare function createListResponse<T>(params: CreateListResponseParams<T>): [T[], MetaResponse];
13
- export {};
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createListResponse = createListResponse;
7
-
8
- var _cursor = require("./cursor");
9
-
10
- function createListResponse(params) {
11
- const {
12
- items: initialItems,
13
- after,
14
- totalCount,
15
- limit
16
- } = params;
17
- let start = Number((0, _cursor.decodeCursor)(after));
18
-
19
- if (isNaN(start) === true) {
20
- start = 0;
21
- }
22
-
23
- const hasMoreItems = totalCount > start + limit;
24
- const end = limit > totalCount + start + limit ? undefined : start + limit;
25
- const items = end ? initialItems.slice(start, end) : initialItems;
26
- const cursor = items.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
27
- const meta = {
28
- hasMoreItems,
29
- totalCount,
30
- cursor
31
- };
32
- return [items, meta];
33
- }
@@ -1 +0,0 @@
1
- {"version":3,"names":["createListResponse","params","items","initialItems","after","totalCount","limit","start","Number","decodeCursor","isNaN","hasMoreItems","end","undefined","slice","cursor","length","encodeCursor","meta"],"sources":["listResponse.ts"],"sourcesContent":["import { decodeCursor, encodeCursor } from \"~/utils/cursor\";\n\ninterface MetaResponse {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface CreateListResponseParams<T> {\n items: T[];\n after?: string | null;\n totalCount: number;\n limit: number;\n}\n\nexport function createListResponse<T>(params: CreateListResponseParams<T>): [T[], MetaResponse] {\n const { items: initialItems, after, totalCount, limit } = params;\n let start = Number(decodeCursor(after));\n if (isNaN(start) === true) {\n start = 0;\n }\n const hasMoreItems = totalCount > start + limit;\n const end = limit > totalCount + start + limit ? undefined : start + limit;\n const items = end ? initialItems.slice(start, end) : initialItems;\n\n const cursor = items.length > 0 ? encodeCursor(start + limit) : null;\n\n const meta = {\n hasMoreItems,\n totalCount,\n cursor\n };\n\n return [items, meta];\n}\n"],"mappings":";;;;;;;AAAA;;AAeO,SAASA,kBAAT,CAA+BC,MAA/B,EAAyF;EAC5F,MAAM;IAAEC,KAAK,EAAEC,YAAT;IAAuBC,KAAvB;IAA8BC,UAA9B;IAA0CC;EAA1C,IAAoDL,MAA1D;EACA,IAAIM,KAAK,GAAGC,MAAM,CAAC,IAAAC,oBAAA,EAAaL,KAAb,CAAD,CAAlB;;EACA,IAAIM,KAAK,CAACH,KAAD,CAAL,KAAiB,IAArB,EAA2B;IACvBA,KAAK,GAAG,CAAR;EACH;;EACD,MAAMI,YAAY,GAAGN,UAAU,GAAGE,KAAK,GAAGD,KAA1C;EACA,MAAMM,GAAG,GAAGN,KAAK,GAAGD,UAAU,GAAGE,KAAb,GAAqBD,KAA7B,GAAqCO,SAArC,GAAiDN,KAAK,GAAGD,KAArE;EACA,MAAMJ,KAAK,GAAGU,GAAG,GAAGT,YAAY,CAACW,KAAb,CAAmBP,KAAnB,EAA0BK,GAA1B,CAAH,GAAoCT,YAArD;EAEA,MAAMY,MAAM,GAAGb,KAAK,CAACc,MAAN,GAAe,CAAf,GAAmB,IAAAC,oBAAA,EAAaV,KAAK,GAAGD,KAArB,CAAnB,GAAiD,IAAhE;EAEA,MAAMY,IAAI,GAAG;IACTP,YADS;IAETN,UAFS;IAGTU;EAHS,CAAb;EAMA,OAAO,CAACb,KAAD,EAAQgB,IAAR,CAAP;AACH"}
package/utils/table.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { DbContext } from "@webiny/handler-db/types";
2
- /**
3
- * Will be removed in favor of passing the table name directly to the storage operations.
4
- *
5
- * @deprecated
6
- */
7
- export declare const getTable: <T extends DbContext>(context: T) => string;