@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.3386f66516

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 (243) hide show
  1. package/configurations.d.ts +2 -2
  2. package/configurations.js +18 -7
  3. package/configurations.js.map +1 -0
  4. package/definitions/entry.d.ts +2 -2
  5. package/definitions/entry.js +6 -7
  6. package/definitions/entry.js.map +1 -0
  7. package/definitions/entryElasticsearch.d.ts +2 -2
  8. package/definitions/entryElasticsearch.js +3 -7
  9. package/definitions/entryElasticsearch.js.map +1 -0
  10. package/definitions/group.d.ts +2 -2
  11. package/definitions/group.js +3 -7
  12. package/definitions/group.js.map +1 -0
  13. package/definitions/model.d.ts +2 -2
  14. package/definitions/model.js +8 -7
  15. package/definitions/model.js.map +1 -0
  16. package/definitions/settings.d.ts +2 -2
  17. package/definitions/settings.js +3 -7
  18. package/definitions/settings.js.map +1 -0
  19. package/definitions/system.d.ts +2 -2
  20. package/definitions/system.js +3 -7
  21. package/definitions/system.js.map +1 -0
  22. package/definitions/table.d.ts +2 -2
  23. package/definitions/table.js.map +1 -0
  24. package/definitions/tableElasticsearch.d.ts +2 -2
  25. package/definitions/tableElasticsearch.js.map +1 -0
  26. package/dynamoDb/index.d.ts +1 -1
  27. package/dynamoDb/index.js +4 -6
  28. package/dynamoDb/index.js.map +1 -0
  29. package/dynamoDb/storage/date.d.ts +3 -3
  30. package/dynamoDb/storage/date.js +80 -46
  31. package/dynamoDb/storage/date.js.map +1 -0
  32. package/dynamoDb/storage/longText.d.ts +7 -4
  33. package/dynamoDb/storage/longText.js +79 -54
  34. package/dynamoDb/storage/longText.js.map +1 -0
  35. package/dynamoDb/storage/richText.d.ts +2 -3
  36. package/dynamoDb/storage/richText.js +85 -67
  37. package/dynamoDb/storage/richText.js.map +1 -0
  38. package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
  39. package/elasticsearch/createElasticsearchIndex.js +60 -0
  40. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  41. package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
  42. package/elasticsearch/deleteElasticsearchIndex.js +43 -0
  43. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
  44. package/elasticsearch/index.d.ts +1 -1
  45. package/elasticsearch/index.js +1 -1
  46. package/elasticsearch/index.js.map +1 -0
  47. package/elasticsearch/indexing/dateTimeIndexing.js +15 -1
  48. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
  49. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
  50. package/elasticsearch/indexing/index.js +1 -1
  51. package/elasticsearch/indexing/index.js.map +1 -0
  52. package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
  53. package/elasticsearch/indexing/longTextIndexing.js +20 -4
  54. package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
  55. package/elasticsearch/indexing/numberIndexing.js.map +1 -0
  56. package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
  57. package/elasticsearch/indexing/objectIndexing.js +32 -9
  58. package/elasticsearch/indexing/objectIndexing.js.map +1 -0
  59. package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
  60. package/elasticsearch/indices/base.d.ts +2 -0
  61. package/elasticsearch/indices/base.js +15 -0
  62. package/elasticsearch/indices/base.js.map +1 -0
  63. package/elasticsearch/indices/index.d.ts +1 -0
  64. package/elasticsearch/indices/index.js +16 -0
  65. package/elasticsearch/indices/index.js.map +1 -0
  66. package/elasticsearch/indices/japanese.d.ts +2 -0
  67. package/elasticsearch/indices/japanese.js +16 -0
  68. package/elasticsearch/indices/japanese.js.map +1 -0
  69. package/elasticsearch/search/index.d.ts +2 -2
  70. package/elasticsearch/search/index.js +3 -5
  71. package/elasticsearch/search/index.js.map +1 -0
  72. package/elasticsearch/search/refSearch.d.ts +2 -3
  73. package/elasticsearch/search/refSearch.js +27 -16
  74. package/elasticsearch/search/refSearch.js.map +1 -0
  75. package/elasticsearch/search/timeSearch.d.ts +2 -3
  76. package/elasticsearch/search/timeSearch.js +22 -14
  77. package/elasticsearch/search/timeSearch.js.map +1 -0
  78. package/helpers/entryIndexHelpers.js +33 -18
  79. package/helpers/entryIndexHelpers.js.map +1 -0
  80. package/helpers/index.d.ts +0 -1
  81. package/helpers/index.js +0 -13
  82. package/helpers/index.js.map +1 -0
  83. package/index.d.ts +1 -0
  84. package/index.js +132 -34
  85. package/index.js.map +1 -0
  86. package/operations/entry/dataLoaders.d.ts +6 -2
  87. package/operations/entry/dataLoaders.js +31 -13
  88. package/operations/entry/dataLoaders.js.map +1 -0
  89. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  90. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +34 -0
  91. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  92. package/operations/entry/elasticsearch/body.d.ts +13 -0
  93. package/operations/entry/elasticsearch/body.js +162 -0
  94. package/operations/entry/elasticsearch/body.js.map +1 -0
  95. package/operations/entry/elasticsearch/fields.d.ts +9 -0
  96. package/operations/entry/elasticsearch/fields.js +248 -0
  97. package/operations/entry/elasticsearch/fields.js.map +1 -0
  98. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
  99. package/operations/entry/elasticsearch/filtering/applyFiltering.js +66 -0
  100. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
  101. package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
  102. package/operations/entry/elasticsearch/filtering/exec.js +215 -0
  103. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
  104. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
  105. package/operations/entry/elasticsearch/filtering/index.js +18 -0
  106. package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
  107. package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
  108. package/operations/entry/elasticsearch/filtering/path.js +52 -0
  109. package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
  110. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  111. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +35 -0
  112. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  113. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  114. package/operations/entry/elasticsearch/filtering/plugins/index.js +18 -0
  115. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  116. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  117. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +78 -0
  118. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  119. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  120. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +58 -0
  121. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  122. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
  123. package/operations/entry/elasticsearch/filtering/populated.js +30 -0
  124. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
  125. package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
  126. package/operations/entry/elasticsearch/filtering/values.js +28 -0
  127. package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
  128. package/operations/entry/elasticsearch/fullTextSearch.d.ts +9 -0
  129. package/operations/entry/elasticsearch/fullTextSearch.js +34 -0
  130. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
  131. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
  132. package/operations/entry/elasticsearch/fullTextSearchFields.js +52 -0
  133. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
  134. package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
  135. package/operations/entry/elasticsearch/initialQuery.js +117 -0
  136. package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
  137. package/operations/entry/elasticsearch/keyword.d.ts +2 -0
  138. package/operations/entry/elasticsearch/keyword.js +38 -0
  139. package/operations/entry/elasticsearch/keyword.js.map +1 -0
  140. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
  141. package/operations/entry/elasticsearch/plugins/bodyModifier.js +19 -0
  142. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
  143. package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
  144. package/operations/entry/elasticsearch/plugins/operator.js +45 -0
  145. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
  146. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
  147. package/operations/entry/elasticsearch/plugins/queryModifier.js +19 -0
  148. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
  149. package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
  150. package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +9 -5
  151. package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
  152. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
  153. package/operations/entry/elasticsearch/plugins/sortModifier.js +19 -0
  154. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
  155. package/operations/entry/elasticsearch/sort.d.ts +12 -0
  156. package/operations/entry/elasticsearch/sort.js +97 -0
  157. package/operations/entry/elasticsearch/sort.js.map +1 -0
  158. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
  159. package/operations/entry/elasticsearch/transformValueForSearch.js +34 -0
  160. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
  161. package/operations/entry/elasticsearch/types.d.ts +41 -0
  162. package/operations/entry/elasticsearch/types.js +5 -0
  163. package/operations/entry/elasticsearch/types.js.map +1 -0
  164. package/operations/entry/index.d.ts +2 -4
  165. package/operations/entry/index.js +473 -374
  166. package/operations/entry/index.js.map +1 -0
  167. package/operations/entry/keys.js.map +1 -0
  168. package/operations/entry/recordType.d.ts +3 -0
  169. package/operations/entry/recordType.js +24 -0
  170. package/operations/entry/recordType.js.map +1 -0
  171. package/operations/group/index.d.ts +2 -2
  172. package/operations/group/index.js +8 -15
  173. package/operations/group/index.js.map +1 -0
  174. package/operations/model/index.d.ts +2 -2
  175. package/operations/model/index.js +38 -39
  176. package/operations/model/index.js.map +1 -0
  177. package/operations/settings/index.d.ts +2 -2
  178. package/operations/settings/index.js +7 -13
  179. package/operations/settings/index.js.map +1 -0
  180. package/operations/system/index.d.ts +2 -2
  181. package/operations/system/index.js +5 -11
  182. package/operations/system/index.js.map +1 -0
  183. package/package.json +24 -29
  184. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +7 -3
  185. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +11 -5
  186. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
  187. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
  188. package/plugins/CmsEntryElasticsearchFieldPlugin.js +3 -3
  189. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
  190. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
  191. package/plugins/CmsEntryElasticsearchIndexPlugin.js +17 -0
  192. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
  193. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
  194. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +43 -0
  195. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
  196. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +4 -3
  197. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +11 -5
  198. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
  199. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +4 -3
  200. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +11 -5
  201. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
  202. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  203. package/plugins/CmsEntryFilterPlugin.js +31 -0
  204. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  205. package/plugins/index.d.ts +6 -0
  206. package/plugins/index.js +83 -0
  207. package/plugins/index.js.map +1 -0
  208. package/types.d.ts +7 -34
  209. package/types.js +0 -13
  210. package/types.js.map +1 -0
  211. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  212. package/helpers/createElasticsearchQueryBody.js +0 -375
  213. package/helpers/fields.d.ts +0 -77
  214. package/helpers/fields.js +0 -174
  215. package/helpers/operatorPluginsList.d.ts +0 -7
  216. package/helpers/operatorPluginsList.js +0 -30
  217. package/helpers/searchPluginsList.d.ts +0 -6
  218. package/helpers/transformValueForSearch.d.ts +0 -9
  219. package/helpers/transformValueForSearch.js +0 -26
  220. package/operations/entry/elasticsearchFields.d.ts +0 -2
  221. package/operations/entry/elasticsearchFields.js +0 -32
  222. package/operations/entry/fields.d.ts +0 -3
  223. package/operations/entry/fields.js +0 -60
  224. package/operations/system/createElasticsearchTemplate.d.ts +0 -5
  225. package/operations/system/createElasticsearchTemplate.js +0 -62
  226. package/upgrades/index.d.ts +0 -2
  227. package/upgrades/index.js +0 -16
  228. package/upgrades/utils.d.ts +0 -1
  229. package/upgrades/utils.js +0 -16
  230. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
  231. package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
  232. package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
  233. package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
  234. package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
  235. package/upgrades/v5.0.0/entryValueFixer.js +0 -124
  236. package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
  237. package/upgrades/v5.0.0/fieldFinder.js +0 -42
  238. package/upgrades/v5.0.0/helpers.d.ts +0 -4
  239. package/upgrades/v5.0.0/helpers.js +0 -57
  240. package/upgrades/v5.0.0/index.d.ts +0 -4
  241. package/upgrades/v5.0.0/index.js +0 -232
  242. package/upgrades/v5.8.0/index.d.ts +0 -4
  243. package/upgrades/v5.8.0/index.js +0 -426
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getAllEntryRevisions","params","entity","model","tenant","locale","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","getRevisionById","queries","reduce","collection","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","Object","values","filter","item","getPublishedRevisionByEntryId","publishedKey","createPublishedSortKey","entryId","getLatestRevisionByEntryId","latestKey","createLatestSortKey","dataLoaders","loaderNames","DataLoadersHandler","constructor","Map","loadMany","clearAllEntryRevisions","clear","clearRevisionById","clearPublishedRevisionByEntryId","clearLatestRevisionByEntryId","getLoader","name","WebinyError","loaderKey","modelId","loaders","has","set","get","loader","Array","isArray","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll","entry"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport {\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"./keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\n\nconst getAllEntryRevisions = (params: LoaderParams) => {\n const { entity, model } = params;\n const { tenant, locale } = model;\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const results: Record<string, CmsEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsEntry>(queryAllParams);\n\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n });\n};\n\nconst getRevisionById = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (!version) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n });\n};\n\nconst getPublishedRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const publishedKey = createPublishedSortKey();\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst getLatestRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We use any because there is no type for the return type.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst dataLoaders: Record<Loaders, any> = {\n getAllEntryRevisions,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId\n};\n\nexport interface GetAllEntryRevisionsParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetRevisionByIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetPublishedRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetLatestRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\ninterface LoaderParams {\n entity: Entity<any>;\n model: CmsModel;\n}\n\ninterface GetLoaderParams {\n model: CmsModel;\n}\n\ninterface ClearLoaderParams {\n model: CmsModel;\n entry?: CmsEntry;\n}\n\ntype Loaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nconst loaderNames = Object.keys(dataLoaders) as Loaders[];\n\nexport interface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\nexport class DataLoadersHandler {\n private readonly loaders: Map<string, DataLoader<any, any>> = new Map();\n private readonly entity: Entity<any>;\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(params: GetAllEntryRevisionsParams): Promise<CmsEntry[]> {\n return await this.loadMany(\"getAllEntryRevisions\", params, params.ids);\n }\n\n public clearAllEntryRevisions(params: ClearLoaderParams): void {\n this.clear(\"getAllEntryRevisions\", params);\n }\n\n public async getRevisionById(params: GetRevisionByIdParams): Promise<CmsEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public clearRevisionById(params: ClearLoaderParams): void {\n this.clear(\"getRevisionById\", params);\n }\n\n public async getPublishedRevisionByEntryId(\n params: GetPublishedRevisionByEntryIdParams\n ): Promise<CmsEntry[]> {\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, params.ids);\n }\n public clearPublishedRevisionByEntryId(params: ClearLoaderParams): void {\n this.clear(\"getPublishedRevisionByEntryId\", params);\n }\n\n public async getLatestRevisionByEntryId(\n params: GetLatestRevisionByEntryIdParams\n ): Promise<CmsEntry[]> {\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, params.ids);\n }\n\n public clearLatestRevisionByEntryId(params: ClearLoaderParams): void {\n this.clear(\"getLatestRevisionByEntryId\", params);\n }\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: Loaders, params: GetLoaderParams): DataLoader<any, any> {\n if (!dataLoaders[name]) {\n throw new WebinyError(\"Unknown data loader.\", \"UNKNOWN_DATA_LOADER\", {\n name\n });\n }\n const { model } = params;\n const { tenant, locale } = model;\n const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;\n if (!this.loaders.has(loaderKey)) {\n this.loaders.set(\n loaderKey,\n dataLoaders[name]({\n ...params,\n entity: this.entity\n })\n );\n }\n return this.loaders.get(loaderKey) as DataLoader<any, any>;\n }\n\n private async loadMany(\n loader: Loaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsEntry[]> {\n let results;\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params: Omit<ClearLoaderParams, \"entry\">): void {\n for (const name of loaderNames) {\n const loader = this.getLoader(name, params);\n loader.clearAll();\n }\n }\n /**\n * Helper to clear the cache for certain data loader.\n * If entry is passed then clear target key only.\n */\n private clear(name: Loaders, params: ClearLoaderParams): void {\n const { entry } = params;\n const loader = this.getLoader(name, params);\n if (!entry) {\n loader.clearAll();\n return;\n }\n loader.clear(entry.id);\n const { tenant, locale } = params.model;\n loader.clear(\n createPartitionKey({\n tenant,\n locale,\n id: entry.id\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AAMA;;AACA;;AACA;;AAEA,MAAMA,oBAAoB,GAAIC,MAAD,IAA0B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAoBF,MAA1B;EACA,MAAM;IAAEG,MAAF;IAAUC;EAAV,IAAqBF,KAA3B;EACA,OAAO,IAAIG,mBAAJ,CAAmC,MAAOC,GAAP,IAAkC;IACxE,MAAMC,OAAmC,GAAG,EAA5C;;IACA,KAAK,MAAMC,EAAX,IAAiBF,GAAjB,EAAsB;MAClB,MAAMG,cAA8B,GAAG;QACnCR,MADmC;QAEnCS,YAAY,EAAE,IAAAC,wBAAA,EAAmB;UA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KK3E,MALL;QAMEgE,MANF;QAOE1D;MAPF,GAAN;IAUH;;IACD,MAAM,IAAImD,cAAJ,CACD,2DADC,EAEF,4BAFE,EAGF;MACIO,MADJ;MAEI1D,GAFJ;MAGIC;IAHJ,CAHE,CAAN;EASH;;EAEMsE,QAAQ,CAAC7E,MAAD,EAAiD;IAC5D,KAAK,MAAMwD,IAAX,IAAmBX,WAAnB,EAAgC;MAC5B,MAAMmB,MAAM,GAAG,KAAKT,SAAL,CAAeC,IAAf,EAAqBxD,MAArB,CAAf;MACAgE,MAAM,CAACa,QAAP;IACH;EACJ;EACD;AACJ;AACA;AACA;;;EACY1B,KAAK,CAACK,IAAD,EAAgBxD,MAAhB,EAAiD;IAC1D,MAAM;MAAE8E;IAAF,IAAY9E,MAAlB;IACA,MAAMgE,MAAM,GAAG,KAAKT,SAAL,CAAeC,IAAf,EAAqBxD,MAArB,CAAf;;IACA,IAAI,CAAC8E,KAAL,EAAY;MACRd,MAAM,CAACa,QAAP;MACA;IACH;;IACDb,MAAM,CAACb,KAAP,CAAa2B,KAAK,CAACtE,EAAnB;IACA,MAAM;MAAEL,MAAF;MAAUC;IAAV,IAAqBJ,MAAM,CAACE,KAAlC;IACA8D,MAAM,CAACb,KAAP,CACI,IAAAxC,wBAAA,EAAmB;MACfR,MADe;MAEfC,MAFe;MAGfI,EAAE,EAAEsE,KAAK,CAACtE;IAHK,CAAnB,CADJ;EAOH;;AAlJ2B"}
@@ -0,0 +1,18 @@
1
+ import { BoolQueryConfig } from "@webiny/api-elasticsearch/types";
2
+ /**
3
+ * This function will assign a minimum_should_match for the query if conditions are met:
4
+ * * should is an array
5
+ * * it is not empty
6
+ * * minimum_should_match is not already set
7
+ *
8
+ *
9
+ * By the default we set it to 1 as we want at least one OR condition to produce results.
10
+ *
11
+ * Users can modify minimum_should_match value via the body or query modification plugins.
12
+ */
13
+ interface Params {
14
+ query: BoolQueryConfig;
15
+ value?: number;
16
+ }
17
+ export declare const assignMinimumShouldMatchToQuery: ({ query, value }: Params) => void;
18
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignMinimumShouldMatchToQuery = void 0;
7
+
8
+ /**
9
+ * This function will assign a minimum_should_match for the query if conditions are met:
10
+ * * should is an array
11
+ * * it is not empty
12
+ * * minimum_should_match is not already set
13
+ *
14
+ *
15
+ * By the default we set it to 1 as we want at least one OR condition to produce results.
16
+ *
17
+ * Users can modify minimum_should_match value via the body or query modification plugins.
18
+ */
19
+ const assignMinimumShouldMatchToQuery = ({
20
+ query,
21
+ value = 1
22
+ }) => {
23
+ if (!Array.isArray(query.should)) {
24
+ return;
25
+ } else if (query.should.length === 0) {
26
+ return;
27
+ } else if (query.minimum_should_match) {
28
+ return;
29
+ }
30
+
31
+ query.minimum_should_match = value > 0 ? value : 1;
32
+ };
33
+
34
+ exports.assignMinimumShouldMatchToQuery = assignMinimumShouldMatchToQuery;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["assignMinimumShouldMatchToQuery","query","value","Array","isArray","should","length","minimum_should_match"],"sources":["assignMinimumShouldMatchToQuery.ts"],"sourcesContent":["import { BoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\n\n/**\n * This function will assign a minimum_should_match for the query if conditions are met:\n * * should is an array\n * * it is not empty\n * * minimum_should_match is not already set\n *\n *\n * By the default we set it to 1 as we want at least one OR condition to produce results.\n *\n * Users can modify minimum_should_match value via the body or query modification plugins.\n */\ninterface Params {\n query: BoolQueryConfig;\n value?: number;\n}\nexport const assignMinimumShouldMatchToQuery = ({ query, value = 1 }: Params): void => {\n if (!Array.isArray(query.should)) {\n return;\n } else if (query.should.length === 0) {\n return;\n } else if (query.minimum_should_match) {\n return;\n }\n query.minimum_should_match = value > 0 ? value : 1;\n};\n"],"mappings":";;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKO,MAAMA,+BAA+B,GAAG,CAAC;EAAEC,KAAF;EAASC,KAAK,GAAG;AAAjB,CAAD,KAAwC;EACnF,IAAI,CAACC,KAAK,CAACC,OAAN,CAAcH,KAAK,CAACI,MAApB,CAAL,EAAkC;IAC9B;EACH,CAFD,MAEO,IAAIJ,KAAK,CAACI,MAAN,CAAaC,MAAb,KAAwB,CAA5B,EAA+B;IAClC;EACH,CAFM,MAEA,IAAIL,KAAK,CAACM,oBAAV,EAAgC;IACnC;EACH;;EACDN,KAAK,CAACM,oBAAN,GAA6BL,KAAK,GAAG,CAAR,GAAYA,KAAZ,GAAoB,CAAjD;AACH,CATM"}
@@ -0,0 +1,13 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { CmsEntryListParams, CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types";
3
+ import { PrimitiveValue, SearchBody } from "@webiny/api-elasticsearch/types";
4
+ interface Params {
5
+ plugins: PluginsContainer;
6
+ model: CmsModel;
7
+ params: Omit<CmsEntryListParams, "where" | "after"> & {
8
+ where: CmsEntryListWhere;
9
+ after?: PrimitiveValue[];
10
+ };
11
+ }
12
+ export declare const createElasticsearchBody: ({ plugins, model, params }: Params) => SearchBody;
13
+ export {};
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createElasticsearchBody = void 0;
7
+
8
+ var _fields = require("./fields");
9
+
10
+ var _fullTextSearchFields = require("./fullTextSearchFields");
11
+
12
+ var _initialQuery = require("./initialQuery");
13
+
14
+ var _fullTextSearch = require("./fullTextSearch");
15
+
16
+ var _queryModifier = require("./plugins/queryModifier");
17
+
18
+ var _sortModifier = require("./plugins/sortModifier");
19
+
20
+ var _bodyModifier = require("./plugins/bodyModifier");
21
+
22
+ var _sort = require("./sort");
23
+
24
+ var _filtering = require("./filtering");
25
+
26
+ var _assignMinimumShouldMatchToQuery = require("./assignMinimumShouldMatchToQuery");
27
+
28
+ const createElasticsearchBody = ({
29
+ plugins,
30
+ model,
31
+ params
32
+ }) => {
33
+ const {
34
+ fields,
35
+ search: term,
36
+ where,
37
+ sort: initialSort,
38
+ after,
39
+ limit
40
+ } = params;
41
+ /**
42
+ * We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.
43
+ */
44
+
45
+ const modelFields = (0, _fields.createModelFields)({
46
+ plugins,
47
+ fields: model.fields
48
+ });
49
+ /**
50
+ * We need the query modifier plugins.
51
+ */
52
+
53
+ const queryModifierPlugins = (0, _queryModifier.createQueryModifierPluginList)({
54
+ plugins,
55
+ model
56
+ });
57
+ /**
58
+ * We need the sort modifier plugins.
59
+ */
60
+
61
+ const sortModifierPlugins = (0, _sortModifier.createSortModifierPluginList)({
62
+ plugins,
63
+ model
64
+ });
65
+ /**
66
+ * We need the body modifier plugins.
67
+ */
68
+
69
+ const bodyModifierPlugins = (0, _bodyModifier.createBodyModifierPluginList)({
70
+ plugins,
71
+ model
72
+ });
73
+ /**
74
+ * We need the fields which we can search through via the full text search.
75
+ *
76
+ */
77
+
78
+ const fullTextSearchFields = (0, _fullTextSearchFields.createFullTextSearchFields)({
79
+ model,
80
+ term,
81
+ fields
82
+ });
83
+ /**
84
+ * The initial elasticsearch query where we attach some default conditions we always need.
85
+ */
86
+
87
+ const query = (0, _initialQuery.createInitialQuery)({
88
+ where,
89
+ model
90
+ });
91
+ /**
92
+ * Apply the full text search, if term is set.
93
+ */
94
+
95
+ (0, _fullTextSearch.applyFullTextSearch)({
96
+ query,
97
+ term,
98
+ fields: fullTextSearchFields
99
+ });
100
+ const execFiltering = (0, _filtering.createExecFiltering)({
101
+ model,
102
+ fields: modelFields,
103
+ plugins
104
+ });
105
+ execFiltering({
106
+ where,
107
+ query
108
+ });
109
+
110
+ for (const pl of queryModifierPlugins) {
111
+ pl.modifyQuery({
112
+ query,
113
+ model,
114
+ where
115
+ });
116
+ }
117
+
118
+ const sort = (0, _sort.createElasticsearchSort)({
119
+ plugins,
120
+ sort: initialSort,
121
+ modelFields,
122
+ model
123
+ });
124
+
125
+ for (const pl of sortModifierPlugins) {
126
+ pl.modifySort({
127
+ sort,
128
+ model
129
+ });
130
+ }
131
+
132
+ const boolQuery = {
133
+ must: query.must.length > 0 ? query.must : undefined,
134
+ must_not: query.must_not.length > 0 ? query.must_not : undefined,
135
+ should: query.should.length > 0 ? query.should : undefined,
136
+ filter: query.filter.length > 0 ? query.filter : undefined
137
+ };
138
+ (0, _assignMinimumShouldMatchToQuery.assignMinimumShouldMatchToQuery)({
139
+ query: boolQuery
140
+ });
141
+ const body = {
142
+ query: {
143
+ bool: boolQuery
144
+ },
145
+ sort,
146
+ size: (limit || 0) + 1,
147
+ search_after: after,
148
+ track_total_hits: true
149
+ };
150
+
151
+ for (const pl of bodyModifierPlugins) {
152
+ pl.modifyBody({
153
+ body,
154
+ model,
155
+ where
156
+ });
157
+ }
158
+
159
+ return body;
160
+ };
161
+
162
+ exports.createElasticsearchBody = createElasticsearchBody;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createElasticsearchBody","plugins","model","params","fields","search","term","where","sort","initialSort","after","limit","modelFields","createModelFields","queryModifierPlugins","createQueryModifierPluginList","sortModifierPlugins","createSortModifierPluginList","bodyModifierPlugins","createBodyModifierPluginList","fullTextSearchFields","createFullTextSearchFields","query","createInitialQuery","applyFullTextSearch","execFiltering","createExecFiltering","pl","modifyQuery","createElasticsearchSort","modifySort","boolQuery","must","length","undefined","must_not","should","filter","assignMinimumShouldMatchToQuery","body","bool","size","search_after","track_total_hits","modifyBody"],"sources":["body.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListParams, CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createModelFields } from \"./fields\";\nimport { createFullTextSearchFields } from \"./fullTextSearchFields\";\nimport { createInitialQuery } from \"./initialQuery\";\nimport { applyFullTextSearch } from \"./fullTextSearch\";\nimport { createQueryModifierPluginList } from \"./plugins/queryModifier\";\nimport { createSortModifierPluginList } from \"./plugins/sortModifier\";\nimport { createBodyModifierPluginList } from \"./plugins/bodyModifier\";\nimport { createElasticsearchSort } from \"./sort\";\nimport { PrimitiveValue, SearchBody, BoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createExecFiltering } from \"./filtering\";\nimport { assignMinimumShouldMatchToQuery } from \"./assignMinimumShouldMatchToQuery\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n params: Omit<CmsEntryListParams, \"where\" | \"after\"> & {\n where: CmsEntryListWhere;\n after?: PrimitiveValue[];\n };\n}\nexport const createElasticsearchBody = ({ plugins, model, params }: Params): SearchBody => {\n const { fields, search: term, where, sort: initialSort, after, limit } = params;\n /**\n * We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.\n */\n const modelFields = createModelFields({\n plugins,\n fields: model.fields\n });\n\n /**\n * We need the query modifier plugins.\n */\n const queryModifierPlugins = createQueryModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the sort modifier plugins.\n */\n const sortModifierPlugins = createSortModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the body modifier plugins.\n */\n const bodyModifierPlugins = createBodyModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the fields which we can search through via the full text search.\n *\n */\n const fullTextSearchFields = createFullTextSearchFields({\n model,\n term,\n fields\n });\n /**\n * The initial elasticsearch query where we attach some default conditions we always need.\n */\n const query = createInitialQuery({\n where,\n model\n });\n /**\n * Apply the full text search, if term is set.\n */\n applyFullTextSearch({\n query,\n term,\n fields: fullTextSearchFields\n });\n\n const execFiltering = createExecFiltering({\n model,\n fields: modelFields,\n plugins\n });\n\n execFiltering({\n where,\n query\n });\n\n for (const pl of queryModifierPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSort({\n plugins,\n sort: initialSort,\n modelFields,\n model\n });\n\n for (const pl of sortModifierPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const boolQuery: BoolQueryConfig = {\n must: query.must.length > 0 ? query.must : undefined,\n must_not: query.must_not.length > 0 ? query.must_not : undefined,\n should: query.should.length > 0 ? query.should : undefined,\n filter: query.filter.length > 0 ? query.filter : undefined\n };\n\n assignMinimumShouldMatchToQuery({\n query: boolQuery\n });\n\n const body: SearchBody = {\n query: {\n bool: boolQuery\n },\n sort,\n size: (limit || 0) + 1,\n search_after: after,\n track_total_hits: true\n };\n\n for (const pl of bodyModifierPlugins) {\n pl.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAUO,MAAMA,uBAAuB,GAAG,CAAC;EAAEC,OAAF;EAAWC,KAAX;EAAkBC;AAAlB,CAAD,KAAoD;EACvF,MAAM;IAAEC,MAAF;IAAUC,MAAM,EAAEC,IAAlB;IAAwBC,KAAxB;IAA+BC,IAAI,EAAEC,WAArC;IAAkDC,KAAlD;IAAyDC;EAAzD,IAAmER,MAAzE;EACA;AACJ;AACA;;EACI,MAAMS,WAAW,GAAG,IAAAC,yBAAA,EAAkB;IAClCZ,OADkC;IAElCG,MAAM,EAAEF,KAAK,CAACE;EAFoB,CAAlB,CAApB;EAKA;AACJ;AACA;;EACI,MAAMU,oBAAoB,GAAG,IAAAC,4CAAA,EAA8B;IACvDd,OADuD;IAEvDC;EAFuD,CAA9B,CAA7B;EAIA;AACJ;AACA;;EACI,MAAMc,mBAAmB,GAAG,IAAAC,0CAAA,EAA6B;IACrDhB,OADqD;IAErDC;EAFqD,CAA7B,CAA5B;EAIA;AACJ;AACA;;EACI,MAAMgB,mBAAmB,GAAG,IAAAC,0CAAA,EAA6B;IACrDlB,OADqD;IAErDC;EAFqD,CAA7B,CAA5B;EAIA;AACJ;AACA;AACA;;EACI,MAAMkB,oBAAoB,GAAG,IAAAC,gDAAA,EAA2B;IACpDnB,KADoD;IAEpDI,IAFoD;IAGpDF;EAHoD,CAA3B,CAA7B;EAKA;AACJ;AACA;;EACI,MAA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lB,CAAnC;EAOA,IAAAI,gEAAA,EAAgC;IAC5BhB,KAAK,EAAES;EADqB,CAAhC;EAIA,MAAMQ,IAAgB,GAAG;IACrBjB,KAAK,EAAE;MACHkB,IAAI,EAAET;IADH,CADc;IAIrBvB,IAJqB;IAKrBiC,IAAI,EAAE,CAAC9B,KAAK,IAAI,CAAV,IAAe,CALA;IAMrB+B,YAAY,EAAEhC,KANO;IAOrBiC,gBAAgB,EAAE;EAPG,CAAzB;;EAUA,KAAK,MAAMhB,EAAX,IAAiBT,mBAAjB,EAAsC;IAClCS,EAAE,CAACiB,UAAH,CAAc;MACVL,IADU;MAEVrC,KAFU;MAGVK;IAHU,CAAd;EAKH;;EAED,OAAOgC,IAAP;AACH,CAnHM"}
@@ -0,0 +1,9 @@
1
+ import { PluginsContainer } from "@webiny/plugins";
2
+ import { CmsModelField } from "@webiny/api-headless-cms/types";
3
+ import { ModelFields } from "./types";
4
+ interface Params {
5
+ plugins: PluginsContainer;
6
+ fields?: CmsModelField[];
7
+ }
8
+ export declare const createModelFields: ({ plugins, fields }: Params) => ModelFields;
9
+ export {};
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createModelFields = void 0;
9
+
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
12
+ var _error = _interopRequireDefault(require("@webiny/error"));
13
+
14
+ const createSystemField = field => {
15
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
16
+ id: field.fieldId,
17
+ label: field.fieldId
18
+ });
19
+ };
20
+
21
+ const createSystemFields = () => {
22
+ return {
23
+ id: {
24
+ type: "text",
25
+ isSystemField: true,
26
+ isSearchable: true,
27
+ isSortable: true,
28
+ field: createSystemField({
29
+ storageId: "id",
30
+ fieldId: "id",
31
+ type: "text"
32
+ }),
33
+ parents: []
34
+ },
35
+ entryId: {
36
+ type: "text",
37
+ isSystemField: true,
38
+ isSearchable: true,
39
+ isSortable: true,
40
+ field: createSystemField({
41
+ storageId: "entryId",
42
+ fieldId: "entryId",
43
+ type: "text"
44
+ }),
45
+ parents: []
46
+ },
47
+ savedOn: {
48
+ type: "date",
49
+ unmappedType: "date",
50
+ keyword: false,
51
+ isSystemField: true,
52
+ isSearchable: true,
53
+ isSortable: true,
54
+ field: createSystemField({
55
+ storageId: "savedOn",
56
+ fieldId: "savedOn",
57
+ type: "datetime",
58
+ settings: {
59
+ type: "dateTimeWithoutTimezone"
60
+ }
61
+ }),
62
+ parents: []
63
+ },
64
+ createdOn: {
65
+ type: "date",
66
+ unmappedType: "date",
67
+ keyword: false,
68
+ isSystemField: true,
69
+ isSearchable: true,
70
+ isSortable: true,
71
+ field: createSystemField({
72
+ storageId: "createdOn",
73
+ fieldId: "createdOn",
74
+ type: "text",
75
+ settings: {
76
+ type: "dateTimeWithoutTimezone"
77
+ }
78
+ }),
79
+ parents: []
80
+ },
81
+ createdBy: {
82
+ type: "text",
83
+ unmappedType: undefined,
84
+ isSystemField: true,
85
+ isSearchable: true,
86
+ isSortable: false,
87
+ path: "createdBy.id",
88
+ field: createSystemField({
89
+ storageId: "createdBy",
90
+ fieldId: "createdBy",
91
+ type: "text"
92
+ }),
93
+ parents: []
94
+ },
95
+ ownedBy: {
96
+ type: "text",
97
+ unmappedType: undefined,
98
+ isSystemField: true,
99
+ isSearchable: true,
100
+ isSortable: false,
101
+ path: "ownedBy.id",
102
+ field: createSystemField({
103
+ storageId: "ownedBy",
104
+ fieldId: "ownedBy",
105
+ type: "text"
106
+ }),
107
+ parents: []
108
+ },
109
+ version: {
110
+ type: "number",
111
+ unmappedType: undefined,
112
+ keyword: false,
113
+ isSystemField: true,
114
+ isSearchable: true,
115
+ isSortable: true,
116
+ field: createSystemField({
117
+ storageId: "version",
118
+ fieldId: "version",
119
+ type: "number"
120
+ }),
121
+ parents: []
122
+ },
123
+ status: {
124
+ type: "string",
125
+ unmappedType: undefined,
126
+ keyword: false,
127
+ isSystemField: true,
128
+ isSearchable: true,
129
+ isSortable: false,
130
+ field: createSystemField({
131
+ storageId: "status",
132
+ fieldId: "status",
133
+ type: "string"
134
+ }),
135
+ parents: []
136
+ }
137
+ };
138
+ };
139
+
140
+ const buildFieldsList = params => {
141
+ const {
142
+ plugins,
143
+ fields,
144
+ parents
145
+ } = params;
146
+ return fields.reduce((result, field) => {
147
+ var _field$settings;
148
+
149
+ const plugin = plugins[field.type];
150
+
151
+ if (!plugin) {
152
+ throw new _error.default(`There is no plugin for field type "${field.type}".`);
153
+ }
154
+
155
+ const {
156
+ isSearchable,
157
+ isSortable,
158
+ unmappedType,
159
+ fullTextSearch
160
+ } = plugin;
161
+ /**
162
+ * If a field has child fields, go through them and add them to a result.
163
+ */
164
+
165
+ const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
166
+
167
+ if (childFields.length > 0) {
168
+ /**
169
+ * Let's build all the child fields
170
+ */
171
+ const childResult = buildFieldsList({
172
+ fields: childFields,
173
+ plugins,
174
+ parents: [...parents, {
175
+ fieldId: field.fieldId,
176
+ storageId: field.storageId,
177
+ type: field.type
178
+ }]
179
+ });
180
+ /**
181
+ *
182
+ */
183
+
184
+ Object.assign(result, childResult);
185
+ }
186
+
187
+ const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(".");
188
+ result[identifier] = {
189
+ type: field.type,
190
+ parents,
191
+ isSearchable,
192
+ isSortable,
193
+ fullTextSearch,
194
+ unmappedType: typeof unmappedType === "function" ? unmappedType(field) : undefined,
195
+ isSystemField: false,
196
+ field
197
+ };
198
+ return result;
199
+ }, {});
200
+ };
201
+
202
+ const createModelFields = ({
203
+ plugins,
204
+ fields
205
+ }) => {
206
+ if (!fields || fields.length === 0) {
207
+ return createSystemFields();
208
+ }
209
+ /**
210
+ * Collect all unmappedType from elastic plugins.
211
+ */
212
+
213
+
214
+ const unmappedTypes = plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
215
+ if (!plugin.unmappedType) {
216
+ return acc;
217
+ }
218
+
219
+ acc[plugin.fieldType] = plugin.unmappedType;
220
+ return acc;
221
+ }, {});
222
+ /**
223
+ * Collect all field types from the plugins.
224
+ */
225
+
226
+ const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
227
+ const {
228
+ fieldType,
229
+ isSearchable,
230
+ isSortable,
231
+ fullTextSearch
232
+ } = plugin;
233
+ types[fieldType] = {
234
+ unmappedType: unmappedTypes[fieldType],
235
+ isSearchable,
236
+ isSortable,
237
+ fullTextSearch
238
+ };
239
+ return types;
240
+ }, {});
241
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, createSystemFields()), buildFieldsList({
242
+ fields,
243
+ plugins: fieldTypePlugins,
244
+ parents: []
245
+ }));
246
+ };
247
+
248
+ exports.createModelFields = createModelFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","isSystemField","isSearchable","isSortable","storageId","parents","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","buildFieldsList","params","plugins","fields","reduce","result","plugin","WebinyError","fullTextSearch","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","unmappedTypes","byType","acc","fieldType","fieldTypePlugins","types"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFieldParent, ModelFields } from \"./types\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n }),\n parents: []\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n }),\n parents: []\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: CmsModelField) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: CmsModelField) => string | undefined;\n isSearchable: boolean;\n isSortable: boolean;\n fullTextSearch?: boolean;\n}\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const plugin = plugins[field.type];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { isSearchable, isSortable, unmappedType, fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: field.type\n }\n ]\n });\n /**\n *\n */\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: field.type,\n parents,\n isSearchable,\n isSortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n isSystemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n fields?: CmsModelField[];\n}\nexport const createModelFields = ({ plugins, fields }: Params) => {\n if (!fields || fields.length === 0) {\n return createSystemFields();\n }\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, isSearchable, isSortable, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n isSearchable,\n isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: []\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAQA,MAAMA,iBAAiB,GAAIC,KAAD,IAAgD;EACtE,mEACOA,KADP;IAEIC,EAAE,EAAED,KAAK,CAACE,OAFd;IAGIC,KAAK,EAAEH,KAAK,CAACE;EAHjB;AAKH,CAND;;AAQA,MAAME,kBAAkB,GAAG,MAAmB;EAC1C,OAAO;IACHH,EAAE,EAAE;MACAI,IAAI,EAAE,MADN;MAEAC,aAAa,EAAE,IAFf;MAGAC,YAAY,EAAE,IAHd;MAIAC,UAAU,EAAE,IAJZ;MAKAR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,IADU;QAErBP,OAAO,EAAE,IAFY;QAGrBG,IAAI,EAAE;MAHe,CAAD,CALxB;MAUAK,OAAO,EAAE;IAVT,CADD;IAaHC,OAAO,EAAE;MACLN,IAAI,EAAE,MADD;MAELC,aAAa,EAAE,IAFV;MAGLC,YAAY,EAAE,IAHT;MAILC,UAAU,EAAE,IAJP;MAKLR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,SADU;QAErBP,OAAO,EAAE,SAFY;QAGrBG,IAAI,EAAE;MAHe,CAAD,CALnB;MAULK,OAAO,EAAE;IAVJ,CAbN;IAyBHE,OAAO,EAAE;MACLP,IAAI,EAAE,MADD;MAELQ,YAAY,EAAE,MAFT;MAGLC,OAAO,EAAE,KAHJ;M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,aAAa,GAAGjB,OAAO,CACxBkB,MADiB,CAC0B,mCAD1B,EAEjBhB,MAFiB,CAEU,CAACiB,GAAD,EAAMf,MAAN,KAAiB;IACzC,IAAI,CAACA,MAAM,CAAChB,YAAZ,EAA0B;MACtB,OAAO+B,GAAP;IACH;;IACDA,GAAG,CAACf,MAAM,CAACgB,SAAR,CAAH,GAAwBhB,MAAM,CAAChB,YAA/B;IACA,OAAO+B,GAAP;EACH,CARiB,EAQf,EARe,CAAtB;EASA;AACJ;AACA;;EACI,MAAME,gBAAgB,GAAGrB,OAAO,CAC3BkB,MADoB,CACiB,4BADjB,EAEpBhB,MAFoB,CAEK,CAACoB,KAAD,EAAQlB,MAAR,KAAmB;IACzC,MAAM;MAAEgB,SAAF;MAAatC,YAAb;MAA2BC,UAA3B;MAAuCuB;IAAvC,IAA0DF,MAAhE;IACAkB,KAAK,CAACF,SAAD,CAAL,GAAmB;MACfhC,YAAY,EAAE6B,aAAa,CAACG,SAAD,CADZ;MAEftC,YAFe;MAGfC,UAHe;MAIfuB;IAJe,CAAnB;IAMA,OAAOgB,KAAP;EACH,CAXoB,EAWlB,EAXkB,CAAzB;EAaA,mEACO3C,kBAAkB,EADzB,GAEOmB,eAAe,CAAC;IACfG,MADe;IAEfD,OAAO,EAAEqB,gBAFM;IAGfpC,OAAO,EAAE;EAHM,CAAD,CAFtB;AAQH,CAxCM"}
@@ -0,0 +1,8 @@
1
+ import { ElasticsearchQueryBuilderOperatorPlugins, ElasticsearchQuerySearchValuePlugins } from "../types";
2
+ import { ApplyFilteringCb } from "../../../../plugins/CmsEntryFilterPlugin";
3
+ interface CreateParams {
4
+ operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;
5
+ searchPlugins: ElasticsearchQuerySearchValuePlugins;
6
+ }
7
+ export declare const createApplyFiltering: ({ operatorPlugins, searchPlugins }: CreateParams) => ApplyFilteringCb;
8
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createApplyFiltering = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ var _transformValueForSearch = require("../transformValueForSearch");
13
+
14
+ var _keyword = require("../keyword");
15
+
16
+ var _path = require("./path");
17
+
18
+ const createApplyFiltering = ({
19
+ operatorPlugins,
20
+ searchPlugins
21
+ }) => {
22
+ const createFieldPath = (0, _path.createFieldPathFactory)({
23
+ plugins: searchPlugins
24
+ });
25
+ return params => {
26
+ const {
27
+ key,
28
+ value: initialValue,
29
+ query,
30
+ operator,
31
+ field
32
+ } = params;
33
+ const plugin = operatorPlugins[operator];
34
+
35
+ if (!plugin) {
36
+ throw new _error.default("Operator plugin missing.", "PLUGIN_MISSING", {
37
+ operator
38
+ });
39
+ }
40
+
41
+ const value = (0, _transformValueForSearch.transformValueForSearch)({
42
+ plugins: searchPlugins,
43
+ field: field.field,
44
+ value: initialValue
45
+ });
46
+ const keyword = (0, _keyword.hasKeyword)(field);
47
+ const {
48
+ basePath,
49
+ path
50
+ } = createFieldPath({
51
+ field,
52
+ value,
53
+ key,
54
+ keyword
55
+ });
56
+ plugin.apply(query, {
57
+ name: field.field.fieldId,
58
+ basePath,
59
+ path,
60
+ value,
61
+ keyword
62
+ });
63
+ };
64
+ };
65
+
66
+ exports.createApplyFiltering = createApplyFiltering;