@webiny/api-headless-cms-ddb-es 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (411) hide show
  1. package/README.md +6 -30
  2. package/configurations.d.ts +13 -6
  3. package/configurations.js +28 -40
  4. package/configurations.js.map +1 -1
  5. package/definitions/entry.d.ts +4 -5
  6. package/definitions/entry.js +9 -88
  7. package/definitions/entry.js.map +1 -1
  8. package/definitions/group.d.ts +6 -6
  9. package/definitions/group.js +9 -68
  10. package/definitions/group.js.map +1 -1
  11. package/definitions/model.d.ts +6 -6
  12. package/definitions/model.js +9 -90
  13. package/definitions/model.js.map +1 -1
  14. package/definitions/types.d.ts +65 -0
  15. package/definitions/types.js +0 -0
  16. package/elasticsearch/createElasticsearchIndex.d.ts +5 -5
  17. package/elasticsearch/createElasticsearchIndex.js +53 -56
  18. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  19. package/elasticsearch/deleteElasticsearchIndex.d.ts +3 -3
  20. package/elasticsearch/deleteElasticsearchIndex.js +20 -40
  21. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  22. package/exports/api/cms/opensearch.d.ts +9 -0
  23. package/exports/api/cms/opensearch.js +9 -0
  24. package/feature.d.ts +1 -0
  25. package/feature.js +179 -0
  26. package/feature.js.map +1 -0
  27. package/features/CmsEntryOpenSearchBodyModifier/abstractions.d.ts +16 -0
  28. package/features/CmsEntryOpenSearchBodyModifier/abstractions.js +5 -0
  29. package/features/CmsEntryOpenSearchBodyModifier/abstractions.js.map +1 -0
  30. package/features/CmsEntryOpenSearchBodyModifier/index.d.ts +1 -0
  31. package/features/CmsEntryOpenSearchBodyModifier/index.js +1 -0
  32. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.d.ts +14 -0
  33. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js +42 -0
  34. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -0
  35. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.d.ts +32 -0
  36. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js +5 -0
  37. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js.map +1 -0
  38. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.d.ts +11 -0
  39. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js +5 -0
  40. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -0
  41. package/features/CmsEntryOpenSearchFieldIndex/constants.d.ts +1 -0
  42. package/features/CmsEntryOpenSearchFieldIndex/constants.js +4 -0
  43. package/features/CmsEntryOpenSearchFieldIndex/constants.js.map +1 -0
  44. package/features/CmsEntryOpenSearchFieldIndex/feature.d.ts +4 -0
  45. package/features/CmsEntryOpenSearchFieldIndex/feature.js +29 -0
  46. package/features/CmsEntryOpenSearchFieldIndex/feature.js.map +1 -0
  47. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.d.ts +11 -0
  48. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js +60 -0
  49. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js.map +1 -0
  50. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.d.ts +13 -0
  51. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js +33 -0
  52. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js.map +1 -0
  53. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.d.ts +10 -0
  54. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js +21 -0
  55. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js.map +1 -0
  56. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.d.ts +10 -0
  57. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js +22 -0
  58. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js.map +1 -0
  59. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.d.ts +11 -0
  60. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js +32 -0
  61. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js.map +1 -0
  62. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.d.ts +12 -0
  63. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js +107 -0
  64. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js.map +1 -0
  65. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.d.ts +10 -0
  66. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js +21 -0
  67. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js.map +1 -0
  68. package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.d.ts +15 -0
  69. package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js +40 -0
  70. package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js.map +1 -0
  71. package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.d.ts +15 -0
  72. package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js +40 -0
  73. package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js.map +1 -0
  74. package/features/CmsEntryOpenSearchFieldIndex/index.d.ts +3 -0
  75. package/features/CmsEntryOpenSearchFieldIndex/index.js +3 -0
  76. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.d.ts +11 -0
  77. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js +36 -0
  78. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js.map +1 -0
  79. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.d.ts +37 -0
  80. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js +5 -0
  81. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js.map +1 -0
  82. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.d.ts +9 -0
  83. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js +5 -0
  84. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js.map +1 -0
  85. package/features/CmsEntryOpenSearchFilter/constants.d.ts +1 -0
  86. package/features/CmsEntryOpenSearchFilter/constants.js +4 -0
  87. package/features/CmsEntryOpenSearchFilter/constants.js.map +1 -0
  88. package/features/CmsEntryOpenSearchFilter/feature.d.ts +4 -0
  89. package/features/CmsEntryOpenSearchFilter/feature.js +17 -0
  90. package/features/CmsEntryOpenSearchFilter/feature.js.map +1 -0
  91. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.d.ts +9 -0
  92. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js +26 -0
  93. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js.map +1 -0
  94. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.d.ts +9 -0
  95. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js +43 -0
  96. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js.map +1 -0
  97. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.d.ts +9 -0
  98. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js +36 -0
  99. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js.map +1 -0
  100. package/features/CmsEntryOpenSearchFilter/index.d.ts +3 -0
  101. package/features/CmsEntryOpenSearchFilter/index.js +3 -0
  102. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.d.ts +20 -0
  103. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js +5 -0
  104. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js.map +1 -0
  105. package/features/CmsEntryOpenSearchFullTextSearch/index.d.ts +1 -0
  106. package/features/CmsEntryOpenSearchFullTextSearch/index.js +1 -0
  107. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.d.ts +11 -0
  108. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js +17 -0
  109. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js.map +1 -0
  110. package/features/CmsEntryOpenSearchIndex/abstractions.d.ts +14 -0
  111. package/features/CmsEntryOpenSearchIndex/abstractions.js +5 -0
  112. package/features/CmsEntryOpenSearchIndex/abstractions.js.map +1 -0
  113. package/features/CmsEntryOpenSearchIndex/feature.d.ts +4 -0
  114. package/features/CmsEntryOpenSearchIndex/feature.js +11 -0
  115. package/features/CmsEntryOpenSearchIndex/feature.js.map +1 -0
  116. package/features/CmsEntryOpenSearchIndex/index.d.ts +3 -0
  117. package/features/CmsEntryOpenSearchIndex/index.js +3 -0
  118. package/features/CmsEntryOpenSearchQueryModifier/abstractions.d.ts +16 -0
  119. package/features/CmsEntryOpenSearchQueryModifier/abstractions.js +5 -0
  120. package/features/CmsEntryOpenSearchQueryModifier/abstractions.js.map +1 -0
  121. package/features/CmsEntryOpenSearchQueryModifier/index.d.ts +1 -0
  122. package/features/CmsEntryOpenSearchQueryModifier/index.js +1 -0
  123. package/features/CmsEntryOpenSearchSortModifier/abstractions.d.ts +15 -0
  124. package/features/CmsEntryOpenSearchSortModifier/abstractions.js +5 -0
  125. package/features/CmsEntryOpenSearchSortModifier/abstractions.js.map +1 -0
  126. package/features/CmsEntryOpenSearchSortModifier/index.d.ts +1 -0
  127. package/features/CmsEntryOpenSearchSortModifier/index.js +1 -0
  128. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.d.ts +12 -0
  129. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js +31 -0
  130. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -0
  131. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.d.ts +22 -0
  132. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js +5 -0
  133. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js.map +1 -0
  134. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.d.ts +10 -0
  135. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js +5 -0
  136. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -0
  137. package/features/CmsEntryOpenSearchValueSearch/feature.d.ts +4 -0
  138. package/features/CmsEntryOpenSearchValueSearch/feature.js +17 -0
  139. package/features/CmsEntryOpenSearchValueSearch/feature.js.map +1 -0
  140. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.d.ts +10 -0
  141. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js +21 -0
  142. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js.map +1 -0
  143. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.d.ts +10 -0
  144. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js +44 -0
  145. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js.map +1 -0
  146. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.d.ts +10 -0
  147. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js +22 -0
  148. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js.map +1 -0
  149. package/features/CmsEntryOpenSearchValueSearch/index.d.ts +3 -0
  150. package/features/CmsEntryOpenSearchValueSearch/index.js +3 -0
  151. package/features/CmsEntryOpenSearchValuesModifier/abstractions.d.ts +23 -0
  152. package/features/CmsEntryOpenSearchValuesModifier/abstractions.js +5 -0
  153. package/features/CmsEntryOpenSearchValuesModifier/abstractions.js.map +1 -0
  154. package/features/CmsEntryOpenSearchValuesModifier/index.d.ts +1 -0
  155. package/features/CmsEntryOpenSearchValuesModifier/index.js +1 -0
  156. package/helpers/entryIndexHelpers.d.ts +13 -11
  157. package/helpers/entryIndexHelpers.js +72 -196
  158. package/helpers/entryIndexHelpers.js.map +1 -1
  159. package/helpers/fieldIdentifier.d.ts +6 -0
  160. package/helpers/fieldIdentifier.js +23 -0
  161. package/helpers/fieldIdentifier.js.map +1 -0
  162. package/helpers/index.d.ts +2 -2
  163. package/helpers/index.js +2 -31
  164. package/index.d.ts +1 -3
  165. package/index.js +1 -268
  166. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  167. package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
  168. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  169. package/operations/entry/dataLoader/constants.d.ts +1 -0
  170. package/operations/entry/dataLoader/constants.js +5 -0
  171. package/operations/entry/dataLoader/constants.js.map +1 -0
  172. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  173. package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
  174. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  175. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  176. package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
  177. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  178. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  179. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +34 -0
  180. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  181. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  182. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +34 -0
  183. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  184. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  185. package/operations/entry/dataLoader/getRevisionById.js +40 -0
  186. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  187. package/operations/entry/dataLoader/index.d.ts +8 -0
  188. package/operations/entry/dataLoader/index.js +18 -0
  189. package/operations/entry/dataLoader/index.js.map +1 -0
  190. package/operations/entry/dataLoader/types.d.ts +6 -0
  191. package/operations/entry/dataLoader/types.js +0 -0
  192. package/operations/entry/dataLoaders.d.ts +17 -38
  193. package/operations/entry/dataLoaders.js +82 -357
  194. package/operations/entry/dataLoaders.js.map +1 -1
  195. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  196. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +9 -0
  197. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  198. package/operations/entry/elasticsearch/body.d.ts +29 -0
  199. package/operations/entry/elasticsearch/body.js +87 -0
  200. package/operations/entry/elasticsearch/body.js.map +1 -0
  201. package/operations/entry/elasticsearch/fields/createSystemField.d.ts +4 -0
  202. package/operations/entry/elasticsearch/fields/createSystemField.js +9 -0
  203. package/operations/entry/elasticsearch/fields/createSystemField.js.map +1 -0
  204. package/operations/entry/elasticsearch/fields/live.d.ts +2 -0
  205. package/operations/entry/elasticsearch/fields/live.js +50 -0
  206. package/operations/entry/elasticsearch/fields/live.js.map +1 -0
  207. package/operations/entry/elasticsearch/fields/location.d.ts +2 -0
  208. package/operations/entry/elasticsearch/fields/location.js +50 -0
  209. package/operations/entry/elasticsearch/fields/location.js.map +1 -0
  210. package/operations/entry/elasticsearch/fields/state.d.ts +2 -0
  211. package/operations/entry/elasticsearch/fields/state.js +104 -0
  212. package/operations/entry/elasticsearch/fields/state.js.map +1 -0
  213. package/operations/entry/elasticsearch/fields.d.ts +12 -0
  214. package/operations/entry/elasticsearch/fields.js +207 -0
  215. package/operations/entry/elasticsearch/fields.js.map +1 -0
  216. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +9 -0
  217. package/operations/entry/elasticsearch/filtering/applyFiltering.js +39 -0
  218. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
  219. package/operations/entry/elasticsearch/filtering/exec.d.ts +22 -0
  220. package/operations/entry/elasticsearch/filtering/exec.js +96 -0
  221. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
  222. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
  223. package/operations/entry/elasticsearch/filtering/index.js +1 -0
  224. package/operations/entry/elasticsearch/filtering/path.d.ts +17 -0
  225. package/operations/entry/elasticsearch/filtering/path.js +27 -0
  226. package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
  227. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
  228. package/operations/entry/elasticsearch/filtering/populated.js +12 -0
  229. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
  230. package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
  231. package/operations/entry/elasticsearch/filtering/values.js +15 -0
  232. package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
  233. package/operations/entry/elasticsearch/fullTextSearch.d.ts +13 -0
  234. package/operations/entry/elasticsearch/fullTextSearch.js +51 -0
  235. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
  236. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
  237. package/operations/entry/elasticsearch/fullTextSearchFields.js +10 -0
  238. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
  239. package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
  240. package/operations/entry/elasticsearch/initialQuery.js +45 -0
  241. package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
  242. package/operations/entry/elasticsearch/keyword.d.ts +2 -0
  243. package/operations/entry/elasticsearch/keyword.js +17 -0
  244. package/operations/entry/elasticsearch/keyword.js.map +1 -0
  245. package/operations/entry/elasticsearch/plugins/operator.d.ts +7 -0
  246. package/operations/entry/elasticsearch/plugins/operator.js +13 -0
  247. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
  248. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.d.ts +2 -0
  249. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +8 -0
  250. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -0
  251. package/operations/entry/elasticsearch/sort.d.ts +12 -0
  252. package/operations/entry/elasticsearch/sort.js +80 -0
  253. package/operations/entry/elasticsearch/sort.js.map +1 -0
  254. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +9 -0
  255. package/operations/entry/elasticsearch/transformValueForSearch.js +12 -0
  256. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
  257. package/operations/entry/elasticsearch/types.d.ts +34 -0
  258. package/operations/entry/elasticsearch/types.js +0 -0
  259. package/operations/entry/index.d.ts +27 -8
  260. package/operations/entry/index.js +1344 -1245
  261. package/operations/entry/index.js.map +1 -1
  262. package/operations/entry/keys.d.ts +31 -1
  263. package/operations/entry/keys.js +45 -35
  264. package/operations/entry/keys.js.map +1 -1
  265. package/operations/entry/recordType.d.ts +3 -0
  266. package/operations/entry/recordType.js +6 -0
  267. package/operations/entry/recordType.js.map +1 -0
  268. package/operations/entry/transformations/convertEntryKeys.d.ts +8 -0
  269. package/operations/entry/transformations/convertEntryKeys.js +25 -0
  270. package/operations/entry/transformations/convertEntryKeys.js.map +1 -0
  271. package/operations/entry/transformations/index.d.ts +33 -0
  272. package/operations/entry/transformations/index.js +91 -0
  273. package/operations/entry/transformations/index.js.map +1 -0
  274. package/operations/entry/transformations/modifyEntryValues.d.ts +53 -0
  275. package/operations/entry/transformations/modifyEntryValues.js +16 -0
  276. package/operations/entry/transformations/modifyEntryValues.js.map +1 -0
  277. package/operations/entry/transformations/transformEntryKeys.d.ts +11 -0
  278. package/operations/entry/transformations/transformEntryKeys.js +17 -0
  279. package/operations/entry/transformations/transformEntryKeys.js.map +1 -0
  280. package/operations/entry/transformations/transformEntryToIndex.d.ts +10 -0
  281. package/operations/entry/transformations/transformEntryToIndex.js +20 -0
  282. package/operations/entry/transformations/transformEntryToIndex.js.map +1 -0
  283. package/operations/group/index.d.ts +7 -6
  284. package/operations/group/index.js +116 -190
  285. package/operations/group/index.js.map +1 -1
  286. package/operations/model/index.d.ts +4 -4
  287. package/operations/model/index.js +130 -199
  288. package/operations/model/index.js.map +1 -1
  289. package/package.json +44 -41
  290. package/tasks/createIndexTaskPlugin.d.ts +2 -0
  291. package/tasks/createIndexTaskPlugin.js +45 -0
  292. package/tasks/createIndexTaskPlugin.js.map +1 -0
  293. package/types.d.ts +34 -137
  294. package/types.js +10 -47
  295. package/types.js.map +1 -1
  296. package/values/NoValueContainer.d.ts +5 -0
  297. package/values/NoValueContainer.js +11 -0
  298. package/values/NoValueContainer.js.map +1 -0
  299. package/definitions/entryElasticsearch.d.ts +0 -8
  300. package/definitions/entryElasticsearch.js +0 -42
  301. package/definitions/entryElasticsearch.js.map +0 -1
  302. package/definitions/settings.d.ts +0 -8
  303. package/definitions/settings.js +0 -58
  304. package/definitions/settings.js.map +0 -1
  305. package/definitions/system.d.ts +0 -8
  306. package/definitions/system.js +0 -46
  307. package/definitions/system.js.map +0 -1
  308. package/definitions/table.d.ts +0 -8
  309. package/definitions/table.js +0 -24
  310. package/definitions/table.js.map +0 -1
  311. package/definitions/tableElasticsearch.d.ts +0 -8
  312. package/definitions/tableElasticsearch.js +0 -24
  313. package/definitions/tableElasticsearch.js.map +0 -1
  314. package/dynamoDb/index.d.ts +0 -2
  315. package/dynamoDb/index.js +0 -16
  316. package/dynamoDb/index.js.map +0 -1
  317. package/dynamoDb/storage/date.d.ts +0 -2
  318. package/dynamoDb/storage/date.js +0 -99
  319. package/dynamoDb/storage/date.js.map +0 -1
  320. package/dynamoDb/storage/longText.d.ts +0 -10
  321. package/dynamoDb/storage/longText.js +0 -101
  322. package/dynamoDb/storage/longText.js.map +0 -1
  323. package/dynamoDb/storage/richText.d.ts +0 -7
  324. package/dynamoDb/storage/richText.js +0 -128
  325. package/dynamoDb/storage/richText.js.map +0 -1
  326. package/elasticsearch/index.d.ts +0 -2
  327. package/elasticsearch/index.js +0 -16
  328. package/elasticsearch/index.js.map +0 -1
  329. package/elasticsearch/indexing/dateTimeIndexing.d.ts +0 -3
  330. package/elasticsearch/indexing/dateTimeIndexing.js +0 -103
  331. package/elasticsearch/indexing/dateTimeIndexing.js.map +0 -1
  332. package/elasticsearch/indexing/defaultFieldIndexing.d.ts +0 -3
  333. package/elasticsearch/indexing/defaultFieldIndexing.js +0 -47
  334. package/elasticsearch/indexing/defaultFieldIndexing.js.map +0 -1
  335. package/elasticsearch/indexing/index.d.ts +0 -2
  336. package/elasticsearch/indexing/index.js +0 -24
  337. package/elasticsearch/indexing/index.js.map +0 -1
  338. package/elasticsearch/indexing/longTextIndexing.d.ts +0 -3
  339. package/elasticsearch/indexing/longTextIndexing.js +0 -36
  340. package/elasticsearch/indexing/longTextIndexing.js.map +0 -1
  341. package/elasticsearch/indexing/numberIndexing.d.ts +0 -3
  342. package/elasticsearch/indexing/numberIndexing.js +0 -48
  343. package/elasticsearch/indexing/numberIndexing.js.map +0 -1
  344. package/elasticsearch/indexing/objectIndexing.d.ts +0 -12
  345. package/elasticsearch/indexing/objectIndexing.js +0 -223
  346. package/elasticsearch/indexing/objectIndexing.js.map +0 -1
  347. package/elasticsearch/indexing/richTextIndexing.d.ts +0 -3
  348. package/elasticsearch/indexing/richTextIndexing.js +0 -34
  349. package/elasticsearch/indexing/richTextIndexing.js.map +0 -1
  350. package/elasticsearch/indices/base.d.ts +0 -2
  351. package/elasticsearch/indices/base.js +0 -15
  352. package/elasticsearch/indices/base.js.map +0 -1
  353. package/elasticsearch/indices/index.d.ts +0 -1
  354. package/elasticsearch/indices/index.js +0 -16
  355. package/elasticsearch/indices/index.js.map +0 -1
  356. package/elasticsearch/indices/japanese.d.ts +0 -2
  357. package/elasticsearch/indices/japanese.js +0 -16
  358. package/elasticsearch/indices/japanese.js.map +0 -1
  359. package/elasticsearch/search/index.d.ts +0 -3
  360. package/elasticsearch/search/index.js +0 -14
  361. package/elasticsearch/search/index.js.map +0 -1
  362. package/elasticsearch/search/refSearch.d.ts +0 -2
  363. package/elasticsearch/search/refSearch.js +0 -33
  364. package/elasticsearch/search/refSearch.js.map +0 -1
  365. package/elasticsearch/search/timeSearch.d.ts +0 -2
  366. package/elasticsearch/search/timeSearch.js +0 -33
  367. package/elasticsearch/search/timeSearch.js.map +0 -1
  368. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  369. package/helpers/createElasticsearchQueryBody.js +0 -611
  370. package/helpers/createElasticsearchQueryBody.js.map +0 -1
  371. package/helpers/fields.d.ts +0 -19
  372. package/helpers/fields.js +0 -205
  373. package/helpers/fields.js.map +0 -1
  374. package/helpers/index.js.map +0 -1
  375. package/helpers/searchPluginsList.d.ts +0 -6
  376. package/helpers/searchPluginsList.js +0 -26
  377. package/helpers/searchPluginsList.js.map +0 -1
  378. package/helpers/transformValueForSearch.d.ts +0 -12
  379. package/helpers/transformValueForSearch.js +0 -29
  380. package/helpers/transformValueForSearch.js.map +0 -1
  381. package/index.js.map +0 -1
  382. package/operations/entry/elasticsearchFields.d.ts +0 -2
  383. package/operations/entry/elasticsearchFields.js +0 -38
  384. package/operations/entry/elasticsearchFields.js.map +0 -1
  385. package/operations/settings/index.d.ts +0 -6
  386. package/operations/settings/index.js +0 -135
  387. package/operations/settings/index.js.map +0 -1
  388. package/operations/system/index.d.ts +0 -6
  389. package/operations/system/index.js +0 -99
  390. package/operations/system/index.js.map +0 -1
  391. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +0 -20
  392. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +0 -24
  393. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +0 -1
  394. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +0 -12
  395. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -24
  396. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
  397. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +0 -4
  398. package/plugins/CmsEntryElasticsearchIndexPlugin.js +0 -17
  399. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +0 -1
  400. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +0 -30
  401. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +0 -43
  402. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +0 -1
  403. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +0 -17
  404. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +0 -24
  405. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +0 -1
  406. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +0 -17
  407. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +0 -24
  408. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +0 -1
  409. package/plugins/index.d.ts +0 -6
  410. package/plugins/index.js +0 -83
  411. package/plugins/index.js.map +0 -1
