@sveltejs/kit 1.0.0-next.203 → 1.0.0-next.208

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.
@@ -82,8 +82,7 @@ declare module '$app/paths' {
82
82
 
83
83
  declare module '$app/stores' {
84
84
  import { Readable, Writable } from 'svelte/store';
85
- import { Page } from '@sveltejs/kit';
86
- type Navigating = { from: Page; to: Page };
85
+ type Navigating = { from: URL; to: URL };
87
86
 
88
87
  /**
89
88
  * A convenience function around `getContext` that returns `{ navigating, page, session }`.
@@ -91,16 +90,23 @@ declare module '$app/stores' {
91
90
  */
92
91
  export function getStores<Session = any>(): {
93
92
  navigating: Readable<Navigating | null>;
94
- page: Readable<Page>;
93
+ page: Readable<{
94
+ url: URL;
95
+ params: Record<string, string>;
96
+ }>;
95
97
  session: Writable<Session>;
96
98
  };
99
+ export const url: Readable<URL>;
97
100
  /**
98
- * A readable store whose value reflects the object passed to load functions.
101
+ * A readable store whose value contains page data.
99
102
  */
100
- export const page: Readable<Page>;
103
+ export const page: Readable<{
104
+ url: URL;
105
+ params: Record<string, string>;
106
+ }>;
101
107
  /**
102
108
  * A readable store.
103
- * When navigating starts, its value is `{ from, to }`, where from and to both mirror the page store value.
109
+ * When navigating starts, its value is `{ from: URL, to: URL }`
104
110
  * When navigating finishes, its value reverts to `null`.
105
111
  */
106
112
  export const navigating: Readable<Navigating | null>;
@@ -161,7 +167,9 @@ declare module '@sveltejs/kit/ssr' {
161
167
  type State = import('@sveltejs/kit/types/internal').SSRRenderState;
162
168
 
163
169
  export interface Respond {
164
- (incoming: IncomingRequest, options: Options, state?: State): Promise<Response>;
170
+ (incoming: IncomingRequest & { url: URL }, options: Options, state?: State): Promise<
171
+ Response | undefined
172
+ >;
165
173
  }
166
174
  export const respond: Respond;
167
175
  }
package/types/app.d.ts CHANGED
@@ -1,21 +1,45 @@
1
1
  import { ReadOnlyFormData, RequestHeaders } from './helper';
2
2
  import { ServerResponse } from './hooks';
3
+ import { PrerenderOptions, SSRNodeLoader, SSRRoute } from './internal';
3
4
 
4
- export interface App {
5
- init(): void;
5
+ export class App {
6
+ constructor(manifest: SSRManifest);
6
7
  render(incoming: IncomingRequest): Promise<ServerResponse>;
7
8
  }
8
9
 
10
+ export class InternalApp extends App {
11
+ render(
12
+ incoming: IncomingRequest,
13
+ options?: {
14
+ prerender: PrerenderOptions;
15
+ }
16
+ ): Promise<ServerResponse>;
17
+ }
18
+
9
19
  export type RawBody = null | Uint8Array;
10
20
  export type ParameterizedBody<Body = unknown> = Body extends FormData
11
21
  ? ReadOnlyFormData
12
22
  : (string | RawBody | ReadOnlyFormData) & Body;
13
23
 
14
24
  export interface IncomingRequest {
25
+ url: string | URL;
15
26
  method: string;
16
- host: string;
17
- path: string;
18
- query: URLSearchParams;
19
27
  headers: RequestHeaders;
20
28
  rawBody: RawBody;
21
29
  }
30
+
31
+ export interface SSRManifest {
32
+ appDir: string;
33
+ assets: Set<string>;
34
+ /** private fields */
35
+ _: {
36
+ mime: Record<string, string>;
37
+ entry: {
38
+ file: string;
39
+ js: string[];
40
+ css: string[];
41
+ };
42
+ nodes: SSRNodeLoader[];
43
+ routes: SSRRoute[];
44
+ };
45
+ }
package/types/config.d.ts CHANGED
@@ -1,38 +1,99 @@
1
1
  import { UserConfig as ViteConfig } from 'vite';
2
2
  import { RecursiveRequired } from './helper';
3
- import { Logger, TrailingSlash } from './internal';
3
+ import { HttpMethod, Logger, RouteSegment, TrailingSlash } from './internal';
4
4
 
5
- export interface AdapterUtils {
5
+ export interface RouteDefinition {
6
+ type: 'page' | 'endpoint';
7
+ pattern: RegExp;
8
+ segments: RouteSegment[];
9
+ methods: HttpMethod[];
10
+ }
11
+
12
+ export interface AdapterEntry {
13
+ /**
14
+ * A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
15
+ * For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
16
+ * be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
17
+ */
18
+ id: string;
19
+
20
+ /**
21
+ * A function that compares the candidate route with the current route to determine
22
+ * if it should be treated as a fallback for the current route. For example, `/foo/[c]`
23
+ * is a fallback for `/foo/a-[b]`, and `/[...catchall]` is a fallback for all routes
24
+ */
25
+ filter: (route: RouteDefinition) => boolean;
26
+
27
+ /**
28
+ * A function that is invoked once the entry has been created. This is where you
29
+ * should write the function to the filesystem and generate redirect manifests.
30
+ */
31
+ complete: (entry: {
32
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
33
+ }) => void;
34
+ }
35
+
36
+ export interface Builder {
6
37
  log: Logger;
7
38
  rimraf(dir: string): void;
8
39
  mkdirp(dir: string): void;
40
+
41
+ /**
42
+ * Create entry points that map to individual functions
43
+ * @param fn A function that groups a set of routes into an entry point
44
+ */
45
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): void;
46
+
47
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
48
+
49
+ getBuildDirectory(name: string): string;
50
+ getClientDirectory(): string;
51
+ getServerDirectory(): string;
52
+ getStaticDirectory(): string;
53
+
9
54
  /**
10
55
  * @param dest the destination folder to which files should be copied
11
56
  * @returns an array of paths corresponding to the files that have been created by the copy
12
57
  */
13
- copy_client_files(dest: string): string[];
58
+ writeClient(dest: string): string[];
14
59
  /**
15
60
  * @param dest the destination folder to which files should be copied
16
61
  * @returns an array of paths corresponding to the files that have been created by the copy
17
62
  */
18
- copy_server_files(dest: string): string[];
63
+ writeServer(dest: string): string[];
19
64
  /**
20
65
  * @param dest the destination folder to which files should be copied
21
66
  * @returns an array of paths corresponding to the files that have been created by the copy
22
67
  */
23
- copy_static_files(dest: string): string[];
68
+ writeStatic(dest: string): string[];
24
69
  /**
25
- * @param from the source folder from which files should be copied
26
- * @param to the destination folder to which files should be copied
70
+ * @param from the source file or folder
71
+ * @param to the destination file or folder
72
+ * @param opts.filter a function to determine whether a file or folder should be copied
73
+ * @param opts.replace a map of strings to replace
27
74
  * @returns an array of paths corresponding to the files that have been created by the copy
28
75
  */
29
- copy(from: string, to: string, filter?: (basename: string) => boolean): string[];
30
- prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<void>;
76
+ copy(
77
+ from: string,
78
+ to: string,
79
+ opts?: {
80
+ filter?: (basename: string) => boolean;
81
+ replace?: Record<string, string>;
82
+ }
83
+ ): string[];
84
+
85
+ prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<{
86
+ paths: string[];
87
+ }>;
31
88
  }
32
89
 
33
90
  export interface Adapter {
34
91
  name: string;
35
- adapt(context: { utils: AdapterUtils; config: ValidatedConfig }): Promise<void>;
92
+ headers?: {
93
+ host?: string;
94
+ protocol?: string;
95
+ };
96
+ adapt(builder: Builder): Promise<void>;
36
97
  }
37
98
 
38
99
  export interface PrerenderErrorHandler {
@@ -62,8 +123,11 @@ export interface Config {
62
123
  template?: string;
63
124
  };
64
125
  floc?: boolean;
126
+ headers?: {
127
+ host?: string;
128
+ protocol?: string;
129
+ };
65
130
  host?: string;
66
- hostHeader?: string;
67
131
  hydrate?: boolean;
68
132
  package?: {
69
133
  dir?: string;
@@ -76,14 +140,17 @@ export interface Config {
76
140
  base?: string;
77
141
  };
78
142
  prerender?: {
143
+ concurrency?: number;
79
144
  crawl?: boolean;
80
145
  enabled?: boolean;
81
146
  entries?: string[];
82
147
  onError?: PrerenderOnErrorValue;
83
148
  };
149
+ protocol?: string;
84
150
  router?: boolean;
85
151
  serviceWorker?: {
86
- files?(filepath: string): boolean;
152
+ register?: boolean;
153
+ files?: (filepath: string) => boolean;
87
154
  };
88
155
  ssr?: boolean;
89
156
  target?: string;
package/types/hooks.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- import { IncomingRequest, ParameterizedBody } from './app';
2
- import { MaybePromise, ResponseHeaders } from './helper';
1
+ import { ParameterizedBody, RawBody } from './app';
2
+ import { MaybePromise, RequestHeaders, ResponseHeaders } from './helper';
3
3
 
4
4
  export type StrictBody = string | Uint8Array;
5
5
 
6
- export interface ServerRequest<Locals = Record<string, any>, Body = unknown>
7
- extends IncomingRequest {
6
+ export interface ServerRequest<Locals = Record<string, any>, Body = unknown> {
7
+ url: URL;
8
+ method: string;
9
+ headers: RequestHeaders;
10
+ rawBody: RawBody;
8
11
  params: Record<string, string>;
9
12
  body: ParameterizedBody<Body>;
10
13
  locals: Locals;
@@ -27,6 +30,15 @@ export interface Handle<Locals = Record<string, any>, Body = unknown> {
27
30
  }): MaybePromise<ServerResponse>;
28
31
  }
29
32
 
33
+ // internally, `resolve` could return `undefined`, so we differentiate InternalHandle
34
+ // from the public Handle type
35
+ export interface InternalHandle<Locals = Record<string, any>, Body = unknown> {
36
+ (input: {
37
+ request: ServerRequest<Locals, Body>;
38
+ resolve(request: ServerRequest<Locals, Body>): MaybePromise<ServerResponse | undefined>;
39
+ }): MaybePromise<ServerResponse | undefined>;
40
+ }
41
+
30
42
  export interface HandleError<Locals = Record<string, any>, Body = unknown> {
31
43
  (input: { error: Error & { frame?: string }; request: ServerRequest<Locals, Body> }): void;
32
44
  }
package/types/index.d.ts CHANGED
@@ -3,10 +3,10 @@
3
3
 
4
4
  import './ambient-modules';
5
5
 
6
- export { App, IncomingRequest, RawBody } from './app';
7
- export { Adapter, AdapterUtils, Config, PrerenderErrorHandler, ValidatedConfig } from './config';
6
+ export { App, IncomingRequest, RawBody, SSRManifest } from './app';
7
+ export { Adapter, Builder, Config, PrerenderErrorHandler, ValidatedConfig } from './config';
8
8
  export { EndpointOutput, RequestHandler } from './endpoint';
9
- export { ErrorLoad, ErrorLoadInput, Load, LoadInput, LoadOutput, Page } from './page';
9
+ export { ErrorLoad, ErrorLoadInput, Load, LoadInput, LoadOutput } from './page';
10
10
  export {
11
11
  ExternalFetch,
12
12
  GetSession,
@@ -1,10 +1,11 @@
1
+ import { OutputAsset, OutputChunk } from 'rollup';
1
2
  import { RequestHandler } from './endpoint';
2
- import { App as PublicApp, IncomingRequest } from './app';
3
+ import { InternalApp, SSRManifest } from './app';
3
4
  import {
4
5
  ExternalFetch,
5
6
  GetSession,
6
- Handle,
7
7
  HandleError,
8
+ InternalHandle,
8
9
  ServerRequest,
9
10
  ServerResponse
10
11
  } from './hooks';
@@ -18,22 +19,18 @@ export interface PrerenderOptions {
18
19
  dependencies: Map<string, ServerResponse>;
19
20
  }
20
21
 
21
- export interface App extends PublicApp {
22
- init(options?: {
22
+ export interface AppModule {
23
+ App: typeof InternalApp;
24
+
25
+ override(options: {
23
26
  paths: {
24
27
  base: string;
25
28
  assets: string;
26
29
  };
27
30
  prerendering: boolean;
31
+ protocol?: 'http' | 'https';
28
32
  read(file: string): Buffer;
29
33
  }): void;
30
-
31
- render(
32
- incoming: IncomingRequest,
33
- options?: {
34
- prerender: PrerenderOptions;
35
- }
36
- ): Promise<ServerResponse>;
37
34
  }
38
35
 
39
36
  export interface Logger {
@@ -84,12 +81,12 @@ export interface SSRPage {
84
81
  /**
85
82
  * plan a is to render 1 or more layout components followed by a leaf component.
86
83
  */
87
- a: PageId[];
84
+ a: number[];
88
85
  /**
89
86
  * plan b — if one of them components fails in `load` we backtrack until we find
90
87
  * the nearest error component.
91
88
  */
92
- b: PageId[];
89
+ b: number[];
93
90
  }
94
91
 
95
92
  export interface SSREndpoint {
@@ -105,17 +102,12 @@ export type SSRRoute = SSREndpoint | SSRPage;
105
102
 
106
103
  export type CSRRoute = [RegExp, CSRComponentLoader[], CSRComponentLoader[], GetParams?];
107
104
 
108
- export interface SSRManifest {
109
- assets: Asset[];
110
- layout: string;
111
- error: string;
112
- routes: SSRRoute[];
113
- }
105
+ export type SSRNodeLoader = () => Promise<SSRNode>;
114
106
 
115
107
  export interface Hooks {
116
108
  externalFetch: ExternalFetch;
117
109
  getSession: GetSession;
118
- handle: Handle;
110
+ handle: InternalHandle;
119
111
  handleError: HandleError;
120
112
  }
121
113
 
@@ -134,22 +126,17 @@ export interface SSRNode {
134
126
  export interface SSRRenderOptions {
135
127
  amp: boolean;
136
128
  dev: boolean;
137
- entry: {
138
- file: string;
139
- css: string[];
140
- js: string[];
141
- };
142
129
  floc: boolean;
143
130
  get_stack: (error: Error) => string | undefined;
144
131
  handle_error(error: Error & { frame?: string }, request: ServerRequest<any>): void;
145
132
  hooks: Hooks;
146
133
  hydrate: boolean;
147
- load_component(id: PageId): Promise<SSRNode>;
148
134
  manifest: SSRManifest;
149
135
  paths: {
150
136
  base: string;
151
137
  assets: string;
152
138
  };
139
+ prefix: string;
153
140
  prerender: boolean;
154
141
  read(file: string): Buffer;
155
142
  root: SSRComponent['default'];
@@ -174,8 +161,17 @@ export interface Asset {
174
161
  type: string | null;
175
162
  }
176
163
 
164
+ export interface RouteSegment {
165
+ content: string;
166
+ dynamic: boolean;
167
+ rest: boolean;
168
+ }
169
+
170
+ export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
171
+
177
172
  export interface PageData {
178
173
  type: 'page';
174
+ segments: RouteSegment[];
179
175
  pattern: RegExp;
180
176
  params: string[];
181
177
  path: string;
@@ -185,6 +181,7 @@ export interface PageData {
185
181
 
186
182
  export interface EndpointData {
187
183
  type: 'endpoint';
184
+ segments: RouteSegment[];
188
185
  pattern: RegExp;
189
186
  params: string[];
190
187
  file: string;
@@ -201,8 +198,23 @@ export interface ManifestData {
201
198
  }
202
199
 
203
200
  export interface BuildData {
204
- client: string[];
205
- server: string[];
201
+ app_dir: string;
202
+ manifest_data: ManifestData;
203
+ client: {
204
+ assets: OutputAsset[];
205
+ chunks: OutputChunk[];
206
+ entry: {
207
+ file: string;
208
+ js: string[];
209
+ css: string[];
210
+ };
211
+ vite_manifest: import('vite').Manifest;
212
+ };
213
+ server: {
214
+ chunks: OutputChunk[];
215
+ methods: Record<string, HttpMethod[]>;
216
+ vite_manifest: import('vite').Manifest;
217
+ };
206
218
  static: string[];
207
219
  entries: string[];
208
220
  }
package/types/page.d.ts CHANGED
@@ -1,18 +1,12 @@
1
1
  import { InferValue, MaybePromise, Rec } from './helper';
2
2
 
3
- export interface Page<Params extends Record<string, string> = Record<string, string>> {
4
- host: string;
5
- path: string;
6
- params: Params;
7
- query: URLSearchParams;
8
- }
9
-
10
3
  export interface LoadInput<
11
4
  PageParams extends Rec<string> = Rec<string>,
12
5
  Stuff extends Rec = Rec,
13
6
  Session = any
14
7
  > {
15
- page: Page<PageParams>;
8
+ url: URL;
9
+ params: PageParams;
16
10
  fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
17
11
  session: Session;
18
12
  stuff: Stuff;