@webiny/api-headless-cms-ddb-es 0.0.0-unstable.d4f203fa97 → 0.0.0-unstable.d65ec29d44

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 (189) hide show
  1. package/configurations.js +0 -8
  2. package/configurations.js.map +1 -1
  3. package/definitions/entry.js +0 -5
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/entryElasticsearch.js +0 -5
  6. package/definitions/entryElasticsearch.js.map +1 -1
  7. package/definitions/group.js +0 -5
  8. package/definitions/group.js.map +1 -1
  9. package/definitions/model.js +5 -5
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/settings.js +0 -5
  12. package/definitions/settings.js.map +1 -1
  13. package/definitions/system.js +0 -5
  14. package/definitions/system.js.map +1 -1
  15. package/definitions/table.js +0 -3
  16. package/definitions/table.js.map +1 -1
  17. package/definitions/tableElasticsearch.js +0 -3
  18. package/definitions/tableElasticsearch.js.map +1 -1
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +0 -5
  21. package/dynamoDb/index.js.map +1 -1
  22. package/dynamoDb/storage/date.d.ts +2 -1
  23. package/dynamoDb/storage/date.js +1 -16
  24. package/dynamoDb/storage/date.js.map +1 -1
  25. package/dynamoDb/storage/longText.d.ts +1 -1
  26. package/dynamoDb/storage/longText.js +7 -17
  27. package/dynamoDb/storage/longText.js.map +1 -1
  28. package/dynamoDb/storage/richText.d.ts +1 -1
  29. package/dynamoDb/storage/richText.js +9 -29
  30. package/dynamoDb/storage/richText.js.map +1 -1
  31. package/elasticsearch/createElasticsearchIndex.js +0 -11
  32. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  33. package/elasticsearch/deleteElasticsearchIndex.js +0 -7
  34. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  35. package/elasticsearch/index.js +0 -5
  36. package/elasticsearch/index.js.map +1 -1
  37. package/elasticsearch/indexing/dateTimeIndexing.js +4 -21
  38. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  39. package/elasticsearch/indexing/defaultFieldIndexing.js +15 -10
  40. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
  41. package/elasticsearch/indexing/index.js +0 -9
  42. package/elasticsearch/indexing/index.js.map +1 -1
  43. package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
  44. package/elasticsearch/indexing/longTextIndexing.js +19 -9
  45. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  46. package/elasticsearch/indexing/numberIndexing.js +0 -9
  47. package/elasticsearch/indexing/numberIndexing.js.map +1 -1
  48. package/elasticsearch/indexing/objectIndexing.js +3 -30
  49. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  50. package/elasticsearch/indexing/richTextIndexing.js +0 -5
  51. package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
  52. package/elasticsearch/indices/base.js +0 -3
  53. package/elasticsearch/indices/base.js.map +1 -1
  54. package/elasticsearch/indices/index.js +0 -4
  55. package/elasticsearch/indices/index.js.map +1 -1
  56. package/elasticsearch/indices/japanese.js +0 -3
  57. package/elasticsearch/indices/japanese.js.map +1 -1
  58. package/elasticsearch/search/index.js +0 -4
  59. package/elasticsearch/search/index.js.map +1 -1
  60. package/elasticsearch/search/refSearch.js +0 -6
  61. package/elasticsearch/search/refSearch.js.map +1 -1
  62. package/elasticsearch/search/timeSearch.js +0 -7
  63. package/elasticsearch/search/timeSearch.js.map +1 -1
  64. package/helpers/entryIndexHelpers.js +20 -49
  65. package/helpers/entryIndexHelpers.js.map +1 -1
  66. package/helpers/index.js +0 -2
  67. package/helpers/index.js.map +1 -1
  68. package/index.js +13 -64
  69. package/index.js.map +1 -1
  70. package/operations/entry/dataLoaders.js +0 -52
  71. package/operations/entry/dataLoaders.js.map +1 -1
  72. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  73. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +32 -0
  74. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  75. package/operations/entry/elasticsearch/body.js +7 -29
  76. package/operations/entry/elasticsearch/body.js.map +1 -1
  77. package/operations/entry/elasticsearch/fields.js +79 -46
  78. package/operations/entry/elasticsearch/fields.js.map +1 -1
  79. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +3 -10
  80. package/operations/entry/elasticsearch/filtering/applyFiltering.js +0 -9
  81. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
  82. package/operations/entry/elasticsearch/filtering/exec.js +36 -91
  83. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  84. package/operations/entry/elasticsearch/filtering/index.js +0 -2
  85. package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
  86. package/operations/entry/elasticsearch/filtering/path.js +1 -8
  87. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  88. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  89. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +28 -0
  90. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  91. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  92. package/operations/entry/elasticsearch/filtering/plugins/index.js +13 -0
  93. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  94. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  95. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +65 -0
  96. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  97. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  98. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +48 -0
  99. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  100. package/operations/entry/elasticsearch/filtering/populated.js +0 -7
  101. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
  102. package/operations/entry/elasticsearch/filtering/values.d.ts +1 -1
  103. package/operations/entry/elasticsearch/filtering/values.js +3 -9
  104. package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
  105. package/operations/entry/elasticsearch/fullTextSearch.d.ts +4 -1
  106. package/operations/entry/elasticsearch/fullTextSearch.js +70 -15
  107. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  108. package/operations/entry/elasticsearch/fullTextSearchFields.js +8 -35
  109. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
  110. package/operations/entry/elasticsearch/initialQuery.js +5 -19
  111. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  112. package/operations/entry/elasticsearch/keyword.js +0 -4
  113. package/operations/entry/elasticsearch/keyword.js.map +1 -1
  114. package/operations/entry/elasticsearch/plugins/bodyModifier.js +0 -3
  115. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
  116. package/operations/entry/elasticsearch/plugins/operator.js +0 -8
  117. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
  118. package/operations/entry/elasticsearch/plugins/queryModifier.js +0 -3
  119. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
  120. package/operations/entry/elasticsearch/plugins/search.js +0 -6
  121. package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
  122. package/operations/entry/elasticsearch/plugins/sortModifier.js +0 -3
  123. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
  124. package/operations/entry/elasticsearch/sort.js +12 -15
  125. package/operations/entry/elasticsearch/sort.js.map +1 -1
  126. package/operations/entry/elasticsearch/transformValueForSearch.js +0 -4
  127. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
  128. package/operations/entry/elasticsearch/types.d.ts +9 -1
  129. package/operations/entry/elasticsearch/types.js.map +1 -1
  130. package/operations/entry/index.js +32 -155
  131. package/operations/entry/index.js.map +1 -1
  132. package/operations/entry/keys.js +0 -9
  133. package/operations/entry/keys.js.map +1 -1
  134. package/operations/entry/recordType.js +0 -6
  135. package/operations/entry/recordType.js.map +1 -1
  136. package/operations/group/index.js +2 -32
  137. package/operations/group/index.js.map +1 -1
  138. package/operations/model/index.js +0 -33
  139. package/operations/model/index.js.map +1 -1
  140. package/operations/settings/index.js +0 -24
  141. package/operations/settings/index.js.map +1 -1
  142. package/operations/system/index.js +0 -17
  143. package/operations/system/index.js.map +1 -1
  144. package/package.json +16 -16
  145. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +1 -0
  146. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +6 -8
  147. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
  148. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -6
  149. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -1
  150. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
  151. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +28 -0
  152. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
  153. package/plugins/CmsEntryElasticsearchIndexPlugin.js +0 -5
  154. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
  155. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +1 -0
  156. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +6 -12
  157. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
  158. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +1 -0
  159. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +6 -8
  160. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
  161. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +1 -0
  162. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +6 -8
  163. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
  164. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  165. package/plugins/CmsEntryFilterPlugin.js +24 -0
  166. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  167. package/plugins/index.d.ts +1 -0
  168. package/plugins/index.js +11 -12
  169. package/plugins/index.js.map +1 -1
  170. package/types.js +0 -5
  171. package/types.js.map +1 -1
  172. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  173. package/helpers/createElasticsearchQueryBody.js +0 -618
  174. package/helpers/createElasticsearchQueryBody.js.map +0 -1
  175. package/helpers/fields.d.ts +0 -19
  176. package/helpers/fields.js +0 -196
  177. package/helpers/fields.js.map +0 -1
  178. package/helpers/searchPluginsList.d.ts +0 -6
  179. package/helpers/searchPluginsList.js +0 -26
  180. package/helpers/searchPluginsList.js.map +0 -1
  181. package/helpers/transformValueForSearch.d.ts +0 -12
  182. package/helpers/transformValueForSearch.js +0 -29
  183. package/helpers/transformValueForSearch.js.map +0 -1
  184. package/operations/entry/elasticsearch/filtering/isRefFieldFiltering.d.ts +0 -8
  185. package/operations/entry/elasticsearch/filtering/isRefFieldFiltering.js +0 -39
  186. package/operations/entry/elasticsearch/filtering/isRefFieldFiltering.js.map +0 -1
  187. package/operations/entry/elasticsearchFields.d.ts +0 -2
  188. package/operations/entry/elasticsearchFields.js +0 -38
  189. package/operations/entry/elasticsearchFields.js.map +0 -1
