@webiny/api-headless-cms-ddb 0.0.0-mt-3 → 0.0.0-unstable.40876133bb
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.d.ts +2 -1
- package/definitions/entry.js +6 -7
- package/definitions/entry.js.map +1 -0
- package/definitions/group.d.ts +2 -1
- package/definitions/group.js +3 -7
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +2 -1
- package/definitions/model.js +3 -7
- package/definitions/model.js.map +1 -0
- package/definitions/settings.d.ts +2 -1
- package/definitions/settings.js +3 -7
- package/definitions/settings.js.map +1 -0
- package/definitions/system.d.ts +2 -1
- package/definitions/system.js +3 -7
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +2 -1
- package/definitions/table.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +6 -10
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +2 -3
- package/dynamoDb/path/plainObject.js +29 -22
- package/dynamoDb/path/plainObject.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +2 -3
- package/dynamoDb/storage/date.js +80 -46
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +7 -4
- package/dynamoDb/storage/longText.js +72 -54
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -8
- package/dynamoDb/storage/richText.js +70 -67
- package/dynamoDb/storage/richText.js.map +1 -0
- package/dynamoDb/transformValue/datetime.d.ts +4 -2
- package/dynamoDb/transformValue/datetime.js +31 -26
- package/dynamoDb/transformValue/datetime.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +42 -24
- package/index.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +12 -8
- package/operations/entry/dataLoaders.js +31 -13
- package/operations/entry/dataLoaders.js.map +1 -0
- package/operations/entry/index.d.ts +2 -2
- package/operations/entry/index.js +253 -219
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.js +11 -0
- package/operations/entry/keys.js.map +1 -0
- package/operations/entry/systemFields.js +24 -0
- package/operations/entry/systemFields.js.map +1 -0
- package/operations/entry/utils.d.ts +10 -5
- package/operations/entry/utils.js +370 -96
- package/operations/entry/utils.js.map +1 -0
- package/operations/group/index.d.ts +3 -2
- package/operations/group/index.js +7 -13
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +3 -2
- package/operations/model/index.js +15 -14
- package/operations/model/index.js.map +1 -0
- package/operations/settings/index.d.ts +3 -2
- package/operations/settings/index.js +7 -13
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +3 -2
- package/operations/system/index.js +5 -11
- package/operations/system/index.js.map +1 -0
- package/package.json +22 -23
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js +55 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/types.d.ts +1 -32
- package/types.js.map +1 -0
- package/dynamoDb/path/ref.d.ts +0 -3
- package/dynamoDb/path/ref.js +0 -27
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.sortEntryItems = exports.filterItems = exports.buildModelFields = void 0;
|
|
9
9
|
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
10
12
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
|
|
13
15
|
|
|
14
16
|
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
15
17
|
|
|
@@ -17,11 +19,18 @@ var _systemFields = require("./systemFields");
|
|
|
17
19
|
|
|
18
20
|
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
19
21
|
|
|
22
|
+
var _CmsEntryFieldFilterPathPlugin = require("../../plugins/CmsEntryFieldFilterPathPlugin");
|
|
23
|
+
|
|
20
24
|
const VALUES_ATTRIBUTE = "values";
|
|
21
25
|
|
|
22
26
|
const extractWhereParams = key => {
|
|
23
27
|
const result = key.split("_");
|
|
24
28
|
const fieldId = result.shift();
|
|
29
|
+
|
|
30
|
+
if (!fieldId) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
const rawOp = result.length === 0 ? "eq" : result.join("_");
|
|
26
35
|
/**
|
|
27
36
|
* When rawOp is not, it means it is equal negated so just return that.
|
|
@@ -52,6 +61,63 @@ const transformValue = (value, transform) => {
|
|
|
52
61
|
return transform(value);
|
|
53
62
|
};
|
|
54
63
|
|
|
64
|
+
const getFilterPlugin = params => {
|
|
65
|
+
const {
|
|
66
|
+
plugins,
|
|
67
|
+
operation
|
|
68
|
+
} = params;
|
|
69
|
+
const plugin = plugins[operation];
|
|
70
|
+
|
|
71
|
+
if (plugin) {
|
|
72
|
+
return plugin;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
throw new _error.default(`There is no filter plugin for operation "${operation}".`, "FILTER_PLUGIN_ERROR", {
|
|
76
|
+
operation
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const createValuePath = params => {
|
|
81
|
+
const {
|
|
82
|
+
field,
|
|
83
|
+
plugins,
|
|
84
|
+
index
|
|
85
|
+
} = params;
|
|
86
|
+
const {
|
|
87
|
+
fieldId
|
|
88
|
+
} = field;
|
|
89
|
+
const valuePathPlugin = plugins[field.type];
|
|
90
|
+
const basePath = _systemFields.systemFields[fieldId] ? "" : `${VALUES_ATTRIBUTE}.`;
|
|
91
|
+
|
|
92
|
+
if (!valuePathPlugin || valuePathPlugin.canUse(field) === false) {
|
|
93
|
+
return `${basePath}${fieldId}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const path = valuePathPlugin.createPath({
|
|
97
|
+
field,
|
|
98
|
+
index
|
|
99
|
+
});
|
|
100
|
+
return `${basePath}${path}`;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const isObjectFiltering = params => {
|
|
104
|
+
const {
|
|
105
|
+
value
|
|
106
|
+
} = params;
|
|
107
|
+
|
|
108
|
+
if (!value) {
|
|
109
|
+
return false;
|
|
110
|
+
} else if (Array.isArray(value) === true) {
|
|
111
|
+
return false;
|
|
112
|
+
} else if (value instanceof Date || !!value.toISOString) {
|
|
113
|
+
return false;
|
|
114
|
+
} else if (typeof value !== "object") {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return true;
|
|
119
|
+
};
|
|
120
|
+
|
|
55
121
|
const createFilters = params => {
|
|
56
122
|
const {
|
|
57
123
|
where,
|
|
@@ -70,15 +136,33 @@ const createFilters = params => {
|
|
|
70
136
|
});
|
|
71
137
|
const valuePathPlugins = getMappedPlugins({
|
|
72
138
|
plugins,
|
|
73
|
-
type:
|
|
139
|
+
type: _CmsEntryFieldFilterPathPlugin.CmsEntryFieldFilterPathPlugin.type,
|
|
74
140
|
property: "fieldType"
|
|
75
141
|
});
|
|
76
|
-
|
|
142
|
+
const filters = [];
|
|
143
|
+
|
|
144
|
+
for (const key in where) {
|
|
145
|
+
if (where.hasOwnProperty(key) === false) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const value = where[key];
|
|
150
|
+
|
|
151
|
+
if (value === undefined) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const whereParams = extractWhereParams(key);
|
|
156
|
+
|
|
157
|
+
if (!whereParams) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
77
161
|
const {
|
|
78
162
|
fieldId,
|
|
79
163
|
operation,
|
|
80
164
|
negate
|
|
81
|
-
} =
|
|
165
|
+
} = whereParams;
|
|
82
166
|
const field = fields[fieldId];
|
|
83
167
|
|
|
84
168
|
if (!field) {
|
|
@@ -88,33 +172,6 @@ const createFilters = params => {
|
|
|
88
172
|
}
|
|
89
173
|
|
|
90
174
|
const transformValuePlugin = transformValuePlugins[field.def.type];
|
|
91
|
-
const valuePathPlugin = valuePathPlugins[field.def.type];
|
|
92
|
-
let targetValuePath;
|
|
93
|
-
/**
|
|
94
|
-
* add the base path if field is not a system field
|
|
95
|
-
* pathPlugin should not know about that
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
const basePath = _systemFields.systemFields[fieldId] ? "" : `${VALUES_ATTRIBUTE}.`;
|
|
99
|
-
|
|
100
|
-
if (valuePathPlugin) {
|
|
101
|
-
targetValuePath = valuePathPlugin.createPath({
|
|
102
|
-
field: field.def
|
|
103
|
-
});
|
|
104
|
-
} else if (_systemFields.systemFields[fieldId]) {
|
|
105
|
-
targetValuePath = fieldId;
|
|
106
|
-
} else {
|
|
107
|
-
targetValuePath = field.def.fieldId;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const valuePath = `${basePath}${targetValuePath}`;
|
|
111
|
-
const filterPlugin = filterPlugins[operation];
|
|
112
|
-
|
|
113
|
-
if (!filterPlugin) {
|
|
114
|
-
throw new _error.default(`There is no filter plugin for operation "${operation}".`, "FILTER_PLUGIN_ERROR", {
|
|
115
|
-
operation
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
175
|
|
|
119
176
|
const transformValueCallable = value => {
|
|
120
177
|
if (!transformValuePlugin) {
|
|
@@ -127,42 +184,232 @@ const createFilters = params => {
|
|
|
127
184
|
});
|
|
128
185
|
};
|
|
129
186
|
|
|
130
|
-
|
|
187
|
+
const objectFilteringParams = {
|
|
188
|
+
key,
|
|
189
|
+
value,
|
|
190
|
+
field: field.def
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
if (isObjectFiltering(objectFilteringParams)) {
|
|
194
|
+
const propertyFilters = Object.keys(value);
|
|
195
|
+
|
|
196
|
+
if (propertyFilters.length === 0) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for (const propertyFilter of propertyFilters) {
|
|
201
|
+
const whereParams = extractWhereParams(propertyFilter);
|
|
202
|
+
|
|
203
|
+
if (!whereParams) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const {
|
|
208
|
+
fieldId: propertyId,
|
|
209
|
+
operation: propertyOperation,
|
|
210
|
+
negate: propertyNegate
|
|
211
|
+
} = whereParams;
|
|
212
|
+
const filterPlugin = getFilterPlugin({
|
|
213
|
+
plugins: filterPlugins,
|
|
214
|
+
operation: propertyOperation
|
|
215
|
+
});
|
|
216
|
+
const basePath = createValuePath({
|
|
217
|
+
field: field.def,
|
|
218
|
+
plugins: valuePathPlugins
|
|
219
|
+
});
|
|
220
|
+
const multiValuesPath = field.def.multipleValues ? "%s." : "";
|
|
221
|
+
filters.push({
|
|
222
|
+
fieldId,
|
|
223
|
+
path: `${basePath}.${multiValuesPath}${propertyId}`,
|
|
224
|
+
filterPlugin,
|
|
225
|
+
negate: propertyNegate,
|
|
226
|
+
compareValue: transformValue(value[propertyFilter], transformValueCallable),
|
|
227
|
+
transformValue: transformValueCallable
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const filterPlugin = getFilterPlugin({
|
|
235
|
+
plugins: filterPlugins,
|
|
236
|
+
operation
|
|
237
|
+
});
|
|
238
|
+
filters.push({
|
|
131
239
|
fieldId,
|
|
132
|
-
path:
|
|
240
|
+
path: createValuePath({
|
|
241
|
+
field: field.def,
|
|
242
|
+
plugins: valuePathPlugins
|
|
243
|
+
}),
|
|
133
244
|
filterPlugin,
|
|
134
245
|
negate,
|
|
135
|
-
compareValue: transformValue(
|
|
246
|
+
compareValue: transformValue(value, transformValueCallable),
|
|
136
247
|
transformValue: transformValueCallable
|
|
137
|
-
};
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return filters;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* In case filter field is not multiple values one, return exact path.
|
|
255
|
+
* If is multiple values field, use path without the last part
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
const getFilterValuePath = filter => {
|
|
260
|
+
if (filter.path.includes(".%s.") === false) {
|
|
261
|
+
return filter.path;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const paths = filter.path.split(".%s.");
|
|
265
|
+
return paths.shift();
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const getFilterValuePropertyPath = filter => {
|
|
269
|
+
if (filter.path.includes(".%s.") === false) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const paths = filter.path.split(".%s.");
|
|
274
|
+
return paths.pop() || null;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const execFilter = params => {
|
|
278
|
+
const {
|
|
279
|
+
value: plainValue,
|
|
280
|
+
filter
|
|
281
|
+
} = params;
|
|
282
|
+
const value = transformValue(plainValue, filter.transformValue);
|
|
283
|
+
const matched = filter.filterPlugin.matches({
|
|
284
|
+
value,
|
|
285
|
+
compareValue: filter.compareValue
|
|
138
286
|
});
|
|
287
|
+
|
|
288
|
+
if (filter.negate) {
|
|
289
|
+
return matched === false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return matched;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
297
|
+
*/
|
|
298
|
+
const createFullTextSearch = ({
|
|
299
|
+
term,
|
|
300
|
+
fields: targetFields,
|
|
301
|
+
plugin
|
|
302
|
+
}) => {
|
|
303
|
+
if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return async ({
|
|
308
|
+
item,
|
|
309
|
+
fromStorage,
|
|
310
|
+
fields
|
|
311
|
+
}) => {
|
|
312
|
+
for (const targetField of targetFields) {
|
|
313
|
+
const field = Object.values(fields).find(field => {
|
|
314
|
+
return field.def.fieldId === targetField;
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
if (!field) {
|
|
318
|
+
throw new _error.default(`Unknown field "${targetField}" in the model.`, "UNKNOWN_FIELD", {
|
|
319
|
+
target: targetField
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const value = await fromStorage(field.def, item.values[targetField]);
|
|
324
|
+
|
|
325
|
+
if (!value) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (plugin.matches({
|
|
330
|
+
value,
|
|
331
|
+
compareValue: term
|
|
332
|
+
}) === true) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return false;
|
|
338
|
+
};
|
|
139
339
|
};
|
|
140
340
|
|
|
141
341
|
const filterItems = async params => {
|
|
142
342
|
const {
|
|
143
|
-
items,
|
|
343
|
+
items: records,
|
|
144
344
|
where,
|
|
145
345
|
plugins,
|
|
146
346
|
fields,
|
|
147
|
-
fromStorage
|
|
347
|
+
fromStorage,
|
|
348
|
+
fullTextSearch
|
|
148
349
|
} = params;
|
|
149
350
|
const filters = createFilters({
|
|
150
351
|
plugins,
|
|
151
352
|
where,
|
|
152
353
|
fields
|
|
153
354
|
});
|
|
154
|
-
const
|
|
355
|
+
const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
|
|
155
356
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const item = items[key];
|
|
162
|
-
let passed = true;
|
|
357
|
+
if (!fullTextSearchPlugin) {
|
|
358
|
+
throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
359
|
+
}
|
|
163
360
|
|
|
361
|
+
const search = createFullTextSearch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fullTextSearch), {}, {
|
|
362
|
+
plugin: fullTextSearchPlugin
|
|
363
|
+
}));
|
|
364
|
+
const promises = records.map(async record => {
|
|
365
|
+
/**
|
|
366
|
+
* We need to go through all the filters and apply them to the given record.
|
|
367
|
+
*/
|
|
164
368
|
for (const filter of filters) {
|
|
165
|
-
|
|
369
|
+
/**
|
|
370
|
+
* In case is multiple values field, last part is removed from path.
|
|
371
|
+
* -> values.categories.id -> values.categories
|
|
372
|
+
*/
|
|
373
|
+
const valuePath = getFilterValuePath(filter);
|
|
374
|
+
|
|
375
|
+
const rawValue = _dotProp.default.get(record, valuePath);
|
|
376
|
+
|
|
377
|
+
if (valuePath !== filter.path) {
|
|
378
|
+
/**
|
|
379
|
+
* Calculated is different than original because we need to search in the array of objects.
|
|
380
|
+
*/
|
|
381
|
+
const propertyPath = getFilterValuePropertyPath(filter);
|
|
382
|
+
|
|
383
|
+
if (!propertyPath) {
|
|
384
|
+
console.log(`Cannot determine the property path of "${filter.path}".`);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const plainValue = await fromStorage(fields[filter.fieldId].def, rawValue);
|
|
389
|
+
/**
|
|
390
|
+
* We cannot go through the value because it is not array. Log the error and continue.
|
|
391
|
+
*/
|
|
392
|
+
|
|
393
|
+
if (Array.isArray(plainValue) === false) {
|
|
394
|
+
console.log(`Cannot go through the value on ${valuePath} because it is not an array, and we expect it to be.`);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
record = _dotProp.default.set(record, valuePath, plainValue);
|
|
399
|
+
const values = plainValue.map(value => {
|
|
400
|
+
return value[propertyPath];
|
|
401
|
+
});
|
|
402
|
+
const result = execFilter({
|
|
403
|
+
value: values,
|
|
404
|
+
filter
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
if (!result) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
166
413
|
|
|
167
414
|
const plainValue = await fromStorage(fields[filter.fieldId].def, rawValue);
|
|
168
415
|
/**
|
|
@@ -170,46 +417,49 @@ const filterItems = async params => {
|
|
|
170
417
|
*/
|
|
171
418
|
|
|
172
419
|
if (plainValue !== rawValue) {
|
|
173
|
-
|
|
420
|
+
record = _dotProp.default.set(record, filter.path, plainValue);
|
|
174
421
|
}
|
|
175
422
|
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
compareValue: filter.compareValue
|
|
423
|
+
const result = execFilter({
|
|
424
|
+
value: plainValue,
|
|
425
|
+
filter
|
|
180
426
|
});
|
|
181
427
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
break;
|
|
428
|
+
if (result === false) {
|
|
429
|
+
return null;
|
|
185
430
|
}
|
|
186
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* If we have full text search defined, run it. Otherwise just return the given record.
|
|
434
|
+
*/
|
|
187
435
|
|
|
188
|
-
|
|
189
|
-
|
|
436
|
+
|
|
437
|
+
if (!search) {
|
|
438
|
+
return record;
|
|
190
439
|
}
|
|
191
440
|
|
|
192
|
-
|
|
193
|
-
|
|
441
|
+
const result = await search({
|
|
442
|
+
item: record,
|
|
443
|
+
fromStorage,
|
|
444
|
+
fields
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
if (!result) {
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return record;
|
|
452
|
+
});
|
|
453
|
+
/**
|
|
454
|
+
* We run filtering as promises so it is a bit faster than in for ... of loop.
|
|
455
|
+
*/
|
|
194
456
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
//
|
|
202
|
-
// const value = transformValue(plainValue, filter.transformValue);
|
|
203
|
-
// const matched = filter.filterPlugin.matches({
|
|
204
|
-
// value,
|
|
205
|
-
// compareValue: filter.compareValue
|
|
206
|
-
// });
|
|
207
|
-
// if ((filter.negate ? !matched : matched) === false) {
|
|
208
|
-
// return false;
|
|
209
|
-
// }
|
|
210
|
-
// }
|
|
211
|
-
// return true;
|
|
212
|
-
// });
|
|
457
|
+
const results = await Promise.all(promises);
|
|
458
|
+
/**
|
|
459
|
+
* And filter out the null values which are returned when filter is not satisfied.
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
return results.filter(Boolean);
|
|
213
463
|
};
|
|
214
464
|
|
|
215
465
|
exports.filterItems = filterItems;
|
|
@@ -218,13 +468,15 @@ const extractSort = (sortBy, fields) => {
|
|
|
218
468
|
const result = sortBy.split("_");
|
|
219
469
|
|
|
220
470
|
if (result.length !== 2) {
|
|
221
|
-
throw new _error.default("Problem in determining the sorting for the entry items.", "
|
|
471
|
+
throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
222
472
|
sortBy
|
|
223
473
|
});
|
|
224
474
|
}
|
|
225
475
|
|
|
226
476
|
const [fieldId, order] = result;
|
|
227
|
-
const modelField = fields
|
|
477
|
+
const modelField = Object.values(fields).find(field => {
|
|
478
|
+
return field.def.fieldId === fieldId;
|
|
479
|
+
});
|
|
228
480
|
|
|
229
481
|
if (!modelField) {
|
|
230
482
|
throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
@@ -233,8 +485,11 @@ const extractSort = (sortBy, fields) => {
|
|
|
233
485
|
});
|
|
234
486
|
}
|
|
235
487
|
|
|
236
|
-
const valuePath = modelField.
|
|
488
|
+
const valuePath = modelField.createPath({
|
|
489
|
+
field: modelField.def
|
|
490
|
+
});
|
|
237
491
|
return {
|
|
492
|
+
field: modelField,
|
|
238
493
|
fieldId,
|
|
239
494
|
valuePath,
|
|
240
495
|
reverse: order === "DESC"
|
|
@@ -253,7 +508,7 @@ const sortEntryItems = params => {
|
|
|
253
508
|
} else if (sort.length === 0) {
|
|
254
509
|
sort.push("savedOn_DESC");
|
|
255
510
|
} else if (sort.length > 1) {
|
|
256
|
-
throw new _error.default("Sorting is limited to a single field.", "
|
|
511
|
+
throw new _error.default("Sorting is limited to a single field.", "SORT_MULTIPLE_FIELDS_ERROR", {
|
|
257
512
|
sort: sort
|
|
258
513
|
});
|
|
259
514
|
}
|
|
@@ -261,24 +516,24 @@ const sortEntryItems = params => {
|
|
|
261
516
|
const [firstSort] = sort;
|
|
262
517
|
|
|
263
518
|
if (!firstSort) {
|
|
264
|
-
throw new _error.default("Empty sort array item.", "
|
|
519
|
+
throw new _error.default("Empty sort array item.", "SORT_EMPTY_ERROR", {
|
|
265
520
|
sort
|
|
266
521
|
});
|
|
267
522
|
}
|
|
268
523
|
|
|
269
524
|
const {
|
|
270
525
|
fieldId,
|
|
526
|
+
field,
|
|
271
527
|
valuePath,
|
|
272
528
|
reverse
|
|
273
529
|
} = extractSort(firstSort, fields);
|
|
274
|
-
const field = fields[fieldId];
|
|
275
530
|
const itemsToSort = items.map(item => {
|
|
276
531
|
return {
|
|
277
532
|
id: item.id,
|
|
278
533
|
value: field.valueTransformer(_dotProp.default.get(item, valuePath))
|
|
279
534
|
};
|
|
280
535
|
});
|
|
281
|
-
const sortedItems = (0,
|
|
536
|
+
const sortedItems = (0, _sortBy.default)(itemsToSort, "value");
|
|
282
537
|
const newItems = sortedItems.map(s => {
|
|
283
538
|
const item = items.find(i => i.id === s.id);
|
|
284
539
|
|
|
@@ -342,18 +597,30 @@ const buildModelFields = ({
|
|
|
342
597
|
});
|
|
343
598
|
const valuePathPlugins = getMappedPlugins({
|
|
344
599
|
plugins,
|
|
345
|
-
type:
|
|
600
|
+
type: _CmsEntryFieldFilterPathPlugin.CmsEntryFieldFilterPathPlugin.type,
|
|
346
601
|
property: "fieldType"
|
|
347
602
|
});
|
|
348
603
|
const fields = Object.values(_systemFields.systemFields).reduce((collection, field) => {
|
|
604
|
+
/**
|
|
605
|
+
* This should be caught on the tests runs and never actually happen on live system.
|
|
606
|
+
*/
|
|
607
|
+
if (!field.fieldId) {
|
|
608
|
+
throw new _error.default("Missing system field `fieldId`.", "FIELD_ID_ERROR", {
|
|
609
|
+
field
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
|
|
349
613
|
const transformValuePlugin = transformValuePlugins[field.type];
|
|
350
614
|
const valuePathPlugin = valuePathPlugins[field.type];
|
|
351
|
-
|
|
615
|
+
|
|
616
|
+
let createPath = params => {
|
|
617
|
+
return params.field.fieldId;
|
|
618
|
+
};
|
|
352
619
|
|
|
353
620
|
if (valuePathPlugin) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
621
|
+
createPath = params => {
|
|
622
|
+
return valuePathPlugin.createPath(params);
|
|
623
|
+
};
|
|
357
624
|
}
|
|
358
625
|
|
|
359
626
|
collection[field.fieldId] = {
|
|
@@ -368,23 +635,30 @@ const buildModelFields = ({
|
|
|
368
635
|
value
|
|
369
636
|
});
|
|
370
637
|
},
|
|
371
|
-
|
|
638
|
+
createPath,
|
|
372
639
|
isSystemField: true
|
|
373
640
|
};
|
|
374
641
|
return collection;
|
|
375
642
|
}, {});
|
|
376
643
|
return model.fields.reduce((collection, field) => {
|
|
644
|
+
if (!field.fieldId) {
|
|
645
|
+
console.log(`Field "${field.storageId}" in model "${model.modelId}" is missing fieldId.`);
|
|
646
|
+
return collection;
|
|
647
|
+
}
|
|
648
|
+
|
|
377
649
|
const transformValuePlugin = transformValuePlugins[field.type];
|
|
378
650
|
const valuePathPlugin = valuePathPlugins[field.type];
|
|
379
|
-
|
|
651
|
+
|
|
652
|
+
let createPath = params => {
|
|
653
|
+
return `${VALUES_ATTRIBUTE}.${params.field.fieldId}`;
|
|
654
|
+
};
|
|
380
655
|
|
|
381
656
|
if (valuePathPlugin) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
657
|
+
createPath = params => {
|
|
658
|
+
return valuePathPlugin.createPath(params);
|
|
659
|
+
};
|
|
385
660
|
}
|
|
386
661
|
|
|
387
|
-
const targetValuePath = `${VALUES_ATTRIBUTE}.${valuePath || field.fieldId}`;
|
|
388
662
|
collection[field.fieldId] = {
|
|
389
663
|
def: field,
|
|
390
664
|
valueTransformer: value => {
|
|
@@ -397,7 +671,7 @@ const buildModelFields = ({
|
|
|
397
671
|
value
|
|
398
672
|
});
|
|
399
673
|
},
|
|
400
|
-
|
|
674
|
+
createPath
|
|
401
675
|
};
|
|
402
676
|
return collection;
|
|
403
677
|
}, fields);
|