@sveltejs/kit 1.0.0-next.47 → 1.0.0-next.470

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 (115) hide show
  1. package/README.md +12 -9
  2. package/package.json +93 -64
  3. package/scripts/special-types/$env+dynamic+private.md +8 -0
  4. package/scripts/special-types/$env+dynamic+public.md +8 -0
  5. package/scripts/special-types/$env+static+private.md +19 -0
  6. package/scripts/special-types/$env+static+public.md +7 -0
  7. package/scripts/special-types/$lib.md +1 -0
  8. package/src/cli.js +112 -0
  9. package/src/constants.js +7 -0
  10. package/src/core/adapt/builder.js +207 -0
  11. package/src/core/adapt/index.js +31 -0
  12. package/src/core/config/default-error.html +56 -0
  13. package/src/core/config/index.js +105 -0
  14. package/src/core/config/options.js +502 -0
  15. package/src/core/config/types.d.ts +1 -0
  16. package/src/core/env.js +121 -0
  17. package/src/core/generate_manifest/index.js +92 -0
  18. package/src/core/prerender/crawl.js +194 -0
  19. package/src/core/prerender/prerender.js +425 -0
  20. package/src/core/prerender/queue.js +80 -0
  21. package/src/core/sync/create_manifest_data/index.js +472 -0
  22. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  23. package/src/core/sync/sync.js +59 -0
  24. package/src/core/sync/utils.js +33 -0
  25. package/src/core/sync/write_ambient.js +53 -0
  26. package/src/core/sync/write_client_manifest.js +94 -0
  27. package/src/core/sync/write_matchers.js +25 -0
  28. package/src/core/sync/write_root.js +91 -0
  29. package/src/core/sync/write_tsconfig.js +195 -0
  30. package/src/core/sync/write_types/index.js +595 -0
  31. package/src/core/utils.js +70 -0
  32. package/src/exports/hooks/index.js +1 -0
  33. package/src/exports/hooks/sequence.js +44 -0
  34. package/src/exports/index.js +45 -0
  35. package/src/exports/node/index.js +145 -0
  36. package/src/exports/node/polyfills.js +40 -0
  37. package/src/exports/vite/build/build_server.js +358 -0
  38. package/src/exports/vite/build/build_service_worker.js +90 -0
  39. package/src/exports/vite/build/utils.js +162 -0
  40. package/src/exports/vite/dev/index.js +547 -0
  41. package/src/exports/vite/index.js +601 -0
  42. package/src/exports/vite/preview/index.js +186 -0
  43. package/src/exports/vite/types.d.ts +3 -0
  44. package/src/exports/vite/utils.js +345 -0
  45. package/src/runtime/app/env.js +1 -0
  46. package/src/runtime/app/environment.js +11 -0
  47. package/src/runtime/app/navigation.js +23 -0
  48. package/src/runtime/app/paths.js +1 -0
  49. package/src/runtime/app/stores.js +102 -0
  50. package/src/runtime/client/ambient.d.ts +24 -0
  51. package/src/runtime/client/client.js +1494 -0
  52. package/src/runtime/client/fetcher.js +107 -0
  53. package/src/runtime/client/parse.js +60 -0
  54. package/src/runtime/client/singletons.js +21 -0
  55. package/src/runtime/client/start.js +45 -0
  56. package/src/runtime/client/types.d.ts +91 -0
  57. package/src/runtime/client/utils.js +159 -0
  58. package/src/runtime/components/error.svelte +16 -0
  59. package/{assets → src/runtime}/components/layout.svelte +0 -0
  60. package/src/runtime/control.js +33 -0
  61. package/src/runtime/env/dynamic/private.js +1 -0
  62. package/src/runtime/env/dynamic/public.js +1 -0
  63. package/src/runtime/env-private.js +6 -0
  64. package/src/runtime/env-public.js +6 -0
  65. package/src/runtime/env.js +6 -0
  66. package/src/runtime/hash.js +16 -0
  67. package/src/runtime/paths.js +11 -0
  68. package/src/runtime/server/data/index.js +146 -0
  69. package/src/runtime/server/endpoint.js +63 -0
  70. package/src/runtime/server/index.js +354 -0
  71. package/src/runtime/server/page/cookie.js +25 -0
  72. package/src/runtime/server/page/crypto.js +239 -0
  73. package/src/runtime/server/page/csp.js +249 -0
  74. package/src/runtime/server/page/fetch.js +282 -0
  75. package/src/runtime/server/page/index.js +404 -0
  76. package/src/runtime/server/page/load_data.js +124 -0
  77. package/src/runtime/server/page/render.js +358 -0
  78. package/src/runtime/server/page/respond_with_error.js +92 -0
  79. package/src/runtime/server/page/serialize_data.js +72 -0
  80. package/src/runtime/server/page/types.d.ts +45 -0
  81. package/src/runtime/server/utils.js +209 -0
  82. package/src/utils/array.js +9 -0
  83. package/src/utils/error.js +22 -0
  84. package/src/utils/escape.js +46 -0
  85. package/src/utils/filesystem.js +108 -0
  86. package/src/utils/functions.js +16 -0
  87. package/src/utils/http.js +55 -0
  88. package/src/utils/misc.js +1 -0
  89. package/src/utils/routing.js +117 -0
  90. package/src/utils/url.js +142 -0
  91. package/svelte-kit.js +1 -1
  92. package/types/ambient.d.ts +356 -0
  93. package/types/index.d.ts +356 -0
  94. package/types/internal.d.ts +386 -0
  95. package/types/private.d.ts +213 -0
  96. package/CHANGELOG.md +0 -463
  97. package/assets/components/error.svelte +0 -13
  98. package/assets/runtime/app/env.js +0 -5
  99. package/assets/runtime/app/navigation.js +0 -44
  100. package/assets/runtime/app/paths.js +0 -1
  101. package/assets/runtime/app/stores.js +0 -93
  102. package/assets/runtime/chunks/utils.js +0 -22
  103. package/assets/runtime/internal/singletons.js +0 -23
  104. package/assets/runtime/internal/start.js +0 -773
  105. package/assets/runtime/paths.js +0 -12
  106. package/dist/chunks/index.js +0 -3517
  107. package/dist/chunks/index2.js +0 -587
  108. package/dist/chunks/index3.js +0 -246
  109. package/dist/chunks/index4.js +0 -530
  110. package/dist/chunks/index5.js +0 -763
  111. package/dist/chunks/index6.js +0 -322
  112. package/dist/chunks/standard.js +0 -99
  113. package/dist/chunks/utils.js +0 -83
  114. package/dist/cli.js +0 -553
  115. package/dist/ssr.js +0 -2581