@@ -1,23 +1,18 @@
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.createModelFields = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  const createSystemField = field => {
15
11
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
16
12
  id: field.fieldId,
17
13
  label: field.fieldId
18
14
  });
19
15
  };
20
-
21
16
  const createSystemFields = () => {
22
17
  return {
23
18
  id: {
@@ -29,7 +24,8 @@ const createSystemFields = () => {
29
24
  storageId: "id",
30
25
  fieldId: "id",
31
26
  type: "text"
32
- })
27
+ }),
28
+ parents: []
33
29
  },
34
30
  entryId: {
35
31
  type: "text",
@@ -40,7 +36,8 @@ const createSystemFields = () => {
40
36
  storageId: "entryId",
41
37
  fieldId: "entryId",
42
38
  type: "text"
43
- })
39
+ }),
40
+ parents: []
44
41
  },
45
42
  savedOn: {
46
43
  type: "date",
@@ -56,7 +53,8 @@ const createSystemFields = () => {
56
53
  settings: {
57
54
  type: "dateTimeWithoutTimezone"
58
55
  }
59
- })
56
+ }),
57
+ parents: []
60
58
  },
61
59
  createdOn: {
62
60
  type: "date",
@@ -72,7 +70,8 @@ const createSystemFields = () => {
72
70
  settings: {
73
71
  type: "dateTimeWithoutTimezone"
74
72
  }
75
- })
73
+ }),
74
+ parents: []
76
75
  },
