@webiny/api-headless-cms-ddb-es 0.0.0-unstable.6f45466a1d → 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 (388) hide show
  1. package/configurations.d.ts +5 -4
  2. package/configurations.js +27 -33
  3. package/configurations.js.map +1 -1
  4. package/definitions/entry.js +7 -9
  5. package/definitions/entry.js.map +1 -1
  6. package/definitions/group.js +7 -9
  7. package/definitions/group.js.map +1 -1
  8. package/definitions/model.js +7 -9
  9. package/definitions/model.js.map +1 -1
  10. package/definitions/types.d.ts +9 -3
  11. package/definitions/types.js +0 -3
  12. package/elasticsearch/createElasticsearchIndex.d.ts +3 -3
  13. package/elasticsearch/createElasticsearchIndex.js +52 -27
  14. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  15. package/elasticsearch/deleteElasticsearchIndex.d.ts +1 -1
  16. package/elasticsearch/deleteElasticsearchIndex.js +18 -26
  17. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
  18. package/exports/api/cms/opensearch.d.ts +9 -0
  19. package/exports/api/cms/opensearch.js +9 -0
  20. package/feature.d.ts +1 -0
  21. package/feature.js +179 -0
  22. package/feature.js.map +1 -0
  23. package/features/CmsEntryOpenSearchBodyModifier/abstractions.d.ts +16 -0
  24. package/features/CmsEntryOpenSearchBodyModifier/abstractions.js +5 -0
  25. package/features/CmsEntryOpenSearchBodyModifier/abstractions.js.map +1 -0
  26. package/features/CmsEntryOpenSearchBodyModifier/index.d.ts +1 -0
  27. package/features/CmsEntryOpenSearchBodyModifier/index.js +1 -0
  28. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.d.ts +14 -0
  29. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js +42 -0
  30. package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -0
  31. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.d.ts +32 -0
  32. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js +5 -0
  33. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js.map +1 -0
  34. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.d.ts +11 -0
  35. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js +5 -0
  36. package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -0
  37. package/features/CmsEntryOpenSearchFieldIndex/constants.d.ts +1 -0
  38. package/features/CmsEntryOpenSearchFieldIndex/constants.js +4 -0
  39. package/features/CmsEntryOpenSearchFieldIndex/constants.js.map +1 -0
  40. package/features/CmsEntryOpenSearchFieldIndex/feature.d.ts +4 -0
  41. package/features/CmsEntryOpenSearchFieldIndex/feature.js +29 -0
  42. package/features/CmsEntryOpenSearchFieldIndex/feature.js.map +1 -0
  43. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.d.ts +11 -0
  44. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js +60 -0
  45. package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js.map +1 -0
  46. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.d.ts +13 -0
  47. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js +33 -0
  48. package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js.map +1 -0
  49. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.d.ts +10 -0
  50. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js +21 -0
  51. package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js.map +1 -0
  52. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.d.ts +10 -0
  53. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js +22 -0
  54. package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js.map +1 -0
  55. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.d.ts +11 -0
  56. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js +32 -0
  57. package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js.map +1 -0
  58. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.d.ts +12 -0
  59. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js +107 -0
  60. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js.map +1 -0
  61. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.d.ts +10 -0
  62. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js +21 -0
  63. package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js.map +1 -0
  64. package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.d.ts +15 -0
  65. package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js +40 -0
  66. package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js.map +1 -0
  67. package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.d.ts +15 -0
  68. package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js +40 -0
  69. package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js.map +1 -0
  70. package/features/CmsEntryOpenSearchFieldIndex/index.d.ts +3 -0
  71. package/features/CmsEntryOpenSearchFieldIndex/index.js +3 -0
  72. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.d.ts +11 -0
  73. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js +36 -0
  74. package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js.map +1 -0
  75. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.d.ts +37 -0
  76. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js +5 -0
  77. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js.map +1 -0
  78. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.d.ts +9 -0
  79. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js +5 -0
  80. package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js.map +1 -0
  81. package/features/CmsEntryOpenSearchFilter/constants.d.ts +1 -0
  82. package/features/CmsEntryOpenSearchFilter/constants.js +4 -0
  83. package/features/CmsEntryOpenSearchFilter/constants.js.map +1 -0
  84. package/features/CmsEntryOpenSearchFilter/feature.d.ts +4 -0
  85. package/features/CmsEntryOpenSearchFilter/feature.js +17 -0
  86. package/features/CmsEntryOpenSearchFilter/feature.js.map +1 -0
  87. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.d.ts +9 -0
  88. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js +26 -0
  89. package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js.map +1 -0
  90. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.d.ts +9 -0
  91. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js +43 -0
  92. package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js.map +1 -0
  93. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.d.ts +9 -0
  94. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js +36 -0
  95. package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js.map +1 -0
  96. package/features/CmsEntryOpenSearchFilter/index.d.ts +3 -0
  97. package/features/CmsEntryOpenSearchFilter/index.js +3 -0
  98. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.d.ts +20 -0
  99. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js +5 -0
  100. package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js.map +1 -0
  101. package/features/CmsEntryOpenSearchFullTextSearch/index.d.ts +1 -0
  102. package/features/CmsEntryOpenSearchFullTextSearch/index.js +1 -0
  103. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.d.ts +11 -0
  104. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js +17 -0
  105. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js.map +1 -0
  106. package/features/CmsEntryOpenSearchIndex/abstractions.d.ts +14 -0
  107. package/features/CmsEntryOpenSearchIndex/abstractions.js +5 -0
  108. package/features/CmsEntryOpenSearchIndex/abstractions.js.map +1 -0
  109. package/features/CmsEntryOpenSearchIndex/feature.d.ts +4 -0
  110. package/features/CmsEntryOpenSearchIndex/feature.js +11 -0
  111. package/features/CmsEntryOpenSearchIndex/feature.js.map +1 -0
  112. package/features/CmsEntryOpenSearchIndex/index.d.ts +3 -0
  113. package/features/CmsEntryOpenSearchIndex/index.js +3 -0
  114. package/features/CmsEntryOpenSearchQueryModifier/abstractions.d.ts +16 -0
  115. package/features/CmsEntryOpenSearchQueryModifier/abstractions.js +5 -0
  116. package/features/CmsEntryOpenSearchQueryModifier/abstractions.js.map +1 -0
  117. package/features/CmsEntryOpenSearchQueryModifier/index.d.ts +1 -0
  118. package/features/CmsEntryOpenSearchQueryModifier/index.js +1 -0
  119. package/features/CmsEntryOpenSearchSortModifier/abstractions.d.ts +15 -0
  120. package/features/CmsEntryOpenSearchSortModifier/abstractions.js +5 -0
  121. package/features/CmsEntryOpenSearchSortModifier/abstractions.js.map +1 -0
  122. package/features/CmsEntryOpenSearchSortModifier/index.d.ts +1 -0
  123. package/features/CmsEntryOpenSearchSortModifier/index.js +1 -0
  124. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.d.ts +12 -0
  125. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js +31 -0
  126. package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -0
  127. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.d.ts +22 -0
  128. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js +5 -0
  129. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js.map +1 -0
  130. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.d.ts +10 -0
  131. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js +5 -0
  132. package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -0
  133. package/features/CmsEntryOpenSearchValueSearch/feature.d.ts +4 -0
  134. package/features/CmsEntryOpenSearchValueSearch/feature.js +17 -0
  135. package/features/CmsEntryOpenSearchValueSearch/feature.js.map +1 -0
  136. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.d.ts +10 -0
  137. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js +21 -0
  138. package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js.map +1 -0
  139. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.d.ts +10 -0
  140. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js +44 -0
  141. package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js.map +1 -0
  142. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.d.ts +10 -0
  143. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js +22 -0
  144. package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js.map +1 -0
  145. package/features/CmsEntryOpenSearchValueSearch/index.d.ts +3 -0
  146. package/features/CmsEntryOpenSearchValueSearch/index.js +3 -0
  147. package/features/CmsEntryOpenSearchValuesModifier/abstractions.d.ts +23 -0
  148. package/features/CmsEntryOpenSearchValuesModifier/abstractions.js +5 -0
  149. package/features/CmsEntryOpenSearchValuesModifier/abstractions.js.map +1 -0
  150. package/features/CmsEntryOpenSearchValuesModifier/index.d.ts +1 -0
  151. package/features/CmsEntryOpenSearchValuesModifier/index.js +1 -0
  152. package/helpers/entryIndexHelpers.d.ts +6 -4
  153. package/helpers/entryIndexHelpers.js +70 -186
  154. package/helpers/entryIndexHelpers.js.map +1 -1
  155. package/helpers/fieldIdentifier.js +18 -30
  156. package/helpers/fieldIdentifier.js.map +1 -1
  157. package/helpers/index.js +0 -2
  158. package/index.d.ts +1 -3
  159. package/index.js +1 -190
  160. package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -0
  161. package/operations/entry/dataLoader/DataLoaderCache.js +22 -29
  162. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
  163. package/operations/entry/dataLoader/constants.js +2 -1
  164. package/operations/entry/dataLoader/constants.js.map +1 -1
  165. package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
  166. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
  167. package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -26
  168. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
  169. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +28 -34
  170. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
  171. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +28 -34
  172. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
  173. package/operations/entry/dataLoader/getRevisionById.js +33 -43
  174. package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
  175. package/operations/entry/dataLoader/index.js +8 -9
  176. package/operations/entry/dataLoader/index.js.map +1 -1
  177. package/operations/entry/dataLoader/types.d.ts +1 -0
  178. package/operations/entry/dataLoader/types.js +0 -3
  179. package/operations/entry/dataLoaders.js +81 -97
  180. package/operations/entry/dataLoaders.js.map +1 -1
  181. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +1 -1
  182. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +6 -24
  183. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
  184. package/operations/entry/elasticsearch/body.d.ts +19 -3
  185. package/operations/entry/elasticsearch/body.js +74 -122
  186. package/operations/entry/elasticsearch/body.js.map +1 -1
  187. package/operations/entry/elasticsearch/fields/createSystemField.d.ts +4 -0
  188. package/operations/entry/elasticsearch/fields/createSystemField.js +9 -0
  189. package/operations/entry/elasticsearch/fields/createSystemField.js.map +1 -0
  190. package/operations/entry/elasticsearch/fields/live.d.ts +2 -0
  191. package/operations/entry/elasticsearch/fields/live.js +50 -0
  192. package/operations/entry/elasticsearch/fields/live.js.map +1 -0
  193. package/operations/entry/elasticsearch/fields/location.d.ts +2 -0
  194. package/operations/entry/elasticsearch/fields/location.js +50 -0
  195. package/operations/entry/elasticsearch/fields/location.js.map +1 -0
  196. package/operations/entry/elasticsearch/fields/state.d.ts +2 -0
  197. package/operations/entry/elasticsearch/fields/state.js +104 -0
  198. package/operations/entry/elasticsearch/fields/state.js.map +1 -0
  199. package/operations/entry/elasticsearch/fields.d.ts +6 -4
  200. package/operations/entry/elasticsearch/fields.js +194 -388
  201. package/operations/entry/elasticsearch/fields.js.map +1 -1
  202. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +6 -5
  203. package/operations/entry/elasticsearch/filtering/applyFiltering.js +32 -45
  204. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
  205. package/operations/entry/elasticsearch/filtering/exec.d.ts +6 -2
  206. package/operations/entry/elasticsearch/filtering/exec.js +84 -166
  207. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  208. package/operations/entry/elasticsearch/filtering/index.js +0 -2
  209. package/operations/entry/elasticsearch/filtering/path.d.ts +4 -3
  210. package/operations/entry/elasticsearch/filtering/path.js +24 -35
  211. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  212. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -2
  213. package/operations/entry/elasticsearch/filtering/populated.js +8 -14
  214. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
  215. package/operations/entry/elasticsearch/filtering/values.js +11 -12
  216. package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
  217. package/operations/entry/elasticsearch/fullTextSearch.d.ts +7 -6
  218. package/operations/entry/elasticsearch/fullTextSearch.js +45 -79
  219. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  220. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +4 -4
  221. package/operations/entry/elasticsearch/fullTextSearchFields.js +7 -17
  222. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
  223. package/operations/entry/elasticsearch/initialQuery.d.ts +3 -3
  224. package/operations/entry/elasticsearch/initialQuery.js +37 -80
  225. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  226. package/operations/entry/elasticsearch/keyword.js +13 -27
  227. package/operations/entry/elasticsearch/keyword.js.map +1 -1
  228. package/operations/entry/elasticsearch/plugins/operator.d.ts +2 -2
  229. package/operations/entry/elasticsearch/plugins/operator.js +10 -21
  230. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
  231. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +6 -4
  232. package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -1
  233. package/operations/entry/elasticsearch/sort.d.ts +4 -4
  234. package/operations/entry/elasticsearch/sort.js +69 -96
  235. package/operations/entry/elasticsearch/sort.js.map +1 -1
  236. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +2 -9
  237. package/operations/entry/elasticsearch/transformValueForSearch.js +9 -24
  238. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
  239. package/operations/entry/elasticsearch/types.d.ts +3 -10
  240. package/operations/entry/elasticsearch/types.js +0 -3
  241. package/operations/entry/index.d.ts +22 -2
  242. package/operations/entry/index.js +1316 -1650
  243. package/operations/entry/index.js.map +1 -1
  244. package/operations/entry/keys.js +43 -63
  245. package/operations/entry/keys.js.map +1 -1
  246. package/operations/entry/recordType.js +4 -9
  247. package/operations/entry/recordType.js.map +1 -1
  248. package/operations/entry/transformations/convertEntryKeys.js +21 -26
  249. package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
  250. package/operations/entry/transformations/index.d.ts +6 -2
  251. package/operations/entry/transformations/index.js +84 -112
  252. package/operations/entry/transformations/index.js.map +1 -1
  253. package/operations/entry/transformations/modifyEntryValues.d.ts +6 -4
  254. package/operations/entry/transformations/modifyEntryValues.js +12 -17
  255. package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
  256. package/operations/entry/transformations/transformEntryKeys.js +13 -16
  257. package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
  258. package/operations/entry/transformations/transformEntryToIndex.d.ts +2 -2
  259. package/operations/entry/transformations/transformEntryToIndex.js +16 -20
  260. package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
  261. package/operations/group/index.d.ts +2 -2
  262. package/operations/group/index.js +115 -139
  263. package/operations/group/index.js.map +1 -1
  264. package/operations/model/index.d.ts +1 -1
  265. package/operations/model/index.js +128 -157
  266. package/operations/model/index.js.map +1 -1
  267. package/package.json +35 -30
  268. package/tasks/createIndexTaskPlugin.js +36 -32
  269. package/tasks/createIndexTaskPlugin.js.map +1 -1
  270. package/types.d.ts +7 -112
  271. package/types.js +7 -36
  272. package/types.js.map +1 -1
  273. package/values/NoValueContainer.js +8 -10
  274. package/values/NoValueContainer.js.map +1 -1
  275. package/definitions/types.js.map +0 -1
  276. package/dynamoDb/index.d.ts +0 -3
  277. package/dynamoDb/index.js +0 -8
  278. package/dynamoDb/index.js.map +0 -1
  279. package/dynamoDb/storage/longText.d.ts +0 -10
  280. package/dynamoDb/storage/longText.js +0 -88
  281. package/dynamoDb/storage/longText.js.map +0 -1
  282. package/dynamoDb/storage/richText.d.ts +0 -2
  283. package/dynamoDb/storage/richText.js +0 -51
  284. package/dynamoDb/storage/richText.js.map +0 -1
  285. package/elasticsearch/index.d.ts +0 -2
  286. package/elasticsearch/index.js +0 -5
  287. package/elasticsearch/index.js.map +0 -1
  288. package/elasticsearch/indexing/dateTimeIndexing.d.ts +0 -3
  289. package/elasticsearch/indexing/dateTimeIndexing.js +0 -81
  290. package/elasticsearch/indexing/dateTimeIndexing.js.map +0 -1
  291. package/elasticsearch/indexing/defaultFieldIndexing.d.ts +0 -3
  292. package/elasticsearch/indexing/defaultFieldIndexing.js +0 -47
  293. package/elasticsearch/indexing/defaultFieldIndexing.js.map +0 -1
  294. package/elasticsearch/indexing/index.d.ts +0 -2
  295. package/elasticsearch/indexing/index.js +0 -10
  296. package/elasticsearch/indexing/index.js.map +0 -1
  297. package/elasticsearch/indexing/jsonIndexing.d.ts +0 -2
  298. package/elasticsearch/indexing/jsonIndexing.js +0 -21
  299. package/elasticsearch/indexing/jsonIndexing.js.map +0 -1
  300. package/elasticsearch/indexing/longTextIndexing.d.ts +0 -7
  301. package/elasticsearch/indexing/longTextIndexing.js +0 -35
  302. package/elasticsearch/indexing/longTextIndexing.js.map +0 -1
  303. package/elasticsearch/indexing/numberIndexing.d.ts +0 -3
  304. package/elasticsearch/indexing/numberIndexing.js +0 -34
  305. package/elasticsearch/indexing/numberIndexing.js.map +0 -1
  306. package/elasticsearch/indexing/objectIndexing.d.ts +0 -12
  307. package/elasticsearch/indexing/objectIndexing.js +0 -194
  308. package/elasticsearch/indexing/objectIndexing.js.map +0 -1
  309. package/elasticsearch/indexing/richTextIndexing.d.ts +0 -3
  310. package/elasticsearch/indexing/richTextIndexing.js +0 -24
  311. package/elasticsearch/indexing/richTextIndexing.js.map +0 -1
  312. package/elasticsearch/indices/base.d.ts +0 -2
  313. package/elasticsearch/indices/base.js +0 -7
  314. package/elasticsearch/indices/base.js.map +0 -1
  315. package/elasticsearch/indices/index.d.ts +0 -1
  316. package/elasticsearch/indices/index.js +0 -6
  317. package/elasticsearch/indices/index.js.map +0 -1
  318. package/elasticsearch/search/index.d.ts +0 -3
  319. package/elasticsearch/search/index.js +0 -6
  320. package/elasticsearch/search/index.js.map +0 -1
  321. package/elasticsearch/search/refSearch.d.ts +0 -2
  322. package/elasticsearch/search/refSearch.js +0 -24
  323. package/elasticsearch/search/refSearch.js.map +0 -1
  324. package/elasticsearch/search/searchableJson.d.ts +0 -2
  325. package/elasticsearch/search/searchableJson.js +0 -53
  326. package/elasticsearch/search/searchableJson.js.map +0 -1
  327. package/elasticsearch/search/timeSearch.d.ts +0 -2
  328. package/elasticsearch/search/timeSearch.js +0 -20
  329. package/elasticsearch/search/timeSearch.js.map +0 -1
  330. package/helpers/index.js.map +0 -1
  331. package/index.js.map +0 -1
  332. package/operations/entry/dataLoader/types.js.map +0 -1
  333. package/operations/entry/elasticsearch/filtering/index.js.map +0 -1
  334. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +0 -2
  335. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +0 -22
  336. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +0 -1
  337. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +0 -1
  338. package/operations/entry/elasticsearch/filtering/plugins/index.js +0 -8
  339. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +0 -1
  340. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +0 -2
  341. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +0 -61
  342. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +0 -1
  343. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +0 -2
  344. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +0 -49
  345. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +0 -1
  346. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +0 -9
  347. package/operations/entry/elasticsearch/plugins/bodyModifier.js +0 -11
  348. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +0 -1
  349. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +0 -9
  350. package/operations/entry/elasticsearch/plugins/queryModifier.js +0 -11
  351. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +0 -1
  352. package/operations/entry/elasticsearch/plugins/search.d.ts +0 -7
  353. package/operations/entry/elasticsearch/plugins/search.js +0 -18
  354. package/operations/entry/elasticsearch/plugins/search.js.map +0 -1
  355. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +0 -9
  356. package/operations/entry/elasticsearch/plugins/sortModifier.js +0 -11
  357. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +0 -1
  358. package/operations/entry/elasticsearch/types.js.map +0 -1
  359. package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +0 -69
  360. package/plugins/CmsElasticsearchModelFieldPlugin.js +0 -46
  361. package/plugins/CmsElasticsearchModelFieldPlugin.js.map +0 -1
  362. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +0 -22
  363. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +0 -13
  364. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +0 -1
  365. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +0 -23
  366. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +0 -19
  367. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +0 -1
  368. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +0 -4
  369. package/plugins/CmsEntryElasticsearchIndexPlugin.js +0 -6
  370. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +0 -1
  371. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +0 -32
  372. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +0 -32
  373. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +0 -1
  374. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +0 -19
  375. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +0 -13
  376. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +0 -1
  377. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +0 -19
  378. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +0 -13
  379. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +0 -1
  380. package/plugins/CmsEntryElasticsearchValuesModifier.d.ts +0 -33
  381. package/plugins/CmsEntryElasticsearchValuesModifier.js +0 -42
  382. package/plugins/CmsEntryElasticsearchValuesModifier.js.map +0 -1
  383. package/plugins/CmsEntryFilterPlugin.d.ts +0 -49
  384. package/plugins/CmsEntryFilterPlugin.js +0 -15
  385. package/plugins/CmsEntryFilterPlugin.js.map +0 -1
  386. package/plugins/index.d.ts +0 -8
  387. package/plugins/index.js +0 -10
  388. package/plugins/index.js.map +0 -1
