@webiny/api-headless-cms-ddb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7c2def32a7

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