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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/configurations.js +0 -8
  2. package/configurations.js.map +1 -1
  3. package/definitions/entry.js +0 -5
  4. package/definitions/entry.js.map +1 -1
  5. package/definitions/entryElasticsearch.js +0 -5
  6. package/definitions/entryElasticsearch.js.map +1 -1
  7. package/definitions/group.js +0 -5
  8. package/definitions/group.js.map +1 -1
  9. package/definitions/model.js +5 -5
  10. package/definitions/model.js.map +1 -1
  11. package/definitions/settings.js +0 -5
  12. package/definitions/settings.js.map +1 -1
  13. package/definitions/system.js +0 -5
  14. package/definitions/system.js.map +1 -1
  15. package/definitions/table.js +0 -3
  16. package/definitions/table.js.map +1 -1
  17. package/definitions/tableElasticsearch.js +0 -3
  18. package/definitions/tableElasticsearch.js.map +1 -1
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +0 -5
  21. package/dynamoDb/index.js.map +1 -1
  22. package/dynamoDb/storage/date.d.ts +2 -1
  23. package/dynamoDb/storage/date.js +1 -16
  24. package/dynamoDb/storage/date.js.map +1 -1
  25. package/dynamoDb/storage/longText.d.ts +1 -1
  26. package/dynamoDb/storage/longText.js +7 -17
  27. package/dynamoDb/storage/longText.js.map +1 -1
  28. package/dynamoDb/storage/richText.d.ts +1 -1
  29. package/dynamoDb/storage/richText.js +9 -29
  30. package/dynamoDb/storage/richText.js.map +1 -1
  31. package/elasticsearch/createElasticsearchIndex.js +0 -11
  32. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  33. package/elasticsearch/deleteElasticsearchIndex.js +0 -7
  34. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  35. package/elasticsearch/index.js +0 -5
  36. package/elasticsearch/index.js.map +1 -1
  37. package/elasticsearch/indexing/dateTimeIndexing.js +4 -21
  38. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  39. package/elasticsearch/indexing/defaultFieldIndexing.js +15 -10
  40. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
  41. package/elasticsearch/indexing/index.js +0 -9
  42. package/elasticsearch/indexing/index.js.map +1 -1
  43. package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
  44. package/elasticsearch/indexing/longTextIndexing.js +19 -9
  45. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  46. package/elasticsearch/indexing/numberIndexing.js +0 -9
  47. package/elasticsearch/indexing/numberIndexing.js.map +1 -1
  48. package/elasticsearch/indexing/objectIndexing.js +3 -30
  49. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  50. package/elasticsearch/indexing/richTextIndexing.js +0 -5
  51. package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
  52. package/elasticsearch/indices/base.js +0 -3
  53. package/elasticsearch/indices/base.js.map +1 -1
  54. package/elasticsearch/indices/index.js +0 -4
  55. package/elasticsearch/indices/index.js.map +1 -1
  56. package/elasticsearch/indices/japanese.js +0 -3
  57. package/elasticsearch/indices/japanese.js.map +1 -1
  58. package/elasticsearch/search/index.js +0 -4
  59. package/elasticsearch/search/index.js.map +1 -1
  60. package/elasticsearch/search/refSearch.js +0 -6
  61. package/elasticsearch/search/refSearch.js.map +1 -1
  62. package/elasticsearch/search/timeSearch.js +0 -7
  63. package/elasticsearch/search/timeSearch.js.map +1 -1
  64. package/helpers/entryIndexHelpers.js +20 -49
  65. package/helpers/entryIndexHelpers.js.map +1 -1
  66. package/helpers/index.js +0 -2
  67. package/helpers/index.js.map +1 -1
  68. package/index.js +13 -64
  69. package/index.js.map +1 -1
  70. package/operations/entry/dataLoaders.js +0 -52
  71. package/operations/entry/dataLoaders.js.map +1 -1
  72. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  73. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +32 -0
  74. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  75. package/operations/entry/elasticsearch/body.js +7 -29
  76. package/operations/entry/elasticsearch/body.js.map +1 -1
  77. package/operations/entry/elasticsearch/fields.js +79 -46
  78. package/operations/entry/elasticsearch/fields.js.map +1 -1
  79. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +3 -10
  80. package/operations/entry/elasticsearch/filtering/applyFiltering.js +0 -9
  81. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
  82. package/operations/entry/elasticsearch/filtering/exec.js +36 -91
  83. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  84. package/operations/entry/elasticsearch/filtering/index.js +0 -2
  85. package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
  86. package/operations/entry/elasticsearch/filtering/path.js +1 -8
  87. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  88. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  89. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +28 -0
  90. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  91. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  92. package/operations/entry/elasticsearch/filtering/plugins/index.js +13 -0
  93. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  94. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  95. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +65 -0
  96. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  97. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  98. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +48 -0
  99. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  100. package/operations/entry/elasticsearch/filtering/populated.js +0 -7
  101. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
  102. package/operations/entry/elasticsearch/filtering/values.d.ts +1 -1
  103. package/operations/entry/elasticsearch/filtering/values.js +3 -9
  104. package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
  105. package/operations/entry/elasticsearch/fullTextSearch.d.ts +4 -1
  106. package/operations/entry/elasticsearch/fullTextSearch.js +70 -15
  107. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  108. package/operations/entry/elasticsearch/fullTextSearchFields.js +8 -35
  109. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
  110. package/operations/entry/elasticsearch/initialQuery.js +5 -19
  111. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  112. package/operations/entry/elasticsearch/keyword.js +0 -4
  113. package/operations/entry/elasticsearch/keyword.js.map +1 -1
  114. package/operations/entry/elasticsearch/plugins/bodyModifier.js +0 -3
  115. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
  116. package/operations/entry/elasticsearch/plugins/operator.js +0 -8
  117. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
  118. package/operations/entry/elasticsearch/plugins/queryModifier.js +0 -3
  119. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
  120. package/operations/entry/elasticsearch/plugins/search.js +0 -6
  121. package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
  122. package/operations/entry/elasticsearch/plugins/sortModifier.js +0 -3
  123. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
  124. package/operations/entry/elasticsearch/sort.js +12 -15
  125. package/operations/entry/elasticsearch/sort.js.map +1 -1
  126. package/operations/entry/elasticsearch/transformValueForSearch.js +0 -4
  127. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
  128. package/operations/entry/elasticsearch/types.d.ts +9 -1
  129. package/operations/entry/elasticsearch/types.js.map +1 -1
  130. package/operations/entry/index.js +32 -155
  131. package/operations/entry/index.js.map +1 -1
  132. package/operations/entry/keys.js +0 -9
  133. package/operations/entry/keys.js.map +1 -1
  134. package/operations/entry/recordType.js +0 -6
  135. package/operations/entry/recordType.js.map +1 -1
  136. package/operations/group/index.js +2 -32
  137. package/operations/group/index.js.map +1 -1
  138. package/operations/model/index.js +0 -33
  139. package/operations/model/index.js.map +1 -1
  140. package/operations/settings/index.js +0 -24
  141. package/operations/settings/index.js.map +1 -1
  142. package/operations/system/index.js +0 -17
  143. package/operations/system/index.js.map +1 -1
  144. package/package.json +16 -16
  145. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +1 -0
  146. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +6 -8
  147. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
  148. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -6
  149. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -1
  150. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
  151. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +28 -0
  152. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
  153. package/plugins/CmsEntryElasticsearchIndexPlugin.js +0 -5
  154. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
  155. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +1 -0
  156. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +6 -12
  157. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
  158. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +1 -0
  159. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +6 -8
  160. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
  161. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +1 -0
  162. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +6 -8
  163. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
  164. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  165. package/plugins/CmsEntryFilterPlugin.js +24 -0
  166. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  167. package/plugins/index.d.ts +1 -0
  168. package/plugins/index.js +11 -12
  169. package/plugins/index.js.map +1 -1
  170. package/types.js +0 -5
  171. package/types.js.map +1 -1
  172. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  173. package/helpers/createElasticsearchQueryBody.js +0 -618
  174. package/helpers/createElasticsearchQueryBody.js.map +0 -1
  175. package/helpers/fields.d.ts +0 -19
  176. package/helpers/fields.js +0 -196
  177. package/helpers/fields.js.map +0 -1
  178. package/helpers/searchPluginsList.d.ts +0 -6
  179. package/helpers/searchPluginsList.js +0 -26
  180. package/helpers/searchPluginsList.js.map +0 -1
  181. package/helpers/transformValueForSearch.d.ts +0 -12
  182. package/helpers/transformValueForSearch.js +0 -29
  183. package/helpers/transformValueForSearch.js.map +0 -1
  184. package/operations/entry/elasticsearch/filtering/isRefFieldFiltering.d.ts +0 -8
  185. package/operations/entry/elasticsearch/filtering/isRefFieldFiltering.js +0 -39
  186. package/operations/entry/elasticsearch/filtering/isRefFieldFiltering.js.map +0 -1
  187. package/operations/entry/elasticsearchFields.d.ts +0 -2
  188. package/operations/entry/elasticsearchFields.js +0 -38
  189. package/operations/entry/elasticsearchFields.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["createExecFiltering","params","fields","plugins","model","searchPlugins","createSearchPluginList","operatorPlugins","createOperatorPluginList","locale","applyFiltering","createApplyFiltering","execFiltering","where","initialWhere","query","keys","Object","length","key","value","undefined","childWhereList","getValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","filter","push","bool","should","minimum_should_match","field","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","find","f","WebinyError","isSearchable","isRefFieldFiltering","whereKey"],"sources":["exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"~/operations/entry/elasticsearch/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchBoolQueryConfig, Query } from \"@webiny/api-elasticsearch/types\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport { getValues } from \"./values\";\nimport { getPopulated } from \"./populated\";\nimport { createApplyFiltering } from \"./applyFiltering\";\nimport { isRefFieldFiltering } from \"~/operations/entry/elasticsearch/filtering/isRefFieldFiltering\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n}\nexport interface ExecParams {\n where: CmsEntryListWhere;\n query: ElasticsearchBoolQueryConfig;\n}\nexport interface CreateExecFilteringResponse {\n (params: ExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model } = params;\n\n /**\n * We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.\n */\n const searchPlugins = createSearchPluginList({\n plugins\n });\n /**\n * We need the operator plugins, which we execute on our where conditions.\n */\n const operatorPlugins = createOperatorPluginList({\n plugins,\n locale: model.locale\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n searchPlugins\n });\n\n const execFiltering = (params: ExecParams) => {\n const { where: initialWhere, query } = params;\n /**\n * No point in continuing if no \"where\" conditions exist.\n */\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n for (const key in where) {\n const value = where[key] as unknown as any;\n /**\n * We always skip if no value is defined.\n * Only skip undefined value, null is valid.\n */\n if (value === undefined) {\n continue;\n }\n //\n /**\n * When we are running with AND, the \"value\" MUST be an array.\n */\n else if (key === \"AND\") {\n const childWhereList = getValues(value, \"AND\");\n\n const childQuery = createBaseQuery();\n\n for (const childWhere of childWhereList) {\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({\n bool: childQueryBool\n });\n\n continue;\n }\n //\n /**\n * When we are running with OR, the \"value\" must be an array.\n */\n else if (key === \"OR\") {\n const childWhereList = getValues(value, \"OR\");\n /**\n * Each of the conditions MUST produce it's own should section.\n */\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({\n bool: {\n ...childQueryBool\n }\n });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n /**\n * If there are any should, minimum to have is 1.\n * Of course, do not override if it's already set.\n */\n if (query.should.length > 0 && !query.minimum_should_match) {\n query.minimum_should_match = 1;\n }\n\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n let fieldId: string = whereFieldId;\n\n /**\n * TODO This will be required until the storage operations receive the fieldId instead of field storageId.\n * TODO For this to work without field searching, we need to refactor how the query looks like.\n *\n * Storage operations should NEVER receive an field storageId, only alias - fieldId.\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 field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`);\n }\n\n if (!field.isSearchable) {\n throw new WebinyError(`Field \"${field.field.fieldId}\" is not searchable.`);\n }\n\n /**\n * There is a possibility that value is an object.\n * In that case, check if field is ref field and continue a bit differently.\n */\n if (isRefFieldFiltering({ key, value, field })) {\n /**\n * We need to go through each key in where[key] to determine the filters.\n */\n for (const whereKey in value) {\n const { operator } = parseWhereKey(whereKey);\n applyFiltering({\n query,\n field,\n operator,\n key: whereKey,\n value: value[whereKey]\n });\n }\n continue;\n }\n\n applyFiltering({\n key,\n value,\n query,\n field,\n operator\n });\n }\n };\n\n return execFiltering;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAcO,MAAMA,mBAAmB,GAAIC,MAAD,IAA2D;EAC1F,MAAM;IAAEC,MAAF;IAAUC,OAAV;IAAmBC;EAAnB,IAA6BH,MAAnC;EAEA;AACJ;AACA;;EACI,MAAMI,aAAa,GAAG,IAAAC,8BAAA,EAAuB;IACzCH;EADyC,CAAvB,CAAtB;EAGA;AACJ;AACA;;EACI,MAAMI,eAAe,GAAG,IAAAC,kCAAA,EAAyB;IAC7CL,OAD6C;IAE7CM,MAAM,EAAEL,KAAK,CAACK;EAF+B,CAAzB,CAAxB;EAKA,MAAMC,cAAc,GAAG,IAAAC,oCAAA,EAAqB;IACxCJ,eADwC;IAExCF;EAFwC,CAArB,CAAvB;;EAKA,MAAMO,aAAa,GAAIX,MAAD,IAAwB;IAC1C,MAAM;MAAEY,KAAK,EAAEC,YAAT;MAAuBC;IAAvB,IAAiCd,MAAvC;IACA;AACR;AACA;;IACQ,MAAMe,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAYF,YAAZ,CAAb;;IACA,IAAIE,IAAI,CAACE,MAAL,KAAgB,CAApB,EAAuB;MACnB;IACH;;IACD,MAAML,KAAwB,mCACvBC,YADuB,CAA9B;;IAIA,KAAK,MAAMK,GAAX,IAAkBN,KAAlB,EAAyB;MACrB,MAAMO,KAAK,GAAGP,KAAK,CAACM,GAAD,CAAnB;MACA;AACZ;AACA;AACA;;MACY,IAAIC,KAAK,KAAKC,SAAd,EAAyB;QACrB;MACH,CAFD,CAGA;;MACA;AACZ;AACA;MANY,KAOK,IAAIF,GAAG,KAAK,KAAZ,EAAmB;QACpB,MAAMG,cAAc,GAAG,IAA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;YAEXmB,KAFW;YAGXE,QAHW;YAIXjB,GAAG,EAAE0B,QAJM;YAKXzB,KAAK,EAAEA,KAAK,CAACyB,QAAD;UALD,CAAD,CAAd;QAOH;;QACD;MACH;;MAEDnC,cAAc,CAAC;QACXS,GADW;QAEXC,KAFW;QAGXL,KAHW;QAIXmB,KAJW;QAKXE;MALW,CAAD,CAAd;IAOH;EACJ,CA/ID;;EAiJA,OAAOxB,aAAP;AACH,CAxKM"}