@@ -1,1699 +1,1365 @@
1
- import WebinyError from "@webiny/error";
1
+ import { WebinyError } from "@webiny/error";
2
2
  import { CONTENT_ENTRY_STATUS } from "@webiny/api-headless-cms/types/index.js";
3
3
  import { extractEntriesFromIndex } from "../../helpers/index.js";
4
4
  import { configurations } from "../../configurations.js";
5
+ import { createLimit, decodeCursor, encodeCursor } from "@webiny/api-opensearch";
5
6
  import { DataLoadersHandler } from "./dataLoaders.js";
6
7
  import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys, createLatestSortKey, createPartitionKey, createPublishedSortKey, createRevisionSortKey } from "./keys.js";
7
- import { compress, createLimit, decodeCursor, decompress, encodeCursor } from "@webiny/api-elasticsearch";
8
+ import { getTotalCount } from "@webiny/api-opensearch/types.js";
8
9
  import { createElasticsearchBody } from "./elasticsearch/body.js";
9
10
  import { shouldIgnoreEsResponseError } from "./elasticsearch/shouldIgnoreEsResponseError.js";
10
11
  import { StorageOperationsCmsModelPlugin } from "@webiny/api-headless-cms";
11
12
  import { createTransformer } from "./transformations/index.js";
