@sveltejs/kit 1.0.0-next.35 → 1.0.0-next.352

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 (69) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +16 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1787 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/paths.js +13 -0
  11. package/assets/server/index.js +3380 -0
  12. package/dist/chunks/constants.js +663 -0
  13. package/dist/chunks/filesystem.js +110 -0
  14. package/dist/chunks/index.js +1363 -0
  15. package/dist/chunks/index2.js +120 -0
  16. package/dist/chunks/index3.js +183 -0
  17. package/dist/chunks/index4.js +215 -0
  18. package/dist/chunks/index5.js +15748 -0
  19. package/dist/chunks/misc.js +78 -0
  20. package/dist/chunks/multipart-parser.js +444 -0
  21. package/dist/chunks/object.js +83 -0
  22. package/dist/chunks/plugin.js +558 -0
  23. package/dist/chunks/sync.js +856 -0
  24. package/dist/chunks/write_tsconfig.js +169 -0
  25. package/dist/cli.js +1028 -87
  26. package/dist/hooks.js +28 -0
  27. package/dist/node/polyfills.js +6654 -0
  28. package/dist/node.js +301 -0
  29. package/package.json +95 -55
  30. package/types/ambient.d.ts +307 -0
  31. package/types/index.d.ts +294 -0
  32. package/types/internal.d.ts +326 -0
  33. package/types/private.d.ts +235 -0
  34. package/CHANGELOG.md +0 -371
  35. package/assets/runtime/app/navigation.js +0 -23
  36. package/assets/runtime/app/navigation.js.map +0 -1
  37. package/assets/runtime/app/paths.js +0 -2
  38. package/assets/runtime/app/paths.js.map +0 -1
  39. package/assets/runtime/app/stores.js +0 -78
  40. package/assets/runtime/app/stores.js.map +0 -1
  41. package/assets/runtime/internal/singletons.js +0 -15
  42. package/assets/runtime/internal/singletons.js.map +0 -1
  43. package/assets/runtime/internal/start.js +0 -614
  44. package/assets/runtime/internal/start.js.map +0 -1
  45. package/assets/runtime/utils-85ebcc60.js +0 -18
  46. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  47. package/dist/api.js +0 -28
  48. package/dist/api.js.map +0 -1
  49. package/dist/cli.js.map +0 -1
  50. package/dist/create_app.js +0 -502
  51. package/dist/create_app.js.map +0 -1
  52. package/dist/index.js +0 -327
  53. package/dist/index.js.map +0 -1
  54. package/dist/index2.js +0 -3497
  55. package/dist/index2.js.map +0 -1
  56. package/dist/index3.js +0 -296
  57. package/dist/index3.js.map +0 -1
  58. package/dist/index4.js +0 -311
  59. package/dist/index4.js.map +0 -1
  60. package/dist/index5.js +0 -221
  61. package/dist/index5.js.map +0 -1
  62. package/dist/index6.js +0 -730
  63. package/dist/index6.js.map +0 -1
  64. package/dist/renderer.js +0 -2429
  65. package/dist/renderer.js.map +0 -1
  66. package/dist/standard.js +0 -100
  67. package/dist/standard.js.map +0 -1
  68. package/dist/utils.js +0 -61
  69. package/dist/utils.js.map +0 -1
