@sveltejs/kit 1.0.0-next.233 → 1.0.0-next.234
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/server/index.js +261 -441
- package/dist/chunks/{build.js → http.js} +23 -1
- package/dist/chunks/index.js +266 -437
- package/dist/chunks/index3.js +15 -20
- package/dist/chunks/index5.js +24 -39
- package/dist/chunks/index6.js +16 -13
- package/dist/chunks/url.js +1 -23
- package/dist/cli.js +28 -7
- package/dist/hooks.js +8 -8
- package/dist/node.js +27 -1
- package/package.json +1 -1
- package/types/ambient-modules.d.ts +9 -14
- package/types/app.d.ts +3 -17
- package/types/config.d.ts +0 -6
- package/types/endpoint.d.ts +4 -5
- package/types/helper.d.ts +0 -1
- package/types/hooks.d.ts +15 -28
- package/types/index.d.ts +2 -10
- package/types/internal.d.ts +9 -10
package/dist/chunks/index3.js
CHANGED
|
@@ -268,7 +268,7 @@ set_paths(${s(config.kit.paths)});
|
|
|
268
268
|
// named imports without triggering Rollup's missing import detection
|
|
269
269
|
const get_hooks = hooks => ({
|
|
270
270
|
getSession: hooks.getSession || (() => ({})),
|
|
271
|
-
handle: hooks.handle || (({
|
|
271
|
+
handle: hooks.handle || (({ event, resolve }) => resolve(event)),
|
|
272
272
|
handleError: hooks.handleError || (({ error }) => console.error(error.stack)),
|
|
273
273
|
externalFetch: hooks.externalFetch || fetch
|
|
274
274
|
});
|
|
@@ -293,8 +293,17 @@ export class App {
|
|
|
293
293
|
dev: false,
|
|
294
294
|
floc: ${config.kit.floc},
|
|
295
295
|
get_stack: error => String(error), // for security
|
|
296
|
-
handle_error: (error,
|
|
297
|
-
hooks.handleError({
|
|
296
|
+
handle_error: (error, event) => {
|
|
297
|
+
hooks.handleError({
|
|
298
|
+
error,
|
|
299
|
+
event,
|
|
300
|
+
|
|
301
|
+
// TODO remove for 1.0
|
|
302
|
+
// @ts-expect-error
|
|
303
|
+
get request() {
|
|
304
|
+
throw new Error('request in handleError has been replaced with event. See https://github.com/sveltejs/kit/pull/3384 for details');
|
|
305
|
+
}
|
|
306
|
+
});
|
|
298
307
|
error.stack = this.options.get_stack(error);
|
|
299
308
|
},
|
|
300
309
|
hooks,
|
|
@@ -317,25 +326,11 @@ export class App {
|
|
|
317
326
|
render(request, {
|
|
318
327
|
prerender
|
|
319
328
|
} = {}) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
throw new Error('Adapters should call app.render({ url, method, headers, rawBody })');
|
|
329
|
+
if (!(request instanceof Request)) {
|
|
330
|
+
throw new Error('The first argument to app.render must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
|
|
323
331
|
}
|
|
324
332
|
|
|
325
|
-
|
|
326
|
-
config.kit.host
|
|
327
|
-
? s(config.kit.host)
|
|
328
|
-
: `request.headers[${s(config.kit.headers.host || 'host')}]`
|
|
329
|
-
};
|
|
330
|
-
const protocol = ${
|
|
331
|
-
config.kit.protocol
|
|
332
|
-
? s(config.kit.protocol)
|
|
333
|
-
: config.kit.headers.protocol
|
|
334
|
-
? `request.headers[${s(config.kit.headers.protocol)}] || default_protocol`
|
|
335
|
-
: 'default_protocol'
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
return respond({ ...request, url: new URL(request.url, protocol + '://' + host) }, this.options, { prerender });
|
|
333
|
+
return respond(request, this.options, { prerender });
|
|
339
334
|
}
|
|
340
335
|
}
|
|
341
336
|
`;
|
package/dist/chunks/index5.js
CHANGED
|
@@ -3,7 +3,7 @@ import { readFileSync, writeFileSync } from 'fs';
|
|
|
3
3
|
import { resolve, join, dirname } from 'path';
|
|
4
4
|
import { pathToFileURL, URL } from 'url';
|
|
5
5
|
import { __fetch_polyfill } from '../install-fetch.js';
|
|
6
|
-
import {
|
|
6
|
+
import { r as resolve$1, i as is_root_relative } from './url.js';
|
|
7
7
|
import { g as generate_manifest } from './index4.js';
|
|
8
8
|
import 'sade';
|
|
9
9
|
import 'child_process';
|
|
@@ -412,28 +412,19 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
|
|
|
412
412
|
* @param {string?} referrer
|
|
413
413
|
*/
|
|
414
414
|
async function visit(path, decoded_path, referrer) {
|
|
415
|
-
/** @type {Map<string,
|
|
415
|
+
/** @type {Map<string, Response>} */
|
|
416
416
|
const dependencies = new Map();
|
|
417
417
|
|
|
418
|
-
const rendered = await app.render(
|
|
419
|
-
{
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
headers: {},
|
|
423
|
-
rawBody: null
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
prerender: {
|
|
427
|
-
all,
|
|
428
|
-
dependencies
|
|
429
|
-
}
|
|
418
|
+
const rendered = await app.render(new Request(`http://sveltekit-prerender${path}`), {
|
|
419
|
+
prerender: {
|
|
420
|
+
all,
|
|
421
|
+
dependencies
|
|
430
422
|
}
|
|
431
|
-
);
|
|
423
|
+
});
|
|
432
424
|
|
|
433
425
|
if (rendered) {
|
|
434
426
|
const response_type = Math.floor(rendered.status / 100);
|
|
435
|
-
const
|
|
436
|
-
const type = headers && headers['content-type'];
|
|
427
|
+
const type = rendered.headers.get('content-type');
|
|
437
428
|
const is_html = response_type === REDIRECT || type === 'text/html';
|
|
438
429
|
|
|
439
430
|
const parts = decoded_path.split('/');
|
|
@@ -444,7 +435,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
|
|
|
444
435
|
const file = `${out}${parts.join('/')}`;
|
|
445
436
|
|
|
446
437
|
if (response_type === REDIRECT) {
|
|
447
|
-
const location =
|
|
438
|
+
const location = rendered.headers.get('location');
|
|
448
439
|
|
|
449
440
|
if (location) {
|
|
450
441
|
mkdirp(dirname(file));
|
|
@@ -463,20 +454,22 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
|
|
|
463
454
|
return;
|
|
464
455
|
}
|
|
465
456
|
|
|
457
|
+
const text = await rendered.text();
|
|
458
|
+
|
|
466
459
|
if (rendered.status === 200) {
|
|
467
460
|
mkdirp(dirname(file));
|
|
468
461
|
|
|
469
462
|
log.info(`${rendered.status} ${decoded_path}`);
|
|
470
|
-
writeFileSync(file,
|
|
463
|
+
writeFileSync(file, text);
|
|
471
464
|
paths.push(normalize(decoded_path));
|
|
472
465
|
} else if (response_type !== OK) {
|
|
473
466
|
error({ status: rendered.status, path, referrer, referenceType: 'linked' });
|
|
474
467
|
}
|
|
475
468
|
|
|
476
|
-
|
|
469
|
+
for (const [dependency_path, result] of dependencies) {
|
|
477
470
|
const response_type = Math.floor(result.status / 100);
|
|
478
471
|
|
|
479
|
-
const is_html = result.headers
|
|
472
|
+
const is_html = result.headers.get('content-type') === 'text/html';
|
|
480
473
|
|
|
481
474
|
const parts = dependency_path.split('/');
|
|
482
475
|
if (is_html && parts[parts.length - 1] !== 'index.html') {
|
|
@@ -487,7 +480,7 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
|
|
|
487
480
|
mkdirp(dirname(file));
|
|
488
481
|
|
|
489
482
|
if (result.body) {
|
|
490
|
-
writeFileSync(file, result.
|
|
483
|
+
writeFileSync(file, await result.text());
|
|
491
484
|
paths.push(dependency_path);
|
|
492
485
|
}
|
|
493
486
|
|
|
@@ -501,10 +494,10 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
|
|
|
501
494
|
referenceType: 'fetched'
|
|
502
495
|
});
|
|
503
496
|
}
|
|
504
|
-
}
|
|
497
|
+
}
|
|
505
498
|
|
|
506
499
|
if (is_html && config.kit.prerender.crawl) {
|
|
507
|
-
for (const href of crawl(
|
|
500
|
+
for (const href of crawl(text)) {
|
|
508
501
|
if (href.startsWith('data:') || href.startsWith('#')) continue;
|
|
509
502
|
|
|
510
503
|
const resolved = resolve$1(path, href);
|
|
@@ -545,25 +538,17 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
|
|
|
545
538
|
}
|
|
546
539
|
|
|
547
540
|
if (fallback) {
|
|
548
|
-
const rendered = await app.render(
|
|
549
|
-
{
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
rawBody: null
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
prerender: {
|
|
557
|
-
fallback,
|
|
558
|
-
all: false,
|
|
559
|
-
dependencies: new Map()
|
|
560
|
-
}
|
|
541
|
+
const rendered = await app.render(new Request('http://sveltekit-prerender/[fallback]'), {
|
|
542
|
+
prerender: {
|
|
543
|
+
fallback,
|
|
544
|
+
all: false,
|
|
545
|
+
dependencies: new Map()
|
|
561
546
|
}
|
|
562
|
-
);
|
|
547
|
+
});
|
|
563
548
|
|
|
564
549
|
const file = join(out, fallback);
|
|
565
550
|
mkdirp(dirname(file));
|
|
566
|
-
writeFileSync(file, rendered.
|
|
551
|
+
writeFileSync(file, await rendered.text());
|
|
567
552
|
}
|
|
568
553
|
|
|
569
554
|
return {
|
package/dist/chunks/index6.js
CHANGED
|
@@ -2,12 +2,13 @@ import fs__default from 'fs';
|
|
|
2
2
|
import http from 'http';
|
|
3
3
|
import https from 'https';
|
|
4
4
|
import { resolve, join } from 'path';
|
|
5
|
-
import { s as sirv } from './
|
|
5
|
+
import { s as sirv, t as to_headers } from './http.js';
|
|
6
6
|
import { pathToFileURL } from 'url';
|
|
7
7
|
import { getRawBody } from '../node.js';
|
|
8
8
|
import { __fetch_polyfill } from '../install-fetch.js';
|
|
9
9
|
import { a as SVELTE_KIT, S as SVELTE_KIT_ASSETS } from '../cli.js';
|
|
10
10
|
import 'querystring';
|
|
11
|
+
import 'stream';
|
|
11
12
|
import 'node:http';
|
|
12
13
|
import 'node:https';
|
|
13
14
|
import 'node:zlib';
|
|
@@ -101,18 +102,20 @@ async function preview({
|
|
|
101
102
|
return res.end(err.reason || 'Invalid request body');
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
105
|
+
if (initial_url.startsWith(config.kit.paths.base)) {
|
|
106
|
+
const protocol = use_https ? 'https' : 'http';
|
|
107
|
+
const host = req.headers['host'];
|
|
108
|
+
|
|
109
|
+
const rendered = await app.render(
|
|
110
|
+
new Request(`${protocol}://${host}${initial_url}`, {
|
|
111
|
+
method: req.method,
|
|
112
|
+
headers: to_headers(req.headers),
|
|
113
|
+
body
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
res.writeHead(rendered.status, Object.fromEntries(rendered.headers));
|
|
118
|
+
if (rendered.body) res.write(new Uint8Array(await rendered.arrayBuffer()));
|
|
116
119
|
res.end();
|
|
117
120
|
} else {
|
|
118
121
|
res.statusCode = 404;
|
package/dist/chunks/url.js
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {Record<string, string | string[] | undefined>} headers
|
|
3
|
-
* @param {string} key
|
|
4
|
-
* @returns {string | undefined}
|
|
5
|
-
* @throws {Error}
|
|
6
|
-
*/
|
|
7
|
-
function get_single_valued_header(headers, key) {
|
|
8
|
-
const value = headers[key];
|
|
9
|
-
if (Array.isArray(value)) {
|
|
10
|
-
if (value.length === 0) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
if (value.length > 1) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
`Multiple headers provided for ${key}. Multiple may be provided only for set-cookie`
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
return value[0];
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
1
|
const absolute = /^([a-z]+:)?\/?\//;
|
|
24
2
|
const scheme = /^[a-z]+:/;
|
|
25
3
|
|
|
@@ -59,4 +37,4 @@ function is_root_relative(path) {
|
|
|
59
37
|
return path[0] === '/' && path[1] !== '/';
|
|
60
38
|
}
|
|
61
39
|
|
|
62
|
-
export {
|
|
40
|
+
export { is_root_relative as i, resolve as r };
|
package/dist/cli.js
CHANGED
|
@@ -501,12 +501,23 @@ const options = object(
|
|
|
501
501
|
|
|
502
502
|
floc: boolean(false),
|
|
503
503
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
504
|
+
// TODO: remove this for the 1.0 release
|
|
505
|
+
headers: validate(undefined, (input, keypath) => {
|
|
506
|
+
if (typeof input !== undefined) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
509
|
+
);
|
|
510
|
+
}
|
|
507
511
|
}),
|
|
508
512
|
|
|
509
|
-
|
|
513
|
+
// TODO: remove this for the 1.0 release
|
|
514
|
+
host: validate(undefined, (input, keypath) => {
|
|
515
|
+
if (typeof input !== undefined) {
|
|
516
|
+
throw new Error(
|
|
517
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
}),
|
|
510
521
|
|
|
511
522
|
hydrate: boolean(true),
|
|
512
523
|
|
|
@@ -587,6 +598,7 @@ const options = object(
|
|
|
587
598
|
|
|
588
599
|
return input;
|
|
589
600
|
}),
|
|
601
|
+
|
|
590
602
|
// TODO: remove this for the 1.0 release
|
|
591
603
|
force: validate(undefined, (input, keypath) => {
|
|
592
604
|
if (typeof input !== undefined) {
|
|
@@ -599,6 +611,7 @@ const options = object(
|
|
|
599
611
|
);
|
|
600
612
|
}
|
|
601
613
|
}),
|
|
614
|
+
|
|
602
615
|
onError: validate('fail', (input, keypath) => {
|
|
603
616
|
if (typeof input === 'function') return input;
|
|
604
617
|
if (['continue', 'fail'].includes(input)) return input;
|
|
@@ -606,6 +619,7 @@ const options = object(
|
|
|
606
619
|
`${keypath} should be either a custom function or one of "continue" or "fail"`
|
|
607
620
|
);
|
|
608
621
|
}),
|
|
622
|
+
|
|
609
623
|
// TODO: remove this for the 1.0 release
|
|
610
624
|
pages: validate(undefined, (input, keypath) => {
|
|
611
625
|
if (typeof input !== undefined) {
|
|
@@ -614,7 +628,14 @@ const options = object(
|
|
|
614
628
|
})
|
|
615
629
|
}),
|
|
616
630
|
|
|
617
|
-
|
|
631
|
+
// TODO: remove this for the 1.0 release
|
|
632
|
+
protocol: validate(undefined, (input, keypath) => {
|
|
633
|
+
if (typeof input !== undefined) {
|
|
634
|
+
throw new Error(
|
|
635
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
}),
|
|
618
639
|
|
|
619
640
|
router: boolean(true),
|
|
620
641
|
|
|
@@ -912,7 +933,7 @@ async function launch(port, https) {
|
|
|
912
933
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
913
934
|
}
|
|
914
935
|
|
|
915
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
936
|
+
const prog = sade('svelte-kit').version('1.0.0-next.234');
|
|
916
937
|
|
|
917
938
|
prog
|
|
918
939
|
.command('dev')
|
|
@@ -1064,7 +1085,7 @@ async function check_port(port) {
|
|
|
1064
1085
|
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1065
1086
|
if (open) launch(port, https);
|
|
1066
1087
|
|
|
1067
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1088
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.234'}\n`));
|
|
1068
1089
|
|
|
1069
1090
|
const protocol = https ? 'https:' : 'http:';
|
|
1070
1091
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
package/dist/hooks.js
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
*/
|
|
5
5
|
function sequence(...handlers) {
|
|
6
6
|
const length = handlers.length;
|
|
7
|
-
if (!length) return ({
|
|
7
|
+
if (!length) return ({ event, resolve }) => resolve(event);
|
|
8
8
|
|
|
9
|
-
return ({
|
|
10
|
-
return apply_handle(0,
|
|
9
|
+
return ({ event, resolve }) => {
|
|
10
|
+
return apply_handle(0, event);
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @param {number} i
|
|
14
|
-
* @param {import('types/hooks').
|
|
15
|
-
* @returns {import('types/helper').MaybePromise<
|
|
14
|
+
* @param {import('types/hooks').RequestEvent} event
|
|
15
|
+
* @returns {import('types/helper').MaybePromise<Response>}
|
|
16
16
|
*/
|
|
17
|
-
function apply_handle(i,
|
|
17
|
+
function apply_handle(i, event) {
|
|
18
18
|
const handle = handlers[i];
|
|
19
19
|
|
|
20
20
|
return handle({
|
|
21
|
-
|
|
22
|
-
resolve: i < length - 1 ? (
|
|
21
|
+
event,
|
|
22
|
+
resolve: i < length - 1 ? (event) => apply_handle(i + 1, event) : resolve
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
};
|
package/dist/node.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
|
|
1
3
|
/** @type {import('@sveltejs/kit/node').GetRawBody} */
|
|
2
4
|
function getRawBody(req) {
|
|
3
5
|
return new Promise((fulfil, reject) => {
|
|
@@ -48,4 +50,28 @@ function getRawBody(req) {
|
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
/** @type {import('@sveltejs/kit/node').GetRequest} */
|
|
54
|
+
async function getRequest(base, req) {
|
|
55
|
+
return new Request(base + req.url, {
|
|
56
|
+
method: req.method,
|
|
57
|
+
headers: /** @type {Record<string, string>} */ (req.headers),
|
|
58
|
+
body: await getRawBody(req)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @type {import('@sveltejs/kit/node').SetResponse} */
|
|
63
|
+
async function setResponse(res, response) {
|
|
64
|
+
res.writeHead(response.status, Object.fromEntries(response.headers));
|
|
65
|
+
|
|
66
|
+
if (response.body instanceof Readable) {
|
|
67
|
+
response.body.pipe(res);
|
|
68
|
+
} else {
|
|
69
|
+
if (response.body) {
|
|
70
|
+
res.write(await response.arrayBuffer());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
res.end();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { getRawBody, getRequest, setResponse };
|
package/package.json
CHANGED
|
@@ -174,27 +174,22 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
declare module '@sveltejs/kit/node' {
|
|
177
|
-
import { IncomingMessage } from 'http';
|
|
178
|
-
import { RawBody } from '@sveltejs/kit';
|
|
177
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
179
178
|
|
|
180
179
|
export interface GetRawBody {
|
|
181
|
-
(request: IncomingMessage): Promise<
|
|
180
|
+
(request: IncomingMessage): Promise<Uint8Array | null>;
|
|
182
181
|
}
|
|
183
182
|
export const getRawBody: GetRawBody;
|
|
184
|
-
}
|
|
185
183
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
type State = import('@sveltejs/kit/types/internal').SSRRenderState;
|
|
184
|
+
export interface GetRequest {
|
|
185
|
+
(base: string, request: IncomingMessage): Promise<Request>;
|
|
186
|
+
}
|
|
187
|
+
export const getRequest: GetRequest;
|
|
191
188
|
|
|
192
|
-
export interface
|
|
193
|
-
(
|
|
194
|
-
Response | undefined
|
|
195
|
-
>;
|
|
189
|
+
export interface SetResponse {
|
|
190
|
+
(res: ServerResponse, response: Response): void;
|
|
196
191
|
}
|
|
197
|
-
export const
|
|
192
|
+
export const setResponse: SetResponse;
|
|
198
193
|
}
|
|
199
194
|
|
|
200
195
|
declare module '@sveltejs/kit/install-fetch' {
|
package/types/app.d.ts
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
import { ReadOnlyFormData, RequestHeaders } from './helper';
|
|
2
|
-
import { ServerResponse } from './hooks';
|
|
3
1
|
import { PrerenderOptions, SSRNodeLoader, SSRRoute } from './internal';
|
|
4
2
|
|
|
5
3
|
export class App {
|
|
6
4
|
constructor(manifest: SSRManifest);
|
|
7
|
-
render(
|
|
5
|
+
render(request: Request): Promise<Response>;
|
|
8
6
|
}
|
|
9
7
|
|
|
10
8
|
export class InternalApp extends App {
|
|
11
9
|
render(
|
|
12
|
-
|
|
10
|
+
request: Request,
|
|
13
11
|
options?: {
|
|
14
12
|
prerender: PrerenderOptions;
|
|
15
13
|
}
|
|
16
|
-
): Promise<
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type RawBody = null | Uint8Array;
|
|
20
|
-
export type ParameterizedBody<Body = unknown> = Body extends FormData
|
|
21
|
-
? ReadOnlyFormData
|
|
22
|
-
: (string | RawBody | ReadOnlyFormData) & Body;
|
|
23
|
-
|
|
24
|
-
export interface IncomingRequest {
|
|
25
|
-
url: string | URL;
|
|
26
|
-
method: string;
|
|
27
|
-
headers: RequestHeaders;
|
|
28
|
-
rawBody: RawBody;
|
|
14
|
+
): Promise<Response>;
|
|
29
15
|
}
|
|
30
16
|
|
|
31
17
|
export interface SSRManifest {
|
package/types/config.d.ts
CHANGED
|
@@ -125,11 +125,6 @@ export interface Config {
|
|
|
125
125
|
template?: string;
|
|
126
126
|
};
|
|
127
127
|
floc?: boolean;
|
|
128
|
-
headers?: {
|
|
129
|
-
host?: string;
|
|
130
|
-
protocol?: string;
|
|
131
|
-
};
|
|
132
|
-
host?: string;
|
|
133
128
|
hydrate?: boolean;
|
|
134
129
|
inlineStyleThreshold?: number;
|
|
135
130
|
methodOverride?: {
|
|
@@ -153,7 +148,6 @@ export interface Config {
|
|
|
153
148
|
entries?: string[];
|
|
154
149
|
onError?: PrerenderOnErrorValue;
|
|
155
150
|
};
|
|
156
|
-
protocol?: string;
|
|
157
151
|
router?: boolean;
|
|
158
152
|
serviceWorker?: {
|
|
159
153
|
register?: boolean;
|
package/types/endpoint.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestEvent } from './hooks';
|
|
2
2
|
import { JSONString, MaybePromise, ResponseHeaders, Either, Fallthrough } from './helper';
|
|
3
3
|
|
|
4
4
|
type DefaultBody = JSONString | Uint8Array;
|
|
5
5
|
|
|
6
6
|
export interface EndpointOutput<Body extends DefaultBody = DefaultBody> {
|
|
7
7
|
status?: number;
|
|
8
|
-
headers?: Partial<ResponseHeaders>;
|
|
8
|
+
headers?: Headers | Partial<ResponseHeaders>;
|
|
9
9
|
body?: Body;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface RequestHandler<
|
|
13
13
|
Locals = Record<string, any>,
|
|
14
|
-
Input = unknown,
|
|
15
14
|
Output extends DefaultBody = DefaultBody
|
|
16
15
|
> {
|
|
17
|
-
(request:
|
|
18
|
-
Either<EndpointOutput<Output>, Fallthrough>
|
|
16
|
+
(request: RequestEvent<Locals>): MaybePromise<
|
|
17
|
+
Either<Response | EndpointOutput<Output>, Fallthrough>
|
|
19
18
|
>;
|
|
20
19
|
}
|
package/types/helper.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export type JSONString =
|
|
|
21
21
|
|
|
22
22
|
/** `string[]` is only for set-cookie, everything else must be type of `string` */
|
|
23
23
|
export type ResponseHeaders = Record<string, string | string[]>;
|
|
24
|
-
export type RequestHeaders = Record<string, string>;
|
|
25
24
|
|
|
26
25
|
// Utility Types
|
|
27
26
|
export type InferValue<T, Key extends keyof T, Default> = T extends Record<Key, infer Val>
|
package/types/hooks.d.ts
CHANGED
|
@@ -1,53 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MaybePromise, RequestHeaders, ResponseHeaders } from './helper';
|
|
1
|
+
import { MaybePromise } from './helper';
|
|
3
2
|
|
|
4
3
|
export type StrictBody = string | Uint8Array;
|
|
5
4
|
|
|
6
|
-
export interface
|
|
5
|
+
export interface RequestEvent<Locals = Record<string, any>> {
|
|
6
|
+
request: Request;
|
|
7
7
|
url: URL;
|
|
8
|
-
method: string;
|
|
9
|
-
headers: RequestHeaders;
|
|
10
|
-
rawBody: RawBody;
|
|
11
8
|
params: Record<string, string>;
|
|
12
|
-
body: ParameterizedBody<Body>;
|
|
13
9
|
locals: Locals;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export interface
|
|
17
|
-
|
|
18
|
-
headers: Partial<ResponseHeaders>;
|
|
19
|
-
body?: StrictBody;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface GetSession<Locals = Record<string, any>, Body = unknown, Session = any> {
|
|
23
|
-
(request: ServerRequest<Locals, Body>): MaybePromise<Session>;
|
|
12
|
+
export interface GetSession<Locals = Record<string, any>, Session = any> {
|
|
13
|
+
(event: RequestEvent<Locals>): MaybePromise<Session>;
|
|
24
14
|
}
|
|
25
15
|
|
|
26
16
|
export interface ResolveOpts {
|
|
27
17
|
ssr?: boolean;
|
|
28
18
|
}
|
|
29
19
|
|
|
30
|
-
export interface Handle<Locals = Record<string, any
|
|
20
|
+
export interface Handle<Locals = Record<string, any>> {
|
|
31
21
|
(input: {
|
|
32
|
-
|
|
33
|
-
resolve(
|
|
34
|
-
}): MaybePromise<
|
|
22
|
+
event: RequestEvent<Locals>;
|
|
23
|
+
resolve(event: RequestEvent<Locals>, opts?: ResolveOpts): MaybePromise<Response>;
|
|
24
|
+
}): MaybePromise<Response>;
|
|
35
25
|
}
|
|
36
26
|
|
|
37
27
|
// internally, `resolve` could return `undefined`, so we differentiate InternalHandle
|
|
38
28
|
// from the public Handle type
|
|
39
|
-
export interface InternalHandle<Locals = Record<string, any
|
|
29
|
+
export interface InternalHandle<Locals = Record<string, any>> {
|
|
40
30
|
(input: {
|
|
41
|
-
|
|
42
|
-
resolve(
|
|
43
|
-
|
|
44
|
-
opts?: ResolveOpts
|
|
45
|
-
): MaybePromise<ServerResponse | undefined>;
|
|
46
|
-
}): MaybePromise<ServerResponse | undefined>;
|
|
31
|
+
event: RequestEvent<Locals>;
|
|
32
|
+
resolve(event: RequestEvent<Locals>, opts?: ResolveOpts): MaybePromise<Response | undefined>;
|
|
33
|
+
}): MaybePromise<Response | undefined>;
|
|
47
34
|
}
|
|
48
35
|
|
|
49
|
-
export interface HandleError<Locals = Record<string, any
|
|
50
|
-
(input: { error: Error & { frame?: string };
|
|
36
|
+
export interface HandleError<Locals = Record<string, any>> {
|
|
37
|
+
(input: { error: Error & { frame?: string }; event: RequestEvent<Locals> }): void;
|
|
51
38
|
}
|
|
52
39
|
|
|
53
40
|
export interface ExternalFetch {
|
package/types/index.d.ts
CHANGED
|
@@ -3,16 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import './ambient-modules';
|
|
5
5
|
|
|
6
|
-
export { App,
|
|
6
|
+
export { App, SSRManifest } from './app';
|
|
7
7
|
export { Adapter, Builder, Config, PrerenderErrorHandler, ValidatedConfig } from './config';
|
|
8
8
|
export { EndpointOutput, RequestHandler } from './endpoint';
|
|
9
9
|
export { ErrorLoad, ErrorLoadInput, Load, LoadInput, LoadOutput } from './page';
|
|
10
|
-
export {
|
|
11
|
-
ExternalFetch,
|
|
12
|
-
GetSession,
|
|
13
|
-
Handle,
|
|
14
|
-
HandleError,
|
|
15
|
-
ServerRequest as Request,
|
|
16
|
-
ServerResponse as Response,
|
|
17
|
-
ResolveOpts
|
|
18
|
-
} from './hooks';
|
|
10
|
+
export { ExternalFetch, GetSession, Handle, HandleError, RequestEvent, ResolveOpts } from './hooks';
|