@webiny/api-headless-cms-ddb 5.34.8 → 5.35.0-beta.1

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 (91) hide show
  1. package/definitions/entry.js +3 -5
  2. package/definitions/entry.js.map +1 -1
  3. package/definitions/group.js +0 -5
  4. package/definitions/group.js.map +1 -1
  5. package/definitions/model.js +17 -5
  6. package/definitions/model.js.map +1 -1
  7. package/definitions/settings.js +0 -5
  8. package/definitions/settings.js.map +1 -1
  9. package/definitions/system.js +0 -5
  10. package/definitions/system.js.map +1 -1
  11. package/definitions/table.js +0 -3
  12. package/definitions/table.js.map +1 -1
  13. package/dynamoDb/index.js +0 -7
  14. package/dynamoDb/index.js.map +1 -1
  15. package/dynamoDb/path/plainObject.js +1 -8
  16. package/dynamoDb/path/plainObject.js.map +1 -1
  17. package/dynamoDb/storage/date.js +1 -19
  18. package/dynamoDb/storage/date.js.map +1 -1
  19. package/dynamoDb/storage/longText.js +1 -18
  20. package/dynamoDb/storage/longText.js.map +1 -1
  21. package/dynamoDb/storage/richText.js +0 -18
  22. package/dynamoDb/storage/richText.js.map +1 -1
  23. package/dynamoDb/transformValue/datetime.js +1 -8
  24. package/dynamoDb/transformValue/datetime.js.map +1 -1
  25. package/index.js +6 -30
  26. package/index.js.map +1 -1
  27. package/operations/entry/dataLoaders.js +1 -44
  28. package/operations/entry/dataLoaders.js.map +1 -1
  29. package/operations/entry/filtering/createExpressions.js +2 -39
  30. package/operations/entry/filtering/createExpressions.js.map +1 -1
  31. package/operations/entry/filtering/createFields.js +0 -18
  32. package/operations/entry/filtering/createFields.js.map +1 -1
  33. package/operations/entry/filtering/extractSort.js +0 -10
  34. package/operations/entry/filtering/extractSort.js.map +1 -1
  35. package/operations/entry/filtering/filter.js +1 -36
  36. package/operations/entry/filtering/filter.js.map +1 -1
  37. package/operations/entry/filtering/fullTextSearch.js +0 -12
  38. package/operations/entry/filtering/fullTextSearch.js.map +1 -1
  39. package/operations/entry/filtering/getValue.js +0 -18
  40. package/operations/entry/filtering/getValue.js.map +1 -1
  41. package/operations/entry/filtering/index.js +0 -2
  42. package/operations/entry/filtering/index.js.map +1 -1
  43. package/operations/entry/filtering/mapPlugins.js +0 -8
  44. package/operations/entry/filtering/mapPlugins.js.map +1 -1
  45. package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -7
  46. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
  47. package/operations/entry/filtering/plugins/index.js +0 -5
  48. package/operations/entry/filtering/plugins/index.js.map +1 -1
  49. package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -21
  50. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
  51. package/operations/entry/filtering/plugins/refFilterCreate.js +0 -18
  52. package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
  53. package/operations/entry/filtering/sort.js +0 -15
  54. package/operations/entry/filtering/sort.js.map +1 -1
  55. package/operations/entry/filtering/systemFields.js +0 -2
  56. package/operations/entry/filtering/systemFields.js.map +1 -1
  57. package/operations/entry/filtering/transform.js +0 -3
  58. package/operations/entry/filtering/transform.js.map +1 -1
  59. package/operations/entry/filtering/values.js +0 -6
  60. package/operations/entry/filtering/values.js.map +1 -1
  61. package/operations/entry/filtering/where.js +0 -6
  62. package/operations/entry/filtering/where.js.map +1 -1
  63. package/operations/entry/index.js +58 -116
  64. package/operations/entry/index.js.map +1 -1
  65. package/operations/entry/keys.js +0 -18
  66. package/operations/entry/keys.js.map +1 -1
  67. package/operations/entry/systemFields.js +0 -2
  68. package/operations/entry/systemFields.js.map +1 -1
  69. package/operations/group/index.js +2 -32
  70. package/operations/group/index.js.map +1 -1
  71. package/operations/model/index.js +0 -25
  72. package/operations/model/index.js.map +1 -1
  73. package/operations/settings/index.js +0 -24
  74. package/operations/settings/index.js.map +1 -1
  75. package/operations/system/index.js +0 -17
  76. package/operations/system/index.js.map +1 -1
  77. package/package.json +13 -13
  78. package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -14
  79. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
  80. package/plugins/CmsEntryFieldFilterPlugin.js +0 -7
  81. package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
  82. package/plugins/CmsEntryFieldSortingPlugin.js +0 -10
  83. package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
  84. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
  85. package/plugins/CmsFieldFilterValueTransformPlugin.js +24 -0
  86. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
  87. package/plugins/index.d.ts +1 -0
  88. package/plugins/index.js +11 -6
  89. package/plugins/index.js.map +1 -1
  90. package/types.js +0 -1
  91. package/types.js.map +1 -1
