@webiny/db-dynamodb 6.1.0 → 6.2.0

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 (133) hide show
  1. package/exports/api/db.d.ts +2 -0
  2. package/exports/api/db.js +4 -0
  3. package/exports/api/db.js.map +1 -0
  4. package/feature/FilterUtil/FilterUtil.d.ts +11 -0
  5. package/feature/FilterUtil/FilterUtil.js +28 -0
  6. package/feature/FilterUtil/FilterUtil.js.map +1 -0
  7. package/feature/FilterUtil/abstractions/FilterUtil.d.ts +17 -0
  8. package/feature/FilterUtil/abstractions/FilterUtil.js +4 -0
  9. package/feature/FilterUtil/abstractions/FilterUtil.js.map +1 -0
  10. package/feature/FilterUtil/createFilters.d.ts +22 -0
  11. package/{utils/filter.js → feature/FilterUtil/createFilters.js} +20 -64
  12. package/feature/FilterUtil/createFilters.js.map +1 -0
  13. package/feature/FilterUtil/extractWhereArgs.d.ts +7 -0
  14. package/feature/FilterUtil/extractWhereArgs.js +24 -0
  15. package/feature/FilterUtil/extractWhereArgs.js.map +1 -0
  16. package/feature/FilterUtil/feature.d.ts +1 -0
  17. package/feature/FilterUtil/feature.js +10 -0
  18. package/feature/FilterUtil/feature.js.map +1 -0
  19. package/feature/FilterUtil/index.d.ts +2 -0
  20. package/feature/FilterUtil/index.js +4 -0
  21. package/feature/FilterUtil/index.js.map +1 -0
  22. package/feature/ValueFilter/ValueFilterRegistry.d.ts +12 -0
  23. package/feature/ValueFilter/ValueFilterRegistry.js +23 -0
  24. package/feature/ValueFilter/ValueFilterRegistry.js.map +1 -0
  25. package/feature/ValueFilter/abstractions/ValueFilter.d.ts +22 -0
  26. package/feature/ValueFilter/abstractions/ValueFilter.js +4 -0
  27. package/feature/ValueFilter/abstractions/ValueFilter.js.map +1 -0
  28. package/feature/ValueFilter/abstractions/ValueFilterRegistry.d.ts +10 -0
  29. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js +4 -0
  30. package/feature/ValueFilter/abstractions/ValueFilterRegistry.js.map +1 -0
  31. package/feature/ValueFilter/feature.d.ts +1 -0
  32. package/feature/ValueFilter/feature.js +32 -0
  33. package/feature/ValueFilter/feature.js.map +1 -0
  34. package/feature/ValueFilter/filters/AndInFilter.d.ts +11 -0
  35. package/feature/ValueFilter/filters/AndInFilter.js +32 -0
  36. package/feature/ValueFilter/filters/AndInFilter.js.map +1 -0
  37. package/feature/ValueFilter/filters/BetweenFilter.d.ts +11 -0
  38. package/{plugins/filters/between.js → feature/ValueFilter/filters/BetweenFilter.js} +17 -9
  39. package/feature/ValueFilter/filters/BetweenFilter.js.map +1 -0
  40. package/feature/ValueFilter/filters/ContainsFilter.d.ts +11 -0
  41. package/{plugins/filters/contains.js → feature/ValueFilter/filters/ContainsFilter.js} +16 -8
  42. package/feature/ValueFilter/filters/ContainsFilter.js.map +1 -0
  43. package/feature/ValueFilter/filters/EqFilter.d.ts +11 -0
  44. package/{plugins/filters/eq.js → feature/ValueFilter/filters/EqFilter.js} +16 -8
  45. package/feature/ValueFilter/filters/EqFilter.js.map +1 -0
  46. package/feature/ValueFilter/filters/FuzzyFilter.d.ts +11 -0
  47. package/{plugins/filters/fuzzy.js → feature/ValueFilter/filters/FuzzyFilter.js} +16 -8
  48. package/feature/ValueFilter/filters/FuzzyFilter.js.map +1 -0
  49. package/feature/ValueFilter/filters/GtFilter.d.ts +11 -0
  50. package/feature/ValueFilter/filters/GtFilter.js +22 -0
  51. package/feature/ValueFilter/filters/GtFilter.js.map +1 -0
  52. package/feature/ValueFilter/filters/GteFilter.d.ts +11 -0
  53. package/feature/ValueFilter/filters/GteFilter.js +22 -0
  54. package/feature/ValueFilter/filters/GteFilter.js.map +1 -0
  55. package/feature/ValueFilter/filters/InFilter.d.ts +11 -0
  56. package/feature/ValueFilter/filters/InFilter.js +32 -0
  57. package/feature/ValueFilter/filters/InFilter.js.map +1 -0
  58. package/feature/ValueFilter/filters/LtFilter.d.ts +11 -0
  59. package/feature/ValueFilter/filters/LtFilter.js +22 -0
  60. package/feature/ValueFilter/filters/LtFilter.js.map +1 -0
  61. package/feature/ValueFilter/filters/LteFilter.d.ts +11 -0
  62. package/feature/ValueFilter/filters/LteFilter.js +22 -0
  63. package/feature/ValueFilter/filters/LteFilter.js.map +1 -0
  64. package/feature/ValueFilter/filters/StartsWithFilter.d.ts +11 -0
  65. package/{plugins/filters/startsWith.js → feature/ValueFilter/filters/StartsWithFilter.js} +22 -11
  66. package/feature/ValueFilter/filters/StartsWithFilter.js.map +1 -0
  67. package/feature/ValueFilter/index.d.ts +3 -0
  68. package/feature/ValueFilter/index.js +5 -0
  69. package/feature/ValueFilter/index.js.map +1 -0
  70. package/index.d.ts +1 -0
  71. package/index.js +9 -0
  72. package/index.js.map +1 -1
  73. package/package.json +16 -13
  74. package/plugins/definitions/ValueTransformPlugin.d.ts +1 -6
  75. package/plugins/definitions/ValueTransformPlugin.js +0 -6
  76. package/plugins/definitions/ValueTransformPlugin.js.map +1 -1
  77. package/plugins/index.d.ts +0 -5
  78. package/plugins/index.js +0 -10
  79. package/plugins/index.js.map +1 -1
  80. package/utils/index.d.ts +1 -5
  81. package/utils/index.js +1 -5
  82. package/utils/index.js.map +1 -1
  83. package/plugins/definitions/AttributePlugin.d.ts +0 -18
  84. package/plugins/definitions/AttributePlugin.js +0 -38
  85. package/plugins/definitions/AttributePlugin.js.map +0 -1
  86. package/plugins/definitions/FieldPathPlugin.d.ts +0 -22
  87. package/plugins/definitions/FieldPathPlugin.js +0 -26
  88. package/plugins/definitions/FieldPathPlugin.js.map +0 -1
  89. package/plugins/definitions/ValueFilterPlugin.d.ts +0 -22
  90. package/plugins/definitions/ValueFilterPlugin.js +0 -35
  91. package/plugins/definitions/ValueFilterPlugin.js.map +0 -1
  92. package/plugins/filters/andIn.d.ts +0 -3
  93. package/plugins/filters/andIn.js +0 -24
  94. package/plugins/filters/andIn.js.map +0 -1
  95. package/plugins/filters/between.d.ts +0 -3
  96. package/plugins/filters/between.js.map +0 -1
  97. package/plugins/filters/contains.d.ts +0 -3
  98. package/plugins/filters/contains.js.map +0 -1
  99. package/plugins/filters/eq.d.ts +0 -3
  100. package/plugins/filters/eq.js.map +0 -1
  101. package/plugins/filters/fuzzy.d.ts +0 -3
  102. package/plugins/filters/fuzzy.js.map +0 -1
  103. package/plugins/filters/gt.d.ts +0 -3
  104. package/plugins/filters/gt.js +0 -14
  105. package/plugins/filters/gt.js.map +0 -1
  106. package/plugins/filters/gte.d.ts +0 -3
  107. package/plugins/filters/gte.js +0 -14
  108. package/plugins/filters/gte.js.map +0 -1
  109. package/plugins/filters/in.d.ts +0 -3
  110. package/plugins/filters/in.js +0 -24
  111. package/plugins/filters/in.js.map +0 -1
  112. package/plugins/filters/index.d.ts +0 -2
  113. package/plugins/filters/index.js +0 -14
  114. package/plugins/filters/index.js.map +0 -1
  115. package/plugins/filters/lt.d.ts +0 -3
  116. package/plugins/filters/lt.js +0 -14
  117. package/plugins/filters/lt.js.map +0 -1
  118. package/plugins/filters/lte.d.ts +0 -3
  119. package/plugins/filters/lte.js +0 -14
  120. package/plugins/filters/lte.js.map +0 -1
  121. package/plugins/filters/startsWith.d.ts +0 -3
  122. package/plugins/filters/startsWith.js.map +0 -1
  123. package/utils/attributes.d.ts +0 -10
  124. package/utils/attributes.js +0 -19
  125. package/utils/attributes.js.map +0 -1
  126. package/utils/filter.d.ts +0 -12
  127. package/utils/filter.js.map +0 -1
  128. package/utils/listResponse.d.ts +0 -13
  129. package/utils/listResponse.js +0 -25
  130. package/utils/listResponse.js.map +0 -1
  131. package/utils/update.d.ts +0 -12
  132. package/utils/update.js +0 -12
  133. package/utils/update.js.map +0 -1
