-
Notifications
You must be signed in to change notification settings - Fork 19
/
types.ts
148 lines (128 loc) · 3.75 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import type { IntrospectionInputValue, IntrospectionType } from 'graphql'
import { CREATE, DELETE, GET_LIST, GET_MANY, GET_MANY_REFERENCE, GET_ONE, UPDATE } from 'ra-core'
export type FetchQueryType =
| typeof GET_MANY
| typeof GET_LIST
| typeof GET_ONE
| typeof GET_MANY_REFERENCE
| typeof DELETE
| typeof UPDATE
| typeof CREATE
export interface TypeConfig {
/**
* Allows you to map the value if used as an input type for mutations
*
* Some values might not convert 1:1 if returned from the query and used as an input
*/
queryValueToInputValue?: (value: any) => any
/**
* Allows you to exclude certain fields, either by passing an array (e.g. `['field1', 'field2']`) or a function
*
* By default all `Scalar`s, `Enum`s and `List<Scalar|Enum>.` are queried.
* If you have expansive computations that you don't want to expose to `react-admin`, this is the
* perfect place to do so :).
*/
excludeFields?: string[] | ((fieldName: string, fetchType: FetchQueryType) => boolean)
/**
* Same as exclude fields, but if provided will let you dynamically decide if a field is queried.
* Will only pass fields of type `Scalar`, `Enum` and `List<Scalar|Enum>.`
* You can only provide either `includeFields` or `excludeFields`.
*/
includeFields?: string[] | ((fieldName: string, fetchType: FetchQueryType) => boolean)
/**
* Allows you to dynamically provide arguments for a given field
*/
computeArgumentsForField?: (
fieldName: string,
args: ReadonlyArray<IntrospectionInputValue>
) => Record<string, any> | null
/**
* Will expand this type, by default only `Scalar`s, `Enum`s and `List<Scalar|Enum>.` are expanded.
* Make sure you expand subtypes as well if required.
*/
expand?: boolean
/**
* Optional choose your own plural form
*/
pluralize?: (name: string) => string
}
export interface TypeConfigMap {
[type: string]: TypeConfig
}
export interface ProviderOptions {
typeMap: TypeConfigMap
}
export type SortDirection = 'ASC' | 'DESC'
export interface Query {
args: Array<IntrospectionInputValue>
}
export interface QueryMap {
[query: string]: Query
}
export interface TypeMap {
[type: string]: IntrospectionType
}
export interface Response {
data: any
}
// Most operators are from https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/blob/master/src/PgConnectionArgFilterOperatorsPlugin.js#L42-L277
export type Operator =
// Standard Operators
| 'isNull'
| 'equalTo'
| 'notEqualTo'
| 'distinctFrom'
| 'notDistinctFrom'
| 'in'
| 'notIn'
// Pattern Matching Operators
| 'includes'
| 'notIncludes'
| 'includesInsensitive'
| 'notIncludesInsensitive'
| 'startsWith'
| 'notStartsWith'
| 'startsWithInsensitive'
| 'notStartsWithInsensitive'
| 'endsWith'
| 'notEndsWith'
| 'endsWithInsensitive'
| 'notEndsWithInsensitive'
| 'like'
| 'notLike'
| 'likeInsensitive'
| 'notLikeInsensitive'
// HStore / JSON / INET Operators
| 'contains'
| 'containsKey'
| 'containsAllKeys'
| 'containsAnyKeys'
| 'containedBy'
| 'containedByOrEqualTo'
| 'containsOrContainedBy'
// operators from https://github.com/mlipscombe/postgraphile-plugin-fulltext-filter
| 'matches'
export type FilterSpec =
| {
operator: Operator
/** optional key, that will be taken instead of the filters input name */
key?: string
value?: any
}
| {
operator?: Operator
/** optional key, that will be taken instead of the filters input name */
key?: string
value: Record<string, any>
}
export interface Filter {
[key: string]: {
[operator: string]: any
}
}
export interface FilterMap {
and: Filter[]
}
// Constants
export const CAMEL_REGEX = /(.+?)([A-Z])/gm
export const NATURAL_SORTING = 'NATURAL'