@webiny/api-headless-cms-ddb 0.0.0-unstable.496cf268ac → 0.0.0-unstable.5387e5f7c8

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 (294) hide show
  1. package/README.md +6 -20
  2. package/abstractions/CmsDdbDataLoaders.d.ts +5 -0
  3. package/abstractions/CmsDdbDataLoaders.js +5 -0
  4. package/abstractions/CmsDdbDataLoaders.js.map +1 -0
  5. package/abstractions/CmsDdbEntryEntity.d.ts +5 -0
  6. package/abstractions/CmsDdbEntryEntity.js +5 -0
  7. package/abstractions/CmsDdbEntryEntity.js.map +1 -0
  8. package/abstractions/CmsDdbGroupEntity.d.ts +5 -0
  9. package/abstractions/CmsDdbGroupEntity.js +5 -0
  10. package/abstractions/CmsDdbGroupEntity.js.map +1 -0
  11. package/abstractions/CmsDdbModelEntity.d.ts +5 -0
  12. package/abstractions/CmsDdbModelEntity.js +5 -0
  13. package/abstractions/CmsDdbModelEntity.js.map +1 -0
  14. package/abstractions/CmsDdbTable.d.ts +5 -0
  15. package/abstractions/CmsDdbTable.js +5 -0
  16. package/abstractions/CmsDdbTable.js.map +1 -0
  17. package/definitions/entry.d.ts +4 -5
  18. package/definitions/entry.js +10 -93
  19. package/definitions/entry.js.map +1 -1
  20. package/definitions/group.d.ts +4 -5
  21. package/definitions/group.js +10 -64
  22. package/definitions/group.js.map +1 -1
  23. package/definitions/model.d.ts +4 -5
  24. package/definitions/model.js +10 -108
  25. package/definitions/model.js.map +1 -1
  26. package/definitions/table.d.ts +4 -6
  27. package/definitions/table.js +7 -26
  28. package/definitions/table.js.map +1 -1
  29. package/definitions/types.d.ts +65 -0
  30. package/definitions/types.js +0 -0
  31. package/index.d.ts +10 -3
  32. package/index.js +45 -129
  33. package/index.js.map +1 -1
  34. package/operations/entry/DdbCreateEntry.d.ts +16 -0
  35. package/operations/entry/DdbCreateEntry.js +77 -0
  36. package/operations/entry/DdbCreateEntry.js.map +1 -0
  37. package/operations/entry/DdbCreateEntryRevisionFrom.d.ts +16 -0
  38. package/operations/entry/DdbCreateEntryRevisionFrom.js +85 -0
  39. package/operations/entry/DdbCreateEntryRevisionFrom.js.map +1 -0
  40. package/operations/entry/DdbDeleteEntry.d.ts +16 -0
  41. package/operations/entry/DdbDeleteEntry.js +65 -0
  42. package/operations/entry/DdbDeleteEntry.js.map +1 -0
  43. package/operations/entry/DdbDeleteEntryRevision.d.ts +17 -0
  44. package/operations/entry/DdbDeleteEntryRevision.js +91 -0
  45. package/operations/entry/DdbDeleteEntryRevision.js.map +1 -0
  46. package/operations/entry/DdbDeleteMultipleEntries.d.ts +16 -0
  47. package/operations/entry/DdbDeleteMultipleEntries.js +59 -0
  48. package/operations/entry/DdbDeleteMultipleEntries.js.map +1 -0
  49. package/operations/entry/DdbGetEntriesByIds.d.ts +14 -0
  50. package/operations/entry/DdbGetEntriesByIds.js +31 -0
  51. package/operations/entry/DdbGetEntriesByIds.js.map +1 -0
  52. package/operations/entry/DdbGetEntry.d.ts +14 -0
  53. package/operations/entry/DdbGetEntry.js +27 -0
  54. package/operations/entry/DdbGetEntry.js.map +1 -0
  55. package/operations/entry/DdbGetLatestEntriesByIds.d.ts +14 -0
  56. package/operations/entry/DdbGetLatestEntriesByIds.js +31 -0
  57. package/operations/entry/DdbGetLatestEntriesByIds.js.map +1 -0
  58. package/operations/entry/DdbGetLatestRevisionByEntryId.d.ts +14 -0
  59. package/operations/entry/DdbGetLatestRevisionByEntryId.js +35 -0
  60. package/operations/entry/DdbGetLatestRevisionByEntryId.js.map +1 -0
  61. package/operations/entry/DdbGetPreviousRevision.d.ts +14 -0
  62. package/operations/entry/DdbGetPreviousRevision.js +53 -0
  63. package/operations/entry/DdbGetPreviousRevision.js.map +1 -0
  64. package/operations/entry/DdbGetPublishedEntriesByIds.d.ts +14 -0
  65. package/operations/entry/DdbGetPublishedEntriesByIds.js +31 -0
  66. package/operations/entry/DdbGetPublishedEntriesByIds.js.map +1 -0
  67. package/operations/entry/DdbGetPublishedRevisionByEntryId.d.ts +14 -0
  68. package/operations/entry/DdbGetPublishedRevisionByEntryId.js +35 -0
  69. package/operations/entry/DdbGetPublishedRevisionByEntryId.js.map +1 -0
  70. package/operations/entry/DdbGetRevisionById.d.ts +14 -0
  71. package/operations/entry/DdbGetRevisionById.js +34 -0
  72. package/operations/entry/DdbGetRevisionById.js.map +1 -0
  73. package/operations/entry/DdbGetRevisions.d.ts +14 -0
  74. package/operations/entry/DdbGetRevisions.js +33 -0
  75. package/operations/entry/DdbGetRevisions.js.map +1 -0
  76. package/operations/entry/DdbGetUniqueFieldValues.d.ts +12 -0
  77. package/operations/entry/DdbGetUniqueFieldValues.js +31 -0
  78. package/operations/entry/DdbGetUniqueFieldValues.js.map +1 -0
  79. package/operations/entry/DdbListEntries.d.ts +28 -0
  80. package/operations/entry/DdbListEntries.js +124 -0
  81. package/operations/entry/DdbListEntries.js.map +1 -0
  82. package/operations/entry/DdbMoveEntry.d.ts +14 -0
  83. package/operations/entry/DdbMoveEntry.js +57 -0
  84. package/operations/entry/DdbMoveEntry.js.map +1 -0
  85. package/operations/entry/DdbMoveToBin.d.ts +16 -0
  86. package/operations/entry/DdbMoveToBin.js +77 -0
  87. package/operations/entry/DdbMoveToBin.js.map +1 -0
  88. package/operations/entry/DdbPublishEntry.d.ts +18 -0
  89. package/operations/entry/DdbPublishEntry.js +162 -0
  90. package/operations/entry/DdbPublishEntry.js.map +1 -0
  91. package/operations/entry/DdbRestoreFromBin.d.ts +16 -0
  92. package/operations/entry/DdbRestoreFromBin.js +78 -0
  93. package/operations/entry/DdbRestoreFromBin.js.map +1 -0
  94. package/operations/entry/DdbUnpublishEntry.d.ts +17 -0
  95. package/operations/entry/DdbUnpublishEntry.js +112 -0
  96. package/operations/entry/DdbUnpublishEntry.js.map +1 -0
  97. package/operations/entry/DdbUpdateEntry.d.ts +17 -0
  98. package/operations/entry/DdbUpdateEntry.js +105 -0
  99. package/operations/entry/DdbUpdateEntry.js.map +1 -0
  100. package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
  101. package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
  102. package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
  103. package/operations/entry/dataLoader/constants.d.ts +1 -0
  104. package/operations/entry/dataLoader/constants.js +5 -0
  105. package/operations/entry/dataLoader/constants.js.map +1 -0
  106. package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
  107. package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
  108. package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
  109. package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
  110. package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
  111. package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
  112. package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
  113. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
  114. package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
  115. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
  116. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
  117. package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
  118. package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
  119. package/operations/entry/dataLoader/getRevisionById.js +42 -0
  120. package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
  121. package/operations/entry/dataLoader/index.d.ts +8 -0
  122. package/operations/entry/dataLoader/index.js +18 -0
  123. package/operations/entry/dataLoader/index.js.map +1 -0
  124. package/operations/entry/dataLoader/types.d.ts +6 -0
  125. package/operations/entry/dataLoader/types.js +0 -0
  126. package/operations/entry/dataLoaders.d.ts +16 -31
  127. package/operations/entry/dataLoaders.js +92 -272
  128. package/operations/entry/dataLoaders.js.map +1 -1
  129. package/operations/entry/feature.d.ts +4 -0
  130. package/operations/entry/feature.js +55 -0
  131. package/operations/entry/feature.js.map +1 -0
  132. package/operations/entry/keys.d.ts +46 -2
  133. package/operations/entry/keys.js +54 -49
  134. package/operations/entry/keys.js.map +1 -1
  135. package/operations/entry/storageEntryUtils.d.ts +8 -0
  136. package/operations/entry/storageEntryUtils.js +25 -0
  137. package/operations/entry/storageEntryUtils.js.map +1 -0
  138. package/operations/group/DdbCreateGroup.d.ts +12 -0
  139. package/operations/group/DdbCreateGroup.js +35 -0
  140. package/operations/group/DdbCreateGroup.js.map +1 -0
  141. package/operations/group/DdbDeleteGroup.d.ts +12 -0
  142. package/operations/group/DdbDeleteGroup.js +31 -0
  143. package/operations/group/DdbDeleteGroup.js.map +1 -0
  144. package/operations/group/DdbGetGroup.d.ts +12 -0
  145. package/operations/group/DdbGetGroup.js +31 -0
  146. package/operations/group/DdbGetGroup.js.map +1 -0
  147. package/operations/group/DdbListGroups.d.ts +14 -0
  148. package/operations/group/DdbListGroups.js +52 -0
  149. package/operations/group/DdbListGroups.js.map +1 -0
  150. package/operations/group/DdbUpdateGroup.d.ts +12 -0
  151. package/operations/group/DdbUpdateGroup.js +35 -0
  152. package/operations/group/DdbUpdateGroup.js.map +1 -0
  153. package/operations/group/feature.d.ts +4 -0
  154. package/operations/group/feature.js +19 -0
  155. package/operations/group/feature.js.map +1 -0
  156. package/operations/group/keys.d.ts +15 -0
  157. package/operations/group/keys.js +17 -0
  158. package/operations/group/keys.js.map +1 -0
  159. package/operations/model/DdbCreateModel.d.ts +12 -0
  160. package/operations/model/DdbCreateModel.js +37 -0
  161. package/operations/model/DdbCreateModel.js.map +1 -0
  162. package/operations/model/DdbDeleteModel.d.ts +12 -0
  163. package/operations/model/DdbDeleteModel.js +31 -0
  164. package/operations/model/DdbDeleteModel.js.map +1 -0
  165. package/operations/model/DdbGetModel.d.ts +12 -0
  166. package/operations/model/DdbGetModel.js +30 -0
  167. package/operations/model/DdbGetModel.js.map +1 -0
  168. package/operations/model/DdbListModels.d.ts +12 -0
  169. package/operations/model/DdbListModels.js +36 -0
  170. package/operations/model/DdbListModels.js.map +1 -0
  171. package/operations/model/DdbUpdateModel.d.ts +12 -0
  172. package/operations/model/DdbUpdateModel.js +36 -0
  173. package/operations/model/DdbUpdateModel.js.map +1 -0
  174. package/operations/model/feature.d.ts +4 -0
  175. package/operations/model/feature.js +19 -0
  176. package/operations/model/feature.js.map +1 -0
  177. package/operations/model/keys.d.ts +15 -0
  178. package/operations/model/keys.js +16 -0
  179. package/operations/model/keys.js.map +1 -0
  180. package/package.json +30 -33
  181. package/types.d.ts +12 -45
  182. package/types.js +8 -14
  183. package/types.js.map +1 -1
  184. package/definitions/settings.d.ts +0 -9
  185. package/definitions/settings.js +0 -53
  186. package/definitions/settings.js.map +0 -1
  187. package/definitions/system.d.ts +0 -9
  188. package/definitions/system.js +0 -41
  189. package/definitions/system.js.map +0 -1
  190. package/dynamoDb/index.d.ts +0 -2
  191. package/dynamoDb/index.js +0 -13
  192. package/dynamoDb/index.js.map +0 -1
  193. package/dynamoDb/path/plainObject.d.ts +0 -2
  194. package/dynamoDb/path/plainObject.js +0 -33
  195. package/dynamoDb/path/plainObject.js.map +0 -1
  196. package/dynamoDb/storage/date.d.ts +0 -3
  197. package/dynamoDb/storage/date.js +0 -91
  198. package/dynamoDb/storage/date.js.map +0 -1
  199. package/dynamoDb/storage/longText.d.ts +0 -10
  200. package/dynamoDb/storage/longText.js +0 -91
  201. package/dynamoDb/storage/longText.js.map +0 -1
  202. package/dynamoDb/storage/richText.d.ts +0 -2
  203. package/dynamoDb/storage/richText.js +0 -95
  204. package/dynamoDb/storage/richText.js.map +0 -1
  205. package/dynamoDb/transformValue/datetime.d.ts +0 -5
  206. package/dynamoDb/transformValue/datetime.js +0 -45
  207. package/dynamoDb/transformValue/datetime.js.map +0 -1
  208. package/operations/entry/filtering/createExpressions.d.ts +0 -26
  209. package/operations/entry/filtering/createExpressions.js +0 -176
  210. package/operations/entry/filtering/createExpressions.js.map +0 -1
  211. package/operations/entry/filtering/createFields.d.ts +0 -14
  212. package/operations/entry/filtering/createFields.js +0 -105
  213. package/operations/entry/filtering/createFields.js.map +0 -1
  214. package/operations/entry/filtering/extractSort.d.ts +0 -17
  215. package/operations/entry/filtering/extractSort.js +0 -67
  216. package/operations/entry/filtering/extractSort.js.map +0 -1
  217. package/operations/entry/filtering/filter.d.ts +0 -15
  218. package/operations/entry/filtering/filter.js +0 -143
  219. package/operations/entry/filtering/filter.js.map +0 -1
  220. package/operations/entry/filtering/fullTextSearch.d.ts +0 -14
  221. package/operations/entry/filtering/fullTextSearch.js +0 -48
  222. package/operations/entry/filtering/fullTextSearch.js.map +0 -1
  223. package/operations/entry/filtering/getValue.d.ts +0 -5
  224. package/operations/entry/filtering/getValue.js +0 -63
  225. package/operations/entry/filtering/getValue.js.map +0 -1
  226. package/operations/entry/filtering/index.d.ts +0 -2
  227. package/operations/entry/filtering/index.js +0 -19
  228. package/operations/entry/filtering/index.js.map +0 -1
  229. package/operations/entry/filtering/mapPlugins.d.ts +0 -8
  230. package/operations/entry/filtering/mapPlugins.js +0 -31
  231. package/operations/entry/filtering/mapPlugins.js.map +0 -1
  232. package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +0 -2
  233. package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -41
  234. package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +0 -1
  235. package/operations/entry/filtering/plugins/index.d.ts +0 -1
  236. package/operations/entry/filtering/plugins/index.js +0 -13
  237. package/operations/entry/filtering/plugins/index.js.map +0 -1
  238. package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +0 -2
  239. package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -86
  240. package/operations/entry/filtering/plugins/objectFilterCreate.js.map +0 -1
  241. package/operations/entry/filtering/plugins/refFilterCreate.d.ts +0 -2
  242. package/operations/entry/filtering/plugins/refFilterCreate.js +0 -71
  243. package/operations/entry/filtering/plugins/refFilterCreate.js.map +0 -1
  244. package/operations/entry/filtering/sort.d.ts +0 -12
  245. package/operations/entry/filtering/sort.js +0 -69
  246. package/operations/entry/filtering/sort.js.map +0 -1
  247. package/operations/entry/filtering/systemFields.d.ts +0 -4
  248. package/operations/entry/filtering/systemFields.js +0 -70
  249. package/operations/entry/filtering/systemFields.js.map +0 -1
  250. package/operations/entry/filtering/transform.d.ts +0 -6
  251. package/operations/entry/filtering/transform.js +0 -16
  252. package/operations/entry/filtering/transform.js.map +0 -1
  253. package/operations/entry/filtering/types.d.ts +0 -40
  254. package/operations/entry/filtering/types.js +0 -5
  255. package/operations/entry/filtering/types.js.map +0 -1
  256. package/operations/entry/filtering/values.d.ts +0 -2
  257. package/operations/entry/filtering/values.js +0 -22
  258. package/operations/entry/filtering/values.js.map +0 -1
  259. package/operations/entry/filtering/where.d.ts +0 -5
  260. package/operations/entry/filtering/where.js +0 -32
  261. package/operations/entry/filtering/where.js.map +0 -1
  262. package/operations/entry/index.d.ts +0 -8
  263. package/operations/entry/index.js +0 -787
  264. package/operations/entry/index.js.map +0 -1
  265. package/operations/entry/systemFields.d.ts +0 -2
  266. package/operations/entry/systemFields.js +0 -72
  267. package/operations/entry/systemFields.js.map +0 -1
  268. package/operations/group/index.d.ts +0 -9
  269. package/operations/group/index.js +0 -162
  270. package/operations/group/index.js.map +0 -1
  271. package/operations/model/index.d.ts +0 -7
  272. package/operations/model/index.js +0 -137
  273. package/operations/model/index.js.map +0 -1
  274. package/operations/settings/index.d.ts +0 -7
  275. package/operations/settings/index.js +0 -111
  276. package/operations/settings/index.js.map +0 -1
  277. package/operations/system/index.d.ts +0 -7
  278. package/operations/system/index.js +0 -82
  279. package/operations/system/index.js.map +0 -1
  280. package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +0 -22
  281. package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -41
  282. package/plugins/CmsEntryFieldFilterPathPlugin.js.map +0 -1
  283. package/plugins/CmsEntryFieldFilterPlugin.d.ts +0 -43
  284. package/plugins/CmsEntryFieldFilterPlugin.js +0 -24
  285. package/plugins/CmsEntryFieldFilterPlugin.js.map +0 -1
  286. package/plugins/CmsEntryFieldSortingPlugin.d.ts +0 -42
  287. package/plugins/CmsEntryFieldSortingPlugin.js +0 -28
  288. package/plugins/CmsEntryFieldSortingPlugin.js.map +0 -1
  289. package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +0 -11
  290. package/plugins/CmsFieldFilterValueTransformPlugin.js +0 -24
  291. package/plugins/CmsFieldFilterValueTransformPlugin.js.map +0 -1
  292. package/plugins/index.d.ts +0 -4
  293. package/plugins/index.js +0 -49
  294. package/plugins/index.js.map +0 -1
