@sveltejs/kit 1.0.11 → 1.0.13

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 (45) hide show
  1. package/package.json +3 -3
  2. package/src/core/adapt/builder.js +1 -1
  3. package/src/core/{prerender → postbuild}/crawl.js +0 -0
  4. package/src/core/{prerender → postbuild}/entities.js +0 -0
  5. package/src/core/{prerender → postbuild}/fallback.js +10 -7
  6. package/src/core/postbuild/index.js +104 -0
  7. package/src/core/{prerender → postbuild}/prerender.js +32 -106
  8. package/src/core/{prerender → postbuild}/queue.js +0 -0
  9. package/src/core/sync/sync.js +10 -0
  10. package/src/core/sync/write_client_manifest.js +1 -1
  11. package/src/core/sync/write_server.js +89 -0
  12. package/src/core/utils.js +0 -9
  13. package/src/exports/vite/build/build_server.js +11 -163
  14. package/src/exports/vite/build/build_service_worker.js +3 -2
  15. package/src/exports/vite/build/utils.js +1 -0
  16. package/src/exports/vite/dev/index.js +72 -114
  17. package/src/exports/vite/index.js +26 -27
  18. package/src/exports/vite/preview/index.js +11 -12
  19. package/src/runtime/app/environment.js +1 -1
  20. package/src/runtime/app/paths.js +1 -1
  21. package/src/runtime/client/client.js +8 -2
  22. package/src/runtime/client/fetcher.js +12 -4
  23. package/src/runtime/client/start.js +1 -2
  24. package/src/runtime/client/types.d.ts +1 -1
  25. package/src/runtime/client/utils.js +1 -2
  26. package/src/runtime/control.js +23 -5
  27. package/src/runtime/server/ambient.d.ts +8 -0
  28. package/src/runtime/server/cookie.js +4 -5
  29. package/src/runtime/server/data/index.js +5 -2
  30. package/src/runtime/server/endpoint.js +5 -5
  31. package/src/runtime/server/fetch.js +11 -9
  32. package/src/runtime/server/index.js +54 -395
  33. package/src/runtime/server/page/csp.js +9 -11
  34. package/src/runtime/server/page/index.js +13 -8
  35. package/src/runtime/server/page/load_data.js +2 -3
  36. package/src/runtime/server/page/render.js +28 -25
  37. package/src/runtime/server/page/respond_with_error.js +20 -13
  38. package/src/runtime/server/page/types.d.ts +0 -1
  39. package/src/runtime/server/respond.js +419 -0
  40. package/src/runtime/server/utils.js +21 -4
  41. package/src/runtime/shared.js +28 -0
  42. package/types/index.d.ts +10 -5
  43. package/types/internal.d.ts +22 -39
  44. package/src/runtime/env.js +0 -12
  45. package/src/runtime/paths.js +0 -11
@@ -3,6 +3,7 @@ import { coalesce_to_error } from '../../utils/error.js';
3
3
  import { negotiate } from '../../utils/http.js';
4
4
  import { has_data_suffix } from '../../utils/url.js';
5
5
  import { HttpError } from '../control.js';
6
+ import { fix_stack_trace } from '../shared.js';
6
7
 
7
8
  /** @param {any} body */
