-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.ts
119 lines (100 loc) · 3.01 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {ORDER_DIRECTION} from './enums';
export interface IFilter {
value: string | boolean | number | null;
operator: string;
field: string;
}
export interface ICompoundFilter {
and?: IInputFilter[];
or?: IInputFilter[];
not?: IInputFilter[];
}
export type IInputFilter = IFilter | ICompoundFilter;
export type FilterTransformer = (filter: IFilter) => IFilter;
export interface ICursorObj<PublicAttributes> {
orderDir: keyof typeof ORDER_DIRECTION;
orderBy: PublicAttributes;
// The position of the cursor item from the beginning of the query
position: number;
filters: IInputFilter;
search?: string;
}
export interface IInputArgs {
before?: string;
after?: string;
first?: number;
last?: number;
orderBy?: string;
orderDir?: keyof typeof ORDER_DIRECTION;
filter?: IInputFilter;
search?: string;
}
export interface IInAttributeMap {
[nodeField: string]: string;
}
export interface IFilterMap {
[nodeField: string]: string;
}
// QueryContext
export interface IQueryContext {
limit: number;
orderDir: keyof typeof ORDER_DIRECTION;
orderBy: string;
filters: IInputFilter;
offset: number;
search?: string;
inputArgs: IInputArgs;
previousCursor?: string;
indexPosition: number;
isPagingBackwards: boolean;
}
export interface IQueryContextOptions<CursorObj> {
defaultLimit?: number;
cursorEncoder?: ICursorEncoder<CursorObj>;
}
// CursorEncoder
export interface ICursorEncoder<CursorObj> {
encodeToCursor: (cursorObj: CursorObj) => string;
decodeFromCursor: (cursor: string) => CursorObj;
}
// QueryBuilder
export interface IQueryBuilder<Builder> {
createQuery: (queryBuilder: Builder) => Builder;
}
export type QueryBuilderOptions = IKnexQueryBuilderOptions | IKnexMySQLQueryBuilderOptions;
export interface IKnexQueryBuilderOptions {
filterMap?: {[operator: string]: string};
/**
* If given with `useSuggestedValueLiteralTransforms`
* note that coercion happens FIRST, and then filterTransformer.
*/
filterTransformer?: FilterTransformer;
useSuggestedValueLiteralTransforms?: boolean;
}
export interface IKnexMySQLQueryBuilderOptions extends IKnexQueryBuilderOptions {
filterMap?: {[operator: string]: string};
filterTransformer?: FilterTransformer;
useSuggestedValueLiteralTransforms?: boolean;
searchColumns?: string[];
searchModifier?:
| 'IN NATURAL LANGUAGE MODE'
| 'IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION'
| 'IN BOOLEAN MODE'
| 'WITH QUERY EXPANSION'
| string;
}
// QueryResult
export interface IQueryResult<Node> {
edges: Array<{cursor: string; node: Node}>;
pageInfo: {
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor: string;
endCursor: string;
};
}
export type NodeTransformer<Node> = (node: any) => Node;
export interface IQueryResultOptions<CursorObj, Node> {
cursorEncoder?: ICursorEncoder<CursorObj>;
nodeTransformer?: NodeTransformer<Node>;
}