@webiny/api-headless-cms-ddb 0.0.0-ee-vpcs.549378cf03
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/LICENSE +21 -0
- package/README.md +25 -0
- package/definitions/entry.d.ts +9 -0
- package/definitions/entry.js +96 -0
- package/definitions/entry.js.map +1 -0
- package/definitions/group.d.ts +9 -0
- package/definitions/group.js +70 -0
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +9 -0
- package/definitions/model.js +97 -0
- package/definitions/model.js.map +1 -0
- package/definitions/settings.d.ts +9 -0
- package/definitions/settings.js +58 -0
- package/definitions/settings.js.map +1 -0
- package/definitions/system.d.ts +9 -0
- package/definitions/system.js +46 -0
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +9 -0
- package/definitions/table.js +30 -0
- package/definitions/table.js.map +1 -0
- package/dynamoDb/index.d.ts +2 -0
- package/dynamoDb/index.js +20 -0
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/path/plainObject.d.ts +2 -0
- package/dynamoDb/path/plainObject.js +40 -0
- package/dynamoDb/path/plainObject.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +3 -0
- package/dynamoDb/storage/date.js +109 -0
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +10 -0
- package/dynamoDb/storage/longText.js +108 -0
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -0
- package/dynamoDb/storage/richText.js +113 -0
- package/dynamoDb/storage/richText.js.map +1 -0
- package/dynamoDb/transformValue/datetime.d.ts +5 -0
- package/dynamoDb/transformValue/datetime.js +52 -0
- package/dynamoDb/transformValue/datetime.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +150 -0
- package/index.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +42 -0
- package/operations/entry/dataLoaders.js +321 -0
- package/operations/entry/dataLoaders.js.map +1 -0
- package/operations/entry/filtering/createExpressions.d.ts +26 -0
- package/operations/entry/filtering/createExpressions.js +217 -0
- package/operations/entry/filtering/createExpressions.js.map +1 -0
- package/operations/entry/filtering/createFields.d.ts +14 -0
- package/operations/entry/filtering/createFields.js +123 -0
- package/operations/entry/filtering/createFields.js.map +1 -0
- package/operations/entry/filtering/extractSort.d.ts +13 -0
- package/operations/entry/filtering/extractSort.js +55 -0
- package/operations/entry/filtering/extractSort.js.map +1 -0
- package/operations/entry/filtering/filter.d.ts +15 -0
- package/operations/entry/filtering/filter.js +178 -0
- package/operations/entry/filtering/filter.js.map +1 -0
- package/operations/entry/filtering/fullTextSearch.d.ts +14 -0
- package/operations/entry/filtering/fullTextSearch.js +60 -0
- package/operations/entry/filtering/fullTextSearch.js.map +1 -0
- package/operations/entry/filtering/getValue.d.ts +5 -0
- package/operations/entry/filtering/getValue.js +81 -0
- package/operations/entry/filtering/getValue.js.map +1 -0
- package/operations/entry/filtering/index.d.ts +2 -0
- package/operations/entry/filtering/index.js +21 -0
- package/operations/entry/filtering/index.js.map +1 -0
- package/operations/entry/filtering/mapPlugins.d.ts +8 -0
- package/operations/entry/filtering/mapPlugins.js +39 -0
- package/operations/entry/filtering/mapPlugins.js.map +1 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +48 -0
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/filtering/plugins/index.js +18 -0
- package/operations/entry/filtering/plugins/index.js.map +1 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js +107 -0
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -0
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js +89 -0
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +9 -0
- package/operations/entry/filtering/sort.js +80 -0
- package/operations/entry/filtering/sort.js.map +1 -0
- package/operations/entry/filtering/systemFields.d.ts +4 -0
- package/operations/entry/filtering/systemFields.js +72 -0
- package/operations/entry/filtering/systemFields.js.map +1 -0
- package/operations/entry/filtering/transform.d.ts +6 -0
- package/operations/entry/filtering/transform.js +19 -0
- package/operations/entry/filtering/transform.js.map +1 -0
- package/operations/entry/filtering/types.d.ts +40 -0
- package/operations/entry/filtering/types.js +5 -0
- package/operations/entry/filtering/types.js.map +1 -0
- package/operations/entry/filtering/values.d.ts +2 -0
- package/operations/entry/filtering/values.js +28 -0
- package/operations/entry/filtering/values.js.map +1 -0
- package/operations/entry/filtering/where.d.ts +5 -0
- package/operations/entry/filtering/where.js +38 -0
- package/operations/entry/filtering/where.js.map +1 -0
- package/operations/entry/index.d.ts +8 -0
- package/operations/entry/index.js +872 -0
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.d.ts +25 -0
- package/operations/entry/keys.js +73 -0
- package/operations/entry/keys.js.map +1 -0
- package/operations/entry/systemFields.d.ts +2 -0
- package/operations/entry/systemFields.js +74 -0
- package/operations/entry/systemFields.js.map +1 -0
- package/operations/group/index.d.ts +9 -0
- package/operations/group/index.js +192 -0
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +7 -0
- package/operations/model/index.js +162 -0
- package/operations/model/index.js.map +1 -0
- package/operations/settings/index.d.ts +7 -0
- package/operations/settings/index.js +135 -0
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +7 -0
- package/operations/system/index.js +99 -0
- package/operations/system/index.js.map +1 -0
- package/package.json +60 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +22 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js +55 -0
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -0
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +43 -0
- package/plugins/CmsEntryFieldFilterPlugin.js +31 -0
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +18 -0
- package/plugins/index.js.map +1 -0
- package/types.d.ts +53 -0
- package/types.js +16 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,123 @@
|
|
|
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.createFields = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _systemFields = require("./systemFields");
|
|
13
|
+
|
|
14
|
+
var _plugins = require("../../../plugins");
|
|
15
|
+
|
|
16
|
+
var _mapPlugins = require("./mapPlugins");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This method will map the fieldId (fieldId -> field) to the actual field.
|
|
20
|
+
*
|
|
21
|
+
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
22
|
+
*/
|
|
23
|
+
const createFields = params => {
|
|
24
|
+
const {
|
|
25
|
+
fields,
|
|
26
|
+
plugins
|
|
27
|
+
} = params;
|
|
28
|
+
const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
29
|
+
plugins,
|
|
30
|
+
type: "cms-field-filter-value-transform",
|
|
31
|
+
property: "fieldType"
|
|
32
|
+
});
|
|
33
|
+
const valuePathPlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
34
|
+
plugins,
|
|
35
|
+
type: _plugins.CmsEntryFieldFilterPathPlugin.type,
|
|
36
|
+
property: "fieldType"
|
|
37
|
+
});
|
|
38
|
+
const collection = (0, _systemFields.createSystemFields)().reduce((fields, field) => {
|
|
39
|
+
const transformPlugin = transformValuePlugins[field.type];
|
|
40
|
+
fields[field.fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
41
|
+
parents: [],
|
|
42
|
+
system: true,
|
|
43
|
+
createPath: ({
|
|
44
|
+
field
|
|
45
|
+
}) => {
|
|
46
|
+
var _field$settings;
|
|
47
|
+
|
|
48
|
+
return ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.path) || field.fieldId;
|
|
49
|
+
},
|
|
50
|
+
transform: value => {
|
|
51
|
+
if (!transformPlugin) {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return transformPlugin.transform({
|
|
56
|
+
field,
|
|
57
|
+
value
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return fields;
|
|
62
|
+
}, {});
|
|
63
|
+
|
|
64
|
+
const addFieldsToCollection = (fields, parents = []) => {
|
|
65
|
+
/**
|
|
66
|
+
* Exit early if no fields are sent.
|
|
67
|
+
*/
|
|
68
|
+
if (fields.length === 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const field of fields) {
|
|
73
|
+
var _field$settings2;
|
|
74
|
+
|
|
75
|
+
const transformPlugin = transformValuePlugins[field.type];
|
|
76
|
+
const valuePathPlugin = valuePathPlugins[field.type];
|
|
77
|
+
/**
|
|
78
|
+
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
const fieldId = [...parents, {
|
|
82
|
+
fieldId: field.fieldId,
|
|
83
|
+
multipleValues: field.multipleValues
|
|
84
|
+
}].map(f => f.fieldId).join(".");
|
|
85
|
+
collection[fieldId] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
|
|
86
|
+
parents,
|
|
87
|
+
system: false,
|
|
88
|
+
createPath: params => {
|
|
89
|
+
if (valuePathPlugin) {
|
|
90
|
+
return valuePathPlugin.createPath(params);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return ["values"].concat(parents.map(parent => parent.fieldId)).concat([params.field.fieldId]).join(".");
|
|
94
|
+
},
|
|
95
|
+
transform: value => {
|
|
96
|
+
if (!transformPlugin) {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return transformPlugin.transform({
|
|
101
|
+
field,
|
|
102
|
+
value
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const childFields = (_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields;
|
|
107
|
+
|
|
108
|
+
if (!childFields || childFields.length === 0) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
addFieldsToCollection(childFields, [...parents, {
|
|
113
|
+
fieldId: field.fieldId,
|
|
114
|
+
multipleValues: field.multipleValues
|
|
115
|
+
}]);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
addFieldsToCollection(fields);
|
|
120
|
+
return collection;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
exports.createFields = createFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFields","params","fields","plugins","transformValuePlugins","getMappedPlugins","type","property","valuePathPlugins","CmsEntryFieldFilterPathPlugin","collection","createSystemFields","reduce","field","transformPlugin","fieldId","parents","system","createPath","settings","path","transform","value","addFieldsToCollection","length","valuePathPlugin","multipleValues","map","f","join","concat","parent","childFields"],"sources":["createFields.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { createSystemFields } from \"./systemFields\";\nimport { Field, FieldParent } from \"./types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins\";\nimport { getMappedPlugins } from \"./mapPlugins\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n/**\n * This method will map the fieldId (fieldId -> field) to the actual field.\n *\n * In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).\n */\nexport const createFields = (params: Params) => {\n const { fields, plugins } = params;\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const valuePathPlugins = getMappedPlugins<CmsEntryFieldFilterPathPlugin>({\n plugins,\n type: CmsEntryFieldFilterPathPlugin.type,\n property: \"fieldType\"\n });\n\n const collection = createSystemFields().reduce<Record<string, Field>>((fields, field) => {\n const transformPlugin = transformValuePlugins[field.type];\n\n fields[field.fieldId] = {\n ...field,\n parents: [],\n system: true,\n createPath: ({ field }) => {\n return field.settings?.path || field.fieldId;\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n\n return fields;\n }, {});\n\n const addFieldsToCollection = (fields: CmsModelField[], parents: FieldParent[] = []): void => {\n /**\n * Exit early if no fields are sent.\n */\n if (fields.length === 0) {\n return;\n }\n for (const field of fields) {\n const transformPlugin = transformValuePlugins[field.type];\n const valuePathPlugin = valuePathPlugins[field.type];\n /**\n * The required fieldId is a product of all of its parents and its own fieldId.\n */\n const fieldId = [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system: false,\n createPath: params => {\n if (valuePathPlugin) {\n return valuePathPlugin.createPath(params);\n }\n\n return [\"values\"]\n .concat(parents.map(parent => parent.fieldId))\n .concat([params.field.fieldId])\n .join(\".\");\n },\n transform: value => {\n if (!transformPlugin) {\n return value;\n }\n return transformPlugin.transform({\n field,\n value\n });\n }\n };\n const childFields = field.settings?.fields;\n if (!childFields || childFields.length === 0) {\n continue;\n }\n addFieldsToCollection(childFields, [\n ...parents,\n {\n fieldId: field.fieldId,\n multipleValues: field.multipleValues\n }\n ]);\n }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uB,CAA3C,EAA8C;QAC1C;MACH;;MACDD,qBAAqB,CAACS,WAAD,EAAc,CAC/B,GAAGhB,OAD4B,EAE/B;QACID,OAAO,EAAEF,KAAK,CAACE,OADnB;QAEIW,cAAc,EAAEb,KAAK,CAACa;MAF1B,CAF+B,CAAd,CAArB;IAOH;EACJ,CA3DD;;EA6DAH,qBAAqB,CAACrB,MAAD,CAArB;EAEA,OAAOQ,UAAP;AACH,CAtGM"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Field } from "./types";
|
|
2
|
+
interface Result {
|
|
3
|
+
valuePath: string;
|
|
4
|
+
reverse: boolean;
|
|
5
|
+
fieldId: string;
|
|
6
|
+
field: Field;
|
|
7
|
+
}
|
|
8
|
+
interface Params {
|
|
9
|
+
sortBy: string;
|
|
10
|
+
fields: Record<string, Field>;
|
|
11
|
+
}
|
|
12
|
+
export declare const extractSort: (params: Params) => Result;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
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.extractSort = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
const extractSort = params => {
|
|
13
|
+
const {
|
|
14
|
+
sortBy,
|
|
15
|
+
fields
|
|
16
|
+
} = params;
|
|
17
|
+
const result = sortBy.split("_");
|
|
18
|
+
|
|
19
|
+
if (result.length !== 2) {
|
|
20
|
+
throw new _error.default("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
21
|
+
sortBy
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [fieldId, order] = result;
|
|
26
|
+
const field = Object.values(fields).find(field => {
|
|
27
|
+
/**
|
|
28
|
+
* We do not support sorting by nested fields.
|
|
29
|
+
*/
|
|
30
|
+
if (field.parents.length > 0) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return field.fieldId === fieldId;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!field) {
|
|
38
|
+
throw new _error.default("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
39
|
+
fieldId,
|
|
40
|
+
fields
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const valuePath = field.createPath({
|
|
45
|
+
field
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
field,
|
|
49
|
+
fieldId,
|
|
50
|
+
valuePath,
|
|
51
|
+
reverse: order === "DESC"
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.extractSort = extractSort;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["extractSort","params","sortBy","fields","result","split","length","WebinyError","fieldId","order","field","Object","values","find","parents","valuePath","createPath","reverse"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Field } from \"./types\";\n\ninterface Result {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface Params {\n sortBy: string;\n fields: Record<string, Field>;\n}\n\nexport const extractSort = (params: Params): Result => {\n const { sortBy, fields } = params;\n const result = sortBy.split(\"_\");\n if (result.length !== 2) {\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n }\n const [fieldId, order] = result;\n\n const field = Object.values(fields).find(field => {\n /**\n * We do not support sorting by nested fields.\n */\n if (field.parents.length > 0) {\n return false;\n }\n return field.fieldId === fieldId;\n });\n\n if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AAeO,MAAMA,WAAW,GAAIC,MAAD,IAA4B;EACnD,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAqBF,MAA3B;EACA,MAAMG,MAAM,GAAGF,MAAM,CAACG,KAAP,CAAa,GAAb,CAAf;;EACA,IAAID,MAAM,CAACE,MAAP,KAAkB,CAAtB,EAAyB;IACrB,MAAM,IAAIC,cAAJ,CACF,yDADE,EAEF,oBAFE,EAGF;MACIL;IADJ,CAHE,CAAN;EAOH;;EACD,MAAM,CAACM,OAAD,EAAUC,KAAV,IAAmBL,MAAzB;EAEA,MAAMM,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAcT,MAAd,EAAsBU,IAAtB,CAA2BH,KAAK,IAAI;IAC9C;AACR;AACA;IACQ,IAAIA,KAAK,CAACI,OAAN,CAAcR,MAAd,GAAuB,CAA3B,EAA8B;MAC1B,OAAO,KAAP;IACH;;IACD,OAAOI,KAAK,CAACF,OAAN,KAAkBA,OAAzB;EACH,CARa,CAAd;;EAUA,IAAI,CAACE,KAAL,EAAY;IACR,MAAM,IAAIH,cAAJ,CACF,oDADE,EAEF,qBAFE,EAGF;MACIC,OADJ;MAEIL;IAFJ,CAHE,CAAN;EAQH;;EACD,MAAMY,SAAS,GAAGL,KAAK,CAACM,UAAN,CAAiB;IAC/BN;EAD+B,CAAjB,CAAlB;EAGA,OAAO;IACHA,KADG;IAEHF,OAFG;IAGHO,SAHG;IAIHE,OAAO,EAAER,KAAK,KAAK;EAJhB,CAAP;AAMH,CA3CM"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import { Field } from "./types";
|
|
4
|
+
interface Params {
|
|
5
|
+
items: CmsEntry[];
|
|
6
|
+
where: Partial<CmsEntryListWhere>;
|
|
7
|
+
plugins: PluginsContainer;
|
|
8
|
+
fields: Record<string, Field>;
|
|
9
|
+
fullTextSearch?: {
|
|
10
|
+
term?: string;
|
|
11
|
+
fields?: string[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare const filter: (params: Params) => CmsEntry[];
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.filter = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _fullTextSearch = require("./fullTextSearch");
|
|
17
|
+
|
|
18
|
+
var _createExpressions = require("./createExpressions");
|
|
19
|
+
|
|
20
|
+
var _transform = require("./transform");
|
|
21
|
+
|
|
22
|
+
var _getValue = require("./getValue");
|
|
23
|
+
|
|
24
|
+
const executeFilter = params => {
|
|
25
|
+
const {
|
|
26
|
+
value,
|
|
27
|
+
filter
|
|
28
|
+
} = params;
|
|
29
|
+
const matched = filter.plugin.matches({
|
|
30
|
+
value,
|
|
31
|
+
compareValue: filter.compareValue
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (filter.negate) {
|
|
35
|
+
return matched === false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return matched;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const executeExpressions = params => {
|
|
42
|
+
const {
|
|
43
|
+
expressions,
|
|
44
|
+
getCachedValue,
|
|
45
|
+
filters,
|
|
46
|
+
condition
|
|
47
|
+
} = params;
|
|
48
|
+
|
|
49
|
+
if (expressions.length === 0 && filters.length === 0) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Always run filters first as they might trigger an early return.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
for (const filter of filters) {
|
|
58
|
+
const value = getCachedValue(filter);
|
|
59
|
+
const result = executeFilter({
|
|
60
|
+
value,
|
|
61
|
+
filter
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Filters are ALWAYS executed as an AND.
|
|
65
|
+
* So if even one is false, everything false.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
if (!result) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Then we move onto expressions, which are basically nested upon nested filters with different conditions.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
for (const expression of expressions) {
|
|
78
|
+
const result = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
|
|
79
|
+
getCachedValue
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
if (result && condition === "OR") {
|
|
83
|
+
return true;
|
|
84
|
+
} else if (!result && condition == "AND") {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.
|
|
90
|
+
*
|
|
91
|
+
* Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
return condition === "OR" ? false : true;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const filter = params => {
|
|
99
|
+
const {
|
|
100
|
+
items: records,
|
|
101
|
+
where,
|
|
102
|
+
plugins,
|
|
103
|
+
fields,
|
|
104
|
+
fullTextSearch
|
|
105
|
+
} = params;
|
|
106
|
+
const keys = Object.keys(where);
|
|
107
|
+
|
|
108
|
+
if (keys.length === 0 && !fullTextSearch) {
|
|
109
|
+
return records;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const expression = (0, _createExpressions.createExpressions)({
|
|
113
|
+
plugins,
|
|
114
|
+
where,
|
|
115
|
+
fields
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* No point in going further if there are no expressions to be applied and no full text search to be executed.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
if (expression.filters.length === 0 && expression.expressions.length === 0 && !(fullTextSearch !== null && fullTextSearch !== void 0 && fullTextSearch.term)) {
|
|
122
|
+
return records;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* We need the contains plugin to run the full text search.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
const fullTextSearchPlugin = plugins.byType(_ValueFilterPlugin.ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
|
|
130
|
+
|
|
131
|
+
if (!fullTextSearchPlugin) {
|
|
132
|
+
throw new _error.default(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const search = (0, _fullTextSearch.createFullTextSearch)({
|
|
136
|
+
term: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.term,
|
|
137
|
+
targetFields: fullTextSearch === null || fullTextSearch === void 0 ? void 0 : fullTextSearch.fields,
|
|
138
|
+
fields,
|
|
139
|
+
plugin: fullTextSearchPlugin
|
|
140
|
+
});
|
|
141
|
+
return records.filter(record => {
|
|
142
|
+
const cachedValues = {};
|
|
143
|
+
|
|
144
|
+
const getCachedValue = filter => {
|
|
145
|
+
const {
|
|
146
|
+
path
|
|
147
|
+
} = filter;
|
|
148
|
+
|
|
149
|
+
if (cachedValues[path] !== undefined) {
|
|
150
|
+
return cachedValues[path];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const plainValue = (0, _getValue.getValue)(record, path);
|
|
154
|
+
const rawValue = (0, _transform.transformValue)({
|
|
155
|
+
value: plainValue,
|
|
156
|
+
transform: filter.transformValue
|
|
157
|
+
});
|
|
158
|
+
cachedValues[path] = rawValue;
|
|
159
|
+
return rawValue;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const exprResult = executeExpressions((0, _objectSpread2.default)((0, _objectSpread2.default)({}, expression), {}, {
|
|
163
|
+
getCachedValue
|
|
164
|
+
}));
|
|
165
|
+
/**
|
|
166
|
+
* If expression result is false we do not need to continue further.
|
|
167
|
+
* Also, if there is no full text search defined, just return the expression result.
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
if (!exprResult || !search) {
|
|
171
|
+
return exprResult;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return search(record);
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
exports.filter = filter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["executeFilter","params","value","filter","matched","plugin","matches","compareValue","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","createExpressions","term","fullTextSearchPlugin","byType","ValueFilterPlugin","type","find","getOperation","WebinyError","search","createFullTextSearch","targetFields","record","cachedValues","path","undefined","plainValue","getValue","rawValue","transformValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import { CmsEntry, CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { Field } from \"./types\";\nimport { createFullTextSearch } from \"./fullTextSearch\";\nimport { createExpressions, Expression, ExpressionCondition, Filter } from \"./createExpressions\";\nimport { transformValue } from \"./transform\";\nimport { getValue } from \"~/operations/entry/filtering/getValue\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n const matched = filter.plugin.matches({\n value,\n compareValue: filter.compareValue\n });\n if (filter.negate) {\n return matched === false;\n }\n return matched;\n};\n\ninterface ExecuteExpressionsParams {\n getCachedValue: (filter: Filter) => Promise<any>;\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nconst executeExpressions = (params: ExecuteExpressionsParams): boolean => {\n const { expressions, getCachedValue, filters, condition } = params;\n if (expressions.length === 0 && filters.length === 0) {\n return true;\n }\n /**\n * Always run filters first as they might trigger an early return.\n */\n for (const filter of filters) {\n const value = getCachedValue(filter);\n\n const result = executeFilter({\n value,\n filter\n });\n /**\n * Filters are ALWAYS executed as an AND.\n * So if even one is false, everything false.\n */\n if (!result) {\n return false;\n }\n }\n /**\n * Then we move onto expressions, which are basically nested upon nested filters with different conditions.\n */\n for (const expression of expressions) {\n const result = executeExpressions({\n ...expression,\n getCachedValue\n });\n if (result && condition === \"OR\") {\n return true;\n } else if (!result && condition == \"AND\") {\n return false;\n }\n }\n /**\n * If condition is an OR, we can fail the expressions check because the code would return a lot earlier than this line.\n *\n * Also, if condition is not an OR, we can say that the expressions check is ok, because it would fail a lot earlier than this line.\n */\n return condition === \"OR\" ? false : true;\n};\n\ninterface Params {\n items: CmsEntry[];\n where: Partial<CmsEntryListWhere>;\n plugins: PluginsContainer;\n fields: Record<string, Field>;\n fullTextSearch?: {\n term?: string;\n fields?: string[];\n };\n}\n\nexport const filter = (params: Params): CmsEntry[] => {\n const { items: records, where, plugins, fields, fullTextSearch } = params;\n\n const keys = Object.keys(where);\n if (keys.length === 0 && !fullTextSearch) {\n return records;\n }\n const expression = createExpressions({\n plugins,\n where,\n fields\n });\n\n /**\n * No point in going further if there are no expressions to be applied and no full text search to be executed.\n */\n if (\n expression.filters.length === 0 &&\n expression.expressions.length === 0 &&\n !fullTextSearch?.term\n ) {\n return records;\n }\n /**\n * We need the contains plugin to run the full text search.\n */\n const fullTextSearchPlugin = plugins\n .byType<ValueFilterPlugin>(ValueFilterPlugin.type)\n .find(plugin => plugin.getOperation() === \"contains\");\n if (!fullTextSearchPlugin) {\n throw new WebinyError(\n `Missing \"contains\" plugin to run the full-text search.`,\n \"MISSING_PLUGIN\"\n );\n }\n\n const search = createFullTextSearch({\n term: fullTextSearch?.term,\n targetFields: fullTextSearch?.fields,\n fields,\n plugin: fullTextSearchPlugin\n });\n\n return records.filter(record => {\n const cachedValues: Record<string, any> = {};\n\n const getCachedValue = (filter: Filter) => {\n const { path } = filter;\n if (cachedValues[path] !== undefined) {\n return cachedValues[path];\n }\n const plainValue = getValue(record, path);\n\n const rawValue = transformValue({\n value: plainValue,\n transform: filter.transformValue\n });\n\n cachedValues[path] = rawValue;\n return rawValue;\n };\n\n const exprResult = executeExpressions({ ...expression, getCachedValue });\n /**\n * If expression result is false we do not need to continue further.\n * Also, if there is no full text search defined, just return the expression result.\n */\n if (!exprResult || !search) {\n return exprResult;\n }\n\n return search(record);\n });\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AAOA,MAAMA,aAAa,GAAIC,MAAD,IAAiC;EACnD,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAoBF,MAA1B;EAEA,MAAMG,OAAO,GAAGD,MAAM,CAACE,MAAP,CAAcC,OAAd,CAAsB;IAClCJ,KADkC;IAElCK,YAAY,EAAEJ,MAAM,CAACI;EAFa,CAAtB,CAAhB;;EAIA,IAAIJ,MAAM,CAACK,MAAX,EAAmB;IACf,OAAOJ,OAAO,KAAK,KAAnB;EACH;;EACD,OAAOA,OAAP;AACH,CAXD;;AAoBA,MAAMK,kBAAkB,GAAIR,MAAD,IAA+C;EACtE,MAAM;IAAES,WAAF;IAAeC,cAAf;IAA+BC,OAA/B;IAAwCC;EAAxC,IAAsDZ,MAA5D;;EACA,IAA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CAAZ,GAAqBI,QAArB;MACA,OAAOA,QAAP;IACH,CAdD;;IAgBA,MAAMG,UAAU,GAAGrC,kBAAkB,6DAAMO,UAAN;MAAkBL;IAAlB,GAArC;IACA;AACR;AACA;AACA;;IACQ,IAAI,CAACmC,UAAD,IAAe,CAACZ,MAApB,EAA4B;MACxB,OAAOY,UAAP;IACH;;IAED,OAAOZ,MAAM,CAACG,MAAD,CAAb;EACH,CA7BM,CAAP;AA8BH,CAzEM"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
2
|
+
import { CmsEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
+
import { Field } from "./types";
|
|
4
|
+
interface Params {
|
|
5
|
+
term?: string;
|
|
6
|
+
targetFields?: string[];
|
|
7
|
+
fields: Record<string, Field>;
|
|
8
|
+
plugin: ValueFilterPlugin;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
12
|
+
*/
|
|
13
|
+
export declare const createFullTextSearch: (params: Params) => ((item: CmsEntry) => boolean) | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createFullTextSearch = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
var _getValue = require("./getValue");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
16
|
+
*/
|
|
17
|
+
const createFullTextSearch = params => {
|
|
18
|
+
const {
|
|
19
|
+
term,
|
|
20
|
+
targetFields,
|
|
21
|
+
fields: fieldDefinitions,
|
|
22
|
+
plugin
|
|
23
|
+
} = params;
|
|
24
|
+
|
|
25
|
+
if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return item => {
|
|
30
|
+
for (const target of targetFields) {
|
|
31
|
+
/**
|
|
32
|
+
* As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.
|
|
33
|
+
*/
|
|
34
|
+
const field = fieldDefinitions[target];
|
|
35
|
+
|
|
36
|
+
if (!field) {
|
|
37
|
+
throw new _error.default(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
|
|
38
|
+
target
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const value = (0, _getValue.getValue)(item.values, target);
|
|
43
|
+
|
|
44
|
+
if (!value) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (plugin.matches({
|
|
49
|
+
value,
|
|
50
|
+
compareValue: term
|
|
51
|
+
}) === true) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.createFullTextSearch = createFullTextSearch;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","plugin","trim","length","item","target","field","WebinyError","value","getValue","values","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport { CmsEntry } from \"@webiny/api-headless-cms/types\";\nimport { Field } from \"./types\";\nimport { getValue } from \"./getValue\";\n\ninterface Params {\n term?: string;\n targetFields?: string[];\n fields: Record<string, Field>;\n plugin: ValueFilterPlugin;\n}\n\n/**\n * Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.\n */\nexport const createFullTextSearch = (params: Params) => {\n const { term, targetFields, fields: fieldDefinitions, plugin } = params;\n if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {\n return null;\n }\n return (item: CmsEntry) => {\n for (const target of targetFields) {\n /**\n * As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.\n */\n const field = fieldDefinitions[target];\n\n if (!field) {\n throw new WebinyError(`Unknown field \"${target}\" in the model.`, \"UNKNOWN_FIELD\", {\n target\n });\n }\n const value = getValue(item.values, target);\n if (!value) {\n continue;\n }\n if (plugin.matches({ value, compareValue: term }) === true) {\n return true;\n }\n }\n return false;\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AAIA;;AASA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAIC,MAAD,IAAoB;EACpD,MAAM;IAAEC,IAAF;IAAQC,YAAR;IAAsBC,MAAM,EAAEC,gBAA9B;IAAgDC;EAAhD,IAA2DL,MAAjE;;EACA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACK,IAAL,GAAYC,MAAZ,KAAuB,CAAhC,IAAqC,CAACL,YAAtC,IAAsDA,YAAY,CAACK,MAAb,KAAwB,CAAlF,EAAqF;IACjF,OAAO,IAAP;EACH;;EACD,OAAQC,IAAD,IAAoB;IACvB,KAAK,MAAMC,MAAX,IAAqBP,YAArB,EAAmC;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAD,CAA9B;;MAEA,IAAI,CAACC,KAAL,EAAY;QACR,MAAM,IAAIC,cAAJ,CAAiB,kBAAiBF,MAAO,iBAAzC,EAA2D,eAA3D,EAA4E;UAC9EA;QAD8E,CAA5E,CAAN;MAGH;;MACD,MAAMG,KAAK,GAAG,IAAAC,kBAAA,EAASL,IAAI,CAACM,MAAd,EAAsBL,MAAtB,CAAd;;MACA,IAAI,CAACG,KAAL,EAAY;QACR;MACH;;MACD,IAAIP,MAAM,CAACU,OAAP,CAAe;QAAEH,KAAF;QAASI,YAAY,EAAEf;MAAvB,CAAf,MAAkD,IAAtD,EAA4D;QACxD,OAAO,IAAP;MACH;IACJ;;IACD,OAAO,KAAP;EACH,CArBD;AAsBH,CA3BM"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getValue = void 0;
|
|
7
|
+
|
|
8
|
+
const addArrayResult = (target, result) => {
|
|
9
|
+
for (const r of result) {
|
|
10
|
+
if (target.some(t => r === t)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
target.push(r);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A recursive function which goes through given input paths and returns the value in it.
|
|
19
|
+
* In case a path is an array, it goes through the array of those values to get values further down the path line.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const find = (target, input) => {
|
|
24
|
+
const paths = [...input];
|
|
25
|
+
const path = paths.shift();
|
|
26
|
+
|
|
27
|
+
if (!path) {
|
|
28
|
+
return undefined;
|
|
29
|
+
} else if (target[path] === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const value = target[path];
|
|
34
|
+
|
|
35
|
+
if (paths.length === 0) {
|
|
36
|
+
return value;
|
|
37
|
+
} else if (Array.isArray(value)) {
|
|
38
|
+
if (value.length === 0) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return value.reduce((collection, v) => {
|
|
43
|
+
const result = find(v, paths);
|
|
44
|
+
|
|
45
|
+
if (result === undefined) {
|
|
46
|
+
return collection;
|
|
47
|
+
} else if (Array.isArray(result)) {
|
|
48
|
+
addArrayResult(collection, result);
|
|
49
|
+
return collection;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
collection.push(result);
|
|
53
|
+
return collection;
|
|
54
|
+
}, []);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return find(value, paths);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A wrapper function for the find function.
|
|
61
|
+
* Basically it transforms input paths to an array (and runs various checks).
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const getValue = (target, input) => {
|
|
66
|
+
const paths = Array.isArray(input) ? input : input.split(".");
|
|
67
|
+
|
|
68
|
+
if (paths.length === 0) {
|
|
69
|
+
throw new Error(`Path is empty!`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const filtered = paths.filter(Boolean);
|
|
73
|
+
|
|
74
|
+
if (paths.length !== filtered.length) {
|
|
75
|
+
throw new Error(`Input path is different than the filtered empty path string. (${paths.join(".")} to ${filtered.join(".")})`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return find(target, paths);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
exports.getValue = getValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any>, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n } else if (target[path] === undefined) {\n return undefined;\n }\n const value = target[path];\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":";;;;;;;AAAA,MAAMA,cAAc,GAAG,CAACC,MAAD,EAAgBC,MAAhB,KAAwC;EAC3D,KAAK,MAAMC,CAAX,IAAgBD,MAAhB,EAAwB;IACpB,IAAID,MAAM,CAACG,IAAP,CAAYC,CAAC,IAAIF,CAAC,KAAKE,CAAvB,CAAJ,EAA+B;MAC3B;IACH;;IACDJ,MAAM,CAACK,IAAP,CAAYH,CAAZ;EACH;AACJ,CAPD;AAQA;AACA;AACA;AACA;;;AACA,MAAMI,IAAI,GAAG,CAACN,MAAD,EAA8BO,KAA9B,KAAqE;EAC9E,MAAMC,KAAK,GAAG,CAAC,GAAGD,KAAJ,CAAd;EACA,MAAME,IAAI,GAAGD,KAAK,CAACE,KAAN,EAAb;;EAEA,IAAI,CAACD,IAAL,EAAW;IACP,OAAOE,SAAP;EACH,CAFD,MAEO,IAAIX,MAAM,CAACS,IAAD,CAAN,KAAiBE,SAArB,EAAgC;IACnC,OAAOA,SAAP;EACH;;EACD,MAAMC,KAAK,GAAGZ,MAAM,CAACS,IAAD,CAApB;;EACA,IAAID,KAAK,CAACK,MAAN,KAAiB,CAArB,EAAwB;IACpB,OAAOD,KAAP;EACH,CAFD,MAEO,IAAIE,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAJ,EAA0B;IAC7B,IAAIA,KAAK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+1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "filter", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _filter.filter;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "sort", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _sort.sort;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _filter = require("./filter");
|
|
20
|
+
|
|
21
|
+
var _sort = require("./sort");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter\";\nexport { sort } from \"./sort\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin, PluginsContainer } from "@webiny/plugins/types";
|
|
2
|
+
interface Params {
|
|
3
|
+
plugins: PluginsContainer;
|
|
4
|
+
type: string;
|
|
5
|
+
property: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const getMappedPlugins: <T extends Plugin<Record<string, any>>>(params: Params) => Record<string, T>;
|
|
8
|
+
export {};
|