@@ -0,0 +1,2 @@
1
+ export { ValueFilter, ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
2
+ export { FilterUtil } from "../../feature/FilterUtil/index.js";
@@ -0,0 +1,4 @@
1
+ export { ValueFilter, ValueFilterRegistry } from "../../feature/ValueFilter/index.js";
2
+ export { FilterUtil } from "../../feature/FilterUtil/index.js";
3
+
4
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ValueFilter","ValueFilterRegistry","FilterUtil"],"sources":["db.ts"],"sourcesContent":["export { ValueFilter, ValueFilterRegistry } from \"~/feature/ValueFilter/index.js\";\nexport { FilterUtil } from \"~/feature/FilterUtil/index.js\";\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,mBAAmB;AACzC,SAASC,UAAU","ignoreList":[]}
@@ -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,28 @@
1
+ import { FilterUtil as Abstraction } 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
+ /**
15
+ * No point in going through all the items when there are no filters to be applied.
16
+ */
17
+ if (!filterFn) {
18
+ return params.items;
19
+ }
20
+ return params.items.filter(filterFn);
21
+ }
22
+ }
23
+ export const FilterUtil = Abstraction.createImplementation({
24
+ implementation: FilterUtilImpl,
25
+ dependencies: [ValueFilterRegistry]
26
+ });
27
+
28
+ //# sourceMappingURL=FilterUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilterUtil","Abstraction","ValueFilterRegistry","createFilterCallable","FilterUtilImpl","constructor","filterRegistry","filter","params","filterFn","where","fields","items","createImplementation","implementation","dependencies"],"sources":["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"],"mappings":"AAAA,SAASA,UAAU,IAAIC,WAAW;AAClC,SAASC,mBAAmB;AAC5B,SAASC,oBAAoB;AAE7B,MAAMC,cAAc,CAAkC;EAC3CC,WAAWA,CAAkBC,cAA6C,EAAE;IAAA,KAA/CA,cAA6C,GAA7CA,cAA6C;EAAG;EAE7EC,MAAMA,CAAUC,MAA6B,EAAO;IACvD,MAAMC,QAAQ,GAAGN,oBAAoB,CAAC;MAClCG,cAAc,EAAE,IAAI,CAACA,cAAc;MACnCI,KAAK,EAAEF,MAAM,CAACE,KAAK;MACnBC,MAAM,EAAEH,MAAM,CAACG;IACnB,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAI,CAACF,QAAQ,EAAE;MACX,OAAOD,MAAM,CAACI,KAAK;IACvB;IACA,OAAOJ,MAAM,CAACI,KAAK,CAACL,MAAM,CAACE,QAAQ,CAAC;EACxC;AACJ;AAEA,OAAO,MAAMT,UAAU,GAAGC,WAAW,CAACY,oBAAoB,CAAC;EACvDC,cAAc,EAAEV,cAAc;EAC9BW,YAAY,EAAE,CAACb,mBAAmB;AACtC,CAAC,CAAC","ignoreList":[]}
@@ -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,4 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ export const FilterUtil = createAbstraction("Db/DynamoDB/FilterUtil");
3
+
4
+ //# sourceMappingURL=FilterUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","FilterUtil"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAgBvD,OAAO,MAAMC,UAAU,GAAGD,iBAAiB,CAAc,wBAAwB,CAAC","ignoreList":[]}
@@ -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 {};
@@ -1,52 +1,21 @@
1
1
  import * as dotProp from "dot-prop";
