@sveltejs/kit 1.0.0-next.253 → 1.0.0-next.257
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/assets/app/stores.js +17 -2
- package/assets/client/start.js +59 -2
- package/assets/server/index.js +39 -20
- package/dist/chunks/index.js +3 -1
- package/dist/chunks/index3.js +10 -2
- package/dist/chunks/index5.js +2 -0
- package/dist/cli.js +9 -3
- package/package.json +1 -1
- package/types/ambient-modules.d.ts +16 -3
- package/types/config.d.ts +6 -3
- package/types/endpoint.d.ts +4 -10
- package/types/helper.d.ts +5 -8
- package/types/hooks.d.ts +10 -14
- package/types/internal.d.ts +3 -4
- package/types/page.d.ts +12 -65
package/assets/app/stores.js
CHANGED
|
@@ -33,7 +33,8 @@ const getStores = () => {
|
|
|
33
33
|
subscribe: stores.navigating.subscribe
|
|
34
34
|
};
|
|
35
35
|
},
|
|
36
|
-
session: stores.session
|
|
36
|
+
session: stores.session,
|
|
37
|
+
updated: stores.updated
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
|
|
@@ -79,4 +80,18 @@ const session = {
|
|
|
79
80
|
update: () => throw_error('update')
|
|
80
81
|
};
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
/** @type {typeof import('$app/stores').updated} */
|
|
84
|
+
const updated = {
|
|
85
|
+
subscribe(fn) {
|
|
86
|
+
const store = getStores().updated;
|
|
87
|
+
|
|
88
|
+
if (browser) {
|
|
89
|
+
updated.check = store.check;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return store.subscribe(fn);
|
|
93
|
+
},
|
|
94
|
+
check: () => throw_error('check')
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { getStores, navigating, page, session, stores, updated };
|
package/assets/client/start.js
CHANGED
|
@@ -3,8 +3,8 @@ import { fallback, routes } from '__GENERATED__/manifest.js';
|
|
|
3
3
|
import { onMount, tick } from 'svelte';
|
|
4
4
|
import { g as get_base_uri } from '../chunks/utils.js';
|
|
5
5
|
import { writable } from 'svelte/store';
|
|
6
|
+
import { base, set_paths } from '../paths.js';
|
|
6
7
|
import { init } from './singletons.js';
|
|
7
|
-
import { set_paths } from '../paths.js';
|
|
8
8
|
|
|
9
9
|
function scroll_state() {
|
|
10
10
|
return {
|
|
@@ -553,6 +553,56 @@ function notifiable_store(value) {
|
|
|
553
553
|
return { notify, set, subscribe };
|
|
554
554
|
}
|
|
555
555
|
|
|
556
|
+
function create_updated_store() {
|
|
557
|
+
const { set, subscribe } = writable(false);
|
|
558
|
+
|
|
559
|
+
const interval = +(
|
|
560
|
+
/** @type {string} */ (import.meta.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL)
|
|
561
|
+
);
|
|
562
|
+
const initial = import.meta.env.VITE_SVELTEKIT_APP_VERSION;
|
|
563
|
+
|
|
564
|
+
/** @type {NodeJS.Timeout} */
|
|
565
|
+
let timeout;
|
|
566
|
+
|
|
567
|
+
async function check() {
|
|
568
|
+
if (import.meta.env.DEV || import.meta.env.SSR) return false;
|
|
569
|
+
|
|
570
|
+
clearTimeout(timeout);
|
|
571
|
+
|
|
572
|
+
if (interval) timeout = setTimeout(check, interval);
|
|
573
|
+
|
|
574
|
+
const file = import.meta.env.VITE_SVELTEKIT_APP_VERSION_FILE;
|
|
575
|
+
|
|
576
|
+
const res = await fetch(`${base}/${file}`, {
|
|
577
|
+
headers: {
|
|
578
|
+
pragma: 'no-cache',
|
|
579
|
+
'cache-control': 'no-cache'
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
if (res.ok) {
|
|
584
|
+
const { version } = await res.json();
|
|
585
|
+
const updated = version !== initial;
|
|
586
|
+
|
|
587
|
+
if (updated) {
|
|
588
|
+
set(true);
|
|
589
|
+
clearTimeout(timeout);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return updated;
|
|
593
|
+
} else {
|
|
594
|
+
throw new Error(`Version check failed: ${res.status}`);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (interval) timeout = setTimeout(check, interval);
|
|
599
|
+
|
|
600
|
+
return {
|
|
601
|
+
subscribe,
|
|
602
|
+
check
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
556
606
|
/**
|
|
557
607
|
* @param {RequestInfo} resource
|
|
558
608
|
* @param {RequestInit} [opts]
|
|
@@ -622,7 +672,8 @@ class Renderer {
|
|
|
622
672
|
url: notifiable_store({}),
|
|
623
673
|
page: notifiable_store({}),
|
|
624
674
|
navigating: writable(/** @type {Navigating | null} */ (null)),
|
|
625
|
-
session: writable(session)
|
|
675
|
+
session: writable(session),
|
|
676
|
+
updated: create_updated_store()
|
|
626
677
|
};
|
|
627
678
|
|
|
628
679
|
this.$session = null;
|
|
@@ -788,6 +839,12 @@ class Renderer {
|
|
|
788
839
|
location.href = new URL(navigation_result.redirect, location.href).href;
|
|
789
840
|
}
|
|
790
841
|
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
} else if (navigation_result.props?.page?.status >= 400) {
|
|
845
|
+
const updated = await this.stores.updated.check();
|
|
846
|
+
if (updated) {
|
|
847
|
+
location.href = info.url.href;
|
|
791
848
|
return;
|
|
792
849
|
}
|
|
793
850
|
}
|
package/assets/server/index.js
CHANGED
|
@@ -413,6 +413,16 @@ function safe_not_equal(a, b) {
|
|
|
413
413
|
Promise.resolve();
|
|
414
414
|
|
|
415
415
|
const subscriber_queue = [];
|
|
416
|
+
/**
|
|
417
|
+
* Creates a `Readable` store that allows reading by subscription.
|
|
418
|
+
* @param value initial value
|
|
419
|
+
* @param {StartStopNotifier}start start and stop notifications for subscriptions
|
|
420
|
+
*/
|
|
421
|
+
function readable(value, start) {
|
|
422
|
+
return {
|
|
423
|
+
subscribe: writable(value, start).subscribe
|
|
424
|
+
};
|
|
425
|
+
}
|
|
416
426
|
/**
|
|
417
427
|
* Create a `Writable` store that allows both updating and reading by subscription.
|
|
418
428
|
* @param {*=}value initial value
|
|
@@ -1015,11 +1025,16 @@ class Csp {
|
|
|
1015
1025
|
|
|
1016
1026
|
// TODO rename this function/module
|
|
1017
1027
|
|
|
1028
|
+
const updated = {
|
|
1029
|
+
...readable(false),
|
|
1030
|
+
check: () => false
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1018
1033
|
/**
|
|
1019
1034
|
* @param {{
|
|
1020
1035
|
* branch: Array<import('./types').Loaded>;
|
|
1021
|
-
* options: import('types/internal').
|
|
1022
|
-
* state: import('types/internal').
|
|
1036
|
+
* options: import('types/internal').SSROptions;
|
|
1037
|
+
* state: import('types/internal').SSRState;
|
|
1023
1038
|
* $session: any;
|
|
1024
1039
|
* page_config: { hydrate: boolean, router: boolean };
|
|
1025
1040
|
* status: number;
|
|
@@ -1091,7 +1106,8 @@ async function render_response({
|
|
|
1091
1106
|
stores: {
|
|
1092
1107
|
page: writable(null),
|
|
1093
1108
|
navigating: writable(null),
|
|
1094
|
-
session
|
|
1109
|
+
session,
|
|
1110
|
+
updated
|
|
1095
1111
|
},
|
|
1096
1112
|
page: {
|
|
1097
1113
|
url: state.prerender ? create_prerendering_url_proxy(url) : url,
|
|
@@ -1152,11 +1168,13 @@ async function render_response({
|
|
|
1152
1168
|
needs_nonce: options.template_contains_nonce
|
|
1153
1169
|
});
|
|
1154
1170
|
|
|
1171
|
+
const target = hash(body);
|
|
1172
|
+
|
|
1155
1173
|
// prettier-ignore
|
|
1156
1174
|
const init_app = `
|
|
1157
1175
|
import { start } from ${s(options.prefix + options.manifest._.entry.file)};
|
|
1158
1176
|
start({
|
|
1159
|
-
target:
|
|
1177
|
+
target: document.querySelector('[data-hydrate="${target}"]').parentNode,
|
|
1160
1178
|
paths: ${s(options.paths)},
|
|
1161
1179
|
session: ${try_serialize($session, (error) => {
|
|
1162
1180
|
throw new Error(`Failed to serialize session data: ${error.message}`);
|
|
@@ -1234,7 +1252,7 @@ async function render_response({
|
|
|
1234
1252
|
.map((dep) => `\n\t<link rel="modulepreload" href="${options.prefix + dep}">`)
|
|
1235
1253
|
.join('');
|
|
1236
1254
|
|
|
1237
|
-
const attributes = ['type="module"'];
|
|
1255
|
+
const attributes = ['type="module"', `data-hydrate="${target}"`];
|
|
1238
1256
|
|
|
1239
1257
|
csp.add_script(init_app);
|
|
1240
1258
|
|
|
@@ -1242,7 +1260,7 @@ async function render_response({
|
|
|
1242
1260
|
attributes.push(`nonce="${csp.nonce}"`);
|
|
1243
1261
|
}
|
|
1244
1262
|
|
|
1245
|
-
|
|
1263
|
+
body += `\n\t\t<script ${attributes.join(' ')}>${init_app}</script>`;
|
|
1246
1264
|
|
|
1247
1265
|
// prettier-ignore
|
|
1248
1266
|
body += serialized_data
|
|
@@ -1252,7 +1270,7 @@ async function render_response({
|
|
|
1252
1270
|
|
|
1253
1271
|
return `<script ${attributes}>${json}</script>`;
|
|
1254
1272
|
})
|
|
1255
|
-
.join('\n\
|
|
1273
|
+
.join('\n\t');
|
|
1256
1274
|
}
|
|
1257
1275
|
|
|
1258
1276
|
if (options.service_worker) {
|
|
@@ -1449,8 +1467,8 @@ function is_root_relative(path) {
|
|
|
1449
1467
|
/**
|
|
1450
1468
|
* @param {{
|
|
1451
1469
|
* event: import('types/hooks').RequestEvent;
|
|
1452
|
-
* options: import('types/internal').
|
|
1453
|
-
* state: import('types/internal').
|
|
1470
|
+
* options: import('types/internal').SSROptions;
|
|
1471
|
+
* state: import('types/internal').SSRState;
|
|
1454
1472
|
* route: import('types/internal').SSRPage | null;
|
|
1455
1473
|
* url: URL;
|
|
1456
1474
|
* params: Record<string, string>;
|
|
@@ -1747,15 +1765,15 @@ async function load_node({
|
|
|
1747
1765
|
|
|
1748
1766
|
/**
|
|
1749
1767
|
* @typedef {import('./types.js').Loaded} Loaded
|
|
1750
|
-
* @typedef {import('types/internal').
|
|
1751
|
-
* @typedef {import('types/internal').
|
|
1768
|
+
* @typedef {import('types/internal').SSROptions} SSROptions
|
|
1769
|
+
* @typedef {import('types/internal').SSRState} SSRState
|
|
1752
1770
|
*/
|
|
1753
1771
|
|
|
1754
1772
|
/**
|
|
1755
1773
|
* @param {{
|
|
1756
1774
|
* event: import('types/hooks').RequestEvent;
|
|
1757
|
-
* options:
|
|
1758
|
-
* state:
|
|
1775
|
+
* options: SSROptions;
|
|
1776
|
+
* state: SSRState;
|
|
1759
1777
|
* $session: any;
|
|
1760
1778
|
* status: number;
|
|
1761
1779
|
* error: Error;
|
|
@@ -1832,15 +1850,15 @@ async function respond_with_error({ event, options, state, $session, status, err
|
|
|
1832
1850
|
/**
|
|
1833
1851
|
* @typedef {import('./types.js').Loaded} Loaded
|
|
1834
1852
|
* @typedef {import('types/internal').SSRNode} SSRNode
|
|
1835
|
-
* @typedef {import('types/internal').
|
|
1836
|
-
* @typedef {import('types/internal').
|
|
1853
|
+
* @typedef {import('types/internal').SSROptions} SSROptions
|
|
1854
|
+
* @typedef {import('types/internal').SSRState} SSRState
|
|
1837
1855
|
*/
|
|
1838
1856
|
|
|
1839
1857
|
/**
|
|
1840
1858
|
* @param {{
|
|
1841
1859
|
* event: import('types/hooks').RequestEvent;
|
|
1842
|
-
* options:
|
|
1843
|
-
* state:
|
|
1860
|
+
* options: SSROptions;
|
|
1861
|
+
* state: SSRState;
|
|
1844
1862
|
* $session: any;
|
|
1845
1863
|
* route: import('types/internal').SSRPage;
|
|
1846
1864
|
* params: Record<string, string>;
|
|
@@ -2065,7 +2083,7 @@ async function respond$1(opts) {
|
|
|
2065
2083
|
|
|
2066
2084
|
/**
|
|
2067
2085
|
* @param {import('types/internal').SSRComponent} leaf
|
|
2068
|
-
* @param {
|
|
2086
|
+
* @param {SSROptions} options
|
|
2069
2087
|
*/
|
|
2070
2088
|
function get_page_config(leaf, options) {
|
|
2071
2089
|
// TODO remove for 1.0
|
|
@@ -2098,8 +2116,8 @@ function with_cookies(response, set_cookie_headers) {
|
|
|
2098
2116
|
* @param {import('types/hooks').RequestEvent} event
|
|
2099
2117
|
* @param {import('types/internal').SSRPage} route
|
|
2100
2118
|
* @param {RegExpExecArray} match
|
|
2101
|
-
* @param {import('types/internal').
|
|
2102
|
-
* @param {import('types/internal').
|
|
2119
|
+
* @param {import('types/internal').SSROptions} options
|
|
2120
|
+
* @param {import('types/internal').SSRState} state
|
|
2103
2121
|
* @param {boolean} ssr
|
|
2104
2122
|
* @returns {Promise<Response | undefined>}
|
|
2105
2123
|
*/
|
|
@@ -2196,6 +2214,7 @@ async function respond(request, options, state = {}) {
|
|
|
2196
2214
|
request,
|
|
2197
2215
|
url,
|
|
2198
2216
|
params: {},
|
|
2217
|
+
// @ts-expect-error this picks up types that belong to the tests
|
|
2199
2218
|
locals: {},
|
|
2200
2219
|
platform: state.platform
|
|
2201
2220
|
};
|
package/dist/chunks/index.js
CHANGED
|
@@ -37,6 +37,8 @@ async function create_plugin(config, cwd) {
|
|
|
37
37
|
amp = (await import('./amp_hook.js')).handle;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = '0';
|
|
41
|
+
|
|
40
42
|
/** @type {import('types/internal').Respond} */
|
|
41
43
|
const respond = (await import(`${runtime}/server/index.js`)).respond;
|
|
42
44
|
|
|
@@ -183,6 +185,7 @@ async function create_plugin(config, cwd) {
|
|
|
183
185
|
|
|
184
186
|
/** @type {import('types/internal').Hooks} */
|
|
185
187
|
const hooks = {
|
|
188
|
+
// @ts-expect-error this picks up types that belong to the tests
|
|
186
189
|
getSession: user_hooks.getSession || (() => ({})),
|
|
187
190
|
handle: amp ? sequence(amp, handle) : handle,
|
|
188
191
|
handleError:
|
|
@@ -269,7 +272,6 @@ async function create_plugin(config, cwd) {
|
|
|
269
272
|
read: (file) => fs__default.readFileSync(path__default.join(config.kit.files.assets, file)),
|
|
270
273
|
root,
|
|
271
274
|
router: config.kit.browser.router,
|
|
272
|
-
target: config.kit.target,
|
|
273
275
|
template: ({ head, body, assets, nonce }) => {
|
|
274
276
|
return (
|
|
275
277
|
template
|
package/dist/chunks/index3.js
CHANGED
|
@@ -151,6 +151,10 @@ async function build_client({
|
|
|
151
151
|
output_dir,
|
|
152
152
|
client_entry_file
|
|
153
153
|
}) {
|
|
154
|
+
process.env.VITE_SVELTEKIT_APP_VERSION = config.kit.version.name;
|
|
155
|
+
process.env.VITE_SVELTEKIT_APP_VERSION_FILE = `${config.kit.appDir}/version.json`;
|
|
156
|
+
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = `${config.kit.version.pollInterval}`;
|
|
157
|
+
|
|
154
158
|
create_app({
|
|
155
159
|
manifest_data,
|
|
156
160
|
output: `${SVELTE_KIT}/generated`,
|
|
@@ -227,6 +231,11 @@ async function build_client({
|
|
|
227
231
|
const entry_css = new Set();
|
|
228
232
|
find_deps(entry, vite_manifest, entry_js, entry_css);
|
|
229
233
|
|
|
234
|
+
fs__default.writeFileSync(
|
|
235
|
+
`${client_out_dir}/version.json`,
|
|
236
|
+
JSON.stringify({ version: process.env.VITE_SVELTEKIT_APP_VERSION })
|
|
237
|
+
);
|
|
238
|
+
|
|
230
239
|
return {
|
|
231
240
|
assets,
|
|
232
241
|
chunks,
|
|
@@ -319,7 +328,6 @@ export class App {
|
|
|
319
328
|
root,
|
|
320
329
|
service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
|
|
321
330
|
router: ${s(config.kit.browser.router)},
|
|
322
|
-
target: ${s(config.kit.target)},
|
|
323
331
|
template,
|
|
324
332
|
template_contains_nonce: ${template.includes('%svelte.nonce%')},
|
|
325
333
|
trailing_slash: ${s(config.kit.trailingSlash)}
|
|
@@ -626,7 +634,7 @@ async function build(config) {
|
|
|
626
634
|
const build_data = {
|
|
627
635
|
app_dir: config.kit.appDir,
|
|
628
636
|
manifest_data: options.manifest_data,
|
|
629
|
-
service_worker: options.service_worker_entry_file ? '
|
|
637
|
+
service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
|
|
630
638
|
client,
|
|
631
639
|
server,
|
|
632
640
|
static: options.manifest_data.assets.map((asset) => posixify(asset.file)),
|
package/dist/chunks/index5.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -684,10 +684,16 @@ const options = object(
|
|
|
684
684
|
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'`
|
|
685
685
|
),
|
|
686
686
|
|
|
687
|
-
|
|
687
|
+
// TODO remove this for 1.0
|
|
688
|
+
target: error((keypath) => `${keypath} is no longer required, and should be removed`),
|
|
688
689
|
|
|
689
690
|
trailingSlash: list(['never', 'always', 'ignore']),
|
|
690
691
|
|
|
692
|
+
version: object({
|
|
693
|
+
name: string(Date.now().toString()),
|
|
694
|
+
pollInterval: number(0)
|
|
695
|
+
}),
|
|
696
|
+
|
|
691
697
|
vite: validate(
|
|
692
698
|
() => ({}),
|
|
693
699
|
(input, keypath) => {
|
|
@@ -989,7 +995,7 @@ async function launch(port, https) {
|
|
|
989
995
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
990
996
|
}
|
|
991
997
|
|
|
992
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
998
|
+
const prog = sade('svelte-kit').version('1.0.0-next.257');
|
|
993
999
|
|
|
994
1000
|
prog
|
|
995
1001
|
.command('dev')
|
|
@@ -1147,7 +1153,7 @@ async function check_port(port) {
|
|
|
1147
1153
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1148
1154
|
if (open) launch(port, https);
|
|
1149
1155
|
|
|
1150
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1156
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.257'}\n`));
|
|
1151
1157
|
|
|
1152
1158
|
const protocol = https ? 'https:' : 'http:';
|
|
1153
1159
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/package.json
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/* eslint-disable import/no-duplicates */
|
|
2
2
|
|
|
3
|
+
declare namespace App {
|
|
4
|
+
interface Locals {}
|
|
5
|
+
interface Platform {}
|
|
6
|
+
interface Session {}
|
|
7
|
+
interface Stuff {}
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
declare module '$app/env' {
|
|
4
11
|
/**
|
|
5
12
|
* Whether or not app is in AMP mode.
|
|
@@ -106,10 +113,11 @@ declare module '$app/stores' {
|
|
|
106
113
|
* A convenience function around `getContext` that returns `{ navigating, page, session }`.
|
|
107
114
|
* Most of the time, you won't need to use it.
|
|
108
115
|
*/
|
|
109
|
-
export function getStores
|
|
116
|
+
export function getStores(): {
|
|
110
117
|
navigating: typeof navigating;
|
|
111
118
|
page: typeof page;
|
|
112
|
-
session: Writable<Session>;
|
|
119
|
+
session: Writable<App.Session>;
|
|
120
|
+
updated: typeof updated;
|
|
113
121
|
};
|
|
114
122
|
/**
|
|
115
123
|
* A readable store whose value contains page data.
|
|
@@ -131,7 +139,12 @@ declare module '$app/stores' {
|
|
|
131
139
|
* A writable store whose initial value is whatever was returned from `getSession`.
|
|
132
140
|
* It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
|
|
133
141
|
*/
|
|
134
|
-
export const session: Writable<
|
|
142
|
+
export const session: Writable<App.Session>;
|
|
143
|
+
/**
|
|
144
|
+
* A writable store indicating if the site was updated since the store was created.
|
|
145
|
+
* It can be written to when custom logic is required to detect updates.
|
|
146
|
+
*/
|
|
147
|
+
export const updated: Readable<boolean> & { check: () => boolean };
|
|
135
148
|
}
|
|
136
149
|
|
|
137
150
|
declare module '$service-worker' {
|
package/types/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CompileOptions } from 'svelte/types/compiler/interfaces';
|
|
2
2
|
import { UserConfig as ViteConfig } from 'vite';
|
|
3
3
|
import { CspDirectives } from './csp';
|
|
4
|
-
import { RecursiveRequired } from './helper';
|
|
4
|
+
import { MaybePromise, RecursiveRequired } from './helper';
|
|
5
5
|
import { HttpMethod, Logger, RouteSegment, TrailingSlash } from './internal';
|
|
6
6
|
|
|
7
7
|
export interface RouteDefinition {
|
|
@@ -163,9 +163,12 @@ export interface Config {
|
|
|
163
163
|
register?: boolean;
|
|
164
164
|
files?: (filepath: string) => boolean;
|
|
165
165
|
};
|
|
166
|
-
target?: string;
|
|
167
166
|
trailingSlash?: TrailingSlash;
|
|
168
|
-
|
|
167
|
+
version?: {
|
|
168
|
+
name?: string;
|
|
169
|
+
pollInterval?: number;
|
|
170
|
+
};
|
|
171
|
+
vite?: ViteConfig | (() => MaybePromise<ViteConfig>);
|
|
169
172
|
};
|
|
170
173
|
preprocess?: any;
|
|
171
174
|
}
|
package/types/endpoint.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RequestEvent } from './hooks';
|
|
2
|
-
import { Either,
|
|
2
|
+
import { Either, JSONValue, MaybePromise, ResponseHeaders } from './helper';
|
|
3
3
|
|
|
4
|
-
type Body =
|
|
4
|
+
type Body = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
|
|
5
5
|
|
|
6
6
|
export interface EndpointOutput<Output extends Body = Body> {
|
|
7
7
|
status?: number;
|
|
@@ -13,12 +13,6 @@ export interface Fallthrough {
|
|
|
13
13
|
fallthrough: true;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export interface RequestHandler<
|
|
17
|
-
|
|
18
|
-
Platform = Record<string, any>,
|
|
19
|
-
Output extends Body = Body
|
|
20
|
-
> {
|
|
21
|
-
(event: RequestEvent<Locals, Platform>): MaybePromise<
|
|
22
|
-
Either<Response | EndpointOutput<Output>, Fallthrough>
|
|
23
|
-
>;
|
|
16
|
+
export interface RequestHandler<Output extends Body = Body> {
|
|
17
|
+
(event: RequestEvent): MaybePromise<Either<Response | EndpointOutput<Output>, Fallthrough>>;
|
|
24
18
|
}
|
package/types/helper.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
type ToJSON = { toJSON(...args: any[]): JSONValue };
|
|
2
|
-
|
|
3
|
-
export type
|
|
1
|
+
type ToJSON = { toJSON(...args: any[]): Exclude<JSONValue, ToJSON> };
|
|
2
|
+
|
|
3
|
+
export type JSONValue =
|
|
4
4
|
| string
|
|
5
5
|
| number
|
|
6
6
|
| boolean
|
|
7
7
|
| null
|
|
8
8
|
| ToJSON
|
|
9
|
-
|
|
|
10
|
-
| { [key: string]:
|
|
9
|
+
| JSONValue[]
|
|
10
|
+
| { [key: string]: JSONValue };
|
|
11
11
|
|
|
12
12
|
/** `string[]` is only for set-cookie, everything else must be type of `string` */
|
|
13
13
|
export type ResponseHeaders = Record<string, string | string[]>;
|
|
@@ -16,9 +16,6 @@ export type ResponseHeaders = Record<string, string | string[]>;
|
|
|
16
16
|
type Only<T, U> = { [P in keyof T]: T[P] } & { [P in Exclude<keyof U, keyof T>]?: never };
|
|
17
17
|
|
|
18
18
|
export type Either<T, U> = Only<T, U> | Only<U, T>;
|
|
19
|
-
export type InferValue<T, Key extends keyof T, Default> = T extends Record<Key, infer Val>
|
|
20
|
-
? Val
|
|
21
|
-
: Default;
|
|
22
19
|
export type MaybePromise<T> = T | Promise<T>;
|
|
23
20
|
export type RecursiveRequired<T> = {
|
|
24
21
|
// Recursive implementation of TypeScript's Required utility type.
|
package/types/hooks.d.ts
CHANGED
|
@@ -2,35 +2,31 @@ import { MaybePromise } from './helper';
|
|
|
2
2
|
|
|
3
3
|
export type StrictBody = string | Uint8Array;
|
|
4
4
|
|
|
5
|
-
export interface RequestEvent
|
|
5
|
+
export interface RequestEvent {
|
|
6
6
|
request: Request;
|
|
7
7
|
url: URL;
|
|
8
8
|
params: Record<string, string>;
|
|
9
|
-
locals: Locals;
|
|
10
|
-
platform: Readonly<Platform>;
|
|
9
|
+
locals: App.Locals;
|
|
10
|
+
platform: Readonly<App.Platform>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export interface GetSession
|
|
14
|
-
|
|
15
|
-
Platform = Record<string, any>,
|
|
16
|
-
Session = any
|
|
17
|
-
> {
|
|
18
|
-
(event: RequestEvent<Locals, Platform>): MaybePromise<Session>;
|
|
13
|
+
export interface GetSession {
|
|
14
|
+
(event: RequestEvent): MaybePromise<App.Session>;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
17
|
export interface ResolveOpts {
|
|
22
18
|
ssr?: boolean;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
export interface Handle
|
|
21
|
+
export interface Handle {
|
|
26
22
|
(input: {
|
|
27
|
-
event: RequestEvent
|
|
28
|
-
resolve(event: RequestEvent
|
|
23
|
+
event: RequestEvent;
|
|
24
|
+
resolve(event: RequestEvent, opts?: ResolveOpts): MaybePromise<Response>;
|
|
29
25
|
}): MaybePromise<Response>;
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
export interface HandleError
|
|
33
|
-
(input: { error: Error & { frame?: string }; event: RequestEvent
|
|
28
|
+
export interface HandleError {
|
|
29
|
+
(input: { error: Error & { frame?: string }; event: RequestEvent }): void;
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
export interface ExternalFetch {
|
package/types/internal.d.ts
CHANGED
|
@@ -119,7 +119,7 @@ export interface SSRNode {
|
|
|
119
119
|
styles?: Record<string, string>;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
export interface
|
|
122
|
+
export interface SSROptions {
|
|
123
123
|
amp: boolean;
|
|
124
124
|
csp: ValidatedConfig['kit']['csp'];
|
|
125
125
|
dev: boolean;
|
|
@@ -140,7 +140,6 @@ export interface SSRRenderOptions {
|
|
|
140
140
|
root: SSRComponent['default'];
|
|
141
141
|
router: boolean;
|
|
142
142
|
service_worker?: string;
|
|
143
|
-
target: string;
|
|
144
143
|
template({
|
|
145
144
|
head,
|
|
146
145
|
body,
|
|
@@ -156,7 +155,7 @@ export interface SSRRenderOptions {
|
|
|
156
155
|
trailing_slash: TrailingSlash;
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
export interface
|
|
158
|
+
export interface SSRState {
|
|
160
159
|
fetched?: string;
|
|
161
160
|
initiator?: SSRPage | null;
|
|
162
161
|
platform?: any;
|
|
@@ -248,5 +247,5 @@ export interface MethodOverride {
|
|
|
248
247
|
}
|
|
249
248
|
|
|
250
249
|
export interface Respond {
|
|
251
|
-
(request: Request, options:
|
|
250
|
+
(request: Request, options: SSROptions, state?: SSRState): Promise<Response>;
|
|
252
251
|
}
|
package/types/page.d.ts
CHANGED
|
@@ -1,85 +1,32 @@
|
|
|
1
1
|
import { Fallthrough } from './endpoint';
|
|
2
|
-
import { Either,
|
|
2
|
+
import { Either, MaybePromise } from './helper';
|
|
3
3
|
|
|
4
|
-
export interface LoadInput<
|
|
5
|
-
PageParams extends Record<string, string> = Record<string, string>,
|
|
6
|
-
Stuff extends Record<string, any> = Record<string, any>,
|
|
7
|
-
Session = any
|
|
8
|
-
> {
|
|
4
|
+
export interface LoadInput<Params = Record<string, string>> {
|
|
9
5
|
url: URL;
|
|
10
|
-
params:
|
|
6
|
+
params: Params;
|
|
11
7
|
fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
12
|
-
session: Session;
|
|
13
|
-
stuff: Stuff
|
|
8
|
+
session: App.Session;
|
|
9
|
+
stuff: Partial<App.Stuff>;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export interface ErrorLoadInput<
|
|
17
|
-
PageParams extends Record<string, string> = Record<string, string>,
|
|
18
|
-
Stuff extends Record<string, any> = Record<string, any>,
|
|
19
|
-
Session = any
|
|
20
|
-
> extends LoadInput<PageParams, Stuff, Session> {
|
|
12
|
+
export interface ErrorLoadInput<Params = Record<string, string>> extends LoadInput<Params> {
|
|
21
13
|
status?: number;
|
|
22
14
|
error?: Error;
|
|
23
15
|
}
|
|
24
16
|
|
|
25
|
-
export interface LoadOutput<
|
|
26
|
-
Props extends Record<string, any> = Record<string, any>,
|
|
27
|
-
Stuff extends Record<string, any> = Record<string, any>
|
|
28
|
-
> {
|
|
17
|
+
export interface LoadOutput<Props = Record<string, any>> {
|
|
29
18
|
status?: number;
|
|
30
19
|
error?: string | Error;
|
|
31
20
|
redirect?: string;
|
|
32
21
|
props?: Props;
|
|
33
|
-
stuff?: Stuff
|
|
22
|
+
stuff?: Partial<App.Stuff>;
|
|
34
23
|
maxage?: number;
|
|
35
24
|
}
|
|
36
25
|
|
|
37
|
-
interface
|
|
38
|
-
|
|
39
|
-
pageParams?: Record<string, string>;
|
|
40
|
-
session?: any;
|
|
26
|
+
export interface Load<Params = Record<string, string>, Props = Record<string, any>> {
|
|
27
|
+
(input: LoadInput<Params>): MaybePromise<Either<Fallthrough, LoadOutput<Props>>>;
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
interface
|
|
44
|
-
|
|
45
|
-
props?: Record<string, any>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface Load<
|
|
49
|
-
Input extends LoadInputExtends = Required<LoadInputExtends>,
|
|
50
|
-
Output extends LoadOutputExtends = Required<LoadOutputExtends>
|
|
51
|
-
> {
|
|
52
|
-
(
|
|
53
|
-
input: LoadInput<
|
|
54
|
-
InferValue<Input, 'pageParams', Record<string, string>>,
|
|
55
|
-
InferValue<Input, 'stuff', Record<string, any>>,
|
|
56
|
-
InferValue<Input, 'session', any>
|
|
57
|
-
>
|
|
58
|
-
): MaybePromise<
|
|
59
|
-
Either<
|
|
60
|
-
Fallthrough,
|
|
61
|
-
LoadOutput<
|
|
62
|
-
InferValue<Output, 'props', Record<string, any>>,
|
|
63
|
-
InferValue<Output, 'stuff', Record<string, any>>
|
|
64
|
-
>
|
|
65
|
-
>
|
|
66
|
-
>;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface ErrorLoad<
|
|
70
|
-
Input extends LoadInputExtends = Required<LoadInputExtends>,
|
|
71
|
-
Output extends LoadOutputExtends = Required<LoadOutputExtends>
|
|
72
|
-
> {
|
|
73
|
-
(
|
|
74
|
-
input: ErrorLoadInput<
|
|
75
|
-
InferValue<Input, 'pageParams', Record<string, string>>,
|
|
76
|
-
InferValue<Input, 'stuff', Record<string, any>>,
|
|
77
|
-
InferValue<Input, 'session', any>
|
|
78
|
-
>
|
|
79
|
-
): MaybePromise<
|
|
80
|
-
LoadOutput<
|
|
81
|
-
InferValue<Output, 'props', Record<string, any>>,
|
|
82
|
-
InferValue<Output, 'stuff', Record<string, any>>
|
|
83
|
-
>
|
|
84
|
-
>;
|
|
30
|
+
export interface ErrorLoad<Params = Record<string, string>, Props = Record<string, any>> {
|
|
31
|
+
(input: ErrorLoadInput<Params>): MaybePromise<LoadOutput<Props>>;
|
|
85
32
|
}
|