@webiny/api-headless-cms-ddb-es 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 (170) hide show
  1. package/configurations.d.ts +5 -17
  2. package/configurations.js +9 -38
  3. package/definitions/entry.d.ts +6 -11
  4. package/definitions/entry.js +17 -14
  5. package/definitions/entryElasticsearch.d.ts +8 -0
  6. package/definitions/entryElasticsearch.js +46 -0
  7. package/definitions/group.d.ts +8 -0
  8. package/definitions/group.js +74 -0
  9. package/definitions/model.d.ts +7 -6
  10. package/definitions/model.js +45 -20
  11. package/definitions/settings.d.ts +8 -0
  12. package/definitions/settings.js +62 -0
  13. package/definitions/system.d.ts +8 -0
  14. package/definitions/system.js +50 -0
  15. package/definitions/table.d.ts +7 -3
  16. package/definitions/table.js +12 -29
  17. package/definitions/tableElasticsearch.d.ts +7 -3
  18. package/definitions/tableElasticsearch.js +12 -29
  19. package/dynamoDb/index.d.ts +1 -1
  20. package/dynamoDb/index.js +4 -3
  21. package/dynamoDb/storage/date.d.ts +2 -2
  22. package/dynamoDb/storage/date.js +17 -17
  23. package/dynamoDb/storage/longText.d.ts +7 -0
  24. package/dynamoDb/storage/longText.js +83 -0
  25. package/dynamoDb/storage/richText.d.ts +2 -2
  26. package/dynamoDb/storage/richText.js +69 -67
  27. package/elasticsearch/index.d.ts +1 -1
  28. package/elasticsearch/index.js +1 -2
  29. package/elasticsearch/indexing/dateTimeIndexing.js +1 -2
  30. package/elasticsearch/indexing/defaultFieldIndexing.js +1 -2
  31. package/elasticsearch/indexing/index.js +4 -3
  32. package/elasticsearch/indexing/longTextIndexing.d.ts +3 -0
  33. package/elasticsearch/indexing/longTextIndexing.js +36 -0
  34. package/elasticsearch/indexing/numberIndexing.js +1 -2
  35. package/elasticsearch/indexing/objectIndexing.js +32 -27
  36. package/elasticsearch/indexing/richTextIndexing.js +1 -2
  37. package/elasticsearch/search/index.js +1 -2
  38. package/elasticsearch/search/refSearch.js +1 -2
  39. package/elasticsearch/search/timeSearch.js +1 -2
  40. package/helpers/createElasticsearchQueryBody.d.ts +5 -4
  41. package/helpers/createElasticsearchQueryBody.js +89 -44
  42. package/helpers/entryIndexHelpers.d.ts +14 -12
  43. package/helpers/entryIndexHelpers.js +63 -58
  44. package/helpers/fields.d.ts +11 -10
  45. package/helpers/fields.js +4 -5
  46. package/helpers/index.js +1 -2
  47. package/helpers/operatorPluginsList.d.ts +2 -2
  48. package/helpers/operatorPluginsList.js +3 -4
  49. package/helpers/searchPluginsList.d.ts +2 -2
  50. package/helpers/searchPluginsList.js +3 -4
  51. package/helpers/transformValueForSearch.d.ts +4 -5
  52. package/helpers/transformValueForSearch.js +3 -6
  53. package/index.d.ts +2 -2
  54. package/index.js +154 -12
  55. package/operations/entry/dataLoaders.d.ts +38 -14
  56. package/operations/entry/dataLoaders.js +193 -125
  57. package/operations/entry/elasticsearchFields.d.ts +2 -0
  58. package/operations/entry/elasticsearchFields.js +32 -0
  59. package/operations/entry/fields.d.ts +2 -2
  60. package/operations/entry/fields.js +1 -2
  61. package/operations/entry/index.d.ts +13 -3
  62. package/operations/entry/index.js +1148 -15
  63. package/operations/entry/keys.d.ts +12 -0
  64. package/operations/entry/keys.js +40 -0
  65. package/operations/group/index.d.ts +8 -0
  66. package/operations/group/index.js +202 -0
  67. package/operations/model/index.d.ts +8 -3
  68. package/operations/model/index.js +196 -17
  69. package/operations/settings/index.d.ts +6 -3
  70. package/operations/settings/index.js +132 -16
  71. package/operations/system/createElasticsearchTemplate.d.ts +5 -0
  72. package/operations/system/createElasticsearchTemplate.js +62 -0
  73. package/operations/system/index.d.ts +6 -3
  74. package/operations/system/index.js +93 -17
  75. package/package.json +15 -14
  76. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +17 -0
  77. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +24 -0
  78. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +9 -1
  79. package/plugins/CmsEntryElasticsearchFieldPlugin.js +9 -3
  80. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +17 -0
  81. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +24 -0
  82. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +17 -0
  83. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +24 -0
  84. package/types.d.ts +61 -80
  85. package/types.js +55 -1
  86. package/upgrades/index.js +1 -2
  87. package/upgrades/utils.js +1 -2
  88. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +2 -2
  89. package/upgrades/v5.0.0/cleanDatabaseRecord.js +1 -2
  90. package/upgrades/v5.0.0/createOldVersionIndiceName.js +1 -2
  91. package/upgrades/v5.0.0/entryValueFixer.d.ts +3 -3
  92. package/upgrades/v5.0.0/entryValueFixer.js +3 -4
  93. package/upgrades/v5.0.0/fieldFinder.d.ts +4 -4
  94. package/upgrades/v5.0.0/fieldFinder.js +1 -2
  95. package/upgrades/v5.0.0/helpers.js +1 -2
  96. package/upgrades/v5.0.0/index.js +1 -2
  97. package/upgrades/v5.8.0/index.js +3 -3
  98. package/configurations.js.map +0 -1
  99. package/definitions/elasticsearchEntry.d.ts +0 -13
  100. package/definitions/elasticsearchEntry.js +0 -43
  101. package/definitions/elasticsearchEntry.js.map +0 -1
  102. package/definitions/entry.js.map +0 -1
  103. package/definitions/index.d.ts +0 -17
  104. package/definitions/index.js +0 -28
  105. package/definitions/index.js.map +0 -1
  106. package/definitions/model.js.map +0 -1
  107. package/definitions/table.js.map +0 -1
  108. package/definitions/tableElasticsearch.js.map +0 -1
  109. package/dynamoDb/index.js.map +0 -1
  110. package/dynamoDb/storage/date.js.map +0 -1
  111. package/dynamoDb/storage/richText.js.map +0 -1
  112. package/elasticsearch/index.js.map +0 -1
  113. package/elasticsearch/indexing/dateTimeIndexing.js.map +0 -1
  114. package/elasticsearch/indexing/defaultFieldIndexing.js.map +0 -1
  115. package/elasticsearch/indexing/index.js.map +0 -1
  116. package/elasticsearch/indexing/numberIndexing.js.map +0 -1
  117. package/elasticsearch/indexing/objectIndexing.js.map +0 -1
  118. package/elasticsearch/indexing/richTextIndexing.js.map +0 -1
  119. package/elasticsearch/search/index.js.map +0 -1
  120. package/elasticsearch/search/refSearch.js.map +0 -1
  121. package/elasticsearch/search/timeSearch.js.map +0 -1
  122. package/helpers/createElasticsearchQueryBody.js.map +0 -1
  123. package/helpers/entryIndexHelpers.js.map +0 -1
  124. package/helpers/fields.js.map +0 -1
  125. package/helpers/index.js.map +0 -1
  126. package/helpers/operatorPluginsList.js.map +0 -1
  127. package/helpers/searchPluginsList.js.map +0 -1
  128. package/helpers/transformValueForSearch.js.map +0 -1
  129. package/index.js.map +0 -1
  130. package/operations/entry/CmsContentEntryDynamoElastic.d.ts +0 -54
  131. package/operations/entry/CmsContentEntryDynamoElastic.js +0 -1128
  132. package/operations/entry/CmsContentEntryDynamoElastic.js.map +0 -1
  133. package/operations/entry/dataLoaders.js.map +0 -1
  134. package/operations/entry/fields.js.map +0 -1
  135. package/operations/entry/index.js.map +0 -1
  136. package/operations/model/CmsContentModelDynamoElastic.d.ts +0 -18
  137. package/operations/model/CmsContentModelDynamoElastic.js +0 -180
  138. package/operations/model/CmsContentModelDynamoElastic.js.map +0 -1
  139. package/operations/model/index.js.map +0 -1
  140. package/operations/modelGroup/CmsContentModelGroupDynamoElastic.d.ts +0 -40
  141. package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js +0 -193
  142. package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js.map +0 -1
  143. package/operations/modelGroup/index.d.ts +0 -3
  144. package/operations/modelGroup/index.js +0 -26
  145. package/operations/modelGroup/index.js.map +0 -1
  146. package/operations/settings/CmsSettingsDynamoElastic.d.ts +0 -14
  147. package/operations/settings/CmsSettingsDynamoElastic.js +0 -127
  148. package/operations/settings/CmsSettingsDynamoElastic.js.map +0 -1
  149. package/operations/settings/index.js.map +0 -1
  150. package/operations/system/CmsSystemDynamoElastic.d.ts +0 -14
  151. package/operations/system/CmsSystemDynamoElastic.js +0 -101
  152. package/operations/system/CmsSystemDynamoElastic.js.map +0 -1
  153. package/operations/system/CmsSystemInstallationPlugin.d.ts +0 -11
  154. package/operations/system/CmsSystemInstallationPlugin.js +0 -78
  155. package/operations/system/CmsSystemInstallationPlugin.js.map +0 -1
  156. package/operations/system/index.js.map +0 -1
  157. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
  158. package/types.js.map +0 -1
  159. package/upgrades/index.js.map +0 -1
  160. package/upgrades/utils.js.map +0 -1
  161. package/upgrades/v5.0.0/cleanDatabaseRecord.js.map +0 -1
  162. package/upgrades/v5.0.0/createOldVersionIndiceName.js.map +0 -1
  163. package/upgrades/v5.0.0/entryValueFixer.js.map +0 -1
  164. package/upgrades/v5.0.0/fieldFinder.js.map +0 -1
  165. package/upgrades/v5.0.0/helpers.js.map +0 -1
  166. package/upgrades/v5.0.0/index.js.map +0 -1
  167. package/upgrades/v5.8.0/index.js.map +0 -1
  168. package/utils.d.ts +0 -3
  169. package/utils.js +0 -42
  170. package/utils.js.map +0 -1
