@sveltejs/kit 1.0.0-next.33 → 1.0.0-next.330

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 (75) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +20 -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 +1689 -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 +3408 -0
  12. package/dist/chunks/amp_hook.js +56 -0
  13. package/dist/chunks/cert.js +28154 -0
  14. package/dist/chunks/constants.js +663 -0
  15. package/dist/chunks/filesystem.js +110 -0
  16. package/dist/chunks/index.js +514 -0
  17. package/dist/chunks/index2.js +1384 -0
  18. package/dist/chunks/index3.js +118 -0
  19. package/dist/chunks/index4.js +182 -0
  20. package/dist/chunks/index5.js +252 -0
  21. package/dist/chunks/index6.js +15741 -0
  22. package/dist/chunks/index7.js +4207 -0
  23. package/dist/chunks/misc.js +78 -0
  24. package/dist/chunks/multipart-parser.js +449 -0
  25. package/dist/chunks/object.js +83 -0
  26. package/dist/chunks/sync.js +848 -0
  27. package/dist/chunks/write_tsconfig.js +150 -0
  28. package/dist/cli.js +1025 -65
  29. package/dist/hooks.js +28 -0
  30. package/dist/install-fetch.js +6518 -0
  31. package/dist/node.js +94 -0
  32. package/package.json +96 -62
  33. package/svelte-kit.js +0 -1
  34. package/types/ambient.d.ts +298 -0
  35. package/types/index.d.ts +279 -0
  36. package/types/internal.d.ts +320 -0
  37. package/types/private.d.ts +246 -0
  38. package/CHANGELOG.md +0 -356
  39. package/assets/runtime/app/navigation.js +0 -23
  40. package/assets/runtime/app/navigation.js.map +0 -1
  41. package/assets/runtime/app/paths.js +0 -2
  42. package/assets/runtime/app/paths.js.map +0 -1
  43. package/assets/runtime/app/stores.js +0 -78
  44. package/assets/runtime/app/stores.js.map +0 -1
  45. package/assets/runtime/internal/singletons.js +0 -15
  46. package/assets/runtime/internal/singletons.js.map +0 -1
  47. package/assets/runtime/internal/start.js +0 -591
  48. package/assets/runtime/internal/start.js.map +0 -1
  49. package/assets/runtime/utils-85ebcc60.js +0 -18
  50. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  51. package/dist/api.js +0 -32
  52. package/dist/api.js.map +0 -1
  53. package/dist/cli.js.map +0 -1
  54. package/dist/create_app.js +0 -577
  55. package/dist/create_app.js.map +0 -1
  56. package/dist/index.js +0 -329
  57. package/dist/index.js.map +0 -1
  58. package/dist/index2.js +0 -14368
  59. package/dist/index2.js.map +0 -1
  60. package/dist/index3.js +0 -544
  61. package/dist/index3.js.map +0 -1
  62. package/dist/index4.js +0 -71
  63. package/dist/index4.js.map +0 -1
  64. package/dist/index5.js +0 -465
  65. package/dist/index5.js.map +0 -1
  66. package/dist/index6.js +0 -727
  67. package/dist/index6.js.map +0 -1
  68. package/dist/renderer.js +0 -2413
  69. package/dist/renderer.js.map +0 -1
  70. package/dist/standard.js +0 -100
  71. package/dist/standard.js.map +0 -1
  72. package/dist/utils.js +0 -57
  73. package/dist/utils.js.map +0 -1
  74. package/dist/vite.js +0 -317
  75. package/dist/vite.js.map +0 -1
