@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.2af142b57e

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 (252) hide show
  1. package/configurations.d.ts +2 -2
  2. package/configurations.js +13 -10
  3. package/configurations.js.map +1 -0
  4. package/definitions/entry.d.ts +2 -2
  5. package/definitions/entry.js +6 -12
  6. package/definitions/entry.js.map +1 -0
  7. package/definitions/entryElasticsearch.d.ts +2 -2
  8. package/definitions/entryElasticsearch.js +3 -12
  9. package/definitions/entryElasticsearch.js.map +1 -0
  10. package/definitions/group.d.ts +2 -2
  11. package/definitions/group.js +3 -12
  12. package/definitions/group.js.map +1 -0
  13. package/definitions/model.d.ts +2 -2
  14. package/definitions/model.js +8 -12
  15. package/definitions/model.js.map +1 -0
  16. package/definitions/settings.d.ts +2 -2
  17. package/definitions/settings.js +3 -12
  18. package/definitions/settings.js.map +1 -0
  19. package/definitions/system.d.ts +2 -2
  20. package/definitions/system.js +3 -12
  21. package/definitions/system.js.map +1 -0
  22. package/definitions/table.d.ts +2 -2
  23. package/definitions/table.js +0 -3
  24. package/definitions/table.js.map +1 -0
  25. package/definitions/tableElasticsearch.d.ts +2 -2
  26. package/definitions/tableElasticsearch.js +0 -3
  27. package/definitions/tableElasticsearch.js.map +1 -0
  28. package/dynamoDb/index.d.ts +1 -1
  29. package/dynamoDb/index.js +4 -11
  30. package/dynamoDb/index.js.map +1 -0
  31. package/dynamoDb/storage/date.d.ts +3 -3
  32. package/dynamoDb/storage/date.js +73 -54
  33. package/dynamoDb/storage/date.js.map +1 -0
  34. package/dynamoDb/storage/longText.d.ts +7 -4
  35. package/dynamoDb/storage/longText.js +72 -64
  36. package/dynamoDb/storage/longText.js.map +1 -0
  37. package/dynamoDb/storage/richText.d.ts +2 -3
  38. package/dynamoDb/storage/richText.js +74 -78
  39. package/dynamoDb/storage/richText.js.map +1 -0
  40. package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
  41. package/elasticsearch/createElasticsearchIndex.js +49 -0
  42. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  43. package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
  44. package/elasticsearch/deleteElasticsearchIndex.js +36 -0
  45. package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
  46. package/elasticsearch/index.d.ts +1 -1
  47. package/elasticsearch/index.js +1 -6
  48. package/elasticsearch/index.js.map +1 -0
  49. package/elasticsearch/indexing/dateTimeIndexing.js +17 -20
  50. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
  51. package/elasticsearch/indexing/defaultFieldIndexing.js +5 -9
  52. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
  53. package/elasticsearch/indexing/index.js +1 -10
  54. package/elasticsearch/indexing/index.js.map +1 -0
  55. package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
  56. package/elasticsearch/indexing/longTextIndexing.js +19 -9
  57. package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
  58. package/elasticsearch/indexing/numberIndexing.js +0 -9
  59. package/elasticsearch/indexing/numberIndexing.js.map +1 -0
  60. package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
  61. package/elasticsearch/indexing/objectIndexing.js +26 -30
  62. package/elasticsearch/indexing/objectIndexing.js.map +1 -0
  63. package/elasticsearch/indexing/richTextIndexing.js +0 -5
  64. package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
  65. package/elasticsearch/indices/base.d.ts +2 -0
  66. package/elasticsearch/indices/base.js +12 -0
  67. package/elasticsearch/indices/base.js.map +1 -0
  68. package/elasticsearch/indices/index.d.ts +1 -0
  69. package/elasticsearch/indices/index.js +12 -0
  70. package/elasticsearch/indices/index.js.map +1 -0
  71. package/elasticsearch/indices/japanese.d.ts +2 -0
  72. package/elasticsearch/indices/japanese.js +13 -0
  73. package/elasticsearch/indices/japanese.js.map +1 -0
  74. package/elasticsearch/search/index.d.ts +2 -2
  75. package/elasticsearch/search/index.js +3 -9
  76. package/elasticsearch/search/index.js.map +1 -0
  77. package/elasticsearch/search/refSearch.d.ts +2 -3
  78. package/elasticsearch/search/refSearch.js +23 -18
  79. package/elasticsearch/search/refSearch.js.map +1 -0
  80. package/elasticsearch/search/timeSearch.d.ts +2 -3
  81. package/elasticsearch/search/timeSearch.js +18 -17
  82. package/elasticsearch/search/timeSearch.js.map +1 -0
  83. package/helpers/entryIndexHelpers.js +43 -57
  84. package/helpers/entryIndexHelpers.js.map +1 -0
  85. package/helpers/index.d.ts +0 -1
  86. package/helpers/index.js +0 -15
  87. package/helpers/index.js.map +1 -0
  88. package/index.d.ts +1 -0
  89. package/index.js +120 -58
  90. package/index.js.map +1 -0
  91. package/operations/entry/dataLoaders.d.ts +6 -2
  92. package/operations/entry/dataLoaders.js +27 -61
  93. package/operations/entry/dataLoaders.js.map +1 -0
  94. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
  95. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +32 -0
  96. package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
  97. package/operations/entry/elasticsearch/body.d.ts +13 -0
  98. package/operations/entry/elasticsearch/body.js +140 -0
  99. package/operations/entry/elasticsearch/body.js.map +1 -0
  100. package/operations/entry/elasticsearch/fields.d.ts +9 -0
  101. package/operations/entry/elasticsearch/fields.js +229 -0
  102. package/operations/entry/elasticsearch/fields.js.map +1 -0
  103. package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
  104. package/operations/entry/elasticsearch/filtering/applyFiltering.js +57 -0
  105. package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
  106. package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
  107. package/operations/entry/elasticsearch/filtering/exec.js +172 -0
  108. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
  109. package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
  110. package/operations/entry/elasticsearch/filtering/index.js +16 -0
  111. package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
  112. package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
  113. package/operations/entry/elasticsearch/filtering/path.js +44 -0
  114. package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
  115. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
  116. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +28 -0
  117. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
  118. package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
  119. package/operations/entry/elasticsearch/filtering/plugins/index.js +13 -0
  120. package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
  121. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
  122. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +65 -0
  123. package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
  124. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
  125. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +48 -0
  126. package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
  127. package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
  128. package/operations/entry/elasticsearch/filtering/populated.js +23 -0
  129. package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
  130. package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
  131. package/operations/entry/elasticsearch/filtering/values.js +22 -0
  132. package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
  133. package/operations/entry/elasticsearch/fullTextSearch.d.ts +12 -0
  134. package/operations/entry/elasticsearch/fullTextSearch.js +89 -0
  135. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
  136. package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
  137. package/operations/entry/elasticsearch/fullTextSearchFields.js +25 -0
  138. package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
  139. package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
  140. package/operations/entry/elasticsearch/initialQuery.js +103 -0
  141. package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
  142. package/operations/entry/elasticsearch/keyword.d.ts +2 -0
  143. package/operations/entry/elasticsearch/keyword.js +34 -0
  144. package/operations/entry/elasticsearch/keyword.js.map +1 -0
  145. package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
  146. package/operations/entry/elasticsearch/plugins/bodyModifier.js +16 -0
  147. package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
  148. package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
  149. package/operations/entry/elasticsearch/plugins/operator.js +37 -0
  150. package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
  151. package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
  152. package/operations/entry/elasticsearch/plugins/queryModifier.js +16 -0
  153. package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
  154. package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
  155. package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +8 -10
  156. package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
  157. package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
  158. package/operations/entry/elasticsearch/plugins/sortModifier.js +16 -0
  159. package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
  160. package/operations/entry/elasticsearch/sort.d.ts +12 -0
  161. package/operations/entry/elasticsearch/sort.js +82 -0
  162. package/operations/entry/elasticsearch/sort.js.map +1 -0
  163. package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
  164. package/operations/entry/elasticsearch/transformValueForSearch.js +30 -0
  165. package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
  166. package/operations/entry/elasticsearch/types.d.ts +41 -0
  167. package/operations/entry/elasticsearch/types.js +5 -0
  168. package/operations/entry/elasticsearch/types.js.map +1 -0
  169. package/operations/entry/index.d.ts +2 -4
  170. package/operations/entry/index.js +457 -481
  171. package/operations/entry/index.js.map +1 -0
  172. package/operations/entry/keys.js +0 -9
  173. package/operations/entry/keys.js.map +1 -0
  174. package/operations/entry/recordType.d.ts +3 -0
  175. package/operations/entry/recordType.js +18 -0
  176. package/operations/entry/recordType.js.map +1 -0
  177. package/operations/group/index.d.ts +2 -2
  178. package/operations/group/index.js +10 -47
  179. package/operations/group/index.js.map +1 -0
  180. package/operations/model/index.d.ts +2 -2
  181. package/operations/model/index.js +34 -68
  182. package/operations/model/index.js.map +1 -0
  183. package/operations/settings/index.d.ts +2 -2
  184. package/operations/settings/index.js +7 -37
  185. package/operations/settings/index.js.map +1 -0
  186. package/operations/system/index.d.ts +2 -2
  187. package/operations/system/index.js +5 -28
  188. package/operations/system/index.js.map +1 -0
  189. package/package.json +24 -29
  190. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +7 -3
  191. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +9 -11
  192. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
  193. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
  194. package/plugins/CmsEntryElasticsearchFieldPlugin.js +3 -9
  195. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
  196. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
  197. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +28 -0
  198. package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
  199. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
  200. package/plugins/CmsEntryElasticsearchIndexPlugin.js +12 -0
  201. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
  202. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
  203. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +33 -0
  204. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
  205. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +4 -3
  206. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +9 -11
  207. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
  208. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +4 -3
  209. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +9 -11
  210. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
  211. package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
  212. package/plugins/CmsEntryFilterPlugin.js +24 -0
  213. package/plugins/CmsEntryFilterPlugin.js.map +1 -0
  214. package/plugins/index.d.ts +7 -0
  215. package/plugins/index.js +82 -0
  216. package/plugins/index.js.map +1 -0
  217. package/types.d.ts +7 -34
  218. package/types.js +0 -18
  219. package/types.js.map +1 -0
  220. package/helpers/createElasticsearchQueryBody.d.ts +0 -11
  221. package/helpers/createElasticsearchQueryBody.js +0 -375
  222. package/helpers/fields.d.ts +0 -77
  223. package/helpers/fields.js +0 -174
  224. package/helpers/operatorPluginsList.d.ts +0 -7
  225. package/helpers/operatorPluginsList.js +0 -30
  226. package/helpers/searchPluginsList.d.ts +0 -6
  227. package/helpers/transformValueForSearch.d.ts +0 -9
  228. package/helpers/transformValueForSearch.js +0 -26
  229. package/operations/entry/elasticsearchFields.d.ts +0 -2
  230. package/operations/entry/elasticsearchFields.js +0 -32
  231. package/operations/entry/fields.d.ts +0 -3
  232. package/operations/entry/fields.js +0 -60
  233. package/operations/system/createElasticsearchTemplate.d.ts +0 -5
  234. package/operations/system/createElasticsearchTemplate.js +0 -62
  235. package/upgrades/index.d.ts +0 -2
  236. package/upgrades/index.js +0 -16
  237. package/upgrades/utils.d.ts +0 -1
  238. package/upgrades/utils.js +0 -16
  239. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
  240. package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
  241. package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
  242. package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
  243. package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
  244. package/upgrades/v5.0.0/entryValueFixer.js +0 -124
  245. package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
  246. package/upgrades/v5.0.0/fieldFinder.js +0 -42
  247. package/upgrades/v5.0.0/helpers.d.ts +0 -4
  248. package/upgrades/v5.0.0/helpers.js +0 -57
  249. package/upgrades/v5.0.0/index.d.ts +0 -4
  250. package/upgrades/v5.0.0/index.js +0 -232
  251. package/upgrades/v5.8.0/index.d.ts +0 -4
  252. package/upgrades/v5.8.0/index.js +0 -426
