@webiny/api-headless-cms-ddb-es 0.0.0-mt-2 → 0.0.0-unstable.1145e7667f

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