12
13
  import { convertEntryKeysFromStorage } from "./transformations/convertEntryKeys.js";
13
14
  import { isDeletedEntryMetaField, isEntryLevelEntryMetaField, isRestoredEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
14
- const convertToStorageEntry = params => {
15
- const {
16
- model,
17
- storageEntry
18
- } = params;
19
- const values = model.convertValueKeyToStorage({
20
- fields: model.fields,
21
- values: storageEntry.values
22
- });
23
- return {
24
- ...storageEntry,
25
- values
26
- };
27
- };
28
- export const createEntriesStorageOperations = params => {
29
- const {
30
- entity,
31
- esEntity,
32
- elasticsearch,
33
- plugins
34
- } = params;
35
- let storageOperationsCmsModelPlugin;
36
- const getStorageOperationsCmsModelPlugin = () => {
37
- if (storageOperationsCmsModelPlugin) {
38
- return storageOperationsCmsModelPlugin;
39
- }
40
- storageOperationsCmsModelPlugin = plugins.oneByType(StorageOperationsCmsModelPlugin.type);
41
- return storageOperationsCmsModelPlugin;
42
- };
43
- const getStorageOperationsModel = model => {
44
- const plugin = getStorageOperationsCmsModelPlugin();
45
- return plugin.getModel(model);
46
- };
47
- const dataLoaders = new DataLoadersHandler({
48
- entity
49
- });
50
- const create = async (initialModel, params) => {
51
- const {
52
- entry: initialEntry,
53
- storageEntry: initialStorageEntry
54
- } = params;
55
- const model = getStorageOperationsModel(initialModel);
56
- const isPublished = initialEntry.status === "published";
57
- const locked = isPublished ? true : initialEntry.locked;
58
- initialEntry.locked = locked;
59
- initialStorageEntry.locked = locked;
60
- const transformer = createTransformer({
61
- plugins,
62
- model,
63
- entry: initialEntry,
64
- storageEntry: initialStorageEntry
15
+ const convertToStorageEntry = (params)=>{
16
+ const { model, storageEntry } = params;
17
+ const values = model.convertValueKeyToStorage({
18
+ fields: model.fields,
19
+ values: storageEntry.values
65
20
  });
66
- const {
67
- entry,
68
- storageEntry
69
- } = transformer.transformEntryKeys();
70
- const esEntry = transformer.transformToIndex();
71
- const {
72
- index: esIndex
73
- } = configurations.es({
74
- model
21
+ return {
22
+ ...storageEntry,
23
+ values
24
+ };
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;
33
+ };
34
+ const getStorageOperationsModel = (model)=>{
35
+ const plugin = getStorageOperationsCmsModelPlugin();
36
+ return plugin.getModel(model);
37
+ };
38
+ const dataLoaders = new DataLoadersHandler({
39
+ entity
75
40
  });
76
- const revisionKeys = createEntryRevisionKeys(entry);
77
- const latestKeys = createEntryLatestKeys(entry);
78
- const publishedKeys = createEntryPublishedKeys(entry);
79
- const entityBatch = entity.createEntityWriter({
80
- put: [{
81
- ...revisionKeys,
82
- data: {
83
- ...storageEntry,
84
- locked
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
+ });
85
100
  }
86
- }, {
87
- ...latestKeys,
88
- data: {
89
- ...storageEntry,
90
- locked
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
+ });
91
118
  }
92
- }]
93
- });
94
- if (isPublished) {
95
- entityBatch.put({
96
- ...publishedKeys,
97
- data: {
98
- ...storageEntry,
99
- locked
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
+ });
100
127
  }
101
- });
102
- }
103
- try {
104
- await entityBatch.execute();
105
- dataLoaders.clearAll({
106
- model
107
- });
108
- } catch (ex) {
109
- throw new WebinyError(ex.message || "Could not insert entry data into the DynamoDB table.", ex.code || "CREATE_ENTRY_ERROR", {
110
- error: ex,
111
- entry,
112
- storageEntry
113
- });
114
- }
115
- const esLatestData = await transformer.getElasticsearchLatestEntryData();
116
- const elasticsearchEntityBatch = esEntity.createEntityWriter({
117
- put: [{
118
- ...latestKeys,
119
- index: esIndex,
120
- data: esLatestData
121
- }]
122
- });
123
- if (isPublished) {
124
- const esPublishedData = await transformer.getElasticsearchPublishedEntryData();
125
- elasticsearchEntityBatch.put({
126
- ...publishedKeys,
127
- index: esIndex,
128
- data: esPublishedData
129
- });
130
- }
131
- try {
132
- await elasticsearchEntityBatch.execute();
133
- } catch (ex) {
134
- throw new WebinyError(ex.message || "Could not insert entry data into the Elasticsearch DynamoDB table.", ex.code || "CREATE_ES_ENTRY_ERROR", {
135
- error: ex,
136
- entry,
137
- esEntry
138
- });
139
- }
140
- return initialStorageEntry;
141
- };
142
- const createRevisionFrom = async (initialModel, params) => {
143
- const {
144
- entry: initialEntry,
145
- storageEntry: initialStorageEntry
146
- } = params;
147
- const model = getStorageOperationsModel(initialModel);
148
- const transformer = createTransformer({
149
- plugins,
150
- model,
151
- entry: initialEntry,
152
- storageEntry: initialStorageEntry
153
- });
154
- const {
155
- entry,
156
- storageEntry
157
- } = transformer.transformEntryKeys();
158
- const revisionKeys = createEntryRevisionKeys(entry);
159
- const latestKeys = createEntryLatestKeys(entry);
160
- const publishedKeys = createEntryPublishedKeys(entry);
161
-
162
- // We'll need this flag below.
163
- const isPublished = entry.status === "published";
164
- const esLatestData = await transformer.getElasticsearchLatestEntryData();
165
- const entityBatch = entity.createEntityWriter({
166
- put: [{
167
- ...revisionKeys,
168
- data: storageEntry
169
- }, {
170
- ...latestKeys,
171
- data: storageEntry
172
- }]
173
- });
174
- if (isPublished) {
175
- entityBatch.put({
176
- ...publishedKeys,
177
- data: storageEntry
178
- });
179
-
180
- // Unpublish previously published revision (if any).
181
- const [publishedRevisionStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
182
- model,
183
- ids: [entry.id]
184
- });
185
- if (publishedRevisionStorageEntry) {
186
- const publishedRevisionKey = createEntryRevisionKeys(publishedRevisionStorageEntry);
187
- entityBatch.put({
188
- ...publishedRevisionKey,
189
- data: {
190
- ...publishedRevisionStorageEntry,
191
- status: CONTENT_ENTRY_STATUS.UNPUBLISHED
192
- }
193
- });
194
- }
195
- }
196
- try {
197
- await entityBatch.execute();
198
- dataLoaders.clearAll({
199
- model
200
- });
201
- } catch (ex) {
202
- throw new WebinyError(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
203
- error: ex,
204
- entry,
205
- storageEntry
206
- });
207
- }
208
- const {
209
- index: esIndex
210
- } = configurations.es({
211
- model
212
- });
213
- const elasticsearchEntityBatch = esEntity.createEntityWriter({
214
- put: [{
215
- ...latestKeys,
216
- index: esIndex,
217
- data: esLatestData
218
- }]
219
- });
220
- if (isPublished) {
221
- const esPublishedData = await transformer.getElasticsearchPublishedEntryData();
222
- elasticsearchEntityBatch.put({
223
- ...publishedKeys,
224
- index: esIndex,
225
- data: esPublishedData
226
- });
227
- }
228
- try {
229
- await elasticsearchEntityBatch.execute();
230
- } catch (ex) {
231
- throw new WebinyError(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
232
- error: ex,
233
- entry
234
- });
235
- }
236
- /**
237
- * There are no modifications on the entry created so just return the data.
238
- */
239
- return initialStorageEntry;
240
- };
241
- const update = async (initialModel, params) => {
242
- const {
243
- entry: initialEntry,
244
- storageEntry: initialStorageEntry
245
- } = params;
246
- const model = getStorageOperationsModel(initialModel);
247
- const transformer = createTransformer({
248
- plugins,
249
- model,
250
- entry: initialEntry,
251
- storageEntry: initialStorageEntry
252
- });
253
- const {
254
- entry,
255
- storageEntry
256
- } = transformer.transformEntryKeys();
257
- const isPublished = entry.status === "published";
258
- const locked = isPublished ? true : entry.locked;
259
- const revisionKeys = createEntryRevisionKeys(entry);
260
- const latestKeys = createEntryLatestKeys(entry);
261
- const publishedKeys = createEntryPublishedKeys(entry);
262
-
263
- /**
264
- * We need the latest entry to check if it needs to be updated.
265
- */
266
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
267
- model,
268
- ids: [entry.id]
269
- });
270
- const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
271
- model,
272
- ids: [entry.id]
273
- });
274
- const entityBatch = entity.createEntityWriter({
275
- put: [{
276
- ...revisionKeys,
277
- data: {
278
- ...storageEntry,
279
- locked
128
+ return initialStorageEntry;
129
+ };
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
+ }
280
180
  }
281
- }]
282
- });
283
- if (isPublished) {
284
- entityBatch.put({
285
- ...publishedKeys,
286
- data: {
287
- ...storageEntry,
288
- locked
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
+ });
289
192
  }
290
- });
291
- }
292
- const elasticsearchEntityBatch = esEntity.createEntityWriter();
293
- const {
294
- index: esIndex
295
- } = configurations.es({
296
- model
297
- });
298
-
299
- /**
300
- * If the latest entry is the one being updated, we need to create a new latest entry records.
301
- */
302
- if (latestStorageEntry) {
303
- const updatingLatestRevision = latestStorageEntry.id === entry.id;
304
- if (updatingLatestRevision) {
305
- /**
306
- * First we update the regular DynamoDB table.
307
- */
308
- entityBatch.put({
309
- ...latestKeys,
310
- data: storageEntry
193
+ const { index: esIndex } = configurations.es({
194
+ model
311
195
  });
312
-
313
- /**
314
- * And then update the Elasticsearch table to propagate changes to the Elasticsearch
315
- */
316
- const elasticsearchLatestData = await transformer.getElasticsearchLatestEntryData();
317
- elasticsearchEntityBatch.put({
318
- ...latestKeys,
319
- index: esIndex,
320
- data: elasticsearchLatestData
321
- });
322
- } else {
323
- /**
324
- * If not updating latest revision, we still want to update the latest revision's
325
- * entry-level meta fields to match the current revision's entry-level meta fields.
326
- */
327
- const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
328
- const updatedLatestStorageEntry = {
329
- ...latestKeys,
330
- data: {
331
- ...latestStorageEntry,
332
- ...updatedEntryLevelMetaFields
333
- }
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;
222
+ };
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;
351
+ };
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
+ }
334
363
  };
335
-
336
- /**
337
- * First we update the regular DynamoDB table. Two updates are needed:
338
- * - one for the actual revision record
339
- * - one for the latest record
340
- */
341
- entityBatch.put({
342
- ...updatedLatestStorageEntry,
343
- PK: createPartitionKey({
344
- id: latestStorageEntry.id,
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
+ }
434
+ };
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,
345
449
  tenant: model.tenant
346
- }),
347
- SK: createRevisionSortKey(latestStorageEntry)
348
450
  });