@@ -1,787 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createEntriesStorageOperations = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _error = _interopRequireDefault(require("@webiny/error"));
10
- var _dataLoaders = require("./dataLoaders");
11
- var _types = require("@webiny/api-headless-cms/types");
12
- var _keys = require("./keys");
13
- var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
14
- var _query = require("@webiny/db-dynamodb/utils/query");
15
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
16
- var _cursor = require("@webiny/utils/cursor");
17
- var _zeroPad = require("@webiny/utils/zeroPad");
18
- var _apiHeadlessCms = require("@webiny/api-headless-cms");
19
- var _createFields = require("./filtering/createFields");
20
- var _filtering = require("./filtering");
21
- const createType = () => {
22
- return "cms.entry";
23
- };
24
- const createLatestType = () => {
25
- return `${createType()}.l`;
26
- };
27
- const createPublishedType = () => {
28
- return `${createType()}.p`;
29
- };
30
- const convertToStorageEntry = params => {
31
- const {
32
- model,
33
- storageEntry
34
- } = params;
35
- const values = model.convertValueKeyToStorage({
36
- fields: model.fields,
37
- values: storageEntry.values
38
- });
39
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
40
- values
41
- });
42
- };
43
- const convertFromStorageEntry = params => {
44
- const {
45
- model,
46
- storageEntry
47
- } = params;
48
- const values = model.convertValueKeyFromStorage({
49
- fields: model.fields,
50
- values: storageEntry.values
51
- });
52
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
53
- values
54
- });
55
- };
56
- const createEntriesStorageOperations = params => {
57
- const {
58
- entity,
59
- plugins
60
- } = params;
61
- const dataLoaders = new _dataLoaders.DataLoadersHandler({
62
- entity
63
- });
64
- const storageTransformPlugins = plugins.byType(_apiHeadlessCms.StorageTransformPlugin.type).reduce((collection, plugin) => {
65
- collection[plugin.fieldType] = plugin;
66
- return collection;
67
- }, {});
68
- const createStorageTransformCallable = model => {
69
- return (field, value) => {
70
- const plugin = storageTransformPlugins[field.type];
71
- if (!plugin) {
72
- return value;
73
- }
74
- return plugin.fromStorage({
75
- model,
76
- field,
77
- value,
78
- getStoragePlugin(fieldType) {
79
- return storageTransformPlugins[fieldType] || storageTransformPlugins["*"];
80
- },
81
- plugins
82
- });
83
- };
84
- };
85
- const create = async (model, params) => {
86
- const {
87
- entry,
88
- storageEntry: initialStorageEntry
89
- } = params;
90
- const partitionKey = (0, _keys.createPartitionKey)({
91
- id: entry.id,
92
- locale: model.locale,
93
- tenant: model.tenant
94
- });
95
- const isPublished = entry.status === "published";
96
- const locked = isPublished ? true : entry.locked;
97
- const storageEntry = convertToStorageEntry({
98
- model,
99
- storageEntry: initialStorageEntry
100
- });
101
- /**
102
- * We need to:
103
- * - create new main entry item
104
- * - create new or update latest entry item
105
- */
106
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
107
- locked,
108
- PK: partitionKey,
109
- SK: (0, _keys.createRevisionSortKey)(entry),
110
- TYPE: createType(),
111
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
112
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
113
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
114
- locked,
115
- PK: partitionKey,
116
- SK: (0, _keys.createLatestSortKey)(),
117
- TYPE: createLatestType(),
118
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
119
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
120
- }))];
121
-
122
- /**
123
- * We need to create published entry if
124
- */
125
- if (isPublished) {
126
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
127
- locked,
128
- PK: partitionKey,
129
- SK: (0, _keys.createPublishedSortKey)(),
130
- TYPE: createLatestType(),
131
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
132
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
133
- })));
134
- }
135
- try {
136
- await (0, _batchWrite.batchWriteAll)({
137
- table: entity.table,
138
- items
139
- });
140
- dataLoaders.clearAll({
141
- model
142
- });
143
- } catch (ex) {
144
- throw new _error.default(ex.message || "Could not insert data into the DynamoDB.", ex.code || "CREATE_ENTRY_ERROR", {
145
- error: ex,
146
- entry
147
- });
148
- }
149
- return initialStorageEntry;
150
- };
151
- const createRevisionFrom = async (model, params) => {
152
- const {
153
- entry,
154
- storageEntry: initialStorageEntry
155
- } = params;
156
- const partitionKey = (0, _keys.createPartitionKey)({
157
- id: entry.id,
158
- locale: model.locale,
159
- tenant: model.tenant
160
- });
161
- const storageEntry = convertToStorageEntry({
162
- storageEntry: initialStorageEntry,
163
- model
164
- });
165
- /**
166
- * We need to:
167
- * - create the main entry item
168
- * - update the last entry item to a current one
169
- */
170
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
171
- PK: partitionKey,
172
- SK: (0, _keys.createRevisionSortKey)(storageEntry),
173
- TYPE: createType(),
174
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
175
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
176
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
177
- PK: partitionKey,
178
- SK: (0, _keys.createLatestSortKey)(),
179
- TYPE: createLatestType(),
180
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
181
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
182
- }))];
183
- try {
184
- await (0, _batchWrite.batchWriteAll)({
185
- table: entity.table,
186
- items
187
- });
188
- dataLoaders.clearAll({
189
- model
190
- });
191
- } catch (ex) {
192
- throw new _error.default(ex.message || "Could not create revision from given entry.", ex.code || "CREATE_REVISION_ERROR", {
193
- error: ex,
194
- entry,
195
- storageEntry
196
- });
197
- }
198
- /**
199
- * There are no modifications on the entry created so just return the data.
200
- */
201
- return initialStorageEntry;
202
- };
203
- const update = async (model, params) => {
204
- const {
205
- entry,
206
- storageEntry: initialStorageEntry
207
- } = params;
208
- const partitionKey = (0, _keys.createPartitionKey)({
209
- id: entry.id,
210
- locale: model.locale,
211
- tenant: model.tenant
212
- });
213
- const isPublished = entry.status === "published";
214
- const locked = isPublished ? true : entry.locked;
215
- const items = [];
216
- const storageEntry = convertToStorageEntry({
217
- model,
218
- storageEntry: initialStorageEntry
219
- });
220
- /**
221
- * We need to:
222
- * - update the current entry
223
- * - update the latest entry if the current entry is the latest one
224
- */
225
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
226
- locked,
227
- PK: partitionKey,
228
- SK: (0, _keys.createRevisionSortKey)(storageEntry),
229
- TYPE: createType(),
230
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
231
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
232
- })));
233
- if (isPublished) {
234
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
235
- locked,
236
- PK: partitionKey,
237
- SK: (0, _keys.createPublishedSortKey)(),
238
- TYPE: createPublishedType(),
239
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
240
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
241
- })));
242
- }
243
-
244
- /**
245
- * We need the latest entry to update it as well if neccessary.
246
- */
247
- const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
248
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
249
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
250
- locked,
251
- PK: partitionKey,
252
- SK: (0, _keys.createLatestSortKey)(),
253
- TYPE: createLatestType(),
254
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
255
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
256
- })));
257
- }
258
- try {
259
- await (0, _batchWrite.batchWriteAll)({
260
- table: entity.table,
261
- items
262
- });
263
- dataLoaders.clearAll({
264
- model
265
- });
266
- return initialStorageEntry;
267
- } catch (ex) {
268
- throw new _error.default(ex.message || "Could not update entry.", ex.code || "UPDATE_ERROR", {
269
- error: ex,
270
- entry,
271
- latestStorageEntry
272
- });
273
- }
274
- };
275
- const deleteEntry = async (model, params) => {
276
- const {
277
- entry
278
- } = params;
279
- const queryAllParams = {
280
- entity,
281
- partitionKey: (0, _keys.createPartitionKey)({
282
- id: entry.id,
283
- locale: model.locale,
284
- tenant: model.tenant
285
- }),
286
- options: {
287
- gte: " "
288
- }
289
- };
290
- let records = [];
291
- try {
292
- records = await (0, _query.queryAll)(queryAllParams);
293
- } catch (ex) {
294
- throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
295
- error: ex,
296
- entry
297
- });
298
- }
299
- const items = records.map(item => {
300
- return entity.deleteBatch({
301
- PK: item.PK,
302
- SK: item.SK
303
- });
304
- });
305
- try {
306
- await (0, _batchWrite.batchWriteAll)({
307
- table: entity.table,
308
- items
309
- });
310
- dataLoaders.clearAll({
311
- model
312
- });
313
- } catch (ex) {
314
- throw new _error.default(ex.message || "Could not delete the entry.", ex.code || "DELETE_ENTRY_ERROR", {
315
- error: ex,
316
- partitionKey: queryAllParams.partitionKey,
317
- entry
318
- });
319
- }
320
- };
321
- const deleteRevision = async (model, params) => {
322
- const {
323
- entry,
324
- latestEntry,
325
- latestStorageEntry: initialLatestStorageEntry
326
- } = params;
327
- const partitionKey = (0, _keys.createPartitionKey)({
328
- id: entry.id,
329
- locale: model.locale,
330
- tenant: model.tenant
331
- });
332
- const items = [entity.deleteBatch({
333
- PK: partitionKey,
334
- SK: (0, _keys.createRevisionSortKey)(entry)
335
- })];
336
- const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
337
-
338
- /**
339
- * If revision we are deleting is the published one as well, we need to delete those records as well.
340
- */
341
- if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
342
- items.push(entity.deleteBatch({
343
- PK: partitionKey,
344
- SK: (0, _keys.createPublishedSortKey)()
345
- }));
346
- }
347
- if (initialLatestStorageEntry) {
348
- const latestStorageEntry = convertToStorageEntry({
349
- storageEntry: initialLatestStorageEntry,
350
- model
351
- });
352
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestStorageEntry), {}, {
353
- PK: partitionKey,
354
- SK: (0, _keys.createLatestSortKey)(),
355
- TYPE: createLatestType(),
356
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
357
- GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
358
- })));
359
- }
360
- try {
361
- await (0, _batchWrite.batchWriteAll)({
362
- table: entity.table,
363
- items
364
- });
365
- dataLoaders.clearAll({
366
- model
367
- });
368
- } catch (ex) {
369
- throw new _error.default(ex.message, ex.code, {
370
- error: ex,
371
- entry,
372
- latestEntry
373
- });
374
- }
375
- };
376
- const getLatestRevisionByEntryId = async (model, params) => {
377
- const items = await dataLoaders.getLatestRevisionByEntryId({
378
- model,
379
- ids: [params.id]
380
- });
381
- const item = items.shift() || null;
382
- if (!item) {
383
- return null;
384
- }
385
- return convertFromStorageEntry({
386
- storageEntry: item,
387
- model
388
- });
389
- };
390
- const getPublishedRevisionByEntryId = async (model, params) => {
391
- const items = await dataLoaders.getPublishedRevisionByEntryId({
392
- model,
393
- ids: [params.id]
394
- });
395
- const item = items.shift() || null;
396
- if (!item) {
397
- return null;
398
- }
399
- return convertFromStorageEntry({
400
- storageEntry: item,
401
- model
402
- });
403
- };
404
- const getRevisionById = async (model, params) => {
405
- const items = await dataLoaders.getRevisionById({
406
- model,
407
- ids: [params.id]
408
- });
409
- const item = items.shift() || null;
410
- if (!item) {
411
- return null;
412
- }
413
- return convertFromStorageEntry({
414
- storageEntry: item,
415
- model
416
- });
417
- };
418
- const getRevisions = async (model, params) => {
419
- const items = await dataLoaders.getAllEntryRevisions({
420
- model,
421
- ids: [params.id]
422
- });
423
- return items.map(item => {
424
- return convertFromStorageEntry({
425
- storageEntry: item,
426
- model
427
- });
428
- });
429
- };
430
- const getByIds = async (model, params) => {
431
- const items = await dataLoaders.getRevisionById({
432
- model,
433
- ids: params.ids
434
- });
435
- return items.map(item => {
436
- return convertFromStorageEntry({
437
- storageEntry: item,
438
- model
439
- });
440
- });
441
- };
442
- const getLatestByIds = async (model, params) => {
443
- const items = await dataLoaders.getLatestRevisionByEntryId({
444
- model,
445
- ids: params.ids
446
- });
447
- return items.map(item => {
448
- return convertFromStorageEntry({
449
- storageEntry: item,
450
- model
451
- });
452
- });
453
- };
454
- const getPublishedByIds = async (model, params) => {
455
- const items = await dataLoaders.getPublishedRevisionByEntryId({
456
- model,
457
- ids: params.ids
458
- });
459
- return items.map(item => {
460
- return convertFromStorageEntry({
461
- storageEntry: item,
462
- model
463
- });
464
- });
465
- };
466
- const getPreviousRevision = async (model, params) => {
467
- const {
468
- entryId,
469
- version
470
- } = params;
471
- const queryParams = {
472
- entity,
473
- partitionKey: (0, _keys.createPartitionKey)({
474
- tenant: model.tenant,
475
- locale: model.locale,
476
- id: entryId
477
- }),
478
- options: {
479
- lt: `REV#${(0, _zeroPad.zeroPad)(version)}`,
480
- /**
481
- * We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
482
- */
483
- filters: [{
484
- attr: "TYPE",
485
- eq: createType()
486
- }, {
487
- attr: "version",
488
- lt: version
489
- }],
490
- reverse: true
491
- }
492
- };
493
- try {
494
- const result = await (0, _query.queryOne)(queryParams);
495
- const storageEntry = (0, _cleanup.cleanupItem)(entity, result);
496
- if (!storageEntry) {
497
- return null;
498
- }
499
- return convertFromStorageEntry({
500
- storageEntry,
501
- model
502
- });
503
- } catch (ex) {
504
- 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), {}, {
505
- error: ex,
506
- partitionKey: queryParams.partitionKey,
507
- options: queryParams.options,
508
- model
509
- }));
510
- }
511
- };
512
- const list = async (model, params) => {
513
- const {
514
- limit: initialLimit = 10,
515
- where: initialWhere,
516
- after,
517
- sort: sortBy,
518
- fields,
519
- search
520
- } = params;
521
- const limit = initialLimit <= 0 || initialLimit >= 10000 ? 10000 : initialLimit;
522
- const type = initialWhere.published ? "P" : "L";
523
- const queryAllParams = {
524
- entity,
525
- partitionKey: (0, _keys.createGSIPartitionKey)(model, type),
526
- options: {
527
- index: "GSI1",
528
- gte: " "
529
- }
530
- };
531
- let storageEntries = [];
532
- try {
533
- storageEntries = await (0, _query.queryAll)(queryAllParams);
534
- } catch (ex) {
535
- throw new _error.default(ex.message, "QUERY_ENTRIES_ERROR", {
536
- error: ex,
537
- partitionKey: queryAllParams.partitionKey,
538
- options: queryAllParams.options
539
- });
540
- }
541
- if (storageEntries.length === 0) {
542
- return {
543
- hasMoreItems: false,
544
- totalCount: 0,
545
- cursor: null,
546
- items: []
547
- };
548
- }
549
- const where = (0, _objectSpread2.default)({}, initialWhere);
550
- delete where["published"];
551
- delete where["latest"];
552
- /**
553
- * We need an object containing field, transformers and paths.
554
- * Just build it here and pass on into other methods that require it to avoid mapping multiple times.
555
- */
556
- const modelFields = (0, _createFields.createFields)({
557
- plugins,
558
- fields: model.fields
559
- });
560
- const fromStorage = createStorageTransformCallable(model);
561
- /**
562
- * Let's transform records from storage ones to regular ones, so we do not need to do it later.
563
- *
564
- * This is always being done, but at least its in parallel.
565
- */
566
- const records = await Promise.all(storageEntries.map(async storageEntry => {
567
- const entry = convertFromStorageEntry({
568
- storageEntry,
569
- model
570
- });
571
- for (const field of model.fields) {
572
- entry.values[field.fieldId] = await fromStorage(field, entry.values[field.fieldId]);
573
- }
574
- return entry;
575
- }));
576
- /**
577
- * Filter the read items via the code.
578
- * It will build the filters out of the where input and transform the values it is using.
579
- */
580
- const filteredItems = (0, _filtering.filter)({
581
- items: records,
582
- where,
583
- plugins,
584
- fields: modelFields,
585
- fullTextSearch: {
586
- term: search,
587
- fields: fields || []
588
- }
589
- });
590
- const totalCount = filteredItems.length;
591
-
592
- /**
593
- * Sorting is also done via the code.
594
- * It takes the sort input and sorts by it via the lodash sortBy method.
595
- */
596
- const sortedItems = (0, _filtering.sort)({
597
- model,
598
- plugins,
599
- items: filteredItems,
600
- sort: sortBy,
601
- fields: modelFields
602
- });
603
- const start = parseInt((0, _cursor.decodeCursor)(after) || "0") || 0;
604
- const hasMoreItems = totalCount > start + limit;
605
- const end = limit > totalCount + start + limit ? undefined : start + limit;
606
- const slicedItems = sortedItems.slice(start, end);
607
- /**
608
- * Although we do not need a cursor here, we will use it as such to keep it standardized.
609
- * Number is simply encoded.
610
- */
611
- const cursor = totalCount > start + limit ? (0, _cursor.encodeCursor)(`${start + limit}`) : null;
612
- return {
613
- hasMoreItems,
614
- totalCount,
615
- cursor,
616
- items: (0, _cleanup.cleanupItems)(entity, slicedItems)
617
- };
618
- };
619
- const get = async (model, params) => {
620
- const {
621
- items
622
- } = await list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
623
- limit: 1
624
- }));
625
- return items.shift() || null;
626
- };
627
- const publish = async (model, params) => {
628
- const {
629
- entry,
630
- storageEntry: initialStorageEntry
631
- } = params;
632
- const partitionKey = (0, _keys.createPartitionKey)({
633
- id: entry.id,
634
- locale: model.locale,
635
- tenant: model.tenant
636
- });
637
-
638
- /**
639
- * We need the latest and published entries to see if something needs to be updated along side the publishing one.
640
- */
641
- const initialLatestStorageEntry = await getLatestRevisionByEntryId(model, entry);
642
- const initialPublishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
643
- const storageEntry = convertToStorageEntry({
644
- model,
645
- storageEntry: initialStorageEntry
646
- });
647
- /**
648
- * We need to update:
649
- * - current entry revision sort key
650
- * - published sort key
651
- * - latest sort key - if entry updated is actually latest
652
- * - previous published entry to unpublished status - if any previously published entry
653
- */
654
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
655
- PK: partitionKey,
656
- SK: (0, _keys.createRevisionSortKey)(entry),
657
- TYPE: createType(),
658
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
659
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
660
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
661
- PK: partitionKey,
662
- SK: (0, _keys.createPublishedSortKey)(),
663
- TYPE: createPublishedType(),
664
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
665
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
666
- }))];
667
- if (initialLatestStorageEntry && entry.id === initialLatestStorageEntry.id) {
668
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
669
- PK: partitionKey,
670
- SK: (0, _keys.createLatestSortKey)(),
671
- TYPE: createLatestType(),
672
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
673
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
674
- })));
675
- }
676
- if (initialPublishedStorageEntry && initialPublishedStorageEntry.id !== entry.id) {
677
- const publishedStorageEntry = convertToStorageEntry({
678
- storageEntry: initialPublishedStorageEntry,
679
- model
680
- });
681
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedStorageEntry), {}, {
682
- PK: partitionKey,
683
- SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
684
- TYPE: createType(),
685
- status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
686
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
687
- GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
688
- })));
689
- }
690
- try {
691
- await (0, _batchWrite.batchWriteAll)({
692
- table: entity.table,
693
- items
694
- });
695
- dataLoaders.clearAll({
696
- model
697
- });
698
- return initialStorageEntry;
699
- } catch (ex) {
700
- throw new _error.default(ex.message || "Could not execute the publishing batch.", ex.code || "PUBLISH_ERROR", {
701
- entry,
702
- latestStorageEntry: initialLatestStorageEntry,
703
- publishedStorageEntry: initialPublishedStorageEntry
704
- });
705
- }
706
- };
707
- const unpublish = async (model, params) => {
708
- const {
709
- entry,
710
- storageEntry: initialStorageEntry
711
- } = params;
712
- const partitionKey = (0, _keys.createPartitionKey)({
713
- id: entry.id,
714
- locale: model.locale,
715
- tenant: model.tenant
716
- });
717
- const storageEntry = convertToStorageEntry({
718
- storageEntry: initialStorageEntry,
719
- model
720
- });
721
- /**
722
- * We need to:
723
- * - delete currently published entry
724
- * - update current entry revision with new data
725
- * - update latest entry status - if entry being unpublished is latest
726
- */
727
- const items = [entity.deleteBatch({
728
- PK: partitionKey,
729
- SK: (0, _keys.createPublishedSortKey)()
730
- }), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
731
- PK: partitionKey,
732
- SK: (0, _keys.createRevisionSortKey)(entry),
733
- TYPE: createType(),
734
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
735
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
736
- }))];
737
-
738
- /**
739
- * We need the latest entry to see if something needs to be updated along side the unpublishing one.
740
- */
741
- const latestStorageEntry = await getLatestRevisionByEntryId(model, entry);
742
- if (latestStorageEntry && entry.id === latestStorageEntry.id) {
743
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
744
- PK: partitionKey,
745
- SK: (0, _keys.createLatestSortKey)(),
746
- TYPE: createLatestType(),
747
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
748
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
749
- })));
750
- }
751
- try {
752
- await (0, _batchWrite.batchWriteAll)({
753
- table: entity.table,
754
- items
755
- });
756
- dataLoaders.clearAll({
757
- model
758
- });
759
- return initialStorageEntry;
760
- } catch (ex) {
761
- throw new _error.default(ex.message || "Could not execute unpublish batch.", ex.code || "UNPUBLISH_ERROR", {
762
- entry,
763
- storageEntry
764
- });
765
- }
766
- };
767
- return {
768
- create,
769
- createRevisionFrom,
770
- update,
771
- delete: deleteEntry,
772
- deleteRevision,
773
- getPreviousRevision,
774
- getPublishedByIds,
775
- getLatestByIds,
776
- getByIds,
777
- getRevisionById,
778
- getPublishedRevisionByEntryId,
779
- getLatestRevisionByEntryId,
780
- get,
781
- getRevisions,
782
- publish,
783
- list,
784
- unpublish
785
- };
786
- };
787
- exports.createEntriesStorageOperations = createEntriesStorageOperations;