@webiny/api-headless-cms-ddb 5.17.4 → 5.18.0-beta.3

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 (91) hide show
  1. package/definitions/entry.d.ts +6 -4
  2. package/definitions/entry.js +19 -8
  3. package/definitions/group.d.ts +8 -0
  4. package/definitions/group.js +74 -0
  5. package/definitions/model.d.ts +8 -0
  6. package/definitions/model.js +96 -0
  7. package/definitions/settings.d.ts +8 -0
  8. package/definitions/settings.js +62 -0
  9. package/definitions/system.d.ts +8 -0
  10. package/definitions/system.js +50 -0
  11. package/definitions/table.d.ts +6 -12
  12. package/definitions/table.js +15 -15
  13. package/dynamoDb/index.d.ts +1 -1
  14. package/dynamoDb/index.js +4 -3
  15. package/dynamoDb/path/plainObject.js +1 -2
  16. package/dynamoDb/path/ref.js +1 -2
  17. package/dynamoDb/storage/date.d.ts +2 -2
  18. package/dynamoDb/storage/date.js +17 -21
  19. package/dynamoDb/storage/longText.d.ts +7 -0
  20. package/dynamoDb/storage/longText.js +83 -0
  21. package/dynamoDb/storage/richText.d.ts +2 -2
  22. package/dynamoDb/storage/richText.js +69 -67
  23. package/dynamoDb/transformValue/datetime.d.ts +1 -1
  24. package/dynamoDb/transformValue/datetime.js +1 -2
  25. package/index.d.ts +2 -6
  26. package/index.js +108 -13
  27. package/operations/entry/dataLoaders.d.ts +34 -19
  28. package/operations/entry/dataLoaders.js +158 -138
  29. package/operations/entry/index.d.ts +8 -4
  30. package/operations/entry/index.js +812 -16
  31. package/operations/entry/keys.d.ts +25 -0
  32. package/operations/entry/keys.js +62 -0
  33. package/operations/entry/systemFields.d.ts +2 -2
  34. package/operations/entry/systemFields.js +1 -2
  35. package/operations/entry/utils.d.ts +13 -9
  36. package/operations/entry/utils.js +62 -18
  37. package/operations/group/index.d.ts +8 -0
  38. package/operations/group/index.js +198 -0
  39. package/operations/model/index.d.ts +6 -3
  40. package/operations/model/index.js +153 -18
  41. package/operations/settings/index.d.ts +6 -3
  42. package/operations/settings/index.js +132 -16
  43. package/operations/system/index.d.ts +6 -3
  44. package/operations/system/index.js +94 -14
  45. package/package.json +11 -11
  46. package/types.d.ts +38 -8
  47. package/types.js +11 -1
  48. package/configurations.d.ts +0 -18
  49. package/configurations.js +0 -24
  50. package/configurations.js.map +0 -1
  51. package/definitions/entry.js.map +0 -1
  52. package/definitions/table.js.map +0 -1
  53. package/dynamoDb/index.js.map +0 -1
  54. package/dynamoDb/path/plainObject.js.map +0 -1
  55. package/dynamoDb/path/ref.js.map +0 -1
  56. package/dynamoDb/storage/date.js.map +0 -1
  57. package/dynamoDb/storage/richText.js.map +0 -1
  58. package/dynamoDb/transformValue/datetime.js.map +0 -1
  59. package/index.js.map +0 -1
  60. package/operations/entry/CmsContentEntryDynamo.d.ts +0 -86
  61. package/operations/entry/CmsContentEntryDynamo.js +0 -972
  62. package/operations/entry/CmsContentEntryDynamo.js.map +0 -1
  63. package/operations/entry/dataLoaders.js.map +0 -1
  64. package/operations/entry/index.js.map +0 -1
  65. package/operations/entry/systemFields.js.map +0 -1
  66. package/operations/entry/utils.js.map +0 -1
  67. package/operations/helpers.d.ts +0 -5
  68. package/operations/helpers.js +0 -96
  69. package/operations/helpers.js.map +0 -1
  70. package/operations/model/CmsContentModelDynamo.d.ts +0 -18
  71. package/operations/model/CmsContentModelDynamo.js +0 -234
  72. package/operations/model/CmsContentModelDynamo.js.map +0 -1
  73. package/operations/model/index.js.map +0 -1
  74. package/operations/modelGroup/CmsContentModelGroupDynamo.d.ts +0 -42
  75. package/operations/modelGroup/CmsContentModelGroupDynamo.js +0 -230
  76. package/operations/modelGroup/CmsContentModelGroupDynamo.js.map +0 -1
  77. package/operations/modelGroup/index.d.ts +0 -3
  78. package/operations/modelGroup/index.js +0 -26
  79. package/operations/modelGroup/index.js.map +0 -1
  80. package/operations/settings/CmsSettingsDynamo.d.ts +0 -16
  81. package/operations/settings/CmsSettingsDynamo.js +0 -145
  82. package/operations/settings/CmsSettingsDynamo.js.map +0 -1
  83. package/operations/settings/index.js.map +0 -1
  84. package/operations/system/CmsSystemDynamo.d.ts +0 -16
  85. package/operations/system/CmsSystemDynamo.js +0 -126
  86. package/operations/system/CmsSystemDynamo.js.map +0 -1
  87. package/operations/system/index.js.map +0 -1
  88. package/types.js.map +0 -1
  89. package/utils.d.ts +0 -5
  90. package/utils.js +0 -62
  91. package/utils.js.map +0 -1
