@sveltejs/kit 1.0.0-next.26 → 1.0.0-next.260

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.
Files changed (86) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +20 -0
  3. package/assets/app/navigation.js +79 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/chunks/utils.js +13 -0
  7. package/assets/client/singletons.js +21 -0
  8. package/assets/client/start.js +1493 -0
  9. package/assets/components/error.svelte +18 -2
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +2664 -0
  13. package/dist/chunks/amp_hook.js +56 -0
  14. package/dist/chunks/build.js +658 -0
  15. package/dist/chunks/cert.js +28154 -0
  16. package/dist/chunks/index.js +467 -0
  17. package/dist/chunks/index2.js +836 -0
  18. package/dist/chunks/index3.js +638 -0
  19. package/dist/chunks/index4.js +115 -0
  20. package/dist/chunks/index5.js +860 -0
  21. package/dist/chunks/index6.js +170 -0
  22. package/dist/chunks/index7.js +15582 -0
  23. package/dist/chunks/index8.js +4207 -0
  24. package/dist/chunks/misc.js +3 -0
  25. package/dist/chunks/multipart-parser.js +449 -0
  26. package/dist/cli.js +1128 -84
  27. package/dist/hooks.js +28 -0
  28. package/dist/install-fetch.js +6518 -0
  29. package/dist/node.js +95 -0
  30. package/package.json +95 -54
  31. package/svelte-kit.js +2 -0
  32. package/types/ambient-modules.d.ts +208 -0
  33. package/types/app.d.ts +35 -0
  34. package/types/config.d.ts +176 -0
  35. package/types/csp.d.ts +115 -0
  36. package/types/endpoint.d.ts +39 -0
  37. package/types/helper.d.ts +23 -0
  38. package/types/hooks.d.ts +34 -0
  39. package/types/index.d.ts +10 -0
  40. package/types/internal.d.ts +260 -0
  41. package/types/page.d.ts +33 -0
  42. package/CHANGELOG.md +0 -312
  43. package/assets/runtime/app/navigation.js +0 -23
  44. package/assets/runtime/app/navigation.js.map +0 -1
  45. package/assets/runtime/app/paths.js +0 -2
  46. package/assets/runtime/app/paths.js.map +0 -1
  47. package/assets/runtime/app/stores.js +0 -78
  48. package/assets/runtime/app/stores.js.map +0 -1
  49. package/assets/runtime/internal/singletons.js +0 -15
  50. package/assets/runtime/internal/singletons.js.map +0 -1
  51. package/assets/runtime/internal/start.js +0 -591
  52. package/assets/runtime/internal/start.js.map +0 -1
  53. package/assets/runtime/utils-85ebcc60.js +0 -18
  54. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  55. package/dist/api.js +0 -44
  56. package/dist/api.js.map +0 -1
  57. package/dist/build.js +0 -246
  58. package/dist/build.js.map +0 -1
  59. package/dist/cli.js.map +0 -1
  60. package/dist/colors.js +0 -37
  61. package/dist/colors.js.map +0 -1
  62. package/dist/create_app.js +0 -580
  63. package/dist/create_app.js.map +0 -1
  64. package/dist/index.js +0 -367
  65. package/dist/index.js.map +0 -1
  66. package/dist/index2.js +0 -12035
  67. package/dist/index2.js.map +0 -1
  68. package/dist/index3.js +0 -547
  69. package/dist/index3.js.map +0 -1
  70. package/dist/index4.js +0 -74
  71. package/dist/index4.js.map +0 -1
  72. package/dist/index5.js +0 -464
  73. package/dist/index5.js.map +0 -1
  74. package/dist/index6.js +0 -727
  75. package/dist/index6.js.map +0 -1
  76. package/dist/logging.js +0 -43
  77. package/dist/logging.js.map +0 -1
  78. package/dist/package.js +0 -432
  79. package/dist/package.js.map +0 -1
  80. package/dist/renderer.js +0 -2403
  81. package/dist/renderer.js.map +0 -1
  82. package/dist/standard.js +0 -101
  83. package/dist/standard.js.map +0 -1
  84. package/dist/utils.js +0 -54
  85. package/dist/utils.js.map +0 -1
  86. package/svelte-kit +0 -3