349
- entityBatch.put({
350
- ...updatedLatestStorageEntry
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
351
498
  });
352
-
353
- /**
354
- * Update the Elasticsearch table to propagate changes to the Elasticsearch.
355
- */
356
- const latestEsEntry = await esEntity.getClean(latestKeys);
357
- if (latestEsEntry) {
358
- const latestEsEntryDataDecompressed = await decompress(plugins, latestEsEntry.data);
359
- const updatedLatestEntry = await compress(plugins, {
360
- ...latestEsEntryDataDecompressed,
361
- ...updatedEntryLevelMetaFields
362
- });
363
- elasticsearchEntityBatch.put({
364
- ...latestKeys,
365
- index: esIndex,
366
- data: updatedLatestEntry
367
- });
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
+ });
368
528
  }
369
- }
370
- }
371
- if (isPublished && publishedStorageEntry?.id === entry.id) {
372
- const elasticsearchPublishedData = await transformer.getElasticsearchPublishedEntryData();
373
- elasticsearchEntityBatch.put({
374
- ...publishedKeys,
375
- index: esIndex,
376
- data: elasticsearchPublishedData
377
- });
378
- }
379
- try {
380
- await entityBatch.execute();
381
- dataLoaders.clearAll({
382
- model
383
- });
384
- } catch (ex) {
385
- throw new WebinyError(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
386
- error: ex,
387
- entry,
388
- storageEntry
389
- });
390
- }
391
- try {
392
- await elasticsearchEntityBatch.execute();
393
- } catch (ex) {
394
- throw new WebinyError(ex.message || "Could not update entry DynamoDB Elasticsearch records.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
395
- error: ex,
396
- entry
397
- });
398
- }
399
- return initialStorageEntry;
400
- };
401
- const move = async (initialModel, id, folderId) => {
402
- const model = getStorageOperationsModel(initialModel);
403
- const partitionKey = createPartitionKey({
404
- id,
405
- tenant: model.tenant
406
- });
407
- /**
408
- * First we need to fetch all the records in the regular DynamoDB table.
409
- */
410
- const queryAllParams = {
411
- partitionKey,
412
- options: {
413
- gte: " "
414
- }
415
529
  };
416
- const latestSortKey = createLatestSortKey();
417
- const publishedSortKey = createPublishedSortKey();
418
- const records = await entity.queryAll(queryAllParams);
419
- /**
420
- * Then update the folderId in each record and prepare it to be stored.
421
- */
422
- let latestRecord = undefined;
423
- let publishedRecord = undefined;
424
- const entityBatch = entity.createEntityWriter();
425
- for (const record of records) {
426
- entityBatch.put({
427
- ...record,
428
- data: {
429
- ...record.data,
430
- location: {
431
- ...record.data.location,
432
- folderId
433
- }
530
+ const restoreFromBin = async (initialModel, params)=>{
531
+ const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
532
+ const model = getStorageOperationsModel(initialModel);
533
+ const transformer = createTransformer({
534
+ valuesModifiers,
535
+ model,
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;
434
572
  }
435
- });
436
-
437
- /**
438
- * We need to get the published and latest records, so we can update the Elasticsearch.
439
- */
440
- if (record.SK === publishedSortKey) {
441
- publishedRecord = record.data;
442
- } else if (record.SK === latestSortKey) {
443
- latestRecord = record.data;
444
- }
445
- }
446
- try {
447
- await entityBatch.execute();
448
- dataLoaders.clearAll({
449
- model
450
- });
451
- } catch (ex) {
452
- throw new WebinyError(ex.message || "Could not move all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_ERROR", {
453
- error: ex,
454
- id
455
- });
456
- }
457
- const esEntityReader = esEntity.createEntityReader();
458
- if (publishedRecord) {
459
- esEntityReader.get({
460
- PK: partitionKey,
461
- SK: publishedSortKey
462
- });
463
- }
464
- if (latestRecord) {
465
- esEntityReader.get({
466
- PK: partitionKey,
467
- SK: latestSortKey
468
- });
469
- }
470
- if (esEntityReader.total === 0) {
471
- return;
472
- }
473
- const esRecords = await esEntityReader.execute();
474
- const esItems = (await Promise.all(esRecords.map(async record => {
475
- if (!record) {
476
- return null;
477
- }
478
- return {
479
- ...record,
480
- data: await decompress(plugins, record.data)
481
- };
482
- }))).filter(item => !!item);
483
- if (esItems.length === 0) {
484
- return;
485
- }
486
- try {
487
- const elasticsearchEntityBatch = esEntity.createEntityWriter({
488
- put: await Promise.all(esItems.map(async item => {
489
- return {
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({
490
605
  ...item,
491
- data: await compress(plugins, {
492
- ...item.data,
493
- location: {
494
- ...item.data?.location,
495
- folderId
496
- }
606
+ data: await compressionHandler.compress({
607
+ ...item.data,
608
+ ...updatedEntryMetaFields,
609
+ wbyDeleted: entry.wbyDeleted,
610
+ location: entry.location,
611
+ binOriginalFolderId: entry.binOriginalFolderId
497
612
  })
498
- };
499
- }))
500
- });
501
- await elasticsearchEntityBatch.execute();
502
- } catch (ex) {
503
- throw new WebinyError(ex.message || "Could not move entry DynamoDB Elasticsearch records.", ex.code || "MOVE_ES_ENTRY_ERROR", {
504
- error: ex,
505
- partitionKey
506
- });
507
- }
508
- };
509
- const moveToBin = async (initialModel, params) => {
510
- const {
511
- entry: initialEntry,
512
- storageEntry: initialStorageEntry
513
- } = params;
514
- const model = getStorageOperationsModel(initialModel);
515
- const transformer = createTransformer({
516
- plugins,
517
- model,
518
- entry: initialEntry,
519
- storageEntry: initialStorageEntry
520
- });
521
- const {
522
- entry,
523
- storageEntry
524
- } = transformer.transformEntryKeys();
525
- const partitionKey = createPartitionKey({
526
- id: entry.id,
527
- tenant: model.tenant
528
- });
529
-
530
- /**
531
- * First we need to fetch all the records in the regular DynamoDB table.
532
- */
533
- const queryAllParams = {
534
- partitionKey,
535
- options: {
536
- gte: " "
537
- }
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;
538
624
  };
539
- const latestSortKey = createLatestSortKey();
540
- const publishedSortKey = createPublishedSortKey();
541
- const records = await entity.queryAll(queryAllParams);
542
-
543
- /**
544
- * Let's pick the `deleted` meta fields from the entry.
545
- */
546
- const updatedEntryMetaFields = pickEntryMetaFields(entry, isDeletedEntryMetaField);
547
-
548
- /**
549
- * Then update all the records with data received.
550
- */
551
- let latestRecord = undefined;
552
- let publishedRecord = undefined;
553
- const entityBatch = entity.createEntityWriter();
554
- for (const record of records) {
555
- entityBatch.put({
556
- ...record,
557
- data: {
558
- ...record.data,
559
- ...updatedEntryMetaFields,
560
- wbyDeleted: storageEntry.wbyDeleted,
561
- location: storageEntry.location,
562
- binOriginalFolderId: storageEntry.binOriginalFolderId
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
+ });
563
675
  }
564
- });
565
-
566
- /**
567
- * We need to get the published and latest records, so we can update the Elasticsearch.
568
- */
569
- if (record.SK === publishedSortKey) {
570
- publishedRecord = record.data;
571
- } else if (record.SK === latestSortKey) {
572
- latestRecord = record.data;
573
- }
574
- }
575
-
576
- /**
577
- * We write the records back to the primary DynamoDB table.
578
- */
579
- try {
580
- await entityBatch.execute();
581
- dataLoaders.clearAll({
582
- model
583
- });
584
- } catch (ex) {
585
- throw new WebinyError(ex.message || "Could mark as deleted all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
586
- error: ex,
587
- entry,
588
- storageEntry
589
- });
590
- }
591
-
592
- /**
593
- * We need to get the published and latest records from Elasticsearch.
594
- */
595
- const esEntityReader = esEntity.createEntityReader();
596
- if (publishedRecord) {
597
- esEntityReader.get({
598
- PK: partitionKey,
599
- SK: publishedSortKey
600
- });
601
- }
602
- if (latestRecord) {
603
- esEntityReader.get({
604
- PK: partitionKey,
605
- SK: latestSortKey
606
- });
607
- }
608
- if (esEntityReader.total === 0) {
609
- return;
610
- }
611
- const esRecords = await esEntityReader.execute();
612
- const esItems = (await Promise.all(esRecords.map(async record => {
613
- if (!record) {
614
- return null;
615
- }
616
- return {
617
- ...record,
618
- data: await decompress(plugins, record.data)
619
- };
620
- }))).filter(item => !!item);
621
- if (esItems.length === 0) {
622
- return;
623
- }
624
-
625
- /**
626
- * We update all ES records with data received.
627
- */
628
- const elasticsearchEntityBatch = esEntity.createEntityWriter();
629
- for (const item of esItems) {
630
- elasticsearchEntityBatch.put({
631
- ...item,
632
- data: await compress(plugins, {
633
- ...item.data,
634
- ...updatedEntryMetaFields,
635
- wbyDeleted: entry.wbyDeleted,
636
- location: entry.location,
637
- binOriginalFolderId: entry.binOriginalFolderId
638
- })
639
- });
640
- }
641
-
642
- /**
643
- * We write the records back to the primary DynamoDB Elasticsearch table.
644
- */
645
- try {
646
- await elasticsearchEntityBatch.execute();
647
- } catch (ex) {
648
- throw new WebinyError(ex.message || "Could not mark as deleted entry records from DynamoDB Elasticsearch table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
649
- error: ex,
650
- entry,
651
- storageEntry
652
- });
653
- }
654
- };
655
- const restoreFromBin = async (initialModel, params) => {
656
- const {
657
- entry: initialEntry,
658
- storageEntry: initialStorageEntry
659
- } = params;
660
- const model = getStorageOperationsModel(initialModel);
661
- const transformer = createTransformer({
662
- plugins,
663
- model,
664
- entry: initialEntry,
665
- storageEntry: initialStorageEntry
666
- });
667
- const {
668
- entry,
669
- storageEntry
670
- } = transformer.transformEntryKeys();
671
-
672
- /**
673
- * Let's pick the `restored` meta fields from the storage entry.
674
- */
675
- const updatedEntryMetaFields = pickEntryMetaFields(entry, isRestoredEntryMetaField);
676
- const partitionKey = createPartitionKey({
677
- id: entry.id,
678
- tenant: model.tenant
679
- });
680
-
681
- /**
682
- * First we need to fetch all the records in the regular DynamoDB table.
683
- */
684
- const queryAllParams = {
685
- partitionKey,
686
- options: {
687
- gte: " "
688
- }
689
676
  };
690
- const latestSortKey = createLatestSortKey();
691
- const publishedSortKey = createPublishedSortKey();
692
- const records = await entity.queryAll(queryAllParams);
693
-
694
- /**
695
- * Then update all the records with data received.
696
- */
697
- let latestRecord = undefined;
698
- let publishedRecord = undefined;
699
- const entityBatch = entity.createEntityWriter();
700
- for (const record of records) {
701
- entityBatch.put({
702
- ...record,
703
- data: {
704
- ...record.data,
705
- ...updatedEntryMetaFields,
706
- wbyDeleted: storageEntry.wbyDeleted,
707
- location: storageEntry.location,
708
- binOriginalFolderId: storageEntry.binOriginalFolderId
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
+ });
709
711
  }
710
- });
711
-
712
- /**
713
- * We need to get the published and latest records, so we can update the Elasticsearch.
714
- */
715
- if (record.SK === publishedSortKey) {
716
- publishedRecord = record.data;
717
- } else if (record.SK === latestSortKey) {
718
- latestRecord = record.data;
719
- }
720
- }
721
-
722
- /**
723
- * We write the records back to the primary DynamoDB table.
724
- */
725
- try {
726
- await entityBatch.execute();
727
- dataLoaders.clearAll({
728
- model
729
- });
730
- } catch (ex) {
731
- throw new WebinyError(ex.message || "Could not restore all entry records from in the DynamoDB table.", ex.code || "RESTORE_ENTRY_ERROR", {
732
- error: ex,
733
- entry,
734
- storageEntry
735
- });
736
- }
737
-
738
- /**
739
- * We need to get the published and latest records from Elasticsearch.
740
- */
741
- const esEntityReader = esEntity.createEntityReader();
742
- if (publishedRecord) {
743
- esEntityReader.get({
744
- PK: partitionKey,
745
- SK: publishedSortKey
746
- });
747
- }
748
- if (latestRecord) {
749
- esEntityReader.get({
750
- PK: partitionKey,
751
- SK: latestSortKey
752
- });
753
- }
754
- const esRecords = await esEntityReader.execute();
755
- const esItems = (await Promise.all(esRecords.map(async record => {
756
- if (!record) {
757
- return null;
758
- }
759
- return {
760
- ...record,
761
- data: await decompress(plugins, record.data)
762
- };
763
- }))).filter(item => !!item);
764
- if (esItems.length === 0) {
765
- return initialStorageEntry;
766
- }
767
-
768
- /**
769
- * We update all ES records with data received.
770
- */
771
- const elasticsearchEntityBatch = esEntity.createEntityWriter();
772
- for (const item of esItems) {
773
- elasticsearchEntityBatch.put({
774
- ...item,
775
- data: await compress(plugins, {
776
- ...item.data,
777
- ...updatedEntryMetaFields,
778
- wbyDeleted: entry.wbyDeleted,
779
- location: entry.location,
780
- binOriginalFolderId: entry.binOriginalFolderId
781
- })
782
- });
783
- }
784
-
785
- /**
786
- * We write the records back to the primary DynamoDB Elasticsearch table.
787
- */
788
- try {
789
- await elasticsearchEntityBatch.execute();
790
- } catch (ex) {
791
- throw new WebinyError(ex.message || "Could not restore entry records from DynamoDB Elasticsearch table.", ex.code || "RESTORE_ENTRY_ERROR", {
792
- error: ex,
793
- entry,
794
- storageEntry
795
- });
796
- }
797
- return initialStorageEntry;
798
- };
799
- const deleteEntry = async (initialModel, params) => {
800
- const {
801
- entry
802
- } = params;
803
- const id = entry.id || entry.entryId;
804
- const model = getStorageOperationsModel(initialModel);
805
- const partitionKey = createPartitionKey({
806
- id,
807
- tenant: model.tenant
808
- });
809
- const items = await entity.queryAll({
810
- partitionKey,
811
- options: {
812
- gte: " "
813
- }
814
- });
815
- const esItems = await esEntity.queryAll({
816
- partitionKey,
817
- options: {
818
- gte: " "
819
- }
820
- });
821
- const entityBatch = entity.createEntityWriter({
822
- delete: items.map(item => {
823
- return {
824
- PK: item.PK,
825
- SK: item.SK
826
- };
827
- })
828
- });
829
- const elasticsearchEntityBatch = esEntity.createEntityWriter({
830
- delete: esItems.map(item => {
831
- return {
832
- PK: item.PK,
833
- SK: item.SK
834
- };
835
- })
836
- });
837
- try {
838
- await entityBatch.execute();
839
- dataLoaders.clearAll({
840
- model
841
- });
842
- } catch (ex) {
843
- throw new WebinyError(ex.message || "Could not destroy entry records from DynamoDB table.", ex.code || "DELETE_ENTRY_ERROR", {
844
- error: ex,
845
- id
846
- });
847
- }
848
- try {
849
- await elasticsearchEntityBatch.execute();
850
- } catch (ex) {
851
- throw new WebinyError(ex.message || "Could not destroy entry records from DynamoDB Elasticsearch table.", ex.code || "DELETE_ENTRY_ERROR", {
852
- error: ex,
853
- id
854
- });
855
- }
856
- };
857
- const deleteRevision = async (initialModel, params) => {
858
- const {
859
- entry,
860
- latestEntry,
861
- latestStorageEntry: initialLatestStorageEntry
862
- } = params;
863
- const model = getStorageOperationsModel(initialModel);
864
- const partitionKey = createPartitionKey({
865
- id: entry.id,
866
- tenant: model.tenant
867
- });
868
- const {
869
- index
870
- } = configurations.es({
871
- model
872
- });
873
- /**
874
- * We need published entry to delete it if necessary.
875
- */
876
- const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
877
- model,
878
- ids: [entry.id]
879
- });
880
- /**
881
- * We need to delete all existing records of the given entry revision.
882
- */
883
- const entityBatch = entity.createEntityWriter({
884
- delete: [{
885
- PK: partitionKey,
886
- SK: createRevisionSortKey(entry)
887
- }]
888
- });
889
- const elasticsearchEntityBatch = esEntity.createEntityWriter();
890
-
891
- /**
892
- * If revision we are deleting is the published one as well, we need to delete those records as well.
893
- */
894
- if (publishedStorageEntry?.id === entry.id) {
895
- entityBatch.delete({
896
- PK: partitionKey,
897
- SK: createPublishedSortKey()
898
- });
899
- elasticsearchEntityBatch.delete({
900
- PK: partitionKey,
901
- SK: createPublishedSortKey()
902
- });
903
- }
904
- if (latestEntry && initialLatestStorageEntry) {
905
- const latestStorageEntry = convertToStorageEntry({
906
- storageEntry: initialLatestStorageEntry,
907
- model
908
- });
909
-
910
- /**
911
- * In the end we need to set the new latest entry.
912
- */
913
- const latestStorageEntryLatestKey = createEntryLatestKeys(latestStorageEntry);
914
- entityBatch.put({
915
- ...latestStorageEntryLatestKey,
916
- data: latestStorageEntry
917
- });
918
-
919
- /**
920
- * Also perform an update on the actual revision. This is needed
921
- * because of updates on the entry-level meta fields.
922
- */
923
- const actualRevisionEntryKey = createEntryRevisionKeys(initialLatestStorageEntry);
924
- entityBatch.put({
925
- ...actualRevisionEntryKey,
926
- data: latestStorageEntry
927
- });
928
- const latestTransformer = createTransformer({
929
- plugins,
930
- model,
931
- entry: latestEntry,
932
- storageEntry: initialLatestStorageEntry
933
- });
934
- const esLatestData = await latestTransformer.getElasticsearchLatestEntryData();
935
- const esLatestKeys = createEntryLatestKeys(latestEntry);
936
- elasticsearchEntityBatch.put({
937
- ...esLatestKeys,
938
- index,
939
- data: esLatestData
940
- });
941
- }
942
- try {
943
- await entityBatch.execute();
944
- dataLoaders.clearAll({
945
- model
946
- });
947
- } catch (ex) {
948
- throw new WebinyError(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
949
- error: ex,
950
- entry,
951
- latestEntry,
952
- initialLatestStorageEntry
953
- });
954
- }
955
- try {
956
- await elasticsearchEntityBatch.execute();
957
- } catch (ex) {
958
- throw new WebinyError(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
959
- error: ex,
960
- entry,
961
- latestEntry,
962
- initialLatestStorageEntry
963
- });
964
- }
965
- };
966
- const deleteMultipleEntries = async (initialModel, params) => {
967
- const {
968
- entries
969
- } = params;
970
- const model = getStorageOperationsModel(initialModel);
971
- /**
972
- * First we need all the revisions of the entries we want to delete.
973
- */
974
- const revisions = await dataLoaders.getAllEntryRevisions({
975
- model,
976
- ids: entries
977
- });
978
- /**
979
- * Then we need to construct the queries for all the revisions and entries.
980
- */
981
-
982
- const entityBatch = entity.createEntityWriter();
983
- const elasticsearchEntityBatch = esEntity.createEntityWriter();
984
- for (const id of entries) {
985
- /**
986
- * Latest item.
987
- */
988
- entityBatch.delete({
989
- PK: createPartitionKey({
990
- id,
991
- tenant: model.tenant
992
- }),
993
- SK: "L"
994
- });
995
- elasticsearchEntityBatch.delete({
996
- PK: createPartitionKey({
997
- id,
998
- tenant: model.tenant
999
- }),
1000
- SK: "L"
1001
- });
1002
-
1003
- /**
1004
- * Published item.
1005
- */
1006
- entityBatch.delete({
1007
- PK: createPartitionKey({
1008
- id,
1009
- tenant: model.tenant
1010
- }),
1011
- SK: "P"
1012
- });
1013
- elasticsearchEntityBatch.delete({
1014
- PK: createPartitionKey({
1015
- id,
1016
- tenant: model.tenant
1017
- }),
1018
- SK: "P"
1019
- });
1020
- }
1021
- /**
1022
- * Exact revisions of all the entries
1023
- */
1024
- for (const revision of revisions) {
1025
- entityBatch.delete({
1026
- PK: createPartitionKey({
1027
- id: revision.id,
1028
- tenant: model.tenant
1029
- }),
1030
- SK: createRevisionSortKey({
1031
- version: revision.version
1032
- })
1033
- });
1034
- }
1035
- await entityBatch.execute();
1036
- await elasticsearchEntityBatch.execute();
1037
- };
1038
- const list = async (initialModel, params) => {
1039
- const model = getStorageOperationsModel(initialModel);
1040
- const limit = createLimit(params.limit, 50);
1041
- const {
1042
- index
1043
- } = configurations.es({
1044
- model
1045
- });
1046
- const body = createElasticsearchBody({
1047
- model,
1048
- params: {
1049
- ...params,
1050
- limit,
1051
- after: decodeCursor(params.after)
1052
- },
1053
- plugins
1054
- });
1055
- let response;
1056
- try {
1057
- response = await elasticsearch.search({
1058
- index,
1059
- body
1060
- });
1061
- } catch (error) {
1062
- /**
1063
- * We will silently ignore the `index_not_found_exception` error and return an empty result set.
1064
- * This is because the index might not exist yet, and we don't want to throw an error.
1065
- */
1066
- if (shouldIgnoreEsResponseError(error)) {
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;
1067
874
  return {
1068
- hasMoreItems: false,
1069
- totalCount: 0,
1070
- cursor: null,
1071
- items: []
875
+ hasMoreItems,
876
+ totalCount: getTotalCount(total),
877
+ cursor,
878
+ items
1072
879
  };
1073
- }
1074
- throw new WebinyError(error.message, error.code || "OPENSEARCH_ERROR", {
1075
- error,
1076
- index,
1077
- body,
1078
- model
1079
- });
1080
- }
1081
- const {
1082
- hits,
1083
- total
1084
- } = response?.body?.hits || {};
1085
- const items = extractEntriesFromIndex({
1086
- plugins,
1087
- model,
1088
- entries: hits.map(item => {
1089
- return item._source;
1090
- })
1091
- }).map(item => {
1092
- return convertEntryKeysFromStorage({
1093
- model,
1094
- entry: item
1095
- });
1096
- });
1097
- const hasMoreItems = items.length > limit;
1098
- if (hasMoreItems) {
1099
- /**
1100
- * Remove the last item from results, we don't want to include it.
1101
- */
1102
- items.pop();
1103
- }
1104
- /**
1105
- * Cursor is the `sort` value of the last item in the array.
1106
- * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
1107
- */
1108
- const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;
1109
- return {
1110
- hasMoreItems,
1111
- totalCount: total.value,
1112
- cursor,
1113
- items
1114
880
  };
1115
- };
1116
- const get = async (initialModel, params) => {
1117
- const model = getStorageOperationsModel(initialModel);
1118
- const {
1119
- items
1120
- } = await list(model, {
1121
- ...params,
1122
- limit: 1
1123
- });
1124
- return items.shift() || null;
1125
- };
1126
- const publish = async (initialModel, params) => {
1127
- const {
1128
- entry: initialEntry,
1129
- storageEntry: initialStorageEntry
1130
- } = params;
1131
- const model = getStorageOperationsModel(initialModel);
1132
- const transformer = createTransformer({
1133
- plugins,
1134
- model,
1135
- entry: initialEntry,
1136
- storageEntry: initialStorageEntry
1137
- });
1138
- const {
1139
- entry,
1140
- storageEntry
1141
- } = transformer.transformEntryKeys();
1142
- const revisionKeys = createEntryRevisionKeys(entry);
1143
- const latestKeys = createEntryLatestKeys(entry);
1144
- const publishedKeys = createEntryPublishedKeys(entry);
1145
- let latestEsEntry = null;
1146
- try {
1147
- latestEsEntry = await esEntity.getClean(latestKeys);
1148
- } catch (ex) {
1149
- throw new WebinyError(ex.message || "Could not read Elasticsearch latest data.", ex.code || "PUBLISH_LATEST_READ", {
1150
- error: ex,
1151
- latestKeys: latestKeys,
1152
- publishedKeys: publishedKeys
1153
- });
1154
- }
1155
- if (!latestEsEntry) {
1156
- throw new WebinyError(`Could not publish entry. Could not load latest ("L") record (ES table).`, "PUBLISH_ERROR", {
1157
- entry
1158
- });
1159
- }
1160
-
1161
- /**
1162
- * We need the latest entry to check if it needs to be updated as well in the Elasticsearch.
1163
- */
1164
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
1165
- model,
1166
- ids: [entry.id]
1167
- });
1168
- if (!latestStorageEntry) {
1169
- throw new WebinyError(`Could not publish entry. Could not load latest ("L") record.`, "PUBLISH_ERROR", {
1170
- entry
1171
- });
1172
- }
1173
-
1174
- /**
1175
- * We need currently published entry to check if need to remove it.
1176
- */
1177
- const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
1178
- model,
1179
- ids: [entry.id]
1180
- });
1181
-
1182
- // 1. Update REV# and P records with new data.
1183
- const entityBatch = entity.createEntityWriter({
1184
- put: [{
1185
- ...revisionKeys,
1186
- data: storageEntry
1187
- }, {
1188
- ...publishedKeys,
1189
- data: storageEntry
1190
- }]
1191
- });
1192
- const elasticsearchEntityWriter = esEntity.createEntityWriter();
1193
- const {
1194
- index: esIndex
1195
- } = configurations.es({
1196
- model
1197
- });
1198
-
1199
- // 2. When it comes to the latest record, we need to perform a couple of different
1200
- // updates, based on whether the entry being published is the latest revision or not.
1201
- const publishedRevisionId = publishedStorageEntry?.id;
1202
- const publishingLatestRevision = latestStorageEntry?.id === entry.id;
1203
- if (publishingLatestRevision) {
1204
- // 2.1 If we're publishing the latest revision, we first need to update the L record.
1205
- entityBatch.put({
1206
- ...latestKeys,
1207
- data: storageEntry
1208
- });
1209
-
1210
- // 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.
1211
- // Note that we need to take re-publishing into account (same published revision being
1212
- // published again), in which case the below code does not apply. This is because the
1213
- // required updates were already applied above.
1214
- if (publishedStorageEntry) {
1215
- const isRepublishing = publishedStorageEntry.id === entry.id;
1216
- if (!isRepublishing) {
1217
- /**
1218
- * Update currently published entry (unpublish it)
1219
- */
1220
- const publishedStorageEntryKeys = createEntryRevisionKeys(publishedStorageEntry);
1221
- entityBatch.put({
1222
- ...publishedStorageEntryKeys,
1223
- data: {
1224
- ...publishedStorageEntry,
1225
- status: CONTENT_ENTRY_STATUS.UNPUBLISHED
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;
888
+ };
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
+ }
1226
1000
  }
1227
- });
1228
1001
  }
