@sveltejs/kit 1.0.0-next.4 → 1.0.0-next.401

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 +13 -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 +1845 -0
  8. package/assets/components/error.svelte +19 -3
  9. package/assets/env/dynamic/private.js +1 -0
  10. package/assets/env/dynamic/public.js +1 -0
  11. package/assets/env-private.js +9 -0
  12. package/assets/env-public.js +9 -0
  13. package/assets/env.js +8 -0
  14. package/assets/paths.js +13 -0
  15. package/assets/server/index.js +3579 -0
  16. package/dist/chunks/error.js +12 -0
  17. package/dist/chunks/filesystem.js +110 -0
  18. package/dist/chunks/index.js +675 -0
  19. package/dist/chunks/index2.js +15745 -0
  20. package/dist/chunks/index3.js +218 -0
  21. package/dist/chunks/multipart-parser.js +458 -0
  22. package/dist/chunks/sync.js +1368 -0
  23. package/dist/chunks/utils.js +66 -0
  24. package/dist/chunks/write_tsconfig.js +273 -0
  25. package/dist/cli.js +91 -101
  26. package/dist/hooks.js +28 -0
  27. package/dist/node/polyfills.js +17778 -0
  28. package/dist/node.js +348 -0
  29. package/dist/prerender.js +788 -0
  30. package/dist/vite.js +2520 -0
  31. package/package.json +98 -52
  32. package/svelte-kit.js +11 -0
  33. package/types/ambient.d.ts +375 -0
  34. package/types/index.d.ts +298 -0
  35. package/types/internal.d.ts +335 -0
  36. package/types/private.d.ts +235 -0
  37. package/CHANGELOG.md +0 -171
  38. package/assets/runtime/app/navigation.js +0 -47
  39. package/assets/runtime/app/navigation.js.map +0 -1
  40. package/assets/runtime/app/stores.js +0 -78
  41. package/assets/runtime/app/stores.js.map +0 -1
  42. package/assets/runtime/internal/singletons.js +0 -10
  43. package/assets/runtime/internal/singletons.js.map +0 -1
  44. package/assets/runtime/internal/start.js +0 -517
  45. package/assets/runtime/internal/start.js.map +0 -1
  46. package/dist/api.js +0 -40
  47. package/dist/api.js.map +0 -1
  48. package/dist/cli.js.map +0 -1
  49. package/dist/create_app.js +0 -550
  50. package/dist/create_app.js.map +0 -1
  51. package/dist/index.js +0 -8331
  52. package/dist/index.js.map +0 -1
  53. package/dist/index2.js +0 -509
  54. package/dist/index2.js.map +0 -1
  55. package/dist/index3.js +0 -63
  56. package/dist/index3.js.map +0 -1
  57. package/dist/index4.js +0 -466
  58. package/dist/index4.js.map +0 -1
  59. package/dist/index5.js +0 -276
  60. package/dist/index5.js.map +0 -1
  61. package/dist/package.js +0 -235
  62. package/dist/package.js.map +0 -1
  63. package/dist/renderer.js +0 -2397
  64. package/dist/renderer.js.map +0 -1
  65. package/dist/standard.js +0 -101
  66. package/dist/standard.js.map +0 -1
  67. package/dist/utils.js +0 -58
  68. package/dist/utils.js.map +0 -1
  69. package/svelte-kit +0 -3