@@ -1,89 +1,74 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.createPublishedType = exports.createLatestType = exports.createEntriesStorageOperations = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
7
+ exports.createEntriesStorageOperations = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
12
11
  var _types = require("@webiny/api-headless-cms/types");
13
-
14
12
  var _helpers = require("../../helpers");
15
-
16
- var _configurations = _interopRequireDefault(require("../../configurations"));
17
-
18
- var _error = _interopRequireDefault(require("@webiny/error"));
19
-
20
- var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
21
-
22
- var _lodash2 = _interopRequireDefault(require("lodash.omit"));
23
-
24
- var _compression = require("@webiny/api-elasticsearch/compression");
25
-
13
+ var _configurations = require("../../configurations");
26
14
  var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
27
-
28
15
  var _dataLoaders = require("./dataLoaders");
29
-
30
16
  var _keys = require("./keys");
31
-
32
17
  var _query = require("@webiny/db-dynamodb/utils/query");
33
-
34
- var _limit = require("@webiny/api-elasticsearch/limit");
35
-
36
- var _cursors = require("@webiny/api-elasticsearch/cursors");
37
-
18
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
38
19
  var _get = require("@webiny/db-dynamodb/utils/get");
39
-
40
20
  var _utils = require("@webiny/utils");
41
-
42
21
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
43
-
44
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
45
-
46
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
47
-
48
- const createType = () => {
49
- return "cms.entry";
50
- };
51
-
52
- const createLatestType = () => {
53
- return `${createType()}.l`;
22
+ var _body = require("./elasticsearch/body");
23
+ var _recordType = require("./recordType");
24
+ const getEntryData = input => {
25
+ const output = (0, _objectSpread2.default)({}, input);
26
+ delete output["PK"];
27
+ delete output["SK"];
28
+ delete output["published"];
29
+ delete output["latest"];
30
+ return output;
54
31
  };
55
-
56
- exports.createLatestType = createLatestType;
57
-
58
- const createPublishedType = () => {
59
- return `${createType()}.p`;
60
- };
61
-
62
- exports.createPublishedType = createPublishedType;
63
-
64
- const getEntryData = entry => {
65
- return _objectSpread(_objectSpread({}, (0, _lodash2.default)(entry, ["PK", "SK", "published", "latest"])), {}, {
66
- TYPE: createType(),
67
- __type: createType()
68
- });
69
- };
70
-
71
32
  const getESLatestEntryData = async (plugins, entry) => {
72
- return (0, _compression.compress)(plugins, _objectSpread(_objectSpread({}, getEntryData(entry)), {}, {
33
+ return (0, _apiElasticsearch.compress)(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getEntryData(entry)), {}, {
73
34
  latest: true,
74
- TYPE: createLatestType(),
75
- __type: createLatestType()
35
+ TYPE: (0, _recordType.createLatestRecordType)(),
36
+ __type: (0, _recordType.createLatestRecordType)()
76
37
  }));
77
38
  };
78
-
79
39
  const getESPublishedEntryData = async (plugins, entry) => {
80
- return (0, _compression.compress)(plugins, _objectSpread(_objectSpread({}, getEntryData(entry)), {}, {
40
+ return (0, _apiElasticsearch.compress)(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getEntryData(entry)), {}, {
81
41
  published: true,
82
- TYPE: createPublishedType(),
83
- __type: createPublishedType()
42
+ TYPE: (0, _recordType.createPublishedRecordType)(),
43
+ __type: (0, _recordType.createPublishedRecordType)()
84
44
  }));
85
45
  };
86
-
46
+ const convertEntryKeysToStorage = params => {
47
+ const {
48
+ model,
49
+ entry
50
+ } = params;
51
+ const values = model.convertValueKeyToStorage({
52
+ fields: model.fields,
53
+ values: entry.values
54
+ });
55
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
56
+ values
57
+ });
58
+ };
59
+ const convertEntryKeysFromStorage = params => {
60
+ const {
61
+ model,
62
+ entry
63
+ } = params;
64
+ const values = model.convertValueKeyFromStorage({
65
+ fields: model.fields,
66
+ values: entry.values
67
+ });
68
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
69
+ values
70
+ });
71
+ };
87
72
  const createEntriesStorageOperations = params => {
88
73
  const {
89
74
  entity,
@@ -94,40 +79,78 @@ const createEntriesStorageOperations = params => {
94
79
  const dataLoaders = new _dataLoaders.DataLoadersHandler({
95
80
  entity
96
81
  });
97
-
98
82
  const create = async (model, params) => {
99
83
  const {
100
- entry,
101
- storageEntry
84
+ entry: initialEntry,
85
+ storageEntry: initialStorageEntry
102
86
  } = params;
87
+ const isPublished = initialEntry.status === "published";
88
+ const locked = isPublished ? true : initialEntry.locked;
89
+ const entry = convertEntryKeysToStorage({
90
+ model,
91
+ entry: initialEntry
92
+ });
93
+ const storageEntry = convertEntryKeysToStorage({
94
+ model,
95
+ entry: initialStorageEntry
96
+ });
103
97
  const esEntry = (0, _helpers.prepareEntryToIndex)({
104
98
  plugins,
105
99
  model,
106
- entry: (0, _lodash.default)(entry),
107
- storageEntry: (0, _lodash.default)(storageEntry)
100
+ entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
101
+ locked
102
+ })),
103
+ storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
104
+ locked
105
+ }))
108
106
  });