1229
- }
1230
- } else {
1231
- // 2.3 If the published revision is not the latest one, the situation is a bit
1232
- // more complex. We first need to update the L and REV# records with the new
1233
- // values of *only entry-level* meta fields.
1234
- const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
1235
-
1236
- // 2.4 Update L record. Apart from updating the entry-level meta fields, we also need
1237
- // to change the status from "published" to "unpublished" (if the status is set to "published").
1238
- let latestRevisionStatus = latestStorageEntry.status;
1239
- if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {
1240
- latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
1241
- }
1242
- const latestStorageEntryFields = {
1243
- ...latestStorageEntry,
1244
- ...updatedEntryLevelMetaFields,
1245
- status: latestRevisionStatus
1246
- };
1247
- const latestStorageEntryLatestKeys = createEntryLatestKeys(latestStorageEntry);
1248
- entityBatch.put({
1249
- ...latestStorageEntryLatestKeys,
1250
- data: latestStorageEntryFields
1251
- });
1252
-
1253
- // 2.5 Update REV# record.
1254
- const latestStorageEntryRevisionKeys = createEntryRevisionKeys(latestStorageEntry);
1255
- entityBatch.put({
1256
- ...latestStorageEntryRevisionKeys,
1257
- data: latestStorageEntryFields
1258
- });
1259
-
1260
- // 2.6 Additionally, if we have a previously published entry, we need to mark it as unpublished.
1261
- // Note that we need to take re-publishing into account (same published revision being
1262
- // published again), in which case the below code does not apply. This is because the
1263
- // required updates were already applied above.
1264
- if (publishedStorageEntry) {
1265
- const isRepublishing = publishedStorageEntry.id === entry.id;
1266
- const publishedRevisionDifferentFromLatest = publishedRevisionId !== latestStorageEntry.id;
1267
- if (!isRepublishing && publishedRevisionDifferentFromLatest) {
1268
- const publishedStorageEntryRevisionKeys = createEntryRevisionKeys(publishedStorageEntry);
1269
- entityBatch.put({
1270
- ...publishedStorageEntryRevisionKeys,
1271
- data: {
1272
- ...publishedStorageEntry,
1273
- status: CONTENT_ENTRY_STATUS.UNPUBLISHED
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
+ });
1274
1046
  }
1275
- });
1276
1047
  }