@@ -1,26 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.filter = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  var _fullTextSearch = require("./fullTextSearch");
17
-
18
12
  var _createExpressions = require("./createExpressions");
19
-
20
13
  var _transform = require("./transform");
21
-
22
14
  var _getValue = require("./getValue");
23
-
24
15
  const executeFilter = params => {
25
16
  const {
26
17
  value,
@@ -30,14 +21,11 @@ const executeFilter = params => {
30
21
  value,
31
22
  compareValue: filter.compareValue
32
23
  });
33
-
34
24
  if (filter.negate) {
35
25
  return matched === false;
36
26
  }
37
-
38
27
  return matched;
39
28
  };
40
-
41
29
  const executeExpressions = params => {
42
30
  const {
43
31
  expressions,
@@ -45,15 +33,12 @@ const executeExpressions = params => {
45
33
  filters,
46
34
  condition
47
35
  } = params;
48
-
49
36
  if (expressions.length === 0 && filters.length === 0) {
50
37
  return true;
51
38
  }
52
39
  /**
53
40
  * Always run filters first as they might trigger an early return.
54
41
  */
55
-
56
-
57
42
  for (const filter of filters) {
58
43
  const value = getCachedValue(filter);
59
44
  const result = executeFilter({
@@ -64,7 +49,6 @@ const executeExpressions = params => {
64
49
  * Filters are ALWAYS executed as an AND.
65
50
  * So if even one is false, everything false.
66
51
  */
67
-
68
52
  if (!result) {
69
53
  return false;
70
54
  }
@@ -72,13 +56,10 @@ const executeExpressions = params => {
72
56
  /**
73
57
  * Then we move onto expressions, which are basically nested upon nested filters with different conditions.
74
58
  */
75
-
76
-
77
59
  for (const expression of expressions) {
78
60
  const result = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
79
61
  getCachedValue
80
62
  }));
81
-
82
63
  if (result && condition === "OR") {
83
64
  return true;
84
65
  } else if (!result && condition == "AND") {
@@ -90,11 +71,8 @@ const executeExpressions = params => {
90
71
  *
91
72
  * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.
92
73
  */
93
-
94
-
95
74
  return condition === "OR" ? false : true;
96
75
  };
97
-
98
76
  const filter = params => {
99
77
  const {
100
78
  items: records,
@@ -104,34 +82,28 @@ const filter = params => {
104
82
  fullTextSearch
105
83
  } = params;
106
84
  const keys = Object.keys(where);
107
-
108
85
  if (keys.length === 0 && !fullTextSearch) {
109
86
  return records;
110
87
  }
111
-
112
88
  const expression = (0, _createExpressions.createExpressions)({
113
89
  plugins,
114
90
  where,
115
91
  fields
116
92
  });
93
+
117
94
  /**
118
95
  * No point in going further if there are no expressions to be applied and no full text search to be executed.
119
96
  */
120
-
121
97
  if (expression.filters.length === 0 && expression.expressions.length === 0 && !(fullTextSearch !== null && fullTextSearch !== void 0 && fullTextSearch.term)) {
122
98
  return records;
123
99
  }
124
100
  /**
125
101
  * We need the contains plugin to run the full text search.
126
102
  */
127
-
128
-
129
103
  const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
130
-
131
104
  if (!fullTextSearchPlugin) {
132
105
  throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
133
106
  }
134
-
135
107
  const search = (0, _fullTextSearch.createFullTextSearch)({
136
108
  term: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.term,
137
109
  targetFields: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.fields,
@@ -140,16 +112,13 @@ const filter = params => {
140
112
  });
141
113
  return records.filter(record => {
142
114
  const cachedValues = {};
143
-
144
115
  const getCachedValue = filter => {
145
116
  const {
146
117
  path
147
118
  } = filter;
148
-
149
119
  if (cachedValues[path] !== undefined) {
150
120
  return cachedValues[path];
151
121
  }
152
-
153
122
  const plainValue = (0, _getValue.getValue)(record, path);
154
123
  const rawValue = (0, _transform.transformValue)({
155
124
  value: plainValue,
@@ -158,7 +127,6 @@ const filter = params => {
158
127
  cachedValues[path] = rawValue;
159
128
  return rawValue;
160
129
  };
161
-
162
130
  const exprResult = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
163
131
  getCachedValue
164
132
  }));
@@ -166,13 +134,10 @@ const filter = params => {
166
134
  * If expression result is false we do not need to continue further.
167
135
  * Also, if there is no full text search defined, just return the expression result.
168
136
  */
169
-
170
137
  if (!exprResult || !search) {
171
138
  return exprResult;
172
139
  }
173
-
174
140
  return search(record);
175
141
  });
176
142
  };
177
-
178
143
  exports.filter = filter;
@@ -1 +1 @@
1
- {"version":3,"names":["executeFilter","params","value","filter","matched","plugin","matches","compareValue","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","createExpressions","term","fullTextSearchPlugin","byType","ValueFilterPlugin","type","find","getOperation","WebinyError","search","createFullTextSearch","targetFields","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import { CmsEntry, CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { createFullTextSearch } from \"./fullTextSearch\";\nimport { createExpressions, Expression, ExpressionCondition, Filter } from \"./createExpressions\";\nimport { transformValue } from \"./transform\";\nimport { getValue } from \"~/operations/entry/filtering/getValue\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n const matched = filter.plugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface Params {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = (params: Params): CmsEntry[] => {\n const { items: records, where, plugins, fields, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n plugin: fullTextSearchPlugin\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AAOA,MAAMA,aAAa,GAAIC,MAAD,IAAiC;EACnD,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAoBF,MAA1B;EAEA,MAAMG,OAAO,GAAGD,MAAM,CAACE,MAAP,CAAcC,OAAd,CAAsB;IAClCJ,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AD,CAAZ,KAAuBC,SAA3B,EAAsC;QAClC,OAAOF,YAAY,CAACC,IAAD,CAAnB;MACH;;MACD,MAAME,UAAU,GAAG,IAAAC,kBAAA,EAASL,MAAT,EAAiBE,IAAjB,CAAnB;MAEA,MAAMI,QAAQ,GAAG,IAAAC,yBAAA,EAAe;QAC5B1C,KAAK,EAAEuC,UADqB;QAE5BI,SAAS,EAAE1C,MAAM,CAACyC;MAFU,CAAf,CAAjB;MAKAN,YAAY,CAACC,IAAD,CAAZ,GAAqBI,QAArB;MACA,OAAOA,QAAP;IACH,CAdD;;IAgBA,MAAMG,UAAU,GAAGrC,kBAAkB,6DAAMO,UAAN;MAAkBL;IAAlB,GAArC;IACA;AACR;AACA;AACA;;IACQ,IAAI,CAACmC,UAAD,IAAe,CAACZ,MAApB,EAA4B;MACxB,OAAOY,UAAP;IACH;;IAED,OAAOZ,MAAM,CAACG,MAAD,CAAb;EACH,CA7BM,CAAP;AA8BH,CAzEM"}
1
+ {"version":3,"names":["executeFilter","params","value","filter","matched","plugin","matches","compareValue","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","createExpressions","term","fullTextSearchPlugin","byType","ValueFilterPlugin","type","find","getOperation","WebinyError","search","createFullTextSearch","targetFields","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import { CmsEntry, CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { createFullTextSearch } from \"./fullTextSearch\";\nimport { createExpressions, Expression, ExpressionCondition, Filter } from \"./createExpressions\";\nimport { transformValue } from \"./transform\";\nimport { getValue } from \"~/operations/entry/filtering/getValue\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n const matched = filter.plugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface Params {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = (params: Params): CmsEntry[] => {\n const { items: records, where, plugins, fields, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n plugin: fullTextSearchPlugin\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"mappings":";;;;;;;;AACA;AACA;AAGA;AACA;AACA;AACA;AAOA,MAAMA,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEhC,MAAMG,OAAO,GAAGD,MAAM,CAACE,MAAM,CAACC,OAAO,CAAC;IAClCJ,KAAK;IACLK,YAAY,EAAEJ,MAAM,CAACI;EACzB,CAAC,CAAC;EACF,IAAIJ,MAAM,CAACK,MAAM,EAAE;IACf,OAAOJ,OAAO,KAAK,KAAK;EAC5B;EACA,OAAOA,OAAO;AAClB,CAAC;AASD,MAAMK,kBAAkB,GAAIR,MAAgC,IAAc;EACtE,MAAM;IAAES,WAAW;IAAEC,cAAc;IAAEC,OAAO;IAAEC;EAAU,CAAC,GAAGZ,MAAM;EAClE,IAAIS,WAAW,CAACI,MAAM,KAAK,CAAC,IAAIF,OAAO,CAACE,MAAM,KAAK,CAAC,EAAE;IA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CAACmC,UAAU,IAAI,CAACZ,MAAM,EAAE;MACxB,OAAOY,UAAU;IACrB;IAEA,OAAOZ,MAAM,CAACG,MAAM,CAAC;EACzB,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createFullTextSearch = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  var _getValue = require("./getValue");
13
-
14
10
  /**
15
11
  * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
16
12
  */
@@ -21,30 +17,24 @@ const createFullTextSearch = params => {
21
17
  fields: fieldDefinitions,
22
18
  plugin
23
19
  } = params;
24
-
25
20
  if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
26
21
  return null;
27
22
  }
28
-
29
23
  return item => {
30
24
  for (const target of targetFields) {
31
25
  /**
32
26
  * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.
33
27
  */
34
28
  const field = fieldDefinitions[target];
35
-
36
29
  if (!field) {
37
30
  throw new _error.default(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
38
31
  target
39
32
  });
40
33
  }
41
-
42
34
  const value = (0, _getValue.getValue)(item.values, target);
43
-
44
35
  if (!value) {
45
36
  continue;
46
37
  }
47
-
48
38
  if (plugin.matches({
49
39
  value,
50
40
  compareValue: term
@@ -52,9 +42,7 @@ const createFullTextSearch = params => {
52
42
  return true;
53
43
  }
54
44
  }
55
-
56
45
  return false;
57
46
  };
58
47
  };
59
-
60
48
  exports.createFullTextSearch = createFullTextSearch;
@@ -1 +1 @@
1
- {"version":3,"names":["createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","plugin","trim","length","item","target","field","WebinyError","value","getValue","values","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { Field } from \"./types\";\nimport { getValue } from \"./getValue\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n plugin: ValueFilterPlugin;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, plugin } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item.values, target);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AAIA;;AASA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAIC,MAAD,IAAoB;EACpD,MAAM;IAAEC,IAAF;IAAQC,YAAR;IAAsBC,MAAM,EAAEC,gBAA9B;IAAgDC;EAAhD,IAA2DL,MAAjE;;EACA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACK,IAAL,GAAYC,MAAZ,KAAuB,CAAhC,IAAqC,CAACL,YAAtC,IAAsDA,YAAY,CAACK,MAAb,KAAwB,CAAlF,EAAqF;IACjF,OAAO,IAAP;EACH;;EACD,OAAQC,IAAD,IAAoB;IACvB,KAAK,MAAMC,MAAX,IAAqBP,YAArB,EAAmC;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAD,CAA9B;;MAEA,IAAI,CAACC,KAAL,EAAY;QACR,MAAM,IAAIC,cAAJ,CAAiB,kBAAiBF,MAAO,iBAAzC,EAA2D,eAA3D,EAA4E;UAC9EA;QAD8E,CAA5E,CAAN;MAGH;;MACD,MAAMG,KAAK,GAAG,IAAAC,kBAAA,EAASL,IAAI,CAACM,MAAd,EAAsBL,MAAtB,CAAd;;MACA,IAAI,CAACG,KAAL,EAAY;QACR;MACH;;MACD,IAAIP,MAAM,CAACU,OAAP,CAAe;QAAEH,KAAF;QAASI,YAAY,EAAEf;MAAvB,CAAf,MAAkD,IAAtD,EAA4D;QACxD,OAAO,IAAP;MACH;IACJ;;IACD,OAAO,KAAP;EACH,CArBD;AAsBH,CA3BM"}
1
+ {"version":3,"names":["createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","plugin","trim","length","item","target","field","WebinyError","value","getValue","values","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { Field } from \"./types\";\nimport { getValue } from \"./getValue\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n plugin: ValueFilterPlugin;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, plugin } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item.values, target);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":";;;;;;;AAAA;AAIA;AASA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAIC,MAAc,IAAK;EACpD,MAAM;IAAEC,IAAI;IAAEC,YAAY;IAAEC,MAAM,EAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACvE,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACK,IAAI,EAAE,CAACC,MAAM,KAAK,CAAC,IAAI,CAACL,YAAY,IAAIA,YAAY,CAACK,MAAM,KAAK,CAAC,EAAE;IACjF,OAAO,IAAI;EACf;EACA,OAAQC,IAAc,IAAK;IACvB,KAAK,MAAMC,MAAM,IAAIP,YAAY,EAAE;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAM,CAAC;MAEtC,IAAI,CAACC,KAAK,EAAE;QACR,MAAM,IAAIC,cAAW,CAAE,kBAAiBF,MAAO,iBAAgB,EAAE,eAAe,EAAE;UAC9EA;QACJ,CAAC,CAAC;MACN;MACA,MAAMG,KAAK,GAAG,IAAAC,kBAAQ,EAACL,IAAI,CAACM,MAAM,EAAEL,MAAM,CAAC;MAC3C,IAAI,CAACG,KAAK,EAAE;QACR;MACJ;MACA,IAAIP,MAAM,CAACU,OAAO,CAAC;QAAEH,KAAK;QAAEI,YAAY,EAAEf;MAAK,CAAC,CAAC,KAAK,IAAI,EAAE;QACxD,OAAO,IAAI;MACf;IACJ;IACA,OAAO,KAAK;EAChB,CAAC;AACL,CAAC;AAAC"}
@@ -4,13 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getValue = void 0;
7
-
8
7
  const addArrayResult = (target, result) => {
9
8
  for (const r of result) {
10
9
  if (target.some(t => r === t)) {
11
10
  continue;
12
11
  }
13
-
14
12
  target.push(r);
15
13
  }
16
14
  };
@@ -18,64 +16,48 @@ const addArrayResult = (target, result) => {
18
16
  * A recursive function which goes through given input paths and returns the value in it.
19
17
  * In case a path is an array, it goes through the array of those values to get values further down the path line.
20
18
  */
21
-
22
-
23
19
  const find = (target, input) => {
24
20
  const paths = [...input];
25
21
  const path = paths.shift();
26
-
27
22
  if (!path) {
28
23
  return undefined;
29
24
  } else if (target[path] === undefined) {
30
25
  return undefined;
31
26
  }
32
-
33
27
  const value = target[path];
34
-
35
28
  if (paths.length === 0) {
36
29
  return value;
37
30
  } else if (Array.isArray(value)) {
38
31
  if (value.length === 0) {
39
32
  return undefined;
40
33
  }
41
-
42
34
  return value.reduce((collection, v) => {
43
35
  const result = find(v, paths);
44
-
45
36
  if (result === undefined) {
46
37
  return collection;
47
38
  } else if (Array.isArray(result)) {
48
39
  addArrayResult(collection, result);
49
40
  return collection;
50
41
  }
51
-
52
42
  collection.push(result);
53
43
  return collection;
54
44
  }, []);
55
45
  }
56
-
57
46
  return find(value, paths);
58
47
  };
59
48
  /**
60
49
  * A wrapper function for the find function.
61
50
  * Basically it transforms input paths to an array (and runs various checks).
62
51
  */
63
-
64
-
65
52
  const getValue = (target, input) => {
66
53
  const paths = Array.isArray(input) ? input : input.split(".");
67
-
68
54
  if (paths.length === 0) {
69
55
  throw new Error(`Path is empty!`);
70
56
  }
71
-
72
57
  const filtered = paths.filter(Boolean);
73
-
74
58
  if (paths.length !== filtered.length) {
75
59
  throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
76
60
  }
77
-
78
61
  return find(target, paths);
79
62
  };
80
-
81
63
  exports.getValue = getValue;
@@ -1 +1 @@
1
- {"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any>, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n } else if (target[path] === undefined) {\n return undefined;\n }\n const value = target[path];\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":";;;;;;;AAAA,MAAMA,cAAc,GAAG,CAACC,MAAD,EAAgBC,MAAhB,KAAwC;EAC3D,KAAK,MAAMC,CAAX,IAAgBD,MAAhB,EAAwB;IACpB,IAAID,MAAM,CAACG,IAAP,CAAYC,CAAC,IAAIF,CAAC,KAAKE,CAAvB,CAAJ,EAA+B;MAC3B;IACH;;IACDJ,MAAM,CAACK,IAAP,CAAYH,CAAZ;EACH;AACJ,CAPD;AAQA;AACA;AACA;AACA;;;AACA,MAAMI,IAAI,GAAG,CAACN,MAAD,EAA8BO,KAA9B,KAAqE;EAC9E,MAAMC,KAAK,GAAG,CAAC,GAAGD,KAAJ,CAAd;EACA,MAAME,IAAI,GAAGD,KAAK,CAACE,KAAN,EAAb;;EAEA,IAAI,CAACD,IAAL,EAAW;IACP,OAAOE,SAAP;EACH,CAFD,MAEO,IAAIX,MAAM,CAACS,IAAD,CAAN,KAAiBE,SAArB,EAAgC;IACnC,OAAOA,SAAP;EACH;;EACD,MAAMC,KAAK,GAA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b,KAAK,CAACiB,IAAN,CAC7D,GAD6D,CAE/D,OAAMH,QAAQ,CAACG,IAAT,CAAc,GAAd,CAAmB,GAHzB,CAAN;EAKH;;EAED,OAAOnB,IAAI,CAACN,MAAD,EAASQ,KAAT,CAAX;AACH,CAfM"}
1
+ {"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any>, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n } else if (target[path] === undefined) {\n return undefined;\n }\n const value = target[path];\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":";;;;;;AAAA,MAAMA,cAAc,GAAG,CAACC,MAAa,EAAEC,MAAa,KAAW;EAC3D,KAAK,MAAMC,CAAC,IAAID,MAAM,E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C7B,CAAC;AACD;AACA;AACA;AACA;AACO,MAAMW,QAAQ,GAAG,CAACnB,MAA2B,EAAEO,KAAwB,KAAU;EACpF,MAAMC,KAAK,GAAGM,KAAK,CAACC,OAAO,CAACR,KAAK,CAAC,GAAGA,KAAK,GAAGA,KAAK,CAACa,KAAK,CAAC,GAAG,CAAC;EAC7D,IAAIZ,KAAK,CAACK,MAAM,KAAK,CAAC,EAAE;IACpB,MAAM,IAAIQ,KAAK,CAAE,gBAAe,CAAC;EACrC;EACA,MAAMC,QAAQ,GAAGd,KAAK,CAACe,MAAM,CAACC,OAAO,CAAC;EACtC,IAAIhB,KAAK,CAACK,MAAM,KAAKS,QAAQ,CAACT,MAAM,EAAE;IAClC,MAAM,IAAIQ,KAAK,CACV,iEAAgEb,KAAK,CAACiB,IAAI,CACvE,GAAG,CACL,OAAMH,QAAQ,CAACG,IAAI,CAAC,GAAG,CAAE,GAAE,CAChC;EACL;EAEA,OAAOnB,IAAI,CAACN,MAAM,EAAEQ,KAAK,CAAC;AAC9B,CAAC;AAAC"}
@@ -15,7 +15,5 @@ Object.defineProperty(exports, "sort", {
15
15
  return _sort.sort;
16
16
  }
17
17
  });
18
-
19
18
  var _filter = require("./filter");
20
-
21
19
  var _sort = require("./sort");
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter\";\nexport { sort } from \"./sort\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter\";\nexport { sort } from \"./sort\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AACA"}
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.getMappedPlugins = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  const getMappedPlugins = params => {
13
10
  const {
14
11
  plugins: pluginsContainer,
@@ -16,24 +13,19 @@ const getMappedPlugins = params => {
16
13
  property
17
14
  } = params;
18
15
  const plugins = pluginsContainer.byType(type);
19
-
20
16
  if (plugins.length === 0) {
21
17
  return {};
22
18
  }
23
-
24
19
  return plugins.reduce((collection, plugin) => {
25
20
  const key = plugin[property];
26
-
27
21
  if (typeof key !== "string") {
28
22
  throw new _error.default("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
29
23
  type,
30
24
  property
31
25
  });
32
26
  }
33
-
34
27
  collection[key] = plugin;
35
28
  return collection;
36
29
  }, {});
37
30
  };
38
-
39
31
  exports.getMappedPlugins = getMappedPlugins;
@@ -1 +1 @@
1
- {"version":3,"names":["getMappedPlugins","params","plugins","pluginsContainer","type","property","byType","length","reduce","collection","plugin","key","WebinyError"],"sources":["mapPlugins.ts"],"sourcesContent":["import { Plugin, PluginsContainer } from \"@webiny/plugins/types\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\nexport const getMappedPlugins = <T extends Plugin>(params: Params) => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n return {};\n }\n return plugins.reduce<Record<string, T>>((collection, plugin) => {\n const key: keyof typeof plugin = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {});\n};\n"],"mappings":";;;;;;;;;AACA;;AAOO,MAAMA,gBAAgB,GAAsBC,MAAnB,IAAsC;EAClE,MAAM;IAAEC,OAAO,EAAEC,gBAAX;IAA6BC,IAA7B;IAAmCC;EAAnC,IAAgDJ,MAAtD;EACA,MAAMC,OAAO,GAAGC,gBAAgB,CAACG,MAAjB,CAA2BF,IAA3B,CAAhB;;EACA,IAAIF,OAAO,CAACK,MAAR,KAAmB,CAAvB,EAA0B;IACtB,OAAO,EAAP;EACH;;EACD,OAAOL,OAAO,CAACM,MAAR,CAAkC,CAACC,UAAD,EAAaC,MAAb,KAAwB;IAC7D,MAAMC,GAAwB,GAAGD,MAAM,CAACL,QAAD,CAAvC;;IACA,IAAI,OAAOM,GAAP,KAAe,QAAnB,EAA6B;MACzB,MAAM,IAAIC,cAAJ,CACF,kDADE,EAEF,uBAFE,EAGF;QACIR,IADJ;QAEIC;MAFJ,CAHE,CAAN;IAQH;;IACDI,UAAU,CAACE,GAAD,CAAV,GAAkBD,MAAlB;IACA,OAAOD,UAAP;EACH,CAdM,EAcJ,EAdI,CAAP;AAeH,CArBM"}
1
+ {"version":3,"names":["getMappedPlugins","params","plugins","pluginsContainer","type","property","byType","length","reduce","collection","plugin","key","WebinyError"],"sources":["mapPlugins.ts"],"sourcesContent":["import { Plugin, PluginsContainer } from \"@webiny/plugins/types\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\nexport const getMappedPlugins = <T extends Plugin>(params: Params) => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n return {};\n }\n return plugins.reduce<Record<string, T>>((collection, plugin) => {\n const key: keyof typeof plugin = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {});\n};\n"],"mappings":";;;;;;;AACA;AAOO,MAAMA,gBAAgB,GAAsBC,MAAc,IAAK;EAClE,MAAM;IAAEC,OAAO,EAAEC,gBAAgB;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGJ,MAAM;EAC5D,MAAMC,OAAO,GAAGC,gBAAgB,CAACG,MAAM,CAAIF,IAAI,CAAC;EAChD,IAAIF,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,CAAC,CAAC;EACb;EACA,OAAOL,OAAO,CAACM,MAAM,CAAoB,CAACC,UAAU,EAAEC,MAAM,KAAK;IAC7D,MAAMC,GAAwB,GAAGD,MAAM,CAACL,QAAQ,CAAC;IACjD,IAAI,OAAOM,GAAG,KAAK,QAAQ,EAAE;MACzB,MAAM,IAAIC,cAAW,CACjB,kDAAkD,EAClD,uBAAuB,EACvB;QACIR,IAAI;QACJC;MACJ,CAAC,CACJ;IACL;IACAI,UAAU,CAACE,GAAG,CAAC,GAAGD,MAAM;IACxB,OAAOD,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAAC;AACV,CAAC;AAAC"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createDefaultFilterCreate = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
13
-
14
10
  const createDefaultFilterCreate = () => {
15
11
  return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
16
12
  fieldType: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.ALL,
@@ -23,13 +19,11 @@ const createDefaultFilterCreate = () => {
23
19
  valueFilterPlugins
24
20
  } = params;
25
21
  const plugin = valueFilterPlugins[params.operation];
26
-
27
22
  if (!plugin) {
28
23
  throw new _error.default(`Missing ValueFilterPlugin for operation "${params.operation}".`, "MISSING_OPERATION_PLUGIN", {
29
24
  operation: params.operation
30
25
  });
31
26
  }
32
-
33
27
  return {
34
28
  negate,
35
29
  transformValue,
@@ -44,5 +38,4 @@ const createDefaultFilterCreate = () => {
44
38
  }
45
39
  });
46
40
  };
47
-
48
41
  exports.createDefaultFilterCreate = createDefaultFilterCreate;
@@ -1 +1 @@
1
- {"version":3,"names":["createDefaultFilterCreate","CmsEntryFieldFilterPlugin","fieldType","ALL","create","params","negate","transformValue","field","compareValue","valueFilterPlugins","plugin","operation","WebinyError","fieldPathId","parents","map","f","fieldId","join","path","createPath"],"sources":["defaultFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\n\nexport const createDefaultFilterCreate = () => {\n return new CmsEntryFieldFilterPlugin({\n fieldType: CmsEntryFieldFilterPlugin.ALL,\n create: params => {\n const { negate, transformValue, field, compareValue, valueFilterPlugins } = params;\n const plugin = valueFilterPlugins[params.operation];\n if (!plugin) {\n throw new WebinyError(\n `Missing ValueFilterPlugin for operation \"${params.operation}\".`,\n \"MISSING_OPERATION_PLUGIN\",\n {\n operation: params.operation\n }\n );\n }\n return {\n negate,\n transformValue,\n field,\n compareValue,\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n path: field.createPath({\n field\n }),\n plugin\n };\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,IAAIC,oDAAJ,CAA8B;IACjCC,SAAS,EAAED,oDAAA,CAA0BE,GADJ;IAEjCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,MAAF;QAAUC,cAAV;QAA0BC,KAA1B;QAAiCC,YAAjC;QAA+CC;MAA/C,IAAsEL,MAA5E;MACA,MAAMM,MAAM,GAAGD,kBAAkB,CAACL,MAAM,CAACO,SAAR,CAAjC;;MACA,IAAI,CAACD,MAAL,EAAa;QACT,MAAM,IAAIE,cAAJ,CACD,4CAA2CR,MAAM,CAACO,SAAU,IAD3D,EAEF,0BAFE,EAGF;UACIA,SAAS,EAAEP,MAAM,CAACO;QADtB,CAHE,CAAN;MAOH;;MACD,OAAO;QACHN,MADG;QAEHC,cAFG;QAGHC,KAHG;QAIHC,YAJG;QAKHK,WAAW,EAAE,CAAC,GAAGN,KAAK,CAACO,OAAN,CAAcC,GAAd,CAAkBC,CAAC,IAAIA,CAAC,CAACC,OAAzB,CAAJ,EAAuCV,KAAK,CAACU,OAA7C,EAAsDC,IAAtD,CAA2D,GAA3D,CALV;QAMHC,IAAI,EAAEZ,KAAK,CAACa,UAAN,CAAiB;UACnBb;QADmB,CAAjB,CANH;QASHG;MATG,CAAP;IAWH;EAzBgC,CAA9B,CAAP;AA2BH,CA5BM"}
1
+ {"version":3,"names":["createDefaultFilterCreate","CmsEntryFieldFilterPlugin","fieldType","ALL","create","params","negate","transformValue","field","compareValue","valueFilterPlugins","plugin","operation","WebinyError","fieldPathId","parents","map","f","fieldId","join","path","createPath"],"sources":["defaultFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\n\nexport const createDefaultFilterCreate = () => {\n return new CmsEntryFieldFilterPlugin({\n fieldType: CmsEntryFieldFilterPlugin.ALL,\n create: params => {\n const { negate, transformValue, field, compareValue, valueFilterPlugins } = params;\n const plugin = valueFilterPlugins[params.operation];\n if (!plugin) {\n throw new WebinyError(\n `Missing ValueFilterPlugin for operation \"${params.operation}\".`,\n \"MISSING_OPERATION_PLUGIN\",\n {\n operation: params.operation\n }\n );\n }\n return {\n negate,\n transformValue,\n field,\n compareValue,\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n path: field.createPath({\n field\n }),\n plugin\n };\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,IAAIC,oDAAyB,CAAC;IACjCC,SAAS,EAAED,oDAAyB,CAACE,GAAG;IACxCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,MAAM;QAAEC,cAAc;QAAEC,KAAK;QAAEC,YAAY;QAAEC;MAAmB,CAAC,GAAGL,MAAM;MAClF,MAAMM,MAAM,GAAGD,kBAAkB,CAACL,MAAM,CAACO,SAAS,CAAC;MACnD,IAAI,CAACD,MAAM,EAAE;QACT,MAAM,IAAIE,cAAW,CAChB,4CAA2CR,MAAM,CAACO,SAAU,IAAG,EAChE,0BAA0B,EAC1B;UACIA,SAAS,EAAEP,MAAM,CAACO;QACtB,CAAC,CACJ;MACL;MACA,OAAO;QACHN,MAAM;QACNC,cAAc;QACdC,KAAK;QACLC,YAAY;QACZK,WAAW,EAAE,CAAC,GAAGN,KAAK,CAACO,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAAEV,KAAK,CAACU,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;QAC5EC,IAAI,EAAEZ,KAAK,CAACa,UAAU,CAAC;UACnBb;QACJ,CAAC,CAAC;QACFG;MACJ,CAAC;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createFilterCreatePlugins = void 0;
7
-
8
7
  var _defaultFilterCreate = require("./defaultFilterCreate");
9
-
10
8
  var _refFilterCreate = require("./refFilterCreate");
11
-
12
9
  var _objectFilterCreate = require("./objectFilterCreate");
13
-
14
10
  const createFilterCreatePlugins = () => {
15
11
  return [(0, _defaultFilterCreate.createDefaultFilterCreate)(), (0, _refFilterCreate.createRefFilterCreate)(), (0, _objectFilterCreate.objectFilterCreate)()];
16
12
  };
17
-
18
13
  exports.createFilterCreatePlugins = createFilterCreatePlugins;
@@ -1 +1 @@
1
- {"version":3,"names":["createFilterCreatePlugins","createDefaultFilterCreate","createRefFilterCreate","objectFilterCreate"],"sources":["index.ts"],"sourcesContent":["import { createDefaultFilterCreate } from \"./defaultFilterCreate\";\nimport { createRefFilterCreate } from \"./refFilterCreate\";\nimport { objectFilterCreate } from \"./objectFilterCreate\";\n\nexport const createFilterCreatePlugins = () => {\n return [createDefaultFilterCreate(), createRefFilterCreate(), objectFilterCreate()];\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,CAAC,IAAAC,8CAAA,GAAD,EAA8B,IAAAC,sCAAA,GAA9B,EAAuD,IAAAC,sCAAA,GAAvD,CAAP;AACH,CAFM"}
1
+ {"version":3,"names":["createFilterCreatePlugins","createDefaultFilterCreate","createRefFilterCreate","objectFilterCreate"],"sources":["index.ts"],"sourcesContent":["import { createDefaultFilterCreate } from \"./defaultFilterCreate\";\nimport { createRefFilterCreate } from \"./refFilterCreate\";\nimport { objectFilterCreate } from \"./objectFilterCreate\";\n\nexport const createFilterCreatePlugins = () => {\n return [createDefaultFilterCreate(), createRefFilterCreate(), objectFilterCreate()];\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,CAAC,IAAAC,8CAAyB,GAAE,EAAE,IAAAC,sCAAqB,GAAE,EAAE,IAAAC,sCAAkB,GAAE,CAAC;AACvF,CAAC;AAAC"}
@@ -1,20 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.objectFilterCreate = void 0;
9
-
10
8
  var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
11
-
12
9
  var _where = require("../where");
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  var _transform = require("../transform");
17
-
18
12
  const objectFilterCreate = () => {
19
13
  return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
20
14
  fieldType: "object",
@@ -28,20 +22,15 @@ const objectFilterCreate = () => {
28
22
  fields
29
23
  } = params;
30
24
  const filters = [];
31
-
32
25
  for (const key in objectValue) {
33
26
  const value = objectValue[key];
34
-
35
27
  if (value === undefined) {
36
28
  continue;
37
29
  }
38
-
39
30
  const whereParams = (0, _where.extractWhereParams)(key);
40
-
41
31
  if (!whereParams) {
42
32
  continue;
43
33
  }
44
-
45
34
  const {
46
35
  negate,
47
36
  fieldId,
@@ -49,27 +38,22 @@ const objectFilterCreate = () => {
49
38
  } = whereParams;
50
39
  const fieldPath = parentField.parents.map(p => p.fieldId).concat([parentField.fieldId, fieldId]).join(".");
51
40
  const field = fields[fieldPath];
52
-
53
41
  if (!field) {
54
42
  throw new _error.default(`There is no field with the field path "${fieldPath}".`, "FIELD_ERROR", {
55
43
  fieldId
56
44
  });
57
45
  }
58
-
59
46
  const filterCreatePlugin = getFilterCreatePlugin(field.type);
60
47
  const transformValuePlugin = transformValuePlugins[field.type];
61
-
62
48
  const transformValueCallable = value => {
63
49
  if (!transformValuePlugin) {
64
50
  return value;
65
51
  }
66
-
67
52
  return transformValuePlugin.transform({
68
53
  field,
69
54
  value
70
55
  });
71
56
  };
72
-
73
57
  const result = filterCreatePlugin.create({
74
58
  key,
75
59
  value,
@@ -86,22 +70,17 @@ const objectFilterCreate = () => {
86
70
  }),
87
71
  transformValue: transformValueCallable
88
72
  });
89
-
90
73
  if (!result) {
91
74
  continue;
92
75
  }
93
-
94
76
  if (Array.isArray(result)) {
95
77
  filters.push(...result);
96
78
  continue;
97
79
  }
98
-
99
80
  filters.push(result);
100
81
  }
101
-
102
82
  return filters;
103
83
  }
104
84
  });
105
85
  };
106
-
107
86
  exports.objectFilterCreate = objectFilterCreate;