@webiny/api-headless-cms-ddb 0.0.0-unstable.e53eceafb5 → 0.0.0-unstable.e6f0dc8ca7
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 +61 -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 +4 -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/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 -3
- package/index.js +62 -92
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -2
- package/operations/entry/dataLoader/DataLoaderCache.js +3 -13
- 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 +16 -26
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +27 -33
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +27 -33
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +29 -35
- 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 +4 -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 +16 -24
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/filtering/createExpressions.d.ts +7 -6
- package/operations/entry/filtering/createExpressions.js +29 -35
- 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 +7 -6
- package/operations/entry/filtering/filter.js +22 -27
- package/operations/entry/filtering/filter.js.map +1 -1
- package/operations/entry/filtering/fullTextSearch.d.ts +4 -4
- package/operations/entry/filtering/fullTextSearch.js +7 -15
- 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 +10 -18
- 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 +15 -21
- 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 +16 -22
- 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 +14 -17
- 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 +4 -4
- 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 +4 -3
- package/operations/entry/index.js +279 -388
- 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 +4 -5
- package/operations/group/index.js +37 -69
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +36 -59
- package/operations/model/index.js.map +1 -1
- package/package.json +24 -20
- 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 +5 -5
- 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 +20 -20
- 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/dynamoDb/storage/longText.d.ts +0 -10
- package/dynamoDb/storage/longText.js +0 -94
- package/dynamoDb/storage/longText.js.map +0 -1
- package/dynamoDb/storage/richText.d.ts +0 -2
- package/dynamoDb/storage/richText.js +0 -61
- package/dynamoDb/storage/richText.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,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.DataLoadersHandler = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _DataLoaderCache = require("./dataLoader/DataLoaderCache");
|
|
10
|
-
var _dataLoader = require("./dataLoader");
|
|
11
|
-
var _utils = require("@webiny/utils");
|
|
12
|
-
class DataLoadersHandler {
|
|
13
|
-
cache = new _DataLoaderCache.DataLoaderCache();
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { DataLoaderCache } from "./dataLoader/DataLoaderCache.js";
|
|
3
|
+
import { getDataLoaderFactory } from "./dataLoader/index.js";
|
|
4
|
+
import { parseIdentifier } from "@webiny/utils";
|
|
5
|
+
export class DataLoadersHandler {
|
|
6
|
+
cache = new DataLoaderCache();
|
|
14
7
|
constructor(params) {
|
|
15
8
|
this.entity = params.entity;
|
|
16
9
|
}
|
|
@@ -18,7 +11,7 @@ class DataLoadersHandler {
|
|
|
18
11
|
const ids = params.ids.map(id => {
|
|
19
12
|
const {
|
|
20
13
|
id: entryId
|
|
21
|
-
} =
|
|
14
|
+
} = parseIdentifier(id);
|
|
22
15
|
return entryId;
|
|
23
16
|
});
|
|
24
17
|
return await this.loadMany("getAllEntryRevisions", params, ids);
|
|
@@ -30,7 +23,7 @@ class DataLoadersHandler {
|
|
|
30
23
|
const ids = params.ids.map(id => {
|
|
31
24
|
const {
|
|
32
25
|
id: entryId
|
|
33
|
-
} =
|
|
26
|
+
} = parseIdentifier(id);
|
|
34
27
|
return entryId;
|
|
35
28
|
});
|
|
36
29
|
return await this.loadMany("getPublishedRevisionByEntryId", params, ids);
|
|
@@ -39,7 +32,7 @@ class DataLoadersHandler {
|
|
|
39
32
|
const ids = params.ids.map(id => {
|
|
40
33
|
const {
|
|
41
34
|
id: entryId
|
|
42
|
-
} =
|
|
35
|
+
} = parseIdentifier(id);
|
|
43
36
|
return entryId;
|
|
44
37
|
});
|
|
45
38
|
return await this.loadMany("getLatestRevisionByEntryId", params, ids);
|
|
@@ -55,18 +48,18 @@ class DataLoadersHandler {
|
|
|
55
48
|
} = params;
|
|
56
49
|
const cacheParams = {
|
|
57
50
|
tenant: model.tenant,
|
|
58
|
-
|
|
51
|
+
modelId: model.modelId,
|
|
59
52
|
name
|
|
60
53
|
};
|
|
61
54
|
let loader = this.cache.getDataLoader(cacheParams);
|
|
62
55
|
if (loader) {
|
|
63
56
|
return loader;
|
|
64
57
|
}
|
|
65
|
-
const factory =
|
|
58
|
+
const factory = getDataLoaderFactory(name);
|
|
66
59
|
loader = factory({
|
|
67
60
|
entity: this.entity,
|
|
68
61
|
tenant: model.tenant,
|
|
69
|
-
|
|
62
|
+
modelId: model.modelId
|
|
70
63
|
});
|
|
71
64
|
this.cache.setDataLoader(cacheParams, loader);
|
|
72
65
|
return loader;
|
|
@@ -79,12 +72,12 @@ class DataLoadersHandler {
|
|
|
79
72
|
return results.reduce((acc, res) => {
|
|
80
73
|
if (Array.isArray(res) === false) {
|
|
81
74
|
if (res && res.message) {
|
|
82
|
-
throw new
|
|
75
|
+
throw new WebinyError(res.message, res.code, {
|
|
83
76
|
...res,
|
|
84
77
|
data: JSON.stringify(res.data || {})
|
|
85
78
|
});
|
|
86
79
|
}
|
|
87
|
-
throw new
|
|
80
|
+
throw new WebinyError("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
|
|
88
81
|
...params,
|
|
89
82
|
loader
|
|
90
83
|
});
|
|
@@ -94,14 +87,14 @@ class DataLoadersHandler {
|
|
|
94
87
|
}, []);
|
|
95
88
|
}
|
|
96
89
|
} catch (ex) {
|
|
97
|
-
throw new
|
|
90
|
+
throw new WebinyError(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
|
|
98
91
|
error: ex,
|
|
99
92
|
...params,
|
|
100
93
|
loader,
|
|
101
94
|
ids
|
|
102
95
|
});
|
|
103
96
|
}
|
|
104
|
-
throw new
|
|
97
|
+
throw new WebinyError(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
|
|
105
98
|
loader,
|
|
106
99
|
ids,
|
|
107
100
|
results
|
|
@@ -111,6 +104,5 @@ class DataLoadersHandler {
|
|
|
111
104
|
this.cache.clearAll(params?.model);
|
|
112
105
|
}
|
|
113
106
|
}
|
|
114
|
-
exports.DataLoadersHandler = DataLoadersHandler;
|
|
115
107
|
|
|
116
108
|
//# sourceMappingURL=dataLoaders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","DataLoaderCache","getDataLoaderFactory","parseIdentifier","DataLoadersHandler","cache","constructor","params","entity","getAllEntryRevisions","ids","map","id","entryId","loadMany","getRevisionById","getPublishedRevisionByEntryId","getLatestRevisionByEntryId","getLoader","name","model","cacheParams","tenant","modelId","loader","getDataLoader","factory","setDataLoader","results","Array","isArray","reduce","acc","res","message","code","data","JSON","stringify","push","ex","error","clearAll"],"sources":["dataLoaders.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport type {\n CmsEntryValues,\n CmsModel,\n CmsStorageEntry\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CacheKeyParams } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport { DataLoaderCache } from \"~/operations/entry/dataLoader/DataLoaderCache.js\";\nimport type { DataLoaders } from \"~/operations/entry/dataLoader/index.js\";\nimport { getDataLoaderFactory } from \"~/operations/entry/dataLoader/index.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport type {\n DataLoadersHandlerInterfaceClearAllParams,\n IDataLoadersHandler,\n IEntryEntity\n} from \"~/types.js\";\n\ninterface DataLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n ids: readonly string[];\n}\n\ninterface GetLoaderParams {\n model: Pick<CmsModel, \"tenant\" | \"modelId\">;\n}\n\ninterface IDataLoadersHandlerParams {\n entity: IEntryEntity;\n}\n\nexport class DataLoadersHandler implements IDataLoadersHandler {\n private readonly entity;\n private readonly cache = new DataLoaderCache();\n\n public constructor(params: IDataLoadersHandlerParams) {\n this.entity = params.entity;\n }\n\n public async getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getAllEntryRevisions\", params, ids);\n }\n\n public async getRevisionById<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n return await this.loadMany<T>(\"getRevisionById\", params, params.ids);\n }\n\n public async getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getPublishedRevisionByEntryId\", params, ids);\n }\n\n public async getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(\n params: DataLoaderParams\n ): Promise<CmsStorageEntry<T>[]> {\n const ids = params.ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return entryId;\n });\n return await this.loadMany<T>(\"getLatestRevisionByEntryId\", params, ids);\n }\n\n /**\n * TODO @ts-refactor\n * Maybe pass on the generics to DataLoader definition?\n */\n private getLoader(name: DataLoaders, params: GetLoaderParams): DataLoader<any, any> {\n const { model } = params;\n const cacheParams: CacheKeyParams = {\n tenant: model.tenant,\n modelId: model.modelId,\n name\n };\n let loader = this.cache.getDataLoader(cacheParams);\n if (loader) {\n return loader;\n }\n const factory = getDataLoaderFactory(name);\n loader = factory({\n entity: this.entity,\n tenant: model.tenant,\n modelId: model.modelId\n });\n this.cache.setDataLoader(cacheParams, loader);\n return loader;\n }\n\n private async loadMany<T extends CmsEntryValues = CmsEntryValues>(\n loader: DataLoaders,\n params: GetLoaderParams,\n ids: readonly string[]\n ): Promise<CmsStorageEntry<T>[]> {\n let results: any[] = [];\n try {\n results = await this.getLoader(loader, params).loadMany(ids);\n if (Array.isArray(results) === true) {\n return results.reduce((acc, res) => {\n if (Array.isArray(res) === false) {\n if (res && res.message) {\n throw new WebinyError(res.message, res.code, {\n ...res,\n data: JSON.stringify(res.data || {})\n });\n }\n throw new WebinyError(\n \"Result from the data loader must be an array of arrays which contain requested items.\",\n \"DATA_LOADER_RESULTS_ERROR\",\n {\n ...params,\n loader\n }\n );\n }\n acc.push(...res);\n return acc;\n }, []);\n }\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Data loader error.\",\n ex.code || \"DATA_LOADER_ERROR\",\n {\n error: ex,\n ...params,\n loader,\n ids\n }\n );\n }\n throw new WebinyError(\n `Data loader did not return array of items or empty array.`,\n \"INVALID_DATA_LOADER_RESULT\",\n {\n loader,\n ids,\n results\n }\n );\n }\n\n public clearAll(params?: DataLoadersHandlerInterfaceClearAllParams): void {\n this.cache.clearAll(params?.model);\n }\n}\n"],"mappings":"AACA,OAAOA,WAAW,MAAM,eAAe;AAOvC,SAASC,eAAe;AAExB,SAASC,oBAAoB;AAC7B,SAASC,eAAe,QAAQ,eAAe;AAoB/C,OAAO,MAAMC,kBAAkB,CAAgC;EAE1CC,KAAK,GAAG,IAAIJ,eAAe,CAAC,CAAC;EAEvCK,WAAWA,CAACC,MAAiC,EAAE;IAClD,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;EAC/B;EAEA,MAAaC,oBAAoBA,CAC7BF,MAAwB,EACK;IAC7B,MAAMG,GAAG,GAAGH,MAAM,CAACG,GAAG,CAACC,GAAG,CAACC,EAAE,IAAI;MAC7B,MAAM;QAAEA,EAAE,EAAEC;MA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AGN,GAAG,CAAC;UAChB,OAAOD,GAAG;QACd,CAAC,EAAE,EAAE,CAAC;MACV;IACJ,CAAC,CAAC,OAAOQ,EAAE,EAAE;MACT,MAAM,IAAIxC,WAAW,CACjBwC,EAAE,CAACN,OAAO,IAAI,oBAAoB,EAClCM,EAAE,CAACL,IAAI,IAAI,mBAAmB,EAC9B;QACIM,KAAK,EAAED,EAAE;QACT,GAAGjC,MAAM;QACTiB,MAAM;QACNd;MACJ,CACJ,CAAC;IACL;IACA,MAAM,IAAIV,WAAW,CACjB,2DAA2D,EAC3D,4BAA4B,EAC5B;MACIwB,MAAM;MACNd,GAAG;MACHkB;IACJ,CACJ,CAAC;EACL;EAEOc,QAAQA,CAACnC,MAAkD,EAAQ;IACtE,IAAI,CAACF,KAAK,CAACqC,QAAQ,CAACnC,MAAM,EAAEa,KAAK,CAAC;EACtC;AACJ","ignoreList":[]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
1
|
+
import type { CmsContext, CmsEntryListWhere } from "@webiny/api-headless-cms/types/index.js";
|
|
3
2
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
|
-
import type { Field } from "./types";
|
|
5
|
-
|
|
3
|
+
import type { Field } from "./types.js";
|
|
4
|
+
import { ValueFilter } from "@webiny/db-dynamodb/feature/ValueFilter/index.js";
|
|
5
|
+
interface ICreateExpressionsParams {
|
|
6
6
|
plugins: PluginsContainer;
|
|
7
|
+
container: CmsContext["container"];
|
|
7
8
|
where: Partial<CmsEntryListWhere>;
|
|
8
9
|
fields: Record<string, Field>;
|
|
9
10
|
}
|
|
@@ -17,10 +18,10 @@ export interface Filter {
|
|
|
17
18
|
field: Field;
|
|
18
19
|
path: string;
|
|
19
20
|
fieldPathId: string;
|
|
20
|
-
|
|
21
|
+
filter: ValueFilter.Interface;
|
|
21
22
|
negate: boolean;
|
|
22
23
|
compareValue: any;
|
|
23
24
|
transformValue: <I = any, O = any>(value: I) => O;
|
|
24
25
|
}
|
|
25
|
-
export declare const createExpressions: (params:
|
|
26
|
+
export declare const createExpressions: (params: ICreateExpressionsParams) => Expression;
|
|
26
27
|
export {};
|
|
@@ -1,46 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var _mapPlugins = require("./mapPlugins");
|
|
11
|
-
var _where = require("./where");
|
|
12
|
-
var _transform = require("./transform");
|
|
13
|
-
var _CmsEntryFieldFilterPlugin = require("../../../plugins/CmsEntryFieldFilterPlugin");
|
|
14
|
-
var _values = require("./values");
|
|
15
|
-
const createExpressions = params => {
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { getMappedPlugins } from "./mapPlugins.js";
|
|
3
|
+
import { extractWhereParams } from "./where.js";
|
|
4
|
+
import { transformValue } from "./transform.js";
|
|
5
|
+
import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
6
|
+
import { getWhereValues } from "./values.js";
|
|
7
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
8
|
+
import { ValueFilterRegistry } from "@webiny/db-dynamodb/exports/api/db.js";
|
|
9
|
+
export const createExpressions = params => {
|
|
16
10
|
const {
|
|
17
11
|
where,
|
|
18
12
|
plugins,
|
|
19
|
-
fields
|
|
13
|
+
fields,
|
|
14
|
+
container
|
|
20
15
|
} = params;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
type: _ValueFilterPlugin.ValueFilterPlugin.type,
|
|
24
|
-
property: "operation"
|
|
25
|
-
});
|
|
26
|
-
const transformValuePlugins = (0, _mapPlugins.getMappedPlugins)({
|
|
16
|
+
const valueFilterRegistry = container.resolve(ValueFilterRegistry);
|
|
17
|
+
const transformValuePlugins = getMappedPlugins({
|
|
27
18
|
plugins,
|
|
28
19
|
type: "cms-field-filter-value-transform",
|
|
29
20
|
property: "fieldType"
|
|
30
21
|
});
|
|
31
|
-
const fieldFilterCreatePlugins =
|
|
22
|
+
const fieldFilterCreatePlugins = getMappedPlugins({
|
|
32
23
|
plugins,
|
|
33
|
-
type:
|
|
24
|
+
type: CmsEntryFieldFilterPlugin.type,
|
|
34
25
|
property: "fieldType"
|
|
35
26
|
});
|
|
36
27
|
const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
|
|
37
28
|
const getFilterCreatePlugin = type => {
|
|
38
|
-
const
|
|
29
|
+
const fieldType = getBaseFieldType({
|
|
30
|
+
type
|
|
31
|
+
});
|
|
32
|
+
const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
|
|
39
33
|
if (filterCreatePlugin) {
|
|
40
34
|
return filterCreatePlugin;
|
|
41
35
|
}
|
|
42
|
-
throw new
|
|
43
|
-
|
|
36
|
+
throw new WebinyError(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
|
|
37
|
+
fieldType
|
|
44
38
|
});
|
|
45
39
|
};
|
|
46
40
|
const createExpression = ({
|
|
@@ -65,7 +59,7 @@ const createExpressions = params => {
|
|
|
65
59
|
* AND conditional
|
|
66
60
|
*/
|
|
67
61
|
if (key === "AND") {
|
|
68
|
-
const childWhereList =
|
|
62
|
+
const childWhereList = getWhereValues(value, key);
|
|
69
63
|
const childExpression = {
|
|
70
64
|
condition: "AND",
|
|
71
65
|
filters: [],
|
|
@@ -85,7 +79,7 @@ const createExpressions = params => {
|
|
|
85
79
|
* OR conditional
|
|
86
80
|
*/
|
|
87
81
|
if (key === "OR") {
|
|
88
|
-
const childWhereList =
|
|
82
|
+
const childWhereList = getWhereValues(value, key);
|
|
89
83
|
const childExpression = {
|
|
90
84
|
condition: "OR",
|
|
91
85
|
filters: [],
|
|
@@ -101,7 +95,7 @@ const createExpressions = params => {
|
|
|
101
95
|
expression.expressions.push(childExpression);
|
|
102
96
|
continue;
|
|
103
97
|
}
|
|
104
|
-
const whereParams =
|
|
98
|
+
const whereParams = extractWhereParams(key);
|
|
105
99
|
if (!whereParams) {
|
|
106
100
|
continue;
|
|
107
101
|
}
|
|
@@ -112,7 +106,7 @@ const createExpressions = params => {
|
|
|
112
106
|
} = whereParams;
|
|
113
107
|
const field = fields[fieldId];
|
|
114
108
|
if (!field) {
|
|
115
|
-
throw new
|
|
109
|
+
throw new WebinyError(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
116
110
|
fieldId
|
|
117
111
|
});
|
|
118
112
|
}
|
|
@@ -121,7 +115,8 @@ const createExpressions = params => {
|
|
|
121
115
|
* We need a filter create plugin for this type.
|
|
122
116
|
*/
|
|
123
117
|
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
124
|
-
const
|
|
118
|
+
const fieldType = getBaseFieldType(field);
|
|
119
|
+
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
125
120
|
const transformValueCallable = value => {
|
|
126
121
|
if (!transformValuePlugin) {
|
|
127
122
|
return value;
|
|
@@ -134,14 +129,14 @@ const createExpressions = params => {
|
|
|
134
129
|
const result = filterCreatePlugin.create({
|
|
135
130
|
key,
|
|
136
131
|
value,
|
|
137
|
-
|
|
132
|
+
valueFilterRegistry,
|
|
138
133
|
transformValuePlugins,
|
|
139
134
|
getFilterCreatePlugin,
|
|
140
135
|
operation,
|
|
141
136
|
negate,
|
|
142
137
|
field,
|
|
143
138
|
fields,
|
|
144
|
-
compareValue:
|
|
139
|
+
compareValue: transformValue({
|
|
145
140
|
value,
|
|
146
141
|
transform: transformValueCallable
|
|
147
142
|
}),
|
|
@@ -173,6 +168,5 @@ const createExpressions = params => {
|
|
|
173
168
|
}
|
|
174
169
|
return expression.expressions[0];
|
|
175
170
|
};
|
|
176
|
-
exports.createExpressions = createExpressions;
|
|
177
171
|
|
|
178
172
|
//# sourceMappingURL=createExpressions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_error","_interopRequireDefault","require","_ValueFilterPlugin","_mapPlugins","_where","_transform","_CmsEntryFieldFilterPlugin","_values","createExpressions","params","where","plugins","fields","filterPlugins","getMappedPlugins","type","ValueFilterPlugin","property","transformValuePlugins","fieldFilterCreatePlugins","CmsEntryFieldFilterPlugin","defaultFilterCreatePlugin","getFilterCreatePlugin","filterCreatePlugin","WebinyError","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","getWhereValues","childExpression","childWhere","result","push","whereParams","extractWhereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","valueFilterPlugins","compareValue","transformValue","Array","isArray","length","exports"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { ValueFilterPlugin } from \"@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types\";\nimport { getMappedPlugins } from \"./mapPlugins\";\nimport { extractWhereParams } from \"./where\";\nimport { transformValue } from \"./transform\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface CreateExpressionCb {\n (params: CreateExpressionParams): Expression;\n}\n\ninterface Params {\n plugins: PluginsContainer;\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n plugin: ValueFilterPlugin;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: Params): Expression => {\n const { where, plugins, fields } = params;\n const filterPlugins = getMappedPlugins<ValueFilterPlugin>({\n plugins,\n type: ValueFilterPlugin.type,\n property: \"operation\"\n });\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const filterCreatePlugin = fieldFilterCreatePlugins[type] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${type}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n type\n }\n );\n };\n\n const createExpression: CreateExpressionCb = ({ where, condition }) => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[field.type];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterPlugins: filterPlugins,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,kBAAA,GAAAD,OAAA;AAIA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,0BAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAmCO,MAAMO,iBAAiB,GAAIC,MAAc,IAAi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AC,IAAI3B,UAAU,CAACE,WAAW,CAACyB,MAAM,KAAK,CAAC,EAAE;IACtE,OAAO3B,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC;AAAC0B,OAAA,CAAA/C,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["WebinyError","getMappedPlugins","extractWhereParams","transformValue","CmsEntryFieldFilterPlugin","getWhereValues","getBaseFieldType","ValueFilterRegistry","createExpressions","params","where","plugins","fields","container","valueFilterRegistry","resolve","transformValuePlugins","type","property","fieldFilterCreatePlugins","defaultFilterCreatePlugin","getFilterCreatePlugin","fieldType","filterCreatePlugin","createExpression","condition","expression","filters","expressions","key","value","undefined","childWhereList","childExpression","childWhere","result","push","whereParams","fieldId","operation","negate","field","transformValuePlugin","transformValueCallable","transform","create","compareValue","Array","isArray","length"],"sources":["createExpressions.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsContext, CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsFieldFilterValueTransformPlugin } from \"~/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type { Field } from \"./types.js\";\nimport { getMappedPlugins } from \"./mapPlugins.js\";\nimport { extractWhereParams } from \"./where.js\";\nimport { transformValue } from \"./transform.js\";\nimport { CmsEntryFieldFilterPlugin } from \"~/plugins/CmsEntryFieldFilterPlugin.js\";\nimport { getWhereValues } from \"~/operations/entry/filtering/values.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\nimport { ValueFilter } from \"@webiny/db-dynamodb/feature/ValueFilter/index.js\";\nimport { ValueFilterRegistry } from \"@webiny/db-dynamodb/exports/api/db.js\";\n\ninterface CreateExpressionParams {\n where: Partial<CmsEntryListWhere>;\n condition: ExpressionCondition;\n}\n\ninterface ICreateExpressionsParams {\n plugins: PluginsContainer;\n container: CmsContext[\"container\"];\n where: Partial<CmsEntryListWhere>;\n fields: Record<string, Field>;\n}\n\nexport type ExpressionCondition = \"AND\" | \"OR\";\n\nexport interface Expression {\n expressions: Expression[];\n filters: Filter[];\n condition: ExpressionCondition;\n}\n\nexport interface Filter {\n field: Field;\n path: string;\n fieldPathId: string;\n filter: ValueFilter.Interface;\n negate: boolean;\n compareValue: any;\n transformValue: <I = any, O = any>(value: I) => O;\n}\n\nexport const createExpressions = (params: ICreateExpressionsParams): Expression => {\n const { where, plugins, fields, container } = params;\n const valueFilterRegistry = container.resolve(ValueFilterRegistry);\n\n const transformValuePlugins = getMappedPlugins<CmsFieldFilterValueTransformPlugin>({\n plugins,\n type: \"cms-field-filter-value-transform\",\n property: \"fieldType\"\n });\n const fieldFilterCreatePlugins = getMappedPlugins<CmsEntryFieldFilterPlugin>({\n plugins,\n type: CmsEntryFieldFilterPlugin.type,\n property: \"fieldType\"\n });\n\n const defaultFilterCreatePlugin = fieldFilterCreatePlugins[\"*\"] as CmsEntryFieldFilterPlugin;\n\n const getFilterCreatePlugin = (type: string) => {\n const fieldType = getBaseFieldType({\n type\n });\n const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;\n if (filterCreatePlugin) {\n return filterCreatePlugin;\n }\n throw new WebinyError(\n `There is no filter create plugin for the field type \"${fieldType}\".`,\n \"MISSING_FILTER_CREATE_PLUGIN\",\n {\n fieldType\n }\n );\n };\n\n const createExpression = ({ where, condition }: CreateExpressionParams): Expression => {\n const expression: Expression = {\n filters: [],\n expressions: [],\n condition\n };\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n }\n\n /**\n * If there are \"AND\" or \"OR\" keys, let's sort them out first.\n *\n *\n * AND conditional\n */\n if (key === \"AND\") {\n const childWhereList = getWhereValues(value, key);\n const childExpression: Expression = {\n condition: \"AND\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n /**\n * OR conditional\n */\n if (key === \"OR\") {\n const childWhereList = getWhereValues(value, key);\n\n const childExpression: Expression = {\n condition: \"OR\",\n filters: [],\n expressions: []\n };\n for (const childWhere of childWhereList) {\n const result = createExpression({\n where: childWhere,\n condition: \"AND\"\n });\n childExpression.expressions.push(result);\n }\n expression.expressions.push(childExpression);\n continue;\n }\n\n const whereParams = extractWhereParams(key);\n if (!whereParams) {\n continue;\n }\n\n const { fieldId, operation, negate } = whereParams;\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field with the fieldId \"${fieldId}\".`,\n \"FIELD_ERROR\",\n {\n fieldId\n }\n );\n }\n\n /**\n * We need a filter create plugin for this type.\n */\n const filterCreatePlugin = getFilterCreatePlugin(field.type);\n\n const fieldType = getBaseFieldType(field);\n\n const transformValuePlugin: CmsFieldFilterValueTransformPlugin =\n transformValuePlugins[fieldType];\n\n const transformValueCallable = (value: any) => {\n if (!transformValuePlugin) {\n return value;\n }\n return transformValuePlugin.transform({\n field,\n value\n });\n };\n\n const result = filterCreatePlugin.create({\n key,\n value,\n valueFilterRegistry,\n transformValuePlugins,\n getFilterCreatePlugin,\n operation,\n negate,\n field,\n fields,\n compareValue: transformValue({\n value,\n transform: transformValueCallable\n }),\n transformValue: transformValueCallable\n });\n /**\n * There is a possibility of\n * - no result\n * - result being an array\n * - result being an object\n */\n if (!result || (Array.isArray(result) && result.length === 0)) {\n continue;\n }\n\n expression.filters.push(...(Array.isArray(result) ? result : [result]));\n }\n\n return expression;\n };\n\n const expression = createExpression({\n where,\n condition: \"AND\"\n });\n /**\n * If the first expression has no filters and has only one expression, put that expression as main one.\n * This will mostly be used when having an OR condition as the single expression in the root level of the where\n */\n if (expression.filters.length > 0 || expression.expressions.length !== 1) {\n return expression;\n }\n return expression.expressions[0];\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAKvC,SAASC,gBAAgB;AACzB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CAAC;IAC3E;IAEA,OAAOT,UAAU;EACrB,CAAC;EAED,MAAMA,UAAU,GAAGF,gBAAgB,CAAC;IAChCd,KAAK;IACLe,SAAS,EAAE;EACf,CAAC,CAAC;EACF;AACJ;AACA;AACA;EACI,IAAIC,UAAU,CAACC,OAAO,CAACsB,MAAM,GAAG,CAAC,IAAIvB,UAAU,CAACE,WAAW,CAACqB,MAAM,KAAK,CAAC,EAAE;IACtE,OAAOvB,UAAU;EACrB;EACA,OAAOA,UAAU,CAACE,WAAW,CAAC,CAAC,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CmsModelField } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import type { Field } from "./types";
|
|
1
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { Field } from "./types.js";
|
|
3
3
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
interface Params {
|
|
5
5
|
fields: CmsModelField[];
|
|
@@ -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,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC,qBAAqB;IAAEC,gBAAgB;IAAEC;EAAO,CAAC,GAAGL,MAAM;EACnF,OAAOC,MAAM,CAACK,MAAM,CAAkB,CAACC,UAAU,EAAEC,KAAK,KAAK;IACzD,MAAMC,SAAS,GAAGX,gBAAgB,CAACU,KAAK,CAAC;IACzC,MAAME,eAAe,GAAGP,qBAAqB,CAACM,SAAS,CAAC;IACxD,MAAME,eAAe,GAAGP,gBAAgB,CAACK,SAAS,CAAC;;IAEnD;AACR;AACA;IACQ,MAAMG,OAAO,GAAG,CACZ,GAAGV,OAAO,EACV;MACIU,OAAO,EAAEJ,KAAK,CAACI,OAAO;MACtBC,IAAI,EAAEL,KAAK,CAACK;IAChB,CAAC,CACJ,CACIC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACH,OAAO,CAAC,CACnBI,IAAI,CAAC,GAAG,CAAC;IAEdT,UAAU,CAACK,OAAO,CAAC,GAAG;MAClB,GAAG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C,MAAM;IAAE8B;EAAQ,CAAC,GAAG/B,MAAM;EAElC,MAAMG,qBAAqB,GAAGN,gBAAgB,CAAqC;IAC/EkC,OAAO;IACPC,IAAI,EAAE,kCAAkC;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EACF,MAAM7B,gBAAgB,GAAGP,gBAAgB,CAAgC;IACrEkC,OAAO;IACPC,IAAI,EAAEpC,6BAA6B,CAACoC,IAAI;IACxCC,QAAQ,EAAE;EACd,CAAC,CAAC;EAEF,MAAM1B,UAAU,GAAGR,qBAAqB,CAAC;IACrCE,MAAM,EAAEN,kBAAkB,CAAC,CAAC;IAC5BQ,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,EAAE;IACXG,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,MAAMsB,MAAM,GAAG5B,qBAAqB,CAAC;IACjCE,MAAM;IACNE,qBAAqB;IACrBC,gBAAgB;IAChBF,OAAO,EAAE,CACL;MACIU,OAAO,EAAE,QAAQ;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 {};
|