@@ -0,0 +1,279 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="vite/client" />
3
+
4
+ import './ambient';
5
+
6
+ import { CompileOptions } from 'svelte/types/compiler/interfaces';
7
+ import {
8
+ AdapterEntry,
9
+ BodyValidator,
10
+ CspDirectives,
11
+ JSONValue,
12
+ Logger,
13
+ MaybePromise,
14
+ Prerendered,
15
+ PrerenderOnErrorValue,
16
+ RequestEvent,
17
+ RequestOptions,
18
+ ResolveOptions,
19
+ ResponseHeaders,
20
+ RouteDefinition,
21
+ TrailingSlash
22
+ } from './private';
23
+ import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal';
24
+
25
+ export interface Adapter {
26
+ name: string;
27
+ adapt(builder: Builder): MaybePromise<void>;
28
+ }
29
+
30
+ export interface Builder {
31
+ log: Logger;
32
+ rimraf(dir: string): void;
33
+ mkdirp(dir: string): void;
34
+
35
+ config: ValidatedConfig;
36
+ prerendered: Prerendered;
37
+
38
+ /**
39
+ * Create entry points that map to individual functions
40
+ * @param fn A function that groups a set of routes into an entry point
41
+ */
42
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
43
+
44
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
45
+
46
+ getBuildDirectory(name: string): string;
47
+ getClientDirectory(): string;
48
+ getServerDirectory(): string;
49
+ getStaticDirectory(): string;
50
+
51
+ /**
52
+ * @param dest the destination folder to which files should be copied
53
+ * @returns an array of paths corresponding to the files that have been created by the copy
54
+ */
55
+ writeClient(dest: string): string[];
56
+ /**
57
+ *
58
+ * @param dest
59
+ */
60
+ writePrerendered(
61
+ dest: string,
62
+ opts?: {
63
+ fallback?: string;
64
+ }
65
+ ): string[];
66
+ /**
67
+ * @param dest the destination folder to which files should be copied
68
+ * @returns an array of paths corresponding to the files that have been created by the copy
69
+ */
70
+ writeServer(dest: string): string[];
71
+ /**
72
+ * @param dest the destination folder to which files should be copied
73
+ * @returns an array of paths corresponding to the files that have been created by the copy
74
+ */
75
+ writeStatic(dest: string): string[];
76
+ /**
77
+ * @param from the source file or folder
78
+ * @param to the destination file or folder
79
+ * @param opts.filter a function to determine whether a file or folder should be copied
80
+ * @param opts.replace a map of strings to replace
81
+ * @returns an array of paths corresponding to the files that have been created by the copy
82
+ */
83
+ copy(
84
+ from: string,
85
+ to: string,
86
+ opts?: {
87
+ filter?: (basename: string) => boolean;
88
+ replace?: Record<string, string>;
89
+ }
90
+ ): string[];
91
+ }
92
+
93
+ export interface Config {
94
+ compilerOptions?: CompileOptions;
95
+ extensions?: string[];
96
+ kit?: {
97
+ adapter?: Adapter;
98
+ amp?: boolean;
99
+ appDir?: string;
100
+ browser?: {
101
+ hydrate?: boolean;
102
+ router?: boolean;
103
+ };
104
+ csp?: {
105
+ mode?: 'hash' | 'nonce' | 'auto';
106
+ directives?: CspDirectives;
107
+ };
108
+ endpointExtensions?: string[];
109
+ files?: {
110
+ assets?: string;
111
+ hooks?: string;
112
+ lib?: string;
113
+ params?: string;
114
+ routes?: string;
115
+ serviceWorker?: string;
116
+ template?: string;
117
+ };
118
+ floc?: boolean;
119
+ inlineStyleThreshold?: number;
120
+ methodOverride?: {
121
+ parameter?: string;
122
+ allowed?: string[];
123
+ };
124
+ outDir?: string;
125
+ package?: {
126
+ dir?: string;
127
+ emitTypes?: boolean;
128
+ exports?(filepath: string): boolean;
129
+ files?(filepath: string): boolean;
130
+ };
131
+ paths?: {
132
+ assets?: string;
133
+ base?: string;
134
+ };
135
+ prerender?: {
136
+ concurrency?: number;
137
+ crawl?: boolean;
138
+ default?: boolean;
139
+ enabled?: boolean;
140
+ entries?: Array<'*' | `/${string}`>;
141
+ onError?: PrerenderOnErrorValue;
142
+ };
143
+ routes?: (filepath: string) => boolean;
144
+ serviceWorker?: {
145
+ register?: boolean;
146
+ files?: (filepath: string) => boolean;
147
+ };
148
+ trailingSlash?: TrailingSlash;
149
+ version?: {
150
+ name?: string;
151
+ pollInterval?: number;
152
+ };
153
+ vite?: import('vite').UserConfig | (() => MaybePromise<import('vite').UserConfig>);
154
+ };
155
+ preprocess?: any;
156
+ }
157
+
158
+ export interface ExternalFetch {
159
+ (req: Request): Promise<Response>;
160
+ }
161
+
162
+ export interface GetSession {
163
+ (event: RequestEvent): MaybePromise<App.Session>;
164
+ }
165
+
166
+ export interface Handle {
167
+ (input: {
168
+ event: RequestEvent;
169
+ resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
170
+ }): MaybePromise<Response>;
171
+ }
172
+
173
+ export interface HandleError {
174
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
175
+ }
176
+
177
+ /**
178
+ * The `(input: LoadInput) => LoadOutput` `load` function exported from `<script context="module">` in a page or layout.
179
+ *
180
+ * Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the Params generic argument.
181
+ */
182
+ export interface Load<
183
+ Params extends Record<string, string> = Record<string, string>,
184
+ InputProps extends Record<string, any> = Record<string, any>,
185
+ OutputProps extends Record<string, any> = InputProps
186
+ > {
187
+ (input: LoadInput<Params, InputProps>): MaybePromise<LoadOutput<OutputProps>>;
188
+ }
189
+
190
+ export interface LoadInput<
191
+ Params extends Record<string, string> = Record<string, string>,
192
+ Props extends Record<string, any> = Record<string, any>
193
+ > {
194
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
195
+ params: Params;
196
+ props: Props;
197
+ routeId: string | null;
198
+ session: App.Session;
199
+ stuff: Partial<App.Stuff>;
200
+ url: URL;
201
+ status: number | null;
202
+ error: Error | null;
203
+ }
204
+
205
+ export interface LoadOutput<Props extends Record<string, any> = Record<string, any>> {
206
+ status?: number;
207
+ error?: string | Error;
208
+ redirect?: string;
209
+ props?: Props;
210
+ stuff?: Partial<App.Stuff>;
211
+ cache?: LoadOutputCache;
212
+ dependencies?: string[];
213
+ }
214
+
215
+ export interface LoadOutputCache {
216
+ maxage: number;
217
+ private?: boolean;
218
+ }
219
+
220
+ export interface Navigation {
221
+ from: URL;
222
+ to: URL;
223
+ }
224
+
225
+ export interface Page<Params extends Record<string, string> = Record<string, string>> {
226
+ url: URL;
227
+ params: Params;
228
+ routeId: string | null;
229
+ stuff: App.Stuff;
230
+ status: number;
231
+ error: Error | null;
232
+ }
233
+
234
+ export interface ParamMatcher {
235
+ (param: string): boolean;
236
+ }
237
+
238
+ /**
239
+ * A `(event: RequestEvent) => RequestHandlerOutput` function exported from an endpoint that corresponds to an HTTP verb (`get`, `put`, `patch`, etc) and handles requests with that method. Note that since 'delete' is a reserved word in JavaScript, delete handles are called `del` instead.
240
+ *
241
+ * Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the `Params` generic argument.
242
+ */
243
+ export interface RequestHandler<
244
+ Params extends Record<string, string> = Record<string, string>,
245
+ Output = ResponseBody
246
+ > {
247
+ (event: RequestEvent<Params>): MaybePromise<RequestHandlerOutput<Output>>;
248
+ }
249
+
250
+ export interface RequestHandlerOutput<Output = ResponseBody> {
251
+ status?: number;
252
+ headers?: Headers | Partial<ResponseHeaders>;
253
+ body?: Output extends ResponseBody ? Output : BodyValidator<Output>;
254
+ }
255
+
256
+ export type ResponseBody = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
257
+
258
+ export class Server {
259
+ constructor(manifest: SSRManifest);
260
+ respond(request: Request, options: RequestOptions): Promise<Response>;
261
+ }
262
+
263
+ export interface SSRManifest {
264
+ appDir: string;
265
+ assets: Set<string>;
266
+ mimeTypes: Record<string, string>;
267
+
268
+ /** private fields */
269
+ _: {
270
+ entry: {
271
+ file: string;
272
+ js: string[];
273
+ css: string[];
274
+ };
275
+ nodes: SSRNodeLoader[];
276
+ routes: SSRRoute[];
277
+ matchers: () => Promise<Record<string, ParamMatcher>>;
278
+ };
279
+ }
@@ -0,0 +1,320 @@
1
+ import { OutputAsset, OutputChunk } from 'rollup';
2
+ import {
3
+ Config,
4
+ ExternalFetch,
5
+ GetSession,
6
+ Handle,
7
+ HandleError,
8
+ Load,
9
+ RequestHandler,
10
+ Server,
11
+ SSRManifest
12
+ } from './index';
13
+ import {
14
+ HttpMethod,
15
+ JSONObject,
16
+ MaybePromise,
17
+ RequestEvent,
18
+ RequestOptions,
19
+ ResolveOptions,
20
+ ResponseHeaders,
21
+ TrailingSlash
22
+ } from './private';
23
+
24
+ export interface ServerModule {
25
+ Server: typeof InternalServer;
26
+
27
+ override(options: {
28
+ paths: {
29
+ base: string;
30
+ assets: string;
31
+ };
32
+ prerendering: boolean;
33
+ protocol?: 'http' | 'https';
34
+ read(file: string): Buffer;
35
+ }): void;
36
+ }
37
+
38
+ export interface Asset {
39
+ file: string;
40
+ size: number;
41
+ type: string | null;
42
+ }
43
+
44
+ export interface BuildData {
45
+ app_dir: string;
46
+ manifest_data: ManifestData;
47
+ service_worker: string | null;
48
+ client: {
49
+ assets: OutputAsset[];
50
+ chunks: OutputChunk[];
51
+ entry: {
52
+ file: string;
53
+ js: string[];
54
+ css: string[];
55
+ };
56
+ vite_manifest: import('vite').Manifest;
57
+ };
58
+ server: {
59
+ chunks: OutputChunk[];
60
+ methods: Record<string, HttpMethod[]>;
61
+ vite_manifest: import('vite').Manifest;
62
+ };
63
+ }
64
+
65
+ export type CSRComponent = any; // TODO
66
+
67
+ export type CSRComponentLoader = () => Promise<CSRComponent>;
68
+
69
+ export type CSRRoute = {
70
+ id: string;
71
+ exec: (path: string) => undefined | Record<string, string>;
72
+ a: CSRComponentLoader[];
73
+ b: CSRComponentLoader[];
74
+ has_shadow: boolean;
75
+ };
76
+
77
+ export interface EndpointData {
78
+ type: 'endpoint';
79
+ id: string;
80
+ pattern: RegExp;
81
+ file: string;
82
+ }
83
+
84
+ export type GetParams = (match: RegExpExecArray) => Record<string, string>;
85
+
86
+ export interface Hooks {
87
+ externalFetch: ExternalFetch;
88
+ getSession: GetSession;
89
+ handle: Handle;
90
+ handleError: HandleError;
91
+ }
92
+
93
+ export class InternalServer extends Server {
94
+ respond(
95
+ request: Request,
96
+ options: RequestOptions & {
97
+ prerender?: PrerenderOptions;
98
+ }
99
+ ): Promise<Response>;
100
+ }
101
+
102
+ export interface ManifestData {
103
+ assets: Asset[];
104
+ components: string[];
105
+ routes: RouteData[];
106
+ matchers: Record<string, string>;
107
+ }
108
+
109
+ export interface MethodOverride {
110
+ parameter: string;
111
+ allowed: string[];
112
+ }
113
+
114
+ export type NormalizedLoadOutput = {
115
+ status: number;
116
+ error?: Error;
117
+ redirect?: string;
118
+ props?: Record<string, any> | Promise<Record<string, any>>;
119
+ stuff?: Record<string, any>;
120
+ cache?: NormalizedLoadOutputCache;
121
+ dependencies?: string[];
122
+ };
123
+
124
+ export interface NormalizedLoadOutputCache {
125
+ maxage: number;
126
+ private?: boolean;
127
+ }
128
+
129
+ export interface PageData {
130
+ type: 'page';
131
+ id: string;
132
+ shadow: string | null;
133
+ pattern: RegExp;
134
+ path: string;
135
+ a: Array<string | undefined>;
136
+ b: Array<string | undefined>;
137
+ }
138
+
139
+ export type PayloadScriptAttributes =
140
+ | { type: 'data'; url: string; body?: string }
141
+ | { type: 'props' };
142
+
143
+ export interface PrerenderDependency {
144
+ response: Response;
145
+ body: null | string | Uint8Array;
146
+ }
147
+
148
+ export interface PrerenderOptions {
149
+ fallback?: boolean;
150
+ default: 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
+ /** client-side module URL for this component */
231
+ entry: string;
232
+ /** external CSS files */
233
+ css: string[];
234
+ /** external JS files */
235
+ js: string[];
236
+ /** inlined styles */
237
+ styles?: Record<string, string>;
238
+ }
239
+
240
+ export type SSRNodeLoader = () => Promise<SSRNode>;
241
+
242
+ export interface SSROptions {
243
+ amp: boolean;
244
+ csp: ValidatedConfig['kit']['csp'];
245
+ dev: boolean;
246
+ floc: boolean;
247
+ get_stack: (error: Error) => string | undefined;
248
+ handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
249
+ hooks: Hooks;
250
+ hydrate: boolean;
251
+ manifest: SSRManifest;
252
+ method_override: MethodOverride;
253
+ paths: {
254
+ base: string;
255
+ assets: string;
256
+ };
257
+ prefix: string;
258
+ prerender: boolean;
259
+ read(file: string): Buffer;
260
+ root: SSRComponent['default'];
261
+ router: boolean;
262
+ service_worker?: string;
263
+ template({
264
+ head,
265
+ body,
266
+ assets,
267
+ nonce
268
+ }: {
269
+ head: string;
270
+ body: string;
271
+ assets: string;
272
+ nonce: string;
273
+ }): string;
274
+ template_contains_nonce: boolean;
275
+ trailing_slash: TrailingSlash;
276
+ }
277
+
278
+ export interface SSRPage {
279
+ type: 'page';
280
+ id: string;
281
+ pattern: RegExp;
282
+ names: string[];
283
+ types: string[];
284
+ shadow:
285
+ | null
286
+ | (() => Promise<{
287
+ [method: string]: ShadowRequestHandler;
288
+ }>);
289
+ /**
290
+ * plan a is to render 1 or more layout components followed by a leaf component.
291
+ */
292
+ a: Array<number | undefined>;
293
+ /**
294
+ * plan b — if one of them components fails in `load` we backtrack until we find
295
+ * the nearest error component.
296
+ */
297
+ b: Array<number | undefined>;
298
+ }
299
+
300
+ export interface SSRPagePart {
301
+ id: string;
302
+ load: SSRComponentLoader;
303
+ }
304
+
305
+ export type SSRRoute = SSREndpoint | SSRPage;
306
+
307
+ export interface SSRState {
308
+ fallback?: string;
309
+ getClientAddress: () => string;
310
+ initiator?: SSRPage | null;
311
+ platform?: any;
312
+ prerender?: PrerenderOptions;
313
+ }
314
+
315
+ export type StrictBody = string | Uint8Array;
316
+
317
+ export type ValidatedConfig = RecursiveRequired<Config>;
318
+
319
+ export * from './index';
320
+ export * from './private';