@webiny/api-headless-cms-ddb 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
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 -6
- package/definitions/entry.js +5 -180
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -6
- package/definitions/group.js +5 -58
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -6
- package/definitions/model.js +5 -102
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +3 -5
- package/definitions/table.js +6 -28
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +61 -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 +4 -13
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +1 -1
- package/dynamoDb/path/locationFolderId.js +5 -14
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +5 -14
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +5 -12
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -3
- package/index.js +62 -92
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -2
- package/operations/entry/dataLoader/DataLoaderCache.js +3 -13
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +1 -7
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +4 -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 +16 -26
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +27 -33
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +27 -33
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +29 -35
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.d.ts +3 -3
- package/operations/entry/dataLoader/index.js +10 -31
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +4 -4
- package/operations/entry/dataLoader/types.js +1 -5
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +11 -12
- package/operations/entry/dataLoaders.js +16 -24
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +7 -6
- package/operations/entry/filtering/createExpressions.js +29 -35
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +2 -2
- package/operations/entry/filtering/createFields.js +20 -22
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +5 -5
- package/operations/entry/filtering/extractSort.js +38 -23
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +7 -6
- package/operations/entry/filtering/filter.js +22 -27
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +4 -4
- package/operations/entry/filtering/fullTextSearch.js +7 -15
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +1 -8
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.d.ts +2 -2
- package/operations/entry/filtering/index.js +2 -19
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +1 -1
- package/operations/entry/filtering/mapPlugins.js +3 -11
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +10 -18
- 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 +6 -13
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +15 -21
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/refFilterCreate.js +16 -22
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +14 -17
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.d.ts +5 -5
- package/operations/entry/filtering/sort.js +15 -19
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -4
- package/operations/entry/filtering/systemFields.js +70 -29
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js +1 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +4 -4
- package/operations/entry/filtering/types.js +1 -5
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +1 -1
- package/operations/entry/filtering/values.js +4 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +1 -8
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +4 -3
- package/operations/entry/index.js +279 -388
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +40 -2
- package/operations/entry/keys.js +53 -30
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +4 -5
- package/operations/group/index.js +37 -69
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +36 -59
- package/operations/model/index.js.map +1 -1
- package/package.json +24 -20
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js +4 -12
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +5 -5
- package/plugins/CmsEntryFieldFilterPlugin.js +2 -8
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldSortingPlugin.js +3 -11
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.js +2 -9
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +4 -4
- package/plugins/index.js +4 -49
- package/plugins/index.js.map +1 -1
- package/types.d.ts +20 -20
- package/types.js +1 -8
- package/types.js.map +1 -1
- package/definitions/system.d.ts +0 -10
- package/definitions/system.js +0 -42
- package/definitions/system.js.map +0 -1
- package/dynamoDb/storage/longText.d.ts +0 -10
- package/dynamoDb/storage/longText.js +0 -94
- package/dynamoDb/storage/longText.js.map +0 -1
- package/dynamoDb/storage/richText.d.ts +0 -2
- package/dynamoDb/storage/richText.js +0 -61
- package/dynamoDb/storage/richText.js.map +0 -1
- package/operations/system/index.d.ts +0 -7
- package/operations/system/index.js +0 -94
- package/operations/system/index.js.map +0 -1
|
@@ -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,6 +80,5 @@ const extractSort = params => {
|
|
|
64
80
|
reverse: order === "DESC"
|
|
65
81
|
};
|
|
66
82
|
};
|
|
67
|
-
exports.extractSort = extractSort;
|
|
68
83
|
|
|
69
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 valueP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AO,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,15 +1,16 @@
|
|
|
1
|
-
import type { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
1
|
+
import type { CmsContext, CmsEntry, CmsEntryListWhere, CmsEntryValues } from "@webiny/api-headless-cms/types/index.js";
|
|
2
2
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import type { Field } from "./types";
|
|
4
|
-
interface
|
|
5
|
-
items: CmsEntry[];
|
|
6
|
-
where: Partial<CmsEntryListWhere>;
|
|
3
|
+
import type { Field } from "./types.js";
|
|
4
|
+
interface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {
|
|
7
5
|
plugins: PluginsContainer;
|
|
6
|
+
container: CmsContext["container"];
|
|
7
|
+
items: CmsEntry<T>[];
|
|
8
|
+
where: Partial<CmsEntryListWhere>;
|
|
8
9
|
fields: Record<string, Field>;
|
|
9
10
|
fullTextSearch?: {
|
|
10
11
|
term?: string;
|
|
11
12
|
fields?: string[];
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
export declare const filter: (params:
|
|
15
|
+
export declare const filter: <T extends CmsEntryValues = CmsEntryValues>(params: IFilterParams<T>) => CmsEntry<T>[];
|
|
15
16
|
export {};
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
exports.filter = void 0;
|
|
8
|
-
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var _fullTextSearch = require("./fullTextSearch");
|
|
11
|
-
var _createExpressions = require("./createExpressions");
|
|
12
|
-
var _transform = require("./transform");
|
|
13
|
-
var _getValue = require("./getValue");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { createFullTextSearch } from "./fullTextSearch.js";
|
|
3
|
+
import { createExpressions } from "./createExpressions.js";
|
|
4
|
+
import { transformValue } from "./transform.js";
|
|
5
|
+
import { getValue } from "./getValue.js";
|
|
6
|
+
import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
14
7
|
const executeFilter = params => {
|
|
15
8
|
const {
|
|
16
9
|
value,
|
|
@@ -21,14 +14,14 @@ const executeFilter = params => {
|
|
|
21
14
|
* We need to check if the filter can be used.
|
|
22
15
|
* If it cannot, we will just return true.
|
|
23
16
|
*/
|
|
24
|
-
const canUse = filter.
|
|
17
|
+
const canUse = filter.filter.canUse({
|
|
25
18
|
value,
|
|
26
19
|
compareValue: filter.compareValue
|
|
27
20
|
});
|
|
28
21
|
if (!canUse) {
|
|
29
22
|
return true;
|
|
30
23
|
}
|
|
31
|
-
const matched = filter.
|
|
24
|
+
const matched = filter.filter.matches({
|
|
32
25
|
value,
|
|
33
26
|
compareValue: filter.compareValue
|
|
34
27
|
});
|
|
@@ -85,22 +78,25 @@ const executeExpressions = params => {
|
|
|
85
78
|
*/
|
|
86
79
|
return condition === "OR" ? false : true;
|
|
87
80
|
};
|
|
88
|
-
const filter = params => {
|
|
81
|
+
export const filter = params => {
|
|
89
82
|
const {
|
|
90
83
|
items: records,
|
|
91
84
|
where,
|
|
92
85
|
plugins,
|
|
93
86
|
fields,
|
|
94
|
-
fullTextSearch
|
|
87
|
+
fullTextSearch,
|
|
88
|
+
container
|
|
95
89
|
} = params;
|
|
90
|
+
const valueFilterRegistry = container.resolve(ValueFilterRegistry);
|
|
96
91
|
const keys = Object.keys(where);
|
|
97
92
|
if (keys.length === 0 && !fullTextSearch) {
|
|
98
93
|
return records;
|
|
99
94
|
}
|
|
100
|
-
const expression =
|
|
95
|
+
const expression = createExpressions({
|
|
101
96
|
plugins,
|
|
102
97
|
where,
|
|
103
|
-
fields
|
|
98
|
+
fields,
|
|
99
|
+
container
|
|
104
100
|
});
|
|
105
101
|
|
|
106
102
|
/**
|
|
@@ -112,15 +108,15 @@ const filter = params => {
|
|
|
112
108
|
/**
|
|
113
109
|
* We need the contains plugin to run the full text search.
|
|
114
110
|
*/
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
117
|
-
throw new
|
|
111
|
+
const fullTextSearchFilter = valueFilterRegistry.get("contains");
|
|
112
|
+
if (!fullTextSearchFilter) {
|
|
113
|
+
throw new WebinyError(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
118
114
|
}
|
|
119
|
-
const search =
|
|
115
|
+
const search = createFullTextSearch({
|
|
120
116
|
term: fullTextSearch?.term,
|
|
121
117
|
targetFields: fullTextSearch?.fields,
|
|
122
118
|
fields,
|
|
123
|
-
|
|
119
|
+
filter: fullTextSearchFilter
|
|
124
120
|
});
|
|
125
121
|
return records.filter(record => {
|
|
126
122
|
const cachedValues = {};
|
|
@@ -131,8 +127,8 @@ const filter = params => {
|
|
|
131
127
|
if (cachedValues[path] !== undefined) {
|
|
132
128
|
return cachedValues[path];
|
|
133
129
|
}
|
|
134
|
-
const plainValue =
|
|
135
|
-
const rawValue =
|
|
130
|
+
const plainValue = getValue(record, path);
|
|
131
|
+
const rawValue = transformValue({
|
|
136
132
|
value: plainValue,
|
|
137
133
|
transform: filter.transformValue
|
|
138
134
|
});
|
|
@@ -153,6 +149,5 @@ const filter = params => {
|
|
|
153
149
|
return search(record);
|
|
154
150
|
});
|
|
155
151
|
};
|
|
156
|
-
exports.filter = filter;
|
|
157
152
|
|
|
158
153
|
//# sourceMappingURL=filter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","createFullTextSearch","createExpressions","transformValue","getValue","ValueFilterRegistry","executeFilter","params","value","filter","canUse","compareValue","matched","matches","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","container","valueFilterRegistry","resolve","keys","Object","term","fullTextSearchFilter","get","search","targetFields","record","cachedValues","path","undefined","plainValue","rawValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { createFullTextSearch } from \"./fullTextSearch.js\";\nimport type { Expression, ExpressionCondition, Filter } from \"./createExpressions.js\";\nimport { createExpressions } from \"./createExpressions.js\";\nimport { transformValue } from \"./transform.js\";\nimport { getValue } from \"~/operations/entry/filtering/getValue.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n /**\n * We need to check if the filter can be used.\n * If it cannot, we will just return true.\n */\n const canUse = filter.filter.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\n\n const matched = filter.filter.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface IFilterParams<T extends CmsEntryValues = CmsEntryValues> {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\n items: CmsEntry<T>[];\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = <T extends CmsEntryValues = CmsEntryValues>(\n params: IFilterParams<T>\n): CmsEntry<T>[] => {\n const { items: records, where, plugins, fields, fullTextSearch, container } = params;\n\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields,\n container\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchFilter = valueFilterRegistry.get(\"contains\");\n if (!fullTextSearchFilter) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n filter: fullTextSearchFilter\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"mappings":"AAMA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,QAAQ;AACjB,SAASC,mBAAmB,QAAQ,uCAAuC;AAO3E,MAAMC,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;;EAEhC;AACJ;AACA;AACA;EACI,MAAMG,MAAM,GAAGD,MAAM,CAACA,MAAM,CAACC,MAAM,CAA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MAAM;MACvB,IAAI+B,YAAY,CAACC,IAAI,CAAC,KAAKC,SAAS,EAAE;QAClC,OAAOF,YAAY,CAACC,IAAI,CAAC;MAC7B;MACA,MAAME,UAAU,GAAGvC,QAAQ,CAACmC,MAAM,EAAEE,IAAI,CAAC;MAEzC,MAAMG,QAAQ,GAAGzC,cAAc,CAAC;QAC5BK,KAAK,EAAEmC,UAAU;QACjBE,SAAS,EAAEpC,MAAM,CAACN;MACtB,CAAC,CAAC;MAEFqC,YAAY,CAACC,IAAI,CAAC,GAAGG,QAAQ;MAC7B,OAAOA,QAAQ;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,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
1
|
+
import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { Field } from "./types.js";
|
|
3
|
+
import { ValueFilter } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
4
4
|
interface Params {
|
|
5
5
|
term?: string;
|
|
6
6
|
targetFields?: string[];
|
|
7
7
|
fields: Record<string, Field>;
|
|
8
|
-
|
|
8
|
+
filter: ValueFilter.Interface;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createFullTextSearch = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _getValue = require("./getValue");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { getValue } from "./getValue.js";
|
|
10
3
|
/**
|
|
11
4
|
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
12
5
|
*/
|
|
13
|
-
const createFullTextSearch = params => {
|
|
6
|
+
export const createFullTextSearch = params => {
|
|
14
7
|
const {
|
|
15
8
|
term,
|
|
16
9
|
targetFields,
|
|
17
10
|
fields: fieldDefinitions,
|
|
18
|
-
|
|
11
|
+
filter
|
|
19
12
|
} = params;
|
|
20
13
|
if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
|
|
21
14
|
return null;
|
|
@@ -27,15 +20,15 @@ const createFullTextSearch = params => {
|
|
|
27
20
|
*/
|
|
28
21
|
const field = fieldDefinitions[target];
|
|
29
22
|
if (!field) {
|
|
30
|
-
throw new
|
|
23
|
+
throw new WebinyError(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
|
|
31
24
|
target
|
|
32
25
|
});
|
|
33
26
|
}
|
|
34
|
-
const value =
|
|
27
|
+
const value = getValue(item, target);
|
|
35
28
|
if (!value) {
|
|
36
29
|
continue;
|
|
37
30
|
}
|
|
38
|
-
if (
|
|
31
|
+
if (filter.matches({
|
|
39
32
|
value,
|
|
40
33
|
compareValue: term
|
|
41
34
|
}) === true) {
|
|
@@ -45,6 +38,5 @@ const createFullTextSearch = params => {
|
|
|
45
38
|
return false;
|
|
46
39
|
};
|
|
47
40
|
};
|
|
48
|
-
exports.createFullTextSearch = createFullTextSearch;
|
|
49
41
|
|
|
50
42
|
//# sourceMappingURL=fullTextSearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","getValue","createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","filter","trim","length","item","target","field","value","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Field } from \"./types.js\";\nimport { getValue } from \"./getValue.js\";\nimport { ValueFilter } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n filter: ValueFilter.Interface;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, filter } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item, target);\n if (!value) {\n continue;\n }\n if (filter.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,QAAQ;AAUjB;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,MAAc,IAAK;EACpD,MAAM;IAAEC,IAAI;IAAEC,YAAY;IAAEC,MAAM,EAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACvE,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACK,IAAI,CAAC,CAAC,CAACC,MAAM,KAAK,CAAC,IAAI,CAACL,YAAY,IAAIA,YAAY,CAACK,MAAM,KAAK,CAAC,EAAE;IACjF,OAAO,IAAI;EACf;EACA,OAAQC,IAAc,IAAK;IACvB,KAAK,MAAMC,MAAM,IAAIP,YAAY,EAAE;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAM,CAAC;MAEtC,IAAI,CAACC,KAAK,EAAE;QACR,MAAM,IAAIb,WAAW,CAAC,kBAAkBY,MAAM,iBAAiB,EAAE,eAAe,EAAE;UAC9EA;QACJ,CAAC,CAAC;MACN;MACA,MAAME,KAAK,GAAGb,QAAQ,CAACU,IAAI,EAAEC,MAAM,CAAC;MACpC,IAAI,CAACE,KAAK,EAAE;QACR;MACJ;MACA,IAAIN,MAAM,CAACO,OAAO,CAAC;QAAED,KAAK;QAAEE,YAAY,EAAEZ;MAAK,CAAC,CAAC,KAAK,IAAI,EAAE;QACxD,OAAO,IAAI;MACf;IACJ;IACA,OAAO,KAAK;EAChB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getValue = void 0;
|
|
7
1
|
const addArrayResult = (target, result) => {
|
|
8
2
|
for (const r of result) {
|
|
9
3
|
if (target.some(t => r === t)) {
|
|
@@ -50,7 +44,7 @@ const find = (target, input) => {
|
|
|
50
44
|
* A wrapper function for the find function.
|
|
51
45
|
* Basically it transforms input paths to an array (and runs various checks).
|
|
52
46
|
*/
|
|
53
|
-
const getValue = (target, input) => {
|
|
47
|
+
export const getValue = (target, input) => {
|
|
54
48
|
const paths = Array.isArray(input) ? input : input.split(".");
|
|
55
49
|
if (paths.length === 0) {
|
|
56
50
|
throw new Error(`Path is empty!`);
|
|
@@ -61,6 +55,5 @@ const getValue = (target, input) => {
|
|
|
61
55
|
}
|
|
62
56
|
return find(target, paths);
|
|
63
57
|
};
|
|
64
|
-
exports.getValue = getValue;
|
|
65
58
|
|
|
66
59
|
//# sourceMappingURL=getValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"
|
|
1
|
+
{"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any> | undefined, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n }\n\n const value = target?.[path];\n if (value === undefined) {\n return undefined;\n }\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":"AAAA,MAAMA,cAAc,GAAGA,CAACC,MAAa,EAAEC,MAAa,KAAW;EAC3D,KAAK,MAAMC,CAAC,IAAID,MAAM,EAAE;IACpB,IAAID,MAAM,CAACG,IAAI,CAACC,CAAC,IAAIF,CAAC,KAAKE,CAAC,CAAC,EAAE;MAC3B;IACJ;IACAJ,MAAM,CAACK,IAAI,CAACH,CAA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KAAK,CAAC,GAAGA,KAAK,GAAGA,KAAK,CAACa,KAAK,CAAC,GAAG,CAAC;EAC7D,IAAIZ,KAAK,CAACK,MAAM,KAAK,CAAC,EAAE;IACpB,MAAM,IAAIQ,KAAK,CAAC,gBAAgB,CAAC;EACrC;EACA,MAAMC,QAAQ,GAAGd,KAAK,CAACe,MAAM,CAACC,OAAO,CAAC;EACtC,IAAIhB,KAAK,CAACK,MAAM,KAAKS,QAAQ,CAACT,MAAM,EAAE;IAClC,MAAM,IAAIQ,KAAK,CACX,iEAAiEb,KAAK,CAACiB,IAAI,CACvE,GACJ,CAAC,OAAOH,QAAQ,CAACG,IAAI,CAAC,GAAG,CAAC,GAC9B,CAAC;EACL;EAEA,OAAOnB,IAAI,CAACN,MAAM,EAAEQ,KAAK,CAAC;AAC9B,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { filter } from "./filter";
|
|
2
|
-
export { sort } from "./sort";
|
|
1
|
+
export { filter } from "./filter.js";
|
|
2
|
+
export { sort } from "./sort.js";
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "filter", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _filter.filter;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "sort", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _sort.sort;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _filter = require("./filter");
|
|
19
|
-
var _sort = require("./sort");
|
|
1
|
+
export { filter } from "./filter.js";
|
|
2
|
+
export { sort } from "./sort.js";
|
|
20
3
|
|
|
21
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["filter","sort"],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter.js\";\nexport { sort } from \"./sort.js\";\n"],"mappings":"AAAA,SAASA,MAAM;AACf,SAASC,IAAI","ignoreList":[]}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.getMappedPlugins = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
const getMappedPlugins = params => {
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
export const getMappedPlugins = params => {
|
|
10
3
|
const {
|
|
11
4
|
plugins: pluginsContainer,
|
|
12
5
|
type,
|
|
@@ -19,7 +12,7 @@ const getMappedPlugins = params => {
|
|
|
19
12
|
return plugins.reduce((collection, plugin) => {
|
|
20
13
|
const key = plugin[property];
|
|
21
14
|
if (typeof key !== "string") {
|
|
22
|
-
throw new
|
|
15
|
+
throw new WebinyError("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
|
|
23
16
|
type,
|
|
24
17
|
property
|
|
25
18
|
});
|
|
@@ -28,6 +21,5 @@ const getMappedPlugins = params => {
|
|
|
28
21
|
return collection;
|
|
29
22
|
}, {});
|
|
30
23
|
};
|
|
31
|
-
exports.getMappedPlugins = getMappedPlugins;
|
|
32
24
|
|
|
33
25
|
//# sourceMappingURL=mapPlugins.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","getMappedPlugins","params","plugins","pluginsContainer","type","property","byType","length","reduce","collection","plugin","key"],"sources":["mapPlugins.ts"],"sourcesContent":["import type { Plugin, PluginsContainer } from \"@webiny/plugins/types.js\";\nimport WebinyError from \"@webiny/error\";\n\ninterface Params {\n plugins: PluginsContainer;\n type: string;\n property: string;\n}\nexport const getMappedPlugins = <T extends Plugin>(params: Params) => {\n const { plugins: pluginsContainer, type, property } = params;\n const plugins = pluginsContainer.byType<T>(type);\n if (plugins.length === 0) {\n return {};\n }\n return plugins.reduce<Record<string, T>>((collection, plugin) => {\n const key: keyof typeof plugin = plugin[property];\n if (typeof key !== \"string\") {\n throw new WebinyError(\n \"Property to map the plugins on must be a string.\",\n \"PLUGIN_PROPERTY_ERROR\",\n {\n type,\n property\n }\n );\n }\n collection[key] = plugin;\n return collection;\n }, {});\n};\n"],"mappings":"AACA,OAAOA,WAAW,MAAM,eAAe;AAOvC,OAAO,MAAMC,gBAAgB,GAAsBC,MAAc,IAAK;EAClE,MAAM;IAAEC,OAAO,EAAEC,gBAAgB;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGJ,MAAM;EAC5D,MAAMC,OAAO,GAAGC,gBAAgB,CAACG,MAAM,CAAIF,IAAI,CAAC;EAChD,IAAIF,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,CAAC,CAAC;EACb;EACA,OAAOL,OAAO,CAACM,MAAM,CAAoB,CAACC,UAAU,EAAEC,MAAM,KAAK;IAC7D,MAAMC,GAAwB,GAAGD,MAAM,CAACL,QAAQ,CAAC;IACjD,IAAI,OAAOM,GAAG,KAAK,QAAQ,EAAE;MACzB,MAAM,IAAIZ,WAAW,CACjB,kDAAkD,EAClD,uBAAuB,EACvB;QACIK,IAAI;QACJC;MACJ,CACJ,CAAC;IACL;IACAI,UAAU,CAACE,GAAG,CAAC,GAAGD,MAAM;IACxB,OAAOD,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAAC;AACV,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin";
|
|
1
|
+
import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
2
2
|
export declare const createDefaultFilterCreate: () => CmsEntryFieldFilterPlugin<any>;
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
exports.createDefaultFilterCreate = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
|
|
10
|
-
const createDefaultFilterCreate = () => {
|
|
11
|
-
const plugin = new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
|
|
12
|
-
fieldType: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.ALL,
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { CmsEntryFieldFilterPlugin } from "../../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
3
|
+
export const createDefaultFilterCreate = () => {
|
|
4
|
+
const plugin = new CmsEntryFieldFilterPlugin({
|
|
5
|
+
fieldType: CmsEntryFieldFilterPlugin.ALL,
|
|
13
6
|
create: params => {
|
|
14
7
|
const {
|
|
15
8
|
negate,
|
|
16
9
|
transformValue,
|
|
17
10
|
field,
|
|
18
11
|
compareValue,
|
|
19
|
-
|
|
12
|
+
valueFilterRegistry
|
|
20
13
|
} = params;
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
23
|
-
throw new
|
|
14
|
+
const filter = valueFilterRegistry.get(params.operation);
|
|
15
|
+
if (!filter) {
|
|
16
|
+
throw new WebinyError(`Missing ValueFilterPlugin for operation "${params.operation}".`, "MISSING_OPERATION_PLUGIN", {
|
|
24
17
|
operation: params.operation
|
|
25
18
|
});
|
|
26
19
|
}
|
|
@@ -33,13 +26,12 @@ const createDefaultFilterCreate = () => {
|
|
|
33
26
|
path: field.createPath({
|
|
34
27
|
field
|
|
35
28
|
}),
|
|
36
|
-
|
|
29
|
+
filter
|
|
37
30
|
};
|
|
38
31
|
}
|
|
39
32
|
});
|
|
40
33
|
plugin.name = `headless-cms.ddb.filter.default`;
|
|
41
34
|
return plugin;
|
|
42
35
|
};
|
|
43
|
-
exports.createDefaultFilterCreate = createDefaultFilterCreate;
|
|
44
36
|
|
|
45
37
|
//# sourceMappingURL=defaultFilterCreate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","CmsEntryFieldFilterPlugin","createDefaultFilterCreate","plugin","fieldType","ALL","create","params","negate","transformValue","field","compareValue","valueFilterRegistry","filter","get","operation","fieldPathId","parents","map","f","fieldId","join","path","createPath","name"],"sources":["defaultFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\n\nexport const createDefaultFilterCreate = () => {\n const plugin = new CmsEntryFieldFilterPlugin({\n fieldType: CmsEntryFieldFilterPlugin.ALL,\n create: params => {\n const { negate, transformValue, field, compareValue, valueFilterRegistry } = params;\n const filter = valueFilterRegistry.get(params.operation);\n if (!filter) {\n throw new WebinyError(\n `Missing ValueFilterPlugin for operation \"${params.operation}\".`,\n \"MISSING_OPERATION_PLUGIN\",\n {\n operation: params.operation\n }\n );\n }\n return {\n negate,\n transformValue,\n field,\n compareValue,\n fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join(\".\"),\n path: field.createPath({\n field\n }),\n filter\n };\n }\n });\n\n plugin.name = `headless-cms.ddb.filter.default`;\n\n return plugin;\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AACvC,SAASC,yBAAyB;AAElC,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIF,yBAAyB,CAAC;IACzCG,SAAS,EAAEH,yBAAyB,CAACI,GAAG;IACxCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,MAAM;QAAEC,cAAc;QAAEC,KAAK;QAAEC,YAAY;QAAEC;MAAoB,CAAC,GAAGL,MAAM;MACnF,MAAMM,MAAM,GAAGD,mBAAmB,CAACE,GAAG,CAACP,MAAM,CAACQ,SAAS,CAAC;MACxD,IAAI,CAACF,MAAM,EAAE;QACT,MAAM,IAAIb,WAAW,CACjB,4CAA4CO,MAAM,CAACQ,SAAS,IAAI,EAChE,0BAA0B,EAC1B;UACIA,SAAS,EAAER,MAAM,CAACQ;QACtB,CACJ,CAAC;MACL;MACA,OAAO;QACHP,MAAM;QACNC,cAAc;QACdC,KAAK;QACLC,YAAY;QACZK,WAAW,EAAE,CAAC,GAAGN,KAAK,CAACO,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,OAAO,CAAC,EAAEV,KAAK,CAACU,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;QAC5EC,IAAI,EAAEZ,KAAK,CAACa,UAAU,CAAC;UACnBb;QACJ,CAAC,CAAC;QACFG;MACJ,CAAC;IACL;EACJ,CAAC,CAAC;EAEFV,MAAM,CAACqB,IAAI,GAAG,iCAAiC;EAE/C,OAAOrB,MAAM;AACjB,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const createFilterCreatePlugins: () => import("
|
|
1
|
+
export declare const createFilterCreatePlugins: () => import("../../../../index.js").CmsEntryFieldFilterPlugin<import("@webiny/api/types.js").GenericRecord | null | undefined>[];
|