77
76
  createdBy: {
78
77
  type: "text",
@@ -85,7 +84,8 @@ const createSystemFields = () => {
85
84
  storageId: "createdBy",
86
85
  fieldId: "createdBy",
87
86
  type: "text"
88
- })
87
+ }),
88
+ parents: []
89
89
  },
90
90
  ownedBy: {
91
91
  type: "text",
@@ -98,7 +98,8 @@ const createSystemFields = () => {
98
98
  storageId: "ownedBy",
99
99
  fieldId: "ownedBy",
100
100
  type: "text"
101
- })
101
+ }),
102
+ parents: []
102
103
  },
103
104
  version: {
104
105
  type: "number",
@@ -111,7 +112,8 @@ const createSystemFields = () => {
111
112
  storageId: "version",
112
113
  fieldId: "version",
113
114
  type: "number"
114
- })
115
+ }),
116
+ parents: []
115
117
  },
116
118
  status: {
117
119
  type: "string",
@@ -124,11 +126,65 @@ const createSystemFields = () => {
124
126
  storageId: "status",
125
127
  fieldId: "status",
126
128
  type: "string"
127
- })
129
+ }),
130
+ parents: []
128
131
  }
129
132
  };
130
133
  };
131
-
134
+ const buildFieldsList = params => {
135
+ const {
136
+ plugins,
137
+ fields,
138
+ parents
139
+ } = params;
140
+ return fields.reduce((result, field) => {
141
+ var _field$settings;
142
+ const plugin = plugins[field.type];
143
+ if (!plugin) {
144
+ throw new _error.default(`There is no plugin for field type "${field.type}".`);
145
+ }
146
+ const {
147
+ isSearchable,
148
+ isSortable,
149
+ unmappedType,
150
+ fullTextSearch
151
+ } = plugin;
152
+ /**
153
+ * If a field has child fields, go through them and add them to a result.
154
+ */
155
+ const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
156
+ if (childFields.length > 0) {
157
+ /**
158
+ * Let's build all the child fields
159
+ */
160
+ const childResult = buildFieldsList({
161
+ fields: childFields,
162
+ plugins,
163
+ parents: [...parents, {
164
+ fieldId: field.fieldId,
165
+ storageId: field.storageId,
166
+ type: field.type
167
+ }]
168
+ });
169
+ /**
170
+ *
171
+ */
172
+ Object.assign(result, childResult);
173
+ }
174
+ const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(".");
175
+ result[identifier] = {
176
+ type: field.type,
177
+ parents,
178
+ isSearchable,
179
+ isSortable,
180
+ fullTextSearch,
181
+ unmappedType: typeof unmappedType === "function" ? unmappedType(field) : undefined,
182
+ isSystemField: false,
183
+ field
184
+ };
185
+ return result;
186
+ }, {});
187
+ };
132
188
  const createModelFields = ({
133
189
  plugins,
134
190
  fields
@@ -139,58 +195,35 @@ const createModelFields = ({
139
195
  /**
140
196
  * Collect all unmappedType from elastic plugins.
141
197
  */
142
-
143
-
144
198
  const unmappedTypes = plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
145
199
  if (!plugin.unmappedType) {
146
200
  return acc;
147
201
  }
148
-
149
202
  acc[plugin.fieldType] = plugin.unmappedType;
150
203
  return acc;
151
204
  }, {});
152
205
  /**
153
206
  * Collect all field types from the plugins.
154
207
  */
155
-
156
208
  const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
157
209
  const {
158
210
  fieldType,
159
211
  isSearchable,
160
- isSortable
212
+ isSortable,
213
+ fullTextSearch
161
214
  } = plugin;
162
215
  types[fieldType] = {
163
216
  unmappedType: unmappedTypes[fieldType],
164
217
  isSearchable,
165
- isSortable
218
+ isSortable,
219
+ fullTextSearch
166
220
  };
167
221
  return types;
168
222
  }, {});