@@ -13,146 +13,183 @@ var _dataloader = _interopRequireDefault(require("dataloader"));
13
13
 
14
14
  var _error = _interopRequireDefault(require("@webiny/error"));
15
15
 
16
- 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; }
17
-
18
- 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; }
16
+ var _query = require("@webiny/db-dynamodb/utils/query");
19
17
 
20
- /**
21
- * *** GLOBAL NOTE ***
22
- * When records are received from the batch get, we get them in all sorts of order.
23
- * What we need for DataLoader to work properly we must have id > records order.
24
- * So in the order IDs got into the DataLoader, its records must go out in the same order / bundle.
25
- */
26
- const flatResponses = responses => {
27
- const entries = [];
28
- const values = Object.values(responses);
29
-
30
- for (const items of values) {
31
- entries.push(...items);
32
- }
18
+ var _keys = require("./keys");
33
19
 
34
- return entries;
35
- };
20
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
36
21
 
37
- const executeBatchGet = async (storageOperations, batch) => {
38
- const items = [];
39
- const result = await storageOperations.table.batchGet(batch);
22
+ var _utils = require("@webiny/utils");
40
23
 
41
- if (!result) {
42
- return items;
43
- }
24
+ var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
44
25
 
45
- if (result.Responses) {
46
- items.push(...flatResponses(result.Responses));
47
- }
48
-
49
- if (typeof result.next === "function") {
50
- let previous = result;
51
- let nResult;
52
-
53
- while (nResult = await previous.next()) {
54
- items.push(...flatResponses(nResult.Responses));
55
- previous = nResult;
56
-
57
- if (!nResult || typeof nResult.next !== "function") {
58
- return items;
59
- }
60
- }
61
- }
26
+ 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; }
62
27
 
63
- return items;
64
- };
28
+ 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; }
65
29
 
