@webiny/api-headless-cms-ddb 0.0.0-unstable.5e7233243f → 0.0.0-unstable.615a930a68
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 +3 -7
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +3 -7
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +3 -7
- package/definitions/model.js.map +1 -1
- package/definitions/settings.js +3 -7
- package/definitions/settings.js.map +1 -1
- package/definitions/system.js +3 -7
- package/definitions/system.js.map +1 -1
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +1 -1
- package/dynamoDb/storage/date.js +14 -4
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.js +1 -1
- package/dynamoDb/storage/richText.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +30 -6
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +7 -9
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +18 -0
- package/operations/entry/filtering/createFields.js +124 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/createFilters.d.ts +20 -0
- package/operations/entry/filtering/createFilters.js +155 -0
- package/operations/entry/filtering/createFilters.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +13 -0
- package/operations/entry/filtering/extractSort.js +55 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +16 -0
- package/operations/entry/filtering/filter.js +137 -0
- package/operations/entry/filtering/filter.js.map +1 -0
- package/operations/entry/filtering/fullTextSearch.d.ts +18 -0
- package/operations/entry/filtering/fullTextSearch.js +64 -0
- package/operations/entry/filtering/fullTextSearch.js.map +1 -0
- package/operations/entry/filtering/getValue.d.ts +5 -0
- package/operations/entry/filtering/getValue.js +81 -0
- package/operations/entry/filtering/getValue.js.map +1 -0
- package/operations/entry/filtering/index.d.ts +2 -0
- package/operations/entry/filtering/index.js +21 -0
- package/operations/entry/filtering/index.js.map +1 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +39 -0
- package/operations/entry/filtering/mapPlugins.js.map +1 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/filtering/plugins/index.js +18 -0
- package/operations/entry/filtering/plugins/index.js.map +1 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +9 -0
- package/operations/entry/filtering/sort.js +80 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +4 -0
- package/operations/entry/filtering/systemFields.js +72 -0
- package/operations/entry/filtering/systemFields.js.map +1 -0
- package/operations/entry/filtering/transform.d.ts +6 -0
- package/operations/entry/filtering/transform.js +19 -0
- package/operations/entry/filtering/transform.js.map +1 -0
- package/operations/entry/filtering/types.d.ts +40 -0
- package/operations/entry/filtering/types.js +5 -0
- package/operations/entry/filtering/types.js.map +1 -0
- package/operations/entry/filtering/where.d.ts +5 -0
- package/operations/entry/filtering/where.js +38 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.js +30 -155
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +1 -1
- package/operations/entry/systemFields.js +6 -0
- package/operations/entry/systemFields.js.map +1 -1
- package/operations/group/index.js +6 -10
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +4 -8
- package/operations/model/index.js.map +1 -1
- package/operations/settings/index.js +6 -10
- package/operations/settings/index.js.map +1 -1
- package/operations/system/index.js +4 -8
- package/operations/system/index.js.map +1 -1
- package/package.json +15 -16
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js +1 -1
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.filter = void 0;
|
|
9
|
+
|
|
10
|
+
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _fullTextSearch = require("./fullTextSearch");
|
|
15
|
+
|
|
16
|
+
var _createFilters = require("./createFilters");
|
|
17
|
+
|
|
18
|
+
var _transform = require("./transform");
|
|
19
|
+
|
|
20
|
+
var _getValue = require("./getValue");
|
|
21
|
+
|
|
22
|
+
const execFilter = params => {
|
|
23
|
+
const {
|
|
24
|
+
value: plainValue,
|
|
25
|
+
filter
|
|
26
|
+
} = params;
|
|
27
|
+
const value = (0, _transform.transformValue)({
|
|
28
|
+
value: plainValue,
|
|
29
|
+
transform: filter.transformValue
|
|
30
|
+
});
|
|
31
|
+
const matched = filter.plugin.matches({
|
|
32
|
+
value,
|
|
33
|
+
compareValue: filter.compareValue
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (filter.negate) {
|
|
37
|
+
return matched === false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return matched;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const filter = async params => {
|
|
44
|
+
const {
|
|
45
|
+
items: records,
|
|
46
|
+
where,
|
|
47
|
+
plugins,
|
|
48
|
+
fields,
|
|
49
|
+
fromStorage,
|
|
50
|
+
fullTextSearch
|
|
51
|
+
} = params;
|
|
52
|
+
const keys = Object.keys(where);
|
|
53
|
+
|
|
54
|
+
if (keys.length === 0 && !fullTextSearch) {
|
|
55
|
+
return records;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const filters = (0, _createFilters.createFilters)({
|
|
59
|
+
plugins,
|
|
60
|
+
where,
|
|
61
|
+
fields
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* No point in going further if there are no filters to be applied and no full text search to be executed.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
if (filters.length === 0 && !fullTextSearch) {
|
|
68
|
+
return records;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* We need the contains plugin to run the full text search.
|
|
72
|
+
* TODO check out to maybe implement fuzzy search.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
|
|
77
|
+
|
|
78
|
+
if (!fullTextSearchPlugin) {
|
|
79
|
+
throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const search = (0, _fullTextSearch.createFullTextSearch)({
|
|
83
|
+
term: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.term,
|
|
84
|
+
targetFields: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.fields,
|
|
85
|
+
fields,
|
|
86
|
+
fromStorage,
|
|
87
|
+
plugin: fullTextSearchPlugin
|
|
88
|
+
});
|
|
89
|
+
const promises = records.map(async record => {
|
|
90
|
+
/**
|
|
91
|
+
* We need to go through all the filters and apply them to the given record.
|
|
92
|
+
*/
|
|
93
|
+
for (const filter of filters) {
|
|
94
|
+
const rawValue = (0, _getValue.getValue)(record, filter.path);
|
|
95
|
+
const field = fields[filter.fieldPathId];
|
|
96
|
+
const plainValue = await fromStorage(field, rawValue);
|
|
97
|
+
const result = execFilter({
|
|
98
|
+
value: plainValue,
|
|
99
|
+
filter
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (result === false) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* If we have full text search defined, run it. Just return the given record if not full text search.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
if (!search) {
|
|
112
|
+
return record;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const result = await search({
|
|
116
|
+
item: record
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (!result) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return record;
|
|
124
|
+
});
|
|
125
|
+
/**
|
|
126
|
+
* We run filtering as promises, so it is a bit faster than in for ... of loop.
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
const results = await Promise.all(promises);
|
|
130
|
+
/**
|
|
131
|
+
* And filter out the null values which are returned when filter is not satisfied.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
return results.filter(Boolean);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
exports.filter = filter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["execFilter","params","value","plainValue","filter","transformValue","transform","matched","plugin","matches","compareValue","negate","items","records","where","plugins","fields","fromStorage","fullTextSearch","keys","Object","length","filters","createFilters","fullTextSearchPlugin","byType","ValueFilterPlugin","type","find","getOperation","WebinyError","search","createFullTextSearch","term","targetFields","promises","map","record","rawValue","getValue","path","field","fieldPathId","result","item","results","Promise","all","Boolean"],"sources":["filter.ts"],"sourcesContent":["import { CmsEntry, CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field, FilterItemFromStorage } from \"./types\";\nimport { createFullTextSearch } from \"./fullTextSearch\";\nimport { createFilters, ItemFilter } from \"./createFilters\";\nimport { transformValue } from \"./transform\";\nimport { getValue } from \"~/operations/entry/filtering/getValue\";\n\ninterface ExecFilterParams {\n value: any;\n filter: ItemFilter;\n}\nconst execFilter = (params: ExecFilterParams) => {\n const { value: plainValue, filter } = params;\n\n const value = transformValue({\n value: plainValue,\n transform: filter.transformValue\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 Params {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fromStorage: FilterItemFromStorage;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = async (params: Params): Promise<CmsEntry[]> => {\n const { items: records, where, plugins, fields, fromStorage, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const filters = createFilters({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no filters to be applied and no full text search to be executed.\n */\n if (filters.length === 0 && !fullTextSearch) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n * TODO check out to maybe implement fuzzy 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 fromStorage,\n plugin: fullTextSearchPlugin\n });\n\n const promises: Promise<CmsEntry | null>[] = records.map(async record => {\n /**\n * We need to go through all the filters and apply them to the given record.\n */\n for (const filter of filters) {\n const rawValue = getValue(record, filter.path);\n\n const field = fields[filter.fieldPathId];\n const plainValue = await fromStorage(field, rawValue);\n\n const result = execFilter({\n value: plainValue,\n filter\n });\n if (result === false) {\n return null;\n }\n }\n /**\n * If we have full text search defined, run it. Just return the given record if not full text search.\n */\n if (!search) {\n return record;\n }\n const result = await search({\n item: record\n });\n if (!result) {\n return null;\n }\n\n return record;\n });\n\n /**\n * We run filtering as promises, so it is a bit faster than in for ... of loop.\n */\n const results: (CmsEntry | null)[] = await Promise.all(promises);\n\n /**\n * And filter out the null values which are returned when filter is not satisfied.\n */\n return results.filter(Boolean) as CmsEntry[];\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
2
|
+
import { CmsEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
+
import { Field, FilterItemFromStorage } from "./types";
|
|
4
|
+
interface Params {
|
|
5
|
+
term?: string;
|
|
6
|
+
targetFields?: string[];
|
|
7
|
+
fromStorage: FilterItemFromStorage;
|
|
8
|
+
fields: Record<string, Field>;
|
|
9
|
+
plugin: ValueFilterPlugin;
|
|
10
|
+
}
|
|
11
|
+
interface FtParams {
|
|
12
|
+
item: CmsEntry;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
16
|
+
*/
|
|
17
|
+
export declare const createFullTextSearch: (params: Params) => (({ item }: FtParams) => Promise<boolean>) | null;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createFullTextSearch = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _getValue = require("./getValue");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
16
|
+
*/
|
|
17
|
+
const createFullTextSearch = params => {
|
|
18
|
+
const {
|
|
19
|
+
term,
|
|
20
|
+
targetFields,
|
|
21
|
+
fromStorage,
|
|
22
|
+
fields: fieldDefinitions,
|
|
23
|
+
plugin
|
|
24
|
+
} = params;
|
|
25
|
+
|
|
26
|
+
if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return async ({
|
|
31
|
+
item
|
|
32
|
+
}) => {
|
|
33
|
+
for (const target of targetFields) {
|
|
34
|
+
/**
|
|
35
|
+
* As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.
|
|
36
|
+
*/
|
|
37
|
+
const field = fieldDefinitions[target];
|
|
38
|
+
|
|
39
|
+
if (!field) {
|
|
40
|
+
throw new _error.default(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
|
|
41
|
+
target
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const targetValue = (0, _getValue.getValue)(item.values, target);
|
|
46
|
+
const value = await fromStorage(field, targetValue);
|
|
47
|
+
|
|
48
|
+
if (!value) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (plugin.matches({
|
|
53
|
+
value,
|
|
54
|
+
compareValue: term
|
|
55
|
+
}) === true) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
exports.createFullTextSearch = createFullTextSearch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFullTextSearch","params","term","targetFields","fromStorage","fields","fieldDefinitions","plugin","trim","length","item","target","field","WebinyError","targetValue","getValue","values","value","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { Field, FilterItemFromStorage } from \"./types\";\nimport { getValue } from \"./getValue\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fromStorage: FilterItemFromStorage;\n fields: Record<string, Field>;\n plugin: ValueFilterPlugin;\n}\n\ninterface FtParams {\n item: CmsEntry;\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, fromStorage, fields: fieldDefinitions, plugin } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return async ({ item }: FtParams) => {\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 targetValue = getValue(item.values, target);\n const value = await fromStorage(field, targetValue);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AAIA;;AAaA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAIC,MAAD,IAAoB;EACpD,MAAM;IAAEC,IAAF;IAAQC,YAAR;IAAsBC,WAAtB;IAAmCC,MAAM,EAAEC,gBAA3C;IAA6DC;EAA7D,IAAwEN,MAA9E;;EACA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACM,IAAL,GAAYC,MAAZ,KAAuB,CAAhC,IAAqC,CAACN,YAAtC,IAAsDA,YAAY,CAACM,MAAb,KAAwB,CAAlF,EAAqF;IACjF,OAAO,IAAP;EACH;;EACD,OAAO,OAAO;IAAEC;EAAF,CAAP,KAA8B;IACjC,KAAK,MAAMC,MAAX,IAAqBR,YAArB,EAAmC;MAC/B;AACZ;AACA;MACY,MAAMS,KAAK,GAAGN,gBAAgB,CAACK,MAAD,CAA9B;;MAEA,IAAI,CAACC,KAAL,EAAY;QACR,MAAM,IAAIC,cAAJ,CAAiB,kBAAiBF,MAAO,iBAAzC,EAA2D,eAA3D,EAA4E;UAC9EA;QAD8E,CAA5E,CAAN;MAGH;;MACD,MAAMG,WAAW,GAAG,IAAAC,kBAAA,EAASL,IAAI,CAACM,MAAd,EAAsBL,MAAtB,CAApB;MACA,MAAMM,KAAK,GAAG,MAAMb,WAAW,CAACQ,KAAD,EAAQE,WAAR,CAA/B;;MACA,IAAI,CAACG,KAAL,EAAY;QACR;MACH;;MACD,IAAIV,MAAM,CAACW,OAAP,CAAe;QAAED,KAAF;QAASE,YAAY,EAAEjB;MAAvB,CAAf,MAAkD,IAAtD,EAA4D;QACxD,OAAO,IAAP;MACH;IACJ;;IACD,OAAO,KAAP;EACH,CAtBD;AAuBH,CA5BM"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getValue = void 0;
|
|
7
|
+
|
|
8
|
+
const addArrayResult = (target, result) => {
|
|
9
|
+
for (const r of result) {
|
|
10
|
+
if (target.some(t => r === t)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
target.push(r);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A recursive function which goes through given input paths and returns the value in it.
|
|
19
|
+
* In case a path is an array, it goes through the array of those values to get values further down the path line.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const find = (target, input) => {
|
|
24
|
+
const paths = [...input];
|
|
25
|
+
const path = paths.shift();
|
|
26
|
+
|
|
27
|
+
if (!path) {
|
|
28
|
+
return undefined;
|
|
29
|
+
} else if (target[path] === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const value = target[path];
|
|
34
|
+
|
|
35
|
+
if (paths.length === 0) {
|
|
36
|
+
return value;
|
|
37
|
+
} else if (Array.isArray(value)) {
|
|
38
|
+
if (value.length === 0) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return value.reduce((collection, v) => {
|
|
43
|
+
const result = find(v, paths);
|
|
44
|
+
|
|
45
|
+
if (result === undefined) {
|
|
46
|
+
return collection;
|
|
47
|
+
} else if (Array.isArray(result)) {
|
|
48
|
+
addArrayResult(collection, result);
|
|
49
|
+
return collection;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
collection.push(result);
|
|
53
|
+
return collection;
|
|
54
|
+
}, []);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return find(value, paths);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A wrapper function for the find function.
|
|
61
|
+
* Basically it transforms input paths to an array (and runs various checks).
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const getValue = (target, input) => {
|
|
66
|
+
const paths = Array.isArray(input) ? input : input.split(".");
|
|
67
|
+
|
|
68
|
+
if (paths.length === 0) {
|
|
69
|
+
throw new Error(`Path is empty!`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const filtered = paths.filter(Boolean);
|
|
73
|
+
|
|
74
|
+
if (paths.length !== filtered.length) {
|
|
75
|
+
throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return find(target, paths);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
exports.getValue = getValue;
|
|
@@ -0,0 +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"],"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>, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n } else if (target[path] === undefined) {\n return undefined;\n }\n const value = target[path];\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,GAAG,CAACC,MAAD,EAAgBC,MAAhB,KAAwC;EAC3D,KAAK,MAAMC,CAAX,IAAgBD,MAAhB,EAAwB;IACpB,IAAID,MAAM,CAACG,IAAP,CAAYC,CAAC,IAAIF,CAAC,KAAKE,CAAvB,CAAJ,EAA+B;MAC3B;IACH;;IACDJ,MAAM,CAACK,IAAP,CAAYH,CAAZ;EACH;AACJ,CAPD;AAQA;AACA;AACA;AACA;;;AACA,MAAMI,IAAI,GAAG,CAACN,MAAD,EAA8BO,KAA9B,KAAqE;EAC9E,MAAMC,KAAK,GAAG,CAAC,GAAGD,KAAJ,CAAd;EACA,MAAME,IAAI,GAAGD,KAAK,CAACE,KAAN,EAAb;;EAEA,IAAI,CAACD,IAAL,EAAW;IACP,OAAOE,SAAP;EACH,CAFD,MAEO,IAAIX,MAAM,CAACS,IAAD,CAAN,KAAiBE,SAArB,EAAgC;IACnC,OAAOA,SAAP;EACH;;EACD,MAAMC,KAAK,GAAGZ,MAAM,CAACS,IAAD,CAApB;;EACA,IAAID,KAAK,CAACK,MAAN,KAAiB,CAArB,EAAwB;IACpB,OAAOD,KAAP;EACH,CAFD,MAEO,IAAIE,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAJ,EAA0B;IAC7B,IAAIA,KAAK,CAACC,MAAN,KAAiB,CAArB,EAAwB;MACpB,OAAOF,SAAP;IACH;;IACD,OAAOC,KAAK,CAACI,MAAN,CAAoB,CAACC,UAAD,EAAaC,CAAb,KAAmB;MAC1C,MAAMjB,MAAM,GAAGK,IAAI,CAACY,CAAD,EAAIV,KAAJ,CAAnB;;MACA,IAAIP,MAAM,KAAKU,SAAf,EAA0B;QACtB,OAAOM,UAAP;MACH,CAFD,MAEO,IAAIH,KAAK,CAACC,OAAN,CAAcd,MAAd,CAAJ,EAA2B;QAC9BF,cAAc,CAACkB,UAAD,EAAahB,MAAb,CAAd;QACA,OAAOgB,UAAP;MACH;;MACDA,UAAU,CAACZ,IAAX,CAAgBJ,MAAhB;MACA,OAAOgB,UAAP;IACH,CAVM,EAUJ,EAVI,CAAP;EAWH;;EACD,OAAOX,IAAI,CAACM,KAAD,EAAQJ,KAAR,CAAX;AACH,CA7BD;AA8BA;AACA;AACA;AACA;;;AACO,MAAMW,QAAQ,GAAG,CAACnB,MAAD,EAA8BO,KAA9B,KAAgE;EACpF,MAAMC,KAAK,GAAGM,KAAK,CAACC,OAAN,CAAcR,KAAd,IAAuBA,KAAvB,GAA+BA,KAAK,CAACa,KAAN,CAAY,GAAZ,CAA7C;;EACA,IAAIZ,KAAK,CAACK,MAAN,KAAiB,CAArB,EAAwB;IACpB,MAAM,IAAIQ,KAAJ,CAAW,gBAAX,CAAN;EACH;;EACD,MAAMC,QAAQ,GAAGd,KAAK,CAACe,MAAN,CAAaC,OAAb,CAAjB;;EACA,IAAIhB,KAAK,CAACK,MAAN,KAAiBS,QAAQ,CAACT,MAA9B,EAAsC;IAClC,MAAM,IAAIQ,KAAJ,CACD,iEAAgEb,KAAK,CAACiB,IAAN,CAC7D,GAD6D,CAE/D,OAAMH,QAAQ,CAACG,IAAT,CAAc,GAAd,CAAmB,GAHzB,CAAN;EAKH;;EAED,OAAOnB,IAAI,CAACN,MAAD,EAASQ,KAAT,CAAX;AACH,CAfM"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
|
|
19
|
+
var _filter = require("./filter");
|
|
20
|
+
|
|
21
|
+
var _sort = require("./sort");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter\";\nexport { sort } from \"./sort\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin, PluginsContainer } from "@webiny/plugins/types";
|
|
2
|
+
interface Params {
|
|
3
|
+
plugins: PluginsContainer;
|
|
4
|
+
type: string;
|
|
5
|
+
property: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const getMappedPlugins: <T extends Plugin<Record<string, any>>>(params: Params) => Record<string, T>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getMappedPlugins = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
const getMappedPlugins = params => {
|
|
13
|
+
const {
|
|
14
|
+
plugins: pluginsContainer,
|
|
15
|
+
type,
|
|
16
|
+
property
|
|
17
|
+
} = params;
|
|
18
|
+
const plugins = pluginsContainer.byType(type);
|
|
19
|
+
|
|
20
|
+
if (plugins.length === 0) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return plugins.reduce((collection, plugin) => {
|
|
25
|
+
const key = plugin[property];
|
|
26
|
+
|
|
27
|
+
if (typeof key !== "string") {
|
|
28
|
+
throw new _error.default("Property to map the plugins on must be a string.", "PLUGIN_PROPERTY_ERROR", {
|
|
29
|
+
type,
|
|
30
|
+
property
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
collection[key] = plugin;
|
|
35
|
+
return collection;
|
|
36
|
+
}, {});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.getMappedPlugins = getMappedPlugins;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getMappedPlugins","params","plugins","pluginsContainer","type","property","byType","length","reduce","collection","plugin","key","WebinyError"],"sources":["mapPlugins.ts"],"sourcesContent":["import { Plugin, PluginsContainer } from \"@webiny/plugins/types\";\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;;AAOO,MAAMA,gBAAgB,GAAsBC,MAAnB,IAAsC;EAClE,MAAM;IAAEC,OAAO,EAAEC,gBAAX;IAA6BC,IAA7B;IAAmCC;EAAnC,IAAgDJ,MAAtD;EACA,MAAMC,OAAO,GAAGC,gBAAgB,CAACG,MAAjB,CAA2BF,IAA3B,CAAhB;;EACA,IAAIF,OAAO,CAACK,MAAR,KAAmB,CAAvB,EAA0B;IACtB,OAAO,EAAP;EACH;;EACD,OAAOL,OAAO,CAACM,MAAR,CAAkC,CAACC,UAAD,EAAaC,MAAb,KAAwB;IAC7D,MAAMC,GAAwB,GAAGD,MAAM,CAACL,QAAD,CAAvC;;IACA,IAAI,OAAOM,GAAP,KAAe,QAAnB,EAA6B;MACzB,MAAM,IAAIC,cAAJ,CACF,kDADE,EAEF,uBAFE,EAGF;QACIR,IADJ;QAEIC;MAFJ,CAHE,CAAN;IAQH;;IACDI,UAAU,CAACE,GAAD,CAAV,GAAkBD,MAAlB;IACA,OAAOD,UAAP;EACH,CAdM,EAcJ,EAdI,CAAP;AAeH,CArBM"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createDefaultFilterCreate = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
|
|
13
|
+
|
|
14
|
+
const createDefaultFilterCreate = () => {
|
|
15
|
+
return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
|
|
16
|
+
fieldType: _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin.ALL,
|
|
17
|
+
create: params => {
|
|
18
|
+
const {
|
|
19
|
+
negate,
|
|
20
|
+
transformValue,
|
|
21
|
+
field,
|
|
22
|
+
compareValue,
|
|
23
|
+
valueFilterPlugins
|
|
24
|
+
} = params;
|
|
25
|
+
const plugin = valueFilterPlugins[params.operation];
|
|
26
|
+
|
|
27
|
+
if (!plugin) {
|
|
28
|
+
throw new _error.default(`Missing ValueFilterPlugin for operation "${params.operation}".`, "MISSING_OPERATION_PLUGIN", {
|
|
29
|
+
operation: params.operation
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
negate,
|
|
35
|
+
transformValue,
|
|
36
|
+
field,
|
|
37
|
+
compareValue,
|
|
38
|
+
fieldPathId: [...field.parents.map(f => f.fieldId), field.fieldId].join("."),
|
|
39
|
+
path: field.createPath({
|
|
40
|
+
field
|
|
41
|
+
}),
|
|
42
|
+
plugin
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.createDefaultFilterCreate = createDefaultFilterCreate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createDefaultFilterCreate","CmsEntryFieldFilterPlugin","fieldType","ALL","create","params","negate","transformValue","field","compareValue","valueFilterPlugins","plugin","operation","WebinyError","fieldPathId","parents","map","f","fieldId","join","path","createPath"],"sources":["defaultFilterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\n\nexport const createDefaultFilterCreate = () => {\n return new CmsEntryFieldFilterPlugin({\n fieldType: CmsEntryFieldFilterPlugin.ALL,\n create: params => {\n const { negate, transformValue, field, compareValue, valueFilterPlugins } = params;\n const plugin = valueFilterPlugins[params.operation];\n if (!plugin) {\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 plugin\n };\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,IAAIC,oDAAJ,CAA8B;IACjCC,SAAS,EAAED,oDAAA,CAA0BE,GADJ;IAEjCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QAAEC,MAAF;QAAUC,cAAV;QAA0BC,KAA1B;QAAiCC,YAAjC;QAA+CC;MAA/C,IAAsEL,MAA5E;MACA,MAAMM,MAAM,GAAGD,kBAAkB,CAACL,MAAM,CAACO,SAAR,CAAjC;;MACA,IAAI,CAACD,MAAL,EAAa;QACT,MAAM,IAAIE,cAAJ,CACD,4CAA2CR,MAAM,CAACO,SAAU,IAD3D,EAEF,0BAFE,EAGF;UACIA,SAAS,EAAEP,MAAM,CAACO;QADtB,CAHE,CAAN;MAOH;;MACD,OAAO;QACHN,MADG;QAEHC,cAFG;QAGHC,KAHG;QAIHC,YAJG;QAKHK,WAAW,EAAE,CAAC,GAAGN,KAAK,CAACO,OAAN,CAAcC,GAAd,CAAkBC,CAAC,IAAIA,CAAC,CAACC,OAAzB,CAAJ,EAAuCV,KAAK,CAACU,OAA7C,EAAsDC,IAAtD,CAA2D,GAA3D,CALV;QAMHC,IAAI,EAAEZ,KAAK,CAACa,UAAN,CAAiB;UACnBb;QADmB,CAAjB,CANH;QASHG;MATG,CAAP;IAWH;EAzBgC,CAA9B,CAAP;AA2BH,CA5BM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createFilterCreatePlugins: () => import("../../../../plugins/CmsEntryFieldFilterPlugin").CmsEntryFieldFilterPlugin[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFilterCreatePlugins = void 0;
|
|
7
|
+
|
|
8
|
+
var _defaultFilterCreate = require("./defaultFilterCreate");
|
|
9
|
+
|
|
10
|
+
var _refFilterCreate = require("./refFilterCreate");
|
|
11
|
+
|
|
12
|
+
var _objectFilterCreate = require("./objectFilterCreate");
|
|
13
|
+
|
|
14
|
+
const createFilterCreatePlugins = () => {
|
|
15
|
+
return [(0, _defaultFilterCreate.createDefaultFilterCreate)(), (0, _refFilterCreate.createRefFilterCreate)(), (0, _objectFilterCreate.objectFilterCreate)()];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.createFilterCreatePlugins = createFilterCreatePlugins;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFilterCreatePlugins","createDefaultFilterCreate","createRefFilterCreate","objectFilterCreate"],"sources":["index.ts"],"sourcesContent":["import { createDefaultFilterCreate } from \"./defaultFilterCreate\";\nimport { createRefFilterCreate } from \"./refFilterCreate\";\nimport { objectFilterCreate } from \"./objectFilterCreate\";\n\nexport const createFilterCreatePlugins = () => {\n return [createDefaultFilterCreate(), createRefFilterCreate(), objectFilterCreate()];\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEO,MAAMA,yBAAyB,GAAG,MAAM;EAC3C,OAAO,CAAC,IAAAC,8CAAA,GAAD,EAA8B,IAAAC,sCAAA,GAA9B,EAAuD,IAAAC,sCAAA,GAAvD,CAAP;AACH,CAFM"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.objectFilterCreate = void 0;
|
|
9
|
+
|
|
10
|
+
var _CmsEntryFieldFilterPlugin = require("../../../../plugins/CmsEntryFieldFilterPlugin");
|
|
11
|
+
|
|
12
|
+
var _where = require("../where");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _transform = require("../transform");
|
|
17
|
+
|
|
18
|
+
const objectFilterCreate = () => {
|
|
19
|
+
return new _CmsEntryFieldFilterPlugin.CmsEntryFieldFilterPlugin({
|
|
20
|
+
fieldType: "object",
|
|
21
|
+
create: params => {
|
|
22
|
+
const {
|
|
23
|
+
value: objectValue,
|
|
24
|
+
valueFilterPlugins,
|
|
25
|
+
transformValuePlugins,
|
|
26
|
+
getFilterCreatePlugin,
|
|
27
|
+
field: parentField,
|
|
28
|
+
fields
|
|
29
|
+
} = params;
|
|
30
|
+
const filters = [];
|
|
31
|
+
|
|
32
|
+
for (const key in objectValue) {
|
|
33
|
+
const value = objectValue[key];
|
|
34
|
+
|
|
35
|
+
if (value === undefined) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const whereParams = (0, _where.extractWhereParams)(key);
|
|
40
|
+
|
|
41
|
+
if (!whereParams) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
negate,
|
|
47
|
+
fieldId,
|
|
48
|
+
operation
|
|
49
|
+
} = whereParams;
|
|
50
|
+
const fieldPath = parentField.parents.map(p => p.fieldId).concat([parentField.fieldId, fieldId]).join(".");
|
|
51
|
+
const field = fields[fieldPath];
|
|
52
|
+
|
|
53
|
+
if (!field) {
|
|
54
|
+
throw new _error.default(`There is no field with the field path "${fieldPath}".`, "FIELD_ERROR", {
|
|
55
|
+
fieldId
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
60
|
+
const transformValuePlugin = transformValuePlugins[field.type];
|
|
61
|
+
|
|
62
|
+
const transformValueCallable = value => {
|
|
63
|
+
if (!transformValuePlugin) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return transformValuePlugin.transform({
|
|
68
|
+
field,
|
|
69
|
+
value
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const result = filterCreatePlugin.create({
|
|
74
|
+
key,
|
|
75
|
+
value,
|
|
76
|
+
valueFilterPlugins,
|
|
77
|
+
transformValuePlugins,
|
|
78
|
+
getFilterCreatePlugin,
|
|
79
|
+
operation,
|
|
80
|
+
negate,
|
|
81
|
+
field,
|
|
82
|
+
fields,
|
|
83
|
+
compareValue: (0, _transform.transformValue)({
|
|
84
|
+
value,
|
|
85
|
+
transform: transformValueCallable
|
|
86
|
+
}),
|
|
87
|
+
transformValue: transformValueCallable
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (!result) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (Array.isArray(result)) {
|
|
95
|
+
filters.push(...result);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
filters.push(result);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return filters;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.objectFilterCreate = objectFilterCreate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["objectFilterCreate","CmsEntryFieldFilterPlugin","fieldType","create","params","value","objectValue","valueFilterPlugins","transformValuePlugins","getFilterCreatePlugin","field","parentField","fields","filters","key","undefined","whereParams","extractWhereParams","negate","fieldId","operation","fieldPath","parents","map","p","concat","join","WebinyError","filterCreatePlugin","type","transformValuePlugin","transformValueCallable","transform","result","compareValue","transformValue","Array","isArray","push"],"sources":["objectFilterCreate.ts"],"sourcesContent":["import { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { extractWhereParams } from \"~/operations/entry/filtering/where\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { transformValue } from \"~/operations/entry/filtering/transform\";\n\nexport const objectFilterCreate = () => {\n return new CmsEntryFieldFilterPlugin({\n fieldType: \"object\",\n create: params => {\n const {\n value: objectValue,\n valueFilterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n field: parentField,\n fields\n } = params;\n\n const filters = [];\n\n for (const key in objectValue) {\n const value = objectValue[key];\n if (value === undefined) {\n continue;\n }\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n const { negate, fieldId, operation } = whereParams;\n\n const fieldPath = parentField.parents\n .map(p => p.fieldId)\n .concat([parentField.fieldId, fieldId])\n .join(\".\");\n\n const field = fields[fieldPath];\n if (!field) {\n throw new WebinyError(\n `There is no field with the field path \"${fieldPath}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n if (!result) {\n continue;\n }\n if (Array.isArray(result)) {\n filters.push(...result);\n continue;\n }\n\n filters.push(result);\n }\n return filters;\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEO,MAAMA,kBAAkB,GAAG,MAAM;EACpC,OAAO,IAAIC,oDAAJ,CAA8B;IACjCC,SAAS,EAAE,QADsB;IAEjCC,MAAM,EAAEC,MAAM,IAAI;MACd,MAAM;QACFC,KAAK,EAAEC,WADL;QAEFC,kBAFE;QAGFC,qBAHE;QAIFC,qBAJE;QAKFC,KAAK,EAAEC,WALL;QAMFC;MANE,IAOFR,MAPJ;MASA,MAAMS,OAAO,GAAG,EAAhB;;MAEA,KAAK,MAAMC,GAAX,IAAkBR,WAAlB,EAA+B;QAC3B,MAAMD,KAAK,GAAGC,WAAW,CAACQ,GAAD,CAAzB;;QACA,IAAIT,KAAK,KAAKU,SAAd,EAAyB;UACrB;QACH;;QACD,MAAMC,WAAW,GAAG,IAAAC,yBAAA,EAAmBH,GAAnB,CAApB;;QACA,IAAI,CAACE,WAAL,EAAkB;UACd;QACH;;QACD,MAAM;UAAEE,MAAF;UAAUC,OAAV;UAAmBC;QAAnB,IAAiCJ,WAAvC;QAEA,MAAMK,SAAS,GAAGV,WAAW,CAACW,OAAZ,CACbC,GADa,CACTC,CAAC,IAAIA,CAAC,CAACL,OADE,EAEbM,MAFa,CAEN,CAACd,WAAW,CAACQ,OAAb,EAAsBA,OAAtB,CAFM,EAGbO,IAHa,CAGR,GAHQ,CAAlB;QAKA,MAAMhB,KAAK,GAAGE,MAAM,CAACS,SAAD,CAApB;;QACA,IAAI,CAACX,KAAL,EAAY;UACR,MAAM,IAAIiB,cAAJ,CACD,0CAAyCN,SAAU,IADlD,EAEF,aAFE,EAGF;YACIF;UADJ,CAHE,CAAN;QAOH;;QAED,MAAMS,kBAAkB,GAAGnB,qBAAqB,CAACC,KAAK,CAACmB,IAAP,CAAhD;QAEA,MAAMC,oBAAwD,GAC1DtB,qBAAqB,CAACE,KAAK,CAACmB,IAAP,CADzB;;QAGA,MAAME,sBAAsB,GAAI1B,KAAD,IAAgB;UAC3C,IAAI,CAACyB,oBAAL,EAA2B;YACvB,OAAOzB,KAAP;UACH;;UACD,OAAOyB,oBAAoB,CAACE,SAArB,CAA+B;YAClCtB,KADkC;YAElCL;UAFkC,CAA/B,CAAP;QAIH,CARD;;QAUA,MAAM4B,MAAM,GAAGL,kBAAkB,CAACzB,MAAnB,CAA0B;UACrCW,GADqC;UAErCT,KAFqC;UAGrCE,kBAHqC;UAIrCC,qBAJqC;UAKrCC,qBALqC;UAMrCW,SANqC;UAOrCF,MAPqC;UAQrCR,KARqC;UASrCE,MATqC;UAUrCsB,YAAY,EAAE,IAAAC,yBAAA,EAAe;YACzB9B,KADyB;YAEzB2B,SAAS,EAAED;UAFc,CAAf,CAVuB;UAcrCI,cAAc,EAAEJ;QAdqB,CAA1B,CAAf;;QAgBA,IAAI,CAACE,MAAL,EAAa;UACT;QACH;;QACD,IAAIG,KAAK,CAACC,OAAN,CAAcJ,MAAd,CAAJ,EAA2B;UACvBpB,OAAO,CAACyB,IAAR,CAAa,GAAGL,MAAhB;UACA;QACH;;QAEDpB,OAAO,CAACyB,IAAR,CAAaL,MAAb;MACH;;MACD,OAAOpB,OAAP;IACH;EAnFgC,CAA9B,CAAP;AAqFH,CAtFM"}
|