2
- import WebinyError from "@webiny/error";
3
- import { ValueFilterPlugin } from "../plugins/definitions/ValueFilterPlugin.js";
4
- const getMappedPlugins = params => {
5
- return params.plugins.byType(params.type).reduce((plugins, plugin) => {
6
- /**
7
- * We expect op to be a string, that is why we cast.
8
- */
9
- const op = plugin[params.property];
10
- plugins[op] = plugin;
11
- return plugins;
12
- }, {});
13
- };
14
- const extractWhereArgs = key => {
15
- const result = key.split("_");
16
- const field = result.shift();
17
- const rawOp = result.length === 0 ? "eq" : result.join("_");
18
- /**
19
- * When rawOp is not, it means it is equal negated so just return that.
20
- */
21
- if (rawOp === "not") {
22
- return {
23
- field,
24
- operation: "eq",
25
- negate: true
26
- };
27
- }
28
- const negate = rawOp.match("not_") !== null;
29
- const operation = rawOp.replace("not_", "");
30
- return {
31
- field,
32
- operation,
33
- negate
34
- };
35
- };
36
- const findFilterPlugin = (plugins, operation) => {
37
- if (plugins[operation]) {
38
- return plugins[operation];
2
+ import { WebinyError } from "@webiny/error";
3
+ import { extractWhereArgs } from "./extractWhereArgs.js";
4
+ const findFilter = (registry, operation) => {
5
+ const filter = registry.get(operation);
6
+ if (filter) {
7
+ return filter;
39
8
  }
40
9
  throw new WebinyError(`Missing filter plugin definition.`, "FILTER_PLUGIN_ERROR", {
41
10
  operation
42
11
  });
43
12
  };
44
13
  const multiSearchFieldOperations = ["contains", "fuzzy"];
45
- const createFilters = params => {
14
+ export const createFilters = params => {
46
15
  const {
47
- plugins,
48
16
  where,
49
- fields
17
+ fields,
18
+ filterRegistry
50
19
  } = params;
51
20
  const keys = Object.keys(where);
52
21
  /**
@@ -55,11 +24,6 @@ const createFilters = params => {
55
24
  if (keys.length === 0) {
56
25
  return [];
57
26
  }
58
- const filterPlugins = getMappedPlugins({
59
- plugins,
60
- type: ValueFilterPlugin.type,
61
- property: "operation"
62
- });
63
27
  return keys.reduce((filters, key) => {
64
28
  const compareValue = where[key];
65
29
  if (compareValue === undefined) {
@@ -81,11 +45,11 @@ const createFilters = params => {
81
45
  }
82
46
  return field;
83
47
  });
84
- const filterPlugin = findFilterPlugin(filterPlugins, key);
48
+ const filter = findFilter(filterRegistry, key);
85
49
  filters.push({
86
- operation: filterPlugin.operation,
50
+ operation: filter.operation,
87
51
  compareValue: data.value,
88
- filterPlugin,
52
+ filter,
89
53
  transformValue,
90
54
  paths,
91
55
  negate: false
@@ -97,7 +61,7 @@ const createFilters = params => {
97
61
  operation,
98
62
  negate
99
63
  } = extractWhereArgs(key);
100
- const filterPlugin = findFilterPlugin(filterPlugins, operation);
64
+ const filter = findFilter(filterRegistry, operation);
101
65
  const fieldPlugin = fields.find(plugin => plugin.getField() === field);
102
66
  let path = field;
103
67
  let transformValue = undefined;
@@ -108,9 +72,9 @@ const createFilters = params => {
108
72
  path = fieldPlugin.getPath();
109
73
  }
110
74
  filters.push({
111
- operation: filterPlugin.operation,
75
+ operation: filter.operation,
112
76
  compareValue,
113
- filterPlugin,
77
+ filter,
114
78
  transformValue,
115
79
  paths: [path],
116
80
  negate
@@ -118,6 +82,7 @@ const createFilters = params => {
118
82
  return filters;
119
83
  }, []);
120
84
  };
85
+
121
86
  /**
122
87
  * Transforms the value with given transformer callable.
123
88
  */
@@ -130,10 +95,11 @@ const transform = (value, transformValue) => {
130
95
  }
131
96
  return transformValue(value);
132
97
  };
98
+
133
99
  /**
134
100
  * Creates a filter callable that we can send to the .filter() method of the array.
135
101
  */
136
- const createFilterCallable = params => {
102
+ export const createFilterCallable = params => {
137
103
  const filters = createFilters(params);
138
104
  /**
139
105
  * Just return null so there are no filters to be applied.
@@ -147,7 +113,7 @@ const createFilterCallable = params => {
147
113
  const result = filter.paths.some(path => {
148
114
  const value = transform(dotProp.getProperty(item, path), filter.transformValue);
149
115
  const compareValue = transform(filter.compareValue, filter.transformValue);
150
- const matched = filter.filterPlugin.matches({
116
+ const matched = filter.filter.matches({
151
117
  value,
152
118
  compareValue
153
119
  });
@@ -160,15 +126,5 @@ const createFilterCallable = params => {
160
126
  return true;
161
127
  };
162
128
  };
163
- export function filterItems(params) {
164
- const filter = createFilterCallable(params);
165
- /**
166
- * No point in going through all the items when there are no filters to be applied.
167
- */
168
- if (!filter) {
169
- return params.items;
170
- }
171
- return params.items.filter(filter);
172
- }
173
129
 
174
- //# sourceMappingURL=filter.js.map
130
+ //# sourceMappingURL=createFilters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["dotProp","WebinyError","extractWhereArgs","findFilter","registry","operation","filter","get","multiSearchFieldOperations","createFilters","params","where","fields","filterRegistry","keys","Object","length","reduce","filters","key","compareValue","undefined","includes","data","transformValue","paths","map","field","fieldPlugin","find","plugin","getField","value","getPath","push","negate","path","transform","Array","isArray","v","createFilterCallable","item","result","some","getProperty","matched","matches"],"sources":["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"],"mappings":"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","ignoreList":[]}
@@ -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,24 @@
1
+ export const extractWhereArgs = key => {
2
+ const result = key.split("_");
3
+ const field = result.shift();
4
+ const rawOp = result.length === 0 ? "eq" : result.join("_");
5
+ /**
6
+ * When rawOp is not, it means it is equal negated so just return that.
7
+ */
8
+ if (rawOp === "not") {
9
+ return {
10
+ field,
11
+ operation: "eq",
12
+ negate: true
13
+ };
14
+ }
15
+ const negate = rawOp.match("not_") !== null;
16
+ const operation = rawOp.replace("not_", "");
17
+ return {
18
+ field,
19
+ operation,
20
+ negate
21
+ };
22
+ };
23
+
24
+ //# sourceMappingURL=extractWhereArgs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["extractWhereArgs","key","result","split","field","shift","rawOp","length","join","operation","negate","match","replace"],"sources":["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"],"mappings":"AAMA,OAAO,MAAMA,gBAAgB,GAAIC,GAAW,IAA6B;EACrE,MAAMC,MAAM,GAAGD,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC;EAC7B,MAAMC,KAAK,GAAGF,MAAM,CAACG,KAAK,CAAC,CAAW;EACtC,MAAMC,KAAK,GAAGJ,MAAM,CAACK,MAAM,KAAK,CAAC,GAAG,IAAI,GAAGL,MAAM,CAACM,IAAI,CAAC,GAAG,CAAC;EAC3D;AACJ;AACA;EACI,IAAIF,KAAK,KAAK,KAAK,EAAE;IACjB,OAAO;MACHF,KAAK;MACLK,SAAS,EAAE,IAAI;MACfC,MAAM,EAAE;IACZ,CAAC;EACL;EACA,MAAMA,MAAM,GAAGJ,KAAK,CAACK,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;EAC3C,MAAMF,SAAS,GAAGH,KAAK,CAACM,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;EAC3C,OAAO;IACHR,KAAK;IACLK,SAAS;IACTC;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const FilterUtilFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
@@ -0,0 +1,10 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { FilterUtil } from "./FilterUtil.js";
3
+ export const FilterUtilFeature = createFeature({
4
+ name: "Db/DynamoDB/FilterUtilFeature",
5
+ register: container => {
6
+ container.register(FilterUtil);
7
+ }
8
+ });
9
+
10
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","FilterUtil","FilterUtilFeature","name","register","container"],"sources":["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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,UAAU;AAEnB,OAAO,MAAMC,iBAAiB,GAAGF,aAAa,CAAC;EAC3CG,IAAI,EAAE,+BAA+B;EACrCC,QAAQ,EAAEC,SAAS,IAAI;IACnBA,SAAS,CAACD,QAAQ,CAACH,UAAU,CAAC;EAClC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export { FilterUtil } from "./abstractions/FilterUtil.js";
2
+ export { FilterUtilFeature } from "./feature.js";
@@ -0,0 +1,4 @@
1
+ export { FilterUtil } from "./abstractions/FilterUtil.js";
2
+ export { FilterUtilFeature } from "./feature.js";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FilterUtil","FilterUtilFeature"],"sources":["index.ts"],"sourcesContent":["export { FilterUtil } from \"./abstractions/FilterUtil.js\";\nexport { FilterUtilFeature } from \"./feature.js\";\n"],"mappings":"AAAA,SAASA,UAAU;AACnB,SAASC,iBAAiB","ignoreList":[]}
@@ -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,23 @@
1
+ import { ValueFilterRegistry as Abstraction } 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 => {
9
+ return filter.is(operation);
10
+ });
11
+ }
12
+ getAll() {
13
+ return this.filters;
14
+ }
15
+ }
16
+ export const ValueFilterRegistry = Abstraction.createImplementation({
17
+ implementation: ValueFilterRegistryImpl,
18
+ dependencies: [[ValueFilter, {
19
+ multiple: true
20
+ }]]
21
+ });
22
+
23
+ //# sourceMappingURL=ValueFilterRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ValueFilterRegistry","Abstraction","ValueFilter","ValueFilterRegistryImpl","constructor","filters","get","operation","find","filter","is","getAll","createImplementation","implementation","dependencies","multiple"],"sources":["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"],"mappings":"AAAA,SAASA,mBAAmB,IAAIC,WAAW;AAC3C,SAASC,WAAW;AAEpB,MAAMC,uBAAuB,CAAkC;EACpDC,WAAWA,CAAkBC,OAAgC,EAAE;IAAA,KAAlCA,OAAgC,GAAhCA,OAAgC;EAAG;EAEhEC,GAAGA,CAACC,SAAiB,EAAqC;IAC7D,OAAO,IAAI,CAACF,OAAO,CAACG,IAAI,CAACC,MAAM,IAAI;MAC/B,OAAOA,MAAM,CAACC,EAAE,CAACH,SAAS,CAAC;IAC/B,CAAC,CAAC;EACN;EAEOI,MAAMA,CAAA,EAA4B;IACrC,OAAO,IAAI,CAACN,OAAO;EACvB;AACJ;AAEA,OAAO,MAAML,mBAAmB,GAAGC,WAAW,CAACW,oBAAoB,CAAC;EAChEC,cAAc,EAAEV,uBAAuB;EACvCW,YAAY,EAAE,CAAC,CAACZ,WAAW,EAAE;IAAEa,QAAQ,EAAE;EAAK,CAAC,CAAC;AACpD,CAAC,CAAC","ignoreList":[]}
@@ -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,4 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ export const ValueFilter = createAbstraction("Db/DynamoDB/ValueFilter");
3
+
4
+ //# sourceMappingURL=ValueFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","ValueFilter"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAqBvD,OAAO,MAAMC,WAAW,GAAGD,iBAAiB,CAAe,yBAAyB,CAAC","ignoreList":[]}
@@ -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,4 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ export const ValueFilterRegistry = createAbstraction("Db/DynamoDB/ValueFilterRegistry");
3
+
4
+ //# sourceMappingURL=ValueFilterRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAbstraction","ValueFilterRegistry"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAQvD,OAAO,MAAMC,mBAAmB,GAAGD,iBAAiB,CAChD,iCACJ,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const ValueFilterFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
@@ -0,0 +1,32 @@
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
+ export 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
+
32
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFeature","EqFilter","GtFilter","GteFilter","LtFilter","LteFilter","BetweenFilter","InFilter","AndInFilter","ContainsFilter","FuzzyFilter","StartsWithFilter","ValueFilterRegistry","ValueFilterFeature","name","register","container"],"sources":["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"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,QAAQ;AACjB,SAASC,QAAQ;AACjB,SAASC,SAAS;AAClB,SAASC,QAAQ;AACjB,SAASC,SAAS;AAClB,SAASC,aAAa;AACtB,SAASC,QAAQ;AACjB,SAASC,WAAW;AACpB,SAASC,cAAc;AACvB,SAASC,WAAW;AACpB,SAASC,gBAAgB;AACzB,SAASC,mBAAmB;AAE5B,OAAO,MAAMC,kBAAkB,GAAGb,aAAa,CAAC;EAC5Cc,IAAI,EAAE,gCAAgC;EACtCC,QAAQ,EAAEC,SAAS,IAAI;IACnBA,SAAS,CAACD,QAAQ,CAACd,QAAQ,CAAC;IAC5Be,SAAS,CAACD,QAAQ,CAACb,QAAQ,CAAC;IAC5Bc,SAAS,CAACD,QAAQ,CAACZ,SAAS,CAAC;IAC7Ba,SAAS,CAACD,QAAQ,CAACX,QAAQ,CAAC;IAC5BY,SAAS,CAACD,QAAQ,CAACV,SAAS,CAAC;IAC7BW,SAAS,CAACD,QAAQ,CAACT,aAAa,CAAC;IACjCU,SAAS,CAACD,QAAQ,CAACR,QAAQ,CAAC;IAC5BS,SAAS,CAACD,QAAQ,CAACP,WAAW,CAAC;IAC/BQ,SAAS,CAACD,QAAQ,CAACN,cAAc,CAAC;IAClCO,SAAS,CAACD,QAAQ,CAACL,WAAW,CAAC;IAC/BM,SAAS,CAACD,QAAQ,CAACJ,gBAAgB,CAAC;IACpCK,SAAS,CAACD,QAAQ,CAACH,mBAAmB,CAAC;EAC3C;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -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,32 @@
1
+ import { WebinyError } from "@webiny/error";
2
+ import { ValueFilter } from "../abstractions/ValueFilter.js";
3
+ class AndInFilterImpl {
4
+ operation = "and_in";
5
+ is(operation) {
6
+ return this.operation === operation;
7
+ }
8
+ canUse() {
9
+ return true;
10
+ }
11
+ matches({
12
+ value,
13
+ compareValue
14
+ }) {
15
+ if (!compareValue || Array.isArray(compareValue) === false) {
16
+ throw new WebinyError(`The value given as "compareValue" must be an array!`, "COMPARE_VALUE_ERROR", {
17
+ value,
18
+ compareValue
19
+ });
20
+ }
21
+ if (Array.isArray(value) === true) {
22
+ return compareValue.every(c => value.includes(c));
23
+ }
24
+ return compareValue.includes(value);
25
+ }
26
+ }
27
+ export const AndInFilter = ValueFilter.createImplementation({
28
+ implementation: AndInFilterImpl,
29
+ dependencies: []
30
+ });
31
+
32
+ //# sourceMappingURL=AndInFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["WebinyError","ValueFilter","AndInFilterImpl","operation","is","canUse","matches","value","compareValue","Array","isArray","every","c","includes","AndInFilter","createImplementation","implementation","dependencies"],"sources":["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"],"mappings":"AAAA,SAASA,WAAW,QAAQ,eAAe;AAC3C,SAASC,WAAW;AAEpB,MAAMC,eAAe,CAAkC;EACnCC,SAAS,GAAG,QAAQ;EAE7BC,EAAEA,CAACD,SAAiB,EAAW;IAClC,OAAO,IAAI,CAACA,SAAS,KAAKA,SAAS;EACvC;EAEOE,MAAMA,CAAA,EAAY;IACrB,OAAO,IAAI;EACf;EAEOC,OAAOA,CAAC;IAAEC,KAAK;IAAEC;EAAwC,CAAC,EAAsB;IACnF,IAAI,CAACA,YAAY,IAAIC,KAAK,CAACC,OAAO,CAACF,YAAY,CAAC,KAAK,KAAK,EAAE;MACxD,MAAM,IAAIR,WAAW,CACjB,qDAAqD,EACrD,qBAAqB,EACrB;QACIO,KAAK;QACLC;MACJ,CACJ,CAAC;IACL;IACA,IAAIC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,KAAK,IAAI,EAAE;MAC/B,OAAOC,YAAY,CAACG,KAAK,CAAEC,CAAM,IAAKL,KAAK,CAACM,QAAQ,CAACD,CAAC,CAAC,CAAC;IAC5D;IACA,OAAOJ,YAAY,CAACK,QAAQ,CAACN,KAAK,CAAC;EACvC;AACJ;AAEA,OAAO,MAAMO,WAAW,GAAGb,WAAW,CAACc,oBAAoB,CAAC;EACxDC,cAAc,EAAEd,eAAe;EAC/Be,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
@@ -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 {};
@@ -1,11 +1,17 @@
1
- import WebinyError from "@webiny/error";
2
- import { ValueFilterPlugin } from "../definitions/ValueFilterPlugin.js";
3
- const plugin = new ValueFilterPlugin({
4
- operation: "between",
5
- matches: ({
1
+ import { WebinyError } from "@webiny/error";
2
+ import { ValueFilter } from "../abstractions/ValueFilter.js";
3
+ class BetweenFilterImpl {
4
+ operation = "between";
5
+ is(operation) {
6
+ return this.operation === operation;
7
+ }
8
+ canUse() {
9
+ return true;
10
+ }
11
+ matches({
6
12
  value,
7
13
  compareValue
8
- }) => {
14
+ }) {
9
15
  if (Array.isArray(compareValue)) {
10
16
  if (compareValue.length !== 2) {
11
17
  throw new WebinyError("When comparing between and you give an array, there must be two items in it.", "FILTER_ERROR", {
@@ -18,8 +24,10 @@ const plugin = new ValueFilterPlugin({
18
24
  }
19
25
  return value >= compareValue && value <= compareValue;
20
26
  }
27
+ }
28
+ export const BetweenFilter = ValueFilter.createImplementation({
29
+ implementation: BetweenFilterImpl,
30
+ dependencies: []
21
31
  });
22
- plugin.name = "dynamodb.value.filter.between";
23
- export default plugin;
24
32
 
25
- //# sourceMappingURL=between.js.map
33
+ //# sourceMappingURL=BetweenFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["WebinyError","ValueFilter","BetweenFilterImpl","operation","is","canUse","matches","value","compareValue","Array","isArray","length","from","to","BetweenFilter","createImplementation","implementation","dependencies"],"sources":["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"],"mappings":"AAAA,SAASA,WAAW,QAAQ,eAAe;AAC3C,SAASC,WAAW;AAEpB,MAAMC,iBAAiB,CAAkC;EACrCC,SAAS,GAAG,SAAS;EAE9BC,EAAEA,CAACD,SAAiB,EAAW;IAClC,OAAO,IAAI,CAACA,SAAS,KAAKA,SAAS;EACvC;EAEOE,MAAMA,CAAA,EAAY;IACrB,OAAO,IAAI;EACf;EAEOC,OAAOA,CAAC;IAAEC,KAAK;IAAEC;EAAwC,CAAC,EAAsB;IACnF,IAAIC,KAAK,CAACC,OAAO,CAACF,YAAY,CAAC,EAAE;MAC7B,IAAIA,YAAY,CAACG,MAAM,KAAK,CAAC,EAAE;QAC3B,MAAM,IAAIX,WAAW,CACjB,8EAA8E,EAC9E,cAAc,EACd;UACIO,KAAK;UACLC;QACJ,CACJ,CAAC;MACL;MACA,MAAM,CAACI,IAAI,EAAEC,EAAE,CAAC,GAAGL,YAAY;MAC/B,OAAOD,KAAK,IAAIK,IAAI,IAAIL,KAAK,IAAIM,EAAE;IACvC;IACA,OAAON,KAAK,IAAIC,YAAY,IAAID,KAAK,IAAIC,YAAY;EACzD;AACJ;AAEA,OAAO,MAAMM,aAAa,GAAGb,WAAW,CAACc,oBAAoB,CAAC;EAC1DC,cAAc,EAAEd,iBAAiB;EACjCe,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}