-
Notifications
You must be signed in to change notification settings - Fork 1
/
odata-parser.d.ts
132 lines (126 loc) · 2.79 KB
/
odata-parser.d.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
export type SupportedMethod =
| 'GET'
| 'PUT'
| 'POST'
| 'PATCH'
| 'MERGE'
| 'DELETE'
| 'OPTIONS';
/**
* string for a parameter alias reference, number for an extracted constant
*/
export type BindKey = `@${string}` | number;
export type BindReference = { bind: BindKey };
export type NumberBind = ['Real', number];
export type BooleanBind = ['Boolean', boolean];
export type TextBind = ['Text', string];
export type DateBind = ['Date' | 'Date Time', Date];
export interface ResourceOptions {
count?: true;
options?: ODataOptions;
}
interface GenericPropertyPath<T = any> {
name: string;
property?: T;
}
export type PropertyPath = GenericPropertyPath<PropertyPath>;
export interface OrderByPropertyPath
extends GenericPropertyPath<OrderByPropertyPath> {
order: 'asc' | 'desc';
}
export interface ExpandPropertyPath
extends GenericPropertyPath<ExpandPropertyPath>,
ResourceOptions {}
export type SelectOption =
| '*'
| {
properties: PropertyPath[];
};
export type FilterOption = any;
export interface ExpandOption {
properties: ExpandPropertyPath[];
}
export interface OrderByOption {
properties: OrderByPropertyPath[];
}
export type FormatOption =
| string
| {
type: string;
metadata: 'none' | 'minimal' | 'full';
};
export interface ODataOptions {
$select?: SelectOption;
$filter?: FilterOption;
$expand?: ExpandOption;
$orderby?: OrderByOption;
$top?: number;
$skip?: number;
$count?: boolean;
$inlinecount?: string;
$format?: FormatOption;
[key: string]: // User defined options, do not start with $ or @
| string
// Parameter aliases (start with @)
| NumberBind
| BooleanBind
| TextBind
| DateBind
// known $ options
| SelectOption
| ExpandOption
| OrderByOption
| FormatOption
| number
| boolean
| undefined;
}
export interface ODataQuery extends ResourceOptions {
resource: any;
key?:
| BindReference
| {
[resourceName: string]: BindReference;
};
link?: any;
property?: any;
}
export interface ODataBinds extends Array<[type: string, value: any]> {
[key: `@${string}`]: [type: string, value: any];
}
export class SyntaxError extends Error {}
export function parse(
url: string,
opts?: { startRule: 'ProcessRule'; rule: 'OData' },
): {
tree: ODataQuery;
binds: ODataBinds;
};
export function parse(
url: string,
opts?: { startRule: 'ProcessRule'; rule: 'KeyBind' },
): {
tree: BindReference;
binds: ODataBinds;
};
export function parse(
url: string,
opts?: { startRule: 'ProcessRule'; rule: 'FilterByExpression' },
): {
tree: FilterOption;
binds: ODataBinds;
};
export function parse(
url: string,
opts?: { startRule: 'ProcessRule'; rule: 'QueryOptions' },
): {
tree: ODataOptions;
binds: ODataBinds;
};
export function parse(
url: string,
opts?: { startRule: 'ProcessRule'; rule: string },
): {
tree: any;
binds: ODataBinds;
};