@@ -13,49 +13,46 @@ var _dataloader = _interopRequireDefault(require("dataloader"));
13
13
 
14
14
  var _error = _interopRequireDefault(require("@webiny/error"));
15
15
 
16
- var _lodash = _interopRequireDefault(require("lodash.chunk"));
16
+ var _query = require("@webiny/db-dynamodb/utils/query");
17
17
 
18
- var _configurations = _interopRequireDefault(require("../../configurations"));
18
+ var _keys = require("./keys");
19
19
 
20
- 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; }
20
+ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
21
21
 
22
- 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; }
22
+ var _utils = require("@webiny/utils");
23
23
 
24
- // Used in functions below. Ensures we are batch getting 100 keys at most.
25
- const batchLoadKeys = loadChunk => {
26
- return new _dataloader.default(async keys => {
27
- // DynamoDB allows getting a maximum of 100 items in a single database call.
28
- // So, we are creating chunks that consist of a maximum of 100 keys.
29
- const keysChunks = (0, _lodash.default)(keys, 100);
30
- const promises = [];
31
- keysChunks.forEach(chunk => {
32
- promises.push(new Promise(resolve => resolve(loadChunk(chunk))));
33
- });
34
- const entriesChunks = await Promise.all(promises);
35
- return entriesChunks.reduce((current, items) => current.concat(items), []);
36
- });
37
- };
24
+ var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
38
25
 
