@webiny/api-headless-cms-ddb 6.4.5-beta.0 → 6.6.0-alpha.0
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/abstractions/CmsDdbDataLoaders.d.ts +5 -0
- package/abstractions/CmsDdbDataLoaders.js +5 -0
- package/abstractions/CmsDdbDataLoaders.js.map +1 -0
- package/abstractions/CmsDdbEntryEntity.d.ts +5 -0
- package/abstractions/CmsDdbEntryEntity.js +5 -0
- package/abstractions/CmsDdbEntryEntity.js.map +1 -0
- package/abstractions/CmsDdbGroupEntity.d.ts +5 -0
- package/abstractions/CmsDdbGroupEntity.js +5 -0
- package/abstractions/CmsDdbGroupEntity.js.map +1 -0
- package/abstractions/CmsDdbModelEntity.d.ts +5 -0
- package/abstractions/CmsDdbModelEntity.js +5 -0
- package/abstractions/CmsDdbModelEntity.js.map +1 -0
- package/abstractions/CmsDdbTable.d.ts +5 -0
- package/abstractions/CmsDdbTable.js +5 -0
- package/abstractions/CmsDdbTable.js.map +1 -0
- package/index.d.ts +13 -2
- package/index.js +31 -71
- package/index.js.map +1 -1
- package/operations/entry/DdbCreateEntry.d.ts +16 -0
- package/operations/entry/DdbCreateEntry.js +77 -0
- package/operations/entry/DdbCreateEntry.js.map +1 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.d.ts +16 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.js +85 -0
- package/operations/entry/DdbCreateEntryRevisionFrom.js.map +1 -0
- package/operations/entry/DdbDeleteEntry.d.ts +16 -0
- package/operations/entry/DdbDeleteEntry.js +65 -0
- package/operations/entry/DdbDeleteEntry.js.map +1 -0
- package/operations/entry/DdbDeleteEntryRevision.d.ts +17 -0
- package/operations/entry/DdbDeleteEntryRevision.js +91 -0
- package/operations/entry/DdbDeleteEntryRevision.js.map +1 -0
- package/operations/entry/DdbDeleteMultipleEntries.d.ts +16 -0
- package/operations/entry/DdbDeleteMultipleEntries.js +56 -0
- package/operations/entry/DdbDeleteMultipleEntries.js.map +1 -0
- package/operations/entry/DdbGetEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetEntriesByIds.js +31 -0
- package/operations/entry/DdbGetEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetEntry.d.ts +14 -0
- package/operations/entry/DdbGetEntry.js +27 -0
- package/operations/entry/DdbGetEntry.js.map +1 -0
- package/operations/entry/DdbGetLatestEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetLatestEntriesByIds.js +31 -0
- package/operations/entry/DdbGetLatestEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.d.ts +14 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.js +35 -0
- package/operations/entry/DdbGetLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/DdbGetPreviousRevision.d.ts +14 -0
- package/operations/entry/DdbGetPreviousRevision.js +53 -0
- package/operations/entry/DdbGetPreviousRevision.js.map +1 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.d.ts +14 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.js +31 -0
- package/operations/entry/DdbGetPublishedEntriesByIds.js.map +1 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.d.ts +14 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.js +35 -0
- package/operations/entry/DdbGetPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/DdbGetRevisionById.d.ts +14 -0
- package/operations/entry/DdbGetRevisionById.js +34 -0
- package/operations/entry/DdbGetRevisionById.js.map +1 -0
- package/operations/entry/DdbGetRevisions.d.ts +14 -0
- package/operations/entry/DdbGetRevisions.js +33 -0
- package/operations/entry/DdbGetRevisions.js.map +1 -0
- package/operations/entry/DdbGetUniqueFieldValues.d.ts +12 -0
- package/operations/entry/DdbGetUniqueFieldValues.js +31 -0
- package/operations/entry/DdbGetUniqueFieldValues.js.map +1 -0
- package/operations/entry/DdbListEntries.d.ts +28 -0
- package/operations/entry/DdbListEntries.js +124 -0
- package/operations/entry/DdbListEntries.js.map +1 -0
- package/operations/entry/DdbMoveEntry.d.ts +14 -0
- package/operations/entry/DdbMoveEntry.js +57 -0
- package/operations/entry/DdbMoveEntry.js.map +1 -0
- package/operations/entry/DdbMoveToBin.d.ts +16 -0
- package/operations/entry/DdbMoveToBin.js +77 -0
- package/operations/entry/DdbMoveToBin.js.map +1 -0
- package/operations/entry/DdbPublishEntry.d.ts +18 -0
- package/operations/entry/DdbPublishEntry.js +161 -0
- package/operations/entry/DdbPublishEntry.js.map +1 -0
- package/operations/entry/DdbRestoreFromBin.d.ts +16 -0
- package/operations/entry/DdbRestoreFromBin.js +78 -0
- package/operations/entry/DdbRestoreFromBin.js.map +1 -0
- package/operations/entry/DdbUnpublishEntry.d.ts +17 -0
- package/operations/entry/DdbUnpublishEntry.js +112 -0
- package/operations/entry/DdbUnpublishEntry.js.map +1 -0
- package/operations/entry/DdbUpdateEntry.d.ts +17 -0
- package/operations/entry/DdbUpdateEntry.js +110 -0
- package/operations/entry/DdbUpdateEntry.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +7 -6
- package/operations/entry/dataLoaders.js +11 -3
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/feature.d.ts +4 -0
- package/operations/entry/feature.js +55 -0
- package/operations/entry/feature.js.map +1 -0
- package/operations/entry/storageEntryUtils.d.ts +8 -0
- package/operations/entry/storageEntryUtils.js +25 -0
- package/operations/entry/storageEntryUtils.js.map +1 -0
- package/operations/group/DdbCreateGroup.d.ts +12 -0
- package/operations/group/DdbCreateGroup.js +35 -0
- package/operations/group/DdbCreateGroup.js.map +1 -0
- package/operations/group/DdbDeleteGroup.d.ts +12 -0
- package/operations/group/DdbDeleteGroup.js +31 -0
- package/operations/group/DdbDeleteGroup.js.map +1 -0
- package/operations/group/DdbGetGroup.d.ts +12 -0
- package/operations/group/DdbGetGroup.js +31 -0
- package/operations/group/DdbGetGroup.js.map +1 -0
- package/operations/group/DdbListGroups.d.ts +14 -0
- package/operations/group/DdbListGroups.js +52 -0
- package/operations/group/DdbListGroups.js.map +1 -0
- package/operations/group/DdbUpdateGroup.d.ts +12 -0
- package/operations/group/DdbUpdateGroup.js +35 -0
- package/operations/group/DdbUpdateGroup.js.map +1 -0
- package/operations/group/feature.d.ts +4 -0
- package/operations/group/feature.js +19 -0
- package/operations/group/feature.js.map +1 -0
- package/operations/group/keys.d.ts +15 -0
- package/operations/group/keys.js +17 -0
- package/operations/group/keys.js.map +1 -0
- package/operations/model/DdbCreateModel.d.ts +12 -0
- package/operations/model/DdbCreateModel.js +37 -0
- package/operations/model/DdbCreateModel.js.map +1 -0
- package/operations/model/DdbDeleteModel.d.ts +12 -0
- package/operations/model/DdbDeleteModel.js +31 -0
- package/operations/model/DdbDeleteModel.js.map +1 -0
- package/operations/model/DdbGetModel.d.ts +12 -0
- package/operations/model/DdbGetModel.js +30 -0
- package/operations/model/DdbGetModel.js.map +1 -0
- package/operations/model/DdbListModels.d.ts +12 -0
- package/operations/model/DdbListModels.js +36 -0
- package/operations/model/DdbListModels.js.map +1 -0
- package/operations/model/DdbUpdateModel.d.ts +12 -0
- package/operations/model/DdbUpdateModel.js +36 -0
- package/operations/model/DdbUpdateModel.js.map +1 -0
- package/operations/model/feature.d.ts +4 -0
- package/operations/model/feature.js +19 -0
- package/operations/model/feature.js.map +1 -0
- package/operations/model/keys.d.ts +15 -0
- package/operations/model/keys.js +16 -0
- package/operations/model/keys.js.map +1 -0
- package/package.json +15 -17
- package/types.d.ts +9 -49
- package/types.js.map +1 -1
- package/dynamoDb/index.d.ts +0 -2
- package/dynamoDb/index.js +0 -11
- package/dynamoDb/index.js.map +0 -1
- package/dynamoDb/path/locationFolderId.d.ts +0 -2
- package/dynamoDb/path/locationFolderId.js +0 -21
- package/dynamoDb/path/locationFolderId.js.map +0 -1
- package/dynamoDb/path/plainObject.d.ts +0 -2
- package/dynamoDb/path/plainObject.js +0 -16
- package/dynamoDb/path/plainObject.js.map +0 -1
- package/dynamoDb/transformValue/datetime.d.ts +0 -5
- package/dynamoDb/transformValue/datetime.js +0 -29
- package/dynamoDb/transformValue/datetime.js.map +0 -1
- package/operations/entry/filtering/createExpressions.d.ts +0 -27
- package/operations/entry/filtering/createExpressions.js +0 -124
- package/operations/entry/filtering/createExpressions.js.map +0 -1
- package/operations/entry/filtering/createFields.d.ts +0 -16
- package/operations/entry/filtering/createFields.js +0 -93
- package/operations/entry/filtering/createFields.js.map +0 -1
- package/operations/entry/filtering/extractSort.d.ts +0 -17
- package/operations/entry/filtering/extractSort.js +0 -60
- package/operations/entry/filtering/extractSort.js.map +0 -1
- package/operations/entry/filtering/filter.d.ts +0 -16
- package/operations/entry/filtering/filter.js +0 -85
- package/operations/entry/filtering/filter.js.map +0 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +0 -14
- package/operations/entry/filtering/fullTextSearch.js +0 -25
- package/operations/entry/filtering/fullTextSearch.js.map +0 -1
- package/operations/entry/filtering/getValue.d.ts +0 -5
- package/operations/entry/filtering/getValue.js +0 -37
- package/operations/entry/filtering/getValue.js.map +0 -1
- package/operations/entry/filtering/index.d.ts +0 -2
- package/operations/entry/filtering/index.js +0 -2
- package/operations/entry/filtering/mapPlugins.d.ts +0 -8
- package/operations/entry/filtering/mapPlugins.js +0 -18
- package/operations/entry/filtering/mapPlugins.js.map +0 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +0 -33
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/index.d.ts +0 -1
- package/operations/entry/filtering/plugins/index.js +0 -13
- package/operations/entry/filtering/plugins/index.js.map +0 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/objectFilterCreate.js +0 -68
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +0 -3
- package/operations/entry/filtering/plugins/refFilterCreate.js +0 -63
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +0 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +0 -2
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +0 -56
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +0 -1
- package/operations/entry/filtering/sort.d.ts +0 -12
- package/operations/entry/filtering/sort.js +0 -41
- package/operations/entry/filtering/sort.js.map +0 -1
- package/operations/entry/filtering/systemFields.d.ts +0 -2
- package/operations/entry/filtering/systemFields.js +0 -149
- package/operations/entry/filtering/systemFields.js.map +0 -1
- package/operations/entry/filtering/transform.d.ts +0 -6
- package/operations/entry/filtering/transform.js +0 -7
- package/operations/entry/filtering/transform.js.map +0 -1
- package/operations/entry/filtering/types.d.ts +0 -40
- package/operations/entry/filtering/types.js +0 -0
- package/operations/entry/filtering/values.d.ts +0 -2
- package/operations/entry/filtering/values.js +0 -15
- package/operations/entry/filtering/values.js.map +0 -1
- package/operations/entry/filtering/where.d.ts +0 -5
- package/operations/entry/filtering/where.js +0 -22
- package/operations/entry/filtering/where.js.map +0 -1
- package/operations/entry/index.d.ts +0 -9
- package/operations/entry/index.js +0 -943
- package/operations/entry/index.js.map +0 -1
- package/operations/group/index.d.ts +0 -8
- package/operations/group/index.js +0 -121
- package/operations/group/index.js.map +0 -1
- package/operations/model/index.d.ts +0 -7
- package/operations/model/index.js +0 -106
- package/operations/model/index.js.map +0 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +0 -23
- package/plugins/CmsEntryFieldFilterPathPlugin.js +0 -30
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +0 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +0 -43
- package/plugins/CmsEntryFieldFilterPlugin.js +0 -20
- package/plugins/CmsEntryFieldFilterPlugin.js.map +0 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +0 -42
- package/plugins/CmsEntryFieldSortingPlugin.js +0 -20
- package/plugins/CmsEntryFieldSortingPlugin.js.map +0 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +0 -11
- package/plugins/CmsFieldFilterValueTransformPlugin.js +0 -19
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +0 -1
- package/plugins/index.d.ts +0 -4
- package/plugins/index.js +0 -4
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import error from "@webiny/error";
|
|
2
|
-
import { getMappedPlugins } from "./mapPlugins.js";
|
|
3
|
-
import { extractWhereParams } from "./where.js";
|
|
4
|
-
import { transformValue } from "./transform.js";
|
|
5
|
-
import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
6
|
-
import { getWhereValues } from "./values.js";
|
|
7
|
-
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
8
|
-
import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
9
|
-
const createExpressions = (params)=>{
|
|
10
|
-
const { where, plugins, fields, container } = params;
|
|
11
|
-
const valueFilterRegistry = container.resolve(ValueFilterRegistry);
|
|
12
|
-
const transformValuePlugins = getMappedPlugins({
|
|
13
|
-
plugins,
|
|
14
|
-
type: "cms-field-filter-value-transform",
|
|
15
|
-
property: "fieldType"
|
|
16
|
-
});
|
|
17
|
-
const fieldFilterCreatePlugins = getMappedPlugins({
|
|
18
|
-
plugins,
|
|
19
|
-
type: CmsEntryFieldFilterPlugin.type,
|
|
20
|
-
property: "fieldType"
|
|
21
|
-
});
|
|
22
|
-
const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
|
|
23
|
-
const getFilterCreatePlugin = (type)=>{
|
|
24
|
-
const fieldType = getBaseFieldType({
|
|
25
|
-
type
|
|
26
|
-
});
|
|
27
|
-
const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
|
|
28
|
-
if (filterCreatePlugin) return filterCreatePlugin;
|
|
29
|
-
throw new error(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
|
|
30
|
-
fieldType
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
const createExpression = ({ where, condition })=>{
|
|
34
|
-
const expression = {
|
|
35
|
-
filters: [],
|
|
36
|
-
expressions: [],
|
|
37
|
-
condition
|
|
38
|
-
};
|
|
39
|
-
for(const key in where){
|
|
40
|
-
const value = where[key];
|
|
41
|
-
if (void 0 === value) continue;
|
|
42
|
-
if ("AND" === key) {
|
|
43
|
-
const childWhereList = getWhereValues(value, key);
|
|
44
|
-
const childExpression = {
|
|
45
|
-
condition: "AND",
|
|
46
|
-
filters: [],
|
|
47
|
-
expressions: []
|
|
48
|
-
};
|
|
49
|
-
for (const childWhere of childWhereList){
|
|
50
|
-
const result = createExpression({
|
|
51
|
-
where: childWhere,
|
|
52
|
-
condition: "AND"
|
|
53
|
-
});
|
|
54
|
-
childExpression.expressions.push(result);
|
|
55
|
-
}
|
|
56
|
-
expression.expressions.push(childExpression);
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if ("OR" === key) {
|
|
60
|
-
const childWhereList = getWhereValues(value, key);
|
|
61
|
-
const childExpression = {
|
|
62
|
-
condition: "OR",
|
|
63
|
-
filters: [],
|
|
64
|
-
expressions: []
|
|
65
|
-
};
|
|
66
|
-
for (const childWhere of childWhereList){
|
|
67
|
-
const result = createExpression({
|
|
68
|
-
where: childWhere,
|
|
69
|
-
condition: "AND"
|
|
70
|
-
});
|
|
71
|
-
childExpression.expressions.push(result);
|
|
72
|
-
}
|
|
73
|
-
expression.expressions.push(childExpression);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const whereParams = extractWhereParams(key);
|
|
77
|
-
if (!whereParams) continue;
|
|
78
|
-
const { fieldId, operation, negate } = whereParams;
|
|
79
|
-
const field = fields[fieldId];
|
|
80
|
-
if (!field) throw new error(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
81
|
-
fieldId
|
|
82
|
-
});
|
|
83
|
-
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
84
|
-
const fieldType = getBaseFieldType(field);
|
|
85
|
-
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
86
|
-
const transformValueCallable = (value)=>{
|
|
87
|
-
if (!transformValuePlugin) return value;
|
|
88
|
-
return transformValuePlugin.transform({
|
|
89
|
-
field,
|
|
90
|
-
value
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
const result = filterCreatePlugin.create({
|
|
94
|
-
key,
|
|
95
|
-
value,
|
|
96
|
-
valueFilterRegistry,
|
|
97
|
-
transformValuePlugins,
|
|
98
|
-
getFilterCreatePlugin,
|
|
99
|
-
operation,
|
|
100
|
-
negate,
|
|
101
|
-
field,
|
|
102
|
-
fields,
|
|
103
|
-
compareValue: transformValue({
|
|
104
|
-
value,
|
|
105
|
-
transform: transformValueCallable
|
|
106
|
-
}),
|
|
107
|
-
transformValue: transformValueCallable
|
|
108
|
-
});
|
|
109
|
-
if (!(!result || Array.isArray(result) && 0 === result.length)) expression.filters.push(...Array.isArray(result) ? result : [
|
|
110
|
-
result
|
|
111
|
-
]);
|
|
112
|
-
}
|
|
113
|
-
return expression;
|
|
114
|
-
};
|
|
115
|
-
const expression = createExpression({
|
|
116
|
-
where,
|
|
117
|
-
condition: "AND"
|
|
118
|
-
});
|
|
119
|
-
if (expression.filters.length > 0 || 1 !== expression.expressions.length) return expression;
|
|
120
|
-
return expression.expressions[0];
|
|
121
|
-
};
|
|
122
|
-
export { createExpressions };
|
|
123
|
-
|
|
124
|
-
//# sourceMappingURL=createExpressions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/filtering/createExpressions.js","sources":["../../../../src/operations/entry/filtering/createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsContext, CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.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\";\nimport { ValueFilter } from \"@webiny/db-dynamodb/feature/ValueFilter/index.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface ICreateExpressionsParams {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\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 filter: ValueFilter.Interface;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: ICreateExpressionsParams): Expression => {\n const { where, plugins, fields, container } = params;\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\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 valueFilterRegistry,\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"],"names":["createExpressions","params","where","plugins","fields","container","valueFilterRegistry","ValueFilterRegistry","transformValuePlugins","getMappedPlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","type","fieldType","getBaseFieldType","filterCreatePlugin","WebinyError","createExpression","condition","expression","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transformValue","Array"],"mappings":";;;;;;;;AA4CO,MAAMA,oBAAoB,CAACC;IAC9B,MAAM,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGJ;IAC9C,MAAMK,sBAAsBD,UAAU,OAAO,CAACE;IAE9C,MAAMC,wBAAwBC,iBAAqD;QAC/EN;QACA,MAAM;QACN,UAAU;IACd;IACA,MAAMO,2BAA2BD,iBAA4C;QACzEN;QACA,MAAMQ,0BAA0B,IAAI;QACpC,UAAU;IACd;IAEA,MAAMC,4BAA4BF,wBAAwB,CAAC,IAAI;IAE/D,MAAMG,wBAAwB,CAACC;QAC3B,MAAMC,YAAYC,iBAAiB;YAC/BF;QACJ;QACA,MAAMG,qBAAqBP,wBAAwB,CAACK,UAAU,IAAIH;QAClE,IAAIK,oBACA,OAAOA;QAEX,MAAM,IAAIC,MACN,CAAC,qDAAqD,EAAEH,UAAU,EAAE,CAAC,EACrE,gCACA;YACIA;QACJ;IAER;IAEA,MAAMI,mBAAmB,CAAC,EAAEjB,KAAK,EAAEkB,SAAS,EAA0B;QAClE,MAAMC,aAAyB;YAC3B,SAAS,EAAE;YACX,aAAa,EAAE;YACfD;QACJ;QAEA,IAAK,MAAME,OAAOpB,MAAO;YACrB,MAAMqB,QAAQrB,KAAK,CAACoB,IAA0B;YAC9C,IAAIC,AAAUC,WAAVD,OACA;YASJ,IAAID,AAAQ,UAARA,KAAe;gBACf,MAAMG,iBAAiBC,eAAeH,OAAOD;gBAC7C,MAAMK,kBAA8B;oBAChC,WAAW;oBACX,SAAS,EAAE;oBACX,aAAa,EAAE;gBACnB;gBACA,KAAK,MAAMC,cAAcH,eAAgB;oBACrC,MAAMI,SAASV,iBAAiB;wBAC5B,OAAOS;wBACP,WAAW;oBACf;oBACAD,gBAAgB,WAAW,CAAC,IAAI,CAACE;gBACrC;gBACAR,WAAW,WAAW,CAAC,IAAI,CAACM;gBAC5B;YACJ;YAIA,IAAIL,AAAQ,SAARA,KAAc;gBACd,MAAMG,iBAAiBC,eAAeH,OAAOD;gBAE7C,MAAMK,kBAA8B;oBAChC,WAAW;oBACX,SAAS,EAAE;oBACX,aAAa,EAAE;gBACnB;gBACA,KAAK,MAAMC,cAAcH,eAAgB;oBACrC,MAAMI,SAASV,iBAAiB;wBAC5B,OAAOS;wBACP,WAAW;oBACf;oBACAD,gBAAgB,WAAW,CAAC,IAAI,CAACE;gBACrC;gBACAR,WAAW,WAAW,CAAC,IAAI,CAACM;gBAC5B;YACJ;YAEA,MAAMG,cAAcC,mBAAmBT;YACvC,IAAI,CAACQ,aACD;YAGJ,MAAM,EAAEE,OAAO,EAAEC,SAAS,EAAEC,MAAM,EAAE,GAAGJ;YAEvC,MAAMK,QAAQ/B,MAAM,CAAC4B,QAAQ;YAC7B,IAAI,CAACG,OACD,MAAM,IAAIjB,MACN,CAAC,oCAAoC,EAAEc,QAAQ,EAAE,CAAC,EAClD,eACA;gBACIA;YACJ;YAOR,MAAMf,qBAAqBJ,sBAAsBsB,MAAM,IAAI;YAE3D,MAAMpB,YAAYC,iBAAiBmB;YAEnC,MAAMC,uBACF5B,qBAAqB,CAACO,UAAU;YAEpC,MAAMsB,yBAAyB,CAACd;gBAC5B,IAAI,CAACa,sBACD,OAAOb;gBAEX,OAAOa,qBAAqB,SAAS,CAAC;oBAClCD;oBACAZ;gBACJ;YACJ;YAEA,MAAMM,SAASZ,mBAAmB,MAAM,CAAC;gBACrCK;gBACAC;gBACAjB;gBACAE;gBACAK;gBACAoB;gBACAC;gBACAC;gBACA/B;gBACA,cAAckC,eAAe;oBACzBf;oBACA,WAAWc;gBACf;gBACA,gBAAgBA;YACpB;YAOA,KAAI,EAACR,UAAWU,MAAM,OAAO,CAACV,WAAWA,AAAkB,MAAlBA,OAAO,MAAM,AAAK,GAI3DR,WAAW,OAAO,CAAC,IAAI,IAAKkB,MAAM,OAAO,CAACV,UAAUA,SAAS;gBAACA;aAAO;QACzE;QAEA,OAAOR;IACX;IAEA,MAAMA,aAAaF,iBAAiB;QAChCjB;QACA,WAAW;IACf;IAKA,IAAImB,WAAW,OAAO,CAAC,MAAM,GAAG,KAAKA,AAAkC,MAAlCA,WAAW,WAAW,CAAC,MAAM,EAC9D,OAAOA;IAEX,OAAOA,WAAW,WAAW,CAAC,EAAE;AACpC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
interface Params {
|
|
5
|
-
fields: CmsModelField[];
|
|
6
|
-
plugins: PluginsContainer;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
10
|
-
*
|
|
11
|
-
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
12
|
-
*/
|
|
13
|
-
export declare const createFields: (params: Params) => {
|
|
14
|
-
[x: string]: Field;
|
|
15
|
-
};
|
|
16
|
-
export {};
|
|
@@ -1,93 +0,0 @@
|
|
|
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)=>{
|
|
6
|
-
const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;
|
|
7
|
-
return fields.reduce((collection, field)=>{
|
|
8
|
-
const fieldType = getBaseFieldType(field);
|
|
9
|
-
const transformPlugin = transformValuePlugins[fieldType];
|
|
10
|
-
const valuePathPlugin = valuePathPlugins[fieldType];
|
|
11
|
-
const fieldId = [
|
|
12
|
-
...parents,
|
|
13
|
-
{
|
|
14
|
-
fieldId: field.fieldId,
|
|
15
|
-
list: field.list
|
|
16
|
-
}
|
|
17
|
-
].map((f)=>f.fieldId).join(".");
|
|
18
|
-
collection[fieldId] = {
|
|
19
|
-
...field,
|
|
20
|
-
parents,
|
|
21
|
-
system,
|
|
22
|
-
createPath: (params)=>{
|
|
23
|
-
if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map((p)=>p.fieldId))) return valuePathPlugin.createPath(params);
|
|
24
|
-
return parents.map((parent)=>parent.fieldId).concat([
|
|
25
|
-
params.field.fieldId
|
|
26
|
-
]).join(".");
|
|
27
|
-
},
|
|
28
|
-
transform: (value)=>{
|
|
29
|
-
if (!transformPlugin) return value;
|
|
30
|
-
return transformPlugin.transform({
|
|
31
|
-
field,
|
|
32
|
-
value
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const childFields = field.settings?.fields;
|
|
37
|
-
if (!childFields?.length) return collection;
|
|
38
|
-
const result = createFieldCollection({
|
|
39
|
-
fields: childFields,
|
|
40
|
-
parents: [
|
|
41
|
-
...parents,
|
|
42
|
-
{
|
|
43
|
-
fieldId: field.fieldId,
|
|
44
|
-
list: field.list
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
transformValuePlugins,
|
|
48
|
-
valuePathPlugins,
|
|
49
|
-
system
|
|
50
|
-
});
|
|
51
|
-
Object.assign(collection, result);
|
|
52
|
-
return collection;
|
|
53
|
-
}, {});
|
|
54
|
-
};
|
|
55
|
-
const createFields = (params)=>{
|
|
56
|
-
const { fields, plugins } = params;
|
|
57
|
-
const transformValuePlugins = getMappedPlugins({
|
|
58
|
-
plugins,
|
|
59
|
-
type: "cms-field-filter-value-transform",
|
|
60
|
-
property: "fieldType"
|
|
61
|
-
});
|
|
62
|
-
const valuePathPlugins = getMappedPlugins({
|
|
63
|
-
plugins,
|
|
64
|
-
type: CmsEntryFieldFilterPathPlugin.type,
|
|
65
|
-
property: "fieldType"
|
|
66
|
-
});
|
|
67
|
-
const collection = createFieldCollection({
|
|
68
|
-
fields: createSystemFields(),
|
|
69
|
-
transformValuePlugins,
|
|
70
|
-
valuePathPlugins,
|
|
71
|
-
parents: [],
|
|
72
|
-
system: true
|
|
73
|
-
});
|
|
74
|
-
const result = createFieldCollection({
|
|
75
|
-
fields,
|
|
76
|
-
transformValuePlugins,
|
|
77
|
-
valuePathPlugins,
|
|
78
|
-
parents: [
|
|
79
|
-
{
|
|
80
|
-
fieldId: "values",
|
|
81
|
-
list: false
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
system: false
|
|
85
|
-
});
|
|
86
|
-
return {
|
|
87
|
-
...collection,
|
|
88
|
-
...result
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
export { createFields };
|
|
92
|
-
|
|
93
|
-
//# sourceMappingURL=createFields.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/filtering/createFields.js","sources":["../../../../src/operations/entry/filtering/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 list: field.list\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 list: field.list\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 list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"names":["createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","collection","field","fieldType","getBaseFieldType","transformPlugin","valuePathPlugin","fieldId","f","p","parent","value","childFields","result","Object","createFields","plugins","getMappedPlugins","CmsEntryFieldFilterPathPlugin","createSystemFields"],"mappings":";;;;AA0BA,MAAMA,wBAAwB,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAEC,qBAAqB,EAAEC,gBAAgB,EAAEC,MAAM,EAAE,GAAGL;IAC7E,OAAOC,OAAO,MAAM,CAAkB,CAACK,YAAYC;QAC/C,MAAMC,YAAYC,iBAAiBF;QACnC,MAAMG,kBAAkBP,qBAAqB,CAACK,UAAU;QACxD,MAAMG,kBAAkBP,gBAAgB,CAACI,UAAU;QAKnD,MAAMI,UAAU;eACTV;YACH;gBACI,SAASK,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;YACpB;SACH,CACI,GAAG,CAACM,CAAAA,IAAKA,EAAE,OAAO,EAClB,IAAI,CAAC;QAEVP,UAAU,CAACM,QAAQ,GAAG;YAClB,GAAGL,KAAK;YACRL;YACAG;YACA,YAAYL,CAAAA;gBACR,IACIW,mBACAA,gBAAgB,MAAM,CAClBJ,OACAL,QAAQ,GAAG,CAACY,CAAAA,IAAKA,EAAE,OAAO,IAG9B,OAAOH,gBAAgB,UAAU,CAACX;gBAGtC,OAAOE,QACF,GAAG,CAACa,CAAAA,SAAUA,OAAO,OAAO,EAC5B,MAAM,CAAC;oBAACf,OAAO,KAAK,CAAC,OAAO;iBAAC,EAC7B,IAAI,CAAC;YACd;YACA,WAAWgB,CAAAA;gBACP,IAAI,CAACN,iBACD,OAAOM;gBAEX,OAAON,gBAAgB,SAAS,CAAC;oBAC7BH;oBACAS;gBACJ;YACJ;QACJ;QACA,MAAMC,cAAcV,MAAM,QAAQ,EAAE;QACpC,IAAI,CAACU,aAAa,QACd,OAAOX;QAGX,MAAMY,SAASnB,sBAAsB;YACjC,QAAQkB;YACR,SAAS;mBACFf;gBACH;oBACI,SAASK,MAAM,OAAO;oBACtB,MAAMA,MAAM,IAAI;gBACpB;aACH;YACDJ;YACAC;YACAC;QACJ;QACAc,OAAO,MAAM,CAACb,YAAYY;QAC1B,OAAOZ;IACX,GAAG,CAAC;AACR;AAMO,MAAMc,eAAe,CAACpB;IACzB,MAAM,EAAEC,MAAM,EAAEoB,OAAO,EAAE,GAAGrB;IAE5B,MAAMG,wBAAwBmB,iBAAqD;QAC/ED;QACA,MAAM;QACN,UAAU;IACd;IACA,MAAMjB,mBAAmBkB,iBAAgD;QACrED;QACA,MAAME,8BAA8B,IAAI;QACxC,UAAU;IACd;IAEA,MAAMjB,aAAaP,sBAAsB;QACrC,QAAQyB;QACRrB;QACAC;QACA,SAAS,EAAE;QACX,QAAQ;IACZ;IAEA,MAAMc,SAASnB,sBAAsB;QACjCE;QACAE;QACAC;QACA,SAAS;YACL;gBACI,SAAS;gBACT,MAAM;YACV;SACH;QACD,QAAQ;IACZ;IAEA,OAAO;QACH,GAAGE,UAAU;QACb,GAAGY,MAAM;IACb;AACJ"}
|
|
@@ -1,17 +0,0 @@
|
|
|
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 {
|
|
5
|
-
valuePath: string;
|
|
6
|
-
reverse: boolean;
|
|
7
|
-
fieldId: string;
|
|
8
|
-
field: Field;
|
|
9
|
-
}
|
|
10
|
-
interface IParams {
|
|
11
|
-
model: CmsModel;
|
|
12
|
-
sortBy: string;
|
|
13
|
-
fields: Record<string, Field>;
|
|
14
|
-
plugins: PluginsContainer;
|
|
15
|
-
}
|
|
16
|
-
export declare const extractSort: (params: IParams) => IResponse;
|
|
17
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import error 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) return {
|
|
6
|
-
fieldId: rootSorting[1],
|
|
7
|
-
isValues: false,
|
|
8
|
-
order: rootSorting[2]
|
|
9
|
-
};
|
|
10
|
-
const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
|
|
11
|
-
if (valuesSorting) return {
|
|
12
|
-
fieldId: valuesSorting[1],
|
|
13
|
-
isValues: true,
|
|
14
|
-
order: valuesSorting[2]
|
|
15
|
-
};
|
|
16
|
-
throw new error("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
17
|
-
sortBy
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
const extractSort = (params)=>{
|
|
21
|
-
const { model, sortBy, fields, plugins } = params;
|
|
22
|
-
const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);
|
|
23
|
-
const field = Object.values(fields).find((f)=>{
|
|
24
|
-
const isValues = f.parents[0]?.fieldId === "values";
|
|
25
|
-
if (isValues && isValuesSorting) return f.fieldId === fieldId;
|
|
26
|
-
if (f.parents.length > 0) return false;
|
|
27
|
-
return f.fieldId === fieldId;
|
|
28
|
-
});
|
|
29
|
-
const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find((plugin)=>plugin.canUse({
|
|
30
|
-
model,
|
|
31
|
-
field,
|
|
32
|
-
fieldId,
|
|
33
|
-
order,
|
|
34
|
-
sortBy
|
|
35
|
-
}));
|
|
36
|
-
if (plugin) return plugin.createSort({
|
|
37
|
-
model,
|
|
38
|
-
fieldId,
|
|
39
|
-
order,
|
|
40
|
-
sortBy,
|
|
41
|
-
field,
|
|
42
|
-
fields
|
|
43
|
-
});
|
|
44
|
-
if (!field) throw new error("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
45
|
-
fieldId,
|
|
46
|
-
fields
|
|
47
|
-
});
|
|
48
|
-
const valuePath = field.createPath({
|
|
49
|
-
field
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
field,
|
|
53
|
-
fieldId,
|
|
54
|
-
valuePath,
|
|
55
|
-
reverse: "DESC" === order
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
export { extractSort };
|
|
59
|
-
|
|
60
|
-
//# sourceMappingURL=extractSort.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/filtering/extractSort.js","sources":["../../../../src/operations/entry/filtering/extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst extractSortInfo = (sortBy: string) => {\n const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);\n if (rootSorting) {\n return {\n fieldId: rootSorting[1],\n isValues: false,\n order: rootSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);\n if (valuesSorting) {\n return {\n fieldId: valuesSorting[1],\n isValues: true,\n order: valuesSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n};\n\ninterface IResponse {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface IParams {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: IParams): IResponse => {\n const { model, sortBy, fields, plugins } = params;\n const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);\n\n const field = Object.values(fields).find(f => {\n /**\n * We do not support sorting by nested fields.\n */\n const isValues = f.parents[0]?.fieldId === \"values\";\n if (isValues && isValuesSorting) {\n return f.fieldId === fieldId;\n }\n if (f.parents.length > 0) {\n return false;\n }\n return f.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"names":["extractSortInfo","sortBy","rootSorting","valuesSorting","WebinyError","extractSort","params","model","fields","plugins","fieldId","isValuesSorting","order","field","Object","f","isValues","plugin","CmsEntryFieldSortingPlugin","valuePath"],"mappings":";;AAMA,MAAMA,kBAAkB,CAACC;IACrB,MAAMC,cAAcD,OAAO,KAAK,CAAC;IACjC,IAAIC,aACA,OAAO;QACH,SAASA,WAAW,CAAC,EAAE;QACvB,UAAU;QACV,OAAOA,WAAW,CAAC,EAAE;IACzB;IAEJ,MAAMC,gBAAgBF,OAAO,KAAK,CAAC;IACnC,IAAIE,eACA,OAAO;QACH,SAASA,aAAa,CAAC,EAAE;QACzB,UAAU;QACV,OAAOA,aAAa,CAAC,EAAE;IAC3B;IAEJ,MAAM,IAAIC,MACN,2DACA,sBACA;QACIH;IACJ;AAER;AAgBO,MAAMI,cAAc,CAACC;IACxB,MAAM,EAAEC,KAAK,EAAEN,MAAM,EAAEO,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAC3C,MAAM,EAAEI,OAAO,EAAE,UAAUC,eAAe,EAAEC,KAAK,EAAE,GAAGZ,gBAAgBC;IAEtE,MAAMY,QAAQC,OAAO,MAAM,CAACN,QAAQ,IAAI,CAACO,CAAAA;QAIrC,MAAMC,WAAWD,EAAE,OAAO,CAAC,EAAE,EAAE,YAAY;QAC3C,IAAIC,YAAYL,iBACZ,OAAOI,EAAE,OAAO,KAAKL;QAEzB,IAAIK,EAAE,OAAO,CAAC,MAAM,GAAG,GACnB,OAAO;QAEX,OAAOA,EAAE,OAAO,KAAKL;IACzB;IAEA,MAAMO,SAASR,QACV,MAAM,CAA6BS,2BAA2B,IAAI,EAClE,OAAO,GACP,IAAI,CAACD,CAAAA,SACKA,OAAO,MAAM,CAAC;YACjBV;YACAM;YACAH;YACAE;YACAX;QACJ;IAGR,IAAIgB,QACA,OAAOA,OAAO,UAAU,CAAC;QACrBV;QACAG;QACAE;QACAX;QACAY;QACAL;IACJ;IACG,IAAI,CAACK,OACR,MAAM,IAAIT,MACN,sDACA,uBACA;QACIM;QACAF;IACJ;IAGR,MAAMW,YAAYN,MAAM,UAAU,CAAC;QAC/BA;IACJ;IACA,OAAO;QACHA;QACAH;QACAS;QACA,SAASP,AAAU,WAAVA;IACb;AACJ"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { CmsContext, CmsEntry, CmsEntryListWhere, CmsEntryValues } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
-
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import type { Field } from "./types.js";
|
|
4
|
-
interface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {
|
|
5
|
-
plugins: PluginsContainer;
|
|
6
|
-
container: CmsContext["container"];
|
|
7
|
-
items: CmsEntry<T>[];
|
|
8
|
-
where: Partial<CmsEntryListWhere>;
|
|
9
|
-
fields: Record<string, Field>;
|
|
10
|
-
fullTextSearch?: {
|
|
11
|
-
term?: string;
|
|
12
|
-
fields?: string[];
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export declare const filter: <T extends CmsEntryValues = CmsEntryValues>(params: IFilterParams<T>) => CmsEntry<T>[];
|
|
16
|
-
export {};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import error from "@webiny/error";
|
|
2
|
-
import { createFullTextSearch } from "./fullTextSearch.js";
|
|
3
|
-
import { createExpressions } from "./createExpressions.js";
|
|
4
|
-
import { transformValue } from "./transform.js";
|
|
5
|
-
import { getValue } from "./getValue.js";
|
|
6
|
-
import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
7
|
-
const executeFilter = (params)=>{
|
|
8
|
-
const { value, filter } = params;
|
|
9
|
-
const canUse = filter.filter.canUse({
|
|
10
|
-
value,
|
|
11
|
-
compareValue: filter.compareValue
|
|
12
|
-
});
|
|
13
|
-
if (!canUse) return true;
|
|
14
|
-
const matched = filter.filter.matches({
|
|
15
|
-
value,
|
|
16
|
-
compareValue: filter.compareValue
|
|
17
|
-
});
|
|
18
|
-
if (filter.negate) return false === matched;
|
|
19
|
-
return matched;
|
|
20
|
-
};
|
|
21
|
-
const executeExpressions = (params)=>{
|
|
22
|
-
const { expressions, getCachedValue, filters, condition } = params;
|
|
23
|
-
if (0 === expressions.length && 0 === filters.length) return true;
|
|
24
|
-
for (const filter of filters){
|
|
25
|
-
const value = getCachedValue(filter);
|
|
26
|
-
const result = executeFilter({
|
|
27
|
-
value,
|
|
28
|
-
filter
|
|
29
|
-
});
|
|
30
|
-
if (!result) return false;
|
|
31
|
-
}
|
|
32
|
-
for (const expression of expressions){
|
|
33
|
-
const result = executeExpressions({
|
|
34
|
-
...expression,
|
|
35
|
-
getCachedValue
|
|
36
|
-
});
|
|
37
|
-
if (result && "OR" === condition) return true;
|
|
38
|
-
if (!result && "AND" == condition) return false;
|
|
39
|
-
}
|
|
40
|
-
return "OR" !== condition;
|
|
41
|
-
};
|
|
42
|
-
const filter_filter = (params)=>{
|
|
43
|
-
const { items: records, where, plugins, fields, fullTextSearch, container } = params;
|
|
44
|
-
const valueFilterRegistry = container.resolve(ValueFilterRegistry);
|
|
45
|
-
const keys = Object.keys(where);
|
|
46
|
-
if (0 === keys.length && !fullTextSearch) return records;
|
|
47
|
-
const expression = createExpressions({
|
|
48
|
-
plugins,
|
|
49
|
-
where,
|
|
50
|
-
fields,
|
|
51
|
-
container
|
|
52
|
-
});
|
|
53
|
-
if (0 === expression.filters.length && 0 === expression.expressions.length && !fullTextSearch?.term) return records;
|
|
54
|
-
const fullTextSearchFilter = valueFilterRegistry.get("contains");
|
|
55
|
-
if (!fullTextSearchFilter) throw new error('Missing "contains" plugin to run the full-text search.', "MISSING_PLUGIN");
|
|
56
|
-
const search = createFullTextSearch({
|
|
57
|
-
term: fullTextSearch?.term,
|
|
58
|
-
targetFields: fullTextSearch?.fields,
|
|
59
|
-
fields,
|
|
60
|
-
filter: fullTextSearchFilter
|
|
61
|
-
});
|
|
62
|
-
return records.filter((record)=>{
|
|
63
|
-
const cachedValues = {};
|
|
64
|
-
const getCachedValue = (filter)=>{
|
|
65
|
-
const { path } = filter;
|
|
66
|
-
if (void 0 !== cachedValues[path]) return cachedValues[path];
|
|
67
|
-
const plainValue = getValue(record, path);
|
|
68
|
-
const rawValue = transformValue({
|
|
69
|
-
value: plainValue,
|
|
70
|
-
transform: filter.transformValue
|
|
71
|
-
});
|
|
72
|
-
cachedValues[path] = rawValue;
|
|
73
|
-
return rawValue;
|
|
74
|
-
};
|
|
75
|
-
const exprResult = executeExpressions({
|
|
76
|
-
...expression,
|
|
77
|
-
getCachedValue
|
|
78
|
-
});
|
|
79
|
-
if (!exprResult || !search) return exprResult;
|
|
80
|
-
return search(record);
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
export { filter_filter as filter };
|
|
84
|
-
|
|
85
|
-
//# sourceMappingURL=filter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/filtering/filter.js","sources":["../../../../src/operations/entry/filtering/filter.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { createFullTextSearch } from \"./fullTextSearch.js\";\nimport type { Expression, ExpressionCondition, Filter } from \"./createExpressions.js\";\nimport { createExpressions } from \"./createExpressions.js\";\nimport { transformValue } from \"./transform.js\";\nimport { getValue } from \"~/operations/entry/filtering/getValue.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n /**\n * We need to check if the filter can be used.\n * If it cannot, we will just return true.\n */\n const canUse = filter.filter.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.filter.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = <T extends CmsEntryValues = CmsEntryValues>(\n params: IFilterParams<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch, container } = params;\n\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields,\n container\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchFilter = valueFilterRegistry.get(\"contains\");\n if (!fullTextSearchFilter) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n filter: fullTextSearchFilter\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"names":["executeFilter","params","value","filter","canUse","matched","executeExpressions","expressions","getCachedValue","filters","condition","result","expression","records","where","plugins","fields","fullTextSearch","container","valueFilterRegistry","ValueFilterRegistry","keys","Object","createExpressions","fullTextSearchFilter","WebinyError","search","createFullTextSearch","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","exprResult"],"mappings":";;;;;;AAqBA,MAAMA,gBAAgB,CAACC;IACnB,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGF;IAM1B,MAAMG,SAASD,OAAO,MAAM,CAAC,MAAM,CAAC;QAChCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAI,CAACC,QACD,OAAO;IAGX,MAAMC,UAAUF,OAAO,MAAM,CAAC,OAAO,CAAC;QAClCD;QACA,cAAcC,OAAO,YAAY;IACrC;IACA,IAAIA,OAAO,MAAM,EACb,OAAOE,AAAY,UAAZA;IAEX,OAAOA;AACX;AASA,MAAMC,qBAAqB,CAACL;IACxB,MAAM,EAAEM,WAAW,EAAEC,cAAc,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGT;IAC5D,IAAIM,AAAuB,MAAvBA,YAAY,MAAM,IAAUE,AAAmB,MAAnBA,QAAQ,MAAM,EAC1C,OAAO;IAKX,KAAK,MAAMN,UAAUM,QAAS;QAC1B,MAAMP,QAAQM,eAAeL;QAE7B,MAAMQ,SAASX,cAAc;YACzBE;YACAC;QACJ;QAKA,IAAI,CAACQ,QACD,OAAO;IAEf;IAIA,KAAK,MAAMC,cAAcL,YAAa;QAClC,MAAMI,SAASL,mBAAmB;YAC9B,GAAGM,UAAU;YACbJ;QACJ;QACA,IAAIG,UAAUD,AAAc,SAAdA,WACV,OAAO;QACJ,IAAI,CAACC,UAAUD,AAAa,SAAbA,WAClB,OAAO;IAEf;IAMA,OAAOA,AAAc,SAAdA;AACX;AAcO,MAAMP,gBAAS,CAClBF;IAEA,MAAM,EAAE,OAAOY,OAAO,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGjB;IAE9E,MAAMkB,sBAAsBD,UAAU,OAAO,CAACE;IAE9C,MAAMC,OAAOC,OAAO,IAAI,CAACR;IACzB,IAAIO,AAAgB,MAAhBA,KAAK,MAAM,IAAU,CAACJ,gBACtB,OAAOJ;IAEX,MAAMD,aAAaW,kBAAkB;QACjCR;QACAD;QACAE;QACAE;IACJ;IAKA,IACIN,AAA8B,MAA9BA,WAAW,OAAO,CAAC,MAAM,IACzBA,AAAkC,MAAlCA,WAAW,WAAW,CAAC,MAAM,IAC7B,CAACK,gBAAgB,MAEjB,OAAOJ;IAKX,MAAMW,uBAAuBL,oBAAoB,GAAG,CAAC;IACrD,IAAI,CAACK,sBACD,MAAM,IAAIC,MACN,0DACA;IAIR,MAAMC,SAASC,qBAAqB;QAChC,MAAMV,gBAAgB;QACtB,cAAcA,gBAAgB;QAC9BD;QACA,QAAQQ;IACZ;IAEA,OAAOX,QAAQ,MAAM,CAACe,CAAAA;QAClB,MAAMC,eAAoC,CAAC;QAE3C,MAAMrB,iBAAiB,CAACL;YACpB,MAAM,EAAE2B,IAAI,EAAE,GAAG3B;YACjB,IAAI0B,AAAuBE,WAAvBF,YAAY,CAACC,KAAK,EAClB,OAAOD,YAAY,CAACC,KAAK;YAE7B,MAAME,aAAaC,SAASL,QAAQE;YAEpC,MAAMI,WAAWC,eAAe;gBAC5B,OAAOH;gBACP,WAAW7B,OAAO,cAAc;YACpC;YAEA0B,YAAY,CAACC,KAAK,GAAGI;YACrB,OAAOA;QACX;QAEA,MAAME,aAAa9B,mBAAmB;YAAE,GAAGM,UAAU;YAAEJ;QAAe;QAKtE,IAAI,CAAC4B,cAAc,CAACV,QAChB,OAAOU;QAGX,OAAOV,OAAOE;IAClB;AACJ"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
-
import type { Field } from "./types.js";
|
|
3
|
-
import { ValueFilter } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
4
|
-
interface Params {
|
|
5
|
-
term?: string;
|
|
6
|
-
targetFields?: string[];
|
|
7
|
-
fields: Record<string, Field>;
|
|
8
|
-
filter: ValueFilter.Interface;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
12
|
-
*/
|
|
13
|
-
export declare const createFullTextSearch: (params: Params) => ((item: CmsEntry) => boolean) | null;
|
|
14
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import error from "@webiny/error";
|
|
2
|
-
import { getValue } from "./getValue.js";
|
|
3
|
-
const createFullTextSearch = (params)=>{
|
|
4
|
-
const { term, targetFields, fields: fieldDefinitions, filter } = params;
|
|
5
|
-
if (!term || 0 === term.trim().length || !targetFields || 0 === targetFields.length) return null;
|
|
6
|
-
return (item)=>{
|
|
7
|
-
for (const target of targetFields){
|
|
8
|
-
const field = fieldDefinitions[target];
|
|
9
|
-
if (!field) throw new error(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
|
|
10
|
-
target
|
|
11
|
-
});
|
|
12
|
-
const value = getValue(item, target);
|
|
13
|
-
if (value) {
|
|
14
|
-
if (true === filter.matches({
|
|
15
|
-
value,
|
|
16
|
-
compareValue: term
|
|
17
|
-
})) return true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export { createFullTextSearch };
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=fullTextSearch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/filtering/fullTextSearch.js","sources":["../../../../src/operations/entry/filtering/fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Field } from \"./types.js\";\nimport { getValue } from \"./getValue.js\";\nimport { ValueFilter } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n filter: ValueFilter.Interface;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, filter } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item, target);\n if (!value) {\n continue;\n }\n if (filter.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"names":["createFullTextSearch","params","term","targetFields","fieldDefinitions","filter","item","target","field","WebinyError","value","getValue"],"mappings":";;AAgBO,MAAMA,uBAAuB,CAACC;IACjC,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAE,QAAQC,gBAAgB,EAAEC,MAAM,EAAE,GAAGJ;IACjE,IAAI,CAACC,QAAQA,AAAuB,MAAvBA,KAAK,IAAI,GAAG,MAAM,IAAU,CAACC,gBAAgBA,AAAwB,MAAxBA,aAAa,MAAM,EACzE,OAAO;IAEX,OAAO,CAACG;QACJ,KAAK,MAAMC,UAAUJ,aAAc;YAI/B,MAAMK,QAAQJ,gBAAgB,CAACG,OAAO;YAEtC,IAAI,CAACC,OACD,MAAM,IAAIC,MAAY,CAAC,eAAe,EAAEF,OAAO,eAAe,CAAC,EAAE,iBAAiB;gBAC9EA;YACJ;YAEJ,MAAMG,QAAQC,SAASL,MAAMC;YAC7B,IAAKG,OAGL;gBAAA,IAAIL,AAAkD,SAAlDA,OAAO,OAAO,CAAC;oBAAEK;oBAAO,cAAcR;gBAAK,IAC3C,OAAO;YACX;QACJ;QACA,OAAO;IACX;AACJ"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const addArrayResult = (target, result)=>{
|
|
2
|
-
for (const r of result)if (!target.some((t)=>r === t)) target.push(r);
|
|
3
|
-
};
|
|
4
|
-
const find = (target, input)=>{
|
|
5
|
-
const paths = [
|
|
6
|
-
...input
|
|
7
|
-
];
|
|
8
|
-
const path = paths.shift();
|
|
9
|
-
if (!path) return;
|
|
10
|
-
const value = target?.[path];
|
|
11
|
-
if (void 0 === value) return;
|
|
12
|
-
if (0 === paths.length) return value;
|
|
13
|
-
if (Array.isArray(value)) {
|
|
14
|
-
if (0 === value.length) return;
|
|
15
|
-
return value.reduce((collection, v)=>{
|
|
16
|
-
const result = find(v, paths);
|
|
17
|
-
if (void 0 === result) return collection;
|
|
18
|
-
if (Array.isArray(result)) {
|
|
19
|
-
addArrayResult(collection, result);
|
|
20
|
-
return collection;
|
|
21
|
-
}
|
|
22
|
-
collection.push(result);
|
|
23
|
-
return collection;
|
|
24
|
-
}, []);
|
|
25
|
-
}
|
|
26
|
-
return find(value, paths);
|
|
27
|
-
};
|
|
28
|
-
const getValue = (target, input)=>{
|
|
29
|
-
const paths = Array.isArray(input) ? input : input.split(".");
|
|
30
|
-
if (0 === paths.length) throw new Error("Path is empty!");
|
|
31
|
-
const filtered = paths.filter(Boolean);
|
|
32
|
-
if (paths.length !== filtered.length) throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
|
|
33
|
-
return find(target, paths);
|
|
34
|
-
};
|
|
35
|
-
export { getValue };
|
|
36
|
-
|
|
37
|
-
//# sourceMappingURL=getValue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/filtering/getValue.js","sources":["../../../../src/operations/entry/filtering/getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any> | undefined, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n }\n\n const value = target?.[path];\n if (value === undefined) {\n return undefined;\n }\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"names":["addArrayResult","target","result","r","t","find","input","paths","path","value","undefined","Array","collection","v","getValue","Error","filtered","Boolean"],"mappings":"AAAA,MAAMA,iBAAiB,CAACC,QAAeC;IACnC,KAAK,MAAMC,KAAKD,OACZ,KAAID,OAAO,IAAI,CAACG,CAAAA,IAAKD,MAAMC,IAG3BH,OAAO,IAAI,CAACE;AAEpB;AAKA,MAAME,OAAO,CAACJ,QAAyCK;IACnD,MAAMC,QAAQ;WAAID;KAAM;IACxB,MAAME,OAAOD,MAAM,KAAK;IAExB,IAAI,CAACC,MACD;IAGJ,MAAMC,QAAQR,QAAQ,CAACO,KAAK;IAC5B,IAAIC,AAAUC,WAAVD,OACA;IAEJ,IAAIF,AAAiB,MAAjBA,MAAM,MAAM,EACZ,OAAOE;IACJ,IAAIE,MAAM,OAAO,CAACF,QAAQ;QAC7B,IAAIA,AAAiB,MAAjBA,MAAM,MAAM,EACZ;QAEJ,OAAOA,MAAM,MAAM,CAAQ,CAACG,YAAYC;YACpC,MAAMX,SAASG,KAAKQ,GAAGN;YACvB,IAAIL,AAAWQ,WAAXR,QACA,OAAOU;YACJ,IAAID,MAAM,OAAO,CAACT,SAAS;gBAC9BF,eAAeY,YAAYV;gBAC3B,OAAOU;YACX;YACAA,WAAW,IAAI,CAACV;YAChB,OAAOU;QACX,GAAG,EAAE;IACT;IACA,OAAOP,KAAKI,OAAOF;AACvB;AAKO,MAAMO,WAAW,CAACb,QAA6BK;IAClD,MAAMC,QAAQI,MAAM,OAAO,CAACL,SAASA,QAAQA,MAAM,KAAK,CAAC;IACzD,IAAIC,AAAiB,MAAjBA,MAAM,MAAM,EACZ,MAAM,IAAIQ,MAAM;IAEpB,MAAMC,WAAWT,MAAM,MAAM,CAACU;IAC9B,IAAIV,MAAM,MAAM,KAAKS,SAAS,MAAM,EAChC,MAAM,IAAID,MACN,CAAC,8DAA8D,EAAER,MAAM,IAAI,CACvE,KACF,IAAI,EAAES,SAAS,IAAI,CAAC,KAAK,CAAC,CAAC;IAIrC,OAAOX,KAAKJ,QAAQM;AACxB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Plugin, PluginsContainer } from "@webiny/plugins/types.js";
|
|
2
|
-
interface Params {
|
|
3
|
-
plugins: PluginsContainer;
|
|
4
|
-
type: string;
|
|
5
|
-
property: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const getMappedPlugins: <T extends Plugin>(params: Params) => Record<string, T>;
|
|
8
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import error from "@webiny/error";
|
|
2
|
-
const getMappedPlugins = (params)=>{
|
|
3
|
-
const { plugins: pluginsContainer, type, property } = params;
|
|
4
|
-
const plugins = pluginsContainer.byType(type);
|
|
5
|
-
if (0 === plugins.length) return {};
|
|
6
|
-
return plugins.reduce((collection, plugin)=>{
|
|
7
|
-
const key = plugin[property];
|
|
8
|
-
if ("string" != typeof key) throw new error("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
|
|
9
|
-
type,
|
|
10
|
-
property
|
|
11
|
-
});
|
|
12
|
-
collection[key] = plugin;
|
|
13
|
-
return collection;
|
|
14
|
-
}, {});
|
|
15
|
-
};
|
|
16
|
-
export { getMappedPlugins };
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=mapPlugins.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/filtering/mapPlugins.js","sources":["../../../../src/operations/entry/filtering/mapPlugins.ts"],"sourcesContent":["import type { Plugin, PluginsContainer } from \"@webiny/plugins/types.js\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\nexport const getMappedPlugins = <T extends Plugin>(params: Params) => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n return {};\n }\n return plugins.reduce<Record<string, T>>((collection, plugin) => {\n const key: keyof typeof plugin = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {});\n};\n"],"names":["getMappedPlugins","params","pluginsContainer","type","property","plugins","collection","plugin","key","WebinyError"],"mappings":";AAQO,MAAMA,mBAAmB,CAAmBC;IAC/C,MAAM,EAAE,SAASC,gBAAgB,EAAEC,IAAI,EAAEC,QAAQ,EAAE,GAAGH;IACtD,MAAMI,UAAUH,iBAAiB,MAAM,CAAIC;IAC3C,IAAIE,AAAmB,MAAnBA,QAAQ,MAAM,EACd,OAAO,CAAC;IAEZ,OAAOA,QAAQ,MAAM,CAAoB,CAACC,YAAYC;QAClD,MAAMC,MAA2BD,MAAM,CAACH,SAAS;QACjD,IAAI,AAAe,YAAf,OAAOI,KACP,MAAM,IAAIC,MACN,oDACA,yBACA;YACIN;YACAC;QACJ;QAGRE,UAAU,CAACE,IAAI,GAAGD;QAClB,OAAOD;IACX,GAAG,CAAC;AACR"}
|