@sveltejs/kit 1.0.0-next.402 → 1.0.0-next.406
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 +24 -25
- package/{dist → src}/cli.js +19 -18
- package/{dist/chunks/index3.js → src/core/adapt/builder.js} +52 -63
- package/src/core/adapt/index.js +19 -0
- package/src/core/config/index.js +86 -0
- package/{dist/chunks/index.js → src/core/config/options.js} +7 -194
- package/src/core/config/types.d.ts +1 -0
- package/src/core/constants.js +3 -0
- package/src/core/generate_manifest/index.js +99 -0
- package/src/core/prerender/crawl.js +194 -0
- package/src/core/prerender/prerender.js +378 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +492 -0
- package/src/core/sync/create_manifest_data/types.d.ts +40 -0
- package/src/core/sync/sync.js +59 -0
- package/src/core/sync/utils.js +97 -0
- package/src/core/sync/write_ambient.js +87 -0
- package/src/core/sync/write_client_manifest.js +82 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +88 -0
- package/{dist/chunks → src/core/sync}/write_tsconfig.js +24 -108
- package/src/core/sync/write_types.js +738 -0
- package/src/core/utils.js +58 -0
- package/{dist → src}/hooks.js +1 -3
- package/src/index/index.js +45 -0
- package/src/index/private.js +31 -0
- package/src/node/index.js +145 -0
- package/src/node/polyfills.js +40 -0
- package/src/packaging/index.js +218 -0
- package/src/packaging/types.d.ts +8 -0
- package/src/packaging/typescript.js +150 -0
- package/src/packaging/utils.js +138 -0
- package/{assets → src/runtime}/app/env.js +3 -5
- package/src/runtime/app/navigation.js +22 -0
- package/src/runtime/app/paths.js +1 -0
- package/{assets → src/runtime}/app/stores.js +6 -9
- package/src/runtime/client/ambient.d.ts +17 -0
- package/{assets/client/start.js → src/runtime/client/client.js} +302 -878
- package/src/runtime/client/fetcher.js +60 -0
- package/src/runtime/client/parse.js +36 -0
- package/{assets → src/runtime}/client/singletons.js +2 -4
- package/src/runtime/client/start.js +48 -0
- package/src/runtime/client/types.d.ts +106 -0
- package/src/runtime/client/utils.js +113 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/{assets → src/runtime}/env/dynamic/private.js +0 -0
- package/{assets → src/runtime}/env/dynamic/public.js +0 -0
- package/{assets → src/runtime}/env-private.js +2 -4
- package/{assets → src/runtime}/env-public.js +2 -4
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +16 -0
- package/{assets → src/runtime}/paths.js +3 -5
- package/src/runtime/server/endpoint.js +42 -0
- package/src/runtime/server/index.js +434 -0
- package/src/runtime/server/page/cookie.js +25 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +249 -0
- package/src/runtime/server/page/fetch.js +265 -0
- package/src/runtime/server/page/index.js +423 -0
- package/src/runtime/server/page/load_data.js +94 -0
- package/src/runtime/server/page/render.js +357 -0
- package/src/runtime/server/page/respond_with_error.js +105 -0
- package/src/runtime/server/page/types.d.ts +44 -0
- package/src/runtime/server/utils.js +116 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +104 -0
- package/{dist/chunks → src/utils}/filesystem.js +22 -24
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/routing.js +107 -0
- package/src/utils/url.js +97 -0
- package/src/vite/build/build_server.js +333 -0
- package/src/vite/build/build_service_worker.js +90 -0
- package/src/vite/build/utils.js +152 -0
- package/src/vite/dev/index.js +565 -0
- package/src/vite/index.js +536 -0
- package/src/vite/preview/index.js +186 -0
- package/src/vite/types.d.ts +3 -0
- package/src/vite/utils.js +335 -0
- package/svelte-kit.js +1 -10
- package/types/ambient.d.ts +5 -12
- package/types/index.d.ts +91 -44
- package/types/internal.d.ts +50 -72
- package/types/private.d.ts +2 -1
- package/assets/app/navigation.js +0 -24
- package/assets/app/paths.js +0 -1
- package/assets/components/error.svelte +0 -29
- package/assets/env.js +0 -8
- package/assets/server/index.js +0 -3579
- package/dist/chunks/error.js +0 -12
- package/dist/chunks/index2.js +0 -15745
- package/dist/chunks/multipart-parser.js +0 -458
- package/dist/chunks/sync.js +0 -1366
- package/dist/chunks/utils.js +0 -66
- package/dist/node/polyfills.js +0 -17778
- package/dist/node.js +0 -348
- package/dist/prerender.js +0 -788
- package/dist/vite.js +0 -2520
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { loadConfigFromFile, loadEnv, normalizePath } from 'vite';
|
|
4
|
+
import { runtime_directory } from '../core/utils.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('vite').ResolvedConfig} config
|
|
8
|
+
* @param {import('vite').ConfigEnv} config_env
|
|
9
|
+
* @return {Promise<import('vite').UserConfig>}
|
|
10
|
+
*/
|
|
11
|
+
export async function get_vite_config(config, config_env) {
|
|
12
|
+
const loaded = await loadConfigFromFile(
|
|
13
|
+
config_env,
|
|
14
|
+
config.configFile,
|
|
15
|
+
undefined,
|
|
16
|
+
config.logLevel
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (!loaded) {
|
|
20
|
+
throw new Error('Could not load Vite config');
|
|
21
|
+
}
|
|
22
|
+
return { ...loaded.config, mode: config_env.mode };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {...import('vite').UserConfig} configs
|
|
27
|
+
* @returns {import('vite').UserConfig}
|
|
28
|
+
*/
|
|
29
|
+
export function merge_vite_configs(...configs) {
|
|
30
|
+
return deep_merge(
|
|
31
|
+
...configs.map((config) => ({
|
|
32
|
+
...config,
|
|
33
|
+
resolve: {
|
|
34
|
+
...config.resolve,
|
|
35
|
+
alias: normalize_alias(config.resolve?.alias || {})
|
|
36
|
+
}
|
|
37
|
+
}))
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Takes zero or more objects and returns a new object that has all the values
|
|
43
|
+
* deeply merged together. None of the original objects will be mutated at any
|
|
44
|
+
* level, and the returned object will have no references to the original
|
|
45
|
+
* objects at any depth. If there's a conflict the last one wins, except for
|
|
46
|
+
* arrays which will be combined.
|
|
47
|
+
* @param {...Object} objects
|
|
48
|
+
* @returns {Record<string, any>} the merged object
|
|
49
|
+
*/
|
|
50
|
+
export function deep_merge(...objects) {
|
|
51
|
+
const result = {};
|
|
52
|
+
/** @type {string[]} */
|
|
53
|
+
objects.forEach((o) => merge_into(result, o));
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* normalize kit.vite.resolve.alias as an array
|
|
59
|
+
* @param {import('vite').AliasOptions} o
|
|
60
|
+
* @returns {import('vite').Alias[]}
|
|
61
|
+
*/
|
|
62
|
+
function normalize_alias(o) {
|
|
63
|
+
if (Array.isArray(o)) return o;
|
|
64
|
+
return Object.entries(o).map(([find, replacement]) => ({ find, replacement }));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Merges b into a, recursively, mutating a.
|
|
69
|
+
* @param {Record<string, any>} a
|
|
70
|
+
* @param {Record<string, any>} b
|
|
71
|
+
*/
|
|
72
|
+
function merge_into(a, b) {
|
|
73
|
+
/**
|
|
74
|
+
* Checks for "plain old Javascript object", typically made as an object
|
|
75
|
+
* literal. Excludes Arrays and built-in types like Buffer.
|
|
76
|
+
* @param {any} x
|
|
77
|
+
*/
|
|
78
|
+
const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
|
|
79
|
+
|
|
80
|
+
for (const prop in b) {
|
|
81
|
+
if (is_plain_object(b[prop])) {
|
|
82
|
+
if (!is_plain_object(a[prop])) {
|
|
83
|
+
a[prop] = {};
|
|
84
|
+
}
|
|
85
|
+
merge_into(a[prop], b[prop]);
|
|
86
|
+
} else if (Array.isArray(b[prop])) {
|
|
87
|
+
if (!Array.isArray(a[prop])) {
|
|
88
|
+
a[prop] = [];
|
|
89
|
+
}
|
|
90
|
+
a[prop].push(...b[prop]);
|
|
91
|
+
} else {
|
|
92
|
+
a[prop] = b[prop];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Transforms kit.alias to a valid vite.resolve.alias array.
|
|
99
|
+
* Related to tsconfig path alias creation.
|
|
100
|
+
*
|
|
101
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
102
|
+
* */
|
|
103
|
+
export function get_aliases(config) {
|
|
104
|
+
/** @type {import('vite').Alias[]} */
|
|
105
|
+
const alias = [
|
|
106
|
+
{ find: '__GENERATED__', replacement: path.posix.join(config.outDir, 'generated') },
|
|
107
|
+
{ find: '$app', replacement: `${runtime_directory}/app` },
|
|
108
|
+
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
109
|
+
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
110
|
+
{ find: '$lib', replacement: config.files.lib }
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
for (let [key, value] of Object.entries(config.alias)) {
|
|
114
|
+
if (value.endsWith('/*')) {
|
|
115
|
+
value = value.slice(0, -2);
|
|
116
|
+
}
|
|
117
|
+
if (key.endsWith('/*')) {
|
|
118
|
+
// Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
|
|
119
|
+
alias.push({
|
|
120
|
+
find: new RegExp(`^${key.slice(0, -2)}\\/(.+)$`),
|
|
121
|
+
replacement: `${path.resolve(value)}/$1`
|
|
122
|
+
});
|
|
123
|
+
} else if (key + '/*' in config.alias) {
|
|
124
|
+
// key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
|
|
125
|
+
alias.push({ find: new RegExp(`^${key}$`), replacement: path.resolve(value) });
|
|
126
|
+
} else {
|
|
127
|
+
alias.push({ find: key, replacement: path.resolve(value) });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
alias.push(
|
|
132
|
+
{
|
|
133
|
+
find: '$env/static/public',
|
|
134
|
+
replacement: path.posix.join(config.outDir, 'runtime/env/static/public.js')
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
find: '$env/static/private',
|
|
138
|
+
replacement: path.posix.join(config.outDir, 'runtime/env/static/private.js')
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
find: '$env',
|
|
142
|
+
replacement: `${runtime_directory}/env`
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return alias;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
|
|
151
|
+
* @param {string} entry
|
|
152
|
+
* @returns {string|null}
|
|
153
|
+
*/
|
|
154
|
+
export function resolve_entry(entry) {
|
|
155
|
+
if (fs.existsSync(entry)) {
|
|
156
|
+
const stats = fs.statSync(entry);
|
|
157
|
+
if (stats.isDirectory()) {
|
|
158
|
+
return resolve_entry(path.join(entry, 'index'));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return entry;
|
|
162
|
+
} else {
|
|
163
|
+
const dir = path.dirname(entry);
|
|
164
|
+
|
|
165
|
+
if (fs.existsSync(dir)) {
|
|
166
|
+
const base = path.basename(entry);
|
|
167
|
+
const files = fs.readdirSync(dir);
|
|
168
|
+
|
|
169
|
+
const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
|
|
170
|
+
|
|
171
|
+
if (found) return path.join(dir, found);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {string} str
|
|
180
|
+
* @param {number} times
|
|
181
|
+
*/
|
|
182
|
+
function repeat(str, times) {
|
|
183
|
+
return new Array(times + 1).join(str);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Create a formatted error for an illegal import.
|
|
188
|
+
* @param {Array<{name: string, dynamic: boolean}>} stack
|
|
189
|
+
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
190
|
+
*/
|
|
191
|
+
function format_illegal_import_chain(stack, out_dir) {
|
|
192
|
+
const app = path.join(out_dir, 'runtime/env');
|
|
193
|
+
|
|
194
|
+
stack = stack.map((file) => {
|
|
195
|
+
if (file.name.startsWith(app)) return { ...file, name: file.name.replace(app, '$env') };
|
|
196
|
+
return { ...file, name: path.relative(process.cwd(), file.name) };
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const pyramid = stack
|
|
200
|
+
.map(
|
|
201
|
+
(file, i) =>
|
|
202
|
+
`${repeat(' ', i * 2)}- ${file.name} ${
|
|
203
|
+
file.dynamic ? '(imported by parent dynamically)' : ''
|
|
204
|
+
}`
|
|
205
|
+
)
|
|
206
|
+
.join('\n');
|
|
207
|
+
|
|
208
|
+
return `Cannot import ${stack.at(-1)?.name} into client-side code:\n${pyramid}`;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Load environment variables from process.env and .env files
|
|
213
|
+
* @param {string} mode
|
|
214
|
+
* @param {string} prefix
|
|
215
|
+
*/
|
|
216
|
+
export function get_env(mode, prefix) {
|
|
217
|
+
const entries = Object.entries(loadEnv(mode, process.cwd(), ''));
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
public: Object.fromEntries(entries.filter(([k]) => k.startsWith(prefix))),
|
|
221
|
+
private: Object.fromEntries(entries.filter(([k]) => !k.startsWith(prefix)))
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
227
|
+
* @param {import('rollup').ModuleInfo} node
|
|
228
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
229
|
+
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
230
|
+
*/
|
|
231
|
+
export function prevent_illegal_rollup_imports(node_getter, node, illegal_imports, out_dir) {
|
|
232
|
+
const chain = find_illegal_rollup_imports(node_getter, node, false, illegal_imports);
|
|
233
|
+
if (chain) throw new Error(format_illegal_import_chain(chain, out_dir));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
238
|
+
* @param {import('rollup').ModuleInfo} node
|
|
239
|
+
* @param {boolean} dynamic
|
|
240
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
241
|
+
* @param {Set<string>} seen
|
|
242
|
+
* @returns {Array<import('types').ImportNode> | null}
|
|
243
|
+
*/
|
|
244
|
+
const find_illegal_rollup_imports = (
|
|
245
|
+
node_getter,
|
|
246
|
+
node,
|
|
247
|
+
dynamic,
|
|
248
|
+
illegal_imports,
|
|
249
|
+
seen = new Set()
|
|
250
|
+
) => {
|
|
251
|
+
const name = normalizePath(node.id);
|
|
252
|
+
if (seen.has(name)) return null;
|
|
253
|
+
seen.add(name);
|
|
254
|
+
|
|
255
|
+
if (illegal_imports.has(name)) {
|
|
256
|
+
return [{ name, dynamic }];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
for (const id of node.importedIds) {
|
|
260
|
+
const child = node_getter(id);
|
|
261
|
+
const chain =
|
|
262
|
+
child && find_illegal_rollup_imports(node_getter, child, false, illegal_imports, seen);
|
|
263
|
+
if (chain) return [{ name, dynamic }, ...chain];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
for (const id of node.dynamicallyImportedIds) {
|
|
267
|
+
const child = node_getter(id);
|
|
268
|
+
const chain =
|
|
269
|
+
child && find_illegal_rollup_imports(node_getter, child, true, illegal_imports, seen);
|
|
270
|
+
if (chain) return [{ name, dynamic }, ...chain];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return null;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Vite does some weird things with import trees in dev
|
|
278
|
+
* for example, a Tailwind app.css will appear to import
|
|
279
|
+
* every file in the project. This isn't a problem for
|
|
280
|
+
* Rollup during build.
|
|
281
|
+
* @param {Iterable<string>} config_module_types
|
|
282
|
+
*/
|
|
283
|
+
const get_module_types = (config_module_types) => {
|
|
284
|
+
return new Set([
|
|
285
|
+
'.ts',
|
|
286
|
+
'.js',
|
|
287
|
+
'.svelte',
|
|
288
|
+
'.mts',
|
|
289
|
+
'.mjs',
|
|
290
|
+
'.cts',
|
|
291
|
+
'.cjs',
|
|
292
|
+
'.svelte.md',
|
|
293
|
+
'.svx',
|
|
294
|
+
'.md',
|
|
295
|
+
...config_module_types
|
|
296
|
+
]);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Throw an error if a private module is imported from a client-side node.
|
|
301
|
+
* @param {import('vite').ModuleNode} node
|
|
302
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
303
|
+
* @param {Iterable<string>} module_types File extensions to analyze in addition to the defaults: `.ts`, `.js`, etc.
|
|
304
|
+
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
305
|
+
*/
|
|
306
|
+
export function prevent_illegal_vite_imports(node, illegal_imports, module_types, out_dir) {
|
|
307
|
+
const chain = find_illegal_vite_imports(node, illegal_imports, get_module_types(module_types));
|
|
308
|
+
if (chain) throw new Error(format_illegal_import_chain(chain, out_dir));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @param {import('vite').ModuleNode} node
|
|
313
|
+
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
314
|
+
* @param {Set<string>} module_types File extensions to analyze: `.ts`, `.js`, etc.
|
|
315
|
+
* @param {Set<string>} seen
|
|
316
|
+
* @returns {Array<import('types').ImportNode> | null}
|
|
317
|
+
*/
|
|
318
|
+
function find_illegal_vite_imports(node, illegal_imports, module_types, seen = new Set()) {
|
|
319
|
+
if (!node.id) return null; // TODO when does this happen?
|
|
320
|
+
const name = normalizePath(node.id);
|
|
321
|
+
|
|
322
|
+
if (seen.has(name) || !module_types.has(path.extname(name))) return null;
|
|
323
|
+
seen.add(name);
|
|
324
|
+
|
|
325
|
+
if (name && illegal_imports.has(name)) {
|
|
326
|
+
return [{ name, dynamic: false }];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
for (const child of node.importedModules) {
|
|
330
|
+
const chain = child && find_illegal_vite_imports(child, illegal_imports, module_types, seen);
|
|
331
|
+
if (chain) return [{ name, dynamic: false }, ...chain];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return null;
|
|
335
|
+
}
|
package/svelte-kit.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
|
|
5
|
-
// in our own CI, and when deploying directly from this monorepo,
|
|
6
|
-
// the `dist` directory will not exist yet
|
|
7
|
-
if (fs.existsSync(fileURLToPath(new URL('./dist', import.meta.url)))) {
|
|
8
|
-
import('./dist/cli.js');
|
|
9
|
-
} else {
|
|
10
|
-
console.error('Run "pnpm build" and try running this command again');
|
|
11
|
-
}
|
|
2
|
+
import './src/cli.js';
|
package/types/ambient.d.ts
CHANGED
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
* interface PublicEnv {}
|
|
15
15
|
*
|
|
16
16
|
* interface Session {}
|
|
17
|
-
*
|
|
18
|
-
* interface Stuff {}
|
|
19
17
|
* }
|
|
20
18
|
* ```
|
|
21
19
|
*
|
|
@@ -57,24 +55,19 @@ declare namespace App {
|
|
|
57
55
|
export interface Platform {}
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
|
-
* The interface that defines the dynamic environment variables exported from
|
|
58
|
+
* The interface that defines the dynamic environment variables exported from `$env/dynamic/private`.
|
|
61
59
|
*/
|
|
62
60
|
export interface PrivateEnv extends Record<string, string> {}
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
|
-
* The interface that defines the dynamic environment variables exported from
|
|
63
|
+
* The interface that defines the dynamic environment variables exported from `$env/dynamic/public`.
|
|
66
64
|
*/
|
|
67
65
|
export interface PublicEnv extends Record<string, string> {}
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
|
-
* The interface that defines `session`, both as an argument to [`load`](https://kit.svelte.dev/docs/
|
|
68
|
+
* The interface that defines `session`, both as an argument to [`load`](https://kit.svelte.dev/docs/load) functions and the value of the [session store](https://kit.svelte.dev/docs/modules#$app-stores).
|
|
71
69
|
*/
|
|
72
70
|
export interface Session {}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The interface that defines `stuff`, as input or output to [`load`](https://kit.svelte.dev/docs/loading) or as the value of the `stuff` property of the [page store](https://kit.svelte.dev/docs/modules#$app-stores).
|
|
76
|
-
*/
|
|
77
|
-
export interface Stuff {}
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
/**
|
|
@@ -165,10 +158,10 @@ declare module '$app/navigation' {
|
|
|
165
158
|
opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any }
|
|
166
159
|
): Promise<void>;
|
|
167
160
|
/**
|
|
168
|
-
* Causes any `load` functions belonging to the currently active page to re-run if they `fetch` the resource in question, or re-fetches data from a page endpoint if the invalidated resource is the page itself. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
161
|
+
* Causes any `load` functions belonging to the currently active page to re-run if they `fetch` the resource in question, or re-fetches data from a page endpoint if the invalidated resource is the page itself. If no argument is given, all resources will be invalidated. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
169
162
|
* @param dependency The invalidated resource
|
|
170
163
|
*/
|
|
171
|
-
export function invalidate(dependency
|
|
164
|
+
export function invalidate(dependency?: string | ((href: string) => boolean)): Promise<void>;
|
|
172
165
|
/**
|
|
173
166
|
* Programmatically prefetches the given page, which means
|
|
174
167
|
* 1. ensuring that the code for the page is loaded, and
|
package/types/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import './ambient.js';
|
|
|
6
6
|
import { CompileOptions } from 'svelte/types/compiler/interfaces';
|
|
7
7
|
import {
|
|
8
8
|
AdapterEntry,
|
|
9
|
-
BodyValidator,
|
|
10
9
|
CspDirectives,
|
|
10
|
+
JSONObject,
|
|
11
11
|
JSONValue,
|
|
12
12
|
Logger,
|
|
13
13
|
MaybePromise,
|
|
@@ -19,12 +19,29 @@ import {
|
|
|
19
19
|
TrailingSlash
|
|
20
20
|
} from './private.js';
|
|
21
21
|
import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
|
|
22
|
+
import { HttpError, Redirect } from '../src/index/private.js';
|
|
22
23
|
|
|
23
24
|
export interface Adapter {
|
|
24
25
|
name: string;
|
|
25
26
|
adapt(builder: Builder): MaybePromise<void>;
|
|
26
27
|
}
|
|
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
|
+
|
|
28
45
|
export interface Builder {
|
|
29
46
|
log: Logger;
|
|
30
47
|
rimraf(dir: string): void;
|
|
@@ -80,6 +97,11 @@ export interface Builder {
|
|
|
80
97
|
replace?: Record<string, string>;
|
|
81
98
|
}
|
|
82
99
|
): string[];
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} directory Path to the directory containing the files to be compressed
|
|
103
|
+
*/
|
|
104
|
+
compress(directory: string): void;
|
|
83
105
|
}
|
|
84
106
|
|
|
85
107
|
export interface Config {
|
|
@@ -140,7 +162,6 @@ export interface KitConfig {
|
|
|
140
162
|
onError?: PrerenderOnErrorValue;
|
|
141
163
|
origin?: string;
|
|
142
164
|
};
|
|
143
|
-
routes?: (filepath: string) => boolean;
|
|
144
165
|
serviceWorker?: {
|
|
145
166
|
register?: boolean;
|
|
146
167
|
files?: (filepath: string) => boolean;
|
|
@@ -172,46 +193,32 @@ export interface HandleError {
|
|
|
172
193
|
}
|
|
173
194
|
|
|
174
195
|
/**
|
|
175
|
-
* The
|
|
176
|
-
*
|
|
177
|
-
* Note that you can use [generated types](/docs/types#generated-types) instead of manually specifying the Params generic argument.
|
|
196
|
+
* The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
197
|
+
* rather than using `Load` directly.
|
|
178
198
|
*/
|
|
179
199
|
export interface Load<
|
|
180
200
|
Params extends Record<string, string> = Record<string, string>,
|
|
181
|
-
|
|
182
|
-
|
|
201
|
+
InputData extends JSONObject | null = JSONObject | null,
|
|
202
|
+
ParentData extends Record<string, any> | null = Record<string, any> | null,
|
|
203
|
+
OutputData extends Record<string, any> = Record<string, any>
|
|
183
204
|
> {
|
|
184
|
-
(event: LoadEvent<Params,
|
|
205
|
+
(event: LoadEvent<Params, InputData, ParentData>): MaybePromise<OutputData | void>;
|
|
185
206
|
}
|
|
186
207
|
|
|
187
208
|
export interface LoadEvent<
|
|
188
209
|
Params extends Record<string, string> = Record<string, string>,
|
|
189
|
-
|
|
210
|
+
Data extends JSONObject | null = JSONObject | null,
|
|
211
|
+
ParentData extends Record<string, any> | null = Record<string, any> | null
|
|
190
212
|
> {
|
|
191
213
|
fetch(info: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
192
214
|
params: Params;
|
|
193
|
-
|
|
215
|
+
data: Data;
|
|
194
216
|
routeId: string | null;
|
|
195
217
|
session: App.Session;
|
|
196
|
-
|
|
218
|
+
setHeaders: (headers: ResponseHeaders) => void;
|
|
197
219
|
url: URL;
|
|
198
|
-
|
|
199
|
-
|
|
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;
|
|
220
|
+
parent: () => Promise<ParentData>;
|
|
221
|
+
depends: (...deps: string[]) => void;
|
|
215
222
|
}
|
|
216
223
|
|
|
217
224
|
export interface Navigation {
|
|
@@ -223,9 +230,9 @@ export interface Page<Params extends Record<string, string> = Record<string, str
|
|
|
223
230
|
url: URL;
|
|
224
231
|
params: Params;
|
|
225
232
|
routeId: string | null;
|
|
226
|
-
stuff: App.Stuff;
|
|
227
233
|
status: number;
|
|
228
|
-
error: Error | null;
|
|
234
|
+
error: HttpError | Error | null;
|
|
235
|
+
data: Record<string, any>;
|
|
229
236
|
}
|
|
230
237
|
|
|
231
238
|
export interface ParamMatcher {
|
|
@@ -239,27 +246,17 @@ export interface RequestEvent<Params extends Record<string, string> = Record<str
|
|
|
239
246
|
platform: Readonly<App.Platform>;
|
|
240
247
|
request: Request;
|
|
241
248
|
routeId: string | null;
|
|
249
|
+
setHeaders: (headers: ResponseHeaders) => void;
|
|
242
250
|
url: URL;
|
|
243
251
|
}
|
|
244
252
|
|
|
245
253
|
/**
|
|
246
|
-
* A `(event: RequestEvent) =>
|
|
254
|
+
* 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.
|
|
247
255
|
*
|
|
248
256
|
* 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
257
|
*/
|
|
252
|
-
export interface RequestHandler<
|
|
253
|
-
|
|
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>;
|
|
258
|
+
export interface RequestHandler<Params extends Record<string, string> = Record<string, string>> {
|
|
259
|
+
(event: RequestEvent<Params>): MaybePromise<Response>;
|
|
263
260
|
}
|
|
264
261
|
|
|
265
262
|
export interface ResolveOptions {
|
|
@@ -296,3 +293,53 @@ export interface SSRManifest {
|
|
|
296
293
|
matchers: () => Promise<Record<string, ParamMatcher>>;
|
|
297
294
|
};
|
|
298
295
|
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
299
|
+
* rather than using `ServerLoad` directly.
|
|
300
|
+
*/
|
|
301
|
+
export interface ServerLoad<
|
|
302
|
+
Params extends Record<string, string> = Record<string, string>,
|
|
303
|
+
ParentData extends JSONObject | null = JSONObject | null,
|
|
304
|
+
OutputData extends JSONObject | void = JSONObject | void
|
|
305
|
+
> {
|
|
306
|
+
(event: ServerLoadEvent<Params, ParentData>): MaybePromise<OutputData | void>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export interface ServerLoadEvent<
|
|
310
|
+
Params extends Record<string, string> = Record<string, string>,
|
|
311
|
+
ParentData extends JSONObject | null = JSONObject | null
|
|
312
|
+
> extends RequestEvent<Params> {
|
|
313
|
+
parent: () => Promise<ParentData>;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface Action<Params extends Record<string, string> = Record<string, string>> {
|
|
317
|
+
(event: RequestEvent<Params>): MaybePromise<
|
|
318
|
+
| { status?: number; errors: Record<string, string>; location?: never }
|
|
319
|
+
| { status?: never; errors?: never; location: string }
|
|
320
|
+
| void
|
|
321
|
+
>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// TODO figure out how to just re-export from '../src/index/index.js' without
|
|
325
|
+
// breaking the site
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Creates an `HttpError` object with an HTTP status code and an optional message.
|
|
329
|
+
* This object, if thrown during request handling, will cause SvelteKit to
|
|
330
|
+
* return an error response without invoking `handleError`
|
|
331
|
+
* @param {number} status
|
|
332
|
+
* @param {string | undefined} [message]
|
|
333
|
+
*/
|
|
334
|
+
export function error(status: number, message?: string | undefined): HttpError;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Creates a `Redirect` object. If thrown during request handling, SvelteKit will
|
|
338
|
+
* return a redirect response.
|
|
339
|
+
*/
|
|
340
|
+
export function redirect(status: number, location: string): Redirect;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Generates a JSON `Response` object from the supplied data.
|
|
344
|
+
*/
|
|
345
|
+
export function json(data: any, init?: ResponseInit): Response;
|