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

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.
Files changed (104) hide show
  1. package/README.md +12 -9
  2. package/package.json +95 -63
  3. package/src/cli.js +112 -0
  4. package/src/core/adapt/builder.js +207 -0
  5. package/src/core/adapt/index.js +19 -0
  6. package/src/core/config/index.js +86 -0
  7. package/src/core/config/options.js +488 -0
  8. package/src/core/config/types.d.ts +1 -0
  9. package/src/core/constants.js +5 -0
  10. package/src/core/env.js +97 -0
  11. package/src/core/generate_manifest/index.js +99 -0
  12. package/src/core/prerender/crawl.js +194 -0
  13. package/src/core/prerender/prerender.js +378 -0
  14. package/src/core/prerender/queue.js +80 -0
  15. package/src/core/sync/create_manifest_data/index.js +506 -0
  16. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  17. package/src/core/sync/sync.js +59 -0
  18. package/src/core/sync/utils.js +44 -0
  19. package/src/core/sync/write_ambient.js +27 -0
  20. package/src/core/sync/write_client_manifest.js +82 -0
  21. package/src/core/sync/write_matchers.js +25 -0
  22. package/src/core/sync/write_root.js +91 -0
  23. package/src/core/sync/write_tsconfig.js +195 -0
  24. package/src/core/sync/write_types.js +775 -0
  25. package/src/core/utils.js +70 -0
  26. package/src/hooks.js +26 -0
  27. package/src/index/index.js +45 -0
  28. package/src/index/private.js +33 -0
  29. package/src/node/index.js +145 -0
  30. package/src/node/polyfills.js +40 -0
  31. package/src/runtime/app/env.js +11 -0
  32. package/src/runtime/app/navigation.js +22 -0
  33. package/src/runtime/app/paths.js +1 -0
  34. package/src/runtime/app/stores.js +102 -0
  35. package/src/runtime/client/ambient.d.ts +17 -0
  36. package/src/runtime/client/client.js +1289 -0
  37. package/src/runtime/client/fetcher.js +60 -0
  38. package/src/runtime/client/parse.js +36 -0
  39. package/src/runtime/client/singletons.js +21 -0
  40. package/src/runtime/client/start.js +46 -0
  41. package/src/runtime/client/types.d.ts +105 -0
  42. package/src/runtime/client/utils.js +113 -0
  43. package/src/runtime/components/error.svelte +16 -0
  44. package/{assets → src/runtime}/components/layout.svelte +0 -0
  45. package/src/runtime/env/dynamic/private.js +1 -0
  46. package/src/runtime/env/dynamic/public.js +1 -0
  47. package/src/runtime/env-private.js +7 -0
  48. package/src/runtime/env-public.js +7 -0
  49. package/src/runtime/env.js +6 -0
  50. package/src/runtime/hash.js +16 -0
  51. package/src/runtime/paths.js +11 -0
  52. package/src/runtime/server/endpoint.js +58 -0
  53. package/src/runtime/server/index.js +448 -0
  54. package/src/runtime/server/page/cookie.js +25 -0
  55. package/src/runtime/server/page/crypto.js +239 -0
  56. package/src/runtime/server/page/csp.js +249 -0
  57. package/src/runtime/server/page/fetch.js +266 -0
  58. package/src/runtime/server/page/index.js +416 -0
  59. package/src/runtime/server/page/load_data.js +135 -0
  60. package/src/runtime/server/page/render.js +362 -0
  61. package/src/runtime/server/page/respond_with_error.js +94 -0
  62. package/src/runtime/server/page/types.d.ts +44 -0
  63. package/src/runtime/server/utils.js +116 -0
  64. package/src/utils/error.js +22 -0
  65. package/src/utils/escape.js +104 -0
  66. package/src/utils/filesystem.js +108 -0
  67. package/src/utils/http.js +55 -0
  68. package/src/utils/misc.js +1 -0
  69. package/src/utils/routing.js +108 -0
  70. package/src/utils/url.js +97 -0
  71. package/src/vite/build/build_server.js +337 -0
  72. package/src/vite/build/build_service_worker.js +90 -0
  73. package/src/vite/build/utils.js +160 -0
  74. package/src/vite/dev/index.js +551 -0
  75. package/src/vite/index.js +574 -0
  76. package/src/vite/preview/index.js +186 -0
  77. package/src/vite/types.d.ts +3 -0
  78. package/src/vite/utils.js +345 -0
  79. package/svelte-kit.js +1 -1
  80. package/types/ambient.d.ts +357 -0
  81. package/types/index.d.ts +343 -0
  82. package/types/internal.d.ts +308 -0
  83. package/types/private.d.ts +209 -0
  84. package/CHANGELOG.md +0 -431
  85. package/assets/components/error.svelte +0 -13
  86. package/assets/runtime/app/env.js +0 -5
  87. package/assets/runtime/app/navigation.js +0 -41
  88. package/assets/runtime/app/paths.js +0 -1
  89. package/assets/runtime/app/stores.js +0 -93
  90. package/assets/runtime/chunks/utils.js +0 -19
  91. package/assets/runtime/internal/singletons.js +0 -23
  92. package/assets/runtime/internal/start.js +0 -770
  93. package/assets/runtime/paths.js +0 -12
  94. package/dist/.DS_Store +0 -0
  95. package/dist/chunks/index.js +0 -3521
  96. package/dist/chunks/index2.js +0 -587
  97. package/dist/chunks/index3.js +0 -246
  98. package/dist/chunks/index4.js +0 -538
  99. package/dist/chunks/index5.js +0 -761
  100. package/dist/chunks/index6.js +0 -322
  101. package/dist/chunks/standard.js +0 -99
  102. package/dist/chunks/utils.js +0 -83
  103. package/dist/cli.js +0 -546
  104. package/dist/ssr.js +0 -2581
