@sveltejs/kit 1.0.0-next.283 → 1.0.0-next.286

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.
@@ -0,0 +1,343 @@
1
+ // This module contains types that are visible in the documentation,
2
+ // but which cannot be imported from `@sveltejs/kit`. Care should
3
+ // be taken to avoid breaking changes when editing this file
4
+
5
+ import { SSRNodeLoader, SSRRoute } from './internal';
6
+
7
+ export interface AdapterEntry {
8
+ /**
9
+ * A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
10
+ * For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
11
+ * be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
12
+ */
13
+ id: string;
14
+
15
+ /**
16
+ * A function that compares the candidate route with the current route to determine
17
+ * if it should be treated as a fallback for the current route. For example, `/foo/[c]`
18
+ * is a fallback for `/foo/a-[b]`, and `/[...catchall]` is a fallback for all routes
19
+ */
20
+ filter: (route: RouteDefinition) => boolean;
21
+
22
+ /**
23
+ * A function that is invoked once the entry has been created. This is where you
24
+ * should write the function to the filesystem and generate redirect manifests.
25
+ */
26
+ complete: (entry: {
27
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
28
+ }) => void;
29
+ }
30
+
31
+ export type Body = JSONValue | Uint8Array | ReadableStream | import('stream').Readable;
32
+
33
+ export interface Builder {
34
+ log: Logger;
35
+ rimraf(dir: string): void;
36
+ mkdirp(dir: string): void;
37
+
38
+ appDir: string;
39
+ trailingSlash: TrailingSlash;
40
+
41
+ /**
42
+ * Create entry points that map to individual functions
43
+ * @param fn A function that groups a set of routes into an entry point
44
+ */
45
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): void;
46
+
47
+ generateManifest: (opts: { relativePath: string; format?: 'esm' | 'cjs' }) => string;
48
+
49
+ getBuildDirectory(name: string): string;
50
+ getClientDirectory(): string;
51
+ getServerDirectory(): string;
52
+ getStaticDirectory(): string;
53
+
54
+ /**
55
+ * @param dest the destination folder to which files should be copied
56
+ * @returns an array of paths corresponding to the files that have been created by the copy
57
+ */
58
+ writeClient(dest: string): string[];
59
+ /**
60
+ * @param dest the destination folder to which files should be copied
61
+ * @returns an array of paths corresponding to the files that have been created by the copy
62
+ */
63
+ writeServer(dest: string): string[];
64
+ /**
65
+ * @param dest the destination folder to which files should be copied
66
+ * @returns an array of paths corresponding to the files that have been created by the copy
67
+ */
68
+ writeStatic(dest: string): string[];
69
+ /**
70
+ * @param from the source file or folder
71
+ * @param to the destination file or folder
72
+ * @param opts.filter a function to determine whether a file or folder should be copied
73
+ * @param opts.replace a map of strings to replace
74
+ * @returns an array of paths corresponding to the files that have been created by the copy
75
+ */
76
+ copy(
77
+ from: string,
78
+ to: string,
79
+ opts?: {
80
+ filter?: (basename: string) => boolean;
81
+ replace?: Record<string, string>;
82
+ }
83
+ ): string[];
84
+
85
+ prerender(options: { all?: boolean; dest: string; fallback?: string }): Promise<Prerendered>;
86
+ }
87
+
88
+ // Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts
89
+ //
90
+ // MIT License
91
+ //
92
+ // Copyright (c) 2021-present, Joshua Hemphill
93
+ // Copyright (c) 2021, Tecnico Corporation
94
+ //
95
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
96
+ // of this software and associated documentation files (the "Software"), to deal
97
+ // in the Software without restriction, including without limitation the rights
98
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
+ // copies of the Software, and to permit persons to whom the Software is
100
+ // furnished to do so, subject to the following conditions:
101
+ //
102
+ // The above copyright notice and this permission notice shall be included in all
103
+ // copies or substantial portions of the Software.
104
+ //
105
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
111
+ // SOFTWARE.
112
+
113
+ export namespace Csp {
114
+ type ActionSource = 'strict-dynamic' | 'report-sample';
115
+ type BaseSource = 'self' | 'unsafe-eval' | 'unsafe-hashes' | 'unsafe-inline' | 'none';
116
+ type CryptoSource = `${'nonce' | 'sha256' | 'sha384' | 'sha512'}-${string}`;
117
+ type FrameSource = HostSource | SchemeSource | 'self' | 'none';
118
+ type HostNameScheme = `${string}.${string}` | 'localhost';
119
+ type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`;
120
+ type HostProtocolSchemes = `${string}://` | '';
121
+ type HttpDelineator = '/' | '?' | '#' | '\\';
122
+ type PortScheme = `:${number}` | '' | ':*';
123
+ type SchemeSource = 'http:' | 'https:' | 'data:' | 'mediastream:' | 'blob:' | 'filesystem:';
124
+ type Source = HostSource | SchemeSource | CryptoSource | BaseSource;
125
+ type Sources = Source[];
126
+ type UriPath = `${HttpDelineator}${string}`;
127
+ }
128
+
129
+ export type CspDirectives = {
130
+ 'child-src'?: Csp.Sources;
131
+ 'default-src'?: Array<Csp.Source | Csp.ActionSource>;
132
+ 'frame-src'?: Csp.Sources;
133
+ 'worker-src'?: Csp.Sources;
134
+ 'connect-src'?: Csp.Sources;
135
+ 'font-src'?: Csp.Sources;
136
+ 'img-src'?: Csp.Sources;
137
+ 'manifest-src'?: Csp.Sources;
138
+ 'media-src'?: Csp.Sources;
139
+ 'object-src'?: Csp.Sources;
140
+ 'prefetch-src'?: Csp.Sources;
141
+ 'script-src'?: Array<Csp.Source | Csp.ActionSource>;
142
+ 'script-src-elem'?: Csp.Sources;
143
+ 'script-src-attr'?: Csp.Sources;
144
+ 'style-src'?: Array<Csp.Source | Csp.ActionSource>;
145
+ 'style-src-elem'?: Csp.Sources;
146
+ 'style-src-attr'?: Csp.Sources;
147
+ 'base-uri'?: Array<Csp.Source | Csp.ActionSource>;
148
+ sandbox?: Array<
149
+ | 'allow-downloads-without-user-activation'
150
+ | 'allow-forms'
151
+ | 'allow-modals'
152
+ | 'allow-orientation-lock'
153
+ | 'allow-pointer-lock'
154
+ | 'allow-popups'
155
+ | 'allow-popups-to-escape-sandbox'
156
+ | 'allow-presentation'
157
+ | 'allow-same-origin'
158
+ | 'allow-scripts'
159
+ | 'allow-storage-access-by-user-activation'
160
+ | 'allow-top-navigation'
161
+ | 'allow-top-navigation-by-user-activation'
162
+ >;
163
+ 'form-action'?: Array<Csp.Source | Csp.ActionSource>;
164
+ 'frame-ancestors'?: Array<Csp.HostSource | Csp.SchemeSource | Csp.FrameSource>;
165
+ 'navigate-to'?: Array<Csp.Source | Csp.ActionSource>;
166
+ 'report-uri'?: Csp.UriPath[];
167
+ 'report-to'?: string[];
168
+
169
+ 'require-trusted-types-for'?: Array<'script'>;
170
+ 'trusted-types'?: Array<'none' | 'allow-duplicates' | '*' | string>;
171
+ 'upgrade-insecure-requests'?: boolean;
172
+
173
+ /** @deprecated */
174
+ 'require-sri-for'?: Array<'script' | 'style' | 'script style'>;
175
+
176
+ /** @deprecated */
177
+ 'block-all-mixed-content'?: boolean;
178
+
179
+ /** @deprecated */
180
+ 'plugin-types'?: Array<`${string}/${string}` | 'none'>;
181
+
182
+ /** @deprecated */
183
+ referrer?: Array<
184
+ | 'no-referrer'
185
+ | 'no-referrer-when-downgrade'
186
+ | 'origin'
187
+ | 'origin-when-cross-origin'
188
+ | 'same-origin'
189
+ | 'strict-origin'
190
+ | 'strict-origin-when-cross-origin'
191
+ | 'unsafe-url'
192
+ | 'none'
193
+ >;
194
+ };
195
+
196
+ export type Either<T, U> = Only<T, U> | Only<U, T>;
197
+
198
+ export interface EndpointOutput<Output extends Body = Body> {
199
+ status?: number;
200
+ headers?: Headers | Partial<ResponseHeaders>;
201
+ body?: Output;
202
+ }
203
+
204
+ export interface ErrorLoadInput<Params = Record<string, string>> extends LoadInput<Params> {
205
+ status?: number;
206
+ error?: Error;
207
+ }
208
+
209
+ export interface Fallthrough {
210
+ fallthrough: true;
211
+ }
212
+
213
+ export type HttpMethod = 'get' | 'head' | 'post' | 'put' | 'delete' | 'patch';
214
+
215
+ export type JSONObject = { [key: string]: JSONValue };
216
+
217
+ export type JSONValue = string | number | boolean | null | ToJSON | JSONValue[] | JSONObject;
218
+
219
+ export interface LoadInput<Params = Record<string, string>> {
220
+ url: URL;
221
+ params: Params;
222
+ props: Record<string, any>;
223
+ fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
224
+ session: App.Session;
225
+ stuff: Partial<App.Stuff>;
226
+ }
227
+
228
+ export interface LoadOutput<Props = Record<string, any>> {
229
+ status?: number;
230
+ error?: string | Error;
231
+ redirect?: string;
232
+ props?: Props;
233
+ stuff?: Partial<App.Stuff>;
234
+ maxage?: number;
235
+ }
236
+
237
+ export interface Logger {
238
+ (msg: string): void;
239
+ success(msg: string): void;
240
+ error(msg: string): void;
241
+ warn(msg: string): void;
242
+ minor(msg: string): void;
243
+ info(msg: string): void;
244
+ }
245
+
246
+ export type MaybePromise<T> = T | Promise<T>;
247
+
248
+ export type Only<T, U> = { [P in keyof T]: T[P] } & { [P in Exclude<keyof U, keyof T>]?: never };
249
+
250
+ export interface Prerendered {
251
+ pages: Map<
252
+ string,
253
+ {
254
+ /** The location of the .html file relative to the output directory */
255
+ file: string;
256
+ }
257
+ >;
258
+ assets: Map<
259
+ string,
260
+ {
261
+ /** The MIME type of the asset */
262
+ type: string;
263
+ }
264
+ >;
265
+ redirects: Map<
266
+ string,
267
+ {
268
+ status: number;
269
+ location: string;
270
+ }
271
+ >;
272
+ /** An array of prerendered paths (without trailing slashes, regardless of the trailingSlash config) */
273
+ paths: string[];
274
+ }
275
+
276
+ export interface PrerenderErrorHandler {
277
+ (details: {
278
+ status: number;
279
+ path: string;
280
+ referrer: string | null;
281
+ referenceType: 'linked' | 'fetched';
282
+ }): void;
283
+ }
284
+
285
+ export type PrerenderOnErrorValue = 'fail' | 'continue' | PrerenderErrorHandler;
286
+
287
+ export interface RequestEvent<Params = Record<string, string>> {
288
+ request: Request;
289
+ url: URL;
290
+ params: Params;
291
+ locals: App.Locals;
292
+ platform: Readonly<App.Platform>;
293
+ }
294
+
295
+ export interface RequestOptions {
296
+ platform?: App.Platform;
297
+ }
298
+
299
+ export type ResolveOptions = {
300
+ ssr?: boolean;
301
+ transformPage?: ({ html }: { html: string }) => MaybePromise<string>;
302
+ };
303
+
304
+ /** `string[]` is only for set-cookie, everything else must be type of `string` */
305
+ export type ResponseHeaders = Record<string, string | number | string[]>;
306
+
307
+ export interface RouteDefinition {
308
+ type: 'page' | 'endpoint';
309
+ pattern: RegExp;
310
+ segments: RouteSegment[];
311
+ methods: HttpMethod[];
312
+ }
313
+
314
+ export interface RouteSegment {
315
+ content: string;
316
+ dynamic: boolean;
317
+ rest: boolean;
318
+ }
319
+
320
+ export class Server {
321
+ constructor(manifest: SSRManifest);
322
+ respond(request: Request, options?: RequestOptions): Promise<Response>;
323
+ }
324
+
325
+ export interface SSRManifest {
326
+ appDir: string;
327
+ assets: Set<string>;
328
+ /** private fields */
329
+ _: {
330
+ mime: Record<string, string>;
331
+ entry: {
332
+ file: string;
333
+ js: string[];
334
+ css: string[];
335
+ };
336
+ nodes: SSRNodeLoader[];
337
+ routes: SSRRoute[];
338
+ };
339
+ }
340
+
341
+ export type ToJSON = { toJSON(...args: any[]): Exclude<JSONValue, ToJSON> };
342
+
343
+ export type TrailingSlash = 'never' | 'always' | 'ignore';