169
- return fields.reduce((collection, field) => {
170
- const {
171
- fieldId,
172
- type
173
- } = field;
174
-
175
- if (!fieldTypePlugins[type]) {
176
- throw new _error.default(`There is no plugin for field type "${type}".`);
177
- }
178
-
179
- const {
180
- isSearchable,
181
- isSortable,
182
- unmappedType
183
- } = fieldTypePlugins[type];
184
- collection[fieldId] = {
185
- type,
186
- isSearchable,
187
- isSortable,
188
- unmappedType: typeof unmappedType === "function" ? unmappedType(field) : undefined,
189
- isSystemField: false,
190
- field
191
- };
192
- return collection;
193
- }, createSystemFields());
223
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, createSystemFields()), buildFieldsList({
224
+ fields,
225
+ plugins: fieldTypePlugins,
226
+ parents: []
227
+ }));
194
228
  };
195
-
196
229
  exports.createModelFields = createModelFields;
@@ -1 +1 @@
1
- {"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","isSystemField","isSearchable","isSortable","storageId","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","createModelFields","plugins","fields","length","unmappedTypes","byType","reduce","acc","plugin","fieldType","fieldTypePlugins","types","collection","WebinyError"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFields } from \"./types\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n })\n },\n entryId: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n })\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n })\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n })\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n })\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n })\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n })\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n })\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: CmsModelField) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: CmsModelField) => string | undefined;\n isSearchable: boolean;\n isSortable: boolean;\n}\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n fields?: CmsModelField[];\n}\nexport const createModelFields = ({ plugins, fields }: Params) => {\n if (!fields || fields.length === 0) {\n return createSystemFields();\n }\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, isSearchable, isSortable } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n isSearchable,\n isSortable\n };\n return types;\n }, {});\n\n return fields.reduce((collection, field) => {\n const { fieldId, type } = field;\n if (!fieldTypePlugins[type]) {\n throw new WebinyError(`There is no plugin for field type \"${type}\".`);\n }\n const { isSearchable, isSortable, unmappedType } = fieldTypePlugins[type];\n collection[fieldId] = {\n type,\n isSearchable,\n isSortable,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n isSystemField: false,\n field\n };\n\n return collection;\n }, createSystemFields());\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAQA,MAAMA,iBAAiB,GAAIC,KAAD,IAAgD;EACtE,mEACOA,KADP;IAEIC,EAAE,EAAED,KAAK,CAACE,OAFd;IAGIC,KAAK,EAAEH,KAAK,CAACE;EAHjB;AAKH,CAND;;AAQA,MAAME,kBAAkB,GAAG,MAAmB;EAC1C,OAAO;IACHH,EAAE,EAAE;MACAI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YAAY,EAAE,OAAOA,YAAP,KAAwB,UAAxB,GAAqCA,YAAY,CAACZ,KAAD,CAAjD,GAA2DiB,SAJvD;MAKlBX,aAAa,EAAE,KALG;MAMlBN;IANkB,CAAtB;IASA,OAAOkC,UAAP;EACH,CAhBM,EAgBJ9B,kBAAkB,EAhBd,CAAP;AAiBH,CAhDM"}
1
+ {"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","isSystemField","isSearchable","isSortable","storageId","parents","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","buildFieldsList","params","plugins","fields","reduce","result","plugin","WebinyError","fullTextSearch","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","unmappedTypes","byType","acc","fieldType","fieldTypePlugins","types"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFieldParent, ModelFields } from \"./types\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n }),\n parents: []\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n }),\n parents: []\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: CmsModelField) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: CmsModelField) => string | undefined;\n isSearchable: boolean;\n isSortable: boolean;\n fullTextSearch?: boolean;\n}\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const plugin = plugins[field.type];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { isSearchable, isSortable, unmappedType, fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: field.type\n }\n ]\n });\n /**\n *\n */\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: field.type,\n parents,\n isSearchable,\n isSortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n isSystemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n fields?: CmsModelField[];\n}\nexport const createModelFields = ({ plugins, fields }: Params) => {\n if (!fields || fields.length === 0) {\n return createSystemFields();\n }\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, isSearchable, isSortable, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n isSearchable,\n isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: []\n })\n };\n};\n"],"mappings":";;;;;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;MAAEC,UAAU;MAAEuB;IAAe,CAAC,GAAGF,MAAM;IACtEkB,KAAK,CAACF,SAAS,CAAC,GAAG;MACfhC,YAAY,EAAE6B,aAAa,CAACG,SAAS,CAAC;MACtCtC,YAAY;MACZC,UAAU;MACVuB;IACJ,CAAC;IACD,OAAOgB,KAAK;EAChB,CAAC,EAAE,CAAC,CAAC,CAAC;EAEV,mEACO3C,kBAAkB,EAAE,GACpBmB,eAAe,CAAC;IACfG,MAAM;IACND,OAAO,EAAEqB,gBAAgB;IACzBpC,OAAO,EAAE;EACb,CAAC,CAAC;AAEV,CAAC;AAAC"}
@@ -1,15 +1,8 @@
1
- import { ElasticsearchBoolQueryConfig } from "@webiny/api-elasticsearch/types";
2
- import { ElasticsearchQueryBuilderOperatorPlugins, ElasticsearchQuerySearchValuePlugins, ModelField } from "../types";
1
+ import { ElasticsearchQueryBuilderOperatorPlugins, ElasticsearchQuerySearchValuePlugins } from "../types";
2
+ import { ApplyFilteringCb } from "../../../../plugins/CmsEntryFilterPlugin";
3
3
  interface CreateParams {
4
4
  operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;
5
5
  searchPlugins: ElasticsearchQuerySearchValuePlugins;
6
6
  }
