@sveltejs/kit 1.0.0-next.43 → 1.0.0-next.430
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/README.md +12 -9
- package/package.json +95 -63
- package/src/cli.js +112 -0
- package/src/core/adapt/builder.js +207 -0
- package/src/core/adapt/index.js +19 -0
- package/src/core/config/index.js +86 -0
- package/src/core/config/options.js +488 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/constants.js +5 -0
- package/src/core/env.js +97 -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 +506 -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 +44 -0
- package/src/core/sync/write_ambient.js +27 -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 +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types.js +775 -0
- package/src/core/utils.js +70 -0
- package/src/hooks.js +26 -0
- package/src/index/index.js +45 -0
- package/src/index/private.js +33 -0
- package/src/node/index.js +145 -0
- package/src/node/polyfills.js +40 -0
- package/src/runtime/app/env.js +11 -0
- package/src/runtime/app/navigation.js +22 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +17 -0
- package/src/runtime/client/client.js +1289 -0
- package/src/runtime/client/fetcher.js +60 -0
- package/src/runtime/client/parse.js +36 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +46 -0
- package/src/runtime/client/types.d.ts +105 -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/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +7 -0
- package/src/runtime/env-public.js +7 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +16 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/endpoint.js +58 -0
- package/src/runtime/server/index.js +448 -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 +266 -0
- package/src/runtime/server/page/index.js +416 -0
- package/src/runtime/server/page/load_data.js +135 -0
- package/src/runtime/server/page/render.js +362 -0
- package/src/runtime/server/page/respond_with_error.js +94 -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/src/utils/filesystem.js +108 -0
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/routing.js +108 -0
- package/src/utils/url.js +97 -0
- package/src/vite/build/build_server.js +337 -0
- package/src/vite/build/build_service_worker.js +90 -0
- package/src/vite/build/utils.js +160 -0
- package/src/vite/dev/index.js +551 -0
- package/src/vite/index.js +574 -0
- package/src/vite/preview/index.js +186 -0
- package/src/vite/types.d.ts +3 -0
- package/src/vite/utils.js +345 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +357 -0
- package/types/index.d.ts +343 -0
- package/types/internal.d.ts +308 -0
- package/types/private.d.ts +209 -0
- package/CHANGELOG.md +0 -431
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -41
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -19
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -770
- package/assets/runtime/paths.js +0 -12
- package/dist/.DS_Store +0 -0
- package/dist/chunks/index.js +0 -3521
- package/dist/chunks/index2.js +0 -587
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -538
- package/dist/chunks/index5.js +0 -761
- package/dist/chunks/index6.js +0 -322
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -546
- package/dist/ssr.js +0 -2581
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import colors from 'kleur';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { posixify } from '../utils/filesystem.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resolved path of the `runtime` directory
|
|
8
|
+
*
|
|
9
|
+
* TODO Windows issue:
|
|
10
|
+
* Vite or sth else somehow sets the driver letter inconsistently to lower or upper case depending on the run environment.
|
|
11
|
+
* In playwright debug mode run through VS Code this a root-to-lowercase conversion is needed in order for the tests to run.
|
|
12
|
+
* If we do this conversion in other cases it has the opposite effect though and fails.
|
|
13
|
+
*/
|
|
14
|
+
export const runtime_directory = posixify(fileURLToPath(new URL('../runtime', import.meta.url)));
|
|
15
|
+
|
|
16
|
+
/** Prefix for the `runtime` directory, for use with import declarations */
|
|
17
|
+
export const runtime_prefix = posixify_path(runtime_directory);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This allows us to import SvelteKit internals that aren't exposed via `pkg.exports` in a
|
|
21
|
+
* way that works whether `@sveltejs/kit` is installed inside the project's `node_modules`
|
|
22
|
+
* or in a workspace root
|
|
23
|
+
*/
|
|
24
|
+
export const runtime_base = runtime_directory.startsWith(process.cwd())
|
|
25
|
+
? `/${path.relative('.', runtime_directory)}`
|
|
26
|
+
: `/@fs${
|
|
27
|
+
// Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
|
|
28
|
+
runtime_directory.startsWith('/') ? '' : '/'
|
|
29
|
+
}${runtime_directory}`;
|
|
30
|
+
|
|
31
|
+
/** @param {string} str */
|
|
32
|
+
function posixify_path(str) {
|
|
33
|
+
const parsed = path.parse(str);
|
|
34
|
+
return `/${parsed.dir.slice(parsed.root.length).split(path.sep).join('/')}/${parsed.base}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function noop() {}
|
|
38
|
+
|
|
39
|
+
/** @param {{ verbose: boolean }} opts */
|
|
40
|
+
export function logger({ verbose }) {
|
|
41
|
+
/** @type {import('types').Logger} */
|
|
42
|
+
const log = (msg) => console.log(msg.replace(/^/gm, ' '));
|
|
43
|
+
|
|
44
|
+
/** @param {string} msg */
|
|
45
|
+
const err = (msg) => console.error(msg.replace(/^/gm, ' '));
|
|
46
|
+
|
|
47
|
+
log.success = (msg) => log(colors.green(`✔ ${msg}`));
|
|
48
|
+
log.error = (msg) => err(colors.bold().red(msg));
|
|
49
|
+
log.warn = (msg) => log(colors.bold().yellow(msg));
|
|
50
|
+
|
|
51
|
+
log.minor = verbose ? (msg) => log(colors.grey(msg)) : noop;
|
|
52
|
+
log.info = verbose ? log : noop;
|
|
53
|
+
|
|
54
|
+
return log;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @param {import('types').ManifestData} manifest_data */
|
|
58
|
+
export function get_mime_lookup(manifest_data) {
|
|
59
|
+
/** @type {Record<string, string>} */
|
|
60
|
+
const mime = {};
|
|
61
|
+
|
|
62
|
+
manifest_data.assets.forEach((asset) => {
|
|
63
|
+
if (asset.type) {
|
|
64
|
+
const ext = path.extname(asset.file);
|
|
65
|
+
mime[ext] = asset.type;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return mime;
|
|
70
|
+
}
|
package/src/hooks.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {...import('types').Handle} handlers
|
|
3
|
+
* @returns {import('types').Handle}
|
|
4
|
+
*/
|
|
5
|
+
export function sequence(...handlers) {
|
|
6
|
+
const length = handlers.length;
|
|
7
|
+
if (!length) return ({ event, resolve }) => resolve(event);
|
|
8
|
+
|
|
9
|
+
return ({ event, resolve }) => {
|
|
10
|
+
return apply_handle(0, event);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {number} i
|
|
14
|
+
* @param {import('types').RequestEvent} event
|
|
15
|
+
* @returns {import('types').MaybePromise<Response>}
|
|
16
|
+
*/
|
|
17
|
+
function apply_handle(i, event) {
|
|
18
|
+
const handle = handlers[i];
|
|
19
|
+
|
|
20
|
+
return handle({
|
|
21
|
+
event,
|
|
22
|
+
resolve: i < length - 1 ? (event) => apply_handle(i + 1, event) : resolve
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { HttpError, Redirect } from './private.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an `HttpError` object with an HTTP status code and an optional message.
|
|
5
|
+
* This object, if thrown during request handling, will cause SvelteKit to
|
|
6
|
+
* return an error response without invoking `handleError`
|
|
7
|
+
* @param {number} status
|
|
8
|
+
* @param {string | undefined} [message]
|
|
9
|
+
*/
|
|
10
|
+
export function error(status, message) {
|
|
11
|
+
return new HttpError(status, message);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates a `Redirect` object. If thrown during request handling, SvelteKit will
|
|
16
|
+
* return a redirect response.
|
|
17
|
+
* @param {number} status
|
|
18
|
+
* @param {string} location
|
|
19
|
+
*/
|
|
20
|
+
export function redirect(status, location) {
|
|
21
|
+
if (isNaN(status) || status < 300 || status > 399) {
|
|
22
|
+
throw new Error('Invalid status code');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return new Redirect(status, location);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Generates a JSON `Response` object from the supplied data.
|
|
30
|
+
* @param {any} data
|
|
31
|
+
* @param {ResponseInit} [init]
|
|
32
|
+
*/
|
|
33
|
+
export function json(data, init) {
|
|
34
|
+
// TODO deprecate this in favour of `Response.json` when it's
|
|
35
|
+
// more widely supported
|
|
36
|
+
const headers = new Headers(init?.headers);
|
|
37
|
+
if (!headers.has('content-type')) {
|
|
38
|
+
headers.set('content-type', 'application/json');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new Response(JSON.stringify(data), {
|
|
42
|
+
...init,
|
|
43
|
+
headers
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export class HttpError {
|
|
2
|
+
// without these, things like `$page.error.stack` will error. we don't want to
|
|
3
|
+
// include a stack for these sorts of errors, but we also don't want red
|
|
4
|
+
// squigglies everywhere, so this feels like a not-terribile compromise
|
|
5
|
+
name = 'HttpError';
|
|
6
|
+
|
|
7
|
+
/** @type {void} */
|
|
8
|
+
stack = undefined;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {number} status
|
|
12
|
+
* @param {string | undefined} message
|
|
13
|
+
*/
|
|
14
|
+
constructor(status, message) {
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.message = message ?? `Error: ${status}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
toString() {
|
|
20
|
+
return this.message;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class Redirect {
|
|
25
|
+
/**
|
|
26
|
+
* @param {number} status
|
|
27
|
+
* @param {string} location
|
|
28
|
+
*/
|
|
29
|
+
constructor(status, location) {
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.location = location;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as set_cookie_parser from 'set-cookie-parser';
|
|
2
|
+
|
|
3
|
+
/** @param {import('http').IncomingMessage} req */
|
|
4
|
+
function get_raw_body(req) {
|
|
5
|
+
const h = req.headers;
|
|
6
|
+
|
|
7
|
+
if (!h['content-type']) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const length = Number(h['content-length']);
|
|
12
|
+
|
|
13
|
+
// check if no request body
|
|
14
|
+
// https://github.com/jshttp/type-is/blob/c1f4388c71c8a01f79934e68f630ca4a15fffcd6/index.js#L81-L95
|
|
15
|
+
if (isNaN(length) && h['transfer-encoding'] == null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (req.destroyed) {
|
|
20
|
+
const readable = new ReadableStream();
|
|
21
|
+
readable.cancel();
|
|
22
|
+
return readable;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let size = 0;
|
|
26
|
+
let cancelled = false;
|
|
27
|
+
|
|
28
|
+
return new ReadableStream({
|
|
29
|
+
start(controller) {
|
|
30
|
+
req.on('error', (error) => {
|
|
31
|
+
controller.error(error);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
req.on('end', () => {
|
|
35
|
+
if (cancelled) return;
|
|
36
|
+
controller.close();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
req.on('data', (chunk) => {
|
|
40
|
+
if (cancelled) return;
|
|
41
|
+
|
|
42
|
+
size += chunk.length;
|
|
43
|
+
if (size > length) {
|
|
44
|
+
controller.error(new Error('content-length exceeded'));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
controller.enqueue(chunk);
|
|
49
|
+
|
|
50
|
+
if (controller.desiredSize === null || controller.desiredSize <= 0) {
|
|
51
|
+
req.pause();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
pull() {
|
|
57
|
+
req.resume();
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
cancel(reason) {
|
|
61
|
+
cancelled = true;
|
|
62
|
+
req.destroy(reason);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @type {import('@sveltejs/kit/node').getRequest} */
|
|
68
|
+
export async function getRequest(base, req) {
|
|
69
|
+
let headers = /** @type {Record<string, string>} */ (req.headers);
|
|
70
|
+
if (req.httpVersionMajor === 2) {
|
|
71
|
+
// we need to strip out the HTTP/2 pseudo-headers because node-fetch's
|
|
72
|
+
// Request implementation doesn't like them
|
|
73
|
+
// TODO is this still true with Node 18
|
|
74
|
+
headers = Object.assign({}, headers);
|
|
75
|
+
delete headers[':method'];
|
|
76
|
+
delete headers[':path'];
|
|
77
|
+
delete headers[':authority'];
|
|
78
|
+
delete headers[':scheme'];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return new Request(base + req.url, {
|
|
82
|
+
method: req.method,
|
|
83
|
+
headers,
|
|
84
|
+
body: get_raw_body(req)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @type {import('@sveltejs/kit/node').setResponse} */
|
|
89
|
+
export async function setResponse(res, response) {
|
|
90
|
+
const headers = Object.fromEntries(response.headers);
|
|
91
|
+
|
|
92
|
+
if (response.headers.has('set-cookie')) {
|
|
93
|
+
const header = /** @type {string} */ (response.headers.get('set-cookie'));
|
|
94
|
+
const split = set_cookie_parser.splitCookiesString(header);
|
|
95
|
+
|
|
96
|
+
// @ts-expect-error
|
|
97
|
+
headers['set-cookie'] = split;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
res.writeHead(response.status, headers);
|
|
101
|
+
|
|
102
|
+
if (!response.body) {
|
|
103
|
+
res.end();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const reader = response.body.getReader();
|
|
108
|
+
|
|
109
|
+
if (res.destroyed) {
|
|
110
|
+
reader.cancel();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const cancel = (/** @type {Error|undefined} */ error) => {
|
|
115
|
+
res.off('close', cancel);
|
|
116
|
+
res.off('error', cancel);
|
|
117
|
+
|
|
118
|
+
// If the reader has already been interrupted with an error earlier,
|
|
119
|
+
// then it will appear here, it is useless, but it needs to be catch.
|
|
120
|
+
reader.cancel(error).catch(() => {});
|
|
121
|
+
if (error) res.destroy(error);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
res.on('close', cancel);
|
|
125
|
+
res.on('error', cancel);
|
|
126
|
+
|
|
127
|
+
next();
|
|
128
|
+
async function next() {
|
|
129
|
+
try {
|
|
130
|
+
for (;;) {
|
|
131
|
+
const { done, value } = await reader.read();
|
|
132
|
+
|
|
133
|
+
if (done) break;
|
|
134
|
+
|
|
135
|
+
if (!res.write(value)) {
|
|
136
|
+
res.once('drain', next);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
res.end();
|
|
141
|
+
} catch (error) {
|
|
142
|
+
cancel(error instanceof Error ? error : new Error(String(error)));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { fetch, Response, Request, Headers } from 'undici';
|
|
2
|
+
import { ReadableStream, TransformStream, WritableStream } from 'stream/web';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { Request as NodeFetchRequest } from 'node-fetch';
|
|
5
|
+
import { webcrypto as crypto } from 'crypto';
|
|
6
|
+
|
|
7
|
+
/** @type {Record<string, any>} */
|
|
8
|
+
const globals = {
|
|
9
|
+
crypto,
|
|
10
|
+
fetch,
|
|
11
|
+
Response,
|
|
12
|
+
// TODO remove the superclass as soon as Undici supports formData
|
|
13
|
+
// https://github.com/nodejs/undici/issues/974
|
|
14
|
+
Request: class extends Request {
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
formData() {
|
|
17
|
+
return new NodeFetchRequest(this.url, {
|
|
18
|
+
method: this.method,
|
|
19
|
+
headers: this.headers,
|
|
20
|
+
body: this.body && Readable.from(this.body)
|
|
21
|
+
}).formData();
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
Headers,
|
|
25
|
+
ReadableStream,
|
|
26
|
+
TransformStream,
|
|
27
|
+
WritableStream
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// exported for dev/preview and node environments
|
|
31
|
+
export function installPolyfills() {
|
|
32
|
+
for (const name in globals) {
|
|
33
|
+
Object.defineProperty(globalThis, name, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: globals[name]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { client } from '../client/singletons.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} name
|
|
5
|
+
*/
|
|
6
|
+
function guard(name) {
|
|
7
|
+
return () => {
|
|
8
|
+
throw new Error(`Cannot call ${name}(...) on the server`);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ssr = import.meta.env.SSR;
|
|
13
|
+
|
|
14
|
+
export const disableScrollHandling = ssr
|
|
15
|
+
? guard('disableScrollHandling')
|
|
16
|
+
: client.disable_scroll_handling;
|
|
17
|
+
export const goto = ssr ? guard('goto') : client.goto;
|
|
18
|
+
export const invalidate = ssr ? guard('invalidate') : client.invalidate;
|
|
19
|
+
export const prefetch = ssr ? guard('prefetch') : client.prefetch;
|
|
20
|
+
export const prefetchRoutes = ssr ? guard('prefetchRoutes') : client.prefetch_routes;
|
|
21
|
+
export const beforeNavigate = ssr ? () => {} : client.before_navigate;
|
|
22
|
+
export const afterNavigate = ssr ? () => {} : client.after_navigate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { base, assets } from '../paths.js';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
import { browser } from './env.js';
|
|
3
|
+
import { stores as browser_stores } from '../client/singletons.js';
|
|
4
|
+
|
|
5
|
+
// TODO remove this (for 1.0? after 1.0?)
|
|
6
|
+
let warned = false;
|
|
7
|
+
export function stores() {
|
|
8
|
+
if (!warned) {
|
|
9
|
+
console.error('stores() is deprecated; use getStores() instead');
|
|
10
|
+
warned = true;
|
|
11
|
+
}
|
|
12
|
+
return getStores();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {import('$app/stores').getStores}
|
|
17
|
+
*/
|
|
18
|
+
export const getStores = () => {
|
|
19
|
+
const stores = browser ? browser_stores : getContext('__svelte__');
|
|
20
|
+
|
|
21
|
+
const readonly_stores = {
|
|
22
|
+
page: {
|
|
23
|
+
subscribe: stores.page.subscribe
|
|
24
|
+
},
|
|
25
|
+
navigating: {
|
|
26
|
+
subscribe: stores.navigating.subscribe
|
|
27
|
+
},
|
|
28
|
+
updated: stores.updated
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// TODO remove this for 1.0
|
|
32
|
+
Object.defineProperties(readonly_stores, {
|
|
33
|
+
preloading: {
|
|
34
|
+
get() {
|
|
35
|
+
console.error('stores.preloading is deprecated; use stores.navigating instead');
|
|
36
|
+
return {
|
|
37
|
+
subscribe: stores.navigating.subscribe
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
enumerable: false
|
|
41
|
+
},
|
|
42
|
+
session: {
|
|
43
|
+
get() {
|
|
44
|
+
removed_session();
|
|
45
|
+
return {};
|
|
46
|
+
},
|
|
47
|
+
enumerable: false
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return readonly_stores;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** @type {typeof import('$app/stores').page} */
|
|
55
|
+
export const page = {
|
|
56
|
+
/** @param {(value: any) => void} fn */
|
|
57
|
+
subscribe(fn) {
|
|
58
|
+
const store = getStores().page;
|
|
59
|
+
return store.subscribe(fn);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** @type {typeof import('$app/stores').navigating} */
|
|
64
|
+
export const navigating = {
|
|
65
|
+
subscribe(fn) {
|
|
66
|
+
const store = getStores().navigating;
|
|
67
|
+
return store.subscribe(fn);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function removed_session() {
|
|
72
|
+
// TODO remove for 1.0
|
|
73
|
+
throw new Error(
|
|
74
|
+
'stores.session is no longer available. See https://github.com/sveltejs/kit/discussions/5883'
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const session = {
|
|
79
|
+
subscribe: removed_session,
|
|
80
|
+
set: removed_session,
|
|
81
|
+
update: removed_session
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** @type {typeof import('$app/stores').updated} */
|
|
85
|
+
export const updated = {
|
|
86
|
+
subscribe(fn) {
|
|
87
|
+
const store = getStores().updated;
|
|
88
|
+
|
|
89
|
+
if (browser) {
|
|
90
|
+
updated.check = store.check;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return store.subscribe(fn);
|
|
94
|
+
},
|
|
95
|
+
check: () => {
|
|
96
|
+
throw new Error(
|
|
97
|
+
browser
|
|
98
|
+
? `Cannot check updated store before subscribing`
|
|
99
|
+
: `Can only check updated store in browser`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module '__GENERATED__/client-manifest.js' {
|
|
2
|
+
import { CSRPageNodeLoader, ParamMatcher } from 'types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A list of all the error/layout/page nodes used in the app
|
|
6
|
+
*/
|
|
7
|
+
export const nodes: CSRPageNodeLoader[];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A map of `[routeId: string]: [errors, layouts, page]` tuples, which
|
|
11
|
+
* is parsed into an array of routes on startup. The numbers refer to the
|
|
12
|
+
* indices in `nodes`.
|
|
13
|
+
*/
|
|
14
|
+
export const dictionary: Record<string, [number[], number[], number]>;
|
|
15
|
+
|
|
16
|
+
export const matchers: Record<string, ParamMatcher>;
|
|
17
|
+
}
|