109
-
110
107
  const {
111
108
  index: esIndex
112
- } = _configurations.default.es({
109
+ } = _configurations.configurations.es({
113
110
  model
114
111
  });
115
-
116
112
  const esLatestData = await getESLatestEntryData(plugins, esEntry);
113
+ const esPublishedData = await getESPublishedEntryData(plugins, esEntry);
117
114
  const revisionKeys = {
118
- PK: (0, _keys.createPartitionKey)(entry),
115
+ PK: (0, _keys.createPartitionKey)({
116
+ id: entry.id,
117
+ locale: model.locale,
118
+ tenant: model.tenant
119
+ }),
119
120
  SK: (0, _keys.createRevisionSortKey)(entry)
120
121
  };
121
122
  const latestKeys = {
122
- PK: (0, _keys.createPartitionKey)(entry),
123
+ PK: (0, _keys.createPartitionKey)({
124
+ id: entry.id,
125
+ locale: model.locale,
126
+ tenant: model.tenant
127
+ }),
123
128
  SK: (0, _keys.createLatestSortKey)()
124
129
  };
125
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), revisionKeys), {}, {
126
- TYPE: createType()
127
- })), entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), latestKeys), {}, {
128
- TYPE: createLatestType()
130
+ const publishedKeys = {
131
+ PK: (0, _keys.createPartitionKey)({
132
+ id: entry.id,
133
+ locale: model.locale,
134
+ tenant: model.tenant
135
+ }),
136
+ SK: (0, _keys.createPublishedSortKey)()
137
+ };
138
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
139
+ locked
140
+ }, revisionKeys), {}, {
141
+ TYPE: (0, _recordType.createRecordType)()
142
+ })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
143
+ locked
144
+ }, latestKeys), {}, {
145
+ TYPE: (0, _recordType.createLatestRecordType)()
129
146
  }))];
130
-
147
+ if (isPublished) {
148
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
149
+ locked
150
+ }, publishedKeys), {}, {
151
+ TYPE: (0, _recordType.createPublishedRecordType)()
152
+ })));
153
+ }
131
154
  try {
132
155
  await (0, _batchWrite.batchWriteAll)({
133
156
  table: entity.table,
@@ -143,12 +166,21 @@ const createEntriesStorageOperations = params => {
143
166
  storageEntry
144
167
  });
145
168
  }
146
-
147
- try {
148
- await esEntity.put(_objectSpread(_objectSpread({}, latestKeys), {}, {
169
+ const esItems = [esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
170
+ index: esIndex,
171
+ data: esLatestData
172
+ }))];
173
+ if (isPublished) {
174
+ esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
149
175
  index: esIndex,
150
- data: esLatestData
151
- }));
176
+ data: esPublishedData
177
+ })));
178
+ }
179
+ try {
180
+ await (0, _batchWrite.batchWriteAll)({
181
+ table: esEntity.table,
182
+ items: esItems
183
+ });
152
184
  } catch (ex) {
153
185
  throw new _error.default(ex.message || "Could not insert entry data into the Elasticsearch DynamoDB table.", ex.code || "CREATE_ES_ENTRY_ERROR", {
154
186
  error: ex,
@@ -156,43 +188,54 @@ const createEntriesStorageOperations = params => {
156
188
  esEntry
157
189
  });
158
190
  }
159
-
160
- return storageEntry;
191
+ return initialStorageEntry;
161
192
  };
162
-
163
193
  const createRevisionFrom = async (model, params) => {
164
194
  const {
165
- originalEntry,
166
- entry,
167
- storageEntry
195
+ entry: initialEntry,
196
+ storageEntry: initialStorageEntry
168
197
  } = params;
198
+ const entry = convertEntryKeysToStorage({
199
+ model,
200
+ entry: initialEntry
201
+ });
202
+ const storageEntry = convertEntryKeysToStorage({
203
+ model,
204
+ entry: initialStorageEntry
205
+ });
169
206
  const revisionKeys = {
170
- PK: (0, _keys.createPartitionKey)(entry),
207
+ PK: (0, _keys.createPartitionKey)({
208
+ id: entry.id,
209
+ locale: model.locale,
210
+ tenant: model.tenant
211
+ }),
171
212
  SK: (0, _keys.createRevisionSortKey)(entry)
172
213
  };
173
214
  const latestKeys = {
174
- PK: (0, _keys.createPartitionKey)(entry),
215
+ PK: (0, _keys.createPartitionKey)({
216
+ id: entry.id,
217
+ locale: model.locale,
218
+ tenant: model.tenant
219
+ }),
175
220
  SK: (0, _keys.createLatestSortKey)()
176
221
  };
177
222
  const esEntry = (0, _helpers.prepareEntryToIndex)({
178
223
  plugins,
179
224
  model,
180
- entry: (0, _lodash.default)(entry),
181
- storageEntry: (0, _lodash.default)(storageEntry)
225
+ entry: (0, _cloneDeep.default)(entry),
226
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
182
227
  });
183
228
  const esLatestData = await getESLatestEntryData(plugins, esEntry);
184
- const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
185
- TYPE: createType()
186
- }, revisionKeys)), entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
187
- TYPE: createLatestType()
229
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
230
+ TYPE: (0, _recordType.createRecordType)()
231
+ }, revisionKeys)), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
232
+ TYPE: (0, _recordType.createLatestRecordType)()
188
233
  }, latestKeys))];
