@webiny/api-headless-cms-ddb 0.0.0-unstable.40876133bb → 0.0.0-unstable.496cf268ac
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/definitions/entry.js +3 -5
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +0 -5
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +22 -5
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +0 -5
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +0 -5
- package/definitions/system.js.map +1 -1
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +0 -7
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/plainObject.js +1 -8
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +11 -19
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +7 -17
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js +0 -18
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +1 -8
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.js +15 -27
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +1 -44
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +26 -0
- package/operations/entry/filtering/createExpressions.js +176 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +14 -0
- package/operations/entry/filtering/createFields.js +105 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +17 -0
- package/operations/entry/filtering/extractSort.js +67 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +15 -0
- package/operations/entry/filtering/filter.js +143 -0
- package/operations/entry/filtering/filter.js.map +1 -0
- package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
- package/operations/entry/filtering/fullTextSearch.js +48 -0
- package/operations/entry/filtering/fullTextSearch.js.map +1 -0
- package/operations/entry/filtering/getValue.d.ts +5 -0
- package/operations/entry/filtering/getValue.js +63 -0
- package/operations/entry/filtering/getValue.js.map +1 -0
- package/operations/entry/filtering/index.d.ts +2 -0
- package/operations/entry/filtering/index.js +19 -0
- package/operations/entry/filtering/index.js.map +1 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +31 -0
- package/operations/entry/filtering/mapPlugins.js.map +1 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +41 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/filtering/plugins/index.js +13 -0
- package/operations/entry/filtering/plugins/index.js.map +1 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js +86 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +71 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +12 -0
- package/operations/entry/filtering/sort.js +69 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +4 -0
- package/operations/entry/filtering/systemFields.js +70 -0
- package/operations/entry/filtering/systemFields.js.map +1 -0
- package/operations/entry/filtering/transform.d.ts +6 -0
- package/operations/entry/filtering/transform.js +16 -0
- package/operations/entry/filtering/transform.js.map +1 -0
- package/operations/entry/filtering/types.d.ts +40 -0
- package/operations/entry/filtering/types.js +5 -0
- package/operations/entry/filtering/types.js.map +1 -0
- package/operations/entry/filtering/values.d.ts +2 -0
- package/operations/entry/filtering/values.js +22 -0
- package/operations/entry/filtering/values.js.map +1 -0
- package/operations/entry/filtering/where.d.ts +5 -0
- package/operations/entry/filtering/where.js +32 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.js +37 -107
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +0 -18
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/systemFields.js +0 -2
- package/operations/entry/systemFields.js.map +1 -1
- package/operations/group/index.js +2 -32
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +0 -25
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +0 -24
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +0 -17
- package/operations/system/index.js.map +1 -1
- package/package.json +13 -13
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -14
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +24 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +28 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +24 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +33 -2
- package/plugins/index.js.map +1 -1
- package/types.d.ts +1 -1
- package/types.js +0 -1
- package/types.js.map +1 -1
- package/operations/entry/utils.d.ts +0 -36
- package/operations/entry/utils.js +0 -680
- package/operations/entry/utils.js.map +0 -1
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.DataLoadersHandler = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
10
|
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
15
|
-
|
|
16
11
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
17
|
-
|
|
18
12
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
19
|
-
|
|
20
13
|
var _keys = require("./keys");
|
|
21
|
-
|
|
22
14
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
23
|
-
|
|
24
15
|
var _utils = require("@webiny/utils");
|
|
25
|
-
|
|
26
16
|
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
27
|
-
|
|
28
17
|
const getAllEntryRevisions = params => {
|
|
29
18
|
const {
|
|
30
19
|
entity,
|
|
@@ -36,7 +25,6 @@ const getAllEntryRevisions = params => {
|
|
|
36
25
|
} = model;
|
|
37
26
|
return new _dataloader.default(async ids => {
|
|
38
27
|
const results = {};
|
|
39
|
-
|
|
40
28
|
for (const id of ids) {
|
|
41
29
|
const queryAllParams = {
|
|
42
30
|
entity,
|
|
@@ -52,13 +40,11 @@ const getAllEntryRevisions = params => {
|
|
|
52
40
|
const items = await (0, _query.queryAll)(queryAllParams);
|
|
53
41
|
results[id] = (0, _cleanup.cleanupItems)(entity, items);
|
|
54
42
|
}
|
|
55
|
-
|
|
56
43
|
return ids.map(id => {
|
|
57
44
|
return results[id] || [];
|
|
58
45
|
});
|
|
59
46
|
});
|
|
60
47
|
};
|
|
61
|
-
|
|
62
48
|
const getRevisionById = params => {
|
|
63
49
|
const {
|
|
64
50
|
entity,
|
|
@@ -78,20 +64,16 @@ const getRevisionById = params => {
|
|
|
78
64
|
const {
|
|
79
65
|
version
|
|
80
66
|
} = (0, _utils.parseIdentifier)(id);
|
|
81
|
-
|
|
82
67
|
if (version === null) {
|
|
83
68
|
return collection;
|
|
84
69
|
}
|
|
85
|
-
|
|
86
70
|
const sortKey = (0, _keys.createRevisionSortKey)({
|
|
87
71
|
version
|
|
88
72
|
});
|
|
89
73
|
const keys = `${partitionKey}__${sortKey}`;
|
|
90
|
-
|
|
91
74
|
if (collection[keys]) {
|
|
92
75
|
return collection;
|
|
93
76
|
}
|
|
94
|
-
|
|
95
77
|
collection[keys] = entity.getBatch({
|
|
96
78
|
PK: partitionKey,
|
|
97
79
|
SK: sortKey
|
|
@@ -113,7 +95,6 @@ const getRevisionById = params => {
|
|
|
113
95
|
});
|
|
114
96
|
});
|
|
115
97
|
};
|
|
116
|
-
|
|
117
98
|
const getPublishedRevisionByEntryId = params => {
|
|
118
99
|
const {
|
|
119
100
|
entity,
|
|
@@ -131,11 +112,9 @@ const getPublishedRevisionByEntryId = params => {
|
|
|
131
112
|
locale,
|
|
132
113
|
id
|
|
133
114
|
});
|
|
134
|
-
|
|
135
115
|
if (collection[partitionKey]) {
|
|
136
116
|
return collection;
|
|
137
117
|
}
|
|
138
|
-
|
|
139
118
|
collection[partitionKey] = entity.getBatch({
|
|
140
119
|
PK: partitionKey,
|
|
141
120
|
SK: publishedKey
|
|
@@ -160,7 +139,6 @@ const getPublishedRevisionByEntryId = params => {
|
|
|
160
139
|
});
|
|
161
140
|
});
|
|
162
141
|
};
|
|
163
|
-
|
|
164
142
|
const getLatestRevisionByEntryId = params => {
|
|
165
143
|
const {
|
|
166
144
|
entity,
|
|
@@ -178,11 +156,9 @@ const getLatestRevisionByEntryId = params => {
|
|
|
178
156
|
locale,
|
|
179
157
|
id
|
|
180
158
|
});
|
|
181
|
-
|
|
182
159
|
if (collection[partitionKey]) {
|
|
183
160
|
return collection;
|
|
184
161
|
}
|
|
185
|
-
|
|
186
162
|
collection[partitionKey] = entity.getBatch({
|
|
187
163
|
PK: partitionKey,
|
|
188
164
|
SK: latestKey
|
|
@@ -207,7 +183,6 @@ const getLatestRevisionByEntryId = params => {
|
|
|
207
183
|
});
|
|
208
184
|
});
|
|
209
185
|
};
|
|
210
|
-
|
|
211
186
|
const dataLoaders = {
|
|
212
187
|
getAllEntryRevisions,
|
|
213
188
|
getRevisionById,
|
|
@@ -215,42 +190,35 @@ const dataLoaders = {
|
|
|
215
190
|
getLatestRevisionByEntryId
|
|
216
191
|
};
|
|
217
192
|
const loaderNames = Object.keys(dataLoaders);
|
|
218
|
-
|
|
219
193
|
class DataLoadersHandler {
|
|
220
194
|
constructor(params) {
|
|
221
195
|
(0, _defineProperty2.default)(this, "loaders", new Map());
|
|
222
196
|
(0, _defineProperty2.default)(this, "entity", void 0);
|
|
223
197
|
this.entity = params.entity;
|
|
224
198
|
}
|
|
225
|
-
|
|
226
199
|
async getAllEntryRevisions(params) {
|
|
227
200
|
return await this.loadMany("getAllEntryRevisions", params, params.ids);
|
|
228
201
|
}
|
|
229
|
-
|
|
230
202
|
async getRevisionById(params) {
|
|
231
203
|
return await this.loadMany("getRevisionById", params, params.ids);
|
|
232
204
|
}
|
|
233
|
-
|
|
234
205
|
async getPublishedRevisionByEntryId(params) {
|
|
235
206
|
return await this.loadMany("getPublishedRevisionByEntryId", params, params.ids);
|
|
236
207
|
}
|
|
237
|
-
|
|
238
208
|
async getLatestRevisionByEntryId(params) {
|
|
239
209
|
return await this.loadMany("getLatestRevisionByEntryId", params, params.ids);
|
|
240
210
|
}
|
|
211
|
+
|
|
241
212
|
/**
|
|
242
213
|
* TODO @ts-refactor
|
|
243
214
|
* Maybe pass on the generics to DataLoader definition?
|
|
244
215
|
*/
|
|
245
|
-
|
|
246
|
-
|
|
247
216
|
getLoader(name, params) {
|
|
248
217
|
if (!dataLoaders[name]) {
|
|
249
218
|
throw new _error.default("Unknown data loader.", "UNKNOWN_DATA_LOADER", {
|
|
250
219
|
name
|
|
251
220
|
});
|
|
252
221
|
}
|
|
253
|
-
|
|
254
222
|
const {
|
|
255
223
|
model
|
|
256
224
|
} = params;
|
|
@@ -259,22 +227,17 @@ class DataLoadersHandler {
|
|
|
259
227
|
locale
|
|
260
228
|
} = model;
|
|
261
229
|
const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;
|
|
262
|
-
|
|
263
230
|
if (!this.loaders.has(loaderKey)) {
|
|
264
231
|
this.loaders.set(loaderKey, dataLoaders[name]((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
265
232
|
entity: this.entity
|
|
266
233
|
})));
|
|
267
234
|
}
|
|
268
|
-
|
|
269
235
|
return this.loaders.get(loaderKey);
|
|
270
236
|
}
|
|
271
|
-
|
|
272
237
|
async loadMany(loader, params, ids) {
|
|
273
238
|
let results;
|
|
274
|
-
|
|
275
239
|
try {
|
|
276
240
|
results = await this.getLoader(loader, params).loadMany(ids);
|
|
277
|
-
|
|
278
241
|
if (Array.isArray(results) === true) {
|
|
279
242
|
return results.reduce((acc, res) => {
|
|
280
243
|
if (Array.isArray(res) === false) {
|
|
@@ -283,12 +246,10 @@ class DataLoadersHandler {
|
|
|
283
246
|
data: JSON.stringify(res.data || {})
|
|
284
247
|
}));
|
|
285
248
|
}
|
|
286
|
-
|
|
287
249
|
throw new _error.default("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
288
250
|
loader
|
|
289
251
|
}));
|
|
290
252
|
}
|
|
291
|
-
|
|
292
253
|
acc.push(...res);
|
|
293
254
|
return acc;
|
|
294
255
|
}, []);
|
|
@@ -301,21 +262,17 @@ class DataLoadersHandler {
|
|
|
301
262
|
ids
|
|
302
263
|
}));
|
|
303
264
|
}
|
|
304
|
-
|
|
305
265
|
throw new _error.default(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
|
|
306
266
|
loader,
|
|
307
267
|
ids,
|
|
308
268
|
results
|
|
309
269
|
});
|
|
310
270
|
}
|
|
311
|
-
|
|
312
271
|
clearAll(params) {
|
|
313
272
|
for (const name of loaderNames) {
|
|
314
273
|
const loader = this.getLoader(name, params);
|
|
315
274
|
loader.clearAll();
|
|
316
275
|
}
|
|
317
276
|
}
|
|
318
|
-
|
|
319
277
|
}
|
|
320
|
-
|
|
321
278
|
exports.DataLoadersHandler = DataLoadersHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getAllEntryRevisions","params","entity","model","tenant","locale","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","getRevisionById","queries","reduce","collection","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","Object","values","filter","item","getPublishedRevisionByEntryId","publishedKey","createPublishedSortKey","entryId","getLatestRevisionByEntryId","latestKey","createLatestSortKey","dataLoaders","loaderNames","DataLoadersHandler","constructor","Map","loadMany","getLoader","name","WebinyError","loaderKey","modelId","loaders","has","set","get","loader","Array","isArray","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { CmsStorageEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport {\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"./keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\n\nconst getAllEntryRevisions = (params: LoaderParams) => {\n const { entity, model } = params;\n const { tenant, locale } = model;\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n });\n};\n\nconst getRevisionById = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n });\n};\n\nconst getPublishedRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const publishedKey = createPublishedSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst getLatestRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst dataLoaders: Record<Loaders, any> = {\n getAllEntryRevisions,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId\n};\n\nexport interface GetAllEntryRevisionsParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetRevisionByIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetPublishedRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetLatestRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\ninterface LoaderParams {\n entity: Entity<any>;\n model: CmsModel;\n}\n\ninterface GetLoaderParams {\n model: CmsModel;\n}\n\ninterface ClearLoaderParams {\n model: CmsModel;\n entry?: CmsStorageEntry;\n}\n\ntype Loaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nconst loaderNames = Object.keys(dataLoaders) as Loaders[];\n\ninterface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\nexport class DataLoadersHandler {\n private readonly loaders: Map<string, DataLoader<any, any>> = new Map();\n private readonly entity: Entity<any>;\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(\n params: GetAllEntryRevisionsParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getAllEntryRevisions\", params, params.ids);\n }\n\n public async getRevisionById(params: GetRevisionByIdParams): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId(\n params: GetPublishedRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, params.ids);\n }\n\n public async getLatestRevisionByEntryId(\n params: GetLatestRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, params.ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: Loaders, params: GetLoaderParams): DataLoader<any, any> {\n if (!dataLoaders[name]) {\n throw new WebinyError(\"Unknown data loader.\", \"UNKNOWN_DATA_LOADER\", {\n name\n });\n }\n const { model } = params;\n const { tenant, locale } = model;\n const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;\n if (!this.loaders.has(loaderKey)) {\n this.loaders.set(\n loaderKey,\n dataLoaders[name]({\n ...params,\n entity: this.entity\n })\n );\n }\n return this.loaders.get(loaderKey) as DataLoader<any, any>;\n }\n\n private async loadMany(\n loader: Loaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry[]> {\n let results;\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params: Omit<ClearLoaderParams, \"entry\">): void {\n for (const name of loaderNames) {\n const loader = this.getLoader(name, params);\n loader.clearAll();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AAMA;;AACA;;AACA;;AAEA,MAAMA,oBAAoB,GAAIC,MAAD,IAA0B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAoBF,MAA1B;EACA,MAAM;IAAEG,MAAF;IAAUC;EAAV,IAAqBF,KAA3B;EACA,OAAO,IAAIG,mBAAJ,CAA0C,MAAOC,GAAP,IAAkC;IAC/E,MAAMC,OAA0C,GAAG,EAAnD;;IACA,KAAK,MAAMC,EAAX,IAAiBF,GAAjB,EAAsB;MAClB,MAAMG,cAA8B,GAAG;QACnCR,MADmC;QAEnCS,YAAY,EAAE,IAAAC,wBAAA,EAAmB;UAC7BR,MAD6B;UAE7BC,MAF6B;UAG7BI;QAH6B,CAAnB,CAFqB;QAOnCI,OAAO,EAAE;UACLC,UAAU,EAAE;QADP;MAP0B,CAAvC;MAWA,MAAMC,KAAK,GAAG,MAAM,IAAAC,eAAA,EAA0BN,cAA1B,CAApB;MACAF,OAAO,CAACC,EAAD,CAAP,GAAc,IAAAQ,qBAAA,EAAaf,MAAb,E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3B,EAAkC;YAC9B,IAAIA,GAAG,IAAIA,GAAG,CAACC,OAAf,EAAwB;cACpB,MAAM,IAAIZ,cAAJ,CAAgBW,GAAG,CAACC,OAApB,EAA6BD,GAAG,CAACE,IAAjC,8DACCF,GADD;gBAEFG,IAAI,EAAEC,IAAI,CAACC,SAAL,CAAeL,GAAG,CAACG,IAAJ,IAAY,EAA3B;cAFJ,GAAN;YAIH;;YACD,MAAM,IAAId,cAAJ,CACF,uFADE,EAEF,2BAFE,8DAIKpD,MAJL;cAKE2D;YALF,GAAN;UAQH;;UACDG,GAAG,CAACO,IAAJ,CAAS,GAAGN,GAAZ;UACA,OAAOD,GAAP;QACH,CAnBM,EAmBJ,EAnBI,CAAP;MAoBH;IACJ,CAxBD,CAwBE,OAAOQ,EAAP,EAAW;MACT,MAAM,IAAIlB,cAAJ,CACFkB,EAAE,CAACN,OAAH,IAAc,oBADZ,EAEFM,EAAE,CAACL,IAAH,IAAW,mBAFT;QAIEM,KAAK,EAAED;MAJT,GAKKtE,MALL;QAME2D,MANF;QAOErD;MAPF,GAAN;IAUH;;IACD,MAAM,IAAI8C,cAAJ,CACD,2DADC,EAEF,4BAFE,EAGF;MACIO,MADJ;MAEIrD,GAFJ;MAGIC;IAHJ,CAHE,CAAN;EASH;;EAEMiE,QAAQ,CAACxE,MAAD,EAAiD;IAC5D,KAAK,MAAMmD,IAAX,IAAmBN,WAAnB,EAAgC;MAC5B,MAAMc,MAAM,GAAG,KAAKT,SAAL,CAAeC,IAAf,EAAqBnD,MAArB,CAAf;MACA2D,MAAM,CAACa,QAAP;IACH;EACJ;;AAjH2B"}
|
|
1
|
+
{"version":3,"names":["getAllEntryRevisions","params","entity","model","tenant","locale","DataLoader","ids","results","id","queryAllParams","partitionKey","createPartitionKey","options","beginsWith","items","queryAll","cleanupItems","map","getRevisionById","queries","reduce","collection","version","parseIdentifier","sortKey","createRevisionSortKey","keys","getBatch","PK","SK","records","batchReadAll","table","Object","values","filter","item","getPublishedRevisionByEntryId","publishedKey","createPublishedSortKey","entryId","getLatestRevisionByEntryId","latestKey","createLatestSortKey","dataLoaders","loaderNames","DataLoadersHandler","constructor","Map","loadMany","getLoader","name","WebinyError","loaderKey","modelId","loaders","has","set","get","loader","Array","isArray","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll"],"sources":["dataLoaders.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { CmsStorageEntry, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport { queryAll, QueryAllParams } from \"@webiny/db-dynamodb/utils/query\";\nimport {\n createLatestSortKey,\n createPartitionKey,\n createPublishedSortKey,\n createRevisionSortKey\n} from \"./keys\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\n\nconst getAllEntryRevisions = (params: LoaderParams) => {\n const { entity, model } = params;\n const { tenant, locale } = model;\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const results: Record<string, CmsStorageEntry[]> = {};\n for (const id of ids) {\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n tenant,\n locale,\n id\n }),\n options: {\n beginsWith: \"REV#\"\n }\n };\n const items = await queryAll<CmsStorageEntry>(queryAllParams);\n results[id] = cleanupItems(entity, items);\n }\n\n return ids.map(id => {\n return results[id] || [];\n });\n });\n};\n\nconst getRevisionById = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n return collection;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const keys = `${partitionKey}__${sortKey}`;\n if (collection[keys]) {\n return collection;\n }\n\n collection[keys] = entity.getBatch({\n PK: partitionKey,\n SK: sortKey\n });\n\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n });\n};\n\nconst getPublishedRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const publishedKey = createPublishedSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: publishedKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst getLatestRevisionByEntryId = (params: LoaderParams) => {\n const { entity, model } = params;\n const { locale, tenant } = model;\n\n const latestKey = createLatestSortKey();\n\n return new DataLoader<string, CmsStorageEntry[]>(async (ids: readonly string[]) => {\n const queries = ids.reduce((collection, id) => {\n const partitionKey = createPartitionKey({\n tenant,\n locale,\n id\n });\n if (collection[partitionKey]) {\n return collection;\n }\n collection[partitionKey] = entity.getBatch({\n PK: partitionKey,\n SK: latestKey\n });\n return collection;\n /**\n * We cast as any because there is no return type defined.\n */\n }, {} as Record<string, any>);\n\n const records = await batchReadAll<CmsStorageEntry>({\n table: entity.table,\n items: Object.values(queries)\n });\n const items = cleanupItems(entity, records);\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n });\n};\n\nconst dataLoaders: Record<Loaders, any> = {\n getAllEntryRevisions,\n getRevisionById,\n getPublishedRevisionByEntryId,\n getLatestRevisionByEntryId\n};\n\nexport interface GetAllEntryRevisionsParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetRevisionByIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetPublishedRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\nexport interface GetLatestRevisionByEntryIdParams {\n ids: readonly string[];\n model: CmsModel;\n}\n\ninterface LoaderParams {\n entity: Entity<any>;\n model: CmsModel;\n}\n\ninterface GetLoaderParams {\n model: CmsModel;\n}\n\ninterface ClearLoaderParams {\n model: CmsModel;\n entry?: CmsStorageEntry;\n}\n\ntype Loaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nconst loaderNames = Object.keys(dataLoaders) as Loaders[];\n\ninterface DataLoadersHandlerParams {\n entity: Entity<any>;\n}\nexport class DataLoadersHandler {\n private readonly loaders: Map<string, DataLoader<any, any>> = new Map();\n private readonly entity: Entity<any>;\n\n public constructor(params: DataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions(\n params: GetAllEntryRevisionsParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getAllEntryRevisions\", params, params.ids);\n }\n\n public async getRevisionById(params: GetRevisionByIdParams): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId(\n params: GetPublishedRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getPublishedRevisionByEntryId\", params, params.ids);\n }\n\n public async getLatestRevisionByEntryId(\n params: GetLatestRevisionByEntryIdParams\n ): Promise<CmsStorageEntry[]> {\n return await this.loadMany(\"getLatestRevisionByEntryId\", params, params.ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: Loaders, params: GetLoaderParams): DataLoader<any, any> {\n if (!dataLoaders[name]) {\n throw new WebinyError(\"Unknown data loader.\", \"UNKNOWN_DATA_LOADER\", {\n name\n });\n }\n const { model } = params;\n const { tenant, locale } = model;\n const loaderKey = `${name}-${tenant}-${locale}-${model.modelId}`;\n if (!this.loaders.has(loaderKey)) {\n this.loaders.set(\n loaderKey,\n dataLoaders[name]({\n ...params,\n entity: this.entity\n })\n );\n }\n return this.loaders.get(loaderKey) as DataLoader<any, any>;\n }\n\n private async loadMany(\n loader: Loaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry[]> {\n let results;\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params: Omit<ClearLoaderParams, \"entry\">): void {\n for (const name of loaderNames) {\n const loader = this.getLoader(name, params);\n loader.clearAll();\n }\n }\n}\n"],"mappings":";;;;;;;;;AAAA;AAEA;AAEA;AACA;AAMA;AACA;AACA;AAEA,MAAMA,oBAAoB,GAAIC,MAAoB,IAAK;EACnD,MAAM;IAAEC,MAAM;IAAEC;EAA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EOiE,QAAQ,CAACxE,MAAwC,EAAQ;IAC5D,KAAK,MAAMmD,IAAI,IAAIN,WAAW,EAAE;MAC5B,MAAMc,MAAM,GAAG,IAAI,CAACT,SAAS,CAACC,IAAI,EAAEnD,MAAM,CAAC;MAC3C2D,MAAM,CAACa,QAAQ,EAAE;IACrB;EACJ;AACJ;AAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
import { Field } from "./types";
|
|
5
|
+
interface Params {
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
where: Partial<CmsEntryListWhere>;
|
|
8
|
+
fields: Record<string, Field>;
|
|
9
|
+
}
|
|
10
|
+
export declare type ExpressionCondition = "AND" | "OR";
|
|
11
|
+
export interface Expression {
|
|
12
|
+
expressions: Expression[];
|
|
13
|
+
filters: Filter[];
|
|
14
|
+
condition: ExpressionCondition;
|
|
15
|
+
}
|
|
16
|
+
export interface Filter {
|
|
17
|
+
field: Field;
|
|
18
|
+
path: string;
|
|
19
|
+
fieldPathId: string;
|
|
20
|
+
plugin: ValueFilterPlugin;
|
|
21
|
+
negate: boolean;
|
|
22
|
+
compareValue: any;
|
|
23
|
+
transformValue: <I = any, O = any>(value: I) => O;
|
|
24
|
+
}
|
|
25
|
+
export declare const createExpressions: (params: Params) => Expression;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createExpressions = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
10
|
+
var _mapPlugins = require("./mapPlugins");
|
|
11
|
+
var _where = require("./where");
|
|
12
|
+
var _transform = require("./transform");
|
|
13
|
+
var _CmsEntryFieldFilterPlugin = require("../../../plugins/CmsEntryFieldFilterPlugin");
|
|
14
|
+
var _values = require("./values");
|
|
15
|
+
const createExpressions = params => {
|
|
16
|
+
const {
|
|
17
|
+
where,
|
|
18
|
+
plugins,
|
|
19
|
+
fields
|
|
20
|
+
} = params;
|
|
21
|
+
const filterPlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
22
|
+
plugins,
|
|
23
|
+
type: _ValueFilterPlugin.ValueFilterPlugin.type,
|
|
24
|
+
property: "operation"
|
|
25
|
+
});
|
|
26
|
+
const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
27
|
+
plugins,
|
|
28
|
+
type: "cms-field-filter-value-transform",
|
|
29
|
+
property: "fieldType"
|
|
30
|
+
});
|
|
31
|
+
const fieldFilterCreatePlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
32
|
+
plugins,
|
|
33
|
+
type: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.type,
|
|
34
|
+
property: "fieldType"
|
|
35
|
+
});
|
|
36
|
+
const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
|
|
37
|
+
const getFilterCreatePlugin = type => {
|
|
38
|
+
const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;
|
|
39
|
+
if (filterCreatePlugin) {
|
|
40
|
+
return filterCreatePlugin;
|
|
41
|
+
}
|
|
42
|
+
throw new _error.default(`There is no filter create plugin for the field type "${type}".`, "MISSING_FILTER_CREATE_PLUGIN", {
|
|
43
|
+
type
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const createExpression = ({
|
|
47
|
+
where,
|
|
48
|
+
condition
|
|
49
|
+
}) => {
|
|
50
|
+
const expression = {
|
|
51
|
+
filters: [],
|
|
52
|
+
expressions: [],
|
|
53
|
+
condition
|
|
54
|
+
};
|
|
55
|
+
for (const key in where) {
|
|
56
|
+
const value = where[key];
|
|
57
|
+
if (value === undefined) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* If there are "AND" or "OR" keys, let's sort them out first.
|
|
63
|
+
*
|
|
64
|
+
*
|
|
65
|
+
* AND conditional
|
|
66
|
+
*/
|
|
67
|
+
if (key === "AND") {
|
|
68
|
+
const childWhereList = (0, _values.getWhereValues)(value, key);
|
|
69
|
+
const childExpression = {
|
|
70
|
+
condition: "AND",
|
|
71
|
+
filters: [],
|
|
72
|
+
expressions: []
|
|
73
|
+
};
|
|
74
|
+
for (const childWhere of childWhereList) {
|
|
75
|
+
const result = createExpression({
|
|
76
|
+
where: childWhere,
|
|
77
|
+
condition: "AND"
|
|
78
|
+
});
|
|
79
|
+
childExpression.expressions.push(result);
|
|
80
|
+
}
|
|
81
|
+
expression.expressions.push(childExpression);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* OR conditional
|
|
86
|
+
*/
|
|
87
|
+
if (key === "OR") {
|
|
88
|
+
const childWhereList = (0, _values.getWhereValues)(value, key);
|
|
89
|
+
const childExpression = {
|
|
90
|
+
condition: "OR",
|
|
91
|
+
filters: [],
|
|
92
|
+
expressions: []
|
|
93
|
+
};
|
|
94
|
+
for (const childWhere of childWhereList) {
|
|
95
|
+
const result = createExpression({
|
|
96
|
+
where: childWhere,
|
|
97
|
+
condition: "AND"
|
|
98
|
+
});
|
|
99
|
+
childExpression.expressions.push(result);
|
|
100
|
+
}
|
|
101
|
+
expression.expressions.push(childExpression);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const whereParams = (0, _where.extractWhereParams)(key);
|
|
105
|
+
if (!whereParams) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const {
|
|
109
|
+
fieldId,
|
|
110
|
+
operation,
|
|
111
|
+
negate
|
|
112
|
+
} = whereParams;
|
|
113
|
+
const field = fields[fieldId];
|
|
114
|
+
if (!field) {
|
|
115
|
+
throw new _error.default(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
116
|
+
fieldId
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* We need a filter create plugin for this type.
|
|
122
|
+
*/
|
|
123
|
+
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
124
|
+
const transformValuePlugin = transformValuePlugins[field.type];
|
|
125
|
+
const transformValueCallable = value => {
|
|
126
|
+
if (!transformValuePlugin) {
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
return transformValuePlugin.transform({
|
|
130
|
+
field,
|
|
131
|
+
value
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const result = filterCreatePlugin.create({
|
|
135
|
+
key,
|
|
136
|
+
value,
|
|
137
|
+
valueFilterPlugins: filterPlugins,
|
|
138
|
+
transformValuePlugins,
|
|
139
|
+
getFilterCreatePlugin,
|
|
140
|
+
operation,
|
|
141
|
+
negate,
|
|
142
|
+
field,
|
|
143
|
+
fields,
|
|
144
|
+
compareValue: (0, _transform.transformValue)({
|
|
145
|
+
value,
|
|
146
|
+
transform: transformValueCallable
|
|
147
|
+
}),
|
|
148
|
+
transformValue: transformValueCallable
|
|
149
|
+
});
|
|
150
|
+
/**
|
|
151
|
+
* There is a possibility of
|
|
152
|
+
* - no result
|
|
153
|
+
* - result being an array
|
|
154
|
+
* - result being an object
|
|
155
|
+
*/
|
|
156
|
+
if (!result || Array.isArray(result) && result.length === 0) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
expression.filters.push(...(Array.isArray(result) ? result : [result]));
|
|
160
|
+
}
|
|
161
|
+
return expression;
|
|
162
|
+
};
|
|
163
|
+
const expression = createExpression({
|
|
164
|
+
where,
|
|
165
|
+
condition: "AND"
|
|
166
|
+
});
|
|
167
|
+
/**
|
|
168
|
+
* If the first expression has no filters and has only one expression, put that expression as main one.
|
|
169
|
+
* This will mostly be used when having an OR condition as the single expression in the root level of the where
|
|
170
|
+
*/
|
|
171
|
+
if (expression.filters.length > 0 || expression.expressions.length !== 1) {
|
|
172
|
+
return expression;
|
|
173
|
+
}
|
|
174
|
+
return expression.expressions[0];
|
|
175
|
+
};
|
|
176
|
+
exports.createExpressions = createExpressions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createExpressions","params","where","plugins","fields","filterPlugins","getMappedPlugins","type","ValueFilterPlugin","property","transformValuePlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","filterCreatePlugin","WebinyError","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","push","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","transformValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { getMappedPlugins } from \"./mapPlugins\";\nimport { extractWhereParams } from \"./where\";\nimport { transformValue } from \"./transform\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface CreateExpressionCb {\n (params: CreateExpressionParams): Expression;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${type}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n type\n }\n );\n };\n\n const createExpression: CreateExpressionCb = ({ where, condition }) => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AAIA;AACA;AACA;AACA;AACA;AAmCO,MAAMA,iBAAiB,GAAIC,MAAc,IAAiB;EAC7D,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B,UAAU,CAACE,WAAW,CAACyB,MAAM,KAAK,CAAC,EAAE;IACtE,OAAO3B,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC;AAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { Field } from "./types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
interface Params {
|
|
5
|
+
fields: CmsModelField[];
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
10
|
+
*
|
|
11
|
+
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
12
|
+
*/
|
|
13
|
+
export declare const createFields: (params: Params) => Record<string, Field>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createFields = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _systemFields = require("./systemFields");
|
|
10
|
+
var _plugins = require("../../../plugins");
|
|
11
|
+
var _mapPlugins = require("./mapPlugins");
|
|
12
|
+
/**
|
|
13
|
+
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
14
|
+
*
|
|
15
|
+
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
16
|
+
*/
|
|
17
|
+
const createFields = params => {
|
|
18
|
+
const {
|
|
19
|
+
fields,
|
|
20
|
+
plugins
|
|
21
|
+
} = params;
|
|
22
|
+
const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
23
|
+
plugins,
|
|
24
|
+
type: "cms-field-filter-value-transform",
|
|
25
|
+
property: "fieldType"
|
|
26
|
+
});
|
|
27
|
+
const valuePathPlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
28
|
+
plugins,
|
|
29
|
+
type: _plugins.CmsEntryFieldFilterPathPlugin.type,
|
|
30
|
+
property: "fieldType"
|
|
31
|
+
});
|
|
32
|
+
const collection = (0, _systemFields.createSystemFields)().reduce((fields, field) => {
|
|
33
|
+
const transformPlugin = transformValuePlugins[field.type];
|
|
34
|
+
fields[field.fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
35
|
+
parents: [],
|
|
36
|
+
system: true,
|
|
37
|
+
createPath: ({
|
|
38
|
+
field
|
|
39
|
+
}) => {
|
|
40
|
+
var _field$settings;
|
|
41
|
+
return ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.path) || field.fieldId;
|
|
42
|
+
},
|
|
43
|
+
transform: value => {
|
|
44
|
+
if (!transformPlugin) {
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
return transformPlugin.transform({
|
|
48
|
+
field,
|
|
49
|
+
value
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return fields;
|
|
54
|
+
}, {});
|
|
55
|
+
const addFieldsToCollection = (fields, parents = []) => {
|
|
56
|
+
/**
|
|
57
|
+
* Exit early if no fields are sent.
|
|
58
|
+
*/
|
|
59
|
+
if (fields.length === 0) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
for (const field of fields) {
|
|
63
|
+
var _field$settings2;
|
|
64
|
+
const transformPlugin = transformValuePlugins[field.type];
|
|
65
|
+
const valuePathPlugin = valuePathPlugins[field.type];
|
|
66
|
+
/**
|
|
67
|
+
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
68
|
+
*/
|
|
69
|
+
const fieldId = [...parents, {
|
|
70
|
+
fieldId: field.fieldId,
|
|
71
|
+
multipleValues: field.multipleValues
|
|
72
|
+
}].map(f => f.fieldId).join(".");
|
|
73
|
+
collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
74
|
+
parents,
|
|
75
|
+
system: false,
|
|
76
|
+
createPath: params => {
|
|
77
|
+
if (valuePathPlugin) {
|
|
78
|
+
return valuePathPlugin.createPath(params);
|
|
79
|
+
}
|
|
80
|
+
return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
|
|
81
|
+
},
|
|
82
|
+
transform: value => {
|
|
83
|
+
if (!transformPlugin) {
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
return transformPlugin.transform({
|
|
87
|
+
field,
|
|
88
|
+
value
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
|
|
93
|
+
if (!childFields || childFields.length === 0) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
addFieldsToCollection(childFields, [...parents, {
|
|
97
|
+
fieldId: field.fieldId,
|
|
98
|
+
multipleValues: field.multipleValues
|
|
99
|
+
}]);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
addFieldsToCollection(fields);
|
|
103
|
+
return collection;
|
|
104
|
+
};
|
|
105
|
+
exports.createFields = createFields;
|