39
- const flattenResults = results => {
40
- return results.reduce((collection, items) => {
41
- collection.push(...items);
42
- return collection;
43
- }, []);
44
- };
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; }
27
+
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; }
45
29
 
46
- 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;
47
39
  return new _dataloader.default(async ids => {
48
40
  const results = [];
49
41
 
50
42
  for (const id of ids) {
51
- const [entries] = await context.db.read(_objectSpread(_objectSpread({}, _configurations.default.db()), {}, {
52
- query: {
53
- PK: storageOperations.getPartitionKey(id),
54
- SK: {
55
- $beginsWith: "REV#"
56
- }
43
+ const queryAllParams = {
44
+ entity,
45
+ partitionKey: (0, _keys.createPartitionKey)({
46
+ tenant,
47
+ locale,
48
+ id
49
+ }),
50
+ options: {
51
+ beginsWith: "REV#"
57
52
  }
58
- }));
53
+ };
54
+ const items = await (0, _query.queryAll)(queryAllParams);
55
+ const entries = (0, _cleanup.cleanupItems)(entity, items);
59
56
  results.push(entries);
60
57
  }
61
58
 
@@ -63,93 +60,136 @@ const getAllEntryRevisions = (context, model, storageOperations) => {
63
60
  });
64
61
  };
65
62
 
66
- const getRevisionById = (context, model, storageOperations) => {
67
- return batchLoadKeys(keys => {
68
- const queries = keys.reduce((collection, id) => {
69
- const partitionKey = storageOperations.getPartitionKey(id);
70
- const sortKey = storageOperations.getSortKeyRevision(id);
63
+ const getRevisionById = params => {
64
+ const {
65
+ entity,
66
+ model
67
+ } = params;
68
+ const {
69
+ locale,
70
+ tenant
71
+ } = model;
72
+ return new _dataloader.default(async ids => {
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
+ });
71
85
  const keys = `${partitionKey}__${sortKey}`;
72
86
 
73
87
  if (collection[keys]) {
74
88
  return collection;
75
89
  }
76
90
 
77
- collection[keys] = _objectSpread(_objectSpread({}, _configurations.default.db()), {}, {
78
- query: {
79
- PK: storageOperations.getPartitionKey(id),
80
- SK: storageOperations.getSortKeyRevision(id)
81
- }
91
+ collection[keys] = entity.getBatch({
92
+ PK: partitionKey,
93
+ SK: sortKey
82
94
  });
83
95
  return collection;
84
96
  }, {});
85
- return context.db.batch().read(...Object.values(queries)).execute().then(results => results.map(result => result[0])).then(results => {
86
- const items = flattenResults(results);
87
- return keys.map(id => {
88
- return items.filter(item => {
89
- const partitionKey = storageOperations.getPartitionKey(id);
90
- const sortKey = storageOperations.getSortKeyRevision(id);
91
- return item.PK === partitionKey && item.SK === sortKey;
92
- });
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);
102
+ return ids.map(id => {
103
+ return items.filter(item => {
104
+ return id === item.id;
93
105
  });
94
106
  });
95
107
  });
96
108
  };
97
109
 
98
- const getPublishedRevisionByEntryId = (context, model, storageOperations) => {
99
- return batchLoadKeys(keys => {
100
- const sortKey = storageOperations.getSortKeyPublished();
101
- const queries = keys.reduce((collection, id) => {
102
- const partitionKey = storageOperations.getPartitionKey(id);
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)();
120
+ return new _dataloader.default(async ids => {
121
+ const queries = ids.reduce((collection, id) => {
122
+ const partitionKey = (0, _keys.createPartitionKey)({
123
+ tenant,
124
+ locale,
125
+ id
126
+ });
103
127
 
104
128
  if (collection[partitionKey]) {
105
129
  return collection;
106
130
  }
107
131
 
108
- collection[partitionKey] = _objectSpread(_objectSpread({}, _configurations.default.db()), {}, {
109
- query: {
110
- PK: partitionKey,
111
- SK: sortKey
112
- }
132
+ collection[partitionKey] = entity.getBatch({
133
+ PK: partitionKey,
134
+ SK: publishedKey
113
135
  });
114
136
  return collection;
115
137
  }, {});
116
- return context.db.batch().read(...Object.values(queries)).execute().then(results => results.map(result => result[0])).then(results => {
117
- const items = flattenResults(results);
118
- return keys.map(id => {
119
- return items.filter(item => {
120
- const partitionKey = storageOperations.getPartitionKey(id);
121
- return item.PK === partitionKey && item.SK === sortKey;
122
- });
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);
143
+ return ids.map(id => {
144
+ const {
145
+ id: entryId
146
+ } = (0, _utils.parseIdentifier)(id);
147
+ return items.filter(item => {
148
+ return entryId === item.entryId;
123
149
  });
124
150
  });
125
151
  });
126
152
  };
127
153
 
128
- const getLatestRevisionByEntryId = (context, model, storageOperations) => {
129
- return batchLoadKeys(keys => {
130
- const sortKey = storageOperations.getSortKeyLatest();
131
- const queries = keys.reduce((collection, id) => {
132
- const partitionKey = storageOperations.getPartitionKey(id);
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)();
164
+ return new _dataloader.default(async ids => {
165
+ const queries = ids.reduce((collection, id) => {
166
+ const partitionKey = (0, _keys.createPartitionKey)({
167
+ tenant,
168
+ locale,
169
+ id
170
+ });
133
171
 
134
172
  if (collection[partitionKey]) {
135
173
  return collection;
136
174
  }
137
175
 
138
- collection[partitionKey] = _objectSpread(_objectSpread({}, _configurations.default.db()), {}, {
139
- query: {
140
- PK: storageOperations.getPartitionKey(id),
141
- SK: sortKey
142
- }
176
+ collection[partitionKey] = entity.getBatch({
177
+ PK: partitionKey,
178
+ SK: latestKey
143
179
  });
144
180
  return collection;
145
181
  }, {});
146
- return context.db.batch().read(...Object.values(queries)).execute().then(results => results.map(result => result[0])).then(results => {
147
- const items = flattenResults(results);
148
- return keys.map(id => {
149
- return items.filter(item => {
150
- const partitionKey = storageOperations.getPartitionKey(id);
151
- return item.PK === partitionKey && item.SK === sortKey;
152
- });
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);
187
+ return ids.map(id => {
188
+ const {
189
+ id: entryId
190
+ } = (0, _utils.parseIdentifier)(id);
191
+ return items.filter(item => {
192
+ return entryId === item.entryId;
153
193
  });
154
194
  });
155
195
  });
@@ -161,80 +201,90 @@ const dataLoaders = {
161
201
  getPublishedRevisionByEntryId,
162
202
  getLatestRevisionByEntryId
163
203
  };
204
+ const loaderNames = Object.keys(dataLoaders);
164
205
 
165
206
  class DataLoadersHandler {
166
- constructor(context, storageOperations) {
167
- (0, _defineProperty2.default)(this, "_loaders", new Map());
168
- (0, _defineProperty2.default)(this, "_context", void 0);
169
- (0, _defineProperty2.default)(this, "_storageOperations", void 0);
170
- this._context = context;
171
- 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;
172
211
  }
173
212
 
174
- async getAllEntryRevisions(model, ids) {
175
- return await this.loadMany("getAllEntryRevisions", model, ids);
213
+ async getAllEntryRevisions(params) {
214
+ return await this.loadMany("getAllEntryRevisions", params, params.ids);
176
215
  }
177
216
 
178
- clearAllEntryRevisions(model, entry) {
179
- this.clear("getAllEntryRevisions", model, entry);
217
+ clearAllEntryRevisions(params) {
218
+ this.clear("getAllEntryRevisions", params);
180
219
  }
181
220
 
182
- async getRevisionById(model, ids) {
183
- return await this.loadMany("getRevisionById", model, ids);
221
+ async getRevisionById(params) {
222
+ return await this.loadMany("getRevisionById", params, params.ids);
184
223
  }
185
224
 
186
- clearRevisionById(model, entry) {
187
- this.clear("getRevisionById", model, entry);
225
+ clearRevisionById(params) {
226
+ this.clear("getRevisionById", params);
188
227
  }
189
228
 
190
- async getPublishedRevisionByEntryId(model, ids) {
191
- return await this.loadMany("getPublishedRevisionByEntryId", model, ids);
229
+ async getPublishedRevisionByEntryId(params) {
230
+ return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
192
231
  }
193
232
 
194
- clearPublishedRevisionByEntryId(model, entry) {
195
- this.clear("getPublishedRevisionByEntryId", model, entry);
233
+ clearPublishedRevisionByEntryId(params) {
234
+ this.clear("getPublishedRevisionByEntryId", params);
196
235
  }
197
236
 
198
- async getLatestRevisionByEntryId(model, ids) {
199
- return await this.loadMany("getLatestRevisionByEntryId", model, ids);
237
+ async getLatestRevisionByEntryId(params) {
238
+ return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
200
239
  }
201
240
 
202
- clearLatestRevisionByEntryId(model, entry) {
203
- this.clear("getLatestRevisionByEntryId", model, entry);
241
+ clearLatestRevisionByEntryId(params) {
242
+ this.clear("getLatestRevisionByEntryId", params);
204
243
  }
205
244
 
206
- getLoader(name, model) {
245
+ getLoader(name, params) {
207
246
  if (!dataLoaders[name]) {
208
247
  throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
209
248
  name
210
249
  });
211
250
  }
212
251
 
213
- const loaderKey = `${name}-${model.modelId}`;
214
-
215
- if (!this._loaders.has(loaderKey)) {
216
- this._loaders.set(loaderKey, dataLoaders[name](this._context, model, this._storageOperations));
252
+ const {
253
+ model
254
+ } = params;
255
+ const {
256
+ tenant,
257
+ locale
258
+ } = model;
259
+ const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
260
+
261
+ if (!this.loaders.has(loaderKey)) {
262
+ this.loaders.set(loaderKey, dataLoaders[name](_objectSpread(_objectSpread({}, params), {}, {
263
+ entity: this.entity
264
+ })));
217
265
  }
218
266
 
219
- return this._loaders.get(loaderKey);
267
+ return this.loaders.get(loaderKey);
220
268
  }
221
269
 
222
- async loadMany(loader, model, ids) {
270
+ async loadMany(loader, params, ids) {
223
271
  let results;
224
272
 
225
273
  try {
226
- results = await this.getLoader(loader, model).loadMany(ids);
274
+ results = await this.getLoader(loader, params).loadMany(ids);
227
275
 
228
276
  if (Array.isArray(results) === true) {
229
277
  return results.reduce((acc, res) => {
230
278
  if (Array.isArray(res) === false) {
231
- if (res !== null && res !== void 0 && res.message) {
279
+ if (res && res.message) {
232
280
  throw new _error.default(res.message, res.code, _objectSpread(_objectSpread({}, res), {}, {
233
281
  data: JSON.stringify(res.data || {})
234
282
  }));
235
283
  }
236
284
 
237
- throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.");
285
+ 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), {}, {
286
+ loader
287
+ }));
238
288
  }
239
289
 
240
290
  acc.push(...res);
@@ -242,11 +292,12 @@ class DataLoadersHandler {
242
292
  }, []);
243
293
  }
244
294
  } catch (ex) {
245
- throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
295
+ throw new _error.default(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", _objectSpread(_objectSpread({
296
+ error: ex
297
+ }, params), {}, {
246
298
  loader,
247
- ids,
248
- model
249
- });
299
+ ids
300
+ }));
250
301
  }
251
302
 
252
303
  throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
@@ -255,14 +306,24 @@ class DataLoadersHandler {
255
306
  results
256
307
  });
257
308
  }
309
+
310
+ clearAll(params) {
311
+ for (const name of loaderNames) {
312
+ const loader = this.getLoader(name, params);
313
+ loader.clearAll();
314
+ }
315
+ }
258
316
  /**
259
317
  * Helper to clear the cache for certain data loader.
260
318
  * If entry is passed then clear target key only.
261
319
  */
262
320
 
263
321
 
264
- clear(name, model, entry) {
265
- const loader = this.getLoader(name, model);
322
+ clear(name, params) {
323
+ const {
324
+ entry
325
+ } = params;
326
+ const loader = this.getLoader(name, params);
266
327
 
267
328
  if (!entry) {
268
329
  loader.clearAll();
@@ -270,10 +331,17 @@ class DataLoadersHandler {
270
331
  }
271
332
 
272
333
  loader.clear(entry.id);
273
- loader.clear(this._storageOperations.getPartitionKey(entry.id));
334
+ const {
335
+ tenant,
336
+ locale
337
+ } = params.model;
338
+ loader.clear((0, _keys.createPartitionKey)({
339
+ tenant,
340
+ locale,
341
+ id: entry.id
342
+ }));
274
343
  }
275
344
 
276
345
  }
277
346
 
278
- exports.DataLoadersHandler = DataLoadersHandler;
279
- //# sourceMappingURL=dataLoaders.js.map
347
+ exports.DataLoadersHandler = DataLoadersHandler;
@@ -0,0 +1,2 @@
1
+ import { CmsEntryElasticsearchFieldPlugin } from "../../plugins/CmsEntryElasticsearchFieldPlugin";
2
+ export declare const elasticsearchFields: CmsEntryElasticsearchFieldPlugin[];
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.elasticsearchFields = void 0;
7
+
8
+ var _CmsEntryElasticsearchFieldPlugin = require("../../plugins/CmsEntryElasticsearchFieldPlugin");
9
+
10
+ const elasticsearchFields = [new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
11
+ field: "createdOn",
12
+ unmappedType: "date"
13
+ }), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
14
+ field: "savedOn",
15
+ unmappedType: "date"
16
+ }), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
17
+ field: "publishedOn",
18
+ unmappedType: "date"
19
+ }), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
20
+ field: "ownedBy",
21
+ path: "ownedBy.id"
22
+ }), new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
23
+ field: "createdBy",
24
+ path: "createdBy.id"
25
+ }),
26
+ /**
27
+ * Always add the ALL fields plugin because of the keyword/path build.
28
+ */
29
+ new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
30
+ field: _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin.ALL
31
+ })];
32
+ exports.elasticsearchFields = elasticsearchFields;
@@ -1,3 +1,3 @@
1
- import { CmsContentModel } from "@webiny/api-headless-cms/types";
1
+ import { CmsModel } from "@webiny/api-headless-cms/types";
2
2
  import { CmsEntryElasticsearchFieldPlugin } from "../../plugins/CmsEntryElasticsearchFieldPlugin";
3
- export declare const createElasticsearchFields: (model: CmsContentModel) => Record<string, CmsEntryElasticsearchFieldPlugin>;
3
+ export declare const createElasticsearchFields: (model: CmsModel) => Record<string, CmsEntryElasticsearchFieldPlugin>;
@@ -57,5 +57,4 @@ const createElasticsearchFields = model => {
57
57
  }, systemFields);
58
58
  };
59
59
 
60
- exports.createElasticsearchFields = createElasticsearchFields;
61
- //# sourceMappingURL=fields.js.map
60
+ exports.createElasticsearchFields = createElasticsearchFields;
@@ -1,3 +1,13 @@
1
- import { CmsContentEntryStorageOperationsProvider } from "@webiny/api-headless-cms/types";
2
- declare const contentEntryStorageOperationsProvider: () => CmsContentEntryStorageOperationsProvider;
3
- export default contentEntryStorageOperationsProvider;
1
+ import { CmsEntryStorageOperations } from "@webiny/api-headless-cms/types";
2
+ import { Entity } from "dynamodb-toolbox";
3
+ import { Client } from "@elastic/elasticsearch";
4
+ import { PluginsContainer } from "@webiny/plugins";
5
+ export declare const createLatestType: () => string;
6
+ export declare const createPublishedType: () => string;
7
+ export interface Params {
8
+ entity: Entity<any>;
9
+ esEntity: Entity<any>;
10
+ elasticsearch: Client;
11
+ plugins: PluginsContainer;
12
+ }
13
+ export declare const createEntriesStorageOperations: (params: Params) => CmsEntryStorageOperations;