1277
- }
1278
- }
1279
-
1280
- // 3. Update records in ES -> DDB table.
1281
-
1282
- /**
1283
- * Update the published revision entry in ES.
1284
- */
1285
- const esPublishedData = await transformer.getElasticsearchPublishedEntryData();
1286
- elasticsearchEntityWriter.put({
1287
- ...publishedKeys,
1288
- index: esIndex,
1289
- data: esPublishedData
1290
- });
1291
-
1292
- /**
1293
- * Need to decompress the data from Elasticsearch DynamoDB table.
1294
- *
1295
- * No need to transform it for the storage because it was fetched
1296
- * directly from the Elasticsearch table, where it sits transformed.
1297
- */
1298
- const latestEsEntryDataDecompressed = await decompress(plugins, latestEsEntry.data);
1299
- if (publishingLatestRevision) {
1300
- const updatedMetaFields = pickEntryMetaFields(entry);
1301
- const latestTransformer = createTransformer({
1302
- plugins,
1303
- model,
1304
- transformedToIndex: {
1305
- ...latestEsEntryDataDecompressed,
1306
- status: CONTENT_ENTRY_STATUS.PUBLISHED,
1307
- locked: true,
1308
- ...updatedMetaFields
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
+ });
1309
1060
  }
1310
- });
1311
- const esEntryLatestKeys = createEntryLatestKeys(latestEsEntryDataDecompressed);
1312
- elasticsearchEntityWriter.put({
1313
- index: esIndex,
1314
- data: await latestTransformer.getElasticsearchLatestEntryData(),
1315
- ...esEntryLatestKeys
1316
- });
1317
- } else {
1318
- const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
1319
-
1320
- /**
1321
- * Update the Elasticsearch table to propagate changes to the Elasticsearch.
1322
- */
1323
- const latestEsEntry = await esEntity.getClean(latestKeys);
1324
- if (latestEsEntry) {
1325
- const latestEsEntryDataDecompressed = await decompress(plugins, latestEsEntry.data);
1326
- let latestRevisionStatus = latestEsEntryDataDecompressed.status;
1327
- if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {
1328
- latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
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;
1072
+ };
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
+ });
1329
1144
  }