@@ -0,0 +1,356 @@
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
+ CspDirectives,
10
+ Logger,
11
+ MaybePromise,
12
+ Prerendered,
13
+ PrerenderOnErrorValue,
14
+ RequestOptions,
15
+ ResponseHeaders,
16
+ RouteDefinition,
17
+ TrailingSlash
18
+ } from './private.js';
19
+ import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
20
+ import { HttpError, Redirect } from '../src/runtime/control.js';
21
+
22
+ export { PrerenderOption } from './private.js';
23
+
24
+ export interface Adapter {
25
+ name: string;
26
+ adapt(builder: Builder): MaybePromise<void>;
27
+ }
28
+
29
+ export type AwaitedProperties<input extends Record<string, any> | void> = input extends void
30
+ ? undefined // needs to be undefined, because void will break intellisense
31
+ : input extends Record<string, any>
32
+ ? {
33
+ [key in keyof input]: Awaited<input[key]>;
34
+ }
35
+ : {} extends input // handles the any case
36
+ ? input
37
+ : unknown;
38
+
39
+ export type AwaitedErrors<T extends (...args: any) => any> = Awaited<ReturnType<T>> extends {
40
+ errors?: any;
41
+ }
42
+ ? Awaited<ReturnType<T>>['errors']
43
+ : undefined;
44
+
45
+ export interface Builder {
46
+ log: Logger;
47
+ rimraf(dir: string): void;
48
+ mkdirp(dir: string): void;
49
+
50
+ config: ValidatedConfig;
51
+ prerendered: Prerendered;
52
+
53
+ /**
54
+ * Create entry points that map to individual functions
55
+ * @param fn A function that groups a set of routes into an entry point
56
+ */
57
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
58
+
59
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
60
+
61
+ getBuildDirectory(name: string): string;
62
+ getClientDirectory(): string;
63
+ getServerDirectory(): string;
64
+ getStaticDirectory(): string;
65
+
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
+ writeClient(dest: string): string[];
71
+ /**
72
+ * @param dest
73
+ */
74
+ writePrerendered(
75
+ dest: string,
76
+ opts?: {
77
+ fallback?: string;
78
+ }
79
+ ): string[];
80
+ /**
81
+ * @param dest the destination folder to which files should be copied
82
+ * @returns an array of paths corresponding to the files that have been created by the copy
83
+ */
84
+ writeServer(dest: string): string[];
85
+ /**
86
+ * @param from the source file or folder
87
+ * @param to the destination file or folder
88
+ * @param opts.filter a function to determine whether a file or folder should be copied
89
+ * @param opts.replace a map of strings to replace
90
+ * @returns an array of paths corresponding to the files that have been created by the copy
91
+ */
92
+ copy(
93
+ from: string,
94
+ to: string,
95
+ opts?: {
96
+ filter?: (basename: string) => boolean;
97
+ replace?: Record<string, string>;
98
+ }
99
+ ): string[];
100
+
101
+ /**
102
+ * @param {string} directory Path to the directory containing the files to be compressed
103
+ */
104
+ compress(directory: string): Promise<void>;
105
+ }
106
+
107
+ export interface Config {
108
+ compilerOptions?: CompileOptions;
109
+ extensions?: string[];
110
+ kit?: KitConfig;
111
+ package?: {
112
+ source?: string;
113
+ dir?: string;
114
+ emitTypes?: boolean;
115
+ exports?: (filepath: string) => boolean;
116
+ files?: (filepath: string) => boolean;
117
+ };
118
+ preprocess?: any;
119
+ [key: string]: any;
120
+ }
121
+
122
+ export interface KitConfig {
123
+ adapter?: Adapter;
124
+ alias?: Record<string, string>;
125
+ appDir?: string;
126
+ csp?: {
127
+ mode?: 'hash' | 'nonce' | 'auto';
128
+ directives?: CspDirectives;
129
+ reportOnly?: CspDirectives;
130
+ };
131
+ csrf?: {
132
+ checkOrigin?: boolean;
133
+ };
134
+ env?: {
135
+ dir?: string;
136
+ publicPrefix?: string;
137
+ };
138
+ moduleExtensions?: string[];
139
+ files?: {
140
+ assets?: string;
141
+ hooks?: string;
142
+ lib?: string;
143
+ params?: string;
144
+ routes?: string;
145
+ serviceWorker?: string;
146
+ appTemplate?: string;
147
+ errorTemplate?: string;
148
+ };
149
+ inlineStyleThreshold?: number;
150
+ methodOverride?: {
151
+ parameter?: string;
152
+ allowed?: string[];
153
+ };
154
+ outDir?: string;
155
+ paths?: {
156
+ assets?: string;
157
+ base?: string;
158
+ };
159
+ prerender?: {
160
+ concurrency?: number;
161
+ crawl?: boolean;
162
+ default?: boolean;
163
+ enabled?: boolean;
164
+ entries?: Array<'*' | `/${string}`>;
165
+ onError?: PrerenderOnErrorValue;
166
+ origin?: string;
167
+ };
168
+ serviceWorker?: {
169
+ register?: boolean;
170
+ files?: (filepath: string) => boolean;
171
+ };
172
+ trailingSlash?: TrailingSlash;
173
+ version?: {
174
+ name?: string;
175
+ pollInterval?: number;
176
+ };
177
+ }
178
+
179
+ export interface Handle {
180
+ (input: {
181
+ event: RequestEvent;
182
+ resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
183
+ }): MaybePromise<Response>;
184
+ }
185
+
186
+ export interface HandleError {
187
+ (input: { error: Error & { frame?: string }; event: RequestEvent }): void;
188
+ }
189
+
190
+ export interface HandleFetch {
191
+ (input: { event: RequestEvent; request: Request; fetch: typeof fetch }): MaybePromise<Response>;
192
+ }
193
+
194
+ /**
195
+ * The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
196
+ * rather than using `Load` directly.
197
+ */
198
+ export interface Load<
199
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
200
+ InputData extends Record<string, unknown> | null = Record<string, any> | null,
201
+ ParentData extends Record<string, unknown> = Record<string, any>,
202
+ OutputData extends Record<string, unknown> | void = Record<string, any> | void
203
+ > {
204
+ (event: LoadEvent<Params, InputData, ParentData>): MaybePromise<OutputData>;
205
+ }
206
+
207
+ export interface LoadEvent<
208
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
209
+ Data extends Record<string, unknown> | null = Record<string, any> | null,
210
+ ParentData extends Record<string, unknown> = Record<string, any>
211
+ > {
212
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
213
+ params: Params;
214
+ data: Data;
215
+ routeId: string | null;
216
+ setHeaders: (headers: ResponseHeaders) => void;
217
+ url: URL;
218
+ parent: () => Promise<ParentData>;
219
+ depends: (...deps: string[]) => void;
220
+ }
221
+
222
+ export interface NavigationTarget {
223
+ params: Record<string, string> | null;
224
+ routeId: string | null;
225
+ url: URL;
226
+ }
227
+
228
+ export type NavigationType = 'load' | 'unload' | 'link' | 'goto' | 'popstate';
229
+
230
+ export interface Navigation {
231
+ from: NavigationTarget | null;
232
+ to: NavigationTarget | null;
233
+ type: NavigationType;
234
+ delta?: number;
235
+ }
236
+
237
+ export interface Page<Params extends Record<string, string> = Record<string, string>> {
238
+ url: URL;
239
+ params: Params;
240
+ routeId: string | null;
241
+ status: number;
242
+ error: HttpError | Error | null;
243
+ data: App.PageData & Record<string, any>;
244
+ }
245
+
246
+ export interface ParamMatcher {
247
+ (param: string): boolean;
248
+ }
249
+
250
+ export interface RequestEvent<
251
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
252
+ > {
253
+ getClientAddress: () => string;
254
+ locals: App.Locals;
255
+ params: Params;
256
+ platform: Readonly<App.Platform>;
257
+ request: Request;
258
+ routeId: string | null;
259
+ setHeaders: (headers: ResponseHeaders) => void;
260
+ url: URL;
261
+ }
262
+
263
+ /**
264
+ * A `(event: RequestEvent) => Response` function exported from a `+server.js` file that corresponds to an HTTP verb (`GET`, `PUT`, `PATCH`, etc) and handles requests with that method.
265
+ *
266
+ * It receives `Params` as the first generic argument, which you can skip by using [generated types](/docs/types#generated-types) instead.
267
+ */
268
+ export interface RequestHandler<
269
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
270
+ > {
271
+ (event: RequestEvent<Params>): MaybePromise<Response>;
272
+ }
273
+
274
+ export interface ResolveOptions {
275
+ transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
276
+ }
277
+
278
+ export class Server {
279
+ constructor(manifest: SSRManifest);
280
+ init(options: ServerInitOptions): Promise<void>;
281
+ respond(request: Request, options: RequestOptions): Promise<Response>;
282
+ }
283
+
284
+ export interface ServerInitOptions {
285
+ env: Record<string, string>;
286
+ }
287
+
288
+ export interface SSRManifest {
289
+ appDir: string;
290
+ assets: Set<string>;
291
+ mimeTypes: Record<string, string>;
292
+
293
+ /** private fields */
294
+ _: {
295
+ entry: {
296
+ file: string;
297
+ imports: string[];
298
+ stylesheets: string[];
299
+ };
300
+ nodes: SSRNodeLoader[];
301
+ routes: SSRRoute[];
302
+ matchers: () => Promise<Record<string, ParamMatcher>>;
303
+ };
304
+ }
305
+
306
+ /**
307
+ * The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
308
+ * rather than using `ServerLoad` directly.
309
+ */
310
+ export interface ServerLoad<
311
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
312
+ ParentData extends Record<string, any> = Record<string, any>,
313
+ OutputData extends Record<string, any> | void = Record<string, any> | void
314
+ > {
315
+ (event: ServerLoadEvent<Params, ParentData>): MaybePromise<OutputData>;
316
+ }
317
+
318
+ export interface ServerLoadEvent<
319
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
320
+ ParentData extends Record<string, any> = Record<string, any>
321
+ > extends RequestEvent<Params> {
322
+ parent: () => Promise<ParentData>;
323
+ }
324
+
325
+ export interface Action<
326
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>
327
+ > {
328
+ (event: RequestEvent<Params>): MaybePromise<
329
+ | { status?: number; errors: Record<string, any>; location?: never }
330
+ | { status?: never; errors?: never; location: string }
331
+ | void
332
+ >;
333
+ }
334
+
335
+ // TODO figure out how to just re-export from '../src/index/index.js' without
336
+ // breaking the site
337
+
338
+ /**
339
+ * Creates an `HttpError` object with an HTTP status code and an optional message.
340
+ * This object, if thrown during request handling, will cause SvelteKit to
341
+ * return an error response without invoking `handleError`
342
+ * @param {number} status
343
+ * @param {string | undefined} [message]
344
+ */
345
+ export function error(status: number, message?: string | undefined): HttpError;
346
+
347
+ /**
348
+ * Creates a `Redirect` object. If thrown during request handling, SvelteKit will
349
+ * return a redirect response.
350
+ */
351
+ export function redirect(status: number, location: string): Redirect;
352
+
353
+ /**
354
+ * Generates a JSON `Response` object from the supplied data.
355
+ */
356
+ export function json(data: any, init?: ResponseInit): Response;