@sveltejs/kit 1.0.0-next.44 → 1.0.0-next.442

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 (153) hide show
  1. package/README.md +12 -9
  2. package/package.json +94 -63
  3. package/src/cli.js +112 -0
  4. package/src/core/adapt/builder.js +223 -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 +78 -0
  12. package/src/core/prerender/crawl.js +194 -0
  13. package/src/core/prerender/prerender.js +380 -0
  14. package/src/core/prerender/queue.js +80 -0
  15. package/src/core/sync/create_manifest_data/index.js +452 -0
  16. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  17. package/src/core/sync/sync.js +59 -0
  18. package/src/core/sync/utils.js +33 -0
  19. package/src/core/sync/write_ambient.js +27 -0
  20. package/src/core/sync/write_client_manifest.js +92 -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/index.js +580 -0
  25. package/src/core/sync/write_types/test/layout/+layout.js +5 -0
  26. package/src/core/sync/write_types/test/layout/+layout.server.js +5 -0
  27. package/src/core/sync/write_types/test/layout/+layout.svelte +0 -0
  28. package/src/core/sync/write_types/test/layout/+page.js +5 -0
  29. package/src/core/sync/write_types/test/layout/+page.server.js +5 -0
  30. package/src/core/sync/write_types/test/layout/+page.svelte +0 -0
  31. package/src/core/sync/write_types/test/layout/_expected/$types.d.ts +67 -0
  32. package/src/core/sync/write_types/test/layout-advanced/(main)/+layout.server.js +5 -0
  33. package/src/core/sync/write_types/test/layout-advanced/(main)/+layout.svelte +0 -0
  34. package/src/core/sync/write_types/test/layout-advanced/(main)/+page.js +5 -0
  35. package/src/core/sync/write_types/test/layout-advanced/(main)/+page@.svelte +0 -0
  36. package/src/core/sync/write_types/test/layout-advanced/(main)/sub/+page.js +5 -0
  37. package/src/core/sync/write_types/test/layout-advanced/(main)/sub/+page.svelte +0 -0
  38. package/src/core/sync/write_types/test/layout-advanced/+layout.js +5 -0
  39. package/src/core/sync/write_types/test/layout-advanced/+layout.svelte +0 -0
  40. package/src/core/sync/write_types/test/layout-advanced/_expected/$types.d.ts +32 -0
  41. package/src/core/sync/write_types/test/layout-advanced/_expected/(main)/$types.d.ts +42 -0
  42. package/src/core/sync/write_types/test/layout-advanced/_expected/(main)/sub/$types.d.ts +33 -0
  43. package/src/core/sync/write_types/test/simple-page-server-and-shared/+page.js +5 -0
  44. package/src/core/sync/write_types/test/simple-page-server-and-shared/+page.server.js +5 -0
  45. package/src/core/sync/write_types/test/simple-page-server-and-shared/+page.svelte +0 -0
  46. package/src/core/sync/write_types/test/simple-page-server-and-shared/_expected/$types.d.ts +44 -0
  47. package/src/core/sync/write_types/test/simple-page-server-only/+page.server.js +5 -0
  48. package/src/core/sync/write_types/test/simple-page-server-only/+page.svelte +0 -0
  49. package/src/core/sync/write_types/test/simple-page-server-only/_expected/$types.d.ts +30 -0
  50. package/src/core/sync/write_types/test/simple-page-shared-only/+page.js +5 -0
  51. package/src/core/sync/write_types/test/simple-page-shared-only/+page.svelte +0 -0
  52. package/src/core/sync/write_types/test/simple-page-shared-only/_expected/$types.d.ts +33 -0
  53. package/src/core/sync/write_types/test/slugs/+layout.js +1 -0
  54. package/src/core/sync/write_types/test/slugs/+layout.svelte +1 -0
  55. package/src/core/sync/write_types/test/slugs/[...rest]/+page.js +3 -0
  56. package/src/core/sync/write_types/test/slugs/[...rest]/+page.svelte +0 -0
  57. package/src/core/sync/write_types/test/slugs/[slug]/+page.js +3 -0
  58. package/src/core/sync/write_types/test/slugs/[slug]/+page.svelte +0 -0
  59. package/src/core/sync/write_types/test/slugs/_expected/$types.d.ts +32 -0
  60. package/src/core/sync/write_types/test/slugs/_expected/[...rest]/$types.d.ts +29 -0
  61. package/src/core/sync/write_types/test/slugs/_expected/[slug]/$types.d.ts +29 -0
  62. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/+layout.js +1 -0
  63. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/+layout.svelte +1 -0
  64. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/$types.d.ts +30 -0
  65. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/nested/$types.d.ts +32 -0
  66. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/nested/[...rest]/$types.d.ts +37 -0
  67. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/_expected/nested/[slug]/$types.d.ts +17 -0
  68. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/+layout.js +1 -0
  69. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/+layout.svelte +1 -0
  70. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/[...rest]/+page.js +3 -0
  71. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/[...rest]/+page.svelte +0 -0
  72. package/src/core/sync/write_types/test/slugs-layout-not-all-pages-have-load/nested/[slug]/+page@.svelte +0 -0
  73. package/src/core/utils.js +70 -0
  74. package/src/hooks.js +26 -0
  75. package/src/index/index.js +45 -0
  76. package/src/index/private.js +33 -0
  77. package/src/node/index.js +145 -0
  78. package/src/node/polyfills.js +40 -0
  79. package/src/runtime/app/env.js +11 -0
  80. package/src/runtime/app/navigation.js +22 -0
  81. package/src/runtime/app/paths.js +1 -0
  82. package/src/runtime/app/stores.js +102 -0
  83. package/src/runtime/client/ambient.d.ts +18 -0
  84. package/src/runtime/client/client.js +1362 -0
  85. package/src/runtime/client/fetcher.js +60 -0
  86. package/src/runtime/client/parse.js +41 -0
  87. package/src/runtime/client/singletons.js +21 -0
  88. package/src/runtime/client/start.js +46 -0
  89. package/src/runtime/client/types.d.ts +86 -0
  90. package/src/runtime/client/utils.js +113 -0
  91. package/src/runtime/components/error.svelte +16 -0
  92. package/{assets → src/runtime}/components/layout.svelte +0 -0
  93. package/src/runtime/env/dynamic/private.js +1 -0
  94. package/src/runtime/env/dynamic/public.js +1 -0
  95. package/src/runtime/env-private.js +7 -0
  96. package/src/runtime/env-public.js +7 -0
  97. package/src/runtime/env.js +6 -0
  98. package/src/runtime/hash.js +16 -0
  99. package/src/runtime/paths.js +11 -0
  100. package/src/runtime/server/endpoint.js +50 -0
  101. package/src/runtime/server/index.js +492 -0
  102. package/src/runtime/server/page/cookie.js +25 -0
  103. package/src/runtime/server/page/crypto.js +239 -0
  104. package/src/runtime/server/page/csp.js +249 -0
  105. package/src/runtime/server/page/fetch.js +266 -0
  106. package/src/runtime/server/page/index.js +408 -0
  107. package/src/runtime/server/page/load_data.js +168 -0
  108. package/src/runtime/server/page/render.js +361 -0
  109. package/src/runtime/server/page/respond_with_error.js +95 -0
  110. package/src/runtime/server/page/types.d.ts +44 -0
  111. package/src/runtime/server/utils.js +116 -0
  112. package/src/utils/array.js +9 -0
  113. package/src/utils/error.js +22 -0
  114. package/src/utils/escape.js +104 -0
  115. package/src/utils/filesystem.js +108 -0
  116. package/src/utils/functions.js +16 -0
  117. package/src/utils/http.js +55 -0
  118. package/src/utils/misc.js +1 -0
  119. package/src/utils/routing.js +146 -0
  120. package/src/utils/url.js +142 -0
  121. package/src/vite/build/build_server.js +348 -0
  122. package/src/vite/build/build_service_worker.js +90 -0
  123. package/src/vite/build/utils.js +160 -0
  124. package/src/vite/dev/index.js +543 -0
  125. package/src/vite/index.js +578 -0
  126. package/src/vite/preview/index.js +186 -0
  127. package/src/vite/types.d.ts +3 -0
  128. package/src/vite/utils.js +345 -0
  129. package/svelte-kit.js +1 -1
  130. package/types/ambient.d.ts +366 -0
  131. package/types/index.d.ts +345 -0
  132. package/types/internal.d.ts +374 -0
  133. package/types/private.d.ts +209 -0
  134. package/CHANGELOG.md +0 -437
  135. package/assets/components/error.svelte +0 -13
  136. package/assets/runtime/app/env.js +0 -5
  137. package/assets/runtime/app/navigation.js +0 -41
  138. package/assets/runtime/app/paths.js +0 -1
  139. package/assets/runtime/app/stores.js +0 -93
  140. package/assets/runtime/chunks/utils.js +0 -19
  141. package/assets/runtime/internal/singletons.js +0 -23
  142. package/assets/runtime/internal/start.js +0 -770
  143. package/assets/runtime/paths.js +0 -12
  144. package/dist/chunks/index.js +0 -3521
  145. package/dist/chunks/index2.js +0 -587
  146. package/dist/chunks/index3.js +0 -246
  147. package/dist/chunks/index4.js +0 -545
  148. package/dist/chunks/index5.js +0 -761
  149. package/dist/chunks/index6.js +0 -322
  150. package/dist/chunks/standard.js +0 -99
  151. package/dist/chunks/utils.js +0 -83
  152. package/dist/cli.js +0 -546
  153. package/dist/ssr.js +0 -2580