@@ -1,1266 +1,1365 @@
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.createPublishedType = exports.createLatestType = exports.createEntriesStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
- var _types = require("@webiny/api-headless-cms/types");
13
-
14
- var _helpers = require("../../helpers");
15
-
16
- var _configurations = require("../../configurations");
17
-
18
- var _error = _interopRequireDefault(require("@webiny/error"));
19
-
20
- var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
21
-
22
- var _omit = _interopRequireDefault(require("lodash/omit"));
23
-
24
- var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
25
-
26
- var _dataLoaders = require("./dataLoaders");
27
-
28
- var _keys = require("./keys");
29
-
30
- var _query = require("@webiny/db-dynamodb/utils/query");
31
-
32
- var _apiElasticsearch = require("@webiny/api-elasticsearch");
33
-
34
- var _get = require("@webiny/db-dynamodb/utils/get");
35
-
36
- var _utils = require("@webiny/utils");
37
-
38
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
39
-
40
- const createType = () => {
41
- return "cms.entry";
42
- };
43
-
44
- const createLatestType = () => {
45
- return `${createType()}.l`;
46
- };
47
-
48
- exports.createLatestType = createLatestType;
49
-
50
- const createPublishedType = () => {
51
- return `${createType()}.p`;
52
- };
53
-
54
- exports.createPublishedType = createPublishedType;
55
-
56
- const getEntryData = entry => {
57
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _omit.default)(entry, ["PK", "SK", "published", "latest"])), {}, {
58
- TYPE: createType(),
59
- __type: createType()
60
- });
61
- };
62
-
63
- const getESLatestEntryData = async (plugins, entry) => {
64
- return (0, _apiElasticsearch.compress)(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getEntryData(entry)), {}, {
65
- latest: true,
66
- TYPE: createLatestType(),
67
- __type: createLatestType()
68
- }));
69
- };
70
-
71
- const getESPublishedEntryData = async (plugins, entry) => {
72
- return (0, _apiElasticsearch.compress)(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getEntryData(entry)), {}, {
73
- published: true,
74
- TYPE: createPublishedType(),
75
- __type: createPublishedType()
76
- }));
77
- };
78
-
79
- const convertToStorageEntry = params => {
80
- const {
81
- model,
82
- entry
83
- } = params;
84
- const values = model.convertValueKeyToStorage({
85
- fields: model.fields,
86
- values: entry.values
87
- });
88
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
89
- values
90
- });
91
- };
92
-
93
- const convertFromStorageEntry = params => {
94
- const {
95
- model,
96
- entry
97
- } = params;
98
- const values = model.convertValueKeyFromStorage({
99
- fields: model.fields,
100
- values: entry.values
101
- });
102
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
103
- values
104
- });
105
- };
106
-
107
- const createEntriesStorageOperations = params => {
108
- const {
109
- entity,
110
- esEntity,
111
- elasticsearch,
112
- plugins
113
- } = params;
114
- const dataLoaders = new _dataLoaders.DataLoadersHandler({
115
- entity
116
- });
117
-
118
- const create = async (model, params) => {
119
- const {
120
- entry: initialEntry,
121
- storageEntry: initialStorageEntry
122
- } = params;
123
- const isPublished = initialEntry.status === "published";
124
- const locked = isPublished ? true : initialEntry.locked;
125
- const entry = convertToStorageEntry({
126
- model,
127
- entry: initialEntry
128
- });
129
- const storageEntry = convertToStorageEntry({
130
- model,
131
- entry: initialStorageEntry
1
+ import { WebinyError } from "@webiny/error";
2
+ import { CONTENT_ENTRY_STATUS } from "@webiny/api-headless-cms/types/index.js";
3
+ import { extractEntriesFromIndex } from "../../helpers/index.js";
4
+ import { configurations } from "../../configurations.js";
5
+ import { createLimit, decodeCursor, encodeCursor } from "@webiny/api-opensearch";
6
+ import { DataLoadersHandler } from "./dataLoaders.js";
7
+ import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys, createLatestSortKey, createPartitionKey, createPublishedSortKey, createRevisionSortKey } from "./keys.js";
8
+ import { getTotalCount } from "@webiny/api-opensearch/types.js";
9
+ import { createElasticsearchBody } from "./elasticsearch/body.js";
10
+ import { shouldIgnoreEsResponseError } from "./elasticsearch/shouldIgnoreEsResponseError.js";
11
+ import { StorageOperationsCmsModelPlugin } from "@webiny/api-headless-cms";
12
+ import { createTransformer } from "./transformations/index.js";
13
+ import { convertEntryKeysFromStorage } from "./transformations/convertEntryKeys.js";
14
+ import { isDeletedEntryMetaField, isEntryLevelEntryMetaField, isRestoredEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
15
+ const convertToStorageEntry = (params)=>{
16
+ const { model, storageEntry } = params;
17
+ const values = model.convertValueKeyToStorage({
18
+ fields: model.fields,
19
+ values: storageEntry.values
132
20
  });
133
- const esEntry = (0, _helpers.prepareEntryToIndex)({
134
- plugins,
135
- model,
136
- entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
137
- locked
138
- })),
139
- storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
140
- locked
141
- }))
142
- });
143
-
144
- const {
145
- index: esIndex
146
- } = _configurations.configurations.es({
147
- model
148
- });
149
-
150
- const esLatestData = await getESLatestEntryData(plugins, esEntry);
151
- const esPublishedData = await getESPublishedEntryData(plugins, esEntry);
152
- const revisionKeys = {
153
- PK: (0, _keys.createPartitionKey)({
154
- id: entry.id,
155
- locale: model.locale,
156
- tenant: model.tenant
157
- }),
158
- SK: (0, _keys.createRevisionSortKey)(entry)
21
+ return {
22
+ ...storageEntry,
23
+ values
159
24
  };
160
- const latestKeys = {
161
- PK: (0, _keys.createPartitionKey)({
162
- id: entry.id,
163
- locale: model.locale,
164
- tenant: model.tenant
165
- }),
166
- SK: (0, _keys.createLatestSortKey)()
25
+ };
26
+ const createEntriesStorageOperations = (params)=>{
27
+ const { entity, esEntity, elasticsearch, plugins, fieldRegistry, fieldIndexRegistry, compressionHandler, bodyModifiers, sortModifiers, queryModifiers, valueSearchRegistry, fullTextSearches, valuesModifiers, filterRegistry } = params;
28
+ let storageOperationsCmsModelPlugin;
29
+ const getStorageOperationsCmsModelPlugin = ()=>{
30
+ if (storageOperationsCmsModelPlugin) return storageOperationsCmsModelPlugin;
31
+ storageOperationsCmsModelPlugin = plugins.oneByType(StorageOperationsCmsModelPlugin.type);
32
+ return storageOperationsCmsModelPlugin;
167
33
  };
168
- const publishedKeys = {
169
- PK: (0, _keys.createPartitionKey)({
170
- id: entry.id,
171
- locale: model.locale,
172
- tenant: model.tenant
173
- }),
174
- SK: (0, _keys.createPublishedSortKey)()
34
+ const getStorageOperationsModel = (model)=>{
35
+ const plugin = getStorageOperationsCmsModelPlugin();
36
+ return plugin.getModel(model);
175
37
  };
176
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
177
- locked
178
- }, revisionKeys), {}, {
179
- TYPE: createType()
180
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
181
- locked
182
- }, latestKeys), {}, {
183
- TYPE: createLatestType()
184
- }))];
185
-
186
- if (isPublished) {
187
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
188
- locked
189
- }, publishedKeys), {}, {
190
- TYPE: createPublishedType()
191
- })));
192
- }
193
-
194
- try {
195
- await (0, _batchWrite.batchWriteAll)({
196
- table: entity.table,
197
- items
198
- });
199
- dataLoaders.clearAll({
200
- model
201
- });
202
- } catch (ex) {
203
- throw new _error.default(ex.message || "Could not insert entry data into the DynamoDB table.", ex.code || "CREATE_ENTRY_ERROR", {
204
- error: ex,
205
- entry,
206
- storageEntry
207
- });
208
- }
209
-
210
- const esItems = [esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
211
- index: esIndex,
212
- data: esLatestData
213
- }))];
214
-
215
- if (isPublished) {
216
- esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
217
- index: esIndex,
218
- data: esPublishedData
219
- })));
220
- }
221
-
222
- try {
223
- await (0, _batchWrite.batchWriteAll)({
224
- table: esEntity.table,
225
- items: esItems
226
- });
227
- } catch (ex) {
228
- throw new _error.default(ex.message || "Could not insert entry data into the Elasticsearch DynamoDB table.", ex.code || "CREATE_ES_ENTRY_ERROR", {
229
- error: ex,
230
- entry,
231
- esEntry
232
- });
233
- }
234
-
235
- return initialStorageEntry;
236
- };
237
-
238
- const createRevisionFrom = async (model, params) => {
239
- const {
240
- entry: initialEntry,
241
- storageEntry: initialStorageEntry
242
- } = params;
243
- const entry = convertToStorageEntry({
244
- model,
245
- entry: initialEntry
246
- });
247
- const storageEntry = convertToStorageEntry({
248
- model,
249
- entry: initialStorageEntry
38
+ const dataLoaders = new DataLoadersHandler({
39
+ entity
250
40
  });
251
- const revisionKeys = {
252
- PK: (0, _keys.createPartitionKey)({
253
- id: entry.id,
254
- locale: model.locale,
255
- tenant: model.tenant
256
- }),
257
- SK: (0, _keys.createRevisionSortKey)(entry)
41
+ const create = async (initialModel, params)=>{
42
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
43
+ const model = getStorageOperationsModel(initialModel);
44
+ const isPublished = "published" === initialEntry.status;
45
+ const locked = isPublished ? true : initialEntry.locked;
46
+ initialEntry.locked = locked;
47
+ initialStorageEntry.locked = locked;
48
+ const transformer = createTransformer({
49
+ fieldIndexRegistry,
50
+ model,
51
+ entry: initialEntry,
52
+ storageEntry: initialStorageEntry,
53
+ compressionHandler,
54
+ valuesModifiers
55
+ });
56
+ const { entry, storageEntry } = transformer.transformEntryKeys();
57
+ const esEntry = transformer.transformToIndex();
58
+ const { index: esIndex } = configurations.es({
59
+ model
60
+ });
61
+ const revisionKeys = createEntryRevisionKeys(entry);
62
+ const latestKeys = createEntryLatestKeys(entry);
63
+ const publishedKeys = createEntryPublishedKeys(entry);
64
+ const entityBatch = entity.createEntityWriter({
65
+ put: [
66
+ {
67
+ ...revisionKeys,
68
+ data: {
69
+ ...storageEntry,
70
+ locked
71
+ }
72
+ },
73
+ {
74
+ ...latestKeys,
75
+ data: {
76
+ ...storageEntry,
77
+ locked
78
+ }
79
+ }
80
+ ]
81
+ });
82
+ if (isPublished) entityBatch.put({
83
+ ...publishedKeys,
84
+ data: {
85
+ ...storageEntry,
86
+ locked
87
+ }
88
+ });
89
+ try {
90
+ await entityBatch.execute();
91
+ dataLoaders.clearAll({
92
+ model
93
+ });
94
+ } catch (ex) {
95
+ throw new WebinyError(ex.message || "Could not insert entry data into the DynamoDB table.", ex.code || "CREATE_ENTRY_ERROR", {
96
+ error: ex,
97
+ entry,
98
+ storageEntry
99
+ });
100
+ }
101
+ const esLatestData = await transformer.getElasticsearchLatestEntryData();
102
+ const elasticsearchEntityBatch = esEntity.createEntityWriter({
103
+ put: [
104
+ {
105
+ ...latestKeys,
106
+ index: esIndex,
107
+ data: esLatestData
108
+ }
109
+ ]
110
+ });
111
+ if (isPublished) {
112
+ const esPublishedData = await transformer.getElasticsearchPublishedEntryData();
113
+ elasticsearchEntityBatch.put({
114
+ ...publishedKeys,
115
+ index: esIndex,
116
+ data: esPublishedData
117
+ });
118
+ }
119
+ try {
120
+ await elasticsearchEntityBatch.execute();
121
+ } catch (ex) {
122
+ throw new WebinyError(ex.message || "Could not insert entry data into the Elasticsearch DynamoDB table.", ex.code || "CREATE_ES_ENTRY_ERROR", {
123
+ error: ex,
124
+ entry,
125
+ esEntry
126
+ });
127
+ }
128
+ return initialStorageEntry;
258
129
  };
259
- const latestKeys = {
260
- PK: (0, _keys.createPartitionKey)({
261
- id: entry.id,
262
- locale: model.locale,
263
- tenant: model.tenant
264
- }),
265
- SK: (0, _keys.createLatestSortKey)()
130
+ const createRevisionFrom = async (initialModel, params)=>{
131
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
132
+ const model = getStorageOperationsModel(initialModel);
133
+ const transformer = createTransformer({
134
+ model,
135
+ entry: initialEntry,
136
+ storageEntry: initialStorageEntry,
137
+ fieldIndexRegistry,
138
+ compressionHandler,
139
+ valuesModifiers
140
+ });
141
+ const { entry, storageEntry } = transformer.transformEntryKeys();
142
+ const revisionKeys = createEntryRevisionKeys(entry);
143
+ const latestKeys = createEntryLatestKeys(entry);
144
+ const publishedKeys = createEntryPublishedKeys(entry);
145
+ const isPublished = "published" === entry.status;
146
+ const esLatestData = await transformer.getElasticsearchLatestEntryData();
147
+ const entityBatch = entity.createEntityWriter({
148
+ put: [
149
+ {
150
+ ...revisionKeys,
151
+ data: storageEntry
152
+ },
153
+ {
154
+ ...latestKeys,
155
+ data: storageEntry
156
+ }
157
+ ]
158
+ });
159
+ if (isPublished) {
160
+ entityBatch.put({
161
+ ...publishedKeys,
162
+ data: storageEntry
163
+ });
164
+ const [publishedRevisionStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
165
+ model,
166
+ ids: [
167
+ entry.id
168
+ ]
169
+ });
170
+ if (publishedRevisionStorageEntry) {
171
+ const publishedRevisionKey = createEntryRevisionKeys(publishedRevisionStorageEntry);
172
+ entityBatch.put({
173
+ ...publishedRevisionKey,
174
+ data: {
175
+ ...publishedRevisionStorageEntry,
176
+ status: CONTENT_ENTRY_STATUS.UNPUBLISHED
177
+ }
178
+ });
179
+ }
180
+ }
181
+ try {
182
+ await entityBatch.execute();
183
+ dataLoaders.clearAll({
184
+ model
185
+ });
186
+ } catch (ex) {
187
+ throw new WebinyError(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
188
+ error: ex,
189
+ entry,
190
+ storageEntry
191
+ });
192
+ }
193
+ const { index: esIndex } = configurations.es({
194
+ model
195
+ });
196
+ const elasticsearchEntityBatch = esEntity.createEntityWriter({
197
+ put: [
198
+ {
199
+ ...latestKeys,
200
+ index: esIndex,
201
+ data: esLatestData
202
+ }
203
+ ]
204
+ });
205
+ if (isPublished) {
206
+ const esPublishedData = await transformer.getElasticsearchPublishedEntryData();
207
+ elasticsearchEntityBatch.put({
208
+ ...publishedKeys,
209
+ index: esIndex,
210
+ data: esPublishedData
211
+ });
212
+ }
213
+ try {
214
+ await elasticsearchEntityBatch.execute();
215
+ } catch (ex) {
216
+ throw new WebinyError(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
217
+ error: ex,
218
+ entry
219
+ });
220
+ }
221
+ return initialStorageEntry;
266
222
  };
267
- const esEntry = (0, _helpers.prepareEntryToIndex)({
268
- plugins,
269
- model,
270
- entry: (0, _cloneDeep.default)(entry),
271
- storageEntry: (0, _cloneDeep.default)(storageEntry)
272
- });
273
- const esLatestData = await getESLatestEntryData(plugins, esEntry);
274
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
275
- TYPE: createType()
276
- }, revisionKeys)), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
277
- TYPE: createLatestType()
278
- }, latestKeys))];
279
-
280
- const {
281
- index
282
- } = _configurations.configurations.es({
283
- model
284
- });
285
-
286
- try {
287
- await (0, _batchWrite.batchWriteAll)({
288
- table: entity.table,
289
- items
290
- });
291
- dataLoaders.clearAll({
292
- model
293
- });
294
- } catch (ex) {
295
- throw new _error.default(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
296
- error: ex,
297
- entry,
298
- storageEntry
299
- });
300
- }
301
- /**
302
- * Update the "latest" entry item in the Elasticsearch
303
- */
304
-
305
-
306
- try {
307
- await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
308
- index,
309
- data: esLatestData
310
- }));
311
- } catch (ex) {
312
- throw new _error.default(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
313
- error: ex,
314
- entry
315
- });
316
- }
317
- /**
318
- * There are no modifications on the entry created so just return the data.
319
- */
320
-
321
-
322
- return initialStorageEntry;
323
- };
324
-
325
- const update = async (model, params) => {
326
- const {
327
- entry: initialEntry,
328
- storageEntry: initialStorageEntry
329
- } = params;
330
- const entry = convertToStorageEntry({
331
- model,
332
- entry: initialEntry
333
- });
334
- const storageEntry = convertToStorageEntry({
335
- model,
336
- entry: initialStorageEntry
337
- });
338
- const isPublished = entry.status === "published";
339
- const locked = isPublished ? true : entry.locked;
340
- const revisionKeys = {
341
- PK: (0, _keys.createPartitionKey)({
342
- id: entry.id,
343
- locale: model.locale,
344
- tenant: model.tenant
345
- }),
346
- SK: (0, _keys.createRevisionSortKey)(entry)
223
+ const update = async (initialModel, params)=>{
224
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
225
+ const model = getStorageOperationsModel(initialModel);
226
+ const transformer = createTransformer({
227
+ valuesModifiers,
228
+ model,
229
+ entry: initialEntry,
230
+ storageEntry: initialStorageEntry,
231
+ fieldIndexRegistry,
232
+ compressionHandler
233
+ });
234
+ const { entry, storageEntry } = transformer.transformEntryKeys();
235
+ const isPublished = "published" === entry.status;
236
+ const locked = isPublished ? true : entry.locked;
237
+ const revisionKeys = createEntryRevisionKeys(entry);
238
+ const latestKeys = createEntryLatestKeys(entry);
239
+ const publishedKeys = createEntryPublishedKeys(entry);
240
+ const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
241
+ model,
242
+ ids: [
243
+ entry.id
244
+ ]
245
+ });
246
+ const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
247
+ model,
248
+ ids: [
249
+ entry.id
250
+ ]
251
+ });
252
+ const entityBatch = entity.createEntityWriter({
253
+ put: [
254
+ {
255
+ ...revisionKeys,
256
+ data: {
257
+ ...storageEntry,
258
+ locked
259
+ }
260
+ }
261
+ ]
262
+ });
263
+ if (isPublished) entityBatch.put({
264
+ ...publishedKeys,
265
+ data: {
266
+ ...storageEntry,
267
+ locked
268
+ }
269
+ });
270
+ const elasticsearchEntityBatch = esEntity.createEntityWriter();
271
+ const { index: esIndex } = configurations.es({
272
+ model
273
+ });
274
+ if (latestStorageEntry) {
275
+ const updatingLatestRevision = latestStorageEntry.id === entry.id;
276
+ if (updatingLatestRevision) {
277
+ entityBatch.put({
278
+ ...latestKeys,
279
+ data: storageEntry
280
+ });
281
+ const elasticsearchLatestData = await transformer.getElasticsearchLatestEntryData();
282
+ elasticsearchEntityBatch.put({
283
+ ...latestKeys,
284
+ index: esIndex,
285
+ data: elasticsearchLatestData
286
+ });
287
+ } else {
288
+ const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
289
+ const updatedLatestStorageEntry = {
290
+ ...latestKeys,
291
+ data: {
292
+ ...latestStorageEntry,
293
+ ...updatedEntryLevelMetaFields
294
+ }
295
+ };
296
+ entityBatch.put({
297
+ ...updatedLatestStorageEntry,
298
+ PK: createPartitionKey({
299
+ id: latestStorageEntry.id,
300
+ tenant: model.tenant
301
+ }),
302
+ SK: createRevisionSortKey(latestStorageEntry)
303
+ });
304
+ entityBatch.put({
305
+ ...updatedLatestStorageEntry
306
+ });
307
+ const latestEsEntry = await esEntity.getClean(latestKeys);
308
+ if (latestEsEntry) {
309
+ const latestEsEntryDataDecompressed = await compressionHandler.decompress(latestEsEntry.data);
310
+ const updatedLatestEntry = await compressionHandler.compress({
311
+ ...latestEsEntryDataDecompressed,
312
+ ...updatedEntryLevelMetaFields
313
+ });
314
+ elasticsearchEntityBatch.put({
315
+ ...latestKeys,
316
+ index: esIndex,
317
+ data: updatedLatestEntry
318
+ });
319
+ }
320
+ }
321
+ }
322
+ if (isPublished && publishedStorageEntry?.id === entry.id) {
323
+ const elasticsearchPublishedData = await transformer.getElasticsearchPublishedEntryData();
324
+ elasticsearchEntityBatch.put({
325
+ ...publishedKeys,
326
+ index: esIndex,
327
+ data: elasticsearchPublishedData
328
+ });
329
+ }
330
+ try {
331
+ await entityBatch.execute();
332
+ dataLoaders.clearAll({
333
+ model
334
+ });
335
+ } catch (ex) {
336
+ throw new WebinyError(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
337
+ error: ex,
338
+ entry,
339
+ storageEntry
340
+ });
341
+ }
342
+ try {
343
+ await elasticsearchEntityBatch.execute();
344
+ } catch (ex) {
345
+ throw new WebinyError(ex.message || "Could not update entry DynamoDB Elasticsearch records.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
346
+ error: ex,
347
+ entry
348
+ });
349
+ }
350
+ return initialStorageEntry;
347
351
  };
