@webiny/api-headless-cms-ddb-es 5.33.5-beta.0 → 5.34.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configurations.js +1 -1
- package/definitions/entry.js +3 -7
- package/definitions/entry.js.map +1 -1
- package/definitions/entryElasticsearch.js +3 -7
- package/definitions/entryElasticsearch.js.map +1 -1
- package/definitions/group.js +3 -7
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +8 -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/storage/date.d.ts +2 -1
- package/dynamoDb/storage/date.js +1 -1
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +1 -1
- package/dynamoDb/storage/longText.js +8 -1
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -1
- package/dynamoDb/storage/richText.js +1 -1
- package/elasticsearch/createElasticsearchIndex.js +1 -1
- package/elasticsearch/index.js +1 -1
- package/elasticsearch/indexing/index.js +1 -1
- package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
- package/elasticsearch/indexing/longTextIndexing.js +20 -4
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
- package/elasticsearch/search/refSearch.js +4 -2
- package/elasticsearch/search/refSearch.js.map +1 -1
- package/helpers/entryIndexHelpers.js +6 -11
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/index.d.ts +0 -1
- package/helpers/index.js +0 -13
- package/helpers/index.js.map +1 -1
- package/index.js +17 -10
- package/index.js.map +1 -1
- package/operations/entry/dataLoaders.js +7 -9
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +34 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
- package/operations/entry/elasticsearch/body.d.ts +13 -0
- package/operations/entry/elasticsearch/body.js +162 -0
- package/operations/entry/elasticsearch/body.js.map +1 -0
- package/operations/entry/elasticsearch/fields.d.ts +9 -0
- package/operations/entry/elasticsearch/fields.js +248 -0
- package/operations/entry/elasticsearch/fields.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +66 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
- package/operations/entry/elasticsearch/filtering/exec.js +215 -0
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/index.js +18 -0
- package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
- package/operations/entry/elasticsearch/filtering/path.js +52 -0
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +35 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js +18 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +78 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +58 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/populated.js +30 -0
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/values.js +28 -0
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearch.d.ts +9 -0
- package/operations/entry/elasticsearch/fullTextSearch.js +34 -0
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js +52 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
- package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
- package/operations/entry/elasticsearch/initialQuery.js +117 -0
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
- package/operations/entry/elasticsearch/keyword.d.ts +2 -0
- package/operations/entry/elasticsearch/keyword.js +38 -0
- package/operations/entry/elasticsearch/keyword.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
- package/operations/entry/elasticsearch/plugins/operator.js +45 -0
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
- package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +9 -5
- package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
- package/operations/entry/elasticsearch/sort.d.ts +12 -0
- package/operations/entry/elasticsearch/sort.js +92 -0
- package/operations/entry/elasticsearch/sort.js.map +1 -0
- package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
- package/{helpers → operations/entry/elasticsearch}/transformValueForSearch.js +8 -3
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
- package/operations/entry/elasticsearch/types.d.ts +41 -0
- package/operations/entry/elasticsearch/types.js +5 -0
- package/operations/entry/elasticsearch/types.js.map +1 -0
- package/operations/entry/elasticsearchFields.js +3 -0
- package/operations/entry/elasticsearchFields.js.map +1 -1
- package/operations/entry/index.d.ts +0 -2
- package/operations/entry/index.js +100 -310
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/recordType.d.ts +3 -0
- package/operations/entry/recordType.js +24 -0
- package/operations/entry/recordType.js.map +1 -0
- package/operations/group/index.js +7 -12
- 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 +18 -19
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +1 -1
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +1 -1
- package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
- package/plugins/CmsEntryFilterPlugin.js +31 -0
- package/plugins/CmsEntryFilterPlugin.js.map +1 -0
- package/helpers/createElasticsearchQueryBody.d.ts +0 -11
- package/helpers/createElasticsearchQueryBody.js +0 -618
- package/helpers/createElasticsearchQueryBody.js.map +0 -1
- package/helpers/fields.d.ts +0 -19
- package/helpers/fields.js +0 -196
- package/helpers/fields.js.map +0 -1
- package/helpers/searchPluginsList.d.ts +0 -6
- package/helpers/searchPluginsList.js.map +0 -1
- package/helpers/transformValueForSearch.d.ts +0 -12
- package/helpers/transformValueForSearch.js.map +0 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createElasticsearchBody = void 0;
|
|
7
|
+
|
|
8
|
+
var _fields = require("./fields");
|
|
9
|
+
|
|
10
|
+
var _fullTextSearchFields = require("./fullTextSearchFields");
|
|
11
|
+
|
|
12
|
+
var _initialQuery = require("./initialQuery");
|
|
13
|
+
|
|
14
|
+
var _fullTextSearch = require("./fullTextSearch");
|
|
15
|
+
|
|
16
|
+
var _queryModifier = require("./plugins/queryModifier");
|
|
17
|
+
|
|
18
|
+
var _sortModifier = require("./plugins/sortModifier");
|
|
19
|
+
|
|
20
|
+
var _bodyModifier = require("./plugins/bodyModifier");
|
|
21
|
+
|
|
22
|
+
var _sort = require("./sort");
|
|
23
|
+
|
|
24
|
+
var _filtering = require("./filtering");
|
|
25
|
+
|
|
26
|
+
var _assignMinimumShouldMatchToQuery = require("./assignMinimumShouldMatchToQuery");
|
|
27
|
+
|
|
28
|
+
const createElasticsearchBody = ({
|
|
29
|
+
plugins,
|
|
30
|
+
model,
|
|
31
|
+
params
|
|
32
|
+
}) => {
|
|
33
|
+
const {
|
|
34
|
+
fields,
|
|
35
|
+
search: term,
|
|
36
|
+
where,
|
|
37
|
+
sort: initialSort,
|
|
38
|
+
after,
|
|
39
|
+
limit
|
|
40
|
+
} = params;
|
|
41
|
+
/**
|
|
42
|
+
* We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
const modelFields = (0, _fields.createModelFields)({
|
|
46
|
+
plugins,
|
|
47
|
+
fields: model.fields
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* We need the query modifier plugins.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
const queryModifierPlugins = (0, _queryModifier.createQueryModifierPluginList)({
|
|
54
|
+
plugins,
|
|
55
|
+
model
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* We need the sort modifier plugins.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
const sortModifierPlugins = (0, _sortModifier.createSortModifierPluginList)({
|
|
62
|
+
plugins,
|
|
63
|
+
model
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* We need the body modifier plugins.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
const bodyModifierPlugins = (0, _bodyModifier.createBodyModifierPluginList)({
|
|
70
|
+
plugins,
|
|
71
|
+
model
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* We need the fields which we can search through via the full text search.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
const fullTextSearchFields = (0, _fullTextSearchFields.createFullTextSearchFields)({
|
|
79
|
+
model,
|
|
80
|
+
term,
|
|
81
|
+
fields
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* The initial elasticsearch query where we attach some default conditions we always need.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
const query = (0, _initialQuery.createInitialQuery)({
|
|
88
|
+
where,
|
|
89
|
+
model
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Apply the full text search, if term is set.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
(0, _fullTextSearch.applyFullTextSearch)({
|
|
96
|
+
query,
|
|
97
|
+
term,
|
|
98
|
+
fields: fullTextSearchFields
|
|
99
|
+
});
|
|
100
|
+
const execFiltering = (0, _filtering.createExecFiltering)({
|
|
101
|
+
model,
|
|
102
|
+
fields: modelFields,
|
|
103
|
+
plugins
|
|
104
|
+
});
|
|
105
|
+
execFiltering({
|
|
106
|
+
where,
|
|
107
|
+
query
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
for (const pl of queryModifierPlugins) {
|
|
111
|
+
pl.modifyQuery({
|
|
112
|
+
query,
|
|
113
|
+
model,
|
|
114
|
+
where
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const sort = (0, _sort.createElasticsearchSort)({
|
|
119
|
+
plugins,
|
|
120
|
+
sort: initialSort,
|
|
121
|
+
modelFields,
|
|
122
|
+
model
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
for (const pl of sortModifierPlugins) {
|
|
126
|
+
pl.modifySort({
|
|
127
|
+
sort,
|
|
128
|
+
model
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const boolQuery = {
|
|
133
|
+
must: query.must.length > 0 ? query.must : undefined,
|
|
134
|
+
must_not: query.must_not.length > 0 ? query.must_not : undefined,
|
|
135
|
+
should: query.should.length > 0 ? query.should : undefined,
|
|
136
|
+
filter: query.filter.length > 0 ? query.filter : undefined
|
|
137
|
+
};
|
|
138
|
+
(0, _assignMinimumShouldMatchToQuery.assignMinimumShouldMatchToQuery)({
|
|
139
|
+
query: boolQuery
|
|
140
|
+
});
|
|
141
|
+
const body = {
|
|
142
|
+
query: {
|
|
143
|
+
bool: boolQuery
|
|
144
|
+
},
|
|
145
|
+
sort,
|
|
146
|
+
size: (limit || 0) + 1,
|
|
147
|
+
search_after: after,
|
|
148
|
+
track_total_hits: true
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
for (const pl of bodyModifierPlugins) {
|
|
152
|
+
pl.modifyBody({
|
|
153
|
+
body,
|
|
154
|
+
model,
|
|
155
|
+
where
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return body;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
exports.createElasticsearchBody = createElasticsearchBody;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createElasticsearchBody","plugins","model","params","fields","search","term","where","sort","initialSort","after","limit","modelFields","createModelFields","queryModifierPlugins","createQueryModifierPluginList","sortModifierPlugins","createSortModifierPluginList","bodyModifierPlugins","createBodyModifierPluginList","fullTextSearchFields","createFullTextSearchFields","query","createInitialQuery","applyFullTextSearch","execFiltering","createExecFiltering","pl","modifyQuery","createElasticsearchSort","modifySort","boolQuery","must","length","undefined","must_not","should","filter","assignMinimumShouldMatchToQuery","body","bool","size","search_after","track_total_hits","modifyBody"],"sources":["body.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListParams, CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createModelFields } from \"./fields\";\nimport { createFullTextSearchFields } from \"./fullTextSearchFields\";\nimport { createInitialQuery } from \"./initialQuery\";\nimport { applyFullTextSearch } from \"./fullTextSearch\";\nimport { createQueryModifierPluginList } from \"./plugins/queryModifier\";\nimport { createSortModifierPluginList } from \"./plugins/sortModifier\";\nimport { createBodyModifierPluginList } from \"./plugins/bodyModifier\";\nimport { createElasticsearchSort } from \"./sort\";\nimport { PrimitiveValue, SearchBody, BoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createExecFiltering } from \"./filtering\";\nimport { assignMinimumShouldMatchToQuery } from \"./assignMinimumShouldMatchToQuery\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n params: Omit<CmsEntryListParams, \"where\" | \"after\"> & {\n where: CmsEntryListWhere;\n after?: PrimitiveValue[];\n };\n}\nexport const createElasticsearchBody = ({ plugins, model, params }: Params): SearchBody => {\n const { fields, search: term, where, sort: initialSort, after, limit } = params;\n /**\n * We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.\n */\n const modelFields = createModelFields({\n plugins,\n fields: model.fields\n });\n\n /**\n * We need the query modifier plugins.\n */\n const queryModifierPlugins = createQueryModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the sort modifier plugins.\n */\n const sortModifierPlugins = createSortModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the body modifier plugins.\n */\n const bodyModifierPlugins = createBodyModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the fields which we can search through via the full text search.\n *\n */\n const fullTextSearchFields = createFullTextSearchFields({\n model,\n term,\n fields\n });\n /**\n * The initial elasticsearch query where we attach some default conditions we always need.\n */\n const query = createInitialQuery({\n where,\n model\n });\n /**\n * Apply the full text search, if term is set.\n */\n applyFullTextSearch({\n query,\n term,\n fields: fullTextSearchFields\n });\n\n const execFiltering = createExecFiltering({\n model,\n fields: modelFields,\n plugins\n });\n\n execFiltering({\n where,\n query\n });\n\n for (const pl of queryModifierPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSort({\n plugins,\n sort: initialSort,\n modelFields,\n model\n });\n\n for (const pl of sortModifierPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const boolQuery: BoolQueryConfig = {\n must: query.must.length > 0 ? query.must : undefined,\n must_not: query.must_not.length > 0 ? query.must_not : undefined,\n should: query.should.length > 0 ? query.should : undefined,\n filter: query.filter.length > 0 ? query.filter : undefined\n };\n\n assignMinimumShouldMatchToQuery({\n query: boolQuery\n });\n\n const body: SearchBody = {\n query: {\n bool: boolQuery\n },\n sort,\n size: (limit || 0) + 1,\n search_after: after,\n track_total_hits: true\n };\n\n for (const pl of bodyModifierPlugins) {\n pl.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAUO,MAAMA,uBAAuB,GAAG,CAAC;EAAEC,OAAF;EAAWC,KAAX;EAAkBC;AAAlB,C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}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
2
|
+
import { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
3
|
+
import { ModelFields } from "./types";
|
|
4
|
+
interface Params {
|
|
5
|
+
plugins: PluginsContainer;
|
|
6
|
+
fields?: CmsModelField[];
|
|
7
|
+
}
|
|
8
|
+
export declare const createModelFields: ({ plugins, fields }: Params) => ModelFields;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,248 @@
|
|
|
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.createModelFields = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
const createSystemField = field => {
|
|
15
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
16
|
+
id: field.fieldId,
|
|
17
|
+
label: field.fieldId
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const createSystemFields = () => {
|
|
22
|
+
return {
|
|
23
|
+
id: {
|
|
24
|
+
type: "text",
|
|
25
|
+
isSystemField: true,
|
|
26
|
+
isSearchable: true,
|
|
27
|
+
isSortable: true,
|
|
28
|
+
field: createSystemField({
|
|
29
|
+
storageId: "id",
|
|
30
|
+
fieldId: "id",
|
|
31
|
+
type: "text"
|
|
32
|
+
}),
|
|
33
|
+
parents: []
|
|
34
|
+
},
|
|
35
|
+
entryId: {
|
|
36
|
+
type: "text",
|
|
37
|
+
isSystemField: true,
|
|
38
|
+
isSearchable: true,
|
|
39
|
+
isSortable: true,
|
|
40
|
+
field: createSystemField({
|
|
41
|
+
storageId: "entryId",
|
|
42
|
+
fieldId: "entryId",
|
|
43
|
+
type: "text"
|
|
44
|
+
}),
|
|
45
|
+
parents: []
|
|
46
|
+
},
|
|
47
|
+
savedOn: {
|
|
48
|
+
type: "date",
|
|
49
|
+
unmappedType: "date",
|
|
50
|
+
keyword: false,
|
|
51
|
+
isSystemField: true,
|
|
52
|
+
isSearchable: true,
|
|
53
|
+
isSortable: true,
|
|
54
|
+
field: createSystemField({
|
|
55
|
+
storageId: "savedOn",
|
|
56
|
+
fieldId: "savedOn",
|
|
57
|
+
type: "datetime",
|
|
58
|
+
settings: {
|
|
59
|
+
type: "dateTimeWithoutTimezone"
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
parents: []
|
|
63
|
+
},
|
|
64
|
+
createdOn: {
|
|
65
|
+
type: "date",
|
|
66
|
+
unmappedType: "date",
|
|
67
|
+
keyword: false,
|
|
68
|
+
isSystemField: true,
|
|
69
|
+
isSearchable: true,
|
|
70
|
+
isSortable: true,
|
|
71
|
+
field: createSystemField({
|
|
72
|
+
storageId: "createdOn",
|
|
73
|
+
fieldId: "createdOn",
|
|
74
|
+
type: "text",
|
|
75
|
+
settings: {
|
|
76
|
+
type: "dateTimeWithoutTimezone"
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
parents: []
|
|
80
|
+
},
|
|
81
|
+
createdBy: {
|
|
82
|
+
type: "text",
|
|
83
|
+
unmappedType: undefined,
|
|
84
|
+
isSystemField: true,
|
|
85
|
+
isSearchable: true,
|
|
86
|
+
isSortable: false,
|
|
87
|
+
path: "createdBy.id",
|
|
88
|
+
field: createSystemField({
|
|
89
|
+
storageId: "createdBy",
|
|
90
|
+
fieldId: "createdBy",
|
|
91
|
+
type: "text"
|
|
92
|
+
}),
|
|
93
|
+
parents: []
|
|
94
|
+
},
|
|
95
|
+
ownedBy: {
|
|
96
|
+
type: "text",
|
|
97
|
+
unmappedType: undefined,
|
|
98
|
+
isSystemField: true,
|
|
99
|
+
isSearchable: true,
|
|
100
|
+
isSortable: false,
|
|
101
|
+
path: "ownedBy.id",
|
|
102
|
+
field: createSystemField({
|
|
103
|
+
storageId: "ownedBy",
|
|
104
|
+
fieldId: "ownedBy",
|
|
105
|
+
type: "text"
|
|
106
|
+
}),
|
|
107
|
+
parents: []
|
|
108
|
+
},
|
|
109
|
+
version: {
|
|
110
|
+
type: "number",
|
|
111
|
+
unmappedType: undefined,
|
|
112
|
+
keyword: false,
|
|
113
|
+
isSystemField: true,
|
|
114
|
+
isSearchable: true,
|
|
115
|
+
isSortable: true,
|
|
116
|
+
field: createSystemField({
|
|
117
|
+
storageId: "version",
|
|
118
|
+
fieldId: "version",
|
|
119
|
+
type: "number"
|
|
120
|
+
}),
|
|
121
|
+
parents: []
|
|
122
|
+
},
|
|
123
|
+
status: {
|
|
124
|
+
type: "string",
|
|
125
|
+
unmappedType: undefined,
|
|
126
|
+
keyword: false,
|
|
127
|
+
isSystemField: true,
|
|
128
|
+
isSearchable: true,
|
|
129
|
+
isSortable: false,
|
|
130
|
+
field: createSystemField({
|
|
131
|
+
storageId: "status",
|
|
132
|
+
fieldId: "status",
|
|
133
|
+
type: "string"
|
|
134
|
+
}),
|
|
135
|
+
parents: []
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const buildFieldsList = params => {
|
|
141
|
+
const {
|
|
142
|
+
plugins,
|
|
143
|
+
fields,
|
|
144
|
+
parents
|
|
145
|
+
} = params;
|
|
146
|
+
return fields.reduce((result, field) => {
|
|
147
|
+
var _field$settings;
|
|
148
|
+
|
|
149
|
+
const plugin = plugins[field.type];
|
|
150
|
+
|
|
151
|
+
if (!plugin) {
|
|
152
|
+
throw new _error.default(`There is no plugin for field type "${field.type}".`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const {
|
|
156
|
+
isSearchable,
|
|
157
|
+
isSortable,
|
|
158
|
+
unmappedType,
|
|
159
|
+
fullTextSearch
|
|
160
|
+
} = plugin;
|
|
161
|
+
/**
|
|
162
|
+
* If a field has child fields, go through them and add them to a result.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
|
|
166
|
+
|
|
167
|
+
if (childFields.length > 0) {
|
|
168
|
+
/**
|
|
169
|
+
* Let's build all the child fields
|
|
170
|
+
*/
|
|
171
|
+
const childResult = buildFieldsList({
|
|
172
|
+
fields: childFields,
|
|
173
|
+
plugins,
|
|
174
|
+
parents: [...parents, {
|
|
175
|
+
fieldId: field.fieldId,
|
|
176
|
+
storageId: field.storageId,
|
|
177
|
+
type: field.type
|
|
178
|
+
}]
|
|
179
|
+
});
|
|
180
|
+
/**
|
|
181
|
+
*
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
Object.assign(result, childResult);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(".");
|
|
188
|
+
result[identifier] = {
|
|
189
|
+
type: field.type,
|
|
190
|
+
parents,
|
|
191
|
+
isSearchable,
|
|
192
|
+
isSortable,
|
|
193
|
+
fullTextSearch,
|
|
194
|
+
unmappedType: typeof unmappedType === "function" ? unmappedType(field) : undefined,
|
|
195
|
+
isSystemField: false,
|
|
196
|
+
field
|
|
197
|
+
};
|
|
198
|
+
return result;
|
|
199
|
+
}, {});
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const createModelFields = ({
|
|
203
|
+
plugins,
|
|
204
|
+
fields
|
|
205
|
+
}) => {
|
|
206
|
+
if (!fields || fields.length === 0) {
|
|
207
|
+
return createSystemFields();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Collect all unmappedType from elastic plugins.
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
const unmappedTypes = plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
|
|
215
|
+
if (!plugin.unmappedType) {
|
|
216
|
+
return acc;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
acc[plugin.fieldType] = plugin.unmappedType;
|
|
220
|
+
return acc;
|
|
221
|
+
}, {});
|
|
222
|
+
/**
|
|
223
|
+
* Collect all field types from the plugins.
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
|
|
227
|
+
const {
|
|
228
|
+
fieldType,
|
|
229
|
+
isSearchable,
|
|
230
|
+
isSortable,
|
|
231
|
+
fullTextSearch
|
|
232
|
+
} = plugin;
|
|
233
|
+
types[fieldType] = {
|
|
234
|
+
unmappedType: unmappedTypes[fieldType],
|
|
235
|
+
isSearchable,
|
|
236
|
+
isSortable,
|
|
237
|
+
fullTextSearch
|
|
238
|
+
};
|
|
239
|
+
return types;
|
|
240
|
+
}, {});
|
|
241
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, createSystemFields()), buildFieldsList({
|
|
242
|
+
fields,
|
|
243
|
+
plugins: fieldTypePlugins,
|
|
244
|
+
parents: []
|
|
245
|
+
}));
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
exports.createModelFields = createModelFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","isSystemField","isSearchable","isSortable","storageId","parents","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","buildFieldsList","params","plugins","fields","reduce","result","plugin","WebinyError","fullTextSearch","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","unmappedTypes","byType","acc","fieldType","fieldTypePlugins","types"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFieldParent, ModelFields } from \"./types\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n }),\n parents: []\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n }),\n parents: []\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: CmsModelField) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: CmsModelField) => string | undefined;\n isSearchable: boolean;\n isSortable: boolean;\n fullTextSearch?: boolean;\n}\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const plugin = plugins[field.type];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { isSearchable, isSortable, unmappedType, fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: field.type\n }\n ]\n });\n /**\n *\n */\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: field.type,\n parents,\n isSearchable,\n isSortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n isSystemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n fields?: CmsModelField[];\n}\nexport const createModelFields = ({ plugins, fields }: Params) => {\n if (!fields || fields.length === 0) {\n return createSystemFields();\n }\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, isSearchable, isSortable, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n isSearchable,\n isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: []\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAQA,MAAMA,iBAAiB,GAAIC,KAAD,IAAgD;EACtE,mEACOA,KADP;IAEIC,EAAE,EAAED,KAAK,CAACE,OAFd;IAGIC,KAAK,EAAEH,KAAK,CAACE;EAHjB;AAKH,CAND;;AAQA,MAAME,kBAAkB,GAAG,MAAmB;EAC1C,OAAO;IACHH,EAAE,EAAE;MACAI,IAAI,EAAE,MADN;MAEAC,aAAa,EAAE,IAFf;MAGAC,YAAY,EAAE,IAHd;MAIAC,UAAU,EAAE,IAJZ;MAKAR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,IADU;QAErBP,OAAO,EAAE,IAFY;QAGrBG,IAAI,EAAE;MAHe,CAAD,CALxB;MAUAK,OAAO,EAAE;IAVT,CADD;IAaHC,OAAO,EAAE;MACLN,IAAI,EAAE,MADD;MAELC,aAAa,EAAE,IAFV;MAGLC,YAAY,EAAE,IAHT;MAILC,UAAU,EAAE,IAJP;MAKLR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAA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iBAAiB,GAAG,CAAC;EAAEhB,OAAF;EAAWC;AAAX,CAAD,KAAiC;EAC9D,IAAI,CAACA,MAAD,IAAWA,MAAM,CAACO,MAAP,KAAkB,CAAjC,EAAoC;IAChC,OAAO7B,kBAAkB,EAAzB;EACH;EACD;AACJ;AACA;;;EACI,MAAMsC,aAAa,GAAGjB,OAAO,CACxBkB,MADiB,CAC0B,mCAD1B,EAEjBhB,MAFiB,CAEU,CAACiB,GAAD,EAAMf,MAAN,KAAiB;IACzC,IAAI,CAACA,MAAM,CAAChB,YAAZ,EAA0B;MACtB,OAAO+B,GAAP;IACH;;IACDA,GAAG,CAACf,MAAM,CAACgB,SAAR,CAAH,GAAwBhB,MAAM,CAAChB,YAA/B;IACA,OAAO+B,GAAP;EACH,CARiB,EAQf,EARe,CAAtB;EASA;AACJ;AACA;;EACI,MAAME,gBAAgB,GAAGrB,OAAO,CAC3BkB,MADoB,CACiB,4BADjB,EAEpBhB,MAFoB,CAEK,CAACoB,KAAD,EAAQlB,MAAR,KAAmB;IACzC,MAAM;MAAEgB,SAAF;MAAatC,YAAb;MAA2BC,UAA3B;MAAuCuB;IAAvC,IAA0DF,MAAhE;IACAkB,KAAK,CAACF,SAAD,CAAL,GAAmB;MACfhC,YAAY,EAAE6B,aAAa,CAACG,SAAD,CADZ;MAEftC,YAFe;MAGfC,UAHe;MAIfuB;IAJe,CAAnB;IAMA,OAAOgB,KAAP;EACH,CAXoB,EAWlB,EAXkB,CAAzB;EAaA,mEACO3C,kBAAkB,EADzB,GAEOmB,eAAe,CAAC;IACfG,MADe;IAEfD,OAAO,EAAEqB,gBAFM;IAGfpC,OAAO,EAAE;EAHM,CAAD,CAFtB;AAQH,CAxCM"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugins, ElasticsearchQuerySearchValuePlugins } from "../types";
|
|
2
|
+
import { ApplyFilteringCb } from "../../../../plugins/CmsEntryFilterPlugin";
|
|
3
|
+
interface CreateParams {
|
|
4
|
+
operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;
|
|
5
|
+
searchPlugins: ElasticsearchQuerySearchValuePlugins;
|
|
6
|
+
}
|
|
7
|
+
export declare const createApplyFiltering: ({ operatorPlugins, searchPlugins }: CreateParams) => ApplyFilteringCb;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
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.createApplyFiltering = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _transformValueForSearch = require("../transformValueForSearch");
|
|
13
|
+
|
|
14
|
+
var _keyword = require("../keyword");
|
|
15
|
+
|
|
16
|
+
var _path = require("./path");
|
|
17
|
+
|
|
18
|
+
const createApplyFiltering = ({
|
|
19
|
+
operatorPlugins,
|
|
20
|
+
searchPlugins
|
|
21
|
+
}) => {
|
|
22
|
+
const createFieldPath = (0, _path.createFieldPathFactory)({
|
|
23
|
+
plugins: searchPlugins
|
|
24
|
+
});
|
|
25
|
+
return params => {
|
|
26
|
+
const {
|
|
27
|
+
key,
|
|
28
|
+
value: initialValue,
|
|
29
|
+
query,
|
|
30
|
+
operator,
|
|
31
|
+
field
|
|
32
|
+
} = params;
|
|
33
|
+
const plugin = operatorPlugins[operator];
|
|
34
|
+
|
|
35
|
+
if (!plugin) {
|
|
36
|
+
throw new _error.default("Operator plugin missing.", "PLUGIN_MISSING", {
|
|
37
|
+
operator
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const value = (0, _transformValueForSearch.transformValueForSearch)({
|
|
42
|
+
plugins: searchPlugins,
|
|
43
|
+
field: field.field,
|
|
44
|
+
value: initialValue
|
|
45
|
+
});
|
|
46
|
+
const keyword = (0, _keyword.hasKeyword)(field);
|
|
47
|
+
const {
|
|
48
|
+
basePath,
|
|
49
|
+
path
|
|
50
|
+
} = createFieldPath({
|
|
51
|
+
field,
|
|
52
|
+
value,
|
|
53
|
+
key,
|
|
54
|
+
keyword
|
|
55
|
+
});
|
|
56
|
+
plugin.apply(query, {
|
|
57
|
+
name: field.field.fieldId,
|
|
58
|
+
basePath,
|
|
59
|
+
path,
|
|
60
|
+
value,
|
|
61
|
+
keyword
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.createApplyFiltering = createApplyFiltering;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createApplyFiltering","operatorPlugins","searchPlugins","createFieldPath","createFieldPathFactory","plugins","params","key","value","initialValue","query","operator","field","plugin","WebinyError","transformValueForSearch","keyword","hasKeyword","basePath","path","apply","name","fieldId"],"sources":["applyFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport {\n ElasticsearchQueryBuilderOperatorPlugins,\n ElasticsearchQuerySearchValuePlugins\n} from \"~/operations/entry/elasticsearch/types\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\nimport { ApplyFilteringCb } from \"~/plugins/CmsEntryFilterPlugin\";\n\ninterface CreateParams {\n operatorPlugins: ElasticsearchQueryBuilderOperatorPlugins;\n searchPlugins: ElasticsearchQuerySearchValuePlugins;\n}\n\nexport const createApplyFiltering = ({\n operatorPlugins,\n searchPlugins\n}: CreateParams): ApplyFilteringCb => {\n const createFieldPath = createFieldPathFactory({\n plugins: searchPlugins\n });\n\n return params => {\n const { key, value: initialValue, query, operator, field } = params;\n\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: field.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(field);\n\n const { basePath, path } = createFieldPath({\n field,\n value,\n key,\n keyword\n });\n\n plugin.apply(query, {\n name: field.field.fieldId,\n basePath,\n path,\n value,\n keyword\n });\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAKA;;AAQO,MAAMA,oBAAoB,GAAG,CAAC;EACjCC,eADiC;EAEjCC;AAFiC,CAAD,KAGE;EAClC,MAAMC,eAAe,GAAG,IAAAC,4BAAA,EAAuB;IAC3CC,OAAO,EAAEH;EADkC,CAAvB,CAAxB;EAIA,OAAOI,MAAM,IAAI;IACb,MAAM;MAAEC,GAAF;MAAOC,KAAK,EAAEC,YAAd;MAA4BC,KAA5B;MAAmCC,QAAnC;MAA6CC;IAA7C,IAAuDN,MAA7D;IAEA,MAAMO,MAAM,GAAGZ,eAAe,CAACU,QAAD,CAA9B;;IACA,IAAI,CAACE,MAAL,EAAa;MACT,MAAM,IAAIC,cAAJ,CAAgB,0BAAhB,EAA4C,gBAA5C,EAA8D;QAChEH;MADgE,CAA9D,CAAN;IAGH;;IAED,MAAMH,KAAK,GAAG,IAAAO,gDAAA,EAAwB;MAClCV,OAAO,EAAEH,aADyB;MAElCU,KAAK,EAAEA,KAAK,CAACA,KAFqB;MAGlCJ,KAAK,EAAEC;IAH2B,CAAxB,CAAd;IAMA,MAAMO,OAAO,GAAG,IAAAC,mBAAA,EAAWL,KAAX,CAAhB;IAEA,MAAM;MAAEM,QAAF;MAAYC;IAAZ,IAAqBhB,eAAe,CAAC;MACvCS,KADuC;MAEvCJ,KAFuC;MAGvCD,GAHuC;MAIvCS;IAJuC,CAAD,CAA1C;IAOAH,MAAM,CAACO,KAAP,CAAaV,KAAb,EAAoB;MAChBW,IAAI,EAAET,KAAK,CAACA,KAAN,CAAYU,OADF;MAEhBJ,QAFgB;MAGhBC,IAHgB;MAIhBX,KAJgB;MAKhBQ;IALgB,CAApB;EAOH,CAhCD;AAiCH,CAzCM"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { ModelFields } from "../types";
|
|
3
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
import { ElasticsearchBoolQueryConfig } from "@webiny/api-elasticsearch/types";
|
|
5
|
+
export interface CreateExecParams {
|
|
6
|
+
model: CmsModel;
|
|
7
|
+
fields: ModelFields;
|
|
8
|
+
plugins: PluginsContainer;
|
|
9
|
+
}
|
|
10
|
+
export interface ExecParams {
|
|
11
|
+
where: CmsEntryListWhere;
|
|
12
|
+
query: ElasticsearchBoolQueryConfig;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateExecFilteringResponse {
|
|
15
|
+
(params: ExecParams): void;
|
|
16
|
+
}
|
|
17
|
+
export declare const createExecFiltering: (params: CreateExecParams) => CreateExecFilteringResponse;
|