@sveltejs/kit 1.0.0-next.39 → 1.0.0-next.392

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 (41) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +13 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/{runtime/app → app}/stores.js +33 -29
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1836 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/{runtime/chunks/paths.js → paths.js} +4 -3
  11. package/assets/server/index.js +3576 -0
  12. package/dist/chunks/error.js +682 -0
  13. package/dist/chunks/index.js +15292 -3067
  14. package/dist/chunks/index2.js +185 -555
  15. package/dist/chunks/multipart-parser.js +458 -0
  16. package/dist/chunks/sync.js +1007 -0
  17. package/dist/chunks/write_tsconfig.js +274 -0
  18. package/dist/cli.js +66 -514
  19. package/dist/hooks.js +28 -0
  20. package/dist/node/polyfills.js +17778 -0
  21. package/dist/node.js +348 -0
  22. package/dist/vite.js +3292 -0
  23. package/package.json +97 -64
  24. package/types/ambient.d.ts +328 -0
  25. package/types/index.d.ts +290 -0
  26. package/types/internal.d.ts +327 -0
  27. package/types/private.d.ts +235 -0
  28. package/CHANGELOG.md +0 -405
  29. package/assets/runtime/app/env.js +0 -5
  30. package/assets/runtime/app/navigation.js +0 -41
  31. package/assets/runtime/app/paths.js +0 -1
  32. package/assets/runtime/chunks/utils.js +0 -19
  33. package/assets/runtime/internal/singletons.js +0 -23
  34. package/assets/runtime/internal/start.js +0 -770
  35. package/dist/chunks/index3.js +0 -246
  36. package/dist/chunks/index4.js +0 -517
  37. package/dist/chunks/index5.js +0 -761
  38. package/dist/chunks/index6.js +0 -322
  39. package/dist/chunks/standard.js +0 -99
  40. package/dist/chunks/utils.js +0 -83
  41. package/dist/ssr.js +0 -2523