7
- interface ApplyParams {
8
- key: string;
9
- value: any;
10
- query: ElasticsearchBoolQueryConfig;
11
- operator: string;
12
- field: ModelField;
13
- }
14
- export declare const createApplyFiltering: ({ operatorPlugins, searchPlugins }: CreateParams) => (params: ApplyParams) => void;
7
+ export declare const createApplyFiltering: ({ operatorPlugins, searchPlugins }: CreateParams) => ApplyFilteringCb;
15
8
  export {};
@@ -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.createApplyFiltering = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  var _transformValueForSearch = require("../transformValueForSearch");
13
-
14
10
  var _keyword = require("../keyword");
15
-
16
11
  var _path = require("./path");
17
-
18
12
  const createApplyFiltering = ({
19
13
  operatorPlugins,
20
14
  searchPlugins
@@ -31,13 +25,11 @@ const createApplyFiltering = ({
31
25
  field
32
26
  } = params;
33
27
  const plugin = operatorPlugins[operator];
34
-
35
28
  if (!plugin) {
36
29
  throw new _error.default("Operator plugin missing.", "PLUGIN_MISSING", {
37
30
  operator
38
31
  });
39
32
  }
40
-
41
33
  const value = (0, _transformValueForSearch.transformValueForSearch)({
42
34
  plugins: searchPlugins,
43
35
  field: field.field,
@@ -62,5 +54,4 @@ const createApplyFiltering = ({
62
54
  });
63
55
  };
64
56
  };
65
-
66
57
  exports.createApplyFiltering = createApplyFiltering;
@@ -1 +1 @@
1
- {"version":3,"names":["createApplyFiltering","operatorPlugins","searchPlugins","createFieldPath","createFieldPathFactory","plugins","params","key","value","initialValue","query","operator","field","plugin","WebinyError","transformValueForSearch","keyword","hasKeyword","basePath","path","apply","name","fieldId"],"sources":["applyFiltering.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport {\n ElasticsearchQueryBuilderOperatorPlugins,\n ElasticsearchQuerySearchValuePlugins,\n ModelField\n} from \"~/operations/entry/elasticsearch/types\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\n\ninterface CreateParams {\n operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;\n searchPlugins: ElasticsearchQuerySearchValuePlugins;\n}\ninterface ApplyParams {\n key: string;\n value: any;\n query: ElasticsearchBoolQueryConfig;\n operator: string;\n field: ModelField;\n}\n\nexport const createApplyFiltering = ({ operatorPlugins, searchPlugins }: CreateParams) => {\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n return (params: ApplyParams) => {\n const { key, value: initialValue, query, operator, field } = params;\n\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: field.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(field);\n\n const { basePath, path } = createFieldPath({\n field,\n value,\n key,\n keyword\n });\n\n plugin.apply(query, {\n name: field.field.fieldId,\n basePath,\n path,\n value,\n keyword\n });\n };\n};\n"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AAMA;;AAcO,MAAMA,oBAAoB,GAAG,CAAC;EAAEC,eAAF;EAAmBC;AAAnB,CAAD,KAAsD;EACtF,MAAMC,eAAe,GAAG,IAAAC,4BAAA,EAAuB;IAC3CC,OAAO,EAAEH;EADkC,CAAvB,CAAxB;EAIA,OAAQI,MAAD,IAAyB;IAC5B,MAAM;MAAEC,GAAF;MAAOC,KAAK,EAAEC,YAAd;MAA4BC,KAA5B;MAAmCC,QAAnC;MAA6CC;IAA7C,IAAuDN,MAA7D;IAEA,MAAMO,MAAM,GAAGZ,eAAe,CAACU,QAAD,CAA9B;;IACA,IAAI,CAACE,MAAL,EAAa;MACT,MAAM,IAAIC,cAAJ,CAAgB,0BAAhB,EAA4C,gBAA5C,EAA8D;QAChEH;MADgE,CAA9D,CAAN;IAGH;;IAED,MAAMH,KAAK,GAAG,IAAAO,gDAAA,EAAwB;MAClCV,OAAO,EAAEH,aADyB;MAElCU,KAAK,EAAEA,KAAK,CAACA,KAFqB;MAGlCJ,KAAK,EAAEC;IAH2B,CAAxB,CAAd;IAMA,MAAMO,OAAO,GAAG,IAAAC,mBAAA,EAAWL,KAAX,CAAhB;IAEA,MAAM;MAAEM,QAAF;MAAYC;IAAZ,IAAqBhB,eAAe,CAAC;MACvCS,KADuC;MAEvCJ,KAFuC;MAGvCD,GAHuC;MAIvCS;IAJuC,CAAD,CAA1C;IAOAH,MAAM,CAACO,KAAP,CAAaV,KAAb,EAAoB;MAChBW,IAAI,EAAET,KAAK,CAACA,KAAN,CAAYU,OADF;MAEhBJ,QAFgB;MAGhBC,IAHgB;MAIhBX,KAJgB;MAKhBQ;IALgB,CAApB;EAOH,CAhCD;AAiCH,CAtCM"}
1
+ {"version":3,"names":["createApplyFiltering","operatorPlugins","searchPlugins","createFieldPath","createFieldPathFactory","plugins","params","key","value","initialValue","query","operator","field","plugin","WebinyError","transformValueForSearch","keyword","hasKeyword","basePath","path","apply","name","fieldId"],"sources":["applyFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport {\n ElasticsearchQueryBuilderOperatorPlugins,\n ElasticsearchQuerySearchValuePlugins\n} from \"~/operations/entry/elasticsearch/types\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\nimport { ApplyFilteringCb } from \"~/plugins/CmsEntryFilterPlugin\";\n\ninterface CreateParams {\n operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;\n searchPlugins: ElasticsearchQuerySearchValuePlugins;\n}\n\nexport const createApplyFiltering = ({\n operatorPlugins,\n searchPlugins\n}: CreateParams): ApplyFilteringCb => {\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n return params => {\n const { key, value: initialValue, query, operator, field } = params;\n\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: field.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(field);\n\n const { basePath, path } = createFieldPath({\n field,\n value,\n key,\n keyword\n });\n\n plugin.apply(query, {\n name: field.field.fieldId,\n basePath,\n path,\n value,\n keyword\n });\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAKA;AAQO,MAAMA,oBAAoB,GAAG,CAAC;EACjCC,eAAe;EACfC;AACU,CAAC,KAAuB;EAClC,MAAMC,eAAe,GAAG,IAAAC,4BAAsB,EAAC;IAC3CC,OAAO,EAAEH;EACb,CAAC,CAAC;EAEF,OAAOI,MAAM,IAAI;IACb,MAAM;MAAEC,GAAG;MAAEC,KAAK,EAAEC,YAAY;MAAEC,KAAK;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGN,MAAM;IAEnE,MAAMO,MAAM,GAAGZ,eAAe,CAACU,QAAQ,CAAC;IACxC,IAAI,CAACE,MAAM,EAAE;MACT,MAAM,IAAIC,cAAW,CAAC,0BAA0B,EAAE,gBAAgB,EAAE;QAChEH;MACJ,CAAC,CAAC;IACN;IAEA,MAAMH,KAAK,GAAG,IAAAO,gDAAuB,EAAC;MAClCV,OAAO,EAAEH,aAAa;MACtBU,KAAK,EAAEA,KAAK,CAACA,KAAK;MAClBJ,KAAK,EAAEC;IACX,CAAC,CAAC;IAEF,MAAMO,OAAO,GAAG,IAAAC,mBAAU,EAACL,KAAK,CAAC;IAEjC,MAAM;MAAEM,QAAQ;MAAEC;IAAK,CAAC,GAAGhB,eAAe,CAAC;MACvCS,KAAK;MACLJ,KAAK;MACLD,GAAG;MACHS;IACJ,CAAC,CAAC;IAEFH,MAAM,CAACO,KAAK,CAACV,KAAK,EAAE;MAChBW,IAAI,EAAET,KAAK,CAACA,KAAK,CAACU,OAAO;MACzBJ,QAAQ;MACRC,IAAI;MACJX,KAAK;MACLQ;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
@@ -1,49 +1,37 @@
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.createExecFiltering = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _search = require("../plugins/search");
15
-
16
11
  var _operator = require("../plugins/operator");
17
-
18
12
  var _initialQuery = require("../initialQuery");
19
-
20
13
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
21
-
22
14
  var _values = require("./values");
23
-
24
15
  var _populated = require("./populated");
25
-
26
16
  var _applyFiltering = require("./applyFiltering");
27
-
28
- var _isRefFieldFiltering = require("./isRefFieldFiltering");
29
-
17
+ var _CmsEntryFilterPlugin = require("../../../../plugins/CmsEntryFilterPlugin");
18
+ var _assignMinimumShouldMatchToQuery = require("../assignMinimumShouldMatchToQuery");
30
19
  const createExecFiltering = params => {
31
20
  const {
32
21
  fields,
33
22
  plugins,
34
23
  model
35
24
  } = params;
25
+
36
26
  /**
37
27
  * We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.
38
28
  */
39
-
40
29
  const searchPlugins = (0, _search.createSearchPluginList)({
41
30
  plugins
42
31
  });
43
32
  /**
44
33
  * We need the operator plugins, which we execute on our where conditions.
45
34
  */
46
-
47
35
  const operatorPlugins = (0, _operator.createOperatorPluginList)({
48
36
  plugins,
49
37
  locale: model.locale
@@ -52,7 +40,19 @@ const createExecFiltering = params => {
52
40
  operatorPlugins,
53
41
  searchPlugins
54
42
  });
55
-
43
+ const filteringPlugins = plugins.byType(_CmsEntryFilterPlugin.CmsEntryFilterPlugin.type).reduce((collection, plugin) => {
44
+ collection[plugin.fieldType] = plugin;
45
+ return collection;
46
+ }, {});
47
+ const getFilterPlugin = type => {
48
+ const plugin = filteringPlugins[type] || filteringPlugins["*"];
49
+ if (plugin) {
50
+ return plugin;
51
+ }
52
+ throw new _error.default(`There is no filtering plugin for the given field type "${type}".`, "FILTERING_PLUGIN_ERROR", {
53
+ type
54
+ });
55
+ };
56
56
  const execFiltering = params => {
57
57
  const {
58
58
  where: initialWhere,
@@ -61,63 +61,50 @@ const createExecFiltering = params => {
61
61
  /**
62
62
  * No point in continuing if no "where" conditions exist.
63
63
  */
64
-
65
64
  const keys = Object.keys(initialWhere);
66
-
67
65
  if (keys.length === 0) {
68
66
  return;
69
67
  }
70
-
71
68
  const where = (0, _objectSpread2.default)({}, initialWhere);
72
-
73
69
  for (const key in where) {
74
70
  const value = where[key];
75
71
  /**
76
72
  * We always skip if no value is defined.
77
73
  * Only skip undefined value, null is valid.
78
74
  */
79
-
80
75
  if (value === undefined) {
81
76
  continue;
82
- } //
83
-
77
+ }
78
+ //
84
79
  /**
85
80
  * When we are running with AND, the "value" MUST be an array.
86
- */
87
- else if (key === "AND") {
88
- const childWhereList = (0, _values.getValues)(value, "AND");
81
+ */else if (key === "AND") {
82
+ const childWhereList = (0, _values.getWhereValues)(value, "AND");
89
83
  const childQuery = (0, _initialQuery.createBaseQuery)();
90
-
91
84
  for (const childWhere of childWhereList) {
92
85
  execFiltering({
93
86
  query: childQuery,
94
87
  where: childWhere
95
88
  });
96
89
  }
97
-
98
90
  const childQueryBool = (0, _populated.getPopulated)(childQuery);
99
-
100
91
  if (Object.keys(childQueryBool).length === 0) {
101
92
  continue;
102
93
  }
103
-
104
94
  query.filter.push({
105
95
  bool: childQueryBool
106
96
  });
107
97
  continue;
108
- } //
109
-
98
+ }
99
+ //
110
100
  /**
111
101
  * When we are running with OR, the "value" must be an array.
112
- */
113
- else if (key === "OR") {
114
- const childWhereList = (0, _values.getValues)(value, "OR");
102
+ */else if (key === "OR") {
103
+ const childWhereList = (0, _values.getWhereValues)(value, "OR");
115
104
  /**
116
105
  * Each of the conditions MUST produce it's own should section.
117
106
  */
118
-
119
107
  const should = [];
120
-
121
108
  for (const childWhere of childWhereList) {
122
109
  const childQuery = (0, _initialQuery.createBaseQuery)();
123
110
  execFiltering({
@@ -125,103 +112,61 @@ const createExecFiltering = params => {
125
112
  where: childWhere
126
113
  });
127
114
  const childQueryBool = (0, _populated.getPopulated)(childQuery);
128
-
129
115
  if (Object.keys(childQueryBool).length === 0) {
130
116
  continue;
131
117
  }
132
-
133
118
  should.push({
134
- bool: (0, _objectSpread2.default)({}, childQueryBool)
119
+ bool: childQueryBool
135
120
  });
136
121
  }
137
-
138
122
  if (should.length === 0) {
139
123
  continue;
140
124
  }
141
-
142
125
  query.should.push(...should);
143
126
  /**
144
127
  * If there are any should, minimum to have is 1.
145
128
  * Of course, do not override if it's already set.
146
129
  */
147
-
148
- if (query.should.length > 0 && !query.minimum_should_match) {
149
- query.minimum_should_match = 1;
150
- }
151
-
130
+ (0, _assignMinimumShouldMatchToQuery.assignMinimumShouldMatchToQuery)({
131
+ query
132
+ });
152
133
  continue;
153
134
  }
154
-
155
135
  const {
156
136
  field: whereFieldId,
157
137
  operator
158
138
  } = (0, _apiElasticsearch.parseWhereKey)(key);
159
139
  let fieldId = whereFieldId;
140
+
160
141
  /**
161
142
  * TODO This will be required until the storage operations receive the fieldId instead of field storageId.
162
143
  * TODO For this to work without field searching, we need to refactor how the query looks like.
163
144
  *
164
145
  * Storage operations should NEVER receive an field storageId, only alias - fieldId.
165
146
  */
166
-
167
147
  const cmsModelField = model.fields.find(f => f.fieldId === fieldId);
168
-
169
148
  if (!cmsModelField && !fields[fieldId]) {
170
149
  throw new _error.default(`There is no CMS Model Field field "${fieldId}".`);
171
150
  } else if (cmsModelField) {
172
151
  fieldId = cmsModelField.fieldId;
173
152
  }
174
-
175
153
  const field = fields[fieldId];
176
-
177
154
  if (!field) {
178
155
  throw new _error.default(`There is no field "${fieldId}".`);
179
156
  }
180
-
181
- if (!field.isSearchable) {
182
- throw new _error.default(`Field "${field.field.fieldId}" is not searchable.`);
183
- }
184
- /**
185
- * There is a possibility that value is an object.
186
- * In that case, check if field is ref field and continue a bit differently.
187
- */
188
-
189
-
190
- if ((0, _isRefFieldFiltering.isRefFieldFiltering)({
157
+ const filterPlugin = getFilterPlugin(field.type);
158
+ filterPlugin.exec({
159
+ applyFiltering,
160
+ getFilterPlugin,
191
161
  key,
192
162
  value,
193
- field
194
- })) {
195
- /**
196
- * We need to go through each key in where[key] to determine the filters.
197
- */
198
- for (const whereKey in value) {
199
- const {
200
- operator
201
- } = (0, _apiElasticsearch.parseWhereKey)(whereKey);
202
- applyFiltering({
203
- query,
204
- field,
205
- operator,
206
- key: whereKey,
207
- value: value[whereKey]
208
- });
209
- }
210
-
211
- continue;
212
- }
213
-
214
- applyFiltering({
215
- key,
216
- value,
217
- query,
163
+ operator,
218
164
  field,
219
- operator
165
+ fields,
166
+ query
220
167
  });
221
168
  }
222
169
  };
223
-
224
170
  return execFiltering;
225
171
  };
226
-
227
172
  exports.createExecFiltering = createExecFiltering;