@sveltejs/kit 1.0.0-next.414 → 1.0.0-next.417
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/create_manifest_data/index.js +14 -4
- package/src/runtime/app/stores.js +18 -21
- package/src/runtime/client/client.js +8 -31
- package/src/runtime/client/start.js +1 -3
- package/src/runtime/client/types.d.ts +0 -1
- package/src/runtime/server/index.js +0 -5
- package/src/runtime/server/page/index.js +0 -8
- package/src/runtime/server/page/load_data.js +5 -18
- package/src/runtime/server/page/render.js +0 -22
- package/src/runtime/server/page/respond_with_error.js +1 -13
- package/src/vite/build/build_server.js +0 -1
- package/src/vite/dev/index.js +0 -1
- package/types/ambient.d.ts +5 -18
- package/types/index.d.ts +1 -5
- package/types/internal.d.ts +0 -2
package/package.json
CHANGED
|
@@ -172,12 +172,22 @@ export default function create_manifest_data({
|
|
|
172
172
|
if (item.is_page) {
|
|
173
173
|
const route = /** @type {import('types').PageData} */ (route_map.get(id));
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
// This ensures that layouts and errors are set for pages that have no Svelte file
|
|
176
|
+
// and only redirect or throw an error, but are set to the Svelte file definition if it exists.
|
|
177
|
+
// This ensures the proper error page is used and rendered in the proper layout.
|
|
178
|
+
if (item.kind === 'component' || route.layouts.length === 0) {
|
|
179
|
+
const { layouts, errors } = trace(
|
|
180
|
+
tree,
|
|
181
|
+
id,
|
|
182
|
+
item.kind === 'component' ? item.uses_layout : undefined,
|
|
183
|
+
project_relative
|
|
184
|
+
);
|
|
179
185
|
route.layouts = layouts;
|
|
180
186
|
route.errors = errors;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (item.kind === 'component') {
|
|
190
|
+
route.leaf.component = project_relative;
|
|
181
191
|
} else if (item.kind === 'server') {
|
|
182
192
|
route.leaf.server = project_relative;
|
|
183
193
|
} else {
|
|
@@ -32,7 +32,10 @@ export const getStores = () => {
|
|
|
32
32
|
subscribe: stores.navigating.subscribe
|
|
33
33
|
};
|
|
34
34
|
},
|
|
35
|
-
session
|
|
35
|
+
get session() {
|
|
36
|
+
removed_session();
|
|
37
|
+
return {};
|
|
38
|
+
},
|
|
36
39
|
updated: stores.updated
|
|
37
40
|
};
|
|
38
41
|
};
|
|
@@ -54,29 +57,17 @@ export const navigating = {
|
|
|
54
57
|
}
|
|
55
58
|
};
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
function removed_session() {
|
|
61
|
+
// TODO remove for 1.0
|
|
59
62
|
throw new Error(
|
|
60
|
-
|
|
61
|
-
? `Cannot ${verb} session store before subscribing`
|
|
62
|
-
: `Can only ${verb} session store in browser`
|
|
63
|
+
'stores.session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
|
|
63
64
|
);
|
|
64
|
-
}
|
|
65
|
+
}
|
|
65
66
|
|
|
66
|
-
/** @type {typeof import('$app/stores').session} */
|
|
67
67
|
export const session = {
|
|
68
|
-
subscribe
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (browser) {
|
|
72
|
-
session.set = store.set;
|
|
73
|
-
session.update = store.update;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return store.subscribe(fn);
|
|
77
|
-
},
|
|
78
|
-
set: () => throw_error('set'),
|
|
79
|
-
update: () => throw_error('update')
|
|
68
|
+
subscribe: removed_session,
|
|
69
|
+
set: removed_session,
|
|
70
|
+
update: removed_session
|
|
80
71
|
};
|
|
81
72
|
|
|
82
73
|
/** @type {typeof import('$app/stores').updated} */
|
|
@@ -90,5 +81,11 @@ export const updated = {
|
|
|
90
81
|
|
|
91
82
|
return store.subscribe(fn);
|
|
92
83
|
},
|
|
93
|
-
check: () =>
|
|
84
|
+
check: () => {
|
|
85
|
+
throw new Error(
|
|
86
|
+
browser
|
|
87
|
+
? `Cannot check updated store before subscribing`
|
|
88
|
+
: `Can only check updated store in browser`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
94
91
|
};
|
|
@@ -50,13 +50,12 @@ function update_scroll_positions(index) {
|
|
|
50
50
|
/**
|
|
51
51
|
* @param {{
|
|
52
52
|
* target: Element;
|
|
53
|
-
* session: App.Session;
|
|
54
53
|
* base: string;
|
|
55
54
|
* trailing_slash: import('types').TrailingSlash;
|
|
56
55
|
* }} opts
|
|
57
56
|
* @returns {import('./types').Client}
|
|
58
57
|
*/
|
|
59
|
-
export function create_client({ target,
|
|
58
|
+
export function create_client({ target, base, trailing_slash }) {
|
|
60
59
|
/** @type {Array<((href: string) => boolean)>} */
|
|
61
60
|
const invalidated = [];
|
|
62
61
|
|
|
@@ -64,7 +63,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
64
63
|
url: notifiable_store({}),
|
|
65
64
|
page: notifiable_store({}),
|
|
66
65
|
navigating: writable(/** @type {import('types').Navigation | null} */ (null)),
|
|
67
|
-
session: writable(session),
|
|
68
66
|
updated: create_updated_store()
|
|
69
67
|
};
|
|
70
68
|
|
|
@@ -102,23 +100,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
102
100
|
/** @type {import('svelte').SvelteComponent} */
|
|
103
101
|
let root;
|
|
104
102
|
|
|
105
|
-
/** @type {App.Session} */
|
|
106
|
-
let $session;
|
|
107
|
-
|
|
108
|
-
let ready = false;
|
|
109
|
-
stores.session.subscribe(async (value) => {
|
|
110
|
-
$session = value;
|
|
111
|
-
|
|
112
|
-
if (!ready) return;
|
|
113
|
-
session_id += 1;
|
|
114
|
-
|
|
115
|
-
const current_load_uses_session = current.branch.some((node) => node?.uses.session);
|
|
116
|
-
if (!current_load_uses_session) return;
|
|
117
|
-
|
|
118
|
-
update(new URL(location.href), []);
|
|
119
|
-
});
|
|
120
|
-
ready = true;
|
|
121
|
-
|
|
122
103
|
let router_enabled = true;
|
|
123
104
|
|
|
124
105
|
// keeping track of the history index in order to prevent popstate navigation events if needed
|
|
@@ -475,7 +456,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
475
456
|
const uses = {
|
|
476
457
|
params: new Set(),
|
|
477
458
|
url: false,
|
|
478
|
-
session: false,
|
|
479
459
|
dependencies: new Set(),
|
|
480
460
|
parent: false
|
|
481
461
|
};
|
|
@@ -511,7 +491,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
511
491
|
});
|
|
512
492
|
}
|
|
513
493
|
|
|
514
|
-
const session = $session;
|
|
515
494
|
const load_url = new LoadURL(url);
|
|
516
495
|
|
|
517
496
|
if (node.shared?.load) {
|
|
@@ -524,10 +503,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
524
503
|
uses.url = true;
|
|
525
504
|
return load_url;
|
|
526
505
|
},
|
|
527
|
-
get session() {
|
|
528
|
-
uses.session = true;
|
|
529
|
-
return session;
|
|
530
|
-
},
|
|
531
506
|
async fetch(resource, init) {
|
|
532
507
|
let requested;
|
|
533
508
|
|
|
@@ -581,6 +556,12 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
581
556
|
'@migration task: Replace `props` with `data` stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
|
|
582
557
|
);
|
|
583
558
|
},
|
|
559
|
+
get session() {
|
|
560
|
+
// TODO remove this for 1.0
|
|
561
|
+
throw new Error(
|
|
562
|
+
'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
|
|
563
|
+
);
|
|
564
|
+
},
|
|
584
565
|
get stuff() {
|
|
585
566
|
throw new Error(
|
|
586
567
|
'@migration task: Remove stuff https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292693'
|
|
@@ -620,8 +601,7 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
620
601
|
|
|
621
602
|
const changed = current.url && {
|
|
622
603
|
url: id !== current.url.pathname + current.url.search,
|
|
623
|
-
params: Object.keys(params).filter((key) => current.params[key] !== params[key])
|
|
624
|
-
session: session_id !== current.session_id
|
|
604
|
+
params: Object.keys(params).filter((key) => current.params[key] !== params[key])
|
|
625
605
|
};
|
|
626
606
|
|
|
627
607
|
// preload modules to avoid waterfall, but handle rejections
|
|
@@ -643,7 +623,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
643
623
|
!previous ||
|
|
644
624
|
(changed.url && previous.uses.url) ||
|
|
645
625
|
changed.params.some((param) => previous.uses.params.has(param)) ||
|
|
646
|
-
(changed.session && previous.uses.session) ||
|
|
647
626
|
Array.from(previous.uses.dependencies).some((dep) => invalidated.some((fn) => fn(dep))) ||
|
|
648
627
|
(previous.uses.parent && nodes_changed_since_last_render.includes(true));
|
|
649
628
|
nodes_changed_since_last_render.push(changed_since_last_render);
|
|
@@ -753,7 +732,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
753
732
|
uses: {
|
|
754
733
|
params: new Set(),
|
|
755
734
|
url: false,
|
|
756
|
-
session: false,
|
|
757
735
|
dependencies: new Set(),
|
|
758
736
|
parent: false
|
|
759
737
|
}
|
|
@@ -825,7 +803,6 @@ export function create_client({ target, session, base, trailing_slash }) {
|
|
|
825
803
|
uses: {
|
|
826
804
|
params: new Set(),
|
|
827
805
|
url: false,
|
|
828
|
-
session: false,
|
|
829
806
|
dependencies: new Set(),
|
|
830
807
|
parent: false
|
|
831
808
|
}
|
|
@@ -11,7 +11,6 @@ export { set_public_env } from '../env-public.js';
|
|
|
11
11
|
* base: string;
|
|
12
12
|
* },
|
|
13
13
|
* target: Element;
|
|
14
|
-
* session: any;
|
|
15
14
|
* route: boolean;
|
|
16
15
|
* spa: boolean;
|
|
17
16
|
* trailing_slash: import('types').TrailingSlash;
|
|
@@ -24,10 +23,9 @@ export { set_public_env } from '../env-public.js';
|
|
|
24
23
|
* };
|
|
25
24
|
* }} opts
|
|
26
25
|
*/
|
|
27
|
-
export async function start({ paths, target,
|
|
26
|
+
export async function start({ paths, target, route, spa, trailing_slash, hydrate }) {
|
|
28
27
|
const client = create_client({
|
|
29
28
|
target,
|
|
30
|
-
session,
|
|
31
29
|
base: paths.base,
|
|
32
30
|
trailing_slash
|
|
33
31
|
});
|
|
@@ -222,7 +222,6 @@ export async function respond(request, options, state) {
|
|
|
222
222
|
event,
|
|
223
223
|
options,
|
|
224
224
|
state,
|
|
225
|
-
$session: await options.hooks.getSession(event),
|
|
226
225
|
page_config: { router: true, hydrate: true },
|
|
227
226
|
status: 200,
|
|
228
227
|
error: null,
|
|
@@ -365,12 +364,10 @@ export async function respond(request, options, state) {
|
|
|
365
364
|
// if this request came direct from the user, rather than
|
|
366
365
|
// via a `fetch` in a `load`, render a 404 page
|
|
367
366
|
if (!state.initiator) {
|
|
368
|
-
const $session = await options.hooks.getSession(event);
|
|
369
367
|
return await respond_with_error({
|
|
370
368
|
event,
|
|
371
369
|
options,
|
|
372
370
|
state,
|
|
373
|
-
$session,
|
|
374
371
|
status: 404,
|
|
375
372
|
error: new Error(`Not found: ${event.url.pathname}`),
|
|
376
373
|
resolve_opts
|
|
@@ -418,12 +415,10 @@ export async function respond(request, options, state) {
|
|
|
418
415
|
|
|
419
416
|
// TODO is this necessary? should we just return a plain 500 at this point?
|
|
420
417
|
try {
|
|
421
|
-
const $session = await options.hooks.getSession(event);
|
|
422
418
|
return await respond_with_error({
|
|
423
419
|
event,
|
|
424
420
|
options,
|
|
425
421
|
state,
|
|
426
|
-
$session,
|
|
427
422
|
status: 500,
|
|
428
423
|
error,
|
|
429
424
|
resolve_opts
|
|
@@ -43,8 +43,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const $session = await options.hooks.getSession(event);
|
|
47
|
-
|
|
48
46
|
const { fetcher, fetched, cookies } = create_fetch({ event, options, state, route });
|
|
49
47
|
|
|
50
48
|
try {
|
|
@@ -112,7 +110,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
112
110
|
event,
|
|
113
111
|
options,
|
|
114
112
|
state,
|
|
115
|
-
$session,
|
|
116
113
|
resolve_opts
|
|
117
114
|
});
|
|
118
115
|
}
|
|
@@ -180,11 +177,9 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
180
177
|
return Promise.resolve().then(async () => {
|
|
181
178
|
try {
|
|
182
179
|
return await load_data({
|
|
183
|
-
$session,
|
|
184
180
|
event,
|
|
185
181
|
fetcher,
|
|
186
182
|
node,
|
|
187
|
-
options,
|
|
188
183
|
parent: async () => {
|
|
189
184
|
const data = {};
|
|
190
185
|
for (let j = 0; j < i; j += 1) {
|
|
@@ -240,7 +235,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
240
235
|
event,
|
|
241
236
|
options,
|
|
242
237
|
state,
|
|
243
|
-
$session,
|
|
244
238
|
resolve_opts,
|
|
245
239
|
page_config: { router: true, hydrate: true },
|
|
246
240
|
status,
|
|
@@ -294,7 +288,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
294
288
|
event,
|
|
295
289
|
options,
|
|
296
290
|
state,
|
|
297
|
-
$session,
|
|
298
291
|
resolve_opts,
|
|
299
292
|
page_config: get_page_config(leaf_node, options),
|
|
300
293
|
status,
|
|
@@ -313,7 +306,6 @@ export async function render_page(event, route, options, state, resolve_opts) {
|
|
|
313
306
|
event,
|
|
314
307
|
options,
|
|
315
308
|
state,
|
|
316
|
-
$session,
|
|
317
309
|
status: 500,
|
|
318
310
|
error: /** @type {Error} */ (error),
|
|
319
311
|
resolve_opts
|
|
@@ -33,26 +33,15 @@ export async function load_server_data({ event, node, parent }) {
|
|
|
33
33
|
/**
|
|
34
34
|
* Calls the user's `load` function.
|
|
35
35
|
* @param {{
|
|
36
|
-
* $session: Record<string, any>;
|
|
37
36
|
* event: import('types').RequestEvent;
|
|
38
37
|
* fetcher: typeof fetch;
|
|
39
38
|
* node: import('types').SSRNode | undefined;
|
|
40
|
-
* options: import('types').SSROptions;
|
|
41
39
|
* parent: () => Promise<Record<string, any>>;
|
|
42
40
|
* server_data_promise: Promise<import('types').JSONObject | null>;
|
|
43
41
|
* state: import('types').SSRState;
|
|
44
42
|
* }} opts
|
|
45
43
|
*/
|
|
46
|
-
export async function load_data({
|
|
47
|
-
$session,
|
|
48
|
-
event,
|
|
49
|
-
fetcher,
|
|
50
|
-
node,
|
|
51
|
-
options,
|
|
52
|
-
parent,
|
|
53
|
-
server_data_promise,
|
|
54
|
-
state
|
|
55
|
-
}) {
|
|
44
|
+
export async function load_data({ event, fetcher, node, parent, server_data_promise, state }) {
|
|
56
45
|
const server_data = await server_data_promise;
|
|
57
46
|
|
|
58
47
|
if (!node?.shared?.load) {
|
|
@@ -65,12 +54,10 @@ export async function load_data({
|
|
|
65
54
|
data: server_data,
|
|
66
55
|
routeId: event.routeId,
|
|
67
56
|
get session() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
return $session;
|
|
57
|
+
// TODO remove for 1.0
|
|
58
|
+
throw new Error(
|
|
59
|
+
'session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
|
|
60
|
+
);
|
|
74
61
|
},
|
|
75
62
|
fetch: fetcher,
|
|
76
63
|
setHeaders: event.setHeaders,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import devalue from 'devalue';
|
|
2
2
|
import { readable, writable } from 'svelte/store';
|
|
3
3
|
import * as cookie from 'cookie';
|
|
4
|
-
import { coalesce_to_error } from '../../../utils/error.js';
|
|
5
4
|
import { hash } from '../../hash.js';
|
|
6
5
|
import { render_json_payload_script } from '../../../utils/escape.js';
|
|
7
6
|
import { s } from '../../../utils/misc.js';
|
|
@@ -25,7 +24,6 @@ const updated = {
|
|
|
25
24
|
* cookies: import('set-cookie-parser').Cookie[];
|
|
26
25
|
* options: import('types').SSROptions;
|
|
27
26
|
* state: import('types').SSRState;
|
|
28
|
-
* $session: any;
|
|
29
27
|
* page_config: { hydrate: boolean, router: boolean };
|
|
30
28
|
* status: number;
|
|
31
29
|
* error: HttpError | Error | null;
|
|
@@ -40,7 +38,6 @@ export async function render_response({
|
|
|
40
38
|
cookies,
|
|
41
39
|
options,
|
|
42
40
|
state,
|
|
43
|
-
$session,
|
|
44
41
|
page_config,
|
|
45
42
|
status,
|
|
46
43
|
error = null,
|
|
@@ -79,14 +76,11 @@ export async function render_response({
|
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
if (resolve_opts.ssr) {
|
|
82
|
-
const session = writable($session);
|
|
83
|
-
|
|
84
79
|
/** @type {Record<string, any>} */
|
|
85
80
|
const props = {
|
|
86
81
|
stores: {
|
|
87
82
|
page: writable(null),
|
|
88
83
|
navigating: writable(null),
|
|
89
|
-
session,
|
|
90
84
|
updated
|
|
91
85
|
},
|
|
92
86
|
/** @type {import('types').Page} */
|
|
@@ -165,9 +159,6 @@ export async function render_response({
|
|
|
165
159
|
start({
|
|
166
160
|
target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
|
|
167
161
|
paths: ${s(options.paths)},
|
|
168
|
-
session: ${try_serialize($session, (error) => {
|
|
169
|
-
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
170
|
-
})},
|
|
171
162
|
route: ${!!page_config.router},
|
|
172
163
|
spa: ${!resolve_opts.ssr},
|
|
173
164
|
trailing_slash: ${s(options.trailing_slash)},
|
|
@@ -348,16 +339,3 @@ export async function render_response({
|
|
|
348
339
|
headers
|
|
349
340
|
});
|
|
350
341
|
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* @param {any} data
|
|
354
|
-
* @param {(error: Error) => void} [fail]
|
|
355
|
-
*/
|
|
356
|
-
function try_serialize(data, fail) {
|
|
357
|
-
try {
|
|
358
|
-
return devalue(data);
|
|
359
|
-
} catch (err) {
|
|
360
|
-
if (fail) fail(coalesce_to_error(err));
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
@@ -15,21 +15,12 @@ import { create_fetch } from './fetch.js';
|
|
|
15
15
|
* event: import('types').RequestEvent;
|
|
16
16
|
* options: SSROptions;
|
|
17
17
|
* state: SSRState;
|
|
18
|
-
* $session: any;
|
|
19
18
|
* status: number;
|
|
20
19
|
* error: Error;
|
|
21
20
|
* resolve_opts: import('types').RequiredResolveOptions;
|
|
22
21
|
* }} opts
|
|
23
22
|
*/
|
|
24
|
-
export async function respond_with_error({
|
|
25
|
-
event,
|
|
26
|
-
options,
|
|
27
|
-
state,
|
|
28
|
-
$session,
|
|
29
|
-
status,
|
|
30
|
-
error,
|
|
31
|
-
resolve_opts
|
|
32
|
-
}) {
|
|
23
|
+
export async function respond_with_error({ event, options, state, status, error, resolve_opts }) {
|
|
33
24
|
const { fetcher, fetched, cookies } = create_fetch({
|
|
34
25
|
event,
|
|
35
26
|
options,
|
|
@@ -52,11 +43,9 @@ export async function respond_with_error({
|
|
|
52
43
|
const server_data = await server_data_promise;
|
|
53
44
|
|
|
54
45
|
const data = await load_data({
|
|
55
|
-
$session,
|
|
56
46
|
event,
|
|
57
47
|
fetcher,
|
|
58
48
|
node: default_layout,
|
|
59
|
-
options,
|
|
60
49
|
parent: async () => ({}),
|
|
61
50
|
server_data_promise,
|
|
62
51
|
state
|
|
@@ -79,7 +68,6 @@ export async function respond_with_error({
|
|
|
79
68
|
return await render_response({
|
|
80
69
|
options,
|
|
81
70
|
state,
|
|
82
|
-
$session,
|
|
83
71
|
page_config: {
|
|
84
72
|
hydrate: options.hydrate,
|
|
85
73
|
router: options.router
|
|
@@ -110,7 +110,6 @@ export class Server {
|
|
|
110
110
|
if (!this.options.hooks) {
|
|
111
111
|
const module = await import(${s(hooks)});
|
|
112
112
|
this.options.hooks = {
|
|
113
|
-
getSession: module.getSession || (() => ({})),
|
|
114
113
|
handle: module.handle || (({ event, resolve }) => resolve(event)),
|
|
115
114
|
handleError: module.handleError || (({ error }) => console.error(error.stack)),
|
|
116
115
|
externalFetch: module.externalFetch || fetch
|
package/src/vite/dev/index.js
CHANGED
|
@@ -343,7 +343,6 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
|
343
343
|
|
|
344
344
|
/** @type {import('types').Hooks} */
|
|
345
345
|
const hooks = {
|
|
346
|
-
getSession: user_hooks.getSession || (() => ({})),
|
|
347
346
|
handle,
|
|
348
347
|
handleError:
|
|
349
348
|
user_hooks.handleError ||
|
package/types/ambient.d.ts
CHANGED
|
@@ -12,12 +12,10 @@
|
|
|
12
12
|
* interface PrivateEnv {}
|
|
13
13
|
*
|
|
14
14
|
* interface PublicEnv {}
|
|
15
|
-
*
|
|
16
|
-
* interface Session {}
|
|
17
15
|
* }
|
|
18
16
|
* ```
|
|
19
17
|
*
|
|
20
|
-
* By populating these interfaces, you will gain type safety when using `env`, `event.locals
|
|
18
|
+
* By populating these interfaces, you will gain type safety when using `env`, `event.locals` and `event.platform`.
|
|
21
19
|
*
|
|
22
20
|
* Note that since it's an ambient declaration file, you have to be careful when using `import` statements. Once you add an `import`
|
|
23
21
|
* at the top level, the declaration file is no longer considered ambient and you lose access to these typings in other files.
|
|
@@ -45,7 +43,7 @@
|
|
|
45
43
|
*/
|
|
46
44
|
declare namespace App {
|
|
47
45
|
/**
|
|
48
|
-
* The interface that defines `event.locals`, which can be accessed in [hooks](https://kit.svelte.dev/docs/hooks) (`handle`, `handleError`
|
|
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.
|
|
49
47
|
*/
|
|
50
48
|
export interface Locals {}
|
|
51
49
|
|
|
@@ -63,11 +61,6 @@ declare namespace App {
|
|
|
63
61
|
* The interface that defines the dynamic environment variables exported from `$env/dynamic/public`.
|
|
64
62
|
*/
|
|
65
63
|
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
64
|
}
|
|
72
65
|
|
|
73
66
|
/**
|
|
@@ -220,15 +213,15 @@ declare module '$app/paths' {
|
|
|
220
213
|
|
|
221
214
|
/**
|
|
222
215
|
* ```ts
|
|
223
|
-
* import { getStores, navigating, page,
|
|
216
|
+
* import { getStores, navigating, page, updated } from '$app/stores';
|
|
224
217
|
* ```
|
|
225
218
|
*
|
|
226
|
-
* Stores are _contextual_ — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `
|
|
219
|
+
* Stores 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 on the server, rather than shared between multiple requests handled by the same server simultaneously.
|
|
227
220
|
*
|
|
228
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.
|
|
229
222
|
*/
|
|
230
223
|
declare module '$app/stores' {
|
|
231
|
-
import { Readable
|
|
224
|
+
import { Readable } from 'svelte/store';
|
|
232
225
|
import { Navigation, Page } from '@sveltejs/kit';
|
|
233
226
|
|
|
234
227
|
/**
|
|
@@ -238,7 +231,6 @@ declare module '$app/stores' {
|
|
|
238
231
|
export function getStores(): {
|
|
239
232
|
navigating: typeof navigating;
|
|
240
233
|
page: typeof page;
|
|
241
|
-
session: typeof session;
|
|
242
234
|
updated: typeof updated;
|
|
243
235
|
};
|
|
244
236
|
|
|
@@ -252,11 +244,6 @@ declare module '$app/stores' {
|
|
|
252
244
|
* When navigating finishes, its value reverts to `null`.
|
|
253
245
|
*/
|
|
254
246
|
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
247
|
/**
|
|
261
248
|
* 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
249
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -109,6 +109,7 @@ export interface Config {
|
|
|
109
109
|
extensions?: string[];
|
|
110
110
|
kit?: KitConfig;
|
|
111
111
|
preprocess?: any;
|
|
112
|
+
[key: string]: any;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
export interface KitConfig {
|
|
@@ -177,10 +178,6 @@ export interface ExternalFetch {
|
|
|
177
178
|
(req: Request): Promise<Response>;
|
|
178
179
|
}
|
|
179
180
|
|
|
180
|
-
export interface GetSession {
|
|
181
|
-
(event: RequestEvent): MaybePromise<App.Session>;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
181
|
export interface Handle {
|
|
185
182
|
(input: {
|
|
186
183
|
event: RequestEvent;
|
|
@@ -214,7 +211,6 @@ export interface LoadEvent<
|
|
|
214
211
|
params: Params;
|
|
215
212
|
data: Data;
|
|
216
213
|
routeId: string | null;
|
|
217
|
-
session: App.Session;
|
|
218
214
|
setHeaders: (headers: ResponseHeaders) => void;
|
|
219
215
|
url: URL;
|
|
220
216
|
parent: () => Promise<ParentData>;
|
package/types/internal.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
Config,
|
|
6
6
|
ExternalFetch,
|
|
7
7
|
ServerLoad,
|
|
8
|
-
GetSession,
|
|
9
8
|
Handle,
|
|
10
9
|
HandleError,
|
|
11
10
|
KitConfig,
|
|
@@ -92,7 +91,6 @@ export type GetParams = (match: RegExpExecArray) => Record<string, string>;
|
|
|
92
91
|
|
|
93
92
|
export interface Hooks {
|
|
94
93
|
externalFetch: ExternalFetch;
|
|
95
|
-
getSession: GetSession;
|
|
96
94
|
handle: Handle;
|
|
97
95
|
handleError: HandleError;
|
|
98
96
|
}
|