-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
internal.d.ts
212 lines (184 loc) · 4 KB
/
internal.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import { Load } from './page';
import { Incoming, GetSession, Handle, ServerResponse } from './hooks';
import { RequestHandler } from './endpoint';
type PageId = string;
export type Logger = {
(msg: string): void;
success: (msg: string) => void;
error: (msg: string) => void;
warn: (msg: string) => void;
minor: (msg: string) => void;
info: (msg: string) => void;
};
export type App = {
init: ({
paths,
prerendering,
read
}: {
paths: {
base: string;
assets: string;
};
prerendering: boolean;
read: (file: string) => Buffer;
}) => void;
render: (
incoming: Incoming,
options?: {
prerender: {
fallback: string;
all: boolean;
dependencies: Map<string, ServerResponse>;
};
}
) => ServerResponse;
};
export type SSRComponent = {
ssr?: boolean;
router?: boolean;
hydrate?: boolean;
prerender?: boolean;
preload?: any; // TODO remove for 1.0
load: Load;
default: {
render: (
props: Record<string, any>
) => {
html: string;
head: string;
css: {
code: string;
map: any; // TODO
};
};
};
};
export type SSRComponentLoader = () => Promise<SSRComponent>;
export type CSRComponent = any; // TODO
export type CSRComponentLoader = () => Promise<CSRComponent>;
export type SSRPagePart = {
id: string;
load: SSRComponentLoader;
};
export type GetParams = (match: RegExpExecArray) => Record<string, string>;
export type SSRPage = {
type: 'page';
pattern: RegExp;
params: GetParams;
// plan a is to render 1 or more layout components followed
// by a leaf component. if one of them fails in `load`, we
// backtrack until we find the nearest error component —
// plan b — and render that instead
a: PageId[];
b: PageId[];
};
export type SSREndpoint = {
type: 'endpoint';
pattern: RegExp;
params: GetParams;
load: () => Promise<{
[method: string]: RequestHandler;
}>;
};
export type SSRRoute = SSREndpoint | SSRPage;
export type CSRPage = [RegExp, CSRComponentLoader[], CSRComponentLoader[], GetParams?];
export type CSREndpoint = [RegExp];
export type CSRRoute = CSREndpoint | CSRPage;
export type SSRManifest = {
assets: Asset[];
layout: string;
error: string;
routes: SSRRoute[];
};
export type Hooks = {
getSession?: GetSession;
handle?: Handle;
};
export type SSRNode = {
module: SSRComponent;
entry: string; // client-side module corresponding to this component
css: string[];
js: string[];
styles: string[];
};
export type SSRRenderOptions = {
amp: boolean;
dev: boolean;
entry: {
file: string;
css: string[];
js: string[];
};
floc: boolean;
get_stack: (error: Error) => string;
handle_error: (error: Error) => void;
hooks: Hooks;
hydrate: boolean;
load_component: (id: PageId) => Promise<SSRNode>;
manifest: SSRManifest;
paths: {
base: string;
assets: string;
};
read: (file: string) => Buffer;
root: SSRComponent['default'];
router: boolean;
ssr: boolean;
target: string;
template: ({ head, body }: { head: string; body: string }) => string;
trailing_slash: TrailingSlash;
};
export type SSRRenderState = {
fetched?: string;
initiator?: SSRPage;
prerender?: {
fallback: string;
all: boolean;
dependencies: Map<string, ServerResponse>;
error: Error;
};
fallback?: string;
};
export type Asset = {
file: string;
size: number;
type: string;
};
export type PageData = {
type: 'page';
pattern: RegExp;
params: string[];
path: string;
a: string[];
b: string[];
};
export type EndpointData = {
type: 'endpoint';
pattern: RegExp;
params: string[];
file: string;
};
export type RouteData = PageData | EndpointData;
export type ManifestData = {
assets: Asset[];
layout: string;
error: string;
components: string[];
routes: RouteData[];
};
export type BuildData = {
client: string[];
server: string[];
static: string[];
entries: string[];
};
export type NormalizedLoadOutput = {
status?: number;
error?: Error;
redirect?: string;
props?: Record<string, any> | Promise<Record<string, any>>;
context?: Record<string, any>;
maxage?: number;
};
export type TrailingSlash = 'never' | 'always' | 'ignore';