@sveltejs/kit 1.0.0-next.32 → 1.0.0-next.322

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 (72) 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 +1687 -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 +3413 -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 +1334 -0
  18. package/dist/chunks/index3.js +118 -0
  19. package/dist/chunks/index4.js +182 -0
  20. package/dist/chunks/index5.js +240 -0
  21. package/dist/chunks/index6.js +15737 -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/sync.js +978 -0
  26. package/dist/chunks/url.js +138 -0
  27. package/dist/cli.js +1024 -65
  28. package/dist/hooks.js +28 -0
  29. package/dist/install-fetch.js +6518 -0
  30. package/dist/node.js +94 -0
  31. package/package.json +95 -62
  32. package/svelte-kit.js +0 -1
  33. package/types/ambient.d.ts +298 -0
  34. package/types/index.d.ts +278 -0
  35. package/types/internal.d.ts +320 -0
  36. package/types/private.d.ts +242 -0
  37. package/CHANGELOG.md +0 -350
  38. package/assets/runtime/app/navigation.js +0 -23
  39. package/assets/runtime/app/navigation.js.map +0 -1
  40. package/assets/runtime/app/paths.js +0 -2
  41. package/assets/runtime/app/paths.js.map +0 -1
  42. package/assets/runtime/app/stores.js +0 -78
  43. package/assets/runtime/app/stores.js.map +0 -1
  44. package/assets/runtime/internal/singletons.js +0 -15
  45. package/assets/runtime/internal/singletons.js.map +0 -1
  46. package/assets/runtime/internal/start.js +0 -591
  47. package/assets/runtime/internal/start.js.map +0 -1
  48. package/assets/runtime/utils-85ebcc60.js +0 -18
  49. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  50. package/dist/api.js +0 -32
  51. package/dist/api.js.map +0 -1
  52. package/dist/cli.js.map +0 -1
  53. package/dist/create_app.js +0 -577
  54. package/dist/create_app.js.map +0 -1
  55. package/dist/index.js +0 -329
  56. package/dist/index.js.map +0 -1
  57. package/dist/index2.js +0 -14363
  58. package/dist/index2.js.map +0 -1
  59. package/dist/index3.js +0 -544
  60. package/dist/index3.js.map +0 -1
  61. package/dist/index4.js +0 -71
  62. package/dist/index4.js.map +0 -1
  63. package/dist/index5.js +0 -465
  64. package/dist/index5.js.map +0 -1
  65. package/dist/index6.js +0 -727
  66. package/dist/index6.js.map +0 -1
  67. package/dist/renderer.js +0 -2413
  68. package/dist/renderer.js.map +0 -1
  69. package/dist/standard.js +0 -100
  70. package/dist/standard.js.map +0 -1
  71. package/dist/utils.js +0 -57
  72. package/dist/utils.js.map +0 -1
