@sveltejs/kit 1.0.0-next.230 → 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.
@@ -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 { get_single_valued_header as g, is_root_relative as i, resolve as r };
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
- headers: object({
505
- host: string(null),
506
- protocol: string(null)
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
- host: string(null),
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
- protocol: string(null),
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.230');
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.230'}\n`));
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';
@@ -1101,4 +1122,4 @@ function welcome({ port, host, https, open, loose, allow, cwd }) {
1101
1122
  console.log('\n');
1102
1123
  }
1103
1124
 
1104
- export { $, SVELTE_KIT as S, runtime as a, SVELTE_KIT_ASSETS as b, coalesce_to_error as c, copy_assets as d, get_aliases as e, posixify as f, get_mime_lookup as g, rimraf as h, copy as i, logger as j, load_template as l, mkdirp as m, print_config_conflicts as p, resolve_entry as r, walk as w };
1125
+ export { $, SVELTE_KIT_ASSETS as S, SVELTE_KIT as a, runtime as b, coalesce_to_error as c, copy_assets as d, get_aliases as e, posixify as f, get_mime_lookup as g, rimraf as h, copy as i, logger as j, load_template as l, mkdirp as m, print_config_conflicts as p, resolve_entry as r, walk as w };
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 ({ request, resolve }) => resolve(request);
7
+ if (!length) return ({ event, resolve }) => resolve(event);
8
8
 
9
- return ({ request, resolve }) => {
10
- return apply_handle(0, request);
9
+ return ({ event, resolve }) => {
10
+ return apply_handle(0, event);
11
11
 
12
12
  /**
13
13
  * @param {number} i
14
- * @param {import('types/hooks').ServerRequest} request
15
- * @returns {import('types/helper').MaybePromise<import('types/hooks').ServerResponse>}
14
+ * @param {import('types/hooks').RequestEvent} event
15
+ * @returns {import('types/helper').MaybePromise<Response>}
16
16
  */
17
- function apply_handle(i, request) {
17
+ function apply_handle(i, event) {
18
18
  const handle = handlers[i];
19
19
 
20
20
  return handle({
21
- request,
22
- resolve: i < length - 1 ? (request) => apply_handle(i + 1, request) : resolve
21
+ event,
22
+ resolve: i < length - 1 ? (event) => apply_handle(i + 1, event) : resolve
23
23
  });
24
24
  }
25
25
  };
@@ -6494,18 +6494,22 @@ function __fetch_polyfill() {
6494
6494
  Object.defineProperties(globalThis, {
6495
6495
  fetch: {
6496
6496
  enumerable: true,
6497
+ configurable: true,
6497
6498
  value: fetch
6498
6499
  },
6499
6500
  Response: {
6500
6501
  enumerable: true,
6502
+ configurable: true,
6501
6503
  value: Response
6502
6504
  },
6503
6505
  Request: {
6504
6506
  enumerable: true,
6507
+ configurable: true,
6505
6508
  value: Request
6506
6509
  },
6507
6510
  Headers: {
6508
6511
  enumerable: true,
6512
+ configurable: true,
6509
6513
  value: Headers
6510
6514
  }
6511
6515
  });
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
- export { getRawBody };
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.230",
3
+ "version": "1.0.0-next.234",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -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<RawBody>;
180
+ (request: IncomingMessage): Promise<Uint8Array | null>;
182
181
  }
183
182
  export const getRawBody: GetRawBody;
184
- }
185
183
 
186
- declare module '@sveltejs/kit/ssr' {
187
- import { IncomingRequest, Response } from '@sveltejs/kit';
188
- // TODO import from public types, right now its heavily coupled with internal
189
- type Options = import('@sveltejs/kit/types/internal').SSRRenderOptions;
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 Respond {
193
- (incoming: IncomingRequest & { url: URL }, options: Options, state?: State): Promise<
194
- Response | undefined
195
- >;
189
+ export interface SetResponse {
190
+ (res: ServerResponse, response: Response): void;
196
191
  }
197
- export const respond: Respond;
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(incoming: IncomingRequest): Promise<ServerResponse>;
5
+ render(request: Request): Promise<Response>;
8
6
  }
9
7
 
10
8
  export class InternalApp extends App {
11
9
  render(
12
- incoming: IncomingRequest,
10
+ request: Request,
13
11
  options?: {
14
12
  prerender: PrerenderOptions;
15
13
  }
16
- ): Promise<ServerResponse>;
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;
@@ -1,20 +1,19 @@
1
- import { ServerRequest } from './hooks';
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: ServerRequest<Locals, Input>): MaybePromise<
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 { ParameterizedBody, RawBody } from './app';
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 ServerRequest<Locals = Record<string, any>, Body = unknown> {
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 ServerResponse {
17
- status: number;
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>, Body = unknown> {
20
+ export interface Handle<Locals = Record<string, any>> {
31
21
  (input: {
32
- request: ServerRequest<Locals, Body>;
33
- resolve(request: ServerRequest<Locals, Body>, opts?: ResolveOpts): MaybePromise<ServerResponse>;
34
- }): MaybePromise<ServerResponse>;
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>, Body = unknown> {
29
+ export interface InternalHandle<Locals = Record<string, any>> {
40
30
  (input: {
41
- request: ServerRequest<Locals, Body>;
42
- resolve(
43
- request: ServerRequest<Locals, Body>,
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>, Body = unknown> {
50
- (input: { error: Error & { frame?: string }; request: ServerRequest<Locals, Body> }): void;
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, IncomingRequest, RawBody, SSRManifest } from './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';
@@ -1,14 +1,7 @@
1
1
  import { OutputAsset, OutputChunk } from 'rollup';
2
2
  import { RequestHandler } from './endpoint';
3
3
  import { InternalApp, SSRManifest } from './app';
4
- import {
5
- ExternalFetch,
6
- GetSession,
7
- HandleError,
8
- InternalHandle,
9
- ServerRequest,
10
- ServerResponse
11
- } from './hooks';
4
+ import { ExternalFetch, GetSession, HandleError, InternalHandle, RequestEvent } from './hooks';
12
5
  import { Load } from './page';
13
6
  import { Either, Fallthrough } from './helper';
14
7
 
@@ -17,7 +10,7 @@ type PageId = string;
17
10
  export interface PrerenderOptions {
18
11
  fallback?: string;
19
12
  all: boolean;
20
- dependencies: Map<string, ServerResponse>;
13
+ dependencies: Map<string, Response>;
21
14
  }
22
15
 
23
16
  export interface AppModule {
@@ -127,7 +120,7 @@ export interface SSRRenderOptions {
127
120
  dev: boolean;
128
121
  floc: boolean;
129
122
  get_stack: (error: Error) => string | undefined;
130
- handle_error(error: Error & { frame?: string }, request: ServerRequest<any>): void;
123
+ handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
131
124
  hooks: Hooks;
132
125
  hydrate: boolean;
133
126
  manifest: SSRManifest;
@@ -235,3 +228,9 @@ export interface MethodOverride {
235
228
  parameter: string;
236
229
  allowed: string[];
237
230
  }
231
+
232
+ export interface Respond {
233
+ (request: Request, options: SSRRenderOptions, state?: SSRRenderState): Promise<
234
+ Response | undefined
235
+ >;
236
+ }