@sveltejs/kit 1.0.0-next.285 → 1.0.0-next.286
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.
- package/dist/chunks/index.js +28 -4
- package/dist/cli.js +3 -3
- package/dist/node.js +3 -4
- package/package.json +1 -1
- package/types/ambient.d.ts +159 -65
- package/types/index.d.ts +18 -270
- package/types/internal.d.ts +18 -81
- package/types/private.d.ts +343 -0
package/dist/chunks/index.js
CHANGED
|
@@ -144,6 +144,24 @@ async function create_plugin(config, cwd) {
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
/** @param {Error} error */
|
|
148
|
+
function fix_stack_trace(error) {
|
|
149
|
+
// TODO https://github.com/vitejs/vite/issues/7045
|
|
150
|
+
|
|
151
|
+
// ideally vite would expose ssrRewriteStacktrace, but
|
|
152
|
+
// in lieu of that, we can implement it ourselves. we
|
|
153
|
+
// don't want to mutate the error object, because
|
|
154
|
+
// the stack trace could be 'fixed' multiple times,
|
|
155
|
+
// and Vite will fix stack traces before we even
|
|
156
|
+
// see them if they occur during ssrLoadModule
|
|
157
|
+
const original = error.stack;
|
|
158
|
+
vite.ssrFixStacktrace(error);
|
|
159
|
+
const fixed = error.stack;
|
|
160
|
+
error.stack = original;
|
|
161
|
+
|
|
162
|
+
return fixed;
|
|
163
|
+
}
|
|
164
|
+
|
|
147
165
|
update_manifest();
|
|
148
166
|
|
|
149
167
|
vite.watcher.on('add', update_manifest);
|
|
@@ -248,13 +266,19 @@ async function create_plugin(config, cwd) {
|
|
|
248
266
|
dev: true,
|
|
249
267
|
floc: config.kit.floc,
|
|
250
268
|
get_stack: (error) => {
|
|
251
|
-
|
|
252
|
-
return error.stack;
|
|
269
|
+
return fix_stack_trace(error);
|
|
253
270
|
},
|
|
254
271
|
handle_error: (error, event) => {
|
|
255
|
-
vite.ssrFixStacktrace(error);
|
|
256
272
|
hooks.handleError({
|
|
257
|
-
error,
|
|
273
|
+
error: new Proxy(error, {
|
|
274
|
+
get: (target, property) => {
|
|
275
|
+
if (property === 'stack') {
|
|
276
|
+
return fix_stack_trace(error);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return Reflect.get(target, property, target);
|
|
280
|
+
}
|
|
281
|
+
}),
|
|
258
282
|
event,
|
|
259
283
|
|
|
260
284
|
// TODO remove for 1.0
|
package/dist/cli.js
CHANGED
|
@@ -422,7 +422,7 @@ function get_mime_lookup(manifest_data) {
|
|
|
422
422
|
return mime;
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
/** @param {import('
|
|
425
|
+
/** @param {import('types').ValidatedConfig} config */
|
|
426
426
|
function get_aliases(config) {
|
|
427
427
|
const alias = {
|
|
428
428
|
__GENERATED__: path__default.posix.resolve(`${SVELTE_KIT}/generated`),
|
|
@@ -998,7 +998,7 @@ async function launch(port, https) {
|
|
|
998
998
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
1001
|
+
const prog = sade('svelte-kit').version('1.0.0-next.286');
|
|
1002
1002
|
|
|
1003
1003
|
prog
|
|
1004
1004
|
.command('dev')
|
|
@@ -1156,7 +1156,7 @@ async function check_port(port) {
|
|
|
1156
1156
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1157
1157
|
if (open) launch(port, https);
|
|
1158
1158
|
|
|
1159
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1159
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.286'}\n`));
|
|
1160
1160
|
|
|
1161
1161
|
const protocol = https ? 'https:' : 'http:';
|
|
1162
1162
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
2
|
|
|
3
|
-
/** @
|
|
3
|
+
/** @param {import('http').IncomingMessage} req */
|
|
4
4
|
function get_raw_body(req) {
|
|
5
5
|
return new Promise((fulfil, reject) => {
|
|
6
6
|
const h = req.headers;
|
|
@@ -50,7 +50,7 @@ function get_raw_body(req) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/** @type {import('@sveltejs/kit/node').
|
|
53
|
+
/** @type {import('@sveltejs/kit/node').getRequest} */
|
|
54
54
|
async function getRequest(base, req) {
|
|
55
55
|
let headers = /** @type {Record<string, string>} */ (req.headers);
|
|
56
56
|
if (req.httpVersionMajor === 2) {
|
|
@@ -69,9 +69,8 @@ async function getRequest(base, req) {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/** @type {import('@sveltejs/kit/node').
|
|
72
|
+
/** @type {import('@sveltejs/kit/node').setResponse} */
|
|
73
73
|
async function setResponse(res, response) {
|
|
74
|
-
/** @type {import('types').ResponseHeaders} */
|
|
75
74
|
const headers = Object.fromEntries(response.headers);
|
|
76
75
|
|
|
77
76
|
if (response.headers.has('set-cookie')) {
|
package/package.json
CHANGED
package/types/ambient.d.ts
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* It's possible to tell SvelteKit how to type objects inside your app by declaring the `App` namespace. By default, a new project will have a file called `src/app.d.ts` containing the following:
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* /// <reference types="@sveltejs/kit" />
|
|
6
|
+
*
|
|
7
|
+
* declare namespace App {
|
|
8
|
+
* interface Locals {}
|
|
9
|
+
*
|
|
10
|
+
* interface Platform {}
|
|
11
|
+
*
|
|
12
|
+
* interface Session {}
|
|
13
|
+
*
|
|
14
|
+
* interface Stuff {}
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, `session` and `stuff`:
|
|
19
|
+
*/
|
|
1
20
|
declare namespace App {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface
|
|
21
|
+
/**
|
|
22
|
+
* The interface that defines `event.locals`, which can be accessed in [hooks](/docs/hooks) (`handle`, `handleError` and `getSession`) and [endpoints](/docs/routing#endpoints).
|
|
23
|
+
*/
|
|
24
|
+
export interface Locals {}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* If your adapter provides [platform-specific context](/docs/adapters#supported-environments-platform-specific-context) via `event.platform`, you can specify it here.
|
|
28
|
+
*/
|
|
29
|
+
export interface Platform {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The interface that defines `session`, both as an argument to [`load`](/docs/loading) functions and the value of the [session store](/docs/modules#$app-stores).
|
|
33
|
+
*/
|
|
34
|
+
export interface Session {}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The interface that defines `stuff`, as input or output to [`load`](/docs/loading) or as the value of the `stuff` property of the [page store](/docs/modules#$app-stores).
|
|
38
|
+
*/
|
|
39
|
+
export interface Stuff {}
|
|
6
40
|
}
|
|
7
41
|
|
|
42
|
+
/**
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { amp, browser, dev, mode, prerendering } from '$app/env';
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
8
47
|
declare module '$app/env' {
|
|
9
48
|
/**
|
|
10
|
-
* Whether or not app is in AMP mode.
|
|
49
|
+
* Whether or not the app is running in [AMP mode](/docs/seo#manual-setup-amp).
|
|
11
50
|
*/
|
|
12
51
|
export const amp: boolean;
|
|
13
52
|
/**
|
|
@@ -30,14 +69,27 @@ declare module '$app/env' {
|
|
|
30
69
|
export const mode: string;
|
|
31
70
|
}
|
|
32
71
|
|
|
72
|
+
/**
|
|
73
|
+
* ```ts
|
|
74
|
+
* import {
|
|
75
|
+
* afterNavigate,
|
|
76
|
+
* beforeNavigate,
|
|
77
|
+
* disableScrollHandling,
|
|
78
|
+
* goto,
|
|
79
|
+
* invalidate,
|
|
80
|
+
* prefetch,
|
|
81
|
+
* prefetchRoutes
|
|
82
|
+
* } from '$app/navigation';
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
33
85
|
declare module '$app/navigation' {
|
|
34
86
|
/**
|
|
35
|
-
*
|
|
87
|
+
* If called when the page is being updated following a navigation (in `onMount` or an action, for example), this disables SvelteKit's built-in scroll handling.
|
|
36
88
|
* This is generally discouraged, since it breaks user expectations.
|
|
37
89
|
*/
|
|
38
90
|
export function disableScrollHandling(): void;
|
|
39
91
|
/**
|
|
40
|
-
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified href
|
|
92
|
+
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `href`.
|
|
41
93
|
*
|
|
42
94
|
* @param href Where to navigate to
|
|
43
95
|
* @param opts.replaceState If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
|
|
@@ -48,12 +100,12 @@ declare module '$app/navigation' {
|
|
|
48
100
|
export function goto(
|
|
49
101
|
href: string,
|
|
50
102
|
opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any }
|
|
51
|
-
): Promise<
|
|
103
|
+
): Promise<void>;
|
|
52
104
|
/**
|
|
53
|
-
*
|
|
105
|
+
* Causes any `load` functions belonging to the currently active page to re-run if they `fetch` the resource in question. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
54
106
|
* @param href The invalidated resource
|
|
55
107
|
*/
|
|
56
|
-
export function invalidate(href: string): Promise<
|
|
108
|
+
export function invalidate(href: string): Promise<void>;
|
|
57
109
|
/**
|
|
58
110
|
* Programmatically prefetches the given page, which means
|
|
59
111
|
* 1. ensuring that the code for the page is loaded, and
|
|
@@ -65,7 +117,7 @@ declare module '$app/navigation' {
|
|
|
65
117
|
*
|
|
66
118
|
* @param href Page to prefetch
|
|
67
119
|
*/
|
|
68
|
-
export function prefetch(href: string): Promise<
|
|
120
|
+
export function prefetch(href: string): Promise<void>;
|
|
69
121
|
/**
|
|
70
122
|
* Programmatically prefetches the code for routes that haven't yet been fetched.
|
|
71
123
|
* Typically, you might call this to speed up subsequent navigation.
|
|
@@ -76,92 +128,108 @@ declare module '$app/navigation' {
|
|
|
76
128
|
* Unlike prefetch, this won't call preload for individual pages.
|
|
77
129
|
* Returns a Promise that resolves when the routes have been prefetched.
|
|
78
130
|
*/
|
|
79
|
-
export function prefetchRoutes(routes?: string[]): Promise<
|
|
131
|
+
export function prefetchRoutes(routes?: string[]): Promise<void>;
|
|
80
132
|
|
|
81
133
|
/**
|
|
82
|
-
* A navigation interceptor that triggers before we navigate to a new
|
|
134
|
+
* A navigation interceptor that triggers before we navigate to a new URL (internal or external) whether by clicking a link, calling `goto`, or using the browser back/forward controls.
|
|
83
135
|
* This is helpful if we want to conditionally prevent a navigation from completing or lookup the upcoming url.
|
|
84
136
|
*/
|
|
85
137
|
export function beforeNavigate(
|
|
86
|
-
fn: (
|
|
87
|
-
):
|
|
138
|
+
fn: (navigation: { from: URL; to: URL | null; cancel: () => void }) => void
|
|
139
|
+
): void;
|
|
88
140
|
|
|
89
141
|
/**
|
|
90
142
|
* A lifecycle function that runs when the page mounts, and also whenever SvelteKit navigates to a new URL but stays on this component.
|
|
91
143
|
*/
|
|
92
|
-
export function afterNavigate(fn: (
|
|
144
|
+
export function afterNavigate(fn: (navigation: { from: URL | null; to: URL }) => void): void;
|
|
93
145
|
}
|
|
94
146
|
|
|
147
|
+
/**
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { base, assets } from '$app/paths';
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
95
152
|
declare module '$app/paths' {
|
|
96
153
|
/**
|
|
97
|
-
* A
|
|
154
|
+
* A string that matches [`config.kit.paths.base`](/docs/configuration#paths). It must begin, but not end, with a `/`.
|
|
98
155
|
*/
|
|
99
|
-
export const base: string
|
|
156
|
+
export const base: `/${string}`;
|
|
100
157
|
/**
|
|
101
|
-
*
|
|
158
|
+
* An absolute path that matches [`config.kit.paths.assets`](/docs/configuration#paths).
|
|
159
|
+
*
|
|
160
|
+
* > If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during [`svelte-kit dev`](/docs/cli#svelte-kit-dev) or [`svelte-kit preview`](/docs/cli#svelte-kit-preview), since the assets don't yet live at their eventual URL.
|
|
102
161
|
*/
|
|
103
|
-
export const assets: string
|
|
162
|
+
export const assets: `https://${string}` | `http://${string}`;
|
|
104
163
|
}
|
|
105
164
|
|
|
165
|
+
/**
|
|
166
|
+
* ```ts
|
|
167
|
+
* import { getStores, navigating, page, session, updated } from '$app/stores';
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* Stores are _contextual_ — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `session` and `page` are unique to each request on the server, rather than shared between multiple requests handled by the same server simultaneously, which is what makes it safe to include user-specific data in `session`.
|
|
171
|
+
*
|
|
172
|
+
* Because of that, you must subscribe to the stores during component initialization (which happens automatically if you reference the store value, e.g. as `$page`, in a component) before you can use them.
|
|
173
|
+
*/
|
|
106
174
|
declare module '$app/stores' {
|
|
107
175
|
import { Readable, Writable } from 'svelte/store';
|
|
108
|
-
|
|
176
|
+
import { Navigation, Page } from '@sveltejs/kit';
|
|
109
177
|
|
|
110
178
|
/**
|
|
111
|
-
* A convenience function around `getContext
|
|
112
|
-
*
|
|
179
|
+
* A convenience function around `getContext`. Must be called during component initialization.
|
|
180
|
+
* Only use this if you need to defer store subscription until after the component has mounted, for some reason.
|
|
113
181
|
*/
|
|
114
182
|
export function getStores(): {
|
|
115
183
|
navigating: typeof navigating;
|
|
116
184
|
page: typeof page;
|
|
117
|
-
session:
|
|
185
|
+
session: typeof session;
|
|
118
186
|
updated: typeof updated;
|
|
119
187
|
};
|
|
188
|
+
|
|
120
189
|
/**
|
|
121
190
|
* A readable store whose value contains page data.
|
|
122
191
|
*/
|
|
123
|
-
export const page: Readable<
|
|
124
|
-
url: URL;
|
|
125
|
-
params: Record<string, string>;
|
|
126
|
-
stuff: App.Stuff;
|
|
127
|
-
status: number;
|
|
128
|
-
error: Error | null;
|
|
129
|
-
}>;
|
|
192
|
+
export const page: Readable<Page>;
|
|
130
193
|
/**
|
|
131
194
|
* A readable store.
|
|
132
|
-
* When navigating starts, its value is `{ from: URL, to: URL }
|
|
195
|
+
* When navigating starts, its value is `{ from: URL, to: URL }`,
|
|
133
196
|
* When navigating finishes, its value reverts to `null`.
|
|
134
197
|
*/
|
|
135
|
-
export const navigating: Readable<
|
|
198
|
+
export const navigating: Readable<Navigation | null>;
|
|
136
199
|
/**
|
|
137
|
-
* A writable store whose initial value is whatever was returned from `getSession
|
|
200
|
+
* A writable store whose initial value is whatever was returned from [`getSession`](/docs/hooks#getsession).
|
|
138
201
|
* It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
|
|
139
202
|
*/
|
|
140
203
|
export const session: Writable<App.Session>;
|
|
141
204
|
/**
|
|
142
|
-
*
|
|
143
|
-
* It can be written to when custom logic is required to detect updates.
|
|
205
|
+
* A readable store whose initial value is `false`. If [`version.pollInterval`](/docs/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update the store value to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
|
|
144
206
|
*/
|
|
145
207
|
export const updated: Readable<boolean> & { check: () => boolean };
|
|
146
208
|
}
|
|
147
209
|
|
|
210
|
+
/**
|
|
211
|
+
* This is a simple alias to `src/lib`, or whatever directory is specified as [`config.kit.files.lib`](/docs/configuration#files). It allows you to access common components and utility modules without `../../../../` nonsense.
|
|
212
|
+
*/
|
|
213
|
+
declare module '$lib' {}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* ```ts
|
|
217
|
+
* import { build, files, timestamp } from '$service-worker';
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* This module is only available to [service workers](/docs/service-workers).
|
|
221
|
+
*/
|
|
148
222
|
declare module '$service-worker' {
|
|
149
223
|
/**
|
|
150
224
|
* An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`.
|
|
151
|
-
* This is only available to service workers.
|
|
152
225
|
*/
|
|
153
226
|
export const build: string[];
|
|
154
227
|
/**
|
|
155
|
-
* An array of URL strings representing the files in your static directory,
|
|
156
|
-
* or whatever directory is specified by `config.kit.files.assets`.
|
|
157
|
-
* This is only available to service workers.
|
|
228
|
+
* An array of URL strings representing the files in your static directory, or whatever directory is specified by `config.kit.files.assets`. You can customize which files are included from `static` directory using [`config.kit.serviceWorker.files`](/docs/configuration)
|
|
158
229
|
*/
|
|
159
230
|
export const files: string[];
|
|
160
231
|
/**
|
|
161
|
-
* The result of calling `Date.now()` at build time.
|
|
162
|
-
* It's useful for generating unique cache names inside your service worker,
|
|
163
|
-
* so that a later deployment of your app can invalidate old caches.
|
|
164
|
-
* This is only available to service workers.
|
|
232
|
+
* The result of calling `Date.now()` at build time. It's useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.
|
|
165
233
|
*/
|
|
166
234
|
export const timestamp: number;
|
|
167
235
|
}
|
|
@@ -170,33 +238,48 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
170
238
|
import { Handle } from '@sveltejs/kit';
|
|
171
239
|
|
|
172
240
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
241
|
+
* A helper function for sequencing multiple `handle` calls in a middleware-like manner.
|
|
242
|
+
*
|
|
243
|
+
* ```js
|
|
244
|
+
* /// file: src/hooks.js
|
|
245
|
+
* import { sequence } from '@sveltejs/kit/hooks';
|
|
246
|
+
*
|
|
247
|
+
* /** @type {import('@sveltejs/kit').Handle} *\/
|
|
248
|
+
* async function first({ event, resolve }) {
|
|
249
|
+
* console.log('first pre-processing');
|
|
250
|
+
* const result = await resolve(event);
|
|
251
|
+
* console.log('first post-processing');
|
|
252
|
+
* return result;
|
|
253
|
+
* }
|
|
254
|
+
*
|
|
255
|
+
* /** @type {import('@sveltejs/kit').Handle} *\/
|
|
256
|
+
* async function second({ event, resolve }) {
|
|
257
|
+
* console.log('second pre-processing');
|
|
258
|
+
* const result = await resolve(event);
|
|
259
|
+
* console.log('second post-processing');
|
|
260
|
+
* return result;
|
|
261
|
+
* }
|
|
262
|
+
*
|
|
263
|
+
* export const handle = sequence(first, second);
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* The example above would print:
|
|
267
|
+
*
|
|
268
|
+
* ```
|
|
269
|
+
* first pre-processing
|
|
270
|
+
* second pre-processing
|
|
271
|
+
* second post-processing
|
|
272
|
+
* first post-processing
|
|
273
|
+
* ```
|
|
175
274
|
*
|
|
176
275
|
* @param handlers The chain of `handle` functions
|
|
177
276
|
*/
|
|
178
277
|
export function sequence(...handlers: Handle[]): Handle;
|
|
179
278
|
}
|
|
180
279
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
export interface GetRawBody {
|
|
185
|
-
(request: IncomingMessage): Promise<Uint8Array | null>;
|
|
186
|
-
}
|
|
187
|
-
export const getRawBody: GetRawBody;
|
|
188
|
-
|
|
189
|
-
export interface GetRequest {
|
|
190
|
-
(base: string, request: IncomingMessage): Promise<Request>;
|
|
191
|
-
}
|
|
192
|
-
export const getRequest: GetRequest;
|
|
193
|
-
|
|
194
|
-
export interface SetResponse {
|
|
195
|
-
(res: ServerResponse, response: Response): void;
|
|
196
|
-
}
|
|
197
|
-
export const setResponse: SetResponse;
|
|
198
|
-
}
|
|
199
|
-
|
|
280
|
+
/**
|
|
281
|
+
* A polyfill for `fetch` and its related interfaces, used by adapters for environments that don't provide a native implementation.
|
|
282
|
+
*/
|
|
200
283
|
declare module '@sveltejs/kit/install-fetch' {
|
|
201
284
|
import fetch, { Headers, Request, Response } from 'node-fetch';
|
|
202
285
|
|
|
@@ -204,3 +287,14 @@ declare module '@sveltejs/kit/install-fetch' {
|
|
|
204
287
|
|
|
205
288
|
export { fetch, Headers, Request, Response };
|
|
206
289
|
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Utilities used by adapters for Node-like environments.
|
|
293
|
+
*/
|
|
294
|
+
declare module '@sveltejs/kit/node' {
|
|
295
|
+
export function getRequest(
|
|
296
|
+
base: string,
|
|
297
|
+
request: import('http').IncomingMessage
|
|
298
|
+
): Promise<Request>;
|
|
299
|
+
export function setResponse(res: import('http').ServerResponse, response: Response): void;
|
|
300
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -5,82 +5,27 @@ import './ambient';
|
|
|
5
5
|
|
|
6
6
|
import { CompileOptions } from 'svelte/types/compiler/interfaces';
|
|
7
7
|
import {
|
|
8
|
-
AdapterEntry,
|
|
9
8
|
Body,
|
|
9
|
+
Builder,
|
|
10
|
+
CspDirectives,
|
|
10
11
|
Either,
|
|
12
|
+
EndpointOutput,
|
|
13
|
+
ErrorLoadInput,
|
|
11
14
|
Fallthrough,
|
|
12
|
-
|
|
15
|
+
LoadInput,
|
|
16
|
+
LoadOutput,
|
|
13
17
|
MaybePromise,
|
|
14
18
|
PrerenderOnErrorValue,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
ResponseHeaders,
|
|
18
|
-
RouteDefinition,
|
|
19
|
-
SSRNodeLoader,
|
|
20
|
-
SSRRoute,
|
|
19
|
+
RequestEvent,
|
|
20
|
+
ResolveOptions,
|
|
21
21
|
TrailingSlash
|
|
22
|
-
} from './
|
|
22
|
+
} from './private';
|
|
23
23
|
|
|
24
24
|
export interface Adapter {
|
|
25
25
|
name: string;
|
|
26
26
|
adapt(builder: Builder): Promise<void>;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export interface Builder {
|
|
30
|
-
log: Logger;
|
|
31
|
-
rimraf(dir: string): void;
|
|
32
|
-
mkdirp(dir: string): void;
|
|
33
|
-
|
|
34
|
-
appDir: string;
|
|
35
|
-
trailingSlash: TrailingSlash;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Create entry points that map to individual functions
|
|
39
|
-
* @param fn A function that groups a set of routes into an entry point
|
|
40
|
-
*/
|
|
41
|
-
createEntries(fn: (route: RouteDefinition) => AdapterEntry): void;
|
|
42
|
-
|
|
43
|
-
generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
|
|
44
|
-
|
|
45
|
-
getBuildDirectory(name: string): string;
|
|
46
|
-
getClientDirectory(): string;
|
|
47
|
-
getServerDirectory(): string;
|
|
48
|
-
getStaticDirectory(): string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @param dest the destination folder to which files should be copied
|
|
52
|
-
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
53
|
-
*/
|
|
54
|
-
writeClient(dest: string): string[];
|
|
55
|
-
/**
|
|
56
|
-
* @param dest the destination folder to which files should be copied
|
|
57
|
-
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
58
|
-
*/
|
|
59
|
-
writeServer(dest: string): string[];
|
|
60
|
-
/**
|
|
61
|
-
* @param dest the destination folder to which files should be copied
|
|
62
|
-
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
63
|
-
*/
|
|
64
|
-
writeStatic(dest: string): string[];
|
|
65
|
-
/**
|
|
66
|
-
* @param from the source file or folder
|
|
67
|
-
* @param to the destination file or folder
|
|
68
|
-
* @param opts.filter a function to determine whether a file or folder should be copied
|
|
69
|
-
* @param opts.replace a map of strings to replace
|
|
70
|
-
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
71
|
-
*/
|
|
72
|
-
copy(
|
|
73
|
-
from: string,
|
|
74
|
-
to: string,
|
|
75
|
-
opts?: {
|
|
76
|
-
filter?: (basename: string) => boolean;
|
|
77
|
-
replace?: Record<string, string>;
|
|
78
|
-
}
|
|
79
|
-
): string[];
|
|
80
|
-
|
|
81
|
-
prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<Prerendered>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
29
|
export interface Config {
|
|
85
30
|
compilerOptions?: CompileOptions;
|
|
86
31
|
extensions?: string[];
|
|
@@ -142,129 +87,10 @@ export interface Config {
|
|
|
142
87
|
preprocess?: any;
|
|
143
88
|
}
|
|
144
89
|
|
|
145
|
-
// Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts
|
|
146
|
-
//
|
|
147
|
-
// MIT License
|
|
148
|
-
//
|
|
149
|
-
// Copyright (c) 2021-present, Joshua Hemphill
|
|
150
|
-
// Copyright (c) 2021, Tecnico Corporation
|
|
151
|
-
//
|
|
152
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
153
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
154
|
-
// in the Software without restriction, including without limitation the rights
|
|
155
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
156
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
157
|
-
// furnished to do so, subject to the following conditions:
|
|
158
|
-
//
|
|
159
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
160
|
-
// copies or substantial portions of the Software.
|
|
161
|
-
//
|
|
162
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
163
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
164
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
165
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
166
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
167
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
168
|
-
// SOFTWARE.
|
|
169
|
-
|
|
170
|
-
export namespace Csp {
|
|
171
|
-
type ActionSource = 'strict-dynamic' | 'report-sample';
|
|
172
|
-
type BaseSource = 'self' | 'unsafe-eval' | 'unsafe-hashes' | 'unsafe-inline' | 'none';
|
|
173
|
-
type CryptoSource = `${'nonce' | 'sha256' | 'sha384' | 'sha512'}-${string}`;
|
|
174
|
-
type FrameSource = HostSource | SchemeSource | 'self' | 'none';
|
|
175
|
-
type HostNameScheme = `${string}.${string}` | 'localhost';
|
|
176
|
-
type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`;
|
|
177
|
-
type HostProtocolSchemes = `${string}://` | '';
|
|
178
|
-
type HttpDelineator = '/' | '?' | '#' | '\\';
|
|
179
|
-
type PortScheme = `:${number}` | '' | ':*';
|
|
180
|
-
type SchemeSource = 'http:' | 'https:' | 'data:' | 'mediastream:' | 'blob:' | 'filesystem:';
|
|
181
|
-
type Source = HostSource | SchemeSource | CryptoSource | BaseSource;
|
|
182
|
-
type Sources = Source[];
|
|
183
|
-
type UriPath = `${HttpDelineator}${string}`;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export type CspDirectives = {
|
|
187
|
-
'child-src'?: Csp.Sources;
|
|
188
|
-
'default-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
189
|
-
'frame-src'?: Csp.Sources;
|
|
190
|
-
'worker-src'?: Csp.Sources;
|
|
191
|
-
'connect-src'?: Csp.Sources;
|
|
192
|
-
'font-src'?: Csp.Sources;
|
|
193
|
-
'img-src'?: Csp.Sources;
|
|
194
|
-
'manifest-src'?: Csp.Sources;
|
|
195
|
-
'media-src'?: Csp.Sources;
|
|
196
|
-
'object-src'?: Csp.Sources;
|
|
197
|
-
'prefetch-src'?: Csp.Sources;
|
|
198
|
-
'script-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
199
|
-
'script-src-elem'?: Csp.Sources;
|
|
200
|
-
'script-src-attr'?: Csp.Sources;
|
|
201
|
-
'style-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
202
|
-
'style-src-elem'?: Csp.Sources;
|
|
203
|
-
'style-src-attr'?: Csp.Sources;
|
|
204
|
-
'base-uri'?: Array<Csp.Source | Csp.ActionSource>;
|
|
205
|
-
sandbox?: Array<
|
|
206
|
-
| 'allow-downloads-without-user-activation'
|
|
207
|
-
| 'allow-forms'
|
|
208
|
-
| 'allow-modals'
|
|
209
|
-
| 'allow-orientation-lock'
|
|
210
|
-
| 'allow-pointer-lock'
|
|
211
|
-
| 'allow-popups'
|
|
212
|
-
| 'allow-popups-to-escape-sandbox'
|
|
213
|
-
| 'allow-presentation'
|
|
214
|
-
| 'allow-same-origin'
|
|
215
|
-
| 'allow-scripts'
|
|
216
|
-
| 'allow-storage-access-by-user-activation'
|
|
217
|
-
| 'allow-top-navigation'
|
|
218
|
-
| 'allow-top-navigation-by-user-activation'
|
|
219
|
-
>;
|
|
220
|
-
'form-action'?: Array<Csp.Source | Csp.ActionSource>;
|
|
221
|
-
'frame-ancestors'?: Array<Csp.HostSource | Csp.SchemeSource | Csp.FrameSource>;
|
|
222
|
-
'navigate-to'?: Array<Csp.Source | Csp.ActionSource>;
|
|
223
|
-
'report-uri'?: Csp.UriPath[];
|
|
224
|
-
'report-to'?: string[];
|
|
225
|
-
|
|
226
|
-
'require-trusted-types-for'?: Array<'script'>;
|
|
227
|
-
'trusted-types'?: Array<'none' | 'allow-duplicates' | '*' | string>;
|
|
228
|
-
'upgrade-insecure-requests'?: boolean;
|
|
229
|
-
|
|
230
|
-
/** @deprecated */
|
|
231
|
-
'require-sri-for'?: Array<'script' | 'style' | 'script style'>;
|
|
232
|
-
|
|
233
|
-
/** @deprecated */
|
|
234
|
-
'block-all-mixed-content'?: boolean;
|
|
235
|
-
|
|
236
|
-
/** @deprecated */
|
|
237
|
-
'plugin-types'?: Array<`${string}/${string}` | 'none'>;
|
|
238
|
-
|
|
239
|
-
/** @deprecated */
|
|
240
|
-
referrer?: Array<
|
|
241
|
-
| 'no-referrer'
|
|
242
|
-
| 'no-referrer-when-downgrade'
|
|
243
|
-
| 'origin'
|
|
244
|
-
| 'origin-when-cross-origin'
|
|
245
|
-
| 'same-origin'
|
|
246
|
-
| 'strict-origin'
|
|
247
|
-
| 'strict-origin-when-cross-origin'
|
|
248
|
-
| 'unsafe-url'
|
|
249
|
-
| 'none'
|
|
250
|
-
>;
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
export interface EndpointOutput<Output extends Body = Body> {
|
|
254
|
-
status?: number;
|
|
255
|
-
headers?: Headers | Partial<ResponseHeaders>;
|
|
256
|
-
body?: Output;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
90
|
export interface ErrorLoad<Params = Record<string, string>, Props = Record<string, any>> {
|
|
260
91
|
(input: ErrorLoadInput<Params>): MaybePromise<LoadOutput<Props>>;
|
|
261
92
|
}
|
|
262
93
|
|
|
263
|
-
export interface ErrorLoadInput<Params = Record<string, string>> extends LoadInput<Params> {
|
|
264
|
-
status?: number;
|
|
265
|
-
error?: Error;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
94
|
export interface ExternalFetch {
|
|
269
95
|
(req: Request): Promise<Response>;
|
|
270
96
|
}
|
|
@@ -288,105 +114,27 @@ export interface Load<Params = Record<string, string>, Props = Record<string, an
|
|
|
288
114
|
(input: LoadInput<Params>): MaybePromise<Either<Fallthrough, LoadOutput<Props>>>;
|
|
289
115
|
}
|
|
290
116
|
|
|
291
|
-
export interface
|
|
117
|
+
export interface Page<Params extends Record<string, string> = Record<string, string>> {
|
|
292
118
|
url: URL;
|
|
293
119
|
params: Params;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
stuff: Partial<App.Stuff>;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export interface LoadOutput<Props = Record<string, any>> {
|
|
301
|
-
status?: number;
|
|
302
|
-
error?: string | Error;
|
|
303
|
-
redirect?: string;
|
|
304
|
-
props?: Props;
|
|
305
|
-
stuff?: Partial<App.Stuff>;
|
|
306
|
-
maxage?: number;
|
|
120
|
+
stuff: App.Stuff;
|
|
121
|
+
status: number;
|
|
122
|
+
error: Error | null;
|
|
307
123
|
}
|
|
308
124
|
|
|
309
|
-
export interface
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
{
|
|
313
|
-
/** The location of the .html file relative to the output directory */
|
|
314
|
-
file: string;
|
|
315
|
-
}
|
|
316
|
-
>;
|
|
317
|
-
assets: Map<
|
|
318
|
-
string,
|
|
319
|
-
{
|
|
320
|
-
/** The MIME type of the asset */
|
|
321
|
-
type: string;
|
|
322
|
-
}
|
|
323
|
-
>;
|
|
324
|
-
redirects: Map<
|
|
325
|
-
string,
|
|
326
|
-
{
|
|
327
|
-
status: number;
|
|
328
|
-
location: string;
|
|
329
|
-
}
|
|
330
|
-
>;
|
|
331
|
-
/** An array of prerendered paths (without trailing slashes, regardless of the trailingSlash config) */
|
|
332
|
-
paths: string[];
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export interface PrerenderErrorHandler {
|
|
336
|
-
(details: {
|
|
337
|
-
status: number;
|
|
338
|
-
path: string;
|
|
339
|
-
referrer: string | null;
|
|
340
|
-
referenceType: 'linked' | 'fetched';
|
|
341
|
-
}): void;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
export interface RequestEvent<Params = Record<string, string>> {
|
|
345
|
-
request: Request;
|
|
346
|
-
url: URL;
|
|
347
|
-
params: Params;
|
|
348
|
-
locals: App.Locals;
|
|
349
|
-
platform: Readonly<App.Platform>;
|
|
125
|
+
export interface Navigation {
|
|
126
|
+
from: URL;
|
|
127
|
+
to: URL;
|
|
350
128
|
}
|
|
351
129
|
|
|
352
130
|
/**
|
|
353
131
|
* A function exported from an endpoint that corresponds to an
|
|
354
|
-
* HTTP verb (get
|
|
132
|
+
* HTTP verb (`get`, `put`, `patch`, etc) and handles requests with
|
|
355
133
|
* that method. Note that since 'delete' is a reserved word in
|
|
356
|
-
* JavaScript, delete handles are called
|
|
134
|
+
* JavaScript, delete handles are called `del` instead.
|
|
357
135
|
*/
|
|
358
136
|
export interface RequestHandler<Params = Record<string, string>, Output extends Body = Body> {
|
|
359
137
|
(event: RequestEvent<Params>): MaybePromise<
|
|
360
138
|
Either<Output extends Response ? Response : EndpointOutput<Output>, Fallthrough>
|
|
361
139
|
>;
|
|
362
140
|
}
|
|
363
|
-
|
|
364
|
-
export interface RequestOptions {
|
|
365
|
-
platform?: App.Platform;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
export type ResolveOptions = Partial<RequiredResolveOptions>;
|
|
369
|
-
|
|
370
|
-
export class Server {
|
|
371
|
-
constructor(manifest: SSRManifest);
|
|
372
|
-
respond(request: Request, options?: RequestOptions): Promise<Response>;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
export interface SSRManifest {
|
|
376
|
-
appDir: string;
|
|
377
|
-
assets: Set<string>;
|
|
378
|
-
/** private fields */
|
|
379
|
-
_: {
|
|
380
|
-
mime: Record<string, string>;
|
|
381
|
-
entry: {
|
|
382
|
-
file: string;
|
|
383
|
-
js: string[];
|
|
384
|
-
css: string[];
|
|
385
|
-
};
|
|
386
|
-
nodes: SSRNodeLoader[];
|
|
387
|
-
routes: SSRRoute[];
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// TODO should this be public?
|
|
392
|
-
export type ValidatedConfig = RecursiveRequired<Config>;
|
package/types/internal.d.ts
CHANGED
|
@@ -1,42 +1,28 @@
|
|
|
1
1
|
import { OutputAsset, OutputChunk } from 'rollup';
|
|
2
2
|
import {
|
|
3
|
-
SSRManifest,
|
|
4
|
-
ValidatedConfig,
|
|
5
3
|
RequestHandler,
|
|
6
4
|
Load,
|
|
7
5
|
ExternalFetch,
|
|
8
6
|
GetSession,
|
|
9
7
|
Handle,
|
|
10
8
|
HandleError,
|
|
9
|
+
Config
|
|
10
|
+
} from './index';
|
|
11
|
+
import {
|
|
12
|
+
Either,
|
|
13
|
+
Fallthrough,
|
|
14
|
+
HttpMethod,
|
|
15
|
+
JSONObject,
|
|
16
|
+
MaybePromise,
|
|
11
17
|
RequestEvent,
|
|
12
18
|
RequestOptions,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
|
|
21
|
-
* be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
|
|
22
|
-
*/
|
|
23
|
-
id: string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A function that compares the candidate route with the current route to determine
|
|
27
|
-
* if it should be treated as a fallback for the current route. For example, `/foo/[c]`
|
|
28
|
-
* is a fallback for `/foo/a-[b]`, and `/[...catchall]` is a fallback for all routes
|
|
29
|
-
*/
|
|
30
|
-
filter: (route: RouteDefinition) => boolean;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A function that is invoked once the entry has been created. This is where you
|
|
34
|
-
* should write the function to the filesystem and generate redirect manifests.
|
|
35
|
-
*/
|
|
36
|
-
complete: (entry: {
|
|
37
|
-
generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
|
|
38
|
-
}) => void;
|
|
39
|
-
}
|
|
19
|
+
ResolveOptions,
|
|
20
|
+
ResponseHeaders,
|
|
21
|
+
RouteSegment,
|
|
22
|
+
Server,
|
|
23
|
+
SSRManifest,
|
|
24
|
+
TrailingSlash
|
|
25
|
+
} from './private';
|
|
40
26
|
|
|
41
27
|
export interface ServerModule {
|
|
42
28
|
Server: typeof InternalServer;
|
|
@@ -58,8 +44,6 @@ export interface Asset {
|
|
|
58
44
|
type: string | null;
|
|
59
45
|
}
|
|
60
46
|
|
|
61
|
-
export type Body = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
|
|
62
|
-
|
|
63
47
|
export interface BuildData {
|
|
64
48
|
app_dir: string;
|
|
65
49
|
manifest_data: ManifestData;
|
|
@@ -89,8 +73,6 @@ export type CSRComponentLoader = () => Promise<CSRComponent>;
|
|
|
89
73
|
|
|
90
74
|
export type CSRRoute = [RegExp, CSRComponentLoader[], CSRComponentLoader[], GetParams?, HasShadow?];
|
|
91
75
|
|
|
92
|
-
export type Either<T, U> = Only<T, U> | Only<U, T>;
|
|
93
|
-
|
|
94
76
|
export interface EndpointData {
|
|
95
77
|
type: 'endpoint';
|
|
96
78
|
key: string;
|
|
@@ -100,10 +82,6 @@ export interface EndpointData {
|
|
|
100
82
|
file: string;
|
|
101
83
|
}
|
|
102
84
|
|
|
103
|
-
export interface Fallthrough {
|
|
104
|
-
fallthrough: true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
85
|
export type GetParams = (match: RegExpExecArray) => Record<string, string>;
|
|
108
86
|
|
|
109
87
|
type HasShadow = 1;
|
|
@@ -115,8 +93,6 @@ export interface Hooks {
|
|
|
115
93
|
handleError: HandleError;
|
|
116
94
|
}
|
|
117
95
|
|
|
118
|
-
export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
|
|
119
|
-
|
|
120
96
|
export class InternalServer extends Server {
|
|
121
97
|
respond(
|
|
122
98
|
request: Request,
|
|
@@ -126,19 +102,6 @@ export class InternalServer extends Server {
|
|
|
126
102
|
): Promise<Response>;
|
|
127
103
|
}
|
|
128
104
|
|
|
129
|
-
export type JSONObject = { [key: string]: JSONValue };
|
|
130
|
-
|
|
131
|
-
export type JSONValue = string | number | boolean | null | ToJSON | JSONValue[] | JSONObject;
|
|
132
|
-
|
|
133
|
-
export interface Logger {
|
|
134
|
-
(msg: string): void;
|
|
135
|
-
success(msg: string): void;
|
|
136
|
-
error(msg: string): void;
|
|
137
|
-
warn(msg: string): void;
|
|
138
|
-
minor(msg: string): void;
|
|
139
|
-
info(msg: string): void;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
105
|
export interface ManifestData {
|
|
143
106
|
assets: Asset[];
|
|
144
107
|
layout: string;
|
|
@@ -147,8 +110,6 @@ export interface ManifestData {
|
|
|
147
110
|
routes: RouteData[];
|
|
148
111
|
}
|
|
149
112
|
|
|
150
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
151
|
-
|
|
152
113
|
export interface MethodOverride {
|
|
153
114
|
parameter: string;
|
|
154
115
|
allowed: string[];
|
|
@@ -166,8 +127,6 @@ export type NormalizedLoadOutput = Either<
|
|
|
166
127
|
Fallthrough
|
|
167
128
|
>;
|
|
168
129
|
|
|
169
|
-
type Only<T, U> = { [P in keyof T]: T[P] } & { [P in Exclude<keyof U, keyof T>]?: never };
|
|
170
|
-
|
|
171
130
|
export interface PageData {
|
|
172
131
|
type: 'page';
|
|
173
132
|
key: string;
|
|
@@ -185,8 +144,6 @@ export interface PrerenderDependency {
|
|
|
185
144
|
body: null | string | Uint8Array;
|
|
186
145
|
}
|
|
187
146
|
|
|
188
|
-
export type PrerenderOnErrorValue = 'fail' | 'continue' | PrerenderErrorHandler;
|
|
189
|
-
|
|
190
147
|
export interface PrerenderOptions {
|
|
191
148
|
fallback?: string;
|
|
192
149
|
all: boolean;
|
|
@@ -204,33 +161,14 @@ export type RecursiveRequired<T> = {
|
|
|
204
161
|
: T[K]; // Use the exact type for everything else
|
|
205
162
|
};
|
|
206
163
|
|
|
207
|
-
export
|
|
208
|
-
ssr: boolean;
|
|
209
|
-
transformPage: ({ html }: { html: string }) => MaybePromise<string>;
|
|
210
|
-
}
|
|
164
|
+
export type RequiredResolveOptions = Required<ResolveOptions>;
|
|
211
165
|
|
|
212
166
|
export interface Respond {
|
|
213
167
|
(request: Request, options: SSROptions, state?: SSRState): Promise<Response>;
|
|
214
168
|
}
|
|
215
169
|
|
|
216
|
-
/** `string[]` is only for set-cookie, everything else must be type of `string` */
|
|
217
|
-
export type ResponseHeaders = Record<string, string | number | string[]>;
|
|
218
|
-
|
|
219
170
|
export type RouteData = PageData | EndpointData;
|
|
220
171
|
|
|
221
|
-
export interface RouteDefinition {
|
|
222
|
-
type: 'page' | 'endpoint';
|
|
223
|
-
pattern: RegExp;
|
|
224
|
-
segments: RouteSegment[];
|
|
225
|
-
methods: HttpMethod[];
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export interface RouteSegment {
|
|
229
|
-
content: string;
|
|
230
|
-
dynamic: boolean;
|
|
231
|
-
rest: boolean;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
172
|
export interface ShadowEndpointOutput<Output extends JSONObject = JSONObject> {
|
|
235
173
|
status?: number;
|
|
236
174
|
headers?: Partial<ResponseHeaders>;
|
|
@@ -365,8 +303,7 @@ export interface SSRState {
|
|
|
365
303
|
|
|
366
304
|
export type StrictBody = string | Uint8Array;
|
|
367
305
|
|
|
368
|
-
type
|
|
369
|
-
|
|
370
|
-
export type TrailingSlash = 'never' | 'always' | 'ignore';
|
|
306
|
+
export type ValidatedConfig = RecursiveRequired<Config>;
|
|
371
307
|
|
|
372
308
|
export * from './index';
|
|
309
|
+
export * from './private';
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// This module contains types that are visible in the documentation,
|
|
2
|
+
// but which cannot be imported from `@sveltejs/kit`. Care should
|
|
3
|
+
// be taken to avoid breaking changes when editing this file
|
|
4
|
+
|
|
5
|
+
import { SSRNodeLoader, SSRRoute } from './internal';
|
|
6
|
+
|
|
7
|
+
export interface AdapterEntry {
|
|
8
|
+
/**
|
|
9
|
+
* A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
|
|
10
|
+
* For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
|
|
11
|
+
* be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
|
|
12
|
+
*/
|
|
13
|
+
id: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A function that compares the candidate route with the current route to determine
|
|
17
|
+
* if it should be treated as a fallback for the current route. For example, `/foo/[c]`
|
|
18
|
+
* is a fallback for `/foo/a-[b]`, and `/[...catchall]` is a fallback for all routes
|
|
19
|
+
*/
|
|
20
|
+
filter: (route: RouteDefinition) => boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A function that is invoked once the entry has been created. This is where you
|
|
24
|
+
* should write the function to the filesystem and generate redirect manifests.
|
|
25
|
+
*/
|
|
26
|
+
complete: (entry: {
|
|
27
|
+
generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
|
|
28
|
+
}) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type Body = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
|
|
32
|
+
|
|
33
|
+
export interface Builder {
|
|
34
|
+
log: Logger;
|
|
35
|
+
rimraf(dir: string): void;
|
|
36
|
+
mkdirp(dir: string): void;
|
|
37
|
+
|
|
38
|
+
appDir: string;
|
|
39
|
+
trailingSlash: TrailingSlash;
|
|
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
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param dest the destination folder to which files should be copied
|
|
56
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
57
|
+
*/
|
|
58
|
+
writeClient(dest: string): string[];
|
|
59
|
+
/**
|
|
60
|
+
* @param dest the destination folder to which files should be copied
|
|
61
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
62
|
+
*/
|
|
63
|
+
writeServer(dest: string): string[];
|
|
64
|
+
/**
|
|
65
|
+
* @param dest the destination folder to which files should be copied
|
|
66
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
67
|
+
*/
|
|
68
|
+
writeStatic(dest: string): string[];
|
|
69
|
+
/**
|
|
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
|
|
74
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
75
|
+
*/
|
|
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<Prerendered>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts
|
|
89
|
+
//
|
|
90
|
+
// MIT License
|
|
91
|
+
//
|
|
92
|
+
// Copyright (c) 2021-present, Joshua Hemphill
|
|
93
|
+
// Copyright (c) 2021, Tecnico Corporation
|
|
94
|
+
//
|
|
95
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
96
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
97
|
+
// in the Software without restriction, including without limitation the rights
|
|
98
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
99
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
100
|
+
// furnished to do so, subject to the following conditions:
|
|
101
|
+
//
|
|
102
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
103
|
+
// copies or substantial portions of the Software.
|
|
104
|
+
//
|
|
105
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
106
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
107
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
108
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
109
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
110
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
111
|
+
// SOFTWARE.
|
|
112
|
+
|
|
113
|
+
export namespace Csp {
|
|
114
|
+
type ActionSource = 'strict-dynamic' | 'report-sample';
|
|
115
|
+
type BaseSource = 'self' | 'unsafe-eval' | 'unsafe-hashes' | 'unsafe-inline' | 'none';
|
|
116
|
+
type CryptoSource = `${'nonce' | 'sha256' | 'sha384' | 'sha512'}-${string}`;
|
|
117
|
+
type FrameSource = HostSource | SchemeSource | 'self' | 'none';
|
|
118
|
+
type HostNameScheme = `${string}.${string}` | 'localhost';
|
|
119
|
+
type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`;
|
|
120
|
+
type HostProtocolSchemes = `${string}://` | '';
|
|
121
|
+
type HttpDelineator = '/' | '?' | '#' | '\\';
|
|
122
|
+
type PortScheme = `:${number}` | '' | ':*';
|
|
123
|
+
type SchemeSource = 'http:' | 'https:' | 'data:' | 'mediastream:' | 'blob:' | 'filesystem:';
|
|
124
|
+
type Source = HostSource | SchemeSource | CryptoSource | BaseSource;
|
|
125
|
+
type Sources = Source[];
|
|
126
|
+
type UriPath = `${HttpDelineator}${string}`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type CspDirectives = {
|
|
130
|
+
'child-src'?: Csp.Sources;
|
|
131
|
+
'default-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
132
|
+
'frame-src'?: Csp.Sources;
|
|
133
|
+
'worker-src'?: Csp.Sources;
|
|
134
|
+
'connect-src'?: Csp.Sources;
|
|
135
|
+
'font-src'?: Csp.Sources;
|
|
136
|
+
'img-src'?: Csp.Sources;
|
|
137
|
+
'manifest-src'?: Csp.Sources;
|
|
138
|
+
'media-src'?: Csp.Sources;
|
|
139
|
+
'object-src'?: Csp.Sources;
|
|
140
|
+
'prefetch-src'?: Csp.Sources;
|
|
141
|
+
'script-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
142
|
+
'script-src-elem'?: Csp.Sources;
|
|
143
|
+
'script-src-attr'?: Csp.Sources;
|
|
144
|
+
'style-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
145
|
+
'style-src-elem'?: Csp.Sources;
|
|
146
|
+
'style-src-attr'?: Csp.Sources;
|
|
147
|
+
'base-uri'?: Array<Csp.Source | Csp.ActionSource>;
|
|
148
|
+
sandbox?: Array<
|
|
149
|
+
| 'allow-downloads-without-user-activation'
|
|
150
|
+
| 'allow-forms'
|
|
151
|
+
| 'allow-modals'
|
|
152
|
+
| 'allow-orientation-lock'
|
|
153
|
+
| 'allow-pointer-lock'
|
|
154
|
+
| 'allow-popups'
|
|
155
|
+
| 'allow-popups-to-escape-sandbox'
|
|
156
|
+
| 'allow-presentation'
|
|
157
|
+
| 'allow-same-origin'
|
|
158
|
+
| 'allow-scripts'
|
|
159
|
+
| 'allow-storage-access-by-user-activation'
|
|
160
|
+
| 'allow-top-navigation'
|
|
161
|
+
| 'allow-top-navigation-by-user-activation'
|
|
162
|
+
>;
|
|
163
|
+
'form-action'?: Array<Csp.Source | Csp.ActionSource>;
|
|
164
|
+
'frame-ancestors'?: Array<Csp.HostSource | Csp.SchemeSource | Csp.FrameSource>;
|
|
165
|
+
'navigate-to'?: Array<Csp.Source | Csp.ActionSource>;
|
|
166
|
+
'report-uri'?: Csp.UriPath[];
|
|
167
|
+
'report-to'?: string[];
|
|
168
|
+
|
|
169
|
+
'require-trusted-types-for'?: Array<'script'>;
|
|
170
|
+
'trusted-types'?: Array<'none' | 'allow-duplicates' | '*' | string>;
|
|
171
|
+
'upgrade-insecure-requests'?: boolean;
|
|
172
|
+
|
|
173
|
+
/** @deprecated */
|
|
174
|
+
'require-sri-for'?: Array<'script' | 'style' | 'script style'>;
|
|
175
|
+
|
|
176
|
+
/** @deprecated */
|
|
177
|
+
'block-all-mixed-content'?: boolean;
|
|
178
|
+
|
|
179
|
+
/** @deprecated */
|
|
180
|
+
'plugin-types'?: Array<`${string}/${string}` | 'none'>;
|
|
181
|
+
|
|
182
|
+
/** @deprecated */
|
|
183
|
+
referrer?: Array<
|
|
184
|
+
| 'no-referrer'
|
|
185
|
+
| 'no-referrer-when-downgrade'
|
|
186
|
+
| 'origin'
|
|
187
|
+
| 'origin-when-cross-origin'
|
|
188
|
+
| 'same-origin'
|
|
189
|
+
| 'strict-origin'
|
|
190
|
+
| 'strict-origin-when-cross-origin'
|
|
191
|
+
| 'unsafe-url'
|
|
192
|
+
| 'none'
|
|
193
|
+
>;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export type Either<T, U> = Only<T, U> | Only<U, T>;
|
|
197
|
+
|
|
198
|
+
export interface EndpointOutput<Output extends Body = Body> {
|
|
199
|
+
status?: number;
|
|
200
|
+
headers?: Headers | Partial<ResponseHeaders>;
|
|
201
|
+
body?: Output;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface ErrorLoadInput<Params = Record<string, string>> extends LoadInput<Params> {
|
|
205
|
+
status?: number;
|
|
206
|
+
error?: Error;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface Fallthrough {
|
|
210
|
+
fallthrough: true;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
|
|
214
|
+
|
|
215
|
+
export type JSONObject = { [key: string]: JSONValue };
|
|
216
|
+
|
|
217
|
+
export type JSONValue = string | number | boolean | null | ToJSON | JSONValue[] | JSONObject;
|
|
218
|
+
|
|
219
|
+
export interface LoadInput<Params = Record<string, string>> {
|
|
220
|
+
url: URL;
|
|
221
|
+
params: Params;
|
|
222
|
+
props: Record<string, any>;
|
|
223
|
+
fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
224
|
+
session: App.Session;
|
|
225
|
+
stuff: Partial<App.Stuff>;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface LoadOutput<Props = Record<string, any>> {
|
|
229
|
+
status?: number;
|
|
230
|
+
error?: string | Error;
|
|
231
|
+
redirect?: string;
|
|
232
|
+
props?: Props;
|
|
233
|
+
stuff?: Partial<App.Stuff>;
|
|
234
|
+
maxage?: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface Logger {
|
|
238
|
+
(msg: string): void;
|
|
239
|
+
success(msg: string): void;
|
|
240
|
+
error(msg: string): void;
|
|
241
|
+
warn(msg: string): void;
|
|
242
|
+
minor(msg: string): void;
|
|
243
|
+
info(msg: string): void;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
247
|
+
|
|
248
|
+
export type Only<T, U> = { [P in keyof T]: T[P] } & { [P in Exclude<keyof U, keyof T>]?: never };
|
|
249
|
+
|
|
250
|
+
export interface Prerendered {
|
|
251
|
+
pages: Map<
|
|
252
|
+
string,
|
|
253
|
+
{
|
|
254
|
+
/** The location of the .html file relative to the output directory */
|
|
255
|
+
file: string;
|
|
256
|
+
}
|
|
257
|
+
>;
|
|
258
|
+
assets: Map<
|
|
259
|
+
string,
|
|
260
|
+
{
|
|
261
|
+
/** The MIME type of the asset */
|
|
262
|
+
type: string;
|
|
263
|
+
}
|
|
264
|
+
>;
|
|
265
|
+
redirects: Map<
|
|
266
|
+
string,
|
|
267
|
+
{
|
|
268
|
+
status: number;
|
|
269
|
+
location: string;
|
|
270
|
+
}
|
|
271
|
+
>;
|
|
272
|
+
/** An array of prerendered paths (without trailing slashes, regardless of the trailingSlash config) */
|
|
273
|
+
paths: string[];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface PrerenderErrorHandler {
|
|
277
|
+
(details: {
|
|
278
|
+
status: number;
|
|
279
|
+
path: string;
|
|
280
|
+
referrer: string | null;
|
|
281
|
+
referenceType: 'linked' | 'fetched';
|
|
282
|
+
}): void;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export type PrerenderOnErrorValue = 'fail' | 'continue' | PrerenderErrorHandler;
|
|
286
|
+
|
|
287
|
+
export interface RequestEvent<Params = Record<string, string>> {
|
|
288
|
+
request: Request;
|
|
289
|
+
url: URL;
|
|
290
|
+
params: Params;
|
|
291
|
+
locals: App.Locals;
|
|
292
|
+
platform: Readonly<App.Platform>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export interface RequestOptions {
|
|
296
|
+
platform?: App.Platform;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export type ResolveOptions = {
|
|
300
|
+
ssr?: boolean;
|
|
301
|
+
transformPage?: ({ html }: { html: string }) => MaybePromise<string>;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/** `string[]` is only for set-cookie, everything else must be type of `string` */
|
|
305
|
+
export type ResponseHeaders = Record<string, string | number | string[]>;
|
|
306
|
+
|
|
307
|
+
export interface RouteDefinition {
|
|
308
|
+
type: 'page' | 'endpoint';
|
|
309
|
+
pattern: RegExp;
|
|
310
|
+
segments: RouteSegment[];
|
|
311
|
+
methods: HttpMethod[];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface RouteSegment {
|
|
315
|
+
content: string;
|
|
316
|
+
dynamic: boolean;
|
|
317
|
+
rest: boolean;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export class Server {
|
|
321
|
+
constructor(manifest: SSRManifest);
|
|
322
|
+
respond(request: Request, options?: RequestOptions): Promise<Response>;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface SSRManifest {
|
|
326
|
+
appDir: string;
|
|
327
|
+
assets: Set<string>;
|
|
328
|
+
/** private fields */
|
|
329
|
+
_: {
|
|
330
|
+
mime: Record<string, string>;
|
|
331
|
+
entry: {
|
|
332
|
+
file: string;
|
|
333
|
+
js: string[];
|
|
334
|
+
css: string[];
|
|
335
|
+
};
|
|
336
|
+
nodes: SSRNodeLoader[];
|
|
337
|
+
routes: SSRRoute[];
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export type ToJSON = { toJSON(...args: any[]): Exclude<JSONValue, ToJSON> };
|
|
342
|
+
|
|
343
|
+
export type TrailingSlash = 'never' | 'always' | 'ignore';
|