1330
- const updatedLatestEntry = await compress(plugins, {
1331
- ...latestEsEntryDataDecompressed,
1332
- ...updatedEntryLevelMetaFields,
1333
- status: latestRevisionStatus
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;
1154
+ };
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
+ ]
1334
1162
  });
1335
- elasticsearchEntityWriter.put({
1336
- ...latestKeys,
1337
- index: esIndex,
1338
- data: updatedLatestEntry
1163
+ if (!entry) return null;
1164
+ return convertEntryKeysFromStorage({
1165
+ model,
1166
+ entry
1339
1167
  });
1340
- }
1341
- }
1342
-
1343
- /**
1344
- * Finally, execute regular table batch.
1345
- */
1346
- try {
1347
- await entityBatch.execute();
1348
- dataLoaders.clearAll({
1349
- model
1350
- });
1351
- } catch (ex) {
1352
- throw new WebinyError(ex.message || "Could not store publish entry records in DynamoDB table.", ex.code || "PUBLISH_ERROR", {
1353
- error: ex,
1354
- entry,
1355
- latestStorageEntry,
1356
- publishedStorageEntry
1357
- });
1358
- }
1359
- /**
1360
- * And Elasticsearch table batch.
1361
- */
1362
- try {
1363
- await elasticsearchEntityWriter.execute();
1364
- } catch (ex) {
1365
- throw new WebinyError(ex.message || "Could not store publish entry records in DynamoDB Elasticsearch table.", ex.code || "PUBLISH_ES_ERROR", {
1366
- error: ex,
1367
- entry,
1368
- latestStorageEntry,
1369
- publishedStorageEntry
1370
- });
1371
- }
1372
- return initialStorageEntry;
1373
- };
1374
- const unpublish = async (initialModel, params) => {
1375
- const {
1376
- entry: initialEntry,
1377
- storageEntry: initialStorageEntry
1378
- } = params;
1379
- const model = getStorageOperationsModel(initialModel);
1380
- const transformer = createTransformer({
1381
- plugins,
1382
- model,
1383
- entry: initialEntry,
1384
- storageEntry: initialStorageEntry
1385
- });
1386
- const {
1387
- entry,
1388
- storageEntry
1389
- } = await transformer.transformEntryKeys();
1390
-
1391
- /**
1392
- * We need the latest entry to check if it needs to be updated.
1393
- */
1394
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
1395
- model,
1396
- ids: [entry.id]
1397
- });
1398
- const partitionKey = createPartitionKey({
1399
- id: entry.id,
1400
- tenant: model.tenant
1401
- });
1402
- const entryRevisionKeys = createEntryRevisionKeys(entry);
1403
- const entityBatch = entity.createEntityWriter({
1404
- put: [{
1405
- ...entryRevisionKeys,
1406
- data: storageEntry
1407
- }],
1408
- delete: [{
1409
- PK: partitionKey,
1410
- SK: createPublishedSortKey()
1411
- }]
1412
- });
1413
- const elasticsearchEntityBatch = esEntity.createEntityWriter({
1414
- delete: [{
1415
- PK: partitionKey,
1416
- SK: createPublishedSortKey()
1417
- }]
1418
- });
1419
-
1420
- /**
1421
- * If we are unpublishing the latest revision, let's also update the latest revision entry's status in both DynamoDB tables.
1422
- */
1423
- if (latestStorageEntry?.id === entry.id) {
1424
- const {
1425
- index
1426
- } = configurations.es({
1427
- model
1428
- });
1429
- const entryLatestKeys = createEntryLatestKeys(storageEntry);
1430
- entityBatch.put({
1431
- ...entryLatestKeys,
1432
- data: storageEntry
1433
- });
1434
- const esLatestData = await transformer.getElasticsearchLatestEntryData();
1435
- elasticsearchEntityBatch.put({
1436
- index,
1437
- data: esLatestData,
1438
- ...entryLatestKeys
1439
- });
1440
- }
1441
-
1442
- /**
1443
- * Finally, execute regular table batch.
1444
- */
1445
- try {
1446
- await entityBatch.execute();
1447
- dataLoaders.clearAll({
1448
- model
1449
- });
1450
- } catch (ex) {
1451
- throw new WebinyError(ex.message || "Could not store unpublished entry records in DynamoDB table.", ex.code || "UNPUBLISH_ERROR", {
1452
- entry,
1453
- storageEntry
1454
- });
1455
- }
1456
- /**
1457
- * And Elasticsearch table batch.
1458
- */
1459
- try {
1460
- await elasticsearchEntityBatch.execute();
1461
- } catch (ex) {
1462
- throw new WebinyError(ex.message || "Could not store unpublished entry records in DynamoDB Elasticsearch table.", ex.code || "UNPUBLISH_ERROR", {
1463
- entry,
1464
- storageEntry
1465
- });
1466
- }
1467
- return initialStorageEntry;
1468
- };
1469
- const getLatestRevisionByEntryId = async (initialModel, params) => {
1470
- const model = getStorageOperationsModel(initialModel);
1471
- const [entry] = await dataLoaders.getLatestRevisionByEntryId({
1472
- model,
1473
- ids: [params.id]
1474
- });
1475
- if (!entry) {
1476
- return null;
1477
- }
1478
- return convertEntryKeysFromStorage({
1479
- model,
1480
- entry
1481
- });
1482
- };
1483
- const getPublishedRevisionByEntryId = async (initialModel, params) => {
1484
- const model = getStorageOperationsModel(initialModel);
1485
- const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
1486
- model,
1487
- ids: [params.id]
1488
- });
1489
- if (!entry) {
1490
- return null;
1491
- }
1492
- return convertEntryKeysFromStorage({
1493
- model,
1494
- entry
1495
- });
1496
- };
1497
- const getRevisionById = async (initialModel, params) => {
1498
- const model = getStorageOperationsModel(initialModel);
1499
- const [entry] = await dataLoaders.getRevisionById({
1500
- model,
1501
- ids: [params.id]
1502
- });
1503
- if (!entry) {
1504
- return null;
1505
- }
1506
- return convertEntryKeysFromStorage({
1507
- model,
1508
- entry
1509
- });
1510
- };
1511
- const getRevisions = async (initialModel, params) => {
1512
- const model = getStorageOperationsModel(initialModel);
1513
- const entries = await dataLoaders.getAllEntryRevisions({
1514
- model,
1515
- ids: [params.id]
1516
- });
1517
- return entries.map(entry => {
1518
- return convertEntryKeysFromStorage({
1519
- model,
1520
- entry
1521
- });
1522
- });
1523
- };
1524
- const getByIds = async (initialModel, params) => {
1525
- const model = getStorageOperationsModel(initialModel);
1526
- const entries = await dataLoaders.getRevisionById({
1527
- model,
1528
- ids: params.ids
1529
- });
1530
- return entries.map(entry => {
1531
- return convertEntryKeysFromStorage({
1532
- model,
1533
- entry
1534
- });
1535
- });
1536
- };
1537
- const getLatestByIds = async (initialModel, params) => {
1538
- const model = getStorageOperationsModel(initialModel);
1539
- const entries = await dataLoaders.getLatestRevisionByEntryId({
1540
- model,
1541
- ids: params.ids
1542
- });
1543
- return entries.map(entry => {
1544
- return convertEntryKeysFromStorage({
1545
- model,
1546
- entry
1547
- });
1548
- });
1549
- };
1550
- const getPublishedByIds = async (initialModel, params) => {
1551
- const model = getStorageOperationsModel(initialModel);
1552
- const entries = await dataLoaders.getPublishedRevisionByEntryId({
1553
- model,
1554
- ids: params.ids
1555
- });
1556
- return entries.map(entry => {
1557
- return convertEntryKeysFromStorage({
1558
- model,
1559
- entry
1560
- });
1561
- });
1562
- };
1563
- const getPreviousRevision = async (initialModel, params) => {
1564
- const model = getStorageOperationsModel(initialModel);
1565
- const {
1566
- tenant
1567
- } = model;
1568
- const {
1569
- entryId,
1570
- version
1571
- } = params;
1572
- const partitionKey = createPartitionKey({
1573
- tenant,
1574
- id: entryId
1575
- });
1576
- const options = {
1577
- beginsWith: `REV#`,
1578
- reverse: true
1579
1168
  };
1580
- try {
1581
- const unfilteredEntries = (await entity.queryAll({
1582
- partitionKey,
1583
- options
1584
- })).map(item => {
1585
- return item.data;
1586
- });
1587
- const entries = unfilteredEntries.filter(item => {
1588
- return item.version < version;
1589
- });
1590
- const entry = entries[0];
1591
- if (!entry) {
1592
- return null;
1593
- }
1594
- return convertEntryKeysFromStorage({
1595
- entry,
1596
- model
1597
- });
1598
- } catch (ex) {
1599
- throw new WebinyError(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", {
1600
- ...params,
1601
- error: ex,
1602
- partitionKey,
1603
- options,
1604
- model
1605
- });
1606
- }
1607
- };
1608
- const getUniqueFieldValues = async (model, params) => {
1609
- const {
1610
- where,
1611
- fieldId
1612
- } = params;
1613
- const {
1614
- index
1615
- } = configurations.es({
1616
- model
1617
- });
1618
- const initialBody = createElasticsearchBody({
1619
- model,
1620
- params: {
1621
- limit: 1,
1622
- where
1623
- },
1624
- plugins
1625
- });
1626
- const field = model.fields.find(f => f.fieldId === fieldId);
1627
- if (!field) {
1628
- throw new WebinyError(`Could not find field with given "fieldId" value.`, "FIELD_NOT_FOUND", {
1629
- fieldId
1630
- });
1631
- }
1632
- const body = {
1633
- ...initialBody,
1634
- /**
1635
- * We do not need any hits returned, we only need the aggregations.
1636
- */
1637
- size: 0,
1638
- aggregations: {
1639
- getUniqueFieldValues: {
1640
- terms: {
1641
- field: `values.${field.storageId}.keyword`,
1642
- size: 1000000
1643
- }
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
+ });
1644
1275
  }
1645
- }
1646
1276
  };