8
9
  export function is_pojo(body) {
@@ -74,7 +75,7 @@ export function get_option(nodes, option) {
74
75
  * @param {string} message
75
76
  */
76
77
  export function static_error_page(options, status, message) {
77
- return new Response(options.error_template({ status, message }), {
78
+ return new Response(options.templates.error({ status, message }), {
78
79
  headers: { 'content-type': 'text/html; charset=utf-8' },
79
80
  status
80
81
  });
@@ -110,13 +111,29 @@ export async function handle_fatal_error(event, options, error) {
110
111
  * @param {import('types').RequestEvent} event
111
112
  * @param {import('types').SSROptions} options
112
113
  * @param {any} error
113
- * @returns {import('types').MaybePromise<App.Error>}
114
+ * @returns {Promise<App.Error>}
114
115
  */
115
- export function handle_error_and_jsonify(event, options, error) {
116
+ export async function handle_error_and_jsonify(event, options, error) {
116
117
  if (error instanceof HttpError) {
117
118
  return error.body;
118
119
  } else {
119
- return options.handle_error(error, event);
120
+ if (__SVELTEKIT_DEV__) {
121
+ error = new Proxy(error, {
122
+ get: (target, property) => {
123
+ if (property === 'stack') {
124
+ return fix_stack_trace(target.stack);
125
+ }
126
+
127
+ return Reflect.get(target, property, target);
128
+ }
129
+ });
130
+ }
131
+
132
+ return (
133
+ (await options.hooks.handleError({ error, event })) ?? {
134
+ message: event.route.id != null ? 'Internal Error' : 'Not Found'
135
+ }
136
+ );
120
137
  }
121
138
  }
122
139
 
@@ -0,0 +1,28 @@
1
+ export let assets = '';
2
+ export let base = '';
3
+ export let building = false;
4
+ export let version = '';
5
+
6
+ /** @param {string} stack */
7
+ export let fix_stack_trace = (stack) => stack;
8
+
9
+ /** @param {{ base: string, assets: string }} paths */
10
+ export function set_paths(paths) {
11
+ base = paths.base;
12
+ assets = paths.assets || base;
13
+ }
14
+
15
+ /** @param {boolean} value */
16
+ export function set_building(value) {
17
+ building = value;
18
+ }
19
+
20
+ /** @param {string} value */
21
+ export function set_version(value) {
22
+ version = value;
23
+ }
24
+
25
+ /** @param {(stack: string) => string} value */
26
+ export function set_fix_stack_trace(value) {
27
+ fix_stack_trace = value;
28
+ }
package/types/index.d.ts CHANGED
@@ -1080,7 +1080,7 @@ export type ActionResult<
1080
1080
  * Creates an `HttpError` object with an HTTP status code and an optional message.
1081
1081
  * This object, if thrown during request handling, will cause SvelteKit to
1082
1082
  * return an error response without invoking `handleError`
1083
- * @param status The HTTP status code
1083
+ * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
1084
1084
  * @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
1085
1085
  */
1086
1086
  export function error(status: number, body: App.Error): HttpError;
@@ -1094,15 +1094,16 @@ export function error(
1094
1094
  * The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
1095
1095
  */
1096
1096
  export interface HttpError {
1097
- /** The [HTTP status code](https://httpstatusdogs.com), in the range 400-599 */
1097
+ /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
1098
1098
  status: number;
1099
1099
  /** The content of the error. */
1100
1100
  body: App.Error;
1101
1101
  }
1102
1102
 
1103
1103
  /**
1104
- * Create a `Redirect` object. If thrown during request handling, SvelteKit will
1105
- * return a redirect response.
1104
+ * Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response.
1105
+ * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
1106
+ * @param location The location to redirect to.
1106
1107
  */
1107
1108
  export function redirect(
1108
1109
  status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
@@ -1113,7 +1114,7 @@ export function redirect(
1113
1114
  * The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
1114
1115
  */
1115
1116
  export interface Redirect {
1116
- /** The [HTTP status code](https://httpstatusdogs.com), in the range 300-308. */
1117
+ /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
1117
1118
  status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
1118
1119
  /** The location to redirect to. */
1119
1120
  location: string;
@@ -1128,6 +1129,8 @@ export function json(data: any, init?: ResponseInit): Response;
1128
1129
 
1129
1130
  /**
1130
1131
  * Create an `ActionFailure` object.
1132
+ * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
1133
+ * @param data Data associated with the failure (e.g. validation errors)
1131
1134
  */
1132
1135
  export function fail<T extends Record<string, unknown> | undefined>(
1133
1136
  status: number,
@@ -1139,7 +1142,9 @@ export function fail<T extends Record<string, unknown> | undefined>(
1139
1142
  */
1140
1143
  export interface ActionFailure<T extends Record<string, unknown> | undefined = undefined>
1141
1144
  extends UniqueInterface {
1145
+ /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
1142
1146
  status: number;
1147
+ /** Data associated with the failure (e.g. validation errors) */
1143
1148
  data: T;
1144
1149
  }
1145
1150
 
@@ -27,16 +27,13 @@ import {
27
27
 
28
28
  export interface ServerModule {
29
29
  Server: typeof InternalServer;
30
+ }
30
31
 
31
- override(options: {
32
- building: boolean;
33
- paths: {
34
- base: string;
35
- assets: string;
36
- };
37
- protocol?: 'http' | 'https';
38
- read(file: string): Buffer;
39
- }): void;
32
+ export interface ServerInternalModule {
33
+ set_building(building: boolean): void;
34
+ set_paths(paths: { base: string; assets: string }): void;
35
+ set_version(version: string): void;
36
+ set_fix_stack_trace(fix_stack_trace: (stack: string) => string): void;
40
37
  }
41
38
 
42
39
  export interface Asset {
@@ -74,7 +71,7 @@ export interface CSRPageNode {
74
71
  load?: Load;
75
72
  trailingSlash?: TrailingSlash;
76
73
  };
77
- server: boolean;
74
+ has_server_load: boolean;
78
75
  }
79
76
 
80
77
  export type CSRPageNodeLoader = () => Promise<CSRPageNode>;
@@ -109,6 +106,7 @@ export class InternalServer extends Server {
109
106
  request: Request,
110
107
  options: RequestOptions & {
111
108
  prerendering?: PrerenderOptions;
109
+ read: (file: string) => Buffer;
112
110
  }
113
111
  ): Promise<Response>;
114
112
  }
@@ -155,7 +153,12 @@ export type RecursiveRequired<T> = {
155
153
  export type RequiredResolveOptions = Required<ResolveOptions>;
156
154
 
157
155
  export interface Respond {
158
- (request: Request, options: SSROptions, state: SSRState): Promise<Response>;
156
+ (
157
+ request: Request,
158
+ options: SSROptions,
159
+ manifest: SSRManifest,
160
+ state: SSRState
161
+ ): Promise<Response>;
159
162
  }
160
163
 
161
164
  export interface RouteParam {
@@ -294,37 +297,18 @@ export interface SSRNode {
294
297
  export type SSRNodeLoader = () => Promise<SSRNode>;
295
298
 
296
299
  export interface SSROptions {
300
+ app_template_contains_nonce: boolean;
297
301
  csp: ValidatedConfig['kit']['csp'];
298
- csrf: {
299
- check_origin: boolean;
300
- };
301
- dev: boolean;
302
+ csrf_check_origin: boolean;
302
303
  embedded: boolean;
303
- handle_error(error: Error & { frame?: string }, event: RequestEvent): MaybePromise<App.Error>;
304
+ env_public_prefix: string;
304
305
  hooks: ServerHooks;
305
- manifest: SSRManifest;
306
- paths: {
307
- base: string;
308
- assets: string;
309
- };
310
- public_env: Record<string, string>;
311
- read(file: string): Buffer;
312
306
  root: SSRComponent['default'];
313
307
  service_worker: boolean;
314
- app_template({
315
- head,
316
- body,
317
- assets,
318
- nonce
319
- }: {
320
- head: string;
321
- body: string;
322
- assets: string;
323
- nonce: string;
324
- }): string;
325
- app_template_contains_nonce: boolean;
326
- error_template({ message, status }: { message: string; status: number }): string;
327
- version: string;
308
+ templates: {
309
+ app(values: { head: string; body: string; assets: string; nonce: string }): string;
310
+ error(values: { message: string; status: number }): string;
311
+ };
328
312
  }
329
313
 
330
314
  export interface SSRErrorPage {
@@ -362,6 +346,7 @@ export interface SSRState {
362
346
  * prerender option is inherited by the endpoint, unless overridden
363
347
  */
364
348
  prerender_default?: PrerenderOption;
349
+ read?: (file: string) => Buffer;
365
350
  }
366
351
 
367
352
  export type StrictBody = string | ArrayBufferView;
@@ -383,10 +368,8 @@ export * from './private';
383
368
 
384
369
  declare global {
385
370
  const __SVELTEKIT_ADAPTER_NAME__: string;
386
- const __SVELTEKIT_APP_VERSION__: string;
387
371
  const __SVELTEKIT_APP_VERSION_FILE__: string;
388
372
  const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
389
- const __SVELTEKIT_BROWSER__: boolean;
390
373
  const __SVELTEKIT_DEV__: boolean;
391
374
  const __SVELTEKIT_EMBEDDED__: boolean;
392
375
  var Bun: object;
@@ -1,12 +0,0 @@
1
- export let building = false;
2
- export let version = '';
3
-
4
- /** @param {boolean} value */
5
- export function set_building(value) {
6
- building = value;
7
- }
8
-
9
- /** @param {string} value */
10
- export function set_version(value) {
11
- version = value;
12
- }
@@ -1,11 +0,0 @@
1
- /** @type {string} */
2
- export let base = '';
3
-
4
- /** @type {string} */
5
- export let assets = '';
6
-
7
- /** @param {{ base: string, assets: string }} paths */
8
- export function set_paths(paths) {
9
- base = paths.base;
10
- assets = paths.assets || base;
11
- }