package/types/csp.d.ts ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2021-present, Joshua Hemphill
7
+ * Copyright (c) 2021, Tecnico Corporation
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+ type SchemeSource = 'http:' | 'https:' | 'data:' | 'mediastream:' | 'blob:' | 'filesystem:';
28
+
29
+ type HostProtocolSchemes = `${string}://` | '';
30
+ type PortScheme = `:${number}` | '' | ':*';
31
+ /** Can actually be any string, but typed more explicitly to
32
+ * restrict the combined optional types of Source from collapsing to just bing `string` */
33
+ type HostNameScheme = `${string}.${string}` | `localhost`;
34
+ type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`;
35
+
36
+ type CryptoSource = `${'nonce' | 'sha256' | 'sha384' | 'sha512'}-${string}`;
37
+
38
+ type BaseSource = 'self' | 'unsafe-eval' | 'unsafe-hashes' | 'unsafe-inline' | 'none';
39
+
40
+ export type Source = HostSource | SchemeSource | CryptoSource | BaseSource;
41
+ type Sources = Source[];
42
+
43
+ type ActionSource = 'strict-dynamic' | 'report-sample';
44
+
45
+ type FrameSource = HostSource | SchemeSource | 'self' | 'none';
46
+
47
+ type HttpDelineator = '/' | '?' | '#' | '\\';
48
+ type UriPath = `${HttpDelineator}${string}`;
49
+
50
+ export type CspDirectives = {
51
+ 'child-src'?: Sources;
52
+ 'default-src'?: Array<Source | ActionSource>;
53
+ 'frame-src'?: Sources;
54
+ 'worker-src'?: Sources;
55
+ 'connect-src'?: Sources;
56
+ 'font-src'?: Sources;
57
+ 'img-src'?: Sources;
58
+ 'manifest-src'?: Sources;
59
+ 'media-src'?: Sources;
60
+ 'object-src'?: Sources;
61
+ 'prefetch-src'?: Sources;
62
+ 'script-src'?: Array<Source | ActionSource>;
63
+ 'script-src-elem'?: Sources;
64
+ 'script-src-attr'?: Sources;
65
+ 'style-src'?: Array<Source | ActionSource>;
66
+ 'style-src-elem'?: Sources;
67
+ 'style-src-attr'?: Sources;
68
+ 'base-uri'?: Array<Source | ActionSource>;
69
+ sandbox?: Array<
70
+ | 'allow-downloads-without-user-activation'
71
+ | 'allow-forms'
72
+ | 'allow-modals'
73
+ | 'allow-orientation-lock'
74
+ | 'allow-pointer-lock'
75
+ | 'allow-popups'
76
+ | 'allow-popups-to-escape-sandbox'
77
+ | 'allow-presentation'
78
+ | 'allow-same-origin'
79
+ | 'allow-scripts'
80
+ | 'allow-storage-access-by-user-activation'
81
+ | 'allow-top-navigation'
82
+ | 'allow-top-navigation-by-user-activation'
83
+ >;
84
+ 'form-action'?: Array<Source | ActionSource>;
85
+ 'frame-ancestors'?: Array<HostSource | SchemeSource | FrameSource>;
86
+ 'navigate-to'?: Array<Source | ActionSource>;
87
+ 'report-uri'?: UriPath[];
88
+ 'report-to'?: string[];
89
+
90
+ 'require-trusted-types-for'?: Array<'script'>;
91
+ 'trusted-types'?: Array<'none' | 'allow-duplicates' | '*' | string>;
92
+ 'upgrade-insecure-requests'?: boolean;
93
+
94
+ /** @deprecated */
95
+ 'require-sri-for'?: Array<'script' | 'style' | 'script style'>;
96
+
97
+ /** @deprecated */
98
+ 'block-all-mixed-content'?: boolean;
99
+
100
+ /** @deprecated */
101
+ 'plugin-types'?: Array<`${string}/${string}` | 'none'>;
102
+
103
+ /** @deprecated */
104
+ referrer?: Array<
105
+ | 'no-referrer'
106
+ | 'no-referrer-when-downgrade'
107
+ | 'origin'
108
+ | 'origin-when-cross-origin'
109
+ | 'same-origin'
110
+ | 'strict-origin'
111
+ | 'strict-origin-when-cross-origin'
112
+ | 'unsafe-url'
113
+ | 'none'
114
+ >;
115
+ };
@@ -0,0 +1,39 @@
1
+ import { RequestEvent } from './hooks';
2
+ import { Either, JSONObject, JSONValue, MaybePromise, ResponseHeaders } from './helper';
3
+
4
+ type Body = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
5
+
6
+ export interface EndpointOutput<Output extends Body = Body> {
7
+ status?: number;
8
+ headers?: Headers | Partial<ResponseHeaders>;
9
+ body?: Output;
10
+ }
11
+
12
+ export interface Fallthrough {
13
+ fallthrough: true;
14
+ }
15
+
16
+ export interface RequestHandler<Output extends Body = Body> {
17
+ (event: RequestEvent): MaybePromise<
18
+ Either<Output extends Response ? Response : EndpointOutput<Output>, Fallthrough>
19
+ >;
20
+ }
21
+
22
+ export interface ShadowEndpointOutput<Output extends JSONObject = JSONObject> {
23
+ status?: number;
24
+ headers?: Partial<ResponseHeaders>;
25
+ body?: Output;
26
+ }
27
+
28
+ export interface ShadowRequestHandler<Output extends JSONObject = JSONObject> {
29
+ (event: RequestEvent): MaybePromise<Either<ShadowEndpointOutput<Output>, Fallthrough>>;
30
+ }
31
+
32
+ export interface ShadowData {
33
+ fallthrough?: boolean;
34
+ status?: number;
35
+ error?: Error;
36
+ redirect?: string;
37
+ cookies?: string[];
38
+ body?: JSONObject;
39
+ }
@@ -0,0 +1,23 @@
1
+ type ToJSON = { toJSON(...args: any[]): Exclude<JSONValue, ToJSON> };
2
+
3
+ export type JSONObject = { [key: string]: JSONValue };
4
+ export type JSONValue = string | number | boolean | null | ToJSON | JSONValue[] | JSONObject;
5
+
6
+ /** `string[]` is only for set-cookie, everything else must be type of `string` */
7
+ export type ResponseHeaders = Record<string, string | string[]>;
8
+
9
+ // <-- Utility Types -->
10
+ type Only<T, U> = { [P in keyof T]: T[P] } & { [P in Exclude<keyof U, keyof T>]?: never };
11
+
12
+ export type Either<T, U> = Only<T, U> | Only<U, T>;
13
+ export type MaybePromise<T> = T | Promise<T>;
14
+ export type RecursiveRequired<T> = {
15
+ // Recursive implementation of TypeScript's Required utility type.
16
+ // Will recursively continue until it reaches primitive or union
17
+ // with a Function in it, except those commented below
18
+ [K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
19
+ ? RecursiveRequired<T[K]> // recursively continue through.
20
+ : K extends 'vite' // If it reaches the 'vite' key
21
+ ? Extract<T[K], Function> // only take the Function type.
22
+ : T[K]; // Use the exact type for everything else
23
+ };
@@ -0,0 +1,34 @@
1
+ import { MaybePromise } from './helper';
2
+
3
+ export type StrictBody = string | Uint8Array;
4
+
5
+ export interface RequestEvent {
6
+ request: Request;
7
+ url: URL;
8
+ params: Record<string, string>;
9
+ locals: App.Locals;
10
+ platform: Readonly<App.Platform>;
11
+ }
12
+
13
+ export interface GetSession {
14
+ (event: RequestEvent): MaybePromise<App.Session>;
15
+ }
16
+
17
+ export interface ResolveOpts {
18
+ ssr?: boolean;
19
+ }
20
+
21
+ export interface Handle {
22
+ (input: {
23
+ event: RequestEvent;
24
+ resolve(event: RequestEvent, opts?: ResolveOpts): MaybePromise<Response>;
25
+ }): MaybePromise<Response>;
26
+ }
27
+
28
+ export interface HandleError {
29
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
30
+ }
31
+
32
+ export interface ExternalFetch {
33
+ (req: Request): Promise<Response>;
34
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="vite/client" />
3
+
4
+ import './ambient-modules';
5
+
6
+ export { App, 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 { ExternalFetch, GetSession, Handle, HandleError, RequestEvent, ResolveOpts } from './hooks';
@@ -0,0 +1,260 @@
1
+ import { OutputAsset, OutputChunk } from 'rollup';
2
+ import { ValidatedConfig } from './config';
3
+ import { InternalApp, SSRManifest } from './app';
4
+ import { Fallthrough, RequestHandler, ShadowRequestHandler } from './endpoint';
5
+ import { Either } from './helper';
6
+ import { ExternalFetch, GetSession, Handle, HandleError, RequestEvent } from './hooks';
7
+ import { Load } from './page';
8
+
9
+ export interface PrerenderDependency {
10
+ response: Response;
11
+ body: null | string | Uint8Array;
12
+ }
13
+
14
+ export interface PrerenderOptions {
15
+ fallback?: string;
16
+ all: boolean;
17
+ dependencies: Map<string, PrerenderDependency>;
18
+ }
19
+
20
+ export interface AppModule {
21
+ App: typeof InternalApp;
22
+
23
+ override(options: {
24
+ paths: {
25
+ base: string;
26
+ assets: string;
27
+ };
28
+ prerendering: boolean;
29
+ protocol?: 'http' | 'https';
30
+ read(file: string): Buffer;
31
+ }): void;
32
+ }
33
+
34
+ export interface Logger {
35
+ (msg: string): void;
36
+ success(msg: string): void;
37
+ error(msg: string): void;
38
+ warn(msg: string): void;
39
+ minor(msg: string): void;
40
+ info(msg: string): void;
41
+ }
42
+
43
+ export interface SSRComponent {
44
+ router?: boolean;
45
+ hydrate?: boolean;
46
+ prerender?: boolean;
47
+ load: Load;
48
+ default: {
49
+ render(props: Record<string, any>): {
50
+ html: string;
51
+ head: string;
52
+ css: {
53
+ code: string;
54
+ map: any; // TODO
55
+ };
56
+ };
57
+ };
58
+ }
59
+
60
+ export type SSRComponentLoader = () => Promise<SSRComponent>;
61
+
62
+ export type CSRComponent = any; // TODO
63
+
64
+ export type CSRComponentLoader = () => Promise<CSRComponent>;
65
+
66
+ export interface SSRPagePart {
67
+ id: string;
68
+ load: SSRComponentLoader;
69
+ }
70
+
71
+ export type GetParams = (match: RegExpExecArray) => Record<string, string>;
72
+
73
+ export interface SSRPage {
74
+ type: 'page';
75
+ pattern: RegExp;
76
+ params: GetParams;
77
+ shadow:
78
+ | null
79
+ | (() => Promise<{
80
+ [method: string]: ShadowRequestHandler;
81
+ }>);
82
+ /**
83
+ * plan a is to render 1 or more layout components followed by a leaf component.
84
+ */
85
+ a: number[];
86
+ /**
87
+ * plan b — if one of them components fails in `load` we backtrack until we find
88
+ * the nearest error component.
89
+ */
90
+ b: number[];
91
+ }
92
+
93
+ export interface SSREndpoint {
94
+ type: 'endpoint';
95
+ pattern: RegExp;
96
+ params: GetParams;
97
+ load(): Promise<{
98
+ [method: string]: RequestHandler;
99
+ }>;
100
+ }
101
+
102
+ export type SSRRoute = SSREndpoint | SSRPage;
103
+
104
+ type HasShadow = 1;
105
+ export type CSRRoute = [RegExp, CSRComponentLoader[], CSRComponentLoader[], GetParams?, HasShadow?];
106
+
107
+ export type SSRNodeLoader = () => Promise<SSRNode>;
108
+
109
+ export interface Hooks {
110
+ externalFetch: ExternalFetch;
111
+ getSession: GetSession;
112
+ handle: Handle;
113
+ handleError: HandleError;
114
+ }
115
+
116
+ export interface SSRNode {
117
+ module: SSRComponent;
118
+ /** client-side module URL for this component */
119
+ entry: string;
120
+ /** external CSS files */
121
+ css: string[];
122
+ /** external JS files */
123
+ js: string[];
124
+ /** inlined styles */
125
+ styles?: Record<string, string>;
126
+ }
127
+
128
+ export interface SSROptions {
129
+ amp: boolean;
130
+ csp: ValidatedConfig['kit']['csp'];
131
+ dev: boolean;
132
+ floc: boolean;
133
+ get_stack: (error: Error) => string | undefined;
134
+ handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
135
+ hooks: Hooks;
136
+ hydrate: boolean;
137
+ manifest: SSRManifest;
138
+ method_override: MethodOverride;
139
+ paths: {
140
+ base: string;
141
+ assets: string;
142
+ };
143
+ prefix: string;
144
+ prerender: boolean;
145
+ read(file: string): Buffer;
146
+ root: SSRComponent['default'];
147
+ router: boolean;
148
+ service_worker?: string;
149
+ template({
150
+ head,
151
+ body,
152
+ assets,
153
+ nonce
154
+ }: {
155
+ head: string;
156
+ body: string;
157
+ assets: string;
158
+ nonce: string;
159
+ }): string;
160
+ template_contains_nonce: boolean;
161
+ trailing_slash: TrailingSlash;
162
+ }
163
+
164
+ export interface SSRState {
165
+ fetched?: string;
166
+ initiator?: SSRPage | null;
167
+ platform?: any;
168
+ prerender?: PrerenderOptions;
169
+ fallback?: string;
170
+ }
171
+
172
+ export interface Asset {
173
+ file: string;
174
+ size: number;
175
+ type: string | null;
176
+ }
177
+
178
+ export interface RouteSegment {
179
+ content: string;
180
+ dynamic: boolean;
181
+ rest: boolean;
182
+ }
183
+
184
+ export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
185
+
186
+ export interface PageData {
187
+ type: 'page';
188
+ key: string;
189
+ shadow: string | null;
190
+ segments: RouteSegment[];
191
+ pattern: RegExp;
192
+ params: string[];
193
+ path: string;
194
+ a: string[];
195
+ b: string[];
196
+ }
197
+
198
+ export interface EndpointData {
199
+ type: 'endpoint';
200
+ key: string;
201
+ segments: RouteSegment[];
202
+ pattern: RegExp;
203
+ params: string[];
204
+ file: string;
205
+ }
206
+
207
+ export type RouteData = PageData | EndpointData;
208
+
209
+ export interface ManifestData {
210
+ assets: Asset[];
211
+ layout: string;
212
+ error: string;
213
+ components: string[];
214
+ routes: RouteData[];
215
+ }
216
+
217
+ export interface BuildData {
218
+ app_dir: string;
219
+ manifest_data: ManifestData;
220
+ service_worker: string | null;
221
+ client: {
222
+ assets: OutputAsset[];
223
+ chunks: OutputChunk[];
224
+ entry: {
225
+ file: string;
226
+ js: string[];
227
+ css: string[];
228
+ };
229
+ vite_manifest: import('vite').Manifest;
230
+ };
231
+ server: {
232
+ chunks: OutputChunk[];
233
+ methods: Record<string, HttpMethod[]>;
234
+ vite_manifest: import('vite').Manifest;
235
+ };
236
+ static: string[];
237
+ entries: string[];
238
+ }
239
+
240
+ export type NormalizedLoadOutput = Either<
241
+ {
242
+ status: number;
243
+ error?: Error;
244
+ redirect?: string;
245
+ props?: Record<string, any> | Promise<Record<string, any>>;
246
+ stuff?: Record<string, any>;
247
+ maxage?: number;
248
+ },
249
+ Fallthrough
250
+ >;
251
+
252
+ export type TrailingSlash = 'never' | 'always' | 'ignore';
253
+ export interface MethodOverride {
254
+ parameter: string;
255
+ allowed: string[];
256
+ }
257
+
258
+ export interface Respond {
259
+ (request: Request, options: SSROptions, state?: SSRState): Promise<Response>;
260
+ }
@@ -0,0 +1,33 @@
1
+ import { Fallthrough } from './endpoint';
2
+ import { Either, MaybePromise } from './helper';
3
+
4
+ export interface LoadInput<Params = Record<string, string>> {
5
+ url: URL;
6
+ params: Params;
7
+ props: Record<string, any>;
8
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
9
+ session: App.Session;
10
+ stuff: Partial<App.Stuff>;
11
+ }
12
+
13
+ export interface ErrorLoadInput<Params = Record<string, string>> extends LoadInput<Params> {
14
+ status?: number;
15
+ error?: Error;
16
+ }
17
+
18
+ export interface LoadOutput<Props = Record<string, any>> {
19
+ status?: number;
20
+ error?: string | Error;
21
+ redirect?: string;
22
+ props?: Props;
23
+ stuff?: Partial<App.Stuff>;
24
+ maxage?: number;
25
+ }
26
+
27
+ export interface Load<Params = Record<string, string>, Props = Record<string, any>> {
28
+ (input: LoadInput<Params>): MaybePromise<Either<Fallthrough, LoadOutput<Props>>>;
29
+ }
30
+
31
+ export interface ErrorLoad<Params = Record<string, string>, Props = Record<string, any>> {
32
+ (input: ErrorLoadInput<Params>): MaybePromise<LoadOutput<Props>>;
33
+ }