@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.2af142b57e

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 (252) hide show
  1. package/configurations.d.ts +2 -2
  2. package/configurations.js +13 -10
  3. package/configurations.js.map +1 -0
  4. package/definitions/entry.d.ts +2 -2
  5. package/definitions/entry.js +6 -12
  6. package/definitions/entry.js.map +1 -0
  7. package/definitions/entryElasticsearch.d.ts +2 -2
  8. package/definitions/entryElasticsearch.js +3 -12
  9. package/definitions/entryElasticsearch.js.map +1 -0
  10. package/definitions/group.d.ts +2 -2
  11. package/definitions/group.js +3 -12
  12. package/definitions/group.js.map +1 -0
  13. package/definitions/model.d.ts +2 -2
  14. package/definitions/model.js +8 -12
  15. package/definitions/model.js.map +1 -0
  16. package/definitions/settings.d.ts +2 -2
  17. package/definitions/settings.js +3 -12
  18. package/definitions/settings.js.map +1 -0
  19. package/definitions/system.d.ts +2 -2
  20. package/definitions/system.js +3 -12
  21. package/definitions/system.js.map +1 -0
  22. package/definitions/table.d.ts +2 -2
  23. package/definitions/table.js +0 -3
  24. package/definitions/table.js.map +1 -0
  25. package/definitions/tableElasticsearch.d.ts +2 -2
  26. package/definitions/tableElasticsearch.js +0 -3
  27. package/definitions/tableElasticsearch.js.map +1 -0
  28. package/dynamoDb/index.d.ts +1 -1
  29. package/dynamoDb/index.js +4 -11
  30. package/dynamoDb/index.js.map +1 -0
  31. package/dynamoDb/storage/date.d.ts +3 -3
  32. package/dynamoDb/storage/date.js +73 -54
  33. package/dynamoDb/storage/date.js.map +1 -0
  34. package/dynamoDb/storage/longText.d.ts +7 -4
  35. package/dynamoDb/storage/longText.js +72 -64
  36. package/dynamoDb/storage/longText.js.map +1 -0
  37. package/dynamoDb/storage/richText.d.ts +2 -3
  38. package/dynamoDb/storage/richText.js +74 -78
  39. package/dynamoDb/storage/richText.js.map +1 -0
  40. package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
  41. package/elasticsearch/createElasticsearchIndex.js +49 -0
  42. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  43. package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
  44. package/elasticsearch/deleteElasticsearchIndex.js +36 -0
  45. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
  46. package/elasticsearch/index.d.ts +1 -1
  47. package/elasticsearch/index.js +1 -6
  48. package/elasticsearch/index.js.map +1 -0
  49. package/elasticsearch/indexing/dateTimeIndexing.js +17 -20
  50. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
  51. package/elasticsearch/indexing/defaultFieldIndexing.js +5 -9
  52. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
  53. package/elasticsearch/indexing/index.js +1 -10
  54. package/elasticsearch/indexing/index.js.map +1 -0
  55. package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
  56. package/elasticsearch/indexing/longTextIndexing.js +19 -9
  57. package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
  58. package/elasticsearch/indexing/numberIndexing.js +0 -9
  59. package/elasticsearch/indexing/numberIndexing.js.map +1 -0
  60. package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
  61. package/elasticsearch/indexing/objectIndexing.js +26 -30
  62. package/elasticsearch/indexing/objectIndexing.js.map +1 -0
  63. package/elasticsearch/indexing/richTextIndexing.js +0 -5
  64. package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
  65. package/elasticsearch/indices/base.d.ts +2 -0
  66. package/elasticsearch/indices/base.js +12 -0
  67. package/elasticsearch/indices/base.js.map +1 -0
  68. package/elasticsearch/indices/index.d.ts +1 -0
  69. package/elasticsearch/indices/index.js +12 -0
  70. package/elasticsearch/indices/index.js.map +1 -0
  71. package/elasticsearch/indices/japanese.d.ts +2 -0
  72. package/elasticsearch/indices/japanese.js +13 -0
  73. package/elasticsearch/indices/japanese.js.map +1 -0
  74. package/elasticsearch/search/index.d.ts +2 -2
  75. package/elasticsearch/search/index.js +3 -9
  76. package/elasticsearch/search/index.js.map +1 -0
  77. package/elasticsearch/search/refSearch.d.ts +2 -3
  78. package/elasticsearch/search/refSearch.js +23 -18
  79. package/elasticsearch/search/refSearch.js.map +1 -0
  80. package/elasticsearch/search/timeSearch.d.ts +2 -3
  81. package/elasticsearch/search/timeSearch.js +18 -17
  82. package/elasticsearch/search/timeSearch.js.map +1 -0
  83. package/helpers/entryIndexHelpers.js +43 -57
  84. package/helpers/entryIndexHelpers.js.map +1 -0
  85. package/helpers/index.d.ts +0 -1
  86. package/helpers/index.js +0 -15
  87. package/helpers/index.js.map +1 -0
  88. package/index.d.ts +1 -0
  89. package/index.js +120 -58
  90. package/index.js.map +1 -0
  91. package/operations/entry/dataLoaders.d.ts +6 -2
  92. package/operations/entry/dataLoaders.js +27 -61
  93. package/operations/entry/dataLoaders.js.map +1 -0
  94. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  95. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +32 -0
  96. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  97. package/operations/entry/elasticsearch/body.d.ts +13 -0
  98. package/operations/entry/elasticsearch/body.js +140 -0
  99. package/operations/entry/elasticsearch/body.js.map +1 -0
  100. package/operations/entry/elasticsearch/fields.d.ts +9 -0
  101. package/operations/entry/elasticsearch/fields.js +229 -0
  102. package/operations/entry/elasticsearch/fields.js.map +1 -0
  103. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
  104. package/operations/entry/elasticsearch/filtering/applyFiltering.js +57 -0
  105. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
  106. package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
  107. package/operations/entry/elasticsearch/filtering/exec.js +172 -0
  108. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
  109. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
  110. package/operations/entry/elasticsearch/filtering/index.js +16 -0
  111. package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
  112. package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
  113. package/operations/entry/elasticsearch/filtering/path.js +44 -0
  114. package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
  115. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  116. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +28 -0
  117. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  118. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  119. package/operations/entry/elasticsearch/filtering/plugins/index.js +13 -0
  120. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  121. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  122. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +65 -0
  123. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  124. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  125. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +48 -0
  126. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  127. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
  128. package/operations/entry/elasticsearch/filtering/populated.js +23 -0
  129. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
  130. package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
  131. package/operations/entry/elasticsearch/filtering/values.js +22 -0
  132. package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
  133. package/operations/entry/elasticsearch/fullTextSearch.d.ts +12 -0
  134. package/operations/entry/elasticsearch/fullTextSearch.js +89 -0
  135. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
  136. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
  137. package/operations/entry/elasticsearch/fullTextSearchFields.js +25 -0
  138. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
  139. package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
  140. package/operations/entry/elasticsearch/initialQuery.js +103 -0
  141. package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
  142. package/operations/entry/elasticsearch/keyword.d.ts +2 -0
  143. package/operations/entry/elasticsearch/keyword.js +34 -0
  144. package/operations/entry/elasticsearch/keyword.js.map +1 -0
  145. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
  146. package/operations/entry/elasticsearch/plugins/bodyModifier.js +16 -0
  147. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
  148. package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
  149. package/operations/entry/elasticsearch/plugins/operator.js +37 -0
  150. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
  151. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
  152. package/operations/entry/elasticsearch/plugins/queryModifier.js +16 -0
  153. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
  154. package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
  155. package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +8 -10
  156. package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
  157. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
  158. package/operations/entry/elasticsearch/plugins/sortModifier.js +16 -0
  159. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
  160. package/operations/entry/elasticsearch/sort.d.ts +12 -0
  161. package/operations/entry/elasticsearch/sort.js +82 -0
  162. package/operations/entry/elasticsearch/sort.js.map +1 -0
  163. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
  164. package/operations/entry/elasticsearch/transformValueForSearch.js +30 -0
  165. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
  166. package/operations/entry/elasticsearch/types.d.ts +41 -0
  167. package/operations/entry/elasticsearch/types.js +5 -0
  168. package/operations/entry/elasticsearch/types.js.map +1 -0
  169. package/operations/entry/index.d.ts +2 -4
  170. package/operations/entry/index.js +457 -481
  171. package/operations/entry/index.js.map +1 -0
  172. package/operations/entry/keys.js +0 -9
  173. package/operations/entry/keys.js.map +1 -0
  174. package/operations/entry/recordType.d.ts +3 -0
  175. package/operations/entry/recordType.js +18 -0
  176. package/operations/entry/recordType.js.map +1 -0
  177. package/operations/group/index.d.ts +2 -2
  178. package/operations/group/index.js +10 -47
  179. package/operations/group/index.js.map +1 -0
  180. package/operations/model/index.d.ts +2 -2
  181. package/operations/model/index.js +34 -68
  182. package/operations/model/index.js.map +1 -0
  183. package/operations/settings/index.d.ts +2 -2
  184. package/operations/settings/index.js +7 -37
  185. package/operations/settings/index.js.map +1 -0
  186. package/operations/system/index.d.ts +2 -2
  187. package/operations/system/index.js +5 -28
  188. package/operations/system/index.js.map +1 -0
  189. package/package.json +24 -29
  190. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +7 -3
  191. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +9 -11
  192. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
  193. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
  194. package/plugins/CmsEntryElasticsearchFieldPlugin.js +3 -9
  195. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
  196. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
  197. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +28 -0
  198. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
  199. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
  200. package/plugins/CmsEntryElasticsearchIndexPlugin.js +12 -0
  201. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
  202. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
  203. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +33 -0
  204. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
  205. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +4 -3
  206. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +9 -11
  207. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
  208. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +4 -3
  209. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +9 -11
  210. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
  211. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  212. package/plugins/CmsEntryFilterPlugin.js +24 -0
  213. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  214. package/plugins/index.d.ts +7 -0
  215. package/plugins/index.js +82 -0
  216. package/plugins/index.js.map +1 -0
  217. package/types.d.ts +7 -34
  218. package/types.js +0 -18
  219. package/types.js.map +1 -0
  220. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  221. package/helpers/createElasticsearchQueryBody.js +0 -375
  222. package/helpers/fields.d.ts +0 -77
  223. package/helpers/fields.js +0 -174
  224. package/helpers/operatorPluginsList.d.ts +0 -7
  225. package/helpers/operatorPluginsList.js +0 -30
  226. package/helpers/searchPluginsList.d.ts +0 -6
  227. package/helpers/transformValueForSearch.d.ts +0 -9
  228. package/helpers/transformValueForSearch.js +0 -26
  229. package/operations/entry/elasticsearchFields.d.ts +0 -2
  230. package/operations/entry/elasticsearchFields.js +0 -32
  231. package/operations/entry/fields.d.ts +0 -3
  232. package/operations/entry/fields.js +0 -60
  233. package/operations/system/createElasticsearchTemplate.d.ts +0 -5
  234. package/operations/system/createElasticsearchTemplate.js +0 -62
  235. package/upgrades/index.d.ts +0 -2
  236. package/upgrades/index.js +0 -16
  237. package/upgrades/utils.d.ts +0 -1
  238. package/upgrades/utils.js +0 -16
  239. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
  240. package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
  241. package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
  242. package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
  243. package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
  244. package/upgrades/v5.0.0/entryValueFixer.js +0 -124
  245. package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
  246. package/upgrades/v5.0.0/fieldFinder.js +0 -42
  247. package/upgrades/v5.0.0/helpers.d.ts +0 -4
  248. package/upgrades/v5.0.0/helpers.js +0 -57
  249. package/upgrades/v5.0.0/index.d.ts +0 -4
  250. package/upgrades/v5.0.0/index.js +0 -232
  251. package/upgrades/v5.8.0/index.d.ts +0 -4
  252. package/upgrades/v5.8.0/index.js +0 -426
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyFullTextSearch = void 0;
7
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
8
+ var _plugins = require("../../../plugins");
9
+ /**
10
+ * Our default plugin is working with the AND operator for the multiple words query string.
11
+ */
12
+ const defaultPlugin = (0, _plugins.createCmsEntryElasticsearchFullTextSearchPlugin)({
13
+ apply: params => {
14
+ const {
15
+ query,
16
+ term,
17
+ fields,
18
+ createFieldPath,
19
+ prepareTerm
20
+ } = params;
21
+ query.must.push({
22
+ query_string: {
23
+ allow_leading_wildcard: true,
24
+ fields: fields.map(createFieldPath),
25
+ query: `*${prepareTerm(term)}*`,
26
+ default_operator: "and"
27
+ }
28
+ });
29
+ }
30
+ });
31
+ defaultPlugin.name = "headless-cms.elasticsearch.entry.fullTextSearch.default";
32
+ const getPlugin = params => {
33
+ const {
34
+ container,
35
+ model
36
+ } = params;
37
+ /**
38
+ * We need to reverse the plugins, so we can take the last one first - possibility to override existing plugins.
39
+ */
40
+ const plugins = container.byType(_plugins.CmsEntryElasticsearchFullTextSearchPlugin.type).reverse();
41
+ /**
42
+ * We need to find the most specific plugin for the given model.
43
+ * Also, we need to use the first possible plugin if the specific one is not found.
44
+ */
45
+ let plugin = null;
46
+ for (const pl of plugins) {
47
+ const models = pl.models || [];
48
+ /**
49
+ * We take the first available plugin for the given model.
50
+ */
51
+ if (models.includes(model.modelId)) {
52
+ return pl;
53
+ }
54
+ /**
55
+ * Then we set the first possible plugin, which has no models defined, as the default one.
56
+ * It is important not to set the plugin which has models defined as they are specifically for the targeted model.
57
+ */
58
+ //
59
+ else if (!plugin && models.length === 0) {
60
+ plugin = pl;
61
+ }
62
+ }
63
+ return plugin || defaultPlugin;
64
+ };
65
+ const applyFullTextSearch = params => {
66
+ const {
67
+ plugins,
68
+ query,
69
+ term,
70
+ fields,
71
+ model
72
+ } = params;
73
+ if (!term || term.length === 0 || fields.length === 0) {
74
+ return;
75
+ }
76
+ const plugin = getPlugin({
77
+ container: plugins,
78
+ model
79
+ });
80
+ plugin.apply({
81
+ model,
82
+ createFieldPath: field => `values.${field.storageId}`,
83
+ fields,
84
+ query,
85
+ term,
86
+ prepareTerm: _apiElasticsearch.normalizeValue
87
+ });
88
+ };
89
+ exports.applyFullTextSearch = applyFullTextSearch;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["defaultPlugin","createCmsEntryElasticsearchFullTextSearchPlugin","apply","params","query","term","fields","createFieldPath","prepareTerm","must","push","query_string","allow_leading_wildcard","map","default_operator","name","getPlugin","container","model","plugins","byType","CmsEntryElasticsearchFullTextSearchPlugin","type","reverse","plugin","pl","models","includes","modelId","length","applyFullTextSearch","field","storageId","normalizeValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { normalizeValue } from \"@webiny/api-elasticsearch\";\nimport { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsEntryElasticsearchFullTextSearchPlugin,\n createCmsEntryElasticsearchFullTextSearchPlugin\n} from \"~/plugins\";\n\n/**\n * Our default plugin is working with the AND operator for the multiple words query string.\n */\nconst defaultPlugin = createCmsEntryElasticsearchFullTextSearchPlugin({\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: fields.map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n});\ndefaultPlugin.name = \"headless-cms.elasticsearch.entry.fullTextSearch.default\";\n\ninterface GetPluginParams {\n container: PluginsContainer;\n model: CmsModel;\n}\nconst getPlugin = (params: GetPluginParams): CmsEntryElasticsearchFullTextSearchPlugin => {\n const { container, model } = params;\n /**\n * We need to reverse the plugins, so we can take the last one first - possibility to override existing plugins.\n */\n const plugins = container\n .byType<CmsEntryElasticsearchFullTextSearchPlugin>(\n CmsEntryElasticsearchFullTextSearchPlugin.type\n )\n .reverse();\n /**\n * We need to find the most specific plugin for the given model.\n * Also, we need to use the first possible plugin if the specific one is not found.\n */\n let plugin: CmsEntryElasticsearchFullTextSearchPlugin | null = null;\n for (const pl of plugins) {\n const models = pl.models || [];\n /**\n * We take the first available plugin for the given model.\n */\n if (models.includes(model.modelId)) {\n return pl;\n }\n /**\n * Then we set the first possible plugin, which has no models defined, as the default one.\n * It is important not to set the plugin which has models defined as they are specifically for the targeted model.\n */\n //\n else if (!plugin && models.length === 0) {\n plugin = pl;\n }\n }\n\n return plugin || defaultPlugin;\n};\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n query: ElasticsearchBoolQueryConfig;\n term?: string;\n fields: CmsModelField[];\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { plugins, query, term, fields, model } = params;\n if (!term || term.length === 0 || fields.length === 0) {\n return;\n }\n\n const plugin = getPlugin({\n container: plugins,\n model\n });\n\n plugin.apply({\n model,\n createFieldPath: field => `values.${field.storageId}`,\n fields,\n query,\n term,\n prepareTerm: normalizeValue\n });\n};\n"],"mappings":";;;;;;AACA;AAGA;AAKA;AACA;AACA;AACA,MAAMA,aAAa,GAAG,IAAAC,wDAA+C,EAAC;EAClEC,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,EAAEA,MAAM,CAACO,GAAG,CAACN,eAAe,CAAC;QACnCH,KAAK,EAAG,IAAGI,WAAW,CAACH,IAAI,CAAE,GAAE;QAC/BS,gBAAgB,EAAE;MACtB;IACJ,CAAC,CAAC;EACN;AACJ,CAAC,CAAC;AACFd,aAAa,CAACe,IAAI,GAAG,yDAAyD;AAM9E,MAAMC,SAAS,GAAIb,MAAuB,IAAgD;EACtF,MAAM;IAAEc,SAAS;IAAEC;EAAM,CAAC,GAAGf,MAAM;EACnC;AACJ;AACA;EACI,MAAMgB,OAAO,GAAGF,SAAS,CACpBG,MAAM,CACHC,kDAAyC,CAACC,IAAI,CACjD,CACAC,OAAO,EAAE;EACd;AACJ;AACA;AACA;EACI,IAAIC,MAAwD,GAAG,IAAI;EACnE,KAAK,MAAMC,EAAE,IAAIN,OAAO,EAAE;IACtB,MAAMO,MAAM,GAAGD,EAAE,CAACC,MAAM,IAAI,EAAE;IAC9B;AACR;AACA;IACQ,IAAIA,MAAM,CAACC,QAAQ,CAACT,KAAK,CAACU,OAAO,CAAC,EAAE;MAChC,OAAOH,EAAE;IACb;IACA;AACR;AACA;AACA;IACQ;IAAA,KACK,IAAI,CAACD,MAAM,IAAIE,MAAM,CAACG,MAAM,KAAK,CAAC,EAAE;MACrCL,MAAM,GAAGC,EAAE;IACf;EACJ;EAEA,OAAOD,MAAM,IAAIxB,aAAa;AAClC,CAAC;AASM,MAAM8B,mBAAmB,GAAI3B,MAAc,IAAW;EACzD,MAAM;IAAEgB,OAAO;IAAEf,KAAK;IAAEC,IAAI;IAAEC,MAAM;IAAEY;EAAM,CAAC,GAAGf,MAAM;EACtD,IAAI,CAACE,IAAI,IAAIA,IAAI,CAACwB,MAAM,KAAK,CAAC,IAAIvB,MAAM,CAACuB,MAAM,KAAK,CAAC,EAAE;IACnD;EACJ;EAEA,MAAML,MAAM,GAAGR,SAAS,CAAC;IACrBC,SAAS,EAAEE,OAAO;IAClBD;EACJ,CAAC,CAAC;EAEFM,MAAM,CAACtB,KAAK,CAAC;IACTgB,KAAK;IACLX,eAAe,EAAEwB,KAAK,IAAK,UAASA,KAAK,CAACC,SAAU,EAAC;IACrD1B,MAAM;IACNF,KAAK;IACLC,IAAI;IACJG,WAAW,EAAEyB;EACjB,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,8 @@
1
+ import { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
2
+ interface Params {
3
+ model: CmsModel;
4
+ term?: string;
5
+ fields?: string[];
6
+ }
7
+ export declare const createFullTextSearchFields: (params: Params) => CmsModelField[];
8
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createFullTextSearchFields = void 0;
7
+ const createFullTextSearchFields = params => {
8
+ const {
9
+ term,
10
+ model,
11
+ fields
12
+ } = params;
13
+ if (!fields || fields.length === 0 || !term || term.trim().length === 0) {
14
+ return [];
15
+ }
16
+ return fields.reduce((collection, fieldId) => {
17
+ const field = model.fields.find(f => f.fieldId === fieldId);
18
+ if (!field) {
19
+ return collection;
20
+ }
21
+ collection.push(field);
22
+ return collection;
23
+ }, []);
24
+ };
25
+ exports.createFullTextSearchFields = createFullTextSearchFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFullTextSearchFields","params","term","model","fields","length","trim","reduce","collection","fieldId","field","find","f","push"],"sources":["fullTextSearchFields.ts"],"sourcesContent":["import { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n model: CmsModel;\n term?: string;\n fields?: string[];\n}\nexport const createFullTextSearchFields = (params: Params): CmsModelField[] => {\n const { term, model, fields } = params;\n if (!fields || fields.length === 0 || !term || term.trim().length === 0) {\n return [];\n }\n return fields.reduce<CmsModelField[]>((collection, fieldId) => {\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n return collection;\n }\n collection.push(field);\n return collection;\n }, []);\n};\n"],"mappings":";;;;;;AAOO,MAAMA,0BAA0B,GAAIC,MAAc,IAAsB;EAC3E,MAAM;IAAEC,IAAI;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGH,MAAM;EACtC,IAAI,CAACG,MAAM,IAAIA,MAAM,CAACC,MAAM,KAAK,CAAC,IAAI,CAACH,IAAI,IAAIA,IAAI,CAACI,IAAI,EAAE,CAACD,MAAM,KAAK,CAAC,EAAE;IACrE,OAAO,EAAE;EACb;EACA,OAAOD,MAAM,CAACG,MAAM,CAAkB,CAACC,UAAU,EAAEC,OAAO,KAAK;IAC3D,MAAMC,KAAK,GAAGP,KAAK,CAACC,MAAM,CAACO,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACH,OAAO,KAAKA,OAAO,CAAC;IAC3D,IAAI,CAACC,KAAK,EAAE;MACR,OAAOF,UAAU;IACrB;IACAA,UAAU,CAACK,IAAI,CAACH,KAAK,CAAC;IACtB,OAAOF,UAAU;EACrB,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AAAC"}
@@ -0,0 +1,17 @@
1
+ import { ElasticsearchBoolQueryConfig } from "@webiny/api-elasticsearch/types";
2
+ import { CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types";
3
+ export declare const createBaseQuery: () => ElasticsearchBoolQueryConfig;
4
+ interface Params {
5
+ model: CmsModel;
6
+ where: CmsEntryListWhere;
7
+ }
8
+ /**
9
+ * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.
10
+ * We allow either published or either latest.
11
+ * Latest is used in the manage API and published in the read API.
12
+ *
13
+ *
14
+ * We add the query.filter terms because we do not need scored search here and it is a bit faster.
15
+ */
16
+ export declare const createInitialQuery: (params: Params) => ElasticsearchBoolQueryConfig;
17
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createInitialQuery = exports.createBaseQuery = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _recordType = require("../recordType");
10
+ const createBaseQuery = () => {
11
+ return {
12
+ must: [],
13
+ must_not: [],
14
+ should: [],
15
+ filter: []
16
+ };
17
+ };
18
+ exports.createBaseQuery = createBaseQuery;
19
+ /**
20
+ * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.
21
+ * We allow either published or either latest.
22
+ * Latest is used in the manage API and published in the read API.
23
+ *
24
+ *
25
+ * We add the query.filter terms because we do not need scored search here and it is a bit faster.
26
+ */
27
+ const createInitialQuery = params => {
28
+ const {
29
+ model,
30
+ where
31
+ } = params;
32
+ const query = createBaseQuery();
33
+
34
+ /**
35
+ * When ES index is shared between tenants, we need to filter records by tenant ID
36
+ *
37
+ * TODO determine if we want to search across tenants in shared index?
38
+ */
39
+ const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
40
+ if (sharedIndex) {
41
+ /**
42
+ * Tenant for the filtering is taken from the model.
43
+ *
44
+ * TODO determine if we want to send it in the "where" parameter?
45
+ */
46
+ query.filter.push({
47
+ term: {
48
+ "tenant.keyword": model.tenant
49
+ }
50
+ });
51
+ /**
52
+ * Also, we must search only in selected model.
53
+ */
54
+ query.filter.push({
55
+ term: {
56
+ "modelId.keyword": model.modelId
57
+ }
58
+ });
59
+ /**
60
+ * TODO determine if we want to search across locales?
61
+ * This search would anyway work for a single model and when sharing index.
62
+ */
63
+ query.filter.push({
64
+ term: {
65
+ "locale.keyword": model.locale
66
+ }
67
+ });
68
+ }
69
+
70
+ /**
71
+ * We must transform published and latest where args into something that is understandable by our Elasticsearch
72
+ */
73
+ if (where.published === true) {
74
+ query.filter.push({
75
+ term: {
76
+ "__type.keyword": (0, _recordType.createPublishedRecordType)()
77
+ }
78
+ });
79
+ } else if (where.latest === true) {
80
+ query.filter.push({
81
+ term: {
82
+ "__type.keyword": (0, _recordType.createLatestRecordType)()
83
+ }
84
+ });
85
+ }
86
+ //
87
+ /**
88
+ * We do not allow filtering without the published or latest parameter.
89
+ * Also, we do not want to set the default one, as there is a large possibility for user error when filtering.
90
+ */else {
91
+ throw new _error.default(`Cannot call Elasticsearch query when not setting "published" or "latest".`, "ELASTICSEARCH_UNSUPPORTED_QUERY", {
92
+ where
93
+ });
94
+ }
95
+ /**
96
+ * We need to remove fields that actually do not exist on the record - it will break otherwise.
97
+ * This will modify the original object, which is what we want.
98
+ */
99
+ delete where.published;
100
+ delete where.latest;
101
+ return query;
102
+ };
103
+ exports.createInitialQuery = createInitialQuery;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createBaseQuery","must","must_not","should","filter","createInitialQuery","params","model","where","query","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","push","term","tenant","modelId","locale","published","createPublishedRecordType","latest","createLatestRecordType","WebinyError"],"sources":["initialQuery.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createLatestRecordType, createPublishedRecordType } from \"../recordType\";\n\nexport const createBaseQuery = (): ElasticsearchBoolQueryConfig => {\n return {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\ninterface Params {\n model: CmsModel;\n where: CmsEntryListWhere;\n}\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n *\n *\n * We add the query.filter terms because we do not need scored search here and it is a bit faster.\n */\nexport const createInitialQuery = (params: Params): ElasticsearchBoolQueryConfig => {\n const { model, where } = params;\n\n const query = createBaseQuery();\n\n /**\n * When ES index is shared between tenants, we need to filter records by tenant ID\n *\n * TODO determine if we want to search across tenants in shared index?\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex) {\n /**\n * Tenant for the filtering is taken from the model.\n *\n * TODO determine if we want to send it in the \"where\" parameter?\n */\n query.filter.push({\n term: {\n \"tenant.keyword\": model.tenant\n }\n });\n /**\n * Also, we must search only in selected model.\n */\n query.filter.push({\n term: {\n \"modelId.keyword\": model.modelId\n }\n });\n /**\n * TODO determine if we want to search across locales?\n * This search would anyway work for a single model and when sharing index.\n */\n query.filter.push({\n term: {\n \"locale.keyword\": model.locale\n }\n });\n }\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.filter.push({\n term: {\n \"__type.keyword\": createPublishedRecordType()\n }\n });\n } else if (where.latest === true) {\n query.filter.push({\n term: {\n \"__type.keyword\": createLatestRecordType()\n }\n });\n }\n //\n /**\n * We do not allow filtering without the published or latest parameter.\n * Also, we do not want to set the default one, as there is a large possibility for user error when filtering.\n */\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n /**\n * We need to remove fields that actually do not exist on the record - it will break otherwise.\n * This will modify the original object, which is what we want.\n */\n delete where.published;\n delete where.latest;\n\n return query;\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AAEO,MAAMA,eAAe,GAAG,MAAoC;EAC/D,OAAO;IACHC,IAAI,EAAE,EAAE;IACRC,QAAQ,EAAE,EAAE;IACZC,MAAM,EAAE,EAAE;IACVC,MAAM,EAAE;EACZ,CAAC;AACL,CAAC;AAAC;AAMF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,GAAIC,MAAc,IAAmC;EAChF,MAAM;IAAEC,KAAK;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAE/B,MAAMG,KAAK,GAAGT,eAAe,EAAE;;EAE/B;AACJ;AACA;AACA;AACA;EACI,MAAMU,WAAW,GAAGC,OAAO,CAACC,GAAG,CAACC,4BAA4B,KAAK,MAAM;EACvE,IAAIH,WAAW,EAAE;IACb;AACR;AACA;AACA;AACA;IACQD,KAAK,CAACL,MAAM,CAACU,IAAI,CAAC;MACdC,IAAI,EAAE;QACF,gBAAgB,EAAER,KAAK,CAACS;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQP,KAAK,CAACL,MAAM,CAACU,IAAI,CAAC;MACdC,IAAI,EAAE;QACF,iBAAiB,EAAER,KAAK,CAACU;MAC7B;IACJ,CAAC,CAAC;IACF;AACR;AACA;AACA;IACQR,KAAK,CAACL,MAAM,CAACU,IAAI,CAAC;MACdC,IAAI,EAAE;QACF,gBAAgB,EAAER,KAAK,CAACW;MAC5B;IACJ,CAAC,CAAC;EACN;;EAEA;AACJ;AACA;EACI,IAAIV,KAAK,CAACW,SAAS,KAAK,IAAI,EAAE;IAC1BV,KAAK,CAACL,MAAM,CAACU,IAAI,CAAC;MACdC,IAAI,EAAE;QACF,gBAAgB,EAAE,IAAAK,qCAAyB;MAC/C;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIZ,KAAK,CAACa,MAAM,KAAK,IAAI,EAAE;IAC9BZ,KAAK,CAACL,MAAM,CAACU,IAAI,CAAC;MACdC,IAAI,EAAE;QACF,gBAAgB,EAAE,IAAAO,kCAAsB;MAC5C;IACJ,CAAC,CAAC;EACN;EACA;EACA;AACJ;AACA;AACA,KAHI,KAIK;IACD,MAAM,IAAIC,cAAW,CAChB,2EAA0E,EAC3E,iCAAiC,EACjC;MACIf;IACJ,CAAC,CACJ;EACL;EACA;AACJ;AACA;AACA;EACI,OAAOA,KAAK,CAACW,SAAS;EACtB,OAAOX,KAAK,CAACa,MAAM;EAEnB,OAAOZ,KAAK;AAChB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { ModelField } from "./types";
2
+ export declare const hasKeyword: (field: ModelField) => boolean;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasKeyword = void 0;
7
+ const noKeywordFields = ["date", "datetime", "number", "boolean"];
8
+ const hasKeyword = field => {
9
+ /**
10
+ * We defined some field types that MUST have no keyword added to the field path
11
+ */
12
+ if (noKeywordFields.includes(field.type)) {
13
+ return false;
14
+ }
15
+ /**
16
+ * If field has unmapped type defined, do not add keyword.
17
+ */
18
+ //
19
+ else if (field.unmappedType) {
20
+ return false;
21
+ }
22
+ /**
23
+ * And if specifically defined that field has no keyword, do not add it.
24
+ */
25
+ //
26
+ else if (field.keyword === false) {
27
+ return false;
28
+ }
29
+ /**
30
+ * All other fields have keyword added.
31
+ */
32
+ return true;
33
+ };
34
+ exports.hasKeyword = hasKeyword;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["noKeywordFields","hasKeyword","field","includes","type","unmappedType","keyword"],"sources":["keyword.ts"],"sourcesContent":["import { ModelField } from \"./types\";\n\nconst noKeywordFields: string[] = [\"date\", \"datetime\", \"number\", \"boolean\"];\nexport const hasKeyword = (field: ModelField): boolean => {\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(field.type)) {\n return false;\n }\n /**\n * If field has unmapped type defined, do not add keyword.\n */\n //\n else if (field.unmappedType) {\n return false;\n }\n /**\n * And if specifically defined that field has no keyword, do not add it.\n */\n //\n else if (field.keyword === false) {\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n"],"mappings":";;;;;;AAEA,MAAMA,eAAyB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,CAAC;AACpE,MAAMC,UAAU,GAAIC,KAAiB,IAAc;EACtD;AACJ;AACA;EACI,IAAIF,eAAe,CAACG,QAAQ,CAACD,KAAK,CAACE,IAAI,CAAC,EAAE;IACtC,OAAO,KAAK;EAChB;EACA;AACJ;AACA;EACI;EAAA,KACK,IAAIF,KAAK,CAACG,YAAY,EAAE;IACzB,OAAO,KAAK;EAChB;EACA;AACJ;AACA;EACI;EAAA,KACK,IAAIH,KAAK,CAACI,OAAO,KAAK,KAAK,EAAE;IAC9B,OAAO,KAAK;EAChB;EACA;AACJ;AACA;EACI,OAAO,IAAI;AACf,CAAC;AAAC"}
@@ -0,0 +1,9 @@
1
+ import { CmsEntryElasticsearchBodyModifierPlugin } from "../../../../plugins";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { CmsModel } from "@webiny/api-headless-cms/types";
4
+ interface Params {
5
+ plugins: PluginsContainer;
6
+ model: CmsModel;
7
+ }
8
+ export declare const createBodyModifierPluginList: ({ plugins, model }: Params) => CmsEntryElasticsearchBodyModifierPlugin[];
9
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createBodyModifierPluginList = void 0;
7
+ var _plugins = require("../../../../plugins");
8
+ const createBodyModifierPluginList = ({
9
+ plugins,
10
+ model
11
+ }) => {
12
+ return plugins.byType(_plugins.CmsEntryElasticsearchBodyModifierPlugin.type).filter(pl => {
13
+ return !pl.modelId || pl.modelId === model.modelId;
14
+ });
15
+ };
16
+ exports.createBodyModifierPluginList = createBodyModifierPluginList;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createBodyModifierPluginList","plugins","model","byType","CmsEntryElasticsearchBodyModifierPlugin","type","filter","pl","modelId"],"sources":["bodyModifier.ts"],"sourcesContent":["import { CmsEntryElasticsearchBodyModifierPlugin } from \"~/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n}\nexport const createBodyModifierPluginList = ({ plugins, model }: Params) => {\n return plugins\n .byType<CmsEntryElasticsearchBodyModifierPlugin>(\n CmsEntryElasticsearchBodyModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n};\n"],"mappings":";;;;;;AAAA;AAQO,MAAMA,4BAA4B,GAAG,CAAC;EAAEC,OAAO;EAAEC;AAAc,CAAC,KAAK;EACxE,OAAOD,OAAO,CACTE,MAAM,CACHC,gDAAuC,CAACC,IAAI,CAC/C,CACAC,MAAM,CAACC,EAAE,IAAI;IACV,OAAO,CAACA,EAAE,CAACC,OAAO,IAAID,EAAE,CAACC,OAAO,KAAKN,KAAK,CAACM,OAAO;EACtD,CAAC,CAAC;AACV,CAAC;AAAC"}
@@ -0,0 +1,8 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { ElasticsearchQueryBuilderOperatorPlugins } from "../types";
3
+ interface Params {
4
+ plugins: PluginsContainer;
5
+ locale: string;
6
+ }
7
+ export declare const createOperatorPluginList: (params: Params) => ElasticsearchQueryBuilderOperatorPlugins;
8
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createOperatorPluginList = void 0;
7
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
8
+ const createOperatorPluginList = params => {
9
+ const {
10
+ plugins,
11
+ locale
12
+ } = params;
13
+ /**
14
+ * We always set the last one operator plugin added.
15
+ * This way user can override the plugins.
16
+ */
17
+ return plugins.byType(_apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((acc, plugin) => {
18
+ const operator = plugin.getOperator();
19
+ /**
20
+ * We only allow the plugins which can pass the locale test.
21
+ * The default plugins always return true.
22
+ */
23
+ if (plugin.isLocaleSupported(locale) === false) {
24
+ return acc;
25
+ }
26
+ /**
27
+ * We also only allow the override of the plugins if the new plugin is NOT a default one.
28
+ * If a user sets the plugin name ending with .default, we cannot do anything about it.
29
+ */
30
+ if (!!acc[operator] && (plugin.name || "").match(/\.default$/)) {
31
+ return acc;
32
+ }
33
+ acc[operator] = plugin;
34
+ return acc;
35
+ }, {});
36
+ };
37
+ exports.createOperatorPluginList = createOperatorPluginList;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createOperatorPluginList","params","plugins","locale","byType","ElasticsearchQueryBuilderOperatorPlugin","type","reduce","acc","plugin","operator","getOperator","isLocaleSupported","name","match"],"sources":["operator.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch\";\nimport { ElasticsearchQueryBuilderOperatorPlugins } from \"../types\";\n\ninterface Params {\n plugins: PluginsContainer;\n locale: string;\n}\nexport const createOperatorPluginList = (\n params: Params\n): ElasticsearchQueryBuilderOperatorPlugins => {\n const { plugins, locale } = params;\n /**\n * We always set the last one operator plugin added.\n * This way user can override the plugins.\n */\n return plugins\n .byType<ElasticsearchQueryBuilderOperatorPlugin>(\n ElasticsearchQueryBuilderOperatorPlugin.type\n )\n .reduce<ElasticsearchQueryBuilderOperatorPlugins>((acc, plugin) => {\n const operator = plugin.getOperator();\n /**\n * We only allow the plugins which can pass the locale test.\n * The default plugins always return true.\n */\n if (plugin.isLocaleSupported(locale) === false) {\n return acc;\n }\n /**\n * We also only allow the override of the plugins if the new plugin is NOT a default one.\n * If a user sets the plugin name ending with .default, we cannot do anything about it.\n */\n if (!!acc[operator] && (plugin.name || \"\").match(/\\.default$/)) {\n return acc;\n }\n acc[operator] = plugin;\n return acc;\n }, {});\n};\n"],"mappings":";;;;;;AACA;AAOO,MAAMA,wBAAwB,GACjCC,MAAc,IAC6B;EAC3C,MAAM;IAAEC,OAAO;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAClC;AACJ;AACA;AACA;EACI,OAAOC,OAAO,CACTE,MAAM,CACHC,yDAAuC,CAACC,IAAI,CAC/C,CACAC,MAAM,CAA2C,CAACC,GAAG,EAAEC,MAAM,KAAK;IAC/D,MAAMC,QAAQ,GAAGD,MAAM,CAACE,WAAW,EAAE;IACrC;AACZ;AACA;AACA;IACY,IAAIF,MAAM,CAACG,iBAAiB,CAACT,MAAM,CAAC,KAAK,KAAK,EAAE;MAC5C,OAAOK,GAAG;IACd;IACA;AACZ;AACA;AACA;IACY,IAAI,CAAC,CAACA,GAAG,CAACE,QAAQ,CAAC,IAAI,CAACD,MAAM,CAACI,IAAI,IAAI,EAAE,EAAEC,KAAK,CAAC,YAAY,CAAC,EAAE;MAC5D,OAAON,GAAG;IACd;IACAA,GAAG,CAACE,QAAQ,CAAC,GAAGD,MAAM;IACtB,OAAOD,GAAG;EACd,CAAC,EAAE,CAAC,CAAC,CAAC;AACd,CAAC;AAAC"}
@@ -0,0 +1,9 @@
1
+ import { CmsEntryElasticsearchQueryModifierPlugin } from "../../../../plugins";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { CmsModel } from "@webiny/api-headless-cms/types";
4
+ interface Params {
5
+ plugins: PluginsContainer;
6
+ model: CmsModel;
7
+ }
8
+ export declare const createQueryModifierPluginList: ({ plugins, model }: Params) => CmsEntryElasticsearchQueryModifierPlugin[];
9
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createQueryModifierPluginList = void 0;
7
+ var _plugins = require("../../../../plugins");
8
+ const createQueryModifierPluginList = ({
9
+ plugins,
10
+ model
11
+ }) => {
12
+ return plugins.byType(_plugins.CmsEntryElasticsearchQueryModifierPlugin.type).filter(pl => {
13
+ return !pl.modelId || pl.modelId === model.modelId;
14
+ });
15
+ };
16
+ exports.createQueryModifierPluginList = createQueryModifierPluginList;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createQueryModifierPluginList","plugins","model","byType","CmsEntryElasticsearchQueryModifierPlugin","type","filter","pl","modelId"],"sources":["queryModifier.ts"],"sourcesContent":["import { CmsEntryElasticsearchQueryModifierPlugin } from \"~/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n}\nexport const createQueryModifierPluginList = ({ plugins, model }: Params) => {\n return plugins\n .byType<CmsEntryElasticsearchQueryModifierPlugin>(\n CmsEntryElasticsearchQueryModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n};\n"],"mappings":";;;;;;AAAA;AAQO,MAAMA,6BAA6B,GAAG,CAAC;EAAEC,OAAO;EAAEC;AAAc,CAAC,KAAK;EACzE,OAAOD,OAAO,CACTE,MAAM,CACHC,iDAAwC,CAACC,IAAI,CAChD,CACAC,MAAM,CAACC,EAAE,IAAI;IACV,OAAO,CAACA,EAAE,CAACC,OAAO,IAAID,EAAE,CAACC,OAAO,KAAKN,KAAK,CAACM,OAAO;EACtD,CAAC,CAAC;AACV,CAAC;AAAC"}
@@ -0,0 +1,7 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { ElasticsearchQuerySearchValuePlugins } from "../types";
3
+ interface Params {
4
+ plugins: PluginsContainer;
5
+ }
6
+ export declare const createSearchPluginList: ({ plugins }: Params) => ElasticsearchQuerySearchValuePlugins;
7
+ export {};
@@ -1,26 +1,24 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.searchPluginsList = void 0;
9
-
7
+ exports.createSearchPluginList = void 0;
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- const searchPluginsList = plugins => {
13
- return plugins.byType("cms-elastic-search-query-builder-value-search").reduce((plugins, plugin) => {
9
+ var _plugins = require("../../../../plugins");
10
+ const createSearchPluginList = ({
11
+ plugins
12
+ }) => {
13
+ return plugins.byType(_plugins.CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type).reduce((plugins, plugin) => {
14
14
  if (plugins[plugin.fieldType]) {
15
15
  throw new _error.default("There is a ElasticsearchQueryBuilderValueSearchPlugin defined for the field type.", "PLUGIN_ALREADY_EXISTS", {
16
16
  fieldType: plugin.fieldType,
17
17
  name: plugin.name || "unknown"
18
18
  });
19
19
  }
20
-
21
20
  plugins[plugin.fieldType] = plugin;
22
21
  return plugins;
23
22
  }, {});
24
23
  };
25
-
26
- exports.searchPluginsList = searchPluginsList;
24
+ exports.createSearchPluginList = createSearchPluginList;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSearchPluginList","plugins","byType","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","type","reduce","plugin","fieldType","WebinyError","name"],"sources":["search.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryElasticsearchQueryBuilderValueSearchPlugin } from \"~/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchQuerySearchValuePlugins } from \"../types\";\n\ninterface Params {\n plugins: PluginsContainer;\n}\nexport const createSearchPluginList = ({\n plugins\n}: Params): ElasticsearchQuerySearchValuePlugins => {\n return plugins\n .byType<CmsEntryElasticsearchQueryBuilderValueSearchPlugin>(\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type\n )\n .reduce<ElasticsearchQuerySearchValuePlugins>((plugins, plugin) => {\n if (plugins[plugin.fieldType]) {\n throw new WebinyError(\n \"There is a ElasticsearchQueryBuilderValueSearchPlugin defined for the field type.\",\n \"PLUGIN_ALREADY_EXISTS\",\n {\n fieldType: plugin.fieldType,\n name: plugin.name || \"unknown\"\n }\n );\n }\n plugins[plugin.fieldType] = plugin;\n\n return plugins;\n }, {});\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAOO,MAAMA,sBAAsB,GAAG,CAAC;EACnCC;AACI,CAAC,KAA2C;EAChD,OAAOA,OAAO,CACTC,MAAM,CACHC,2DAAkD,CAACC,IAAI,CAC1D,CACAC,MAAM,CAAuC,CAACJ,OAAO,EAAEK,MAAM,KAAK;IAC/D,IAAIL,OAAO,CAACK,MAAM,CAACC,SAAS,CAAC,EAAE;MAC3B,MAAM,IAAIC,cAAW,CACjB,mFAAmF,EACnF,uBAAuB,EACvB;QACID,SAAS,EAAED,MAAM,CAACC,SAAS;QAC3BE,IAAI,EAAEH,MAAM,CAACG,IAAI,IAAI;MACzB,CAAC,CACJ;IACL;IACAR,OAAO,CAACK,MAAM,CAACC,SAAS,CAAC,GAAGD,MAAM;IAElC,OAAOL,OAAO;EAClB,CAAC,EAAE,CAAC,CAAC,CAAC;AACd,CAAC;AAAC"}
@@ -0,0 +1,9 @@
1
+ import { CmsEntryElasticsearchSortModifierPlugin } from "../../../../plugins";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { CmsModel } from "@webiny/api-headless-cms/types";
4
+ interface Params {
5
+ plugins: PluginsContainer;
6
+ model: CmsModel;
7
+ }
8
+ export declare const createSortModifierPluginList: ({ plugins, model }: Params) => CmsEntryElasticsearchSortModifierPlugin[];
9
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createSortModifierPluginList = void 0;
7
+ var _plugins = require("../../../../plugins");
8
+ const createSortModifierPluginList = ({
9
+ plugins,
10
+ model
11
+ }) => {
12
+ return plugins.byType(_plugins.CmsEntryElasticsearchSortModifierPlugin.type).filter(pl => {
13
+ return !pl.modelId || pl.modelId === model.modelId;
14
+ });
15
+ };
16
+ exports.createSortModifierPluginList = createSortModifierPluginList;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSortModifierPluginList","plugins","model","byType","CmsEntryElasticsearchSortModifierPlugin","type","filter","pl","modelId"],"sources":["sortModifier.ts"],"sourcesContent":["import { CmsEntryElasticsearchSortModifierPlugin } from \"~/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n}\nexport const createSortModifierPluginList = ({ plugins, model }: Params) => {\n return plugins\n .byType<CmsEntryElasticsearchSortModifierPlugin>(\n CmsEntryElasticsearchSortModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n};\n"],"mappings":";;;;;;AAAA;AAQO,MAAMA,4BAA4B,GAAG,CAAC;EAAEC,OAAO;EAAEC;AAAc,CAAC,KAAK;EACxE,OAAOD,OAAO,CACTE,MAAM,CACHC,gDAAuC,CAACC,IAAI,CAC/C,CACAC,MAAM,CAACC,EAAE,IAAI;IACV,OAAO,CAACA,EAAE,CAACC,OAAO,IAAID,EAAE,CAACC,OAAO,KAAKN,KAAK,CAACM,OAAO;EACtD,CAAC,CAAC;AACV,CAAC;AAAC"}
@@ -0,0 +1,12 @@
1
+ import { Sort as esSort } from "@webiny/api-elasticsearch/types";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ import { CmsEntryListSort, CmsModel } from "@webiny/api-headless-cms/types";
4
+ import { ModelFields } from "./types";
5
+ interface Params {
6
+ plugins: PluginsContainer;
7
+ sort?: CmsEntryListSort;
8
+ modelFields: ModelFields;
9
+ model: CmsModel;
10
+ }
11
+ export declare const createElasticsearchSort: (params: Params) => esSort;
12
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createElasticsearchSort = void 0;
7
+ var _plugins = require("../../../plugins");
8
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
9
+ var _keyword = require("./keyword");
10
+ var _search = require("./plugins/search");
11
+ var _path = require("./filtering/path");
12
+ const createElasticsearchSort = params => {
13
+ const {
14
+ sort,
15
+ modelFields,
16
+ plugins
17
+ } = params;
18
+ if (!sort || sort.length === 0) {
19
+ return [];
20
+ }
21
+ const searchPlugins = (0, _search.createSearchPluginList)({
22
+ plugins
23
+ });
24
+ const createFieldPath = (0, _path.createFieldPathFactory)({
25
+ plugins: searchPlugins
26
+ });
27
+ const fieldIdToStorageIdIdMap = {};
28
+ const sortPlugins = Object.values(modelFields).reduce((plugins, field) => {
29
+ /**
30
+ * We do not support sorting by nested fields.
31
+ */
32
+ if (field.parents.length > 0) {
33
+ return plugins;
34
+ }
35
+ const {
36
+ fieldId,
37
+ storageId
38
+ } = field.field;
39
+ fieldIdToStorageIdIdMap[fieldId] = fieldId;
40
+ const {
41
+ path
42
+ } = createFieldPath({
43
+ key: storageId,
44
+ field,
45
+ value: "",
46
+ keyword: false
47
+ });
48
+ /**
49
+ * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.
50
+ */
51
+ plugins[fieldId] = new _plugins.CmsEntryElasticsearchFieldPlugin({
52
+ unmappedType: field.unmappedType,
53
+ keyword: (0, _keyword.hasKeyword)(field),
54
+ sortable: field.isSortable,
55
+ searchable: field.isSearchable,
56
+ field: fieldId,
57
+ path
58
+ });
59
+ return plugins;
60
+ }, {
61
+ ["*"]: new _plugins.CmsEntryElasticsearchFieldPlugin({
62
+ field: _plugins.CmsEntryElasticsearchFieldPlugin.ALL,
63
+ keyword: false
64
+ })
65
+ });
66
+ const transformedSort = sort.map(value => {
67
+ const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);
68
+ if (!matched) {
69
+ return null;
70
+ }
71
+ const [, fieldId, order] = matched;
72
+ if (fieldIdToStorageIdIdMap[fieldId]) {
73
+ return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;
74
+ }
75
+ return value;
76
+ }).filter(Boolean);
77
+ return (0, _apiElasticsearch.createSort)({
78
+ fieldPlugins: sortPlugins,
79
+ sort: transformedSort
80
+ });
81
+ };
82
+ exports.createElasticsearchSort = createElasticsearchSort;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElasticsearchSort","params","sort","modelFields","plugins","length","searchPlugins","createSearchPluginList","createFieldPath","createFieldPathFactory","fieldIdToStorageIdIdMap","sortPlugins","Object","values","reduce","field","parents","fieldId","storageId","path","key","value","keyword","CmsEntryElasticsearchFieldPlugin","unmappedType","hasKeyword","sortable","isSortable","searchable","isSearchable","ALL","transformedSort","map","matched","match","order","filter","Boolean","createSort","fieldPlugins"],"sources":["sort.ts"],"sourcesContent":["import { Sort as esSort } from \"@webiny/api-elasticsearch/types\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins\";\nimport { createSort } from \"@webiny/api-elasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListSort, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"./types\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\n\ninterface Params {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n model: CmsModel;\n}\nexport const createElasticsearchSort = (params: Params): esSort => {\n const { sort, modelFields, plugins } = params;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const searchPlugins = createSearchPluginList({\n plugins\n });\n\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n const fieldIdToStorageIdIdMap: Record<string, string> = {};\n\n const sortPlugins = Object.values(modelFields).reduce<\n Record<string, CmsEntryElasticsearchFieldPlugin>\n >(\n (plugins, field) => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return plugins;\n }\n const { fieldId, storageId } = field.field;\n\n fieldIdToStorageIdIdMap[fieldId] = fieldId;\n\n const { path } = createFieldPath({\n key: storageId,\n field,\n value: \"\",\n keyword: false\n });\n /**\n * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.\n */\n plugins[fieldId] = new CmsEntryElasticsearchFieldPlugin({\n unmappedType: field.unmappedType,\n keyword: hasKeyword(field),\n sortable: field.isSortable,\n searchable: field.isSearchable,\n field: fieldId,\n path\n });\n return plugins;\n },\n {\n [\"*\"]: new CmsEntryElasticsearchFieldPlugin({\n field: CmsEntryElasticsearchFieldPlugin.ALL,\n keyword: false\n })\n }\n );\n\n const transformedSort = sort\n .map(value => {\n const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);\n if (!matched) {\n return null;\n }\n const [, fieldId, order] = matched;\n if (fieldIdToStorageIdIdMap[fieldId]) {\n return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;\n }\n\n return value;\n })\n .filter(Boolean) as string[];\n return createSort({\n fieldPlugins: sortPlugins,\n sort: transformedSort\n });\n};\n"],"mappings":";;;;;;AACA;AACA;AAIA;AACA;AACA;AAQO,MAAMA,uBAAuB,GAAIC,MAAc,IAAa;EAC/D,MAAM;IAAEC,IAAI;IAAEC,WAAW;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAE7C,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACG,MAAM,KAAK,CAAC,EAAE;IAC5B,OAAO,EAAE;EACb;EAEA,MAAMC,aAAa,GAAG,IAAAC,8BAAsB,EAAC;IACzCH;EACJ,CAAC,CAAC;EAEF,MAAMI,eAAe,GAAG,IAAAC,4BAAsB,EAAC;IAC3CL,OAAO,EAAEE;EACb,CAAC,CAAC;EAEF,MAAMI,uBAA+C,GAAG,CAAC,CAAC;EAE1D,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAACV,WAAW,CAAC,CAACW,MAAM,CAGjD,CAACV,OAAO,EAAEW,KAAK,KAAK;IAChB;AACZ;AACA;IACY,IAAIA,KAAK,CAACC,OAAO,CAACX,MAAM,GAAG,CAAC,EAAE;MAC1B,OAAOD,OAAO;IAClB;IACA,MAAM;MAAEa,OAAO;MAAEC;IAAU,CAAC,GAAGH,KAAK,CAACA,KAAK;IAE1CL,uBAAuB,CAACO,OAAO,CAAC,GAAGA,OAAO;IAE1C,MAAM;MAAEE;IAAK,CAAC,GAAGX,eAAe,CAAC;MAC7BY,GAAG,EAAEF,SAAS;MACdH,KAAK;MACLM,KAAK,EAAE,EAAE;MACTC,OAAO,EAAE;IACb,CAAC,CAAC;IACF;AACZ;AACA;IACYlB,OAAO,CAACa,OAAO,CAAC,GAAG,IAAIM,yCAAgC,CAAC;MACpDC,YAAY,EAAET,KAAK,CAACS,YAAY;MAChCF,OAAO,EAAE,IAAAG,mBAAU,EAACV,KAAK,CAAC;MAC1BW,QAAQ,EAAEX,KAAK,CAACY,UAAU;MAC1BC,UAAU,EAAEb,KAAK,CAACc,YAAY;MAC9Bd,KAAK,EAAEE,OAAO;MACdE;IACJ,CAAC,CAAC;IACF,OAAOf,OAAO;EAClB,CAAC,EACD;IACI,CAAC,GAAG,GAAG,IAAImB,yCAAgC,CAAC;MACxCR,KAAK,EAAEQ,yCAAgC,CAACO,GAAG;MAC3CR,OAAO,EAAE;IACb,CAAC;EACL,CAAC,CACJ;EAED,MAAMS,eAAe,GAAG7B,IAAI,CACvB8B,GAAG,CAACX,KAAK,IAAI;IACV,MAAMY,OAAO,GAAGZ,KAAK,CAACa,KAAK,CAAC,+BAA+B,CAAC;IAC5D,IAAI,CAACD,OAAO,EAAE;MACV,OAAO,IAAI;IACf;IACA,MAAM,GAAGhB,OAAO,EAAEkB,KAAK,CAAC,GAAGF,OAAO;IAClC,IAAIvB,uBAAuB,CAACO,OAAO,CAAC,EAAE;MAClC,OAAQ,GAAEP,uBAAuB,CAACO,OAAO,CAAE,IAAGkB,KAAM,EAAC;IACzD;IAEA,OAAOd,KAAK;EAChB,CAAC,CAAC,CACDe,MAAM,CAACC,OAAO,CAAa;EAChC,OAAO,IAAAC,4BAAU,EAAC;IACdC,YAAY,EAAE5B,WAAW;IACzBT,IAAI,EAAE6B;EACV,CAAC,CAAC;AACN,CAAC;AAAC"}