189
-
190
234
  const {
191
235
  index
192
- } = _configurations.default.es({
236
+ } = _configurations.configurations.es({
193
237
  model
194
238
  });
195
-
196
239
  try {
197
240
  await (0, _batchWrite.batchWriteAll)({
198
241
  table: entity.table,
@@ -204,7 +247,6 @@ const createEntriesStorageOperations = params => {
204
247
  } catch (ex) {
205
248
  throw new _error.default(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
206
249
  error: ex,
207
- originalEntry,
208
250
  entry,
209
251
  storageEntry
210
252
  });
@@ -212,79 +254,157 @@ const createEntriesStorageOperations = params => {
212
254
  /**
213
255
  * Update the "latest" entry item in the Elasticsearch
214
256
  */
215
-
216
-
217
257
  try {
218
- await esEntity.put(_objectSpread(_objectSpread({}, latestKeys), {}, {
258
+ await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
219
259
  index,
220
260
  data: esLatestData
221
261
  }));
222
262
  } catch (ex) {
223
263
  throw new _error.default(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
224
264
  error: ex,
225
- originalEntry,
226
265
  entry
227
266
  });
228
267
  }
229
268
  /**
230
269
  * There are no modifications on the entry created so just return the data.
231
270
  */
232
-
233
-
234
- return storageEntry;
271
+ return initialStorageEntry;
235
272
  };
236
-
237
273
  const update = async (model, params) => {
238
274
  const {
239
- originalEntry,
240
- entry,
241
- storageEntry
275
+ entry: initialEntry,
276
+ storageEntry: initialStorageEntry
242
277
  } = params;
278
+ const entry = convertEntryKeysToStorage({
279
+ model,
280
+ entry: initialEntry
281
+ });
282
+ const storageEntry = convertEntryKeysToStorage({
283
+ model,
284
+ entry: initialStorageEntry
285
+ });
286
+ const isPublished = entry.status === "published";
287
+ const locked = isPublished ? true : entry.locked;
243
288
  const revisionKeys = {
244
- PK: (0, _keys.createPartitionKey)(entry),
289
+ PK: (0, _keys.createPartitionKey)({
290
+ id: entry.id,
291
+ locale: model.locale,
292
+ tenant: model.tenant
293
+ }),
245
294
  SK: (0, _keys.createRevisionSortKey)(entry)
246
295
  };
247
296
  const latestKeys = {
248
- PK: (0, _keys.createPartitionKey)(entry),
297
+ PK: (0, _keys.createPartitionKey)({
298
+ id: entry.id,
299
+ locale: model.locale,
300
+ tenant: model.tenant
301
+ }),
249
302
  SK: (0, _keys.createLatestSortKey)()
250
303
  };
304
+ const publishedKeys = {
305
+ PK: (0, _keys.createPartitionKey)({
306
+ id: entry.id,
307
+ locale: model.locale,
308
+ tenant: model.tenant
309
+ }),
310
+ SK: (0, _keys.createPublishedSortKey)()
311
+ };
312
+
251
313
  /**
252
314
  * We need the latest entry to check if it needs to be updated.
253
315
  */
254
-
255
316
  const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
256
317
  model,
257
- ids: [originalEntry.id]
318
+ ids: [entry.id]
319
+ });
320
+ const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
321
+ model,
322
+ ids: [entry.id]
258
323
  });
259
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), revisionKeys), {}, {
260
- TYPE: createType()
324
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
325
+ locked
326
+ }, revisionKeys), {}, {
327
+ TYPE: (0, _recordType.createRecordType)()
261
328
  }))];
329
+ if (isPublished) {
330
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
331
+ locked
332
+ }, publishedKeys), {}, {
333
+ TYPE: (0, _recordType.createPublishedRecordType)()
334
+ })));
335
+ }
336
+ const esItems = [];
337
+ const {
338
+ index: esIndex
339
+ } = _configurations.configurations.es({
340
+ model
341
+ });
342
+ /**
343
+ * Variable for the elasticsearch entry so we do not convert it more than once
344
+ */
345
+ let esEntry = undefined;
262
346
  /**
263
347
  * If the latest entry is the one being updated, we need to create a new latest entry records.
264
348
  */
265
-
266
349
  let elasticsearchLatestData = null;
267
-
268
- if (latestStorageEntry.id === originalEntry.id) {
350
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
269
351
  /**
270
352
  * First we update the regular DynamoDB table
271
353
  */
272
- items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), latestKeys), {}, {
354
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), latestKeys), {}, {
273
355
  TYPE: (0, _keys.createLatestSortKey)()
274
356
  })));
275
357
  /**
276
358
  * And then update the Elasticsearch table to propagate changes to the Elasticsearch
277
359
  */
278
-
279
- const esEntry = (0, _helpers.prepareEntryToIndex)({
360
+ esEntry = (0, _helpers.prepareEntryToIndex)({
280
361
  plugins,
281
362
  model,
282
- entry: (0, _lodash.default)(entry),
283
- storageEntry: (0, _lodash.default)(storageEntry)
363
+ entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
364
+ locked
365
+ })),
366
+ storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
367
+ locked
368
+ }))
284
369
  });
285
370
  elasticsearchLatestData = await getESLatestEntryData(plugins, esEntry);
371
+ esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
372
+ index: esIndex,
373
+ data: elasticsearchLatestData
374
+ })));
375
+ }
376
+ let elasticsearchPublishedData = null;
377
+ if (isPublished && (publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
378
+ if (!elasticsearchLatestData) {
379
+ /**
380
+ * And then update the Elasticsearch table to propagate changes to the Elasticsearch
381
+ */
382
+ if (!esEntry) {
383
+ esEntry = (0, _helpers.prepareEntryToIndex)({
384
+ plugins,
385
+ model,
386
+ entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
387
+ locked
388
+ })),
389
+ storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
390
+ locked
391
+ }))
392
+ });
393
+ }
394
+ elasticsearchPublishedData = await getESPublishedEntryData(plugins, esEntry);
395
+ } else {
396
+ elasticsearchPublishedData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, elasticsearchLatestData), {}, {
397
+ published: true,
398
+ TYPE: (0, _recordType.createPublishedRecordType)(),
399
+ __type: (0, _recordType.createPublishedRecordType)()
400
+ });
401
+ delete elasticsearchPublishedData.latest;
402
+ }
403
+ esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
404
+ index: esIndex,
405
+ data: elasticsearchPublishedData
406
+ })));
286
407
  }
287
-
288
408
  try {
289
409
  await (0, _batchWrite.batchWriteAll)({
290
410
  table: entity.table,
@@ -296,43 +416,35 @@ const createEntriesStorageOperations = params => {
296
416
  } catch (ex) {
297
417
  throw new _error.default(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
298
418
  error: ex,
299
- originalEntry,
300
419
  entry,
301
420
  storageEntry
302
421
  });
303
422
  }
304
-
305
- if (!elasticsearchLatestData) {
306
- return storageEntry;
423
+ if (esItems.length === 0) {
424
+ return initialStorageEntry;
307
425
  }
308
-
309
- const {
310
- index: esIndex
311
- } = _configurations.default.es({
312
- model
313
- });
314
-
315
426
  try {
316
- await esEntity.put(_objectSpread(_objectSpread({}, latestKeys), {}, {
317
- index: esIndex,
318
- data: elasticsearchLatestData
319
- }));
427
+ await (0, _batchWrite.batchWriteAll)({
428
+ table: esEntity.table,
429
+ items: esItems
430
+ });
320
431
  } catch (ex) {
321
- throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch record.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
432
+ throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch records.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
322
433
  error: ex,
323
- originalEntry,
324
434
  entry
325
435
  });
326
436
  }
327
-
328
- return storageEntry;
437
+ return initialStorageEntry;
329
438
  };
