@webiny/api-headless-cms-ddb 6.0.0-beta.0 → 6.0.0-rc.1
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 -5
- package/definitions/entry.js +5 -180
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +4 -5
- package/definitions/group.js +5 -58
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +4 -5
- 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 +59 -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 -14
- 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 +11 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +26 -71
- 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 -72
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +1 -3
- 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 +5 -5
- 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 +5 -5
- package/operations/entry/filtering/createExpressions.js +27 -30
- package/operations/entry/filtering/createExpressions.js.map +1 -1
- package/operations/entry/filtering/createFields.d.ts +3 -3
- package/operations/entry/filtering/createFields.js +20 -22
- package/operations/entry/filtering/createFields.js.map +1 -1
- package/operations/entry/filtering/extractSort.d.ts +6 -6
- package/operations/entry/filtering/extractSort.js +38 -23
- package/operations/entry/filtering/extractSort.js.map +1 -1
- package/operations/entry/filtering/filter.d.ts +6 -6
- 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 +6 -14
- 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 +2 -2
- 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 +2 -2
- 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 -12
- package/operations/entry/filtering/plugins/index.js.map +1 -1
- package/operations/entry/filtering/plugins/objectFilterCreate.d.ts +2 -2
- 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 +3 -2
- package/operations/entry/filtering/plugins/refFilterCreate.js +18 -19
- package/operations/entry/filtering/plugins/refFilterCreate.js.map +1 -1
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.d.ts +2 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js +57 -0
- package/operations/entry/filtering/plugins/searchableJsonFilterCreate.js.map +1 -0
- package/operations/entry/filtering/sort.d.ts +6 -6
- package/operations/entry/filtering/sort.js +16 -20
- package/operations/entry/filtering/sort.js.map +1 -1
- package/operations/entry/filtering/systemFields.d.ts +2 -4
- package/operations/entry/filtering/systemFields.js +55 -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 +3 -4
- package/operations/entry/index.js +447 -495
- 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 -4
- 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 +20 -26
- 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 +10 -10
- 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 +2 -2
- 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 -9
- package/definitions/system.js +0 -42
- package/definitions/system.js.map +0 -1
- package/dynamoDb/storage/date.d.ts +0 -3
- package/dynamoDb/storage/date.js +0 -84
- package/dynamoDb/storage/date.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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DataLoader","cleanupItems","createPartitionKey","createPublishedSortKey","parseIdentifier","createBatchScheduleFn","createGetPublishedRevisionByEntryId","params","entity","tenant","publishedKey","ids","reader","createEntityReader","keys","Set","id","partitionKey","has","add","get","PK","SK","records","execute","items","map","item","data","entryId","filter","batchScheduleFn"],"sources":["getPublishedRevisionByEntryId.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup.js\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createPartitionKey, createPublishedSortKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\n\nexport const createGetPublishedRevisionByEntryId = (params: IDataLoaderParams) => {\n const { entity, tenant } = params;\n\n const publishedKey = createPublishedSortKey();\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const reader = entity.createEntityReader();\n\n const keys = new Set<string>();\n\n for (const id of ids) {\n const partitionKey = createPartitionKey({\n tenant,\n id\n });\n if (keys.has(partitionKey)) {\n continue;\n }\n keys.add(partitionKey);\n reader.get({\n PK: partitionKey,\n SK: publishedKey\n });\n }\n\n const records = await reader.execute();\n const items = cleanupItems(entity.entity, records).map(item => {\n return item.data;\n });\n\n return ids.map(id => {\n const { id: entryId } = parseIdentifier(id);\n return items.filter(item => {\n return entryId === item.entryId;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,YAAY;AACnC,SAASC,YAAY,QAAQ,sCAAsC;AAEnE,SAASC,kBAAkB,EAAEC,sBAAsB;AAE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;EAC3C,CACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import DataLoader from "dataloader";
|
|
2
|
-
import { CmsStorageEntry } from "@webiny/api-headless-cms/types";
|
|
3
|
-
import {
|
|
4
|
-
export declare const createGetRevisionById: (params:
|
|
2
|
+
import type { CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import type { IDataLoaderParams } from "./types.js";
|
|
4
|
+
export declare const createGetRevisionById: (params: IDataLoaderParams) => DataLoader<string, CmsStorageEntry<import("@webiny/api-headless-cms/types/types.js").CmsEntryValues>[], string>;
|
|
@@ -1,62 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.createGetRevisionById = void 0;
|
|
8
|
-
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
9
|
-
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
10
|
-
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
11
|
-
var _keys = require("../keys");
|
|
12
|
-
var _utils = require("@webiny/utils");
|
|
13
|
-
var _createBatchScheduleFn = require("./createBatchScheduleFn");
|
|
14
|
-
const createGetRevisionById = params => {
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import { cleanupItems } from "@webiny/db-dynamodb/utils/cleanup.js";
|
|
3
|
+
import { createPartitionKey, createRevisionSortKey } from "../keys.js";
|
|
4
|
+
import { parseIdentifier } from "@webiny/utils";
|
|
5
|
+
import { createBatchScheduleFn } from "./createBatchScheduleFn.js";
|
|
6
|
+
export const createGetRevisionById = params => {
|
|
15
7
|
const {
|
|
16
8
|
entity,
|
|
17
|
-
locale,
|
|
18
9
|
tenant
|
|
19
10
|
} = params;
|
|
20
|
-
return new
|
|
21
|
-
const
|
|
22
|
-
|
|
11
|
+
return new DataLoader(async ids => {
|
|
12
|
+
const reader = entity.createEntityReader();
|
|
13
|
+
const keys = new Set();
|
|
14
|
+
for (const id of ids) {
|
|
15
|
+
const partitionKey = createPartitionKey({
|
|
23
16
|
tenant,
|
|
24
|
-
locale,
|
|
25
17
|
id
|
|
26
18
|
});
|
|
27
19
|
const {
|
|
28
20
|
version
|
|
29
|
-
} =
|
|
21
|
+
} = parseIdentifier(id);
|
|
30
22
|
if (version === null) {
|
|
31
|
-
|
|
23
|
+
continue;
|
|
32
24
|
}
|
|
33
|
-
const sortKey =
|
|
25
|
+
const sortKey = createRevisionSortKey({
|
|
34
26
|
version
|
|
35
27
|
});
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
|
|
28
|
+
const key = `${partitionKey}__${sortKey}`;
|
|
29
|
+
if (keys.has(key)) {
|
|
30
|
+
continue;
|
|
39
31
|
}
|
|
40
|
-
|
|
32
|
+
keys.add(key);
|
|
33
|
+
reader.get({
|
|
41
34
|
PK: partitionKey,
|
|
42
35
|
SK: sortKey
|
|
43
36
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
items: Object.values(queries)
|
|
37
|
+
}
|
|
38
|
+
const records = await reader.execute();
|
|
39
|
+
const items = cleanupItems(entity.entity, records).map(item => {
|
|
40
|
+
return item.data;
|
|
49
41
|
});
|
|
50
|
-
const items = (0, _cleanup.cleanupItems)(entity, records);
|
|
51
42
|
return ids.map(id => {
|
|
52
43
|
return items.filter(item => {
|
|
53
44
|
return id === item.id;
|
|
54
45
|
});
|
|
55
46
|
});
|
|
56
47
|
}, {
|
|
57
|
-
batchScheduleFn:
|
|
48
|
+
batchScheduleFn: createBatchScheduleFn()
|
|
58
49
|
});
|
|
59
50
|
};
|
|
60
|
-
exports.createGetRevisionById = createGetRevisionById;
|
|
61
51
|
|
|
62
52
|
//# sourceMappingURL=getRevisionById.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["DataLoader","cleanupItems","createPartitionKey","createRevisionSortKey","parseIdentifier","createBatchScheduleFn","createGetRevisionById","params","entity","tenant","ids","reader","createEntityReader","keys","Set","id","partitionKey","version","sortKey","key","has","add","get","PK","SK","records","execute","items","map","item","data","filter","batchScheduleFn"],"sources":["getRevisionById.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport type { CmsStorageEntry } from \"@webiny/api-headless-cms/types/index.js\";\nimport { cleanupItems } from \"@webiny/db-dynamodb/utils/cleanup.js\";\nimport { createPartitionKey, createRevisionSortKey } from \"~/operations/entry/keys.js\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { createBatchScheduleFn } from \"./createBatchScheduleFn.js\";\n\nexport const createGetRevisionById = (params: IDataLoaderParams) => {\n const { entity, tenant } = params;\n\n return new DataLoader<string, CmsStorageEntry[]>(\n async ids => {\n const reader = entity.createEntityReader();\n\n const keys = new Set<string>();\n\n for (const id of ids) {\n const partitionKey = createPartitionKey({\n tenant,\n id\n });\n const { version } = parseIdentifier(id);\n if (version === null) {\n continue;\n }\n const sortKey = createRevisionSortKey({\n version\n });\n const key = `${partitionKey}__${sortKey}`;\n if (keys.has(key)) {\n continue;\n }\n keys.add(key);\n\n reader.get({\n PK: partitionKey,\n SK: sortKey\n });\n }\n\n const records = await reader.execute();\n const items = cleanupItems(entity.entity, records).map(item => {\n return item.data;\n });\n\n return ids.map(id => {\n return items.filter(item => {\n return id === item.id;\n });\n });\n },\n {\n batchScheduleFn: createBatchScheduleFn()\n }\n );\n};\n"],"mappings":"AAAA,OAAOA,UAAU,MAAM,YAAY;AAEnC,SAASC,YAAY,QAAQ,sCAAsC;AACnE,SAASC,kBAAkB,EAAEC,qBAAqB;AAElD,SAASC,eAAe,QAAQ,eAAe;AAC/C,SAASC,qBAAqB;AAE9B,OAAO,MAAMC,qBAAqB,GAAIC,MAAyB,IAAK;EAChE,MAAM;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGF,MAAM;EAEjC,O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8 @@
|
|
|
1
|
-
import DataLoader from "dataloader";
|
|
2
|
-
import {
|
|
3
|
-
export * from "./DataLoaderCache";
|
|
1
|
+
import type DataLoader from "dataloader";
|
|
2
|
+
import type { IDataLoaderParams } from "./types.js";
|
|
3
|
+
export * from "./DataLoaderCache.js";
|
|
4
4
|
interface Callable {
|
|
5
|
-
(params:
|
|
5
|
+
(params: IDataLoaderParams): DataLoader<any, any>;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type DataLoaders = "getAllEntryRevisions" | "getRevisionById" | "getPublishedRevisionByEntryId" | "getLatestRevisionByEntryId";
|
|
8
8
|
export declare const getDataLoaderFactory: (name: string) => Callable;
|
|
@@ -1,40 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
getDataLoaderFactory: true
|
|
8
|
-
};
|
|
9
|
-
exports.getDataLoaderFactory = void 0;
|
|
10
|
-
var _getAllEntryRevisions = require("./getAllEntryRevisions");
|
|
11
|
-
var _getLatestRevisionByEntryId = require("./getLatestRevisionByEntryId");
|
|
12
|
-
var _getPublishedRevisionByEntryId = require("./getPublishedRevisionByEntryId");
|
|
13
|
-
var _getRevisionById = require("./getRevisionById");
|
|
14
|
-
var _DataLoaderCache = require("./DataLoaderCache");
|
|
15
|
-
Object.keys(_DataLoaderCache).forEach(function (key) {
|
|
16
|
-
if (key === "default" || key === "__esModule") return;
|
|
17
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
18
|
-
if (key in exports && exports[key] === _DataLoaderCache[key]) return;
|
|
19
|
-
Object.defineProperty(exports, key, {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return _DataLoaderCache[key];
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
1
|
+
import { createGetAllEntryRevisions } from "./getAllEntryRevisions.js";
|
|
2
|
+
import { createGetLatestRevisionByEntryId } from "./getLatestRevisionByEntryId.js";
|
|
3
|
+
import { createGetPublishedRevisionByEntryId } from "./getPublishedRevisionByEntryId.js";
|
|
4
|
+
import { createGetRevisionById } from "./getRevisionById.js";
|
|
5
|
+
export * from "./DataLoaderCache.js";
|
|
26
6
|
const dataLoaders = {
|
|
27
|
-
getAllEntryRevisions:
|
|
28
|
-
getLatestRevisionByEntryId:
|
|
29
|
-
getPublishedRevisionByEntryId:
|
|
30
|
-
getRevisionById:
|
|
7
|
+
getAllEntryRevisions: createGetAllEntryRevisions,
|
|
8
|
+
getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,
|
|
9
|
+
getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,
|
|
10
|
+
getRevisionById: createGetRevisionById
|
|
31
11
|
};
|
|
32
|
-
const getDataLoaderFactory = name => {
|
|
12
|
+
export const getDataLoaderFactory = name => {
|
|
33
13
|
if (!dataLoaders[name]) {
|
|
34
14
|
throw new Error(`Missing data loader "${name}".`);
|
|
35
15
|
}
|
|
36
16
|
return dataLoaders[name];
|
|
37
17
|
};
|
|
38
|
-
exports.getDataLoaderFactory = getDataLoaderFactory;
|
|
39
18
|
|
|
40
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createGetAllEntryRevisions","createGetLatestRevisionByEntryId","createGetPublishedRevisionByEntryId","createGetRevisionById","dataLoaders","getAllEntryRevisions","getLatestRevisionByEntryId","getPublishedRevisionByEntryId","getRevisionById","getDataLoaderFactory","name","Error"],"sources":["index.ts"],"sourcesContent":["import type DataLoader from \"dataloader\";\nimport type { IDataLoaderParams } from \"./types.js\";\nimport { createGetAllEntryRevisions } from \"./getAllEntryRevisions.js\";\nimport { createGetLatestRevisionByEntryId } from \"./getLatestRevisionByEntryId.js\";\nimport { createGetPublishedRevisionByEntryId } from \"./getPublishedRevisionByEntryId.js\";\nimport { createGetRevisionById } from \"./getRevisionById.js\";\n\nexport * from \"./DataLoaderCache.js\";\n\ninterface Callable {\n (params: IDataLoaderParams): DataLoader<any, any>;\n}\n\nconst dataLoaders: Record<string, Callable> = {\n getAllEntryRevisions: createGetAllEntryRevisions,\n getLatestRevisionByEntryId: createGetLatestRevisionByEntryId,\n getPublishedRevisionByEntryId: createGetPublishedRevisionByEntryId,\n getRevisionById: createGetRevisionById\n};\n\nexport type DataLoaders =\n | \"getAllEntryRevisions\"\n | \"getRevisionById\"\n | \"getPublishedRevisionByEntryId\"\n | \"getLatestRevisionByEntryId\";\n\nexport const getDataLoaderFactory = (name: string) => {\n if (!dataLoaders[name]) {\n throw new Error(`Missing data loader \"${name}\".`);\n }\n return dataLoaders[name];\n};\n"],"mappings":"AAEA,SAASA,0BAA0B;AACnC,SAASC,gCAAgC;AACzC,SAASC,mCAAmC;AAC5C,SAASC,qBAAqB;AAE9B;AAMA,MAAMC,WAAqC,GAAG;EAC1CC,oBAAoB,EAAEL,0BAA0B;EAChDM,0BAA0B,EAAEL,gCAAgC;EAC5DM,6BAA6B,EAAEL,mCAAmC;EAClEM,eAAe,EAAEL;AACrB,CAAC;AAQD,OAAO,MAAMM,oBAAoB,GAAIC,IAAY,IAAK;EAClD,IAAI,CAACN,WAAW,CAACM,IAAI,CAAC,EAAE;IACpB,MAAM,IAAIC,KAAK,CAAC,wBAAwBD,IAAI,IAAI,CAAC;EACrD;EACA,OAAON,WAAW,CAACM,IAAI,CAAC;AAC5B,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface
|
|
3
|
-
entity:
|
|
1
|
+
import type { IEntryEntity } from "../../../definitions/types.js";
|
|
2
|
+
export interface IDataLoaderParams {
|
|
3
|
+
entity: IEntryEntity;
|
|
4
4
|
tenant: string;
|
|
5
|
-
locale: string;
|
|
6
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { IEntryEntity } from \"~/definitions/types.js\";\n\nexport interface IDataLoaderParams {\n entity: IEntryEntity;\n tenant: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import {
|
|
3
|
-
import { DataLoadersHandlerInterface, DataLoadersHandlerInterfaceClearAllParams } from "../../types";
|
|
1
|
+
import type { CmsEntryValues, CmsModel, CmsStorageEntry } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import type { DataLoadersHandlerInterfaceClearAllParams, IDataLoadersHandler, IEntryEntity } from "../../types.js";
|
|
4
3
|
interface DataLoaderParams {
|
|
5
|
-
model: Pick<CmsModel, "tenant" | "
|
|
4
|
+
model: Pick<CmsModel, "tenant" | "modelId">;
|
|
6
5
|
ids: readonly string[];
|
|
7
6
|
}
|
|
8
|
-
interface
|
|
9
|
-
entity:
|
|
7
|
+
interface IDataLoadersHandlerParams {
|
|
8
|
+
entity: IEntryEntity;
|
|
10
9
|
}
|
|
11
|
-
export declare class DataLoadersHandler implements
|
|
10
|
+
export declare class DataLoadersHandler implements IDataLoadersHandler {
|
|
12
11
|
private readonly entity;
|
|
13
12
|
private readonly cache;
|
|
14
|
-
constructor(params:
|
|
15
|
-
getAllEntryRevisions(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
16
|
-
getRevisionById(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
17
|
-
getPublishedRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
18
|
-
getLatestRevisionByEntryId(params: DataLoaderParams): Promise<CmsStorageEntry[]>;
|
|
13
|
+
constructor(params: IDataLoadersHandlerParams);
|
|
14
|
+
getAllEntryRevisions<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
|
|
15
|
+
getRevisionById<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
|
|
16
|
+
getPublishedRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
|
|
17
|
+
getLatestRevisionByEntryId<T extends CmsEntryValues = CmsEntryValues>(params: DataLoaderParams): Promise<CmsStorageEntry<T>[]>;
|
|
19
18
|
/**
|
|
20
19
|
* TODO @ts-refactor
|
|
21
20
|
* Maybe pass on the generics to DataLoader definition?
|
|
@@ -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,16 @@ class DataLoadersHandler {
|
|
|
55
48
|
} = params;
|
|
56
49
|
const cacheParams = {
|
|
57
50
|
tenant: model.tenant,
|
|
58
|
-
locale: model.locale,
|
|
59
51
|
name
|
|
60
52
|
};
|
|
61
53
|
let loader = this.cache.getDataLoader(cacheParams);
|
|
62
54
|
if (loader) {
|
|
63
55
|
return loader;
|
|
64
56
|
}
|
|
65
|
-
const factory =
|
|
57
|
+
const factory = getDataLoaderFactory(name);
|
|
66
58
|
loader = factory({
|
|
67
59
|
entity: this.entity,
|
|
68
|
-
tenant: model.tenant
|
|
69
|
-
locale: model.locale
|
|
60
|
+
tenant: model.tenant
|
|
70
61
|
});
|
|
71
62
|
this.cache.setDataLoader(cacheParams, loader);
|
|
72
63
|
return loader;
|
|
@@ -79,12 +70,12 @@ class DataLoadersHandler {
|
|
|
79
70
|
return results.reduce((acc, res) => {
|
|
80
71
|
if (Array.isArray(res) === false) {
|
|
81
72
|
if (res && res.message) {
|
|
82
|
-
throw new
|
|
73
|
+
throw new WebinyError(res.message, res.code, {
|
|
83
74
|
...res,
|
|
84
75
|
data: JSON.stringify(res.data || {})
|
|
85
76
|
});
|
|
86
77
|
}
|
|
87
|
-
throw new
|
|
78
|
+
throw new WebinyError("Result from the data loader must be an array of arrays which contain requested items.", "DATA_LOADER_RESULTS_ERROR", {
|
|
88
79
|
...params,
|
|
89
80
|
loader
|
|
90
81
|
});
|
|
@@ -94,14 +85,14 @@ class DataLoadersHandler {
|
|
|
94
85
|
}, []);
|
|
95
86
|
}
|
|
96
87
|
} catch (ex) {
|
|
97
|
-
throw new
|
|
88
|
+
throw new WebinyError(ex.message || "Data loader error.", ex.code || "DATA_LOADER_ERROR", {
|
|
98
89
|
error: ex,
|
|
99
90
|
...params,
|
|
100
91
|
loader,
|
|
101
92
|
ids
|
|
102
93
|
});
|
|
103
94
|
}
|
|
104
|
-
throw new
|
|
95
|
+
throw new WebinyError(`Data loader did not return array of items or empty array.`, "INVALID_DATA_LOADER_RESULT", {
|
|
105
96
|
loader,
|
|
106
97
|
ids,
|
|
107
98
|
results
|
|
@@ -111,6 +102,5 @@ class DataLoadersHandler {
|
|
|
111
102
|
this.cache.clearAll(params?.model);
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
|
-
exports.DataLoadersHandler = DataLoadersHandler;
|
|
115
105
|
|
|
116
106
|
//# 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","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 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 });\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,WAAW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,CAAC;YACN;YACA,MAAM,IAAInC,WAAW,CACjB,uFAAuF,EACvF,2BAA2B,EAC3B;cACI,GAAGO,MAAM;cACTgB;YACJ,CACJ,CAAC;UACL;UACAQ,GAAG,CAACO,IAAI,CAAC,GAAGN,GAAG,CAAC;UAChB,OAAOD,GAAG;QACd,CAAC,EAAE,EAAE,CAAC;MACV;IACJ,CAAC,CAAC,OAAOQ,EAAE,EAAE;MACT,MAAM,IAAIvC,WAAW,CACjBuC,EAAE,CAACN,OAAO,IAAI,oBAAoB,EAClCM,EAAE,CAACL,IAAI,IAAI,mBAAmB,EAC9B;QACIM,KAAK,EAAED,EAAE;QACT,GAAGhC,MAAM;QACTgB,MAAM;QACNb;MACJ,CACJ,CAAC;IACL;IACA,MAAM,IAAIV,WAAW,CACjB,2DAA2D,EAC3D,4BAA4B,EAC5B;MACIuB,MAAM;MACNb,GAAG;MACHiB;IACJ,CACJ,CAAC;EACL;EAEOc,QAAQA,CAAClC,MAAkD,EAAQ;IACtE,IAAI,CAACF,KAAK,CAACoC,QAAQ,CAAClC,MAAM,EAAEa,KAAK,CAAC;EACtC;AACJ","ignoreList":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
|
|
2
|
-
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin";
|
|
3
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
4
|
-
import { Field } from "./types";
|
|
1
|
+
import type { CmsEntryListWhere } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
+
import { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
3
|
+
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
|
+
import type { Field } from "./types.js";
|
|
5
5
|
interface Params {
|
|
6
6
|
plugins: PluginsContainer;
|
|
7
7
|
where: Partial<CmsEntryListWhere>;
|
|
8
8
|
fields: Record<string, Field>;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export type ExpressionCondition = "AND" | "OR";
|
|
11
11
|
export interface Expression {
|
|
12
12
|
expressions: Expression[];
|
|
13
13
|
filters: Filter[];
|
|
@@ -1,46 +1,43 @@
|
|
|
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 { ValueFilterPlugin } from "@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin.js";
|
|
3
|
+
import { getMappedPlugins } from "./mapPlugins.js";
|
|
4
|
+
import { extractWhereParams } from "./where.js";
|
|
5
|
+
import { transformValue } from "./transform.js";
|
|
6
|
+
import { CmsEntryFieldFilterPlugin } from "../../../plugins/CmsEntryFieldFilterPlugin.js";
|
|
7
|
+
import { getWhereValues } from "./values.js";
|
|
8
|
+
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
9
|
+
export const createExpressions = params => {
|
|
16
10
|
const {
|
|
17
11
|
where,
|
|
18
12
|
plugins,
|
|
19
13
|
fields
|
|
20
14
|
} = params;
|
|
21
|
-
const filterPlugins =
|
|
15
|
+
const filterPlugins = getMappedPlugins({
|
|
22
16
|
plugins,
|
|
23
|
-
type:
|
|
17
|
+
type: ValueFilterPlugin.type,
|
|
24
18
|
property: "operation"
|
|
25
19
|
});
|
|
26
|
-
const transformValuePlugins =
|
|
20
|
+
const transformValuePlugins = getMappedPlugins({
|
|
27
21
|
plugins,
|
|
28
22
|
type: "cms-field-filter-value-transform",
|
|
29
23
|
property: "fieldType"
|
|
30
24
|
});
|
|
31
|
-
const fieldFilterCreatePlugins =
|
|
25
|
+
const fieldFilterCreatePlugins = getMappedPlugins({
|
|
32
26
|
plugins,
|
|
33
|
-
type:
|
|
27
|
+
type: CmsEntryFieldFilterPlugin.type,
|
|
34
28
|
property: "fieldType"
|
|
35
29
|
});
|
|
36
30
|
const defaultFilterCreatePlugin = fieldFilterCreatePlugins["*"];
|
|
37
31
|
const getFilterCreatePlugin = type => {
|
|
38
|
-
const
|
|
32
|
+
const fieldType = getBaseFieldType({
|
|
33
|
+
type
|
|
34
|
+
});
|
|
35
|
+
const filterCreatePlugin = fieldFilterCreatePlugins[fieldType] || defaultFilterCreatePlugin;
|
|
39
36
|
if (filterCreatePlugin) {
|
|
40
37
|
return filterCreatePlugin;
|
|
41
38
|
}
|
|
42
|
-
throw new
|
|
43
|
-
|
|
39
|
+
throw new WebinyError(`There is no filter create plugin for the field type "${fieldType}".`, "MISSING_FILTER_CREATE_PLUGIN", {
|
|
40
|
+
fieldType
|
|
44
41
|
});
|
|
45
42
|
};
|
|
46
43
|
const createExpression = ({
|
|
@@ -65,7 +62,7 @@ const createExpressions = params => {
|
|
|
65
62
|
* AND conditional
|
|
66
63
|
*/
|
|
67
64
|
if (key === "AND") {
|
|
68
|
-
const childWhereList =
|
|
65
|
+
const childWhereList = getWhereValues(value, key);
|
|
69
66
|
const childExpression = {
|
|
70
67
|
condition: "AND",
|
|
71
68
|
filters: [],
|
|
@@ -85,7 +82,7 @@ const createExpressions = params => {
|
|
|
85
82
|
* OR conditional
|
|
86
83
|
*/
|
|
87
84
|
if (key === "OR") {
|
|
88
|
-
const childWhereList =
|
|
85
|
+
const childWhereList = getWhereValues(value, key);
|
|
89
86
|
const childExpression = {
|
|
90
87
|
condition: "OR",
|
|
91
88
|
filters: [],
|
|
@@ -101,7 +98,7 @@ const createExpressions = params => {
|
|
|
101
98
|
expression.expressions.push(childExpression);
|
|
102
99
|
continue;
|
|
103
100
|
}
|
|
104
|
-
const whereParams =
|
|
101
|
+
const whereParams = extractWhereParams(key);
|
|
105
102
|
if (!whereParams) {
|
|
106
103
|
continue;
|
|
107
104
|
}
|
|
@@ -112,7 +109,7 @@ const createExpressions = params => {
|
|
|
112
109
|
} = whereParams;
|
|
113
110
|
const field = fields[fieldId];
|
|
114
111
|
if (!field) {
|
|
115
|
-
throw new
|
|
112
|
+
throw new WebinyError(`There is no field with the fieldId "${fieldId}".`, "FIELD_ERROR", {
|
|
116
113
|
fieldId
|
|
117
114
|
});
|
|
118
115
|
}
|
|
@@ -121,7 +118,8 @@ const createExpressions = params => {
|
|
|
121
118
|
* We need a filter create plugin for this type.
|
|
122
119
|
*/
|
|
123
120
|
const filterCreatePlugin = getFilterCreatePlugin(field.type);
|
|
124
|
-
const
|
|
121
|
+
const fieldType = getBaseFieldType(field);
|
|
122
|
+
const transformValuePlugin = transformValuePlugins[fieldType];
|
|
125
123
|
const transformValueCallable = value => {
|
|
126
124
|
if (!transformValuePlugin) {
|
|
127
125
|
return value;
|
|
@@ -141,7 +139,7 @@ const createExpressions = params => {
|
|
|
141
139
|
negate,
|
|
142
140
|
field,
|
|
143
141
|
fields,
|
|
144
|
-
compareValue:
|
|
142
|
+
compareValue: transformValue({
|
|
145
143
|
value,
|
|
146
144
|
transform: transformValueCallable
|
|
147
145
|
}),
|
|
@@ -173,6 +171,5 @@ const createExpressions = params => {
|
|
|
173
171
|
}
|
|
174
172
|
return expression.expressions[0];
|
|
175
173
|
};
|
|
176
|
-
exports.createExpressions = createExpressions;
|
|
177
174
|
|
|
178
175
|
//# sourceMappingURL=createExpressions.js.map
|