@@ -0,0 +1,278 @@
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
+ CspDirectives,
10
+ JSONValue,
11
+ Logger,
12
+ MaybePromise,
13
+ Prerendered,
14
+ PrerenderOnErrorValue,
15
+ RequestEvent,
16
+ RequestOptions,
17
+ ResolveOptions,
18
+ ResponseHeaders,
19
+ RouteDefinition,
20
+ TrailingSlash
21
+ } from './private';
22
+ import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal';
23
+
24
+ export interface Adapter {
25
+ name: string;
26
+ adapt(builder: Builder): MaybePromise<void>;
27
+ }
28
+
29
+ export interface Builder {
30
+ log: Logger;
31
+ rimraf(dir: string): void;
32
+ mkdirp(dir: string): void;
33
+
34
+ config: ValidatedConfig;
35
+ prerendered: Prerendered;
36
+
37
+ /**
38
+ * Create entry points that map to individual functions
39
+ * @param fn A function that groups a set of routes into an entry point
40
+ */
41
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
42
+
43
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
44
+
45
+ getBuildDirectory(name: string): string;
46
+ getClientDirectory(): string;
47
+ getServerDirectory(): string;
48
+ getStaticDirectory(): string;
49
+
50
+ /**
51
+ * @param dest the destination folder to which files should be copied
52
+ * @returns an array of paths corresponding to the files that have been created by the copy
53
+ */
54
+ writeClient(dest: string): string[];
55
+ /**
56
+ *
57
+ * @param dest
58
+ */
59
+ writePrerendered(
60
+ dest: string,
61
+ opts?: {
62
+ fallback?: string;
63
+ }
64
+ ): string[];
65
+ /**
66
+ * @param dest the destination folder to which files should be copied
67
+ * @returns an array of paths corresponding to the files that have been created by the copy
68
+ */
69
+ writeServer(dest: string): string[];
70
+ /**
71
+ * @param dest the destination folder to which files should be copied
72
+ * @returns an array of paths corresponding to the files that have been created by the copy
73
+ */
74
+ writeStatic(dest: string): string[];
75
+ /**
76
+ * @param from the source file or folder
77
+ * @param to the destination file or folder
78
+ * @param opts.filter a function to determine whether a file or folder should be copied
79
+ * @param opts.replace a map of strings to replace
80
+ * @returns an array of paths corresponding to the files that have been created by the copy
81
+ */
82
+ copy(
83
+ from: string,
84
+ to: string,
85
+ opts?: {
86
+ filter?: (basename: string) => boolean;
87
+ replace?: Record<string, string>;
88
+ }
89
+ ): string[];
90
+ }
91
+
92
+ export interface Config {
93
+ compilerOptions?: CompileOptions;
94
+ extensions?: string[];
95
+ kit?: {
96
+ adapter?: Adapter;
97
+ amp?: boolean;
98
+ appDir?: string;
99
+ browser?: {
100
+ hydrate?: boolean;
101
+ router?: boolean;
102
+ };
103
+ csp?: {
104
+ mode?: 'hash' | 'nonce' | 'auto';
105
+ directives?: CspDirectives;
106
+ };
107
+ endpointExtensions?: string[];
108
+ files?: {
109
+ assets?: string;
110
+ hooks?: string;
111
+ lib?: string;
112
+ params?: string;
113
+ routes?: string;
114
+ serviceWorker?: string;
115
+ template?: string;
116
+ };
117
+ floc?: boolean;
118
+ inlineStyleThreshold?: number;
119
+ methodOverride?: {
120
+ parameter?: string;
121
+ allowed?: string[];
122
+ };
123
+ outDir?: string;
124
+ package?: {
125
+ dir?: string;
126
+ emitTypes?: boolean;
127
+ exports?(filepath: string): boolean;
128
+ files?(filepath: string): boolean;
129
+ };
130
+ paths?: {
131
+ assets?: string;
132
+ base?: string;
133
+ };
134
+ prerender?: {
135
+ concurrency?: number;
136
+ crawl?: boolean;
137
+ default?: boolean;
138
+ enabled?: boolean;
139
+ entries?: string[];
140
+ onError?: PrerenderOnErrorValue;
141
+ };
142
+ routes?: (filepath: string) => boolean;
143
+ serviceWorker?: {
144
+ register?: boolean;
145
+ files?: (filepath: string) => boolean;
146
+ };
147
+ trailingSlash?: TrailingSlash;
148
+ version?: {
149
+ name?: string;
150
+ pollInterval?: number;
151
+ };
152
+ vite?: import('vite').UserConfig | (() => MaybePromise<import('vite').UserConfig>);
153
+ };
154
+ preprocess?: any;
155
+ }
156
+
157
+ export interface ExternalFetch {
158
+ (req: Request): Promise<Response>;
159
+ }
160
+
161
+ export interface GetSession {
162
+ (event: RequestEvent): MaybePromise<App.Session>;
163
+ }
164
+
165
+ export interface Handle {
166
+ (input: {
167
+ event: RequestEvent;
168
+ resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
169
+ }): MaybePromise<Response>;
170
+ }
171
+
172
+ export interface HandleError {
173
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
174
+ }
175
+
176
+ /**
177
+ * The `(input: LoadInput) => LoadOutput` `load` function exported from `<script context="module">` in a page or layout.
178
+ *
179
+ * Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the Params generic argument.
180
+ */
181
+ export interface Load<
182
+ Params extends Record<string, string> = Record<string, string>,
183
+ InputProps extends Record<string, any> = Record<string, any>,
184
+ OutputProps extends Record<string, any> = InputProps
185
+ > {
186
+ (input: LoadInput<Params, InputProps>): MaybePromise<LoadOutput<OutputProps>>;
187
+ }
188
+
189
+ export interface LoadInput<
190
+ Params extends Record<string, string> = Record<string, string>,
191
+ Props extends Record<string, any> = Record<string, any>
192
+ > {
193
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
194
+ params: Params;
195
+ props: Props;
196
+ routeId: string | null;
197
+ session: App.Session;
198
+ stuff: Partial<App.Stuff>;
199
+ url: URL;
200
+ status: number | null;
201
+ error: Error | null;
202
+ }
203
+
204
+ export interface LoadOutput<Props extends Record<string, any> = Record<string, any>> {
205
+ status?: number;
206
+ error?: string | Error;
207
+ redirect?: string;
208
+ props?: Props;
209
+ stuff?: Partial<App.Stuff>;
210
+ cache?: LoadOutputCache;
211
+ dependencies?: string[];
212
+ }
213
+
214
+ export interface LoadOutputCache {
215
+ maxage: number;
216
+ private?: boolean;
217
+ }
218
+
219
+ export interface Navigation {
220
+ from: URL;
221
+ to: URL;
222
+ }
223
+
224
+ export interface Page<Params extends Record<string, string> = Record<string, string>> {
225
+ url: URL;
226
+ params: Params;
227
+ routeId: string | null;
228
+ stuff: App.Stuff;
229
+ status: number;
230
+ error: Error | null;
231
+ }
232
+
233
+ export interface ParamMatcher {
234
+ (param: string): boolean;
235
+ }
236
+
237
+ /**
238
+ * 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.
239
+ *
240
+ * Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the `Params` generic argument.
241
+ */
242
+ export interface RequestHandler<
243
+ Params extends Record<string, string> = Record<string, string>,
244
+ Output extends ResponseBody = ResponseBody
245
+ > {
246
+ (event: RequestEvent<Params>): MaybePromise<RequestHandlerOutput<Output>>;
247
+ }
248
+
249
+ export interface RequestHandlerOutput<Output extends ResponseBody = ResponseBody> {
250
+ status?: number;
251
+ headers?: Headers | Partial<ResponseHeaders>;
252
+ body?: Output;
253
+ }
254
+
255
+ export type ResponseBody = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
256
+
257
+ export class Server {
258
+ constructor(manifest: SSRManifest);
259
+ respond(request: Request, options: RequestOptions): Promise<Response>;
260
+ }
261
+
262
+ export interface SSRManifest {
263
+ appDir: string;
264
+ assets: Set<string>;
265
+ mimeTypes: Record<string, string>;
266
+
267
+ /** private fields */
268
+ _: {
269
+ entry: {
270
+ file: string;
271
+ js: string[];
272
+ css: string[];
273
+ };
274
+ nodes: SSRNodeLoader[];
275
+ routes: SSRRoute[];
276
+ matchers: () => Promise<Record<string, ParamMatcher>>;
277
+ };
278
+ }
@@ -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';