@@ -0,0 +1,290 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="vite/client" />
3
+
4
+ import './ambient.js';
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
+ RequestOptions,
17
+ ResponseHeaders,
18
+ RouteDefinition,
19
+ TrailingSlash
20
+ } from './private.js';
21
+ import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
22
+
23
+ export interface Adapter {
24
+ name: string;
25
+ adapt(builder: Builder): MaybePromise<void>;
26
+ }
27
+
28
+ export interface Builder {
29
+ log: Logger;
30
+ rimraf(dir: string): void;
31
+ mkdirp(dir: string): void;
32
+
33
+ config: ValidatedConfig;
34
+ prerendered: Prerendered;
35
+
36
+ /**
37
+ * Create entry points that map to individual functions
38
+ * @param fn A function that groups a set of routes into an entry point
39
+ */
40
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
41
+
42
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
43
+
44
+ getBuildDirectory(name: string): string;
45
+ getClientDirectory(): string;
46
+ getServerDirectory(): string;
47
+ getStaticDirectory(): string;
48
+
49
+ /**
50
+ * @param dest the destination folder to which files should be copied
51
+ * @returns an array of paths corresponding to the files that have been created by the copy
52
+ */
53
+ writeClient(dest: string): string[];
54
+ /**
55
+ * @param dest
56
+ */
57
+ writePrerendered(
58
+ dest: string,
59
+ opts?: {
60
+ fallback?: string;
61
+ }
62
+ ): string[];
63
+ /**
64
+ * @param dest the destination folder to which files should be copied
65
+ * @returns an array of paths corresponding to the files that have been created by the copy
66
+ */
67
+ writeServer(dest: string): string[];
68
+ /**
69
+ * @param from the source file or folder
70
+ * @param to the destination file or folder
71
+ * @param opts.filter a function to determine whether a file or folder should be copied
72
+ * @param opts.replace a map of strings to replace
73
+ * @returns an array of paths corresponding to the files that have been created by the copy
74
+ */
75
+ copy(
76
+ from: string,
77
+ to: string,
78
+ opts?: {
79
+ filter?: (basename: string) => boolean;
80
+ replace?: Record<string, string>;
81
+ }
82
+ ): string[];
83
+ }
84
+
85
+ export interface Config {
86
+ compilerOptions?: CompileOptions;
87
+ extensions?: string[];
88
+ kit?: KitConfig;
89
+ preprocess?: any;
90
+ }
91
+
92
+ export interface KitConfig {
93
+ adapter?: Adapter;
94
+ alias?: Record<string, string>;
95
+ appDir?: string;
96
+ browser?: {
97
+ hydrate?: boolean;
98
+ router?: boolean;
99
+ };
100
+ csp?: {
101
+ mode?: 'hash' | 'nonce' | 'auto';
102
+ directives?: CspDirectives;
103
+ reportOnly?: CspDirectives;
104
+ };
105
+ moduleExtensions?: string[];
106
+ files?: {
107
+ assets?: string;
108
+ hooks?: string;
109
+ lib?: string;
110
+ params?: string;
111
+ routes?: string;
112
+ serviceWorker?: string;
113
+ template?: string;
114
+ };
115
+ inlineStyleThreshold?: number;
116
+ methodOverride?: {
117
+ parameter?: string;
118
+ allowed?: string[];
119
+ };
120
+ outDir?: string;
121
+ package?: {
122
+ dir?: string;
123
+ emitTypes?: boolean;
124
+ exports?(filepath: string): boolean;
125
+ files?(filepath: string): boolean;
126
+ };
127
+ paths?: {
128
+ assets?: string;
129
+ base?: string;
130
+ };
131
+ prerender?: {
132
+ concurrency?: number;
133
+ crawl?: boolean;
134
+ default?: boolean;
135
+ enabled?: boolean;
136
+ entries?: Array<'*' | `/${string}`>;
137
+ onError?: PrerenderOnErrorValue;
138
+ origin?: string;
139
+ };
140
+ routes?: (filepath: string) => boolean;
141
+ serviceWorker?: {
142
+ register?: boolean;
143
+ files?: (filepath: string) => boolean;
144
+ };
145
+ trailingSlash?: TrailingSlash;
146
+ version?: {
147
+ name?: string;
148
+ pollInterval?: number;
149
+ };
150
+ }
151
+
152
+ export interface ExternalFetch {
153
+ (req: Request): Promise<Response>;
154
+ }
155
+
156
+ export interface GetSession {
157
+ (event: RequestEvent): MaybePromise<App.Session>;
158
+ }
159
+
160
+ export interface Handle {
161
+ (input: {
162
+ event: RequestEvent;
163
+ resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
164
+ }): MaybePromise<Response>;
165
+ }
166
+
167
+ export interface HandleError {
168
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
169
+ }
170
+
171
+ /**
172
+ * The `(event: LoadEvent) => LoadOutput` `load` function exported from `<script context="module">` in a page or layout.
173
+ *
174
+ * Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the Params generic argument.
175
+ */
176
+ export interface Load<
177
+ Params extends Record<string, string> = Record<string, string>,
178
+ InputProps extends Record<string, any> = Record<string, any>,
179
+ OutputProps extends Record<string, any> = InputProps
180
+ > {
181
+ (event: LoadEvent<Params, InputProps>): MaybePromise<LoadOutput<OutputProps> | void>;
182
+ }
183
+
184
+ export interface LoadEvent<
185
+ Params extends Record<string, string> = Record<string, string>,
186
+ Props extends Record<string, any> = Record<string, any>
187
+ > {
188
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
189
+ params: Params;
190
+ props: Props;
191
+ routeId: string | null;
192
+ session: App.Session;
193
+ stuff: Partial<App.Stuff>;
194
+ url: URL;
195
+ status: number | null;
196
+ error: Error | null;
197
+ }
198
+
199
+ export interface LoadOutput<Props extends Record<string, any> = Record<string, any>> {
200
+ status?: number;
201
+ error?: string | Error;
202
+ redirect?: string;
203
+ props?: Props;
204
+ stuff?: Partial<App.Stuff>;
205
+ cache?: LoadOutputCache;
206
+ dependencies?: string[];
207
+ }
208
+
209
+ export interface LoadOutputCache {
210
+ maxage: number;
211
+ private?: boolean;
212
+ }
213
+
214
+ export interface Navigation {
215
+ from: URL;
216
+ to: URL;
217
+ }
218
+
219
+ export interface Page<Params extends Record<string, string> = Record<string, string>> {
220
+ url: URL;
221
+ params: Params;
222
+ routeId: string | null;
223
+ stuff: App.Stuff;
224
+ status: number;
225
+ error: Error | null;
226
+ }
227
+
228
+ export interface ParamMatcher {
229
+ (param: string): boolean;
230
+ }
231
+
232
+ export interface RequestEvent<Params extends Record<string, string> = Record<string, string>> {
233
+ clientAddress: string;
234
+ locals: App.Locals;
235
+ params: Params;
236
+ platform: Readonly<App.Platform>;
237
+ request: Request;
238
+ routeId: string | null;
239
+ url: URL;
240
+ }
241
+
242
+ /**
243
+ * 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.
244
+ *
245
+ * It receives `Params` as the first generic argument, which you can skip by using [generated types](/docs/types#generated-types) instead.
246
+ *
247
+ * The next generic argument `Output` is used to validate the returned `body` from your functions by passing it through `BodyValidator`, which will make sure the variable in the `body` matches what with you assign here. It defaults to `ResponseBody`, which will error when `body` receives a [custom object type](https://www.typescriptlang.org/docs/handbook/2/objects.html).
248
+ */
249
+ export interface RequestHandler<
250
+ Params extends Record<string, string> = Record<string, string>,
251
+ Output = ResponseBody
252
+ > {
253
+ (event: RequestEvent<Params>): MaybePromise<RequestHandlerOutput<Output>>;
254
+ }
255
+
256
+ export interface RequestHandlerOutput<Output = ResponseBody> {
257
+ status?: number;
258
+ headers?: Headers | Partial<ResponseHeaders>;
259
+ body?: Output extends ResponseBody ? Output : BodyValidator<Output>;
260
+ }
261
+
262
+ export interface ResolveOptions {
263
+ ssr?: boolean;
264
+ transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
265
+ }
266
+
267
+ export type ResponseBody = JSONValue | Uint8Array | ReadableStream | Error;
268
+
269
+ export class Server {
270
+ constructor(manifest: SSRManifest);
271
+ respond(request: Request, options: RequestOptions): Promise<Response>;
272
+ }
273
+
274
+ export interface SSRManifest {
275
+ appDir: string;
276
+ assets: Set<string>;
277
+ mimeTypes: Record<string, string>;
278
+
279
+ /** private fields */
280
+ _: {
281
+ entry: {
282
+ file: string;
283
+ imports: string[];
284
+ stylesheets: string[];
285
+ };
286
+ nodes: SSRNodeLoader[];
287
+ routes: SSRRoute[];
288
+ matchers: () => Promise<Record<string, ParamMatcher>>;
289
+ };
290
+ }
@@ -0,0 +1,327 @@
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.js';
16
+ import {
17
+ HttpMethod,
18
+ JSONObject,
19
+ MaybePromise,
20
+ RequestOptions,
21
+ ResponseHeaders,
22
+ TrailingSlash
23
+ } from './private.js';
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
+ imports: string[];
55
+ stylesheets: 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 a primitive or Function
157
+ [K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
158
+ ? RecursiveRequired<T[K]> // recursively continue through.
159
+ : T[K]; // Use the exact type for everything else
160
+ };
161
+
162
+ export type RequiredResolveOptions = Required<ResolveOptions>;
163
+
164
+ export interface Respond {
165
+ (request: Request, options: SSROptions, state: SSRState): Promise<Response>;
166
+ }
167
+
168
+ export type RouteData = PageData | EndpointData;
169
+
170
+ export interface ShadowEndpointOutput<Output extends JSONObject = JSONObject> {
171
+ status?: number;
172
+ headers?: Partial<ResponseHeaders>;
173
+ body?: Output;
174
+ }
175
+
176
+ export interface ShadowRequestHandler<Output extends JSONObject = JSONObject> {
177
+ (event: RequestEvent): MaybePromise<ShadowEndpointOutput<Output>>;
178
+ }
179
+
180
+ export interface ShadowData {
181
+ status?: number;
182
+ error?: Error;
183
+ redirect?: string;
184
+ cookies?: string[];
185
+ body?: JSONObject;
186
+ }
187
+
188
+ export interface SSRComponent {
189
+ router?: boolean;
190
+ hydrate?: boolean;
191
+ prerender?: boolean;
192
+ load: Load;
193
+ default: {
194
+ render(props: Record<string, any>): {
195
+ html: string;
196
+ head: string;
197
+ css: {
198
+ code: string;
199
+ map: any; // TODO
200
+ };
201
+ };
202
+ };
203
+ }
204
+
205
+ export type SSRComponentLoader = () => Promise<SSRComponent>;
206
+
207
+ export interface SSREndpoint {
208
+ type: 'endpoint';
209
+ id: string;
210
+ pattern: RegExp;
211
+ names: string[];
212
+ types: string[];
213
+ load(): Promise<{
214
+ [method: string]: RequestHandler;
215
+ }>;
216
+ }
217
+
218
+ export interface SSRNode {
219
+ module: SSRComponent;
220
+ /** index into the `components` array in client-manifest.js */
221
+ index: number;
222
+ /** client-side module URL for this component */
223
+ file: string;
224
+ /** external JS files */
225
+ imports: string[];
226
+ /** external CSS files */
227
+ stylesheets: string[];
228
+ /** inlined styles */
229
+ inline_styles?: () => MaybePromise<Record<string, string>>;
230
+ }
231
+
232
+ export type SSRNodeLoader = () => Promise<SSRNode>;
233
+
234
+ export interface SSROptions {
235
+ csp: ValidatedConfig['kit']['csp'];
236
+ dev: boolean;
237
+ get_stack: (error: Error) => string | undefined;
238
+ handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
239
+ hooks: Hooks;
240
+ hydrate: boolean;
241
+ manifest: SSRManifest;
242
+ method_override: MethodOverride;
243
+ paths: {
244
+ base: string;
245
+ assets: string;
246
+ };
247
+ prefix: string;
248
+ prerender: {
249
+ default: boolean;
250
+ enabled: boolean;
251
+ };
252
+ read(file: string): Buffer;
253
+ root: SSRComponent['default'];
254
+ router: boolean;
255
+ service_worker?: string;
256
+ template({
257
+ head,
258
+ body,
259
+ assets,
260
+ nonce
261
+ }: {
262
+ head: string;
263
+ body: string;
264
+ assets: string;
265
+ nonce: string;
266
+ }): string;
267
+ template_contains_nonce: boolean;
268
+ trailing_slash: TrailingSlash;
269
+ }
270
+
271
+ export interface SSRPage {
272
+ type: 'page';
273
+ id: string;
274
+ pattern: RegExp;
275
+ names: string[];
276
+ types: string[];
277
+ shadow:
278
+ | null
279
+ | (() => Promise<{
280
+ [method: string]: ShadowRequestHandler;
281
+ }>);
282
+ /**
283
+ * plan a is to render 1 or more layout components followed by a leaf component.
284
+ */
285
+ a: Array<number | undefined>;
286
+ /**
287
+ * plan b — if one of them components fails in `load` we backtrack until we find
288
+ * the nearest error component.
289
+ */
290
+ b: Array<number | undefined>;
291
+ }
292
+
293
+ export interface SSRErrorPage {
294
+ id: '__error';
295
+ }
296
+
297
+ export interface SSRPagePart {
298
+ id: string;
299
+ load: SSRComponentLoader;
300
+ }
301
+
302
+ export type SSRRoute = SSREndpoint | SSRPage;
303
+
304
+ export interface SSRState {
305
+ fallback?: string;
306
+ getClientAddress: () => string;
307
+ initiator?: SSRPage | SSRErrorPage;
308
+ platform?: any;
309
+ prerendering?: PrerenderOptions;
310
+ }
311
+
312
+ export type StrictBody = string | Uint8Array;
313
+
314
+ export type ValidatedConfig = RecursiveRequired<Config>;
315
+
316
+ export type ValidatedKitConfig = RecursiveRequired<KitConfig>;
317
+
318
+ export * from './index';
319
+ export * from './private';
320
+
321
+ declare global {
322
+ const __SVELTEKIT_ADAPTER_NAME__: string;
323
+ const __SVELTEKIT_APP_VERSION__: string;
324
+ const __SVELTEKIT_APP_VERSION_FILE__: string;
325
+ const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
326
+ const __SVELTEKIT_DEV__: boolean;
327
+ }