@sveltejs/kit 1.0.0-next.21 → 1.0.0-next.210
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/README.md +12 -9
- package/assets/components/error.svelte +19 -3
- package/assets/kit.js +1912 -0
- package/assets/runtime/app/env.js +20 -0
- package/assets/runtime/app/navigation.js +45 -13
- package/assets/runtime/app/paths.js +1 -2
- package/assets/runtime/app/stores.js +15 -9
- package/assets/runtime/chunks/utils.js +13 -0
- package/assets/runtime/env.js +8 -0
- package/assets/runtime/internal/singletons.js +5 -11
- package/assets/runtime/internal/start.js +979 -355
- package/assets/runtime/paths.js +13 -0
- package/dist/chunks/cert.js +29255 -0
- package/dist/chunks/constants.js +8 -0
- package/dist/chunks/error.js +21 -0
- package/dist/chunks/index.js +4732 -0
- package/dist/chunks/index2.js +812 -0
- package/dist/chunks/index3.js +624 -0
- package/dist/chunks/index4.js +109 -0
- package/dist/chunks/index5.js +628 -0
- package/dist/chunks/index6.js +827 -0
- package/dist/chunks/index7.js +15575 -0
- package/dist/chunks/misc.js +3 -0
- package/dist/chunks/multipart-parser.js +449 -0
- package/dist/chunks/url.js +62 -0
- package/dist/cli.js +1012 -67
- package/dist/hooks.js +28 -0
- package/dist/install-fetch.js +6514 -0
- package/dist/node.js +51 -0
- package/dist/ssr.js +1842 -0
- package/package.json +90 -54
- package/svelte-kit.js +2 -0
- package/types/ambient-modules.d.ts +181 -0
- package/types/app.d.ts +45 -0
- package/types/config.d.ts +163 -0
- package/types/endpoint.d.ts +18 -0
- package/types/helper.d.ts +41 -0
- package/types/hooks.d.ts +48 -0
- package/types/index.d.ts +17 -0
- package/types/internal.d.ts +231 -0
- package/types/page.d.ts +71 -0
- package/CHANGELOG.md +0 -282
- package/assets/runtime/app/navigation.js.map +0 -1
- package/assets/runtime/app/paths.js.map +0 -1
- package/assets/runtime/app/stores.js.map +0 -1
- package/assets/runtime/internal/singletons.js.map +0 -1
- package/assets/runtime/internal/start.js.map +0 -1
- package/assets/runtime/utils-85ebcc60.js +0 -18
- package/assets/runtime/utils-85ebcc60.js.map +0 -1
- package/dist/api.js +0 -44
- package/dist/api.js.map +0 -1
- package/dist/build.js +0 -246
- package/dist/build.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/colors.js +0 -37
- package/dist/colors.js.map +0 -1
- package/dist/create_app.js +0 -578
- package/dist/create_app.js.map +0 -1
- package/dist/index.js +0 -12042
- package/dist/index.js.map +0 -1
- package/dist/index2.js +0 -544
- package/dist/index2.js.map +0 -1
- package/dist/index3.js +0 -71
- package/dist/index3.js.map +0 -1
- package/dist/index4.js +0 -466
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -729
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -713
- package/dist/index6.js.map +0 -1
- package/dist/logging.js +0 -43
- package/dist/logging.js.map +0 -1
- package/dist/package.js +0 -432
- package/dist/package.js.map +0 -1
- package/dist/renderer.js +0 -2391
- package/dist/renderer.js.map +0 -1
- package/dist/standard.js +0 -101
- package/dist/standard.js.map +0 -1
- package/dist/utils.js +0 -54
- package/dist/utils.js.map +0 -1
- package/svelte-kit +0 -3
package/package.json
CHANGED
|
@@ -1,55 +1,91 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
2
|
+
"name": "@sveltejs/kit",
|
|
3
|
+
"version": "1.0.0-next.210",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/sveltejs/kit",
|
|
7
|
+
"directory": "packages/kit"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://kit.svelte.dev",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.32",
|
|
14
|
+
"cheap-watch": "^1.0.4",
|
|
15
|
+
"sade": "^1.7.4",
|
|
16
|
+
"vite": "^2.7.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@rollup/plugin-replace": "^3.0.0",
|
|
20
|
+
"@types/amphtml-validator": "^1.0.1",
|
|
21
|
+
"@types/cookie": "^0.4.1",
|
|
22
|
+
"@types/marked": "^4.0.1",
|
|
23
|
+
"@types/mime": "^2.0.3",
|
|
24
|
+
"@types/node": "^16.11.11",
|
|
25
|
+
"@types/sade": "^1.7.3",
|
|
26
|
+
"amphtml-validator": "^1.0.35",
|
|
27
|
+
"cookie": "^0.4.1",
|
|
28
|
+
"devalue": "^2.0.1",
|
|
29
|
+
"eslint": "^8.3.0",
|
|
30
|
+
"kleur": "^4.1.4",
|
|
31
|
+
"locate-character": "^2.0.5",
|
|
32
|
+
"marked": "^4.0.5",
|
|
33
|
+
"mime": "^3.0.0",
|
|
34
|
+
"node-fetch": "^3.1.0",
|
|
35
|
+
"port-authority": "^1.1.2",
|
|
36
|
+
"rollup": "^2.60.2",
|
|
37
|
+
"selfsigned": "^1.10.11",
|
|
38
|
+
"sirv": "^1.0.19",
|
|
39
|
+
"svelte": "^3.44.2",
|
|
40
|
+
"svelte-check": "^2.2.10",
|
|
41
|
+
"svelte2tsx": "~0.4.10",
|
|
42
|
+
"tiny-glob": "^0.2.9",
|
|
43
|
+
"uvu": "^0.5.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"svelte": "^3.44.0"
|
|
47
|
+
},
|
|
48
|
+
"bin": {
|
|
49
|
+
"svelte-kit": "svelte-kit.js"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"assets",
|
|
53
|
+
"dist",
|
|
54
|
+
"types",
|
|
55
|
+
"svelte-kit.js"
|
|
56
|
+
],
|
|
57
|
+
"exports": {
|
|
58
|
+
"./package.json": "./package.json",
|
|
59
|
+
".": {
|
|
60
|
+
"types": "./types/index.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"./ssr": {
|
|
63
|
+
"import": "./dist/ssr.js"
|
|
64
|
+
},
|
|
65
|
+
"./node": {
|
|
66
|
+
"import": "./dist/node.js"
|
|
67
|
+
},
|
|
68
|
+
"./hooks": {
|
|
69
|
+
"import": "./dist/hooks.js"
|
|
70
|
+
},
|
|
71
|
+
"./install-fetch": {
|
|
72
|
+
"import": "./dist/install-fetch.js"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"types": "types/index.d.ts",
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=14.13"
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"build": "rollup -c",
|
|
81
|
+
"dev": "rollup -cw",
|
|
82
|
+
"lint": "eslint --ignore-path .gitignore --ignore-pattern \"src/packaging/test/**\" \"{src,test}/**/*.{ts,mjs,js,svelte}\" && npm run check-format",
|
|
83
|
+
"check": "tsc && svelte-check --ignore \"src/packaging/test\"",
|
|
84
|
+
"format": "npm run check-format -- --write",
|
|
85
|
+
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
|
|
86
|
+
"test": "npm run test:unit && npm run test:packaging && npm run test:integration",
|
|
87
|
+
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
|
|
88
|
+
"test:packaging": "uvu src/packaging \"(spec\\.js|test[\\\\/]index\\.js)\"",
|
|
89
|
+
"test:integration": "uvu test test.js"
|
|
90
|
+
}
|
|
91
|
+
}
|
package/svelte-kit.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/* eslint-disable import/no-duplicates */
|
|
2
|
+
|
|
3
|
+
declare module '$app/env' {
|
|
4
|
+
/**
|
|
5
|
+
* Whether or not app is in AMP mode.
|
|
6
|
+
*/
|
|
7
|
+
export const amp: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether the app is running in the browser or on the server.
|
|
10
|
+
*/
|
|
11
|
+
export const browser: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* `true` in development mode, `false` in production.
|
|
14
|
+
*/
|
|
15
|
+
export const dev: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* `true` when prerendering, `false` otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export const prerendering: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The Vite.js mode the app is running in. Configure in `config.kit.vite.mode`.
|
|
22
|
+
* Vite.js loads the dotenv file associated with the provided mode, `.env.[mode]` or `.env.[mode].local`.
|
|
23
|
+
* By default, `svelte-kit dev` runs with `mode=development` and `svelte-kit build` runs with `mode=production`.
|
|
24
|
+
*/
|
|
25
|
+
export const mode: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare module '$app/navigation' {
|
|
29
|
+
/**
|
|
30
|
+
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified href.
|
|
31
|
+
*
|
|
32
|
+
* @param href Where to navigate to
|
|
33
|
+
* @param opts.replaceState If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
|
|
34
|
+
* @param opts.noscroll If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation
|
|
35
|
+
* @param opts.keepfocus If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body
|
|
36
|
+
* @param opts.state The state of the new/updated history entry
|
|
37
|
+
*/
|
|
38
|
+
export function goto(
|
|
39
|
+
href: string,
|
|
40
|
+
opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any }
|
|
41
|
+
): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a Promise that resolves when SvelteKit re-runs any current `load` functions that depend on `href`
|
|
44
|
+
* @param href The invalidated resource
|
|
45
|
+
*/
|
|
46
|
+
export function invalidate(href: string): Promise<any>;
|
|
47
|
+
/**
|
|
48
|
+
* Programmatically prefetches the given page, which means
|
|
49
|
+
* 1. ensuring that the code for the page is loaded, and
|
|
50
|
+
* 2. calling the page's load function with the appropriate options.
|
|
51
|
+
*
|
|
52
|
+
* This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `sveltekit:prefetch`.
|
|
53
|
+
* If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
|
|
54
|
+
* Returns a Promise that resolves when the prefetch is complete.
|
|
55
|
+
*
|
|
56
|
+
* @param href Page to prefetch
|
|
57
|
+
*/
|
|
58
|
+
export function prefetch(href: string): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Programmatically prefetches the code for routes that haven't yet been fetched.
|
|
61
|
+
* Typically, you might call this to speed up subsequent navigation.
|
|
62
|
+
*
|
|
63
|
+
* If no argument is given, all routes will be fetched, otherwise you can specify routes by any matching pathname
|
|
64
|
+
* such as `/about` (to match `src/routes/about.svelte`) or `/blog/*` (to match `src/routes/blog/[slug].svelte`).
|
|
65
|
+
*
|
|
66
|
+
* Unlike prefetch, this won't call preload for individual pages.
|
|
67
|
+
* Returns a Promise that resolves when the routes have been prefetched.
|
|
68
|
+
*/
|
|
69
|
+
export function prefetchRoutes(routes?: string[]): Promise<any>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare module '$app/paths' {
|
|
73
|
+
/**
|
|
74
|
+
* A root-relative (i.e. begins with a `/`) string that matches `config.kit.paths.base` in your project configuration.
|
|
75
|
+
*/
|
|
76
|
+
export const base: string;
|
|
77
|
+
/**
|
|
78
|
+
* A root-relative or absolute path that matches `config.kit.paths.assets` (after it has been resolved against base).
|
|
79
|
+
*/
|
|
80
|
+
export const assets: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare module '$app/stores' {
|
|
84
|
+
import { Readable, Writable } from 'svelte/store';
|
|
85
|
+
type Navigating = { from: URL; to: URL };
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A convenience function around `getContext` that returns `{ navigating, page, session }`.
|
|
89
|
+
* Most of the time, you won't need to use it.
|
|
90
|
+
*/
|
|
91
|
+
export function getStores<Session = any>(): {
|
|
92
|
+
navigating: Readable<Navigating | null>;
|
|
93
|
+
page: Readable<{
|
|
94
|
+
url: URL;
|
|
95
|
+
params: Record<string, string>;
|
|
96
|
+
}>;
|
|
97
|
+
session: Writable<Session>;
|
|
98
|
+
};
|
|
99
|
+
export const url: Readable<URL>;
|
|
100
|
+
/**
|
|
101
|
+
* A readable store whose value contains page data.
|
|
102
|
+
*/
|
|
103
|
+
export const page: Readable<{
|
|
104
|
+
url: URL;
|
|
105
|
+
params: Record<string, string>;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* A readable store.
|
|
109
|
+
* When navigating starts, its value is `{ from: URL, to: URL }`
|
|
110
|
+
* When navigating finishes, its value reverts to `null`.
|
|
111
|
+
*/
|
|
112
|
+
export const navigating: Readable<Navigating | null>;
|
|
113
|
+
/**
|
|
114
|
+
* A writable store whose initial value is whatever was returned from `getSession`.
|
|
115
|
+
* It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
|
|
116
|
+
*/
|
|
117
|
+
export const session: Writable<any>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
declare module '$service-worker' {
|
|
121
|
+
/**
|
|
122
|
+
* An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`.
|
|
123
|
+
* This is only available to service workers.
|
|
124
|
+
*/
|
|
125
|
+
export const build: string[];
|
|
126
|
+
/**
|
|
127
|
+
* An array of URL strings representing the files in your static directory,
|
|
128
|
+
* or whatever directory is specified by `config.kit.files.assets`.
|
|
129
|
+
* This is only available to service workers.
|
|
130
|
+
*/
|
|
131
|
+
export const files: string[];
|
|
132
|
+
/**
|
|
133
|
+
* The result of calling `Date.now()` at build time.
|
|
134
|
+
* It's useful for generating unique cache names inside your service worker,
|
|
135
|
+
* so that a later deployment of your app can invalidate old caches.
|
|
136
|
+
* This is only available to service workers.
|
|
137
|
+
*/
|
|
138
|
+
export const timestamp: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
declare module '@sveltejs/kit/hooks' {
|
|
142
|
+
import { Handle } from '@sveltejs/kit';
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Utility function that allows chaining `handle` functions in a
|
|
146
|
+
* middleware-like manner.
|
|
147
|
+
*
|
|
148
|
+
* @param handlers The chain of `handle` functions
|
|
149
|
+
*/
|
|
150
|
+
export function sequence(...handlers: Handle[]): Handle;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare module '@sveltejs/kit/node' {
|
|
154
|
+
import { IncomingMessage } from 'http';
|
|
155
|
+
import { RawBody } from '@sveltejs/kit';
|
|
156
|
+
|
|
157
|
+
export interface GetRawBody {
|
|
158
|
+
(request: IncomingMessage): Promise<RawBody>;
|
|
159
|
+
}
|
|
160
|
+
export const getRawBody: GetRawBody;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
declare module '@sveltejs/kit/ssr' {
|
|
164
|
+
import { IncomingRequest, Response } from '@sveltejs/kit';
|
|
165
|
+
// TODO import from public types, right now its heavily coupled with internal
|
|
166
|
+
type Options = import('@sveltejs/kit/types/internal').SSRRenderOptions;
|
|
167
|
+
type State = import('@sveltejs/kit/types/internal').SSRRenderState;
|
|
168
|
+
|
|
169
|
+
export interface Respond {
|
|
170
|
+
(incoming: IncomingRequest & { url: URL }, options: Options, state?: State): Promise<
|
|
171
|
+
Response | undefined
|
|
172
|
+
>;
|
|
173
|
+
}
|
|
174
|
+
export const respond: Respond;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
declare module '@sveltejs/kit/install-fetch' {
|
|
178
|
+
import fetch, { Headers, Request, Response } from 'node-fetch';
|
|
179
|
+
|
|
180
|
+
export { fetch, Headers, Request, Response };
|
|
181
|
+
}
|
package/types/app.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ReadOnlyFormData, RequestHeaders } from './helper';
|
|
2
|
+
import { ServerResponse } from './hooks';
|
|
3
|
+
import { PrerenderOptions, SSRNodeLoader, SSRRoute } from './internal';
|
|
4
|
+
|
|
5
|
+
export class App {
|
|
6
|
+
constructor(manifest: SSRManifest);
|
|
7
|
+
render(incoming: IncomingRequest): Promise<ServerResponse>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class InternalApp extends App {
|
|
11
|
+
render(
|
|
12
|
+
incoming: IncomingRequest,
|
|
13
|
+
options?: {
|
|
14
|
+
prerender: PrerenderOptions;
|
|
15
|
+
}
|
|
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;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SSRManifest {
|
|
32
|
+
appDir: string;
|
|
33
|
+
assets: Set<string>;
|
|
34
|
+
/** private fields */
|
|
35
|
+
_: {
|
|
36
|
+
mime: Record<string, string>;
|
|
37
|
+
entry: {
|
|
38
|
+
file: string;
|
|
39
|
+
js: string[];
|
|
40
|
+
css: string[];
|
|
41
|
+
};
|
|
42
|
+
nodes: SSRNodeLoader[];
|
|
43
|
+
routes: SSRRoute[];
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { UserConfig as ViteConfig } from 'vite';
|
|
2
|
+
import { RecursiveRequired } from './helper';
|
|
3
|
+
import { HttpMethod, Logger, RouteSegment, TrailingSlash } from './internal';
|
|
4
|
+
|
|
5
|
+
export interface RouteDefinition {
|
|
6
|
+
type: 'page' | 'endpoint';
|
|
7
|
+
pattern: RegExp;
|
|
8
|
+
segments: RouteSegment[];
|
|
9
|
+
methods: HttpMethod[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface AdapterEntry {
|
|
13
|
+
/**
|
|
14
|
+
* A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
|
|
15
|
+
* For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
|
|
16
|
+
* be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
|
|
17
|
+
*/
|
|
18
|
+
id: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A function that compares the candidate route with the current route to determine
|
|
22
|
+
* if it should be treated as a fallback for the current route. For example, `/foo/[c]`
|
|
23
|
+
* is a fallback for `/foo/a-[b]`, and `/[...catchall]` is a fallback for all routes
|
|
24
|
+
*/
|
|
25
|
+
filter: (route: RouteDefinition) => boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A function that is invoked once the entry has been created. This is where you
|
|
29
|
+
* should write the function to the filesystem and generate redirect manifests.
|
|
30
|
+
*/
|
|
31
|
+
complete: (entry: {
|
|
32
|
+
generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
|
|
33
|
+
}) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Builder {
|
|
37
|
+
log: Logger;
|
|
38
|
+
rimraf(dir: string): void;
|
|
39
|
+
mkdirp(dir: string): void;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create entry points that map to individual functions
|
|
43
|
+
* @param fn A function that groups a set of routes into an entry point
|
|
44
|
+
*/
|
|
45
|
+
createEntries(fn: (route: RouteDefinition) => AdapterEntry): void;
|
|
46
|
+
|
|
47
|
+
generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
|
|
48
|
+
|
|
49
|
+
getBuildDirectory(name: string): string;
|
|
50
|
+
getClientDirectory(): string;
|
|
51
|
+
getServerDirectory(): string;
|
|
52
|
+
getStaticDirectory(): string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param dest the destination folder to which files should be copied
|
|
56
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
57
|
+
*/
|
|
58
|
+
writeClient(dest: string): string[];
|
|
59
|
+
/**
|
|
60
|
+
* @param dest the destination folder to which files should be copied
|
|
61
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
62
|
+
*/
|
|
63
|
+
writeServer(dest: string): string[];
|
|
64
|
+
/**
|
|
65
|
+
* @param dest the destination folder to which files should be copied
|
|
66
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
67
|
+
*/
|
|
68
|
+
writeStatic(dest: string): string[];
|
|
69
|
+
/**
|
|
70
|
+
* @param from the source file or folder
|
|
71
|
+
* @param to the destination file or folder
|
|
72
|
+
* @param opts.filter a function to determine whether a file or folder should be copied
|
|
73
|
+
* @param opts.replace a map of strings to replace
|
|
74
|
+
* @returns an array of paths corresponding to the files that have been created by the copy
|
|
75
|
+
*/
|
|
76
|
+
copy(
|
|
77
|
+
from: string,
|
|
78
|
+
to: string,
|
|
79
|
+
opts?: {
|
|
80
|
+
filter?: (basename: string) => boolean;
|
|
81
|
+
replace?: Record<string, string>;
|
|
82
|
+
}
|
|
83
|
+
): string[];
|
|
84
|
+
|
|
85
|
+
prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<{
|
|
86
|
+
paths: string[];
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface Adapter {
|
|
91
|
+
name: string;
|
|
92
|
+
headers?: {
|
|
93
|
+
host?: string;
|
|
94
|
+
protocol?: string;
|
|
95
|
+
};
|
|
96
|
+
adapt(builder: Builder): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface PrerenderErrorHandler {
|
|
100
|
+
(details: {
|
|
101
|
+
status: number;
|
|
102
|
+
path: string;
|
|
103
|
+
referrer: string | null;
|
|
104
|
+
referenceType: 'linked' | 'fetched';
|
|
105
|
+
}): void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type PrerenderOnErrorValue = 'fail' | 'continue' | PrerenderErrorHandler;
|
|
109
|
+
|
|
110
|
+
export interface Config {
|
|
111
|
+
compilerOptions?: any;
|
|
112
|
+
extensions?: string[];
|
|
113
|
+
kit?: {
|
|
114
|
+
adapter?: Adapter;
|
|
115
|
+
amp?: boolean;
|
|
116
|
+
appDir?: string;
|
|
117
|
+
files?: {
|
|
118
|
+
assets?: string;
|
|
119
|
+
hooks?: string;
|
|
120
|
+
lib?: string;
|
|
121
|
+
routes?: string;
|
|
122
|
+
serviceWorker?: string;
|
|
123
|
+
template?: string;
|
|
124
|
+
};
|
|
125
|
+
floc?: boolean;
|
|
126
|
+
headers?: {
|
|
127
|
+
host?: string;
|
|
128
|
+
protocol?: string;
|
|
129
|
+
};
|
|
130
|
+
host?: string;
|
|
131
|
+
hydrate?: boolean;
|
|
132
|
+
package?: {
|
|
133
|
+
dir?: string;
|
|
134
|
+
emitTypes?: boolean;
|
|
135
|
+
exports?(filepath: string): boolean;
|
|
136
|
+
files?(filepath: string): boolean;
|
|
137
|
+
};
|
|
138
|
+
paths?: {
|
|
139
|
+
assets?: string;
|
|
140
|
+
base?: string;
|
|
141
|
+
};
|
|
142
|
+
prerender?: {
|
|
143
|
+
concurrency?: number;
|
|
144
|
+
crawl?: boolean;
|
|
145
|
+
enabled?: boolean;
|
|
146
|
+
entries?: string[];
|
|
147
|
+
onError?: PrerenderOnErrorValue;
|
|
148
|
+
};
|
|
149
|
+
protocol?: string;
|
|
150
|
+
router?: boolean;
|
|
151
|
+
serviceWorker?: {
|
|
152
|
+
register?: boolean;
|
|
153
|
+
files?: (filepath: string) => boolean;
|
|
154
|
+
};
|
|
155
|
+
ssr?: boolean;
|
|
156
|
+
target?: string;
|
|
157
|
+
trailingSlash?: TrailingSlash;
|
|
158
|
+
vite?: ViteConfig | (() => ViteConfig);
|
|
159
|
+
};
|
|
160
|
+
preprocess?: any;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type ValidatedConfig = RecursiveRequired<Config>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ServerRequest } from './hooks';
|
|
2
|
+
import { JSONString, MaybePromise, ResponseHeaders } from './helper';
|
|
3
|
+
|
|
4
|
+
type DefaultBody = JSONString | Uint8Array;
|
|
5
|
+
|
|
6
|
+
export interface EndpointOutput<Body extends DefaultBody = DefaultBody> {
|
|
7
|
+
status?: number;
|
|
8
|
+
headers?: ResponseHeaders;
|
|
9
|
+
body?: Body;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RequestHandler<
|
|
13
|
+
Locals = Record<string, any>,
|
|
14
|
+
Input = unknown,
|
|
15
|
+
Output extends DefaultBody = DefaultBody
|
|
16
|
+
> {
|
|
17
|
+
(request: ServerRequest<Locals, Input>): MaybePromise<void | EndpointOutput<Output>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface ReadOnlyFormData {
|
|
2
|
+
get(key: string): string;
|
|
3
|
+
getAll(key: string): string[];
|
|
4
|
+
has(key: string): boolean;
|
|
5
|
+
entries(): Generator<[string, string], void>;
|
|
6
|
+
keys(): Generator<string, void>;
|
|
7
|
+
values(): Generator<string, void>;
|
|
8
|
+
[Symbol.iterator](): Generator<[string, string], void>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type ToJSON = { toJSON(...args: any[]): JSONValue };
|
|
12
|
+
type JSONValue = Exclude<JSONString, ToJSON>;
|
|
13
|
+
export type JSONString =
|
|
14
|
+
| string
|
|
15
|
+
| number
|
|
16
|
+
| boolean
|
|
17
|
+
| null
|
|
18
|
+
| ToJSON
|
|
19
|
+
| JSONString[]
|
|
20
|
+
| { [key: string]: JSONString };
|
|
21
|
+
|
|
22
|
+
/** `string[]` is only for set-cookie, everything else must be type of `string` */
|
|
23
|
+
export type ResponseHeaders = Record<string, string | string[]>;
|
|
24
|
+
export type RequestHeaders = Record<string, string>;
|
|
25
|
+
|
|
26
|
+
// Utility Types
|
|
27
|
+
export type InferValue<T, Key extends keyof T, Default> = T extends Record<Key, infer Val>
|
|
28
|
+
? Val
|
|
29
|
+
: Default;
|
|
30
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
31
|
+
export type Rec<T = any> = Record<string, T>;
|
|
32
|
+
export type RecursiveRequired<T> = {
|
|
33
|
+
// Recursive implementation of TypeScript's Required utility type.
|
|
34
|
+
// Will recursively continue until it reaches primitive or union
|
|
35
|
+
// with a Function in it, except those commented below
|
|
36
|
+
[K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
|
|
37
|
+
? RecursiveRequired<T[K]> // recursively continue through.
|
|
38
|
+
: K extends 'vite' // If it reaches the 'vite' key
|
|
39
|
+
? Extract<T[K], Function> // only take the Function type.
|
|
40
|
+
: T[K]; // Use the exact type for everything else
|
|
41
|
+
};
|
package/types/hooks.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ParameterizedBody, RawBody } from './app';
|
|
2
|
+
import { MaybePromise, RequestHeaders, ResponseHeaders } from './helper';
|
|
3
|
+
|
|
4
|
+
export type StrictBody = string | Uint8Array;
|
|
5
|
+
|
|
6
|
+
export interface ServerRequest<Locals = Record<string, any>, Body = unknown> {
|
|
7
|
+
url: URL;
|
|
8
|
+
method: string;
|
|
9
|
+
headers: RequestHeaders;
|
|
10
|
+
rawBody: RawBody;
|
|
11
|
+
params: Record<string, string>;
|
|
12
|
+
body: ParameterizedBody<Body>;
|
|
13
|
+
locals: Locals;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ServerResponse {
|
|
17
|
+
status: number;
|
|
18
|
+
headers: 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>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface Handle<Locals = Record<string, any>, Body = unknown> {
|
|
27
|
+
(input: {
|
|
28
|
+
request: ServerRequest<Locals, Body>;
|
|
29
|
+
resolve(request: ServerRequest<Locals, Body>): MaybePromise<ServerResponse>;
|
|
30
|
+
}): MaybePromise<ServerResponse>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// internally, `resolve` could return `undefined`, so we differentiate InternalHandle
|
|
34
|
+
// from the public Handle type
|
|
35
|
+
export interface InternalHandle<Locals = Record<string, any>, Body = unknown> {
|
|
36
|
+
(input: {
|
|
37
|
+
request: ServerRequest<Locals, Body>;
|
|
38
|
+
resolve(request: ServerRequest<Locals, Body>): MaybePromise<ServerResponse | undefined>;
|
|
39
|
+
}): MaybePromise<ServerResponse | undefined>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface HandleError<Locals = Record<string, any>, Body = unknown> {
|
|
43
|
+
(input: { error: Error & { frame?: string }; request: ServerRequest<Locals, Body> }): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ExternalFetch {
|
|
47
|
+
(req: Request): Promise<Response>;
|
|
48
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
/// <reference types="vite/client" />
|
|
3
|
+
|
|
4
|
+
import './ambient-modules';
|
|
5
|
+
|
|
6
|
+
export { App, IncomingRequest, RawBody, SSRManifest } from './app';
|
|
7
|
+
export { Adapter, Builder, Config, PrerenderErrorHandler, ValidatedConfig } from './config';
|
|
8
|
+
export { EndpointOutput, RequestHandler } from './endpoint';
|
|
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
|
+
} from './hooks';
|