@@ -0,0 +1,357 @@
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 PrivateEnv {}
13
+ *
14
+ * interface PublicEnv {}
15
+ * }
16
+ * ```
17
+ *
18
+ * By populating these interfaces, you will gain type safety when using `env`, `event.locals` and `event.platform`.
19
+ *
20
+ * Note that since it's an ambient declaration file, you have to be careful when using `import` statements. Once you add an `import`
21
+ * at the top level, the declaration file is no longer considered ambient and you lose access to these typings in other files.
22
+ * To avoid this, either use the `import(...)` function:
23
+ *
24
+ * ```ts
25
+ * interface Locals {
26
+ * user: import('$lib/types').User;
27
+ * }
28
+ * ```
29
+ * Or wrap the namespace with `declare global`:
30
+ * ```ts
31
+ * import { User } from '$lib/types';
32
+ *
33
+ * declare global {
34
+ * namespace App {
35
+ * interface Locals {
36
+ * user: User;
37
+ * }
38
+ * // ...
39
+ * }
40
+ * }
41
+ * ```
42
+ *
43
+ */
44
+ declare namespace App {
45
+ /**
46
+ * The interface that defines `event.locals`, which can be accessed in [hooks](https://kit.svelte.dev/docs/hooks) (`handle`, and `handleError`), server-only `load` functions, and `+server.js` files.
47
+ */
48
+ export interface Locals {}
49
+
50
+ /**
51
+ * If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#supported-environments-platform-specific-context) via `event.platform`, you can specify it here.
52
+ */
53
+ export interface Platform {}
54
+
55
+ /**
56
+ * The interface that defines the dynamic environment variables exported from `$env/dynamic/private`.
57
+ */
58
+ export interface PrivateEnv extends Record<string, string> {}
59
+
60
+ /**
61
+ * The interface that defines the dynamic environment variables exported from `$env/dynamic/public`.
62
+ */
63
+ export interface PublicEnv extends Record<string, string> {}
64
+ }
65
+
66
+ /**
67
+ * ```ts
68
+ * import { browser, dev, prerendering } from '$app/env';
69
+ * ```
70
+ */
71
+ declare module '$app/env' {
72
+ /**
73
+ * `true` if the app is running in the browser.
74
+ */
75
+ export const browser: boolean;
76
+
77
+ /**
78
+ * Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
79
+ */
80
+ export const dev: boolean;
81
+
82
+ /**
83
+ * `true` when prerendering, `false` otherwise.
84
+ */
85
+ export const prerendering: boolean;
86
+ }
87
+
88
+ /**
89
+ * This module provides access to runtime environment variables, as defined by the platform you're running on. For example
90
+ * if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/master/packages/adapter-node) (or running
91
+ * [`vite preview`](https://kit.svelte.dev/docs/cli)), this is equivalent to `process.env`. This module only includes
92
+ * variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix).
93
+ *
94
+ * This module cannot be imported into client-side code.
95
+ *
96
+ * ```ts
97
+ * import { env } from '$env/dynamic/private';
98
+ * console.log(env.DEPLOYMENT_SPECIFIC_VARIABLE);
99
+ * ```
100
+ */
101
+ declare module '$env/dynamic/private' {
102
+ export let env: App.PrivateEnv;
103
+ }
104
+
105
+ /**
106
+ * Similar to [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), but only includes
107
+ * variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix)
108
+ * (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code
109
+ *
110
+ * Note that public dynamic environment variables must all be sent from the server to the client, causing larger network requests — when possible, use `$env/static/public` instead.
111
+ *
112
+ * ```ts
113
+ * import { env } from '$env/dynamic/public';
114
+ * console.log(env.PUBLIC_DEPLOYMENT_SPECIFIC_VARIABLE);
115
+ * ```
116
+ */
117
+ declare module '$env/dynamic/public' {
118
+ export let env: App.PublicEnv;
119
+ }
120
+
121
+ /**
122
+ * ```ts
123
+ * import {
124
+ * afterNavigate,
125
+ * beforeNavigate,
126
+ * disableScrollHandling,
127
+ * goto,
128
+ * invalidate,
129
+ * prefetch,
130
+ * prefetchRoutes
131
+ * } from '$app/navigation';
132
+ * ```
133
+ */
134
+ declare module '$app/navigation' {
135
+ /**
136
+ * If called when the page is being updated following a navigation (in `onMount` or `afterNavigate` or an action, for example), this disables SvelteKit's built-in scroll handling.
137
+ * This is generally discouraged, since it breaks user expectations.
138
+ */
139
+ export function disableScrollHandling(): void;
140
+ /**
141
+ * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
142
+ *
143
+ * @param url Where to navigate to
144
+ * @param opts.replaceState If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
145
+ * @param opts.noscroll If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation
146
+ * @param opts.keepfocus If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body
147
+ * @param opts.state The state of the new/updated history entry
148
+ */
149
+ export function goto(
150
+ url: string | URL,
151
+ opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any }
152
+ ): Promise<void>;
153
+ /**
154
+ * Causes any `load` functions belonging to the currently active page to re-run if they `fetch` the resource in question, or re-fetches data from a page endpoint if the invalidated resource is the page itself. If no argument is given, all resources will be invalidated. Returns a `Promise` that resolves when the page is subsequently updated.
155
+ * @param dependency The invalidated resource
156
+ */
157
+ export function invalidate(dependency?: string | ((href: string) => boolean)): Promise<void>;
158
+ /**
159
+ * Programmatically prefetches the given page, which means
160
+ * 1. ensuring that the code for the page is loaded, and
161
+ * 2. calling the page's load function with the appropriate options.
162
+ *
163
+ * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `sveltekit:prefetch`.
164
+ * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
165
+ * Returns a Promise that resolves when the prefetch is complete.
166
+ *
167
+ * @param href Page to prefetch
168
+ */
169
+ export function prefetch(href: string): Promise<void>;
170
+ /**
171
+ * Programmatically prefetches the code for routes that haven't yet been fetched.
172
+ * Typically, you might call this to speed up subsequent navigation.
173
+ *
174
+ * If no argument is given, all routes will be fetched, otherwise you can specify routes by any matching pathname
175
+ * such as `/about` (to match `src/routes/about.svelte`) or `/blog/*` (to match `src/routes/blog/[slug].svelte`).
176
+ *
177
+ * Unlike prefetch, this won't call load for individual pages.
178
+ * Returns a Promise that resolves when the routes have been prefetched.
179
+ */
180
+ export function prefetchRoutes(routes?: string[]): Promise<void>;
181
+
182
+ /**
183
+ * 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.
184
+ * This is helpful if we want to conditionally prevent a navigation from completing or lookup the upcoming url.
185
+ */
186
+ export function beforeNavigate(
187
+ fn: (navigation: { from: URL; to: URL | null; cancel: () => void }) => void
188
+ ): void;
189
+
190
+ /**
191
+ * A lifecycle function that runs when the page mounts, and also whenever SvelteKit navigates to a new URL but stays on this component.
192
+ */
193
+ export function afterNavigate(fn: (navigation: { from: URL | null; to: URL }) => void): void;
194
+ }
195
+
196
+ /**
197
+ * ```ts
198
+ * import { base, assets } from '$app/paths';
199
+ * ```
200
+ */
201
+ declare module '$app/paths' {
202
+ /**
203
+ * A string that matches [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths). It must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string.
204
+ */
205
+ export const base: `/${string}`;
206
+ /**
207
+ * An absolute path that matches [`config.kit.paths.assets`](https://kit.svelte.dev/docs/configuration#paths).
208
+ *
209
+ * > If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
210
+ */
211
+ export const assets: `https://${string}` | `http://${string}`;
212
+ }
213
+
214
+ /**
215
+ * ```ts
216
+ * import { getStores, navigating, page, updated } from '$app/stores';
217
+ * ```
218
+ *
219
+ * Stores on the server are _contextual_ — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `page` is unique to each request, rather than shared between multiple requests handled by the same server simultaneously.
220
+ *
221
+ * 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.
222
+ *
223
+ * In the browser, we don't need to worry about this, and stores can be accessed from anywhere. Code that will only ever run on the browser can refer to (or subscribe to) any of these stores at any time.
224
+ */
225
+ declare module '$app/stores' {
226
+ import { Readable } from 'svelte/store';
227
+ import { Navigation, Page } from '@sveltejs/kit';
228
+
229
+ /**
230
+ * A readable store whose value contains page data.
231
+ */
232
+ export const page: Readable<Page>;
233
+ /**
234
+ * A readable store.
235
+ * When navigating starts, its value is `{ from: URL, to: URL }`,
236
+ * When navigating finishes, its value reverts to `null`.
237
+ */
238
+ export const navigating: Readable<Navigation | null>;
239
+ /**
240
+ * A readable store whose initial value is `false`. If [`version.pollInterval`](https://kit.svelte.dev/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.
241
+ */
242
+ export const updated: Readable<boolean> & { check: () => boolean };
243
+
244
+ /**
245
+ * A function that returns all of the contextual stores. On the server, this must be called during component initialization.
246
+ * Only use this if you need to defer store subscription until after the component has mounted, for some reason.
247
+ */
248
+ export function getStores(): {
249
+ navigating: typeof navigating;
250
+ page: typeof page;
251
+ updated: typeof updated;
252
+ };
253
+ }
254
+
255
+ /**
256
+ * ```ts
257
+ * import { build, files, prerendered, version } from '$service-worker';
258
+ * ```
259
+ *
260
+ * This module is only available to [service workers](https://kit.svelte.dev/docs/service-workers).
261
+ */
262
+ declare module '$service-worker' {
263
+ /**
264
+ * An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`.
265
+ */
266
+ export const build: string[];
267
+ /**
268
+ * 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`](https://kit.svelte.dev/docs/configuration)
269
+ */
270
+ export const files: string[];
271
+ /**
272
+ * An array of pathnames corresponding to prerendered pages and endpoints.
273
+ */
274
+ export const prerendered: string[];
275
+ /**
276
+ * See [`config.kit.version`](https://kit.svelte.dev/docs/configuration#version). It's useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.
277
+ */
278
+ export const version: string;
279
+ }
280
+
281
+ declare module '@sveltejs/kit/hooks' {
282
+ import { Handle } from '@sveltejs/kit';
283
+
284
+ /**
285
+ * A helper function for sequencing multiple `handle` calls in a middleware-like manner.
286
+ *
287
+ * ```js
288
+ * /// file: src/hooks.js
289
+ * import { sequence } from '@sveltejs/kit/hooks';
290
+ *
291
+ * /** @type {import('@sveltejs/kit').Handle} *\/
292
+ * async function first({ event, resolve }) {
293
+ * console.log('first pre-processing');
294
+ * const result = await resolve(event);
295
+ * console.log('first post-processing');
296
+ * return result;
297
+ * }
298
+ *
299
+ * /** @type {import('@sveltejs/kit').Handle} *\/
300
+ * async function second({ event, resolve }) {
301
+ * console.log('second pre-processing');
302
+ * const result = await resolve(event);
303
+ * console.log('second post-processing');
304
+ * return result;
305
+ * }
306
+ *
307
+ * export const handle = sequence(first, second);
308
+ * ```
309
+ *
310
+ * The example above would print:
311
+ *
312
+ * ```
313
+ * first pre-processing
314
+ * second pre-processing
315
+ * second post-processing
316
+ * first post-processing
317
+ * ```
318
+ *
319
+ * @param handlers The chain of `handle` functions
320
+ */
321
+ export function sequence(...handlers: Handle[]): Handle;
322
+ }
323
+
324
+ /**
325
+ * A polyfill for `fetch` and its related interfaces, used by adapters for environments that don't provide a native implementation.
326
+ */
327
+ declare module '@sveltejs/kit/node/polyfills' {
328
+ /**
329
+ * Make various web APIs available as globals:
330
+ * - `crypto`
331
+ * - `fetch`
332
+ * - `Headers`
333
+ * - `Request`
334
+ * - `Response`
335
+ */
336
+ export function installPolyfills(): void;
337
+ }
338
+
339
+ /**
340
+ * Utilities used by adapters for Node-like environments.
341
+ */
342
+ declare module '@sveltejs/kit/node' {
343
+ export function getRequest(
344
+ base: string,
345
+ request: import('http').IncomingMessage
346
+ ): Promise<Request>;
347
+ export function setResponse(res: import('http').ServerResponse, response: Response): void;
348
+ }
349
+
350
+ declare module '@sveltejs/kit/vite' {
351
+ import { Plugin } from 'vite';
352
+
353
+ /**
354
+ * Returns the SvelteKit Vite plugins.
355
+ */
356
+ export function sveltekit(): Plugin[];
357
+ }
@@ -0,0 +1,343 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="vite/client" />
3
+
4
+ import './ambient.js';
5
+
6
+ import { CompileOptions } from 'svelte/types/compiler/interfaces';
7
+ import {
8
+ AdapterEntry,
9
+ CspDirectives,
10
+ Logger,
11
+ MaybePromise,
12
+ Prerendered,
13
+ PrerenderOnErrorValue,
14
+ RequestOptions,
15
+ ResponseHeaders,
16
+ RouteDefinition,
17
+ TrailingSlash
18
+ } from './private.js';
19
+ import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
20
+ import { HttpError, Redirect } from '../src/index/private.js';
21
+
22
+ export interface Adapter {
23
+ name: string;
24
+ adapt(builder: Builder): MaybePromise<void>;
25
+ }
26
+
27
+ export type AwaitedProperties<input extends Record<string, any> | void> = input extends void
28
+ ? undefined // needs to be undefined, because void will break intellisense
29
+ : input extends Record<string, any>
30
+ ? {
31
+ [key in keyof input]: Awaited<input[key]>;
32
+ }
33
+ : {} extends input // handles the any case
34
+ ? input
35
+ : unknown;
36
+
37
+ export type AwaitedErrors<T extends (...args: any) => any> = Awaited<ReturnType<T>> extends {
38
+ errors?: any;
39
+ }
40
+ ? Awaited<ReturnType<T>>['errors']
41
+ : undefined;
42
+
43
+ export interface Builder {
44
+ log: Logger;
45
+ rimraf(dir: string): void;
46
+ mkdirp(dir: string): void;
47
+
48
+ config: ValidatedConfig;
49
+ prerendered: Prerendered;
50
+
51
+ /**
52
+ * Create entry points that map to individual functions
53
+ * @param fn A function that groups a set of routes into an entry point
54
+ */
55
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
56
+
57
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
58
+
59
+ getBuildDirectory(name: string): string;
60
+ getClientDirectory(): string;
61
+ getServerDirectory(): string;
62
+ getStaticDirectory(): string;
63
+
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
+ writeClient(dest: string): string[];
69
+ /**
70
+ * @param dest
71
+ */
72
+ writePrerendered(
73
+ dest: string,
74
+ opts?: {
75
+ fallback?: string;
76
+ }
77
+ ): string[];
78
+ /**
79
+ * @param dest the destination folder to which files should be copied
80
+ * @returns an array of paths corresponding to the files that have been created by the copy
81
+ */
82
+ writeServer(dest: string): string[];
83
+ /**
84
+ * @param from the source file or folder
85
+ * @param to the destination file or folder
86
+ * @param opts.filter a function to determine whether a file or folder should be copied
87
+ * @param opts.replace a map of strings to replace
88
+ * @returns an array of paths corresponding to the files that have been created by the copy
89
+ */
90
+ copy(
91
+ from: string,
92
+ to: string,
93
+ opts?: {
94
+ filter?: (basename: string) => boolean;
95
+ replace?: Record<string, string>;
96
+ }
97
+ ): string[];
98
+
99
+ /**
100
+ * @param {string} directory Path to the directory containing the files to be compressed
101
+ */
102
+ compress(directory: string): void;
103
+ }
104
+
105
+ export interface Config {
106
+ compilerOptions?: CompileOptions;
107
+ extensions?: string[];
108
+ kit?: KitConfig;
109
+ package?: {
110
+ source?: string;
111
+ dir?: string;
112
+ emitTypes?: boolean;
113
+ exports?: (filepath: string) => boolean;
114
+ files?: (filepath: string) => boolean;
115
+ };
116
+ preprocess?: any;
117
+ [key: string]: any;
118
+ }
119
+
120
+ export interface KitConfig {
121
+ adapter?: Adapter;
122
+ alias?: Record<string, string>;
123
+ appDir?: string;
124
+ browser?: {
125
+ hydrate?: boolean;
126
+ router?: boolean;
127
+ };
128
+ csp?: {
129
+ mode?: 'hash' | 'nonce' | 'auto';
130
+ directives?: CspDirectives;
131
+ reportOnly?: CspDirectives;
132
+ };
133
+ env?: {
134
+ dir?: string;
135
+ publicPrefix?: string;
136
+ };
137
+ moduleExtensions?: string[];
138
+ files?: {
139
+ assets?: string;
140
+ hooks?: string;
141
+ lib?: string;
142
+ params?: string;
143
+ routes?: string;
144
+ serviceWorker?: string;
145
+ template?: string;
146
+ };
147
+ inlineStyleThreshold?: number;
148
+ methodOverride?: {
149
+ parameter?: string;
150
+ allowed?: string[];
151
+ };
152
+ outDir?: string;
153
+ paths?: {
154
+ assets?: string;
155
+ base?: string;
156
+ };
157
+ prerender?: {
158
+ concurrency?: number;
159
+ crawl?: boolean;
160
+ default?: boolean;
161
+ enabled?: boolean;
162
+ entries?: Array<'*' | `/${string}`>;
163
+ onError?: PrerenderOnErrorValue;
164
+ origin?: string;
165
+ };
166
+ serviceWorker?: {
167
+ register?: boolean;
168
+ files?: (filepath: string) => boolean;
169
+ };
170
+ trailingSlash?: TrailingSlash;
171
+ version?: {
172
+ name?: string;
173
+ pollInterval?: number;
174
+ };
175
+ }
176
+
177
+ export interface ExternalFetch {
178
+ (req: Request): Promise<Response>;
179
+ }
180
+
181
+ export interface Handle {
182
+ (input: {
183
+ event: RequestEvent;
184
+ resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
185
+ }): MaybePromise<Response>;
186
+ }
187
+
188
+ export interface HandleError {
189
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
190
+ }
191
+
192
+ /**
193
+ * The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
194
+ * rather than using `Load` directly.
195
+ */
196
+ export interface Load<
197
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
198
+ InputData extends Record<string, any> | null = Record<string, any> | null,
199
+ ParentData extends Record<string, any> = Record<string, any>,
200
+ OutputData extends Record<string, any> | void = Record<string, any> | void
201
+ > {
202
+ (event: LoadEvent<Params, InputData, ParentData>): MaybePromise<OutputData>;
203
+ }
204
+
205
+ export interface LoadEvent<
206
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
207
+ Data extends Record<string, any> | null = Record<string, any> | null,
208
+ ParentData extends Record<string, any> = Record<string, any>
209
+ > {
210
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
211
+ params: Params;
212
+ data: Data;
213
+ routeId: string | null;
214
+ setHeaders: (headers: ResponseHeaders) => void;
215
+ url: URL;
216
+ parent: () => Promise<ParentData>;
217
+ depends: (...deps: string[]) => void;
218
+ }
219
+
220
+ export interface Navigation {
221
+ from: URL;
222
+ to: URL;
223
+ }
224
+
225
+ export interface Page<Params extends Record<string, string> = Record<string, string>> {
226
+ url: URL;
227
+ params: Params;
228
+ routeId: string | null;
229
+ status: number;
230
+ error: HttpError | Error | null;
231
+ data: Record<string, any>;
232
+ }
233
+
234
+ export interface ParamMatcher {
235
+ (param: string): boolean;
236
+ }
237
+
238
+ export interface RequestEvent<
239
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
240
+ > {
241
+ clientAddress: string;
242
+ locals: App.Locals;
243
+ params: Params;
244
+ platform: Readonly<App.Platform>;
245
+ request: Request;
246
+ routeId: string | null;
247
+ setHeaders: (headers: ResponseHeaders) => void;
248
+ url: URL;
249
+ }
250
+
251
+ /**
252
+ * A `(event: RequestEvent) => Response` function exported from a `+server.js` file that corresponds to an HTTP verb (`GET`, `PUT`, `PATCH`, etc) and handles requests with that method.
253
+ *
254
+ * It receives `Params` as the first generic argument, which you can skip by using [generated types](/docs/types#generated-types) instead.
255
+ */
256
+ export interface RequestHandler<Params extends Record<string, string> = Record<string, string>> {
257
+ (event: RequestEvent<Params>): MaybePromise<Response>;
258
+ }
259
+
260
+ export interface ResolveOptions {
261
+ ssr?: boolean;
262
+ transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
263
+ }
264
+
265
+ export class Server {
266
+ constructor(manifest: SSRManifest);
267
+ init(options: ServerInitOptions): void;
268
+ respond(request: Request, options: RequestOptions): Promise<Response>;
269
+ }
270
+
271
+ export interface ServerInitOptions {
272
+ env: Record<string, string>;
273
+ }
274
+
275
+ export interface SSRManifest {
276
+ appDir: string;
277
+ assets: Set<string>;
278
+ mimeTypes: Record<string, string>;
279
+
280
+ /** private fields */
281
+ _: {
282
+ entry: {
283
+ file: string;
284
+ imports: string[];
285
+ stylesheets: string[];
286
+ };
287
+ nodes: SSRNodeLoader[];
288
+ routes: SSRRoute[];
289
+ matchers: () => Promise<Record<string, ParamMatcher>>;
290
+ };
291
+ }
292
+
293
+ /**
294
+ * The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
295
+ * rather than using `ServerLoad` directly.
296
+ */
297
+ export interface ServerLoad<
298
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
299
+ ParentData extends Record<string, any> = Record<string, any>,
300
+ OutputData extends Record<string, any> | void = Record<string, any> | void
301
+ > {
302
+ (event: ServerLoadEvent<Params, ParentData>): MaybePromise<OutputData>;
303
+ }
304
+
305
+ export interface ServerLoadEvent<
306
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
307
+ ParentData extends Record<string, any> = Record<string, any>
308
+ > extends RequestEvent<Params> {
309
+ parent: () => Promise<ParentData>;
310
+ }
311
+
312
+ export interface Action<
313
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
314
+ > {
315
+ (event: RequestEvent<Params>): MaybePromise<
316
+ | { status?: number; errors: Record<string, any>; location?: never }
317
+ | { status?: never; errors?: never; location: string }
318
+ | void
319
+ >;
320
+ }
321
+
322
+ // TODO figure out how to just re-export from '../src/index/index.js' without
323
+ // breaking the site
324
+
325
+ /**
326
+ * Creates an `HttpError` object with an HTTP status code and an optional message.
327
+ * This object, if thrown during request handling, will cause SvelteKit to
328
+ * return an error response without invoking `handleError`
329
+ * @param {number} status
330
+ * @param {string | undefined} [message]
331
+ */
332
+ export function error(status: number, message?: string | undefined): HttpError;
333
+
334
+ /**
335
+ * Creates a `Redirect` object. If thrown during request handling, SvelteKit will
336
+ * return a redirect response.
337
+ */
338
+ export function redirect(status: number, location: string): Redirect;
339
+
340
+ /**
341
+ * Generates a JSON `Response` object from the supplied data.
342
+ */
343
+ export function json(data: any, init?: ResponseInit): Response;