66
- const getAllEntryRevisions = (context, model, storageOperations) => {
30
+ const getAllEntryRevisions = params => {
31
+ const {
32
+ entity,
33
+ model
34
+ } = params;
35
+ const {
36
+ tenant,
37
+ locale
38
+ } = model;
67
39
  return new _dataloader.default(async ids => {
68
- const promises = ids.map(id => {
69
- const partitionKey = storageOperations.getPartitionKey(id);
70
- return storageOperations.runQuery({
71
- partitionKey,
40
+ const results = [];
41
+
42
+ for (const id of ids) {
43
+ const queryAllParams = {
44
+ entity,
45
+ partitionKey: (0, _keys.createPartitionKey)({
46
+ tenant,
47
+ locale,
48
+ id
49
+ }),
72
50
  options: {
73
51
  beginsWith: "REV#"
74
52
  }
75
- });
76
- });
77
- return Promise.all(promises);
53
+ };
54
+ const items = await (0, _query.queryAll)(queryAllParams);
55
+ const entries = (0, _cleanup.cleanupItems)(entity, items);
56
+ results.push(entries);
57
+ }
58
+
59
+ return results;
78
60
  });
79
61
  };
80
62
 
81
- const getRevisionById = (context, model, storageOperations) => {
63
+ const getRevisionById = params => {
64
+ const {
65
+ entity,
66
+ model
67
+ } = params;
68
+ const {
69
+ locale,
70
+ tenant
71
+ } = model;
82
72
  return new _dataloader.default(async ids => {
83
- const batch = ids.reduce((collection, id) => {
84
- const partitionKey = storageOperations.getPartitionKey(id);
85
- const sortKey = storageOperations.getSortKeyRevision(id);
73
+ const queries = ids.reduce((collection, id) => {
74
+ const partitionKey = (0, _keys.createPartitionKey)({
75
+ tenant,
76
+ locale,
77
+ id
78
+ });
79
+ const {
80
+ version
81
+ } = (0, _utils.parseIdentifier)(id);
82
+ const sortKey = (0, _keys.createRevisionSortKey)({
83
+ version
84
+ });
86
85
  const keys = `${partitionKey}__${sortKey}`;
87
86
 
88
87
  if (collection[keys]) {
89
88
  return collection;
90
89
  }
91
90
 
92
- collection[keys] = storageOperations.entity.getBatch({
91
+ collection[keys] = entity.getBatch({
93
92
  PK: partitionKey,
94
93
  SK: sortKey
95
94
  });
96
95
  return collection;
97
96
  }, {});
98
- const items = await executeBatchGet(storageOperations, Object.values(batch));
97
+ const records = await (0, _batchRead.batchReadAll)({
98
+ table: entity.table,
99
+ items: Object.values(queries)
100
+ });
101
+ const items = (0, _cleanup.cleanupItems)(entity, records);
99
102
  return ids.map(id => {
100
103
  return items.filter(item => {
101
- const partitionKey = storageOperations.getPartitionKey(id);
102
- const sortKey = storageOperations.getSortKeyRevision(id);
103
- return item.PK === partitionKey && item.SK === sortKey;
104
+ return id === item.id;
104
105
  });
105
106
  });
106
107
  });
107
108
  };
108
109
 
109
- const getPublishedRevisionByEntryId = (context, model, storageOperations) => {
110
+ const getPublishedRevisionByEntryId = params => {
111
+ const {
112
+ entity,
113
+ model
114
+ } = params;
115
+ const {
116
+ locale,
117
+ tenant
118
+ } = model;
119
+ const publishedKey = (0, _keys.createPublishedSortKey)();
110
120
  return new _dataloader.default(async ids => {
111
- const sortKey = storageOperations.getSortKeyPublished();
112
- const batch = ids.reduce((collection, id) => {
113
- const partitionKey = storageOperations.getPartitionKey(id);
121
+ const queries = ids.reduce((collection, id) => {
122
+ const partitionKey = (0, _keys.createPartitionKey)({
123
+ tenant,
124
+ locale,
125
+ id
126
+ });
114
127
 
115
128
  if (collection[partitionKey]) {
116
129
  return collection;
117
130
  }
118
131
 
119
- collection[partitionKey] = storageOperations.entity.getBatch({
132
+ collection[partitionKey] = entity.getBatch({
120
133
  PK: partitionKey,
121
- SK: sortKey
134
+ SK: publishedKey
122
135
  });
123
136
  return collection;
124
137
  }, {});
125
- const items = await executeBatchGet(storageOperations, Object.values(batch));
138
+ const records = await (0, _batchRead.batchReadAll)({
139
+ table: entity.table,
140
+ items: Object.values(queries)
141
+ });
142
+ const items = (0, _cleanup.cleanupItems)(entity, records);
126
143
  return ids.map(id => {
144
+ const {
145
+ id: entryId
146
+ } = (0, _utils.parseIdentifier)(id);
127
147
  return items.filter(item => {
128
- const partitionKey = storageOperations.getPartitionKey(id);
129
- return item.PK === partitionKey && item.SK === sortKey;
148
+ return entryId === item.entryId;
130
149
  });
131
150
  });
132
151
  });
133
152
  };
134
153
 
135
- const getLatestRevisionByEntryId = (context, model, storageOperations) => {
154
+ const getLatestRevisionByEntryId = params => {
155
+ const {
156
+ entity,
157
+ model
158
+ } = params;
159
+ const {
160
+ locale,
161
+ tenant
162
+ } = model;
163
+ const latestKey = (0, _keys.createLatestSortKey)();
136
164
  return new _dataloader.default(async ids => {
137
- const sortKey = storageOperations.getSortKeyLatest();
138
- const batch = ids.reduce((collection, id) => {
139
- const partitionKey = storageOperations.getPartitionKey(id);
165
+ const queries = ids.reduce((collection, id) => {
166
+ const partitionKey = (0, _keys.createPartitionKey)({
167
+ tenant,
168
+ locale,
169
+ id
170
+ });
140
171
 
141
172
  if (collection[partitionKey]) {
142
173
  return collection;
143
174
  }
144
175
 
145
- collection[partitionKey] = storageOperations.entity.getBatch({
176
+ collection[partitionKey] = entity.getBatch({
146
177
  PK: partitionKey,
147
- SK: sortKey
178
+ SK: latestKey
148
179
  });
149
180
  return collection;
150
181
  }, {});
151
- const items = await executeBatchGet(storageOperations, Object.values(batch));
182
+ const records = await (0, _batchRead.batchReadAll)({
183
+ table: entity.table,
184
+ items: Object.values(queries)
185
+ });
186
+ const items = (0, _cleanup.cleanupItems)(entity, records);
152
187
  return ids.map(id => {
188
+ const {
189
+ id: entryId
190
+ } = (0, _utils.parseIdentifier)(id);
153
191
  return items.filter(item => {
154
- const partitionKey = storageOperations.getPartitionKey(id);
155
- return item.PK === partitionKey && item.SK === sortKey;
192
+ return entryId === item.entryId;
156
193
  });
157
194
  });
158
195
  });
@@ -164,80 +201,74 @@ const dataLoaders = {
164
201
  getPublishedRevisionByEntryId,
165
202
  getLatestRevisionByEntryId
166
203
  };
204
+ const loaderNames = Object.keys(dataLoaders);
167
205
 
168
206
  class DataLoadersHandler {
169
- constructor(context, storageOperations) {
170
- (0, _defineProperty2.default)(this, "_loaders", new Map());
171
- (0, _defineProperty2.default)(this, "_context", void 0);
172
- (0, _defineProperty2.default)(this, "_storageOperations", void 0);
173
- this._context = context;
174
- this._storageOperations = storageOperations;
207
+ constructor(params) {
208
+ (0, _defineProperty2.default)(this, "loaders", new Map());
209
+ (0, _defineProperty2.default)(this, "entity", void 0);
210
+ this.entity = params.entity;
175
211
  }
176
212
 
177
- async getAllEntryRevisions(model, ids) {
178
- return await this.loadMany("getAllEntryRevisions", model, ids);
213
+ async getAllEntryRevisions(params) {
214
+ return await this.loadMany("getAllEntryRevisions", params, params.ids);
179
215
  }
180
216
 
181
- clearAllEntryRevisions(model, entry) {
182
- this.clear("getAllEntryRevisions", model, entry);
217
+ async getRevisionById(params) {
218
+ return await this.loadMany("getRevisionById", params, params.ids);
183
219
  }
184
220
 
185
- async getRevisionById(model, ids) {
186
- return await this.loadMany("getRevisionById", model, ids);
221
+ async getPublishedRevisionByEntryId(params) {
222
+ return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
187
223
  }
188
224
 
189
- clearRevisionById(model, entry) {
190
- this.clear("getRevisionById", model, entry);
225
+ async getLatestRevisionByEntryId(params) {
226
+ return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
191
227
  }
192
228
 
193
- async getPublishedRevisionByEntryId(model, ids) {
194
- return await this.loadMany("getPublishedRevisionByEntryId", model, ids);
195
- }
196
-
197
- clearPublishedRevisionByEntryId(model, entry) {
198
- this.clear("getPublishedRevisionByEntryId", model, entry);
199
- }
200
-
201
- async getLatestRevisionByEntryId(model, ids) {
202
- return await this.loadMany("getLatestRevisionByEntryId", model, ids);
203
- }
204
-
205
- clearLatestRevisionByEntryId(model, entry) {
206
- this.clear("getLatestRevisionByEntryId", model, entry);
207
- }
208
-
209
- getLoader(name, model) {
229
+ getLoader(name, params) {
210
230
  if (!dataLoaders[name]) {
211
231
  throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
212
232
  name
213
233
  });
214
234
  }
215
235
 
216
- const loaderKey = `${name}-${model.modelId}`;
217
-
218
- if (!this._loaders.has(loaderKey)) {
219
- this._loaders.set(loaderKey, dataLoaders[name](this._context, model, this._storageOperations));
236
+ const {
237
+ model
238
+ } = params;
239
+ const {
240
+ tenant,
241
+ locale
242
+ } = model;
243
+ const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
244
+
245
+ if (!this.loaders.has(loaderKey)) {
246
+ this.loaders.set(loaderKey, dataLoaders[name](_objectSpread(_objectSpread({}, params), {}, {
247
+ entity: this.entity
248
+ })));
220
249
  }
221
250
 
222
- return this._loaders.get(loaderKey);
251
+ return this.loaders.get(loaderKey);
223
252
  }
224
253
 
225
- async loadMany(loader, model, ids) {
254
+ async loadMany(loader, params, ids) {
226
255
  let results;
227
256
 
228
257
  try {
229
- results = await this.getLoader(loader, model).loadMany(ids);
258
+ results = await this.getLoader(loader, params).loadMany(ids);
230
259
 
231
260
  if (Array.isArray(results) === true) {
232
261
  return results.reduce((acc, res) => {
233
262
  if (Array.isArray(res) === false) {
234
- if (res !== null && res !== void 0 && res.message) {
263
+ if (res && res.message) {
235
264
  throw new _error.default(res.message, res.code, _objectSpread(_objectSpread({}, res), {}, {
236
265
  data: JSON.stringify(res.data || {})
237
266
  }));
238
267
  }
239
268
 
240
- throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.");
269
+ throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", _objectSpread(_objectSpread({}, params), {}, {
270
+ loader
271
+ }));
241
272
  }
242
273
 
243
274
  acc.push(...res);
@@ -245,12 +276,12 @@ class DataLoadersHandler {
245
276
  }, []);
246
277
  }
247
278
  } catch (ex) {
248
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
279
+ throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", _objectSpread(_objectSpread({
280
+ error: ex
281
+ }, params), {}, {
249
282
  loader,
250
- ids,
251
- model,
252
- data: ex.data || {}
253
- });
283
+ ids
284
+ }));
254
285
  }
255
286
 
256
287
  throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
@@ -259,25 +290,14 @@ class DataLoadersHandler {
259
290
  results
260
291
  });
261
292
  }
262
- /**
263
- * Helper to clear the cache for certain data loader.
264
- * If entry is passed then clear target key only.
265
- */
266
-
267
293
 
268
- clear(name, model, entry) {
269
- const loader = this.getLoader(name, model);
270
-
271
- if (!entry) {
294
+ clearAll(params) {
295
+ for (const name of loaderNames) {
296
+ const loader = this.getLoader(name, params);
272
297
  loader.clearAll();
273
- return;
274
298
  }
275
-
276
- loader.clear(entry.id);
277
- loader.clear(this._storageOperations.getPartitionKey(entry.id));
278
299
  }
279
300
 
280
301
  }
281
302
 
282
- exports.DataLoadersHandler = DataLoadersHandler;
283
- //# sourceMappingURL=dataLoaders.js.map
303
+ exports.DataLoadersHandler = DataLoadersHandler;
@@ -1,4 +1,8 @@
1
- import { CmsContentEntryConfiguration } from "./CmsContentEntryDynamo";
2
- import { CmsContentEntryStorageOperationsProvider } from "@webiny/api-headless-cms/types";
3
- declare const contentEntryStorageOperationsProvider: (configuration?: CmsContentEntryConfiguration) => CmsContentEntryStorageOperationsProvider;
4
- export default contentEntryStorageOperationsProvider;
1
+ import { CmsEntryStorageOperations } from "@webiny/api-headless-cms/types";
2
+ import { Entity } from "dynamodb-toolbox";
3
+ import { PluginsContainer } from "@webiny/plugins";
4
+ export interface Params {
5
+ entity: Entity<any>;
6
+ plugins: PluginsContainer;
7
+ }
8
+ export declare const createEntriesStorageOperations: (params: Params) => CmsEntryStorageOperations;