/
types.ts
133 lines (119 loc) · 2.62 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
import { HandleValue } from './index';
export type RouteApiError = {
name: string;
code: string;
message: string;
link?: string; // link to error message details
action?: string; // label for error link
errors?: string[]; // array of all error messages
};
export type HasField = Array<
| {
type: 'host';
value: string;
}
| {
type: 'header' | 'cookie' | 'query';
key: string;
value?: string;
}
>;
export type RouteWithSrc = {
src: string;
dest?: string;
headers?: { [name: string]: string };
methods?: string[];
continue?: boolean;
override?: boolean;
caseSensitive?: boolean;
check?: boolean;
important?: boolean;
status?: number;
has?: HasField;
missing?: HasField;
locale?: {
redirect?: Record<string, string>;
cookie?: string;
};
/**
* A middleware key within the `output` key under the build result.
* Overrides a `middleware` definition.
*/
middlewarePath?: string;
/**
* The original middleware matchers.
*/
middlewareRawSrc?: string[];
/**
* A middleware index in the `middleware` key under the build result
*/
middleware?: number;
};
export type RouteWithHandle = {
handle: HandleValue;
src?: string;
dest?: string;
status?: number;
};
export type Route = RouteWithSrc | RouteWithHandle;
export type NormalizedRoutes = {
routes: Route[] | null;
error: RouteApiError | null;
};
export interface GetRoutesProps {
routes?: Route[];
cleanUrls?: boolean;
rewrites?: Rewrite[];
redirects?: Redirect[];
headers?: Header[];
trailingSlash?: boolean;
}
export interface MergeRoutesProps {
userRoutes?: Route[] | null | undefined;
builds: Build[];
}
export interface Build {
use: string;
entrypoint: string;
routes?: Route[];
}
export interface Rewrite {
source: string;
destination: string;
has?: HasField;
missing?: HasField;
statusCode?: number;
}
export interface Redirect {
source: string;
destination: string;
permanent?: boolean;
statusCode?: number;
has?: HasField;
missing?: HasField;
}
export interface Header {
source: string;
headers: HeaderKeyValue[];
has?: HasField;
missing?: HasField;
}
export interface HeaderKeyValue {
key: string;
value: string;
}
export interface AppendRoutesToPhaseProps {
/**
* All input routes including `handle` phases.
*/
routes: Route[] | null;
/**
* The routes to append to a specific phase.
*/
newRoutes: Route[] | null;
/**
* The phase to append the routes such as `filesystem`.
* If the phase is `null`, the routes will be appended prior to the first handle being found.
*/
phase: HandleValue | null;
}