348
- const latestKeys = {
349
- PK: (0, _keys.createPartitionKey)({
350
- id: entry.id,
351
- locale: model.locale,
352
- tenant: model.tenant
353
- }),
354
- SK: (0, _keys.createLatestSortKey)()
352
+ const move = async (initialModel, id, folderId)=>{
353
+ const model = getStorageOperationsModel(initialModel);
354
+ const partitionKey = createPartitionKey({
355
+ id,
356
+ tenant: model.tenant
357
+ });
358
+ const queryAllParams = {
359
+ partitionKey,
360
+ options: {
361
+ gte: " "
362
+ }
363
+ };
364
+ const latestSortKey = createLatestSortKey();
365
+ const publishedSortKey = createPublishedSortKey();
366
+ const records = await entity.queryAll(queryAllParams);
367
+ let latestRecord;
368
+ let publishedRecord;
369
+ const entityBatch = entity.createEntityWriter();
370
+ for (const record of records){
371
+ entityBatch.put({
372
+ ...record,
373
+ data: {
374
+ ...record.data,
375
+ location: {
376
+ ...record.data.location,
377
+ folderId
378
+ }
379
+ }
380
+ });
381
+ if (record.SK === publishedSortKey) publishedRecord = record.data;
382
+ else if (record.SK === latestSortKey) latestRecord = record.data;
383
+ }
384
+ try {
385
+ await entityBatch.execute();
386
+ dataLoaders.clearAll({
387
+ model
388
+ });
389
+ } catch (ex) {
390
+ throw new WebinyError(ex.message || "Could not move all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_ERROR", {
391
+ error: ex,
392
+ id
393
+ });
394
+ }
395
+ const esEntityReader = esEntity.createEntityReader();
396
+ if (publishedRecord) esEntityReader.get({
397
+ PK: partitionKey,
398
+ SK: publishedSortKey
399
+ });
400
+ if (latestRecord) esEntityReader.get({
401
+ PK: partitionKey,
402
+ SK: latestSortKey
403
+ });
404
+ if (0 === esEntityReader.total) return;
405
+ const esRecords = await esEntityReader.execute();
406
+ const esItems = (await Promise.all(esRecords.map(async (record)=>{
407
+ if (!record) return null;
408
+ return {
409
+ ...record,
410
+ data: await compressionHandler.decompress(record.data)
411
+ };
412
+ }))).filter((item)=>!!item);
413
+ if (0 === esItems.length) return;
414
+ try {
415
+ const elasticsearchEntityBatch = esEntity.createEntityWriter({
416
+ put: await Promise.all(esItems.map(async (item)=>({
417
+ ...item,
418
+ data: await compressionHandler.compress({
419
+ ...item.data,
420
+ location: {
421
+ ...item.data?.location,
422
+ folderId
423
+ }
424
+ })
425
+ })))
426
+ });
427
+ await elasticsearchEntityBatch.execute();
428
+ } catch (ex) {
429
+ throw new WebinyError(ex.message || "Could not move entry DynamoDB Elasticsearch records.", ex.code || "MOVE_ES_ENTRY_ERROR", {
430
+ error: ex,
431
+ partitionKey
432
+ });
433
+ }
355
434
  };
356
- const publishedKeys = {
357
- PK: (0, _keys.createPartitionKey)({
358
- id: entry.id,
359
- locale: model.locale,
360
- tenant: model.tenant
361
- }),
362
- SK: (0, _keys.createPublishedSortKey)()
435
+ const moveToBin = async (initialModel, params)=>{
436
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
437
+ const model = getStorageOperationsModel(initialModel);
438
+ const transformer = createTransformer({
439
+ valuesModifiers,
440
+ model,
441
+ entry: initialEntry,
442
+ storageEntry: initialStorageEntry,
443
+ fieldIndexRegistry,
444
+ compressionHandler
445
+ });
446
+ const { entry, storageEntry } = transformer.transformEntryKeys();
447
+ const partitionKey = createPartitionKey({
448
+ id: entry.id,
449
+ tenant: model.tenant
450
+ });
451
+ const queryAllParams = {
452
+ partitionKey,
453
+ options: {
454
+ gte: " "
455
+ }
456
+ };
457
+ const latestSortKey = createLatestSortKey();
458
+ const publishedSortKey = createPublishedSortKey();
459
+ const records = await entity.queryAll(queryAllParams);
460
+ const updatedEntryMetaFields = pickEntryMetaFields(entry, isDeletedEntryMetaField);
461
+ let latestRecord;
462
+ let publishedRecord;
463
+ const entityBatch = entity.createEntityWriter();
464
+ for (const record of records){
465
+ entityBatch.put({
466
+ ...record,
467
+ data: {
468
+ ...record.data,
469
+ ...updatedEntryMetaFields,
470
+ wbyDeleted: storageEntry.wbyDeleted,
471
+ location: storageEntry.location,
472
+ binOriginalFolderId: storageEntry.binOriginalFolderId
473
+ }
474
+ });
475
+ if (record.SK === publishedSortKey) publishedRecord = record.data;
476
+ else if (record.SK === latestSortKey) latestRecord = record.data;
477
+ }
478
+ try {
479
+ await entityBatch.execute();
480
+ dataLoaders.clearAll({
481
+ model
482
+ });
483
+ } catch (ex) {
484
+ throw new WebinyError(ex.message || "Could mark as deleted all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
485
+ error: ex,
486
+ entry,
487
+ storageEntry
488
+ });
489
+ }
490
+ const esEntityReader = esEntity.createEntityReader();
491
+ if (publishedRecord) esEntityReader.get({
492
+ PK: partitionKey,
493
+ SK: publishedSortKey
494
+ });
495
+ if (latestRecord) esEntityReader.get({
496
+ PK: partitionKey,
497
+ SK: latestSortKey
498
+ });
499
+ if (0 === esEntityReader.total) return;
500
+ const esRecords = await esEntityReader.execute();
501
+ const esItems = (await Promise.all(esRecords.map(async (record)=>{
502
+ if (!record) return null;
503
+ return {
504
+ ...record,
505
+ data: await compressionHandler.decompress(record.data)
506
+ };
507
+ }))).filter((item)=>!!item);
508
+ if (0 === esItems.length) return;
509
+ const elasticsearchEntityBatch = esEntity.createEntityWriter();
510
+ for (const item of esItems)elasticsearchEntityBatch.put({
511
+ ...item,
512
+ data: await compressionHandler.compress({
513
+ ...item.data,
514
+ ...updatedEntryMetaFields,
515
+ wbyDeleted: entry.wbyDeleted,
516
+ location: entry.location,
517
+ binOriginalFolderId: entry.binOriginalFolderId
518
+ })
519
+ });
520
+ try {
521
+ await elasticsearchEntityBatch.execute();
522
+ } catch (ex) {
523
+ throw new WebinyError(ex.message || "Could not mark as deleted entry records from DynamoDB Elasticsearch table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
524
+ error: ex,
525
+ entry,
526
+ storageEntry
527
+ });
528
+ }
363
529
  };
