@sveltejs/kit 1.0.0-next.430 → 1.0.0-next.433

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,9 +62,9 @@ export interface BuildData {
62
62
  export interface CSRPageNode {
63
63
  component: typeof SvelteComponent;
64
64
  shared: {
65
- load: Load;
66
- hydrate: boolean;
67
- router: boolean;
65
+ load?: Load;
66
+ hydrate?: boolean;
67
+ router?: boolean;
68
68
  };
69
69
  server: boolean;
70
70
  }
@@ -80,13 +80,6 @@ export type CSRRoute = {
80
80
  uses_server_data: boolean;
81
81
  };
82
82
 
83
- export interface EndpointData {
84
- type: 'endpoint';
85
- id: string;
86
- pattern: RegExp;
87
- file: string;
88
- }
89
-
90
83
  export type GetParams = (match: RegExpExecArray) => Record<string, string>;
91
84
 
92
85
  export interface Hooks {
@@ -101,7 +94,7 @@ export interface ImportNode {
101
94
  }
102
95
 
103
96
  export class InternalServer extends Server {
104
- init(options: ServerInitOptions): void;
97
+ init(options: ServerInitOptions): Promise<void>;
105
98
  respond(
106
99
  request: Request,
107
100
  options: RequestOptions & {
@@ -123,18 +116,12 @@ export interface MethodOverride {
123
116
  }
124
117
 
125
118
  export interface PageNode {
119
+ depth: number;
126
120
  component?: string; // TODO supply default component if it's missing (bit of an edge case)
127
121
  shared?: string;
128
122
  server?: string;
129
- }
130
-
131
- export interface PageData {
132
- type: 'page';
133
- id: string;
134
- pattern: RegExp;
135
- errors: Array<PageNode | undefined>;
136
- layouts: Array<PageNode | undefined>;
137
- leaf: PageNode;
123
+ parent_id?: string;
124
+ parent?: PageNode;
138
125
  }
139
126
 
140
127
  export type PayloadScriptAttributes =
@@ -167,7 +154,78 @@ export interface Respond {
167
154
  (request: Request, options: SSROptions, state: SSRState): Promise<Response>;
168
155
  }
169
156
 
170
- export type RouteData = PageData | EndpointData;
157
+ /**
158
+ * Represents a route segment in the app. It can either be an intermediate node
159
+ * with only layout/error pages, or a leaf, at which point either `page` and `leaf`
160
+ * or `endpoint` is set.
161
+ */
162
+ export interface RouteData {
163
+ id: string;
164
+ parent: RouteData | null;
165
+
166
+ segment: string;
167
+ pattern: RegExp;
168
+ names: string[];
169
+ types: string[];
170
+
171
+ layout: PageNode | null;
172
+ error: PageNode | null;
173
+ leaf: PageNode | null;
174
+
175
+ page: {
176
+ layouts: Array<number | undefined>;
177
+ errors: Array<number | undefined>;
178
+ leaf: number;
179
+ } | null;
180
+
181
+ endpoint: {
182
+ file: string;
183
+ } | null;
184
+ }
185
+
186
+ export type ServerData =
187
+ | {
188
+ type: 'redirect';
189
+ location: string;
190
+ }
191
+ | {
192
+ type: 'data';
193
+ nodes: Array<ServerDataNode | ServerDataSkippedNode | ServerErrorNode | null>;
194
+ };
195
+
196
+ /**
197
+ * Signals a successful response of the server `load` function.
198
+ * The `uses` property tells the client when it's possible to reuse this data
199
+ * in a subsequent request.
200
+ */
201
+ export interface ServerDataNode {
202
+ type: 'data';
203
+ data: Record<string, any> | null;
204
+ uses: {
205
+ dependencies?: string[];
206
+ params?: string[];
207
+ parent?: number | void; // 1 or undefined
208
+ url?: number | void; // 1 or undefined
209
+ };
210
+ }
211
+
212
+ /**
213
+ * Signals that the server `load` function was not run, and the
214
+ * client should use what it has in memory
215
+ */
216
+ export interface ServerDataSkippedNode {
217
+ type: 'skip';
218
+ }
219
+
220
+ /**
221
+ * Signals that the server `load` function failed
222
+ */
223
+ export interface ServerErrorNode {
224
+ type: 'error';
225
+ // Either-or situation, but we don't want to have to do a type assertion
226
+ error?: Record<string, any>;
227
+ httperror?: { status: number; message: string };
228
+ }
171
229
 
172
230
  export interface SSRComponent {
173
231
  default: {
@@ -184,15 +242,6 @@ export interface SSRComponent {
184
242
 
185
243
  export type SSRComponentLoader = () => Promise<SSRComponent>;
186
244
 
187
- export interface SSREndpoint {
188
- type: 'endpoint';
189
- id: string;
190
- pattern: RegExp;
191
- names: string[];
192
- types: string[];
193
- load(): Promise<Partial<Record<HttpMethod, RequestHandler>>>;
194
- }
195
-
196
245
  export interface SSRNode {
197
246
  component: SSRComponentLoader;
198
247
  /** index into the `components` array in client-manifest.js */
@@ -265,33 +314,46 @@ export interface SSROptions {
265
314
  trailing_slash: TrailingSlash;
266
315
  }
267
316
 
268
- export interface SSRPage {
269
- type: 'page';
270
- id: string;
271
- pattern: RegExp;
272
- names: string[];
273
- types: string[];
317
+ export interface SSRErrorPage {
318
+ id: '__error';
319
+ }
320
+
321
+ export interface PageNodeIndexes {
274
322
  errors: Array<number | undefined>;
275
323
  layouts: Array<number | undefined>;
276
324
  leaf: number;
277
325
  }
278
326
 
279
- export interface SSRErrorPage {
280
- id: '__error';
281
- }
327
+ export type SSREndpoint = Partial<Record<HttpMethod, RequestHandler>>;
282
328
 
283
- export type SSRRoute = SSREndpoint | SSRPage;
329
+ export interface SSRRoute {
330
+ id: string;
331
+ pattern: RegExp;
332
+ names: string[];
333
+ types: string[];
334
+
335
+ page: PageNodeIndexes | null;
336
+
337
+ endpoint: (() => Promise<SSREndpoint>) | null;
338
+ }
284
339
 
285
340
  export interface SSRState {
286
341
  fallback?: string;
287
342
  getClientAddress: () => string;
288
- initiator?: SSRPage | SSRErrorPage;
343
+ initiator?: SSRRoute | SSRErrorPage;
289
344
  platform?: any;
290
345
  prerendering?: PrerenderOptions;
291
346
  }
292
347
 
293
348
  export type StrictBody = string | Uint8Array;
294
349
 
350
+ export interface Uses {
351
+ dependencies: Set<string>;
352
+ params: Set<string>;
353
+ parent: boolean;
354
+ url: boolean;
355
+ }
356
+
295
357
  export type ValidatedConfig = RecursiveRequired<Config>;
296
358
 
297
359
  export type ValidatedKitConfig = RecursiveRequired<KitConfig>;