@webiny/api-headless-cms-storage 6.6.0-alpha.0 → 6.6.0-alpha.10
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/{dist/cms → cms}/storageHelpers.js +3 -3
- package/cms/storageHelpers.js.map +1 -0
- package/features/FilterRegistriesFeature.d.ts +9 -0
- package/features/FilterRegistriesFeature.js +17 -0
- package/features/FilterRegistriesFeature.js.map +1 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.d.ts +9 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js +26 -0
- package/features/fieldFilterCreate/DefaultFieldFilterCreateRegistry.js.map +1 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.d.ts +9 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js +20 -0
- package/features/fieldFilterPath/DefaultFieldFilterPathRegistry.js.map +1 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.d.ts +9 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js +17 -0
- package/features/fieldFilterValueTransform/DefaultFieldFilterValueTransformRegistry.js.map +1 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.d.ts +8 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.js +11 -0
- package/features/fieldSorting/DefaultFieldSortingRegistry.js.map +1 -0
- package/{dist/filtering → filtering}/fields/createFields.d.ts +2 -0
- package/{dist/filtering → filtering}/fields/createFields.js +2 -2
- package/filtering/fields/createFields.js.map +1 -0
- package/{dist/filtering → filtering}/fields/extractSort.js +1 -1
- package/{dist/filtering → filtering}/fields/extractSort.js.map +1 -1
- package/filtering/fields/systemFields.d.ts +5 -0
- package/{dist/filtering → filtering}/fields/systemFields.js +17 -1
- package/filtering/fields/systemFields.js.map +1 -0
- package/{dist/filtering → filtering}/filter.js +1 -1
- package/{dist/filtering → filtering}/filter.js.map +1 -1
- package/{dist/filtering → filtering}/getValue.js +2 -2
- package/{dist/filtering → filtering}/getValue.js.map +1 -1
- package/{dist/filtering → filtering}/sort.js +1 -1
- package/{dist/filtering → filtering}/sort.js.map +1 -1
- package/{dist/handlers → handlers}/datetimeTransformHandler.js +3 -3
- package/{dist/handlers → handlers}/datetimeTransformHandler.js.map +1 -1
- package/{dist/handlers → handlers}/locationFolderIdPathHandler.js +1 -1
- package/{dist/handlers → handlers}/locationFolderIdPathHandler.js.map +1 -1
- package/package.json +20 -15
- package/{dist/path → path}/locationFolderId.js +1 -1
- package/{dist/path → path}/locationFolderId.js.map +1 -1
- package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js +2 -2
- package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.js.map +1 -1
- package/{dist/transforms → transforms}/datetime.js +3 -3
- package/{dist/transforms → transforms}/datetime.js.map +1 -1
- package/__tests__/filtering/getValue.test.ts +0 -58
- package/__tests__/filtering/mocks/entry.noModel.ts +0 -110
- package/__tests__/path/plainObject.test.ts +0 -32
- package/__tests__/transforms/datetime.test.ts +0 -71
- package/dist/cms/storageHelpers.js.map +0 -1
- package/dist/features/FilterRegistriesFeature.d.ts +0 -4
- package/dist/features/FilterRegistriesFeature.js +0 -39
- package/dist/features/FilterRegistriesFeature.js.map +0 -1
- package/dist/filtering/fields/createFields.js.map +0 -1
- package/dist/filtering/fields/systemFields.d.ts +0 -2
- package/dist/filtering/fields/systemFields.js.map +0 -1
- package/dist/package.json +0 -30
- package/src/cms/storageHelpers.ts +0 -92
- package/src/features/FilterRegistriesFeature.ts +0 -40
- package/src/features/fieldFilterCreate/FieldFilterCreateRegistry.ts +0 -25
- package/src/features/fieldFilterCreate/abstractions.ts +0 -51
- package/src/features/fieldFilterPath/FieldFilterPathRegistry.ts +0 -13
- package/src/features/fieldFilterPath/abstractions.ts +0 -22
- package/src/features/fieldFilterValueTransform/FieldFilterValueTransformRegistry.ts +0 -15
- package/src/features/fieldFilterValueTransform/abstractions.ts +0 -21
- package/src/features/fieldSorting/FieldSortingRegistry.ts +0 -20
- package/src/features/fieldSorting/abstractions.ts +0 -49
- package/src/filtering/expressions/createExpressions.ts +0 -170
- package/src/filtering/fields/createFields.ts +0 -124
- package/src/filtering/fields/extractSort.ts +0 -97
- package/src/filtering/fields/systemFields.ts +0 -165
- package/src/filtering/fields/types.ts +0 -46
- package/src/filtering/filter.ts +0 -166
- package/src/filtering/fullTextSearch.ts +0 -40
- package/src/filtering/getValue.ts +0 -64
- package/src/filtering/mapPlugins.ts +0 -30
- package/src/filtering/plugins/defaultFilterCreate.ts +0 -36
- package/src/filtering/plugins/index.ts +0 -13
- package/src/filtering/plugins/objectFilterCreate.ts +0 -100
- package/src/filtering/plugins/refFilterCreate.ts +0 -83
- package/src/filtering/plugins/searchableJsonFilterCreate.ts +0 -78
- package/src/filtering/sort.ts +0 -79
- package/src/filtering/transform.ts +0 -11
- package/src/filtering/values.ts +0 -24
- package/src/filtering/where.ts +0 -24
- package/src/handlers/datetimeTransformHandler.ts +0 -52
- package/src/handlers/defaultFilterCreateHandler.ts +0 -31
- package/src/handlers/locationFolderIdPathHandler.ts +0 -24
- package/src/handlers/objectFilterCreateHandler.ts +0 -86
- package/src/handlers/plainObjectPathHandler.ts +0 -17
- package/src/handlers/refFilterCreateHandler.ts +0 -65
- package/src/handlers/searchableJsonFilterCreateHandler.ts +0 -61
- package/src/index.ts +0 -63
- package/src/path/locationFolderId.ts +0 -29
- package/src/path/plainObject.ts +0 -21
- package/src/plugins/CmsEntryFieldFilterPathPlugin.ts +0 -58
- package/src/plugins/CmsEntryFieldFilterPlugin.ts +0 -59
- package/src/plugins/CmsEntryFieldSortingPlugin.ts +0 -63
- package/src/plugins/CmsFieldFilterValueTransformPlugin.ts +0 -43
- package/src/plugins/index.ts +0 -10
- package/src/transforms/datetime.ts +0 -62
- package/tsconfig.build.json +0 -33
- package/tsconfig.json +0 -33
- package/vitest.config.ts +0 -5
- package/webiny.config.js +0 -8
- /package/{dist/LICENSE → LICENSE} +0 -0
- /package/{dist/README.md → README.md} +0 -0
- /package/{dist/cms → cms}/storageHelpers.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js +0 -0
- /package/{dist/features → features}/fieldFilterCreate/FieldFilterCreateRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldFilterCreate/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterCreate/abstractions.js +0 -0
- /package/{dist/features → features}/fieldFilterCreate/abstractions.js.map +0 -0
- /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js +0 -0
- /package/{dist/features → features}/fieldFilterPath/FieldFilterPathRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldFilterPath/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterPath/abstractions.js +0 -0
- /package/{dist/features → features}/fieldFilterPath/abstractions.js.map +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/FieldFilterValueTransformRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js +0 -0
- /package/{dist/features → features}/fieldFilterValueTransform/abstractions.js.map +0 -0
- /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.d.ts +0 -0
- /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js +0 -0
- /package/{dist/features → features}/fieldSorting/FieldSortingRegistry.js.map +0 -0
- /package/{dist/features → features}/fieldSorting/abstractions.d.ts +0 -0
- /package/{dist/features → features}/fieldSorting/abstractions.js +0 -0
- /package/{dist/features → features}/fieldSorting/abstractions.js.map +0 -0
- /package/{dist/filtering → filtering}/expressions/createExpressions.d.ts +0 -0
- /package/{dist/filtering → filtering}/expressions/createExpressions.js +0 -0
- /package/{dist/filtering → filtering}/expressions/createExpressions.js.map +0 -0
- /package/{dist/filtering → filtering}/fields/extractSort.d.ts +0 -0
- /package/{dist/filtering → filtering}/fields/types.d.ts +0 -0
- /package/{dist/filtering → filtering}/fields/types.js +0 -0
- /package/{dist/filtering → filtering}/filter.d.ts +0 -0
- /package/{dist/filtering → filtering}/fullTextSearch.d.ts +0 -0
- /package/{dist/filtering → filtering}/fullTextSearch.js +0 -0
- /package/{dist/filtering → filtering}/fullTextSearch.js.map +0 -0
- /package/{dist/filtering → filtering}/getValue.d.ts +0 -0
- /package/{dist/filtering → filtering}/mapPlugins.d.ts +0 -0
- /package/{dist/filtering → filtering}/mapPlugins.js +0 -0
- /package/{dist/filtering → filtering}/mapPlugins.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/defaultFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/index.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/index.js +0 -0
- /package/{dist/filtering → filtering}/plugins/index.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/objectFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/objectFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/refFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/refFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/refFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.d.ts +0 -0
- /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js +0 -0
- /package/{dist/filtering → filtering}/plugins/searchableJsonFilterCreate.js.map +0 -0
- /package/{dist/filtering → filtering}/sort.d.ts +0 -0
- /package/{dist/filtering → filtering}/transform.d.ts +0 -0
- /package/{dist/filtering → filtering}/transform.js +0 -0
- /package/{dist/filtering → filtering}/transform.js.map +0 -0
- /package/{dist/filtering → filtering}/values.d.ts +0 -0
- /package/{dist/filtering → filtering}/values.js +0 -0
- /package/{dist/filtering → filtering}/values.js.map +0 -0
- /package/{dist/filtering → filtering}/where.d.ts +0 -0
- /package/{dist/filtering → filtering}/where.js +0 -0
- /package/{dist/filtering → filtering}/where.js.map +0 -0
- /package/{dist/handlers → handlers}/datetimeTransformHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/defaultFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/defaultFilterCreateHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/locationFolderIdPathHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/objectFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/objectFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/objectFilterCreateHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/plainObjectPathHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/plainObjectPathHandler.js +0 -0
- /package/{dist/handlers → handlers}/plainObjectPathHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/refFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/refFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/refFilterCreateHandler.js.map +0 -0
- /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.d.ts +0 -0
- /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js +0 -0
- /package/{dist/handlers → handlers}/searchableJsonFilterCreateHandler.js.map +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/path → path}/locationFolderId.d.ts +0 -0
- /package/{dist/path → path}/plainObject.d.ts +0 -0
- /package/{dist/path → path}/plainObject.js +0 -0
- /package/{dist/path → path}/plainObject.js.map +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPathPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldFilterPlugin.js.map +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js +0 -0
- /package/{dist/plugins → plugins}/CmsEntryFieldSortingPlugin.js.map +0 -0
- /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.d.ts +0 -0
- /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js +0 -0
- /package/{dist/plugins → plugins}/CmsFieldFilterValueTransformPlugin.js.map +0 -0
- /package/{dist/plugins → plugins}/index.d.ts +0 -0
- /package/{dist/plugins → plugins}/index.js +0 -0
- /package/{dist/transforms → transforms}/datetime.d.ts +0 -0
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { createFeature } from "@webiny/feature/api/index.js";
|
|
2
|
-
import { FieldFilterPathRegistry } from "./fieldFilterPath/abstractions.js";
|
|
3
|
-
import { FieldFilterValueTransformRegistry } from "./fieldFilterValueTransform/abstractions.js";
|
|
4
|
-
import { FieldFilterCreateRegistry } from "./fieldFilterCreate/abstractions.js";
|
|
5
|
-
import { FieldSortingRegistry } from "./fieldSorting/abstractions.js";
|
|
6
|
-
import { FieldFilterPathRegistryImpl } from "./fieldFilterPath/FieldFilterPathRegistry.js";
|
|
7
|
-
import { FieldFilterValueTransformRegistryImpl } from "./fieldFilterValueTransform/FieldFilterValueTransformRegistry.js";
|
|
8
|
-
import { FieldFilterCreateRegistryImpl } from "./fieldFilterCreate/FieldFilterCreateRegistry.js";
|
|
9
|
-
import { FieldSortingRegistryImpl } from "./fieldSorting/FieldSortingRegistry.js";
|
|
10
|
-
import { createPlainObjectPathHandler } from "../handlers/plainObjectPathHandler.js";
|
|
11
|
-
import { createLocationFolderIdPathHandler } from "../handlers/locationFolderIdPathHandler.js";
|
|
12
|
-
import { createDatetimeTransformHandler } from "../handlers/datetimeTransformHandler.js";
|
|
13
|
-
import { createDefaultFilterCreateHandler } from "../handlers/defaultFilterCreateHandler.js";
|
|
14
|
-
import { createRefFilterCreateHandler } from "../handlers/refFilterCreateHandler.js";
|
|
15
|
-
import { createObjectFilterCreateHandler } from "../handlers/objectFilterCreateHandler.js";
|
|
16
|
-
import { createSearchableJsonFilterCreateHandler } from "../handlers/searchableJsonFilterCreateHandler.js";
|
|
17
|
-
|
|
18
|
-
export const FilterRegistriesFeature = createFeature({
|
|
19
|
-
name: "cms.storage.filterRegistries",
|
|
20
|
-
register: container => {
|
|
21
|
-
const pathRegistry = new FieldFilterPathRegistryImpl();
|
|
22
|
-
pathRegistry.register("plainObject", createPlainObjectPathHandler());
|
|
23
|
-
pathRegistry.register("text", createLocationFolderIdPathHandler());
|
|
24
|
-
container.registerInstance(FieldFilterPathRegistry, pathRegistry);
|
|
25
|
-
|
|
26
|
-
const transformRegistry = new FieldFilterValueTransformRegistryImpl();
|
|
27
|
-
transformRegistry.register("datetime", createDatetimeTransformHandler());
|
|
28
|
-
container.registerInstance(FieldFilterValueTransformRegistry, transformRegistry);
|
|
29
|
-
|
|
30
|
-
const filterCreateRegistry = new FieldFilterCreateRegistryImpl();
|
|
31
|
-
filterCreateRegistry.register("*", createDefaultFilterCreateHandler());
|
|
32
|
-
filterCreateRegistry.register("ref", createRefFilterCreateHandler());
|
|
33
|
-
filterCreateRegistry.register("object", createObjectFilterCreateHandler());
|
|
34
|
-
filterCreateRegistry.register("searchable-json", createSearchableJsonFilterCreateHandler());
|
|
35
|
-
container.registerInstance(FieldFilterCreateRegistry, filterCreateRegistry);
|
|
36
|
-
|
|
37
|
-
const sortingRegistry = new FieldSortingRegistryImpl();
|
|
38
|
-
container.registerInstance(FieldSortingRegistry, sortingRegistry);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import WebinyError from "@webiny/error";
|
|
2
|
-
import type { FieldFilterCreateRegistry } from "./abstractions.js";
|
|
3
|
-
|
|
4
|
-
export class FieldFilterCreateRegistryImpl implements FieldFilterCreateRegistry.Interface {
|
|
5
|
-
private readonly handlers = new Map<string, FieldFilterCreateRegistry.Handler>();
|
|
6
|
-
|
|
7
|
-
public register(fieldType: string, handler: FieldFilterCreateRegistry.Handler): void {
|
|
8
|
-
this.handlers.set(fieldType, handler);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public get(fieldType: string): FieldFilterCreateRegistry.Handler | undefined {
|
|
12
|
-
return this.handlers.get(fieldType);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public getDefault(): FieldFilterCreateRegistry.Handler {
|
|
16
|
-
const handler = this.handlers.get("*");
|
|
17
|
-
if (!handler) {
|
|
18
|
-
throw new WebinyError(
|
|
19
|
-
"No default filter create handler registered.",
|
|
20
|
-
"MISSING_DEFAULT_HANDLER"
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return handler;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Abstraction } from "@webiny/di";
|
|
2
|
-
import type { Field } from "../../filtering/fields/types.js";
|
|
3
|
-
import type { ValueFilterRegistry } from "@webiny/db-utils";
|
|
4
|
-
import type { FieldFilterValueTransformRegistry } from "../fieldFilterValueTransform/abstractions.js";
|
|
5
|
-
|
|
6
|
-
export interface IFieldFilterCreateResult {
|
|
7
|
-
field: Field;
|
|
8
|
-
path: string;
|
|
9
|
-
fieldPathId: string;
|
|
10
|
-
filter: ValueFilterRegistry.Filter;
|
|
11
|
-
negate: boolean;
|
|
12
|
-
compareValue: any;
|
|
13
|
-
transformValue: <I = any, O = any>(value: I) => O;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface IFieldFilterCreateParams<T = any> {
|
|
17
|
-
key: string;
|
|
18
|
-
value: T;
|
|
19
|
-
field: Field;
|
|
20
|
-
fields: Record<string, Field>;
|
|
21
|
-
operation: string;
|
|
22
|
-
valueFilterRegistry: ValueFilterRegistry.Interface;
|
|
23
|
-
transformRegistry: FieldFilterValueTransformRegistry.Interface;
|
|
24
|
-
getHandler: (fieldType: string) => IFieldFilterCreateHandler;
|
|
25
|
-
negate: boolean;
|
|
26
|
-
compareValue: any;
|
|
27
|
-
transformValue: <I = any, O = any>(value: I) => O;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IFieldFilterCreateHandler {
|
|
31
|
-
create(
|
|
32
|
-
params: IFieldFilterCreateParams
|
|
33
|
-
): null | IFieldFilterCreateResult | IFieldFilterCreateResult[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface IFieldFilterCreateRegistry {
|
|
37
|
-
register(fieldType: string, handler: IFieldFilterCreateHandler): void;
|
|
38
|
-
get(fieldType: string): IFieldFilterCreateHandler | undefined;
|
|
39
|
-
getDefault(): IFieldFilterCreateHandler;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const FieldFilterCreateRegistry = new Abstraction<IFieldFilterCreateRegistry>(
|
|
43
|
-
"Cms/Storage/FieldFilterCreateRegistry"
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
export namespace FieldFilterCreateRegistry {
|
|
47
|
-
export type Interface = IFieldFilterCreateRegistry;
|
|
48
|
-
export type Handler = IFieldFilterCreateHandler;
|
|
49
|
-
export type Params = IFieldFilterCreateParams;
|
|
50
|
-
export type Result = IFieldFilterCreateResult;
|
|
51
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { FieldFilterPathRegistry } from "./abstractions.js";
|
|
2
|
-
|
|
3
|
-
export class FieldFilterPathRegistryImpl implements FieldFilterPathRegistry.Interface {
|
|
4
|
-
private readonly handlers = new Map<string, FieldFilterPathRegistry.Handler>();
|
|
5
|
-
|
|
6
|
-
public register(fieldType: string, handler: FieldFilterPathRegistry.Handler): void {
|
|
7
|
-
this.handlers.set(fieldType, handler);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public get(fieldType: string): FieldFilterPathRegistry.Handler | undefined {
|
|
11
|
-
return this.handlers.get(fieldType);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Abstraction } from "@webiny/di";
|
|
2
|
-
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
-
import type { CreatePathCallableParams } from "../../plugins/CmsEntryFieldFilterPathPlugin.js";
|
|
4
|
-
|
|
5
|
-
export interface IFieldFilterPathHandler {
|
|
6
|
-
canUse(field: Pick<CmsModelField, "fieldId" | "type">, parents: string[]): boolean;
|
|
7
|
-
createPath(params: CreatePathCallableParams): string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface IFieldFilterPathRegistry {
|
|
11
|
-
register(fieldType: string, handler: IFieldFilterPathHandler): void;
|
|
12
|
-
get(fieldType: string): IFieldFilterPathHandler | undefined;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const FieldFilterPathRegistry = new Abstraction<IFieldFilterPathRegistry>(
|
|
16
|
-
"Cms/Storage/FieldFilterPathRegistry"
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export namespace FieldFilterPathRegistry {
|
|
20
|
-
export type Interface = IFieldFilterPathRegistry;
|
|
21
|
-
export type Handler = IFieldFilterPathHandler;
|
|
22
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { FieldFilterValueTransformRegistry } from "./abstractions.js";
|
|
2
|
-
|
|
3
|
-
export class FieldFilterValueTransformRegistryImpl
|
|
4
|
-
implements FieldFilterValueTransformRegistry.Interface
|
|
5
|
-
{
|
|
6
|
-
private readonly handlers = new Map<string, FieldFilterValueTransformRegistry.Handler>();
|
|
7
|
-
|
|
8
|
-
public register(fieldType: string, handler: FieldFilterValueTransformRegistry.Handler): void {
|
|
9
|
-
this.handlers.set(fieldType, handler);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public get(fieldType: string): FieldFilterValueTransformRegistry.Handler | undefined {
|
|
13
|
-
return this.handlers.get(fieldType);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Abstraction } from "@webiny/di";
|
|
2
|
-
import type { CmsFieldFilterValueTransformParams } from "../../plugins/CmsFieldFilterValueTransformPlugin.js";
|
|
3
|
-
|
|
4
|
-
export interface IFieldFilterValueTransformHandler {
|
|
5
|
-
transform(params: CmsFieldFilterValueTransformParams): any;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface IFieldFilterValueTransformRegistry {
|
|
9
|
-
register(fieldType: string, handler: IFieldFilterValueTransformHandler): void;
|
|
10
|
-
get(fieldType: string): IFieldFilterValueTransformHandler | undefined;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const FieldFilterValueTransformRegistry =
|
|
14
|
-
new Abstraction<IFieldFilterValueTransformRegistry>(
|
|
15
|
-
"Cms/Storage/FieldFilterValueTransformRegistry"
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
export namespace FieldFilterValueTransformRegistry {
|
|
19
|
-
export type Interface = IFieldFilterValueTransformRegistry;
|
|
20
|
-
export type Handler = IFieldFilterValueTransformHandler;
|
|
21
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FieldSortingRegistry } from "./abstractions.js";
|
|
2
|
-
|
|
3
|
-
export class FieldSortingRegistryImpl implements FieldSortingRegistry.Interface {
|
|
4
|
-
private readonly handlers: FieldSortingRegistry.Handler[] = [];
|
|
5
|
-
|
|
6
|
-
public register(handler: FieldSortingRegistry.Handler): void {
|
|
7
|
-
this.handlers.push(handler);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public find(
|
|
11
|
-
params: FieldSortingRegistry.CanUseParams
|
|
12
|
-
): FieldSortingRegistry.Handler | undefined {
|
|
13
|
-
for (let i = this.handlers.length - 1; i >= 0; i--) {
|
|
14
|
-
if (this.handlers[i].canUse(params)) {
|
|
15
|
-
return this.handlers[i];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Abstraction } from "@webiny/di";
|
|
2
|
-
import type { Field } from "../../filtering/fields/types.js";
|
|
3
|
-
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
-
|
|
5
|
-
export interface IFieldSortingCanUseParams {
|
|
6
|
-
model: CmsModel;
|
|
7
|
-
field?: Field;
|
|
8
|
-
fieldId: string;
|
|
9
|
-
order: "ASC" | "DESC";
|
|
10
|
-
sortBy: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface IFieldSortingCreateParams {
|
|
14
|
-
model: CmsModel;
|
|
15
|
-
fieldId: string;
|
|
16
|
-
order: "ASC" | "DESC";
|
|
17
|
-
sortBy: string;
|
|
18
|
-
fields: Record<string, Field>;
|
|
19
|
-
field?: Field;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IFieldSortingResult {
|
|
23
|
-
valuePath: string;
|
|
24
|
-
reverse: boolean;
|
|
25
|
-
fieldId: string;
|
|
26
|
-
field: Field;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface IFieldSortingHandler {
|
|
30
|
-
canUse(params: IFieldSortingCanUseParams): boolean;
|
|
31
|
-
createSort(params: IFieldSortingCreateParams): IFieldSortingResult;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface IFieldSortingRegistry {
|
|
35
|
-
register(handler: IFieldSortingHandler): void;
|
|
36
|
-
find(params: IFieldSortingCanUseParams): IFieldSortingHandler | undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const FieldSortingRegistry = new Abstraction<IFieldSortingRegistry>(
|
|
40
|
-
"Cms/Storage/FieldSortingRegistry"
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
export namespace FieldSortingRegistry {
|
|
44
|
-
export type Interface = IFieldSortingRegistry;
|
|
45
|
-
export type Handler = IFieldSortingHandler;
|
|
46
|
-
export type CanUseParams = IFieldSortingCanUseParams;
|
|
47
|
-
export type CreateParams = IFieldSortingCreateParams;
|
|
48
|
-
export type Result = IFieldSortingResult;
|
|
49
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import WebinyError from "@webiny/error";
|
|
2
|
-
import type { CmsEntryListWhere } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
-
import type { Field } from "../fields/types.js";
|
|
4
|
-
import { extractWhereParams } from "../where.js";
|
|
5
|
-
import { transformValue } from "../transform.js";
|
|
6
|
-
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
7
|
-
import { ValueFilter, ValueFilterRegistry } from "@webiny/db-utils";
|
|
8
|
-
import type { FieldFilterCreateRegistry } from "../../features/fieldFilterCreate/abstractions.js";
|
|
9
|
-
import type { FieldFilterValueTransformRegistry } from "../../features/fieldFilterValueTransform/abstractions.js";
|
|
10
|
-
import { getWhereValues } from "../values.js";
|
|
11
|
-
|
|
12
|
-
interface CreateExpressionParams {
|
|
13
|
-
where: Partial<CmsEntryListWhere>;
|
|
14
|
-
condition: ExpressionCondition;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface ICreateExpressionsParams {
|
|
18
|
-
filterCreateRegistry: FieldFilterCreateRegistry.Interface;
|
|
19
|
-
transformRegistry: FieldFilterValueTransformRegistry.Interface;
|
|
20
|
-
valueFilterRegistry: ValueFilterRegistry.Interface;
|
|
21
|
-
where: Partial<CmsEntryListWhere>;
|
|
22
|
-
fields: Record<string, Field>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type ExpressionCondition = "AND" | "OR";
|
|
26
|
-
|
|
27
|
-
export interface Expression {
|
|
28
|
-
expressions: Expression[];
|
|
29
|
-
filters: Filter[];
|
|
30
|
-
condition: ExpressionCondition;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface Filter {
|
|
34
|
-
field: Field;
|
|
35
|
-
path: string;
|
|
36
|
-
fieldPathId: string;
|
|
37
|
-
filter: ValueFilter.Interface;
|
|
38
|
-
negate: boolean;
|
|
39
|
-
compareValue: any;
|
|
40
|
-
transformValue: <I = any, O = any>(value: I) => O;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const createExpressions = (params: ICreateExpressionsParams): Expression => {
|
|
44
|
-
const { where, filterCreateRegistry, transformRegistry, fields, valueFilterRegistry } = params;
|
|
45
|
-
|
|
46
|
-
const getHandler = (type: string) => {
|
|
47
|
-
const fieldType = getBaseFieldType({ type });
|
|
48
|
-
const handler = filterCreateRegistry.get(fieldType) || filterCreateRegistry.getDefault();
|
|
49
|
-
if (handler) {
|
|
50
|
-
return handler;
|
|
51
|
-
}
|
|
52
|
-
throw new WebinyError(
|
|
53
|
-
`There is no filter create handler for the field type "${fieldType}".`,
|
|
54
|
-
"MISSING_FILTER_CREATE_HANDLER",
|
|
55
|
-
{ fieldType }
|
|
56
|
-
);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const createExpression = ({ where, condition }: CreateExpressionParams): Expression => {
|
|
60
|
-
const expression: Expression = {
|
|
61
|
-
filters: [],
|
|
62
|
-
expressions: [],
|
|
63
|
-
condition
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
for (const key in where) {
|
|
67
|
-
const value = where[key as keyof typeof where];
|
|
68
|
-
if (value === undefined) {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (key === "AND") {
|
|
73
|
-
const childWhereList = getWhereValues(value, key);
|
|
74
|
-
const childExpression: Expression = {
|
|
75
|
-
condition: "AND",
|
|
76
|
-
filters: [],
|
|
77
|
-
expressions: []
|
|
78
|
-
};
|
|
79
|
-
for (const childWhere of childWhereList) {
|
|
80
|
-
const result = createExpression({
|
|
81
|
-
where: childWhere,
|
|
82
|
-
condition: "AND"
|
|
83
|
-
});
|
|
84
|
-
childExpression.expressions.push(result);
|
|
85
|
-
}
|
|
86
|
-
expression.expressions.push(childExpression);
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (key === "OR") {
|
|
90
|
-
const childWhereList = getWhereValues(value, key);
|
|
91
|
-
const childExpression: Expression = {
|
|
92
|
-
condition: "OR",
|
|
93
|
-
filters: [],
|
|
94
|
-
expressions: []
|
|
95
|
-
};
|
|
96
|
-
for (const childWhere of childWhereList) {
|
|
97
|
-
const result = createExpression({
|
|
98
|
-
where: childWhere,
|
|
99
|
-
condition: "AND"
|
|
100
|
-
});
|
|
101
|
-
childExpression.expressions.push(result);
|
|
102
|
-
}
|
|
103
|
-
expression.expressions.push(childExpression);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const whereParams = extractWhereParams(key);
|
|
108
|
-
if (!whereParams) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const { fieldId, operation, negate } = whereParams;
|
|
113
|
-
|
|
114
|
-
const field = fields[fieldId];
|
|
115
|
-
if (!field) {
|
|
116
|
-
throw new WebinyError(
|
|
117
|
-
`There is no field with the fieldId "${fieldId}".`,
|
|
118
|
-
"FIELD_ERROR",
|
|
119
|
-
{ fieldId }
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const handler = getHandler(field.type);
|
|
124
|
-
const fieldType = getBaseFieldType(field);
|
|
125
|
-
const transformHandler = transformRegistry.get(fieldType);
|
|
126
|
-
|
|
127
|
-
const transformValueCallable = (value: any) => {
|
|
128
|
-
if (!transformHandler) {
|
|
129
|
-
return value;
|
|
130
|
-
}
|
|
131
|
-
return transformHandler.transform({ field, value });
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const result = handler.create({
|
|
135
|
-
key,
|
|
136
|
-
value,
|
|
137
|
-
valueFilterRegistry,
|
|
138
|
-
transformRegistry,
|
|
139
|
-
getHandler,
|
|
140
|
-
operation,
|
|
141
|
-
negate,
|
|
142
|
-
field,
|
|
143
|
-
fields,
|
|
144
|
-
compareValue: transformValue({
|
|
145
|
-
value,
|
|
146
|
-
transform: transformValueCallable
|
|
147
|
-
}),
|
|
148
|
-
transformValue: transformValueCallable
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
if (!result || (Array.isArray(result) && result.length === 0)) {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
expression.filters.push(...(Array.isArray(result) ? result : [result]));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return expression;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const expression = createExpression({
|
|
162
|
-
where,
|
|
163
|
-
condition: "AND"
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
if (expression.filters.length > 0 || expression.expressions.length !== 1) {
|
|
167
|
-
return expression;
|
|
168
|
-
}
|
|
169
|
-
return expression.expressions[0];
|
|
170
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
|
-
import { createSystemFields } from "./systemFields.js";
|
|
3
|
-
import type { Field, FieldParent } from "./types.js";
|
|
4
|
-
import type { FieldFilterPathRegistry } from "../../features/fieldFilterPath/abstractions.js";
|
|
5
|
-
import type { FieldFilterValueTransformRegistry } from "../../features/fieldFilterValueTransform/abstractions.js";
|
|
6
|
-
import { getBaseFieldType } from "@webiny/api-headless-cms/utils/getBaseFieldType.js";
|
|
7
|
-
|
|
8
|
-
interface Params {
|
|
9
|
-
fields: CmsModelField[];
|
|
10
|
-
pathRegistry: FieldFilterPathRegistry.Interface;
|
|
11
|
-
transformRegistry: FieldFilterValueTransformRegistry.Interface;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface FieldCollection {
|
|
15
|
-
[key: string]: Field;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface AddFieldsToCollectionParams {
|
|
19
|
-
fields: CmsModelField[];
|
|
20
|
-
parents: FieldParent[];
|
|
21
|
-
pathRegistry: FieldFilterPathRegistry.Interface;
|
|
22
|
-
transformRegistry: FieldFilterValueTransformRegistry.Interface;
|
|
23
|
-
system: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const createFieldCollection = (params: AddFieldsToCollectionParams): FieldCollection => {
|
|
27
|
-
const { fields, parents, pathRegistry, transformRegistry, system } = params;
|
|
28
|
-
return fields.reduce<FieldCollection>((collection, field) => {
|
|
29
|
-
const fieldType = getBaseFieldType(field);
|
|
30
|
-
const transformHandler = transformRegistry.get(fieldType);
|
|
31
|
-
const pathHandler = pathRegistry.get(fieldType);
|
|
32
|
-
|
|
33
|
-
const fieldId = [
|
|
34
|
-
...parents,
|
|
35
|
-
{
|
|
36
|
-
fieldId: field.fieldId,
|
|
37
|
-
list: field.list
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
.map(f => f.fieldId)
|
|
41
|
-
.join(".");
|
|
42
|
-
|
|
43
|
-
collection[fieldId] = {
|
|
44
|
-
...field,
|
|
45
|
-
parents,
|
|
46
|
-
system,
|
|
47
|
-
createPath: pathParams => {
|
|
48
|
-
if (
|
|
49
|
-
pathHandler &&
|
|
50
|
-
pathHandler.canUse(
|
|
51
|
-
field,
|
|
52
|
-
parents.map(p => p.fieldId)
|
|
53
|
-
)
|
|
54
|
-
) {
|
|
55
|
-
return pathHandler.createPath(pathParams);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return parents
|
|
59
|
-
.map(parent => parent.fieldId)
|
|
60
|
-
.concat([pathParams.field.fieldId])
|
|
61
|
-
.join(".");
|
|
62
|
-
},
|
|
63
|
-
transform: value => {
|
|
64
|
-
if (!transformHandler) {
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
return transformHandler.transform({
|
|
68
|
-
field,
|
|
69
|
-
value
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const childFields = field.settings?.fields;
|
|
74
|
-
if (!childFields?.length) {
|
|
75
|
-
return collection;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const result = createFieldCollection({
|
|
79
|
-
fields: childFields,
|
|
80
|
-
parents: [
|
|
81
|
-
...parents,
|
|
82
|
-
{
|
|
83
|
-
fieldId: field.fieldId,
|
|
84
|
-
list: field.list
|
|
85
|
-
}
|
|
86
|
-
],
|
|
87
|
-
pathRegistry,
|
|
88
|
-
transformRegistry,
|
|
89
|
-
system
|
|
90
|
-
});
|
|
91
|
-
Object.assign(collection, result);
|
|
92
|
-
return collection;
|
|
93
|
-
}, {});
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const createFields = (params: Params) => {
|
|
97
|
-
const { fields, pathRegistry, transformRegistry } = params;
|
|
98
|
-
|
|
99
|
-
const collection = createFieldCollection({
|
|
100
|
-
fields: createSystemFields(),
|
|
101
|
-
pathRegistry,
|
|
102
|
-
transformRegistry,
|
|
103
|
-
parents: [],
|
|
104
|
-
system: true
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const result = createFieldCollection({
|
|
108
|
-
fields,
|
|
109
|
-
pathRegistry,
|
|
110
|
-
transformRegistry,
|
|
111
|
-
parents: [
|
|
112
|
-
{
|
|
113
|
-
fieldId: "values",
|
|
114
|
-
list: false
|
|
115
|
-
}
|
|
116
|
-
],
|
|
117
|
-
system: false
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
...collection,
|
|
122
|
-
...result
|
|
123
|
-
};
|
|
124
|
-
};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import WebinyError from "@webiny/error";
|
|
2
|
-
import type { Field } from "./types.js";
|
|
3
|
-
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
-
import type { FieldSortingRegistry } from "../../features/fieldSorting/abstractions.js";
|
|
5
|
-
|
|
6
|
-
const extractSortInfo = (sortBy: string) => {
|
|
7
|
-
const rootSorting = sortBy.match(/^([a-zA-Z]+)_(ASC|DESC)$/);
|
|
8
|
-
if (rootSorting) {
|
|
9
|
-
return {
|
|
10
|
-
fieldId: rootSorting[1],
|
|
11
|
-
isValues: false,
|
|
12
|
-
order: rootSorting[2] as "ASC" | "DESC"
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
const valuesSorting = sortBy.match(/^values_([a-zA-Z0-9]+)_(ASC|DESC)$/);
|
|
16
|
-
if (valuesSorting) {
|
|
17
|
-
return {
|
|
18
|
-
fieldId: valuesSorting[1],
|
|
19
|
-
isValues: true,
|
|
20
|
-
order: valuesSorting[2] as "ASC" | "DESC"
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
throw new WebinyError(
|
|
24
|
-
"Problem in determining the sorting for the entry items.",
|
|
25
|
-
"SORT_EXTRACT_ERROR",
|
|
26
|
-
{
|
|
27
|
-
sortBy
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
interface IResponse {
|
|
33
|
-
valuePath: string;
|
|
34
|
-
reverse: boolean;
|
|
35
|
-
fieldId: string;
|
|
36
|
-
field: Field;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface IParams {
|
|
40
|
-
model: CmsModel;
|
|
41
|
-
sortBy: string;
|
|
42
|
-
fields: Record<string, Field>;
|
|
43
|
-
sortingRegistry: FieldSortingRegistry.Interface;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const extractSort = (params: IParams): IResponse => {
|
|
47
|
-
const { model, sortBy, fields, sortingRegistry } = params;
|
|
48
|
-
const { fieldId, isValues: isValuesSorting, order } = extractSortInfo(sortBy);
|
|
49
|
-
|
|
50
|
-
const field = Object.values(fields).find(f => {
|
|
51
|
-
const isValues = f.parents[0]?.fieldId === "values";
|
|
52
|
-
if (isValues && isValuesSorting) {
|
|
53
|
-
return f.fieldId === fieldId;
|
|
54
|
-
}
|
|
55
|
-
if (f.parents.length > 0) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
return f.fieldId === fieldId;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const handler = sortingRegistry.find({
|
|
62
|
-
model,
|
|
63
|
-
field,
|
|
64
|
-
fieldId,
|
|
65
|
-
order,
|
|
66
|
-
sortBy
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
if (handler) {
|
|
70
|
-
return handler.createSort({
|
|
71
|
-
model,
|
|
72
|
-
fieldId,
|
|
73
|
-
order,
|
|
74
|
-
sortBy,
|
|
75
|
-
field,
|
|
76
|
-
fields
|
|
77
|
-
});
|
|
78
|
-
} else if (!field) {
|
|
79
|
-
throw new WebinyError(
|
|
80
|
-
"Sorting field does not exist in the content model.",
|
|
81
|
-
"SORTING_FIELD_ERROR",
|
|
82
|
-
{
|
|
83
|
-
fieldId,
|
|
84
|
-
fields
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const valuePath = field.createPath({
|
|
89
|
-
field
|
|
90
|
-
});
|
|
91
|
-
return {
|
|
92
|
-
field,
|
|
93
|
-
fieldId,
|
|
94
|
-
valuePath,
|
|
95
|
-
reverse: order === "DESC"
|
|
96
|
-
};
|
|
97
|
-
};
|