1
+ {"version":3,"names":["createExecFiltering","params","fields","plugins","model","searchPlugins","createSearchPluginList","operatorPlugins","createOperatorPluginList","locale","applyFiltering","createApplyFiltering","filteringPlugins","byType","CmsEntryFilterPlugin","type","reduce","collection","plugin","fieldType","getFilterPlugin","WebinyError","execFiltering","where","initialWhere","query","keys","Object","length","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","filter","push","bool","should","assignMinimumShouldMatchToQuery","field","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","find","f","filterPlugin","exec"],"sources":["exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"~/operations/entry/elasticsearch/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchBoolQueryConfig, Query } from \"@webiny/api-elasticsearch/types\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport { getWhereValues } from \"./values\";\nimport { getPopulated } from \"./populated\";\nimport { createApplyFiltering } from \"./applyFiltering\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n}\nexport interface ExecParams {\n where: CmsEntryListWhere;\n query: ElasticsearchBoolQueryConfig;\n}\nexport interface CreateExecFilteringResponse {\n (params: ExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model } = params;\n\n /**\n * We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.\n */\n const searchPlugins = createSearchPluginList({\n plugins\n });\n /**\n * We need the operator plugins, which we execute on our where conditions.\n */\n const operatorPlugins = createOperatorPluginList({\n plugins,\n locale: model.locale\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n searchPlugins\n });\n\n const filteringPlugins = plugins\n .byType<CmsEntryFilterPlugin>(CmsEntryFilterPlugin.type)\n .reduce<Record<string, CmsEntryFilterPlugin>>((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {});\n\n const getFilterPlugin = (type: string) => {\n const plugin = filteringPlugins[type] || filteringPlugins[\"*\"];\n if (plugin) {\n return plugin;\n }\n throw new WebinyError(\n `There is no filtering plugin for the given field type \"${type}\".`,\n \"FILTERING_PLUGIN_ERROR\",\n {\n type\n }\n );\n };\n\n const execFiltering = (params: ExecParams) => {\n const { where: initialWhere, query } = params;\n /**\n * No point in continuing if no \"where\" conditions exist.\n */\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n for (const key in where) {\n const value = where[key] as unknown as any;\n /**\n * We always skip if no value is defined.\n * Only skip undefined value, null is valid.\n */\n if (value === undefined) {\n continue;\n }\n //\n /**\n * When we are running with AND, the \"value\" MUST be an array.\n */\n else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n\n const childQuery = createBaseQuery();\n\n for (const childWhere of childWhereList) {\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({\n bool: childQueryBool\n });\n\n continue;\n }\n //\n /**\n * When we are running with OR, the \"value\" must be an array.\n */\n else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n /**\n * Each of the conditions MUST produce it's own should section.\n */\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({\n bool: childQueryBool\n });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n /**\n * If there are any should, minimum to have is 1.\n * Of course, do not override if it's already set.\n */\n assignMinimumShouldMatchToQuery({\n query\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n let fieldId: string = whereFieldId;\n\n /**\n * TODO This will be required until the storage operations receive the fieldId instead of field storageId.\n * TODO For this to work without field searching, we need to refactor how the query looks like.\n *\n * Storage operations should NEVER receive an field storageId, only alias - fieldId.\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 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}\".`);\n }\n const filterPlugin = getFilterPlugin(field.type);\n\n filterPlugin.exec({\n applyFiltering,\n getFilterPlugin,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"mappings":";;;;;;;;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcO,MAAMA,mBAAmB,GAAIC,MAAwB,IAAkC;EAC1F,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGH,MAAM;;EAEzC;AACJ;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;QACJ;QACAH,KAAK,CAACiB,MAAM,CAACF,IAAI,CAAC,GAAGE,MAAM,CAAC;QAC5B;AAChB;AACA;AACA;QACgB,IAAAC,gEAA+B,EAAC;UAC5BlB;QACJ,CAAC,CAAC;QACF;MACJ;MACA,MAAM;QAAEmB,KAAK,EAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAAC,+BAAa,EAAClB,GAAG,CAAC;MAE5D,IAAImB,OAAe,GAAGH,YAAY;;MAElC;AACZ;AACA;AACA;AACA;AACA;MACY,MAAMI,aAAa,GAAG7C,KAAK,CAACF,MAAM,CAACgD,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACH,OAAO,KAAKA,OAAO,CAAC;MACnE,IAAI,CAACC,aAAa,IAAI,CAAC/C,MAAM,CAAC8C,OAAO,CAAC,EAAE;QACpC,MAAM,IAAI3B,cAAW,CAAE,sCAAqC2B,OAAQ,IAAG,CAAC;MAC5E,CAAC,MAAM,IAAIC,aAAa,EAAE;QACtBD,OAAO,GAAGC,aAAa,CAACD,OAAO;MACnC;MAEA,MAAMJ,KAAK,GAAG1C,MAAM,CAAC8C,OAAO,CAAC;MAC7B,IAAI,CAACJ,KAAK,EAAE;QACR,MAAM,IAAIvB,cAAW,CAAE,sBAAqB2B,OAAQ,IAAG,CAAC;MAC5D;MACA,MAAMI,YAAY,GAAGhC,eAAe,CAACwB,KAAK,CAAC7B,IAAI,CAAC;MAEhDqC,YAAY,CAACC,IAAI,CAAC;QACd3C,cAAc;QACdU,eAAe;QACfS,GAAG;QACHC,KAAK;QACLgB,QAAQ;QACRF,KAAK;QACL1C,MAAM;QACNuB;MACJ,CAAC,CAAC;IACN;EACJ,CAAC;EAED,OAAOH,aAAa;AACxB,CAAC;AAAC"}
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _exec = require("./exec");
8
-
9
7
  Object.keys(_exec).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _exec[key]) return;
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./exec\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./exec\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createFieldPathFactory = void 0;
7
-
8
7
  const createFieldPathFactory = ({
9
8
  plugins
10
9
  }) => {
@@ -17,7 +16,6 @@ const createFieldPathFactory = ({
17
16
  } = params;
18
17
  const plugin = plugins[field.type];
19
18
  let fieldPath = null;
20
-
21
19
  if (plugin) {
22
20
  fieldPath = plugin.createPath({
23
21
  field: field.field,
@@ -25,21 +23,17 @@ const createFieldPathFactory = ({
25
23
  key
26
24
  });
27
25
  }
28
-
29
26
  if (!fieldPath) {
30
27
  fieldPath = field.field.storageId;
31
-
32
28
  if (field.path) {
33
29
  fieldPath = typeof field.path === "function" ? field.path(value) : field.path;
34
30
  }
35
31
  }
36
-
37
32
  const result = [];
38
-
39
33
  if (!field.isSystemField) {
40
34
  result.push("values");
41
35
  }
42
-
36
+ result.push(...field.parents.map(p => p.storageId));
43
37
  result.push(fieldPath);
44
38
  return {
45
39
  basePath: result.join("."),
@@ -47,5 +41,4 @@ const createFieldPathFactory = ({
47
41
  };
48
42
  };
49
43
  };
50
-
51
44
  exports.createFieldPathFactory = createFieldPathFactory;
@@ -1 +1 @@
1
- {"version":3,"names":["createFieldPathFactory","plugins","params","field","key","value","keyword","plugin","type","fieldPath","createPath","storageId","path","result","isSystemField","push","basePath","join","concat"],"sources":["path.ts"],"sourcesContent":["import {\n ElasticsearchQuerySearchValuePlugins,\n ModelField\n} from \"~/operations/entry/elasticsearch/types\";\n\ninterface FieldPathFactoryParams {\n plugins: ElasticsearchQuerySearchValuePlugins;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ plugins }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword } = params;\n const plugin = plugins[field.type];\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field: field.field, value, key });\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[] = [];\n if (!field.isSystemField) {\n result.push(\"values\");\n }\n result.push(fieldPath);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"mappings":";;;;;;;AAeO,MAAMA,sBAAsB,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAyC;EAC3E,OAAQC,MAAD,IAA6B;IAChC,MAAM;MAAEC,KAAF;MAASC,GAAT;MAAcC,KAAd;MAAqBC;IAArB,IAAiCJ,MAAvC;IACA,MAAMK,MAAM,GAAGN,OAAO,CAACE,KAAK,CAACK,IAAP,CAAtB;IAEA,IAAIC,SAAwB,GAAG,IAA/B;;IACA,IAAIF,MAAJ,EAAY;MACRE,SAAS,GAAGF,MAAM,CAACG,UAAP,CAAkB;QAAEP,KAAK,EAAEA,KAAK,CAACA,KAAf;QAAsBE,KAAtB;QAA6BD;MAA7B,CAAlB,CAAZ;IACH;;IACD,IAAI,CAACK,SAAL,EAAgB;MACZA,SAAS,GAAGN,KAAK,CAACA,KAAN,CAAYQ,SAAxB;;MACA,IAAIR,KAAK,CAACS,IAAV,EAAgB;QACZH,SAAS,GAAG,OAAON,KAAK,CAACS,IAAb,KAAsB,UAAtB,GAAmCT,KAAK,CAACS,IAAN,CAAWP,KAAX,CAAnC,GAAuDF,KAAK,CAACS,IAAzE;MACH;IACJ;;IAED,MAAMC,MAAgB,GAAG,EAAzB;;IACA,IAAI,CAACV,KAAK,CAACW,aAAX,EAA0B;MACtBD,MAAM,CAACE,IAAP,CAAY,QAAZ;IACH;;IACDF,MAAM,CAACE,IAAP,CAAYN,SAAZ;IAEA,OAAO;MACHO,QAAQ,EAAEH,MAAM,CAACI,IAAP,CAAY,GAAZ,CADP;MAEHL,IAAI,EAAEC,MAAM,CAACK,MAAP,CAAcZ,OAAO,GAAG,CAAC,SAAD,CAAH,GAAiB,EAAtC,EAA0CW,IAA1C,CAA+C,GAA/C;IAFH,CAAP;EAIH,CAzBD;AA0BH,CA3BM"}
1
+ {"version":3,"names":["createFieldPathFactory","plugins","params","field","key","value","keyword","plugin","type","fieldPath","createPath","storageId","path","result","isSystemField","push","parents","map","p","basePath","join","concat"],"sources":["path.ts"],"sourcesContent":["import {\n ElasticsearchQuerySearchValuePlugins,\n ModelField\n} from \"~/operations/entry/elasticsearch/types\";\n\ninterface FieldPathFactoryParams {\n plugins: ElasticsearchQuerySearchValuePlugins;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ plugins }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword } = params;\n const plugin = plugins[field.type];\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field: field.field, value, key });\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[] = [];\n if (!field.isSystemField) {\n result.push(\"values\");\n }\n result.push(...field.parents.map(p => p.storageId));\n result.push(fieldPath);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"mappings":";;;;;;AAeO,MAAMA,sBAAsB,GAAG,CAAC;EAAEC;AAAgC,CAAC,KAAK;EAC3E,OAAQC,MAAuB,IAAK;IAChC,MAAM;MAAEC,KAAK;MAAEC,GAAG;MAAEC,KAAK;MAAEC;IAAQ,CAAC,GAAGJ,MAAM;IAC7C,MAAMK,MAAM,GAAGN,OAAO,CAACE,KAAK,CAACK,IAAI,CAAC;IAElC,IAAIC,SAAwB,GAAG,IAAI;IACnC,IAAIF,MAAM,EAAE;MACRE,SAAS,GAAGF,MAAM,CAACG,UAAU,CAAC;QAAEP,KAAK,EAAEA,KAAK,CAACA,KAAK;QAAEE,KAAK;QAAED;MAAI,CAAC,CAAC;IACrE;IACA,IAAI,CAACK,SAAS,EAAE;MACZA,SAAS,GAAGN,KAAK,CAACA,KAAK,CAACQ,SAAS;MACjC,IAAIR,KAAK,CAACS,IAAI,EAAE;QACZH,SAAS,GAAG,OAAON,KAAK,CAACS,IAAI,KAAK,UAAU,GAAGT,KAAK,CAACS,IAAI,CAACP,KAAK,CAAC,GAAGF,KAAK,CAACS,IAAI;MACjF;IACJ;IAEA,MAAMC,MAAgB,GAAG,EAAE;IAC3B,IAAI,CAACV,KAAK,CAACW,aAAa,EAAE;MACtBD,MAAM,CAACE,IAAI,CAAC,QAAQ,CAAC;IACzB;IACAF,MAAM,CAACE,IAAI,CAAC,GAAGZ,KAAK,CAACa,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACP,SAAS,CAAC,CAAC;IACnDE,MAAM,CAACE,IAAI,CAACN,SAAS,CAAC;IAEtB,OAAO;MACHU,QAAQ,EAAEN,MAAM,CAACO,IAAI,CAAC,GAAG,CAAC;MAC1BR,IAAI,EAAEC,MAAM,CAACQ,MAAM,CAACf,OAAO,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAACc,IAAI,CAAC,GAAG;IAC5D,CAAC;EACL,CAAC;AACL,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntryFilterPlugin } from "../../../../../plugins/CmsEntryFilterPlugin";
2
+ export declare const createDefaultFilterPlugin: () => CmsEntryFilterPlugin;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createDefaultFilterPlugin = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _CmsEntryFilterPlugin = require("../../../../../plugins/CmsEntryFilterPlugin");
10
+ const createDefaultFilterPlugin = () => {
11
+ const plugin = new _CmsEntryFilterPlugin.CmsEntryFilterPlugin({
12
+ fieldType: _CmsEntryFilterPlugin.CmsEntryFilterPlugin.ALL,
13
+ exec: params => {
14
+ const {
15
+ applyFiltering,
16
+ field
17
+ } = params;
18
+ if (!params.field.isSearchable) {
19
+ const identifier = [...field.parents.map(p => p.fieldId), field.field.fieldId].join(".");
20
+ throw new _error.default(`Field "${identifier}" is not searchable.`);
21
+ }
22
+ applyFiltering(params);
23
+ }
24
+ });
25
+ plugin.name = `${plugin.type}.default.all`;
26
+ return plugin;
27
+ };
28
+ exports.createDefaultFilterPlugin = createDefaultFilterPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createDefaultFilterPlugin","plugin","CmsEntryFilterPlugin","fieldType","ALL","exec","params","applyFiltering","field","isSearchable","identifier","parents","map","p","fieldId","join","WebinyError","name","type"],"sources":["defaultFilterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\n\nexport const createDefaultFilterPlugin = () => {\n const plugin = new CmsEntryFilterPlugin({\n fieldType: CmsEntryFilterPlugin.ALL,\n exec: params => {\n const { applyFiltering, field } = params;\n if (!params.field.isSearchable) {\n const identifier = [...field.parents.map(p => p.fieldId), field.field.fieldId].join(\n \".\"\n );\n throw new WebinyError(`Field \"${identifier}\" is not searchable.`);\n }\n applyFiltering(params);\n }\n });\n\n plugin.name = `${plugin.type}.default.all`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIC,0CAAoB,CAAC;IACpCC,SAAS,EAAED,0CAAoB,CAACE,GAAG;IACnCC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QAAEC,cAAc;QAAEC;MAAM,CAAC,GAAGF,MAAM;MACxC,IAAI,CAACA,MAAM,CAACE,KAAK,CAACC,YAAY,EAAE;QAC5B,MAAMC,UAAU,GAAG,CAAC,GAAGF,KAAK,CAACG,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAAEN,KAAK,CAACA,KAAK,CAACM,OAAO,CAAC,CAACC,IAAI,CAC/E,GAAG,CACN;QACD,MAAM,IAAIC,cAAW,CAAE,UAASN,UAAW,sBAAqB,CAAC;MACrE;MACAH,cAAc,CAACD,MAAM,CAAC;IAC1B;EACJ,CAAC,CAAC;EAEFL,MAAM,CAACgB,IAAI,GAAI,GAAEhB,MAAM,CAACiB,IAAK,cAAa;EAE1C,OAAOjB,MAAM;AACjB,CAAC;AAAC"}
@@ -0,0 +1 @@
1
+ export declare const createFilterPlugins: () => import("../../../../../plugins/CmsEntryFilterPlugin").CmsEntryFilterPlugin[];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createFilterPlugins = void 0;
7
+ var _defaultFilterPlugin = require("./defaultFilterPlugin");
8
+ var _objectFilterPlugin = require("./objectFilterPlugin");
9
+ var _refFilterPlugin = require("./refFilterPlugin");
10
+ const createFilterPlugins = () => {
11
+ return [(0, _defaultFilterPlugin.createDefaultFilterPlugin)(), (0, _objectFilterPlugin.createObjectFilterPlugin)(), (0, _refFilterPlugin.createRefFilterPlugin)()];
12
+ };
13
+ exports.createFilterPlugins = createFilterPlugins;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFilterPlugins","createDefaultFilterPlugin","createObjectFilterPlugin","createRefFilterPlugin"],"sources":["index.ts"],"sourcesContent":["import { createDefaultFilterPlugin } from \"./defaultFilterPlugin\";\nimport { createObjectFilterPlugin } from \"./objectFilterPlugin\";\nimport { createRefFilterPlugin } from \"./refFilterPlugin\";\n\nexport const createFilterPlugins = () => {\n return [createDefaultFilterPlugin(), createObjectFilterPlugin(), createRefFilterPlugin()];\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAEO,MAAMA,mBAAmB,GAAG,MAAM;EACrC,OAAO,CAAC,IAAAC,8CAAyB,GAAE,EAAE,IAAAC,4CAAwB,GAAE,EAAE,IAAAC,sCAAqB,GAAE,CAAC;AAC7F,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntryFilterPlugin } from "../../../../../plugins/CmsEntryFilterPlugin";
2
+ export declare const createObjectFilterPlugin: () => CmsEntryFilterPlugin;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createObjectFilterPlugin = void 0;
8
+ var _CmsEntryFilterPlugin = require("../../../../../plugins/CmsEntryFilterPlugin");
9
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+ const createObjectFilterPlugin = () => {
12
+ const plugin = new _CmsEntryFilterPlugin.CmsEntryFilterPlugin({
13
+ fieldType: "object",
14
+ exec: params => {
15
+ const {
16
+ applyFiltering,
17
+ value: where,
18
+ fields,
19
+ field: parentField,
20
+ getFilterPlugin,
21
+ query
22
+ } = params;
23
+ /**
24
+ * Because this is an object field, we must construct filters based on the value property.
25
+ * Value property is actually a where condition.
26
+ */
27
+ for (const key in where) {
28
+ const value = where[key];
29
+ if (value === undefined) {
30
+ continue;
31
+ }
32
+ const {
33
+ field: whereFieldId,
34
+ operator
35
+ } = (0, _apiElasticsearch.parseWhereKey)(key);
36
+ const identifier = [...parentField.parents.map(p => p.fieldId), parentField.field.fieldId, whereFieldId].join(".");
37
+ const field = fields[identifier];
38
+ if (!field) {
39
+ throw new _error.default(`There is no field "${identifier}".`);
40
+ }
41
+ /**
42
+ * We need to find the filter plugin for the child field.
43
+ * This will throw error if no plugin can be found.
44
+ */
45
+ const plugin = getFilterPlugin(field.type);
46
+ /**
47
+ * Basically this allows us to go into depth as much as we want with the object fields.
48
+ */
49
+ plugin.exec({
50
+ applyFiltering,
51
+ getFilterPlugin,
52
+ key,
53
+ value,
54
+ operator,
55
+ field,
56
+ fields,
57
+ query
58
+ });
59
+ }
60
+ }
61
+ });
62
+ plugin.name = `${plugin.type}.default.object`;
63
+ return plugin;
64
+ };
65
+ exports.createObjectFilterPlugin = createObjectFilterPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createObjectFilterPlugin","plugin","CmsEntryFilterPlugin","fieldType","exec","params","applyFiltering","value","where","fields","field","parentField","getFilterPlugin","query","key","undefined","whereFieldId","operator","parseWhereKey","identifier","parents","map","p","fieldId","join","WebinyError","type","name"],"sources":["objectFilterPlugin.ts"],"sourcesContent":["import { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport WebinyError from \"@webiny/error\";\n\nexport const createObjectFilterPlugin = () => {\n const plugin = new CmsEntryFilterPlugin({\n fieldType: \"object\",\n exec: params => {\n const {\n applyFiltering,\n value: where,\n fields,\n field: parentField,\n getFilterPlugin,\n query\n } = params;\n /**\n * Because this is an object field, we must construct filters based on the value property.\n * Value property is actually a where condition.\n */\n for (const key in where) {\n const value = where[key];\n if (value === undefined) {\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n const identifier = [\n ...parentField.parents.map(p => p.fieldId),\n parentField.field.fieldId,\n whereFieldId\n ].join(\".\");\n const field = fields[identifier];\n if (!field) {\n throw new WebinyError(`There is no field \"${identifier}\".`);\n }\n /**\n * We need to find the filter plugin for the child field.\n * This will throw error if no plugin can be found.\n */\n const plugin = getFilterPlugin(field.type);\n /**\n * Basically this allows us to go into depth as much as we want with the object fields.\n */\n plugin.exec({\n applyFiltering,\n getFilterPlugin,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n }\n });\n\n plugin.name = `${plugin.type}.default.object`;\n\n return plugin;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEO,MAAMA,wBAAwB,GAAG,MAAM;EAC1C,MAAMC,MAAM,GAAG,IAAIC,0CAAoB,CAAC;IACpCC,SAAS,EAAE,QAAQ;IACnBC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QACFC,cAAc;QACdC,KAAK,EAAEC,KAAK;QACZC,MAAM;QACNC,KAAK,EAAEC,WAAW;QAClBC,eAAe;QACfC;MACJ,CAAC,GAAGR,MAAM;MACV;AACZ;AACA;AACA;MACY,KAAK,MAAMS,GAAG,IAAIN,KAAK,EAAE;QACrB,MAAMD,KAAK,GAAGC,KAAK,CAACM,GAAG,CAAC;QACxB,IAAIP,KAAK,KAAKQ,SAAS,EAAE;UACrB;QACJ;QACA,MAAM;UAAEL,KAAK,EAAEM,YAAY;UAAEC;QAAS,CAAC,GAAG,IAAAC,+BAAa,EAACJ,GAAG,CAAC;QAE5D,MAAMK,UAAU,GAAG,CACf,GAAGR,WAAW,CAACS,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAC1CZ,WAAW,CAACD,KAAK,CAACa,OAAO,EACzBP,YAAY,CACf,CAACQ,IAAI,CAAC,GAAG,CAAC;QACX,MAAMd,KAAK,GAAGD,MAAM,CAACU,UAAU,CAAC;QAChC,IAAI,CAACT,KAAK,EAAE;UACR,MAAM,IAAIe,cAAW,CAAE,sBAAqBN,UAAW,IAAG,CAAC;QAC/D;QACA;AAChB;AACA;AACA;QACgB,MAAMlB,MAAM,GAAGW,eAAe,CAACF,KAAK,CAACgB,IAAI,CAAC;QAC1C;AAChB;AACA;QACgBzB,MAAM,CAACG,IAAI,CAAC;UACRE,cAAc;UACdM,eAAe;UACfE,GAAG;UACHP,KAAK;UACLU,QAAQ;UACRP,KAAK;UACLD,MAAM;UACNI;QACJ,CAAC,CAAC;MACN;IACJ;EACJ,CAAC,CAAC;EAEFZ,MAAM,CAAC0B,IAAI,GAAI,GAAE1B,MAAM,CAACyB,IAAK,iBAAgB;EAE7C,OAAOzB,MAAM;AACjB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsEntryFilterPlugin } from "../../../../../plugins/CmsEntryFilterPlugin";
2
+ export declare const createRefFilterPlugin: () => CmsEntryFilterPlugin;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createRefFilterPlugin = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _CmsEntryFilterPlugin = require("../../../../../plugins/CmsEntryFilterPlugin");
10
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
11
+ const createRefFilterPlugin = () => {
12
+ return new _CmsEntryFilterPlugin.CmsEntryFilterPlugin({
13
+ fieldType: "ref",
14
+ exec: params => {
15
+ const {
16
+ applyFiltering,
17
+ value: values,
18
+ query,
19
+ field
20
+ } = params;
21
+ /**
22
+ * We must have an object when querying in the ref field.
23
+ */
24
+ if (typeof values !== "object") {
25
+ throw new _error.default(`When querying by ref field, value of the field must be an object.`, "OBJECT_REQUIRED", {
26
+ value: values
27
+ });
28
+ }
29
+ for (const key in values) {
30
+ const {
31
+ operator
32
+ } = (0, _apiElasticsearch.parseWhereKey)(key);
33
+ const value = values[key];
34
+ if (value === undefined) {
35
+ continue;
36
+ }
37
+ applyFiltering({
38
+ query,
39
+ field,
40
+ operator,
41
+ key,
42
+ value
43
+ });
44
+ }
45
+ }
46
+ });
47
+ };
48
+ exports.createRefFilterPlugin = createRefFilterPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createRefFilterPlugin","CmsEntryFilterPlugin","fieldType","exec","params","applyFiltering","value","values","query","field","WebinyError","key","operator","parseWhereKey","undefined"],"sources":["refFilterPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\n\nexport const createRefFilterPlugin = () => {\n return new CmsEntryFilterPlugin({\n fieldType: \"ref\",\n exec: params => {\n const { applyFiltering, value: values, query, field } = params;\n /**\n * We must have an object when querying in the ref field.\n */\n if (typeof values !== \"object\") {\n throw new WebinyError(\n `When querying by ref field, value of the field must be an object.`,\n \"OBJECT_REQUIRED\",\n {\n value: values\n }\n );\n }\n\n for (const key in values) {\n const { operator } = parseWhereKey(key);\n const value = values[key];\n if (value === undefined) {\n continue;\n }\n\n applyFiltering({\n query,\n field,\n operator,\n key,\n value\n });\n }\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAEO,MAAMA,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAIC,0CAAoB,CAAC;IAC5BC,SAAS,EAAE,KAAK;IAChBC,IAAI,EAAEC,MAAM,IAAI;MACZ,MAAM;QAAEC,cAAc;QAAEC,KAAK,EAAEC,MAAM;QAAEC,KAAK;QAAEC;MAAM,CAAC,GAAGL,MAAM;MAC9D;AACZ;AACA;MACY,IAAI,OAAOG,MAAM,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIG,cAAW,CAChB,mEAAkE,EACnE,iBAAiB,EACjB;UACIJ,KAAK,EAAEC;QACX,CAAC,CACJ;MACL;MAEA,KAAK,MAAMI,GAAG,IAAIJ,MAAM,EAAE;QACtB,MAAM;UAAEK;QAAS,CAAC,GAAG,IAAAC,+BAAa,EAACF,GAAG,CAAC;QACvC,MAAML,KAAK,GAAGC,MAAM,CAACI,GAAG,CAAC;QACzB,IAAIL,KAAK,KAAKQ,SAAS,EAAE;UACrB;QACJ;QAEAT,cAAc,CAAC;UACXG,KAAK;UACLC,KAAK;UACLG,QAAQ;UACRD,GAAG;UACHL;QACJ,CAAC,CAAC;MACN;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getPopulated = void 0;
7
-
8
7
  const getPopulated = query => {
9
8
  const result = {};
10
9
  let key;
11
-
12
10
  for (key in query) {
13
11
  const value = query[key];
14
-
15
12
  if (value === undefined || Array.isArray(value) && value.length === 0) {
16
13
  continue;
17
14
  }
@@ -19,12 +16,8 @@ const getPopulated = query => {
19
16
  * TODO figure out better types.
20
17
  */
21
18
  // @ts-ignore
22
-
23
-
24
19
  result[key] = value;
25
20
  }
26
-
27
21
  return result;
28
22
  };
29
-
30
23
  exports.getPopulated = getPopulated;
@@ -1 +1 @@
1
- {"version":3,"names":["getPopulated","query","result","key","value","undefined","Array","isArray","length"],"sources":["populated.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\n\nexport const getPopulated = (\n query: ElasticsearchBoolQueryConfig\n): Partial<ElasticsearchBoolQueryConfig> => {\n const result: Partial<ElasticsearchBoolQueryConfig> = {};\n let key: keyof ElasticsearchBoolQueryConfig;\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-ignore\n result[key] = value;\n }\n return result;\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,YAAY,GACrBC,KADwB,IAEgB;EACxC,MAAMC,MAA6C,GAAG,EAAtD;EACA,IAAIC,GAAJ;;EACA,KAAKA,GAAL,IAAYF,KAAZ,EAAmB;IACf,MAAMG,KAAK,GAAGH,KAAK,CAACE,GAAD,CAAnB;;IACA,IAAIC,KAAK,KAAKC,SAAV,IAAwBC,KAAK,CAACC,OAAN,CAAcH,KAAd,KAAwBA,KAAK,CAACI,MAAN,KAAiB,CAArE,EAAyE;MACrE;IACH;IACD;AACR;AACA;IACQ;;;IACAN,MAAM,CAACC,GAAD,CAAN,GAAcC,KAAd;EACH;;EACD,OAAOF,MAAP;AACH,CAjBM"}
1
+ {"version":3,"names":["getPopulated","query","result","key","value","undefined","Array","isArray","length"],"sources":["populated.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\n\nexport const getPopulated = (\n query: ElasticsearchBoolQueryConfig\n): Partial<ElasticsearchBoolQueryConfig> => {\n const result: Partial<ElasticsearchBoolQueryConfig> = {};\n let key: keyof ElasticsearchBoolQueryConfig;\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-ignore\n result[key] = value;\n }\n return result;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,YAAY,GACrBC,KAAmC,IACK;EACxC,MAAMC,MAA6C,GAAG,CAAC,CAAC;EACxD,IAAIC,GAAuC;EAC3C,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;AAAC"}
@@ -1,2 +1,2 @@
1
1
  import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
- export declare const getValues: (value: unknown, condition: "AND" | "OR") => CmsEntryListWhere[];
2
+ export declare const getWhereValues: (value: unknown, condition: "AND" | "OR") => CmsEntryListWhere[];
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.getValues = void 0;
9
-
7
+ exports.getWhereValues = void 0;
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
- const getValues = (value, condition) => {
9
+ const getWhereValues = (value, condition) => {
13
10
  const values = value;
14
-
15
11
  if (!Array.isArray(values)) {
16
12
  throw new _error.default(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
17
13
  value
@@ -21,8 +17,6 @@ const getValues = (value, condition) => {
21
17
  value
22
18
  });
23
19
  }
24
-
25
20
  return values;
26
21
  };
27
-
28
- exports.getValues = getValues;
22
+ exports.getWhereValues = getWhereValues;
@@ -1 +1 @@
1
- {"version":3,"names":["getValues","value","condition","values","Array","isArray","WebinyError","length"],"sources":["values.ts"],"sourcesContent":["import { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getValues = (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;;AAEO,MAAMA,SAAS,GAAG,CAACC,KAAD,EAAiBC,SAAjB,KAA6C;EAClE,MAAMC,MAAM,GAAGF,KAAf;;EACA,IAAI,CAACG,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAL,EAA4B;IACxB,MAAM,IAAIG,cAAJ,CACD,iCAAgCJ,SAAU,wCADzC,EAED,aAAYA,SAAU,YAFrB,EAGF;MACID;IADJ,CAHE,CAAN;EAOH,CARD,MAQO,IAAIE,MAAM,CAACI,MAAP,KAAkB,CAAtB,EAAyB;IAC5B,MAAM,IAAID,cAAJ,CACD,iCAAgCJ,SAAU,uCADzC,EAED,aAAYA,SAAU,YAFrB,EAGF;MACID;IADJ,CAHE,CAAN;EAOH;;EACD,OAAOE,MAAP;AACH,CApBM"}
1
+ {"version":3,"names":["getWhereValues","value","condition","values","Array","isArray","WebinyError","length"],"sources":["values.ts"],"sourcesContent":["import { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\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;AAEO,MAAMA,cAAc,GAAG,CAACC,KAAc,EAAEC,SAAuB,KAAK;EACvE,MAAMC,MAAM,GAAGF,KAAwC;EACvD,IAAI,CAACG,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACxB,MAAM,IAAIG,cAAW,CAChB,iCAAgCJ,SAAU,wCAAuC,EACjF,aAAYA,SAAU,YAAW,EAClC;MACID;IACJ,CAAC,CACJ;EACL,CAAC,MAAM,IAAIE,MAAM,CAACI,MAAM,KAAK,CAAC,EAAE;IAC5B,MAAM,IAAID,cAAW,CAChB,iCAAgCJ,SAAU,uCAAsC,EAChF,aAAYA,SAAU,YAAW,EAClC;MACID;IACJ,CAAC,CACJ;EACL;EACA,OAAOE,MAAM;AACjB,CAAC;AAAC"}
@@ -1,6 +1,9 @@
1
1
  import { ElasticsearchBoolQueryConfig } from "@webiny/api-elasticsearch/types";
2
- import { CmsModelField } from "@webiny/api-headless-cms/types";
2
+ import { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types";
3
+ import { PluginsContainer } from "@webiny/plugins";
3
4
  interface Params {
5
+ plugins: PluginsContainer;
6
+ model: CmsModel;
4
7
  query: ElasticsearchBoolQueryConfig;
5
8
  term?: string;
6
9
  fields: CmsModelField[];
@@ -4,31 +4,86 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.applyFullTextSearch = void 0;
7
-
8
7
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
9
-
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
+ };
10
65
  const applyFullTextSearch = params => {
11
66
  const {
67
+ plugins,
12
68
  query,
13
69
  term,
14
- fields
70
+ fields,
71
+ model
15
72
  } = params;
16
-
17
73
  if (!term || term.length === 0 || fields.length === 0) {
18
74
  return;
19
75
  }
20
-
21
- const fieldPaths = fields.map(field => {
22
- return `values.${field.storageId}`;
76
+ const plugin = getPlugin({
77
+ container: plugins,
78
+ model
23
79
  });
24
- query.must.push({
25
- query_string: {
26
- allow_leading_wildcard: true,
27
- fields: fieldPaths,
28
- query: (0, _apiElasticsearch.normalizeValue)(term),
29
- default_operator: "or"
30
- }
80
+ plugin.apply({
81
+ model,
82
+ createFieldPath: field => `values.${field.storageId}`,
83
+ fields,
84
+ query,
85
+ term,
86
+ prepareTerm: _apiElasticsearch.normalizeValue
31
87
  });
32
88
  };
33
-
34
89
  exports.applyFullTextSearch = applyFullTextSearch;
@@ -1 +1 @@
1
- {"version":3,"names":["applyFullTextSearch","params","query","term","fields","length","fieldPaths","map","field","storageId","must","push","query_string","allow_leading_wildcard","normalizeValue","default_operator"],"sources":["fullTextSearch.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { normalizeValue } from \"@webiny/api-elasticsearch\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n query: ElasticsearchBoolQueryConfig;\n term?: string;\n fields: CmsModelField[];\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { query, term, fields } = params;\n if (!term || term.length === 0 || fields.length === 0) {\n return;\n }\n\n const fieldPaths = fields.map(field => {\n return `values.${field.storageId}`;\n });\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: fieldPaths,\n query: normalizeValue(term),\n default_operator: \"or\"\n }\n });\n};\n"],"mappings":";;;;;;;AACA;;AAQO,MAAMA,mBAAmB,GAAIC,MAAD,IAA0B;EACzD,MAAM;IAAEC,KAAF;IAASC,IAAT;IAAeC;EAAf,IAA0BH,MAAhC;;EACA,IAAI,CAACE,IAAD,IAASA,IAAI,CAACE,MAAL,KAAgB,CAAzB,IAA8BD,MAAM,CAACC,MAAP,KAAkB,CAApD,EAAuD;IACnD;EACH;;EAED,MAAMC,UAAU,GAAGF,MAAM,CAACG,GAAP,CAAWC,KAAK,IAAI;IACnC,OAAQ,UAASA,KAAK,CAACC,SAAU,EAAjC;EACH,CAFkB,CAAnB;EAIAP,KAAK,CAACQ,IAAN,CAAWC,IAAX,CAAgB;IACZC,YAAY,EAAE;MACVC,sBAAsB,EAAE,IADd;MAEVT,MAAM,EAAEE,UAFE;MAGVJ,KAAK,EAAE,IAAAY,gCAAA,EAAeX,IAAf,CAHG;MAIVY,gBAAgB,EAAE;IAJR;EADF,CAAhB;AAQH,CAlBM"}
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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AAIvB,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"}
@@ -4,49 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createFullTextSearchFields = void 0;
7
-
8
- /* eslint-disable */
9
- const extractFields = fields => {
10
- return fields.reduce((collection, field) => {
11
- var _field$settings;
12
-
13
- if ((_field$settings = field.settings) !== null && _field$settings !== void 0 && _field$settings.fields) {
14
- collection.push(...extractFields(field.settings.fields));
15
- } else if (field) {}
16
-
17
- return collection;
18
- }, []);
19
- };
20
-
21
7
  const createFullTextSearchFields = params => {
22
8
  const {
23
9
  term,
24
10
  model,
25
11
  fields
26
12
  } = params;
27
-
28
- if (!fields || fields.length === 0 || !term || term.length === 0) {
13
+ if (!fields || fields.length === 0 || !term || term.trim().length === 0) {
29
14
  return [];
30
15
  }
31
-
32
- const fullTextSearchFields = [];
33
- /**
34
- * No point in going through fields if there is no search performed - no search term.
35
- */
36
-
37
- if (!!term) {
38
- for (const fieldId of fields) {
39
- const field = model.fields.find(f => f.fieldId === fieldId);
40
-
41
- if (!field) {
42
- continue;
43
- }
44
-
45
- fullTextSearchFields.push(field);
16
+ return fields.reduce((collection, fieldId) => {
17
+ const field = model.fields.find(f => f.fieldId === fieldId);
18
+ if (!field) {
19
+ return collection;
46
20
  }
47
- }
48
-
49
- return fullTextSearchFields;
21
+ collection.push(field);
22
+ return collection;
23
+ }, []);
50
24
  };
51
-
52
25
  exports.createFullTextSearchFields = createFullTextSearchFields;