@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.
- package/configurations.d.ts +5 -17
- package/configurations.js +9 -38
- package/definitions/entry.d.ts +6 -11
- package/definitions/entry.js +17 -14
- package/definitions/entryElasticsearch.d.ts +8 -0
- package/definitions/entryElasticsearch.js +46 -0
- package/definitions/group.d.ts +8 -0
- package/definitions/group.js +74 -0
- package/definitions/model.d.ts +7 -6
- package/definitions/model.js +45 -20
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +62 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +50 -0
- package/definitions/table.d.ts +7 -3
- package/definitions/table.js +12 -29
- package/definitions/tableElasticsearch.d.ts +7 -3
- package/definitions/tableElasticsearch.js +12 -29
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +4 -3
- package/dynamoDb/storage/date.d.ts +2 -2
- package/dynamoDb/storage/date.js +17 -17
- package/dynamoDb/storage/longText.d.ts +7 -0
- package/dynamoDb/storage/longText.js +83 -0
- package/dynamoDb/storage/richText.d.ts +2 -2
- package/dynamoDb/storage/richText.js +69 -67
- package/elasticsearch/index.d.ts +1 -1
- package/elasticsearch/index.js +1 -2
- package/elasticsearch/indexing/dateTimeIndexing.js +1 -2
- package/elasticsearch/indexing/defaultFieldIndexing.js +1 -2
- package/elasticsearch/indexing/index.js +4 -3
- package/elasticsearch/indexing/longTextIndexing.d.ts +3 -0
- package/elasticsearch/indexing/longTextIndexing.js +36 -0
- package/elasticsearch/indexing/numberIndexing.js +1 -2
- package/elasticsearch/indexing/objectIndexing.js +32 -27
- package/elasticsearch/indexing/richTextIndexing.js +1 -2
- package/elasticsearch/search/index.js +1 -2
- package/elasticsearch/search/refSearch.js +1 -2
- package/elasticsearch/search/timeSearch.js +1 -2
- package/helpers/createElasticsearchQueryBody.d.ts +5 -4
- package/helpers/createElasticsearchQueryBody.js +89 -44
- package/helpers/entryIndexHelpers.d.ts +14 -12
- package/helpers/entryIndexHelpers.js +63 -58
- package/helpers/fields.d.ts +11 -10
- package/helpers/fields.js +4 -5
- package/helpers/index.js +1 -2
- package/helpers/operatorPluginsList.d.ts +2 -2
- package/helpers/operatorPluginsList.js +3 -4
- package/helpers/searchPluginsList.d.ts +2 -2
- package/helpers/searchPluginsList.js +3 -4
- package/helpers/transformValueForSearch.d.ts +4 -5
- package/helpers/transformValueForSearch.js +3 -6
- package/index.d.ts +2 -2
- package/index.js +154 -12
- package/operations/entry/dataLoaders.d.ts +38 -14
- package/operations/entry/dataLoaders.js +193 -125
- package/operations/entry/elasticsearchFields.d.ts +2 -0
- package/operations/entry/elasticsearchFields.js +32 -0
- package/operations/entry/fields.d.ts +2 -2
- package/operations/entry/fields.js +1 -2
- package/operations/entry/index.d.ts +13 -3
- package/operations/entry/index.js +1148 -15
- package/operations/entry/keys.d.ts +12 -0
- package/operations/entry/keys.js +40 -0
- package/operations/group/index.d.ts +8 -0
- package/operations/group/index.js +202 -0
- package/operations/model/index.d.ts +8 -3
- package/operations/model/index.js +196 -17
- package/operations/settings/index.d.ts +6 -3
- package/operations/settings/index.js +132 -16
- package/operations/system/createElasticsearchTemplate.d.ts +5 -0
- package/operations/system/createElasticsearchTemplate.js +62 -0
- package/operations/system/index.d.ts +6 -3
- package/operations/system/index.js +93 -17
- package/package.json +15 -14
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +9 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +9 -3
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +24 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +17 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +24 -0
- package/types.d.ts +61 -80
- package/types.js +55 -1
- package/upgrades/index.js +1 -2
- package/upgrades/utils.js +1 -2
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +2 -2
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +1 -2
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +1 -2
- package/upgrades/v5.0.0/entryValueFixer.d.ts +3 -3
- package/upgrades/v5.0.0/entryValueFixer.js +3 -4
- package/upgrades/v5.0.0/fieldFinder.d.ts +4 -4
- package/upgrades/v5.0.0/fieldFinder.js +1 -2
- package/upgrades/v5.0.0/helpers.js +1 -2
- package/upgrades/v5.0.0/index.js +1 -2
- package/upgrades/v5.8.0/index.js +3 -3
- package/configurations.js.map +0 -1
- package/definitions/elasticsearchEntry.d.ts +0 -13
- package/definitions/elasticsearchEntry.js +0 -43
- package/definitions/elasticsearchEntry.js.map +0 -1
- package/definitions/entry.js.map +0 -1
- package/definitions/index.d.ts +0 -17
- package/definitions/index.js +0 -28
- package/definitions/index.js.map +0 -1
- package/definitions/model.js.map +0 -1
- package/definitions/table.js.map +0 -1
- package/definitions/tableElasticsearch.js.map +0 -1
- package/dynamoDb/index.js.map +0 -1
- package/dynamoDb/storage/date.js.map +0 -1
- package/dynamoDb/storage/richText.js.map +0 -1
- package/elasticsearch/index.js.map +0 -1
- package/elasticsearch/indexing/dateTimeIndexing.js.map +0 -1
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +0 -1
- package/elasticsearch/indexing/index.js.map +0 -1
- package/elasticsearch/indexing/numberIndexing.js.map +0 -1
- package/elasticsearch/indexing/objectIndexing.js.map +0 -1
- package/elasticsearch/indexing/richTextIndexing.js.map +0 -1
- package/elasticsearch/search/index.js.map +0 -1
- package/elasticsearch/search/refSearch.js.map +0 -1
- package/elasticsearch/search/timeSearch.js.map +0 -1
- package/helpers/createElasticsearchQueryBody.js.map +0 -1
- package/helpers/entryIndexHelpers.js.map +0 -1
- package/helpers/fields.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/helpers/operatorPluginsList.js.map +0 -1
- package/helpers/searchPluginsList.js.map +0 -1
- package/helpers/transformValueForSearch.js.map +0 -1
- package/index.js.map +0 -1
- package/operations/entry/CmsContentEntryDynamoElastic.d.ts +0 -54
- package/operations/entry/CmsContentEntryDynamoElastic.js +0 -1128
- package/operations/entry/CmsContentEntryDynamoElastic.js.map +0 -1
- package/operations/entry/dataLoaders.js.map +0 -1
- package/operations/entry/fields.js.map +0 -1
- package/operations/entry/index.js.map +0 -1
- package/operations/model/CmsContentModelDynamoElastic.d.ts +0 -18
- package/operations/model/CmsContentModelDynamoElastic.js +0 -180
- package/operations/model/CmsContentModelDynamoElastic.js.map +0 -1
- package/operations/model/index.js.map +0 -1
- package/operations/modelGroup/CmsContentModelGroupDynamoElastic.d.ts +0 -40
- package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js +0 -193
- package/operations/modelGroup/CmsContentModelGroupDynamoElastic.js.map +0 -1
- package/operations/modelGroup/index.d.ts +0 -3
- package/operations/modelGroup/index.js +0 -26
- package/operations/modelGroup/index.js.map +0 -1
- package/operations/settings/CmsSettingsDynamoElastic.d.ts +0 -14
- package/operations/settings/CmsSettingsDynamoElastic.js +0 -127
- package/operations/settings/CmsSettingsDynamoElastic.js.map +0 -1
- package/operations/settings/index.js.map +0 -1
- package/operations/system/CmsSystemDynamoElastic.d.ts +0 -14
- package/operations/system/CmsSystemDynamoElastic.js +0 -101
- package/operations/system/CmsSystemDynamoElastic.js.map +0 -1
- package/operations/system/CmsSystemInstallationPlugin.d.ts +0 -11
- package/operations/system/CmsSystemInstallationPlugin.js +0 -78
- package/operations/system/CmsSystemInstallationPlugin.js.map +0 -1
- package/operations/system/index.js.map +0 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
- package/types.js.map +0 -1
- package/upgrades/index.js.map +0 -1
- package/upgrades/utils.js.map +0 -1
- package/upgrades/v5.0.0/cleanDatabaseRecord.js.map +0 -1
- package/upgrades/v5.0.0/createOldVersionIndiceName.js.map +0 -1
- package/upgrades/v5.0.0/entryValueFixer.js.map +0 -1
- package/upgrades/v5.0.0/fieldFinder.js.map +0 -1
- package/upgrades/v5.0.0/helpers.js.map +0 -1
- package/upgrades/v5.0.0/index.js.map +0 -1
- package/upgrades/v5.8.0/index.js.map +0 -1
- package/utils.d.ts +0 -3
- package/utils.js +0 -42
- 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
|
|
16
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _keys = require("./keys");
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
var _utils = require("@webiny/utils");
|
|
23
23
|
|
|
24
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 =
|
|
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
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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] =
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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 =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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] =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
SK: sortKey
|
|
112
|
-
}
|
|
132
|
+
collection[partitionKey] = entity.getBatch({
|
|
133
|
+
PK: partitionKey,
|
|
134
|
+
SK: publishedKey
|
|
113
135
|
});
|
|
114
136
|
return collection;
|
|
115
137
|
}, {});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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 =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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] =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
SK: sortKey
|
|
142
|
-
}
|
|
176
|
+
collection[partitionKey] = entity.getBatch({
|
|
177
|
+
PK: partitionKey,
|
|
178
|
+
SK: latestKey
|
|
143
179
|
});
|
|
144
180
|
return collection;
|
|
145
181
|
}, {});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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(
|
|
167
|
-
(0, _defineProperty2.default)(this, "
|
|
168
|
-
(0, _defineProperty2.default)(this, "
|
|
169
|
-
|
|
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(
|
|
175
|
-
return await this.loadMany("getAllEntryRevisions",
|
|
213
|
+
async getAllEntryRevisions(params) {
|
|
214
|
+
return await this.loadMany("getAllEntryRevisions", params, params.ids);
|
|
176
215
|
}
|
|
177
216
|
|
|
178
|
-
clearAllEntryRevisions(
|
|
179
|
-
this.clear("getAllEntryRevisions",
|
|
217
|
+
clearAllEntryRevisions(params) {
|
|
218
|
+
this.clear("getAllEntryRevisions", params);
|
|
180
219
|
}
|
|
181
220
|
|
|
182
|
-
async getRevisionById(
|
|
183
|
-
return await this.loadMany("getRevisionById",
|
|
221
|
+
async getRevisionById(params) {
|
|
222
|
+
return await this.loadMany("getRevisionById", params, params.ids);
|
|
184
223
|
}
|
|
185
224
|
|
|
186
|
-
clearRevisionById(
|
|
187
|
-
this.clear("getRevisionById",
|
|
225
|
+
clearRevisionById(params) {
|
|
226
|
+
this.clear("getRevisionById", params);
|
|
188
227
|
}
|
|
189
228
|
|
|
190
|
-
async getPublishedRevisionByEntryId(
|
|
191
|
-
return await this.loadMany("getPublishedRevisionByEntryId",
|
|
229
|
+
async getPublishedRevisionByEntryId(params) {
|
|
230
|
+
return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
|
|
192
231
|
}
|
|
193
232
|
|
|
194
|
-
clearPublishedRevisionByEntryId(
|
|
195
|
-
this.clear("getPublishedRevisionByEntryId",
|
|
233
|
+
clearPublishedRevisionByEntryId(params) {
|
|
234
|
+
this.clear("getPublishedRevisionByEntryId", params);
|
|
196
235
|
}
|
|
197
236
|
|
|
198
|
-
async getLatestRevisionByEntryId(
|
|
199
|
-
return await this.loadMany("getLatestRevisionByEntryId",
|
|
237
|
+
async getLatestRevisionByEntryId(params) {
|
|
238
|
+
return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
|
|
200
239
|
}
|
|
201
240
|
|
|
202
|
-
clearLatestRevisionByEntryId(
|
|
203
|
-
this.clear("getLatestRevisionByEntryId",
|
|
241
|
+
clearLatestRevisionByEntryId(params) {
|
|
242
|
+
this.clear("getLatestRevisionByEntryId", params);
|
|
204
243
|
}
|
|
205
244
|
|
|
206
|
-
getLoader(name,
|
|
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
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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.
|
|
267
|
+
return this.loaders.get(loaderKey);
|
|
220
268
|
}
|
|
221
269
|
|
|
222
|
-
async loadMany(loader,
|
|
270
|
+
async loadMany(loader, params, ids) {
|
|
223
271
|
let results;
|
|
224
272
|
|
|
225
273
|
try {
|
|
226
|
-
results = await this.getLoader(loader,
|
|
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
|
|
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
|
-
|
|
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,
|
|
265
|
-
const
|
|
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
|
-
|
|
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,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 {
|
|
1
|
+
import { CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
2
|
import { CmsEntryElasticsearchFieldPlugin } from "../../plugins/CmsEntryElasticsearchFieldPlugin";
|
|
3
|
-
export declare const createElasticsearchFields: (model:
|
|
3
|
+
export declare const createElasticsearchFields: (model: CmsModel) => Record<string, CmsEntryElasticsearchFieldPlugin>;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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;
|