@webiny/api-headless-cms-ddb 0.0.0-unstable.615a930a68 → 0.0.0-unstable.61c048f412
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 +6 -89
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -5
- package/definitions/group.js +6 -63
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -5
- package/definitions/model.js +6 -85
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +4 -6
- package/definitions/table.js +7 -28
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +59 -0
- package/definitions/types.js +3 -0
- package/definitions/types.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +8 -20
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +2 -0
- package/dynamoDb/path/locationFolderId.js +34 -0
- package/dynamoDb/path/locationFolderId.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +6 -20
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +19 -34
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js +27 -88
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +7 -19
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +47 -105
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +15 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +34 -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 +4 -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 +19 -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 +32 -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 +46 -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 +46 -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 +52 -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 +19 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +5 -0
- package/operations/entry/dataLoader/types.js +3 -0
- package/operations/entry/dataLoader/types.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +14 -30
- package/operations/entry/dataLoaders.js +56 -271
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +26 -0
- package/operations/entry/filtering/createExpressions.js +175 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +7 -9
- package/operations/entry/filtering/createFields.js +87 -105
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +8 -4
- package/operations/entry/filtering/extractSort.js +60 -31
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +6 -7
- package/operations/entry/filtering/filter.js +102 -89
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +4 -8
- package/operations/entry/filtering/fullTextSearch.js +8 -30
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +5 -27
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.d.ts +2 -2
- package/operations/entry/filtering/index.js +3 -20
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +2 -2
- package/operations/entry/filtering/mapPlugins.js +4 -18
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +9 -20
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +7 -16
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/objectFilterCreate.js +16 -39
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -2
- package/operations/entry/filtering/plugins/refFilterCreate.js +21 -36
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +8 -5
- package/operations/entry/filtering/sort.js +23 -36
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -4
- package/operations/entry/filtering/systemFields.js +87 -43
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js +2 -10
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +2 -2
- package/operations/entry/filtering/types.js +2 -4
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +2 -0
- package/operations/entry/filtering/values.js +16 -0
- package/operations/entry/filtering/values.js.map +1 -0
- package/operations/entry/filtering/where.js +5 -15
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +3 -4
- package/operations/entry/index.js +751 -414
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +40 -2
- package/operations/entry/keys.js +54 -47
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +4 -4
- package/operations/group/index.js +44 -91
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +36 -70
- package/operations/model/index.js.map +1 -1
- package/package.json +22 -29
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
- package/plugins/CmsEntryFieldFilterPathPlugin.js +14 -29
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
- package/plugins/CmsEntryFieldFilterPlugin.js +9 -19
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +42 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +19 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +11 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +16 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +4 -1
- package/plugins/index.js +5 -17
- package/plugins/index.js.map +1 -1
- package/types.d.ts +24 -19
- package/types.js +5 -13
- 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 -109
- package/dynamoDb/storage/date.js.map +0 -1
- package/operations/entry/filtering/createFilters.d.ts +0 -20
- package/operations/entry/filtering/createFilters.js +0 -155
- package/operations/entry/filtering/createFilters.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 -684
- 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
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
3
|
+
import { getMappedPlugins } from "./mapPlugins.js";
|
|
4
|
+
import { extractWhereParams } from "./where.js";
|
|
5
|
+
import { transformValue } from "./transform.js";
|
|
6
|
+
import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
7
|
+
import { getWhereValues } from "./values.js";
|
|
8
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
9
|
+
export const createExpressions = params => {
|
|
10
|
+
const {
|
|
11
|
+
where,
|
|
12
|
+
plugins,
|
|
13
|
+
fields
|
|
14
|
+
} = params;
|
|
15
|
+
const filterPlugins = getMappedPlugins({
|
|
16
|
+
plugins,
|
|
17
|
+
type: ValueFilterPlugin.type,
|
|
18
|
+
property: "operation"
|
|
19
|
+
});
|
|
20
|
+
const transformValuePlugins = getMappedPlugins({
|
|
21
|
+
plugins,
|
|
22
|
+
type: "cms-field-filter-value-transform",
|
|
23
|
+
property: "fieldType"
|
|
24
|
+
});
|
|
25
|
+
const fieldFilterCreatePlugins = getMappedPlugins({
|
|
26
|
+
plugins,
|
|
27
|
+
type: CmsEntryFieldFilterPlugin.type,
|
|
28
|
+
property: "fieldType"
|
|
29
|
+
});
|
|
30
|
+
const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
|
|
31
|
+
const getFilterCreatePlugin = type => {
|
|
32
|
+
const fieldType = getBaseFieldType({
|
|
33
|
+
type
|
|
34
|
+
});
|
|
35
|
+
const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
|
|
36
|
+
if (filterCreatePlugin) {
|
|
37
|
+
return filterCreatePlugin;
|
|
38
|
+
}
|
|
39
|
+
throw new WebinyError(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
|
|
40
|
+
fieldType
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const createExpression = ({
|
|
44
|
+
where,
|
|
45
|
+
condition
|
|
46
|
+
}) => {
|
|
47
|
+
const expression = {
|
|
48
|
+
filters: [],
|
|
49
|
+
expressions: [],
|
|
50
|
+
condition
|
|
51
|
+
};
|
|
52
|
+
for (const key in where) {
|
|
53
|
+
const value = where[key];
|
|
54
|
+
if (value === undefined) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* If there are "AND" or "OR" keys, let's sort them out first.
|
|
60
|
+
*
|
|
61
|
+
*
|
|
62
|
+
* AND conditional
|
|
63
|
+
*/
|
|
64
|
+
if (key === "AND") {
|
|
65
|
+
const childWhereList = getWhereValues(value, key);
|
|
66
|
+
const childExpression = {
|
|
67
|
+
condition: "AND",
|
|
68
|
+
filters: [],
|
|
69
|
+
expressions: []
|
|
70
|
+
};
|
|
71
|
+
for (const childWhere of childWhereList) {
|
|
72
|
+
const result = createExpression({
|
|
73
|
+
where: childWhere,
|
|
74
|
+
condition: "AND"
|
|
75
|
+
});
|
|
76
|
+
childExpression.expressions.push(result);
|
|
77
|
+
}
|
|
78
|
+
expression.expressions.push(childExpression);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* OR conditional
|
|
83
|
+
*/
|
|
84
|
+
if (key === "OR") {
|
|
85
|
+
const childWhereList = getWhereValues(value, key);
|
|
86
|
+
const childExpression = {
|
|
87
|
+
condition: "OR",
|
|
88
|
+
filters: [],
|
|
89
|
+
expressions: []
|
|
90
|
+
};
|
|
91
|
+
for (const childWhere of childWhereList) {
|
|
92
|
+
const result = createExpression({
|
|
93
|
+
where: childWhere,
|
|
94
|
+
condition: "AND"
|
|
95
|
+
});
|
|
96
|
+
childExpression.expressions.push(result);
|
|
97
|
+
}
|
|
98
|
+
expression.expressions.push(childExpression);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const whereParams = extractWhereParams(key);
|
|
102
|
+
if (!whereParams) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const {
|
|
106
|
+
fieldId,
|
|
107
|
+
operation,
|
|
108
|
+
negate
|
|
109
|
+
} = whereParams;
|
|
110
|
+
const field = fields[fieldId];
|
|
111
|
+
if (!field) {
|
|
112
|
+
throw new WebinyError(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
113
|
+
fieldId
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* We need a filter create plugin for this type.
|
|
119
|
+
*/
|
|
120
|
+
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
121
|
+
const fieldType = getBaseFieldType(field);
|
|
122
|
+
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
123
|
+
const transformValueCallable = value => {
|
|
124
|
+
if (!transformValuePlugin) {
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
return transformValuePlugin.transform({
|
|
128
|
+
field,
|
|
129
|
+
value
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const result = filterCreatePlugin.create({
|
|
133
|
+
key,
|
|
134
|
+
value,
|
|
135
|
+
valueFilterPlugins: filterPlugins,
|
|
136
|
+
transformValuePlugins,
|
|
137
|
+
getFilterCreatePlugin,
|
|
138
|
+
operation,
|
|
139
|
+
negate,
|
|
140
|
+
field,
|
|
141
|
+
fields,
|
|
142
|
+
compareValue: transformValue({
|
|
143
|
+
value,
|
|
144
|
+
transform: transformValueCallable
|
|
145
|
+
}),
|
|
146
|
+
transformValue: transformValueCallable
|
|
147
|
+
});
|
|
148
|
+
/**
|
|
149
|
+
* There is a possibility of
|
|
150
|
+
* - no result
|
|
151
|
+
* - result being an array
|
|
152
|
+
* - result being an object
|
|
153
|
+
*/
|
|
154
|
+
if (!result || Array.isArray(result) && result.length === 0) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
expression.filters.push(...(Array.isArray(result) ? result : [result]));
|
|
158
|
+
}
|
|
159
|
+
return expression;
|
|
160
|
+
};
|
|
161
|
+
const expression = createExpression({
|
|
162
|
+
where,
|
|
163
|
+
condition: "AND"
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* If the first expression has no filters and has only one expression, put that expression as main one.
|
|
167
|
+
* This will mostly be used when having an OR condition as the single expression in the root level of the where
|
|
168
|
+
*/
|
|
169
|
+
if (expression.filters.length > 0 || expression.expressions.length !== 1) {
|
|
170
|
+
return expression;
|
|
171
|
+
}
|
|
172
|
+
return expression.expressions[0];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=createExpressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["WebinyError","ValueFilterPlugin","getMappedPlugins","extractWhereParams","transformValue","CmsEntryFieldFilterPlugin","getWhereValues","getBaseFieldType","createExpressions","params","where","plugins","fields","filterPlugins","type","property","transformValuePlugins","fieldFilterCreatePlugins","defaultFilterCreatePlugin","getFilterCreatePlugin","fieldType","filterCreatePlugin","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","childExpression","childWhere","result","push","whereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { extractWhereParams } from \"./where.js\";\nimport { transformValue } from \"./transform.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\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 fieldType = getBaseFieldType({\n type\n });\n const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${fieldType}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n fieldType\n }\n );\n };\n\n const createExpression = ({ where, condition }: CreateExpressionParams): Expression => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\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 fieldType = getBaseFieldType(field);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\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,OAAOA,WAAW,MAAM,eAAe;AAEvC,SAASC,iBAAiB,QAAQ,8DAA8D;AAIhG,SAASC,gBAAgB;AACzB,SAASC,kBAAkB;AAC3B,SAASC,cAAc;AACvB,SAASC,yBAAyB;AAClC,SAASC,cAAc;AACvB,SAASC,gBAAgB,QAAQ,oDAAoD;AA+BrF,OAAO,MAAMC,iBAAiB,GAAIC,MAAc,IAAiB;EAC7D,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC;EAAO,CAAC,GAAGH,MAAM;EACzC,MAAMI,aAAa,GAAGX,gBAAgB,CAAoB;IACtDS,OAAO;IACPG,IAAI,EAAEb,iBAA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B;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Field } from "./types";
|
|
3
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
1
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { Field } from "./types.js";
|
|
3
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
interface Params {
|
|
5
|
-
|
|
5
|
+
fields: CmsModelField[];
|
|
6
6
|
plugins: PluginsContainer;
|
|
7
7
|
}
|
|
8
|
-
interface Fields {
|
|
9
|
-
[key: string]: Field;
|
|
10
|
-
}
|
|
11
8
|
/**
|
|
12
9
|
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
13
10
|
*
|
|
14
11
|
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
15
|
-
* @param params
|
|
16
12
|
*/
|
|
17
|
-
export declare const createFields: (params: Params) =>
|
|
13
|
+
export declare const createFields: (params: Params) => {
|
|
14
|
+
[x: string]: Field;
|
|
15
|
+
};
|
|
18
16
|
export {};
|
|
@@ -1,124 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.createFields = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _systemFields = require("./systemFields");
|
|
13
|
-
|
|
14
|
-
var _plugins = require("../../../plugins");
|
|
15
|
-
|
|
16
|
-
var _mapPlugins = require("./mapPlugins");
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
20
|
-
*
|
|
21
|
-
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
22
|
-
* @param params
|
|
23
|
-
*/
|
|
24
|
-
const createFields = params => {
|
|
1
|
+
import { createSystemFields } from "./systemFields.js";
|
|
2
|
+
import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
|
|
3
|
+
import { getMappedPlugins } from "./mapPlugins.js";
|
|
4
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
5
|
+
const createFieldCollection = params => {
|
|
25
6
|
const {
|
|
26
|
-
|
|
27
|
-
|
|
7
|
+
fields,
|
|
8
|
+
parents,
|
|
9
|
+
transformValuePlugins,
|
|
10
|
+
valuePathPlugins,
|
|
11
|
+
system
|
|
28
12
|
} = params;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
const valuePathPlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
35
|
-
plugins,
|
|
36
|
-
type: _plugins.CmsEntryFieldFilterPathPlugin.type,
|
|
37
|
-
property: "fieldType"
|
|
38
|
-
});
|
|
39
|
-
const collection = (0, _systemFields.createSystemFields)().reduce((fields, field) => {
|
|
40
|
-
const transformPlugin = transformValuePlugins[field.type];
|
|
41
|
-
fields[field.fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
42
|
-
parents: [],
|
|
43
|
-
system: true,
|
|
44
|
-
createPath: ({
|
|
45
|
-
field
|
|
46
|
-
}) => {
|
|
47
|
-
var _field$settings;
|
|
13
|
+
return fields.reduce((collection, field) => {
|
|
14
|
+
const fieldType = getBaseFieldType(field);
|
|
15
|
+
const transformPlugin = transformValuePlugins[fieldType];
|
|
16
|
+
const valuePathPlugin = valuePathPlugins[fieldType];
|
|
48
17
|
|
|
49
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
20
|
+
*/
|
|
21
|
+
const fieldId = [...parents, {
|
|
22
|
+
fieldId: field.fieldId,
|
|
23
|
+
multipleValues: field.multipleValues
|
|
24
|
+
}].map(f => f.fieldId).join(".");
|
|
25
|
+
collection[fieldId] = {
|
|
26
|
+
...field,
|
|
27
|
+
parents,
|
|
28
|
+
system,
|
|
29
|
+
createPath: params => {
|
|
30
|
+
if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map(p => p.fieldId))) {
|
|
31
|
+
return valuePathPlugin.createPath(params);
|
|
32
|
+
}
|
|
33
|
+
return parents.map(parent => parent.fieldId).concat([params.field.fieldId]).join(".");
|
|
50
34
|
},
|
|
51
35
|
transform: value => {
|
|
52
36
|
if (!transformPlugin) {
|
|
53
37
|
return value;
|
|
54
38
|
}
|
|
55
|
-
|
|
56
39
|
return transformPlugin.transform({
|
|
57
40
|
field,
|
|
58
41
|
value
|
|
59
42
|
});
|
|
60
43
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const addFieldsToCollection = (fields, parents = []) => {
|
|
66
|
-
/**
|
|
67
|
-
* Exit early if no fields are sent.
|
|
68
|
-
*/
|
|
69
|
-
if (fields.length === 0) {
|
|
70
|
-
return;
|
|
44
|
+
};
|
|
45
|
+
const childFields = field.settings?.fields;
|
|
46
|
+
if (!childFields?.length) {
|
|
47
|
+
return collection;
|
|
71
48
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const transformPlugin = transformValuePlugins[field.type];
|
|
77
|
-
const valuePathPlugin = valuePathPlugins[field.type];
|
|
78
|
-
/**
|
|
79
|
-
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
const fieldId = [...parents, {
|
|
83
|
-
fieldId: field.fieldId,
|
|
84
|
-
multipleValues: field.multipleValues
|
|
85
|
-
}].map(f => f.fieldId).join(".");
|
|
86
|
-
collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
87
|
-
parents,
|
|
88
|
-
system: false,
|
|
89
|
-
createPath: params => {
|
|
90
|
-
if (valuePathPlugin) {
|
|
91
|
-
return valuePathPlugin.createPath(params);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
|
|
95
|
-
},
|
|
96
|
-
transform: value => {
|
|
97
|
-
if (!transformPlugin) {
|
|
98
|
-
return value;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return transformPlugin.transform({
|
|
102
|
-
field,
|
|
103
|
-
value
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
|
|
108
|
-
|
|
109
|
-
if (!childFields || childFields.length === 0) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
addFieldsToCollection(childFields, [...parents, {
|
|
49
|
+
const result = createFieldCollection({
|
|
50
|
+
fields: childFields,
|
|
51
|
+
parents: [...parents, {
|
|
114
52
|
fieldId: field.fieldId,
|
|
115
53
|
multipleValues: field.multipleValues
|
|
116
|
-
}]
|
|
117
|
-
|
|
54
|
+
}],
|
|
55
|
+
transformValuePlugins,
|
|
56
|
+
valuePathPlugins,
|
|
57
|
+
system
|
|
58
|
+
});
|
|
59
|
+
Object.assign(collection, result);
|
|
60
|
+
return collection;
|
|
61
|
+
}, {});
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
65
|
+
*
|
|
66
|
+
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
67
|
+
*/
|
|
68
|
+
export const createFields = params => {
|
|
69
|
+
const {
|
|
70
|
+
fields,
|
|
71
|
+
plugins
|
|
72
|
+
} = params;
|
|
73
|
+
const transformValuePlugins = getMappedPlugins({
|
|
74
|
+
plugins,
|
|
75
|
+
type: "cms-field-filter-value-transform",
|
|
76
|
+
property: "fieldType"
|
|
77
|
+
});
|
|
78
|
+
const valuePathPlugins = getMappedPlugins({
|
|
79
|
+
plugins,
|
|
80
|
+
type: CmsEntryFieldFilterPathPlugin.type,
|
|
81
|
+
property: "fieldType"
|
|
82
|
+
});
|
|
83
|
+
const collection = createFieldCollection({
|
|
84
|
+
fields: createSystemFields(),
|
|
85
|
+
transformValuePlugins,
|
|
86
|
+
valuePathPlugins,
|
|
87
|
+
parents: [],
|
|
88
|
+
system: true
|
|
89
|
+
});
|
|
90
|
+
const result = createFieldCollection({
|
|
91
|
+
fields,
|
|
92
|
+
transformValuePlugins,
|
|
93
|
+
valuePathPlugins,
|
|
94
|
+
parents: [{
|
|
95
|
+
fieldId: "values",
|
|
96
|
+
multipleValues: false
|
|
97
|
+
}],
|
|
98
|
+
system: false
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
...collection,
|
|
102
|
+
...result
|
|
118
103
|
};
|
|
119
|
-
|
|
120
|
-
addFieldsToCollection(model.fields);
|
|
121
|
-
return collection;
|
|
122
104
|
};
|
|
123
105
|
|
|
124
|
-
|
|
106
|
+
//# sourceMappingURL=createFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createSystemFields","CmsEntryFieldFilterPathPlugin","getMappedPlugins","getBaseFieldType","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","fieldType","transformPlugin","valuePathPlugin","fieldId","multipleValues","map","f","join","createPath","canUse","p","parent","concat","transform","value","childFields","settings","length","result","Object","assign","createFields","plugins","type","property"],"sources":["createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;\n valuePathPlugins: Record<string, CmsEntryFieldFilterPathPlugin>;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system,\n createPath: params => {\n if (\n valuePathPlugin &&\n valuePathPlugin.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return valuePathPlugin.createPath(params);\n }\n\n return parents\n .map(parent => parent.fieldId)\n .concat([params.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n const childFields = field.settings?.fields;\n if (!childFields?.length) {\n return collection;\n }\n\n const result = createFieldCollection({\n fields: childFields,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ],\n transformValuePlugins,\n valuePathPlugins,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\n};\n/**\n * This method will map the fieldId (fieldId -> field) to the actual field.\n *\n * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).\n */\nexport const createFields = (params: Params) => {\n const { fields, plugins } = params;\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const collection = createFieldCollection({\n fields: createSystemFields(),\n transformValuePlugins,\n valuePathPlugins,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n transformValuePlugins,\n valuePathPlugins,\n parents: [\n {\n fieldId: \"values\",\n multipleValues: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"mappings":"AACA,SAASA,kBAAkB;AAI3B,SAASC,6BAA6B;AACtC,SAASC,gBAAgB;AACzB,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,MAAMC,qBAAqB,GAAIC,MAAmC,IAAsB;EACpF,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,qBAAqB;IAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACnF,OAAOC,MAAM,CAACK,MAAM,CAAkB,CAACC,UAAU,EAAEC,KAAK,KAAK;IACzD,MAAMC,SAAS,GAAGX,gBAAgB,CAACU,KAAK,CAAC;IACzC,MAAME,eAAe,GAAGP,qBAAqB,CAACM,SAAS,CAAC;IACxD,MAAME,eAAe,GAAGP,gBAAgB,CAACK,SAAS,CAAC;;IAEnD;AACR;AACA;IACQ,MAAMG,OAAO,GAAG,CACZ,GAAGV,OAAO,EACV;MACIU,OAAO,EAAEJ,KAAK,CAACI,OAAO;MACtBC,cAAc,EAAEL,KAAK,CAACK;IAC1B,CAAC,CACJ,CACIC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACH,OAAO,CAAC,CACnBI,IAAI,CAAC,GAAG,CAAC;IAEdT,UAAU,CAACK,OAAO,CAAC,GAA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5C,MAAM;IAAEC,MAAM;IAAE8B;EAAQ,CAAC,GAAG/B,MAAM;EAElC,MAAMG,qBAAqB,GAAGN,gBAAgB,CAAqC;IAC/EkC,OAAO;IACPC,IAAI,EAAE,kCAAkC;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EACF,MAAM7B,gBAAgB,GAAGP,gBAAgB,CAAgC;IACrEkC,OAAO;IACPC,IAAI,EAAEpC,6BAA6B,CAACoC,IAAI;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EAEF,MAAM1B,UAAU,GAAGR,qBAAqB,CAAC;IACrCE,MAAM,EAAEN,kBAAkB,CAAC,CAAC;IAC5BQ,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,EAAE;IACXG,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMsB,MAAM,GAAG5B,qBAAqB,CAAC;IACjCE,MAAM;IACNE,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,CACL;MACIU,OAAO,EAAE,QAAQ;MACjBC,cAAc,EAAE;IACpB,CAAC,CACJ;IACDR,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,OAAO;IACH,GAAGE,UAAU;IACb,GAAGoB;EACP,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { Field } from "./types";
|
|
2
|
-
|
|
1
|
+
import type { Field } from "./types.js";
|
|
2
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
interface IResponse {
|
|
3
5
|
valuePath: string;
|
|
4
6
|
reverse: boolean;
|
|
5
7
|
fieldId: string;
|
|
6
8
|
field: Field;
|
|
7
9
|
}
|
|
8
|
-
interface
|
|
10
|
+
interface IParams {
|
|
11
|
+
model: CmsModel;
|
|
9
12
|
sortBy: string;
|
|
10
13
|
fields: Record<string, Field>;
|
|
14
|
+
plugins: PluginsContainer;
|
|
11
15
|
}
|
|
12
|
-
export declare const extractSort: (params:
|
|
16
|
+
export declare const extractSort: (params: IParams) => IResponse;
|
|
13
17
|
export {};
|
|
@@ -1,46 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { CmsEntryFieldSortingPlugin } from "../../../plugins/index.js";
|
|
3
|
+
const extractSortInfo = sortBy => {
|
|
4
|
+
const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
|
|
5
|
+
if (rootSorting) {
|
|
6
|
+
return {
|
|
7
|
+
fieldId: rootSorting[1],
|
|
8
|
+
isValues: false,
|
|
9
|
+
order: rootSorting[2]
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
|
|
13
|
+
if (valuesSorting) {
|
|
14
|
+
return {
|
|
15
|
+
fieldId: valuesSorting[1],
|
|
16
|
+
isValues: true,
|
|
17
|
+
order: valuesSorting[2]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
21
|
+
sortBy
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export const extractSort = params => {
|
|
13
25
|
const {
|
|
26
|
+
model,
|
|
14
27
|
sortBy,
|
|
15
|
-
fields
|
|
28
|
+
fields,
|
|
29
|
+
plugins
|
|
16
30
|
} = params;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const [fieldId, order] = result;
|
|
26
|
-
const field = Object.values(fields).find(field => {
|
|
31
|
+
const {
|
|
32
|
+
fieldId,
|
|
33
|
+
isValues: isValuesSorting,
|
|
34
|
+
order
|
|
35
|
+
} = extractSortInfo(sortBy);
|
|
36
|
+
const field = Object.values(fields).find(f => {
|
|
27
37
|
/**
|
|
28
38
|
* We do not support sorting by nested fields.
|
|
29
39
|
*/
|
|
30
|
-
|
|
40
|
+
const isValues = f.parents[0]?.fieldId === "values";
|
|
41
|
+
if (isValues && isValuesSorting) {
|
|
42
|
+
return f.fieldId === fieldId;
|
|
43
|
+
}
|
|
44
|
+
if (f.parents.length > 0) {
|
|
31
45
|
return false;
|
|
32
46
|
}
|
|
33
|
-
|
|
34
|
-
return field.fieldId === fieldId;
|
|
47
|
+
return f.fieldId === fieldId;
|
|
35
48
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
|
|
50
|
+
return plugin.canUse({
|
|
51
|
+
model,
|
|
52
|
+
field,
|
|
53
|
+
fieldId,
|
|
54
|
+
order,
|
|
55
|
+
sortBy
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
if (plugin) {
|
|
59
|
+
return plugin.createSort({
|
|
60
|
+
model,
|
|
61
|
+
fieldId,
|
|
62
|
+
order,
|
|
63
|
+
sortBy,
|
|
64
|
+
field,
|
|
65
|
+
fields
|
|
66
|
+
});
|
|
67
|
+
} else if (!field) {
|
|
68
|
+
throw new WebinyError("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
39
69
|
fieldId,
|
|
40
70
|
fields
|
|
41
71
|
});
|
|
42
72
|
}
|
|
43
|
-
|
|
44
73
|
const valuePath = field.createPath({
|
|
45
74
|
field
|
|
46
75
|
});
|
|
@@ -52,4 +81,4 @@ const extractSort = params => {
|
|
|
52
81
|
};
|
|
53
82
|
};
|
|
54
83
|
|
|
55
|
-
|
|
84
|
+
//# sourceMappingURL=extractSort.js.map
|