330
-
331
439
  const deleteEntry = async (model, params) => {
332
440
  const {
333
441
  entry
334
442
  } = params;
335
- const partitionKey = (0, _keys.createPartitionKey)(entry);
443
+ const partitionKey = (0, _keys.createPartitionKey)({
444
+ id: entry.id,
445
+ locale: model.locale,
446
+ tenant: model.tenant
447
+ });
336
448
  const items = await (0, _query.queryAll)({
337
449
  entity,
338
450
  partitionKey,
@@ -359,7 +471,6 @@ const createEntriesStorageOperations = params => {
359
471
  SK: item.SK
360
472
  });
361
473
  });
362
-
363
474
  try {
364
475
  await (0, _batchWrite.batchWriteAll)({
365
476
  table: entity.table,
@@ -374,7 +485,6 @@ const createEntriesStorageOperations = params => {
374
485
  entry
375
486
  });
376
487
  }
377
-
378
488
  try {
379
489
  await (0, _batchWrite.batchWriteAll)({
380
490
  table: esEntity.table,
@@ -387,47 +497,46 @@ const createEntriesStorageOperations = params => {
387
497
  });
388
498
  }
389
499
  };
390
-
391
500
  const deleteRevision = async (model, params) => {
392
501
  const {
393
- entryToDelete,
394
- entryToSetAsLatest,
395
- storageEntryToSetAsLatest
502
+ entry,
503
+ latestEntry,
504
+ latestStorageEntry
396
505
  } = params;
397
- const partitionKey = (0, _keys.createPartitionKey)(entryToDelete);
398
-
506
+ const partitionKey = (0, _keys.createPartitionKey)({
507
+ id: entry.id,
508
+ locale: model.locale,
509
+ tenant: model.tenant
510
+ });
399
511
  const {
400
512
  index
401
- } = _configurations.default.es({
513
+ } = _configurations.configurations.es({
402
514
  model
403
515
  });
404
516
  /**
405
517
  * We need published entry to delete it if necessary.
406
518
  */
407
-
408
-
409
519
  const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
410
520
  model,
411
- ids: [entryToDelete.id]
521
+ ids: [entry.id]
412
522
  });
413
523
  /**
414
524
  * We need to delete all existing records of the given entry revision.
415
525
  */
416
-
417
526
  const items = [
418
527
  /**
419
528
  * Delete records of given entry revision.
420
529
  */
421
530
  entity.deleteBatch({
422
531
  PK: partitionKey,
423
- SK: (0, _keys.createRevisionSortKey)(entryToDelete)
532
+ SK: (0, _keys.createRevisionSortKey)(entry)
424
533
  })];
425
534
  const esItems = [];
535
+
426
536
  /**
427
537
  * If revision we are deleting is the published one as well, we need to delete those records as well.
428
538
  */
429
-
430
- if (publishedStorageEntry && entryToDelete.id === publishedStorageEntry.id) {
539
+ if ((publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
431
540
  items.push(entity.deleteBatch({
432
541
  PK: partitionKey,
433
542
  SK: (0, _keys.createPublishedSortKey)()
@@ -437,23 +546,21 @@ const createEntriesStorageOperations = params => {
437
546
  SK: (0, _keys.createPublishedSortKey)()
438
547
  }));
439
548
  }
440
-
441
- if (entryToSetAsLatest) {
549
+ if (latestEntry && latestStorageEntry) {
442
550
  const esEntry = (0, _helpers.prepareEntryToIndex)({
443
551
  plugins,
444
552
  model,
445
- entry: (0, _lodash.default)(entryToSetAsLatest),
446
- storageEntry: (0, _lodash.default)(storageEntryToSetAsLatest)
553
+ entry: (0, _cloneDeep.default)(latestEntry),
554
+ storageEntry: (0, _cloneDeep.default)(latestStorageEntry)
447
555
  });
448
556
  const esLatestData = await getESLatestEntryData(plugins, esEntry);
449
557
  /**
450
558
  * In the end we need to set the new latest entry
451
559
  */
452
-
453
- items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntryToSetAsLatest), {}, {
560
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestStorageEntry), {}, {
454
561
  PK: partitionKey,
455
562
  SK: (0, _keys.createLatestSortKey)(),
456
- TYPE: createLatestType()
563
+ TYPE: (0, _recordType.createLatestRecordType)()
457
564
  })));
458
565
  esItems.push(esEntity.putBatch({
459
566
  PK: partitionKey,
@@ -462,7 +569,6 @@ const createEntriesStorageOperations = params => {
462
569
  data: esLatestData
463
570
  }));
464
571
  }
465
-
466
572
  try {
467
573
  await (0, _batchWrite.batchWriteAll)({
468
574
  table: entity.table,
@@ -474,16 +580,14 @@ const createEntriesStorageOperations = params => {
474
580
  } catch (ex) {
475
581
  throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
476
582
  error: ex,
477
- entryToDelete,
478
- entryToSetAsLatest,
479
- storageEntryToSetAsLatest
583
+ entry,
584
+ latestEntry,
585
+ latestStorageEntry
480
586
  });
481
587
  }
482
-
483
588
  if (esItems.length === 0) {
484
589
  return;
485
590
  }
486
-
487
591
  try {
488
592
  await (0, _batchWrite.batchWriteAll)({
489
593
  table: esEntity.table,
@@ -492,31 +596,47 @@ const createEntriesStorageOperations = params => {
492
596
  } catch (ex) {
493
597
  throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
494
598
  error: ex,
495
- entryToDelete,
496
- entryToSetAsLatest,
497
- storageEntryToSetAsLatest
599
+ entry,
600
+ latestEntry,
601
+ latestStorageEntry
498
602
  });
499
603
  }
500
604
  };
501
-
502
605
  const list = async (model, params) => {
503
- const limit = (0, _limit.createLimit)(params.limit, 50);
504
- const body = (0, _helpers.createElasticsearchQueryBody)({
505
- model,
506
- args: _objectSpread(_objectSpread({}, params), {}, {
507
- limit
508
- }),
509
- plugins,
510
- parentPath: "values"
511
- });
512
- let response;
513
-
606
+ var _response, _response$body;
607
+ const limit = (0, _apiElasticsearch.createLimit)(params.limit, 50);
514
608
  const {
515
609
  index
516
- } = _configurations.default.es({
610
+ } = _configurations.configurations.es({
517
611
  model
518
612
  });
519
-
613
+ try {
614
+ const result = await elasticsearch.indices.exists({
615
+ index
616
+ });
617
+ if (!(result !== null && result !== void 0 && result.body)) {
618
+ return {
619
+ hasMoreItems: false,
620
+ totalCount: 0,
621
+ cursor: null,
622
+ items: []
623
+ };
624
+ }
625
+ } catch (ex) {
626
+ throw new _error.default("Could not determine if Elasticsearch index exists.", "ELASTICSEARCH_INDEX_CHECK_ERROR", {
627
+ error: ex,
628
+ index
629
+ });
630
+ }
631
+ const body = (0, _body.createElasticsearchBody)({
632
+ model,
633
+ params: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
634
+ limit,
635
+ after: (0, _apiElasticsearch.decodeCursor)(params.after)
636
+ }),
637
+ plugins
638
+ });
639
+ let response;
520
640
  try {
521
641
  response = await elasticsearch.search({
522
642
  index,
@@ -526,21 +646,25 @@ const createEntriesStorageOperations = params => {
526
646
  throw new _error.default(ex.message, ex.code || "ELASTICSEARCH_ERROR", {
527
647
  error: ex,
528
648
  index,
529
- body
649
+ body,
650
+ model
530
651
  });
531
652
  }
532
-
533
653
  const {
534
654
  hits,
535
655
  total
536
- } = response.body.hits;
656
+ } = ((_response = response) === null || _response === void 0 ? void 0 : (_response$body = _response.body) === null || _response$body === void 0 ? void 0 : _response$body.hits) || {};
537
657
  const items = (0, _helpers.extractEntriesFromIndex)({
538
658
  plugins,
539
659
  model,
540
660
  entries: hits.map(item => item._source)
661
+ }).map(item => {
662
+ return convertEntryKeysFromStorage({
663
+ model,
664
+ entry: item
665
+ });
541
666
  });
542
667
  const hasMoreItems = items.length > limit;
543
-
544
668
  if (hasMoreItems) {
545
669
  /**
546
670
  * Remove the last item from results, we don't want to include it.
@@ -551,9 +675,7 @@ const createEntriesStorageOperations = params => {
551
675
  * Cursor is the `sort` value of the last item in the array.
552
676
  * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
553
677
  */
554
-
555
-
556
- const cursor = items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null;
678
+ const cursor = items.length > 0 ? (0, _apiElasticsearch.encodeCursor)(hits[items.length - 1].sort) || null : null;
557
679
  return {
558
680
  hasMoreItems,
559
681
  totalCount: total.value,
@@ -561,48 +683,60 @@ const createEntriesStorageOperations = params => {
561
683
  items
562
684
  };
563
685
  };
564
-
565
686
  const get = async (model, params) => {
566
687
  const {
567
688
  items
568
- } = await list(model, _objectSpread(_objectSpread({}, params), {}, {
689
+ } = await list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
569
690
  limit: 1
570
691
  }));
571
-
572
- if (items.length === 0) {
573
- return null;
574
- }
575
-
576
- return items.shift();
692
+ return items.shift() || null;
577
693
  };
578
-
579
694
  const publish = async (model, params) => {
580
695
  const {
581
- entry,
582
- storageEntry
696
+ entry: initialEntry,
697
+ storageEntry: initialStorageEntry
583
698
  } = params;
699
+ const entry = convertEntryKeysToStorage({
700
+ model,
701
+ entry: initialEntry
702
+ });
703
+ const storageEntry = convertEntryKeysToStorage({
704
+ model,
705
+ entry: initialStorageEntry
706
+ });
707
+
584
708
  /**
585
709
  * We need currently published entry to check if need to remove it.
586
710
  */
587
-
588
711
  const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
589
712
  model,
590
713
  ids: [entry.id]
591
714
  });
592
715
  const revisionKeys = {
593
- PK: (0, _keys.createPartitionKey)(entry),
716
+ PK: (0, _keys.createPartitionKey)({
717
+ id: entry.id,
718
+ locale: model.locale,
719
+ tenant: model.tenant
720
+ }),
594
721
  SK: (0, _keys.createRevisionSortKey)(entry)
595
722
  };
596
723
  const latestKeys = {
597
- PK: (0, _keys.createPartitionKey)(entry),
724
+ PK: (0, _keys.createPartitionKey)({
725
+ id: entry.id,
726
+ locale: model.locale,
727
+ tenant: model.tenant
728
+ }),
598
729
  SK: (0, _keys.createLatestSortKey)()
599
730
  };
600
731
  const publishedKeys = {
601
- PK: (0, _keys.createPartitionKey)(entry),
732
+ PK: (0, _keys.createPartitionKey)({
733
+ id: entry.id,
734
+ locale: model.locale,
735
+ tenant: model.tenant
736
+ }),
602
737
  SK: (0, _keys.createPublishedSortKey)()
603
738
  };
604
739
  let latestEsEntry = null;
605
-
606
740
  try {
607
741
  latestEsEntry = await (0, _get.get)({
608
742
  entity: esEntity,
@@ -615,19 +749,16 @@ const createEntriesStorageOperations = params => {
615
749
  publishedKeys: publishedKeys
616
750
  });
617
751
  }
618
-
619
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), revisionKeys), {}, {
620
- TYPE: createType()
752
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), revisionKeys), {}, {
753
+ TYPE: (0, _recordType.createRecordType)()
621
754
  }))];