@@ -0,0 +1,326 @@
1
+ import { OutputAsset, OutputChunk } from 'rollup';
2
+ import {
3
+ Config,
4
+ ExternalFetch,
5
+ GetSession,
6
+ Handle,
7
+ HandleError,
8
+ KitConfig,
9
+ Load,
10
+ RequestEvent,
11
+ RequestHandler,
12
+ ResolveOptions,
13
+ Server,
14
+ SSRManifest
15
+ } from './index';
16
+ import {
17
+ HttpMethod,
18
+ JSONObject,
19
+ MaybePromise,
20
+ RequestOptions,
21
+ ResponseHeaders,
22
+ TrailingSlash
23
+ } from './private';
24
+
25
+ export interface ServerModule {
26
+ Server: typeof InternalServer;
27
+
28
+ override(options: {
29
+ paths: {
30
+ base: string;
31
+ assets: string;
32
+ };
33
+ prerendering: boolean;
34
+ protocol?: 'http' | 'https';
35
+ read(file: string): Buffer;
36
+ }): void;
37
+ }
38
+
39
+ export interface Asset {
40
+ file: string;
41
+ size: number;
42
+ type: string | null;
43
+ }
44
+
45
+ export interface BuildData {
46
+ app_dir: string;
47
+ manifest_data: ManifestData;
48
+ service_worker: string | null;
49
+ client: {
50
+ assets: OutputAsset[];
51
+ chunks: OutputChunk[];
52
+ entry: {
53
+ file: string;
54
+ js: string[];
55
+ css: string[];
56
+ };
57
+ vite_manifest: import('vite').Manifest;
58
+ };
59
+ server: {
60
+ chunks: OutputChunk[];
61
+ methods: Record<string, HttpMethod[]>;
62
+ vite_manifest: import('vite').Manifest;
63
+ };
64
+ }
65
+
66
+ export type CSRComponent = any; // TODO
67
+
68
+ export type CSRComponentLoader = () => Promise<CSRComponent>;
69
+
70
+ export type CSRRoute = {
71
+ id: string;
72
+ exec: (path: string) => undefined | Record<string, string>;
73
+ a: CSRComponentLoader[];
74
+ b: CSRComponentLoader[];
75
+ has_shadow: boolean;
76
+ };
77
+
78
+ export interface EndpointData {
79
+ type: 'endpoint';
80
+ id: string;
81
+ pattern: RegExp;
82
+ file: string;
83
+ }
84
+
85
+ export type GetParams = (match: RegExpExecArray) => Record<string, string>;
86
+
87
+ export interface Hooks {
88
+ externalFetch: ExternalFetch;
89
+ getSession: GetSession;
90
+ handle: Handle;
91
+ handleError: HandleError;
92
+ }
93
+
94
+ export class InternalServer extends Server {
95
+ respond(
96
+ request: Request,
97
+ options: RequestOptions & {
98
+ prerendering?: PrerenderOptions;
99
+ }
100
+ ): Promise<Response>;
101
+ }
102
+
103
+ export interface ManifestData {
104
+ assets: Asset[];
105
+ components: string[];
106
+ routes: RouteData[];
107
+ matchers: Record<string, string>;
108
+ }
109
+
110
+ export interface MethodOverride {
111
+ parameter: string;
112
+ allowed: string[];
113
+ }
114
+
115
+ export type NormalizedLoadOutput = {
116
+ status: number;
117
+ error?: Error;
118
+ redirect?: string;
119
+ props?: Record<string, any> | Promise<Record<string, any>>;
120
+ stuff?: Record<string, any>;
121
+ cache?: NormalizedLoadOutputCache;
122
+ dependencies?: string[];
123
+ };
124
+
125
+ export interface NormalizedLoadOutputCache {
126
+ maxage: number;
127
+ private?: boolean;
128
+ }
129
+
130
+ export interface PageData {
131
+ type: 'page';
132
+ id: string;
133
+ shadow: string | null;
134
+ pattern: RegExp;
135
+ path: string;
136
+ a: Array<string | undefined>;
137
+ b: Array<string | undefined>;
138
+ }
139
+
140
+ export type PayloadScriptAttributes =
141
+ | { type: 'data'; url: string; body?: string }
142
+ | { type: 'props' };
143
+
144
+ export interface PrerenderDependency {
145
+ response: Response;
146
+ body: null | string | Uint8Array;
147
+ }
148
+
149
+ export interface PrerenderOptions {
150
+ fallback?: boolean;
151
+ dependencies: Map<string, PrerenderDependency>;
152
+ }
153
+
154
+ export type RecursiveRequired<T> = {
155
+ // Recursive implementation of TypeScript's Required utility type.
156
+ // Will recursively continue until it reaches primitive or union
157
+ // with a Function in it, except those commented below
158
+ [K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
159
+ ? RecursiveRequired<T[K]> // recursively continue through.
160
+ : K extends 'vite' // If it reaches the 'vite' key
161
+ ? Extract<T[K], Function> // only take the Function type.
162
+ : T[K]; // Use the exact type for everything else
163
+ };
164
+
165
+ export type RequiredResolveOptions = Required<ResolveOptions>;
166
+
167
+ export interface Respond {
168
+ (request: Request, options: SSROptions, state: SSRState): Promise<Response>;
169
+ }
170
+
171
+ export type RouteData = PageData | EndpointData;
172
+
173
+ export interface ShadowEndpointOutput<Output extends JSONObject = JSONObject> {
174
+ status?: number;
175
+ headers?: Partial<ResponseHeaders>;
176
+ body?: Output;
177
+ }
178
+
179
+ /**
180
+ * The route key of a page with a matching endpoint — used to ensure the
181
+ * client loads data from the right endpoint during client-side navigation
182
+ * rather than a different route that happens to match the path
183
+ */
184
+ type ShadowKey = string;
185
+
186
+ export interface ShadowRequestHandler<Output extends JSONObject = JSONObject> {
187
+ (event: RequestEvent): MaybePromise<ShadowEndpointOutput<Output>>;
188
+ }
189
+
190
+ export interface ShadowData {
191
+ status?: number;
192
+ error?: Error;
193
+ redirect?: string;
194
+ cookies?: string[];
195
+ body?: JSONObject;
196
+ }
197
+
198
+ export interface SSRComponent {
199
+ router?: boolean;
200
+ hydrate?: boolean;
201
+ prerender?: boolean;
202
+ load: Load;
203
+ default: {
204
+ render(props: Record<string, any>): {
205
+ html: string;
206
+ head: string;
207
+ css: {
208
+ code: string;
209
+ map: any; // TODO
210
+ };
211
+ };
212
+ };
213
+ }
214
+
215
+ export type SSRComponentLoader = () => Promise<SSRComponent>;
216
+
217
+ export interface SSREndpoint {
218
+ type: 'endpoint';
219
+ id: string;
220
+ pattern: RegExp;
221
+ names: string[];
222
+ types: string[];
223
+ load(): Promise<{
224
+ [method: string]: RequestHandler;
225
+ }>;
226
+ }
227
+
228
+ export interface SSRNode {
229
+ module: SSRComponent;
230
+ /** index into the `components` array in client-manifest.js */
231
+ index: number;
232
+ /** client-side module URL for this component */
233
+ entry: string;
234
+ /** external CSS files */
235
+ css: string[];
236
+ /** external JS files */
237
+ js: string[];
238
+ /** inlined styles */
239
+ styles?: Record<string, string>;
240
+ }
241
+
242
+ export type SSRNodeLoader = () => Promise<SSRNode>;
243
+
244
+ export interface SSROptions {
245
+ csp: ValidatedConfig['kit']['csp'];
246
+ dev: boolean;
247
+ floc: boolean;
248
+ get_stack: (error: Error) => string | undefined;
249
+ handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
250
+ hooks: Hooks;
251
+ hydrate: boolean;
252
+ manifest: SSRManifest;
253
+ method_override: MethodOverride;
254
+ paths: {
255
+ base: string;
256
+ assets: string;
257
+ };
258
+ prefix: string;
259
+ prerender: {
260
+ default: boolean;
261
+ enabled: boolean;
262
+ };
263
+ read(file: string): Buffer;
264
+ root: SSRComponent['default'];
265
+ router: boolean;
266
+ service_worker?: string;
267
+ template({
268
+ head,
269
+ body,
270
+ assets,
271
+ nonce
272
+ }: {
273
+ head: string;
274
+ body: string;
275
+ assets: string;
276
+ nonce: string;
277
+ }): string;
278
+ template_contains_nonce: boolean;
279
+ trailing_slash: TrailingSlash;
280
+ }
281
+
282
+ export interface SSRPage {
283
+ type: 'page';
284
+ id: string;
285
+ pattern: RegExp;
286
+ names: string[];
287
+ types: string[];
288
+ shadow:
289
+ | null
290
+ | (() => Promise<{
291
+ [method: string]: ShadowRequestHandler;
292
+ }>);
293
+ /**
294
+ * plan a is to render 1 or more layout components followed by a leaf component.
295
+ */
296
+ a: Array<number | undefined>;
297
+ /**
298
+ * plan b — if one of them components fails in `load` we backtrack until we find
299
+ * the nearest error component.
300
+ */
301
+ b: Array<number | undefined>;
302
+ }
303
+
304
+ export interface SSRPagePart {
305
+ id: string;
306
+ load: SSRComponentLoader;
307
+ }
308
+
309
+ export type SSRRoute = SSREndpoint | SSRPage;
310
+
311
+ export interface SSRState {
312
+ fallback?: string;
313
+ getClientAddress: () => string;
314
+ initiator?: SSRPage | null;
315
+ platform?: any;
316
+ prerendering?: PrerenderOptions;
317
+ }
318
+
319
+ export type StrictBody = string | Uint8Array;
320
+
321
+ export type ValidatedConfig = RecursiveRequired<Config>;
322
+
323
+ export type ValidatedKitConfig = RecursiveRequired<KitConfig>;
324
+
325
+ export * from './index';
326
+ export * from './private';
@@ -0,0 +1,235 @@
1
+ // This module contains types that are visible in the documentation,
2
+ // but which cannot be imported from `@sveltejs/kit`. Care should
3
+ // be taken to avoid breaking changes when editing this file
4
+
5
+ export interface AdapterEntry {
6
+ /**
7
+ * A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
8
+ * For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
9
+ * be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
10
+ */
11
+ id: string;
12
+
13
+ /**
14
+ * A function that compares the candidate route with the current route to determine
15
+ * if it should be treated as a fallback for the current route. For example, `/foo/[c]`
16
+ * is a fallback for `/foo/a-[b]`, and `/[...catchall]` is a fallback for all routes
17
+ */
18
+ filter: (route: RouteDefinition) => boolean;
19
+
20
+ /**
21
+ * A function that is invoked once the entry has been created. This is where you
22
+ * should write the function to the filesystem and generate redirect manifests.
23
+ */
24
+ complete: (entry: {
25
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
26
+ }) => MaybePromise<void>;
27
+ }
28
+
29
+ export type BodyValidator<T> = {
30
+ [P in keyof T]: T[P] extends { [k: string]: unknown }
31
+ ? BodyValidator<T[P]> // recurse when T[P] is an object
32
+ : T[P] extends BigInt | Function | Symbol
33
+ ? never
34
+ : T[P];
35
+ };
36
+
37
+ // Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts
38
+ //
39
+ // MIT License
40
+ //
41
+ // Copyright (c) 2021-present, Joshua Hemphill
42
+ // Copyright (c) 2021, Tecnico Corporation
43
+ //
44
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
45
+ // of this software and associated documentation files (the "Software"), to deal
46
+ // in the Software without restriction, including without limitation the rights
47
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
+ // copies of the Software, and to permit persons to whom the Software is
49
+ // furnished to do so, subject to the following conditions:
50
+ //
51
+ // The above copyright notice and this permission notice shall be included in all
52
+ // copies or substantial portions of the Software.
53
+ //
54
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60
+ // SOFTWARE.
61
+
62
+ export namespace Csp {
63
+ type ActionSource = 'strict-dynamic' | 'report-sample';
64
+ type BaseSource = 'self' | 'unsafe-eval' | 'unsafe-hashes' | 'unsafe-inline' | 'none';
65
+ type CryptoSource = `${'nonce' | 'sha256' | 'sha384' | 'sha512'}-${string}`;
66
+ type FrameSource = HostSource | SchemeSource | 'self' | 'none';
67
+ type HostNameScheme = `${string}.${string}` | 'localhost';
68
+ type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`;
69
+ type HostProtocolSchemes = `${string}://` | '';
70
+ type HttpDelineator = '/' | '?' | '#' | '\\';
71
+ type PortScheme = `:${number}` | '' | ':*';
72
+ type SchemeSource = 'http:' | 'https:' | 'data:' | 'mediastream:' | 'blob:' | 'filesystem:';
73
+ type Source = HostSource | SchemeSource | CryptoSource | BaseSource;
74
+ type Sources = Source[];
75
+ type UriPath = `${HttpDelineator}${string}`;
76
+ }
77
+
78
+ export interface CspDirectives {
79
+ 'child-src'?: Csp.Sources;
80
+ 'default-src'?: Array<Csp.Source | Csp.ActionSource>;
81
+ 'frame-src'?: Csp.Sources;
82
+ 'worker-src'?: Csp.Sources;
83
+ 'connect-src'?: Csp.Sources;
84
+ 'font-src'?: Csp.Sources;
85
+ 'img-src'?: Csp.Sources;
86
+ 'manifest-src'?: Csp.Sources;
87
+ 'media-src'?: Csp.Sources;
88
+ 'object-src'?: Csp.Sources;
89
+ 'prefetch-src'?: Csp.Sources;
90
+ 'script-src'?: Array<Csp.Source | Csp.ActionSource>;
91
+ 'script-src-elem'?: Csp.Sources;
92
+ 'script-src-attr'?: Csp.Sources;
93
+ 'style-src'?: Array<Csp.Source | Csp.ActionSource>;
94
+ 'style-src-elem'?: Csp.Sources;
95
+ 'style-src-attr'?: Csp.Sources;
96
+ 'base-uri'?: Array<Csp.Source | Csp.ActionSource>;
97
+ sandbox?: Array<
98
+ | 'allow-downloads-without-user-activation'
99
+ | 'allow-forms'
100
+ | 'allow-modals'
101
+ | 'allow-orientation-lock'
102
+ | 'allow-pointer-lock'
103
+ | 'allow-popups'
104
+ | 'allow-popups-to-escape-sandbox'
105
+ | 'allow-presentation'
106
+ | 'allow-same-origin'
107
+ | 'allow-scripts'
108
+ | 'allow-storage-access-by-user-activation'
109
+ | 'allow-top-navigation'
110
+ | 'allow-top-navigation-by-user-activation'
111
+ >;
112
+ 'form-action'?: Array<Csp.Source | Csp.ActionSource>;
113
+ 'frame-ancestors'?: Array<Csp.HostSource | Csp.SchemeSource | Csp.FrameSource>;
114
+ 'navigate-to'?: Array<Csp.Source | Csp.ActionSource>;
115
+ 'report-uri'?: Csp.UriPath[];
116
+ 'report-to'?: string[];
117
+
118
+ 'require-trusted-types-for'?: Array<'script'>;
119
+ 'trusted-types'?: Array<'none' | 'allow-duplicates' | '*' | string>;
120
+ 'upgrade-insecure-requests'?: boolean;
121
+
122
+ /** @deprecated */
123
+ 'require-sri-for'?: Array<'script' | 'style' | 'script style'>;
124
+
125
+ /** @deprecated */
126
+ 'block-all-mixed-content'?: boolean;
127
+
128
+ /** @deprecated */
129
+ 'plugin-types'?: Array<`${string}/${string}` | 'none'>;
130
+
131
+ /** @deprecated */
132
+ referrer?: Array<
133
+ | 'no-referrer'
134
+ | 'no-referrer-when-downgrade'
135
+ | 'origin'
136
+ | 'origin-when-cross-origin'
137
+ | 'same-origin'
138
+ | 'strict-origin'
139
+ | 'strict-origin-when-cross-origin'
140
+ | 'unsafe-url'
141
+ | 'none'
142
+ >;
143
+ }
144
+
145
+ export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
146
+
147
+ export interface JSONObject {
148
+ [key: string]: JSONValue;
149
+ }
150
+
151
+ export type JSONValue =
152
+ | string
153
+ | number
154
+ | boolean
155
+ | null
156
+ | undefined
157
+ | ToJSON
158
+ | JSONValue[]
159
+ | JSONObject;
160
+
161
+ export interface Logger {
162
+ (msg: string): void;
163
+ success(msg: string): void;
164
+ error(msg: string): void;
165
+ warn(msg: string): void;
166
+ minor(msg: string): void;
167
+ info(msg: string): void;
168
+ }
169
+
170
+ export type MaybePromise<T> = T | Promise<T>;
171
+
172
+ export interface Prerendered {
173
+ pages: Map<
174
+ string,
175
+ {
176
+ /** The location of the .html file relative to the output directory */
177
+ file: string;
178
+ }
179
+ >;
180
+ assets: Map<
181
+ string,
182
+ {
183
+ /** The MIME type of the asset */
184
+ type: string;
185
+ }
186
+ >;
187
+ redirects: Map<
188
+ string,
189
+ {
190
+ status: number;
191
+ location: string;
192
+ }
193
+ >;
194
+ /** An array of prerendered paths (without trailing slashes, regardless of the trailingSlash config) */
195
+ paths: string[];
196
+ }
197
+
198
+ export interface PrerenderErrorHandler {
199
+ (details: {
200
+ status: number;
201
+ path: string;
202
+ referrer: string | null;
203
+ referenceType: 'linked' | 'fetched';
204
+ }): void;
205
+ }
206
+
207
+ export type PrerenderOnErrorValue = 'fail' | 'continue' | PrerenderErrorHandler;
208
+
209
+ export interface RequestOptions {
210
+ getClientAddress: () => string;
211
+ platform?: App.Platform;
212
+ }
213
+
214
+ /** `string[]` is only for set-cookie, everything else must be type of `string` */
215
+ export type ResponseHeaders = Record<string, string | number | string[]>;
216
+
217
+ export interface RouteDefinition {
218
+ id: string;
219
+ type: 'page' | 'endpoint';
220
+ pattern: RegExp;
221
+ segments: RouteSegment[];
222
+ methods: HttpMethod[];
223
+ }
224
+
225
+ export interface RouteSegment {
226
+ content: string;
227
+ dynamic: boolean;
228
+ rest: boolean;
229
+ }
230
+
231
+ export interface ToJSON {
232
+ toJSON(...args: any[]): Exclude<JSONValue, ToJSON>;
233
+ }
234
+
235
+ export type TrailingSlash = 'never' | 'always' | 'ignore';