@webiny/api-headless-cms-ddb 6.3.0-beta.4 → 6.4.0-beta.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/definitions/entry.js +7 -9
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +7 -9
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +7 -9
- package/definitions/model.js.map +1 -1
- package/definitions/table.js +6 -7
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +1 -0
- package/definitions/types.js +0 -3
- package/dynamoDb/index.js +6 -1
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.js +16 -29
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.js +11 -21
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/transformValue/datetime.js +21 -32
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.js +67 -77
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +2 -1
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -29
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +31 -41
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +31 -41
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +33 -47
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.js +8 -9
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.js +0 -3
- package/operations/entry/dataLoaders.js +81 -99
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.js +109 -157
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.js +83 -96
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.js +50 -74
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.js +72 -140
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.js +21 -38
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +31 -53
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.js +0 -2
- package/operations/entry/filtering/mapPlugins.js +15 -22
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +29 -33
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.js +7 -3
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +60 -76
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.js +55 -66
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +43 -56
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.js +34 -60
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.js +144 -126
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.js +4 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.js +0 -3
- package/operations/entry/filtering/values.js +11 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +17 -23
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.js +894 -1148
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +54 -77
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.js +113 -134
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +100 -121
- package/operations/model/index.js.map +1 -1
- package/package.json +15 -15
- package/plugins/CmsEntryFieldFilterPathPlugin.js +23 -33
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.js +16 -17
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.js +16 -15
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.js +15 -12
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.js +0 -2
- package/types.js +6 -5
- package/types.js.map +1 -1
- package/definitions/types.js.map +0 -1
- package/operations/entry/dataLoader/types.js.map +0 -1
- package/operations/entry/filtering/index.js.map +0 -1
- package/operations/entry/filtering/types.js.map +0 -1
- package/plugins/index.js.map +0 -1
|
@@ -2,105 +2,92 @@ import { createSystemFields } from "./systemFields.js";
|
|
|
2
2
|
import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
|
|
3
3
|
import { getMappedPlugins } from "./mapPlugins.js";
|
|
4
4
|
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
5
|
-
const createFieldCollection = params
|
|
6
|
-
|
|
7
|
-
fields,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
42
50
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
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
|
+
});
|
|
49
74
|
const result = createFieldCollection({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
75
|
+
fields,
|
|
76
|
+
transformValuePlugins,
|
|
77
|
+
valuePathPlugins,
|
|
78
|
+
parents: [
|
|
79
|
+
{
|
|
80
|
+
fieldId: "values",
|
|
81
|
+
list: false
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
system: false
|
|
58
85
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
65
|
-
*
|
|
66
|
-
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
67
|
-
*/
|
|
68
|
-
export const createFields = params => {
|
|
69
|
-
const {
|
|
70
|
-
fields,
|
|
71
|
-
plugins
|
|
72
|
-
} = params;
|
|
73
|
-
const transformValuePlugins = getMappedPlugins({
|
|
74
|
-
plugins,
|
|
75
|
-
type: "cms-field-filter-value-transform",
|
|
76
|
-
property: "fieldType"
|
|
77
|
-
});
|
|
78
|
-
const valuePathPlugins = getMappedPlugins({
|
|
79
|
-
plugins,
|
|
80
|
-
type: CmsEntryFieldFilterPathPlugin.type,
|
|
81
|
-
property: "fieldType"
|
|
82
|
-
});
|
|
83
|
-
const collection = createFieldCollection({
|
|
84
|
-
fields: createSystemFields(),
|
|
85
|
-
transformValuePlugins,
|
|
86
|
-
valuePathPlugins,
|
|
87
|
-
parents: [],
|
|
88
|
-
system: true
|
|
89
|
-
});
|
|
90
|
-
const result = createFieldCollection({
|
|
91
|
-
fields,
|
|
92
|
-
transformValuePlugins,
|
|
93
|
-
valuePathPlugins,
|
|
94
|
-
parents: [{
|
|
95
|
-
fieldId: "values",
|
|
96
|
-
list: false
|
|
97
|
-
}],
|
|
98
|
-
system: false
|
|
99
|
-
});
|
|
100
|
-
return {
|
|
101
|
-
...collection,
|
|
102
|
-
...result
|
|
103
|
-
};
|
|
86
|
+
return {
|
|
87
|
+
...collection,
|
|
88
|
+
...result
|
|
89
|
+
};
|
|
104
90
|
};
|
|
91
|
+
export { createFields };
|
|
105
92
|
|
|
106
93
|
//# sourceMappingURL=createFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,84 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { CmsEntryFieldSortingPlugin } from "../../../plugins/index.js";
|
|
3
|
-
const extractSortInfo = sortBy
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
order: rootSorting[2]
|
|
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]
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
isValues: true,
|
|
17
|
-
order: valuesSorting[2]
|
|
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]
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
16
|
+
throw new error("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
17
|
+
sortBy
|
|
18
|
+
});
|
|
23
19
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
fieldId,
|
|
33
|
-
isValues: isValuesSorting,
|
|
34
|
-
order
|
|
35
|
-
} = extractSortInfo(sortBy);
|
|
36
|
-
const field = Object.values(fields).find(f => {
|
|
37
|
-
/**
|
|
38
|
-
* We do not support sorting by nested fields.
|
|
39
|
-
*/
|
|
40
|
-
const isValues = f.parents[0]?.fieldId === "values";
|
|
41
|
-
if (isValues && isValuesSorting) {
|
|
42
|
-
return f.fieldId === fieldId;
|
|
43
|
-
}
|
|
44
|
-
if (f.parents.length > 0) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return f.fieldId === fieldId;
|
|
48
|
-
});
|
|
49
|
-
const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
|
|
50
|
-
return plugin.canUse({
|
|
51
|
-
model,
|
|
52
|
-
field,
|
|
53
|
-
fieldId,
|
|
54
|
-
order,
|
|
55
|
-
sortBy
|
|
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;
|
|
56
28
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
66
43
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
fields
|
|
44
|
+
if (!field) throw new error("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
45
|
+
fieldId,
|
|
46
|
+
fields
|
|
71
47
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
48
|
+
const valuePath = field.createPath({
|
|
49
|
+
field
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
field,
|
|
53
|
+
fieldId,
|
|
54
|
+
valuePath,
|
|
55
|
+
reverse: "DESC" === order
|
|
56
|
+
};
|
|
82
57
|
};
|
|
58
|
+
export { extractSort };
|
|
83
59
|
|
|
84
60
|
//# sourceMappingURL=extractSort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,153 +1,85 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { createFullTextSearch } from "./fullTextSearch.js";
|
|
3
3
|
import { createExpressions } from "./createExpressions.js";
|
|
4
4
|
import { transformValue } from "./transform.js";
|
|
5
5
|
import { getValue } from "./getValue.js";
|
|
6
6
|
import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
7
|
-
const executeFilter = params
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* We need to check if the filter can be used.
|
|
15
|
-
* If it cannot, we will just return true.
|
|
16
|
-
*/
|
|
17
|
-
const canUse = filter.filter.canUse({
|
|
18
|
-
value,
|
|
19
|
-
compareValue: filter.compareValue
|
|
20
|
-
});
|
|
21
|
-
if (!canUse) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
const matched = filter.filter.matches({
|
|
25
|
-
value,
|
|
26
|
-
compareValue: filter.compareValue
|
|
27
|
-
});
|
|
28
|
-
if (filter.negate) {
|
|
29
|
-
return matched === false;
|
|
30
|
-
}
|
|
31
|
-
return matched;
|
|
32
|
-
};
|
|
33
|
-
const executeExpressions = params => {
|
|
34
|
-
const {
|
|
35
|
-
expressions,
|
|
36
|
-
getCachedValue,
|
|
37
|
-
filters,
|
|
38
|
-
condition
|
|
39
|
-
} = params;
|
|
40
|
-
if (expressions.length === 0 && filters.length === 0) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Always run filters first as they might trigger an early return.
|
|
45
|
-
*/
|
|
46
|
-
for (const filter of filters) {
|
|
47
|
-
const value = getCachedValue(filter);
|
|
48
|
-
const result = executeFilter({
|
|
49
|
-
value,
|
|
50
|
-
filter
|
|
7
|
+
const executeFilter = (params)=>{
|
|
8
|
+
const { value, filter } = params;
|
|
9
|
+
const canUse = filter.filter.canUse({
|
|
10
|
+
value,
|
|
11
|
+
compareValue: filter.compareValue
|
|
51
12
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!result) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Then we move onto expressions, which are basically nested upon nested filters with different conditions.
|
|
62
|
-
*/
|
|
63
|
-
for (const expression of expressions) {
|
|
64
|
-
const result = executeExpressions({
|
|
65
|
-
...expression,
|
|
66
|
-
getCachedValue
|
|
13
|
+
if (!canUse) return true;
|
|
14
|
+
const matched = filter.filter.matches({
|
|
15
|
+
value,
|
|
16
|
+
compareValue: filter.compareValue
|
|
67
17
|
});
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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;
|
|
72
39
|
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.
|
|
76
|
-
*
|
|
77
|
-
* 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.
|
|
78
|
-
*/
|
|
79
|
-
return condition === "OR" ? false : true;
|
|
40
|
+
return "OR" !== condition;
|
|
80
41
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
where
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
return records.filter(record => {
|
|
122
|
-
const cachedValues = {};
|
|
123
|
-
const getCachedValue = filter => {
|
|
124
|
-
const {
|
|
125
|
-
path
|
|
126
|
-
} = filter;
|
|
127
|
-
if (cachedValues[path] !== undefined) {
|
|
128
|
-
return cachedValues[path];
|
|
129
|
-
}
|
|
130
|
-
const plainValue = getValue(record, path);
|
|
131
|
-
const rawValue = transformValue({
|
|
132
|
-
value: plainValue,
|
|
133
|
-
transform: filter.transformValue
|
|
134
|
-
});
|
|
135
|
-
cachedValues[path] = rawValue;
|
|
136
|
-
return rawValue;
|
|
137
|
-
};
|
|
138
|
-
const exprResult = executeExpressions({
|
|
139
|
-
...expression,
|
|
140
|
-
getCachedValue
|
|
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);
|
|
141
81
|
});
|
|
142
|
-
/**
|
|
143
|
-
* If expression result is false we do not need to continue further.
|
|
144
|
-
* Also, if there is no full text search defined, just return the expression result.
|
|
145
|
-
*/
|
|
146
|
-
if (!exprResult || !search) {
|
|
147
|
-
return exprResult;
|
|
148
|
-
}
|
|
149
|
-
return search(record);
|
|
150
|
-
});
|
|
151
82
|
};
|
|
83
|
+
export { filter_filter as filter };
|
|
152
84
|
|
|
153
85
|
//# sourceMappingURL=filter.js.map
|