364
- /**
365
- * We need the latest entry to check if it needs to be updated.
366
- */
367
-
368
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
369
- model,
370
- ids: [entry.id]
371
- });
372
- const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
373
- model,
374
- ids: [entry.id]
375
- });
376
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
377
- locked
378
- }, revisionKeys), {}, {
379
- TYPE: createType()
380
- }))];
381
-
382
- if (isPublished) {
383
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
384
- locked
385
- }, publishedKeys), {}, {
386
- TYPE: createPublishedType()
387
- })));
388
- }
389
-
390
- const esItems = [];
391
-
392
- const {
393
- index: esIndex
394
- } = _configurations.configurations.es({
395
- model
396
- });
397
- /**
398
- * Variable for the elasticsearch entry so we do not convert it more than once
399
- */
400
-
401
-
402
- let esEntry = undefined;
403
- /**
404
- * If the latest entry is the one being updated, we need to create a new latest entry records.
405
- */
406
-
407
- let elasticsearchLatestData = null;
408
-
409
- if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
410
- /**
411
- * First we update the regular DynamoDB table
412
- */
413
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), latestKeys), {}, {
414
- TYPE: (0, _keys.createLatestSortKey)()
415
- })));
416
- /**
417
- * And then update the Elasticsearch table to propagate changes to the Elasticsearch
418
- */
419
-
420
- esEntry = (0, _helpers.prepareEntryToIndex)({
421
- plugins,
422
- model,
423
- entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
424
- locked
425
- })),
426
- storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
427
- locked
428
- }))
429
- });
430
- elasticsearchLatestData = await getESLatestEntryData(plugins, esEntry);
431
- esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
432
- index: esIndex,
433
- data: elasticsearchLatestData
434
- })));
435
- }
436
-
437
- let elasticsearchPublishedData = null;
438
-
439
- if (isPublished && (publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
440
- if (!elasticsearchLatestData) {
441
- /**
442
- * And then update the Elasticsearch table to propagate changes to the Elasticsearch
443
- */
444
- if (!esEntry) {
445
- esEntry = (0, _helpers.prepareEntryToIndex)({
446
- plugins,
530
+ const restoreFromBin = async (initialModel, params)=>{
531
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
532
+ const model = getStorageOperationsModel(initialModel);
533
+ const transformer = createTransformer({
534
+ valuesModifiers,
447
535
  model,
448
- entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
449
- locked
450
- })),
451
- storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
452
- locked
453
- }))
454
- });
536
+ entry: initialEntry,
537
+ storageEntry: initialStorageEntry,
538
+ fieldIndexRegistry,
539
+ compressionHandler
540
+ });
541
+ const { entry, storageEntry } = transformer.transformEntryKeys();
542
+ const updatedEntryMetaFields = pickEntryMetaFields(entry, isRestoredEntryMetaField);
543
+ const partitionKey = createPartitionKey({
544
+ id: entry.id,
545
+ tenant: model.tenant
546
+ });
547
+ const queryAllParams = {
548
+ partitionKey,
549
+ options: {
550
+ gte: " "
551
+ }
552
+ };
553
+ const latestSortKey = createLatestSortKey();
554
+ const publishedSortKey = createPublishedSortKey();
555
+ const records = await entity.queryAll(queryAllParams);
556
+ let latestRecord;
557
+ let publishedRecord;
558
+ const entityBatch = entity.createEntityWriter();
559
+ for (const record of records){
560
+ entityBatch.put({
561
+ ...record,
562
+ data: {
563
+ ...record.data,
564
+ ...updatedEntryMetaFields,
565
+ wbyDeleted: storageEntry.wbyDeleted,
566
+ location: storageEntry.location,
567
+ binOriginalFolderId: storageEntry.binOriginalFolderId
568
+ }
569
+ });
570
+ if (record.SK === publishedSortKey) publishedRecord = record.data;
571
+ else if (record.SK === latestSortKey) latestRecord = record.data;
455
572
  }
