@webiny/api-headless-cms-ddb-es 0.0.0-unstable.e6f0dc8ca7 → 0.0.0-unstable.eb81deee7e

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