1647
- let response = undefined;
1648
- try {
1649
- response = await elasticsearch.search({
1650
- index,
1651
- body
1652
- });
1653
- } catch (error) {
1654
- if (shouldIgnoreEsResponseError(error)) {
1655
- return [];
1656
- }
1657
- throw new WebinyError(error.message || "Error in the Elasticsearch query.", error.code || "OPENSEARCH_ERROR", {
1658
- error,
1659
- index,
1660
- model,
1661
- body
1662
- });
1663
- }
1664
- const buckets = response.body.aggregations["getUniqueFieldValues"]?.buckets || [];
1665
- return buckets.map(file => {
1666
- return {
1667
- value: file.key,
1668
- count: file.doc_count
1669
- };
1670
- });
1671
- };
1672
- return {
1673
- create,
1674
- createRevisionFrom,
1675
- update,
1676
- move,
1677
- delete: deleteEntry,
1678
- moveToBin,
1679
- restoreFromBin,
1680
- deleteRevision,
1681
- deleteMultipleEntries,
1682
- get,
1683
- publish,
1684
- unpublish,
1685
- list,
1686
- getLatestRevisionByEntryId,
1687
- getPublishedRevisionByEntryId,
1688
- getRevisionById,
1689
- getRevisions,
1690
- getByIds,
1691
- getLatestByIds,
1692
- getPublishedByIds,
1693
- getPreviousRevision,
1694
- getUniqueFieldValues,
1695
- dataLoaders
1696
- };
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
1361
+ };
1697
1362
  };
1363
+ export { createEntriesStorageOperations };
1698
1364
 
1699
1365
  //# sourceMappingURL=index.js.map