456
-
457
- elasticsearchPublishedData = await getESPublishedEntryData(plugins, esEntry);
458
- } else {
459
- elasticsearchPublishedData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, elasticsearchLatestData), {}, {
460
- published: true,
461
- TYPE: createPublishedType(),
462
- __type: createPublishedType()
463
- });
464
- delete elasticsearchPublishedData.latest;
465
- }
466
-
467
- esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
468
- index: esIndex,
469
- data: elasticsearchPublishedData
470
- })));
471
- }
472
-
473
- try {
474
- await (0, _batchWrite.batchWriteAll)({
475
- table: entity.table,
476
- items
477
- });
478
- dataLoaders.clearAll({
479
- model
480
- });
481
- } catch (ex) {
482
- throw new _error.default(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
483
- error: ex,
484
- entry,
485
- storageEntry
486
- });
487
- }
488
-
489
- if (esItems.length === 0) {
490
- return initialStorageEntry;
491
- }
492
-
493
- try {
494
- await (0, _batchWrite.batchWriteAll)({
495
- table: esEntity.table,
496
- items: esItems
497
- });
498
- } catch (ex) {
499
- throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch records.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
500
- error: ex,
501
- entry
502
- });
503
- }
504
-
505
- return initialStorageEntry;
506
- };
507
-
508
- const deleteEntry = async (model, params) => {
509
- const {
510
- entry
511
- } = params;
512
- const partitionKey = (0, _keys.createPartitionKey)({
513
- id: entry.id,
514
- locale: model.locale,
515
- tenant: model.tenant
516
- });
517
- const items = await (0, _query.queryAll)({
518
- entity,
519
- partitionKey,
520
- options: {
521
- gte: " "
522
- }
523
- });
524
- const esItems = await (0, _query.queryAll)({
525
- entity: esEntity,
526
- partitionKey,
527
- options: {
528
- gte: " "
529
- }
530
- });
531
- const deleteItems = items.map(item => {
532
- return entity.deleteBatch({
533
- PK: item.PK,
534
- SK: item.SK
535
- });
536
- });
537
- const deleteEsItems = esItems.map(item => {
538
- return esEntity.deleteBatch({
539
- PK: item.PK,
540
- SK: item.SK
541
- });
542
- });
543
-
544
- try {
545
- await (0, _batchWrite.batchWriteAll)({
546
- table: entity.table,
547
- items: deleteItems
548
- });
549
- dataLoaders.clearAll({
550
- model
551
- });
552
- } catch (ex) {
553
- throw new _error.default(ex.message || "Could not delete entry records from DynamoDB table.", ex.code || "DELETE_ENTRY_ERROR", {
554
- error: ex,
555
- entry
556
- });
557
- }
558
-
559
- try {
560
- await (0, _batchWrite.batchWriteAll)({
561
- table: esEntity.table,
562
- items: deleteEsItems
563
- });
564
- } catch (ex) {
565
- throw new _error.default(ex.message || "Could not delete entry records from DynamoDB Elasticsearch table.", ex.code || "DELETE_ENTRY_ERROR", {
566
- error: ex,
567
- entry
568
- });
569
- }
570
- };
571
-
572
- const deleteRevision = async (model, params) => {
573
- const {
574
- entry,
575
- latestEntry,
576
- latestStorageEntry
577
- } = params;
578
- const partitionKey = (0, _keys.createPartitionKey)({
579
- id: entry.id,
580
- locale: model.locale,
581
- tenant: model.tenant
582
- });
583
-
584
- const {
585
- index
586
- } = _configurations.configurations.es({
587
- model
588
- });
589
- /**
590
- * We need published entry to delete it if necessary.
591
- */
592
-
593
-
594
- const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
595
- model,
596
- ids: [entry.id]
597
- });
598
- /**
599
- * We need to delete all existing records of the given entry revision.
600
- */
601
-
602
- const items = [
603
- /**
604
- * Delete records of given entry revision.
605
- */
606
- entity.deleteBatch({
607
- PK: partitionKey,
608
- SK: (0, _keys.createRevisionSortKey)(entry)
609
- })];
610
- const esItems = [];
611
- /**
612
- * If revision we are deleting is the published one as well, we need to delete those records as well.
613
- */
614
-
615
- if ((publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
616
- items.push(entity.deleteBatch({
617
- PK: partitionKey,
618
- SK: (0, _keys.createPublishedSortKey)()
619
- }));
620
- esItems.push(entity.deleteBatch({
621
- PK: partitionKey,
622
- SK: (0, _keys.createPublishedSortKey)()
623
- }));
624
- }
625
-
626
- if (latestEntry && latestStorageEntry) {
627
- const esEntry = (0, _helpers.prepareEntryToIndex)({
628
- plugins,
629
- model,
630
- entry: (0, _cloneDeep.default)(latestEntry),
631
- storageEntry: (0, _cloneDeep.default)(latestStorageEntry)
632
- });
633
- const esLatestData = await getESLatestEntryData(plugins, esEntry);
634
- /**
635
- * In the end we need to set the new latest entry
636
- */
637
-
638
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestStorageEntry), {}, {
639
- PK: partitionKey,
640
- SK: (0, _keys.createLatestSortKey)(),
641
- TYPE: createLatestType()
642
- })));
643
- esItems.push(esEntity.putBatch({
644
- PK: partitionKey,
645
- SK: (0, _keys.createLatestSortKey)(),
646
- index,
647
- data: esLatestData
648
- }));
649
- }
650
-
651
- try {
652
- await (0, _batchWrite.batchWriteAll)({
653
- table: entity.table,
654
- items
655
- });
656
- dataLoaders.clearAll({
657
- model
658
- });
659
- } catch (ex) {
660
- throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
661
- error: ex,
662
- entry,
663
- latestEntry,
664
- latestStorageEntry
665
- });
666
- }
667
-
668
- if (esItems.length === 0) {
669
- return;
670
- }
671
-
672
- try {
673
- await (0, _batchWrite.batchWriteAll)({
674
- table: esEntity.table,
675
- items: esItems
676
- });
677
- } catch (ex) {
678
- throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
679
- error: ex,
680
- entry,
681
- latestEntry,
682
- latestStorageEntry
683
- });
684
- }
685
- };
686
-
687
- const list = async (model, params) => {
688
- const limit = (0, _apiElasticsearch.createLimit)(params.limit, 50);
689
-
690
- const {
691
- index
692
- } = _configurations.configurations.es({
693
- model
694
- });
695
-
696
- try {
697
- const result = await elasticsearch.indices.exists({
698
- index
699
- });
700
-
701
- if (!result || !result.body) {
573
+ try {
574
+ await entityBatch.execute();
575
+ dataLoaders.clearAll({
576
+ model
577
+ });
578
+ } catch (ex) {
579
+ throw new WebinyError(ex.message || "Could not restore all entry records from in the DynamoDB table.", ex.code || "RESTORE_ENTRY_ERROR", {
580
+ error: ex,
581
+ entry,
582
+ storageEntry
583
+ });
584
+ }
585
+ const esEntityReader = esEntity.createEntityReader();
586
+ if (publishedRecord) esEntityReader.get({
587
+ PK: partitionKey,
588
+ SK: publishedSortKey
589
+ });
590
+ if (latestRecord) esEntityReader.get({
591
+ PK: partitionKey,
592
+ SK: latestSortKey
593
+ });
594
+ const esRecords = await esEntityReader.execute();
595
+ const esItems = (await Promise.all(esRecords.map(async (record)=>{
596
+ if (!record) return null;
597
+ return {
598
+ ...record,
599
+ data: await compressionHandler.decompress(record.data)
600
+ };
601
+ }))).filter((item)=>!!item);
602
+ if (0 === esItems.length) return initialStorageEntry;
603
+ const elasticsearchEntityBatch = esEntity.createEntityWriter();
604
+ for (const item of esItems)elasticsearchEntityBatch.put({
605
+ ...item,
606
+ data: await compressionHandler.compress({
607
+ ...item.data,
608
+ ...updatedEntryMetaFields,
609
+ wbyDeleted: entry.wbyDeleted,
610
+ location: entry.location,
611
+ binOriginalFolderId: entry.binOriginalFolderId
612
+ })
613
+ });
614
+ try {
615
+ await elasticsearchEntityBatch.execute();
616
+ } catch (ex) {
617
+ throw new WebinyError(ex.message || "Could not restore entry records from DynamoDB Elasticsearch table.", ex.code || "RESTORE_ENTRY_ERROR", {
618
+ error: ex,
619
+ entry,
620
+ storageEntry
621
+ });
622
+ }
623
+ return initialStorageEntry;
624
+ };
625
+ const deleteEntry = async (initialModel, params)=>{
626
+ const { entry } = params;
627
+ const id = entry.id || entry.entryId;
628
+ const model = getStorageOperationsModel(initialModel);
629
+ const partitionKey = createPartitionKey({
630
+ id,
631
+ tenant: model.tenant
632
+ });
633
+ const items = await entity.queryAll({
634
+ partitionKey,
635
+ options: {
636
+ gte: " "
637
+ }
638
+ });
639
+ const esItems = await esEntity.queryAll({
640
+ partitionKey,
641
+ options: {
642
+ gte: " "
643
+ }
644
+ });
645
+ const entityBatch = entity.createEntityWriter({
646
+ delete: items.map((item)=>({
647
+ PK: item.PK,
648
+ SK: item.SK
649
+ }))
650
+ });
651
+ const elasticsearchEntityBatch = esEntity.createEntityWriter({
652
+ delete: esItems.map((item)=>({
653
+ PK: item.PK,
654
+ SK: item.SK
655
+ }))
656
+ });
657
+ try {
658
+ await entityBatch.execute();
659
+ dataLoaders.clearAll({
660
+ model
661
+ });
662
+ } catch (ex) {
663
+ throw new WebinyError(ex.message || "Could not destroy entry records from DynamoDB table.", ex.code || "DELETE_ENTRY_ERROR", {
664
+ error: ex,
665
+ id
666
+ });
667
+ }
668
+ try {
669
+ await elasticsearchEntityBatch.execute();
670
+ } catch (ex) {
671
+ throw new WebinyError(ex.message || "Could not destroy entry records from DynamoDB Elasticsearch table.", ex.code || "DELETE_ENTRY_ERROR", {
672
+ error: ex,
673
+ id
674
+ });
675
+ }
676
+ };
677
+ const deleteRevision = async (initialModel, params)=>{
678
+ const { entry, latestEntry, latestStorageEntry: initialLatestStorageEntry } = params;
679
+ const model = getStorageOperationsModel(initialModel);
680
+ const partitionKey = createPartitionKey({
681
+ id: entry.id,
682
+ tenant: model.tenant
683
+ });
684
+ const { index } = configurations.es({
685
+ model
686
+ });
687
+ const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
688
+ model,
689
+ ids: [
690
+ entry.id
691
+ ]
692
+ });
693
+ const entityBatch = entity.createEntityWriter({
694
+ delete: [
695
+ {
696
+ PK: partitionKey,
697
+ SK: createRevisionSortKey(entry)
698
+ }
699
+ ]
700
+ });
701
+ const elasticsearchEntityBatch = esEntity.createEntityWriter();
702
+ if (publishedStorageEntry?.id === entry.id) {
703
+ entityBatch.delete({
704
+ PK: partitionKey,
705
+ SK: createPublishedSortKey()
706
+ });
707
+ elasticsearchEntityBatch.delete({
708
+ PK: partitionKey,
709
+ SK: createPublishedSortKey()
710
+ });
711
+ }
712
+ if (latestEntry && initialLatestStorageEntry) {
713
+ const latestStorageEntry = convertToStorageEntry({
714
+ storageEntry: initialLatestStorageEntry,
715
+ model
716
+ });
717
+ const latestStorageEntryLatestKey = createEntryLatestKeys(latestStorageEntry);
718
+ entityBatch.put({
719
+ ...latestStorageEntryLatestKey,
720
+ data: latestStorageEntry
721
+ });
722
+ const actualRevisionEntryKey = createEntryRevisionKeys(initialLatestStorageEntry);
723
+ entityBatch.put({
724
+ ...actualRevisionEntryKey,
725
+ data: latestStorageEntry
726
+ });
727
+ const latestTransformer = createTransformer({
728
+ valuesModifiers,
729
+ model,
730
+ entry: latestEntry,
731
+ storageEntry: initialLatestStorageEntry,
732
+ fieldIndexRegistry,
733
+ compressionHandler
734
+ });
735
+ const esLatestData = await latestTransformer.getElasticsearchLatestEntryData();
736
+ const esLatestKeys = createEntryLatestKeys(latestEntry);
737
+ elasticsearchEntityBatch.put({
738
+ ...esLatestKeys,
739
+ index,
740
+ data: esLatestData
741
+ });
742
+ }
743
+ try {
744
+ await entityBatch.execute();
745
+ dataLoaders.clearAll({
746
+ model
747
+ });
748
+ } catch (ex) {
749
+ throw new WebinyError(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
750
+ error: ex,
751
+ entry,
752
+ latestEntry,
753
+ initialLatestStorageEntry
754
+ });
755
+ }
756
+ try {
757
+ await elasticsearchEntityBatch.execute();
758
+ } catch (ex) {
759
+ throw new WebinyError(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
760
+ error: ex,
761
+ entry,
762
+ latestEntry,
763
+ initialLatestStorageEntry
764
+ });
765
+ }
766
+ };
767
+ const deleteMultipleEntries = async (initialModel, params)=>{
768
+ const { entries } = params;
769
+ const model = getStorageOperationsModel(initialModel);
770
+ const revisions = await dataLoaders.getAllEntryRevisions({
771
+ model,
772
+ ids: entries
773
+ });
774
+ const entityBatch = entity.createEntityWriter();
775
+ const elasticsearchEntityBatch = esEntity.createEntityWriter();
776
+ for (const id of entries){
777
+ entityBatch.delete({
778
+ PK: createPartitionKey({
779
+ id,
780
+ tenant: model.tenant
781
+ }),
782
+ SK: "L"
783
+ });
784
+ elasticsearchEntityBatch.delete({
785
+ PK: createPartitionKey({
786
+ id,
787
+ tenant: model.tenant
788
+ }),
789
+ SK: "L"
790
+ });
791
+ entityBatch.delete({
792
+ PK: createPartitionKey({
793
+ id,
794
+ tenant: model.tenant
795
+ }),
796
+ SK: "P"
797
+ });
798
+ elasticsearchEntityBatch.delete({
799
+ PK: createPartitionKey({
800
+ id,
801
+ tenant: model.tenant
802
+ }),
803
+ SK: "P"
804
+ });
805
+ }
806
+ for (const revision of revisions)entityBatch.delete({
807
+ PK: createPartitionKey({
808
+ id: revision.id,
809
+ tenant: model.tenant
810
+ }),
811
+ SK: createRevisionSortKey({
812
+ version: revision.version
813
+ })
814
+ });
815
+ await entityBatch.execute();
816
+ await elasticsearchEntityBatch.execute();
817
+ };
818
+ const list = async (initialModel, params)=>{
819
+ const model = getStorageOperationsModel(initialModel);
820
+ const limit = createLimit(params.limit, 50);
821
+ const { index } = configurations.es({
822
+ model
823
+ });
824
+ const body = createElasticsearchBody({
825
+ model,
826
+ fieldRegistry,
827
+ fieldIndexRegistry,
828
+ bodyModifiers,
829
+ sortModifiers,
830
+ queryModifiers,
831
+ valueSearchRegistry,
832
+ fullTextSearches,
833
+ filterRegistry,
834
+ params: {
835
+ ...params,
836
+ limit,
837
+ after: decodeCursor(params.after)
838
+ },
839
+ plugins
840
+ });
841
+ let response;
842
+ try {
843
+ response = await elasticsearch.search({
844
+ index,
845
+ body
846
+ });
847
+ } catch (error) {
848
+ if (shouldIgnoreEsResponseError(error)) return {
849
+ hasMoreItems: false,
850
+ totalCount: 0,
851
+ cursor: null,
852
+ items: []
853
+ };
854
+ throw new WebinyError(error.message, error.code || "OPENSEARCH_ERROR", {
855
+ error,
856
+ index,
857
+ body,
858
+ model
859
+ });
860
+ }
861
+ const { hits, total } = response.body.hits;
862
+ const items = extractEntriesFromIndex({
863
+ fieldRegistry,
864
+ fieldIndexRegistry,
865
+ model,
866
+ entries: hits.map((item)=>item._source)
867
+ }).map((item)=>convertEntryKeysFromStorage({
868
+ model,
869
+ entry: item
870
+ }));
871
+ const hasMoreItems = items.length > limit;
872
+ if (hasMoreItems) items.pop();
873
+ const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;
702
874
  return {
703
- hasMoreItems: false,
704
- totalCount: 0,
705
- cursor: null,
706
- items: []
875
+ hasMoreItems,
876
+ totalCount: getTotalCount(total),
877
+ cursor,
878
+ items
707
879
  };
708
- }
709
- } catch (ex) {
710
- throw new _error.default("Could not determine if Elasticsearch index exists.", "ELASTICSEARCH_INDEX_CHECK_ERROR", {
711
- error: ex,
712
- index
713
- });
714
- }
715
-
716
- const body = (0, _helpers.createElasticsearchQueryBody)({
717
- model,
718
- args: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
719
- limit
720
- }),
721
- plugins,
722
- parentPath: "values"
723
- });
724
- let response;
725
-
726
- try {
727
- response = await elasticsearch.search({
728
- index,
729
- body
730
- });
731
- } catch (ex) {
732
- throw new _error.default(ex.message, ex.code || "ELASTICSEARCH_ERROR", {
733
- error: ex,
734
- index,
735
- body,
736
- model
737
- });
738
- }
739
-
740
- const {
741
- hits,
742
- total
743
- } = response.body.hits;
744
- const items = (0, _helpers.extractEntriesFromIndex)({
745
- plugins,
746
- model,
747
- entries: hits.map(item => item._source)
748
- }).map(item => {
749
- return convertFromStorageEntry({
750
- model,
751
- entry: item
752
- });
753
- });
754
- const hasMoreItems = items.length > limit;
755
-
756
- if (hasMoreItems) {
757
- /**
758
- * Remove the last item from results, we don't want to include it.
759
- */
760
- items.pop();
761
- }
762
- /**
763
- * Cursor is the `sort` value of the last item in the array.
764
- * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
765
- */
766
-
767
-
768
- const cursor = items.length > 0 ? (0, _apiElasticsearch.encodeCursor)(hits[items.length - 1].sort) || null : null;
769
- return {
770
- hasMoreItems,
771
- totalCount: total.value,
772
- cursor,
773
- items
774
880
  };
