@sveltejs/kit 3.0.0-next.6 → 3.0.0-next.7
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.
- package/package.json +7 -2
- package/src/core/adapt/builder.js +11 -39
- package/src/core/config/index.js +76 -71
- package/src/core/config/options.js +280 -285
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +85 -1
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/sync/create_manifest_data/index.js +6 -44
- package/src/core/sync/write_client_manifest.js +7 -14
- package/src/core/sync/write_non_ambient.js +10 -7
- package/src/core/sync/write_root.js +9 -30
- package/src/core/sync/write_server.js +0 -1
- package/src/core/sync/write_types/index.js +11 -10
- package/src/exports/index.js +3 -3
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/index.js +1 -91
- package/src/exports/internal/{event.js → server/event.js} +1 -2
- package/src/exports/internal/server/index.js +33 -0
- package/src/exports/internal/shared.js +89 -0
- package/src/exports/node/index.js +1 -1
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +82 -32
- package/src/exports/url.js +84 -0
- package/src/exports/vite/dev/index.js +28 -17
- package/src/exports/vite/index.js +217 -156
- package/src/exports/vite/preview/index.js +1 -1
- package/src/exports/vite/utils.js +3 -5
- package/src/runtime/app/paths/client.js +3 -7
- package/src/runtime/app/paths/server.js +1 -1
- package/src/runtime/app/server/remote/query.js +6 -12
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/client.js +26 -79
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/form.svelte.js +5 -24
- package/src/runtime/client/remote-functions/prerender.svelte.js +10 -3
- package/src/runtime/client/remote-functions/query/instance.svelte.js +18 -9
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +16 -6
- package/src/runtime/client/remote-functions/shared.svelte.js +1 -2
- package/src/runtime/client/state.svelte.js +66 -49
- package/src/runtime/client/types.d.ts +1 -1
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/form-utils.js +15 -2
- package/src/runtime/server/index.js +1 -1
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +15 -24
- package/src/runtime/server/page/server_routing.js +13 -9
- package/src/runtime/server/remote.js +21 -12
- package/src/runtime/server/respond.js +11 -8
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/types/ambient.d.ts +5 -1
- package/src/types/global-private.d.ts +1 -1
- package/src/types/internal.d.ts +9 -10
- package/src/utils/error.js +1 -1
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +84 -38
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +0 -79
- package/src/version.js +1 -1
- package/types/index.d.ts +98 -87
- package/types/index.d.ts.map +10 -7
- package/src/exports/internal/server.js +0 -22
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @import { SvelteConfig } from '@sveltejs/vite-plugin-svelte' */
|
|
2
|
+
/** @import { ValidatedKitConfig } from 'types' */
|
|
1
3
|
/** @import { Validator } from './types.js' */
|
|
2
4
|
|
|
3
5
|
const directives = object({
|
|
@@ -34,8 +36,8 @@ const directives = object({
|
|
|
34
36
|
referrer: string_array()
|
|
35
37
|
});
|
|
36
38
|
|
|
37
|
-
/** @type {Validator} */
|
|
38
|
-
export const
|
|
39
|
+
/** @type {Validator<{ extensions: string[] } & SvelteConfig>} */
|
|
40
|
+
export const validate_svelte_options = object(
|
|
39
41
|
{
|
|
40
42
|
extensions: validate(['.svelte'], (input, keypath) => {
|
|
41
43
|
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
@@ -53,289 +55,296 @@ export const options = object(
|
|
|
53
55
|
});
|
|
54
56
|
|
|
55
57
|
return input;
|
|
56
|
-
})
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
true
|
|
61
|
+
);
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
/** @type {Validator<ValidatedKitConfig>} */
|
|
64
|
+
export const validate_kit_options = object({
|
|
65
|
+
adapter: validate(undefined, (input, keypath) => {
|
|
66
|
+
if (typeof input !== 'object' || !input.adapt) {
|
|
67
|
+
const message = `The SvelteKit Vite plugin ${keypath} should be an object with an \`adapt\` method`;
|
|
68
|
+
throw new Error(`${message}. See https://svelte.dev/docs/kit/adapters`);
|
|
69
|
+
}
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
return input;
|
|
72
|
+
}),
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
alias: validate({}, (input, keypath) => {
|
|
75
|
+
if (typeof input !== 'object') {
|
|
76
|
+
throw new Error(`${keypath} should be an object`);
|
|
77
|
+
}
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
for (const key in input) {
|
|
80
|
+
assert_string(input[key], `${keypath}.${key}`);
|
|
81
|
+
}
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
return input;
|
|
84
|
+
}),
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
appDir: validate('_app', (input, keypath) => {
|
|
87
|
+
assert_string(input, keypath);
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
if (input) {
|
|
90
|
+
if (input.startsWith('/') || input.endsWith('/')) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`${keypath} cannot start or end with '/'. See https://svelte.dev/docs/kit/configuration`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
throw new Error(`${keypath} cannot be empty`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return input;
|
|
100
|
+
}),
|
|
101
|
+
|
|
102
|
+
csp: object({
|
|
103
|
+
mode: list(['auto', 'hash', 'nonce']),
|
|
104
|
+
directives,
|
|
105
|
+
reportOnly: directives
|
|
106
|
+
}),
|
|
107
|
+
|
|
108
|
+
csrf: object({
|
|
109
|
+
checkOrigin: removed(
|
|
110
|
+
(keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
|
|
111
|
+
),
|
|
112
|
+
trustedOrigins: string_array([])
|
|
113
|
+
}),
|
|
114
|
+
|
|
115
|
+
embedded: boolean(false),
|
|
116
|
+
|
|
117
|
+
env: object({
|
|
118
|
+
dir: string('')
|
|
119
|
+
}),
|
|
120
|
+
|
|
121
|
+
experimental: object({
|
|
122
|
+
tracing: removed(
|
|
123
|
+
(keypath) =>
|
|
124
|
+
`\`${keypath}\` has been removed. Server-side tracing is now configured via \`tracing.server\``
|
|
125
|
+
),
|
|
126
|
+
instrumentation: removed(
|
|
127
|
+
(keypath) =>
|
|
128
|
+
`\`${keypath}\` has been removed. \`src/instrumentation.server.js\` is now included in the build automatically when it exists; no opt-in is required`
|
|
129
|
+
),
|
|
130
|
+
remoteFunctions: boolean(false),
|
|
131
|
+
forkPreloads: boolean(false),
|
|
132
|
+
handleRenderingErrors: boolean(false)
|
|
133
|
+
}),
|
|
134
|
+
|
|
135
|
+
files: object({
|
|
136
|
+
src: string('src'),
|
|
137
|
+
assets: string('static'),
|
|
138
|
+
hooks: object({
|
|
139
|
+
client: string(null),
|
|
140
|
+
server: string(null),
|
|
141
|
+
universal: string(null)
|
|
142
|
+
}),
|
|
143
|
+
lib: string(null),
|
|
144
|
+
params: string(null),
|
|
145
|
+
routes: string(null),
|
|
146
|
+
serviceWorker: string(null),
|
|
147
|
+
appTemplate: string(null),
|
|
148
|
+
errorTemplate: string(null)
|
|
149
|
+
}),
|
|
150
|
+
|
|
151
|
+
inlineStyleThreshold: number(0),
|
|
152
|
+
|
|
153
|
+
moduleExtensions: string_array(['.js', '.ts']),
|
|
154
|
+
|
|
155
|
+
outDir: string('.svelte-kit'),
|
|
156
|
+
|
|
157
|
+
output: object({
|
|
158
|
+
linkHeaderPreload: boolean(false),
|
|
159
|
+
preloadStrategy: removed(
|
|
160
|
+
(keypath) => `\`${keypath}\` has been removed. modulepreload will always be used`
|
|
161
|
+
),
|
|
162
|
+
bundleStrategy: list(['split', 'single', 'inline'])
|
|
163
|
+
}),
|
|
164
|
+
|
|
165
|
+
paths: object({
|
|
166
|
+
base: validate('', (input, keypath) => {
|
|
167
|
+
assert_string(input, keypath);
|
|
168
|
+
|
|
169
|
+
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return input;
|
|
176
|
+
}),
|
|
177
|
+
assets: validate('', (input, keypath) => {
|
|
178
|
+
assert_string(input, keypath);
|
|
179
|
+
|
|
180
|
+
if (input) {
|
|
181
|
+
if (!/^[a-z]+:\/\//.test(input)) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`${keypath} option must be an absolute path, if specified. See https://svelte.dev/docs/kit/configuration#paths`
|
|
184
|
+
);
|
|
91
185
|
}
|
|
92
186
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
reportOnly: directives
|
|
100
|
-
}),
|
|
101
|
-
|
|
102
|
-
csrf: object({
|
|
103
|
-
checkOrigin: removed(
|
|
104
|
-
(keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
|
|
105
|
-
),
|
|
106
|
-
trustedOrigins: string_array([])
|
|
107
|
-
}),
|
|
108
|
-
|
|
109
|
-
embedded: boolean(false),
|
|
110
|
-
|
|
111
|
-
env: object({
|
|
112
|
-
dir: string('')
|
|
113
|
-
}),
|
|
114
|
-
|
|
115
|
-
experimental: object({
|
|
116
|
-
tracing: object({
|
|
117
|
-
server: boolean(false)
|
|
118
|
-
}),
|
|
119
|
-
instrumentation: object({
|
|
120
|
-
server: boolean(false)
|
|
121
|
-
}),
|
|
122
|
-
remoteFunctions: boolean(false),
|
|
123
|
-
forkPreloads: boolean(false),
|
|
124
|
-
handleRenderingErrors: boolean(false)
|
|
125
|
-
}),
|
|
126
|
-
|
|
127
|
-
files: object({
|
|
128
|
-
src: string('src'),
|
|
129
|
-
assets: string('static'),
|
|
130
|
-
hooks: object({
|
|
131
|
-
client: string(null),
|
|
132
|
-
server: string(null),
|
|
133
|
-
universal: string(null)
|
|
134
|
-
}),
|
|
135
|
-
lib: string(null),
|
|
136
|
-
params: string(null),
|
|
137
|
-
routes: string(null),
|
|
138
|
-
serviceWorker: string(null),
|
|
139
|
-
appTemplate: string(null),
|
|
140
|
-
errorTemplate: string(null)
|
|
141
|
-
}),
|
|
142
|
-
|
|
143
|
-
inlineStyleThreshold: number(0),
|
|
144
|
-
|
|
145
|
-
moduleExtensions: string_array(['.js', '.ts']),
|
|
146
|
-
|
|
147
|
-
outDir: string('.svelte-kit'),
|
|
148
|
-
|
|
149
|
-
output: object({
|
|
150
|
-
linkHeaderPreload: boolean(false),
|
|
151
|
-
preloadStrategy: removed(
|
|
152
|
-
(keypath) => `\`${keypath}\` has been removed. modulepreload will always be used`
|
|
153
|
-
),
|
|
154
|
-
bundleStrategy: list(['split', 'single', 'inline'])
|
|
155
|
-
}),
|
|
156
|
-
|
|
157
|
-
paths: object({
|
|
158
|
-
base: validate('', (input, keypath) => {
|
|
159
|
-
assert_string(input, keypath);
|
|
160
|
-
|
|
161
|
-
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
`${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
164
|
-
);
|
|
165
|
-
}
|
|
187
|
+
if (input.endsWith('/')) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`${keypath} option must not end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
166
193
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (input) {
|
|
173
|
-
if (!/^[a-z]+:\/\//.test(input)) {
|
|
174
|
-
throw new Error(
|
|
175
|
-
`${keypath} option must be an absolute path, if specified. See https://svelte.dev/docs/kit/configuration#paths`
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (input.endsWith('/')) {
|
|
180
|
-
throw new Error(
|
|
181
|
-
`${keypath} option must not end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
194
|
+
return input;
|
|
195
|
+
}),
|
|
196
|
+
origin: validate(undefined, (input, keypath) => {
|
|
197
|
+
assert_string(input, keypath);
|
|
185
198
|
|
|
186
|
-
|
|
187
|
-
}),
|
|
188
|
-
origin: validate(undefined, (input, keypath) => {
|
|
189
|
-
assert_string(input, keypath);
|
|
199
|
+
let url;
|
|
190
200
|
|
|
191
|
-
|
|
201
|
+
try {
|
|
202
|
+
url = new URL(input);
|
|
203
|
+
} catch {
|
|
204
|
+
throw new Error(
|
|
205
|
+
`${keypath} must be a valid origin (e.g. 'https://my-site.com'). '${input}' could not be parsed as a URL`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
192
208
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
);
|
|
199
|
-
}
|
|
209
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`${keypath} must be a valid origin — only 'http' and 'https' protocols are supported, received '${url.protocol}'`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
200
214
|
|
|
201
|
-
|
|
202
|
-
throw new Error(
|
|
203
|
-
`${keypath} must be a valid origin — only 'http' and 'https' protocols are supported, received '${url.protocol}'`
|
|
204
|
-
);
|
|
205
|
-
}
|
|
215
|
+
const origin = url.origin;
|
|
206
216
|
|
|
207
|
-
|
|
217
|
+
if (input !== origin) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`${keypath} must be a valid origin — received '${input}' which contains a path, query, or hash. Use the bare origin '${origin}' instead`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
208
222
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
223
|
+
return origin;
|
|
224
|
+
}),
|
|
225
|
+
relative: boolean(true)
|
|
226
|
+
}),
|
|
214
227
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
crawl: boolean(true),
|
|
223
|
-
entries: validate(['*'], (input, keypath) => {
|
|
224
|
-
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
225
|
-
throw new Error(`${keypath} must be an array of strings`);
|
|
226
|
-
}
|
|
228
|
+
prerender: object({
|
|
229
|
+
concurrency: number(1),
|
|
230
|
+
crawl: boolean(true),
|
|
231
|
+
entries: validate(['*'], (input, keypath) => {
|
|
232
|
+
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
233
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
234
|
+
}
|
|
227
235
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
)
|
|
236
|
+
input.forEach((page) => {
|
|
237
|
+
if (page !== '*' && page[0] !== '/') {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return input;
|
|
245
|
+
}),
|
|
246
|
+
|
|
247
|
+
handleHttpError: validate(
|
|
248
|
+
(/** @type {any} */ { message }) => {
|
|
249
|
+
throw new Error(
|
|
250
|
+
message +
|
|
251
|
+
'\nTo suppress or handle this error, implement `handleHttpError` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
252
|
+
);
|
|
253
|
+
},
|
|
254
|
+
(input, keypath) => {
|
|
255
|
+
if (typeof input === 'function') return input;
|
|
256
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
257
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
258
|
+
}
|
|
259
|
+
),
|
|
260
|
+
|
|
261
|
+
handleMissingId: validate(
|
|
262
|
+
(/** @type {any} */ { message }) => {
|
|
263
|
+
throw new Error(
|
|
264
|
+
message +
|
|
265
|
+
'\nTo suppress or handle this error, implement `handleMissingId` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
266
|
+
);
|
|
267
|
+
},
|
|
268
|
+
(input, keypath) => {
|
|
269
|
+
if (typeof input === 'function') return input;
|
|
270
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
271
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
272
|
+
}
|
|
273
|
+
),
|
|
274
|
+
|
|
275
|
+
handleEntryGeneratorMismatch: validate(
|
|
276
|
+
(/** @type {any} */ { message }) => {
|
|
277
|
+
throw new Error(
|
|
278
|
+
message +
|
|
279
|
+
'\nTo suppress or handle this error, implement `handleEntryGeneratorMismatch` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
280
|
+
);
|
|
281
|
+
},
|
|
282
|
+
(input, keypath) => {
|
|
283
|
+
if (typeof input === 'function') return input;
|
|
284
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
285
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
286
|
+
}
|
|
287
|
+
),
|
|
288
|
+
|
|
289
|
+
handleUnseenRoutes: validate(
|
|
290
|
+
(/** @type {any} */ { message }) => {
|
|
291
|
+
throw new Error(
|
|
292
|
+
message +
|
|
293
|
+
'\nTo suppress or handle this error, implement `handleUnseenRoutes` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
(input, keypath) => {
|
|
297
|
+
if (typeof input === 'function') return input;
|
|
298
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
299
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
300
|
+
}
|
|
301
|
+
),
|
|
302
|
+
|
|
303
|
+
handleInvalidUrl: validate(
|
|
304
|
+
(/** @type {any} */ { message }) => {
|
|
305
|
+
throw new Error(
|
|
306
|
+
message +
|
|
307
|
+
'\nTo suppress or handle this error, implement `handleInvalidUrl` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
308
|
+
);
|
|
309
|
+
},
|
|
310
|
+
(input, keypath) => {
|
|
311
|
+
if (typeof input === 'function') return input;
|
|
312
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
313
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
314
|
+
}
|
|
315
|
+
),
|
|
316
|
+
|
|
317
|
+
origin: removed(
|
|
318
|
+
(keypath) => `\`${keypath}\` has been removed in favour of \`config.paths.origin\``
|
|
319
|
+
)
|
|
320
|
+
}),
|
|
321
|
+
|
|
322
|
+
router: object({
|
|
323
|
+
type: list(['pathname', 'hash']),
|
|
324
|
+
resolution: list(['client', 'server'])
|
|
325
|
+
}),
|
|
326
|
+
|
|
327
|
+
serviceWorker: object({
|
|
328
|
+
register: boolean(true),
|
|
329
|
+
// options could be undefined but if it is defined we only validate that
|
|
330
|
+
// it's an object since the type comes from the browser itself
|
|
331
|
+
options: validate(undefined, object({}, true)),
|
|
332
|
+
files: fun((filename) => !/\.DS_Store/.test(filename))
|
|
333
|
+
}),
|
|
334
|
+
|
|
335
|
+
tracing: object({
|
|
336
|
+
server: boolean(false)
|
|
337
|
+
}),
|
|
338
|
+
|
|
339
|
+
typescript: object({
|
|
340
|
+
config: fun((config) => config)
|
|
341
|
+
}),
|
|
342
|
+
|
|
343
|
+
version: object({
|
|
344
|
+
name: string(Date.now().toString()),
|
|
345
|
+
pollInterval: number(0)
|
|
346
|
+
})
|
|
347
|
+
});
|
|
339
348
|
|
|
340
349
|
// /**
|
|
341
350
|
// * @param {Validator} fn
|
|
@@ -361,13 +370,13 @@ export const options = object(
|
|
|
361
370
|
// Derive the names of SvelteKit's own config options from the schema, so they
|
|
362
371
|
// stay in sync automatically. These are used to separate Kit's options from
|
|
363
372
|
// `vite-plugin-svelte`'s options when config is passed via the Vite plugin.
|
|
364
|
-
const
|
|
373
|
+
const kit_defaults = validate_kit_options({}, 'config');
|
|
365
374
|
|
|
366
375
|
/** The names of the options that live under the `kit` namespace */
|
|
367
|
-
export const kit_options = Object.keys(
|
|
376
|
+
export const kit_options = Object.keys(kit_defaults);
|
|
368
377
|
|
|
369
378
|
/** The names of the options that live under the `kit.experimental` namespace */
|
|
370
|
-
export const kit_experimental_options = Object.keys(
|
|
379
|
+
export const kit_experimental_options = Object.keys(kit_defaults.experimental);
|
|
371
380
|
|
|
372
381
|
/**
|
|
373
382
|
* @param {(keypath: string) => string} get_message
|
|
@@ -378,8 +387,6 @@ function removed(
|
|
|
378
387
|
`The \`${keypath}\` option has been removed. Please see the list of breaking changes for your major release`
|
|
379
388
|
) {
|
|
380
389
|
return (input, keypath) => {
|
|
381
|
-
keypath = remove_kit_prefix(keypath);
|
|
382
|
-
|
|
383
390
|
if (typeof input !== 'undefined') {
|
|
384
391
|
throw new Error(get_message(keypath));
|
|
385
392
|
}
|
|
@@ -393,8 +400,6 @@ function removed(
|
|
|
393
400
|
*/
|
|
394
401
|
export function object(children, allow_unknown = false) {
|
|
395
402
|
return (input, keypath) => {
|
|
396
|
-
keypath = remove_kit_prefix(keypath);
|
|
397
|
-
|
|
398
403
|
/** @type {Record<string, any>} */
|
|
399
404
|
const output = {};
|
|
400
405
|
|
|
@@ -410,7 +415,7 @@ export function object(children, allow_unknown = false) {
|
|
|
410
415
|
let message = `Unexpected option ${keypath}.${key}`;
|
|
411
416
|
|
|
412
417
|
// special case
|
|
413
|
-
if (keypath === 'config.kit' && key in
|
|
418
|
+
if (keypath === 'config.kit' && key in kit_options) {
|
|
414
419
|
message += ` (did you mean config.${key}?)`;
|
|
415
420
|
}
|
|
416
421
|
|
|
@@ -435,7 +440,6 @@ export function object(children, allow_unknown = false) {
|
|
|
435
440
|
*/
|
|
436
441
|
export function validate(fallback, fn) {
|
|
437
442
|
return (input, keypath) => {
|
|
438
|
-
keypath = remove_kit_prefix(keypath);
|
|
439
443
|
return input === undefined ? fallback : fn(input, keypath);
|
|
440
444
|
};
|
|
441
445
|
}
|
|
@@ -533,16 +537,7 @@ function fun(fallback) {
|
|
|
533
537
|
* @param {string} keypath
|
|
534
538
|
*/
|
|
535
539
|
function assert_string(input, keypath) {
|
|
536
|
-
keypath = remove_kit_prefix(keypath);
|
|
537
540
|
if (typeof input !== 'string') {
|
|
538
541
|
throw new Error(`${keypath} should be a string, if specified`);
|
|
539
542
|
}
|
|
540
543
|
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* @param {string} keypath
|
|
544
|
-
* @deprecated TODO get rid of the nesting so this is unnecessary
|
|
545
|
-
*/
|
|
546
|
-
function remove_kit_prefix(keypath) {
|
|
547
|
-
return keypath.replace('.kit.', '.');
|
|
548
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Validator<T = any> = (input:
|
|
1
|
+
export type Validator<T = any> = (input: any, keypath: string) => T;
|