@webiny/api-headless-cms-storage 0.0.0-unstable.0156a4c312
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/LICENSE +21 -0
- package/README.md +11 -0
- package/cms/storageHelpers.d.ts +9 -0
- package/cms/storageHelpers.js +45 -0
- package/cms/storageHelpers.js.map +1 -0
- package/features/FilterRegistriesFeature.d.ts +9 -0
- package/features/FilterRegistriesFeature.js +17 -0
- package/features/FilterRegistriesFeature.js.map +1 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.d.ts +9 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js +26 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js.map +1 -0
- package/features/fieldFilterCreate/FieldFilterCreateRegistry.d.ts +7 -0
- package/features/fieldFilterCreate/FieldFilterCreateRegistry.js +20 -0
- package/features/fieldFilterCreate/FieldFilterCreateRegistry.js.map +1 -0
- package/features/fieldFilterCreate/abstractions.d.ts +41 -0
- package/features/fieldFilterCreate/abstractions.js +5 -0
- package/features/fieldFilterCreate/abstractions.js.map +1 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.d.ts +9 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js +20 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js.map +1 -0
- package/features/fieldFilterPath/FieldFilterPathRegistry.d.ts +6 -0
- package/features/fieldFilterPath/FieldFilterPathRegistry.js +14 -0
- package/features/fieldFilterPath/FieldFilterPathRegistry.js.map +1 -0
- package/features/fieldFilterPath/abstractions.d.ts +16 -0
- package/features/fieldFilterPath/abstractions.js +5 -0
- package/features/fieldFilterPath/abstractions.js.map +1 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.d.ts +9 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js +17 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js.map +1 -0
- package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.d.ts +6 -0
- package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js +14 -0
- package/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js.map +1 -0
- package/features/fieldFilterValueTransform/abstractions.d.ts +14 -0
- package/features/fieldFilterValueTransform/abstractions.js +5 -0
- package/features/fieldFilterValueTransform/abstractions.js.map +1 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.d.ts +8 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.js +11 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.js.map +1 -0
- package/features/fieldSorting/FieldSortingRegistry.d.ts +6 -0
- package/features/fieldSorting/FieldSortingRegistry.js +14 -0
- package/features/fieldSorting/FieldSortingRegistry.js.map +1 -0
- package/features/fieldSorting/abstractions.d.ts +40 -0
- package/features/fieldSorting/abstractions.js +5 -0
- package/features/fieldSorting/abstractions.js.map +1 -0
- package/filtering/expressions/createExpressions.d.ts +29 -0
- package/filtering/expressions/createExpressions.js +109 -0
- package/filtering/expressions/createExpressions.js.map +1 -0
- package/filtering/fields/createFields.d.ts +15 -0
- package/filtering/fields/createFields.js +81 -0
- package/filtering/fields/createFields.js.map +1 -0
- package/filtering/fields/extractSort.d.ts +17 -0
- package/filtering/fields/extractSort.js +59 -0
- package/filtering/fields/extractSort.js.map +1 -0
- package/filtering/fields/systemFields.d.ts +5 -0
- package/filtering/fields/systemFields.js +165 -0
- package/filtering/fields/systemFields.js.map +1 -0
- package/filtering/fields/types.d.ts +19 -0
- package/filtering/fields/types.js +0 -0
- package/filtering/filter.d.ts +19 -0
- package/filtering/filter.js +84 -0
- package/filtering/filter.js.map +1 -0
- package/filtering/fullTextSearch.d.ts +11 -0
- package/filtering/fullTextSearch.js +25 -0
- package/filtering/fullTextSearch.js.map +1 -0
- package/filtering/getValue.d.ts +1 -0
- package/filtering/getValue.js +37 -0
- package/filtering/getValue.js.map +1 -0
- package/filtering/mapPlugins.d.ts +8 -0
- package/filtering/mapPlugins.js +18 -0
- package/filtering/mapPlugins.js.map +1 -0
- package/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/filtering/plugins/defaultFilterCreate.js +33 -0
- package/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/filtering/plugins/index.d.ts +1 -0
- package/filtering/plugins/index.js +13 -0
- package/filtering/plugins/index.js.map +1 -0
- package/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/filtering/plugins/objectFilterCreate.js +68 -0
- package/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/filtering/plugins/refFilterCreate.d.ts +3 -0
- package/filtering/plugins/refFilterCreate.js +63 -0
- package/filtering/plugins/refFilterCreate.js.map +1 -0
- package/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/filtering/plugins/searchableJsonFilterCreate.js +56 -0
- package/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/filtering/sort.d.ts +12 -0
- package/filtering/sort.js +41 -0
- package/filtering/sort.js.map +1 -0
- package/filtering/transform.d.ts +6 -0
- package/filtering/transform.js +7 -0
- package/filtering/transform.js.map +1 -0
- package/filtering/values.d.ts +2 -0
- package/filtering/values.js +15 -0
- package/filtering/values.js.map +1 -0
- package/filtering/where.d.ts +5 -0
- package/filtering/where.js +22 -0
- package/filtering/where.js.map +1 -0
- package/handlers/datetimeTransformHandler.d.ts +2 -0
- package/handlers/datetimeTransformHandler.js +34 -0
- package/handlers/datetimeTransformHandler.js.map +1 -0
- package/handlers/defaultFilterCreateHandler.d.ts +2 -0
- package/handlers/defaultFilterCreateHandler.js +27 -0
- package/handlers/defaultFilterCreateHandler.js.map +1 -0
- package/handlers/locationFolderIdPathHandler.d.ts +2 -0
- package/handlers/locationFolderIdPathHandler.js +18 -0
- package/handlers/locationFolderIdPathHandler.js.map +1 -0
- package/handlers/objectFilterCreateHandler.d.ts +2 -0
- package/handlers/objectFilterCreateHandler.js +62 -0
- package/handlers/objectFilterCreateHandler.js.map +1 -0
- package/handlers/plainObjectPathHandler.d.ts +2 -0
- package/handlers/plainObjectPathHandler.js +14 -0
- package/handlers/plainObjectPathHandler.js.map +1 -0
- package/handlers/refFilterCreateHandler.d.ts +2 -0
- package/handlers/refFilterCreateHandler.js +57 -0
- package/handlers/refFilterCreateHandler.js.map +1 -0
- package/handlers/searchableJsonFilterCreateHandler.d.ts +2 -0
- package/handlers/searchableJsonFilterCreateHandler.js +43 -0
- package/handlers/searchableJsonFilterCreateHandler.js.map +1 -0
- package/index.d.ts +24 -0
- package/index.js +19 -0
- package/package.json +35 -0
- package/path/locationFolderId.d.ts +2 -0
- package/path/locationFolderId.js +21 -0
- package/path/locationFolderId.js.map +1 -0
- package/path/plainObject.d.ts +2 -0
- package/path/plainObject.js +16 -0
- package/path/plainObject.js.map +1 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +23 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js +30 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +39 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +20 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +37 -0
- package/plugins/CmsEntryFieldSortingPlugin.js +20 -0
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +21 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js +19 -0
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +7 -0
- package/plugins/index.js +4 -0
- package/transforms/datetime.d.ts +2 -0
- package/transforms/datetime.js +37 -0
- package/transforms/datetime.js.map +1 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { extractWhereParams } from "../where.js";
|
|
3
|
+
import { transformValue } from "../transform.js";
|
|
4
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
5
|
+
import { getWhereValues } from "../values.js";
|
|
6
|
+
const createExpressions = (params)=>{
|
|
7
|
+
const { where, filterCreateRegistry, transformRegistry, fields, valueFilterRegistry } = params;
|
|
8
|
+
const getHandler = (type)=>{
|
|
9
|
+
const fieldType = getBaseFieldType({
|
|
10
|
+
type
|
|
11
|
+
});
|
|
12
|
+
const handler = filterCreateRegistry.get(fieldType) || filterCreateRegistry.getDefault();
|
|
13
|
+
if (handler) return handler;
|
|
14
|
+
throw new error(`There is no filter create handler for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_HANDLER", {
|
|
15
|
+
fieldType
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const createExpression = ({ where, condition })=>{
|
|
19
|
+
const expression = {
|
|
20
|
+
filters: [],
|
|
21
|
+
expressions: [],
|
|
22
|
+
condition
|
|
23
|
+
};
|
|
24
|
+
for(const key in where){
|
|
25
|
+
const value = where[key];
|
|
26
|
+
if (void 0 === value) continue;
|
|
27
|
+
if ("AND" === key) {
|
|
28
|
+
const childWhereList = getWhereValues(value, key);
|
|
29
|
+
const childExpression = {
|
|
30
|
+
condition: "AND",
|
|
31
|
+
filters: [],
|
|
32
|
+
expressions: []
|
|
33
|
+
};
|
|
34
|
+
for (const childWhere of childWhereList){
|
|
35
|
+
const result = createExpression({
|
|
36
|
+
where: childWhere,
|
|
37
|
+
condition: "AND"
|
|
38
|
+
});
|
|
39
|
+
childExpression.expressions.push(result);
|
|
40
|
+
}
|
|
41
|
+
expression.expressions.push(childExpression);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if ("OR" === key) {
|
|
45
|
+
const childWhereList = getWhereValues(value, key);
|
|
46
|
+
const childExpression = {
|
|
47
|
+
condition: "OR",
|
|
48
|
+
filters: [],
|
|
49
|
+
expressions: []
|
|
50
|
+
};
|
|
51
|
+
for (const childWhere of childWhereList){
|
|
52
|
+
const result = createExpression({
|
|
53
|
+
where: childWhere,
|
|
54
|
+
condition: "AND"
|
|
55
|
+
});
|
|
56
|
+
childExpression.expressions.push(result);
|
|
57
|
+
}
|
|
58
|
+
expression.expressions.push(childExpression);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const whereParams = extractWhereParams(key);
|
|
62
|
+
if (!whereParams) continue;
|
|
63
|
+
const { fieldId, operation, negate } = whereParams;
|
|
64
|
+
const field = fields[fieldId];
|
|
65
|
+
if (!field) throw new error(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
66
|
+
fieldId
|
|
67
|
+
});
|
|
68
|
+
const handler = getHandler(field.type);
|
|
69
|
+
const fieldType = getBaseFieldType(field);
|
|
70
|
+
const transformHandler = transformRegistry.get(fieldType);
|
|
71
|
+
const transformValueCallable = (value)=>{
|
|
72
|
+
if (!transformHandler) return value;
|
|
73
|
+
return transformHandler.transform({
|
|
74
|
+
field,
|
|
75
|
+
value
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const result = handler.create({
|
|
79
|
+
key,
|
|
80
|
+
value,
|
|
81
|
+
valueFilterRegistry,
|
|
82
|
+
transformRegistry,
|
|
83
|
+
getHandler,
|
|
84
|
+
operation,
|
|
85
|
+
negate,
|
|
86
|
+
field,
|
|
87
|
+
fields,
|
|
88
|
+
compareValue: transformValue({
|
|
89
|
+
value,
|
|
90
|
+
transform: transformValueCallable
|
|
91
|
+
}),
|
|
92
|
+
transformValue: transformValueCallable
|
|
93
|
+
});
|
|
94
|
+
if (!(!result || Array.isArray(result) && 0 === result.length)) expression.filters.push(...Array.isArray(result) ? result : [
|
|
95
|
+
result
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
return expression;
|
|
99
|
+
};
|
|
100
|
+
const expression = createExpression({
|
|
101
|
+
where,
|
|
102
|
+
condition: "AND"
|
|
103
|
+
});
|
|
104
|
+
if (expression.filters.length > 0 || 1 !== expression.expressions.length) return expression;
|
|
105
|
+
return expression.expressions[0];
|
|
106
|
+
};
|
|
107
|
+
export { createExpressions };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=createExpressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/expressions/createExpressions.js","sources":["../../../src/filtering/expressions/createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Field } from \"../fields/types.js\";\nimport { extractWhereParams } from \"../where.js\";\nimport { transformValue } from \"../transform.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\nimport { ValueFilter, ValueFilterRegistry } from \"@webiny/db-utils\";\nimport type { FieldFilterCreateRegistry } from \"../../features/fieldFilterCreate/abstractions.js\";\nimport type { FieldFilterValueTransformRegistry } from \"../../features/fieldFilterValueTransform/abstractions.js\";\nimport { getWhereValues } from \"../values.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface ICreateExpressionsParams {\n filterCreateRegistry: FieldFilterCreateRegistry.Interface;\n transformRegistry: FieldFilterValueTransformRegistry.Interface;\n valueFilterRegistry: ValueFilterRegistry.Interface;\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, filterCreateRegistry, transformRegistry, fields, valueFilterRegistry } = params;\n\n const getHandler = (type: string) => {\n const fieldType = getBaseFieldType({ type });\n const handler = filterCreateRegistry.get(fieldType) || filterCreateRegistry.getDefault();\n if (handler) {\n return handler;\n }\n throw new WebinyError(\n `There is no filter create handler for the field type \"${fieldType}\".`,\n \"MISSING_FILTER_CREATE_HANDLER\",\n { fieldType }\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 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 if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\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 { fieldId }\n );\n }\n\n const handler = getHandler(field.type);\n const fieldType = getBaseFieldType(field);\n const transformHandler = transformRegistry.get(fieldType);\n\n const transformValueCallable = (value: any) => {\n if (!transformHandler) {\n return value;\n }\n return transformHandler.transform({ field, value });\n };\n\n const result = handler.create({\n key,\n value,\n valueFilterRegistry,\n transformRegistry,\n getHandler,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\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 (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"names":["createExpressions","params","where","filterCreateRegistry","transformRegistry","fields","valueFilterRegistry","getHandler","type","fieldType","getBaseFieldType","handler","WebinyError","createExpression","condition","expression","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","whereParams","extractWhereParams","fieldId","operation","negate","field","transformHandler","transformValueCallable","transformValue","Array"],"mappings":";;;;;AA0CO,MAAMA,oBAAoB,CAACC;IAC9B,MAAM,EAAEC,KAAK,EAAEC,oBAAoB,EAAEC,iBAAiB,EAAEC,MAAM,EAAEC,mBAAmB,EAAE,GAAGL;IAExF,MAAMM,aAAa,CAACC;QAChB,MAAMC,YAAYC,iBAAiB;YAAEF;QAAK;QAC1C,MAAMG,UAAUR,qBAAqB,GAAG,CAACM,cAAcN,qBAAqB,UAAU;QACtF,IAAIQ,SACA,OAAOA;QAEX,MAAM,IAAIC,MACN,CAAC,sDAAsD,EAAEH,UAAU,EAAE,CAAC,EACtE,iCACA;YAAEA;QAAU;IAEpB;IAEA,MAAMI,mBAAmB,CAAC,EAAEX,KAAK,EAAEY,SAAS,EAA0B;QAClE,MAAMC,aAAyB;YAC3B,SAAS,EAAE;YACX,aAAa,EAAE;YACfD;QACJ;QAEA,IAAK,MAAME,OAAOd,MAAO;YACrB,MAAMe,QAAQf,KAAK,CAACc,IAA0B;YAC9C,IAAIC,AAAUC,WAAVD,OACA;YAGJ,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,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AAS;gBAACA;aAAO;QACzE;QAEA,OAAOR;IACX;IAEA,MAAMA,aAAaF,iBAAiB;QAChCX;QACA,WAAW;IACf;IAEA,IAAIa,WAAW,OAAO,CAAC,MAAM,GAAG,KAAKA,AAAkC,MAAlCA,WAAW,WAAW,CAAC,MAAM,EAC9D,OAAOA;IAEX,OAAOA,WAAW,WAAW,CAAC,EAAE;AACpC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { Field } from "./types.js";
|
|
3
|
+
import type { FieldFilterPathRegistry } from "../../features/fieldFilterPath/abstractions.js";
|
|
4
|
+
import type { FieldFilterValueTransformRegistry } from "../../features/fieldFilterValueTransform/abstractions.js";
|
|
5
|
+
interface Params {
|
|
6
|
+
fields: CmsModelField[];
|
|
7
|
+
/** Fields registered as `CmsEntrySystemField`, filterable under `system`. */
|
|
8
|
+
systemFields?: CmsModelField[];
|
|
9
|
+
pathRegistry: FieldFilterPathRegistry.Interface;
|
|
10
|
+
transformRegistry: FieldFilterValueTransformRegistry.Interface;
|
|
11
|
+
}
|
|
12
|
+
export declare const createFields: (params: Params) => {
|
|
13
|
+
[x: string]: Field;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createSystemFields } from "./systemFields.js";
|
|
2
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
3
|
+
const createFieldCollection = (params)=>{
|
|
4
|
+
const { fields, parents, pathRegistry, transformRegistry, system } = params;
|
|
5
|
+
return fields.reduce((collection, field)=>{
|
|
6
|
+
const fieldType = getBaseFieldType(field);
|
|
7
|
+
const transformHandler = transformRegistry.get(fieldType);
|
|
8
|
+
const pathHandler = pathRegistry.get(fieldType);
|
|
9
|
+
const fieldId = [
|
|
10
|
+
...parents,
|
|
11
|
+
{
|
|
12
|
+
fieldId: field.fieldId,
|
|
13
|
+
list: field.list
|
|
14
|
+
}
|
|
15
|
+
].map((f)=>f.fieldId).join(".");
|
|
16
|
+
collection[fieldId] = {
|
|
17
|
+
...field,
|
|
18
|
+
parents,
|
|
19
|
+
system,
|
|
20
|
+
createPath: (pathParams)=>{
|
|
21
|
+
if (pathHandler && pathHandler.canUse(field, parents.map((p)=>p.fieldId))) return pathHandler.createPath(pathParams);
|
|
22
|
+
return parents.map((parent)=>parent.fieldId).concat([
|
|
23
|
+
pathParams.field.fieldId
|
|
24
|
+
]).join(".");
|
|
25
|
+
},
|
|
26
|
+
transform: (value)=>{
|
|
27
|
+
if (!transformHandler) return value;
|
|
28
|
+
return transformHandler.transform({
|
|
29
|
+
field,
|
|
30
|
+
value
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const childFields = field.settings?.fields;
|
|
35
|
+
if (!childFields?.length) return collection;
|
|
36
|
+
const result = createFieldCollection({
|
|
37
|
+
fields: childFields,
|
|
38
|
+
parents: [
|
|
39
|
+
...parents,
|
|
40
|
+
{
|
|
41
|
+
fieldId: field.fieldId,
|
|
42
|
+
list: field.list
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
pathRegistry,
|
|
46
|
+
transformRegistry,
|
|
47
|
+
system
|
|
48
|
+
});
|
|
49
|
+
Object.assign(collection, result);
|
|
50
|
+
return collection;
|
|
51
|
+
}, {});
|
|
52
|
+
};
|
|
53
|
+
const createFields = (params)=>{
|
|
54
|
+
const { fields, systemFields, pathRegistry, transformRegistry } = params;
|
|
55
|
+
const collection = createFieldCollection({
|
|
56
|
+
fields: createSystemFields(systemFields),
|
|
57
|
+
pathRegistry,
|
|
58
|
+
transformRegistry,
|
|
59
|
+
parents: [],
|
|
60
|
+
system: true
|
|
61
|
+
});
|
|
62
|
+
const result = createFieldCollection({
|
|
63
|
+
fields,
|
|
64
|
+
pathRegistry,
|
|
65
|
+
transformRegistry,
|
|
66
|
+
parents: [
|
|
67
|
+
{
|
|
68
|
+
fieldId: "values",
|
|
69
|
+
list: false
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
system: false
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
...collection,
|
|
76
|
+
...result
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export { createFields };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=createFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/fields/createFields.js","sources":["../../../src/filtering/fields/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 { FieldFilterPathRegistry } from \"../../features/fieldFilterPath/abstractions.js\";\nimport type { FieldFilterValueTransformRegistry } from \"../../features/fieldFilterValueTransform/abstractions.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n /** Fields registered as `CmsEntrySystemField`, filterable under `system`. */\n systemFields?: CmsModelField[];\n pathRegistry: FieldFilterPathRegistry.Interface;\n transformRegistry: FieldFilterValueTransformRegistry.Interface;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n pathRegistry: FieldFilterPathRegistry.Interface;\n transformRegistry: FieldFilterValueTransformRegistry.Interface;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, pathRegistry, transformRegistry, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformHandler = transformRegistry.get(fieldType);\n const pathHandler = pathRegistry.get(fieldType);\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: pathParams => {\n if (\n pathHandler &&\n pathHandler.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return pathHandler.createPath(pathParams);\n }\n\n return parents\n .map(parent => parent.fieldId)\n .concat([pathParams.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformHandler) {\n return value;\n }\n return transformHandler.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 pathRegistry,\n transformRegistry,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\n};\n\nexport const createFields = (params: Params) => {\n const { fields, systemFields, pathRegistry, transformRegistry } = params;\n\n const collection = createFieldCollection({\n fields: createSystemFields(systemFields),\n pathRegistry,\n transformRegistry,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n pathRegistry,\n transformRegistry,\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","pathRegistry","transformRegistry","system","collection","field","fieldType","getBaseFieldType","transformHandler","pathHandler","fieldId","f","pathParams","p","parent","value","childFields","result","Object","createFields","systemFields","createSystemFields"],"mappings":";;AA2BA,MAAMA,wBAAwB,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAEC,YAAY,EAAEC,iBAAiB,EAAEC,MAAM,EAAE,GAAGL;IACrE,OAAOC,OAAO,MAAM,CAAkB,CAACK,YAAYC;QAC/C,MAAMC,YAAYC,iBAAiBF;QACnC,MAAMG,mBAAmBN,kBAAkB,GAAG,CAACI;QAC/C,MAAMG,cAAcR,aAAa,GAAG,CAACK;QAErC,MAAMI,UAAU;eACTV;YACH;gBACI,SAASK,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;YACpB;SACH,CACI,GAAG,CAACM,CAAAA,IAA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type { Field } from "./types.js";
|
|
2
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import type { FieldSortingRegistry } from "../../features/fieldSorting/abstractions.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
|
+
sortingRegistry: FieldSortingRegistry.Interface;
|
|
15
|
+
}
|
|
16
|
+
export declare const extractSort: (params: IParams) => IResponse;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
const extractSortInfo = (sortBy)=>{
|
|
3
|
+
const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
|
|
4
|
+
if (rootSorting) return {
|
|
5
|
+
fieldId: rootSorting[1],
|
|
6
|
+
isValues: false,
|
|
7
|
+
order: rootSorting[2]
|
|
8
|
+
};
|
|
9
|
+
const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
|
|
10
|
+
if (valuesSorting) return {
|
|
11
|
+
fieldId: valuesSorting[1],
|
|
12
|
+
isValues: true,
|
|
13
|
+
order: valuesSorting[2]
|
|
14
|
+
};
|
|
15
|
+
throw new error("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
16
|
+
sortBy
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const extractSort = (params)=>{
|
|
20
|
+
const { model, sortBy, fields, sortingRegistry } = params;
|
|
21
|
+
const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);
|
|
22
|
+
const field = Object.values(fields).find((f)=>{
|
|
23
|
+
const isValues = f.parents[0]?.fieldId === "values";
|
|
24
|
+
if (isValues && isValuesSorting) return f.fieldId === fieldId;
|
|
25
|
+
if (f.parents.length > 0) return false;
|
|
26
|
+
return f.fieldId === fieldId;
|
|
27
|
+
});
|
|
28
|
+
const handler = sortingRegistry.find({
|
|
29
|
+
model,
|
|
30
|
+
field,
|
|
31
|
+
fieldId,
|
|
32
|
+
order,
|
|
33
|
+
sortBy
|
|
34
|
+
});
|
|
35
|
+
if (handler) return handler.createSort({
|
|
36
|
+
model,
|
|
37
|
+
fieldId,
|
|
38
|
+
order,
|
|
39
|
+
sortBy,
|
|
40
|
+
field,
|
|
41
|
+
fields
|
|
42
|
+
});
|
|
43
|
+
else if (!field) throw new error("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
44
|
+
fieldId,
|
|
45
|
+
fields
|
|
46
|
+
});
|
|
47
|
+
const valuePath = field.createPath({
|
|
48
|
+
field
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
field,
|
|
52
|
+
fieldId,
|
|
53
|
+
valuePath,
|
|
54
|
+
reverse: "DESC" === order
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export { extractSort };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=extractSort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/fields/extractSort.js","sources":["../../../src/filtering/fields/extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { FieldSortingRegistry } from \"../../features/fieldSorting/abstractions.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 sortingRegistry: FieldSortingRegistry.Interface;\n}\n\nexport const extractSort = (params: IParams): IResponse => {\n const { model, sortBy, fields, sortingRegistry } = params;\n const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);\n\n const field = Object.values(fields).find(f => {\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 handler = sortingRegistry.find({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n\n if (handler) {\n return handler.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","sortingRegistry","fieldId","isValuesSorting","order","field","Object","f","isValues","handler","valuePath"],"mappings":";AAKA,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,eAAe,EAAE,GAAGH;IACnD,MAAM,EAAEI,OAAO,EAAE,UAAUC,eAAe,EAAEC,KAAK,EAAE,GAAGZ,gBAAgBC;IAEtE,MAAMY,QAAQC,OAAO,MAAM,CAACN,QAAQ,IAAI,CAACO,CAAAA;QACrC,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,UAAUR,gBAAgB,IAAI,CAAC;QACjCF;QACAM;QACAH;QACAE;QACAX;IACJ;IAEA,IAAIgB,SACA,OAAOA,QAAQ,UAAU,CAAC;QACtBV;QACAG;QACAE;QACAX;QACAY;QACAL;IACJ;SACG,IAAI,CAACK,OACR,MAAM,IAAIT,MACN,sDACA,uBACA;QACIM;QACAF;IACJ;IAGR,MAAMU,YAAYL,MAAM,UAAU,CAAC;QAC/BA;IACJ;IACA,OAAO;QACHA;QACAH;QACAQ;QACA,SAASN,AAAU,WAAVA;IACb;AACJ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* @param entrySystemFields Fields registered as `CmsEntrySystemField`, filterable under `system`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const createSystemFields: (entrySystemFields?: CmsModelField[]) => CmsModelField[];
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ENTRY_META_FIELDS, isDateTimeEntryMetaField, isIdentityEntryMetaField } from "@webiny/api-headless-cms/constants.js";
|
|
2
|
+
import startCase from "lodash/startCase.js";
|
|
3
|
+
import { createModelField } from "@webiny/api-headless-cms";
|
|
4
|
+
const createSystemFields = (entrySystemFields = [])=>{
|
|
5
|
+
const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).map((fieldName)=>createModelField({
|
|
6
|
+
id: fieldName,
|
|
7
|
+
type: "datetime",
|
|
8
|
+
storageId: fieldName,
|
|
9
|
+
fieldId: fieldName,
|
|
10
|
+
label: startCase(fieldName)
|
|
11
|
+
}));
|
|
12
|
+
const byMetaFields = ENTRY_META_FIELDS.filter(isIdentityEntryMetaField).map((fieldName)=>createModelField({
|
|
13
|
+
id: fieldName,
|
|
14
|
+
type: "plainObject",
|
|
15
|
+
storageId: fieldName,
|
|
16
|
+
fieldId: fieldName,
|
|
17
|
+
label: startCase(fieldName),
|
|
18
|
+
settings: {
|
|
19
|
+
path: `${fieldName}.id`
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
return [
|
|
23
|
+
createModelField({
|
|
24
|
+
id: "id",
|
|
25
|
+
type: "text",
|
|
26
|
+
storageId: "id",
|
|
27
|
+
fieldId: "id",
|
|
28
|
+
label: "ID"
|
|
29
|
+
}),
|
|
30
|
+
createModelField({
|
|
31
|
+
id: "entryId",
|
|
32
|
+
type: "text",
|
|
33
|
+
storageId: "entryId",
|
|
34
|
+
fieldId: "entryId",
|
|
35
|
+
label: "Entry ID"
|
|
36
|
+
}),
|
|
37
|
+
...onMetaFields,
|
|
38
|
+
...byMetaFields,
|
|
39
|
+
createModelField({
|
|
40
|
+
id: "meta",
|
|
41
|
+
type: "plainObject",
|
|
42
|
+
storageId: "meta",
|
|
43
|
+
fieldId: "meta",
|
|
44
|
+
label: "Meta"
|
|
45
|
+
}),
|
|
46
|
+
createModelField({
|
|
47
|
+
id: "wbyAco_location",
|
|
48
|
+
type: "object",
|
|
49
|
+
storageId: "location",
|
|
50
|
+
label: "Location",
|
|
51
|
+
fieldId: "wbyAco_location",
|
|
52
|
+
settings: {
|
|
53
|
+
fields: [
|
|
54
|
+
createModelField({
|
|
55
|
+
id: "folderId",
|
|
56
|
+
type: "text",
|
|
57
|
+
fieldId: "folderId",
|
|
58
|
+
label: "Folder ID",
|
|
59
|
+
storageId: "folderId",
|
|
60
|
+
settings: {
|
|
61
|
+
path: "location.folderId"
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
createModelField({
|
|
68
|
+
id: "version",
|
|
69
|
+
type: "number",
|
|
70
|
+
storageId: "version",
|
|
71
|
+
fieldId: "version",
|
|
72
|
+
label: "Version"
|
|
73
|
+
}),
|
|
74
|
+
createModelField({
|
|
75
|
+
id: "status",
|
|
76
|
+
type: "text",
|
|
77
|
+
storageId: "status",
|
|
78
|
+
fieldId: "status",
|
|
79
|
+
label: "Status"
|
|
80
|
+
}),
|
|
81
|
+
createModelField({
|
|
82
|
+
id: "wbyDeleted",
|
|
83
|
+
type: "boolean",
|
|
84
|
+
storageId: "wbyDeleted",
|
|
85
|
+
fieldId: "wbyDeleted",
|
|
86
|
+
label: "Deleted"
|
|
87
|
+
}),
|
|
88
|
+
createModelField({
|
|
89
|
+
id: "state",
|
|
90
|
+
type: "object",
|
|
91
|
+
storageId: "object@state",
|
|
92
|
+
fieldId: "state",
|
|
93
|
+
label: "State",
|
|
94
|
+
settings: {
|
|
95
|
+
fields: [
|
|
96
|
+
createModelField({
|
|
97
|
+
id: "stepId",
|
|
98
|
+
type: "text",
|
|
99
|
+
fieldId: "stepId",
|
|
100
|
+
label: "Step ID",
|
|
101
|
+
storageId: "stepId"
|
|
102
|
+
}),
|
|
103
|
+
createModelField({
|
|
104
|
+
id: "stepName",
|
|
105
|
+
type: "text",
|
|
106
|
+
fieldId: "stepName",
|
|
107
|
+
label: "Step Name",
|
|
108
|
+
storageId: "stepName"
|
|
109
|
+
}),
|
|
110
|
+
createModelField({
|
|
111
|
+
id: "state",
|
|
112
|
+
type: "text",
|
|
113
|
+
fieldId: "state",
|
|
114
|
+
label: "State",
|
|
115
|
+
storageId: "state"
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
createModelField({
|
|
121
|
+
id: "values",
|
|
122
|
+
type: "object",
|
|
123
|
+
storageId: "values",
|
|
124
|
+
fieldId: "values",
|
|
125
|
+
label: "Values"
|
|
126
|
+
}),
|
|
127
|
+
createModelField({
|
|
128
|
+
id: "live",
|
|
129
|
+
type: "object",
|
|
130
|
+
storageId: "live",
|
|
131
|
+
fieldId: "live",
|
|
132
|
+
label: "Live",
|
|
133
|
+
settings: {
|
|
134
|
+
fields: [
|
|
135
|
+
createModelField({
|
|
136
|
+
id: "version",
|
|
137
|
+
type: "number",
|
|
138
|
+
fieldId: "version",
|
|
139
|
+
label: "Version",
|
|
140
|
+
storageId: "version"
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
}),
|
|
145
|
+
...createEntrySystemField(entrySystemFields)
|
|
146
|
+
];
|
|
147
|
+
};
|
|
148
|
+
const createEntrySystemField = (fields)=>{
|
|
149
|
+
if (0 === fields.length) return [];
|
|
150
|
+
return [
|
|
151
|
+
createModelField({
|
|
152
|
+
id: "system",
|
|
153
|
+
type: "object",
|
|
154
|
+
storageId: "system",
|
|
155
|
+
fieldId: "system",
|
|
156
|
+
label: "System",
|
|
157
|
+
settings: {
|
|
158
|
+
fields
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
];
|
|
162
|
+
};
|
|
163
|
+
export { createSystemFields };
|
|
164
|
+
|
|
165
|
+
//# sourceMappingURL=systemFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering/fields/systemFields.js","sources":["../../../src/filtering/fields/systemFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport {\n ENTRY_META_FIELDS,\n isDateTimeEntryMetaField,\n isIdentityEntryMetaField\n} from \"@webiny/api-headless-cms/constants.js\";\nimport lodashStartCase from \"lodash/startCase.js\";\nimport { createModelField } from \"@webiny/api-headless-cms\";\n\n/**\n * @param entrySystemFields Fields registered as `CmsEntrySystemField`, filterable under `system`.\n */\nexport const createSystemFields = (entrySystemFields: CmsModelField[] = []): CmsModelField[] => {\n const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).map<CmsModelField>(\n fieldName => {\n return createModelField({\n id: fieldName,\n type: \"datetime\",\n storageId: fieldName,\n fieldId: fieldName,\n label: lodashStartCase(fieldName)\n });\n }\n );\n\n const byMetaFields = ENTRY_META_FIELDS.filter(isIdentityEntryMetaField).map<CmsModelField>(\n fieldName => {\n return createModelField({\n id: fieldName,\n type: \"plainObject\",\n storageId: fieldName,\n fieldId: fieldName,\n label: lodashStartCase(fieldName),\n settings: {\n path: `${fieldName}.id`\n }\n });\n }\n );\n\n return [\n createModelField({\n id: \"id\",\n type: \"text\",\n storageId: \"id\",\n fieldId: \"id\",\n label: \"ID\"\n }),\n createModelField({\n id: \"entryId\",\n type: \"text\",\n storageId: \"entryId\",\n fieldId: \"entryId\",\n label: \"Entry ID\"\n }),\n\n ...onMetaFields,\n ...byMetaFields,\n\n createModelField({\n id: \"meta\",\n type: \"plainObject\",\n storageId: \"meta\",\n fieldId: \"meta\",\n label: \"Meta\"\n }),\n createModelField({\n id: \"wbyAco_location\",\n type: \"object\",\n storageId: \"location\",\n label: \"Location\",\n fieldId: \"wbyAco_location\",\n settings: {\n fields: [\n createModelField({\n id: \"folderId\",\n type: \"text\",\n fieldId: \"folderId\",\n label: \"Folder ID\",\n storageId: \"folderId\",\n settings: {\n path: \"location.folderId\"\n }\n })\n ]\n }\n }),\n\n createModelField({\n id: \"version\",\n type: \"number\",\n storageId: \"version\",\n fieldId: \"version\",\n label: \"Version\"\n }),\n createModelField({\n id: \"status\",\n type: \"text\",\n storageId: \"status\",\n fieldId: \"status\",\n label: \"Status\"\n }),\n createModelField({\n id: \"wbyDeleted\",\n type: \"boolean\",\n storageId: \"wbyDeleted\",\n fieldId: \"wbyDeleted\",\n label: \"Deleted\"\n }),\n createModelField({\n id: \"state\",\n type: \"object\",\n storageId: \"object@state\",\n fieldId: \"state\",\n label: \"State\",\n settings: {\n fields: [\n createModelField({\n id: \"stepId\",\n type: \"text\",\n fieldId: \"stepId\",\n label: \"Step ID\",\n storageId: \"stepId\"\n }),\n createModelField({\n id: \"stepName\",\n type: \"text\",\n fieldId: \"stepName\",\n label: \"Step Name\",\n storageId: \"stepName\"\n }),\n createModelField({\n id: \"state\",\n type: \"text\",\n fieldId: \"state\",\n label: \"State\",\n storageId: \"state\"\n })\n ]\n }\n }),\n createModelField({\n id: \"values\",\n type: \"object\",\n storageId: \"values\",\n fieldId: \"values\",\n label: \"Values\"\n }),\n createModelField({\n id: \"live\",\n type: \"object\",\n storageId: \"live\",\n fieldId: \"live\",\n label: \"Live\",\n settings: {\n fields: [\n createModelField({\n id: \"version\",\n type: \"number\",\n fieldId: \"version\",\n label: \"Version\",\n storageId: \"version\"\n })\n ]\n }\n }),\n ...createEntrySystemField(entrySystemFields)\n ];\n};\n\nconst createEntrySystemField = (fields: CmsModelField[]): CmsModelField[] => {\n if (fields.length === 0) {\n return [];\n }\n return [\n createModelField({\n id: \"system\",\n type: \"object\",\n storageId: \"system\",\n fieldId: \"system\",\n label: \"System\",\n settings: {\n fields\n }\n })\n ];\n};\n"],"names":["createSystemFields","entrySystemFields","onMetaFields","ENTRY_META_FIELDS","isDateTimeEntryMetaField","fieldName","createModelField","lodashStartCase","byMetaFields","isIdentityEntryMetaField","createEntrySystemField","fields"],"mappings":";;;AAYO,MAAMA,qBAAqB,CAACC,oBAAqC,EAAE;IACtE,MAAMC,eAAeC,kBAAkB,MAAM,CAACC,0BAA0B,GAAG,CACvEC,CAAAA,YACWC,iBAAiB;YACpB,IAAID;YACJ,MAAM;YACN,WAAWA;YACX,SAASA;YACT,OAAOE,UAAgBF;QAC3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wBACT,OAAO;wBACP,WAAW;oBACf;iBACH;YACL;QACJ;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;QACX;QACAA,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;YACP,UAAU;gBACN,QAAQ;oBACJA,iBAAiB;wBACb,IAAI;wBACJ,MAAM;wBACN,SAAS;wBACT,OAAO;wBACP,WAAW;oBACf;iBACH;YACL;QACJ;WACGI,uBAAuBT;KAC7B;AACL;AAEA,MAAMS,yBAAyB,CAACC;IAC5B,IAAIA,AAAkB,MAAlBA,OAAO,MAAM,EACb,OAAO,EAAE;IAEb,OAAO;QACHL,iBAAiB;YACb,IAAI;YACJ,MAAM;YACN,WAAW;YACX,SAAS;YACT,OAAO;YACP,UAAU;gBACNK;YACJ;QACJ;KACH;AACL"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { CreatePathCallable } from "../../plugins/CmsEntryFieldFilterPathPlugin.js";
|
|
3
|
+
interface FieldValueTransform {
|
|
4
|
+
(value: any): any;
|
|
5
|
+
}
|
|
6
|
+
export interface FieldParent {
|
|
7
|
+
fieldId: string;
|
|
8
|
+
list?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface Field extends Partial<Omit<CmsModelField, "id" | "type" | "storageId" | "fieldId">>, Pick<CmsModelField, "id" | "type" | "storageId" | "fieldId"> {
|
|
11
|
+
parents: FieldParent[];
|
|
12
|
+
createPath: CreatePathCallable;
|
|
13
|
+
transform: FieldValueTransform;
|
|
14
|
+
system: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface FilterItemFromStorage {
|
|
17
|
+
<T = any>(field: CmsModelField, value: any): Promise<T>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CmsEntry, CmsEntryListWhere, CmsEntryValues } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { Field } from "./fields/types.js";
|
|
3
|
+
import { ValueFilterRegistry } from "@webiny/db-utils";
|
|
4
|
+
import type { FieldFilterCreateRegistry } from "../features/fieldFilterCreate/abstractions.js";
|
|
5
|
+
import type { FieldFilterValueTransformRegistry } from "../features/fieldFilterValueTransform/abstractions.js";
|
|
6
|
+
interface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {
|
|
7
|
+
filterCreateRegistry: FieldFilterCreateRegistry.Interface;
|
|
8
|
+
transformRegistry: FieldFilterValueTransformRegistry.Interface;
|
|
9
|
+
valueFilterRegistry: ValueFilterRegistry.Interface;
|
|
10
|
+
items: CmsEntry<T>[];
|
|
11
|
+
where: Partial<CmsEntryListWhere>;
|
|
12
|
+
fields: Record<string, Field>;
|
|
13
|
+
fullTextSearch?: {
|
|
14
|
+
term?: string;
|
|
15
|
+
fields?: string[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare const filter: <T extends CmsEntryValues = CmsEntryValues>(params: IFilterParams<T>) => CmsEntry<T>[];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { createFullTextSearch } from "./fullTextSearch.js";
|
|
3
|
+
import { createExpressions } from "./expressions/createExpressions.js";
|
|
4
|
+
import { transformValue } from "./transform.js";
|
|
5
|
+
import { getValue } from "./getValue.js";
|
|
6
|
+
const executeFilter = (params)=>{
|
|
7
|
+
const { value, filter } = params;
|
|
8
|
+
const canUse = filter.filter.canUse({
|
|
9
|
+
value,
|
|
10
|
+
compareValue: filter.compareValue
|
|
11
|
+
});
|
|
12
|
+
if (!canUse) return true;
|
|
13
|
+
const matched = filter.filter.matches({
|
|
14
|
+
value,
|
|
15
|
+
compareValue: filter.compareValue
|
|
16
|
+
});
|
|
17
|
+
if (filter.negate) return false === matched;
|
|
18
|
+
return matched;
|
|
19
|
+
};
|
|
20
|
+
const executeExpressions = (params)=>{
|
|
21
|
+
const { expressions, getCachedValue, filters, condition } = params;
|
|
22
|
+
if (0 === expressions.length && 0 === filters.length) return true;
|
|
23
|
+
for (const filter of filters){
|
|
24
|
+
const value = getCachedValue(filter);
|
|
25
|
+
const result = executeFilter({
|
|
26
|
+
value,
|
|
27
|
+
filter
|
|
28
|
+
});
|
|
29
|
+
if (!result) return false;
|
|
30
|
+
}
|
|
31
|
+
for (const expression of expressions){
|
|
32
|
+
const result = executeExpressions({
|
|
33
|
+
...expression,
|
|
34
|
+
getCachedValue
|
|
35
|
+
});
|
|
36
|
+
if (result && "OR" === condition) return true;
|
|
37
|
+
else if (!result && "AND" == condition) return false;
|
|
38
|
+
}
|
|
39
|
+
return "OR" !== condition;
|
|
40
|
+
};
|
|
41
|
+
const filter_filter = (params)=>{
|
|
42
|
+
const { items: records, where, filterCreateRegistry, transformRegistry, fields, fullTextSearch, valueFilterRegistry } = params;
|
|
43
|
+
const keys = Object.keys(where);
|
|
44
|
+
if (0 === keys.length && !fullTextSearch) return records;
|
|
45
|
+
const expression = createExpressions({
|
|
46
|
+
filterCreateRegistry,
|
|
47
|
+
transformRegistry,
|
|
48
|
+
where,
|
|
49
|
+
fields,
|
|
50
|
+
valueFilterRegistry
|
|
51
|
+
});
|
|
52
|
+
if (0 === expression.filters.length && 0 === expression.expressions.length && !fullTextSearch?.term) return records;
|
|
53
|
+
const fullTextSearchFilter = valueFilterRegistry.get("contains");
|
|
54
|
+
if (!fullTextSearchFilter) throw new error('Missing "contains" plugin to run the full-text search.', "MISSING_PLUGIN");
|
|
55
|
+
const search = createFullTextSearch({
|
|
56
|
+
term: fullTextSearch?.term,
|
|
57
|
+
targetFields: fullTextSearch?.fields,
|
|
58
|
+
fields,
|
|
59
|
+
filter: fullTextSearchFilter
|
|
60
|
+
});
|
|
61
|
+
return records.filter((record)=>{
|
|
62
|
+
const cachedValues = {};
|
|
63
|
+
const getCachedValue = (filter)=>{
|
|
64
|
+
const { path } = filter;
|
|
65
|
+
if (void 0 !== cachedValues[path]) return cachedValues[path];
|
|
66
|
+
const plainValue = getValue(record, path);
|
|
67
|
+
const rawValue = transformValue({
|
|
68
|
+
value: plainValue,
|
|
69
|
+
transform: filter.transformValue
|
|
70
|
+
});
|
|
71
|
+
cachedValues[path] = rawValue;
|
|
72
|
+
return rawValue;
|
|
73
|
+
};
|
|
74
|
+
const exprResult = executeExpressions({
|
|
75
|
+
...expression,
|
|
76
|
+
getCachedValue
|
|
77
|
+
});
|
|
78
|
+
if (!exprResult || !search) return exprResult;
|
|
79
|
+
return search(record);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
export { filter_filter as filter };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=filter.js.map
|