775
- };
776
-
777
- const get = async (model, params) => {
778
- const {
779
- items
780
- } = await list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
781
- limit: 1
782
- }));
783
- return items.shift() || null;
784
- };
785
-
786
- const publish = async (model, params) => {
787
- const {
788
- entry: initialEntry,
789
- storageEntry: initialStorageEntry
790
- } = params;
791
- const entry = convertToStorageEntry({
792
- model,
793
- entry: initialEntry
794
- });
795
- const storageEntry = convertToStorageEntry({
796
- model,
797
- entry: initialStorageEntry
798
- });
799
- /**
800
- * We need currently published entry to check if need to remove it.
801
- */
802
-
803
- const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
804
- model,
805
- ids: [entry.id]
806
- });
807
- const revisionKeys = {
808
- PK: (0, _keys.createPartitionKey)({
809
- id: entry.id,
810
- locale: model.locale,
811
- tenant: model.tenant
812
- }),
813
- SK: (0, _keys.createRevisionSortKey)(entry)
881
+ const get = async (initialModel, params)=>{
882
+ const model = getStorageOperationsModel(initialModel);
883
+ const { items } = await list(model, {
884
+ ...params,
885
+ limit: 1
886
+ });
887
+ return items.shift() || null;
814
888
  };
815
- const latestKeys = {
816
- PK: (0, _keys.createPartitionKey)({
817
- id: entry.id,
818
- locale: model.locale,
819
- tenant: model.tenant
820
- }),
821
- SK: (0, _keys.createLatestSortKey)()
889
+ const publish = async (initialModel, params)=>{
890
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
891
+ const model = getStorageOperationsModel(initialModel);
892
+ const transformer = createTransformer({
893
+ valuesModifiers,
894
+ model,
895
+ entry: initialEntry,
896
+ storageEntry: initialStorageEntry,
897
+ fieldIndexRegistry,
898
+ compressionHandler
899
+ });
900
+ const { entry, storageEntry } = transformer.transformEntryKeys();
901
+ const revisionKeys = createEntryRevisionKeys(entry);
902
+ const latestKeys = createEntryLatestKeys(entry);
903
+ const publishedKeys = createEntryPublishedKeys(entry);
904
+ let latestEsEntry = null;
905
+ try {
906
+ latestEsEntry = await esEntity.getClean(latestKeys);
907
+ } catch (ex) {
908
+ throw new WebinyError(ex.message || "Could not read Elasticsearch latest data.", ex.code || "PUBLISH_LATEST_READ", {
909
+ error: ex,
910
+ latestKeys: latestKeys,
911
+ publishedKeys: publishedKeys
912
+ });
913
+ }
914
+ if (!latestEsEntry) throw new WebinyError('Could not publish entry. Could not load latest ("L") record (ES table).', "PUBLISH_ERROR", {
915
+ entry
916
+ });
917
+ const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
918
+ model,
919
+ ids: [
920
+ entry.id
921
+ ]
922
+ });
923
+ if (!latestStorageEntry) throw new WebinyError('Could not publish entry. Could not load latest ("L") record.', "PUBLISH_ERROR", {
924
+ entry
925
+ });
926
+ const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
927
+ model,
928
+ ids: [
929
+ entry.id
930
+ ]
931
+ });
932
+ const entityBatch = entity.createEntityWriter({
933
+ put: [
934
+ {
935
+ ...revisionKeys,
936
+ data: storageEntry
937
+ },
938
+ {
939
+ ...publishedKeys,
940
+ data: storageEntry
941
+ }
942
+ ]
943
+ });
944
+ const elasticsearchEntityWriter = esEntity.createEntityWriter();
945
+ const { index: esIndex } = configurations.es({
946
+ model
947
+ });
948
+ const publishedRevisionId = publishedStorageEntry?.id;
949
+ const publishingLatestRevision = latestStorageEntry?.id === entry.id;
950
+ if (publishingLatestRevision) {
951
+ entityBatch.put({
952
+ ...latestKeys,
953
+ data: storageEntry
954
+ });
955
+ if (publishedStorageEntry) {
956
+ const isRepublishing = publishedStorageEntry.id === entry.id;
957
+ if (!isRepublishing) {
958
+ const publishedStorageEntryKeys = createEntryRevisionKeys(publishedStorageEntry);
959
+ entityBatch.put({
960
+ ...publishedStorageEntryKeys,
961
+ data: {
962
+ ...publishedStorageEntry,
963
+ status: CONTENT_ENTRY_STATUS.UNPUBLISHED
964
+ }
965
+ });
966
+ }
967
+ }
968
+ } else {
969
+ const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
970
+ let latestRevisionStatus = latestStorageEntry.status;
971
+ if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
972
+ const latestStorageEntryFields = {
973
+ ...latestStorageEntry,
974
+ ...updatedEntryLevelMetaFields,
975
+ status: latestRevisionStatus
976
+ };
977
+ const latestStorageEntryLatestKeys = createEntryLatestKeys(latestStorageEntry);
978
+ entityBatch.put({
979
+ ...latestStorageEntryLatestKeys,
980
+ data: latestStorageEntryFields
981
+ });
982
+ const latestStorageEntryRevisionKeys = createEntryRevisionKeys(latestStorageEntry);
983
+ entityBatch.put({
984
+ ...latestStorageEntryRevisionKeys,
985
+ data: latestStorageEntryFields
986
+ });
987
+ if (publishedStorageEntry) {
988
+ const isRepublishing = publishedStorageEntry.id === entry.id;
989
+ const publishedRevisionDifferentFromLatest = publishedRevisionId !== latestStorageEntry.id;
990
+ if (!isRepublishing && publishedRevisionDifferentFromLatest) {
991
+ const publishedStorageEntryRevisionKeys = createEntryRevisionKeys(publishedStorageEntry);
992
+ entityBatch.put({
993
+ ...publishedStorageEntryRevisionKeys,
994
+ data: {
995
+ ...publishedStorageEntry,
996
+ status: CONTENT_ENTRY_STATUS.UNPUBLISHED
997
+ }
998
+ });
999
+ }
1000
+ }
1001
+ }
1002
+ const esPublishedData = await transformer.getElasticsearchPublishedEntryData();
1003
+ elasticsearchEntityWriter.put({
1004
+ ...publishedKeys,
1005
+ index: esIndex,
1006
+ data: esPublishedData
1007
+ });
1008
+ const latestEsEntryDataDecompressed = await compressionHandler.decompress(latestEsEntry.data);
1009
+ if (publishingLatestRevision) {
1010
+ const updatedMetaFields = pickEntryMetaFields(entry);
1011
+ const latestTransformer = createTransformer({
1012
+ valuesModifiers,
1013
+ model,
1014
+ transformedToIndex: {
1015
+ ...latestEsEntryDataDecompressed,
1016
+ status: CONTENT_ENTRY_STATUS.PUBLISHED,
1017
+ locked: true,
1018
+ ...updatedMetaFields
1019
+ },
1020
+ fieldIndexRegistry,
1021
+ compressionHandler
1022
+ });
1023
+ const esEntryLatestKeys = createEntryLatestKeys(latestEsEntryDataDecompressed);
1024
+ elasticsearchEntityWriter.put({
1025
+ index: esIndex,
1026
+ data: await latestTransformer.getElasticsearchLatestEntryData(),
1027
+ ...esEntryLatestKeys
1028
+ });
1029
+ } else {
1030
+ const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
1031
+ const latestEsEntry = await esEntity.getClean(latestKeys);
1032
+ if (latestEsEntry) {
1033
+ const latestEsEntryDataDecompressed = await compressionHandler.decompress(latestEsEntry.data);
1034
+ let latestRevisionStatus = latestEsEntryDataDecompressed.status;
1035
+ if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
1036
+ const updatedLatestEntry = await compressionHandler.compress({
1037
+ ...latestEsEntryDataDecompressed,
1038
+ ...updatedEntryLevelMetaFields,
1039
+ status: latestRevisionStatus
1040
+ });
1041
+ elasticsearchEntityWriter.put({
1042
+ ...latestKeys,
1043
+ index: esIndex,
1044
+ data: updatedLatestEntry
1045
+ });
1046
+ }
1047
+ }
1048
+ try {
1049
+ await entityBatch.execute();
1050
+ dataLoaders.clearAll({
1051
+ model
1052
+ });
1053
+ } catch (ex) {
1054
+ throw new WebinyError(ex.message || "Could not store publish entry records in DynamoDB table.", ex.code || "PUBLISH_ERROR", {
1055
+ error: ex,
1056
+ entry,
1057
+ latestStorageEntry,
1058
+ publishedStorageEntry
1059
+ });
1060
+ }
1061
+ try {
1062
+ await elasticsearchEntityWriter.execute();
1063
+ } catch (ex) {
1064
+ throw new WebinyError(ex.message || "Could not store publish entry records in DynamoDB Elasticsearch table.", ex.code || "PUBLISH_ES_ERROR", {
1065
+ error: ex,
1066
+ entry,
1067
+ latestStorageEntry,
1068
+ publishedStorageEntry
1069
+ });
1070
+ }
1071
+ return initialStorageEntry;
822
1072
  };
