@webiny/api-headless-cms-ddb-es 6.3.0 → 6.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/configurations.js +27 -35
  2. package/configurations.js.map +1 -1
  3. package/definitions/entry.js +7 -9
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/group.js +7 -9
  6. package/definitions/group.js.map +1 -1
  7. package/definitions/model.js +7 -9
  8. package/definitions/model.js.map +1 -1
  9. package/definitions/types.d.ts +1 -0
  10. package/definitions/types.js +0 -3
  11. package/elasticsearch/createElasticsearchIndex.js +50 -67
  12. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  13. package/elasticsearch/deleteElasticsearchIndex.js +18 -26
  14. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  15. package/exports/api/cms/opensearch.js +2 -4
  16. package/feature.js +144 -153
  17. package/feature.js.map +1 -1
  18. package/features/CmsEntryOpenSearchBodyModifier/abstractions.js +2 -1
  19. package/features/CmsEntryOpenSearchBodyModifier/abstractions.js.map +1 -1
  20. package/features/CmsEntryOpenSearchBodyModifier/index.js +0 -2
  21. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js +28 -27
  22. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -1
  23. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js +2 -1
  24. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js.map +1 -1
  25. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js +2 -1
  26. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -1
  27. package/features/CmsEntryOpenSearchFieldIndex/constants.js +2 -1
  28. package/features/CmsEntryOpenSearchFieldIndex/constants.js.map +1 -1
  29. package/features/CmsEntryOpenSearchFieldIndex/feature.js +13 -12
  30. package/features/CmsEntryOpenSearchFieldIndex/feature.js.map +1 -1
  31. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js +48 -65
  32. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js.map +1 -1
  33. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js +20 -30
  34. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js.map +1 -1
  35. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js +15 -16
  36. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js.map +1 -1
  37. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js +15 -18
  38. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js.map +1 -1
  39. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js +24 -29
  40. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js.map +1 -1
  41. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js +99 -144
  42. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js.map +1 -1
  43. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js +15 -16
  44. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js.map +1 -1
  45. package/features/CmsEntryOpenSearchFieldIndex/index.js +0 -2
  46. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js +26 -28
  47. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js.map +1 -1
  48. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js +2 -1
  49. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js.map +1 -1
  50. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js +2 -1
  51. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js.map +1 -1
  52. package/features/CmsEntryOpenSearchFilter/constants.js +2 -1
  53. package/features/CmsEntryOpenSearchFilter/constants.js.map +1 -1
  54. package/features/CmsEntryOpenSearchFilter/feature.js +9 -8
  55. package/features/CmsEntryOpenSearchFilter/feature.js.map +1 -1
  56. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js +18 -15
  57. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js.map +1 -1
  58. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js +35 -53
  59. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js.map +1 -1
  60. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js +27 -40
  61. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js.map +1 -1
  62. package/features/CmsEntryOpenSearchFilter/index.js +0 -2
  63. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js +2 -1
  64. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js.map +1 -1
  65. package/features/CmsEntryOpenSearchFullTextSearch/index.js +0 -2
  66. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js +10 -9
  67. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js.map +1 -1
  68. package/features/CmsEntryOpenSearchIndex/abstractions.js +2 -1
  69. package/features/CmsEntryOpenSearchIndex/abstractions.js.map +1 -1
  70. package/features/CmsEntryOpenSearchIndex/feature.js +6 -5
  71. package/features/CmsEntryOpenSearchIndex/feature.js.map +1 -1
  72. package/features/CmsEntryOpenSearchIndex/index.js +0 -2
  73. package/features/CmsEntryOpenSearchQueryModifier/abstractions.js +2 -1
  74. package/features/CmsEntryOpenSearchQueryModifier/abstractions.js.map +1 -1
  75. package/features/CmsEntryOpenSearchQueryModifier/index.js +0 -2
  76. package/features/CmsEntryOpenSearchSortModifier/abstractions.js +2 -1
  77. package/features/CmsEntryOpenSearchSortModifier/abstractions.js.map +1 -1
  78. package/features/CmsEntryOpenSearchSortModifier/index.js +0 -2
  79. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js +24 -20
  80. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -1
  81. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js +2 -1
  82. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js.map +1 -1
  83. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js +2 -1
  84. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -1
  85. package/features/CmsEntryOpenSearchValueSearch/feature.js +9 -8
  86. package/features/CmsEntryOpenSearchValueSearch/feature.js.map +1 -1
  87. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js +14 -16
  88. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js.map +1 -1
  89. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js +31 -42
  90. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js.map +1 -1
  91. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js +15 -17
  92. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js.map +1 -1
  93. package/features/CmsEntryOpenSearchValueSearch/index.js +0 -2
  94. package/features/CmsEntryOpenSearchValuesModifier/abstractions.js +2 -1
  95. package/features/CmsEntryOpenSearchValuesModifier/abstractions.js.map +1 -1
  96. package/features/CmsEntryOpenSearchValuesModifier/index.js +0 -2
  97. package/helpers/entryIndexHelpers.js +71 -123
  98. package/helpers/entryIndexHelpers.js.map +1 -1
  99. package/helpers/fieldIdentifier.js +18 -30
  100. package/helpers/fieldIdentifier.js.map +1 -1
  101. package/helpers/index.js +0 -2
  102. package/index.js +0 -2
  103. package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
  104. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  105. package/operations/entry/dataLoader/constants.js +2 -1
  106. package/operations/entry/dataLoader/constants.js.map +1 -1
  107. package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
  108. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  109. package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -29
  110. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  111. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +27 -37
  112. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  113. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +27 -37
  114. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  115. package/operations/entry/dataLoader/getRevisionById.js +32 -46
  116. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  117. package/operations/entry/dataLoader/index.js +8 -9
  118. package/operations/entry/dataLoader/index.js.map +1 -1
  119. package/operations/entry/dataLoader/types.js +0 -3
  120. package/operations/entry/dataLoaders.js +81 -99
  121. package/operations/entry/dataLoaders.js.map +1 -1
  122. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +6 -24
  123. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
  124. package/operations/entry/elasticsearch/body.js +74 -125
  125. package/operations/entry/elasticsearch/body.js.map +1 -1
  126. package/operations/entry/elasticsearch/fields/createSystemField.js +6 -7
  127. package/operations/entry/elasticsearch/fields/createSystemField.js.map +1 -1
  128. package/operations/entry/elasticsearch/fields/live.js +45 -40
  129. package/operations/entry/elasticsearch/fields/live.js.map +1 -1
  130. package/operations/entry/elasticsearch/fields/location.js +45 -40
  131. package/operations/entry/elasticsearch/fields/location.js.map +1 -1
  132. package/operations/entry/elasticsearch/fields/state.js +99 -88
  133. package/operations/entry/elasticsearch/fields/state.js.map +1 -1
  134. package/operations/entry/elasticsearch/fields.js +193 -217
  135. package/operations/entry/elasticsearch/fields.js.map +1 -1
  136. package/operations/entry/elasticsearch/filtering/applyFiltering.js +32 -45
  137. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
  138. package/operations/entry/elasticsearch/filtering/exec.js +85 -114
  139. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  140. package/operations/entry/elasticsearch/filtering/index.js +0 -2
  141. package/operations/entry/elasticsearch/filtering/path.js +24 -33
  142. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  143. package/operations/entry/elasticsearch/filtering/populated.js +8 -14
  144. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
  145. package/operations/entry/elasticsearch/filtering/values.js +11 -12
  146. package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
  147. package/operations/entry/elasticsearch/fullTextSearch.js +43 -80
  148. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  149. package/operations/entry/elasticsearch/fullTextSearchFields.js +7 -17
  150. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
  151. package/operations/entry/elasticsearch/initialQuery.js +37 -80
  152. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  153. package/operations/entry/elasticsearch/keyword.js +13 -27
  154. package/operations/entry/elasticsearch/keyword.js.map +1 -1
  155. package/operations/entry/elasticsearch/plugins/operator.js +9 -20
  156. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
  157. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +6 -4
  158. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -1
  159. package/operations/entry/elasticsearch/sort.js +69 -92
  160. package/operations/entry/elasticsearch/sort.js.map +1 -1
  161. package/operations/entry/elasticsearch/transformValueForSearch.js +9 -14
  162. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
  163. package/operations/entry/elasticsearch/types.js +0 -3
  164. package/operations/entry/index.js +1322 -1709
  165. package/operations/entry/index.js.map +1 -1
  166. package/operations/entry/keys.js +43 -63
  167. package/operations/entry/keys.js.map +1 -1
  168. package/operations/entry/recordType.js +4 -9
  169. package/operations/entry/recordType.js.map +1 -1
  170. package/operations/entry/transformations/convertEntryKeys.js +21 -26
  171. package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
  172. package/operations/entry/transformations/index.js +85 -114
  173. package/operations/entry/transformations/index.js.map +1 -1
  174. package/operations/entry/transformations/modifyEntryValues.d.ts +1 -1
  175. package/operations/entry/transformations/modifyEntryValues.js +12 -17
  176. package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
  177. package/operations/entry/transformations/transformEntryKeys.js +13 -16
  178. package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
  179. package/operations/entry/transformations/transformEntryToIndex.js +17 -22
  180. package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
  181. package/operations/group/index.js +113 -134
  182. package/operations/group/index.js.map +1 -1
  183. package/operations/model/index.js +128 -156
  184. package/operations/model/index.js.map +1 -1
  185. package/package.json +23 -23
  186. package/tasks/createIndexTaskPlugin.js +35 -38
  187. package/tasks/createIndexTaskPlugin.js.map +1 -1
  188. package/types.js +7 -13
  189. package/types.js.map +1 -1
  190. package/values/NoValueContainer.js +8 -10
  191. package/values/NoValueContainer.js.map +1 -1
  192. package/definitions/types.js.map +0 -1
  193. package/exports/api/cms/opensearch.js.map +0 -1
  194. package/features/CmsEntryOpenSearchBodyModifier/index.js.map +0 -1
  195. package/features/CmsEntryOpenSearchFieldIndex/index.js.map +0 -1
  196. package/features/CmsEntryOpenSearchFilter/index.js.map +0 -1
  197. package/features/CmsEntryOpenSearchFullTextSearch/index.js.map +0 -1
  198. package/features/CmsEntryOpenSearchIndex/index.js.map +0 -1
  199. package/features/CmsEntryOpenSearchQueryModifier/index.js.map +0 -1
  200. package/features/CmsEntryOpenSearchSortModifier/index.js.map +0 -1
  201. package/features/CmsEntryOpenSearchValueSearch/index.js.map +0 -1
  202. package/features/CmsEntryOpenSearchValuesModifier/index.js.map +0 -1
  203. package/helpers/index.js.map +0 -1
  204. package/index.js.map +0 -1
  205. package/operations/entry/dataLoader/types.js.map +0 -1
  206. package/operations/entry/elasticsearch/filtering/index.js.map +0 -1
  207. package/operations/entry/elasticsearch/types.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import WebinyError from "@webiny/error";