622
755
  const esItems = [];
623
-
624
756
  const {
625
757
  index
626
- } = _configurations.default.es({
758
+ } = _configurations.configurations.es({
627
759
  model
628
760
  });
629
-
630
- if (publishedStorageEntry) {
761
+ if (publishedStorageEntry && publishedStorageEntry.id !== entry.id) {
631
762
  /**
632
763
  * If there is a `published` entry already, we need to set it to `unpublished`. We need to
633
764
  * execute two updates: update the previously published entry's status and the published entry record.
@@ -643,10 +774,10 @@ const createEntriesStorageOperations = params => {
643
774
  /**
644
775
  * Update currently published entry (unpublish it)
645
776
  */
646
- entity.putBatch(_objectSpread(_objectSpread({}, previouslyPublishedEntry), {}, {
777
+ entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedEntry), {}, {
647
778
  status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
648
779
  savedOn: entry.savedOn,
649
- TYPE: createType(),
780
+ TYPE: (0, _recordType.createRecordType)(),
650
781
  PK: (0, _keys.createPartitionKey)(publishedStorageEntry),
651
782
  SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry)
652
783
  })));
@@ -654,60 +785,60 @@ const createEntriesStorageOperations = params => {
654
785
  /**
655
786
  * Update the helper item in DB with the new published entry
656
787
  */
657
-
658
-
659
- items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), publishedKeys), {}, {
660
- TYPE: createPublishedType()
788
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), publishedKeys), {}, {
789
+ TYPE: (0, _recordType.createPublishedRecordType)()
661
790
  })));
791
+
662
792
  /**
663
- * We need the latest entry to check if it neds to be updated as well in the Elasticsearch.
793
+ * We need the latest entry to check if it needs to be updated as well in the Elasticsearch.
664
794
  */
665
-
666
795
  const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
667
796
  model,
668
797
  ids: [entry.id]
669
798
  });
799
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
800
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), latestKeys)));
801
+ }
670
802
  /**
671
803
  * If we are publishing the latest revision, let's also update the latest revision's status in ES.
672
804
  */
673
-
674
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
805
+ if (latestEsEntry && (latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
675
806
  /**
676
807
  * Need to decompress the data from Elasticsearch DynamoDB table.
808
+ *
809
+ * No need to transform it for the storage because it was fetched directly from the Elasticsearch table, where it sits transformed.
677
810
  */
678
- const latestEsEntryDataDecompressed = await (0, _compression.decompress)(plugins, latestEsEntry.data);
811
+ const latestEsEntryDataDecompressed = await (0, _apiElasticsearch.decompress)(plugins, latestEsEntry.data);
679
812
  esItems.push(esEntity.putBatch({
680
813
  index,
681
814
  PK: (0, _keys.createPartitionKey)(latestEsEntryDataDecompressed),
682
815
  SK: (0, _keys.createLatestSortKey)(),
683
- data: _objectSpread(_objectSpread({}, latestEsEntryDataDecompressed), {}, {
816
+ data: await getESLatestEntryData(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestEsEntryDataDecompressed), {}, {
684
817
  status: _types.CONTENT_ENTRY_STATUS.PUBLISHED,
685
818
  locked: true,
686
819
  savedOn: entry.savedOn,
687
820
  publishedOn: entry.publishedOn
688
- })
821
+ }))
689
822
  }));
690
823
  }
691
-
692
824
  const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
693
825
  plugins,
694
826
  model,
