@webiny/api-headless-cms-ddb 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.f6dc066313
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -20
- package/definitions/entry.d.ts +4 -6
- package/definitions/entry.js +5 -180
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -6
- package/definitions/group.js +5 -58
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -6
- package/definitions/model.js +5 -102
- package/definitions/model.js.map +1 -1
- package/definitions/table.d.ts +3 -5
- package/definitions/table.js +6 -28
- package/definitions/table.js.map +1 -1
- package/definitions/types.d.ts +60 -0
- package/definitions/types.js +3 -0
- package/definitions/types.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +6 -13
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/path/locationFolderId.d.ts +1 -1
- package/dynamoDb/path/locationFolderId.js +5 -14
- package/dynamoDb/path/locationFolderId.js.map +1 -1
- package/dynamoDb/path/plainObject.d.ts +1 -1
- package/dynamoDb/path/plainObject.js +5 -14
- package/dynamoDb/path/plainObject.js.map +1 -1
- package/dynamoDb/storage/longText.js +10 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +10 -19
- package/dynamoDb/storage/richText.js.map +1 -1
- package/dynamoDb/transformValue/datetime.d.ts +1 -1
- package/dynamoDb/transformValue/datetime.js +5 -12
- package/dynamoDb/transformValue/datetime.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +38 -73
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +0 -2
- package/operations/entry/dataLoader/DataLoaderCache.js +2 -9
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +1 -7
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +4 -10
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
- package/operations/entry/dataLoader/getAllEntryRevisions.js +11 -24
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +22 -32
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +22 -32
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +24 -34
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.d.ts +3 -3
- package/operations/entry/dataLoader/index.js +10 -31
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +3 -4
- package/operations/entry/dataLoader/types.js +1 -5
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +11 -12
- package/operations/entry/dataLoaders.js +15 -25
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +3 -3
- package/operations/entry/filtering/createExpressions.js +27 -30
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +2 -2
- package/operations/entry/filtering/createFields.js +20 -22
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +5 -5
- package/operations/entry/filtering/extractSort.js +38 -23
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +5 -5
- package/operations/entry/filtering/filter.js +13 -21
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +3 -3
- package/operations/entry/filtering/fullTextSearch.js +5 -13
- package/operations/entry/filtering/fullTextSearch.js.map +1 -1
- package/operations/entry/filtering/getValue.js +1 -8
- package/operations/entry/filtering/getValue.js.map +1 -1
- package/operations/entry/filtering/index.d.ts +2 -2
- package/operations/entry/filtering/index.js +2 -19
- package/operations/entry/filtering/index.js.map +1 -1
- package/operations/entry/filtering/mapPlugins.d.ts +1 -1
- package/operations/entry/filtering/mapPlugins.js +3 -11
- package/operations/entry/filtering/mapPlugins.js.map +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/defaultFilterCreate.js +6 -14
- package/operations/entry/filtering/plugins/defaultFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/filtering/plugins/index.js +6 -13
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.js +13 -19
- package/operations/entry/filtering/plugins/objectFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/refFilterCreate.d.ts +2 -2
- package/operations/entry/filtering/plugins/refFilterCreate.js +12 -18
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +7 -15
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -1
- package/operations/entry/filtering/sort.d.ts +5 -5
- package/operations/entry/filtering/sort.js +15 -19
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -4
- package/operations/entry/filtering/systemFields.js +70 -29
- package/operations/entry/filtering/systemFields.js.map +1 -1
- package/operations/entry/filtering/transform.d.ts +1 -1
- package/operations/entry/filtering/transform.js +1 -8
- package/operations/entry/filtering/transform.js.map +1 -1
- package/operations/entry/filtering/types.d.ts +3 -3
- package/operations/entry/filtering/types.js +1 -5
- package/operations/entry/filtering/types.js.map +1 -1
- package/operations/entry/filtering/values.d.ts +1 -1
- package/operations/entry/filtering/values.js +4 -12
- package/operations/entry/filtering/values.js.map +1 -1
- package/operations/entry/filtering/where.js +1 -8
- package/operations/entry/filtering/where.js.map +1 -1
- package/operations/entry/index.d.ts +2 -3
- package/operations/entry/index.js +267 -377
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +40 -2
- package/operations/entry/keys.js +53 -30
- package/operations/entry/keys.js.map +1 -1
- package/operations/group/index.d.ts +3 -3
- package/operations/group/index.js +35 -64
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +36 -58
- package/operations/model/index.js.map +1 -1
- package/package.json +16 -18
- package/plugins/CmsEntryFieldFilterPathPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldFilterPathPlugin.js +4 -12
- package/plugins/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldFilterPlugin.d.ts +3 -3
- package/plugins/CmsEntryFieldFilterPlugin.js +2 -8
- package/plugins/CmsEntryFieldFilterPlugin.js.map +1 -1
- package/plugins/CmsEntryFieldSortingPlugin.d.ts +2 -2
- package/plugins/CmsEntryFieldSortingPlugin.js +3 -11
- package/plugins/CmsEntryFieldSortingPlugin.js.map +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.d.ts +1 -1
- package/plugins/CmsFieldFilterValueTransformPlugin.js +2 -9
- package/plugins/CmsFieldFilterValueTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +4 -4
- package/plugins/index.js +4 -49
- package/plugins/index.js.map +1 -1
- package/types.d.ts +17 -19
- package/types.js +1 -8
- package/types.js.map +1 -1
- package/definitions/system.d.ts +0 -10
- package/definitions/system.js +0 -42
- package/definitions/system.js.map +0 -1
- package/operations/system/index.d.ts +0 -7
- package/operations/system/index.js +0 -94
- package/operations/system/index.js.map +0 -1
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.createFields = void 0;
|
|
7
|
-
var _systemFields = require("./systemFields");
|
|
8
|
-
var _plugins = require("../../../plugins");
|
|
9
|
-
var _mapPlugins = require("./mapPlugins");
|
|
1
|
+
import { createSystemFields } from "./systemFields.js";
|
|
2
|
+
import { CmsEntryFieldFilterPathPlugin } from "../../../plugins/index.js";
|
|
3
|
+
import { getMappedPlugins } from "./mapPlugins.js";
|
|
4
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
10
5
|
const createFieldCollection = params => {
|
|
11
6
|
const {
|
|
12
7
|
fields,
|
|
@@ -16,15 +11,16 @@ const createFieldCollection = params => {
|
|
|
16
11
|
system
|
|
17
12
|
} = params;
|
|
18
13
|
return fields.reduce((collection, field) => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
14
|
+
const fieldType = getBaseFieldType(field);
|
|
15
|
+
const transformPlugin = transformValuePlugins[fieldType];
|
|
16
|
+
const valuePathPlugin = valuePathPlugins[fieldType];
|
|
17
|
+
|
|
22
18
|
/**
|
|
23
19
|
* The required fieldId is a product of all of its parents and its own fieldId.
|
|
24
20
|
*/
|
|
25
21
|
const fieldId = [...parents, {
|
|
26
22
|
fieldId: field.fieldId,
|
|
27
|
-
|
|
23
|
+
list: field.list
|
|
28
24
|
}].map(f => f.fieldId).join(".");
|
|
29
25
|
collection[fieldId] = {
|
|
30
26
|
...field,
|
|
@@ -34,7 +30,7 @@ const createFieldCollection = params => {
|
|
|
34
30
|
if (valuePathPlugin && valuePathPlugin.canUse(field, parents.map(p => p.fieldId))) {
|
|
35
31
|
return valuePathPlugin.createPath(params);
|
|
36
32
|
}
|
|
37
|
-
return
|
|
33
|
+
return parents.map(parent => parent.fieldId).concat([params.field.fieldId]).join(".");
|
|
38
34
|
},
|
|
39
35
|
transform: value => {
|
|
40
36
|
if (!transformPlugin) {
|
|
@@ -54,7 +50,7 @@ const createFieldCollection = params => {
|
|
|
54
50
|
fields: childFields,
|
|
55
51
|
parents: [...parents, {
|
|
56
52
|
fieldId: field.fieldId,
|
|
57
|
-
|
|
53
|
+
list: field.list
|
|
58
54
|
}],
|
|
59
55
|
transformValuePlugins,
|
|
60
56
|
valuePathPlugins,
|
|
@@ -69,23 +65,23 @@ const createFieldCollection = params => {
|
|
|
69
65
|
*
|
|
70
66
|
* In case of nested fields, fieldId is all the parent fieldIds + current one, joined by the dot (.).
|
|
71
67
|
*/
|
|
72
|
-
const createFields = params => {
|
|
68
|
+
export const createFields = params => {
|
|
73
69
|
const {
|
|
74
70
|
fields,
|
|
75
71
|
plugins
|
|
76
72
|
} = params;
|
|
77
|
-
const transformValuePlugins =
|
|
73
|
+
const transformValuePlugins = getMappedPlugins({
|
|
78
74
|
plugins,
|
|
79
75
|
type: "cms-field-filter-value-transform",
|
|
80
76
|
property: "fieldType"
|
|
81
77
|
});
|
|
82
|
-
const valuePathPlugins =
|
|
78
|
+
const valuePathPlugins = getMappedPlugins({
|
|
83
79
|
plugins,
|
|
84
|
-
type:
|
|
80
|
+
type: CmsEntryFieldFilterPathPlugin.type,
|
|
85
81
|
property: "fieldType"
|
|
86
82
|
});
|
|
87
83
|
const collection = createFieldCollection({
|
|
88
|
-
fields:
|
|
84
|
+
fields: createSystemFields(),
|
|
89
85
|
transformValuePlugins,
|
|
90
86
|
valuePathPlugins,
|
|
91
87
|
parents: [],
|
|
@@ -95,7 +91,10 @@ const createFields = params => {
|
|
|
95
91
|
fields,
|
|
96
92
|
transformValuePlugins,
|
|
97
93
|
valuePathPlugins,
|
|
98
|
-
parents: [
|
|
94
|
+
parents: [{
|
|
95
|
+
fieldId: "values",
|
|
96
|
+
list: false
|
|
97
|
+
}],
|
|
99
98
|
system: false
|
|
100
99
|
});
|
|
101
100
|
return {
|
|
@@ -103,6 +102,5 @@ const createFields = params => {
|
|
|
103
102
|
...result
|
|
104
103
|
};
|
|
105
104
|
};
|
|
106
|
-
exports.createFields = createFields;
|
|
107
105
|
|
|
108
106
|
//# sourceMappingURL=createFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createSystemFields","CmsEntryFieldFilterPathPlugin","getMappedPlugins","getBaseFieldType","createFieldCollection","params","fields","parents","transformValuePlugins","valuePathPlugins","system","reduce","collection","field","fieldType","transformPlugin","valuePathPlugin","fieldId","list","map","f","join","createPath","canUse","p","parent","concat","transform","value","childFields","settings","length","result","Object","assign","createFields","plugins","type","property"],"sources":["createFields.ts"],"sourcesContent":["import type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemFields } from \"./systemFields.js\";\nimport type { Field, FieldParent } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport { CmsEntryFieldFilterPathPlugin } from \"~/plugins/index.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\ninterface Params {\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\n\ninterface FieldCollection {\n [key: string]: Field;\n}\n\ninterface AddFieldsToCollectionParams {\n fields: CmsModelField[];\n parents: FieldParent[];\n transformValuePlugins: Record<string, CmsFieldFilterValueTransformPlugin>;\n valuePathPlugins: Record<string, CmsEntryFieldFilterPathPlugin>;\n system: boolean;\n}\n\nconst createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {\n const { fields, parents, transformValuePlugins, valuePathPlugins, system } = params;\n return fields.reduce<FieldCollection>((collection, field) => {\n const fieldType = getBaseFieldType(field);\n const transformPlugin = transformValuePlugins[fieldType];\n const valuePathPlugin = valuePathPlugins[fieldType];\n\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 list: field.list\n }\n ]\n .map(f => f.fieldId)\n .join(\".\");\n\n collection[fieldId] = {\n ...field,\n parents,\n system,\n createPath: params => {\n if (\n valuePathPlugin &&\n valuePathPlugin.canUse(\n field,\n parents.map(p => p.fieldId)\n )\n ) {\n return valuePathPlugin.createPath(params);\n }\n\n return parents\n .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?.length) {\n return collection;\n }\n\n const result = createFieldCollection({\n fields: childFields,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n list: field.list\n }\n ],\n transformValuePlugins,\n valuePathPlugins,\n system\n });\n Object.assign(collection, result);\n return collection;\n }, {});\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 = createFieldCollection({\n fields: createSystemFields(),\n transformValuePlugins,\n valuePathPlugins,\n parents: [],\n system: true\n });\n\n const result = createFieldCollection({\n fields,\n transformValuePlugins,\n valuePathPlugins,\n parents: [\n {\n fieldId: \"values\",\n list: false\n }\n ],\n system: false\n });\n\n return {\n ...collection,\n ...result\n };\n};\n"],"mappings":"AACA,SAASA,kBAAkB;AAI3B,SAASC,6BAA6B;AACtC,SAASC,gBAAgB;AACzB,SAASC,gBAAgB,QAAQ,oDAAoD;AAmBrF,MAAMC,qBAAqB,GAAIC,MAAmC,IAAsB;EACpF,M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;MACjBC,IAAI,EAAE;IACV,CAAC,CACJ;IACDR,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,OAAO;IACH,GAAGE,UAAU;IACb,GAAGoB;EACP,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { Field } from "./types";
|
|
1
|
+
import type { Field } from "./types.js";
|
|
2
2
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import type { CmsModel } from "@webiny/api-headless-cms/types";
|
|
4
|
-
interface
|
|
3
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
interface IResponse {
|
|
5
5
|
valuePath: string;
|
|
6
6
|
reverse: boolean;
|
|
7
7
|
fieldId: string;
|
|
8
8
|
field: Field;
|
|
9
9
|
}
|
|
10
|
-
interface
|
|
10
|
+
interface IParams {
|
|
11
11
|
model: CmsModel;
|
|
12
12
|
sortBy: string;
|
|
13
13
|
fields: Record<string, Field>;
|
|
14
14
|
plugins: PluginsContainer;
|
|
15
15
|
}
|
|
16
|
-
export declare const extractSort: (params:
|
|
16
|
+
export declare const extractSort: (params: IParams) => IResponse;
|
|
17
17
|
export {};
|
|
@@ -1,36 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { CmsEntryFieldSortingPlugin } from "../../../plugins/index.js";
|
|
3
|
+
const extractSortInfo = sortBy => {
|
|
4
|
+
const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
|
|
5
|
+
if (rootSorting) {
|
|
6
|
+
return {
|
|
7
|
+
fieldId: rootSorting[1],
|
|
8
|
+
isValues: false,
|
|
9
|
+
order: rootSorting[2]
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
|
|
13
|
+
if (valuesSorting) {
|
|
14
|
+
return {
|
|
15
|
+
fieldId: valuesSorting[1],
|
|
16
|
+
isValues: true,
|
|
17
|
+
order: valuesSorting[2]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
throw new WebinyError("Problem in determining the sorting for the entry items.", "SORT_EXTRACT_ERROR", {
|
|
21
|
+
sortBy
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export const extractSort = params => {
|
|
11
25
|
const {
|
|
12
26
|
model,
|
|
13
27
|
sortBy,
|
|
14
28
|
fields,
|
|
15
29
|
plugins
|
|
16
30
|
} = params;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const [fieldId, order] = result;
|
|
24
|
-
const field = Object.values(fields).find(field => {
|
|
31
|
+
const {
|
|
32
|
+
fieldId,
|
|
33
|
+
isValues: isValuesSorting,
|
|
34
|
+
order
|
|
35
|
+
} = extractSortInfo(sortBy);
|
|
36
|
+
const field = Object.values(fields).find(f => {
|
|
25
37
|
/**
|
|
26
38
|
* We do not support sorting by nested fields.
|
|
27
39
|
*/
|
|
28
|
-
|
|
40
|
+
const isValues = f.parents[0]?.fieldId === "values";
|
|
41
|
+
if (isValues && isValuesSorting) {
|
|
42
|
+
return f.fieldId === fieldId;
|
|
43
|
+
}
|
|
44
|
+
if (f.parents.length > 0) {
|
|
29
45
|
return false;
|
|
30
46
|
}
|
|
31
|
-
return
|
|
47
|
+
return f.fieldId === fieldId;
|
|
32
48
|
});
|
|
33
|
-
const plugin = plugins.byType(
|
|
49
|
+
const plugin = plugins.byType(CmsEntryFieldSortingPlugin.type).reverse().find(plugin => {
|
|
34
50
|
return plugin.canUse({
|
|
35
51
|
model,
|
|
36
52
|
field,
|
|
@@ -49,7 +65,7 @@ const extractSort = params => {
|
|
|
49
65
|
fields
|
|
50
66
|
});
|
|
51
67
|
} else if (!field) {
|
|
52
|
-
throw new
|
|
68
|
+
throw new WebinyError("Sorting field does not exist in the content model.", "SORTING_FIELD_ERROR", {
|
|
53
69
|
fieldId,
|
|
54
70
|
fields
|
|
55
71
|
});
|
|
@@ -64,6 +80,5 @@ const extractSort = params => {
|
|
|
64
80
|
reverse: order === "DESC"
|
|
65
81
|
};
|
|
66
82
|
};
|
|
67
|
-
exports.extractSort = extractSort;
|
|
68
83
|
|
|
69
84
|
//# sourceMappingURL=extractSort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","CmsEntryFieldSortingPlugin","extractSortInfo","sortBy","rootSorting","match","fieldId","isValues","order","valuesSorting","extractSort","params","model","fields","plugins","isValuesSorting","field","Object","values","find","f","parents","length","plugin","byType","type","reverse","canUse","createSort","valuePath","createPath"],"sources":["extractSort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { Field } from \"./types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryFieldSortingPlugin } from \"~/plugins/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst extractSortInfo = (sortBy: string) => {\n const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);\n if (rootSorting) {\n return {\n fieldId: rootSorting[1],\n isValues: false,\n order: rootSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);\n if (valuesSorting) {\n return {\n fieldId: valuesSorting[1],\n isValues: true,\n order: valuesSorting[2] as \"ASC\" | \"DESC\"\n };\n }\n throw new WebinyError(\n \"Problem in determining the sorting for the entry items.\",\n \"SORT_EXTRACT_ERROR\",\n {\n sortBy\n }\n );\n};\n\ninterface IResponse {\n valuePath: string;\n reverse: boolean;\n fieldId: string;\n field: Field;\n}\n\ninterface IParams {\n model: CmsModel;\n sortBy: string;\n fields: Record<string, Field>;\n plugins: PluginsContainer;\n}\n\nexport const extractSort = (params: IParams): IResponse => {\n const { model, sortBy, fields, plugins } = params;\n const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);\n\n const field = Object.values(fields).find(f => {\n /**\n * We do not support sorting by nested fields.\n */\n const isValues = f.parents[0]?.fieldId === \"values\";\n if (isValues && isValuesSorting) {\n return f.fieldId === fieldId;\n }\n if (f.parents.length > 0) {\n return false;\n }\n return f.fieldId === fieldId;\n });\n\n const plugin = plugins\n .byType<CmsEntryFieldSortingPlugin>(CmsEntryFieldSortingPlugin.type)\n .reverse()\n .find(plugin => {\n return plugin.canUse({\n model,\n field,\n fieldId,\n order,\n sortBy\n });\n });\n\n if (plugin) {\n return plugin.createSort({\n model,\n fieldId,\n order,\n sortBy,\n field,\n fields\n });\n } else if (!field) {\n throw new WebinyError(\n \"Sorting field does not exist in the content model.\",\n \"SORTING_FIELD_ERROR\",\n {\n fieldId,\n fields\n }\n );\n }\n const valuePath = field.createPath({\n field\n });\n return {\n field,\n fieldId,\n valuePath,\n reverse: order === \"DESC\"\n };\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAGvC,SAASC,0BAA0B;AAGnC,MAAMC,eAAe,GAAIC,MAAc,IAAK;EACxC,MAAMC,WAAW,GAAGD,MAAM,CAACE,KAAK,CAAC,0BAA0B,CAAC;EAC5D,IAAID,WAAW,EAAE;IACb,OAAO;MACHE,OAAO,EAAEF,WAAW,CAAC,CAAC,CAAC;MACvBG,QAAQ,EAAE,KAAK;MACfC,KAAK,EAAEJ,WAAW,CAAC,CAAC;IACxB,CAAC;EACL;EACA,MAAMK,aAAa,GAAGN,MAAM,CAACE,KAAK,CAAC,oCAAoC,CAAC;EACxE,IAAII,aAAa,EAAE;IACf,OAAO;MACHH,OAAO,EAAEG,aAAa,CAAC,CAAC,CAAC;MACzBF,QAAQ,EAAE,IAAI;MACdC,KAAK,EAAEC,aAAa,CAAC,CAAC;IAC1B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EAAE;IACf,MAAM,IAAIhB,WAAW,CACjB,oDAAoD,EACpD,qBAAqB,EACrB;MACIM,OAAO;MACPO;IACJ,CACJ,CAAC;EACL;EACA,MAAMgB,SAAS,GAAGb,KAAK,CAACc,UAAU,CAAC;IAC/Bd;EACJ,CAAC,CAAC;EACF,OAAO;IACHA,KAAK;IACLV,OAAO;IACPuB,SAAS;IACTH,OAAO,EAAElB,KAAK,KAAK;EACvB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { CmsEntry, CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
1
|
+
import type { CmsEntry, CmsEntryListWhere, CmsEntryValues } from "@webiny/api-headless-cms/types/index.js";
|
|
2
2
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import type { Field } from "./types";
|
|
4
|
-
interface Params {
|
|
5
|
-
items: CmsEntry[];
|
|
3
|
+
import type { Field } from "./types.js";
|
|
4
|
+
interface Params<T extends CmsEntryValues = CmsEntryValues> {
|
|
5
|
+
items: CmsEntry<T>[];
|
|
6
6
|
where: Partial<CmsEntryListWhere>;
|
|
7
7
|
plugins: PluginsContainer;
|
|
8
8
|
fields: Record<string, Field>;
|
|
@@ -11,5 +11,5 @@ interface Params {
|
|
|
11
11
|
fields?: string[];
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
export declare const filter: (params: Params) => CmsEntry[];
|
|
14
|
+
export declare const filter: <T extends CmsEntryValues = CmsEntryValues>(params: Params<T>) => CmsEntry<T>[];
|
|
15
15
|
export {};
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
exports.filter = void 0;
|
|
8
|
-
var _ValueFilterPlugin = require("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin");
|
|
9
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
var _fullTextSearch = require("./fullTextSearch");
|
|
11
|
-
var _createExpressions = require("./createExpressions");
|
|
12
|
-
var _transform = require("./transform");
|
|
13
|
-
var _getValue = require("./getValue");
|
|
1
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
2
|
+
import WebinyError from "@webiny/error";
|
|
3
|
+
import { createFullTextSearch } from "./fullTextSearch.js";
|
|
4
|
+
import { createExpressions } from "./createExpressions.js";
|
|
5
|
+
import { transformValue } from "./transform.js";
|
|
6
|
+
import { getValue } from "./getValue.js";
|
|
14
7
|
const executeFilter = params => {
|
|
15
8
|
const {
|
|
16
9
|
value,
|
|
@@ -85,7 +78,7 @@ const executeExpressions = params => {
|
|
|
85
78
|
*/
|
|
86
79
|
return condition === "OR" ? false : true;
|
|
87
80
|
};
|
|
88
|
-
const filter = params => {
|
|
81
|
+
export const filter = params => {
|
|
89
82
|
const {
|
|
90
83
|
items: records,
|
|
91
84
|
where,
|
|
@@ -97,7 +90,7 @@ const filter = params => {
|
|
|
97
90
|
if (keys.length === 0 && !fullTextSearch) {
|
|
98
91
|
return records;
|
|
99
92
|
}
|
|
100
|
-
const expression =
|
|
93
|
+
const expression = createExpressions({
|
|
101
94
|
plugins,
|
|
102
95
|
where,
|
|
103
96
|
fields
|
|
@@ -112,11 +105,11 @@ const filter = params => {
|
|
|
112
105
|
/**
|
|
113
106
|
* We need the contains plugin to run the full text search.
|
|
114
107
|
*/
|
|
115
|
-
const fullTextSearchPlugin = plugins.byType(
|
|
108
|
+
const fullTextSearchPlugin = plugins.byType(ValueFilterPlugin.type).find(plugin => plugin.getOperation() === "contains");
|
|
116
109
|
if (!fullTextSearchPlugin) {
|
|
117
|
-
throw new
|
|
110
|
+
throw new WebinyError(`Missing "contains" plugin to run the full-text search.`, "MISSING_PLUGIN");
|
|
118
111
|
}
|
|
119
|
-
const search =
|
|
112
|
+
const search = createFullTextSearch({
|
|
120
113
|
term: fullTextSearch?.term,
|
|
121
114
|
targetFields: fullTextSearch?.fields,
|
|
122
115
|
fields,
|
|
@@ -131,8 +124,8 @@ const filter = params => {
|
|
|
131
124
|
if (cachedValues[path] !== undefined) {
|
|
132
125
|
return cachedValues[path];
|
|
133
126
|
}
|
|
134
|
-
const plainValue =
|
|
135
|
-
const rawValue =
|
|
127
|
+
const plainValue = getValue(record, path);
|
|
128
|
+
const rawValue = transformValue({
|
|
136
129
|
value: plainValue,
|
|
137
130
|
transform: filter.transformValue
|
|
138
131
|
});
|
|
@@ -153,6 +146,5 @@ const filter = params => {
|
|
|
153
146
|
return search(record);
|
|
154
147
|
});
|
|
155
148
|
};
|
|
156
|
-
exports.filter = filter;
|
|
157
149
|
|
|
158
150
|
//# sourceMappingURL=filter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["ValueFilterPlugin","WebinyError","createFullTextSearch","createExpressions","transformValue","getValue","executeFilter","params","value","filter","canUse","plugin","compareValue","matched","matches","negate","executeExpressions","expressions","getCachedValue","filters","condition","length","result","expression","items","records","where","plugins","fields","fullTextSearch","keys","Object","term","fullTextSearchPlugin","byType","type","find","getOperation","search","targetFields","record","cachedValues","path","undefined","plainValue","rawValue","transform","exprResult"],"sources":["filter.ts"],"sourcesContent":["import type {\n CmsEntry,\n CmsEntryListWhere,\n CmsEntryValues\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { createFullTextSearch } from \"./fullTextSearch.js\";\nimport type { Expression, ExpressionCondition, Filter } from \"./createExpressions.js\";\nimport { createExpressions } from \"./createExpressions.js\";\nimport { transformValue } from \"./transform.js\";\nimport { getValue } from \"~/operations/entry/filtering/getValue.js\";\n\ninterface ExecuteFilterParams {\n value: any;\n filter: Filter;\n}\n\nconst executeFilter = (params: ExecuteFilterParams) => {\n const { value, filter } = params;\n\n /**\n * We need to check if the filter can be used.\n * If it cannot, we will just return true.\n */\n const canUse = filter.plugin.canUse({\n value,\n compareValue: filter.compareValue\n });\n if (!canUse) {\n return true;\n }\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<T extends CmsEntryValues = CmsEntryValues> {\n items: CmsEntry<T>[];\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 = <T extends CmsEntryValues = CmsEntryValues>(\n params: Params<T>\n): CmsEntry<T>[] => {\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":"AAKA,SAASA,iBAAiB,QAAQ,8DAA8D;AAChG,OAAOC,WAAW,MAAM,eAAe;AAGvC,SAASC,oBAAoB;AAE7B,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,QAAQ;AAOjB,MAAMC,aAAa,GAAIC,MAA2B,IAAK;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGF,MAAM;;EAEhC;AACJ;AACA;AACA;EACI,MAAMG,MAAM,GAAGD,MAAM,CAACE,MAAM,CAACD,MAAM,CAAC;IAChCF,KAAK;IACLI,YAAY,EAAEH,MAAM,CAACG;EACzB,CAAC,CAAC;EACF,IAAI,CAACF,MAA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OAAOF,YAAY,CAACC,IAAI,CAAC;MAC7B;MACA,MAAME,UAAU,GAAGvC,QAAQ,CAACmC,MAAM,EAAEE,IAAI,CAAC;MAEzC,MAAMG,QAAQ,GAAGzC,cAAc,CAAC;QAC5BI,KAAK,EAAEoC,UAAU;QACjBE,SAAS,EAAErC,MAAM,CAACL;MACtB,CAAC,CAAC;MAEFqC,YAAY,CAACC,IAAI,CAAC,GAAGG,QAAQ;MAC7B,OAAOA,QAAQ;IACnB,CAAC;IAED,MAAME,UAAU,GAAG/B,kBAAkB,CAAC;MAAE,GAAGO,UAAU;MAAEL;IAAe,CAAC,CAAC;IACxE;AACR;AACA;AACA;IACQ,IAAI,CAAC6B,UAAU,IAAI,CAACT,MAAM,EAAE;MACxB,OAAOS,UAAU;IACrB;IAEA,OAAOT,MAAM,CAACE,MAAM,CAAC;EACzB,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
2
|
-
import type { CmsEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
-
import type { Field } from "./types";
|
|
1
|
+
import type { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
2
|
+
import type { CmsEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import type { Field } from "./types.js";
|
|
4
4
|
interface Params {
|
|
5
5
|
term?: string;
|
|
6
6
|
targetFields?: string[];
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createFullTextSearch = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _getValue = require("./getValue");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { getValue } from "./getValue.js";
|
|
10
3
|
/**
|
|
11
4
|
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
|
|
12
5
|
*/
|
|
13
|
-
const createFullTextSearch = params => {
|
|
6
|
+
export const createFullTextSearch = params => {
|
|
14
7
|
const {
|
|
15
8
|
term,
|
|
16
9
|
targetFields,
|
|
@@ -27,11 +20,11 @@ const createFullTextSearch = params => {
|
|
|
27
20
|
*/
|
|
28
21
|
const field = fieldDefinitions[target];
|
|
29
22
|
if (!field) {
|
|
30
|
-
throw new
|
|
23
|
+
throw new WebinyError(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
|
|
31
24
|
target
|
|
32
25
|
});
|
|
33
26
|
}
|
|
34
|
-
const value =
|
|
27
|
+
const value = getValue(item, target);
|
|
35
28
|
if (!value) {
|
|
36
29
|
continue;
|
|
37
30
|
}
|
|
@@ -45,6 +38,5 @@ const createFullTextSearch = params => {
|
|
|
45
38
|
return false;
|
|
46
39
|
};
|
|
47
40
|
};
|
|
48
|
-
exports.createFullTextSearch = createFullTextSearch;
|
|
49
41
|
|
|
50
42
|
//# sourceMappingURL=fullTextSearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","getValue","createFullTextSearch","params","term","targetFields","fields","fieldDefinitions","plugin","trim","length","item","target","field","value","matches","compareValue"],"sources":["fullTextSearch.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js\";\nimport type { CmsEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { Field } from \"./types.js\";\nimport { getValue } from \"./getValue.js\";\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, 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,OAAOA,WAAW,MAAM,eAAe;AAIvC,SAASC,QAAQ;AASjB;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,MAAc,IAAK;EACpD,MAAM;IAAEC,IAAI;IAAEC,YAAY;IAAEC,MAAM,EAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACvE,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACK,IAAI,CAAC,CAAC,CAACC,MAAM,KAAK,CAAC,IAAI,CAACL,YAAY,IAAIA,YAAY,CAACK,MAAM,KAAK,CAAC,EAAE;IACjF,OAAO,IAAI;EACf;EACA,OAAQC,IAAc,IAAK;IACvB,KAAK,MAAMC,MAAM,IAAIP,YAAY,EAAE;MAC/B;AACZ;AACA;MACY,MAAMQ,KAAK,GAAGN,gBAAgB,CAACK,MAAM,CAAC;MAEtC,IAAI,CAACC,KAAK,EAAE;QACR,MAAM,IAAIb,WAAW,CAAC,kBAAkBY,MAAM,iBAAiB,EAAE,eAAe,EAAE;UAC9EA;QACJ,CAAC,CAAC;MACN;MACA,MAAME,KAAK,GAAGb,QAAQ,CAACU,IAAI,EAAEC,MAAM,CAAC;MACpC,IAAI,CAACE,KAAK,EAAE;QACR;MACJ;MACA,IAAIN,MAAM,CAACO,OAAO,CAAC;QAAED,KAAK;QAAEE,YAAY,EAAEZ;MAAK,CAAC,CAAC,KAAK,IAAI,EAAE;QACxD,OAAO,IAAI;MACf;IACJ;IACA,OAAO,KAAK;EAChB,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getValue = void 0;
|
|
7
1
|
const addArrayResult = (target, result) => {
|
|
8
2
|
for (const r of result) {
|
|
9
3
|
if (target.some(t => r === t)) {
|
|
@@ -50,7 +44,7 @@ const find = (target, input) => {
|
|
|
50
44
|
* A wrapper function for the find function.
|
|
51
45
|
* Basically it transforms input paths to an array (and runs various checks).
|
|
52
46
|
*/
|
|
53
|
-
const getValue = (target, input) => {
|
|
47
|
+
export const getValue = (target, input) => {
|
|
54
48
|
const paths = Array.isArray(input) ? input : input.split(".");
|
|
55
49
|
if (paths.length === 0) {
|
|
56
50
|
throw new Error(`Path is empty!`);
|
|
@@ -61,6 +55,5 @@ const getValue = (target, input) => {
|
|
|
61
55
|
}
|
|
62
56
|
return find(target, paths);
|
|
63
57
|
};
|
|
64
|
-
exports.getValue = getValue;
|
|
65
58
|
|
|
66
59
|
//# sourceMappingURL=getValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"
|
|
1
|
+
{"version":3,"names":["addArrayResult","target","result","r","some","t","push","find","input","paths","path","shift","undefined","value","length","Array","isArray","reduce","collection","v","getValue","split","Error","filtered","filter","Boolean","join"],"sources":["getValue.ts"],"sourcesContent":["const addArrayResult = (target: any[], result: any[]): void => {\n for (const r of result) {\n if (target.some(t => r === t)) {\n continue;\n }\n target.push(r);\n }\n};\n/**\n * A recursive function which goes through given input paths and returns the value in it.\n * In case a path is an array, it goes through the array of those values to get values further down the path line.\n */\nconst find = (target: Record<string, any> | undefined, input: string[]): any[] | undefined => {\n const paths = [...input];\n const path = paths.shift();\n\n if (!path) {\n return undefined;\n }\n\n const value = target?.[path];\n if (value === undefined) {\n return undefined;\n }\n if (paths.length === 0) {\n return value;\n } else if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n return value.reduce<any[]>((collection, v) => {\n const result = find(v, paths);\n if (result === undefined) {\n return collection;\n } else if (Array.isArray(result)) {\n addArrayResult(collection, result);\n return collection;\n }\n collection.push(result);\n return collection;\n }, []);\n }\n return find(value, paths);\n};\n/**\n * A wrapper function for the find function.\n * Basically it transforms input paths to an array (and runs various checks).\n */\nexport const getValue = (target: Record<string, any>, input: string | string[]): any => {\n const paths = Array.isArray(input) ? input : input.split(\".\");\n if (paths.length === 0) {\n throw new Error(`Path is empty!`);\n }\n const filtered = paths.filter(Boolean);\n if (paths.length !== filtered.length) {\n throw new Error(\n `Input path is different than the filtered empty path string. (${paths.join(\n \".\"\n )} to ${filtered.join(\".\")})`\n );\n }\n\n return find(target, paths);\n};\n"],"mappings":"AAAA,MAAMA,cAAc,GAAGA,CAACC,MAAa,EAAEC,MAAa,KAAW;EAC3D,KAAK,MAAMC,CAAC,IAAID,MAAM,EAAE;IACpB,IAAID,MAAM,CAACG,IAAI,CAACC,CAAC,IAAIF,CAAC,KAAKE,CAAC,CAAC,EAAE;MAC3B;IACJ;IACAJ,MAAM,CAACK,IAAI,CAACH,CAAC,CAAC;EAClB;AACJ,CAAC;AACD;AACA;AACA;AACA;AACA,MAAMI,IAAI,GAAGA,CAACN,MAAuC,EAAEO,KAAe,KAAwB;EAC1F,MAAMC,KAAK,GAAG,CAAC,GAAGD,KAAK,CAAC;EACxB,MAAME,IAAI,GAAGD,KAAK,CAACE,KAAK,CAAC,CAAC;EAE1B,IAAI,CAACD,IAAI,EAAE;IACP,OAAOE,SAAS;EACpB;EAEA,MAAMC,KAAK,GAAGZ,MAAM,GAAGS,IAAI,CAAC;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,KAAK,CACX,iEAAiEb,KAAK,CAACiB,IAAI,CACvE,GACJ,CAAC,OAAOH,QAAQ,CAACG,IAAI,CAAC,GAAG,CAAC,GAC9B,CAAC;EACL;EAEA,OAAOnB,IAAI,CAACN,MAAM,EAAEQ,KAAK,CAAC;AAC9B,CAAC","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { filter } from "./filter";
|
|
2
|
-
export { sort } from "./sort";
|
|
1
|
+
export { filter } from "./filter.js";
|
|
2
|
+
export { sort } from "./sort.js";
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "filter", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _filter.filter;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "sort", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _sort.sort;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _filter = require("./filter");
|
|
19
|
-
var _sort = require("./sort");
|
|
1
|
+
export { filter } from "./filter.js";
|
|
2
|
+
export { sort } from "./sort.js";
|
|
20
3
|
|
|
21
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["filter","sort"],"sources":["index.ts"],"sourcesContent":["export { filter } from \"./filter.js\";\nexport { sort } from \"./sort.js\";\n"],"mappings":"AAAA,SAASA,MAAM;AACf,SAASC,IAAI","ignoreList":[]}
|