1
+ import error from "@webiny/error";
2
2
  import { createOperatorPluginList } from "../plugins/operator.js";
3
3
  import { createBaseQuery } from "../initialQuery.js";
4
4
  import { parseWhereKey } from "@webiny/api-opensearch";
@@ -6,120 +6,91 @@ import { getWhereValues } from "./values.js";
6
6
  import { getPopulated } from "./populated.js";
7
7
  import { createApplyFiltering } from "./applyFiltering.js";
8
8
  import { assignMinimumShouldMatchToQuery } from "../assignMinimumShouldMatchToQuery.js";
9
- export const createExecFiltering = params => {
10
- const {
11
- fields,
12
- plugins,
13
- model,
14
- valueSearchRegistry,
15
- filterRegistry
16
- } = params;
17
- const operatorPlugins = createOperatorPluginList({
18
- plugins
19
- });
20
- const applyFiltering = createApplyFiltering({
21
- operatorPlugins,
22
- valueSearchRegistry
23
- });
24
- const getFilter = type => {
25
- return filterRegistry.get(type);
26
- };
27
- const execFiltering = params => {
28
- const {
29
- where: initialWhere,
30
- query,
31
- isValues = false
32
- } = params;
33
- const keys = Object.keys(initialWhere);
34
- if (keys.length === 0) {
35
- return;
36
- }
37
- const where = structuredClone(initialWhere);
38
- for (const key in where) {
39
- const value = where[key];
40
- if (value === undefined) {
41
- continue;
42
- } else if (key === "AND") {
43
- const childWhereList = getWhereValues(value, "AND");
44
- const childQuery = createBaseQuery();
45
- for (const childWhere of childWhereList) {
46
- execFiltering({
47
- query: childQuery,
48
- where: childWhere,
49
- isValues
50
- });
9
+ const createExecFiltering = (params)=>{
10
+ const { fields, plugins, model, valueSearchRegistry, filterRegistry } = params;
11
+ const operatorPlugins = createOperatorPluginList({
12
+ plugins
13
+ });
14
+ const applyFiltering = createApplyFiltering({
15
+ operatorPlugins,
16
+ valueSearchRegistry
17
+ });
18
+ const getFilter = (type)=>filterRegistry.get(type);
19
+ const execFiltering = (params)=>{
20
+ const { where: initialWhere, query, isValues = false } = params;
21
+ const keys = Object.keys(initialWhere);
22
+ if (0 === keys.length) return;
23
+ const where = structuredClone(initialWhere);
24
+ for(const key in where){
25
+ const value = where[key];
26
+ if (void 0 === value) continue;
27
+ if ("AND" === key) {
28
+ const childWhereList = getWhereValues(value, "AND");
29
+ const childQuery = createBaseQuery();
30
+ for (const childWhere of childWhereList)execFiltering({
31
+ query: childQuery,
32
+ where: childWhere,
33
+ isValues
34
+ });
35
+ const childQueryBool = getPopulated(childQuery);
36
+ if (0 === Object.keys(childQueryBool).length) continue;
37
+ query.filter.push({
38
+ bool: childQueryBool
39
+ });
40
+ continue;
41
+ }
42
+ if ("OR" === key) {
43
+ const childWhereList = getWhereValues(value, "OR");
44
+ const should = [];
45
+ for (const childWhere of childWhereList){
46
+ const childQuery = createBaseQuery();
47
+ execFiltering({
48
+ query: childQuery,
49
+ where: childWhere,
50
+ isValues
51
+ });
52
+ const childQueryBool = getPopulated(childQuery);
53
+ if (0 !== Object.keys(childQueryBool).length) should.push({
54
+ bool: childQueryBool
55
+ });
56
+ }
57
+ if (0 === should.length) continue;
58
+ query.should.push(...should);
59
+ assignMinimumShouldMatchToQuery({
60
+ query
61
+ });
62
+ continue;
63
+ } else if ("values" === key) {
64
+ execFiltering({
65
+ query,
66
+ where: where[key],
67
+ isValues: true
68
+ });
69
+ continue;
70
+ }
71
+ const { field: whereFieldId, operator } = parseWhereKey(key);
72
+ let fieldId = isValues ? `values.${whereFieldId}` : whereFieldId;
73
+ const cmsModelField = model.fields.find((f)=>f.fieldId === fieldId);
74
+ if (cmsModelField || fields[fieldId]) {
75
+ if (cmsModelField) fieldId = cmsModelField.fieldId;
76
+ } else throw new error(`There is no CMS Model Field "${fieldId}".`);
77
+ const field = fields[fieldId];
78
+ if (!field) throw new error(`There is no field "${fieldId}".`, "EXEC_FILTERING_ERROR");
79
+ const filter = getFilter(field.type);
80
+ filter.exec({
81
+ applyFiltering,
82
+ getFilter,
83
+ key,
84
+ value,
85
+ operator,
86
+ field,
87
+ fields,
88
+ query
89
+ });
51
90
  }
52
- const childQueryBool = getPopulated(childQuery);
53
- if (Object.keys(childQueryBool).length === 0) {
54
- continue;
55
- }
56
- query.filter.push({
57
- bool: childQueryBool
58
- });
59
- continue;
60
- } else if (key === "OR") {
61
- const childWhereList = getWhereValues(value, "OR");
62
- const should = [];
63
- for (const childWhere of childWhereList) {
64
- const childQuery = createBaseQuery();
65
- execFiltering({
66
- query: childQuery,
67
- where: childWhere,
68
- isValues
69
- });
70
- const childQueryBool = getPopulated(childQuery);
71
- if (Object.keys(childQueryBool).length === 0) {
72
- continue;
73
- }
74
- should.push({
75
- bool: childQueryBool
76
- });
77
- }
78
- if (should.length === 0) {
79
- continue;
80
- }
81
- query.should.push(...should);
82
- assignMinimumShouldMatchToQuery({
83
- query
84
- });
85
- continue;
86
- } else if (key === "values") {
87
- execFiltering({
88
- query,
89
- where: where[key],
90
- isValues: true
91
- });
92
- continue;
93
- }
94
- const {
95
- field: whereFieldId,
96
- operator
97
- } = parseWhereKey(key);
98
- let fieldId = isValues ? `values.${whereFieldId}` : whereFieldId;
99
- const cmsModelField = model.fields.find(f => f.fieldId === fieldId);
100
- if (!cmsModelField && !fields[fieldId]) {
101
- throw new WebinyError(`There is no CMS Model Field "${fieldId}".`);
102
- } else if (cmsModelField) {
103
- fieldId = cmsModelField.fieldId;
104
- }
105
- const field = fields[fieldId];
106
- if (!field) {
107
- throw new WebinyError(`There is no field "${fieldId}".`, "EXEC_FILTERING_ERROR");
108
- }
109
- const filter = getFilter(field.type);
110
- filter.exec({
111
- applyFiltering,
112
- getFilter,
113
- key,
114
- value,
115
- operator,
116
- field,
117
- fields,
118
- query
119
- });
120
- }
121
- };
122
- return execFiltering;
91
+ };
92
+ return execFiltering;
123
93
  };
94
+ export { createExecFiltering };
124
95
 
125
96
  //# sourceMappingURL=exec.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","createOperatorPluginList","createBaseQuery","parseWhereKey","getWhereValues","getPopulated","createApplyFiltering","assignMinimumShouldMatchToQuery","createExecFiltering","params","fields","plugins","model","valueSearchRegistry","filterRegistry","operatorPlugins","applyFiltering","getFilter","type","get","execFiltering","where","initialWhere","query","isValues","keys","Object","length","structuredClone","key","value","undefined","childWhereList","childQuery","childWhere","childQueryBool","filter","push","bool","should","field","whereFieldId","operator","fieldId","cmsModelField","find","f","exec"],"sources":["exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type {\n OpenSearchBoolQueryConfig,\n QueryDslQueryContainer as Query\n} from \"@webiny/api-opensearch/types.js\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator.js\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { parseWhereKey } from \"@webiny/api-opensearch\";\nimport { getWhereValues } from \"./values.js\";\nimport { getPopulated } from \"./populated.js\";\nimport { createApplyFiltering } from \"./applyFiltering.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\nimport type { CmsEntryOpenSearchFilterRegistry } from \"~/features/CmsEntryOpenSearchFilter/index.js\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface;\n}\nexport interface IExecParams {\n where: CmsEntryListWhere;\n query: OpenSearchBoolQueryConfig;\n isValues?: boolean;\n}\nexport interface CreateExecFilteringResponse {\n (params: IExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model, valueSearchRegistry, filterRegistry } = params;\n\n const operatorPlugins = createOperatorPluginList({\n plugins\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n valueSearchRegistry\n });\n\n const getFilter = (type: string) => {\n return filterRegistry.get(type);\n };\n\n const execFiltering = (params: IExecParams) => {\n const { where: initialWhere, query, isValues = false } = params;\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where = structuredClone(initialWhere);\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n } else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n const childQuery = createBaseQuery();\n for (const childWhere of childWhereList) {\n execFiltering({ query: childQuery, where: childWhere, isValues });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({ bool: childQueryBool });\n continue;\n } else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({ query: childQuery, where: childWhere, isValues });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({ bool: childQueryBool });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n assignMinimumShouldMatchToQuery({ query });\n continue;\n } else if (key === \"values\") {\n execFiltering({\n query,\n where: where[key] as CmsEntryListWhere,\n isValues: true\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n let fieldId: string = isValues ? `values.${whereFieldId}` : whereFieldId;\n\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`, \"EXEC_FILTERING_ERROR\");\n }\n const filter = getFilter(field.type);\n\n filter.exec({\n applyFiltering,\n getFilter,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAQvC,SAASC,wBAAwB;AACjC,SAASC,eAAe;AACxB,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,cAAc;AACvB,SAASC,YAAY;AACrB,SAASC,oBAAoB;AAC7B,SAASC,+BAA+B;AAmBxC,OAAO,MAAMC,mBAAmB,GAAIC,MAAwB,IAAkC;EAC1F,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,KAAK;IAAEC,mBAAmB;IAAEC;EAAe,CAAC,GAAGL,MAAM;EAE9E,MAAMM,eAAe,GAAGd,wBAAwB,CAAC;IAC7CU;EACJ,CAAC,CAAC;EAEF,MAAMK,cAAc,GAAGV,oBAAoB,CAAC;IACxCS,eAAe;IACfF;EACJ,CAAC,CAAC;EAEF,MAAMI,SAAS,GAAIC,IAAY,IAAK;IAChC,OAAOJ,cAAc,CAACK,GAAG,CAACD,IAAI,CAAC;EACnC,CAAC;EAED,MAAME,aAAa,GAAIX,MAAmB,IAAK;IAC3C,MAAM;MAAEY,KAAK,EAAEC,YAAY;MAAEC,KAAK;MAAEC,QAAQ,GAAG;IAAM,CAAC,GAAGf,MAAM;IAC/D,MAAMgB,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACH,YAAY,CAAC;IACtC,IAAIG,IAAI,CAACE,MAAM,KAAK,CAAC,EAAE;MACnB;IACJ;IACA,MAAMN,KAAK,GAAGO,eAAe,CAACN,YAAY,CAAC;IAE3C,KAAK,MAAMO,GAAG,IAAIR,KAAK,EAAE;MACrB,MAAMS,KAAK,GAAGT,KAAK,CAACQ,GAAG,CAAuB;MAC9C,IAAIC,K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ec.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type {\n OpenSearchBoolQueryConfig,\n QueryDslQueryContainer as Query\n} from \"@webiny/api-opensearch/types.js\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator.js\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { parseWhereKey } from \"@webiny/api-opensearch\";\nimport { getWhereValues } from \"./values.js\";\nimport { getPopulated } from \"./populated.js\";\nimport { createApplyFiltering } from \"./applyFiltering.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\nimport type { CmsEntryOpenSearchFilterRegistry } from \"~/features/CmsEntryOpenSearchFilter/index.js\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface;\n}\nexport interface IExecParams {\n where: CmsEntryListWhere;\n query: OpenSearchBoolQueryConfig;\n isValues?: boolean;\n}\nexport interface CreateExecFilteringResponse {\n (params: IExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model, valueSearchRegistry, filterRegistry } = params;\n\n const operatorPlugins = createOperatorPluginList({\n plugins\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n valueSearchRegistry\n });\n\n const getFilter = (type: string) => {\n return filterRegistry.get(type);\n };\n\n const execFiltering = (params: IExecParams) => {\n const { where: initialWhere, query, isValues = false } = params;\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where = structuredClone(initialWhere);\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n } else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n const childQuery = createBaseQuery();\n for (const childWhere of childWhereList) {\n execFiltering({ query: childQuery, where: childWhere, isValues });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({ bool: childQueryBool });\n continue;\n } else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({ query: childQuery, where: childWhere, isValues });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({ bool: childQueryBool });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n assignMinimumShouldMatchToQuery({ query });\n continue;\n } else if (key === \"values\") {\n execFiltering({\n query,\n where: where[key] as CmsEntryListWhere,\n isValues: true\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n let fieldId: string = isValues ? `values.${whereFieldId}` : whereFieldId;\n\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`, \"EXEC_FILTERING_ERROR\");\n }\n const filter = getFilter(field.type);\n\n filter.exec({\n applyFiltering,\n getFilter,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"names":["createExecFiltering","params","fields","plugins","model","valueSearchRegistry","filterRegistry","operatorPlugins","createOperatorPluginList","applyFiltering","createApplyFiltering","getFilter","type","execFiltering","initialWhere","query","isValues","keys","Object","where","structuredClone","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","should","assignMinimumShouldMatchToQuery","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","f","WebinyError","field","filter"],"mappings":";;;;;;;;AAiCO,MAAMA,sBAAsB,CAACC;IAChC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,mBAAmB,EAAEC,cAAc,EAAE,GAAGL;IAExE,MAAMM,kBAAkBC,yBAAyB;QAC7CL;IACJ;IAEA,MAAMM,iBAAiBC,qBAAqB;QACxCH;QACAF;IACJ;IAEA,MAAMM,YAAY,CAACC,OACRN,eAAe,GAAG,CAACM;IAG9B,MAAMC,gBAAgB,CAACZ;QACnB,MAAM,EAAE,OAAOa,YAAY,EAAEC,KAAK,EAAEC,WAAW,KAAK,EAAE,GAAGf;QACzD,MAAMgB,OAAOC,OAAO,IAAI,CAACJ;QACzB,IAAIG,AAAgB,MAAhBA,KAAK,MAAM,EACX;QAEJ,MAAME,QAAQC,gBAAgBN;QAE9B,IAAK,MAAMO,OAAOF,MAAO;YACrB,MAAMG,QAAQH,KAAK,CAACE,IAA0B;YAC9C,IAAIC,AAAUC,WAAVD,OACA;YACG,IAAID,AAAQ,UAARA,KAAe;gBACtB,MAAMG,iBAAiBC,eAAeH,OAAO;gBAC7C,MAAMI,aAAaC;gBACnB,KAAK,MAAMC,cAAcJ,eACrBX,cAAc;oBAAE,OAAOa;oBAAY,OAAOE;oBAAYZ;gBAAS;gBAEnE,MAAMa,iBAAiBC,aAAaJ;gBACpC,IAAIR,AAAuC,MAAvCA,OAAO,IAAI,CAACW,gBAAgB,MAAM,EAClC;gBAEJd,MAAM,MAAM,CAAC,IAAI,CAAC;oBAAE,MAAMc;gBAAe;gBACzC;YACJ;YAAO,IAAIR,AAAQ,SAARA,KAAc;gBACrB,MAAMG,iBAAiBC,eAAeH,OAAO;gBAC7C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@@ -1,3 +1 @@
1
1
  export * from "./exec.js";
2
-
3
- //# sourceMappingURL=index.js.map
@@ -1,36 +1,27 @@
1
- export const createFieldPathFactory = ({
2
- valueSearchRegistry
3
- }) => {
4
- return params => {
5
- const {
6
- field,
7
- key,
8
- value,
9
- keyword,
10
- originalValue
11
- } = params;
12
- const search = valueSearchRegistry.get(field.type);
13
- let fieldPath = null;
14
- if (search) {
15
- fieldPath = search.createPath({
16
- field: field.field,
17
- value,
18
- key,
19
- originalValue
20
- });
21
- }
22
- if (!fieldPath) {
23
- fieldPath = field.field.storageId;
24
- if (field.path) {
25
- fieldPath = typeof field.path === "function" ? field.path(value) : field.path;
26
- }
27
- }
28
- const result = field.parents.map(p => p.storageId).concat([fieldPath]);
29
- return {
30
- basePath: result.join("."),
31
- path: result.concat(keyword ? ["keyword"] : []).join(".")
1
+ const createFieldPathFactory = ({ valueSearchRegistry })=>(params)=>{
2
+ const { field, key, value, keyword, originalValue } = params;
3
+ const search = valueSearchRegistry.get(field.type);
4
+ let fieldPath = null;
5
+ if (search) fieldPath = search.createPath({
6
+ field: field.field,
7
+ value,
8
+ key,
9
+ originalValue
10
+ });
11
+ if (!fieldPath) {
12
+ fieldPath = field.field.storageId;
13
+ if (field.path) fieldPath = "function" == typeof field.path ? field.path(value) : field.path;
14
+ }
15
+ const result = field.parents.map((p)=>p.storageId).concat([
16
+ fieldPath
17
+ ]);
18
+ return {
19
+ basePath: result.join("."),
20
+ path: result.concat(keyword ? [
21
+ "keyword"
22
+ ] : []).join(".")
23
+ };
32
24
  };
33
- };
34
- };
25
+ export { createFieldPathFactory };
35
26
 
36
27
  //# sourceMappingURL=path.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFieldPathFactory","valueSearchRegistry","params","field","key","value","keyword","originalValue","search","get","type","fieldPath","createPath","storageId","path","result","parents","map","p","concat","basePath","join"],"sources":["path.ts"],"sourcesContent":["import type { ModelField } from \"~/operations/entry/elasticsearch/types.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\n\ninterface FieldPathFactoryParams {\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n originalValue: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ valueSearchRegistry }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword, originalValue } = params;\n const search = valueSearchRegistry.get(field.type);\n\n let fieldPath: string | null = null;\n if (search) {\n fieldPath = search.createPath({ field: field.field, value, key, originalValue });\n }\n if (!fieldPath) {\n fieldPath = field.field.storageId;\n if (field.path) {\n fieldPath = typeof field.path === \"function\" ? field.path(value) : field.path;\n }\n }\n\n const result: string[] = field.parents.map(p => p.storageId).concat([fieldPath]);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"mappings":"AAcA,OAAO,MAAMA,sBAAsB,GAAGA,CAAC;EAAEC;AAA4C,CAAC,KAAK;EACvF,OAAQC,MAAuB,IAAK;IAChC,MAAM;MAAEC,KAAK;MAAEC,GAAG;MAAEC,KAAK;MAAEC,OAAO;MAAEC;IAAc,CAAC,GAAGL,MAAM;IAC5D,MAAMM,MAAM,GAAGP,mBAAmB,CAACQ,GAAG,CAACN,KAAK,CAACO,IAAI,CAAC;IAElD,IAAIC,SAAwB,GAAG,IAAI;IACnC,IAAIH,MAAM,EAAE;MACRG,SAAS,GAAGH,MAAM,CAACI,UAAU,CAAC;QAAET,KAAK,EAAEA,KAAK,CAACA,KAAK;QAAEE,KAAK;QAAED,GAAG;QAAEG;MAAc,CAAC,CAAC;IACpF;IACA,IAAI,CAACI,SAAS,EAAE;MACZA,SAAS,GAAGR,KAAK,CAACA,KAAK,CAACU,SAAS;MACjC,IAAIV,KAAK,CAACW,IAAI,EAAE;QACZH,SAAS,GAAG,OAAOR,KAAK,CAACW,IAAI,KAAK,UAAU,GAAGX,KAAK,CAACW,IAAI,CAACT,KAAK,CAAC,GAAGF,KAAK,CAACW,IAAI;MACjF;IACJ;IAEA,MAAMC,MAAgB,GAAGZ,KAAK,CAACa,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACL,SAAS,CAAC,CAACM,MAAM,CAAC,CAACR,SAAS,CAAC,CAAC;IAEhF,OAAO;MACHS,QAAQ,EAAEL,MAAM,CAACM,IAAI,CAAC,GAAG,CAAC;MAC1BP,IAAI,EAAEC,MAAM,CAACI,MAAM,CAACb,OAAO,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAACe,IAAI,CAAC,GAAG;IAC5D,CAAC;EACL,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/elasticsearch/filtering/path.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/path.ts"],"sourcesContent":["import type { ModelField } from \"~/operations/entry/elasticsearch/types.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\n\ninterface FieldPathFactoryParams {\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n originalValue: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ valueSearchRegistry }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword, originalValue } = params;\n const search = valueSearchRegistry.get(field.type);\n\n let fieldPath: string | null = null;\n if (search) {\n fieldPath = search.createPath({ field: field.field, value, key, originalValue });\n }\n if (!fieldPath) {\n fieldPath = field.field.storageId;\n if (field.path) {\n fieldPath = typeof field.path === \"function\" ? field.path(value) : field.path;\n }\n }\n\n const result: string[] = field.parents.map(p => p.storageId).concat([fieldPath]);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"names":["createFieldPathFactory","valueSearchRegistry","params","field","key","value","keyword","originalValue","search","fieldPath","result","p"],"mappings":"AAcO,MAAMA,yBAAyB,CAAC,EAAEC,mBAAmB,EAA0B,GAC3E,CAACC;QACJ,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAEC,KAAK,EAAEC,OAAO,EAAEC,aAAa,EAAE,GAAGL;QACtD,MAAMM,SAASP,oBAAoB,GAAG,CAACE,MAAM,IAAI;QAEjD,IAAIM,YAA2B;QAC/B,IAAID,QACAC,YAAYD,OAAO,UAAU,CAAC;YAAE,OAAOL,MAAM,KAAK;YAAEE;YAAOD;YAAKG;QAAc;QAElF,IAAI,CAACE,WAAW;YACZA,YAAYN,MAAM,KAAK,CAAC,SAAS;YACjC,IAAIA,MAAM,IAAI,EACVM,YAAY,AAAsB,cAAtB,OAAON,MAAM,IAAI,GAAkBA,MAAM,IAAI,CAACE,SAASF,MAAM,IAAI;QAErF;QAEA,MAAMO,SAAmBP,MAAM,OAAO,CAAC,GAAG,CAACQ,CAAAA,IAAKA,EAAE,SAAS,EAAE,MAAM,CAAC;YAACF;SAAU;QAE/E,OAAO;YACH,UAAUC,OAAO,IAAI,CAAC;YACtB,MAAMA,OAAO,MAAM,CAACJ,UAAU;gBAAC;aAAU,GAAG,EAAE,EAAE,IAAI,CAAC;QACzD;IACJ"}
@@ -1,18 +1,12 @@
1
- export const getPopulated = query => {
2
- const result = {};
3
- let key;
4
- for (key in query) {
5
- const value = query[key];
6
- if (value === undefined || Array.isArray(value) && value.length === 0) {
7
- continue;
1
+ const getPopulated = (query)=>{
2
+ const result = {};
3
+ let key;
4
+ for(key in query){
5
+ const value = query[key];
6
+ if (!(void 0 === value || Array.isArray(value) && 0 === value.length)) result[key] = value;
8
7
  }
9
- /**
10
- * TODO figure out better types.
11
- */
12
- // @ts-expect-error
13
- result[key] = value;
14
- }
15
- return result;
8
+ return result;
16
9
  };
10
+ export { getPopulated };
17
11
 
18
12
  //# sourceMappingURL=populated.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getPopulated","query","result","key","value","undefined","Array","isArray","length"],"sources":["populated.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\n\nexport const getPopulated = (\n query: OpenSearchBoolQueryConfig\n): Partial<OpenSearchBoolQueryConfig> => {\n const result: Partial<OpenSearchBoolQueryConfig> = {};\n let key: keyof OpenSearchBoolQueryConfig;\n for (key in query) {\n const value = query[key];\n if (value === undefined || (Array.isArray(value) && value.length === 0)) {\n continue;\n }\n /**\n * TODO figure out better types.\n */\n // @ts-expect-error\n result[key] = value;\n }\n return result;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,YAAY,GACrBC,KAAgC,IACK;EACrC,MAAMC,MAA0C,GAAG,CAAC,CAAC;EACrD,IAAIC,GAAoC;EACxC,KAAKA,GAAG,IAAIF,KAAK,EAAE;IACf,MAAMG,KAAK,GAAGH,KAAK,CAACE,GAAG,CAAC;IACxB,IAAIC,KAAK,KAAKC,SAAS,IAAKC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,IAAIA,KAAK,CAACI,MAAM,KAAK,CAAE,EAAE;MACrE;IACJ;IACA;AACR;AACA;IACQ;IACAN,MAAM,CAACC,GAAG,CAAC,GAAGC,KAAK;EACvB;EACA,OAAOF,MAAM;AACjB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/elasticsearch/filtering/populated.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/populated.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\n\nexport const getPopulated = (\n query: OpenSearchBoolQueryConfig\n): Partial<OpenSearchBoolQueryConfig> => {\n const result: Partial<OpenSearchBoolQueryConfig> = {};\n let key: keyof OpenSearchBoolQueryConfig;\n for (key in query) {\n const value = query[key];\n if (value === undefined || (Array.isArray(value) && value.length === 0)) {\n continue;\n }\n /**\n * TODO figure out better types.\n */\n // @ts-expect-error\n result[key] = value;\n }\n return result;\n};\n"],"names":["getPopulated","query","result","key","value","undefined","Array"],"mappings":"AAEO,MAAMA,eAAe,CACxBC;IAEA,MAAMC,SAA6C,CAAC;IACpD,IAAIC;IACJ,IAAKA,OAAOF,MAAO;QACf,MAAMG,QAAQH,KAAK,CAACE,IAAI;QACxB,KAAIC,CAAAA,AAAUC,WAAVD,SAAwBE,MAAM,OAAO,CAACF,UAAUA,AAAiB,MAAjBA,MAAM,MAAM,AAAK,GAOrEF,MAAM,CAACC,IAAI,GAAGC;IAClB;IACA,OAAOF;AACX"}
@@ -1,16 +1,15 @@
1
- import WebinyError from "@webiny/error";
2
- export const getWhereValues = (value, condition) => {
3
- const values = value;
4
- if (!Array.isArray(values)) {
5
- throw new WebinyError(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
6
- value
1
+ import error from "@webiny/error";
2
+ const getWhereValues = (value, condition)=>{
3
+ const values = value;
4
+ if (Array.isArray(values)) {
5
+ if (0 === values.length) throw new error(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
6
+ value
7
+ });
8
+ } else throw new error(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
9
+ value
7
10
  });
8
- } else if (values.length === 0) {
9
- throw new WebinyError(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
10
- value
11
- });
12
- }
13
- return values;
11
+ return values;
14
12
  };
13
+ export { getWhereValues };
15
14
 
16
15
  //# sourceMappingURL=values.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebinyError","getWhereValues","value","condition","values","Array","isArray","length"],"sources":["values.ts"],"sourcesContent":["import type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getWhereValues = (value: unknown, condition: \"AND\" | \"OR\") => {\n const values = value as CmsEntryListWhere[] | undefined;\n if (!Array.isArray(values)) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is not an array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n } else if (values.length === 0) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is empty array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n }\n return values;\n};\n"],"mappings":"AACA,OAAOA,WAAW,MAAM,eAAe;AAEvC,OAAO,MAAMC,cAAc,GAAGA,CAACC,KAAc,EAAEC,SAAuB,KAAK;EACvE,MAAMC,MAAM,GAAGF,KAAwC;EACvD,IAAI,CAACG,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACxB,MAAM,IAAIJ,WAAW,CACjB,iCAAiCG,SAAS,wCAAwC,EAClF,aAAaA,SAAS,YAAY,EAClC;MACID;IACJ,CACJ,CAAC;EACL,CAAC,MAAM,IAAIE,MAAM,CAACG,MAAM,KAAK,CAAC,EAAE;IAC5B,MAAM,IAAIP,WAAW,CACjB,iCAAiCG,SAAS,uCAAuC,EACjF,aAAaA,SAAS,YAAY,EAClC;MACID;IACJ,CACJ,CAAC;EACL;EACA,OAAOE,MAAM;AACjB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/elasticsearch/filtering/values.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/values.ts"],"sourcesContent":["import type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getWhereValues = (value: unknown, condition: \"AND\" | \"OR\") => {\n const values = value as CmsEntryListWhere[] | undefined;\n if (!Array.isArray(values)) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is not an array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n } else if (values.length === 0) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is empty array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n }\n return values;\n};\n"],"names":["getWhereValues","value","condition","values","Array","WebinyError"],"mappings":";AAGO,MAAMA,iBAAiB,CAACC,OAAgBC;IAC3C,MAAMC,SAASF;IACf,IAAKG,MAAM,OAAO,CAACD,SAQZ;QAAA,IAAIA,AAAkB,MAAlBA,OAAO,MAAM,EACpB,MAAM,IAAIE,MACN,CAAC,8BAA8B,EAAEH,UAAU,qCAAqC,CAAC,EACjF,CAAC,UAAU,EAAEA,UAAU,UAAU,CAAC,EAClC;YACID;QACJ;IAER,OAfI,MAAM,IAAII,MACN,CAAC,8BAA8B,EAAEH,UAAU,sCAAsC,CAAC,EAClF,CAAC,UAAU,EAAEA,UAAU,UAAU,CAAC,EAClC;QACID;IACJ;IAWR,OAAOE;AACX"}
@@ -1,88 +1,51 @@
1
1
  import { normalizeValue } from "@webiny/api-opensearch";
2
- /**
3
- * Our default implementation works with the AND operator for the multiple words query string.
4
- */
5
2
  const defaultFullTextSearch = {
6
- apply: params => {
7
- const {
8
- query,
9
- term,
10
- fields,
11
- createFieldPath,
12
- prepareTerm
13
- } = params;
14
- query.must.push({
15
- query_string: {
16
- allow_leading_wildcard: true,
17
- fields: Object.values(fields).map(createFieldPath),
18
- query: `*${prepareTerm(term)}*`,
19
- default_operator: "and"
20
- }
21
- });
22
- }
3
+ apply: (params)=>{
4
+ const { query, term, fields, createFieldPath, prepareTerm } = params;
5
+ query.must.push({
6
+ query_string: {
7
+ allow_leading_wildcard: true,
8
+ fields: Object.values(fields).map(createFieldPath),
9
+ query: `*${prepareTerm(term)}*`,
10
+ default_operator: "and"
11
+ }
12
+ });
13
+ }
23
14
  };
24
- const getFullTextSearch = params => {
25
- const {
26
- fullTextSearches,
27
- model
28
- } = params;
29
- /**
30
- * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.
31
- */
32
- const reversed = [...fullTextSearches].reverse();
33
- /**
34
- * We need to find the most specific implementation for the given model.
35
- * Also, we need to use the first possible implementation if the specific one is not found.
36
- */
37
- let fallback = null;
38
- for (const item of reversed) {
39
- const models = item.models || [];
40
- /**
41
- * We take the first available implementation for the given model.
42
- */
43
- if (models.includes(model.modelId)) {
44
- return item;
45
- } else if (!fallback && models.length === 0) {
46
- /**
47
- * Then we set the first possible implementation, which has no models defined, as the default one.
48
- * It is important not to set the one which has models defined as they are specifically for the targeted model.
49
- */
50
- fallback = item;
15
+ const getFullTextSearch = (params)=>{
16
+ const { fullTextSearches, model } = params;
17
+ const reversed = [
18
+ ...fullTextSearches
19
+ ].reverse();
20
+ let fallback = null;
21
+ for (const item of reversed){
22
+ const models = item.models || [];
23
+ if (models.includes(model.modelId)) return item;
24
+ if (!fallback && 0 === models.length) fallback = item;
51
25
  }
52
- }
53
- return fallback || defaultFullTextSearch;
26
+ return fallback || defaultFullTextSearch;
54
27
  };
55
- export const applyFullTextSearch = params => {
56
- const {
57
- fullTextSearches,
58
- query,
59
- term,
60
- fields,
61
- model
62
- } = params;
63
- const keys = Object.keys(fields);
64
- if (!term || term.length === 0 || keys.length === 0) {
65
- return;
66
- }
67
- const fullTextSearch = getFullTextSearch({
68
- fullTextSearches,
69
- model
70
- });
71
- fullTextSearch.apply({
72
- model,
73
- createFieldPath: field => {
74
- if (typeof field.path === "function") {
75
- return field.path(term);
76
- } else if (field.systemField) {
77
- return field.path || field.field.storageId;
78
- }
79
- return `values.${field.path || field.field.storageId}`;
80
- },
81
- fields,
82
- query,
83
- term,
84
- prepareTerm: normalizeValue
85
- });
28
+ const applyFullTextSearch = (params)=>{
29
+ const { fullTextSearches, query, term, fields, model } = params;
30
+ const keys = Object.keys(fields);
31
+ if (!term || 0 === term.length || 0 === keys.length) return;
32
+ const fullTextSearch = getFullTextSearch({
33
+ fullTextSearches,
34
+ model
35
+ });
36
+ fullTextSearch.apply({
37
+ model,
38
+ createFieldPath: (field)=>{
39
+ if ("function" == typeof field.path) return field.path(term);
40
+ if (field.systemField) return field.path || field.field.storageId;
41
+ return `values.${field.path || field.field.storageId}`;
42
+ },
43
+ fields,
44
+ query,
45
+ term,
46
+ prepareTerm: normalizeValue
47
+ });
86
48
  };
49
+ export { applyFullTextSearch };
87
50
 
88
51
  //# sourceMappingURL=fullTextSearch.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["normalizeValue","defaultFullTextSearch","apply","params","query","term","fields","createFieldPath","prepareTerm","must","push","query_string","allow_leading_wildcard","Object","values","map","default_operator","getFullTextSearch","fullTextSearches","model","reversed","reverse","fallback","item","models","includes","modelId","length","applyFullTextSearch","keys","fullTextSearch","field","path","systemField","storageId"],"sources":["fullTextSearch.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport { normalizeValue } from \"@webiny/api-opensearch\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\n\n/**\n * Our default implementation works with the AND operator for the multiple words query string.\n */\nconst defaultFullTextSearch: CmsEntryOpenSearchFullTextSearch.Interface = {\n apply: params => {\n const { query, term, fields, createFieldPath, prepareTerm } = params;\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: Object.values(fields).map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n};\n\ninterface GetFullTextSearchParams {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n}\nconst getFullTextSearch = (\n params: GetFullTextSearchParams\n): CmsEntryOpenSearchFullTextSearch.Interface => {\n const { fullTextSearches, model } = params;\n /**\n * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.\n */\n const reversed = [...fullTextSearches].reverse();\n /**\n * We need to find the most specific implementation for the given model.\n * Also, we need to use the first possible implementation if the specific one is not found.\n */\n let fallback: CmsEntryOpenSearchFullTextSearch.Interface | null = null;\n for (const item of reversed) {\n const models = item.models || [];\n /**\n * We take the first available implementation for the given model.\n */\n if (models.includes(model.modelId)) {\n return item;\n } else if (!fallback && models.length === 0) {\n /**\n * Then we set the first possible implementation, which has no models defined, as the default one.\n * It is important not to set the one which has models defined as they are specifically for the targeted model.\n */\n fallback = item;\n }\n }\n\n return fallback || defaultFullTextSearch;\n};\n\ninterface Params {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n query: OpenSearchBoolQueryConfig;\n term?: string;\n fields: ModelFields;\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { fullTextSearches, query, term, fields, model } = params;\n const keys = Object.keys(fields);\n if (!term || term.length === 0 || keys.length === 0) {\n return;\n }\n\n const fullTextSearch = getFullTextSearch({\n fullTextSearches,\n model\n });\n\n fullTextSearch.apply({\n model,\n createFieldPath: field => {\n if (typeof field.path === \"function\") {\n return field.path(term);\n } else if (field.systemField) {\n return field.path || field.field.storageId;\n }\n return `values.${field.path || field.field.storageId}`;\n },\n fields,\n query,\n term,\n prepareTerm: normalizeValue\n });\n};\n"],"mappings":"AACA,SAASA,cAAc,QAAQ,wBAAwB;AAKvD;AACA;AACA;AACA,MAAMC,qBAAiE,GAAG;EACtEC,KAAK,EAAEC,MAAM,IAAI;IACb,MAAM;MAAEC,KAAK;MAAEC,IAAI;MAAEC,MAAM;MAAEC,eAAe;MAAEC;IAAY,CAAC,GAAGL,MAAM;IAEpEC,KAAK,CAACK,IAAI,CAACC,IAAI,CAAC;MACZC,YAAY,EAAE;QACVC,sBAAsB,EAAE,IAAI;QAC5BN,MAAM,EAAEO,MAAM,CAACC,MAAM,CAACR,MAAM,CAAC,CAACS,GAAG,CAACR,eAAe,CAAC;QAClDH,KAAK,EAAE,IAAII,WAAW,CAACH,IAAI,CAAC,GAAG;QAC/BW,gBAAgB,EAAE;MACtB;IACJ,CAAC,CAAC;EACN;AACJ,CAAC;AAMD,MAAMC,iBAAiB,GACnBd,MAA+B,IACc;EAC7C,MAAM;IAAEe,gBAAgB;IAAEC;EAAM,CAAC,GAAGhB,MAAM;EAC1C;AACJ;AACA;EACI,MAAMiB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ACG,SAAS;MAC9C;MACA,OAAO,UAAUH,KAAK,CAACC,IAAI,IAAID,KAAK,CAACA,KAAK,CAACG,SAAS,EAAE;IAC1D,CAAC;IACD5B,MAAM;IACNF,KAAK;IACLC,IAAI;IACJG,WAAW,EAAER;EACjB,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"operations/entry/elasticsearch/fullTextSearch.js","sources":["../../../../src/operations/entry/elasticsearch/fullTextSearch.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport { normalizeValue } from \"@webiny/api-opensearch\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\n\n/**\n * Our default implementation works with the AND operator for the multiple words query string.\n */\nconst defaultFullTextSearch: CmsEntryOpenSearchFullTextSearch.Interface = {\n apply: params => {\n const { query, term, fields, createFieldPath, prepareTerm } = params;\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: Object.values(fields).map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n};\n\ninterface GetFullTextSearchParams {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n}\nconst getFullTextSearch = (\n params: GetFullTextSearchParams\n): CmsEntryOpenSearchFullTextSearch.Interface => {\n const { fullTextSearches, model } = params;\n /**\n * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.\n */\n const reversed = [...fullTextSearches].reverse();\n /**\n * We need to find the most specific implementation for the given model.\n * Also, we need to use the first possible implementation if the specific one is not found.\n */\n let fallback: CmsEntryOpenSearchFullTextSearch.Interface | null = null;\n for (const item of reversed) {\n const models = item.models || [];\n /**\n * We take the first available implementation for the given model.\n */\n if (models.includes(model.modelId)) {\n return item;\n } else if (!fallback && models.length === 0) {\n /**\n * Then we set the first possible implementation, which has no models defined, as the default one.\n * It is important not to set the one which has models defined as they are specifically for the targeted model.\n */\n fallback = item;\n }\n }\n\n return fallback || defaultFullTextSearch;\n};\n\ninterface Params {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n query: OpenSearchBoolQueryConfig;\n term?: string;\n fields: ModelFields;\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { fullTextSearches, query, term, fields, model } = params;\n const keys = Object.keys(fields);\n if (!term || term.length === 0 || keys.length === 0) {\n return;\n }\n\n const fullTextSearch = getFullTextSearch({\n fullTextSearches,\n model\n });\n\n fullTextSearch.apply({\n model,\n createFieldPath: field => {\n if (typeof field.path === \"function\") {\n return field.path(term);\n } else if (field.systemField) {\n return field.path || field.field.storageId;\n }\n return `values.${field.path || field.field.storageId}`;\n },\n fields,\n query,\n term,\n prepareTerm: normalizeValue\n });\n};\n"],"names":["defaultFullTextSearch","params","query","term","fields","createFieldPath","prepareTerm","Object","getFullTextSearch","fullTextSearches","model","reversed","fallback","item","models","applyFullTextSearch","keys","fullTextSearch","field","normalizeValue"],"mappings":";AASA,MAAMA,wBAAoE;IACtE,OAAOC,CAAAA;QACH,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEC,eAAe,EAAEC,WAAW,EAAE,GAAGL;QAE9DC,MAAM,IAAI,CAAC,IAAI,CAAC;YACZ,cAAc;gBACV,wBAAwB;gBACxB,QAAQK,OAAO,MAAM,CAACH,QAAQ,GAAG,CAACC;gBAClC,OAAO,CAAC,CAAC,EAAEC,YAAYH,MAAM,CAAC,CAAC;gBAC/B,kBAAkB;YACtB;QACJ;IACJ;AACJ;AAMA,MAAMK,oBAAoB,CACtBP;IAEA,MAAM,EAAEQ,gBAAgB,EAAEC,KAAK,EAAE,GAAGT;IAIpC,MAAMU,WAAW;WAAIF;KAAiB,CAAC,OAAO;IAK9C,IAAIG,WAA8D;IAClE,KAAK,MAAMC,QAAQF,SAAU;QACzB,MAAMG,SAASD,KAAK,MAAM,IAAI,EAAE;QAIhC,IAAIC,OAAO,QAAQ,CAACJ,MAAM,OAAO,GAC7B,OAAOG;QACJ,IAAI,CAACD,YAAYE,AAAkB,MAAlBA,OAAO,MAAM,EAKjCF,WAAWC;IAEnB;IAEA,OAAOD,YAAYZ;AACvB;AASO,MAAMe,sBAAsB,CAACd;IAChC,MAAM,EAAEQ,gBAAgB,EAAEP,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEM,KAAK,EAAE,GAAGT;IACzD,MAAMe,OAAOT,OAAO,IAAI,CAACH;IACzB,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,IAAUa,AAAgB,MAAhBA,KAAK,MAAM,EACzC;IAGJ,MAAMC,iBAAiBT,kBAAkB;QACrCC;QACAC;IACJ;IAEAO,eAAe,KAAK,CAAC;QACjBP;QACA,iBAAiBQ,CAAAA;YACb,IAAI,AAAsB,cAAtB,OAAOA,MAAM,IAAI,EACjB,OAAOA,MAAM,IAAI,CAACf;YACf,IAAIe,MAAM,WAAW,EACxB,OAAOA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS;YAE9C,OAAO,CAAC,OAAO,EAAEA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS,EAAE;QAC1D;QACAd;QACAF;QACAC;QACA,aAAagB;IACjB;AACJ"}
@@ -1,20 +1,10 @@
1
- export const createFullTextSearchFields = params => {
2
- const {
3
- term,
4
- targets,
5
- fields
6
- } = params;
7
- if (!targets?.length || !term || term.trim().length === 0) {
8
- return {};
9
- }
10
- const result = {};
11
- for (const key in fields) {
12
- if (targets.includes(key) === false) {
13
- continue;
14
- }
15
- result[key] = fields[key];
16
- }
17
- return result;
1
+ const createFullTextSearchFields = (params)=>{
2
+ const { term, targets, fields } = params;
3
+ if (!targets?.length || !term || 0 === term.trim().length) return {};
4
+ const result = {};
5
+ for(const key in fields)if (false !== targets.includes(key)) result[key] = fields[key];
6
+ return result;
18
7
  };
8
+ export { createFullTextSearchFields };
19
9
 
20
10
  //# sourceMappingURL=fullTextSearchFields.js.map