@webiny/api-headless-cms-ddb 0.0.0-unstable.aa00eecd97 → 0.0.0-unstable.ac6ebf63c6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -20
- package/definitions/entry.d.ts +4 -5
- package/definitions/entry.js +7 -88
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -5
- package/definitions/group.js +7 -59
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -5
- package/definitions/model.js +7 -103
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +4 -6
- package/definitions/table.js +8 -26
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +59 -0
- package/definitions/types.js +3 -0
- package/definitions/types.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +7 -12
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +2 -0
- package/dynamoDb/path/locationFolderId.js +34 -0
- package/dynamoDb/path/locationFolderId.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +7 -14
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/longText.js +13 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +28 -71
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +7 -12
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +40 -82
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -3
- package/operations/entry/dataLoader/DataLoaderCache.js +8 -17
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +3 -8
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -10
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
- package/operations/entry/dataLoader/getAllEntryRevisions.js +13 -24
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +24 -35
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +24 -35
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +26 -37
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.d.ts +5 -5
- package/operations/entry/dataLoader/index.js +12 -31
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +3 -4
- package/operations/entry/dataLoader/types.js +2 -4
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +11 -12
- package/operations/entry/dataLoaders.js +25 -34
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +5 -5
- package/operations/entry/filtering/createExpressions.js +29 -30
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +6 -4
- package/operations/entry/filtering/createFields.js +87 -86
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +6 -6
- package/operations/entry/filtering/extractSort.js +40 -23
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +6 -6
- package/operations/entry/filtering/filter.js +36 -29
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
- package/operations/entry/filtering/fullTextSearch.js +8 -14
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +6 -10
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.d.ts +2 -2
- package/operations/entry/filtering/index.js +3 -18
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +2 -2
- package/operations/entry/filtering/mapPlugins.js +5 -11
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +10 -14
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +8 -12
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/objectFilterCreate.js +17 -19
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +3 -2
- package/operations/entry/filtering/plugins/refFilterCreate.js +22 -19
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +6 -6
- package/operations/entry/filtering/sort.js +18 -20
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -4
- package/operations/entry/filtering/systemFields.js +88 -42
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js +3 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +3 -3
- package/operations/entry/filtering/types.js +2 -4
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +1 -1
- package/operations/entry/filtering/values.js +6 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +6 -10
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +3 -4
- package/operations/entry/index.js +635 -339
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +40 -2
- package/operations/entry/keys.js +55 -30
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +4 -4
- package/operations/group/index.js +44 -61
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +37 -46
- package/operations/model/index.js.map +1 -1
- package/package.json +21 -28
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +4 -3
- package/plugins/CmsEntryFieldFilterPathPlugin.js +15 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +10 -10
- package/plugins/CmsEntryFieldFilterPlugin.js +11 -14
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldSortingPlugin.js +6 -15
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +2 -2
- package/plugins/CmsFieldFilterValueTransformPlugin.js +5 -13
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +4 -4
- package/plugins/index.js +5 -48
- package/plugins/index.js.map +1 -1
- package/types.d.ts +18 -22
- package/types.js +5 -12
- package/types.js.map +1 -1
- package/definitions/settings.d.ts +0 -9
- package/definitions/settings.js +0 -53
- package/definitions/settings.js.map +0 -1
- package/definitions/system.d.ts +0 -9
- package/definitions/system.js +0 -41
- package/definitions/system.js.map +0 -1
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -91
- package/dynamoDb/storage/date.js.map +0 -1
- package/operations/entry/systemFields.d.ts +0 -2
- package/operations/entry/systemFields.js +0 -72
- package/operations/entry/systemFields.js.map +0 -1
- package/operations/settings/index.d.ts +0 -7
- package/operations/settings/index.js +0 -111
- package/operations/settings/index.js.map +0 -1
- package/operations/system/index.d.ts +0 -7
- package/operations/system/index.js +0 -82
- package/operations/system/index.js.map +0 -1
|
@@ -1,105 +1,106 @@
|
|
|
1
|
-
|
|
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 {
|
|
7
|
+
fields,
|
|
8
|
+
parents,
|
|
9
|
+
transformValuePlugins,
|
|
10
|
+
valuePathPlugins,
|
|
11
|
+
system
|
|
12
|
+
} = params;
|
|
13
|
+
return fields.reduce((collection, field) => {
|
|
14
|
+
const fieldType = getBaseFieldType(field);
|
|
15
|
+
const transformPlugin = transformValuePlugins[fieldType];
|
|
16
|
+
const valuePathPlugin = valuePathPlugins[fieldType];
|
|
2
17
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
20
|
+
*/
|
|
21
|
+
const fieldId = [...parents, {
|
|
22
|
+
fieldId: field.fieldId,
|
|
23
|
+
list: field.list
|
|
24
|
+
}].map(f => f.fieldId).join(".");
|
|
25
|
+
collection[fieldId] = {
|
|
26
|
+
...field,
|
|
27
|
+
parents,
|
|
28
|
+
system,
|
|
29
|
+
createPath: params => {
|
|
30
|
+
if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map(p => p.fieldId))) {
|
|
31
|
+
return valuePathPlugin.createPath(params);
|
|
32
|
+
}
|
|
33
|
+
return parents.map(parent => parent.fieldId).concat([params.field.fieldId]).join(".");
|
|
34
|
+
},
|
|
35
|
+
transform: value => {
|
|
36
|
+
if (!transformPlugin) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
return transformPlugin.transform({
|
|
40
|
+
field,
|
|
41
|
+
value
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const childFields = field.settings?.fields;
|
|
46
|
+
if (!childFields?.length) {
|
|
47
|
+
return collection;
|
|
48
|
+
}
|
|
49
|
+
const result = createFieldCollection({
|
|
50
|
+
fields: childFields,
|
|
51
|
+
parents: [...parents, {
|
|
52
|
+
fieldId: field.fieldId,
|
|
53
|
+
list: field.list
|
|
54
|
+
}],
|
|
55
|
+
transformValuePlugins,
|
|
56
|
+
valuePathPlugins,
|
|
57
|
+
system
|
|
58
|
+
});
|
|
59
|
+
Object.assign(collection, result);
|
|
60
|
+
return collection;
|
|
61
|
+
}, {});
|
|
62
|
+
};
|
|
12
63
|
/**
|
|
13
64
|
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
14
65
|
*
|
|
15
66
|
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
16
67
|
*/
|
|
17
|
-
const createFields = params => {
|
|
68
|
+
export const createFields = params => {
|
|
18
69
|
const {
|
|
19
70
|
fields,
|
|
20
71
|
plugins
|
|
21
72
|
} = params;
|
|
22
|
-
const transformValuePlugins =
|
|
73
|
+
const transformValuePlugins = getMappedPlugins({
|
|
23
74
|
plugins,
|
|
24
75
|
type: "cms-field-filter-value-transform",
|
|
25
76
|
property: "fieldType"
|
|
26
77
|
});
|
|
27
|
-
const valuePathPlugins =
|
|
78
|
+
const valuePathPlugins = getMappedPlugins({
|
|
28
79
|
plugins,
|
|
29
|
-
type:
|
|
80
|
+
type: CmsEntryFieldFilterPathPlugin.type,
|
|
30
81
|
property: "fieldType"
|
|
31
82
|
});
|
|
32
|
-
const collection = (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
return fields;
|
|
54
|
-
}, {});
|
|
55
|
-
const addFieldsToCollection = (fields, parents = []) => {
|
|
56
|
-
/**
|
|
57
|
-
* Exit early if no fields are sent.
|
|
58
|
-
*/
|
|
59
|
-
if (fields.length === 0) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
for (const field of fields) {
|
|
63
|
-
var _field$settings2;
|
|
64
|
-
const transformPlugin = transformValuePlugins[field.type];
|
|
65
|
-
const valuePathPlugin = valuePathPlugins[field.type];
|
|
66
|
-
/**
|
|
67
|
-
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
68
|
-
*/
|
|
69
|
-
const fieldId = [...parents, {
|
|
70
|
-
fieldId: field.fieldId,
|
|
71
|
-
multipleValues: field.multipleValues
|
|
72
|
-
}].map(f => f.fieldId).join(".");
|
|
73
|
-
collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
74
|
-
parents,
|
|
75
|
-
system: false,
|
|
76
|
-
createPath: params => {
|
|
77
|
-
if (valuePathPlugin) {
|
|
78
|
-
return valuePathPlugin.createPath(params);
|
|
79
|
-
}
|
|
80
|
-
return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
|
|
81
|
-
},
|
|
82
|
-
transform: value => {
|
|
83
|
-
if (!transformPlugin) {
|
|
84
|
-
return value;
|
|
85
|
-
}
|
|
86
|
-
return transformPlugin.transform({
|
|
87
|
-
field,
|
|
88
|
-
value
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
|
|
93
|
-
if (!childFields || childFields.length === 0) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
addFieldsToCollection(childFields, [...parents, {
|
|
97
|
-
fieldId: field.fieldId,
|
|
98
|
-
multipleValues: field.multipleValues
|
|
99
|
-
}]);
|
|
100
|
-
}
|
|
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
|
|
101
103
|
};
|
|
102
|
-
addFieldsToCollection(fields);
|
|
103
|
-
return collection;
|
|
104
104
|
};
|
|
105
|
-
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=createFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createSystemFields","CmsEntryFieldFilterPathPlugin","getMappedPlugins","getBaseFieldType","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","fieldType","transformPlugin","valuePathPlugin","fieldId","list","map","f","join","createPath","canUse","p","parent","concat","transform","value","childFields","settings","length","result","Object","assign","createFields","plugins","type","property"],"sources":["createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;\n valuePathPlugins: Record<string, CmsEntryFieldFilterPathPlugin>;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n 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"],"mappings":"AACA,SAASA,kBAAkB;AAI3B,SAASC,6BAA6B;AACtC,SAASC,gBAAgB;AACzB,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,MAAMC,qBAAqB,GAAIC,MAAmC,IAAsB;EACpF,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,qBAAqB;IAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACnF,OAAOC,MAAM,CAACK,MAAM,CAAkB,CAACC,UAAU,EAAEC,KAAK,KAAK;IACzD,MAAMC,SAAS,GAAGX,gBAAgB,CAACU,KAAK,CAAC;IACzC,MAAME,eAAe,GAAGP,qBAAqB,CAACM,SAAS,CAAC;IACxD,MAAME,eAAe,GAAGP,gBAAgB,CAACK,SAAS,CAAC;;IAEnD;AACR;AACA;IACQ,MAAMG,OAAO,GAAG,CACZ,GAAGV,OAAO,EACV;MACIU,OAAO,EAAEJ,KAAK,CAACI,OAAO;MACtBC,IAAI,EAAEL,KAA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CAAC;IACjC,OAAOpB,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAAC;AACV,CAAC;AACD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMuB,YAAY,GAAI9B,MAAc,IAAK;EAC5C,MAAM;IAAEC,MAAM;IAAE8B;EAAQ,CAAC,GAAG/B,MAAM;EAElC,MAAMG,qBAAqB,GAAGN,gBAAgB,CAAqC;IAC/EkC,OAAO;IACPC,IAAI,EAAE,kCAAkC;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EACF,MAAM7B,gBAAgB,GAAGP,gBAAgB,CAAgC;IACrEkC,OAAO;IACPC,IAAI,EAAEpC,6BAA6B,CAACoC,IAAI;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EAEF,MAAM1B,UAAU,GAAGR,qBAAqB,CAAC;IACrCE,MAAM,EAAEN,kBAAkB,CAAC,CAAC;IAC5BQ,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,EAAE;IACXG,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMsB,MAAM,GAAG5B,qBAAqB,CAAC;IACjCE,MAAM;IACNE,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,CACL;MACIU,OAAO,EAAE,QAAQ;MACjBC,IAAI,EAAE;IACV,CAAC,CACJ;IACDR,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,OAAO;IACH,GAAGE,UAAU;IACb,GAAGoB;EACP,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Field } from "./types";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import { CmsModel } from "@webiny/api-headless-cms/types";
|
|
4
|
-
interface
|
|
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
5
|
valuePath: string;
|
|
6
6
|
reverse: boolean;
|
|
7
7
|
fieldId: string;
|
|
8
8
|
field: Field;
|
|
9
9
|
}
|
|
10
|
-
interface
|
|
10
|
+
interface IParams {
|
|
11
11
|
model: CmsModel;
|
|
12
12
|
sortBy: string;
|
|
13
13
|
fields: Record<string, Field>;
|
|
14
14
|
plugins: PluginsContainer;
|
|
15
15
|
}
|
|
16
|
-
export declare const extractSort: (params:
|
|
16
|
+
export declare const extractSort: (params: IParams) => IResponse;
|
|
17
17
|
export {};
|
|
@@ -1,36 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { CmsEntryFieldSortingPlugin } from "../../../plugins/index.js";
|
|
3
|
+
const extractSortInfo = sortBy => {
|
|
4
|
+
const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
|
|
5
|
+
if (rootSorting) {
|
|
6
|
+
return {
|
|
7
|
+
fieldId: rootSorting[1],
|
|
8
|
+
isValues: false,
|
|
9
|
+
order: rootSorting[2]
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
|
|
13
|
+
if (valuesSorting) {
|
|
14
|
+
return {
|
|
15
|
+
fieldId: valuesSorting[1],
|
|
16
|
+
isValues: true,
|
|
17
|
+
order: valuesSorting[2]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
21
|
+
sortBy
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export const extractSort = params => {
|
|
11
25
|
const {
|
|
12
26
|
model,
|
|
13
27
|
sortBy,
|
|
14
28
|
fields,
|
|
15
29
|
plugins
|
|
16
30
|
} = params;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const [fieldId, order] = result;
|
|
24
|
-
const field = Object.values(fields).find(field => {
|
|
31
|
+
const {
|
|
32
|
+
fieldId,
|
|
33
|
+
isValues: isValuesSorting,
|
|
34
|
+
order
|
|
35
|
+
} = extractSortInfo(sortBy);
|
|
36
|
+
const field = Object.values(fields).find(f => {
|
|
25
37
|
/**
|
|
26
38
|
* We do not support sorting by nested fields.
|
|
27
39
|
*/
|
|
28
|
-
|
|
40
|
+
const isValues = f.parents[0]?.fieldId === "values";
|
|
41
|
+
if (isValues && isValuesSorting) {
|
|
42
|
+
return f.fieldId === fieldId;
|
|
43
|
+
}
|
|
44
|
+
if (f.parents.length > 0) {
|
|
29
45
|
return false;
|
|
30
46
|
}
|
|
31
|
-
return
|
|
47
|
+
return f.fieldId === fieldId;
|
|
32
48
|
});
|
|
33
|
-
const plugin = plugins.byType(
|
|
49
|
+
const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
|
|
34
50
|
return plugin.canUse({
|
|
35
51
|
model,
|
|
36
52
|
field,
|
|
@@ -49,7 +65,7 @@ const extractSort = params => {
|
|
|
49
65
|
fields
|
|
50
66
|
});
|
|
51
67
|
} else if (!field) {
|
|
52
|
-
throw new
|
|
68
|
+
throw new WebinyError("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
53
69
|
fieldId,
|
|
54
70
|
fields
|
|
55
71
|
});
|
|
@@ -64,4 +80,5 @@ const extractSort = params => {
|
|
|
64
80
|
reverse: order === "DESC"
|
|
65
81
|
};
|
|
66
82
|
};
|
|
67
|
-
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=extractSort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","CmsEntryFieldSortingPlugin","extractSortInfo","sortBy","rootSorting","match","fieldId","isValues","order","valuesSorting","extractSort","params","model","fields","plugins","isValuesSorting","field","Object","values","find","f","parents","length","plugin","byType","type","reverse","canUse","createSort","valuePath","createPath"],"sources":["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"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,0BAA0B;AAGnC,MAAMC,eAAe,GAAIC,MAAc,IAAK;EACxC,MAAMC,WAAW,GAAGD,MAAM,CAACE,KAAK,CAAC,0BAA0B,CAAC;EAC5D,IAAID,WAAW,EAAE;IACb,OAAO;MACHE,OAAO,EAAEF,WAAW,CAAC,CAAC,CAAC;MACvBG,QAAQ,EAAE,KAAK;MACfC,KAAK,EAAEJ,WAAW,CAAC,CAAC;IACxB,CAAC;EACL;EACA,MAAMK,aAAa,GAAGN,MAAM,CAACE,KAAK,CAAC,oCAAoC,CAAC;EACxE,IAAII,aAAa,EAAE;IACf,OAAO;MACHH,OAAO,EAAEG,aAAa,CAAC,CAAC,CAAC;MACzBF,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAEC,aAAa,CAAC,CAAC;IAC1B,CAAC;EACL;EACA,MAAM,IAAIT,WAAW,CACjB,yDAAyD,EACzD,oBAAoB,EACpB;IACIG;EACJ,CACJ,CAAC;AACL,CAAC;AAgBD,OAAO,MAAMO,WAAW,GAAIC,MAAe,IAAgB;EACvD,MAAM;IAAEC,KAAK;IAAET,MAAM;IAAEU,MAAM;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EACjD,MAAM;IAAEL,OAAO;IAAEC,QAAQ,EAAEQ,eAAe;IAAEP;EAAM,CAAC,GAAGN,eAAe,CAACC,MAAM,CAAC;EAE7E,MAAMa,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACL,MAAM,CAAC,CAACM,IAAI,CAACC,CAAC,IAAI;IAC1C;AACR;AACA;IACQ,MAAMb,QAAQ,GAAGa,CAAC,CAACC,OAAO,CAAC,CAAC,CAAC,EAAEf,OAAO,KAAK,QAAQ;IACnD,IAAIC,QAAQ,IAAIQ,eAAe,EAAE;MAC7B,OAAOK,CAAC,CAACd,OAAO,KAAKA,OAAO;IAChC;IACA,IAAIc,CAAC,CAACC,OAAO,CAACC,MAAM,GAAG,CAAC,EAAE;MACtB,OAAO,KAAK;IAChB;IACA,OAAOF,CAAC,CAACd,OAAO,KAAKA,OAAO;EAChC,CAAC,CAAC;EAEF,MAAMiB,MAAM,GAAGT,OAAO,CACjBU,MAAM,CAA6BvB,0BAA0B,CAACwB,IAAI,CAAC,CACnEC,OAAO,CAAC,CAAC,CACTP,IAAI,CAACI,MAAM,IAAI;IACZ,OAAOA,MAAM,CAACI,MAAM,CAAC;MACjBf,KAAK;MACLI,KAAK;MACLV,OAAO;MACPE,KAAK;MACLL;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEN,IAAIoB,MAAM,EAAE;IACR,OAAOA,MAAM,CAACK,UAAU,CAAC;MACrBhB,KAAK;MACLN,OAAO;MACPE,KAAK;MACLL,MAAM;MACNa,KAAK;MACLH;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAI,CAACG,KAAK,EAAE;IACf,MAAM,IAAIhB,WAAW,CACjB,oDAAoD,EACpD,qBAAqB,EACrB;MACIM,OAAO;MACPO;IACJ,CACJ,CAAC;EACL;EACA,MAAMgB,SAAS,GAAGb,KAAK,CAACc,UAAU,CAAC;IAC/Bd;EACJ,CAAC,CAAC;EACF,OAAO;IACHA,KAAK;IACLV,OAAO;IACPuB,SAAS;IACTH,OAAO,EAAElB,KAAK,KAAK;EACvB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import { Field } from "./types";
|
|
4
|
-
interface Params {
|
|
5
|
-
items: CmsEntry[];
|
|
1
|
+
import type { 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 Params<T extends CmsEntryValues = CmsEntryValues> {
|
|
5
|
+
items: CmsEntry<T>[];
|
|
6
6
|
where: Partial<CmsEntryListWhere>;
|
|
7
7
|
plugins: PluginsContainer;
|
|
8
8
|
fields: Record<string, Field>;
|
|
@@ -11,5 +11,5 @@ interface Params {
|
|
|
11
11
|
fields?: string[];
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
export declare const filter: (params: Params) => CmsEntry[];
|
|
14
|
+
export declare const filter: <T extends CmsEntryValues = CmsEntryValues>(params: Params<T>) => CmsEntry<T>[];
|
|
15
15
|
export {};
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
exports.filter = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
10
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
var _fullTextSearch = require("./fullTextSearch");
|
|
12
|
-
var _createExpressions = require("./createExpressions");
|
|
13
|
-
var _transform = require("./transform");
|
|
14
|
-
var _getValue = require("./getValue");
|
|
1
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
2
|
+
import WebinyError from "@webiny/error";
|
|
3
|
+
import { createFullTextSearch } from "./fullTextSearch.js";
|
|
4
|
+
import { createExpressions } from "./createExpressions.js";
|
|
5
|
+
import { transformValue } from "./transform.js";
|
|
6
|
+
import { getValue } from "./getValue.js";
|
|
15
7
|
const executeFilter = params => {
|
|
16
8
|
const {
|
|
17
9
|
value,
|
|
18
10
|
filter
|
|
19
11
|
} = params;
|
|
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.plugin.canUse({
|
|
18
|
+
value,
|
|
19
|
+
compareValue: filter.compareValue
|
|
20
|
+
});
|
|
21
|
+
if (!canUse) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
20
24
|
const matched = filter.plugin.matches({
|
|
21
25
|
value,
|
|
22
26
|
compareValue: filter.compareValue
|
|
@@ -57,9 +61,10 @@ const executeExpressions = params => {
|
|
|
57
61
|
* Then we move onto expressions, which are basically nested upon nested filters with different conditions.
|
|
58
62
|
*/
|
|
59
63
|
for (const expression of expressions) {
|
|
60
|
-
const result = executeExpressions(
|
|
64
|
+
const result = executeExpressions({
|
|
65
|
+
...expression,
|
|
61
66
|
getCachedValue
|
|
62
|
-
})
|
|
67
|
+
});
|
|
63
68
|
if (result && condition === "OR") {
|
|
64
69
|
return true;
|
|
65
70
|
} else if (!result && condition == "AND") {
|
|
@@ -73,7 +78,7 @@ const executeExpressions = params => {
|
|
|
73
78
|
*/
|
|
74
79
|
return condition === "OR" ? false : true;
|
|
75
80
|
};
|
|
76
|
-
const filter = params => {
|
|
81
|
+
export const filter = params => {
|
|
77
82
|
const {
|
|
78
83
|
items: records,
|
|
79
84
|
where,
|
|
@@ -85,7 +90,7 @@ const filter = params => {
|
|
|
85
90
|
if (keys.length === 0 && !fullTextSearch) {
|
|
86
91
|
return records;
|
|
87
92
|
}
|
|
88
|
-
const expression =
|
|
93
|
+
const expression = createExpressions({
|
|
89
94
|
plugins,
|
|
90
95
|
where,
|
|
91
96
|
fields
|
|
@@ -94,19 +99,19 @@ const filter = params => {
|
|
|
94
99
|
/**
|
|
95
100
|
* No point in going further if there are no expressions to be applied and no full text search to be executed.
|
|
96
101
|
*/
|
|
97
|
-
if (expression.filters.length === 0 && expression.expressions.length === 0 && !
|
|
102
|
+
if (expression.filters.length === 0 && expression.expressions.length === 0 && !fullTextSearch?.term) {
|
|
98
103
|
return records;
|
|
99
104
|
}
|
|
100
105
|
/**
|
|
101
106
|
* We need the contains plugin to run the full text search.
|
|
102
107
|
*/
|
|
103
|
-
const fullTextSearchPlugin = plugins.byType(
|
|
108
|
+
const fullTextSearchPlugin = plugins.byType(ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
|
|
104
109
|
if (!fullTextSearchPlugin) {
|
|
105
|
-
throw new
|
|
110
|
+
throw new WebinyError(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
106
111
|
}
|
|
107
|
-
const search =
|
|
108
|
-
term: fullTextSearch
|
|
109
|
-
targetFields: fullTextSearch
|
|
112
|
+
const search = createFullTextSearch({
|
|
113
|
+
term: fullTextSearch?.term,
|
|
114
|
+
targetFields: fullTextSearch?.fields,
|
|
110
115
|
fields,
|
|
111
116
|
plugin: fullTextSearchPlugin
|
|
112
117
|
});
|
|
@@ -119,17 +124,18 @@ const filter = params => {
|
|
|
119
124
|
if (cachedValues[path] !== undefined) {
|
|
120
125
|
return cachedValues[path];
|
|
121
126
|
}
|
|
122
|
-
const plainValue =
|
|
123
|
-
const rawValue =
|
|
127
|
+
const plainValue = getValue(record, path);
|
|
128
|
+
const rawValue = transformValue({
|
|
124
129
|
value: plainValue,
|
|
125
130
|
transform: filter.transformValue
|
|
126
131
|
});
|
|
127
132
|
cachedValues[path] = rawValue;
|
|
128
133
|
return rawValue;
|
|
129
134
|
};
|
|
130
|
-
const exprResult = executeExpressions(
|
|
135
|
+
const exprResult = executeExpressions({
|
|
136
|
+
...expression,
|
|
131
137
|
getCachedValue
|
|
132
|
-
})
|
|
138
|
+
});
|
|
133
139
|
/**
|
|
134
140
|
* If expression result is false we do not need to continue further.
|
|
135
141
|
* Also, if there is no full text search defined, just return the expression result.
|
|
@@ -140,4 +146,5 @@ const filter = params => {
|
|
|
140
146
|
return search(record);
|
|
141
147
|
});
|
|
142
148
|
};
|
|
143
|
-
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["executeFilter","params","value","filter","
|
|
1
|
+
{"version":3,"names":["ValueFilterPlugin","WebinyError","createFullTextSearch","createExpressions","transformValue","getValue","executeFilter","params","value","filter","canUse","plugin","compareValue","matched","matches","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","term","fullTextSearchPlugin","byType","type","find","getOperation","search","targetFields","record","cachedValues","path","undefined","plainValue","rawValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import type {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.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\";\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.plugin.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.plugin.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 Params<T extends CmsEntryValues = CmsEntryValues> {\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\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: Params<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch } = params;\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 });\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 fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\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 plugin: fullTextSearchPlugin\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"],"mappings":"AAKA,SAASA,iBAAiB,QAAQ,8DAA8D;AAChG,OAAOC,WAAW,MAAM,eAAe;AAGvC,SAASC,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,QAAQ;AAOjB,MAAMC,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;;EAEhC;AACJ;AACA;AACA;EACI,MAAMG,MAAM,GAAGD,MAAM,CAACE,MAAM,CAACD,MAAM,CAAC;IAChCF,KAAK;IACLI,YAAY,EAAEH,MAAM,CAACG;EACzB,CAAC,CAAC;EACF,IAAI,CAACF,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,MAAMG,OAAO,GAAGJ,MAAM,CAACE,MAAM,CAACG,OAAO,CAAC;IAClCN,KAAK;IACLI,YAAY,EAAEH,MAAM,CAACG;EACzB,CAAC,CAAC;EACF,IAAIH,MAAM,CAACM,MAAM,EAAE;IACf,OAAOF,OAAO,KAAK,KAAK;EAC5B;EACA,OAAOA,OAAO;AAClB,CAAC;AASD,MAAMG,kBAAkB,GAAIT,MAAg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;IACnB,CAAC;IAED,MAAME,UAAU,GAAG/B,kBAAkB,CAAC;MAAE,GAAGO,UAAU;MAAEL;IAAe,CAAC,CAAC;IACxE;AACR;AACA;AACA;IACQ,IAAI,CAAC6B,UAAU,IAAI,CAACT,MAAM,EAAE;MACxB,OAAOS,UAAU;IACrB;IAEA,OAAOT,MAAM,CAACE,MAAM,CAAC;EACzB,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
2
|
-
import { CmsEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
-
import { Field } from "./types";
|
|
1
|
+
import type { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
2
|
+
import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import type { Field } from "./types.js";
|
|
4
4
|
interface Params {
|
|
5
5
|
term?: string;
|
|
6
6
|
targetFields?: string[];
|