695
- entry: (0, _lodash.default)(entry),
696
- storageEntry: (0, _lodash.default)(storageEntry)
827
+ entry: (0, _cloneDeep.default)(entry),
828
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
697
829
  });
698
830
  /**
699
831
  * Update the published revision entry in ES.
700
832
  */
701
-
702
- const esLatestData = await getESPublishedEntryData(plugins, preparedEntryData);
703
- esItems.push(esEntity.putBatch(_objectSpread(_objectSpread({}, publishedKeys), {}, {
833
+ const esPublishedData = await getESPublishedEntryData(plugins, preparedEntryData);
834
+ esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
704
835
  index,
705
- data: esLatestData
836
+ data: esPublishedData
706
837
  })));
838
+
707
839
  /**
708
840
  * Finally, execute regular table batch.
709
841
  */
710
-
711
842
  try {
712
843
  await (0, _batchWrite.batchWriteAll)({
713
844
  table: entity.table,
@@ -727,8 +858,6 @@ const createEntriesStorageOperations = params => {
727
858
  /**
728
859
  * And Elasticsearch table batch.
729
860
  */
730
-
731
-
732
861
  try {
733
862
  await (0, _batchWrite.batchWriteAll)({
734
863
  table: esEntity.table,
@@ -742,31 +871,41 @@ const createEntriesStorageOperations = params => {
742
871
  publishedStorageEntry
743
872
  });
744
873
  }
745
-
746
- return storageEntry;
874
+ return initialStorageEntry;
747
875
  };
748
-
749
876
  const unpublish = async (model, params) => {
750
877
  const {
751
- entry,
752
- storageEntry
878
+ entry: initialEntry,
879
+ storageEntry: initialStorageEntry
753
880
  } = params;
881
+ const entry = convertEntryKeysToStorage({
882
+ model,
883
+ entry: initialEntry
884
+ });
885
+ const storageEntry = convertEntryKeysToStorage({
886
+ model,
887
+ entry: initialStorageEntry
888
+ });
889
+
754
890
  /**
755
891
  * We need the latest entry to check if it needs to be updated.
756
892
  */
757
-
758
893
  const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
759
894
  model,
760
895
  ids: [entry.id]
761
896
  });
762
- const partitionKey = (0, _keys.createPartitionKey)(entry);
897
+ const partitionKey = (0, _keys.createPartitionKey)({
898
+ id: entry.id,
899
+ locale: model.locale,
900
+ tenant: model.tenant
901
+ });
763
902
  const items = [entity.deleteBatch({
764
903
  PK: partitionKey,
765
904
  SK: (0, _keys.createPublishedSortKey)()
766
- }), entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
905
+ }), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
767
906
  PK: partitionKey,
768
907
  SK: (0, _keys.createRevisionSortKey)(entry),
769
- TYPE: createType()
908
+ TYPE: (0, _recordType.createRecordType)()
770
909
  }))];
771
910
  const esItems = [esEntity.deleteBatch({
772
911
  PK: partitionKey,
@@ -775,19 +914,17 @@ const createEntriesStorageOperations = params => {
775
914
  /**
776
915
  * If we are unpublishing the latest revision, let's also update the latest revision entry's status in ES.
777
916
  */
778
-
779
- if (latestStorageEntry.id === entry.id) {
917
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
780
918
  const {
781
919
  index
782
- } = _configurations.default.es({
920
+ } = _configurations.configurations.es({
783
921
  model
784
922
  });
785
-
786
923
  const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
787
924
  plugins,
788
925
  model,
789
- entry: (0, _lodash.default)(entry),
790
- storageEntry: (0, _lodash.default)(storageEntry)
926
+ entry: (0, _cloneDeep.default)(entry),
927
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
791
928
  });
792
929
  const esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
793
930
  esItems.push(esEntity.putBatch({
@@ -797,11 +934,10 @@ const createEntriesStorageOperations = params => {
797
934
  data: esLatestData
798
935
  }));
799
936
  }
937
+
800
938
  /**
801
939
  * Finally, execute regular table batch.
802
940
  */
803
-
804
-
805
941
  try {
806
942
  await (0, _batchWrite.batchWriteAll)({
807
943
  table: entity.table,
@@ -819,8 +955,6 @@ const createEntriesStorageOperations = params => {
819
955
  /**
820
956
  * And Elasticsearch table batch.
821
957
  */
822
-
823
-
824
958
  try {
825
959
  await (0, _batchWrite.batchWriteAll)({
826
960
  table: esEntity.table,
@@ -832,253 +966,95 @@ const createEntriesStorageOperations = params => {
832
966
  storageEntry
833
967
  });
834
968
  }
835
-
836
- return storageEntry;
837
- };
838
-
839
- const requestReview = async (model, params) => {
840
- const {
841
- entry,
842
- storageEntry,
843
- originalEntry
844
- } = params;
845
- /**
846
- * We need the latest entry to check if it needs to be updated.
847
- */
848
-
849
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
850
- model,
851
- ids: [entry.id]
852
- });
853
- const partitionKey = (0, _keys.createPartitionKey)(entry);
854
- /**
855
- * If we updated the latest version, then make sure the changes are propagated to ES too.
856
- */
857
-
858
- let esLatestData = null;
859
-
860
- const {
861
- index
862
- } = _configurations.default.es({
863
- model
864
- });
865
-
866
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
867
- const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
868
- plugins,
869
- model,
870
- entry: (0, _lodash.default)(entry),
871
- storageEntry: (0, _lodash.default)(storageEntry)
872
- });
873
- esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
874
- }
875
-
876
- try {
877
- await entity.put(_objectSpread(_objectSpread({}, storageEntry), {}, {
878
- PK: partitionKey,
879
- SK: (0, _keys.createRevisionSortKey)(entry),
880
- TYPE: createType()
881
- }));
882
- dataLoaders.clearAll({
883
- model
884
- });
885
- } catch (ex) {
886
- throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB table.", ex.code || "REQUEST_REVIEW_ERROR", {
887
- entry,
888
- latestStorageEntry,
889
- originalEntry
890
- });
891
- }
892
- /**
893
- * No need to proceed further if nothing to put into Elasticsearch.
894
- */
895
-
896
-
897
- if (!esLatestData) {
898
- return storageEntry;
899
- }
900
-
901
- try {
902
- await esEntity.put({
903
- PK: partitionKey,
904
- SK: (0, _keys.createLatestSortKey)(),
905
- index,
906
- data: esLatestData
907
- });
908
- } catch (ex) {
909
- throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_REVIEW_ERROR", {
910
- entry,
911
- latestStorageEntry,
912
- originalEntry
913
- });
914
- }
915
-
916
- return storageEntry;
917
- };
918
-
919
- const requestChanges = async (model, params) => {
920
- const {
921
- entry,
922
- storageEntry,
923
- originalEntry
924
- } = params;
925
- /**
926
- * We need the latest entry to check if it needs to be updated.
927
- */
928
-
929
- const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
930
- model,
931
- ids: [entry.id]
932
- });
933
- const partitionKey = (0, _keys.createPartitionKey)(entry);
934
- const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
935
- PK: partitionKey,
936
- SK: (0, _keys.createRevisionSortKey)(entry),
937
- TYPE: createType()
938
- }))];
939
- /**
940
- * If we updated the latest version, then make sure the changes are propagated to ES too.
941
- */
942
-
943
- const {
944
- index
945
- } = _configurations.default.es({
946
- model
947
- });
948
-
949
- let esLatestData = null;
950
-
951
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
952
- items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
953
- PK: partitionKey,
954
- SK: (0, _keys.createLatestSortKey)(),
955
- TYPE: createLatestType()
956
- })));
957
- const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
958
- plugins,
959
- model,
960
- entry: (0, _lodash.default)(entry),
961
- storageEntry: (0, _lodash.default)(storageEntry)
962
- });
963
- esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
964
- }
965
-
966
- try {
967
- await (0, _batchWrite.batchWriteAll)({
968
- table: entity.table,
969
- items
970
- });
971
- dataLoaders.clearAll({
972
- model
973
- });
974
- } catch (ex) {
975
- throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB table.", ex.code || "REQUEST_CHANGES_ERROR", {
976
- entry,
977
- latestStorageEntry,
978
- originalEntry
979
- });
980
- }
981
- /**
982
- * No need to proceed further if nothing to put into Elasticsearch.
983
- */
984
-
985
-
986
- if (!esLatestData) {
987
- return storageEntry;
988
- }
989
-
990
- try {
991
- await esEntity.put({
992
- PK: partitionKey,
993
- SK: (0, _keys.createLatestSortKey)(),
994
- index,
995
- data: esLatestData
996
- });
997
- } catch (ex) {
998
- throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_CHANGES_ERROR", {
999
- entry,
1000
- latestStorageEntry,
1001
- originalEntry
1002
- });
1003
- }
1004
-
1005
- return storageEntry;
969
+ return initialStorageEntry;
1006
970
  };
