@sveltejs/kit 1.0.0-next.41 → 1.0.0-next.410

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