@@ -0,0 +1,298 @@
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
+ env?: {
106
+ publicPrefix: string;
107
+ };
108
+ moduleExtensions?: 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
+ 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?: Array<'*' | `/${string}`>;
140
+ onError?: PrerenderOnErrorValue;
141
+ origin?: string;
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
+ }
154
+
155
+ export interface ExternalFetch {
156
+ (req: Request): Promise<Response>;
157
+ }
158
+
159
+ export interface GetSession {
160
+ (event: RequestEvent): MaybePromise<App.Session>;
161
+ }
162
+
163
+ export interface Handle {
164
+ (input: {
165
+ event: RequestEvent;
166
+ resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
167
+ }): MaybePromise<Response>;
168
+ }
169
+
170
+ export interface HandleError {
171
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
172
+ }
173
+
174
+ /**
175
+ * The `(event: LoadEvent) => LoadOutput` `load` function exported from `<script context="module">` in a page or layout.
176
+ *
177
+ * Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the Params generic argument.
178
+ */
179
+ export interface Load<
180
+ Params extends Record<string, string> = Record<string, string>,
181
+ InputProps extends Record<string, any> = Record<string, any>,
182
+ OutputProps extends Record<string, any> = InputProps
183
+ > {
184
+ (event: LoadEvent<Params, InputProps>): MaybePromise<LoadOutput<OutputProps> | void>;
185
+ }
186
+
187
+ export interface LoadEvent<
188
+ Params extends Record<string, string> = Record<string, string>,
189
+ Props extends Record<string, any> = Record<string, any>
190
+ > {
191
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
192
+ params: Params;
193
+ props: Props;
194
+ routeId: string | null;
195
+ session: App.Session;
196
+ stuff: Partial<App.Stuff>;
197
+ url: URL;
198
+ status: number | null;
199
+ error: Error | null;
200
+ }
201
+
202
+ export interface LoadOutput<Props extends Record<string, any> = Record<string, any>> {
203
+ status?: number;
204
+ error?: string | Error;
205
+ redirect?: string;
206
+ props?: Props;
207
+ stuff?: Partial<App.Stuff>;
208
+ cache?: LoadOutputCache;
209
+ dependencies?: string[];
210
+ }
211
+
212
+ export interface LoadOutputCache {
213
+ maxage: number;
214
+ private?: boolean;
215
+ }
216
+
217
+ export interface Navigation {
218
+ from: URL;
219
+ to: URL;
220
+ }
221
+
222
+ export interface Page<Params extends Record<string, string> = Record<string, string>> {
223
+ url: URL;
224
+ params: Params;
225
+ routeId: string | null;
226
+ stuff: App.Stuff;
227
+ status: number;
228
+ error: Error | null;
229
+ }
230
+
231
+ export interface ParamMatcher {
232
+ (param: string): boolean;
233
+ }
234
+
235
+ export interface RequestEvent<Params extends Record<string, string> = Record<string, string>> {
236
+ clientAddress: string;
237
+ locals: App.Locals;
238
+ params: Params;
239
+ platform: Readonly<App.Platform>;
240
+ request: Request;
241
+ routeId: string | null;
242
+ url: URL;
243
+ }
244
+
245
+ /**
246
+ * 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.
247
+ *
248
+ * It receives `Params` as the first generic argument, which you can skip by using [generated types](/docs/types#generated-types) instead.
249
+ *
250
+ * 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).
251
+ */
252
+ export interface RequestHandler<
253
+ Params extends Record<string, string> = Record<string, string>,
254
+ Output = ResponseBody
255
+ > {
256
+ (event: RequestEvent<Params>): MaybePromise<RequestHandlerOutput<Output>>;
257
+ }
258
+
259
+ export interface RequestHandlerOutput<Output = ResponseBody> {
260
+ status?: number;
261
+ headers?: Headers | Partial<ResponseHeaders>;
262
+ body?: Output extends ResponseBody ? Output : BodyValidator<Output>;
263
+ }
264
+
265
+ export interface ResolveOptions {
266
+ ssr?: boolean;
267
+ transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
268
+ }
269
+
270
+ export type ResponseBody = JSONValue | Uint8Array | ReadableStream | Error;
271
+
272
+ export class Server {
273
+ constructor(manifest: SSRManifest);
274
+ init(options: ServerInitOptions): void;
275
+ respond(request: Request, options: RequestOptions): Promise<Response>;
276
+ }
277
+
278
+ export interface ServerInitOptions {
279
+ env: Record<string, string>;
280
+ }
281
+
282
+ export interface SSRManifest {
283
+ appDir: string;
284
+ assets: Set<string>;
285
+ mimeTypes: Record<string, string>;
286
+
287
+ /** private fields */
288
+ _: {
289
+ entry: {
290
+ file: string;
291
+ imports: string[];
292
+ stylesheets: string[];
293
+ };
294
+ nodes: SSRNodeLoader[];
295
+ routes: SSRRoute[];
296
+ matchers: () => Promise<Record<string, ParamMatcher>>;
297
+ };
298
+ }
@@ -0,0 +1,335 @@
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
+ ServerInitOptions,
15
+ SSRManifest
16
+ } from './index.js';
17
+ import {
18
+ HttpMethod,
19
+ JSONObject,
20
+ MaybePromise,
21
+ RequestOptions,
22
+ ResponseHeaders,
23
+ TrailingSlash
24
+ } from './private.js';
25
+
26
+ export interface ServerModule {
27
+ Server: typeof InternalServer;
28
+
29
+ override(options: {
30
+ paths: {
31
+ base: string;
32
+ assets: string;
33
+ };
34
+ prerendering: boolean;
35
+ protocol?: 'http' | 'https';
36
+ read(file: string): Buffer;
37
+ }): void;
38
+ }
39
+
40
+ export interface Asset {
41
+ file: string;
42
+ size: number;
43
+ type: string | null;
44
+ }
45
+
46
+ export interface BuildData {
47
+ app_dir: string;
48
+ manifest_data: ManifestData;
49
+ service_worker: string | null;
50
+ client: {
51
+ assets: OutputAsset[];
52
+ chunks: OutputChunk[];
53
+ entry: {
54
+ file: string;
55
+ imports: string[];
56
+ stylesheets: string[];
57
+ };
58
+ vite_manifest: import('vite').Manifest;
59
+ };
60
+ server: {
61
+ chunks: OutputChunk[];
62
+ methods: Record<string, HttpMethod[]>;
63
+ vite_manifest: import('vite').Manifest;
64
+ };
65
+ }
66
+
67
+ export type CSRComponent = any; // TODO
68
+
69
+ export type CSRComponentLoader = () => Promise<CSRComponent>;
70
+
71
+ export type CSRRoute = {
72
+ id: string;
73
+ exec: (path: string) => undefined | Record<string, string>;
74
+ a: CSRComponentLoader[];
75
+ b: CSRComponentLoader[];
76
+ has_shadow: boolean;
77
+ };
78
+
79
+ export interface EndpointData {
80
+ type: 'endpoint';
81
+ id: string;
82
+ pattern: RegExp;
83
+ file: string;
84
+ }
85
+
86
+ export type GetParams = (match: RegExpExecArray) => Record<string, string>;
87
+
88
+ export interface Hooks {
89
+ externalFetch: ExternalFetch;
90
+ getSession: GetSession;
91
+ handle: Handle;
92
+ handleError: HandleError;
93
+ }
94
+
95
+ export interface ImportNode {
96
+ name: string;
97
+ dynamic: boolean;
98
+ }
99
+
100
+ export class InternalServer extends Server {
101
+ init(options: ServerInitOptions): void;
102
+ respond(
103
+ request: Request,
104
+ options: RequestOptions & {
105
+ prerendering?: PrerenderOptions;
106
+ }
107
+ ): Promise<Response>;
108
+ }
109
+
110
+ export interface ManifestData {
111
+ assets: Asset[];
112
+ components: string[];
113
+ routes: RouteData[];
114
+ matchers: Record<string, string>;
115
+ }
116
+
117
+ export interface MethodOverride {
118
+ parameter: string;
119
+ allowed: string[];
120
+ }
121
+
122
+ export type NormalizedLoadOutput = {
123
+ status?: number;
124
+ error?: Error;
125
+ redirect?: string;
126
+ props?: Record<string, any> | Promise<Record<string, any>>;
127
+ stuff?: Record<string, any>;
128
+ cache?: NormalizedLoadOutputCache;
129
+ dependencies?: string[];
130
+ };
131
+
132
+ export interface NormalizedLoadOutputCache {
133
+ maxage: number;
134
+ private?: boolean;
135
+ }
136
+
137
+ export interface PageData {
138
+ type: 'page';
139
+ id: string;
140
+ shadow: string | null;
141
+ pattern: RegExp;
142
+ path: string;
143
+ a: Array<string | undefined>;
144
+ b: Array<string | undefined>;
145
+ }
146
+
147
+ export type PayloadScriptAttributes =
148
+ | { type: 'data'; url: string; body?: string }
149
+ | { type: 'props' };
150
+
151
+ export interface PrerenderDependency {
152
+ response: Response;
153
+ body: null | string | Uint8Array;
154
+ }
155
+
156
+ export interface PrerenderOptions {
157
+ fallback?: boolean;
158
+ dependencies: Map<string, PrerenderDependency>;
159
+ }
160
+
161
+ export type RecursiveRequired<T> = {
162
+ // Recursive implementation of TypeScript's Required utility type.
163
+ // Will recursively continue until it reaches a primitive or Function
164
+ [K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
165
+ ? RecursiveRequired<T[K]> // recursively continue through.
166
+ : T[K]; // Use the exact type for everything else
167
+ };
168
+
169
+ export type RequiredResolveOptions = Required<ResolveOptions>;
170
+
171
+ export interface Respond {
172
+ (request: Request, options: SSROptions, state: SSRState): Promise<Response>;
173
+ }
174
+
175
+ export type RouteData = PageData | EndpointData;
176
+
177
+ export interface ShadowEndpointOutput<Output extends JSONObject = JSONObject> {
178
+ status?: number;
179
+ headers?: Partial<ResponseHeaders>;
180
+ body?: Output;
181
+ }
182
+
183
+ export interface ShadowRequestHandler<Output extends JSONObject = JSONObject> {
184
+ (event: RequestEvent): MaybePromise<ShadowEndpointOutput<Output>>;
185
+ }
186
+
187
+ export interface ShadowData {
188
+ status?: number;
189
+ error?: Error;
190
+ redirect?: string;
191
+ cookies?: string[];
192
+ body?: JSONObject;
193
+ }
194
+
195
+ export interface SSRComponent {
196
+ router?: boolean;
197
+ hydrate?: boolean;
198
+ prerender?: boolean;
199
+ load: Load;
200
+ default: {
201
+ render(props: Record<string, any>): {
202
+ html: string;
203
+ head: string;
204
+ css: {
205
+ code: string;
206
+ map: any; // TODO
207
+ };
208
+ };
209
+ };
210
+ }
211
+
212
+ export type SSRComponentLoader = () => Promise<SSRComponent>;
213
+
214
+ export interface SSREndpoint {
215
+ type: 'endpoint';
216
+ id: string;
217
+ pattern: RegExp;
218
+ names: string[];
219
+ types: string[];
220
+ load(): Promise<{
221
+ [method: string]: RequestHandler;
222
+ }>;
223
+ }
224
+
225
+ export interface SSRNode {
226
+ module: SSRComponent;
227
+ /** index into the `components` array in client-manifest.js */
228
+ index: number;
229
+ /** client-side module URL for this component */
230
+ file: string;
231
+ /** external JS files */
232
+ imports: string[];
233
+ /** external CSS files */
234
+ stylesheets: string[];
235
+ /** inlined styles */
236
+ inline_styles?: () => MaybePromise<Record<string, string>>;
237
+ }
238
+
239
+ export type SSRNodeLoader = () => Promise<SSRNode>;
240
+
241
+ export interface SSROptions {
242
+ csp: ValidatedConfig['kit']['csp'];
243
+ dev: boolean;
244
+ get_stack: (error: Error) => string | undefined;
245
+ handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
246
+ hooks: Hooks;
247
+ hydrate: boolean;
248
+ manifest: SSRManifest;
249
+ method_override: MethodOverride;
250
+ paths: {
251
+ base: string;
252
+ assets: string;
253
+ };
254
+ prefix: string;
255
+ prerender: {
256
+ default: boolean;
257
+ enabled: boolean;
258
+ };
259
+ public_env: Record<string, string>;
260
+ read(file: string): Buffer;
261
+ root: SSRComponent['default'];
262
+ router: boolean;
263
+ service_worker?: string;
264
+ template({
265
+ head,
266
+ body,
267
+ assets,
268
+ nonce
269
+ }: {
270
+ head: string;
271
+ body: string;
272
+ assets: string;
273
+ nonce: string;
274
+ }): string;
275
+ template_contains_nonce: boolean;
276
+ trailing_slash: TrailingSlash;
277
+ }
278
+
279
+ export interface SSRPage {
280
+ type: 'page';
281
+ id: string;
282
+ pattern: RegExp;
283
+ names: string[];
284
+ types: string[];
285
+ shadow:
286
+ | null
287
+ | (() => Promise<{
288
+ [method: string]: ShadowRequestHandler;
289
+ }>);
290
+ /**
291
+ * plan a is to render 1 or more layout components followed by a leaf component.
292
+ */
293
+ a: Array<number | undefined>;
294
+ /**
295
+ * plan b — if one of them components fails in `load` we backtrack until we find
296
+ * the nearest error component.
297
+ */
298
+ b: Array<number | undefined>;
299
+ }
300
+
301
+ export interface SSRErrorPage {
302
+ id: '__error';
303
+ }
304
+
305
+ export interface SSRPagePart {
306
+ id: string;
307
+ load: SSRComponentLoader;
308
+ }
309
+
310
+ export type SSRRoute = SSREndpoint | SSRPage;
311
+
312
+ export interface SSRState {
313
+ fallback?: string;
314
+ getClientAddress: () => string;
315
+ initiator?: SSRPage | SSRErrorPage;
316
+ platform?: any;
317
+ prerendering?: PrerenderOptions;
318
+ }
319
+
320
+ export type StrictBody = string | Uint8Array;
321
+
322
+ export type ValidatedConfig = RecursiveRequired<Config>;
323
+
324
+ export type ValidatedKitConfig = RecursiveRequired<KitConfig>;
325
+
326
+ export * from './index';
327
+ export * from './private';
328
+
329
+ declare global {
330
+ const __SVELTEKIT_ADAPTER_NAME__: string;
331
+ const __SVELTEKIT_APP_VERSION__: string;
332
+ const __SVELTEKIT_APP_VERSION_FILE__: string;
333
+ const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
334
+ const __SVELTEKIT_DEV__: boolean;
335
+ }