1007
-
1008
- const getAllRevisionsByIds = async (model, params) => {
1009
- return await dataLoaders.getAllEntryRevisions({
1010
- model,
1011
- ids: params.ids
1012
- });
1013
- };
1014
-
1015
971
  const getLatestRevisionByEntryId = async (model, params) => {
1016
- const result = await dataLoaders.getLatestRevisionByEntryId({
972
+ const [entry] = await dataLoaders.getLatestRevisionByEntryId({
1017
973
  model,
1018
974
  ids: [params.id]
1019
975
  });
1020
-
1021
- if (result.length === 0) {
976
+ if (!entry) {
1022
977
  return null;
1023
978
  }
1024
-
1025
- return result.shift();
979
+ return convertEntryKeysFromStorage({
980
+ model,
981
+ entry
982
+ });
1026
983
  };
1027
-
1028
984
  const getPublishedRevisionByEntryId = async (model, params) => {
1029
- const result = await dataLoaders.getPublishedRevisionByEntryId({
985
+ const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
1030
986
  model,
1031
987
  ids: [params.id]
1032
988
  });
1033
-
1034
- if (result.length === 0) {
989
+ if (!entry) {
1035
990
  return null;
1036
991
  }
1037
-
1038
- return result.shift();
992
+ return convertEntryKeysFromStorage({
993
+ model,
994
+ entry
995
+ });
1039
996
  };
1040
-
1041
997
  const getRevisionById = async (model, params) => {
1042
- const result = await dataLoaders.getRevisionById({
998
+ const [entry] = await dataLoaders.getRevisionById({
1043
999
  model,
1044
1000
  ids: [params.id]
1045
1001
  });
1046
-
1047
- if (result.length === 0) {
1002
+ if (!entry) {
1048
1003
  return null;
1049
1004
  }
1050
-
1051
- return result.shift();
1005
+ return convertEntryKeysFromStorage({
1006
+ model,
1007
+ entry
1008
+ });
1052
1009
  };
1053
-
1054
1010
  const getRevisions = async (model, params) => {
1055
- return await dataLoaders.getAllEntryRevisions({
1011
+ const entries = await dataLoaders.getAllEntryRevisions({
1056
1012
  model,
1057
1013
  ids: [params.id]
1058
1014
  });
1015
+ return entries.map(entry => {
1016
+ return convertEntryKeysFromStorage({
1017
+ model,
1018
+ entry
1019
+ });
1020
+ });
1059
1021
  };
1060
-
1061
1022
  const getByIds = async (model, params) => {
1062
- return dataLoaders.getRevisionById({
1023
+ const entries = await dataLoaders.getRevisionById({
1063
1024
  model,
1064
1025
  ids: params.ids
1065
1026
  });
1027
+ return entries.map(entry => {
1028
+ return convertEntryKeysFromStorage({
1029
+ model,
1030
+ entry
1031
+ });
1032
+ });
1066
1033
  };
1067
-
1068
1034
  const getLatestByIds = async (model, params) => {
1069
- return dataLoaders.getLatestRevisionByEntryId({
1035
+ const entries = await dataLoaders.getLatestRevisionByEntryId({
1070
1036
  model,
1071
1037
  ids: params.ids
1072
1038
  });
1039
+ return entries.map(entry => {
1040
+ return convertEntryKeysFromStorage({
1041
+ model,
1042
+ entry
1043
+ });
1044
+ });
1073
1045
  };
1074
-
1075
1046
  const getPublishedByIds = async (model, params) => {
1076
- return dataLoaders.getPublishedRevisionByEntryId({
1047
+ const entries = await dataLoaders.getPublishedRevisionByEntryId({
1077
1048
  model,
1078
1049
  ids: params.ids
1079
1050
  });
1051
+ return entries.map(entry => {
1052
+ return convertEntryKeysFromStorage({
1053
+ model,
1054
+ entry
1055
+ });
1056
+ });
1080
1057
  };
1081
-
1082
1058
  const getPreviousRevision = async (model, params) => {
1083
1059
  const {
1084
1060
  tenant,
@@ -1097,13 +1073,12 @@ const createEntriesStorageOperations = params => {
1097
1073
  }),
1098
1074
  options: {
1099
1075
  lt: `REV#${(0, _utils.zeroPad)(version)}`,
1100
-
1101
1076
  /**
1102
1077
  * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
1103
1078
  */
1104
1079
  filters: [{
1105
1080
  attr: "TYPE",
1106
- eq: createType()
1081
+ eq: (0, _recordType.createRecordType)()
1107
1082
  }, {
1108
1083
  attr: "version",
1109
1084
  lt: version
@@ -1111,12 +1086,18 @@ const createEntriesStorageOperations = params => {
1111
1086
  reverse: true
1112
1087
  }
1113
1088
  };
1114
-
1115
1089
  try {
1116
1090
  const result = await (0, _query.queryOne)(queryParams);
1117
- return (0, _cleanup.cleanupItem)(entity, result);
1091
+ const entry = (0, _cleanup.cleanupItem)(entity, result);
1092
+ if (!entry) {
1093
+ return null;
1094
+ }
1095
+ return convertEntryKeysFromStorage({
1096
+ entry,
1097
+ model
1098
+ });
1118
1099
  } catch (ex) {
1119
- throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", _objectSpread(_objectSpread({}, params), {}, {
1100
+ throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
1120
1101
  error: ex,
1121
1102
  partitionKey: queryParams.partitionKey,
1122
1103
  options: queryParams.options,
@@ -1124,7 +1105,6 @@ const createEntriesStorageOperations = params => {
1124
1105
  }));
1125
1106
  }
1126
1107
  };
1127
-
1128
1108
  return {
1129
1109
  create,
1130
1110
  createRevisionFrom,
@@ -1134,10 +1114,7 @@ const createEntriesStorageOperations = params => {
1134
1114
  get,
1135
1115
  publish,
1136
1116
  unpublish,
1137
- requestReview,
1138
- requestChanges,
1139
1117
  list,
1140
- getAllRevisionsByIds,
1141
1118
  getLatestRevisionByEntryId,
1142
1119
  getPublishedRevisionByEntryId,
1143
1120
  getRevisionById,
@@ -1148,5 +1125,4 @@ const createEntriesStorageOperations = params => {
1148
1125
  getPreviousRevision
1149
1126
  };
1150
1127
  };
1151
-
1152
1128
  exports.createEntriesStorageOperations = createEntriesStorageOperations;