823
- const publishedKeys = {
824
- PK: (0, _keys.createPartitionKey)({
825
- id: entry.id,
826
- locale: model.locale,
827
- tenant: model.tenant
828
- }),
829
- SK: (0, _keys.createPublishedSortKey)()
1073
+ const unpublish = async (initialModel, params)=>{
1074
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
1075
+ const model = getStorageOperationsModel(initialModel);
1076
+ const transformer = createTransformer({
1077
+ valuesModifiers,
1078
+ model,
1079
+ entry: initialEntry,
1080
+ storageEntry: initialStorageEntry,
1081
+ fieldIndexRegistry,
1082
+ compressionHandler
1083
+ });
1084
+ const { entry, storageEntry } = await transformer.transformEntryKeys();
1085
+ const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
1086
+ model,
1087
+ ids: [
1088
+ entry.id
1089
+ ]
1090
+ });
1091
+ const partitionKey = createPartitionKey({
1092
+ id: entry.id,
1093
+ tenant: model.tenant
1094
+ });
1095
+ const entryRevisionKeys = createEntryRevisionKeys(entry);
1096
+ const entityBatch = entity.createEntityWriter({
1097
+ put: [
1098
+ {
1099
+ ...entryRevisionKeys,
1100
+ data: storageEntry
1101
+ }
1102
+ ],
1103
+ delete: [
1104
+ {
1105
+ PK: partitionKey,
1106
+ SK: createPublishedSortKey()
1107
+ }
1108
+ ]
1109
+ });
1110
+ const elasticsearchEntityBatch = esEntity.createEntityWriter({
1111
+ delete: [
1112
+ {
1113
+ PK: partitionKey,
1114
+ SK: createPublishedSortKey()
1115
+ }
1116
+ ]
1117
+ });
1118
+ if (latestStorageEntry?.id === entry.id) {
1119
+ const { index } = configurations.es({
1120
+ model
1121
+ });
1122
+ const entryLatestKeys = createEntryLatestKeys(storageEntry);
1123
+ entityBatch.put({
1124
+ ...entryLatestKeys,
1125
+ data: storageEntry
1126
+ });
1127
+ const esLatestData = await transformer.getElasticsearchLatestEntryData();
1128
+ elasticsearchEntityBatch.put({
1129
+ index,
1130
+ data: esLatestData,
1131
+ ...entryLatestKeys
1132
+ });
1133
+ }
1134
+ try {
1135
+ await entityBatch.execute();
1136
+ dataLoaders.clearAll({
1137
+ model
1138
+ });
1139
+ } catch (ex) {
1140
+ throw new WebinyError(ex.message || "Could not store unpublished entry records in DynamoDB table.", ex.code || "UNPUBLISH_ERROR", {
1141
+ entry,
1142
+ storageEntry
1143
+ });
1144
+ }
1145
+ try {
1146
+ await elasticsearchEntityBatch.execute();
1147
+ } catch (ex) {
1148
+ throw new WebinyError(ex.message || "Could not store unpublished entry records in DynamoDB Elasticsearch table.", ex.code || "UNPUBLISH_ERROR", {
1149
+ entry,
1150
+ storageEntry
1151
+ });
1152
+ }
1153
+ return initialStorageEntry;
830
1154
  };
