@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.
- package/README.md +12 -9
- package/package.json +93 -64
- package/scripts/special-types/$env+dynamic+private.md +8 -0
- package/scripts/special-types/$env+dynamic+public.md +8 -0
- package/scripts/special-types/$env+static+private.md +19 -0
- package/scripts/special-types/$env+static+public.md +7 -0
- package/scripts/special-types/$lib.md +1 -0
- package/src/cli.js +112 -0
- package/src/constants.js +7 -0
- package/src/core/adapt/builder.js +207 -0
- package/src/core/adapt/index.js +31 -0
- package/src/core/config/default-error.html +56 -0
- package/src/core/config/index.js +105 -0
- package/src/core/config/options.js +502 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +121 -0
- package/src/core/generate_manifest/index.js +92 -0
- package/src/core/prerender/crawl.js +194 -0
- package/src/core/prerender/prerender.js +425 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +472 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +59 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +53 -0
- package/src/core/sync/write_client_manifest.js +94 -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/index.js +595 -0
- package/src/core/utils.js +70 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +44 -0
- package/src/exports/index.js +45 -0
- package/src/exports/node/index.js +145 -0
- package/src/exports/node/polyfills.js +40 -0
- package/src/exports/vite/build/build_server.js +358 -0
- package/src/exports/vite/build/build_service_worker.js +90 -0
- package/src/exports/vite/build/utils.js +162 -0
- package/src/exports/vite/dev/index.js +547 -0
- package/src/exports/vite/index.js +601 -0
- package/src/exports/vite/preview/index.js +186 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +345 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/navigation.js +23 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +24 -0
- package/src/runtime/client/client.js +1494 -0
- package/src/runtime/client/fetcher.js +107 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +45 -0
- package/src/runtime/client/types.d.ts +91 -0
- package/src/runtime/client/utils.js +159 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/control.js +33 -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 +6 -0
- package/src/runtime/env-public.js +6 -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/data/index.js +146 -0
- package/src/runtime/server/endpoint.js +63 -0
- package/src/runtime/server/index.js +354 -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 +282 -0
- package/src/runtime/server/page/index.js +404 -0
- package/src/runtime/server/page/load_data.js +124 -0
- package/src/runtime/server/page/render.js +358 -0
- package/src/runtime/server/page/respond_with_error.js +92 -0
- package/src/runtime/server/page/serialize_data.js +72 -0
- package/src/runtime/server/page/types.d.ts +45 -0
- package/src/runtime/server/utils.js +209 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +46 -0
- package/src/utils/filesystem.js +108 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/routing.js +117 -0
- package/src/utils/url.js +142 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +356 -0
- package/types/index.d.ts +356 -0
- package/types/internal.d.ts +386 -0
- package/types/private.d.ts +213 -0
- package/CHANGELOG.md +0 -463
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -44
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -22
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -773
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/index.js +0 -3517
- package/dist/chunks/index2.js +0 -587
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -530
- package/dist/chunks/index5.js +0 -763
- 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 -553
- package/dist/ssr.js +0 -2581
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { hash } from '../hash.js';
|
|
2
|
+
|
|
3
|
+
let loading = 0;
|
|
4
|
+
|
|
5
|
+
const native_fetch = window.fetch;
|
|
6
|
+
|
|
7
|
+
export function lock_fetch() {
|
|
8
|
+
loading += 1;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function unlock_fetch() {
|
|
12
|
+
loading -= 1;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (import.meta.env.DEV) {
|
|
16
|
+
let can_inspect_stack_trace = false;
|
|
17
|
+
|
|
18
|
+
const check_stack_trace = async () => {
|
|
19
|
+
const stack = /** @type {string} */ (new Error().stack);
|
|
20
|
+
can_inspect_stack_trace = stack.includes('check_stack_trace');
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
check_stack_trace();
|
|
24
|
+
|
|
25
|
+
window.fetch = (input, init) => {
|
|
26
|
+
const url = input instanceof Request ? input.url : input.toString();
|
|
27
|
+
const stack = /** @type {string} */ (new Error().stack);
|
|
28
|
+
|
|
29
|
+
const heuristic = can_inspect_stack_trace ? stack.includes('load_node') : loading;
|
|
30
|
+
if (heuristic) {
|
|
31
|
+
console.warn(
|
|
32
|
+
`Loading ${url} using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#input-fetch`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const method = input instanceof Request ? input.method : init?.method || 'GET';
|
|
37
|
+
|
|
38
|
+
if (method !== 'GET') {
|
|
39
|
+
const url = new URL(input instanceof Request ? input.url : input.toString(), document.baseURI)
|
|
40
|
+
.href;
|
|
41
|
+
cache.delete(url);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return native_fetch(input, init);
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
window.fetch = (input, init) => {
|
|
48
|
+
const method = input instanceof Request ? input.method : init?.method || 'GET';
|
|
49
|
+
|
|
50
|
+
if (method !== 'GET') {
|
|
51
|
+
const url = new URL(input instanceof Request ? input.url : input.toString(), document.baseURI)
|
|
52
|
+
.href;
|
|
53
|
+
cache.delete(url);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return native_fetch(input, init);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const cache = new Map();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Should be called on the initial run of load functions that hydrate the page.
|
|
64
|
+
* Saves any requests with cache-control max-age to the cache.
|
|
65
|
+
* @param {RequestInfo} resource
|
|
66
|
+
* @param {string} resolved
|
|
67
|
+
* @param {RequestInit} [opts]
|
|
68
|
+
*/
|
|
69
|
+
export function initial_fetch(resource, resolved, opts) {
|
|
70
|
+
const url = JSON.stringify(typeof resource === 'string' ? resource : resource.url);
|
|
71
|
+
|
|
72
|
+
let selector = `script[data-sveltekit-fetched][data-url=${url}]`;
|
|
73
|
+
|
|
74
|
+
if (opts && typeof opts.body === 'string') {
|
|
75
|
+
selector += `[data-hash="${hash(opts.body)}"]`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const script = document.querySelector(selector);
|
|
79
|
+
if (script?.textContent) {
|
|
80
|
+
const { body, ...init } = JSON.parse(script.textContent);
|
|
81
|
+
|
|
82
|
+
const ttl = script.getAttribute('data-ttl');
|
|
83
|
+
if (ttl) cache.set(resolved, { body, init, ttl: 1000 * Number(ttl) });
|
|
84
|
+
|
|
85
|
+
return Promise.resolve(new Response(body, init));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return native_fetch(resource, opts);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Tries to get the response from the cache, if max-age allows it, else does a fetch.
|
|
93
|
+
* @param {string} resolved
|
|
94
|
+
* @param {RequestInit} [opts]
|
|
95
|
+
*/
|
|
96
|
+
export function subsequent_fetch(resolved, opts) {
|
|
97
|
+
const cached = cache.get(resolved);
|
|
98
|
+
if (cached) {
|
|
99
|
+
if (performance.now() < cached.ttl) {
|
|
100
|
+
return new Response(cached.body, cached.init);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
cache.delete(resolved);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return native_fetch(resolved, opts);
|
|
107
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { exec, parse_route_id } from '../../utils/routing.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('types').CSRPageNodeLoader[]} nodes
|
|
5
|
+
* @param {number[]} server_loads
|
|
6
|
+
* @param {typeof import('__GENERATED__/client-manifest.js').dictionary} dictionary
|
|
7
|
+
* @param {Record<string, (param: string) => boolean>} matchers
|
|
8
|
+
* @returns {import('types').CSRRoute[]}
|
|
9
|
+
*/
|
|
10
|
+
export function parse(nodes, server_loads, dictionary, matchers) {
|
|
11
|
+
const layouts_with_server_load = new Set(server_loads);
|
|
12
|
+
|
|
13
|
+
return Object.entries(dictionary).map(([id, [leaf, layouts, errors]]) => {
|
|
14
|
+
const { pattern, names, types } = parse_route_id(id);
|
|
15
|
+
|
|
16
|
+
const route = {
|
|
17
|
+
id,
|
|
18
|
+
/** @param {string} path */
|
|
19
|
+
exec: (path) => {
|
|
20
|
+
const match = pattern.exec(path);
|
|
21
|
+
if (match) return exec(match, names, types, matchers);
|
|
22
|
+
},
|
|
23
|
+
errors: [1, ...(errors || [])].map((n) => nodes[n]),
|
|
24
|
+
layouts: [0, ...(layouts || [])].map(create_layout_loader),
|
|
25
|
+
leaf: create_leaf_loader(leaf)
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// bit of a hack, but ensures that layout/error node lists are the same
|
|
29
|
+
// length, without which the wrong data will be applied if the route
|
|
30
|
+
// manifest looks like `[[a, b], [c,], d]`
|
|
31
|
+
route.errors.length = route.layouts.length = Math.max(
|
|
32
|
+
route.errors.length,
|
|
33
|
+
route.layouts.length
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return route;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {number} id
|
|
41
|
+
* @returns {[boolean, import('types').CSRPageNodeLoader]}
|
|
42
|
+
*/
|
|
43
|
+
function create_leaf_loader(id) {
|
|
44
|
+
// whether or not the route uses the server data is
|
|
45
|
+
// encoded using the ones' complement, to save space
|
|
46
|
+
const uses_server_data = id < 0;
|
|
47
|
+
if (uses_server_data) id = ~id;
|
|
48
|
+
return [uses_server_data, nodes[id]];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {number | undefined} id
|
|
53
|
+
* @returns {[boolean, import('types').CSRPageNodeLoader] | undefined}
|
|
54
|
+
*/
|
|
55
|
+
function create_layout_loader(id) {
|
|
56
|
+
// whether or not the layout uses the server data is
|
|
57
|
+
// encoded in the layouts array, to save space
|
|
58
|
+
return id === undefined ? id : [layouts_with_server_load.has(id), nodes[id]];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
import { create_updated_store, notifiable_store } from './utils.js';
|
|
3
|
+
|
|
4
|
+
/** @type {import('./types').Client} */
|
|
5
|
+
export let client;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {{
|
|
9
|
+
* client: import('./types').Client;
|
|
10
|
+
* }} opts
|
|
11
|
+
*/
|
|
12
|
+
export function init(opts) {
|
|
13
|
+
client = opts.client;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const stores = {
|
|
17
|
+
url: notifiable_store({}),
|
|
18
|
+
page: notifiable_store({}),
|
|
19
|
+
navigating: writable(/** @type {import('types').Navigation | null} */ (null)),
|
|
20
|
+
updated: create_updated_store()
|
|
21
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { create_client } from './client.js';
|
|
2
|
+
import { init } from './singletons.js';
|
|
3
|
+
import { set_paths } from '../paths.js';
|
|
4
|
+
import { set_public_env } from '../env-public.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {{
|
|
8
|
+
* env: Record<string, string>;
|
|
9
|
+
* hydrate: {
|
|
10
|
+
* status: number;
|
|
11
|
+
* error: Error | (import('../server/page/types').SerializedHttpError);
|
|
12
|
+
* node_ids: number[];
|
|
13
|
+
* params: Record<string, string>;
|
|
14
|
+
* routeId: string | null;
|
|
15
|
+
* data: Array<import('types').ServerDataNode | null>;
|
|
16
|
+
* errors: Record<string, any> | null;
|
|
17
|
+
* };
|
|
18
|
+
* paths: {
|
|
19
|
+
* assets: string;
|
|
20
|
+
* base: string;
|
|
21
|
+
* },
|
|
22
|
+
* target: Element;
|
|
23
|
+
* trailing_slash: import('types').TrailingSlash;
|
|
24
|
+
* }} opts
|
|
25
|
+
*/
|
|
26
|
+
export async function start({ env, hydrate, paths, target, trailing_slash }) {
|
|
27
|
+
set_public_env(env);
|
|
28
|
+
set_paths(paths);
|
|
29
|
+
|
|
30
|
+
const client = create_client({
|
|
31
|
+
target,
|
|
32
|
+
base: paths.base,
|
|
33
|
+
trailing_slash
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
init({ client });
|
|
37
|
+
|
|
38
|
+
if (hydrate) {
|
|
39
|
+
await client._hydrate(hydrate);
|
|
40
|
+
} else {
|
|
41
|
+
client.goto(location.href, { replaceState: true });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
client._start_router();
|
|
45
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
afterNavigate,
|
|
3
|
+
beforeNavigate,
|
|
4
|
+
goto,
|
|
5
|
+
invalidate,
|
|
6
|
+
invalidateAll,
|
|
7
|
+
prefetch,
|
|
8
|
+
prefetchRoutes
|
|
9
|
+
} from '$app/navigation';
|
|
10
|
+
import { CSRPageNode, CSRPageNodeLoader, CSRRoute, Uses } from 'types';
|
|
11
|
+
import { HttpError } from '../control.js';
|
|
12
|
+
import { SerializedHttpError } from '../server/page/types.js';
|
|
13
|
+
|
|
14
|
+
export interface Client {
|
|
15
|
+
// public API, exposed via $app/navigation
|
|
16
|
+
after_navigate: typeof afterNavigate;
|
|
17
|
+
before_navigate: typeof beforeNavigate;
|
|
18
|
+
disable_scroll_handling: () => void;
|
|
19
|
+
goto: typeof goto;
|
|
20
|
+
invalidate: typeof invalidate;
|
|
21
|
+
invalidateAll: typeof invalidateAll;
|
|
22
|
+
prefetch: typeof prefetch;
|
|
23
|
+
prefetch_routes: typeof prefetchRoutes;
|
|
24
|
+
|
|
25
|
+
// private API
|
|
26
|
+
_hydrate: (opts: {
|
|
27
|
+
status: number;
|
|
28
|
+
error: Error | SerializedHttpError;
|
|
29
|
+
node_ids: number[];
|
|
30
|
+
params: Record<string, string>;
|
|
31
|
+
routeId: string | null;
|
|
32
|
+
data: Array<import('types').ServerDataNode | null>;
|
|
33
|
+
errors: Record<string, any> | null;
|
|
34
|
+
}) => Promise<void>;
|
|
35
|
+
_start_router: () => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type NavigationIntent = {
|
|
39
|
+
/**
|
|
40
|
+
* `url.pathname + url.search`
|
|
41
|
+
*/
|
|
42
|
+
id: string;
|
|
43
|
+
/**
|
|
44
|
+
* The route parameters
|
|
45
|
+
*/
|
|
46
|
+
params: Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* The route that matches `path`
|
|
49
|
+
*/
|
|
50
|
+
route: CSRRoute;
|
|
51
|
+
/**
|
|
52
|
+
* The destination URL
|
|
53
|
+
*/
|
|
54
|
+
url: URL;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type NavigationResult = NavigationRedirect | NavigationFinished;
|
|
58
|
+
|
|
59
|
+
export type NavigationRedirect = {
|
|
60
|
+
type: 'redirect';
|
|
61
|
+
location: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type NavigationFinished = {
|
|
65
|
+
type: 'loaded';
|
|
66
|
+
state: NavigationState;
|
|
67
|
+
props: Record<string, any>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type BranchNode = {
|
|
71
|
+
node: CSRPageNode;
|
|
72
|
+
loader: CSRPageNodeLoader;
|
|
73
|
+
server: DataNode | null;
|
|
74
|
+
shared: DataNode | null;
|
|
75
|
+
data: Record<string, any> | null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export interface DataNode {
|
|
79
|
+
type: 'data';
|
|
80
|
+
data: Record<string, any> | null;
|
|
81
|
+
uses: Uses;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface NavigationState {
|
|
85
|
+
branch: Array<BranchNode | undefined>;
|
|
86
|
+
error: HttpError | Error | null;
|
|
87
|
+
params: Record<string, string>;
|
|
88
|
+
route: CSRRoute | null;
|
|
89
|
+
session_id: number;
|
|
90
|
+
url: URL;
|
|
91
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
import { assets } from '../paths.js';
|
|
3
|
+
|
|
4
|
+
/* global __SVELTEKIT_APP_VERSION__, __SVELTEKIT_APP_VERSION_FILE__, __SVELTEKIT_APP_VERSION_POLL_INTERVAL__ */
|
|
5
|
+
|
|
6
|
+
/** @param {HTMLDocument} doc */
|
|
7
|
+
export function get_base_uri(doc) {
|
|
8
|
+
let baseURI = doc.baseURI;
|
|
9
|
+
|
|
10
|
+
if (!baseURI) {
|
|
11
|
+
const baseTags = doc.getElementsByTagName('base');
|
|
12
|
+
baseURI = baseTags.length ? baseTags[0].href : doc.URL;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return baseURI;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function scroll_state() {
|
|
19
|
+
return {
|
|
20
|
+
x: pageXOffset,
|
|
21
|
+
y: pageYOffset
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @param {Event} event */
|
|
26
|
+
export function find_anchor(event) {
|
|
27
|
+
/** @type {HTMLAnchorElement | SVGAElement | undefined} */
|
|
28
|
+
let a;
|
|
29
|
+
|
|
30
|
+
/** @type {boolean | null} */
|
|
31
|
+
let noscroll = null;
|
|
32
|
+
|
|
33
|
+
/** @type {boolean | null} */
|
|
34
|
+
let prefetch = null;
|
|
35
|
+
|
|
36
|
+
/** @type {boolean | null} */
|
|
37
|
+
let reload = null;
|
|
38
|
+
|
|
39
|
+
for (const element of event.composedPath()) {
|
|
40
|
+
if (!(element instanceof Element)) continue;
|
|
41
|
+
|
|
42
|
+
if (!a && element.nodeName.toUpperCase() === 'A') {
|
|
43
|
+
// SVG <a> elements have a lowercase name
|
|
44
|
+
a = /** @type {HTMLAnchorElement | SVGAElement} */ (element);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (noscroll === null) noscroll = get_link_option(element, 'data-sveltekit-noscroll');
|
|
48
|
+
if (prefetch === null) prefetch = get_link_option(element, 'data-sveltekit-prefetch');
|
|
49
|
+
if (reload === null) reload = get_link_option(element, 'data-sveltekit-reload');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const url = a && new URL(a instanceof SVGAElement ? a.href.baseVal : a.href, document.baseURI);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
a,
|
|
56
|
+
url,
|
|
57
|
+
options: {
|
|
58
|
+
noscroll,
|
|
59
|
+
prefetch,
|
|
60
|
+
reload
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const warned = new WeakSet();
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {Element} element
|
|
69
|
+
* @param {string} attribute
|
|
70
|
+
*/
|
|
71
|
+
function get_link_option(element, attribute) {
|
|
72
|
+
const value = element.getAttribute(attribute);
|
|
73
|
+
if (value === null) return value;
|
|
74
|
+
|
|
75
|
+
if (value === '') return true;
|
|
76
|
+
if (value === 'off') return false;
|
|
77
|
+
|
|
78
|
+
if (__SVELTEKIT_DEV__ && !warned.has(element)) {
|
|
79
|
+
console.error(`Unexpected value for ${attribute} — should be "" or "off"`, element);
|
|
80
|
+
warned.add(element);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @param {any} value */
|
|
87
|
+
export function notifiable_store(value) {
|
|
88
|
+
const store = writable(value);
|
|
89
|
+
let ready = true;
|
|
90
|
+
|
|
91
|
+
function notify() {
|
|
92
|
+
ready = true;
|
|
93
|
+
store.update((val) => val);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @param {any} new_value */
|
|
97
|
+
function set(new_value) {
|
|
98
|
+
ready = false;
|
|
99
|
+
store.set(new_value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @param {(value: any) => void} run */
|
|
103
|
+
function subscribe(run) {
|
|
104
|
+
/** @type {any} */
|
|
105
|
+
let old_value;
|
|
106
|
+
return store.subscribe((new_value) => {
|
|
107
|
+
if (old_value === undefined || (ready && new_value !== old_value)) {
|
|
108
|
+
run((old_value = new_value));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return { notify, set, subscribe };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function create_updated_store() {
|
|
117
|
+
const { set, subscribe } = writable(false);
|
|
118
|
+
|
|
119
|
+
const interval = __SVELTEKIT_APP_VERSION_POLL_INTERVAL__;
|
|
120
|
+
|
|
121
|
+
/** @type {NodeJS.Timeout} */
|
|
122
|
+
let timeout;
|
|
123
|
+
|
|
124
|
+
async function check() {
|
|
125
|
+
if (import.meta.env.DEV || import.meta.env.SSR) return false;
|
|
126
|
+
|
|
127
|
+
clearTimeout(timeout);
|
|
128
|
+
|
|
129
|
+
if (interval) timeout = setTimeout(check, interval);
|
|
130
|
+
|
|
131
|
+
const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
|
|
132
|
+
headers: {
|
|
133
|
+
pragma: 'no-cache',
|
|
134
|
+
'cache-control': 'no-cache'
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
if (res.ok) {
|
|
139
|
+
const { version } = await res.json();
|
|
140
|
+
const updated = version !== __SVELTEKIT_APP_VERSION__;
|
|
141
|
+
|
|
142
|
+
if (updated) {
|
|
143
|
+
set(true);
|
|
144
|
+
clearTimeout(timeout);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return updated;
|
|
148
|
+
} else {
|
|
149
|
+
throw new Error(`Version check failed: ${res.status}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (interval) timeout = setTimeout(check, interval);
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
subscribe,
|
|
157
|
+
check
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { page } from '$app/stores';
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<h1>{$page.status}</h1>
|
|
6
|
+
|
|
7
|
+
<pre>{$page.error.message}</pre>
|
|
8
|
+
|
|
9
|
+
<!-- TODO figure out what to do with frames/stacktraces in prod -->
|
|
10
|
+
<!-- frame is populated by Svelte in its CompileError and is a Rollup/Vite convention -->
|
|
11
|
+
{#if $page.error.frame}
|
|
12
|
+
<pre>{$page.error.frame}</pre>
|
|
13
|
+
{/if}
|
|
14
|
+
{#if $page.error.stack}
|
|
15
|
+
<pre>{$page.error.stack}</pre>
|
|
16
|
+
{/if}
|
|
File without changes
|
|
@@ -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 @@
|
|
|
1
|
+
export { env } from '../../env-private.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { env } from '../../env-public.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hash using djb2
|
|
3
|
+
* @param {import('types').StrictBody} value
|
|
4
|
+
*/
|
|
5
|
+
export function hash(value) {
|
|
6
|
+
let hash = 5381;
|
|
7
|
+
let i = value.length;
|
|
8
|
+
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
while (i) hash = (hash * 33) ^ value.charCodeAt(--i);
|
|
11
|
+
} else {
|
|
12
|
+
while (i) hash = (hash * 33) ^ value[--i];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (hash >>> 0).toString(36);
|
|
16
|
+
}
|