@sveltejs/kit 1.0.0-next.498 → 1.0.0-next.499
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/sync/sync.js +11 -0
- package/src/runtime/client/client.js +3 -3
- package/src/runtime/client/types.d.ts +2 -2
- package/src/runtime/control.js +1 -1
- package/src/runtime/server/page/render.js +1 -1
- package/src/runtime/server/utils.js +1 -1
- package/types/ambient.d.ts +7 -7
- package/types/index.d.ts +7 -7
- package/types/internal.d.ts +2 -2
package/package.json
CHANGED
package/src/core/sync/sync.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import create_manifest_data from './create_manifest_data/index.js';
|
|
3
4
|
import { write_client_manifest } from './write_client_manifest.js';
|
|
@@ -13,6 +14,16 @@ import { write_ambient } from './write_ambient.js';
|
|
|
13
14
|
* @param {string} mode
|
|
14
15
|
*/
|
|
15
16
|
export function init(config, mode) {
|
|
17
|
+
// TODO remove for 1.0
|
|
18
|
+
if (fs.existsSync('src/app.d.ts')) {
|
|
19
|
+
const content = fs.readFileSync('src/app.d.ts', 'utf-8');
|
|
20
|
+
if (content.includes('PageError')) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'App.PageError has been renamed to App.Error — please update your src/app.d.ts'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
write_tsconfig(config.kit);
|
|
17
28
|
write_ambient(config.kit, mode);
|
|
18
29
|
}
|
|
@@ -395,7 +395,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
395
395
|
* params: Record<string, string>;
|
|
396
396
|
* branch: Array<import('./types').BranchNode | undefined>;
|
|
397
397
|
* status: number;
|
|
398
|
-
* error: App.
|
|
398
|
+
* error: App.Error | null;
|
|
399
399
|
* route: import('types').CSRRoute | null;
|
|
400
400
|
* form?: Record<string, any> | null;
|
|
401
401
|
* }} opts
|
|
@@ -799,7 +799,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
799
799
|
}
|
|
800
800
|
|
|
801
801
|
let status = 500;
|
|
802
|
-
/** @type {App.
|
|
802
|
+
/** @type {App.Error} */
|
|
803
803
|
let error;
|
|
804
804
|
|
|
805
805
|
if (server_data_nodes?.includes(/** @type {import('types').ServerErrorNode} */ (err))) {
|
|
@@ -1504,7 +1504,7 @@ async function load_data(url, invalid) {
|
|
|
1504
1504
|
/**
|
|
1505
1505
|
* @param {unknown} error
|
|
1506
1506
|
* @param {import('types').NavigationEvent} event
|
|
1507
|
-
* @returns {App.
|
|
1507
|
+
* @returns {App.Error}
|
|
1508
1508
|
*/
|
|
1509
1509
|
function handle_error(error, event) {
|
|
1510
1510
|
return (
|
|
@@ -25,7 +25,7 @@ export interface Client {
|
|
|
25
25
|
// private API
|
|
26
26
|
_hydrate: (opts: {
|
|
27
27
|
status: number;
|
|
28
|
-
error: App.
|
|
28
|
+
error: App.Error;
|
|
29
29
|
node_ids: number[];
|
|
30
30
|
params: Record<string, string>;
|
|
31
31
|
routeId: string | null;
|
|
@@ -77,7 +77,7 @@ export interface DataNode {
|
|
|
77
77
|
|
|
78
78
|
export interface NavigationState {
|
|
79
79
|
branch: Array<BranchNode | undefined>;
|
|
80
|
-
error: App.
|
|
80
|
+
error: App.Error | null;
|
|
81
81
|
params: Record<string, string>;
|
|
82
82
|
route: CSRRoute | null;
|
|
83
83
|
url: URL;
|
package/src/runtime/control.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export class HttpError {
|
|
2
2
|
/**
|
|
3
3
|
* @param {number} status
|
|
4
|
-
* @param {{message: string} extends App.
|
|
4
|
+
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
|
|
5
5
|
*/
|
|
6
6
|
constructor(status, body) {
|
|
7
7
|
this.status = status;
|
|
@@ -23,7 +23,7 @@ const updated = {
|
|
|
23
23
|
* state: import('types').SSRState;
|
|
24
24
|
* page_config: { ssr: boolean; csr: boolean };
|
|
25
25
|
* status: number;
|
|
26
|
-
* error: App.
|
|
26
|
+
* error: App.Error | null;
|
|
27
27
|
* event: import('types').RequestEvent;
|
|
28
28
|
* resolve_opts: import('types').RequiredResolveOptions;
|
|
29
29
|
* action_result?: import('types').ActionResult;
|
|
@@ -154,7 +154,7 @@ export function handle_fatal_error(event, options, error) {
|
|
|
154
154
|
* @param {import('types').RequestEvent} event
|
|
155
155
|
* @param {import('types').SSROptions} options
|
|
156
156
|
* @param {any} error
|
|
157
|
-
* @returns {App.
|
|
157
|
+
* @returns {App.Error}
|
|
158
158
|
*/
|
|
159
159
|
export function handle_error_and_jsonify(event, options, error) {
|
|
160
160
|
if (error instanceof HttpError) {
|
package/types/ambient.d.ts
CHANGED
|
@@ -40,6 +40,13 @@
|
|
|
40
40
|
*
|
|
41
41
|
*/
|
|
42
42
|
declare namespace App {
|
|
43
|
+
/**
|
|
44
|
+
* Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function. Unexpected errors are handled by the `handleError` hooks which should return this shape.
|
|
45
|
+
*/
|
|
46
|
+
export interface Error {
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
43
50
|
/**
|
|
44
51
|
* 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.
|
|
45
52
|
*/
|
|
@@ -56,13 +63,6 @@ declare namespace App {
|
|
|
56
63
|
* 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.
|
|
57
64
|
*/
|
|
58
65
|
export interface Platform {}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function. Unexpected errors are handled by the `handleError` hooks which should return this shape.
|
|
62
|
-
*/
|
|
63
|
-
export interface PageError {
|
|
64
|
-
message: string;
|
|
65
|
-
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
package/types/index.d.ts
CHANGED
|
@@ -236,11 +236,11 @@ export interface Handle {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
export interface HandleServerError {
|
|
239
|
-
(input: { error: unknown; event: RequestEvent }): void | App.
|
|
239
|
+
(input: { error: unknown; event: RequestEvent }): void | App.Error;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
export interface HandleClientError {
|
|
243
|
-
(input: { error: unknown; event: NavigationEvent }): void | App.
|
|
243
|
+
(input: { error: unknown; event: NavigationEvent }): void | App.Error;
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
export interface HandleFetch {
|
|
@@ -300,7 +300,7 @@ export interface Page<Params extends Record<string, string> = Record<string, str
|
|
|
300
300
|
params: Params;
|
|
301
301
|
routeId: string | null;
|
|
302
302
|
status: number;
|
|
303
|
-
error: App.
|
|
303
|
+
error: App.Error | null;
|
|
304
304
|
data: App.PageData & Record<string, any>;
|
|
305
305
|
}
|
|
306
306
|
|
|
@@ -415,13 +415,13 @@ export type ActionResult<
|
|
|
415
415
|
* This object, if thrown during request handling, will cause SvelteKit to
|
|
416
416
|
* return an error response without invoking `handleError`
|
|
417
417
|
* @param status The HTTP status code
|
|
418
|
-
* @param body An object that conforms to the App.
|
|
418
|
+
* @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
419
419
|
*/
|
|
420
|
-
export function error(status: number, body: App.
|
|
420
|
+
export function error(status: number, body: App.Error): HttpError;
|
|
421
421
|
export function error(
|
|
422
422
|
status: number,
|
|
423
|
-
// this overload ensures you can omit the argument or pass in a string if App.
|
|
424
|
-
body?: { message: string } extends App.
|
|
423
|
+
// this overload ensures you can omit the argument or pass in a string if App.Error is of type { message: string }
|
|
424
|
+
body?: { message: string } extends App.Error ? App.Error | string | undefined : never
|
|
425
425
|
): HttpError;
|
|
426
426
|
|
|
427
427
|
/**
|
package/types/internal.d.ts
CHANGED
|
@@ -226,7 +226,7 @@ export interface ServerDataSkippedNode {
|
|
|
226
226
|
*/
|
|
227
227
|
export interface ServerErrorNode {
|
|
228
228
|
type: 'error';
|
|
229
|
-
error: App.
|
|
229
|
+
error: App.Error;
|
|
230
230
|
/**
|
|
231
231
|
* Only set for HttpErrors
|
|
232
232
|
*/
|
|
@@ -288,7 +288,7 @@ export interface SSROptions {
|
|
|
288
288
|
check_origin: boolean;
|
|
289
289
|
};
|
|
290
290
|
dev: boolean;
|
|
291
|
-
handle_error(error: Error & { frame?: string }, event: RequestEvent): App.
|
|
291
|
+
handle_error(error: Error & { frame?: string }, event: RequestEvent): App.Error;
|
|
292
292
|
hooks: ServerHooks;
|
|
293
293
|
manifest: SSRManifest;
|
|
294
294
|
paths: {
|