@@ -0,0 +1,366 @@
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 PageData {}
11
+ *
12
+ * interface Platform {}
13
+ *
14
+ * interface PrivateEnv {}
15
+ *
16
+ * interface PublicEnv {}
17
+ * }
18
+ * ```
19
+ *
20
+ * By populating these interfaces, you will gain type safety when using `env`, `event.locals` and `event.platform`.
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`, and `handleError`), server-only `load` functions, and `+server.js` files.
49
+ */
50
+ export interface Locals {}
51
+
52
+ /**
53
+ * Defines the common shape of the [$page.data store](https://kit.svelte.dev/docs/modules#$app-stores-page) - that is, the data that is shared between all pages.
54
+ * The `Load` and `ServerLoad` functions in `./$types` will be narrowed accordingly.
55
+ * Use optional properties for data that is only present on specific pages. Do not add an index signature (`[key: string]: any`).
56
+ */
57
+ export interface PageData {}
58
+
59
+ /**
60
+ * 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.
61
+ */
62
+ export interface Platform {}
63
+
64
+ /**
65
+ * The interface that defines the dynamic environment variables exported from `$env/dynamic/private`.
66
+ */
67
+ export interface PrivateEnv extends Record<string, string> {}
68
+
69
+ /**
70
+ * The interface that defines the dynamic environment variables exported from `$env/dynamic/public`.
71
+ */
72
+ export interface PublicEnv extends Record<string, string> {}
73
+ }
74
+
75
+ /**
76
+ * ```ts
77
+ * import { browser, dev, prerendering } from '$app/env';
78
+ * ```
79
+ */
80
+ declare module '$app/env' {
81
+ /**
82
+ * `true` if the app is running in the browser.
83
+ */
84
+ export const browser: boolean;
85
+
86
+ /**
87
+ * Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
88
+ */
89
+ export const dev: boolean;
90
+
91
+ /**
92
+ * `true` when prerendering, `false` otherwise.
93
+ */
94
+ export const prerendering: boolean;
95
+ }
96
+
97
+ /**
98
+ * This module provides access to runtime environment variables, as defined by the platform you're running on. For example
99
+ * if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/master/packages/adapter-node) (or running
100
+ * [`vite preview`](https://kit.svelte.dev/docs/cli)), this is equivalent to `process.env`. This module only includes
101
+ * variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix).
102
+ *
103
+ * This module cannot be imported into client-side code.
104
+ *
105
+ * ```ts
106
+ * import { env } from '$env/dynamic/private';
107
+ * console.log(env.DEPLOYMENT_SPECIFIC_VARIABLE);
108
+ * ```
109
+ */
110
+ declare module '$env/dynamic/private' {
111
+ export let env: App.PrivateEnv;
112
+ }
113
+
114
+ /**
115
+ * Similar to [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), but only includes
116
+ * variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#kit-env-publicprefix)
117
+ * (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code
118
+ *
119
+ * 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.
120
+ *
121
+ * ```ts
122
+ * import { env } from '$env/dynamic/public';
123
+ * console.log(env.PUBLIC_DEPLOYMENT_SPECIFIC_VARIABLE);
124
+ * ```
125
+ */
126
+ declare module '$env/dynamic/public' {
127
+ export let env: App.PublicEnv;
128
+ }
129
+
130
+ /**
131
+ * ```ts
132
+ * import {
133
+ * afterNavigate,
134
+ * beforeNavigate,
135
+ * disableScrollHandling,
136
+ * goto,
137
+ * invalidate,
138
+ * prefetch,
139
+ * prefetchRoutes
140
+ * } from '$app/navigation';
141
+ * ```
142
+ */
143
+ declare module '$app/navigation' {
144
+ /**
145
+ * 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.
146
+ * This is generally discouraged, since it breaks user expectations.
147
+ */
148
+ export function disableScrollHandling(): void;
149
+ /**
150
+ * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
151
+ *
152
+ * @param url Where to navigate to
153
+ * @param opts.replaceState If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
154
+ * @param opts.noscroll If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation
155
+ * @param opts.keepfocus If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body
156
+ * @param opts.state The state of the new/updated history entry
157
+ */
158
+ export function goto(
159
+ url: string | URL,
160
+ opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any }
161
+ ): Promise<void>;
162
+ /**
163
+ * Causes any `load` functions belonging to the currently active page to re-run if they `fetch` the resource in question. If no argument is given, all resources will be invalidated. Returns a `Promise` that resolves when the page is subsequently updated.
164
+ * @param dependency The invalidated resource
165
+ */
166
+ export function invalidate(dependency?: string | ((href: string) => boolean)): Promise<void>;
167
+ /**
168
+ * Programmatically prefetches the given page, which means
169
+ * 1. ensuring that the code for the page is loaded, and
170
+ * 2. calling the page's load function with the appropriate options.
171
+ *
172
+ * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `sveltekit:prefetch`.
173
+ * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
174
+ * Returns a Promise that resolves when the prefetch is complete.
175
+ *
176
+ * @param href Page to prefetch
177
+ */
178
+ export function prefetch(href: string): Promise<void>;
179
+ /**
180
+ * Programmatically prefetches the code for routes that haven't yet been fetched.
181
+ * Typically, you might call this to speed up subsequent navigation.
182
+ *
183
+ * If no argument is given, all routes will be fetched, otherwise you can specify routes by any matching pathname
184
+ * such as `/about` (to match `src/routes/about.svelte`) or `/blog/*` (to match `src/routes/blog/[slug].svelte`).
185
+ *
186
+ * Unlike prefetch, this won't call load for individual pages.
187
+ * Returns a Promise that resolves when the routes have been prefetched.
188
+ */
189
+ export function prefetchRoutes(routes?: string[]): Promise<void>;
190
+
191
+ /**
192
+ * 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.
193
+ * This is helpful if we want to conditionally prevent a navigation from completing or lookup the upcoming url.
194
+ */
195
+ export function beforeNavigate(
196
+ fn: (navigation: { from: URL; to: URL | null; cancel: () => void }) => void
197
+ ): void;
198
+
199
+ /**
200
+ * A lifecycle function that runs when the page mounts, and also whenever SvelteKit navigates to a new URL but stays on this component.
201
+ */
202
+ export function afterNavigate(fn: (navigation: { from: URL | null; to: URL }) => void): void;
203
+ }
204
+
205
+ /**
206
+ * ```ts
207
+ * import { base, assets } from '$app/paths';
208
+ * ```
209
+ */
210
+ declare module '$app/paths' {
211
+ /**
212
+ * 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.
213
+ */
214
+ export const base: `/${string}`;
215
+ /**
216
+ * An absolute path that matches [`config.kit.paths.assets`](https://kit.svelte.dev/docs/configuration#paths).
217
+ *
218
+ * > 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.
219
+ */
220
+ export const assets: `https://${string}` | `http://${string}`;
221
+ }
222
+
223
+ /**
224
+ * ```ts
225
+ * import { getStores, navigating, page, updated } from '$app/stores';
226
+ * ```
227
+ *
228
+ * 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.
229
+ *
230
+ * 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.
231
+ *
232
+ * 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.
233
+ */
234
+ declare module '$app/stores' {
235
+ import { Readable } from 'svelte/store';
236
+ import { Navigation, Page } from '@sveltejs/kit';
237
+
238
+ /**
239
+ * A readable store whose value contains page data.
240
+ */
241
+ export const page: Readable<Page>;
242
+ /**
243
+ * A readable store.
244
+ * When navigating starts, its value is `{ from: URL, to: URL }`,
245
+ * When navigating finishes, its value reverts to `null`.
246
+ */
247
+ export const navigating: Readable<Navigation | null>;
248
+ /**
249
+ * 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.
250
+ */
251
+ export const updated: Readable<boolean> & { check: () => boolean };
252
+
253
+ /**
254
+ * A function that returns all of the contextual stores. On the server, this must be called during component initialization.
255
+ * Only use this if you need to defer store subscription until after the component has mounted, for some reason.
256
+ */
257
+ export function getStores(): {
258
+ navigating: typeof navigating;
259
+ page: typeof page;
260
+ updated: typeof updated;
261
+ };
262
+ }
263
+
264
+ /**
265
+ * ```ts
266
+ * import { build, files, prerendered, version } from '$service-worker';
267
+ * ```
268
+ *
269
+ * This module is only available to [service workers](https://kit.svelte.dev/docs/service-workers).
270
+ */
271
+ declare module '$service-worker' {
272
+ /**
273
+ * An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`.
274
+ */
275
+ export const build: string[];
276
+ /**
277
+ * 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)
278
+ */
279
+ export const files: string[];
280
+ /**
281
+ * An array of pathnames corresponding to prerendered pages and endpoints.
282
+ */
283
+ export const prerendered: string[];
284
+ /**
285
+ * 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.
286
+ */
287
+ export const version: string;
288
+ }
289
+
290
+ declare module '@sveltejs/kit/hooks' {
291
+ import { Handle } from '@sveltejs/kit';
292
+
293
+ /**
294
+ * A helper function for sequencing multiple `handle` calls in a middleware-like manner.
295
+ *
296
+ * ```js
297
+ * /// file: src/hooks.js
298
+ * import { sequence } from '@sveltejs/kit/hooks';
299
+ *
300
+ * /** @type {import('@sveltejs/kit').Handle} *\/
301
+ * async function first({ event, resolve }) {
302
+ * console.log('first pre-processing');
303
+ * const result = await resolve(event);
304
+ * console.log('first post-processing');
305
+ * return result;
306
+ * }
307
+ *
308
+ * /** @type {import('@sveltejs/kit').Handle} *\/
309
+ * async function second({ event, resolve }) {
310
+ * console.log('second pre-processing');
311
+ * const result = await resolve(event);
312
+ * console.log('second post-processing');
313
+ * return result;
314
+ * }
315
+ *
316
+ * export const handle = sequence(first, second);
317
+ * ```
318
+ *
319
+ * The example above would print:
320
+ *
321
+ * ```
322
+ * first pre-processing
323
+ * second pre-processing
324
+ * second post-processing
325
+ * first post-processing
326
+ * ```
327
+ *
328
+ * @param handlers The chain of `handle` functions
329
+ */
330
+ export function sequence(...handlers: Handle[]): Handle;
331
+ }
332
+
333
+ /**
334
+ * A polyfill for `fetch` and its related interfaces, used by adapters for environments that don't provide a native implementation.
335
+ */
336
+ declare module '@sveltejs/kit/node/polyfills' {
337
+ /**
338
+ * Make various web APIs available as globals:
339
+ * - `crypto`
340
+ * - `fetch`
341
+ * - `Headers`
342
+ * - `Request`
343
+ * - `Response`
344
+ */
345
+ export function installPolyfills(): void;
346
+ }
347
+
348
+ /**
349
+ * Utilities used by adapters for Node-like environments.
350
+ */
351
+ declare module '@sveltejs/kit/node' {
352
+ export function getRequest(
353
+ base: string,
354
+ request: import('http').IncomingMessage
355
+ ): Promise<Request>;
356
+ export function setResponse(res: import('http').ServerResponse, response: Response): void;
357
+ }
358
+
359
+ declare module '@sveltejs/kit/vite' {
360
+ import { Plugin } from 'vite';
361
+
362
+ /**
363
+ * Returns the SvelteKit Vite plugins.
364
+ */
365
+ export function sveltekit(): Plugin[];
366
+ }
@@ -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
+ 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, unknown> | null = Record<string, any> | null,
199
+ ParentData extends Record<string, unknown> = Record<string, any>,
200
+ OutputData extends Record<string, unknown> | 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, unknown> | null = Record<string, any> | null,
208
+ ParentData extends Record<string, unknown> = 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: App.PageData & 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
+ getClientAddress: () => 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<
257
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
258
+ > {
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 class Server {
268
+ constructor(manifest: SSRManifest);
269
+ init(options: ServerInitOptions): Promise<void>;
270
+ respond(request: Request, options: RequestOptions): Promise<Response>;
271
+ }
272
+
273
+ export interface ServerInitOptions {
274
+ env: Record<string, string>;
275
+ }
276
+
277
+ export interface SSRManifest {
278
+ appDir: string;
279
+ assets: Set<string>;
280
+ mimeTypes: Record<string, string>;
281
+
282
+ /** private fields */
283
+ _: {
284
+ entry: {
285
+ file: string;
286
+ imports: string[];
287
+ stylesheets: string[];
288
+ };
289
+ nodes: SSRNodeLoader[];
290
+ routes: SSRRoute[];
291
+ matchers: () => Promise<Record<string, ParamMatcher>>;
292
+ };
293
+ }
294
+
295
+ /**
296
+ * The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
297
+ * rather than using `ServerLoad` directly.
298
+ */
299
+ export interface ServerLoad<
300
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
301
+ ParentData extends Record<string, any> = Record<string, any>,
302
+ OutputData extends Record<string, any> | void = Record<string, any> | void
303
+ > {
304
+ (event: ServerLoadEvent<Params, ParentData>): MaybePromise<OutputData>;
305
+ }
306
+
307
+ export interface ServerLoadEvent<
308
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
309
+ ParentData extends Record<string, any> = Record<string, any>
310
+ > extends RequestEvent<Params> {
311
+ parent: () => Promise<ParentData>;
312
+ }
313
+
314
+ export interface Action<
315
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
316
+ > {
317
+ (event: RequestEvent<Params>): MaybePromise<
318
+ | { status?: number; errors: Record<string, any>; 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;