@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.06b2ede40f
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.d.ts +15 -8
- package/configurations.js +29 -12
- package/configurations.js.map +1 -0
- package/definitions/entry.d.ts +6 -5
- package/definitions/entry.js +111 -20
- package/definitions/entry.js.map +1 -0
- package/definitions/entryElasticsearch.d.ts +6 -5
- package/definitions/entryElasticsearch.js +11 -16
- package/definitions/entryElasticsearch.js.map +1 -0
- package/definitions/group.d.ts +6 -5
- package/definitions/group.js +8 -16
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +6 -5
- package/definitions/model.js +30 -16
- package/definitions/model.js.map +1 -0
- package/definitions/system.d.ts +6 -5
- package/definitions/system.js +8 -16
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +6 -6
- package/definitions/table.js +7 -6
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +6 -6
- package/definitions/tableElasticsearch.js +7 -6
- package/definitions/tableElasticsearch.js.map +1 -0
- package/dynamoDb/index.d.ts +2 -1
- package/dynamoDb/index.js +10 -12
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +7 -4
- package/dynamoDb/storage/longText.js +75 -62
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -8
- package/dynamoDb/storage/richText.js +49 -100
- package/dynamoDb/storage/richText.js.map +1 -0
- package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
- package/elasticsearch/createElasticsearchIndex.js +40 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
- package/elasticsearch/deleteElasticsearchIndex.js +38 -0
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
- package/elasticsearch/index.d.ts +1 -1
- package/elasticsearch/index.js +3 -6
- package/elasticsearch/index.js.map +1 -0
- package/elasticsearch/indexing/dateTimeIndexing.d.ts +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.js +21 -22
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
- package/elasticsearch/indexing/defaultFieldIndexing.d.ts +1 -1
- package/elasticsearch/indexing/defaultFieldIndexing.js +17 -10
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
- package/elasticsearch/indexing/index.js +5 -11
- package/elasticsearch/indexing/index.js.map +1 -0
- package/elasticsearch/indexing/jsonIndexing.d.ts +2 -0
- package/elasticsearch/indexing/jsonIndexing.js +28 -0
- package/elasticsearch/indexing/jsonIndexing.js.map +1 -0
- package/elasticsearch/indexing/longTextIndexing.d.ts +5 -1
- package/elasticsearch/indexing/longTextIndexing.js +16 -10
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
- package/elasticsearch/indexing/numberIndexing.d.ts +1 -1
- package/elasticsearch/indexing/numberIndexing.js +2 -9
- package/elasticsearch/indexing/numberIndexing.js.map +1 -0
- package/elasticsearch/indexing/objectIndexing.d.ts +10 -1
- package/elasticsearch/indexing/objectIndexing.js +37 -36
- package/elasticsearch/indexing/objectIndexing.js.map +1 -0
- package/elasticsearch/indexing/richTextIndexing.d.ts +1 -1
- package/elasticsearch/indexing/richTextIndexing.js +2 -5
- package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +13 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +14 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +14 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/elasticsearch/search/index.d.ts +2 -2
- package/elasticsearch/search/index.js +6 -9
- package/elasticsearch/search/index.js.map +1 -0
- package/elasticsearch/search/refSearch.d.ts +2 -3
- package/elasticsearch/search/refSearch.js +24 -17
- package/elasticsearch/search/refSearch.js.map +1 -0
- package/elasticsearch/search/searchableJson.d.ts +2 -0
- package/elasticsearch/search/searchableJson.js +60 -0
- package/elasticsearch/search/searchableJson.js.map +1 -0
- package/elasticsearch/search/timeSearch.d.ts +2 -3
- package/elasticsearch/search/timeSearch.js +18 -16
- package/elasticsearch/search/timeSearch.js.map +1 -0
- package/helpers/entryIndexHelpers.d.ts +3 -3
- package/helpers/entryIndexHelpers.js +59 -58
- package/helpers/entryIndexHelpers.js.map +1 -0
- package/helpers/fieldIdentifier.d.ts +6 -0
- package/helpers/fieldIdentifier.js +43 -0
- package/helpers/fieldIdentifier.js.map +1 -0
- package/helpers/index.d.ts +1 -1
- package/helpers/index.js +11 -13
- package/helpers/index.js.map +1 -0
- package/index.d.ts +2 -1
- package/index.js +132 -78
- package/index.js.map +1 -0
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +17 -0
- package/operations/entry/dataLoader/DataLoaderCache.js +41 -0
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -0
- package/operations/entry/dataLoader/constants.d.ts +1 -0
- package/operations/entry/dataLoader/constants.js +10 -0
- package/operations/entry/dataLoader/constants.js.map +1 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.d.ts +8 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js +25 -0
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +4 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js +45 -0
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +52 -0
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +4 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +52 -0
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -0
- package/operations/entry/dataLoader/getRevisionById.d.ts +4 -0
- package/operations/entry/dataLoader/getRevisionById.js +62 -0
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -0
- package/operations/entry/dataLoader/index.d.ts +8 -0
- package/operations/entry/dataLoader/index.js +40 -0
- package/operations/entry/dataLoader/index.js.map +1 -0
- package/operations/entry/dataLoader/types.d.ts +6 -0
- package/operations/entry/dataLoader/types.js +7 -0
- package/operations/entry/dataLoader/types.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +21 -38
- package/operations/entry/dataLoaders.js +59 -290
- package/operations/entry/dataLoaders.js.map +1 -0
- 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 +142 -0
- package/operations/entry/elasticsearch/body.js.map +1 -0
- package/operations/entry/elasticsearch/fields.d.ts +10 -0
- package/operations/entry/elasticsearch/fields.js +315 -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 +60 -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 +175 -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 +16 -0
- package/operations/entry/elasticsearch/filtering/path.js +48 -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 +30 -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 +15 -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 +69 -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 +57 -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 +25 -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 +24 -0
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearch.d.ts +12 -0
- package/operations/entry/elasticsearch/fullTextSearch.js +91 -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 +27 -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 +106 -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 +36 -0
- package/operations/entry/elasticsearch/keyword.js.map +1 -0
- package/operations/entry/elasticsearch/logIgnoredEsResponseError.d.ts +9 -0
- package/operations/entry/elasticsearch/logIgnoredEsResponseError.js +26 -0
- package/operations/entry/elasticsearch/logIgnoredEsResponseError.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +18 -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 +39 -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 +18 -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 -9
- 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 +18 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.d.ts +2 -0
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +13 -0
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -0
- package/operations/entry/elasticsearch/sort.d.ts +12 -0
- package/operations/entry/elasticsearch/sort.js +89 -0
- package/operations/entry/elasticsearch/sort.js.map +1 -0
- package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
- package/operations/entry/elasticsearch/transformValueForSearch.js +32 -0
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
- package/operations/entry/elasticsearch/types.d.ts +41 -0
- package/operations/entry/elasticsearch/types.js +7 -0
- package/operations/entry/elasticsearch/types.js.map +1 -0
- package/operations/entry/index.d.ts +6 -8
- package/operations/entry/index.js +1422 -693
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.js +2 -9
- package/operations/entry/keys.js.map +1 -0
- package/operations/entry/recordType.d.ts +3 -0
- package/operations/entry/recordType.js +20 -0
- package/operations/entry/recordType.js.map +1 -0
- package/operations/entry/transformations/convertEntryKeys.d.ts +8 -0
- package/operations/entry/transformations/convertEntryKeys.js +38 -0
- package/operations/entry/transformations/convertEntryKeys.js.map +1 -0
- package/operations/entry/transformations/index.d.ts +29 -0
- package/operations/entry/transformations/index.js +127 -0
- package/operations/entry/transformations/index.js.map +1 -0
- package/operations/entry/transformations/modifyEntryValues.d.ts +58 -0
- package/operations/entry/transformations/modifyEntryValues.js +28 -0
- package/operations/entry/transformations/modifyEntryValues.js.map +1 -0
- package/operations/entry/transformations/transformEntryKeys.d.ts +11 -0
- package/operations/entry/transformations/transformEntryKeys.js +27 -0
- package/operations/entry/transformations/transformEntryKeys.js.map +1 -0
- package/operations/entry/transformations/transformEntryToIndex.d.ts +10 -0
- package/operations/entry/transformations/transformEntryToIndex.js +31 -0
- package/operations/entry/transformations/transformEntryToIndex.js.map +1 -0
- package/operations/group/index.d.ts +5 -5
- package/operations/group/index.js +40 -63
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +5 -5
- package/operations/model/index.js +56 -78
- package/operations/model/index.js.map +1 -0
- package/operations/system/index.d.ts +4 -4
- package/operations/system/index.js +20 -31
- package/operations/system/index.js.map +1 -0
- package/operations/system/indexes.d.ts +10 -0
- package/operations/system/indexes.js +41 -0
- package/operations/system/indexes.js.map +1 -0
- package/package.json +38 -40
- package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +69 -0
- package/plugins/CmsElasticsearchModelFieldPlugin.js +52 -0
- package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +9 -4
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +10 -13
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +23 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +27 -0
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +13 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +32 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +40 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +6 -4
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +10 -13
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +6 -4
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +10 -13
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchValuesModifier.d.ts +33 -0
- package/plugins/CmsEntryElasticsearchValuesModifier.js +50 -0
- package/plugins/CmsEntryElasticsearchValuesModifier.js.map +1 -0
- package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
- package/plugins/CmsEntryFilterPlugin.js +22 -0
- package/plugins/CmsEntryFilterPlugin.js.map +1 -0
- package/plugins/index.d.ts +8 -0
- package/plugins/index.js +95 -0
- package/plugins/index.js.map +1 -0
- package/tasks/createIndexTaskPlugin.d.ts +2 -0
- package/tasks/createIndexTaskPlugin.js +67 -0
- package/tasks/createIndexTaskPlugin.js.map +1 -0
- package/types.d.ts +30 -52
- package/types.js +5 -23
- package/types.js.map +1 -0
- package/values/NoValueContainer.d.ts +5 -0
- package/values/NoValueContainer.js +20 -0
- package/values/NoValueContainer.js.map +1 -0
- package/definitions/settings.d.ts +0 -8
- package/definitions/settings.js +0 -62
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -65
- package/helpers/createElasticsearchQueryBody.d.ts +0 -11
- package/helpers/createElasticsearchQueryBody.js +0 -375
- package/helpers/fields.d.ts +0 -77
- package/helpers/fields.js +0 -174
- package/helpers/operatorPluginsList.d.ts +0 -7
- package/helpers/operatorPluginsList.js +0 -30
- package/helpers/searchPluginsList.d.ts +0 -6
- package/helpers/transformValueForSearch.d.ts +0 -9
- package/helpers/transformValueForSearch.js +0 -26
- package/operations/entry/elasticsearchFields.d.ts +0 -2
- package/operations/entry/elasticsearchFields.js +0 -32
- package/operations/entry/fields.d.ts +0 -3
- package/operations/entry/fields.js +0 -60
- package/operations/settings/index.d.ts +0 -6
- package/operations/settings/index.js +0 -141
- package/operations/system/createElasticsearchTemplate.d.ts +0 -5
- package/operations/system/createElasticsearchTemplate.js +0 -62
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +0 -12
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -24
- package/upgrades/index.d.ts +0 -2
- package/upgrades/index.js +0 -16
- package/upgrades/utils.d.ts +0 -1
- package/upgrades/utils.js +0 -16
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
- package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
- package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
- package/upgrades/v5.0.0/entryValueFixer.js +0 -124
- package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
- package/upgrades/v5.0.0/fieldFinder.js +0 -42
- package/upgrades/v5.0.0/helpers.d.ts +0 -4
- package/upgrades/v5.0.0/helpers.js +0 -57
- package/upgrades/v5.0.0/index.d.ts +0 -4
- package/upgrades/v5.0.0/index.js +0 -232
- package/upgrades/v5.8.0/index.d.ts +0 -4
- package/upgrades/v5.8.0/index.js +0 -426
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createModelFields = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _plugins = require("../../../plugins");
|
|
10
|
+
var _constants = require("@webiny/api-headless-cms/constants");
|
|
11
|
+
const createSystemField = field => {
|
|
12
|
+
return {
|
|
13
|
+
...field,
|
|
14
|
+
id: field.fieldId,
|
|
15
|
+
label: field.fieldId
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const createSystemFields = () => {
|
|
19
|
+
const onMetaFields = _constants.ENTRY_META_FIELDS.filter(_constants.isDateTimeEntryMetaField).reduce((current, fieldName) => {
|
|
20
|
+
return {
|
|
21
|
+
...current,
|
|
22
|
+
[fieldName]: {
|
|
23
|
+
type: "date",
|
|
24
|
+
unmappedType: "date",
|
|
25
|
+
keyword: false,
|
|
26
|
+
systemField: true,
|
|
27
|
+
searchable: true,
|
|
28
|
+
sortable: true,
|
|
29
|
+
field: createSystemField({
|
|
30
|
+
storageId: fieldName,
|
|
31
|
+
fieldId: fieldName,
|
|
32
|
+
type: "text",
|
|
33
|
+
settings: {
|
|
34
|
+
type: "dateTimeWithoutTimezone"
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
parents: []
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}, {});
|
|
41
|
+
const byMetaFields = _constants.ENTRY_META_FIELDS.filter(_constants.isIdentityEntryMetaField).reduce((current, fieldName) => {
|
|
42
|
+
return {
|
|
43
|
+
...current,
|
|
44
|
+
[fieldName]: {
|
|
45
|
+
type: "text",
|
|
46
|
+
unmappedType: undefined,
|
|
47
|
+
systemField: true,
|
|
48
|
+
searchable: true,
|
|
49
|
+
sortable: true,
|
|
50
|
+
path: `${fieldName}.id`,
|
|
51
|
+
field: createSystemField({
|
|
52
|
+
storageId: fieldName,
|
|
53
|
+
fieldId: fieldName,
|
|
54
|
+
type: "text"
|
|
55
|
+
}),
|
|
56
|
+
parents: []
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, {});
|
|
60
|
+
return {
|
|
61
|
+
id: {
|
|
62
|
+
type: "text",
|
|
63
|
+
systemField: true,
|
|
64
|
+
searchable: true,
|
|
65
|
+
sortable: true,
|
|
66
|
+
field: createSystemField({
|
|
67
|
+
storageId: "id",
|
|
68
|
+
fieldId: "id",
|
|
69
|
+
type: "text"
|
|
70
|
+
}),
|
|
71
|
+
parents: []
|
|
72
|
+
},
|
|
73
|
+
entryId: {
|
|
74
|
+
type: "text",
|
|
75
|
+
systemField: true,
|
|
76
|
+
searchable: true,
|
|
77
|
+
sortable: true,
|
|
78
|
+
field: createSystemField({
|
|
79
|
+
storageId: "entryId",
|
|
80
|
+
fieldId: "entryId",
|
|
81
|
+
type: "text"
|
|
82
|
+
}),
|
|
83
|
+
parents: []
|
|
84
|
+
},
|
|
85
|
+
...onMetaFields,
|
|
86
|
+
...byMetaFields,
|
|
87
|
+
wbyAco_location: {
|
|
88
|
+
type: "object",
|
|
89
|
+
systemField: true,
|
|
90
|
+
searchable: true,
|
|
91
|
+
sortable: true,
|
|
92
|
+
field: createSystemField({
|
|
93
|
+
storageId: "location",
|
|
94
|
+
fieldId: "wbyAco_location",
|
|
95
|
+
type: "object",
|
|
96
|
+
settings: {
|
|
97
|
+
fields: [{
|
|
98
|
+
id: "folderId",
|
|
99
|
+
fieldId: "folderId",
|
|
100
|
+
storageId: "folderId",
|
|
101
|
+
type: "text",
|
|
102
|
+
label: "Folder ID"
|
|
103
|
+
}]
|
|
104
|
+
}
|
|
105
|
+
}),
|
|
106
|
+
parents: []
|
|
107
|
+
},
|
|
108
|
+
"wbyAco_location.folderId": {
|
|
109
|
+
type: "text",
|
|
110
|
+
systemField: true,
|
|
111
|
+
searchable: true,
|
|
112
|
+
sortable: true,
|
|
113
|
+
field: createSystemField({
|
|
114
|
+
id: "folderId",
|
|
115
|
+
fieldId: "folderId",
|
|
116
|
+
storageId: "folderId",
|
|
117
|
+
type: "text",
|
|
118
|
+
label: "Folder ID"
|
|
119
|
+
}),
|
|
120
|
+
parents: [{
|
|
121
|
+
fieldId: "wbyAco_location",
|
|
122
|
+
type: "object",
|
|
123
|
+
storageId: "location"
|
|
124
|
+
}]
|
|
125
|
+
},
|
|
126
|
+
version: {
|
|
127
|
+
type: "number",
|
|
128
|
+
unmappedType: undefined,
|
|
129
|
+
keyword: false,
|
|
130
|
+
systemField: true,
|
|
131
|
+
searchable: true,
|
|
132
|
+
sortable: true,
|
|
133
|
+
field: createSystemField({
|
|
134
|
+
storageId: "version",
|
|
135
|
+
fieldId: "version",
|
|
136
|
+
type: "number"
|
|
137
|
+
}),
|
|
138
|
+
parents: []
|
|
139
|
+
},
|
|
140
|
+
status: {
|
|
141
|
+
type: "string",
|
|
142
|
+
unmappedType: undefined,
|
|
143
|
+
keyword: false,
|
|
144
|
+
systemField: true,
|
|
145
|
+
searchable: true,
|
|
146
|
+
sortable: false,
|
|
147
|
+
field: createSystemField({
|
|
148
|
+
storageId: "status",
|
|
149
|
+
fieldId: "status",
|
|
150
|
+
type: "string"
|
|
151
|
+
}),
|
|
152
|
+
parents: []
|
|
153
|
+
},
|
|
154
|
+
wbyDeleted: {
|
|
155
|
+
type: "boolean",
|
|
156
|
+
unmappedType: undefined,
|
|
157
|
+
keyword: false,
|
|
158
|
+
systemField: true,
|
|
159
|
+
searchable: true,
|
|
160
|
+
sortable: false,
|
|
161
|
+
field: createSystemField({
|
|
162
|
+
storageId: "wbyDeleted",
|
|
163
|
+
fieldId: "wbyDeleted",
|
|
164
|
+
type: "boolean"
|
|
165
|
+
}),
|
|
166
|
+
parents: []
|
|
167
|
+
},
|
|
168
|
+
binOriginalFolderId: {
|
|
169
|
+
type: "text",
|
|
170
|
+
unmappedType: undefined,
|
|
171
|
+
keyword: false,
|
|
172
|
+
systemField: true,
|
|
173
|
+
searchable: true,
|
|
174
|
+
sortable: false,
|
|
175
|
+
field: createSystemField({
|
|
176
|
+
storageId: "binOriginalFolderId",
|
|
177
|
+
fieldId: "binOriginalFolderId",
|
|
178
|
+
type: "text"
|
|
179
|
+
}),
|
|
180
|
+
parents: []
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
const buildCustomFields = params => {
|
|
185
|
+
const {
|
|
186
|
+
fields,
|
|
187
|
+
fieldTypePlugins
|
|
188
|
+
} = params;
|
|
189
|
+
return fields.reduce((collection, field) => {
|
|
190
|
+
const typePlugin = fieldTypePlugins[field.fieldType];
|
|
191
|
+
if (!typePlugin) {
|
|
192
|
+
return collection;
|
|
193
|
+
}
|
|
194
|
+
let unmappedType = undefined;
|
|
195
|
+
if (typePlugin.unmappedType) {
|
|
196
|
+
unmappedType = typePlugin.unmappedType(field);
|
|
197
|
+
}
|
|
198
|
+
collection[field.fieldId] = {
|
|
199
|
+
type: field.fieldType,
|
|
200
|
+
field: createSystemField({
|
|
201
|
+
storageId: field.fieldId,
|
|
202
|
+
fieldId: field.fieldId,
|
|
203
|
+
type: field.fieldType
|
|
204
|
+
}),
|
|
205
|
+
unmappedType,
|
|
206
|
+
fullTextSearch: field.searchable ? typePlugin.fullTextSearch : false,
|
|
207
|
+
searchable: field.searchable || typePlugin.searchable,
|
|
208
|
+
sortable: field.sortable || typePlugin.sortable,
|
|
209
|
+
systemField: false,
|
|
210
|
+
path: field.path,
|
|
211
|
+
parents: []
|
|
212
|
+
};
|
|
213
|
+
return collection;
|
|
214
|
+
}, {});
|
|
215
|
+
};
|
|
216
|
+
const buildFieldsList = params => {
|
|
217
|
+
const {
|
|
218
|
+
plugins,
|
|
219
|
+
fields,
|
|
220
|
+
parents
|
|
221
|
+
} = params;
|
|
222
|
+
return fields.reduce((result, field) => {
|
|
223
|
+
const plugin = plugins[field.type];
|
|
224
|
+
if (!plugin) {
|
|
225
|
+
throw new _error.default(`There is no plugin for field type "${field.type}".`);
|
|
226
|
+
}
|
|
227
|
+
const {
|
|
228
|
+
searchable,
|
|
229
|
+
sortable,
|
|
230
|
+
unmappedType,
|
|
231
|
+
fullTextSearch
|
|
232
|
+
} = plugin;
|
|
233
|
+
/**
|
|
234
|
+
* If a field has child fields, go through them and add them to a result.
|
|
235
|
+
*/
|
|
236
|
+
const childFields = field.settings?.fields || [];
|
|
237
|
+
if (childFields.length > 0) {
|
|
238
|
+
/**
|
|
239
|
+
* Let's build all the child fields
|
|
240
|
+
*/
|
|
241
|
+
const childResult = buildFieldsList({
|
|
242
|
+
fields: childFields,
|
|
243
|
+
plugins,
|
|
244
|
+
parents: [...parents, {
|
|
245
|
+
fieldId: field.fieldId,
|
|
246
|
+
storageId: field.storageId,
|
|
247
|
+
type: field.type
|
|
248
|
+
}]
|
|
249
|
+
});
|
|
250
|
+
Object.assign(result, childResult);
|
|
251
|
+
}
|
|
252
|
+
const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(".");
|
|
253
|
+
result[identifier] = {
|
|
254
|
+
type: field.type,
|
|
255
|
+
parents,
|
|
256
|
+
searchable,
|
|
257
|
+
sortable,
|
|
258
|
+
fullTextSearch,
|
|
259
|
+
unmappedType: typeof unmappedType === "function" ? unmappedType(field) : undefined,
|
|
260
|
+
systemField: false,
|
|
261
|
+
field
|
|
262
|
+
};
|
|
263
|
+
return result;
|
|
264
|
+
}, {});
|
|
265
|
+
};
|
|
266
|
+
const createModelFields = ({
|
|
267
|
+
plugins,
|
|
268
|
+
model
|
|
269
|
+
}) => {
|
|
270
|
+
const fields = model.fields;
|
|
271
|
+
const fieldDefinitionPlugins = plugins.byType(_plugins.CmsElasticsearchModelFieldPlugin.type).filter(plugin => {
|
|
272
|
+
return plugin.canBeApplied(model.modelId);
|
|
273
|
+
});
|
|
274
|
+
/**
|
|
275
|
+
* Collect all unmappedType from elastic plugins.
|
|
276
|
+
*/
|
|
277
|
+
const unmappedTypes = plugins.byType("cms-model-field-to-elastic-search").reduce((acc, plugin) => {
|
|
278
|
+
if (!plugin.unmappedType) {
|
|
279
|
+
return acc;
|
|
280
|
+
}
|
|
281
|
+
acc[plugin.fieldType] = plugin.unmappedType;
|
|
282
|
+
return acc;
|
|
283
|
+
}, {});
|
|
284
|
+
/**
|
|
285
|
+
* Collect all field types from the plugins.
|
|
286
|
+
*/
|
|
287
|
+
const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
|
|
288
|
+
const {
|
|
289
|
+
fieldType,
|
|
290
|
+
fullTextSearch
|
|
291
|
+
} = plugin;
|
|
292
|
+
types[fieldType] = {
|
|
293
|
+
unmappedType: unmappedTypes[fieldType],
|
|
294
|
+
searchable: plugin.isSearchable,
|
|
295
|
+
sortable: plugin.isSortable,
|
|
296
|
+
fullTextSearch
|
|
297
|
+
};
|
|
298
|
+
return types;
|
|
299
|
+
}, {});
|
|
300
|
+
return {
|
|
301
|
+
...createSystemFields(),
|
|
302
|
+
...buildCustomFields({
|
|
303
|
+
fields: fieldDefinitionPlugins,
|
|
304
|
+
fieldTypePlugins
|
|
305
|
+
}),
|
|
306
|
+
...buildFieldsList({
|
|
307
|
+
fields,
|
|
308
|
+
plugins: fieldTypePlugins,
|
|
309
|
+
parents: []
|
|
310
|
+
})
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
exports.createModelFields = createModelFields;
|
|
314
|
+
|
|
315
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_plugins","_constants","createSystemField","field","id","fieldId","label","createSystemFields","onMetaFields","ENTRY_META_FIELDS","filter","isDateTimeEntryMetaField","reduce","current","fieldName","type","unmappedType","keyword","systemField","searchable","sortable","storageId","settings","parents","byMetaFields","isIdentityEntryMetaField","undefined","path","entryId","wbyAco_location","fields","version","status","wbyDeleted","binOriginalFolderId","buildCustomFields","params","fieldTypePlugins","collection","typePlugin","fieldType","fullTextSearch","buildFieldsList","plugins","result","plugin","WebinyError","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","model","fieldDefinitionPlugins","byType","CmsElasticsearchModelFieldPlugin","canBeApplied","modelId","unmappedTypes","acc","types","isSearchable","isSortable","exports"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types\";\nimport type { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport type { ModelFieldParent, ModelFields } from \"./types\";\nimport { CmsElasticsearchModelFieldPlugin } from \"~/plugins\";\nimport {\n ENTRY_META_FIELDS,\n isDateTimeEntryMetaField,\n isIdentityEntryMetaField\n} from \"@webiny/api-headless-cms/constants\";\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 const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).reduce(\n (current, fieldName) => {\n return {\n ...current,\n [fieldName]: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: fieldName,\n fieldId: fieldName,\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n }\n };\n },\n {}\n );\n\n const byMetaFields = ENTRY_META_FIELDS.filter(isIdentityEntryMetaField).reduce(\n (current, fieldName) => {\n return {\n ...current,\n [fieldName]: {\n type: \"text\",\n unmappedType: undefined,\n systemField: true,\n searchable: true,\n sortable: true,\n path: `${fieldName}.id`,\n field: createSystemField({\n storageId: fieldName,\n fieldId: fieldName,\n type: \"text\"\n }),\n parents: []\n }\n };\n },\n {}\n );\n\n return {\n id: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n\n ...onMetaFields,\n ...byMetaFields,\n\n wbyAco_location: {\n type: \"object\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"location\",\n fieldId: \"wbyAco_location\",\n type: \"object\",\n settings: {\n fields: [\n {\n id: \"folderId\",\n fieldId: \"folderId\",\n storageId: \"folderId\",\n type: \"text\",\n label: \"Folder ID\"\n }\n ]\n }\n }),\n parents: []\n },\n \"wbyAco_location.folderId\": {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n id: \"folderId\",\n fieldId: \"folderId\",\n storageId: \"folderId\",\n type: \"text\",\n label: \"Folder ID\"\n }),\n parents: [\n {\n fieldId: \"wbyAco_location\",\n type: \"object\",\n storageId: \"location\"\n }\n ]\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: 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 systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n },\n wbyDeleted: {\n type: \"boolean\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"wbyDeleted\",\n fieldId: \"wbyDeleted\",\n type: \"boolean\"\n }),\n parents: []\n },\n binOriginalFolderId: {\n type: \"text\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"binOriginalFolderId\",\n fieldId: \"binOriginalFolderId\",\n type: \"text\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n searchable: boolean;\n sortable: boolean;\n fullTextSearch?: boolean;\n}\n\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildCustomFieldsParams {\n fields: CmsElasticsearchModelFieldPlugin[];\n fieldTypePlugins: FieldTypePlugins;\n}\n\nconst buildCustomFields = (params: BuildCustomFieldsParams) => {\n const { fields, fieldTypePlugins } = params;\n\n return fields.reduce<ModelFields>((collection, field) => {\n const typePlugin = fieldTypePlugins[field.fieldType];\n if (!typePlugin) {\n return collection;\n }\n let unmappedType: string | undefined = undefined;\n if (typePlugin.unmappedType) {\n unmappedType = typePlugin.unmappedType(field);\n }\n\n collection[field.fieldId] = {\n type: field.fieldType,\n field: createSystemField({\n storageId: field.fieldId,\n fieldId: field.fieldId,\n type: field.fieldType\n }),\n unmappedType,\n fullTextSearch: field.searchable ? typePlugin.fullTextSearch : false,\n searchable: field.searchable || typePlugin.searchable,\n sortable: field.sortable || typePlugin.sortable,\n systemField: false,\n path: field.path,\n parents: []\n };\n\n return collection;\n }, {});\n};\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\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 { searchable, sortable, 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 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 searchable,\n sortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n systemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n}\n\nexport const createModelFields = ({ plugins, model }: Params) => {\n const fields = model.fields;\n const fieldDefinitionPlugins = plugins\n .byType<CmsElasticsearchModelFieldPlugin>(CmsElasticsearchModelFieldPlugin.type)\n .filter(plugin => {\n return plugin.canBeApplied(model.modelId);\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, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n searchable: plugin.isSearchable,\n sortable: plugin.isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildCustomFields({\n fields: fieldDefinitionPlugins,\n fieldTypePlugins\n }),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: []\n })\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AASA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAQA,MAAMG,iBAAiB,GAAIC,KAA2B,IAAoB;EACtE,OAAO;IACH,GAAGA,KAAK;IACRC,EAAE,EAAED,KAAK,CAACE,OAAO;IACjBC,KAAK,EAAEH,KAAK,CAACE;EACjB,CAAC;AACL,CAAC;AAED,MAAME,kBAAkB,GAAGA,CAAA,KAAmB;EAC1C,MAAMC,YAAY,GAAGC,4BAAiB,CAACC,MAAM,CAACC,mCAAwB,CAAC,CAACC,MAAM,CAC1E,CAACC,OAAO,EAAEC,SAAS,KAAK;IACpB,OAAO;MACH,GAAGD,OAAO;MACV,CAACC,SAAS,GAAG;QACTC,IAAI,EAAE,MAAM;QACZC,YAAY,EAAE,MAAM;QACpBC,OAAO,EAAE,KAAK;QACdC,WAAW,EAAE,IAAI;QACjBC,UAAU,EAAE,IAAI;QAChBC,QAAQ,EAAE,IAAI;QACdjB,KAAK,EAAED,iBAAiB,CAAC;UACrBmB,SAAS,EAAEP,SAAS;UACpBT,OAAO,EAAES,SAAS;UAClBC,IAAI,EAAE,MAAM;UACZO,QAAQ,EAAE;YACNP,IAAI,EAAE;UACV;QACJ,CAAC,CAAC;QACFQ,OAAO,EAAE;MACb;IACJ,CAAC;EACL,CAAC,EACD,CAAC,CACL,CAAC;EAED,MAAMC,YAAY,GAAGf,4BAAiB,CAACC,MAAM,CAACe,mCAAwB,CAAC,CAACb,MAAM,CAC1E,CAACC,OAAO,EAAEC,SAAS,KAAK;IACpB,OAAO;MACH,GAAGD,OAAO;MACV,CAACC,SAAS,GAAG;QACTC,IAAI,EAAE,MAAM;QACZC,YAAY,EAAEU,SAAS;QACvBR,WAA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B,MAAM,CAACL,SAAS,CAAC,GAAGK,MAAM,CAAC7B,YAAY;IAC3C,OAAOgD,GAAG;EACd,CAAC,EAAE,CAAC,CAAC,CAAC;EACV;AACJ;AACA;EACI,MAAM3B,gBAAgB,GAAGM,OAAO,CAC3BgB,MAAM,CAA+B,4BAA4B,CAAC,CAClE/C,MAAM,CAAmB,CAACqD,KAAK,EAAEpB,MAAM,KAAK;IACzC,MAAM;MAAEL,SAAS;MAAEC;IAAe,CAAC,GAAGI,MAAM;IAC5CoB,KAAK,CAACzB,SAAS,CAAC,GAAG;MACfxB,YAAY,EAAE+C,aAAa,CAACvB,SAAS,CAAC;MACtCrB,UAAU,EAAE0B,MAAM,CAACqB,YAAY;MAC/B9C,QAAQ,EAAEyB,MAAM,CAACsB,UAAU;MAC3B1B;IACJ,CAAC;IACD,OAAOwB,KAAK;EAChB,CAAC,EAAE,CAAC,CAAC,CAAC;EAEV,OAAO;IACH,GAAG1D,kBAAkB,CAAC,CAAC;IACvB,GAAG4B,iBAAiB,CAAC;MACjBL,MAAM,EAAE4B,sBAAsB;MAC9BrB;IACJ,CAAC,CAAC;IACF,GAAGK,eAAe,CAAC;MACfZ,MAAM;MACNa,OAAO,EAAEN,gBAAgB;MACzBd,OAAO,EAAE;IACb,CAAC;EACL,CAAC;AACL,CAAC;AAAC6C,OAAA,CAAAZ,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ElasticsearchQueryBuilderOperatorPlugins, ElasticsearchQuerySearchValuePlugins } from "../types";
|
|
2
|
+
import type { 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,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createApplyFiltering = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _transformValueForSearch = require("../transformValueForSearch");
|
|
10
|
+
var _keyword = require("../keyword");
|
|
11
|
+
var _path = require("./path");
|
|
12
|
+
const createApplyFiltering = ({
|
|
13
|
+
operatorPlugins,
|
|
14
|
+
searchPlugins
|
|
15
|
+
}) => {
|
|
16
|
+
const createFieldPath = (0, _path.createFieldPathFactory)({
|
|
17
|
+
plugins: searchPlugins
|
|
18
|
+
});
|
|
19
|
+
return params => {
|
|
20
|
+
const {
|
|
21
|
+
key,
|
|
22
|
+
value: initialValue,
|
|
23
|
+
query,
|
|
24
|
+
operator,
|
|
25
|
+
field
|
|
26
|
+
} = params;
|
|
27
|
+
const plugin = operatorPlugins[operator];
|
|
28
|
+
if (!plugin) {
|
|
29
|
+
throw new _error.default(`Elasticsearch operator "${operator}" plugin missing.`, "PLUGIN_MISSING", {
|
|
30
|
+
operator
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const value = (0, _transformValueForSearch.transformValueForSearch)({
|
|
34
|
+
plugins: searchPlugins,
|
|
35
|
+
field: field.field,
|
|
36
|
+
value: initialValue
|
|
37
|
+
});
|
|
38
|
+
const keyword = (0, _keyword.hasKeyword)(field);
|
|
39
|
+
const {
|
|
40
|
+
basePath,
|
|
41
|
+
path
|
|
42
|
+
} = createFieldPath({
|
|
43
|
+
field,
|
|
44
|
+
value,
|
|
45
|
+
originalValue: initialValue,
|
|
46
|
+
key,
|
|
47
|
+
keyword
|
|
48
|
+
});
|
|
49
|
+
plugin.apply(query, {
|
|
50
|
+
name: field.field.fieldId,
|
|
51
|
+
basePath,
|
|
52
|
+
path,
|
|
53
|
+
value,
|
|
54
|
+
keyword
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
exports.createApplyFiltering = createApplyFiltering;
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=applyFiltering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_transformValueForSearch","_keyword","_path","createApplyFiltering","operatorPlugins","searchPlugins","createFieldPath","createFieldPathFactory","plugins","params","key","value","initialValue","query","operator","field","plugin","WebinyError","transformValueForSearch","keyword","hasKeyword","basePath","path","originalValue","apply","name","fieldId","exports"],"sources":["applyFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword\";\nimport type {\n ElasticsearchQueryBuilderOperatorPlugins,\n ElasticsearchQuerySearchValuePlugins\n} from \"~/operations/entry/elasticsearch/types\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path\";\nimport type { 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(\n `Elasticsearch operator \"${operator}\" plugin missing.`,\n \"PLUGIN_MISSING\",\n {\n operator\n }\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 originalValue: initialValue,\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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,wBAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AAQO,MAAMI,oBAAoB,GAAGA,CAAC;EACjCC,eAAe;EACfC;AACU,CAAC,KAAuB;EAClC,MAAMC,eAAe,GAAG,IAAAC,4BAAsB,EAAC;IAC3CC,OAAO,EAAEH;EACb,CAAC,CAAC;EAEF,OAAOI,MAAM,IAAI;IACb,MAAM;MAAEC,GAAG;MAAEC,KAAK,EAAEC,YAAY;MAAEC,KAAK;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGN,MAAM;IAEnE,MAAMO,MAAM,GAAGZ,eAAe,CAACU,QAAQ,CAAC;IACxC,IAAI,CAACE,MAAM,EAAE;MACT,MAAM,IAAIC,cAAW,CACjB,2BAA2BH,QAAQ,mBAAmB,EACtD,gBAAgB,EAChB;QACIA;MACJ,CACJ,CAAC;IACL;IAEA,MAAMH,KAAK,GAAG,IAAAO,gDAAuB,EAAC;MAClCV,OAAO,EAAEH,aAAa;MACtBU,KAAK,EAAEA,KAAK,CAACA,KAAK;MAClBJ,KAAK,EAAEC;IACX,CAAC,CAAC;IAEF,MAAMO,OAAO,GAAG,IAAAC,mBAAU,EAACL,KAAK,CAAC;IAEjC,MAAM;MAAEM,QAAQ;MAAEC;IAAK,CAAC,GAAGhB,eAAe,CAAC;MACvCS,KAAK;MACLJ,KAAK;MACLY,aAAa,EAAEX,YAAY;MAC3BF,GAAG;MACHS;IACJ,CAAC,CAAC;IAEFH,MAAM,CAACQ,KAAK,CAACX,KAAK,EAAE;MAChBY,IAAI,EAAEV,KAAK,CAACA,KAAK,CAACW,OAAO;MACzBL,QAAQ;MACRC,IAAI;MACJX,KAAK;MACLQ;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACQ,OAAA,CAAAxB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import type { ModelFields } from "../types";
|
|
3
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
import type { 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;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createExecFiltering = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _search = require("../plugins/search");
|
|
10
|
+
var _operator = require("../plugins/operator");
|
|
11
|
+
var _initialQuery = require("../initialQuery");
|
|
12
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
13
|
+
var _values = require("./values");
|
|
14
|
+
var _populated = require("./populated");
|
|
15
|
+
var _applyFiltering = require("./applyFiltering");
|
|
16
|
+
var _CmsEntryFilterPlugin = require("../../../../plugins/CmsEntryFilterPlugin");
|
|
17
|
+
var _assignMinimumShouldMatchToQuery = require("../assignMinimumShouldMatchToQuery");
|
|
18
|
+
const createExecFiltering = params => {
|
|
19
|
+
const {
|
|
20
|
+
fields,
|
|
21
|
+
plugins,
|
|
22
|
+
model
|
|
23
|
+
} = params;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.
|
|
27
|
+
*/
|
|
28
|
+
const searchPlugins = (0, _search.createSearchPluginList)({
|
|
29
|
+
plugins
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* We need the operator plugins, which we execute on our where conditions.
|
|
33
|
+
*/
|
|
34
|
+
const operatorPlugins = (0, _operator.createOperatorPluginList)({
|
|
35
|
+
plugins,
|
|
36
|
+
locale: model.locale
|
|
37
|
+
});
|
|
38
|
+
const applyFiltering = (0, _applyFiltering.createApplyFiltering)({
|
|
39
|
+
operatorPlugins,
|
|
40
|
+
searchPlugins
|
|
41
|
+
});
|
|
42
|
+
const filteringPlugins = plugins.byType(_CmsEntryFilterPlugin.CmsEntryFilterPlugin.type).reduce((collection, plugin) => {
|
|
43
|
+
collection[plugin.fieldType] = plugin;
|
|
44
|
+
return collection;
|
|
45
|
+
}, {});
|
|
46
|
+
const getFilterPlugin = type => {
|
|
47
|
+
const plugin = filteringPlugins[type] || filteringPlugins["*"];
|
|
48
|
+
if (plugin) {
|
|
49
|
+
return plugin;
|
|
50
|
+
}
|
|
51
|
+
throw new _error.default(`There is no filtering plugin for the given field type "${type}".`, "FILTERING_PLUGIN_ERROR", {
|
|
52
|
+
type
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const execFiltering = params => {
|
|
56
|
+
const {
|
|
57
|
+
where: initialWhere,
|
|
58
|
+
query
|
|
59
|
+
} = params;
|
|
60
|
+
/**
|
|
61
|
+
* No point in continuing if no "where" conditions exist.
|
|
62
|
+
*/
|
|
63
|
+
const keys = Object.keys(initialWhere);
|
|
64
|
+
if (keys.length === 0) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const where = {
|
|
68
|
+
...initialWhere
|
|
69
|
+
};
|
|
70
|
+
for (const key in where) {
|
|
71
|
+
const value = where[key];
|
|
72
|
+
/**
|
|
73
|
+
* We always skip if no value is defined.
|
|
74
|
+
* Only skip undefined value, null is valid.
|
|
75
|
+
*/
|
|
76
|
+
if (value === undefined) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
//
|
|
80
|
+
/**
|
|
81
|
+
* When we are running with AND, the "value" MUST be an array.
|
|
82
|
+
*/else if (key === "AND") {
|
|
83
|
+
const childWhereList = (0, _values.getWhereValues)(value, "AND");
|
|
84
|
+
const childQuery = (0, _initialQuery.createBaseQuery)();
|
|
85
|
+
for (const childWhere of childWhereList) {
|
|
86
|
+
execFiltering({
|
|
87
|
+
query: childQuery,
|
|
88
|
+
where: childWhere
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const childQueryBool = (0, _populated.getPopulated)(childQuery);
|
|
92
|
+
if (Object.keys(childQueryBool).length === 0) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
query.filter.push({
|
|
96
|
+
bool: childQueryBool
|
|
97
|
+
});
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
//
|
|
101
|
+
/**
|
|
102
|
+
* When we are running with OR, the "value" must be an array.
|
|
103
|
+
*/else if (key === "OR") {
|
|
104
|
+
const childWhereList = (0, _values.getWhereValues)(value, "OR");
|
|
105
|
+
/**
|
|
106
|
+
* Each of the conditions MUST produce it's own should section.
|
|
107
|
+
*/
|
|
108
|
+
const should = [];
|
|
109
|
+
for (const childWhere of childWhereList) {
|
|
110
|
+
const childQuery = (0, _initialQuery.createBaseQuery)();
|
|
111
|
+
execFiltering({
|
|
112
|
+
query: childQuery,
|
|
113
|
+
where: childWhere
|
|
114
|
+
});
|
|
115
|
+
const childQueryBool = (0, _populated.getPopulated)(childQuery);
|
|
116
|
+
if (Object.keys(childQueryBool).length === 0) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
should.push({
|
|
120
|
+
bool: childQueryBool
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (should.length === 0) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
query.should.push(...should);
|
|
127
|
+
/**
|
|
128
|
+
* If there are any should, minimum to have is 1.
|
|
129
|
+
* Of course, do not override if it's already set.
|
|
130
|
+
*/
|
|
131
|
+
(0, _assignMinimumShouldMatchToQuery.assignMinimumShouldMatchToQuery)({
|
|
132
|
+
query
|
|
133
|
+
});
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const {
|
|
137
|
+
field: whereFieldId,
|
|
138
|
+
operator
|
|
139
|
+
} = (0, _apiElasticsearch.parseWhereKey)(key);
|
|
140
|
+
let fieldId = whereFieldId;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* TODO This will be required until the storage operations receive the fieldId instead of field storageId.
|
|
144
|
+
* TODO For this to work without field searching, we need to refactor how the query looks like.
|
|
145
|
+
*
|
|
146
|
+
* Storage operations should NEVER receive an field storageId, only alias - fieldId.
|
|
147
|
+
*/
|
|
148
|
+
const cmsModelField = model.fields.find(f => f.fieldId === fieldId);
|
|
149
|
+
if (!cmsModelField && !fields[fieldId]) {
|
|
150
|
+
throw new _error.default(`There is no CMS Model Field "${fieldId}".`);
|
|
151
|
+
} else if (cmsModelField) {
|
|
152
|
+
fieldId = cmsModelField.fieldId;
|
|
153
|
+
}
|
|
154
|
+
const field = fields[fieldId];
|
|
155
|
+
if (!field) {
|
|
156
|
+
throw new _error.default(`There is no field "${fieldId}".`, "EXEC_FILTERING_ERROR");
|
|
157
|
+
}
|
|
158
|
+
const filterPlugin = getFilterPlugin(field.type);
|
|
159
|
+
filterPlugin.exec({
|
|
160
|
+
applyFiltering,
|
|
161
|
+
getFilterPlugin,
|
|
162
|
+
key,
|
|
163
|
+
value,
|
|
164
|
+
operator,
|
|
165
|
+
field,
|
|
166
|
+
fields,
|
|
167
|
+
query
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
return execFiltering;
|
|
172
|
+
};
|
|
173
|
+
exports.createExecFiltering = createExecFiltering;
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_search","_operator","_initialQuery","_apiElasticsearch","_values","_populated","_applyFiltering","_CmsEntryFilterPlugin","_assignMinimumShouldMatchToQuery","createExecFiltering","params","fields","plugins","model","searchPlugins","createSearchPluginList","operatorPlugins","createOperatorPluginList","locale","applyFiltering","createApplyFiltering","filteringPlugins","byType","CmsEntryFilterPlugin","type","reduce","collection","plugin","fieldType","getFilterPlugin","WebinyError","execFiltering","where","initialWhere","query","keys","Object","length","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","filter","push","bool","should","assignMinimumShouldMatchToQuery","field","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","find","f","filterPlugin","exec","exports"],"sources":["exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { ElasticsearchBoolQueryConfig, Query } from \"@webiny/api-elasticsearch/types\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport { getWhereValues } from \"./values\";\nimport { getPopulated } from \"./populated\";\nimport { createApplyFiltering } from \"./applyFiltering\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n}\nexport interface ExecParams {\n where: CmsEntryListWhere;\n query: ElasticsearchBoolQueryConfig;\n}\nexport interface CreateExecFilteringResponse {\n (params: ExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model } = params;\n\n /**\n * We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.\n */\n const searchPlugins = createSearchPluginList({\n plugins\n });\n /**\n * We need the operator plugins, which we execute on our where conditions.\n */\n const operatorPlugins = createOperatorPluginList({\n plugins,\n locale: model.locale\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n searchPlugins\n });\n\n const filteringPlugins = plugins\n .byType<CmsEntryFilterPlugin>(CmsEntryFilterPlugin.type)\n .reduce<Record<string, CmsEntryFilterPlugin>>((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {});\n\n const getFilterPlugin = (type: string) => {\n const plugin = filteringPlugins[type] || filteringPlugins[\"*\"];\n if (plugin) {\n return plugin;\n }\n throw new WebinyError(\n `There is no filtering plugin for the given field type \"${type}\".`,\n \"FILTERING_PLUGIN_ERROR\",\n {\n type\n }\n );\n };\n\n const execFiltering = (params: ExecParams) => {\n const { where: initialWhere, query } = params;\n /**\n * No point in continuing if no \"where\" conditions exist.\n */\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n for (const key in where) {\n const value = where[key];\n /**\n * We always skip if no value is defined.\n * Only skip undefined value, null is valid.\n */\n if (value === undefined) {\n continue;\n }\n //\n /**\n * When we are running with AND, the \"value\" MUST be an array.\n */\n else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n\n const childQuery = createBaseQuery();\n\n for (const childWhere of childWhereList) {\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({\n bool: childQueryBool\n });\n\n continue;\n }\n //\n /**\n * When we are running with OR, the \"value\" must be an array.\n */\n else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n /**\n * Each of the conditions MUST produce it's own should section.\n */\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({\n bool: childQueryBool\n });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n /**\n * If there are any should, minimum to have is 1.\n * Of course, do not override if it's already set.\n */\n assignMinimumShouldMatchToQuery({\n query\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n let fieldId: string = whereFieldId;\n\n /**\n * TODO This will be required until the storage operations receive the fieldId instead of field storageId.\n * TODO For this to work without field searching, we need to refactor how the query looks like.\n *\n * Storage operations should NEVER receive an field storageId, only alias - fieldId.\n */\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`, \"EXEC_FILTERING_ERROR\");\n }\n const filterPlugin = getFilterPlugin(field.type);\n\n filterPlugin.exec({\n applyFiltering,\n getFilterPlugin,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,S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