@webiny/api-headless-cms-ddb 0.0.0-unstable.5e7233243f → 0.0.0-unstable.60a863e033

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