@webiny/api-headless-cms-ddb 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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/README.md +6 -20
- package/definitions/entry.d.ts +4 -5
- package/definitions/entry.js +9 -94
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -5
- package/definitions/group.js +9 -68
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -5
- package/definitions/model.js +9 -90
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +4 -6
- package/definitions/table.js +8 -30
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +65 -0
- package/definitions/types.js +0 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +11 -20
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +2 -0
- package/dynamoDb/path/locationFolderId.js +21 -0
- package/dynamoDb/path/locationFolderId.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +13 -37
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +27 -50
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +83 -139
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +16 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +27 -0
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
- package/operations/entry/dataLoader/constants.d.ts +1 -0
- package/operations/entry/dataLoader/constants.js +5 -0
- package/operations/entry/dataLoader/constants.js.map +1 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js +10 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js +24 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +40 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +40 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
- package/operations/entry/dataLoader/getRevisionById.js +42 -0
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
- package/operations/entry/dataLoader/index.d.ts +8 -0
- package/operations/entry/dataLoader/index.js +18 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +6 -0
- package/operations/entry/dataLoader/types.js +0 -0
- package/operations/entry/dataLoaders.d.ts +14 -30
- package/operations/entry/dataLoaders.js +83 -314
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +27 -0
- package/operations/entry/filtering/createExpressions.js +124 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +16 -0
- package/operations/entry/filtering/createFields.js +93 -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 +60 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +16 -0
- package/operations/entry/filtering/filter.js +85 -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 +25 -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 +37 -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 +2 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +18 -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 +33 -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 +68 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +63 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +49 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +12 -0
- package/operations/entry/filtering/sort.js +41 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +2 -0
- package/operations/entry/filtering/systemFields.js +149 -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 +7 -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 +0 -0
- package/operations/entry/filtering/values.d.ts +2 -0
- package/operations/entry/filtering/values.js +15 -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 +22 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.d.ts +5 -4
- package/operations/entry/index.js +931 -845
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +46 -2
- package/operations/entry/keys.js +53 -66
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +4 -5
- package/operations/group/index.js +116 -187
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +102 -158
- package/operations/model/index.js.map +1 -1
- package/package.json +34 -33
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +5 -4
- package/plugins/CmsEntryFieldFilterPathPlugin.js +25 -50
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +4 -1
- package/plugins/index.js +4 -18
- package/types.d.ts +28 -21
- package/types.js +8 -15
- package/types.js.map +1 -1
- package/definitions/settings.d.ts +0 -9
- package/definitions/settings.js +0 -58
- package/definitions/settings.js.map +0 -1
- package/definitions/system.d.ts +0 -9
- package/definitions/system.js +0 -46
- package/definitions/system.js.map +0 -1
- package/dynamoDb/storage/date.d.ts +0 -2
- package/dynamoDb/storage/date.js +0 -99
- package/dynamoDb/storage/date.js.map +0 -1
- package/dynamoDb/storage/longText.d.ts +0 -10
- package/dynamoDb/storage/longText.js +0 -101
- package/dynamoDb/storage/longText.js.map +0 -1
- package/dynamoDb/storage/richText.d.ts +0 -2
- package/dynamoDb/storage/richText.js +0 -113
- package/dynamoDb/storage/richText.js.map +0 -1
- package/operations/entry/systemFields.d.ts +0 -2
- package/operations/entry/systemFields.js +0 -74
- package/operations/entry/systemFields.js.map +0 -1
- package/operations/entry/utils.d.ts +0 -36
- package/operations/entry/utils.js +0 -680
- package/operations/entry/utils.js.map +0 -1
- package/operations/settings/index.d.ts +0 -7
- package/operations/settings/index.js +0 -135
- package/operations/settings/index.js.map +0 -1
- package/operations/system/index.d.ts +0 -7
- package/operations/system/index.js +0 -99
- package/operations/system/index.js.map +0 -1
- package/plugins/index.js.map +0 -1
|
@@ -1,680 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.sortEntryItems = exports.filterItems = exports.buildModelFields = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
|
-
var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
|
|
15
|
-
|
|
16
|
-
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
17
|
-
|
|
18
|
-
var _systemFields = require("./systemFields");
|
|
19
|
-
|
|
20
|
-
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
21
|
-
|
|
22
|
-
var _CmsEntryFieldFilterPathPlugin = require("../../plugins/CmsEntryFieldFilterPathPlugin");
|
|
23
|
-
|
|
24
|
-
const VALUES_ATTRIBUTE = "values";
|
|
25
|
-
|
|
26
|
-
const extractWhereParams = key => {
|
|
27
|
-
const result = key.split("_");
|
|
28
|
-
const fieldId = result.shift();
|
|
29
|
-
|
|
30
|
-
if (!fieldId) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const rawOp = result.length === 0 ? "eq" : result.join("_");
|
|
35
|
-
/**
|
|
36
|
-
* When rawOp is not, it means it is equal negated so just return that.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
if (rawOp === "not") {
|
|
40
|
-
return {
|
|
41
|
-
fieldId,
|
|
42
|
-
operation: "eq",
|
|
43
|
-
negate: true
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const negate = rawOp.match("not_") !== null;
|
|
48
|
-
const operation = rawOp.replace("not_", "");
|
|
49
|
-
return {
|
|
50
|
-
fieldId,
|
|
51
|
-
operation,
|
|
52
|
-
negate
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const transformValue = (value, transform) => {
|
|
57
|
-
if (Array.isArray(value)) {
|
|
58
|
-
return value.map(v => transform(v));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return transform(value);
|
|
62
|
-
};
|
|
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
|
-
|
|
121
|
-
const createFilters = params => {
|
|
122
|
-
const {
|
|
123
|
-
where,
|
|
124
|
-
plugins,
|
|
125
|
-
fields
|
|
126
|
-
} = params;
|
|
127
|
-
const filterPlugins = getMappedPlugins({
|
|
128
|
-
plugins,
|
|
129
|
-
type: _ValueFilterPlugin.ValueFilterPlugin.type,
|
|
130
|
-
property: "operation"
|
|
131
|
-
});
|
|
132
|
-
const transformValuePlugins = getMappedPlugins({
|
|
133
|
-
plugins,
|
|
134
|
-
type: "cms-field-filter-value-transform",
|
|
135
|
-
property: "fieldType"
|
|
136
|
-
});
|
|
137
|
-
const valuePathPlugins = getMappedPlugins({
|
|
138
|
-
plugins,
|
|
139
|
-
type: _CmsEntryFieldFilterPathPlugin.CmsEntryFieldFilterPathPlugin.type,
|
|
140
|
-
property: "fieldType"
|
|
141
|
-
});
|
|
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
|
-
|
|
161
|
-
const {
|
|
162
|
-
fieldId,
|
|
163
|
-
operation,
|
|
164
|
-
negate
|
|
165
|
-
} = whereParams;
|
|
166
|
-
const field = fields[fieldId];
|
|
167
|
-
|
|
168
|
-
if (!field) {
|
|
169
|
-
throw new _error.default(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
170
|
-
fieldId
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const transformValuePlugin = transformValuePlugins[field.def.type];
|
|
175
|
-
|
|
176
|
-
const transformValueCallable = value => {
|
|
177
|
-
if (!transformValuePlugin) {
|
|
178
|
-
return value;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return transformValuePlugin.transform({
|
|
182
|
-
field: field.def,
|
|
183
|
-
value
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
|
|
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({
|
|
239
|
-
fieldId,
|
|
240
|
-
path: createValuePath({
|
|
241
|
-
field: field.def,
|
|
242
|
-
plugins: valuePathPlugins
|
|
243
|
-
}),
|
|
244
|
-
filterPlugin,
|
|
245
|
-
negate,
|
|
246
|
-
compareValue: transformValue(value, transformValueCallable),
|
|
247
|
-
transformValue: transformValueCallable
|
|
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
|
|
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
|
-
};
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const filterItems = async params => {
|
|
342
|
-
const {
|
|
343
|
-
items: records,
|
|
344
|
-
where,
|
|
345
|
-
plugins,
|
|
346
|
-
fields,
|
|
347
|
-
fromStorage,
|
|
348
|
-
fullTextSearch
|
|
349
|
-
} = params;
|
|
350
|
-
const filters = createFilters({
|
|
351
|
-
plugins,
|
|
352
|
-
where,
|
|
353
|
-
fields
|
|
354
|
-
});
|
|
355
|
-
const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
|
|
356
|
-
|
|
357
|
-
if (!fullTextSearchPlugin) {
|
|
358
|
-
throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
359
|
-
}
|
|
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
|
-
*/
|
|
368
|
-
for (const filter of filters) {
|
|
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
|
-
}
|
|
413
|
-
|
|
414
|
-
const plainValue = await fromStorage(fields[filter.fieldId].def, rawValue);
|
|
415
|
-
/**
|
|
416
|
-
* If raw value is not same as the value after the storage transform, set the value to the items being filtered.
|
|
417
|
-
*/
|
|
418
|
-
|
|
419
|
-
if (plainValue !== rawValue) {
|
|
420
|
-
record = _dotProp.default.set(record, filter.path, plainValue);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
const result = execFilter({
|
|
424
|
-
value: plainValue,
|
|
425
|
-
filter
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
if (result === false) {
|
|
429
|
-
return null;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* If we have full text search defined, run it. Otherwise just return the given record.
|
|
434
|
-
*/
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
if (!search) {
|
|
438
|
-
return record;
|
|
439
|
-
}
|
|
440
|
-
|
|
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
|
-
*/
|
|
456
|
-
|
|
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);
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
exports.filterItems = filterItems;
|
|
466
|
-
|
|
467
|
-
const extractSort = (sortBy, fields) => {
|
|
468
|
-
const result = sortBy.split("_");
|
|
469
|
-
|
|
470
|
-
if (result.length !== 2) {
|
|
471
|
-
throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
472
|
-
sortBy
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
const [fieldId, order] = result;
|
|
477
|
-
const modelField = Object.values(fields).find(field => {
|
|
478
|
-
return field.def.fieldId === fieldId;
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
if (!modelField) {
|
|
482
|
-
throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
483
|
-
fieldId,
|
|
484
|
-
fields
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
const valuePath = modelField.createPath({
|
|
489
|
-
field: modelField.def
|
|
490
|
-
});
|
|
491
|
-
return {
|
|
492
|
-
field: modelField,
|
|
493
|
-
fieldId,
|
|
494
|
-
valuePath,
|
|
495
|
-
reverse: order === "DESC"
|
|
496
|
-
};
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
const sortEntryItems = params => {
|
|
500
|
-
const {
|
|
501
|
-
items,
|
|
502
|
-
sort = [],
|
|
503
|
-
fields
|
|
504
|
-
} = params;
|
|
505
|
-
|
|
506
|
-
if (items.length <= 1) {
|
|
507
|
-
return items;
|
|
508
|
-
} else if (sort.length === 0) {
|
|
509
|
-
sort.push("savedOn_DESC");
|
|
510
|
-
} else if (sort.length > 1) {
|
|
511
|
-
throw new _error.default("Sorting is limited to a single field.", "SORT_MULTIPLE_FIELDS_ERROR", {
|
|
512
|
-
sort: sort
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
const [firstSort] = sort;
|
|
517
|
-
|
|
518
|
-
if (!firstSort) {
|
|
519
|
-
throw new _error.default("Empty sort array item.", "SORT_EMPTY_ERROR", {
|
|
520
|
-
sort
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
const {
|
|
525
|
-
fieldId,
|
|
526
|
-
field,
|
|
527
|
-
valuePath,
|
|
528
|
-
reverse
|
|
529
|
-
} = extractSort(firstSort, fields);
|
|
530
|
-
const itemsToSort = items.map(item => {
|
|
531
|
-
return {
|
|
532
|
-
id: item.id,
|
|
533
|
-
value: field.valueTransformer(_dotProp.default.get(item, valuePath))
|
|
534
|
-
};
|
|
535
|
-
});
|
|
536
|
-
const sortedItems = (0, _sortBy.default)(itemsToSort, "value");
|
|
537
|
-
const newItems = sortedItems.map(s => {
|
|
538
|
-
const item = items.find(i => i.id === s.id);
|
|
539
|
-
|
|
540
|
-
if (item) {
|
|
541
|
-
return item;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
throw new _error.default("Could not find item by given id after the sorting.", "SORTING_ITEMS_ERROR", {
|
|
545
|
-
id: s.id,
|
|
546
|
-
sortingBy: fieldId,
|
|
547
|
-
reverse
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
if (!reverse) {
|
|
552
|
-
return newItems;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
return newItems.reverse();
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
exports.sortEntryItems = sortEntryItems;
|
|
559
|
-
|
|
560
|
-
const getMappedPlugins = params => {
|
|
561
|
-
const {
|
|
562
|
-
plugins: pluginsContainer,
|
|
563
|
-
type,
|
|
564
|
-
property
|
|
565
|
-
} = params;
|
|
566
|
-
const plugins = pluginsContainer.byType(type);
|
|
567
|
-
|
|
568
|
-
if (plugins.length === 0) {
|
|
569
|
-
throw new _error.default(`There are no plugins of type "${type}".`, "PLUGINS_ERROR", {
|
|
570
|
-
type
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
return plugins.reduce((collection, plugin) => {
|
|
575
|
-
const key = plugin[property];
|
|
576
|
-
|
|
577
|
-
if (typeof key !== "string") {
|
|
578
|
-
throw new _error.default("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
|
|
579
|
-
type,
|
|
580
|
-
property
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
collection[key] = plugin;
|
|
585
|
-
return collection;
|
|
586
|
-
}, {});
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
const buildModelFields = ({
|
|
590
|
-
plugins,
|
|
591
|
-
model
|
|
592
|
-
}) => {
|
|
593
|
-
const transformValuePlugins = getMappedPlugins({
|
|
594
|
-
plugins,
|
|
595
|
-
type: "cms-field-filter-value-transform",
|
|
596
|
-
property: "fieldType"
|
|
597
|
-
});
|
|
598
|
-
const valuePathPlugins = getMappedPlugins({
|
|
599
|
-
plugins,
|
|
600
|
-
type: _CmsEntryFieldFilterPathPlugin.CmsEntryFieldFilterPathPlugin.type,
|
|
601
|
-
property: "fieldType"
|
|
602
|
-
});
|
|
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
|
-
|
|
613
|
-
const transformValuePlugin = transformValuePlugins[field.type];
|
|
614
|
-
const valuePathPlugin = valuePathPlugins[field.type];
|
|
615
|
-
|
|
616
|
-
let createPath = params => {
|
|
617
|
-
return params.field.fieldId;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
if (valuePathPlugin) {
|
|
621
|
-
createPath = params => {
|
|
622
|
-
return valuePathPlugin.createPath(params);
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
collection[field.fieldId] = {
|
|
627
|
-
def: field,
|
|
628
|
-
valueTransformer: value => {
|
|
629
|
-
if (!transformValuePlugin) {
|
|
630
|
-
return value;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
return transformValuePlugin.transform({
|
|
634
|
-
field,
|
|
635
|
-
value
|
|
636
|
-
});
|
|
637
|
-
},
|
|
638
|
-
createPath,
|
|
639
|
-
isSystemField: true
|
|
640
|
-
};
|
|
641
|
-
return collection;
|
|
642
|
-
}, {});
|
|
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
|
-
|
|
649
|
-
const transformValuePlugin = transformValuePlugins[field.type];
|
|
650
|
-
const valuePathPlugin = valuePathPlugins[field.type];
|
|
651
|
-
|
|
652
|
-
let createPath = params => {
|
|
653
|
-
return `${VALUES_ATTRIBUTE}.${params.field.fieldId}`;
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
if (valuePathPlugin) {
|
|
657
|
-
createPath = params => {
|
|
658
|
-
return valuePathPlugin.createPath(params);
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
collection[field.fieldId] = {
|
|
663
|
-
def: field,
|
|
664
|
-
valueTransformer: value => {
|
|
665
|
-
if (!transformValuePlugin) {
|
|
666
|
-
return value;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
return transformValuePlugin.transform({
|
|
670
|
-
field,
|
|
671
|
-
value
|
|
672
|
-
});
|
|
673
|
-
},
|
|
674
|
-
createPath
|
|
675
|
-
};
|
|
676
|
-
return collection;
|
|
677
|
-
}, fields);
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
exports.buildModelFields = buildModelFields;
|