831
- let latestEsEntry = null;
832
-
833
- try {
834
- latestEsEntry = await (0, _get.get)({
835
- entity: esEntity,
836
- keys: latestKeys
837
- });
838
- } catch (ex) {
839
- throw new _error.default(ex.message || "Could not read Elasticsearch latest or published data.", ex.code || "PUBLISH_BATCH_READ", {
840
- error: ex,
841
- latestKeys: latestKeys,
842
- publishedKeys: publishedKeys
843
- });
844
- }
845
-
846
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), revisionKeys), {}, {
847
- TYPE: createType()
848
- }))];
849
- const esItems = [];
850
-
851
- const {
852
- index
853
- } = _configurations.configurations.es({
854
- model
855
- });
856
-
857
- if (publishedStorageEntry && publishedStorageEntry.id !== entry.id) {
858
- /**
859
- * If there is a `published` entry already, we need to set it to `unpublished`. We need to
860
- * execute two updates: update the previously published entry's status and the published entry record.
861
- * DynamoDB does not support `batchUpdate` - so here we load the previously published
862
- * entry's data to update its status within a batch operation. If, hopefully,
863
- * they introduce a true update batch operation, remove this `read` call.
864
- */
865
- const [previouslyPublishedEntry] = await dataLoaders.getRevisionById({
866
- model,
867
- ids: [publishedStorageEntry.id]
868
- }); //
869
- // const previouslyPublishedEntry = convertToStorageEntry({
870
- // model,
871
- // entry: initialPreviouslyPublishedEntry
872
- // });
873
-
874
- items.push(
875
- /**
876
- * Update currently published entry (unpublish it)
877
- */
878
- entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedEntry), {}, {
879
- status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
880
- savedOn: entry.savedOn,
881
- TYPE: createType(),
882
- PK: (0, _keys.createPartitionKey)(publishedStorageEntry),
883
- SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry)
884
- })));
885
- }
886
- /**
887
- * Update the helper item in DB with the new published entry
888
- */
889
-
890
-
891
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), publishedKeys), {}, {
892
- TYPE: createPublishedType()
893
- })));
894
- /**
895
- * We need the latest entry to check if it needs to be updated as well in the Elasticsearch.
896
- */
897
-
898
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
899
- model,
900
- ids: [entry.id]
901
- });
902
-
903
- if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
904
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), latestKeys)));
905
- }
906
- /**
907
- * If we are publishing the latest revision, let's also update the latest revision's status in ES.
908
- */
909
-
910
-
911
- if (latestEsEntry && (latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
912
- /**
913
- * Need to decompress the data from Elasticsearch DynamoDB table.
914
- *
915
- * No need to transform it for the storage because it was fetched directly from the Elasticsearch table, where it sits transformed.
916
- */
917
- const latestEsEntryDataDecompressed = await (0, _apiElasticsearch.decompress)(plugins, latestEsEntry.data);
918
- esItems.push(esEntity.putBatch({
919
- index,
920
- PK: (0, _keys.createPartitionKey)(latestEsEntryDataDecompressed),
921
- SK: (0, _keys.createLatestSortKey)(),
922
- data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestEsEntryDataDecompressed), {}, {
923
- status: _types.CONTENT_ENTRY_STATUS.PUBLISHED,
924
- locked: true,
925
- savedOn: entry.savedOn,
926
- publishedOn: entry.publishedOn
927
- })
928
- }));
929
- }
930
-
931
- const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
932
- plugins,
933
- model,
934
- entry: (0, _cloneDeep.default)(entry),
935
- storageEntry: (0, _cloneDeep.default)(storageEntry)
936
- });
937
- /**
938
- * Update the published revision entry in ES.
939
- */
940
-
941
- const esLatestData = await getESPublishedEntryData(plugins, preparedEntryData);
942
- esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
943
- index,
944
- data: esLatestData
945
- })));
946
- /**
947
- * Finally, execute regular table batch.
948
- */
949
-
950
- try {
951
- await (0, _batchWrite.batchWriteAll)({
952
- table: entity.table,
953
- items
954
- });
955
- dataLoaders.clearAll({
956
- model
957
- });
958
- } catch (ex) {
959
- throw new _error.default(ex.message || "Could not store publish entry records in DynamoDB table.", ex.code || "PUBLISH_ERROR", {
960
- error: ex,
961
- entry,
962
- latestStorageEntry,
963
- publishedStorageEntry
964
- });
965
- }
966
- /**
967
- * And Elasticsearch table batch.
968
- */
969
-
970
-
971
- try {
972
- await (0, _batchWrite.batchWriteAll)({
973
- table: esEntity.table,
974
- items: esItems
975
- });
976
- } catch (ex) {
977
- throw new _error.default(ex.message || "Could not store publish entry records in DynamoDB Elasticsearch table.", ex.code || "PUBLISH_ES_ERROR", {
978
- error: ex,
979
- entry,
980
- latestStorageEntry,
981
- publishedStorageEntry
982
- });
983
- }
984
-
985
- return initialStorageEntry;
986
- };
987
-
988
- const unpublish = async (model, params) => {
989
- const {
990
- entry: initialEntry,
991
- storageEntry: initialStorageEntry
992
- } = params;
993
- const entry = convertToStorageEntry({
994
- model,
995
- entry: initialEntry
996
- });
997
- const storageEntry = convertToStorageEntry({
998
- model,
999
- entry: initialStorageEntry
1000
- });
1001
- /**
1002
- * We need the latest entry to check if it needs to be updated.
1003
- */
1004
-
1005
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
1006
- model,
1007
- ids: [entry.id]
1008
- });
1009
- const partitionKey = (0, _keys.createPartitionKey)({
1010
- id: entry.id,
1011
- locale: model.locale,
1012
- tenant: model.tenant
1013
- });
1014
- const items = [entity.deleteBatch({
1015
- PK: partitionKey,
1016
- SK: (0, _keys.createPublishedSortKey)()
1017
- }), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
1018
- PK: partitionKey,
1019
- SK: (0, _keys.createRevisionSortKey)(entry),
1020
- TYPE: createType()
1021
- }))];
1022
- const esItems = [esEntity.deleteBatch({
1023
- PK: partitionKey,
1024
- SK: (0, _keys.createPublishedSortKey)()
1025
- })];
1026
- /**
1027
- * If we are unpublishing the latest revision, let's also update the latest revision entry's status in ES.
1028
- */
1029
-
1030
- if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
1031
- const {
1032
- index
1033
- } = _configurations.configurations.es({
1034
- model
1035
- });
1036
-
1037
- const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
1038
- plugins,
1039
- model,
1040
- entry: (0, _cloneDeep.default)(entry),
1041
- storageEntry: (0, _cloneDeep.default)(storageEntry)
1042
- });
1043
- const esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
1044
- esItems.push(esEntity.putBatch({
1045
- PK: partitionKey,
1046
- SK: (0, _keys.createLatestSortKey)(),
1047
- index,
1048
- data: esLatestData
1049
- }));
1050
- }
1051
- /**
1052
- * Finally, execute regular table batch.
1053
- */
1054
-
1055
-
1056
- try {
1057
- await (0, _batchWrite.batchWriteAll)({
1058
- table: entity.table,
1059
- items
1060
- });
1061
- dataLoaders.clearAll({
1062
- model
1063
- });
1064
- } catch (ex) {
1065
- throw new _error.default(ex.message || "Could not store unpublished entry records in DynamoDB table.", ex.code || "UNPUBLISH_ERROR", {
1066
- entry,
1067
- storageEntry
1068
- });
1069
- }
1070
- /**
1071
- * And Elasticsearch table batch.
1072
- */
1073
-
1074
-
1075
- try {
1076
- await (0, _batchWrite.batchWriteAll)({
1077
- table: esEntity.table,
1078
- items: esItems
1079
- });
1080
- } catch (ex) {
1081
- throw new _error.default(ex.message || "Could not store unpublished entry records in DynamoDB Elasticsearch table.", ex.code || "UNPUBLISH_ERROR", {
1082
- entry,
1083
- storageEntry
1084
- });
1085
- }
1086
-
1087
- return initialStorageEntry;
1088
- };
1089
-
1090
- const getLatestRevisionByEntryId = async (model, params) => {
1091
- const [entry] = await dataLoaders.getLatestRevisionByEntryId({
1092
- model,
1093
- ids: [params.id]
1094
- });
1095
-
1096
- if (!entry) {
1097
- return null;
1098
- }
1099
-
1100
- return convertFromStorageEntry({
1101
- model,
1102
- entry
1103
- });
1104
- };
1105
-
1106
- const getPublishedRevisionByEntryId = async (model, params) => {
1107
- const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
1108
- model,
1109
- ids: [params.id]
1110
- });
1111
-
1112
- if (!entry) {
1113
- return null;
1114
- }
1115
-
1116
- return convertFromStorageEntry({
1117
- model,
1118
- entry
1119
- });
1120
- };
1121
-
1122
- const getRevisionById = async (model, params) => {
1123
- const [entry] = await dataLoaders.getRevisionById({
1124
- model,
1125
- ids: [params.id]
1126
- });
1127
-
1128
- if (!entry) {
1129
- return null;
1130
- }
1131
-
1132
- return convertFromStorageEntry({
1133
- model,
1134
- entry
1135
- });
1136
- };
1137
-
1138
- const getRevisions = async (model, params) => {
1139
- const entries = await dataLoaders.getAllEntryRevisions({
1140
- model,
1141
- ids: [params.id]
1142
- });
1143
- return entries.map(entry => {
1144
- return convertFromStorageEntry({
1145
- model,
1146
- entry
1147
- });
1148
- });
1149
- };
1150
-
1151
- const getByIds = async (model, params) => {
1152
- const entries = await dataLoaders.getRevisionById({
1153
- model,
1154
- ids: params.ids
1155
- });
1156
- return entries.map(entry => {
1157
- return convertFromStorageEntry({
1158
- model,
1159
- entry
1160
- });
1161
- });
1162
- };
1163
-
1164
- const getLatestByIds = async (model, params) => {
1165
- const entries = await dataLoaders.getLatestRevisionByEntryId({
1166
- model,
1167
- ids: params.ids
1168
- });
1169
- return entries.map(entry => {
1170
- return convertFromStorageEntry({
1171
- model,
1172
- entry
1173
- });
1174
- });
1175
- };
1176
-
1177
- const getPublishedByIds = async (model, params) => {
1178
- const entries = await dataLoaders.getPublishedRevisionByEntryId({
1179
- model,
1180
- ids: params.ids
1181
- });
1182
- return entries.map(entry => {
1183
- return convertFromStorageEntry({
1184
- model,
1185
- entry
1186
- });
1187
- });
1188
- };
1189
-
1190
- const getPreviousRevision = async (model, params) => {
1191
- const {
1192
- tenant,
1193
- locale
1194
- } = model;
1195
- const {
1196
- entryId,
1197
- version
1198
- } = params;
1199
- const queryParams = {
1200
- entity,
1201
- partitionKey: (0, _keys.createPartitionKey)({
1202
- tenant,
1203
- locale,
1204
- id: entryId
1205
- }),
1206
- options: {
1207
- lt: `REV#${(0, _utils.zeroPad)(version)}`,
1208
-
1209
- /**
1210
- * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
1211
- */
1212
- filters: [{
1213
- attr: "TYPE",
1214
- eq: createType()
1215
- }, {
1216
- attr: "version",
1217
- lt: version
1218
- }],
1219
- reverse: true
1220
- }
1155
+ const getLatestRevisionByEntryId = async (initialModel, params)=>{
1156
+ const model = getStorageOperationsModel(initialModel);
1157
+ const [entry] = await dataLoaders.getLatestRevisionByEntryId({
1158
+ model,
1159
+ ids: [
1160
+ params.id
1161
+ ]
1162
+ });
1163
+ if (!entry) return null;
1164
+ return convertEntryKeysFromStorage({
1165
+ model,
1166
+ entry
1167
+ });
1168
+ };
1169
+ const getPublishedRevisionByEntryId = async (initialModel, params)=>{
1170
+ const model = getStorageOperationsModel(initialModel);
1171
+ const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
1172
+ model,
1173
+ ids: [
1174
+ params.id
1175
+ ]
1176
+ });
1177
+ if (!entry) return null;
1178
+ return convertEntryKeysFromStorage({
1179
+ model,
1180
+ entry
1181
+ });
1182
+ };
1183
+ const getRevisionById = async (initialModel, params)=>{
1184
+ const model = getStorageOperationsModel(initialModel);
1185
+ const [entry] = await dataLoaders.getRevisionById({
1186
+ model,
1187
+ ids: [
1188
+ params.id
1189
+ ]
1190
+ });
1191
+ if (!entry) return null;
1192
+ return convertEntryKeysFromStorage({
1193
+ model,
1194
+ entry
1195
+ });
1196
+ };
1197
+ const getRevisions = async (initialModel, params)=>{
1198
+ const model = getStorageOperationsModel(initialModel);
1199
+ const entries = await dataLoaders.getAllEntryRevisions({
1200
+ model,
1201
+ ids: [
1202
+ params.id
1203
+ ]
1204
+ });
1205
+ return entries.map((entry)=>convertEntryKeysFromStorage({
1206
+ model,
1207
+ entry
1208
+ }));
1209
+ };
1210
+ const getByIds = async (initialModel, params)=>{
1211
+ const model = getStorageOperationsModel(initialModel);
1212
+ const entries = await dataLoaders.getRevisionById({
1213
+ model,
1214
+ ids: params.ids
1215
+ });
1216
+ return entries.map((entry)=>convertEntryKeysFromStorage({
1217
+ model,
1218
+ entry
1219
+ }));
1220
+ };
1221
+ const getLatestByIds = async (initialModel, params)=>{
1222
+ const model = getStorageOperationsModel(initialModel);
1223
+ const entries = await dataLoaders.getLatestRevisionByEntryId({
1224
+ model,
1225
+ ids: params.ids
1226
+ });
1227
+ return entries.map((entry)=>convertEntryKeysFromStorage({
1228
+ model,
1229
+ entry
1230
+ }));
1231
+ };
1232
+ const getPublishedByIds = async (initialModel, params)=>{
1233
+ const model = getStorageOperationsModel(initialModel);
1234
+ const entries = await dataLoaders.getPublishedRevisionByEntryId({
1235
+ model,
1236
+ ids: params.ids
1237
+ });
1238
+ return entries.map((entry)=>convertEntryKeysFromStorage({
1239
+ model,
1240
+ entry
1241
+ }));
1242
+ };
1243
+ const getPreviousRevision = async (initialModel, params)=>{
1244
+ const model = getStorageOperationsModel(initialModel);
1245
+ const { tenant } = model;
1246
+ const { entryId, version } = params;
1247
+ const partitionKey = createPartitionKey({
1248
+ tenant,
1249
+ id: entryId
1250
+ });
1251
+ const options = {
1252
+ beginsWith: "REV#",
1253
+ reverse: true
1254
+ };
1255
+ try {
1256
+ const unfilteredEntries = (await entity.queryAll({
1257
+ partitionKey,
1258
+ options
1259
+ })).map((item)=>item.data);
1260
+ const entries = unfilteredEntries.filter((item)=>item.version < version);
1261
+ const entry = entries[0];
1262
+ if (!entry) return null;
1263
+ return convertEntryKeysFromStorage({
1264
+ entry,
1265
+ model
1266
+ });
1267
+ } catch (ex) {
1268
+ throw new WebinyError(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", {
1269
+ ...params,
1270
+ error: ex,
1271
+ partitionKey,
1272
+ options,
1273
+ model
1274
+ });
1275
+ }
1276
+ };
1277
+ const getUniqueFieldValues = async (model, params)=>{
1278
+ const { where, fieldId } = params;
1279
+ const { index } = configurations.es({
1280
+ model
1281
+ });
1282
+ const initialBody = createElasticsearchBody({
1283
+ model,
1284
+ fieldRegistry,
1285
+ fieldIndexRegistry,
1286
+ bodyModifiers,
1287
+ sortModifiers,
1288
+ queryModifiers,
1289
+ valueSearchRegistry,
1290
+ fullTextSearches,
1291
+ filterRegistry,
1292
+ params: {
1293
+ limit: 1,
1294
+ where
1295
+ },
1296
+ plugins
1297
+ });
1298
+ const field = model.fields.find((f)=>f.fieldId === fieldId);
1299
+ if (!field) throw new WebinyError('Could not find field with given "fieldId" value.', "FIELD_NOT_FOUND", {
1300
+ fieldId
1301
+ });
1302
+ const body = {
1303
+ ...initialBody,
1304
+ size: 0,
1305
+ aggregations: {
1306
+ getUniqueFieldValues: {
1307
+ terms: {
1308
+ field: `values.${field.storageId}.keyword`,
1309
+ size: 1000000
1310
+ }
1311
+ }
1312
+ }
1313
+ };
1314
+ let response;
1315
+ try {
1316
+ response = await elasticsearch.search({
1317
+ index,
1318
+ body
1319
+ });
1320
+ } catch (error) {
1321
+ if (shouldIgnoreEsResponseError(error)) return [];
1322
+ throw new WebinyError(error.message || "Error in the Elasticsearch query.", error.code || "OPENSEARCH_ERROR", {
1323
+ error,
1324
+ index,
1325
+ model,
1326
+ body
1327
+ });
1328
+ }
1329
+ const aggregations = response.body.aggregations || {};
1330
+ const agg = aggregations["getUniqueFieldValues"];
1331
+ const buckets = agg && "buckets" in agg && Array.isArray(agg.buckets) ? agg.buckets : [];
1332
+ return buckets.map((bucket)=>({
1333
+ value: bucket.key,
1334
+ count: bucket.doc_count
1335
+ }));
1336
+ };
1337
+ return {
1338
+ create,
1339
+ createRevisionFrom,
1340
+ update,
1341
+ move,
1342
+ delete: deleteEntry,
1343
+ moveToBin,
1344
+ restoreFromBin,
1345
+ deleteRevision,
1346
+ deleteMultipleEntries,
1347
+ get,
1348
+ publish,
1349
+ unpublish,
1350
+ list,
1351
+ getLatestRevisionByEntryId,
1352
+ getPublishedRevisionByEntryId,
1353
+ getRevisionById,
1354
+ getRevisions,
1355
+ getByIds,
1356
+ getLatestByIds,
1357
+ getPublishedByIds,
1358
+ getPreviousRevision,
1359
+ getUniqueFieldValues,
1360
+ dataLoaders
1221
1361
  };
1222
-
1223
- try {
1224
- const result = await (0, _query.queryOne)(queryParams);
1225
- const entry = (0, _cleanup.cleanupItem)(entity, result);
1226
-
1227
- if (!entry) {
1228
- return null;
1229
- }
1230
-
1231
- return convertFromStorageEntry({
1232
- entry,
1233
- model
1234
- });
1235
- } catch (ex) {
1236
- throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
1237
- error: ex,
1238
- partitionKey: queryParams.partitionKey,
1239
- options: queryParams.options,
1240
- model
1241
- }));
1242
- }
1243
- };
1244
-
1245
- return {
1246
- create,
1247
- createRevisionFrom,
1248
- update,
1249
- delete: deleteEntry,
1250
- deleteRevision,
1251
- get,
1252
- publish,
1253
- unpublish,
1254
- list,
1255
- getLatestRevisionByEntryId,
1256
- getPublishedRevisionByEntryId,
1257
- getRevisionById,
1258
- getRevisions,
1259
- getByIds,
1260
- getLatestByIds,
1261
- getPublishedByIds,
1262
- getPreviousRevision
1263
- };
1264
1362
  };
1363
+ export { createEntriesStorageOperations };
1265
1364
 
1266
- exports.createEntriesStorageOperations = createEntriesStorageOperations;
1365
+ //# sourceMappingURL=index.js.map