ambient-display 1.1.0 → 1.1.2
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/build/client/_app/immutable/assets/0.Dl9__I4E.css +1 -0
- package/build/client/_app/immutable/assets/0.Dl9__I4E.css.br +0 -0
- package/build/client/_app/immutable/assets/0.Dl9__I4E.css.gz +0 -0
- package/build/client/_app/immutable/assets/2.BtzFOBtk.css +1 -0
- package/build/client/_app/immutable/assets/2.BtzFOBtk.css.br +0 -0
- package/build/client/_app/immutable/assets/2.BtzFOBtk.css.gz +0 -0
- package/build/client/_app/immutable/assets/3.BvcZlbFP.css +1 -0
- package/build/client/_app/immutable/assets/3.BvcZlbFP.css.br +0 -0
- package/build/client/_app/immutable/assets/3.BvcZlbFP.css.gz +0 -0
- package/build/client/_app/immutable/assets/LoadingIndicator.D0m6rSKQ.css +1 -0
- package/build/client/_app/immutable/assets/LoadingIndicator.D0m6rSKQ.css.br +0 -0
- package/build/client/_app/immutable/assets/LoadingIndicator.D0m6rSKQ.css.gz +0 -0
- package/build/client/_app/immutable/assets/PlayingTracker.9uM5nyWg.css +1 -0
- package/build/client/_app/immutable/assets/PlayingTracker.9uM5nyWg.css.br +0 -0
- package/build/client/_app/immutable/assets/PlayingTracker.9uM5nyWg.css.gz +0 -0
- package/build/client/_app/immutable/assets/_layout.Dl9__I4E.css +1 -0
- package/build/client/_app/immutable/assets/_layout.Dl9__I4E.css.br +0 -0
- package/build/client/_app/immutable/assets/_layout.Dl9__I4E.css.gz +0 -0
- package/build/client/_app/immutable/assets/_page.BtzFOBtk.css +1 -0
- package/build/client/_app/immutable/assets/_page.BtzFOBtk.css.br +0 -0
- package/build/client/_app/immutable/assets/_page.BtzFOBtk.css.gz +0 -0
- package/build/client/_app/immutable/assets/_page.BvcZlbFP.css +1 -0
- package/build/client/_app/immutable/assets/_page.BvcZlbFP.css.br +0 -0
- package/build/client/_app/immutable/assets/_page.BvcZlbFP.css.gz +0 -0
- package/build/client/_app/immutable/chunks/LoadingIndicator.COVTk436.js +1 -0
- package/build/client/_app/immutable/chunks/LoadingIndicator.COVTk436.js.br +0 -0
- package/build/client/_app/immutable/chunks/LoadingIndicator.COVTk436.js.gz +0 -0
- package/build/client/_app/immutable/chunks/PlayingTracker.Cymhk9j5.js +5 -0
- package/build/client/_app/immutable/chunks/PlayingTracker.Cymhk9j5.js.br +0 -0
- package/build/client/_app/immutable/chunks/PlayingTracker.Cymhk9j5.js.gz +0 -0
- package/build/client/_app/immutable/chunks/disclose-version.N57b1q78.js +1 -0
- package/build/client/_app/immutable/chunks/disclose-version.N57b1q78.js.br +0 -0
- package/build/client/_app/immutable/chunks/disclose-version.N57b1q78.js.gz +0 -0
- package/build/client/_app/immutable/chunks/entry.CTcSu7Oh.js +3 -0
- package/build/client/_app/immutable/chunks/entry.CTcSu7Oh.js.br +0 -0
- package/build/client/_app/immutable/chunks/entry.CTcSu7Oh.js.gz +0 -0
- package/build/client/_app/immutable/chunks/index-client.DV07uIiZ.js +1 -0
- package/build/client/_app/immutable/chunks/index-client.DV07uIiZ.js.br +0 -0
- package/build/client/_app/immutable/chunks/index-client.DV07uIiZ.js.gz +0 -0
- package/build/client/_app/immutable/chunks/index.DFULH2AN.js +1 -0
- package/build/client/_app/immutable/chunks/index.DFULH2AN.js.br +0 -0
- package/build/client/_app/immutable/chunks/index.DFULH2AN.js.gz +0 -0
- package/build/client/_app/immutable/chunks/index.DLR8Bvs6.js +4 -0
- package/build/client/_app/immutable/chunks/index.DLR8Bvs6.js.br +0 -0
- package/build/client/_app/immutable/chunks/index.DLR8Bvs6.js.gz +0 -0
- package/build/client/_app/immutable/chunks/legacy.DZgMwYuQ.js +1 -0
- package/build/client/_app/immutable/chunks/legacy.DZgMwYuQ.js.br +0 -0
- package/build/client/_app/immutable/chunks/legacy.DZgMwYuQ.js.gz +0 -0
- package/build/client/_app/immutable/chunks/props.DYfFZGja.js +1 -0
- package/build/client/_app/immutable/chunks/props.DYfFZGja.js.br +0 -0
- package/build/client/_app/immutable/chunks/props.DYfFZGja.js.gz +0 -0
- package/build/client/_app/immutable/chunks/snippet.BVSCguOu.js +1 -0
- package/build/client/_app/immutable/chunks/snippet.BVSCguOu.js.br +0 -0
- package/build/client/_app/immutable/chunks/snippet.BVSCguOu.js.gz +0 -0
- package/build/client/_app/immutable/chunks/this.EZLWgc5v.js +1 -0
- package/build/client/_app/immutable/chunks/this.EZLWgc5v.js.br +0 -0
- package/build/client/_app/immutable/chunks/this.EZLWgc5v.js.gz +0 -0
- package/build/client/_app/immutable/chunks/utils.BXcQV2KO.js +1 -0
- package/build/client/_app/immutable/chunks/utils.BXcQV2KO.js.br +0 -0
- package/build/client/_app/immutable/chunks/utils.BXcQV2KO.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.DHMJZPqS.js +2 -0
- package/build/client/_app/immutable/entry/app.DHMJZPqS.js.br +0 -0
- package/build/client/_app/immutable/entry/app.DHMJZPqS.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.BGJKS9mR.js +1 -0
- package/build/client/_app/immutable/entry/start.BGJKS9mR.js.br +2 -0
- package/build/client/_app/immutable/entry/start.BGJKS9mR.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.DaJoi3FK.js +2 -0
- package/build/client/_app/immutable/nodes/0.DaJoi3FK.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.DaJoi3FK.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.0EwG4xPT.js +1 -0
- package/build/client/_app/immutable/nodes/1.0EwG4xPT.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.0EwG4xPT.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.CIcrK0Mf.js +1 -0
- package/build/client/_app/immutable/nodes/2.CIcrK0Mf.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CIcrK0Mf.js.gz +0 -0
- package/build/client/_app/immutable/nodes/3.vzk8SJSG.js +1 -0
- package/build/client/_app/immutable/nodes/3.vzk8SJSG.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.vzk8SJSG.js.gz +0 -0
- package/build/client/_app/version.json +1 -0
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/client/manifest.json.br +0 -0
- package/build/client/manifest.json.gz +0 -0
- package/build/env.js +45 -0
- package/build/handler.js +1375 -0
- package/build/index.js +334 -0
- package/build/server/chunks/0-D_yciAvo.js +91 -0
- package/build/server/chunks/0-D_yciAvo.js.map +1 -0
- package/build/server/chunks/1-BA-qTHOy.js +9 -0
- package/build/server/chunks/1-BA-qTHOy.js.map +1 -0
- package/build/server/chunks/2-DPsIhdeI.js +9 -0
- package/build/server/chunks/2-DPsIhdeI.js.map +1 -0
- package/build/server/chunks/3-CZREXwZu.js +9 -0
- package/build/server/chunks/3-CZREXwZu.js.map +1 -0
- package/build/server/chunks/LoadingIndicator-CTUFEPkL.js +10 -0
- package/build/server/chunks/LoadingIndicator-CTUFEPkL.js.map +1 -0
- package/build/server/chunks/LoadingIndicator.svelte_svelte_type_style_lang-CVdBHA1v.js +172 -0
- package/build/server/chunks/LoadingIndicator.svelte_svelte_type_style_lang-CVdBHA1v.js.map +1 -0
- package/build/server/chunks/PlayingTracker-BIq1bdv_.js +18 -0
- package/build/server/chunks/PlayingTracker-BIq1bdv_.js.map +1 -0
- package/build/server/chunks/_layout.svelte-BoFI04Ng.js +24 -0
- package/build/server/chunks/_layout.svelte-BoFI04Ng.js.map +1 -0
- package/build/server/chunks/_page.svelte-C3Mw7ZhL.js +115 -0
- package/build/server/chunks/_page.svelte-C3Mw7ZhL.js.map +1 -0
- package/build/server/chunks/_page.svelte-CzGyTA7b.js +368 -0
- package/build/server/chunks/_page.svelte-CzGyTA7b.js.map +1 -0
- package/build/server/chunks/error.svelte-BZE1ioPX.js +116 -0
- package/build/server/chunks/error.svelte-BZE1ioPX.js.map +1 -0
- package/build/server/chunks/exports-DAjI6ZSp.js +125 -0
- package/build/server/chunks/exports-DAjI6ZSp.js.map +1 -0
- package/build/server/chunks/index2-BA59f76P.js +1214 -0
- package/build/server/chunks/index2-BA59f76P.js.map +1 -0
- package/build/server/index.js +4868 -0
- package/build/server/index.js.map +1 -0
- package/build/server/manifest.js +50 -0
- package/build/server/manifest.js.map +1 -0
- package/build/shims.js +32 -0
- package/package.json +9 -2
- package/server/index.js +4 -0
- package/server/spotify_auth.json +1 -0
- package/.prettierignore +0 -4
- package/.prettierrc +0 -17
- package/CHANGELOG.md +0 -34
- package/env.template +0 -2
- package/eslint.config.js +0 -24
- package/jsconfig.json +0 -19
- package/screenshot.png +0 -0
- package/src/app.d.ts +0 -13
- package/src/app.html +0 -12
- package/src/lib/actions/qr.svelte.js +0 -23
- package/src/lib/comms.js +0 -25
- package/src/lib/components/AuthenticateTrigger.svelte +0 -74
- package/src/lib/components/Controls.svelte +0 -91
- package/src/lib/components/ImageLoad.svelte +0 -79
- package/src/lib/components/LoadingIndicator.svelte +0 -75
- package/src/lib/components/MediaItem.svelte +0 -75
- package/src/lib/components/PlayingTracker.svelte +0 -94
- package/src/lib/components/ResultsList.svelte +0 -80
- package/src/lib/components/Toast/Item.svelte +0 -71
- package/src/lib/components/Toast/Manager.svelte +0 -34
- package/src/lib/icons/disc.svg +0 -1
- package/src/lib/index.js +0 -1
- package/src/lib/store.js +0 -146
- package/src/lib/styles.scss +0 -166
- package/src/lib/toast.js +0 -57
- package/src/lib/utils.js +0 -723
- package/src/routes/+layout.server.js +0 -25
- package/src/routes/+layout.svelte +0 -72
- package/src/routes/+page.svelte +0 -381
- package/src/routes/player/+page.svelte +0 -294
- package/svelte.config.js +0 -19
- package/tools/BuildManifest.js +0 -87
- package/vite.config.js +0 -46
- /package/{static → build/client}/favicon.ico +0 -0
- /package/{static → build/client}/favicon.png +0 -0
- /package/{static → build/client}/icons/144.favicon.png +0 -0
- /package/{static → build/client}/icons/168.favicon.png +0 -0
- /package/{static → build/client}/icons/192.favicon.png +0 -0
- /package/{static → build/client}/icons/48.favicon.png +0 -0
- /package/{static → build/client}/icons/72.favicon.png +0 -0
- /package/{static → build/client}/icons/96.favicon.png +0 -0
- /package/{static → build/client}/manifest.json +0 -0
|
@@ -0,0 +1,4868 @@
|
|
|
1
|
+
import { r as render, g as get, L as LEGACY_PROPS, f as flush_sync, d as define_property, a as active_reaction, i as is_runes, D as DERIVED, B as BLOCK_EFFECT, b as derived_sources, s as state_unsafe_mutation, c as increment_version, e as DIRTY, h as set_signal_status, C as CLEAN, U as UNOWNED, j as schedule_effect, k as init_operations, l as get_first_child, H as HYDRATION_START, m as get_next_sibling, n as HYDRATION_ERROR, o as HYDRATION_END, p as hydration_failed, q as clear_text_content, t as array_from, u as component_root, v as push, w as setContext, x as pop, y as active_effect, z as BRANCH_EFFECT, A as new_deps, E as untracked_writes, F as set_untracked_writes, M as MAYBE_DIRTY, G as safe_equals, I as set_active_reaction, J as set_active_effect, K as is_array, N as is_passive_event, O as create_text, P as branch, Q as push$1, R as pop$1, S as equals, T as component_context, V as BROWSER, W as readable, X as writable } from './chunks/index2-BA59f76P.js';
|
|
2
|
+
import { d as decode_pathname, h as has_data_suffix, s as strip_data_suffix, a as decode_params, n as normalize_path, b as disable_search, c as add_data_suffix, m as make_trackable, r as resolve } from './chunks/exports-DAjI6ZSp.js';
|
|
3
|
+
|
|
4
|
+
let base = "";
|
|
5
|
+
let assets = base;
|
|
6
|
+
const initial = { base, assets };
|
|
7
|
+
function override(paths) {
|
|
8
|
+
base = paths.base;
|
|
9
|
+
assets = paths.assets;
|
|
10
|
+
}
|
|
11
|
+
function reset() {
|
|
12
|
+
base = initial.base;
|
|
13
|
+
assets = initial.assets;
|
|
14
|
+
}
|
|
15
|
+
let public_env = {};
|
|
16
|
+
let safe_public_env = {};
|
|
17
|
+
function set_public_env(environment) {
|
|
18
|
+
public_env = environment;
|
|
19
|
+
}
|
|
20
|
+
function set_safe_public_env(environment) {
|
|
21
|
+
safe_public_env = environment;
|
|
22
|
+
}
|
|
23
|
+
function source(v, stack) {
|
|
24
|
+
var signal = {
|
|
25
|
+
f: 0,
|
|
26
|
+
// TODO ideally we could skip this altogether, but it causes type errors
|
|
27
|
+
v,
|
|
28
|
+
reactions: null,
|
|
29
|
+
equals,
|
|
30
|
+
version: 0
|
|
31
|
+
};
|
|
32
|
+
return signal;
|
|
33
|
+
}
|
|
34
|
+
// @__NO_SIDE_EFFECTS__
|
|
35
|
+
function mutable_source(initial_value, immutable = false) {
|
|
36
|
+
const s = source(initial_value);
|
|
37
|
+
if (!immutable) {
|
|
38
|
+
s.equals = safe_equals;
|
|
39
|
+
}
|
|
40
|
+
return s;
|
|
41
|
+
}
|
|
42
|
+
function set(source2, value) {
|
|
43
|
+
if (active_reaction !== null && is_runes() && (active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 && // If the source was created locally within the current derived, then
|
|
44
|
+
// we allow the mutation.
|
|
45
|
+
(derived_sources === null || !derived_sources.includes(source2))) {
|
|
46
|
+
state_unsafe_mutation();
|
|
47
|
+
}
|
|
48
|
+
return internal_set(source2, value);
|
|
49
|
+
}
|
|
50
|
+
function internal_set(source2, value) {
|
|
51
|
+
if (!source2.equals(value)) {
|
|
52
|
+
source2.v = value;
|
|
53
|
+
source2.version = increment_version();
|
|
54
|
+
mark_reactions(source2, DIRTY);
|
|
55
|
+
if (active_effect !== null && (active_effect.f & CLEAN) !== 0 && (active_effect.f & BRANCH_EFFECT) === 0) {
|
|
56
|
+
if (new_deps !== null && new_deps.includes(source2)) {
|
|
57
|
+
set_signal_status(active_effect, DIRTY);
|
|
58
|
+
schedule_effect(active_effect);
|
|
59
|
+
} else {
|
|
60
|
+
if (untracked_writes === null) {
|
|
61
|
+
set_untracked_writes([source2]);
|
|
62
|
+
} else {
|
|
63
|
+
untracked_writes.push(source2);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
function mark_reactions(signal, status) {
|
|
71
|
+
var reactions = signal.reactions;
|
|
72
|
+
if (reactions === null) return;
|
|
73
|
+
var length = reactions.length;
|
|
74
|
+
for (var i = 0; i < length; i++) {
|
|
75
|
+
var reaction = reactions[i];
|
|
76
|
+
var flags = reaction.f;
|
|
77
|
+
if ((flags & DIRTY) !== 0) continue;
|
|
78
|
+
set_signal_status(reaction, status);
|
|
79
|
+
if ((flags & (CLEAN | UNOWNED)) !== 0) {
|
|
80
|
+
if ((flags & DERIVED) !== 0) {
|
|
81
|
+
mark_reactions(
|
|
82
|
+
/** @type {Derived} */
|
|
83
|
+
reaction,
|
|
84
|
+
MAYBE_DIRTY
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
schedule_effect(
|
|
88
|
+
/** @type {Effect} */
|
|
89
|
+
reaction
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function hydration_mismatch(location) {
|
|
96
|
+
{
|
|
97
|
+
console.warn(`https://svelte.dev/e/hydration_mismatch`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
let hydrating = false;
|
|
101
|
+
function set_hydrating(value) {
|
|
102
|
+
hydrating = value;
|
|
103
|
+
}
|
|
104
|
+
let hydrate_node;
|
|
105
|
+
function set_hydrate_node(node) {
|
|
106
|
+
if (node === null) {
|
|
107
|
+
hydration_mismatch();
|
|
108
|
+
throw HYDRATION_ERROR;
|
|
109
|
+
}
|
|
110
|
+
return hydrate_node = node;
|
|
111
|
+
}
|
|
112
|
+
function hydrate_next() {
|
|
113
|
+
return set_hydrate_node(
|
|
114
|
+
/** @type {TemplateNode} */
|
|
115
|
+
get_next_sibling(hydrate_node)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
const all_registered_events = /* @__PURE__ */ new Set();
|
|
119
|
+
const root_event_handles = /* @__PURE__ */ new Set();
|
|
120
|
+
function handle_event_propagation(event) {
|
|
121
|
+
var handler_element = this;
|
|
122
|
+
var owner_document = (
|
|
123
|
+
/** @type {Node} */
|
|
124
|
+
handler_element.ownerDocument
|
|
125
|
+
);
|
|
126
|
+
var event_name = event.type;
|
|
127
|
+
var path = event.composedPath?.() || [];
|
|
128
|
+
var current_target = (
|
|
129
|
+
/** @type {null | Element} */
|
|
130
|
+
path[0] || event.target
|
|
131
|
+
);
|
|
132
|
+
var path_idx = 0;
|
|
133
|
+
var handled_at = event.__root;
|
|
134
|
+
if (handled_at) {
|
|
135
|
+
var at_idx = path.indexOf(handled_at);
|
|
136
|
+
if (at_idx !== -1 && (handler_element === document || handler_element === /** @type {any} */
|
|
137
|
+
window)) {
|
|
138
|
+
event.__root = handler_element;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
var handler_idx = path.indexOf(handler_element);
|
|
142
|
+
if (handler_idx === -1) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (at_idx <= handler_idx) {
|
|
146
|
+
path_idx = at_idx;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
current_target = /** @type {Element} */
|
|
150
|
+
path[path_idx] || event.target;
|
|
151
|
+
if (current_target === handler_element) return;
|
|
152
|
+
define_property(event, "currentTarget", {
|
|
153
|
+
configurable: true,
|
|
154
|
+
get() {
|
|
155
|
+
return current_target || owner_document;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
var previous_reaction = active_reaction;
|
|
159
|
+
var previous_effect = active_effect;
|
|
160
|
+
set_active_reaction(null);
|
|
161
|
+
set_active_effect(null);
|
|
162
|
+
try {
|
|
163
|
+
var throw_error;
|
|
164
|
+
var other_errors = [];
|
|
165
|
+
while (current_target !== null) {
|
|
166
|
+
var parent_element = current_target.assignedSlot || current_target.parentNode || /** @type {any} */
|
|
167
|
+
current_target.host || null;
|
|
168
|
+
try {
|
|
169
|
+
var delegated = current_target["__" + event_name];
|
|
170
|
+
if (delegated !== void 0 && !/** @type {any} */
|
|
171
|
+
current_target.disabled) {
|
|
172
|
+
if (is_array(delegated)) {
|
|
173
|
+
var [fn, ...data] = delegated;
|
|
174
|
+
fn.apply(current_target, [event, ...data]);
|
|
175
|
+
} else {
|
|
176
|
+
delegated.call(current_target, event);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (throw_error) {
|
|
181
|
+
other_errors.push(error);
|
|
182
|
+
} else {
|
|
183
|
+
throw_error = error;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (event.cancelBubble || parent_element === handler_element || parent_element === null) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
current_target = parent_element;
|
|
190
|
+
}
|
|
191
|
+
if (throw_error) {
|
|
192
|
+
for (let error of other_errors) {
|
|
193
|
+
queueMicrotask(() => {
|
|
194
|
+
throw error;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
throw throw_error;
|
|
198
|
+
}
|
|
199
|
+
} finally {
|
|
200
|
+
event.__root = handler_element;
|
|
201
|
+
delete event.currentTarget;
|
|
202
|
+
set_active_reaction(previous_reaction);
|
|
203
|
+
set_active_effect(previous_effect);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function assign_nodes(start, end) {
|
|
207
|
+
var effect = (
|
|
208
|
+
/** @type {Effect} */
|
|
209
|
+
active_effect
|
|
210
|
+
);
|
|
211
|
+
if (effect.nodes_start === null) {
|
|
212
|
+
effect.nodes_start = start;
|
|
213
|
+
effect.nodes_end = end;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function mount(component, options2) {
|
|
217
|
+
return _mount(component, options2);
|
|
218
|
+
}
|
|
219
|
+
function hydrate(component, options2) {
|
|
220
|
+
init_operations();
|
|
221
|
+
options2.intro = options2.intro ?? false;
|
|
222
|
+
const target = options2.target;
|
|
223
|
+
const was_hydrating = hydrating;
|
|
224
|
+
const previous_hydrate_node = hydrate_node;
|
|
225
|
+
try {
|
|
226
|
+
var anchor = (
|
|
227
|
+
/** @type {TemplateNode} */
|
|
228
|
+
get_first_child(target)
|
|
229
|
+
);
|
|
230
|
+
while (anchor && (anchor.nodeType !== 8 || /** @type {Comment} */
|
|
231
|
+
anchor.data !== HYDRATION_START)) {
|
|
232
|
+
anchor = /** @type {TemplateNode} */
|
|
233
|
+
get_next_sibling(anchor);
|
|
234
|
+
}
|
|
235
|
+
if (!anchor) {
|
|
236
|
+
throw HYDRATION_ERROR;
|
|
237
|
+
}
|
|
238
|
+
set_hydrating(true);
|
|
239
|
+
set_hydrate_node(
|
|
240
|
+
/** @type {Comment} */
|
|
241
|
+
anchor
|
|
242
|
+
);
|
|
243
|
+
hydrate_next();
|
|
244
|
+
const instance = _mount(component, { ...options2, anchor });
|
|
245
|
+
if (hydrate_node === null || hydrate_node.nodeType !== 8 || /** @type {Comment} */
|
|
246
|
+
hydrate_node.data !== HYDRATION_END) {
|
|
247
|
+
hydration_mismatch();
|
|
248
|
+
throw HYDRATION_ERROR;
|
|
249
|
+
}
|
|
250
|
+
set_hydrating(false);
|
|
251
|
+
return (
|
|
252
|
+
/** @type {Exports} */
|
|
253
|
+
instance
|
|
254
|
+
);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (error === HYDRATION_ERROR) {
|
|
257
|
+
if (options2.recover === false) {
|
|
258
|
+
hydration_failed();
|
|
259
|
+
}
|
|
260
|
+
init_operations();
|
|
261
|
+
clear_text_content(target);
|
|
262
|
+
set_hydrating(false);
|
|
263
|
+
return mount(component, options2);
|
|
264
|
+
}
|
|
265
|
+
throw error;
|
|
266
|
+
} finally {
|
|
267
|
+
set_hydrating(was_hydrating);
|
|
268
|
+
set_hydrate_node(previous_hydrate_node);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const document_listeners = /* @__PURE__ */ new Map();
|
|
272
|
+
function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
|
|
273
|
+
init_operations();
|
|
274
|
+
var registered_events = /* @__PURE__ */ new Set();
|
|
275
|
+
var event_handle = (events2) => {
|
|
276
|
+
for (var i = 0; i < events2.length; i++) {
|
|
277
|
+
var event_name = events2[i];
|
|
278
|
+
if (registered_events.has(event_name)) continue;
|
|
279
|
+
registered_events.add(event_name);
|
|
280
|
+
var passive = is_passive_event(event_name);
|
|
281
|
+
target.addEventListener(event_name, handle_event_propagation, { passive });
|
|
282
|
+
var n = document_listeners.get(event_name);
|
|
283
|
+
if (n === void 0) {
|
|
284
|
+
document.addEventListener(event_name, handle_event_propagation, { passive });
|
|
285
|
+
document_listeners.set(event_name, 1);
|
|
286
|
+
} else {
|
|
287
|
+
document_listeners.set(event_name, n + 1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
event_handle(array_from(all_registered_events));
|
|
292
|
+
root_event_handles.add(event_handle);
|
|
293
|
+
var component = void 0;
|
|
294
|
+
var unmount2 = component_root(() => {
|
|
295
|
+
var anchor_node = anchor ?? target.appendChild(create_text());
|
|
296
|
+
branch(() => {
|
|
297
|
+
if (context) {
|
|
298
|
+
push$1({});
|
|
299
|
+
var ctx = (
|
|
300
|
+
/** @type {ComponentContext} */
|
|
301
|
+
component_context
|
|
302
|
+
);
|
|
303
|
+
ctx.c = context;
|
|
304
|
+
}
|
|
305
|
+
if (events) {
|
|
306
|
+
props.$$events = events;
|
|
307
|
+
}
|
|
308
|
+
if (hydrating) {
|
|
309
|
+
assign_nodes(
|
|
310
|
+
/** @type {TemplateNode} */
|
|
311
|
+
anchor_node,
|
|
312
|
+
null
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
component = Component(anchor_node, props) || {};
|
|
316
|
+
if (hydrating) {
|
|
317
|
+
active_effect.nodes_end = hydrate_node;
|
|
318
|
+
}
|
|
319
|
+
if (context) {
|
|
320
|
+
pop$1();
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
return () => {
|
|
324
|
+
for (var event_name of registered_events) {
|
|
325
|
+
target.removeEventListener(event_name, handle_event_propagation);
|
|
326
|
+
var n = (
|
|
327
|
+
/** @type {number} */
|
|
328
|
+
document_listeners.get(event_name)
|
|
329
|
+
);
|
|
330
|
+
if (--n === 0) {
|
|
331
|
+
document.removeEventListener(event_name, handle_event_propagation);
|
|
332
|
+
document_listeners.delete(event_name);
|
|
333
|
+
} else {
|
|
334
|
+
document_listeners.set(event_name, n);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
root_event_handles.delete(event_handle);
|
|
338
|
+
if (anchor_node !== anchor) {
|
|
339
|
+
anchor_node.parentNode?.removeChild(anchor_node);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
});
|
|
343
|
+
mounted_components.set(component, unmount2);
|
|
344
|
+
return component;
|
|
345
|
+
}
|
|
346
|
+
let mounted_components = /* @__PURE__ */ new WeakMap();
|
|
347
|
+
function unmount(component, options2) {
|
|
348
|
+
const fn = mounted_components.get(component);
|
|
349
|
+
if (fn) {
|
|
350
|
+
mounted_components.delete(component);
|
|
351
|
+
return fn(options2);
|
|
352
|
+
}
|
|
353
|
+
return Promise.resolve();
|
|
354
|
+
}
|
|
355
|
+
function asClassComponent$1(component) {
|
|
356
|
+
return class extends Svelte4Component {
|
|
357
|
+
/** @param {any} options */
|
|
358
|
+
constructor(options2) {
|
|
359
|
+
super({
|
|
360
|
+
component,
|
|
361
|
+
...options2
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
class Svelte4Component {
|
|
367
|
+
/** @type {any} */
|
|
368
|
+
#events;
|
|
369
|
+
/** @type {Record<string, any>} */
|
|
370
|
+
#instance;
|
|
371
|
+
/**
|
|
372
|
+
* @param {ComponentConstructorOptions & {
|
|
373
|
+
* component: any;
|
|
374
|
+
* }} options
|
|
375
|
+
*/
|
|
376
|
+
constructor(options2) {
|
|
377
|
+
var sources = /* @__PURE__ */ new Map();
|
|
378
|
+
var add_source = (key, value) => {
|
|
379
|
+
var s = /* @__PURE__ */ mutable_source(value);
|
|
380
|
+
sources.set(key, s);
|
|
381
|
+
return s;
|
|
382
|
+
};
|
|
383
|
+
const props = new Proxy(
|
|
384
|
+
{ ...options2.props || {}, $$events: {} },
|
|
385
|
+
{
|
|
386
|
+
get(target, prop) {
|
|
387
|
+
return get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
388
|
+
},
|
|
389
|
+
has(target, prop) {
|
|
390
|
+
if (prop === LEGACY_PROPS) return true;
|
|
391
|
+
get(sources.get(prop) ?? add_source(prop, Reflect.get(target, prop)));
|
|
392
|
+
return Reflect.has(target, prop);
|
|
393
|
+
},
|
|
394
|
+
set(target, prop, value) {
|
|
395
|
+
set(sources.get(prop) ?? add_source(prop, value), value);
|
|
396
|
+
return Reflect.set(target, prop, value);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
);
|
|
400
|
+
this.#instance = (options2.hydrate ? hydrate : mount)(options2.component, {
|
|
401
|
+
target: options2.target,
|
|
402
|
+
anchor: options2.anchor,
|
|
403
|
+
props,
|
|
404
|
+
context: options2.context,
|
|
405
|
+
intro: options2.intro ?? false,
|
|
406
|
+
recover: options2.recover
|
|
407
|
+
});
|
|
408
|
+
if (!options2?.props?.$$host || options2.sync === false) {
|
|
409
|
+
flush_sync();
|
|
410
|
+
}
|
|
411
|
+
this.#events = props.$$events;
|
|
412
|
+
for (const key of Object.keys(this.#instance)) {
|
|
413
|
+
if (key === "$set" || key === "$destroy" || key === "$on") continue;
|
|
414
|
+
define_property(this, key, {
|
|
415
|
+
get() {
|
|
416
|
+
return this.#instance[key];
|
|
417
|
+
},
|
|
418
|
+
/** @param {any} value */
|
|
419
|
+
set(value) {
|
|
420
|
+
this.#instance[key] = value;
|
|
421
|
+
},
|
|
422
|
+
enumerable: true
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
this.#instance.$set = /** @param {Record<string, any>} next */
|
|
426
|
+
(next) => {
|
|
427
|
+
Object.assign(props, next);
|
|
428
|
+
};
|
|
429
|
+
this.#instance.$destroy = () => {
|
|
430
|
+
unmount(this.#instance);
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/** @param {Record<string, any>} props */
|
|
434
|
+
$set(props) {
|
|
435
|
+
this.#instance.$set(props);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* @param {string} event
|
|
439
|
+
* @param {(...args: any[]) => any} callback
|
|
440
|
+
* @returns {any}
|
|
441
|
+
*/
|
|
442
|
+
$on(event, callback) {
|
|
443
|
+
this.#events[event] = this.#events[event] || [];
|
|
444
|
+
const cb = (...args) => callback.call(this, ...args);
|
|
445
|
+
this.#events[event].push(cb);
|
|
446
|
+
return () => {
|
|
447
|
+
this.#events[event] = this.#events[event].filter(
|
|
448
|
+
/** @param {any} fn */
|
|
449
|
+
(fn) => fn !== cb
|
|
450
|
+
);
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
$destroy() {
|
|
454
|
+
this.#instance.$destroy();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
let read_implementation = null;
|
|
458
|
+
function set_read_implementation(fn) {
|
|
459
|
+
read_implementation = fn;
|
|
460
|
+
}
|
|
461
|
+
function asClassComponent(component) {
|
|
462
|
+
const component_constructor = asClassComponent$1(component);
|
|
463
|
+
const _render = (props, { context } = {}) => {
|
|
464
|
+
const result = render(component, { props, context });
|
|
465
|
+
return {
|
|
466
|
+
css: { code: "", map: null },
|
|
467
|
+
head: result.head,
|
|
468
|
+
html: result.body
|
|
469
|
+
};
|
|
470
|
+
};
|
|
471
|
+
component_constructor.render = _render;
|
|
472
|
+
return component_constructor;
|
|
473
|
+
}
|
|
474
|
+
function Root($$payload, $$props) {
|
|
475
|
+
push();
|
|
476
|
+
let {
|
|
477
|
+
stores,
|
|
478
|
+
page,
|
|
479
|
+
constructors,
|
|
480
|
+
components = [],
|
|
481
|
+
form,
|
|
482
|
+
data_0 = null,
|
|
483
|
+
data_1 = null
|
|
484
|
+
} = $$props;
|
|
485
|
+
{
|
|
486
|
+
setContext("__svelte__", stores);
|
|
487
|
+
}
|
|
488
|
+
{
|
|
489
|
+
stores.page.set(page);
|
|
490
|
+
}
|
|
491
|
+
const Pyramid_1 = constructors[1];
|
|
492
|
+
if (constructors[1]) {
|
|
493
|
+
$$payload.out += "<!--[-->";
|
|
494
|
+
const Pyramid_0 = constructors[0];
|
|
495
|
+
$$payload.out += `<!---->`;
|
|
496
|
+
Pyramid_0($$payload, {
|
|
497
|
+
data: data_0,
|
|
498
|
+
form,
|
|
499
|
+
children: ($$payload2) => {
|
|
500
|
+
$$payload2.out += `<!---->`;
|
|
501
|
+
Pyramid_1($$payload2, { data: data_1, form });
|
|
502
|
+
$$payload2.out += `<!---->`;
|
|
503
|
+
},
|
|
504
|
+
$$slots: { default: true }
|
|
505
|
+
});
|
|
506
|
+
$$payload.out += `<!---->`;
|
|
507
|
+
} else {
|
|
508
|
+
$$payload.out += "<!--[!-->";
|
|
509
|
+
const Pyramid_0 = constructors[0];
|
|
510
|
+
$$payload.out += `<!---->`;
|
|
511
|
+
Pyramid_0($$payload, { data: data_0, form });
|
|
512
|
+
$$payload.out += `<!---->`;
|
|
513
|
+
}
|
|
514
|
+
$$payload.out += `<!--]--> `;
|
|
515
|
+
{
|
|
516
|
+
$$payload.out += "<!--[!-->";
|
|
517
|
+
}
|
|
518
|
+
$$payload.out += `<!--]-->`;
|
|
519
|
+
pop();
|
|
520
|
+
}
|
|
521
|
+
const root = asClassComponent(Root);
|
|
522
|
+
const options = {
|
|
523
|
+
app_dir: "_app",
|
|
524
|
+
app_template_contains_nonce: false,
|
|
525
|
+
csp: { "mode": "auto", "directives": { "upgrade-insecure-requests": false, "block-all-mixed-content": false }, "reportOnly": { "upgrade-insecure-requests": false, "block-all-mixed-content": false } },
|
|
526
|
+
csrf_check_origin: true,
|
|
527
|
+
embedded: false,
|
|
528
|
+
env_public_prefix: "PUBLIC_",
|
|
529
|
+
env_private_prefix: "",
|
|
530
|
+
hash_routing: false,
|
|
531
|
+
hooks: null,
|
|
532
|
+
// added lazily, via `get_hooks`
|
|
533
|
+
preload_strategy: "modulepreload",
|
|
534
|
+
root,
|
|
535
|
+
service_worker: false,
|
|
536
|
+
templates: {
|
|
537
|
+
app: ({ head, body, assets: assets2, nonce, env }) => '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <link rel="icon" href="' + assets2 + '/favicon.png" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n ' + head + '\n </head>\n <body data-sveltekit-preload-data="hover">\n <div style="display: contents">' + body + "</div>\n </body>\n</html>\n",
|
|
538
|
+
error: ({ status, message }) => '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <title>' + message + `</title>
|
|
539
|
+
|
|
540
|
+
<style>
|
|
541
|
+
body {
|
|
542
|
+
--bg: white;
|
|
543
|
+
--fg: #222;
|
|
544
|
+
--divider: #ccc;
|
|
545
|
+
background: var(--bg);
|
|
546
|
+
color: var(--fg);
|
|
547
|
+
font-family:
|
|
548
|
+
system-ui,
|
|
549
|
+
-apple-system,
|
|
550
|
+
BlinkMacSystemFont,
|
|
551
|
+
'Segoe UI',
|
|
552
|
+
Roboto,
|
|
553
|
+
Oxygen,
|
|
554
|
+
Ubuntu,
|
|
555
|
+
Cantarell,
|
|
556
|
+
'Open Sans',
|
|
557
|
+
'Helvetica Neue',
|
|
558
|
+
sans-serif;
|
|
559
|
+
display: flex;
|
|
560
|
+
align-items: center;
|
|
561
|
+
justify-content: center;
|
|
562
|
+
height: 100vh;
|
|
563
|
+
margin: 0;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
.error {
|
|
567
|
+
display: flex;
|
|
568
|
+
align-items: center;
|
|
569
|
+
max-width: 32rem;
|
|
570
|
+
margin: 0 1rem;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
.status {
|
|
574
|
+
font-weight: 200;
|
|
575
|
+
font-size: 3rem;
|
|
576
|
+
line-height: 1;
|
|
577
|
+
position: relative;
|
|
578
|
+
top: -0.05rem;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
.message {
|
|
582
|
+
border-left: 1px solid var(--divider);
|
|
583
|
+
padding: 0 0 0 1rem;
|
|
584
|
+
margin: 0 0 0 1rem;
|
|
585
|
+
min-height: 2.5rem;
|
|
586
|
+
display: flex;
|
|
587
|
+
align-items: center;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
.message h1 {
|
|
591
|
+
font-weight: 400;
|
|
592
|
+
font-size: 1em;
|
|
593
|
+
margin: 0;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
@media (prefers-color-scheme: dark) {
|
|
597
|
+
body {
|
|
598
|
+
--bg: #222;
|
|
599
|
+
--fg: #ddd;
|
|
600
|
+
--divider: #666;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
</style>
|
|
604
|
+
</head>
|
|
605
|
+
<body>
|
|
606
|
+
<div class="error">
|
|
607
|
+
<span class="status">` + status + '</span>\n <div class="message">\n <h1>' + message + "</h1>\n </div>\n </div>\n </body>\n</html>\n"
|
|
608
|
+
},
|
|
609
|
+
version_hash: "adx3sp"
|
|
610
|
+
};
|
|
611
|
+
async function get_hooks() {
|
|
612
|
+
let handle;
|
|
613
|
+
let handleFetch;
|
|
614
|
+
let handleError;
|
|
615
|
+
let init;
|
|
616
|
+
let reroute;
|
|
617
|
+
let transport;
|
|
618
|
+
return {
|
|
619
|
+
handle,
|
|
620
|
+
handleFetch,
|
|
621
|
+
handleError,
|
|
622
|
+
init,
|
|
623
|
+
reroute,
|
|
624
|
+
transport
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/** @type {Record<string, string>} */
|
|
629
|
+
const escaped = {
|
|
630
|
+
'<': '\\u003C',
|
|
631
|
+
'\\': '\\\\',
|
|
632
|
+
'\b': '\\b',
|
|
633
|
+
'\f': '\\f',
|
|
634
|
+
'\n': '\\n',
|
|
635
|
+
'\r': '\\r',
|
|
636
|
+
'\t': '\\t',
|
|
637
|
+
'\u2028': '\\u2028',
|
|
638
|
+
'\u2029': '\\u2029'
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
class DevalueError extends Error {
|
|
642
|
+
/**
|
|
643
|
+
* @param {string} message
|
|
644
|
+
* @param {string[]} keys
|
|
645
|
+
*/
|
|
646
|
+
constructor(message, keys) {
|
|
647
|
+
super(message);
|
|
648
|
+
this.name = 'DevalueError';
|
|
649
|
+
this.path = keys.join('');
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** @param {any} thing */
|
|
654
|
+
function is_primitive(thing) {
|
|
655
|
+
return Object(thing) !== thing;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(
|
|
659
|
+
Object.prototype
|
|
660
|
+
)
|
|
661
|
+
.sort()
|
|
662
|
+
.join('\0');
|
|
663
|
+
|
|
664
|
+
/** @param {any} thing */
|
|
665
|
+
function is_plain_object(thing) {
|
|
666
|
+
const proto = Object.getPrototypeOf(thing);
|
|
667
|
+
|
|
668
|
+
return (
|
|
669
|
+
proto === Object.prototype ||
|
|
670
|
+
proto === null ||
|
|
671
|
+
Object.getOwnPropertyNames(proto).sort().join('\0') === object_proto_names
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** @param {any} thing */
|
|
676
|
+
function get_type(thing) {
|
|
677
|
+
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/** @param {string} char */
|
|
681
|
+
function get_escaped_char(char) {
|
|
682
|
+
switch (char) {
|
|
683
|
+
case '"':
|
|
684
|
+
return '\\"';
|
|
685
|
+
case '<':
|
|
686
|
+
return '\\u003C';
|
|
687
|
+
case '\\':
|
|
688
|
+
return '\\\\';
|
|
689
|
+
case '\n':
|
|
690
|
+
return '\\n';
|
|
691
|
+
case '\r':
|
|
692
|
+
return '\\r';
|
|
693
|
+
case '\t':
|
|
694
|
+
return '\\t';
|
|
695
|
+
case '\b':
|
|
696
|
+
return '\\b';
|
|
697
|
+
case '\f':
|
|
698
|
+
return '\\f';
|
|
699
|
+
case '\u2028':
|
|
700
|
+
return '\\u2028';
|
|
701
|
+
case '\u2029':
|
|
702
|
+
return '\\u2029';
|
|
703
|
+
default:
|
|
704
|
+
return char < ' '
|
|
705
|
+
? `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`
|
|
706
|
+
: '';
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/** @param {string} str */
|
|
711
|
+
function stringify_string(str) {
|
|
712
|
+
let result = '';
|
|
713
|
+
let last_pos = 0;
|
|
714
|
+
const len = str.length;
|
|
715
|
+
|
|
716
|
+
for (let i = 0; i < len; i += 1) {
|
|
717
|
+
const char = str[i];
|
|
718
|
+
const replacement = get_escaped_char(char);
|
|
719
|
+
if (replacement) {
|
|
720
|
+
result += str.slice(last_pos, i) + replacement;
|
|
721
|
+
last_pos = i + 1;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/** @param {Record<string | symbol, any>} object */
|
|
729
|
+
function enumerable_symbols(object) {
|
|
730
|
+
return Object.getOwnPropertySymbols(object).filter(
|
|
731
|
+
(symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
736
|
+
|
|
737
|
+
/** @param {string} key */
|
|
738
|
+
function stringify_key(key) {
|
|
739
|
+
return is_identifier.test(key) ? '.' + key : '[' + JSON.stringify(key) + ']';
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
const chars$1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
|
|
743
|
+
const unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g;
|
|
744
|
+
const reserved =
|
|
745
|
+
/^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Turn a value into the JavaScript that creates an equivalent value
|
|
749
|
+
* @param {any} value
|
|
750
|
+
* @param {(value: any) => string | void} [replacer]
|
|
751
|
+
*/
|
|
752
|
+
function uneval(value, replacer) {
|
|
753
|
+
const counts = new Map();
|
|
754
|
+
|
|
755
|
+
/** @type {string[]} */
|
|
756
|
+
const keys = [];
|
|
757
|
+
|
|
758
|
+
const custom = new Map();
|
|
759
|
+
|
|
760
|
+
/** @param {any} thing */
|
|
761
|
+
function walk(thing) {
|
|
762
|
+
if (typeof thing === 'function') {
|
|
763
|
+
throw new DevalueError(`Cannot stringify a function`, keys);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (!is_primitive(thing)) {
|
|
767
|
+
if (counts.has(thing)) {
|
|
768
|
+
counts.set(thing, counts.get(thing) + 1);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
counts.set(thing, 1);
|
|
773
|
+
|
|
774
|
+
if (replacer) {
|
|
775
|
+
const str = replacer(thing);
|
|
776
|
+
|
|
777
|
+
if (typeof str === 'string') {
|
|
778
|
+
custom.set(thing, str);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const type = get_type(thing);
|
|
784
|
+
|
|
785
|
+
switch (type) {
|
|
786
|
+
case 'Number':
|
|
787
|
+
case 'BigInt':
|
|
788
|
+
case 'String':
|
|
789
|
+
case 'Boolean':
|
|
790
|
+
case 'Date':
|
|
791
|
+
case 'RegExp':
|
|
792
|
+
return;
|
|
793
|
+
|
|
794
|
+
case 'Array':
|
|
795
|
+
/** @type {any[]} */ (thing).forEach((value, i) => {
|
|
796
|
+
keys.push(`[${i}]`);
|
|
797
|
+
walk(value);
|
|
798
|
+
keys.pop();
|
|
799
|
+
});
|
|
800
|
+
break;
|
|
801
|
+
|
|
802
|
+
case 'Set':
|
|
803
|
+
Array.from(thing).forEach(walk);
|
|
804
|
+
break;
|
|
805
|
+
|
|
806
|
+
case 'Map':
|
|
807
|
+
for (const [key, value] of thing) {
|
|
808
|
+
keys.push(
|
|
809
|
+
`.get(${is_primitive(key) ? stringify_primitive$1(key) : '...'})`
|
|
810
|
+
);
|
|
811
|
+
walk(value);
|
|
812
|
+
keys.pop();
|
|
813
|
+
}
|
|
814
|
+
break;
|
|
815
|
+
|
|
816
|
+
case "Int8Array":
|
|
817
|
+
case "Uint8Array":
|
|
818
|
+
case "Uint8ClampedArray":
|
|
819
|
+
case "Int16Array":
|
|
820
|
+
case "Uint16Array":
|
|
821
|
+
case "Int32Array":
|
|
822
|
+
case "Uint32Array":
|
|
823
|
+
case "Float32Array":
|
|
824
|
+
case "Float64Array":
|
|
825
|
+
case "BigInt64Array":
|
|
826
|
+
case "BigUint64Array":
|
|
827
|
+
return;
|
|
828
|
+
|
|
829
|
+
case "ArrayBuffer":
|
|
830
|
+
return;
|
|
831
|
+
|
|
832
|
+
default:
|
|
833
|
+
if (!is_plain_object(thing)) {
|
|
834
|
+
throw new DevalueError(
|
|
835
|
+
`Cannot stringify arbitrary non-POJOs`,
|
|
836
|
+
keys
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
841
|
+
throw new DevalueError(
|
|
842
|
+
`Cannot stringify POJOs with symbolic keys`,
|
|
843
|
+
keys
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
for (const key in thing) {
|
|
848
|
+
keys.push(stringify_key(key));
|
|
849
|
+
walk(thing[key]);
|
|
850
|
+
keys.pop();
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
walk(value);
|
|
857
|
+
|
|
858
|
+
const names = new Map();
|
|
859
|
+
|
|
860
|
+
Array.from(counts)
|
|
861
|
+
.filter((entry) => entry[1] > 1)
|
|
862
|
+
.sort((a, b) => b[1] - a[1])
|
|
863
|
+
.forEach((entry, i) => {
|
|
864
|
+
names.set(entry[0], get_name(i));
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* @param {any} thing
|
|
869
|
+
* @returns {string}
|
|
870
|
+
*/
|
|
871
|
+
function stringify(thing) {
|
|
872
|
+
if (names.has(thing)) {
|
|
873
|
+
return names.get(thing);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
if (is_primitive(thing)) {
|
|
877
|
+
return stringify_primitive$1(thing);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
if (custom.has(thing)) {
|
|
881
|
+
return custom.get(thing);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
const type = get_type(thing);
|
|
885
|
+
|
|
886
|
+
switch (type) {
|
|
887
|
+
case 'Number':
|
|
888
|
+
case 'String':
|
|
889
|
+
case 'Boolean':
|
|
890
|
+
return `Object(${stringify(thing.valueOf())})`;
|
|
891
|
+
|
|
892
|
+
case 'RegExp':
|
|
893
|
+
return `new RegExp(${stringify_string(thing.source)}, "${
|
|
894
|
+
thing.flags
|
|
895
|
+
}")`;
|
|
896
|
+
|
|
897
|
+
case 'Date':
|
|
898
|
+
return `new Date(${thing.getTime()})`;
|
|
899
|
+
|
|
900
|
+
case 'Array':
|
|
901
|
+
const members = /** @type {any[]} */ (thing).map((v, i) =>
|
|
902
|
+
i in thing ? stringify(v) : ''
|
|
903
|
+
);
|
|
904
|
+
const tail = thing.length === 0 || thing.length - 1 in thing ? '' : ',';
|
|
905
|
+
return `[${members.join(',')}${tail}]`;
|
|
906
|
+
|
|
907
|
+
case 'Set':
|
|
908
|
+
case 'Map':
|
|
909
|
+
return `new ${type}([${Array.from(thing).map(stringify).join(',')}])`;
|
|
910
|
+
|
|
911
|
+
case "Int8Array":
|
|
912
|
+
case "Uint8Array":
|
|
913
|
+
case "Uint8ClampedArray":
|
|
914
|
+
case "Int16Array":
|
|
915
|
+
case "Uint16Array":
|
|
916
|
+
case "Int32Array":
|
|
917
|
+
case "Uint32Array":
|
|
918
|
+
case "Float32Array":
|
|
919
|
+
case "Float64Array":
|
|
920
|
+
case "BigInt64Array":
|
|
921
|
+
case "BigUint64Array": {
|
|
922
|
+
/** @type {import("./types.js").TypedArray} */
|
|
923
|
+
const typedArray = thing;
|
|
924
|
+
return `new ${type}([${typedArray.toString()}])`;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
case "ArrayBuffer": {
|
|
928
|
+
const ui8 = new Uint8Array(thing);
|
|
929
|
+
return `new Uint8Array([${ui8.toString()}]).buffer`;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
default:
|
|
933
|
+
const obj = `{${Object.keys(thing)
|
|
934
|
+
.map((key) => `${safe_key(key)}:${stringify(thing[key])}`)
|
|
935
|
+
.join(',')}}`;
|
|
936
|
+
const proto = Object.getPrototypeOf(thing);
|
|
937
|
+
if (proto === null) {
|
|
938
|
+
return Object.keys(thing).length > 0
|
|
939
|
+
? `Object.assign(Object.create(null),${obj})`
|
|
940
|
+
: `Object.create(null)`;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
return obj;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
const str = stringify(value);
|
|
948
|
+
|
|
949
|
+
if (names.size) {
|
|
950
|
+
/** @type {string[]} */
|
|
951
|
+
const params = [];
|
|
952
|
+
|
|
953
|
+
/** @type {string[]} */
|
|
954
|
+
const statements = [];
|
|
955
|
+
|
|
956
|
+
/** @type {string[]} */
|
|
957
|
+
const values = [];
|
|
958
|
+
|
|
959
|
+
names.forEach((name, thing) => {
|
|
960
|
+
params.push(name);
|
|
961
|
+
|
|
962
|
+
if (custom.has(thing)) {
|
|
963
|
+
values.push(/** @type {string} */ (custom.get(thing)));
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (is_primitive(thing)) {
|
|
968
|
+
values.push(stringify_primitive$1(thing));
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const type = get_type(thing);
|
|
973
|
+
|
|
974
|
+
switch (type) {
|
|
975
|
+
case 'Number':
|
|
976
|
+
case 'String':
|
|
977
|
+
case 'Boolean':
|
|
978
|
+
values.push(`Object(${stringify(thing.valueOf())})`);
|
|
979
|
+
break;
|
|
980
|
+
|
|
981
|
+
case 'RegExp':
|
|
982
|
+
values.push(thing.toString());
|
|
983
|
+
break;
|
|
984
|
+
|
|
985
|
+
case 'Date':
|
|
986
|
+
values.push(`new Date(${thing.getTime()})`);
|
|
987
|
+
break;
|
|
988
|
+
|
|
989
|
+
case 'Array':
|
|
990
|
+
values.push(`Array(${thing.length})`);
|
|
991
|
+
/** @type {any[]} */ (thing).forEach((v, i) => {
|
|
992
|
+
statements.push(`${name}[${i}]=${stringify(v)}`);
|
|
993
|
+
});
|
|
994
|
+
break;
|
|
995
|
+
|
|
996
|
+
case 'Set':
|
|
997
|
+
values.push(`new Set`);
|
|
998
|
+
statements.push(
|
|
999
|
+
`${name}.${Array.from(thing)
|
|
1000
|
+
.map((v) => `add(${stringify(v)})`)
|
|
1001
|
+
.join('.')}`
|
|
1002
|
+
);
|
|
1003
|
+
break;
|
|
1004
|
+
|
|
1005
|
+
case 'Map':
|
|
1006
|
+
values.push(`new Map`);
|
|
1007
|
+
statements.push(
|
|
1008
|
+
`${name}.${Array.from(thing)
|
|
1009
|
+
.map(([k, v]) => `set(${stringify(k)}, ${stringify(v)})`)
|
|
1010
|
+
.join('.')}`
|
|
1011
|
+
);
|
|
1012
|
+
break;
|
|
1013
|
+
|
|
1014
|
+
default:
|
|
1015
|
+
values.push(
|
|
1016
|
+
Object.getPrototypeOf(thing) === null ? 'Object.create(null)' : '{}'
|
|
1017
|
+
);
|
|
1018
|
+
Object.keys(thing).forEach((key) => {
|
|
1019
|
+
statements.push(
|
|
1020
|
+
`${name}${safe_prop(key)}=${stringify(thing[key])}`
|
|
1021
|
+
);
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
statements.push(`return ${str}`);
|
|
1027
|
+
|
|
1028
|
+
return `(function(${params.join(',')}){${statements.join(
|
|
1029
|
+
';'
|
|
1030
|
+
)}}(${values.join(',')}))`;
|
|
1031
|
+
} else {
|
|
1032
|
+
return str;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/** @param {number} num */
|
|
1037
|
+
function get_name(num) {
|
|
1038
|
+
let name = '';
|
|
1039
|
+
|
|
1040
|
+
do {
|
|
1041
|
+
name = chars$1[num % chars$1.length] + name;
|
|
1042
|
+
num = ~~(num / chars$1.length) - 1;
|
|
1043
|
+
} while (num >= 0);
|
|
1044
|
+
|
|
1045
|
+
return reserved.test(name) ? `${name}0` : name;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/** @param {string} c */
|
|
1049
|
+
function escape_unsafe_char(c) {
|
|
1050
|
+
return escaped[c] || c;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/** @param {string} str */
|
|
1054
|
+
function escape_unsafe_chars(str) {
|
|
1055
|
+
return str.replace(unsafe_chars, escape_unsafe_char);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/** @param {string} key */
|
|
1059
|
+
function safe_key(key) {
|
|
1060
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key)
|
|
1061
|
+
? key
|
|
1062
|
+
: escape_unsafe_chars(JSON.stringify(key));
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/** @param {string} key */
|
|
1066
|
+
function safe_prop(key) {
|
|
1067
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key)
|
|
1068
|
+
? `.${key}`
|
|
1069
|
+
: `[${escape_unsafe_chars(JSON.stringify(key))}]`;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/** @param {any} thing */
|
|
1073
|
+
function stringify_primitive$1(thing) {
|
|
1074
|
+
if (typeof thing === 'string') return stringify_string(thing);
|
|
1075
|
+
if (thing === void 0) return 'void 0';
|
|
1076
|
+
if (thing === 0 && 1 / thing < 0) return '-0';
|
|
1077
|
+
const str = String(thing);
|
|
1078
|
+
if (typeof thing === 'number') return str.replace(/^(-)?0\./, '$1.');
|
|
1079
|
+
if (typeof thing === 'bigint') return thing + 'n';
|
|
1080
|
+
return str;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Base64 Encodes an arraybuffer
|
|
1085
|
+
* @param {ArrayBuffer} arraybuffer
|
|
1086
|
+
* @returns {string}
|
|
1087
|
+
*/
|
|
1088
|
+
function encode64(arraybuffer) {
|
|
1089
|
+
const dv = new DataView(arraybuffer);
|
|
1090
|
+
let binaryString = "";
|
|
1091
|
+
|
|
1092
|
+
for (let i = 0; i < arraybuffer.byteLength; i++) {
|
|
1093
|
+
binaryString += String.fromCharCode(dv.getUint8(i));
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
return binaryToAscii(binaryString);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
const KEY_STRING =
|
|
1100
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Substitute for btoa since it's deprecated in node.
|
|
1104
|
+
* Does not do any input validation.
|
|
1105
|
+
*
|
|
1106
|
+
* @see https://github.com/jsdom/abab/blob/master/lib/btoa.js
|
|
1107
|
+
*
|
|
1108
|
+
* @param {string} str
|
|
1109
|
+
* @returns {string}
|
|
1110
|
+
*/
|
|
1111
|
+
function binaryToAscii(str) {
|
|
1112
|
+
let out = "";
|
|
1113
|
+
for (let i = 0; i < str.length; i += 3) {
|
|
1114
|
+
/** @type {[number, number, number, number]} */
|
|
1115
|
+
const groupsOfSix = [undefined, undefined, undefined, undefined];
|
|
1116
|
+
groupsOfSix[0] = str.charCodeAt(i) >> 2;
|
|
1117
|
+
groupsOfSix[1] = (str.charCodeAt(i) & 0x03) << 4;
|
|
1118
|
+
if (str.length > i + 1) {
|
|
1119
|
+
groupsOfSix[1] |= str.charCodeAt(i + 1) >> 4;
|
|
1120
|
+
groupsOfSix[2] = (str.charCodeAt(i + 1) & 0x0f) << 2;
|
|
1121
|
+
}
|
|
1122
|
+
if (str.length > i + 2) {
|
|
1123
|
+
groupsOfSix[2] |= str.charCodeAt(i + 2) >> 6;
|
|
1124
|
+
groupsOfSix[3] = str.charCodeAt(i + 2) & 0x3f;
|
|
1125
|
+
}
|
|
1126
|
+
for (let j = 0; j < groupsOfSix.length; j++) {
|
|
1127
|
+
if (typeof groupsOfSix[j] === "undefined") {
|
|
1128
|
+
out += "=";
|
|
1129
|
+
} else {
|
|
1130
|
+
out += KEY_STRING[groupsOfSix[j]];
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return out;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
const UNDEFINED = -1;
|
|
1138
|
+
const HOLE = -2;
|
|
1139
|
+
const NAN = -3;
|
|
1140
|
+
const POSITIVE_INFINITY = -4;
|
|
1141
|
+
const NEGATIVE_INFINITY = -5;
|
|
1142
|
+
const NEGATIVE_ZERO = -6;
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
|
1146
|
+
* @param {any} value
|
|
1147
|
+
* @param {Record<string, (value: any) => any>} [reducers]
|
|
1148
|
+
*/
|
|
1149
|
+
function stringify(value, reducers) {
|
|
1150
|
+
/** @type {any[]} */
|
|
1151
|
+
const stringified = [];
|
|
1152
|
+
|
|
1153
|
+
/** @type {Map<any, number>} */
|
|
1154
|
+
const indexes = new Map();
|
|
1155
|
+
|
|
1156
|
+
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
|
|
1157
|
+
const custom = [];
|
|
1158
|
+
if (reducers) {
|
|
1159
|
+
for (const key of Object.getOwnPropertyNames(reducers)) {
|
|
1160
|
+
custom.push({ key, fn: reducers[key] });
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/** @type {string[]} */
|
|
1165
|
+
const keys = [];
|
|
1166
|
+
|
|
1167
|
+
let p = 0;
|
|
1168
|
+
|
|
1169
|
+
/** @param {any} thing */
|
|
1170
|
+
function flatten(thing) {
|
|
1171
|
+
if (typeof thing === 'function') {
|
|
1172
|
+
throw new DevalueError(`Cannot stringify a function`, keys);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (indexes.has(thing)) return indexes.get(thing);
|
|
1176
|
+
|
|
1177
|
+
if (thing === undefined) return UNDEFINED;
|
|
1178
|
+
if (Number.isNaN(thing)) return NAN;
|
|
1179
|
+
if (thing === Infinity) return POSITIVE_INFINITY;
|
|
1180
|
+
if (thing === -Infinity) return NEGATIVE_INFINITY;
|
|
1181
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;
|
|
1182
|
+
|
|
1183
|
+
const index = p++;
|
|
1184
|
+
indexes.set(thing, index);
|
|
1185
|
+
|
|
1186
|
+
for (const { key, fn } of custom) {
|
|
1187
|
+
const value = fn(thing);
|
|
1188
|
+
if (value) {
|
|
1189
|
+
stringified[index] = `["${key}",${flatten(value)}]`;
|
|
1190
|
+
return index;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
let str = '';
|
|
1195
|
+
|
|
1196
|
+
if (is_primitive(thing)) {
|
|
1197
|
+
str = stringify_primitive(thing);
|
|
1198
|
+
} else {
|
|
1199
|
+
const type = get_type(thing);
|
|
1200
|
+
|
|
1201
|
+
switch (type) {
|
|
1202
|
+
case 'Number':
|
|
1203
|
+
case 'String':
|
|
1204
|
+
case 'Boolean':
|
|
1205
|
+
str = `["Object",${stringify_primitive(thing)}]`;
|
|
1206
|
+
break;
|
|
1207
|
+
|
|
1208
|
+
case 'BigInt':
|
|
1209
|
+
str = `["BigInt",${thing}]`;
|
|
1210
|
+
break;
|
|
1211
|
+
|
|
1212
|
+
case 'Date':
|
|
1213
|
+
const valid = !isNaN(thing.getDate());
|
|
1214
|
+
str = `["Date","${valid ? thing.toISOString() : ''}"]`;
|
|
1215
|
+
break;
|
|
1216
|
+
|
|
1217
|
+
case 'RegExp':
|
|
1218
|
+
const { source, flags } = thing;
|
|
1219
|
+
str = flags
|
|
1220
|
+
? `["RegExp",${stringify_string(source)},"${flags}"]`
|
|
1221
|
+
: `["RegExp",${stringify_string(source)}]`;
|
|
1222
|
+
break;
|
|
1223
|
+
|
|
1224
|
+
case 'Array':
|
|
1225
|
+
str = '[';
|
|
1226
|
+
|
|
1227
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
1228
|
+
if (i > 0) str += ',';
|
|
1229
|
+
|
|
1230
|
+
if (i in thing) {
|
|
1231
|
+
keys.push(`[${i}]`);
|
|
1232
|
+
str += flatten(thing[i]);
|
|
1233
|
+
keys.pop();
|
|
1234
|
+
} else {
|
|
1235
|
+
str += HOLE;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
str += ']';
|
|
1240
|
+
|
|
1241
|
+
break;
|
|
1242
|
+
|
|
1243
|
+
case 'Set':
|
|
1244
|
+
str = '["Set"';
|
|
1245
|
+
|
|
1246
|
+
for (const value of thing) {
|
|
1247
|
+
str += `,${flatten(value)}`;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
str += ']';
|
|
1251
|
+
break;
|
|
1252
|
+
|
|
1253
|
+
case 'Map':
|
|
1254
|
+
str = '["Map"';
|
|
1255
|
+
|
|
1256
|
+
for (const [key, value] of thing) {
|
|
1257
|
+
keys.push(
|
|
1258
|
+
`.get(${is_primitive(key) ? stringify_primitive(key) : '...'})`
|
|
1259
|
+
);
|
|
1260
|
+
str += `,${flatten(key)},${flatten(value)}`;
|
|
1261
|
+
keys.pop();
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
str += ']';
|
|
1265
|
+
break;
|
|
1266
|
+
|
|
1267
|
+
case "Int8Array":
|
|
1268
|
+
case "Uint8Array":
|
|
1269
|
+
case "Uint8ClampedArray":
|
|
1270
|
+
case "Int16Array":
|
|
1271
|
+
case "Uint16Array":
|
|
1272
|
+
case "Int32Array":
|
|
1273
|
+
case "Uint32Array":
|
|
1274
|
+
case "Float32Array":
|
|
1275
|
+
case "Float64Array":
|
|
1276
|
+
case "BigInt64Array":
|
|
1277
|
+
case "BigUint64Array": {
|
|
1278
|
+
/** @type {import("./types.js").TypedArray} */
|
|
1279
|
+
const typedArray = thing;
|
|
1280
|
+
const base64 = encode64(typedArray.buffer);
|
|
1281
|
+
str = '["' + type + '","' + base64 + '"]';
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
case "ArrayBuffer": {
|
|
1286
|
+
/** @type {ArrayBuffer} */
|
|
1287
|
+
const arraybuffer = thing;
|
|
1288
|
+
const base64 = encode64(arraybuffer);
|
|
1289
|
+
|
|
1290
|
+
str = `["ArrayBuffer","${base64}"]`;
|
|
1291
|
+
break;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
default:
|
|
1295
|
+
if (!is_plain_object(thing)) {
|
|
1296
|
+
throw new DevalueError(
|
|
1297
|
+
`Cannot stringify arbitrary non-POJOs`,
|
|
1298
|
+
keys
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
1303
|
+
throw new DevalueError(
|
|
1304
|
+
`Cannot stringify POJOs with symbolic keys`,
|
|
1305
|
+
keys
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
if (Object.getPrototypeOf(thing) === null) {
|
|
1310
|
+
str = '["null"';
|
|
1311
|
+
for (const key in thing) {
|
|
1312
|
+
keys.push(stringify_key(key));
|
|
1313
|
+
str += `,${stringify_string(key)},${flatten(thing[key])}`;
|
|
1314
|
+
keys.pop();
|
|
1315
|
+
}
|
|
1316
|
+
str += ']';
|
|
1317
|
+
} else {
|
|
1318
|
+
str = '{';
|
|
1319
|
+
let started = false;
|
|
1320
|
+
for (const key in thing) {
|
|
1321
|
+
if (started) str += ',';
|
|
1322
|
+
started = true;
|
|
1323
|
+
keys.push(stringify_key(key));
|
|
1324
|
+
str += `${stringify_string(key)}:${flatten(thing[key])}`;
|
|
1325
|
+
keys.pop();
|
|
1326
|
+
}
|
|
1327
|
+
str += '}';
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
stringified[index] = str;
|
|
1333
|
+
return index;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
const index = flatten(value);
|
|
1337
|
+
|
|
1338
|
+
// special case — value is represented as a negative index
|
|
1339
|
+
if (index < 0) return `${index}`;
|
|
1340
|
+
|
|
1341
|
+
return `[${stringified.join(',')}]`;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* @param {any} thing
|
|
1346
|
+
* @returns {string}
|
|
1347
|
+
*/
|
|
1348
|
+
function stringify_primitive(thing) {
|
|
1349
|
+
const type = typeof thing;
|
|
1350
|
+
if (type === 'string') return stringify_string(thing);
|
|
1351
|
+
if (thing instanceof String) return stringify_string(thing.toString());
|
|
1352
|
+
if (thing === void 0) return UNDEFINED.toString();
|
|
1353
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO.toString();
|
|
1354
|
+
if (type === 'bigint') return `["BigInt","${thing}"]`;
|
|
1355
|
+
return String(thing);
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
var cookie = {};
|
|
1359
|
+
|
|
1360
|
+
/*!
|
|
1361
|
+
* cookie
|
|
1362
|
+
* Copyright(c) 2012-2014 Roman Shtylman
|
|
1363
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
1364
|
+
* MIT Licensed
|
|
1365
|
+
*/
|
|
1366
|
+
|
|
1367
|
+
var hasRequiredCookie;
|
|
1368
|
+
|
|
1369
|
+
function requireCookie () {
|
|
1370
|
+
if (hasRequiredCookie) return cookie;
|
|
1371
|
+
hasRequiredCookie = 1;
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* Module exports.
|
|
1375
|
+
* @public
|
|
1376
|
+
*/
|
|
1377
|
+
|
|
1378
|
+
cookie.parse = parse;
|
|
1379
|
+
cookie.serialize = serialize;
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Module variables.
|
|
1383
|
+
* @private
|
|
1384
|
+
*/
|
|
1385
|
+
|
|
1386
|
+
var __toString = Object.prototype.toString;
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
1390
|
+
*
|
|
1391
|
+
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
1392
|
+
* field-vchar = VCHAR / obs-text
|
|
1393
|
+
* obs-text = %x80-FF
|
|
1394
|
+
*/
|
|
1395
|
+
|
|
1396
|
+
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* Parse a cookie header.
|
|
1400
|
+
*
|
|
1401
|
+
* Parse the given cookie header string into an object
|
|
1402
|
+
* The object has the various cookies as keys(names) => values
|
|
1403
|
+
*
|
|
1404
|
+
* @param {string} str
|
|
1405
|
+
* @param {object} [options]
|
|
1406
|
+
* @return {object}
|
|
1407
|
+
* @public
|
|
1408
|
+
*/
|
|
1409
|
+
|
|
1410
|
+
function parse(str, options) {
|
|
1411
|
+
if (typeof str !== 'string') {
|
|
1412
|
+
throw new TypeError('argument str must be a string');
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
var obj = {};
|
|
1416
|
+
var opt = options || {};
|
|
1417
|
+
var dec = opt.decode || decode;
|
|
1418
|
+
|
|
1419
|
+
var index = 0;
|
|
1420
|
+
while (index < str.length) {
|
|
1421
|
+
var eqIdx = str.indexOf('=', index);
|
|
1422
|
+
|
|
1423
|
+
// no more cookie pairs
|
|
1424
|
+
if (eqIdx === -1) {
|
|
1425
|
+
break
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
var endIdx = str.indexOf(';', index);
|
|
1429
|
+
|
|
1430
|
+
if (endIdx === -1) {
|
|
1431
|
+
endIdx = str.length;
|
|
1432
|
+
} else if (endIdx < eqIdx) {
|
|
1433
|
+
// backtrack on prior semicolon
|
|
1434
|
+
index = str.lastIndexOf(';', eqIdx - 1) + 1;
|
|
1435
|
+
continue
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
var key = str.slice(index, eqIdx).trim();
|
|
1439
|
+
|
|
1440
|
+
// only assign once
|
|
1441
|
+
if (undefined === obj[key]) {
|
|
1442
|
+
var val = str.slice(eqIdx + 1, endIdx).trim();
|
|
1443
|
+
|
|
1444
|
+
// quoted values
|
|
1445
|
+
if (val.charCodeAt(0) === 0x22) {
|
|
1446
|
+
val = val.slice(1, -1);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
obj[key] = tryDecode(val, dec);
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
index = endIdx + 1;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
return obj;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* Serialize data into a cookie header.
|
|
1460
|
+
*
|
|
1461
|
+
* Serialize the a name value pair into a cookie string suitable for
|
|
1462
|
+
* http headers. An optional options object specified cookie parameters.
|
|
1463
|
+
*
|
|
1464
|
+
* serialize('foo', 'bar', { httpOnly: true })
|
|
1465
|
+
* => "foo=bar; httpOnly"
|
|
1466
|
+
*
|
|
1467
|
+
* @param {string} name
|
|
1468
|
+
* @param {string} val
|
|
1469
|
+
* @param {object} [options]
|
|
1470
|
+
* @return {string}
|
|
1471
|
+
* @public
|
|
1472
|
+
*/
|
|
1473
|
+
|
|
1474
|
+
function serialize(name, val, options) {
|
|
1475
|
+
var opt = options || {};
|
|
1476
|
+
var enc = opt.encode || encode;
|
|
1477
|
+
|
|
1478
|
+
if (typeof enc !== 'function') {
|
|
1479
|
+
throw new TypeError('option encode is invalid');
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
if (!fieldContentRegExp.test(name)) {
|
|
1483
|
+
throw new TypeError('argument name is invalid');
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
var value = enc(val);
|
|
1487
|
+
|
|
1488
|
+
if (value && !fieldContentRegExp.test(value)) {
|
|
1489
|
+
throw new TypeError('argument val is invalid');
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
var str = name + '=' + value;
|
|
1493
|
+
|
|
1494
|
+
if (null != opt.maxAge) {
|
|
1495
|
+
var maxAge = opt.maxAge - 0;
|
|
1496
|
+
|
|
1497
|
+
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
1498
|
+
throw new TypeError('option maxAge is invalid')
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
str += '; Max-Age=' + Math.floor(maxAge);
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
if (opt.domain) {
|
|
1505
|
+
if (!fieldContentRegExp.test(opt.domain)) {
|
|
1506
|
+
throw new TypeError('option domain is invalid');
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
str += '; Domain=' + opt.domain;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
if (opt.path) {
|
|
1513
|
+
if (!fieldContentRegExp.test(opt.path)) {
|
|
1514
|
+
throw new TypeError('option path is invalid');
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
str += '; Path=' + opt.path;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
if (opt.expires) {
|
|
1521
|
+
var expires = opt.expires;
|
|
1522
|
+
|
|
1523
|
+
if (!isDate(expires) || isNaN(expires.valueOf())) {
|
|
1524
|
+
throw new TypeError('option expires is invalid');
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
str += '; Expires=' + expires.toUTCString();
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
if (opt.httpOnly) {
|
|
1531
|
+
str += '; HttpOnly';
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
if (opt.secure) {
|
|
1535
|
+
str += '; Secure';
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
if (opt.partitioned) {
|
|
1539
|
+
str += '; Partitioned';
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
if (opt.priority) {
|
|
1543
|
+
var priority = typeof opt.priority === 'string'
|
|
1544
|
+
? opt.priority.toLowerCase()
|
|
1545
|
+
: opt.priority;
|
|
1546
|
+
|
|
1547
|
+
switch (priority) {
|
|
1548
|
+
case 'low':
|
|
1549
|
+
str += '; Priority=Low';
|
|
1550
|
+
break
|
|
1551
|
+
case 'medium':
|
|
1552
|
+
str += '; Priority=Medium';
|
|
1553
|
+
break
|
|
1554
|
+
case 'high':
|
|
1555
|
+
str += '; Priority=High';
|
|
1556
|
+
break
|
|
1557
|
+
default:
|
|
1558
|
+
throw new TypeError('option priority is invalid')
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
if (opt.sameSite) {
|
|
1563
|
+
var sameSite = typeof opt.sameSite === 'string'
|
|
1564
|
+
? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
1565
|
+
|
|
1566
|
+
switch (sameSite) {
|
|
1567
|
+
case true:
|
|
1568
|
+
str += '; SameSite=Strict';
|
|
1569
|
+
break;
|
|
1570
|
+
case 'lax':
|
|
1571
|
+
str += '; SameSite=Lax';
|
|
1572
|
+
break;
|
|
1573
|
+
case 'strict':
|
|
1574
|
+
str += '; SameSite=Strict';
|
|
1575
|
+
break;
|
|
1576
|
+
case 'none':
|
|
1577
|
+
str += '; SameSite=None';
|
|
1578
|
+
break;
|
|
1579
|
+
default:
|
|
1580
|
+
throw new TypeError('option sameSite is invalid');
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
return str;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* URL-decode string value. Optimized to skip native call when no %.
|
|
1589
|
+
*
|
|
1590
|
+
* @param {string} str
|
|
1591
|
+
* @returns {string}
|
|
1592
|
+
*/
|
|
1593
|
+
|
|
1594
|
+
function decode (str) {
|
|
1595
|
+
return str.indexOf('%') !== -1
|
|
1596
|
+
? decodeURIComponent(str)
|
|
1597
|
+
: str
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
/**
|
|
1601
|
+
* URL-encode value.
|
|
1602
|
+
*
|
|
1603
|
+
* @param {string} val
|
|
1604
|
+
* @returns {string}
|
|
1605
|
+
*/
|
|
1606
|
+
|
|
1607
|
+
function encode (val) {
|
|
1608
|
+
return encodeURIComponent(val)
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* Determine if value is a Date.
|
|
1613
|
+
*
|
|
1614
|
+
* @param {*} val
|
|
1615
|
+
* @private
|
|
1616
|
+
*/
|
|
1617
|
+
|
|
1618
|
+
function isDate (val) {
|
|
1619
|
+
return __toString.call(val) === '[object Date]' ||
|
|
1620
|
+
val instanceof Date
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
/**
|
|
1624
|
+
* Try decoding a string using a decoding function.
|
|
1625
|
+
*
|
|
1626
|
+
* @param {string} str
|
|
1627
|
+
* @param {function} decode
|
|
1628
|
+
* @private
|
|
1629
|
+
*/
|
|
1630
|
+
|
|
1631
|
+
function tryDecode(str, decode) {
|
|
1632
|
+
try {
|
|
1633
|
+
return decode(str);
|
|
1634
|
+
} catch (e) {
|
|
1635
|
+
return str;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
return cookie;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
var cookieExports = requireCookie();
|
|
1642
|
+
|
|
1643
|
+
var setCookie = {exports: {}};
|
|
1644
|
+
|
|
1645
|
+
var hasRequiredSetCookie;
|
|
1646
|
+
|
|
1647
|
+
function requireSetCookie () {
|
|
1648
|
+
if (hasRequiredSetCookie) return setCookie.exports;
|
|
1649
|
+
hasRequiredSetCookie = 1;
|
|
1650
|
+
|
|
1651
|
+
var defaultParseOptions = {
|
|
1652
|
+
decodeValues: true,
|
|
1653
|
+
map: false,
|
|
1654
|
+
silent: false,
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
function isNonEmptyString(str) {
|
|
1658
|
+
return typeof str === "string" && !!str.trim();
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
function parseString(setCookieValue, options) {
|
|
1662
|
+
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
1663
|
+
|
|
1664
|
+
var nameValuePairStr = parts.shift();
|
|
1665
|
+
var parsed = parseNameValuePair(nameValuePairStr);
|
|
1666
|
+
var name = parsed.name;
|
|
1667
|
+
var value = parsed.value;
|
|
1668
|
+
|
|
1669
|
+
options = options
|
|
1670
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
1671
|
+
: defaultParseOptions;
|
|
1672
|
+
|
|
1673
|
+
try {
|
|
1674
|
+
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
1675
|
+
} catch (e) {
|
|
1676
|
+
console.error(
|
|
1677
|
+
"set-cookie-parser encountered an error while decoding a cookie with value '" +
|
|
1678
|
+
value +
|
|
1679
|
+
"'. Set options.decodeValues to false to disable this feature.",
|
|
1680
|
+
e
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
var cookie = {
|
|
1685
|
+
name: name,
|
|
1686
|
+
value: value,
|
|
1687
|
+
};
|
|
1688
|
+
|
|
1689
|
+
parts.forEach(function (part) {
|
|
1690
|
+
var sides = part.split("=");
|
|
1691
|
+
var key = sides.shift().trimLeft().toLowerCase();
|
|
1692
|
+
var value = sides.join("=");
|
|
1693
|
+
if (key === "expires") {
|
|
1694
|
+
cookie.expires = new Date(value);
|
|
1695
|
+
} else if (key === "max-age") {
|
|
1696
|
+
cookie.maxAge = parseInt(value, 10);
|
|
1697
|
+
} else if (key === "secure") {
|
|
1698
|
+
cookie.secure = true;
|
|
1699
|
+
} else if (key === "httponly") {
|
|
1700
|
+
cookie.httpOnly = true;
|
|
1701
|
+
} else if (key === "samesite") {
|
|
1702
|
+
cookie.sameSite = value;
|
|
1703
|
+
} else if (key === "partitioned") {
|
|
1704
|
+
cookie.partitioned = true;
|
|
1705
|
+
} else {
|
|
1706
|
+
cookie[key] = value;
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
|
|
1710
|
+
return cookie;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
function parseNameValuePair(nameValuePairStr) {
|
|
1714
|
+
// Parses name-value-pair according to rfc6265bis draft
|
|
1715
|
+
|
|
1716
|
+
var name = "";
|
|
1717
|
+
var value = "";
|
|
1718
|
+
var nameValueArr = nameValuePairStr.split("=");
|
|
1719
|
+
if (nameValueArr.length > 1) {
|
|
1720
|
+
name = nameValueArr.shift();
|
|
1721
|
+
value = nameValueArr.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
1722
|
+
} else {
|
|
1723
|
+
value = nameValuePairStr;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
return { name: name, value: value };
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
function parse(input, options) {
|
|
1730
|
+
options = options
|
|
1731
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
1732
|
+
: defaultParseOptions;
|
|
1733
|
+
|
|
1734
|
+
if (!input) {
|
|
1735
|
+
if (!options.map) {
|
|
1736
|
+
return [];
|
|
1737
|
+
} else {
|
|
1738
|
+
return {};
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
if (input.headers) {
|
|
1743
|
+
if (typeof input.headers.getSetCookie === "function") {
|
|
1744
|
+
// for fetch responses - they combine headers of the same type in the headers array,
|
|
1745
|
+
// but getSetCookie returns an uncombined array
|
|
1746
|
+
input = input.headers.getSetCookie();
|
|
1747
|
+
} else if (input.headers["set-cookie"]) {
|
|
1748
|
+
// fast-path for node.js (which automatically normalizes header names to lower-case
|
|
1749
|
+
input = input.headers["set-cookie"];
|
|
1750
|
+
} else {
|
|
1751
|
+
// slow-path for other environments - see #25
|
|
1752
|
+
var sch =
|
|
1753
|
+
input.headers[
|
|
1754
|
+
Object.keys(input.headers).find(function (key) {
|
|
1755
|
+
return key.toLowerCase() === "set-cookie";
|
|
1756
|
+
})
|
|
1757
|
+
];
|
|
1758
|
+
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
1759
|
+
if (!sch && input.headers.cookie && !options.silent) {
|
|
1760
|
+
console.warn(
|
|
1761
|
+
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
1762
|
+
);
|
|
1763
|
+
}
|
|
1764
|
+
input = sch;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
if (!Array.isArray(input)) {
|
|
1768
|
+
input = [input];
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
if (!options.map) {
|
|
1772
|
+
return input.filter(isNonEmptyString).map(function (str) {
|
|
1773
|
+
return parseString(str, options);
|
|
1774
|
+
});
|
|
1775
|
+
} else {
|
|
1776
|
+
var cookies = {};
|
|
1777
|
+
return input.filter(isNonEmptyString).reduce(function (cookies, str) {
|
|
1778
|
+
var cookie = parseString(str, options);
|
|
1779
|
+
cookies[cookie.name] = cookie;
|
|
1780
|
+
return cookies;
|
|
1781
|
+
}, cookies);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
/*
|
|
1786
|
+
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
1787
|
+
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
1788
|
+
|
|
1789
|
+
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
1790
|
+
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
1791
|
+
React Native's fetch does this for *every* header, including set-cookie.
|
|
1792
|
+
|
|
1793
|
+
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
1794
|
+
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
1795
|
+
*/
|
|
1796
|
+
function splitCookiesString(cookiesString) {
|
|
1797
|
+
if (Array.isArray(cookiesString)) {
|
|
1798
|
+
return cookiesString;
|
|
1799
|
+
}
|
|
1800
|
+
if (typeof cookiesString !== "string") {
|
|
1801
|
+
return [];
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
var cookiesStrings = [];
|
|
1805
|
+
var pos = 0;
|
|
1806
|
+
var start;
|
|
1807
|
+
var ch;
|
|
1808
|
+
var lastComma;
|
|
1809
|
+
var nextStart;
|
|
1810
|
+
var cookiesSeparatorFound;
|
|
1811
|
+
|
|
1812
|
+
function skipWhitespace() {
|
|
1813
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
1814
|
+
pos += 1;
|
|
1815
|
+
}
|
|
1816
|
+
return pos < cookiesString.length;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
function notSpecialChar() {
|
|
1820
|
+
ch = cookiesString.charAt(pos);
|
|
1821
|
+
|
|
1822
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
while (pos < cookiesString.length) {
|
|
1826
|
+
start = pos;
|
|
1827
|
+
cookiesSeparatorFound = false;
|
|
1828
|
+
|
|
1829
|
+
while (skipWhitespace()) {
|
|
1830
|
+
ch = cookiesString.charAt(pos);
|
|
1831
|
+
if (ch === ",") {
|
|
1832
|
+
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
1833
|
+
lastComma = pos;
|
|
1834
|
+
pos += 1;
|
|
1835
|
+
|
|
1836
|
+
skipWhitespace();
|
|
1837
|
+
nextStart = pos;
|
|
1838
|
+
|
|
1839
|
+
while (pos < cookiesString.length && notSpecialChar()) {
|
|
1840
|
+
pos += 1;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// currently special character
|
|
1844
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
1845
|
+
// we found cookies separator
|
|
1846
|
+
cookiesSeparatorFound = true;
|
|
1847
|
+
// pos is inside the next cookie, so back up and return it.
|
|
1848
|
+
pos = nextStart;
|
|
1849
|
+
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
1850
|
+
start = pos;
|
|
1851
|
+
} else {
|
|
1852
|
+
// in param ',' or param separator ';',
|
|
1853
|
+
// we continue from that comma
|
|
1854
|
+
pos = lastComma + 1;
|
|
1855
|
+
}
|
|
1856
|
+
} else {
|
|
1857
|
+
pos += 1;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
1862
|
+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
return cookiesStrings;
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
setCookie.exports = parse;
|
|
1870
|
+
setCookie.exports.parse = parse;
|
|
1871
|
+
setCookie.exports.parseString = parseString;
|
|
1872
|
+
setCookie.exports.splitCookiesString = splitCookiesString;
|
|
1873
|
+
return setCookie.exports;
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
var setCookieExports = /*@__PURE__*/ requireSetCookie();
|
|
1877
|
+
|
|
1878
|
+
const SVELTE_KIT_ASSETS = "/_svelte_kit_assets";
|
|
1879
|
+
const ENDPOINT_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
1880
|
+
const PAGE_METHODS = ["GET", "POST", "HEAD"];
|
|
1881
|
+
function negotiate(accept, types) {
|
|
1882
|
+
const parts = [];
|
|
1883
|
+
accept.split(",").forEach((str, i) => {
|
|
1884
|
+
const match = /([^/ \t]+)\/([^; \t]+)[ \t]*(?:;[ \t]*q=([0-9.]+))?/.exec(str);
|
|
1885
|
+
if (match) {
|
|
1886
|
+
const [, type, subtype, q = "1"] = match;
|
|
1887
|
+
parts.push({ type, subtype, q: +q, i });
|
|
1888
|
+
}
|
|
1889
|
+
});
|
|
1890
|
+
parts.sort((a, b) => {
|
|
1891
|
+
if (a.q !== b.q) {
|
|
1892
|
+
return b.q - a.q;
|
|
1893
|
+
}
|
|
1894
|
+
if (a.subtype === "*" !== (b.subtype === "*")) {
|
|
1895
|
+
return a.subtype === "*" ? 1 : -1;
|
|
1896
|
+
}
|
|
1897
|
+
if (a.type === "*" !== (b.type === "*")) {
|
|
1898
|
+
return a.type === "*" ? 1 : -1;
|
|
1899
|
+
}
|
|
1900
|
+
return a.i - b.i;
|
|
1901
|
+
});
|
|
1902
|
+
let accepted;
|
|
1903
|
+
let min_priority = Infinity;
|
|
1904
|
+
for (const mimetype of types) {
|
|
1905
|
+
const [type, subtype] = mimetype.split("/");
|
|
1906
|
+
const priority = parts.findIndex(
|
|
1907
|
+
(part) => (part.type === type || part.type === "*") && (part.subtype === subtype || part.subtype === "*")
|
|
1908
|
+
);
|
|
1909
|
+
if (priority !== -1 && priority < min_priority) {
|
|
1910
|
+
accepted = mimetype;
|
|
1911
|
+
min_priority = priority;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
return accepted;
|
|
1915
|
+
}
|
|
1916
|
+
function is_content_type(request, ...types) {
|
|
1917
|
+
const type = request.headers.get("content-type")?.split(";", 1)[0].trim() ?? "";
|
|
1918
|
+
return types.includes(type.toLowerCase());
|
|
1919
|
+
}
|
|
1920
|
+
function is_form_content_type(request) {
|
|
1921
|
+
return is_content_type(
|
|
1922
|
+
request,
|
|
1923
|
+
"application/x-www-form-urlencoded",
|
|
1924
|
+
"multipart/form-data",
|
|
1925
|
+
"text/plain"
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
class HttpError {
|
|
1929
|
+
/**
|
|
1930
|
+
* @param {number} status
|
|
1931
|
+
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
|
|
1932
|
+
*/
|
|
1933
|
+
constructor(status, body2) {
|
|
1934
|
+
this.status = status;
|
|
1935
|
+
if (typeof body2 === "string") {
|
|
1936
|
+
this.body = { message: body2 };
|
|
1937
|
+
} else if (body2) {
|
|
1938
|
+
this.body = body2;
|
|
1939
|
+
} else {
|
|
1940
|
+
this.body = { message: `Error: ${status}` };
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
toString() {
|
|
1944
|
+
return JSON.stringify(this.body);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
class Redirect {
|
|
1948
|
+
/**
|
|
1949
|
+
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
|
|
1950
|
+
* @param {string} location
|
|
1951
|
+
*/
|
|
1952
|
+
constructor(status, location) {
|
|
1953
|
+
this.status = status;
|
|
1954
|
+
this.location = location;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
class SvelteKitError extends Error {
|
|
1958
|
+
/**
|
|
1959
|
+
* @param {number} status
|
|
1960
|
+
* @param {string} text
|
|
1961
|
+
* @param {string} message
|
|
1962
|
+
*/
|
|
1963
|
+
constructor(status, text2, message) {
|
|
1964
|
+
super(message);
|
|
1965
|
+
this.status = status;
|
|
1966
|
+
this.text = text2;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
class ActionFailure {
|
|
1970
|
+
/**
|
|
1971
|
+
* @param {number} status
|
|
1972
|
+
* @param {T} data
|
|
1973
|
+
*/
|
|
1974
|
+
constructor(status, data) {
|
|
1975
|
+
this.status = status;
|
|
1976
|
+
this.data = data;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
function json(data, init2) {
|
|
1980
|
+
const body2 = JSON.stringify(data);
|
|
1981
|
+
const headers2 = new Headers(init2?.headers);
|
|
1982
|
+
if (!headers2.has("content-length")) {
|
|
1983
|
+
headers2.set("content-length", encoder$3.encode(body2).byteLength.toString());
|
|
1984
|
+
}
|
|
1985
|
+
if (!headers2.has("content-type")) {
|
|
1986
|
+
headers2.set("content-type", "application/json");
|
|
1987
|
+
}
|
|
1988
|
+
return new Response(body2, {
|
|
1989
|
+
...init2,
|
|
1990
|
+
headers: headers2
|
|
1991
|
+
});
|
|
1992
|
+
}
|
|
1993
|
+
const encoder$3 = new TextEncoder();
|
|
1994
|
+
function text(body2, init2) {
|
|
1995
|
+
const headers2 = new Headers(init2?.headers);
|
|
1996
|
+
if (!headers2.has("content-length")) {
|
|
1997
|
+
const encoded = encoder$3.encode(body2);
|
|
1998
|
+
headers2.set("content-length", encoded.byteLength.toString());
|
|
1999
|
+
return new Response(encoded, {
|
|
2000
|
+
...init2,
|
|
2001
|
+
headers: headers2
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
return new Response(body2, {
|
|
2005
|
+
...init2,
|
|
2006
|
+
headers: headers2
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
function coalesce_to_error(err) {
|
|
2010
|
+
return err instanceof Error || err && /** @type {any} */
|
|
2011
|
+
err.name && /** @type {any} */
|
|
2012
|
+
err.message ? (
|
|
2013
|
+
/** @type {Error} */
|
|
2014
|
+
err
|
|
2015
|
+
) : new Error(JSON.stringify(err));
|
|
2016
|
+
}
|
|
2017
|
+
function normalize_error(error) {
|
|
2018
|
+
return (
|
|
2019
|
+
/** @type {import('../runtime/control.js').Redirect | HttpError | SvelteKitError | Error} */
|
|
2020
|
+
error
|
|
2021
|
+
);
|
|
2022
|
+
}
|
|
2023
|
+
function get_status(error) {
|
|
2024
|
+
return error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
2025
|
+
}
|
|
2026
|
+
function get_message(error) {
|
|
2027
|
+
return error instanceof SvelteKitError ? error.text : "Internal Error";
|
|
2028
|
+
}
|
|
2029
|
+
const escape_html_attr_dict = {
|
|
2030
|
+
"&": "&",
|
|
2031
|
+
'"': """
|
|
2032
|
+
// Svelte also escapes < because the escape function could be called inside a `noscript` there
|
|
2033
|
+
// https://github.com/sveltejs/svelte/security/advisories/GHSA-8266-84wp-wv5c
|
|
2034
|
+
// However, that doesn't apply in SvelteKit
|
|
2035
|
+
};
|
|
2036
|
+
const escape_html_dict = {
|
|
2037
|
+
"&": "&",
|
|
2038
|
+
"<": "<"
|
|
2039
|
+
};
|
|
2040
|
+
const surrogates = (
|
|
2041
|
+
// high surrogate without paired low surrogate
|
|
2042
|
+
"[\\ud800-\\udbff](?![\\udc00-\\udfff])|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\udc00-\\udfff]"
|
|
2043
|
+
);
|
|
2044
|
+
const escape_html_attr_regex = new RegExp(
|
|
2045
|
+
`[${Object.keys(escape_html_attr_dict).join("")}]|` + surrogates,
|
|
2046
|
+
"g"
|
|
2047
|
+
);
|
|
2048
|
+
const escape_html_regex = new RegExp(
|
|
2049
|
+
`[${Object.keys(escape_html_dict).join("")}]|` + surrogates,
|
|
2050
|
+
"g"
|
|
2051
|
+
);
|
|
2052
|
+
function escape_html(str, is_attr) {
|
|
2053
|
+
const dict = is_attr ? escape_html_attr_dict : escape_html_dict;
|
|
2054
|
+
const escaped_str = str.replace(is_attr ? escape_html_attr_regex : escape_html_regex, (match) => {
|
|
2055
|
+
if (match.length === 2) {
|
|
2056
|
+
return match;
|
|
2057
|
+
}
|
|
2058
|
+
return dict[match] ?? `&#${match.charCodeAt(0)};`;
|
|
2059
|
+
});
|
|
2060
|
+
return escaped_str;
|
|
2061
|
+
}
|
|
2062
|
+
function method_not_allowed(mod, method) {
|
|
2063
|
+
return text(`${method} method not allowed`, {
|
|
2064
|
+
status: 405,
|
|
2065
|
+
headers: {
|
|
2066
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
2067
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
2068
|
+
allow: allowed_methods(mod).join(", ")
|
|
2069
|
+
}
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
function allowed_methods(mod) {
|
|
2073
|
+
const allowed = ENDPOINT_METHODS.filter((method) => method in mod);
|
|
2074
|
+
if ("GET" in mod || "HEAD" in mod) allowed.push("HEAD");
|
|
2075
|
+
return allowed;
|
|
2076
|
+
}
|
|
2077
|
+
function static_error_page(options2, status, message) {
|
|
2078
|
+
let page = options2.templates.error({ status, message: escape_html(message) });
|
|
2079
|
+
return text(page, {
|
|
2080
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
2081
|
+
status
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
async function handle_fatal_error(event, options2, error) {
|
|
2085
|
+
error = error instanceof HttpError ? error : coalesce_to_error(error);
|
|
2086
|
+
const status = get_status(error);
|
|
2087
|
+
const body2 = await handle_error_and_jsonify(event, options2, error);
|
|
2088
|
+
const type = negotiate(event.request.headers.get("accept") || "text/html", [
|
|
2089
|
+
"application/json",
|
|
2090
|
+
"text/html"
|
|
2091
|
+
]);
|
|
2092
|
+
if (event.isDataRequest || type === "application/json") {
|
|
2093
|
+
return json(body2, {
|
|
2094
|
+
status
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
return static_error_page(options2, status, body2.message);
|
|
2098
|
+
}
|
|
2099
|
+
async function handle_error_and_jsonify(event, options2, error) {
|
|
2100
|
+
if (error instanceof HttpError) {
|
|
2101
|
+
return error.body;
|
|
2102
|
+
}
|
|
2103
|
+
const status = get_status(error);
|
|
2104
|
+
const message = get_message(error);
|
|
2105
|
+
return await options2.hooks.handleError({ error, event, status, message }) ?? { message };
|
|
2106
|
+
}
|
|
2107
|
+
function redirect_response(status, location) {
|
|
2108
|
+
const response = new Response(void 0, {
|
|
2109
|
+
status,
|
|
2110
|
+
headers: { location }
|
|
2111
|
+
});
|
|
2112
|
+
return response;
|
|
2113
|
+
}
|
|
2114
|
+
function clarify_devalue_error(event, error) {
|
|
2115
|
+
if (error.path) {
|
|
2116
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not serializable: ${error.message} (data${error.path})`;
|
|
2117
|
+
}
|
|
2118
|
+
if (error.path === "") {
|
|
2119
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not a plain object`;
|
|
2120
|
+
}
|
|
2121
|
+
return error.message;
|
|
2122
|
+
}
|
|
2123
|
+
function stringify_uses(node) {
|
|
2124
|
+
const uses = [];
|
|
2125
|
+
if (node.uses && node.uses.dependencies.size > 0) {
|
|
2126
|
+
uses.push(`"dependencies":${JSON.stringify(Array.from(node.uses.dependencies))}`);
|
|
2127
|
+
}
|
|
2128
|
+
if (node.uses && node.uses.search_params.size > 0) {
|
|
2129
|
+
uses.push(`"search_params":${JSON.stringify(Array.from(node.uses.search_params))}`);
|
|
2130
|
+
}
|
|
2131
|
+
if (node.uses && node.uses.params.size > 0) {
|
|
2132
|
+
uses.push(`"params":${JSON.stringify(Array.from(node.uses.params))}`);
|
|
2133
|
+
}
|
|
2134
|
+
if (node.uses?.parent) uses.push('"parent":1');
|
|
2135
|
+
if (node.uses?.route) uses.push('"route":1');
|
|
2136
|
+
if (node.uses?.url) uses.push('"url":1');
|
|
2137
|
+
return `"uses":{${uses.join(",")}}`;
|
|
2138
|
+
}
|
|
2139
|
+
async function render_endpoint(event, mod, state) {
|
|
2140
|
+
const method = (
|
|
2141
|
+
/** @type {import('types').HttpMethod} */
|
|
2142
|
+
event.request.method
|
|
2143
|
+
);
|
|
2144
|
+
let handler = mod[method] || mod.fallback;
|
|
2145
|
+
if (method === "HEAD" && mod.GET && !mod.HEAD) {
|
|
2146
|
+
handler = mod.GET;
|
|
2147
|
+
}
|
|
2148
|
+
if (!handler) {
|
|
2149
|
+
return method_not_allowed(mod, method);
|
|
2150
|
+
}
|
|
2151
|
+
const prerender = mod.prerender ?? state.prerender_default;
|
|
2152
|
+
if (prerender && (mod.POST || mod.PATCH || mod.PUT || mod.DELETE)) {
|
|
2153
|
+
throw new Error("Cannot prerender endpoints that have mutative methods");
|
|
2154
|
+
}
|
|
2155
|
+
if (state.prerendering && !prerender) {
|
|
2156
|
+
if (state.depth > 0) {
|
|
2157
|
+
throw new Error(`${event.route.id} is not prerenderable`);
|
|
2158
|
+
} else {
|
|
2159
|
+
return new Response(void 0, { status: 204 });
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
try {
|
|
2163
|
+
let response = await handler(
|
|
2164
|
+
/** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */
|
|
2165
|
+
event
|
|
2166
|
+
);
|
|
2167
|
+
if (!(response instanceof Response)) {
|
|
2168
|
+
throw new Error(
|
|
2169
|
+
`Invalid response from route ${event.url.pathname}: handler should return a Response object`
|
|
2170
|
+
);
|
|
2171
|
+
}
|
|
2172
|
+
if (state.prerendering) {
|
|
2173
|
+
response = new Response(response.body, {
|
|
2174
|
+
status: response.status,
|
|
2175
|
+
statusText: response.statusText,
|
|
2176
|
+
headers: new Headers(response.headers)
|
|
2177
|
+
});
|
|
2178
|
+
response.headers.set("x-sveltekit-prerender", String(prerender));
|
|
2179
|
+
}
|
|
2180
|
+
return response;
|
|
2181
|
+
} catch (e) {
|
|
2182
|
+
if (e instanceof Redirect) {
|
|
2183
|
+
return new Response(void 0, {
|
|
2184
|
+
status: e.status,
|
|
2185
|
+
headers: { location: e.location }
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
throw e;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
function is_endpoint_request(event) {
|
|
2192
|
+
const { method, headers: headers2 } = event.request;
|
|
2193
|
+
if (ENDPOINT_METHODS.includes(method) && !PAGE_METHODS.includes(method)) {
|
|
2194
|
+
return true;
|
|
2195
|
+
}
|
|
2196
|
+
if (method === "POST" && headers2.get("x-sveltekit-action") === "true") return false;
|
|
2197
|
+
const accept = event.request.headers.get("accept") ?? "*/*";
|
|
2198
|
+
return negotiate(accept, ["*", "text/html"]) !== "text/html";
|
|
2199
|
+
}
|
|
2200
|
+
function compact(arr) {
|
|
2201
|
+
return arr.filter(
|
|
2202
|
+
/** @returns {val is NonNullable<T>} */
|
|
2203
|
+
(val) => val != null
|
|
2204
|
+
);
|
|
2205
|
+
}
|
|
2206
|
+
function is_action_json_request(event) {
|
|
2207
|
+
const accept = negotiate(event.request.headers.get("accept") ?? "*/*", [
|
|
2208
|
+
"application/json",
|
|
2209
|
+
"text/html"
|
|
2210
|
+
]);
|
|
2211
|
+
return accept === "application/json" && event.request.method === "POST";
|
|
2212
|
+
}
|
|
2213
|
+
async function handle_action_json_request(event, options2, server) {
|
|
2214
|
+
const actions = server?.actions;
|
|
2215
|
+
if (!actions) {
|
|
2216
|
+
const no_actions_error = new SvelteKitError(
|
|
2217
|
+
405,
|
|
2218
|
+
"Method Not Allowed",
|
|
2219
|
+
`POST method not allowed. No form actions exist for ${"this page"}`
|
|
2220
|
+
);
|
|
2221
|
+
return action_json(
|
|
2222
|
+
{
|
|
2223
|
+
type: "error",
|
|
2224
|
+
error: await handle_error_and_jsonify(event, options2, no_actions_error)
|
|
2225
|
+
},
|
|
2226
|
+
{
|
|
2227
|
+
status: no_actions_error.status,
|
|
2228
|
+
headers: {
|
|
2229
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
2230
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
2231
|
+
allow: "GET"
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
);
|
|
2235
|
+
}
|
|
2236
|
+
check_named_default_separate(actions);
|
|
2237
|
+
try {
|
|
2238
|
+
const data = await call_action(event, actions);
|
|
2239
|
+
if (false) ;
|
|
2240
|
+
if (data instanceof ActionFailure) {
|
|
2241
|
+
return action_json({
|
|
2242
|
+
type: "failure",
|
|
2243
|
+
status: data.status,
|
|
2244
|
+
// @ts-expect-error we assign a string to what is supposed to be an object. That's ok
|
|
2245
|
+
// because we don't use the object outside, and this way we have better code navigation
|
|
2246
|
+
// through knowing where the related interface is used.
|
|
2247
|
+
data: stringify_action_response(
|
|
2248
|
+
data.data,
|
|
2249
|
+
/** @type {string} */
|
|
2250
|
+
event.route.id,
|
|
2251
|
+
options2.hooks.transport
|
|
2252
|
+
)
|
|
2253
|
+
});
|
|
2254
|
+
} else {
|
|
2255
|
+
return action_json({
|
|
2256
|
+
type: "success",
|
|
2257
|
+
status: data ? 200 : 204,
|
|
2258
|
+
// @ts-expect-error see comment above
|
|
2259
|
+
data: stringify_action_response(
|
|
2260
|
+
data,
|
|
2261
|
+
/** @type {string} */
|
|
2262
|
+
event.route.id,
|
|
2263
|
+
options2.hooks.transport
|
|
2264
|
+
)
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2267
|
+
} catch (e) {
|
|
2268
|
+
const err = normalize_error(e);
|
|
2269
|
+
if (err instanceof Redirect) {
|
|
2270
|
+
return action_json_redirect(err);
|
|
2271
|
+
}
|
|
2272
|
+
return action_json(
|
|
2273
|
+
{
|
|
2274
|
+
type: "error",
|
|
2275
|
+
error: await handle_error_and_jsonify(event, options2, check_incorrect_fail_use(err))
|
|
2276
|
+
},
|
|
2277
|
+
{
|
|
2278
|
+
status: get_status(err)
|
|
2279
|
+
}
|
|
2280
|
+
);
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
function check_incorrect_fail_use(error) {
|
|
2284
|
+
return error instanceof ActionFailure ? new Error('Cannot "throw fail()". Use "return fail()"') : error;
|
|
2285
|
+
}
|
|
2286
|
+
function action_json_redirect(redirect) {
|
|
2287
|
+
return action_json({
|
|
2288
|
+
type: "redirect",
|
|
2289
|
+
status: redirect.status,
|
|
2290
|
+
location: redirect.location
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
function action_json(data, init2) {
|
|
2294
|
+
return json(data, init2);
|
|
2295
|
+
}
|
|
2296
|
+
function is_action_request(event) {
|
|
2297
|
+
return event.request.method === "POST";
|
|
2298
|
+
}
|
|
2299
|
+
async function handle_action_request(event, server) {
|
|
2300
|
+
const actions = server?.actions;
|
|
2301
|
+
if (!actions) {
|
|
2302
|
+
event.setHeaders({
|
|
2303
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
2304
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
2305
|
+
allow: "GET"
|
|
2306
|
+
});
|
|
2307
|
+
return {
|
|
2308
|
+
type: "error",
|
|
2309
|
+
error: new SvelteKitError(
|
|
2310
|
+
405,
|
|
2311
|
+
"Method Not Allowed",
|
|
2312
|
+
`POST method not allowed. No form actions exist for ${"this page"}`
|
|
2313
|
+
)
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
check_named_default_separate(actions);
|
|
2317
|
+
try {
|
|
2318
|
+
const data = await call_action(event, actions);
|
|
2319
|
+
if (false) ;
|
|
2320
|
+
if (data instanceof ActionFailure) {
|
|
2321
|
+
return {
|
|
2322
|
+
type: "failure",
|
|
2323
|
+
status: data.status,
|
|
2324
|
+
data: data.data
|
|
2325
|
+
};
|
|
2326
|
+
} else {
|
|
2327
|
+
return {
|
|
2328
|
+
type: "success",
|
|
2329
|
+
status: 200,
|
|
2330
|
+
// @ts-expect-error this will be removed upon serialization, so `undefined` is the same as omission
|
|
2331
|
+
data
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
} catch (e) {
|
|
2335
|
+
const err = normalize_error(e);
|
|
2336
|
+
if (err instanceof Redirect) {
|
|
2337
|
+
return {
|
|
2338
|
+
type: "redirect",
|
|
2339
|
+
status: err.status,
|
|
2340
|
+
location: err.location
|
|
2341
|
+
};
|
|
2342
|
+
}
|
|
2343
|
+
return {
|
|
2344
|
+
type: "error",
|
|
2345
|
+
error: check_incorrect_fail_use(err)
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
function check_named_default_separate(actions) {
|
|
2350
|
+
if (actions.default && Object.keys(actions).length > 1) {
|
|
2351
|
+
throw new Error(
|
|
2352
|
+
"When using named actions, the default action cannot be used. See the docs for more info: https://svelte.dev/docs/kit/form-actions#named-actions"
|
|
2353
|
+
);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
async function call_action(event, actions) {
|
|
2357
|
+
const url = new URL(event.request.url);
|
|
2358
|
+
let name = "default";
|
|
2359
|
+
for (const param of url.searchParams) {
|
|
2360
|
+
if (param[0].startsWith("/")) {
|
|
2361
|
+
name = param[0].slice(1);
|
|
2362
|
+
if (name === "default") {
|
|
2363
|
+
throw new Error('Cannot use reserved action name "default"');
|
|
2364
|
+
}
|
|
2365
|
+
break;
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
const action = actions[name];
|
|
2369
|
+
if (!action) {
|
|
2370
|
+
throw new SvelteKitError(404, "Not Found", `No action with name '${name}' found`);
|
|
2371
|
+
}
|
|
2372
|
+
if (!is_form_content_type(event.request)) {
|
|
2373
|
+
throw new SvelteKitError(
|
|
2374
|
+
415,
|
|
2375
|
+
"Unsupported Media Type",
|
|
2376
|
+
`Form actions expect form-encoded data — received ${event.request.headers.get(
|
|
2377
|
+
"content-type"
|
|
2378
|
+
)}`
|
|
2379
|
+
);
|
|
2380
|
+
}
|
|
2381
|
+
return action(event);
|
|
2382
|
+
}
|
|
2383
|
+
function uneval_action_response(data, route_id, transport) {
|
|
2384
|
+
const replacer = (thing) => {
|
|
2385
|
+
for (const key2 in transport) {
|
|
2386
|
+
const encoded = transport[key2].encode(thing);
|
|
2387
|
+
if (encoded) {
|
|
2388
|
+
return `app.decode('${key2}', ${uneval(encoded, replacer)})`;
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
return try_serialize(data, (value) => uneval(value, replacer), route_id);
|
|
2393
|
+
}
|
|
2394
|
+
function stringify_action_response(data, route_id, transport) {
|
|
2395
|
+
const encoders = Object.fromEntries(
|
|
2396
|
+
Object.entries(transport).map(([key2, value]) => [key2, value.encode])
|
|
2397
|
+
);
|
|
2398
|
+
return try_serialize(data, (value) => stringify(value, encoders), route_id);
|
|
2399
|
+
}
|
|
2400
|
+
function try_serialize(data, fn, route_id) {
|
|
2401
|
+
try {
|
|
2402
|
+
return fn(data);
|
|
2403
|
+
} catch (e) {
|
|
2404
|
+
const error = (
|
|
2405
|
+
/** @type {any} */
|
|
2406
|
+
e
|
|
2407
|
+
);
|
|
2408
|
+
if (data instanceof Response) {
|
|
2409
|
+
throw new Error(
|
|
2410
|
+
`Data returned from action inside ${route_id} is not serializable. Form actions need to return plain objects or fail(). E.g. return { success: true } or return fail(400, { message: "invalid" });`
|
|
2411
|
+
);
|
|
2412
|
+
}
|
|
2413
|
+
if ("path" in error) {
|
|
2414
|
+
let message = `Data returned from action inside ${route_id} is not serializable: ${error.message}`;
|
|
2415
|
+
if (error.path !== "") message += ` (data.${error.path})`;
|
|
2416
|
+
throw new Error(message);
|
|
2417
|
+
}
|
|
2418
|
+
throw error;
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
const INVALIDATED_PARAM = "x-sveltekit-invalidated";
|
|
2422
|
+
const TRAILING_SLASH_PARAM = "x-sveltekit-trailing-slash";
|
|
2423
|
+
function b64_encode(buffer) {
|
|
2424
|
+
if (globalThis.Buffer) {
|
|
2425
|
+
return Buffer.from(buffer).toString("base64");
|
|
2426
|
+
}
|
|
2427
|
+
const little_endian = new Uint8Array(new Uint16Array([1]).buffer)[0] > 0;
|
|
2428
|
+
return btoa(
|
|
2429
|
+
new TextDecoder(little_endian ? "utf-16le" : "utf-16be").decode(
|
|
2430
|
+
new Uint16Array(new Uint8Array(buffer))
|
|
2431
|
+
)
|
|
2432
|
+
);
|
|
2433
|
+
}
|
|
2434
|
+
async function load_server_data({ event, state, node, parent }) {
|
|
2435
|
+
if (!node?.server) return null;
|
|
2436
|
+
let is_tracking = true;
|
|
2437
|
+
const uses = {
|
|
2438
|
+
dependencies: /* @__PURE__ */ new Set(),
|
|
2439
|
+
params: /* @__PURE__ */ new Set(),
|
|
2440
|
+
parent: false,
|
|
2441
|
+
route: false,
|
|
2442
|
+
url: false,
|
|
2443
|
+
search_params: /* @__PURE__ */ new Set()
|
|
2444
|
+
};
|
|
2445
|
+
const url = make_trackable(
|
|
2446
|
+
event.url,
|
|
2447
|
+
() => {
|
|
2448
|
+
if (is_tracking) {
|
|
2449
|
+
uses.url = true;
|
|
2450
|
+
}
|
|
2451
|
+
},
|
|
2452
|
+
(param) => {
|
|
2453
|
+
if (is_tracking) {
|
|
2454
|
+
uses.search_params.add(param);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
);
|
|
2458
|
+
if (state.prerendering) {
|
|
2459
|
+
disable_search(url);
|
|
2460
|
+
}
|
|
2461
|
+
const result = await node.server.load?.call(null, {
|
|
2462
|
+
...event,
|
|
2463
|
+
fetch: (info, init2) => {
|
|
2464
|
+
new URL(info instanceof Request ? info.url : info, event.url);
|
|
2465
|
+
return event.fetch(info, init2);
|
|
2466
|
+
},
|
|
2467
|
+
/** @param {string[]} deps */
|
|
2468
|
+
depends: (...deps) => {
|
|
2469
|
+
for (const dep of deps) {
|
|
2470
|
+
const { href } = new URL(dep, event.url);
|
|
2471
|
+
uses.dependencies.add(href);
|
|
2472
|
+
}
|
|
2473
|
+
},
|
|
2474
|
+
params: new Proxy(event.params, {
|
|
2475
|
+
get: (target, key2) => {
|
|
2476
|
+
if (is_tracking) {
|
|
2477
|
+
uses.params.add(key2);
|
|
2478
|
+
}
|
|
2479
|
+
return target[
|
|
2480
|
+
/** @type {string} */
|
|
2481
|
+
key2
|
|
2482
|
+
];
|
|
2483
|
+
}
|
|
2484
|
+
}),
|
|
2485
|
+
parent: async () => {
|
|
2486
|
+
if (is_tracking) {
|
|
2487
|
+
uses.parent = true;
|
|
2488
|
+
}
|
|
2489
|
+
return parent();
|
|
2490
|
+
},
|
|
2491
|
+
route: new Proxy(event.route, {
|
|
2492
|
+
get: (target, key2) => {
|
|
2493
|
+
if (is_tracking) {
|
|
2494
|
+
uses.route = true;
|
|
2495
|
+
}
|
|
2496
|
+
return target[
|
|
2497
|
+
/** @type {'id'} */
|
|
2498
|
+
key2
|
|
2499
|
+
];
|
|
2500
|
+
}
|
|
2501
|
+
}),
|
|
2502
|
+
url,
|
|
2503
|
+
untrack(fn) {
|
|
2504
|
+
is_tracking = false;
|
|
2505
|
+
try {
|
|
2506
|
+
return fn();
|
|
2507
|
+
} finally {
|
|
2508
|
+
is_tracking = true;
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
});
|
|
2512
|
+
return {
|
|
2513
|
+
type: "data",
|
|
2514
|
+
data: result ?? null,
|
|
2515
|
+
uses,
|
|
2516
|
+
slash: node.server.trailingSlash
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
async function load_data({
|
|
2520
|
+
event,
|
|
2521
|
+
fetched,
|
|
2522
|
+
node,
|
|
2523
|
+
parent,
|
|
2524
|
+
server_data_promise,
|
|
2525
|
+
state,
|
|
2526
|
+
resolve_opts,
|
|
2527
|
+
csr
|
|
2528
|
+
}) {
|
|
2529
|
+
const server_data_node = await server_data_promise;
|
|
2530
|
+
if (!node?.universal?.load) {
|
|
2531
|
+
return server_data_node?.data ?? null;
|
|
2532
|
+
}
|
|
2533
|
+
const result = await node.universal.load.call(null, {
|
|
2534
|
+
url: event.url,
|
|
2535
|
+
params: event.params,
|
|
2536
|
+
data: server_data_node?.data ?? null,
|
|
2537
|
+
route: event.route,
|
|
2538
|
+
fetch: create_universal_fetch(event, state, fetched, csr, resolve_opts),
|
|
2539
|
+
setHeaders: event.setHeaders,
|
|
2540
|
+
depends: () => {
|
|
2541
|
+
},
|
|
2542
|
+
parent,
|
|
2543
|
+
untrack: (fn) => fn()
|
|
2544
|
+
});
|
|
2545
|
+
return result ?? null;
|
|
2546
|
+
}
|
|
2547
|
+
function create_universal_fetch(event, state, fetched, csr, resolve_opts) {
|
|
2548
|
+
const universal_fetch = async (input, init2) => {
|
|
2549
|
+
const cloned_body = input instanceof Request && input.body ? input.clone().body : null;
|
|
2550
|
+
const cloned_headers = input instanceof Request && [...input.headers].length ? new Headers(input.headers) : init2?.headers;
|
|
2551
|
+
let response = await event.fetch(input, init2);
|
|
2552
|
+
const url = new URL(input instanceof Request ? input.url : input, event.url);
|
|
2553
|
+
const same_origin = url.origin === event.url.origin;
|
|
2554
|
+
let dependency;
|
|
2555
|
+
if (same_origin) {
|
|
2556
|
+
if (state.prerendering) {
|
|
2557
|
+
dependency = { response, body: null };
|
|
2558
|
+
state.prerendering.dependencies.set(url.pathname, dependency);
|
|
2559
|
+
}
|
|
2560
|
+
} else {
|
|
2561
|
+
const mode = input instanceof Request ? input.mode : init2?.mode ?? "cors";
|
|
2562
|
+
if (mode === "no-cors") {
|
|
2563
|
+
response = new Response("", {
|
|
2564
|
+
status: response.status,
|
|
2565
|
+
statusText: response.statusText,
|
|
2566
|
+
headers: response.headers
|
|
2567
|
+
});
|
|
2568
|
+
} else {
|
|
2569
|
+
const acao = response.headers.get("access-control-allow-origin");
|
|
2570
|
+
if (!acao || acao !== event.url.origin && acao !== "*") {
|
|
2571
|
+
throw new Error(
|
|
2572
|
+
`CORS error: ${acao ? "Incorrect" : "No"} 'Access-Control-Allow-Origin' header is present on the requested resource`
|
|
2573
|
+
);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
const proxy = new Proxy(response, {
|
|
2578
|
+
get(response2, key2, _receiver) {
|
|
2579
|
+
async function push_fetched(body2, is_b64) {
|
|
2580
|
+
const status_number = Number(response2.status);
|
|
2581
|
+
if (isNaN(status_number)) {
|
|
2582
|
+
throw new Error(
|
|
2583
|
+
`response.status is not a number. value: "${response2.status}" type: ${typeof response2.status}`
|
|
2584
|
+
);
|
|
2585
|
+
}
|
|
2586
|
+
fetched.push({
|
|
2587
|
+
url: same_origin ? url.href.slice(event.url.origin.length) : url.href,
|
|
2588
|
+
method: event.request.method,
|
|
2589
|
+
request_body: (
|
|
2590
|
+
/** @type {string | ArrayBufferView | undefined} */
|
|
2591
|
+
input instanceof Request && cloned_body ? await stream_to_string(cloned_body) : init2?.body
|
|
2592
|
+
),
|
|
2593
|
+
request_headers: cloned_headers,
|
|
2594
|
+
response_body: body2,
|
|
2595
|
+
response: response2,
|
|
2596
|
+
is_b64
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
if (key2 === "arrayBuffer") {
|
|
2600
|
+
return async () => {
|
|
2601
|
+
const buffer = await response2.arrayBuffer();
|
|
2602
|
+
if (dependency) {
|
|
2603
|
+
dependency.body = new Uint8Array(buffer);
|
|
2604
|
+
}
|
|
2605
|
+
if (buffer instanceof ArrayBuffer) {
|
|
2606
|
+
await push_fetched(b64_encode(buffer), true);
|
|
2607
|
+
}
|
|
2608
|
+
return buffer;
|
|
2609
|
+
};
|
|
2610
|
+
}
|
|
2611
|
+
async function text2() {
|
|
2612
|
+
const body2 = await response2.text();
|
|
2613
|
+
if (!body2 || typeof body2 === "string") {
|
|
2614
|
+
await push_fetched(body2, false);
|
|
2615
|
+
}
|
|
2616
|
+
if (dependency) {
|
|
2617
|
+
dependency.body = body2;
|
|
2618
|
+
}
|
|
2619
|
+
return body2;
|
|
2620
|
+
}
|
|
2621
|
+
if (key2 === "text") {
|
|
2622
|
+
return text2;
|
|
2623
|
+
}
|
|
2624
|
+
if (key2 === "json") {
|
|
2625
|
+
return async () => {
|
|
2626
|
+
return JSON.parse(await text2());
|
|
2627
|
+
};
|
|
2628
|
+
}
|
|
2629
|
+
return Reflect.get(response2, key2, response2);
|
|
2630
|
+
}
|
|
2631
|
+
});
|
|
2632
|
+
if (csr) {
|
|
2633
|
+
const get = response.headers.get;
|
|
2634
|
+
response.headers.get = (key2) => {
|
|
2635
|
+
const lower = key2.toLowerCase();
|
|
2636
|
+
const value = get.call(response.headers, lower);
|
|
2637
|
+
if (value && !lower.startsWith("x-sveltekit-")) {
|
|
2638
|
+
const included = resolve_opts.filterSerializedResponseHeaders(lower, value);
|
|
2639
|
+
if (!included) {
|
|
2640
|
+
throw new Error(
|
|
2641
|
+
`Failed to get response header "${lower}" — it must be included by the \`filterSerializedResponseHeaders\` option: https://svelte.dev/docs/kit/hooks#Server-hooks-handle (at ${event.route.id})`
|
|
2642
|
+
);
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
return value;
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
return proxy;
|
|
2649
|
+
};
|
|
2650
|
+
return (input, init2) => {
|
|
2651
|
+
const response = universal_fetch(input, init2);
|
|
2652
|
+
response.catch(() => {
|
|
2653
|
+
});
|
|
2654
|
+
return response;
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
async function stream_to_string(stream) {
|
|
2658
|
+
let result = "";
|
|
2659
|
+
const reader = stream.getReader();
|
|
2660
|
+
const decoder = new TextDecoder();
|
|
2661
|
+
while (true) {
|
|
2662
|
+
const { done, value } = await reader.read();
|
|
2663
|
+
if (done) {
|
|
2664
|
+
break;
|
|
2665
|
+
}
|
|
2666
|
+
result += decoder.decode(value);
|
|
2667
|
+
}
|
|
2668
|
+
return result;
|
|
2669
|
+
}
|
|
2670
|
+
function hash(...values) {
|
|
2671
|
+
let hash2 = 5381;
|
|
2672
|
+
for (const value of values) {
|
|
2673
|
+
if (typeof value === "string") {
|
|
2674
|
+
let i = value.length;
|
|
2675
|
+
while (i) hash2 = hash2 * 33 ^ value.charCodeAt(--i);
|
|
2676
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
2677
|
+
const buffer = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
2678
|
+
let i = buffer.length;
|
|
2679
|
+
while (i) hash2 = hash2 * 33 ^ buffer[--i];
|
|
2680
|
+
} else {
|
|
2681
|
+
throw new TypeError("value must be a string or TypedArray");
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
return (hash2 >>> 0).toString(36);
|
|
2685
|
+
}
|
|
2686
|
+
const replacements = {
|
|
2687
|
+
"<": "\\u003C",
|
|
2688
|
+
"\u2028": "\\u2028",
|
|
2689
|
+
"\u2029": "\\u2029"
|
|
2690
|
+
};
|
|
2691
|
+
const pattern = new RegExp(`[${Object.keys(replacements).join("")}]`, "g");
|
|
2692
|
+
function serialize_data(fetched, filter, prerendering2 = false) {
|
|
2693
|
+
const headers2 = {};
|
|
2694
|
+
let cache_control = null;
|
|
2695
|
+
let age = null;
|
|
2696
|
+
let varyAny = false;
|
|
2697
|
+
for (const [key2, value] of fetched.response.headers) {
|
|
2698
|
+
if (filter(key2, value)) {
|
|
2699
|
+
headers2[key2] = value;
|
|
2700
|
+
}
|
|
2701
|
+
if (key2 === "cache-control") cache_control = value;
|
|
2702
|
+
else if (key2 === "age") age = value;
|
|
2703
|
+
else if (key2 === "vary" && value.trim() === "*") varyAny = true;
|
|
2704
|
+
}
|
|
2705
|
+
const payload = {
|
|
2706
|
+
status: fetched.response.status,
|
|
2707
|
+
statusText: fetched.response.statusText,
|
|
2708
|
+
headers: headers2,
|
|
2709
|
+
body: fetched.response_body
|
|
2710
|
+
};
|
|
2711
|
+
const safe_payload = JSON.stringify(payload).replace(pattern, (match) => replacements[match]);
|
|
2712
|
+
const attrs = [
|
|
2713
|
+
'type="application/json"',
|
|
2714
|
+
"data-sveltekit-fetched",
|
|
2715
|
+
`data-url="${escape_html(fetched.url, true)}"`
|
|
2716
|
+
];
|
|
2717
|
+
if (fetched.is_b64) {
|
|
2718
|
+
attrs.push("data-b64");
|
|
2719
|
+
}
|
|
2720
|
+
if (fetched.request_headers || fetched.request_body) {
|
|
2721
|
+
const values = [];
|
|
2722
|
+
if (fetched.request_headers) {
|
|
2723
|
+
values.push([...new Headers(fetched.request_headers)].join(","));
|
|
2724
|
+
}
|
|
2725
|
+
if (fetched.request_body) {
|
|
2726
|
+
values.push(fetched.request_body);
|
|
2727
|
+
}
|
|
2728
|
+
attrs.push(`data-hash="${hash(...values)}"`);
|
|
2729
|
+
}
|
|
2730
|
+
if (!prerendering2 && fetched.method === "GET" && cache_control && !varyAny) {
|
|
2731
|
+
const match = /s-maxage=(\d+)/g.exec(cache_control) ?? /max-age=(\d+)/g.exec(cache_control);
|
|
2732
|
+
if (match) {
|
|
2733
|
+
const ttl = +match[1] - +(age ?? "0");
|
|
2734
|
+
attrs.push(`data-ttl="${ttl}"`);
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
return `<script ${attrs.join(" ")}>${safe_payload}<\/script>`;
|
|
2738
|
+
}
|
|
2739
|
+
const s = JSON.stringify;
|
|
2740
|
+
const encoder$2 = new TextEncoder();
|
|
2741
|
+
function sha256(data) {
|
|
2742
|
+
if (!key[0]) precompute();
|
|
2743
|
+
const out = init.slice(0);
|
|
2744
|
+
const array2 = encode(data);
|
|
2745
|
+
for (let i = 0; i < array2.length; i += 16) {
|
|
2746
|
+
const w = array2.subarray(i, i + 16);
|
|
2747
|
+
let tmp;
|
|
2748
|
+
let a;
|
|
2749
|
+
let b;
|
|
2750
|
+
let out0 = out[0];
|
|
2751
|
+
let out1 = out[1];
|
|
2752
|
+
let out2 = out[2];
|
|
2753
|
+
let out3 = out[3];
|
|
2754
|
+
let out4 = out[4];
|
|
2755
|
+
let out5 = out[5];
|
|
2756
|
+
let out6 = out[6];
|
|
2757
|
+
let out7 = out[7];
|
|
2758
|
+
for (let i2 = 0; i2 < 64; i2++) {
|
|
2759
|
+
if (i2 < 16) {
|
|
2760
|
+
tmp = w[i2];
|
|
2761
|
+
} else {
|
|
2762
|
+
a = w[i2 + 1 & 15];
|
|
2763
|
+
b = w[i2 + 14 & 15];
|
|
2764
|
+
tmp = w[i2 & 15] = (a >>> 7 ^ a >>> 18 ^ a >>> 3 ^ a << 25 ^ a << 14) + (b >>> 17 ^ b >>> 19 ^ b >>> 10 ^ b << 15 ^ b << 13) + w[i2 & 15] + w[i2 + 9 & 15] | 0;
|
|
2765
|
+
}
|
|
2766
|
+
tmp = tmp + out7 + (out4 >>> 6 ^ out4 >>> 11 ^ out4 >>> 25 ^ out4 << 26 ^ out4 << 21 ^ out4 << 7) + (out6 ^ out4 & (out5 ^ out6)) + key[i2];
|
|
2767
|
+
out7 = out6;
|
|
2768
|
+
out6 = out5;
|
|
2769
|
+
out5 = out4;
|
|
2770
|
+
out4 = out3 + tmp | 0;
|
|
2771
|
+
out3 = out2;
|
|
2772
|
+
out2 = out1;
|
|
2773
|
+
out1 = out0;
|
|
2774
|
+
out0 = tmp + (out1 & out2 ^ out3 & (out1 ^ out2)) + (out1 >>> 2 ^ out1 >>> 13 ^ out1 >>> 22 ^ out1 << 30 ^ out1 << 19 ^ out1 << 10) | 0;
|
|
2775
|
+
}
|
|
2776
|
+
out[0] = out[0] + out0 | 0;
|
|
2777
|
+
out[1] = out[1] + out1 | 0;
|
|
2778
|
+
out[2] = out[2] + out2 | 0;
|
|
2779
|
+
out[3] = out[3] + out3 | 0;
|
|
2780
|
+
out[4] = out[4] + out4 | 0;
|
|
2781
|
+
out[5] = out[5] + out5 | 0;
|
|
2782
|
+
out[6] = out[6] + out6 | 0;
|
|
2783
|
+
out[7] = out[7] + out7 | 0;
|
|
2784
|
+
}
|
|
2785
|
+
const bytes = new Uint8Array(out.buffer);
|
|
2786
|
+
reverse_endianness(bytes);
|
|
2787
|
+
return base64(bytes);
|
|
2788
|
+
}
|
|
2789
|
+
const init = new Uint32Array(8);
|
|
2790
|
+
const key = new Uint32Array(64);
|
|
2791
|
+
function precompute() {
|
|
2792
|
+
function frac(x) {
|
|
2793
|
+
return (x - Math.floor(x)) * 4294967296;
|
|
2794
|
+
}
|
|
2795
|
+
let prime = 2;
|
|
2796
|
+
for (let i = 0; i < 64; prime++) {
|
|
2797
|
+
let is_prime = true;
|
|
2798
|
+
for (let factor = 2; factor * factor <= prime; factor++) {
|
|
2799
|
+
if (prime % factor === 0) {
|
|
2800
|
+
is_prime = false;
|
|
2801
|
+
break;
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
if (is_prime) {
|
|
2805
|
+
if (i < 8) {
|
|
2806
|
+
init[i] = frac(prime ** (1 / 2));
|
|
2807
|
+
}
|
|
2808
|
+
key[i] = frac(prime ** (1 / 3));
|
|
2809
|
+
i++;
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
function reverse_endianness(bytes) {
|
|
2814
|
+
for (let i = 0; i < bytes.length; i += 4) {
|
|
2815
|
+
const a = bytes[i + 0];
|
|
2816
|
+
const b = bytes[i + 1];
|
|
2817
|
+
const c = bytes[i + 2];
|
|
2818
|
+
const d = bytes[i + 3];
|
|
2819
|
+
bytes[i + 0] = d;
|
|
2820
|
+
bytes[i + 1] = c;
|
|
2821
|
+
bytes[i + 2] = b;
|
|
2822
|
+
bytes[i + 3] = a;
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
function encode(str) {
|
|
2826
|
+
const encoded = encoder$2.encode(str);
|
|
2827
|
+
const length = encoded.length * 8;
|
|
2828
|
+
const size = 512 * Math.ceil((length + 65) / 512);
|
|
2829
|
+
const bytes = new Uint8Array(size / 8);
|
|
2830
|
+
bytes.set(encoded);
|
|
2831
|
+
bytes[encoded.length] = 128;
|
|
2832
|
+
reverse_endianness(bytes);
|
|
2833
|
+
const words = new Uint32Array(bytes.buffer);
|
|
2834
|
+
words[words.length - 2] = Math.floor(length / 4294967296);
|
|
2835
|
+
words[words.length - 1] = length;
|
|
2836
|
+
return words;
|
|
2837
|
+
}
|
|
2838
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
2839
|
+
function base64(bytes) {
|
|
2840
|
+
const l = bytes.length;
|
|
2841
|
+
let result = "";
|
|
2842
|
+
let i;
|
|
2843
|
+
for (i = 2; i < l; i += 3) {
|
|
2844
|
+
result += chars[bytes[i - 2] >> 2];
|
|
2845
|
+
result += chars[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
2846
|
+
result += chars[(bytes[i - 1] & 15) << 2 | bytes[i] >> 6];
|
|
2847
|
+
result += chars[bytes[i] & 63];
|
|
2848
|
+
}
|
|
2849
|
+
if (i === l + 1) {
|
|
2850
|
+
result += chars[bytes[i - 2] >> 2];
|
|
2851
|
+
result += chars[(bytes[i - 2] & 3) << 4];
|
|
2852
|
+
result += "==";
|
|
2853
|
+
}
|
|
2854
|
+
if (i === l) {
|
|
2855
|
+
result += chars[bytes[i - 2] >> 2];
|
|
2856
|
+
result += chars[(bytes[i - 2] & 3) << 4 | bytes[i - 1] >> 4];
|
|
2857
|
+
result += chars[(bytes[i - 1] & 15) << 2];
|
|
2858
|
+
result += "=";
|
|
2859
|
+
}
|
|
2860
|
+
return result;
|
|
2861
|
+
}
|
|
2862
|
+
const array = new Uint8Array(16);
|
|
2863
|
+
function generate_nonce() {
|
|
2864
|
+
crypto.getRandomValues(array);
|
|
2865
|
+
return base64(array);
|
|
2866
|
+
}
|
|
2867
|
+
const quoted = /* @__PURE__ */ new Set([
|
|
2868
|
+
"self",
|
|
2869
|
+
"unsafe-eval",
|
|
2870
|
+
"unsafe-hashes",
|
|
2871
|
+
"unsafe-inline",
|
|
2872
|
+
"none",
|
|
2873
|
+
"strict-dynamic",
|
|
2874
|
+
"report-sample",
|
|
2875
|
+
"wasm-unsafe-eval",
|
|
2876
|
+
"script"
|
|
2877
|
+
]);
|
|
2878
|
+
const crypto_pattern = /^(nonce|sha\d\d\d)-/;
|
|
2879
|
+
class BaseProvider {
|
|
2880
|
+
/** @type {boolean} */
|
|
2881
|
+
#use_hashes;
|
|
2882
|
+
/** @type {boolean} */
|
|
2883
|
+
#script_needs_csp;
|
|
2884
|
+
/** @type {boolean} */
|
|
2885
|
+
#script_src_needs_csp;
|
|
2886
|
+
/** @type {boolean} */
|
|
2887
|
+
#script_src_elem_needs_csp;
|
|
2888
|
+
/** @type {boolean} */
|
|
2889
|
+
#style_needs_csp;
|
|
2890
|
+
/** @type {boolean} */
|
|
2891
|
+
#style_src_needs_csp;
|
|
2892
|
+
/** @type {boolean} */
|
|
2893
|
+
#style_src_attr_needs_csp;
|
|
2894
|
+
/** @type {boolean} */
|
|
2895
|
+
#style_src_elem_needs_csp;
|
|
2896
|
+
/** @type {import('types').CspDirectives} */
|
|
2897
|
+
#directives;
|
|
2898
|
+
/** @type {import('types').Csp.Source[]} */
|
|
2899
|
+
#script_src;
|
|
2900
|
+
/** @type {import('types').Csp.Source[]} */
|
|
2901
|
+
#script_src_elem;
|
|
2902
|
+
/** @type {import('types').Csp.Source[]} */
|
|
2903
|
+
#style_src;
|
|
2904
|
+
/** @type {import('types').Csp.Source[]} */
|
|
2905
|
+
#style_src_attr;
|
|
2906
|
+
/** @type {import('types').Csp.Source[]} */
|
|
2907
|
+
#style_src_elem;
|
|
2908
|
+
/** @type {string} */
|
|
2909
|
+
#nonce;
|
|
2910
|
+
/**
|
|
2911
|
+
* @param {boolean} use_hashes
|
|
2912
|
+
* @param {import('types').CspDirectives} directives
|
|
2913
|
+
* @param {string} nonce
|
|
2914
|
+
*/
|
|
2915
|
+
constructor(use_hashes, directives, nonce) {
|
|
2916
|
+
this.#use_hashes = use_hashes;
|
|
2917
|
+
this.#directives = directives;
|
|
2918
|
+
const d = this.#directives;
|
|
2919
|
+
this.#script_src = [];
|
|
2920
|
+
this.#script_src_elem = [];
|
|
2921
|
+
this.#style_src = [];
|
|
2922
|
+
this.#style_src_attr = [];
|
|
2923
|
+
this.#style_src_elem = [];
|
|
2924
|
+
const effective_script_src = d["script-src"] || d["default-src"];
|
|
2925
|
+
const script_src_elem = d["script-src-elem"];
|
|
2926
|
+
const effective_style_src = d["style-src"] || d["default-src"];
|
|
2927
|
+
const style_src_attr = d["style-src-attr"];
|
|
2928
|
+
const style_src_elem = d["style-src-elem"];
|
|
2929
|
+
const needs_csp = (directive) => !!directive && !directive.some((value) => value === "unsafe-inline");
|
|
2930
|
+
this.#script_src_needs_csp = needs_csp(effective_script_src);
|
|
2931
|
+
this.#script_src_elem_needs_csp = needs_csp(script_src_elem);
|
|
2932
|
+
this.#style_src_needs_csp = needs_csp(effective_style_src);
|
|
2933
|
+
this.#style_src_attr_needs_csp = needs_csp(style_src_attr);
|
|
2934
|
+
this.#style_src_elem_needs_csp = needs_csp(style_src_elem);
|
|
2935
|
+
this.#script_needs_csp = this.#script_src_needs_csp || this.#script_src_elem_needs_csp;
|
|
2936
|
+
this.#style_needs_csp = this.#style_src_needs_csp || this.#style_src_attr_needs_csp || this.#style_src_elem_needs_csp;
|
|
2937
|
+
this.script_needs_nonce = this.#script_needs_csp && !this.#use_hashes;
|
|
2938
|
+
this.style_needs_nonce = this.#style_needs_csp && !this.#use_hashes;
|
|
2939
|
+
this.#nonce = nonce;
|
|
2940
|
+
}
|
|
2941
|
+
/** @param {string} content */
|
|
2942
|
+
add_script(content) {
|
|
2943
|
+
if (!this.#script_needs_csp) return;
|
|
2944
|
+
const source = this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
|
|
2945
|
+
if (this.#script_src_needs_csp) {
|
|
2946
|
+
this.#script_src.push(source);
|
|
2947
|
+
}
|
|
2948
|
+
if (this.#script_src_elem_needs_csp) {
|
|
2949
|
+
this.#script_src_elem.push(source);
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
/** @param {string} content */
|
|
2953
|
+
add_style(content) {
|
|
2954
|
+
if (!this.#style_needs_csp) return;
|
|
2955
|
+
const source = this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
|
|
2956
|
+
if (this.#style_src_needs_csp) {
|
|
2957
|
+
this.#style_src.push(source);
|
|
2958
|
+
}
|
|
2959
|
+
if (this.#style_src_needs_csp) {
|
|
2960
|
+
this.#style_src.push(source);
|
|
2961
|
+
}
|
|
2962
|
+
if (this.#style_src_attr_needs_csp) {
|
|
2963
|
+
this.#style_src_attr.push(source);
|
|
2964
|
+
}
|
|
2965
|
+
if (this.#style_src_elem_needs_csp) {
|
|
2966
|
+
const sha256_empty_comment_hash = "sha256-9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=";
|
|
2967
|
+
const d = this.#directives;
|
|
2968
|
+
if (d["style-src-elem"] && !d["style-src-elem"].includes(sha256_empty_comment_hash) && !this.#style_src_elem.includes(sha256_empty_comment_hash)) {
|
|
2969
|
+
this.#style_src_elem.push(sha256_empty_comment_hash);
|
|
2970
|
+
}
|
|
2971
|
+
if (source !== sha256_empty_comment_hash) {
|
|
2972
|
+
this.#style_src_elem.push(source);
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
/**
|
|
2977
|
+
* @param {boolean} [is_meta]
|
|
2978
|
+
*/
|
|
2979
|
+
get_header(is_meta = false) {
|
|
2980
|
+
const header = [];
|
|
2981
|
+
const directives = { ...this.#directives };
|
|
2982
|
+
if (this.#style_src.length > 0) {
|
|
2983
|
+
directives["style-src"] = [
|
|
2984
|
+
...directives["style-src"] || directives["default-src"] || [],
|
|
2985
|
+
...this.#style_src
|
|
2986
|
+
];
|
|
2987
|
+
}
|
|
2988
|
+
if (this.#style_src_attr.length > 0) {
|
|
2989
|
+
directives["style-src-attr"] = [
|
|
2990
|
+
...directives["style-src-attr"] || [],
|
|
2991
|
+
...this.#style_src_attr
|
|
2992
|
+
];
|
|
2993
|
+
}
|
|
2994
|
+
if (this.#style_src_elem.length > 0) {
|
|
2995
|
+
directives["style-src-elem"] = [
|
|
2996
|
+
...directives["style-src-elem"] || [],
|
|
2997
|
+
...this.#style_src_elem
|
|
2998
|
+
];
|
|
2999
|
+
}
|
|
3000
|
+
if (this.#script_src.length > 0) {
|
|
3001
|
+
directives["script-src"] = [
|
|
3002
|
+
...directives["script-src"] || directives["default-src"] || [],
|
|
3003
|
+
...this.#script_src
|
|
3004
|
+
];
|
|
3005
|
+
}
|
|
3006
|
+
if (this.#script_src_elem.length > 0) {
|
|
3007
|
+
directives["script-src-elem"] = [
|
|
3008
|
+
...directives["script-src-elem"] || [],
|
|
3009
|
+
...this.#script_src_elem
|
|
3010
|
+
];
|
|
3011
|
+
}
|
|
3012
|
+
for (const key2 in directives) {
|
|
3013
|
+
if (is_meta && (key2 === "frame-ancestors" || key2 === "report-uri" || key2 === "sandbox")) {
|
|
3014
|
+
continue;
|
|
3015
|
+
}
|
|
3016
|
+
const value = (
|
|
3017
|
+
/** @type {string[] | true} */
|
|
3018
|
+
directives[key2]
|
|
3019
|
+
);
|
|
3020
|
+
if (!value) continue;
|
|
3021
|
+
const directive = [key2];
|
|
3022
|
+
if (Array.isArray(value)) {
|
|
3023
|
+
value.forEach((value2) => {
|
|
3024
|
+
if (quoted.has(value2) || crypto_pattern.test(value2)) {
|
|
3025
|
+
directive.push(`'${value2}'`);
|
|
3026
|
+
} else {
|
|
3027
|
+
directive.push(value2);
|
|
3028
|
+
}
|
|
3029
|
+
});
|
|
3030
|
+
}
|
|
3031
|
+
header.push(directive.join(" "));
|
|
3032
|
+
}
|
|
3033
|
+
return header.join("; ");
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
class CspProvider extends BaseProvider {
|
|
3037
|
+
get_meta() {
|
|
3038
|
+
const content = this.get_header(true);
|
|
3039
|
+
if (!content) {
|
|
3040
|
+
return;
|
|
3041
|
+
}
|
|
3042
|
+
return `<meta http-equiv="content-security-policy" content="${escape_html(content, true)}">`;
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
class CspReportOnlyProvider extends BaseProvider {
|
|
3046
|
+
/**
|
|
3047
|
+
* @param {boolean} use_hashes
|
|
3048
|
+
* @param {import('types').CspDirectives} directives
|
|
3049
|
+
* @param {string} nonce
|
|
3050
|
+
*/
|
|
3051
|
+
constructor(use_hashes, directives, nonce) {
|
|
3052
|
+
super(use_hashes, directives, nonce);
|
|
3053
|
+
if (Object.values(directives).filter((v) => !!v).length > 0) {
|
|
3054
|
+
const has_report_to = directives["report-to"]?.length ?? 0 > 0;
|
|
3055
|
+
const has_report_uri = directives["report-uri"]?.length ?? 0 > 0;
|
|
3056
|
+
if (!has_report_to && !has_report_uri) {
|
|
3057
|
+
throw Error(
|
|
3058
|
+
"`content-security-policy-report-only` must be specified with either the `report-to` or `report-uri` directives, or both"
|
|
3059
|
+
);
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
class Csp {
|
|
3065
|
+
/** @readonly */
|
|
3066
|
+
nonce = generate_nonce();
|
|
3067
|
+
/** @type {CspProvider} */
|
|
3068
|
+
csp_provider;
|
|
3069
|
+
/** @type {CspReportOnlyProvider} */
|
|
3070
|
+
report_only_provider;
|
|
3071
|
+
/**
|
|
3072
|
+
* @param {import('./types.js').CspConfig} config
|
|
3073
|
+
* @param {import('./types.js').CspOpts} opts
|
|
3074
|
+
*/
|
|
3075
|
+
constructor({ mode, directives, reportOnly }, { prerender }) {
|
|
3076
|
+
const use_hashes = mode === "hash" || mode === "auto" && prerender;
|
|
3077
|
+
this.csp_provider = new CspProvider(use_hashes, directives, this.nonce);
|
|
3078
|
+
this.report_only_provider = new CspReportOnlyProvider(use_hashes, reportOnly, this.nonce);
|
|
3079
|
+
}
|
|
3080
|
+
get script_needs_nonce() {
|
|
3081
|
+
return this.csp_provider.script_needs_nonce || this.report_only_provider.script_needs_nonce;
|
|
3082
|
+
}
|
|
3083
|
+
get style_needs_nonce() {
|
|
3084
|
+
return this.csp_provider.style_needs_nonce || this.report_only_provider.style_needs_nonce;
|
|
3085
|
+
}
|
|
3086
|
+
/** @param {string} content */
|
|
3087
|
+
add_script(content) {
|
|
3088
|
+
this.csp_provider.add_script(content);
|
|
3089
|
+
this.report_only_provider.add_script(content);
|
|
3090
|
+
}
|
|
3091
|
+
/** @param {string} content */
|
|
3092
|
+
add_style(content) {
|
|
3093
|
+
this.csp_provider.add_style(content);
|
|
3094
|
+
this.report_only_provider.add_style(content);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
function defer() {
|
|
3098
|
+
let fulfil;
|
|
3099
|
+
let reject;
|
|
3100
|
+
const promise = new Promise((f, r) => {
|
|
3101
|
+
fulfil = f;
|
|
3102
|
+
reject = r;
|
|
3103
|
+
});
|
|
3104
|
+
return { promise, fulfil, reject };
|
|
3105
|
+
}
|
|
3106
|
+
function create_async_iterator() {
|
|
3107
|
+
const deferred = [defer()];
|
|
3108
|
+
return {
|
|
3109
|
+
iterator: {
|
|
3110
|
+
[Symbol.asyncIterator]() {
|
|
3111
|
+
return {
|
|
3112
|
+
next: async () => {
|
|
3113
|
+
const next = await deferred[0].promise;
|
|
3114
|
+
if (!next.done) deferred.shift();
|
|
3115
|
+
return next;
|
|
3116
|
+
}
|
|
3117
|
+
};
|
|
3118
|
+
}
|
|
3119
|
+
},
|
|
3120
|
+
push: (value) => {
|
|
3121
|
+
deferred[deferred.length - 1].fulfil({
|
|
3122
|
+
value,
|
|
3123
|
+
done: false
|
|
3124
|
+
});
|
|
3125
|
+
deferred.push(defer());
|
|
3126
|
+
},
|
|
3127
|
+
done: () => {
|
|
3128
|
+
deferred[deferred.length - 1].fulfil({ done: true });
|
|
3129
|
+
}
|
|
3130
|
+
};
|
|
3131
|
+
}
|
|
3132
|
+
const updated = {
|
|
3133
|
+
...readable(false),
|
|
3134
|
+
check: () => false
|
|
3135
|
+
};
|
|
3136
|
+
const encoder$1 = new TextEncoder();
|
|
3137
|
+
async function render_response({
|
|
3138
|
+
branch,
|
|
3139
|
+
fetched,
|
|
3140
|
+
options: options2,
|
|
3141
|
+
manifest,
|
|
3142
|
+
state,
|
|
3143
|
+
page_config,
|
|
3144
|
+
status,
|
|
3145
|
+
error = null,
|
|
3146
|
+
event,
|
|
3147
|
+
resolve_opts,
|
|
3148
|
+
action_result
|
|
3149
|
+
}) {
|
|
3150
|
+
if (state.prerendering) {
|
|
3151
|
+
if (options2.csp.mode === "nonce") {
|
|
3152
|
+
throw new Error('Cannot use prerendering if config.kit.csp.mode === "nonce"');
|
|
3153
|
+
}
|
|
3154
|
+
if (options2.app_template_contains_nonce) {
|
|
3155
|
+
throw new Error("Cannot use prerendering if page template contains %sveltekit.nonce%");
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
const { client } = manifest._;
|
|
3159
|
+
const modulepreloads = new Set(client.imports);
|
|
3160
|
+
const stylesheets = new Set(client.stylesheets);
|
|
3161
|
+
const fonts = new Set(client.fonts);
|
|
3162
|
+
const link_header_preloads = /* @__PURE__ */ new Set();
|
|
3163
|
+
const inline_styles = /* @__PURE__ */ new Map();
|
|
3164
|
+
let rendered;
|
|
3165
|
+
const form_value = action_result?.type === "success" || action_result?.type === "failure" ? action_result.data ?? null : null;
|
|
3166
|
+
let base$1 = base;
|
|
3167
|
+
let assets$1 = assets;
|
|
3168
|
+
let base_expression = s(base);
|
|
3169
|
+
{
|
|
3170
|
+
if (!state.prerendering?.fallback) {
|
|
3171
|
+
const segments = event.url.pathname.slice(base.length).split("/").slice(2);
|
|
3172
|
+
base$1 = segments.map(() => "..").join("/") || ".";
|
|
3173
|
+
base_expression = `new URL(${s(base$1)}, location).pathname.slice(0, -1)`;
|
|
3174
|
+
if (!assets || assets[0] === "/" && assets !== SVELTE_KIT_ASSETS) {
|
|
3175
|
+
assets$1 = base$1;
|
|
3176
|
+
}
|
|
3177
|
+
} else if (options2.hash_routing) {
|
|
3178
|
+
base_expression = "new URL('.', location).pathname.slice(0, -1)";
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
if (page_config.ssr) {
|
|
3182
|
+
const props = {
|
|
3183
|
+
stores: {
|
|
3184
|
+
page: writable(null),
|
|
3185
|
+
navigating: writable(null),
|
|
3186
|
+
updated
|
|
3187
|
+
},
|
|
3188
|
+
constructors: await Promise.all(branch.map(({ node }) => node.component())),
|
|
3189
|
+
form: form_value
|
|
3190
|
+
};
|
|
3191
|
+
let data2 = {};
|
|
3192
|
+
for (let i = 0; i < branch.length; i += 1) {
|
|
3193
|
+
data2 = { ...data2, ...branch[i].data };
|
|
3194
|
+
props[`data_${i}`] = data2;
|
|
3195
|
+
}
|
|
3196
|
+
props.page = {
|
|
3197
|
+
error,
|
|
3198
|
+
params: (
|
|
3199
|
+
/** @type {Record<string, any>} */
|
|
3200
|
+
event.params
|
|
3201
|
+
),
|
|
3202
|
+
route: event.route,
|
|
3203
|
+
status,
|
|
3204
|
+
url: event.url,
|
|
3205
|
+
data: data2,
|
|
3206
|
+
form: form_value,
|
|
3207
|
+
state: {}
|
|
3208
|
+
};
|
|
3209
|
+
override({ base: base$1, assets: assets$1 });
|
|
3210
|
+
const render_opts = {
|
|
3211
|
+
context: /* @__PURE__ */ new Map([
|
|
3212
|
+
[
|
|
3213
|
+
"__request__",
|
|
3214
|
+
{
|
|
3215
|
+
page: props.page
|
|
3216
|
+
}
|
|
3217
|
+
]
|
|
3218
|
+
])
|
|
3219
|
+
};
|
|
3220
|
+
{
|
|
3221
|
+
try {
|
|
3222
|
+
rendered = options2.root.render(props, render_opts);
|
|
3223
|
+
} finally {
|
|
3224
|
+
reset();
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
for (const { node } of branch) {
|
|
3228
|
+
for (const url of node.imports) modulepreloads.add(url);
|
|
3229
|
+
for (const url of node.stylesheets) stylesheets.add(url);
|
|
3230
|
+
for (const url of node.fonts) fonts.add(url);
|
|
3231
|
+
if (node.inline_styles && !client.inline) {
|
|
3232
|
+
Object.entries(await node.inline_styles()).forEach(([k, v]) => inline_styles.set(k, v));
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
} else {
|
|
3236
|
+
rendered = { head: "", html: "", css: { code: "", map: null } };
|
|
3237
|
+
}
|
|
3238
|
+
let head = "";
|
|
3239
|
+
let body2 = rendered.html;
|
|
3240
|
+
const csp = new Csp(options2.csp, {
|
|
3241
|
+
prerender: !!state.prerendering
|
|
3242
|
+
});
|
|
3243
|
+
const prefixed = (path) => {
|
|
3244
|
+
if (path.startsWith("/")) {
|
|
3245
|
+
return base + path;
|
|
3246
|
+
}
|
|
3247
|
+
return `${assets$1}/${path}`;
|
|
3248
|
+
};
|
|
3249
|
+
if (client.inline?.style) {
|
|
3250
|
+
head += `
|
|
3251
|
+
<style>${client.inline.style}</style>`;
|
|
3252
|
+
}
|
|
3253
|
+
if (inline_styles.size > 0) {
|
|
3254
|
+
const content = Array.from(inline_styles.values()).join("\n");
|
|
3255
|
+
const attributes = [];
|
|
3256
|
+
if (csp.style_needs_nonce) attributes.push(` nonce="${csp.nonce}"`);
|
|
3257
|
+
csp.add_style(content);
|
|
3258
|
+
head += `
|
|
3259
|
+
<style${attributes.join("")}>${content}</style>`;
|
|
3260
|
+
}
|
|
3261
|
+
for (const dep of stylesheets) {
|
|
3262
|
+
const path = prefixed(dep);
|
|
3263
|
+
const attributes = ['rel="stylesheet"'];
|
|
3264
|
+
if (inline_styles.has(dep)) {
|
|
3265
|
+
attributes.push("disabled", 'media="(max-width: 0)"');
|
|
3266
|
+
} else {
|
|
3267
|
+
if (resolve_opts.preload({ type: "css", path })) {
|
|
3268
|
+
const preload_atts = ['rel="preload"', 'as="style"'];
|
|
3269
|
+
link_header_preloads.add(`<${encodeURI(path)}>; ${preload_atts.join(";")}; nopush`);
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
head += `
|
|
3273
|
+
<link href="${path}" ${attributes.join(" ")}>`;
|
|
3274
|
+
}
|
|
3275
|
+
for (const dep of fonts) {
|
|
3276
|
+
const path = prefixed(dep);
|
|
3277
|
+
if (resolve_opts.preload({ type: "font", path })) {
|
|
3278
|
+
const ext = dep.slice(dep.lastIndexOf(".") + 1);
|
|
3279
|
+
const attributes = [
|
|
3280
|
+
'rel="preload"',
|
|
3281
|
+
'as="font"',
|
|
3282
|
+
`type="font/${ext}"`,
|
|
3283
|
+
`href="${path}"`,
|
|
3284
|
+
"crossorigin"
|
|
3285
|
+
];
|
|
3286
|
+
head += `
|
|
3287
|
+
<link ${attributes.join(" ")}>`;
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
const global = `__sveltekit_${options2.version_hash}`;
|
|
3291
|
+
const { data, chunks } = get_data(
|
|
3292
|
+
event,
|
|
3293
|
+
options2,
|
|
3294
|
+
branch.map((b) => b.server_data),
|
|
3295
|
+
csp,
|
|
3296
|
+
global
|
|
3297
|
+
);
|
|
3298
|
+
if (page_config.ssr && page_config.csr) {
|
|
3299
|
+
body2 += `
|
|
3300
|
+
${fetched.map(
|
|
3301
|
+
(item) => serialize_data(item, resolve_opts.filterSerializedResponseHeaders, !!state.prerendering)
|
|
3302
|
+
).join("\n ")}`;
|
|
3303
|
+
}
|
|
3304
|
+
if (page_config.csr) {
|
|
3305
|
+
if (client.uses_env_dynamic_public && state.prerendering) {
|
|
3306
|
+
modulepreloads.add(`${options2.app_dir}/env.js`);
|
|
3307
|
+
}
|
|
3308
|
+
if (!client.inline) {
|
|
3309
|
+
const included_modulepreloads = Array.from(modulepreloads, (dep) => prefixed(dep)).filter(
|
|
3310
|
+
(path) => resolve_opts.preload({ type: "js", path })
|
|
3311
|
+
);
|
|
3312
|
+
for (const path of included_modulepreloads) {
|
|
3313
|
+
link_header_preloads.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
3314
|
+
if (options2.preload_strategy !== "modulepreload") {
|
|
3315
|
+
head += `
|
|
3316
|
+
<link rel="preload" as="script" crossorigin="anonymous" href="${path}">`;
|
|
3317
|
+
} else if (state.prerendering) {
|
|
3318
|
+
head += `
|
|
3319
|
+
<link rel="modulepreload" href="${path}">`;
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
const blocks = [];
|
|
3324
|
+
const load_env_eagerly = client.uses_env_dynamic_public && state.prerendering;
|
|
3325
|
+
const properties = [`base: ${base_expression}`];
|
|
3326
|
+
if (assets) {
|
|
3327
|
+
properties.push(`assets: ${s(assets)}`);
|
|
3328
|
+
}
|
|
3329
|
+
if (client.uses_env_dynamic_public) {
|
|
3330
|
+
properties.push(`env: ${load_env_eagerly ? "null" : s(public_env)}`);
|
|
3331
|
+
}
|
|
3332
|
+
if (chunks) {
|
|
3333
|
+
blocks.push("const deferred = new Map();");
|
|
3334
|
+
properties.push(`defer: (id) => new Promise((fulfil, reject) => {
|
|
3335
|
+
deferred.set(id, { fulfil, reject });
|
|
3336
|
+
})`);
|
|
3337
|
+
properties.push(`resolve: ({ id, data, error }) => {
|
|
3338
|
+
const try_to_resolve = () => {
|
|
3339
|
+
if (!deferred.has(id)) {
|
|
3340
|
+
setTimeout(try_to_resolve, 0);
|
|
3341
|
+
return;
|
|
3342
|
+
}
|
|
3343
|
+
const { fulfil, reject } = deferred.get(id);
|
|
3344
|
+
deferred.delete(id);
|
|
3345
|
+
if (error) reject(error);
|
|
3346
|
+
else fulfil(data);
|
|
3347
|
+
}
|
|
3348
|
+
try_to_resolve();
|
|
3349
|
+
}`);
|
|
3350
|
+
}
|
|
3351
|
+
blocks.push(`${global} = {
|
|
3352
|
+
${properties.join(",\n ")}
|
|
3353
|
+
};`);
|
|
3354
|
+
const args = ["element"];
|
|
3355
|
+
blocks.push("const element = document.currentScript.parentElement;");
|
|
3356
|
+
if (page_config.ssr) {
|
|
3357
|
+
const serialized = { form: "null", error: "null" };
|
|
3358
|
+
if (form_value) {
|
|
3359
|
+
serialized.form = uneval_action_response(
|
|
3360
|
+
form_value,
|
|
3361
|
+
/** @type {string} */
|
|
3362
|
+
event.route.id,
|
|
3363
|
+
options2.hooks.transport
|
|
3364
|
+
);
|
|
3365
|
+
}
|
|
3366
|
+
if (error) {
|
|
3367
|
+
serialized.error = uneval(error);
|
|
3368
|
+
}
|
|
3369
|
+
const hydrate = [
|
|
3370
|
+
`node_ids: [${branch.map(({ node }) => node.index).join(", ")}]`,
|
|
3371
|
+
`data: ${data}`,
|
|
3372
|
+
`form: ${serialized.form}`,
|
|
3373
|
+
`error: ${serialized.error}`
|
|
3374
|
+
];
|
|
3375
|
+
if (status !== 200) {
|
|
3376
|
+
hydrate.push(`status: ${status}`);
|
|
3377
|
+
}
|
|
3378
|
+
if (options2.embedded) {
|
|
3379
|
+
hydrate.push(`params: ${uneval(event.params)}`, `route: ${s(event.route)}`);
|
|
3380
|
+
}
|
|
3381
|
+
const indent = " ".repeat(load_env_eagerly ? 7 : 6);
|
|
3382
|
+
args.push(`{
|
|
3383
|
+
${indent} ${hydrate.join(`,
|
|
3384
|
+
${indent} `)}
|
|
3385
|
+
${indent}}`);
|
|
3386
|
+
}
|
|
3387
|
+
const boot = client.inline ? `${client.inline.script}
|
|
3388
|
+
|
|
3389
|
+
__sveltekit_${options2.version_hash}.app.start(${args.join(", ")});` : client.app ? `Promise.all([
|
|
3390
|
+
import(${s(prefixed(client.start))}),
|
|
3391
|
+
import(${s(prefixed(client.app))})
|
|
3392
|
+
]).then(([kit, app]) => {
|
|
3393
|
+
kit.start(app, ${args.join(", ")});
|
|
3394
|
+
});` : `import(${s(prefixed(client.start))}).then((app) => {
|
|
3395
|
+
app.start(${args.join(", ")})
|
|
3396
|
+
});`;
|
|
3397
|
+
if (load_env_eagerly) {
|
|
3398
|
+
blocks.push(`import(${s(`${base$1}/${options2.app_dir}/env.js`)}).then(({ env }) => {
|
|
3399
|
+
${global}.env = env;
|
|
3400
|
+
|
|
3401
|
+
${boot.replace(/\n/g, "\n ")}
|
|
3402
|
+
});`);
|
|
3403
|
+
} else {
|
|
3404
|
+
blocks.push(boot);
|
|
3405
|
+
}
|
|
3406
|
+
if (options2.service_worker) {
|
|
3407
|
+
const opts = "";
|
|
3408
|
+
blocks.push(`if ('serviceWorker' in navigator) {
|
|
3409
|
+
addEventListener('load', function () {
|
|
3410
|
+
navigator.serviceWorker.register('${prefixed("service-worker.js")}'${opts});
|
|
3411
|
+
});
|
|
3412
|
+
}`);
|
|
3413
|
+
}
|
|
3414
|
+
const init_app = `
|
|
3415
|
+
{
|
|
3416
|
+
${blocks.join("\n\n ")}
|
|
3417
|
+
}
|
|
3418
|
+
`;
|
|
3419
|
+
csp.add_script(init_app);
|
|
3420
|
+
body2 += `
|
|
3421
|
+
<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>${init_app}<\/script>
|
|
3422
|
+
`;
|
|
3423
|
+
}
|
|
3424
|
+
const headers2 = new Headers({
|
|
3425
|
+
"x-sveltekit-page": "true",
|
|
3426
|
+
"content-type": "text/html"
|
|
3427
|
+
});
|
|
3428
|
+
if (state.prerendering) {
|
|
3429
|
+
const http_equiv = [];
|
|
3430
|
+
const csp_headers = csp.csp_provider.get_meta();
|
|
3431
|
+
if (csp_headers) {
|
|
3432
|
+
http_equiv.push(csp_headers);
|
|
3433
|
+
}
|
|
3434
|
+
if (state.prerendering.cache) {
|
|
3435
|
+
http_equiv.push(`<meta http-equiv="cache-control" content="${state.prerendering.cache}">`);
|
|
3436
|
+
}
|
|
3437
|
+
if (http_equiv.length > 0) {
|
|
3438
|
+
head = http_equiv.join("\n") + head;
|
|
3439
|
+
}
|
|
3440
|
+
} else {
|
|
3441
|
+
const csp_header = csp.csp_provider.get_header();
|
|
3442
|
+
if (csp_header) {
|
|
3443
|
+
headers2.set("content-security-policy", csp_header);
|
|
3444
|
+
}
|
|
3445
|
+
const report_only_header = csp.report_only_provider.get_header();
|
|
3446
|
+
if (report_only_header) {
|
|
3447
|
+
headers2.set("content-security-policy-report-only", report_only_header);
|
|
3448
|
+
}
|
|
3449
|
+
if (link_header_preloads.size) {
|
|
3450
|
+
headers2.set("link", Array.from(link_header_preloads).join(", "));
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
head += rendered.head;
|
|
3454
|
+
const html = options2.templates.app({
|
|
3455
|
+
head,
|
|
3456
|
+
body: body2,
|
|
3457
|
+
assets: assets$1,
|
|
3458
|
+
nonce: (
|
|
3459
|
+
/** @type {string} */
|
|
3460
|
+
csp.nonce
|
|
3461
|
+
),
|
|
3462
|
+
env: safe_public_env
|
|
3463
|
+
});
|
|
3464
|
+
const transformed = await resolve_opts.transformPageChunk({
|
|
3465
|
+
html,
|
|
3466
|
+
done: true
|
|
3467
|
+
}) || "";
|
|
3468
|
+
if (!chunks) {
|
|
3469
|
+
headers2.set("etag", `"${hash(transformed)}"`);
|
|
3470
|
+
}
|
|
3471
|
+
return !chunks ? text(transformed, {
|
|
3472
|
+
status,
|
|
3473
|
+
headers: headers2
|
|
3474
|
+
}) : new Response(
|
|
3475
|
+
new ReadableStream({
|
|
3476
|
+
async start(controller) {
|
|
3477
|
+
controller.enqueue(encoder$1.encode(transformed + "\n"));
|
|
3478
|
+
for await (const chunk of chunks) {
|
|
3479
|
+
controller.enqueue(encoder$1.encode(chunk));
|
|
3480
|
+
}
|
|
3481
|
+
controller.close();
|
|
3482
|
+
},
|
|
3483
|
+
type: "bytes"
|
|
3484
|
+
}),
|
|
3485
|
+
{
|
|
3486
|
+
headers: headers2
|
|
3487
|
+
}
|
|
3488
|
+
);
|
|
3489
|
+
}
|
|
3490
|
+
function get_data(event, options2, nodes, csp, global) {
|
|
3491
|
+
let promise_id = 1;
|
|
3492
|
+
let count = 0;
|
|
3493
|
+
const { iterator, push, done } = create_async_iterator();
|
|
3494
|
+
function replacer(thing) {
|
|
3495
|
+
if (typeof thing?.then === "function") {
|
|
3496
|
+
const id = promise_id++;
|
|
3497
|
+
count += 1;
|
|
3498
|
+
thing.then(
|
|
3499
|
+
/** @param {any} data */
|
|
3500
|
+
(data) => ({ data })
|
|
3501
|
+
).catch(
|
|
3502
|
+
/** @param {any} error */
|
|
3503
|
+
async (error) => ({
|
|
3504
|
+
error: await handle_error_and_jsonify(event, options2, error)
|
|
3505
|
+
})
|
|
3506
|
+
).then(
|
|
3507
|
+
/**
|
|
3508
|
+
* @param {{data: any; error: any}} result
|
|
3509
|
+
*/
|
|
3510
|
+
async ({ data, error }) => {
|
|
3511
|
+
count -= 1;
|
|
3512
|
+
let str;
|
|
3513
|
+
try {
|
|
3514
|
+
str = uneval({ id, data, error }, replacer);
|
|
3515
|
+
} catch {
|
|
3516
|
+
error = await handle_error_and_jsonify(
|
|
3517
|
+
event,
|
|
3518
|
+
options2,
|
|
3519
|
+
new Error(`Failed to serialize promise while rendering ${event.route.id}`)
|
|
3520
|
+
);
|
|
3521
|
+
data = void 0;
|
|
3522
|
+
str = uneval({ id, data, error }, replacer);
|
|
3523
|
+
}
|
|
3524
|
+
const nonce = csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : "";
|
|
3525
|
+
push(`<script${nonce}>${global}.resolve(${str})<\/script>
|
|
3526
|
+
`);
|
|
3527
|
+
if (count === 0) done();
|
|
3528
|
+
}
|
|
3529
|
+
);
|
|
3530
|
+
return `${global}.defer(${id})`;
|
|
3531
|
+
} else {
|
|
3532
|
+
for (const key2 in options2.hooks.transport) {
|
|
3533
|
+
const encoded = options2.hooks.transport[key2].encode(thing);
|
|
3534
|
+
if (encoded) {
|
|
3535
|
+
return `app.decode('${key2}', ${uneval(encoded, replacer)})`;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
try {
|
|
3541
|
+
const strings = nodes.map((node) => {
|
|
3542
|
+
if (!node) return "null";
|
|
3543
|
+
return `{"type":"data","data":${uneval(node.data, replacer)},${stringify_uses(node)}${node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ""}}`;
|
|
3544
|
+
});
|
|
3545
|
+
return {
|
|
3546
|
+
data: `[${strings.join(",")}]`,
|
|
3547
|
+
chunks: count > 0 ? iterator : null
|
|
3548
|
+
};
|
|
3549
|
+
} catch (e) {
|
|
3550
|
+
throw new Error(clarify_devalue_error(
|
|
3551
|
+
event,
|
|
3552
|
+
/** @type {any} */
|
|
3553
|
+
e
|
|
3554
|
+
));
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
function get_option(nodes, option) {
|
|
3558
|
+
return nodes.reduce(
|
|
3559
|
+
(value, node) => {
|
|
3560
|
+
return (
|
|
3561
|
+
/** @type {Value} TypeScript's too dumb to understand this */
|
|
3562
|
+
node?.universal?.[option] ?? node?.server?.[option] ?? value
|
|
3563
|
+
);
|
|
3564
|
+
},
|
|
3565
|
+
/** @type {Value | undefined} */
|
|
3566
|
+
void 0
|
|
3567
|
+
);
|
|
3568
|
+
}
|
|
3569
|
+
async function respond_with_error({
|
|
3570
|
+
event,
|
|
3571
|
+
options: options2,
|
|
3572
|
+
manifest,
|
|
3573
|
+
state,
|
|
3574
|
+
status,
|
|
3575
|
+
error,
|
|
3576
|
+
resolve_opts
|
|
3577
|
+
}) {
|
|
3578
|
+
if (event.request.headers.get("x-sveltekit-error")) {
|
|
3579
|
+
return static_error_page(
|
|
3580
|
+
options2,
|
|
3581
|
+
status,
|
|
3582
|
+
/** @type {Error} */
|
|
3583
|
+
error.message
|
|
3584
|
+
);
|
|
3585
|
+
}
|
|
3586
|
+
const fetched = [];
|
|
3587
|
+
try {
|
|
3588
|
+
const branch = [];
|
|
3589
|
+
const default_layout = await manifest._.nodes[0]();
|
|
3590
|
+
const ssr = get_option([default_layout], "ssr") ?? true;
|
|
3591
|
+
const csr = get_option([default_layout], "csr") ?? true;
|
|
3592
|
+
if (ssr) {
|
|
3593
|
+
state.error = true;
|
|
3594
|
+
const server_data_promise = load_server_data({
|
|
3595
|
+
event,
|
|
3596
|
+
state,
|
|
3597
|
+
node: default_layout,
|
|
3598
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3599
|
+
parent: async () => ({})
|
|
3600
|
+
});
|
|
3601
|
+
const server_data = await server_data_promise;
|
|
3602
|
+
const data = await load_data({
|
|
3603
|
+
event,
|
|
3604
|
+
fetched,
|
|
3605
|
+
node: default_layout,
|
|
3606
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3607
|
+
parent: async () => ({}),
|
|
3608
|
+
resolve_opts,
|
|
3609
|
+
server_data_promise,
|
|
3610
|
+
state,
|
|
3611
|
+
csr
|
|
3612
|
+
});
|
|
3613
|
+
branch.push(
|
|
3614
|
+
{
|
|
3615
|
+
node: default_layout,
|
|
3616
|
+
server_data,
|
|
3617
|
+
data
|
|
3618
|
+
},
|
|
3619
|
+
{
|
|
3620
|
+
node: await manifest._.nodes[1](),
|
|
3621
|
+
// 1 is always the root error
|
|
3622
|
+
data: null,
|
|
3623
|
+
server_data: null
|
|
3624
|
+
}
|
|
3625
|
+
);
|
|
3626
|
+
}
|
|
3627
|
+
return await render_response({
|
|
3628
|
+
options: options2,
|
|
3629
|
+
manifest,
|
|
3630
|
+
state,
|
|
3631
|
+
page_config: {
|
|
3632
|
+
ssr,
|
|
3633
|
+
csr
|
|
3634
|
+
},
|
|
3635
|
+
status,
|
|
3636
|
+
error: await handle_error_and_jsonify(event, options2, error),
|
|
3637
|
+
branch,
|
|
3638
|
+
fetched,
|
|
3639
|
+
event,
|
|
3640
|
+
resolve_opts
|
|
3641
|
+
});
|
|
3642
|
+
} catch (e) {
|
|
3643
|
+
if (e instanceof Redirect) {
|
|
3644
|
+
return redirect_response(e.status, e.location);
|
|
3645
|
+
}
|
|
3646
|
+
return static_error_page(
|
|
3647
|
+
options2,
|
|
3648
|
+
get_status(e),
|
|
3649
|
+
(await handle_error_and_jsonify(event, options2, e)).message
|
|
3650
|
+
);
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
function once(fn) {
|
|
3654
|
+
let done = false;
|
|
3655
|
+
let result;
|
|
3656
|
+
return () => {
|
|
3657
|
+
if (done) return result;
|
|
3658
|
+
done = true;
|
|
3659
|
+
return result = fn();
|
|
3660
|
+
};
|
|
3661
|
+
}
|
|
3662
|
+
const encoder = new TextEncoder();
|
|
3663
|
+
async function render_data(event, route, options2, manifest, state, invalidated_data_nodes, trailing_slash) {
|
|
3664
|
+
if (!route.page) {
|
|
3665
|
+
return new Response(void 0, {
|
|
3666
|
+
status: 404
|
|
3667
|
+
});
|
|
3668
|
+
}
|
|
3669
|
+
try {
|
|
3670
|
+
const node_ids = [...route.page.layouts, route.page.leaf];
|
|
3671
|
+
const invalidated = invalidated_data_nodes ?? node_ids.map(() => true);
|
|
3672
|
+
let aborted = false;
|
|
3673
|
+
const url = new URL(event.url);
|
|
3674
|
+
url.pathname = normalize_path(url.pathname, trailing_slash);
|
|
3675
|
+
const new_event = { ...event, url };
|
|
3676
|
+
const functions = node_ids.map((n, i) => {
|
|
3677
|
+
return once(async () => {
|
|
3678
|
+
try {
|
|
3679
|
+
if (aborted) {
|
|
3680
|
+
return (
|
|
3681
|
+
/** @type {import('types').ServerDataSkippedNode} */
|
|
3682
|
+
{
|
|
3683
|
+
type: "skip"
|
|
3684
|
+
}
|
|
3685
|
+
);
|
|
3686
|
+
}
|
|
3687
|
+
const node = n == void 0 ? n : await manifest._.nodes[n]();
|
|
3688
|
+
return load_server_data({
|
|
3689
|
+
event: new_event,
|
|
3690
|
+
state,
|
|
3691
|
+
node,
|
|
3692
|
+
parent: async () => {
|
|
3693
|
+
const data2 = {};
|
|
3694
|
+
for (let j = 0; j < i; j += 1) {
|
|
3695
|
+
const parent = (
|
|
3696
|
+
/** @type {import('types').ServerDataNode | null} */
|
|
3697
|
+
await functions[j]()
|
|
3698
|
+
);
|
|
3699
|
+
if (parent) {
|
|
3700
|
+
Object.assign(data2, parent.data);
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
return data2;
|
|
3704
|
+
}
|
|
3705
|
+
});
|
|
3706
|
+
} catch (e) {
|
|
3707
|
+
aborted = true;
|
|
3708
|
+
throw e;
|
|
3709
|
+
}
|
|
3710
|
+
});
|
|
3711
|
+
});
|
|
3712
|
+
const promises = functions.map(async (fn, i) => {
|
|
3713
|
+
if (!invalidated[i]) {
|
|
3714
|
+
return (
|
|
3715
|
+
/** @type {import('types').ServerDataSkippedNode} */
|
|
3716
|
+
{
|
|
3717
|
+
type: "skip"
|
|
3718
|
+
}
|
|
3719
|
+
);
|
|
3720
|
+
}
|
|
3721
|
+
return fn();
|
|
3722
|
+
});
|
|
3723
|
+
let length = promises.length;
|
|
3724
|
+
const nodes = await Promise.all(
|
|
3725
|
+
promises.map(
|
|
3726
|
+
(p, i) => p.catch(async (error) => {
|
|
3727
|
+
if (error instanceof Redirect) {
|
|
3728
|
+
throw error;
|
|
3729
|
+
}
|
|
3730
|
+
length = Math.min(length, i + 1);
|
|
3731
|
+
return (
|
|
3732
|
+
/** @type {import('types').ServerErrorNode} */
|
|
3733
|
+
{
|
|
3734
|
+
type: "error",
|
|
3735
|
+
error: await handle_error_and_jsonify(event, options2, error),
|
|
3736
|
+
status: error instanceof HttpError || error instanceof SvelteKitError ? error.status : void 0
|
|
3737
|
+
}
|
|
3738
|
+
);
|
|
3739
|
+
})
|
|
3740
|
+
)
|
|
3741
|
+
);
|
|
3742
|
+
const { data, chunks } = get_data_json(event, options2, nodes);
|
|
3743
|
+
if (!chunks) {
|
|
3744
|
+
return json_response(data);
|
|
3745
|
+
}
|
|
3746
|
+
return new Response(
|
|
3747
|
+
new ReadableStream({
|
|
3748
|
+
async start(controller) {
|
|
3749
|
+
controller.enqueue(encoder.encode(data));
|
|
3750
|
+
for await (const chunk of chunks) {
|
|
3751
|
+
controller.enqueue(encoder.encode(chunk));
|
|
3752
|
+
}
|
|
3753
|
+
controller.close();
|
|
3754
|
+
},
|
|
3755
|
+
type: "bytes"
|
|
3756
|
+
}),
|
|
3757
|
+
{
|
|
3758
|
+
headers: {
|
|
3759
|
+
// we use a proprietary content type to prevent buffering.
|
|
3760
|
+
// the `text` prefix makes it inspectable
|
|
3761
|
+
"content-type": "text/sveltekit-data",
|
|
3762
|
+
"cache-control": "private, no-store"
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
);
|
|
3766
|
+
} catch (e) {
|
|
3767
|
+
const error = normalize_error(e);
|
|
3768
|
+
if (error instanceof Redirect) {
|
|
3769
|
+
return redirect_json_response(error);
|
|
3770
|
+
} else {
|
|
3771
|
+
return json_response(await handle_error_and_jsonify(event, options2, error), 500);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
function json_response(json2, status = 200) {
|
|
3776
|
+
return text(typeof json2 === "string" ? json2 : JSON.stringify(json2), {
|
|
3777
|
+
status,
|
|
3778
|
+
headers: {
|
|
3779
|
+
"content-type": "application/json",
|
|
3780
|
+
"cache-control": "private, no-store"
|
|
3781
|
+
}
|
|
3782
|
+
});
|
|
3783
|
+
}
|
|
3784
|
+
function redirect_json_response(redirect) {
|
|
3785
|
+
return json_response({
|
|
3786
|
+
type: "redirect",
|
|
3787
|
+
location: redirect.location
|
|
3788
|
+
});
|
|
3789
|
+
}
|
|
3790
|
+
function get_data_json(event, options2, nodes) {
|
|
3791
|
+
let promise_id = 1;
|
|
3792
|
+
let count = 0;
|
|
3793
|
+
const { iterator, push, done } = create_async_iterator();
|
|
3794
|
+
const reducers = {
|
|
3795
|
+
...Object.fromEntries(
|
|
3796
|
+
Object.entries(options2.hooks.transport).map(([key2, value]) => [key2, value.encode])
|
|
3797
|
+
),
|
|
3798
|
+
/** @param {any} thing */
|
|
3799
|
+
Promise: (thing) => {
|
|
3800
|
+
if (typeof thing?.then === "function") {
|
|
3801
|
+
const id = promise_id++;
|
|
3802
|
+
count += 1;
|
|
3803
|
+
let key2 = "data";
|
|
3804
|
+
thing.catch(
|
|
3805
|
+
/** @param {any} e */
|
|
3806
|
+
async (e) => {
|
|
3807
|
+
key2 = "error";
|
|
3808
|
+
return handle_error_and_jsonify(
|
|
3809
|
+
event,
|
|
3810
|
+
options2,
|
|
3811
|
+
/** @type {any} */
|
|
3812
|
+
e
|
|
3813
|
+
);
|
|
3814
|
+
}
|
|
3815
|
+
).then(
|
|
3816
|
+
/** @param {any} value */
|
|
3817
|
+
async (value) => {
|
|
3818
|
+
let str;
|
|
3819
|
+
try {
|
|
3820
|
+
str = stringify(value, reducers);
|
|
3821
|
+
} catch {
|
|
3822
|
+
const error = await handle_error_and_jsonify(
|
|
3823
|
+
event,
|
|
3824
|
+
options2,
|
|
3825
|
+
new Error(`Failed to serialize promise while rendering ${event.route.id}`)
|
|
3826
|
+
);
|
|
3827
|
+
key2 = "error";
|
|
3828
|
+
str = stringify(error, reducers);
|
|
3829
|
+
}
|
|
3830
|
+
count -= 1;
|
|
3831
|
+
push(`{"type":"chunk","id":${id},"${key2}":${str}}
|
|
3832
|
+
`);
|
|
3833
|
+
if (count === 0) done();
|
|
3834
|
+
}
|
|
3835
|
+
);
|
|
3836
|
+
return id;
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
};
|
|
3840
|
+
try {
|
|
3841
|
+
const strings = nodes.map((node) => {
|
|
3842
|
+
if (!node) return "null";
|
|
3843
|
+
if (node.type === "error" || node.type === "skip") {
|
|
3844
|
+
return JSON.stringify(node);
|
|
3845
|
+
}
|
|
3846
|
+
return `{"type":"data","data":${stringify(node.data, reducers)},${stringify_uses(
|
|
3847
|
+
node
|
|
3848
|
+
)}${node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ""}}`;
|
|
3849
|
+
});
|
|
3850
|
+
return {
|
|
3851
|
+
data: `{"type":"data","nodes":[${strings.join(",")}]}
|
|
3852
|
+
`,
|
|
3853
|
+
chunks: count > 0 ? iterator : null
|
|
3854
|
+
};
|
|
3855
|
+
} catch (e) {
|
|
3856
|
+
throw new Error(clarify_devalue_error(
|
|
3857
|
+
event,
|
|
3858
|
+
/** @type {any} */
|
|
3859
|
+
e
|
|
3860
|
+
));
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
function load_page_nodes(page, manifest) {
|
|
3864
|
+
return Promise.all([
|
|
3865
|
+
// we use == here rather than === because [undefined] serializes as "[null]"
|
|
3866
|
+
...page.layouts.map((n) => n == void 0 ? n : manifest._.nodes[n]()),
|
|
3867
|
+
manifest._.nodes[page.leaf]()
|
|
3868
|
+
]);
|
|
3869
|
+
}
|
|
3870
|
+
const MAX_DEPTH = 10;
|
|
3871
|
+
async function render_page(event, page, options2, manifest, state, resolve_opts) {
|
|
3872
|
+
if (state.depth > MAX_DEPTH) {
|
|
3873
|
+
return text(`Not found: ${event.url.pathname}`, {
|
|
3874
|
+
status: 404
|
|
3875
|
+
// TODO in some cases this should be 500. not sure how to differentiate
|
|
3876
|
+
});
|
|
3877
|
+
}
|
|
3878
|
+
if (is_action_json_request(event)) {
|
|
3879
|
+
const node = await manifest._.nodes[page.leaf]();
|
|
3880
|
+
return handle_action_json_request(event, options2, node?.server);
|
|
3881
|
+
}
|
|
3882
|
+
try {
|
|
3883
|
+
const nodes = await load_page_nodes(page, manifest);
|
|
3884
|
+
const leaf_node = (
|
|
3885
|
+
/** @type {import('types').SSRNode} */
|
|
3886
|
+
nodes.at(-1)
|
|
3887
|
+
);
|
|
3888
|
+
let status = 200;
|
|
3889
|
+
let action_result = void 0;
|
|
3890
|
+
if (is_action_request(event)) {
|
|
3891
|
+
action_result = await handle_action_request(event, leaf_node.server);
|
|
3892
|
+
if (action_result?.type === "redirect") {
|
|
3893
|
+
return redirect_response(action_result.status, action_result.location);
|
|
3894
|
+
}
|
|
3895
|
+
if (action_result?.type === "error") {
|
|
3896
|
+
status = get_status(action_result.error);
|
|
3897
|
+
}
|
|
3898
|
+
if (action_result?.type === "failure") {
|
|
3899
|
+
status = action_result.status;
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
const should_prerender_data = nodes.some((node) => node?.server?.load);
|
|
3903
|
+
const data_pathname = add_data_suffix(event.url.pathname);
|
|
3904
|
+
const should_prerender = get_option(nodes, "prerender") ?? false;
|
|
3905
|
+
if (should_prerender) {
|
|
3906
|
+
const mod = leaf_node.server;
|
|
3907
|
+
if (mod?.actions) {
|
|
3908
|
+
throw new Error("Cannot prerender pages with actions");
|
|
3909
|
+
}
|
|
3910
|
+
} else if (state.prerendering) {
|
|
3911
|
+
return new Response(void 0, {
|
|
3912
|
+
status: 204
|
|
3913
|
+
});
|
|
3914
|
+
}
|
|
3915
|
+
state.prerender_default = should_prerender;
|
|
3916
|
+
const fetched = [];
|
|
3917
|
+
if (get_option(nodes, "ssr") === false && !(state.prerendering && should_prerender_data)) {
|
|
3918
|
+
if (BROWSER && action_result && !event.request.headers.has("x-sveltekit-action")) ;
|
|
3919
|
+
return await render_response({
|
|
3920
|
+
branch: [],
|
|
3921
|
+
fetched,
|
|
3922
|
+
page_config: {
|
|
3923
|
+
ssr: false,
|
|
3924
|
+
csr: get_option(nodes, "csr") ?? true
|
|
3925
|
+
},
|
|
3926
|
+
status,
|
|
3927
|
+
error: null,
|
|
3928
|
+
event,
|
|
3929
|
+
options: options2,
|
|
3930
|
+
manifest,
|
|
3931
|
+
state,
|
|
3932
|
+
resolve_opts
|
|
3933
|
+
});
|
|
3934
|
+
}
|
|
3935
|
+
const branch = [];
|
|
3936
|
+
let load_error = null;
|
|
3937
|
+
const server_promises = nodes.map((node, i) => {
|
|
3938
|
+
if (load_error) {
|
|
3939
|
+
throw load_error;
|
|
3940
|
+
}
|
|
3941
|
+
return Promise.resolve().then(async () => {
|
|
3942
|
+
try {
|
|
3943
|
+
if (node === leaf_node && action_result?.type === "error") {
|
|
3944
|
+
throw action_result.error;
|
|
3945
|
+
}
|
|
3946
|
+
return await load_server_data({
|
|
3947
|
+
event,
|
|
3948
|
+
state,
|
|
3949
|
+
node,
|
|
3950
|
+
parent: async () => {
|
|
3951
|
+
const data = {};
|
|
3952
|
+
for (let j = 0; j < i; j += 1) {
|
|
3953
|
+
const parent = await server_promises[j];
|
|
3954
|
+
if (parent) Object.assign(data, parent.data);
|
|
3955
|
+
}
|
|
3956
|
+
return data;
|
|
3957
|
+
}
|
|
3958
|
+
});
|
|
3959
|
+
} catch (e) {
|
|
3960
|
+
load_error = /** @type {Error} */
|
|
3961
|
+
e;
|
|
3962
|
+
throw load_error;
|
|
3963
|
+
}
|
|
3964
|
+
});
|
|
3965
|
+
});
|
|
3966
|
+
const csr = get_option(nodes, "csr") ?? true;
|
|
3967
|
+
const load_promises = nodes.map((node, i) => {
|
|
3968
|
+
if (load_error) throw load_error;
|
|
3969
|
+
return Promise.resolve().then(async () => {
|
|
3970
|
+
try {
|
|
3971
|
+
return await load_data({
|
|
3972
|
+
event,
|
|
3973
|
+
fetched,
|
|
3974
|
+
node,
|
|
3975
|
+
parent: async () => {
|
|
3976
|
+
const data = {};
|
|
3977
|
+
for (let j = 0; j < i; j += 1) {
|
|
3978
|
+
Object.assign(data, await load_promises[j]);
|
|
3979
|
+
}
|
|
3980
|
+
return data;
|
|
3981
|
+
},
|
|
3982
|
+
resolve_opts,
|
|
3983
|
+
server_data_promise: server_promises[i],
|
|
3984
|
+
state,
|
|
3985
|
+
csr
|
|
3986
|
+
});
|
|
3987
|
+
} catch (e) {
|
|
3988
|
+
load_error = /** @type {Error} */
|
|
3989
|
+
e;
|
|
3990
|
+
throw load_error;
|
|
3991
|
+
}
|
|
3992
|
+
});
|
|
3993
|
+
});
|
|
3994
|
+
for (const p of server_promises) p.catch(() => {
|
|
3995
|
+
});
|
|
3996
|
+
for (const p of load_promises) p.catch(() => {
|
|
3997
|
+
});
|
|
3998
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
3999
|
+
const node = nodes[i];
|
|
4000
|
+
if (node) {
|
|
4001
|
+
try {
|
|
4002
|
+
const server_data = await server_promises[i];
|
|
4003
|
+
const data = await load_promises[i];
|
|
4004
|
+
branch.push({ node, server_data, data });
|
|
4005
|
+
} catch (e) {
|
|
4006
|
+
const err = normalize_error(e);
|
|
4007
|
+
if (err instanceof Redirect) {
|
|
4008
|
+
if (state.prerendering && should_prerender_data) {
|
|
4009
|
+
const body2 = JSON.stringify({
|
|
4010
|
+
type: "redirect",
|
|
4011
|
+
location: err.location
|
|
4012
|
+
});
|
|
4013
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
4014
|
+
response: text(body2),
|
|
4015
|
+
body: body2
|
|
4016
|
+
});
|
|
4017
|
+
}
|
|
4018
|
+
return redirect_response(err.status, err.location);
|
|
4019
|
+
}
|
|
4020
|
+
const status2 = get_status(err);
|
|
4021
|
+
const error = await handle_error_and_jsonify(event, options2, err);
|
|
4022
|
+
while (i--) {
|
|
4023
|
+
if (page.errors[i]) {
|
|
4024
|
+
const index = (
|
|
4025
|
+
/** @type {number} */
|
|
4026
|
+
page.errors[i]
|
|
4027
|
+
);
|
|
4028
|
+
const node2 = await manifest._.nodes[index]();
|
|
4029
|
+
let j = i;
|
|
4030
|
+
while (!branch[j]) j -= 1;
|
|
4031
|
+
return await render_response({
|
|
4032
|
+
event,
|
|
4033
|
+
options: options2,
|
|
4034
|
+
manifest,
|
|
4035
|
+
state,
|
|
4036
|
+
resolve_opts,
|
|
4037
|
+
page_config: { ssr: true, csr: true },
|
|
4038
|
+
status: status2,
|
|
4039
|
+
error,
|
|
4040
|
+
branch: compact(branch.slice(0, j + 1)).concat({
|
|
4041
|
+
node: node2,
|
|
4042
|
+
data: null,
|
|
4043
|
+
server_data: null
|
|
4044
|
+
}),
|
|
4045
|
+
fetched
|
|
4046
|
+
});
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
return static_error_page(options2, status2, error.message);
|
|
4050
|
+
}
|
|
4051
|
+
} else {
|
|
4052
|
+
branch.push(null);
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
if (state.prerendering && should_prerender_data) {
|
|
4056
|
+
let { data, chunks } = get_data_json(
|
|
4057
|
+
event,
|
|
4058
|
+
options2,
|
|
4059
|
+
branch.map((node) => node?.server_data)
|
|
4060
|
+
);
|
|
4061
|
+
if (chunks) {
|
|
4062
|
+
for await (const chunk of chunks) {
|
|
4063
|
+
data += chunk;
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
4067
|
+
response: text(data),
|
|
4068
|
+
body: data
|
|
4069
|
+
});
|
|
4070
|
+
}
|
|
4071
|
+
const ssr = get_option(nodes, "ssr") ?? true;
|
|
4072
|
+
return await render_response({
|
|
4073
|
+
event,
|
|
4074
|
+
options: options2,
|
|
4075
|
+
manifest,
|
|
4076
|
+
state,
|
|
4077
|
+
resolve_opts,
|
|
4078
|
+
page_config: {
|
|
4079
|
+
csr: get_option(nodes, "csr") ?? true,
|
|
4080
|
+
ssr
|
|
4081
|
+
},
|
|
4082
|
+
status,
|
|
4083
|
+
error: null,
|
|
4084
|
+
branch: ssr === false ? [] : compact(branch),
|
|
4085
|
+
action_result,
|
|
4086
|
+
fetched
|
|
4087
|
+
});
|
|
4088
|
+
} catch (e) {
|
|
4089
|
+
return await respond_with_error({
|
|
4090
|
+
event,
|
|
4091
|
+
options: options2,
|
|
4092
|
+
manifest,
|
|
4093
|
+
state,
|
|
4094
|
+
status: 500,
|
|
4095
|
+
error: e,
|
|
4096
|
+
resolve_opts
|
|
4097
|
+
});
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
function exec(match, params, matchers) {
|
|
4101
|
+
const result = {};
|
|
4102
|
+
const values = match.slice(1);
|
|
4103
|
+
const values_needing_match = values.filter((value) => value !== void 0);
|
|
4104
|
+
let buffered = 0;
|
|
4105
|
+
for (let i = 0; i < params.length; i += 1) {
|
|
4106
|
+
const param = params[i];
|
|
4107
|
+
let value = values[i - buffered];
|
|
4108
|
+
if (param.chained && param.rest && buffered) {
|
|
4109
|
+
value = values.slice(i - buffered, i + 1).filter((s2) => s2).join("/");
|
|
4110
|
+
buffered = 0;
|
|
4111
|
+
}
|
|
4112
|
+
if (value === void 0) {
|
|
4113
|
+
if (param.rest) result[param.name] = "";
|
|
4114
|
+
continue;
|
|
4115
|
+
}
|
|
4116
|
+
if (!param.matcher || matchers[param.matcher](value)) {
|
|
4117
|
+
result[param.name] = value;
|
|
4118
|
+
const next_param = params[i + 1];
|
|
4119
|
+
const next_value = values[i + 1];
|
|
4120
|
+
if (next_param && !next_param.rest && next_param.optional && next_value && param.chained) {
|
|
4121
|
+
buffered = 0;
|
|
4122
|
+
}
|
|
4123
|
+
if (!next_param && !next_value && Object.keys(result).length === values_needing_match.length) {
|
|
4124
|
+
buffered = 0;
|
|
4125
|
+
}
|
|
4126
|
+
continue;
|
|
4127
|
+
}
|
|
4128
|
+
if (param.optional && param.chained) {
|
|
4129
|
+
buffered++;
|
|
4130
|
+
continue;
|
|
4131
|
+
}
|
|
4132
|
+
return;
|
|
4133
|
+
}
|
|
4134
|
+
if (buffered) return;
|
|
4135
|
+
return result;
|
|
4136
|
+
}
|
|
4137
|
+
const INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/;
|
|
4138
|
+
function validate_options(options2) {
|
|
4139
|
+
if (options2?.path === void 0) {
|
|
4140
|
+
throw new Error("You must specify a `path` when setting, deleting or serializing cookies");
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
function get_cookies(request, url, trailing_slash) {
|
|
4144
|
+
const header = request.headers.get("cookie") ?? "";
|
|
4145
|
+
const initial_cookies = cookieExports.parse(header, { decode: (value) => value });
|
|
4146
|
+
const normalized_url = normalize_path(url.pathname, trailing_slash);
|
|
4147
|
+
const new_cookies = {};
|
|
4148
|
+
const defaults = {
|
|
4149
|
+
httpOnly: true,
|
|
4150
|
+
sameSite: "lax",
|
|
4151
|
+
secure: url.hostname === "localhost" && url.protocol === "http:" ? false : true
|
|
4152
|
+
};
|
|
4153
|
+
const cookies = {
|
|
4154
|
+
// The JSDoc param annotations appearing below for get, set and delete
|
|
4155
|
+
// are necessary to expose the `cookie` library types to
|
|
4156
|
+
// typescript users. `@type {import('@sveltejs/kit').Cookies}` above is not
|
|
4157
|
+
// sufficient to do so.
|
|
4158
|
+
/**
|
|
4159
|
+
* @param {string} name
|
|
4160
|
+
* @param {import('cookie').CookieParseOptions} opts
|
|
4161
|
+
*/
|
|
4162
|
+
get(name, opts) {
|
|
4163
|
+
const c = new_cookies[name];
|
|
4164
|
+
if (c && domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path)) {
|
|
4165
|
+
return c.value;
|
|
4166
|
+
}
|
|
4167
|
+
const req_cookies = cookieExports.parse(header, { decode: opts?.decode });
|
|
4168
|
+
const cookie = req_cookies[name];
|
|
4169
|
+
return cookie;
|
|
4170
|
+
},
|
|
4171
|
+
/**
|
|
4172
|
+
* @param {import('cookie').CookieParseOptions} opts
|
|
4173
|
+
*/
|
|
4174
|
+
getAll(opts) {
|
|
4175
|
+
const cookies2 = cookieExports.parse(header, { decode: opts?.decode });
|
|
4176
|
+
for (const c of Object.values(new_cookies)) {
|
|
4177
|
+
if (domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path)) {
|
|
4178
|
+
cookies2[c.name] = c.value;
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
return Object.entries(cookies2).map(([name, value]) => ({ name, value }));
|
|
4182
|
+
},
|
|
4183
|
+
/**
|
|
4184
|
+
* @param {string} name
|
|
4185
|
+
* @param {string} value
|
|
4186
|
+
* @param {import('./page/types.js').Cookie['options']} options
|
|
4187
|
+
*/
|
|
4188
|
+
set(name, value, options2) {
|
|
4189
|
+
const illegal_characters = name.match(INVALID_COOKIE_CHARACTER_REGEX);
|
|
4190
|
+
if (illegal_characters) {
|
|
4191
|
+
console.warn(
|
|
4192
|
+
`The cookie name "${name}" will be invalid in SvelteKit 3.0 as it contains ${illegal_characters.join(
|
|
4193
|
+
" and "
|
|
4194
|
+
)}. See RFC 2616 for more details https://datatracker.ietf.org/doc/html/rfc2616#section-2.2`
|
|
4195
|
+
);
|
|
4196
|
+
}
|
|
4197
|
+
validate_options(options2);
|
|
4198
|
+
set_internal(name, value, { ...defaults, ...options2 });
|
|
4199
|
+
},
|
|
4200
|
+
/**
|
|
4201
|
+
* @param {string} name
|
|
4202
|
+
* @param {import('./page/types.js').Cookie['options']} options
|
|
4203
|
+
*/
|
|
4204
|
+
delete(name, options2) {
|
|
4205
|
+
validate_options(options2);
|
|
4206
|
+
cookies.set(name, "", { ...options2, maxAge: 0 });
|
|
4207
|
+
},
|
|
4208
|
+
/**
|
|
4209
|
+
* @param {string} name
|
|
4210
|
+
* @param {string} value
|
|
4211
|
+
* @param {import('./page/types.js').Cookie['options']} options
|
|
4212
|
+
*/
|
|
4213
|
+
serialize(name, value, options2) {
|
|
4214
|
+
validate_options(options2);
|
|
4215
|
+
let path = options2.path;
|
|
4216
|
+
if (!options2.domain || options2.domain === url.hostname) {
|
|
4217
|
+
path = resolve(normalized_url, path);
|
|
4218
|
+
}
|
|
4219
|
+
return cookieExports.serialize(name, value, { ...defaults, ...options2, path });
|
|
4220
|
+
}
|
|
4221
|
+
};
|
|
4222
|
+
function get_cookie_header(destination, header2) {
|
|
4223
|
+
const combined_cookies = {
|
|
4224
|
+
// cookies sent by the user agent have lowest precedence
|
|
4225
|
+
...initial_cookies
|
|
4226
|
+
};
|
|
4227
|
+
for (const key2 in new_cookies) {
|
|
4228
|
+
const cookie = new_cookies[key2];
|
|
4229
|
+
if (!domain_matches(destination.hostname, cookie.options.domain)) continue;
|
|
4230
|
+
if (!path_matches(destination.pathname, cookie.options.path)) continue;
|
|
4231
|
+
const encoder2 = cookie.options.encode || encodeURIComponent;
|
|
4232
|
+
combined_cookies[cookie.name] = encoder2(cookie.value);
|
|
4233
|
+
}
|
|
4234
|
+
if (header2) {
|
|
4235
|
+
const parsed = cookieExports.parse(header2, { decode: (value) => value });
|
|
4236
|
+
for (const name in parsed) {
|
|
4237
|
+
combined_cookies[name] = parsed[name];
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
return Object.entries(combined_cookies).map(([name, value]) => `${name}=${value}`).join("; ");
|
|
4241
|
+
}
|
|
4242
|
+
function set_internal(name, value, options2) {
|
|
4243
|
+
let path = options2.path;
|
|
4244
|
+
if (!options2.domain || options2.domain === url.hostname) {
|
|
4245
|
+
path = resolve(normalized_url, path);
|
|
4246
|
+
}
|
|
4247
|
+
new_cookies[name] = { name, value, options: { ...options2, path } };
|
|
4248
|
+
}
|
|
4249
|
+
return { cookies, new_cookies, get_cookie_header, set_internal };
|
|
4250
|
+
}
|
|
4251
|
+
function domain_matches(hostname, constraint) {
|
|
4252
|
+
if (!constraint) return true;
|
|
4253
|
+
const normalized = constraint[0] === "." ? constraint.slice(1) : constraint;
|
|
4254
|
+
if (hostname === normalized) return true;
|
|
4255
|
+
return hostname.endsWith("." + normalized);
|
|
4256
|
+
}
|
|
4257
|
+
function path_matches(path, constraint) {
|
|
4258
|
+
if (!constraint) return true;
|
|
4259
|
+
const normalized = constraint.endsWith("/") ? constraint.slice(0, -1) : constraint;
|
|
4260
|
+
if (path === normalized) return true;
|
|
4261
|
+
return path.startsWith(normalized + "/");
|
|
4262
|
+
}
|
|
4263
|
+
function add_cookies_to_headers(headers2, cookies) {
|
|
4264
|
+
for (const new_cookie of cookies) {
|
|
4265
|
+
const { name, value, options: options2 } = new_cookie;
|
|
4266
|
+
headers2.append("set-cookie", cookieExports.serialize(name, value, options2));
|
|
4267
|
+
if (options2.path.endsWith(".html")) {
|
|
4268
|
+
const path = add_data_suffix(options2.path);
|
|
4269
|
+
headers2.append("set-cookie", cookieExports.serialize(name, value, { ...options2, path }));
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4273
|
+
function create_fetch({ event, options: options2, manifest, state, get_cookie_header, set_internal }) {
|
|
4274
|
+
const server_fetch = async (info, init2) => {
|
|
4275
|
+
const original_request = normalize_fetch_input(info, init2, event.url);
|
|
4276
|
+
let mode = (info instanceof Request ? info.mode : init2?.mode) ?? "cors";
|
|
4277
|
+
let credentials = (info instanceof Request ? info.credentials : init2?.credentials) ?? "same-origin";
|
|
4278
|
+
return options2.hooks.handleFetch({
|
|
4279
|
+
event,
|
|
4280
|
+
request: original_request,
|
|
4281
|
+
fetch: async (info2, init3) => {
|
|
4282
|
+
const request = normalize_fetch_input(info2, init3, event.url);
|
|
4283
|
+
const url = new URL(request.url);
|
|
4284
|
+
if (!request.headers.has("origin")) {
|
|
4285
|
+
request.headers.set("origin", event.url.origin);
|
|
4286
|
+
}
|
|
4287
|
+
if (info2 !== original_request) {
|
|
4288
|
+
mode = (info2 instanceof Request ? info2.mode : init3?.mode) ?? "cors";
|
|
4289
|
+
credentials = (info2 instanceof Request ? info2.credentials : init3?.credentials) ?? "same-origin";
|
|
4290
|
+
}
|
|
4291
|
+
if ((request.method === "GET" || request.method === "HEAD") && (mode === "no-cors" && url.origin !== event.url.origin || url.origin === event.url.origin)) {
|
|
4292
|
+
request.headers.delete("origin");
|
|
4293
|
+
}
|
|
4294
|
+
if (url.origin !== event.url.origin) {
|
|
4295
|
+
if (`.${url.hostname}`.endsWith(`.${event.url.hostname}`) && credentials !== "omit") {
|
|
4296
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
4297
|
+
if (cookie) request.headers.set("cookie", cookie);
|
|
4298
|
+
}
|
|
4299
|
+
return fetch(request);
|
|
4300
|
+
}
|
|
4301
|
+
const prefix = assets || base;
|
|
4302
|
+
const decoded = decodeURIComponent(url.pathname);
|
|
4303
|
+
const filename = (decoded.startsWith(prefix) ? decoded.slice(prefix.length) : decoded).slice(1);
|
|
4304
|
+
const filename_html = `${filename}/index.html`;
|
|
4305
|
+
const is_asset = manifest.assets.has(filename) || filename in manifest._.server_assets;
|
|
4306
|
+
const is_asset_html = manifest.assets.has(filename_html) || filename_html in manifest._.server_assets;
|
|
4307
|
+
if (is_asset || is_asset_html) {
|
|
4308
|
+
const file = is_asset ? filename : filename_html;
|
|
4309
|
+
if (state.read) {
|
|
4310
|
+
const type = is_asset ? manifest.mimeTypes[filename.slice(filename.lastIndexOf("."))] : "text/html";
|
|
4311
|
+
return new Response(state.read(file), {
|
|
4312
|
+
headers: type ? { "content-type": type } : {}
|
|
4313
|
+
});
|
|
4314
|
+
} else if (read_implementation && file in manifest._.server_assets) {
|
|
4315
|
+
const length = manifest._.server_assets[file];
|
|
4316
|
+
const type = manifest.mimeTypes[file.slice(file.lastIndexOf("."))];
|
|
4317
|
+
return new Response(read_implementation(file), {
|
|
4318
|
+
headers: {
|
|
4319
|
+
"Content-Length": "" + length,
|
|
4320
|
+
"Content-Type": type
|
|
4321
|
+
}
|
|
4322
|
+
});
|
|
4323
|
+
}
|
|
4324
|
+
return await fetch(request);
|
|
4325
|
+
}
|
|
4326
|
+
if (credentials !== "omit") {
|
|
4327
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
4328
|
+
if (cookie) {
|
|
4329
|
+
request.headers.set("cookie", cookie);
|
|
4330
|
+
}
|
|
4331
|
+
const authorization = event.request.headers.get("authorization");
|
|
4332
|
+
if (authorization && !request.headers.has("authorization")) {
|
|
4333
|
+
request.headers.set("authorization", authorization);
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
if (!request.headers.has("accept")) {
|
|
4337
|
+
request.headers.set("accept", "*/*");
|
|
4338
|
+
}
|
|
4339
|
+
if (!request.headers.has("accept-language")) {
|
|
4340
|
+
request.headers.set(
|
|
4341
|
+
"accept-language",
|
|
4342
|
+
/** @type {string} */
|
|
4343
|
+
event.request.headers.get("accept-language")
|
|
4344
|
+
);
|
|
4345
|
+
}
|
|
4346
|
+
const response = await respond(request, options2, manifest, {
|
|
4347
|
+
...state,
|
|
4348
|
+
depth: state.depth + 1
|
|
4349
|
+
});
|
|
4350
|
+
const set_cookie = response.headers.get("set-cookie");
|
|
4351
|
+
if (set_cookie) {
|
|
4352
|
+
for (const str of setCookieExports.splitCookiesString(set_cookie)) {
|
|
4353
|
+
const { name, value, ...options3 } = setCookieExports.parseString(str, {
|
|
4354
|
+
decodeValues: false
|
|
4355
|
+
});
|
|
4356
|
+
const path = options3.path ?? (url.pathname.split("/").slice(0, -1).join("/") || "/");
|
|
4357
|
+
set_internal(name, value, {
|
|
4358
|
+
path,
|
|
4359
|
+
encode: (value2) => value2,
|
|
4360
|
+
.../** @type {import('cookie').CookieSerializeOptions} */
|
|
4361
|
+
options3
|
|
4362
|
+
});
|
|
4363
|
+
}
|
|
4364
|
+
}
|
|
4365
|
+
return response;
|
|
4366
|
+
}
|
|
4367
|
+
});
|
|
4368
|
+
};
|
|
4369
|
+
return (input, init2) => {
|
|
4370
|
+
const response = server_fetch(input, init2);
|
|
4371
|
+
response.catch(() => {
|
|
4372
|
+
});
|
|
4373
|
+
return response;
|
|
4374
|
+
};
|
|
4375
|
+
}
|
|
4376
|
+
function normalize_fetch_input(info, init2, url) {
|
|
4377
|
+
if (info instanceof Request) {
|
|
4378
|
+
return info;
|
|
4379
|
+
}
|
|
4380
|
+
return new Request(typeof info === "string" ? new URL(info, url) : info, init2);
|
|
4381
|
+
}
|
|
4382
|
+
let body;
|
|
4383
|
+
let etag;
|
|
4384
|
+
let headers;
|
|
4385
|
+
function get_public_env(request) {
|
|
4386
|
+
body ??= `export const env=${JSON.stringify(public_env)}`;
|
|
4387
|
+
etag ??= `W/${Date.now()}`;
|
|
4388
|
+
headers ??= new Headers({
|
|
4389
|
+
"content-type": "application/javascript; charset=utf-8",
|
|
4390
|
+
etag
|
|
4391
|
+
});
|
|
4392
|
+
if (request.headers.get("if-none-match") === etag) {
|
|
4393
|
+
return new Response(void 0, { status: 304, headers });
|
|
4394
|
+
}
|
|
4395
|
+
return new Response(body, { headers });
|
|
4396
|
+
}
|
|
4397
|
+
function get_page_config(nodes) {
|
|
4398
|
+
let current = {};
|
|
4399
|
+
for (const node of nodes) {
|
|
4400
|
+
if (!node?.universal?.config && !node?.server?.config) continue;
|
|
4401
|
+
current = {
|
|
4402
|
+
...current,
|
|
4403
|
+
...node?.universal?.config,
|
|
4404
|
+
...node?.server?.config
|
|
4405
|
+
};
|
|
4406
|
+
}
|
|
4407
|
+
return Object.keys(current).length ? current : void 0;
|
|
4408
|
+
}
|
|
4409
|
+
const default_transform = ({ html }) => html;
|
|
4410
|
+
const default_filter = () => false;
|
|
4411
|
+
const default_preload = ({ type }) => type === "js" || type === "css";
|
|
4412
|
+
const page_methods = /* @__PURE__ */ new Set(["GET", "HEAD", "POST"]);
|
|
4413
|
+
const allowed_page_methods = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
4414
|
+
async function respond(request, options2, manifest, state) {
|
|
4415
|
+
const url = new URL(request.url);
|
|
4416
|
+
if (options2.csrf_check_origin) {
|
|
4417
|
+
const forbidden = is_form_content_type(request) && (request.method === "POST" || request.method === "PUT" || request.method === "PATCH" || request.method === "DELETE") && request.headers.get("origin") !== url.origin;
|
|
4418
|
+
if (forbidden) {
|
|
4419
|
+
const csrf_error = new HttpError(
|
|
4420
|
+
403,
|
|
4421
|
+
`Cross-site ${request.method} form submissions are forbidden`
|
|
4422
|
+
);
|
|
4423
|
+
if (request.headers.get("accept") === "application/json") {
|
|
4424
|
+
return json(csrf_error.body, { status: csrf_error.status });
|
|
4425
|
+
}
|
|
4426
|
+
return text(csrf_error.body.message, { status: csrf_error.status });
|
|
4427
|
+
}
|
|
4428
|
+
}
|
|
4429
|
+
if (options2.hash_routing && url.pathname !== base + "/" && url.pathname !== "/[fallback]") {
|
|
4430
|
+
return text("Not found", { status: 404 });
|
|
4431
|
+
}
|
|
4432
|
+
let rerouted_path;
|
|
4433
|
+
try {
|
|
4434
|
+
rerouted_path = options2.hooks.reroute({ url: new URL(url) }) ?? url.pathname;
|
|
4435
|
+
} catch {
|
|
4436
|
+
return text("Internal Server Error", {
|
|
4437
|
+
status: 500
|
|
4438
|
+
});
|
|
4439
|
+
}
|
|
4440
|
+
let decoded;
|
|
4441
|
+
try {
|
|
4442
|
+
decoded = decode_pathname(rerouted_path);
|
|
4443
|
+
} catch {
|
|
4444
|
+
return text("Malformed URI", { status: 400 });
|
|
4445
|
+
}
|
|
4446
|
+
let route = null;
|
|
4447
|
+
let params = {};
|
|
4448
|
+
if (base && !state.prerendering?.fallback) {
|
|
4449
|
+
if (!decoded.startsWith(base)) {
|
|
4450
|
+
return text("Not found", { status: 404 });
|
|
4451
|
+
}
|
|
4452
|
+
decoded = decoded.slice(base.length) || "/";
|
|
4453
|
+
}
|
|
4454
|
+
if (decoded === `/${options2.app_dir}/env.js`) {
|
|
4455
|
+
return get_public_env(request);
|
|
4456
|
+
}
|
|
4457
|
+
if (decoded.startsWith(`/${options2.app_dir}`)) {
|
|
4458
|
+
const headers22 = new Headers();
|
|
4459
|
+
headers22.set("cache-control", "public, max-age=0, must-revalidate");
|
|
4460
|
+
return text("Not found", { status: 404, headers: headers22 });
|
|
4461
|
+
}
|
|
4462
|
+
const is_data_request = has_data_suffix(decoded);
|
|
4463
|
+
let invalidated_data_nodes;
|
|
4464
|
+
if (is_data_request) {
|
|
4465
|
+
decoded = strip_data_suffix(decoded) || "/";
|
|
4466
|
+
url.pathname = strip_data_suffix(url.pathname) + (url.searchParams.get(TRAILING_SLASH_PARAM) === "1" ? "/" : "") || "/";
|
|
4467
|
+
url.searchParams.delete(TRAILING_SLASH_PARAM);
|
|
4468
|
+
invalidated_data_nodes = url.searchParams.get(INVALIDATED_PARAM)?.split("").map((node) => node === "1");
|
|
4469
|
+
url.searchParams.delete(INVALIDATED_PARAM);
|
|
4470
|
+
}
|
|
4471
|
+
if (!state.prerendering?.fallback) {
|
|
4472
|
+
const matchers = await manifest._.matchers();
|
|
4473
|
+
for (const candidate of manifest._.routes) {
|
|
4474
|
+
const match = candidate.pattern.exec(decoded);
|
|
4475
|
+
if (!match) continue;
|
|
4476
|
+
const matched = exec(match, candidate.params, matchers);
|
|
4477
|
+
if (matched) {
|
|
4478
|
+
route = candidate;
|
|
4479
|
+
params = decode_params(matched);
|
|
4480
|
+
break;
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
}
|
|
4484
|
+
let trailing_slash = void 0;
|
|
4485
|
+
const headers2 = {};
|
|
4486
|
+
let cookies_to_add = {};
|
|
4487
|
+
const event = {
|
|
4488
|
+
// @ts-expect-error `cookies` and `fetch` need to be created after the `event` itself
|
|
4489
|
+
cookies: null,
|
|
4490
|
+
// @ts-expect-error
|
|
4491
|
+
fetch: null,
|
|
4492
|
+
getClientAddress: state.getClientAddress || (() => {
|
|
4493
|
+
throw new Error(
|
|
4494
|
+
`${"@sveltejs/adapter-node"} does not specify getClientAddress. Please raise an issue`
|
|
4495
|
+
);
|
|
4496
|
+
}),
|
|
4497
|
+
locals: {},
|
|
4498
|
+
params,
|
|
4499
|
+
platform: state.platform,
|
|
4500
|
+
request,
|
|
4501
|
+
route: { id: route?.id ?? null },
|
|
4502
|
+
setHeaders: (new_headers) => {
|
|
4503
|
+
for (const key2 in new_headers) {
|
|
4504
|
+
const lower = key2.toLowerCase();
|
|
4505
|
+
const value = new_headers[key2];
|
|
4506
|
+
if (lower === "set-cookie") {
|
|
4507
|
+
throw new Error(
|
|
4508
|
+
"Use `event.cookies.set(name, value, options)` instead of `event.setHeaders` to set cookies"
|
|
4509
|
+
);
|
|
4510
|
+
} else if (lower in headers2) {
|
|
4511
|
+
throw new Error(`"${key2}" header is already set`);
|
|
4512
|
+
} else {
|
|
4513
|
+
headers2[lower] = value;
|
|
4514
|
+
if (state.prerendering && lower === "cache-control") {
|
|
4515
|
+
state.prerendering.cache = /** @type {string} */
|
|
4516
|
+
value;
|
|
4517
|
+
}
|
|
4518
|
+
}
|
|
4519
|
+
}
|
|
4520
|
+
},
|
|
4521
|
+
url,
|
|
4522
|
+
isDataRequest: is_data_request,
|
|
4523
|
+
isSubRequest: state.depth > 0
|
|
4524
|
+
};
|
|
4525
|
+
let resolve_opts = {
|
|
4526
|
+
transformPageChunk: default_transform,
|
|
4527
|
+
filterSerializedResponseHeaders: default_filter,
|
|
4528
|
+
preload: default_preload
|
|
4529
|
+
};
|
|
4530
|
+
try {
|
|
4531
|
+
if (route) {
|
|
4532
|
+
if (url.pathname === base || url.pathname === base + "/") {
|
|
4533
|
+
trailing_slash = "always";
|
|
4534
|
+
} else if (route.page) {
|
|
4535
|
+
const nodes = await load_page_nodes(route.page, manifest);
|
|
4536
|
+
if (BROWSER) ;
|
|
4537
|
+
trailing_slash = get_option(nodes, "trailingSlash");
|
|
4538
|
+
} else if (route.endpoint) {
|
|
4539
|
+
const node = await route.endpoint();
|
|
4540
|
+
trailing_slash = node.trailingSlash;
|
|
4541
|
+
if (BROWSER) ;
|
|
4542
|
+
}
|
|
4543
|
+
if (!is_data_request) {
|
|
4544
|
+
const normalized = normalize_path(url.pathname, trailing_slash ?? "never");
|
|
4545
|
+
if (normalized !== url.pathname && !state.prerendering?.fallback) {
|
|
4546
|
+
return new Response(void 0, {
|
|
4547
|
+
status: 308,
|
|
4548
|
+
headers: {
|
|
4549
|
+
"x-sveltekit-normalize": "1",
|
|
4550
|
+
location: (
|
|
4551
|
+
// ensure paths starting with '//' are not treated as protocol-relative
|
|
4552
|
+
(normalized.startsWith("//") ? url.origin + normalized : normalized) + (url.search === "?" ? "" : url.search)
|
|
4553
|
+
)
|
|
4554
|
+
}
|
|
4555
|
+
});
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4558
|
+
if (state.before_handle || state.emulator?.platform) {
|
|
4559
|
+
let config = {};
|
|
4560
|
+
let prerender = false;
|
|
4561
|
+
if (route.endpoint) {
|
|
4562
|
+
const node = await route.endpoint();
|
|
4563
|
+
config = node.config ?? config;
|
|
4564
|
+
prerender = node.prerender ?? prerender;
|
|
4565
|
+
} else if (route.page) {
|
|
4566
|
+
const nodes = await load_page_nodes(route.page, manifest);
|
|
4567
|
+
config = get_page_config(nodes) ?? config;
|
|
4568
|
+
prerender = get_option(nodes, "prerender") ?? false;
|
|
4569
|
+
}
|
|
4570
|
+
if (state.before_handle) {
|
|
4571
|
+
state.before_handle(event, config, prerender);
|
|
4572
|
+
}
|
|
4573
|
+
if (state.emulator?.platform) {
|
|
4574
|
+
event.platform = await state.emulator.platform({ config, prerender });
|
|
4575
|
+
}
|
|
4576
|
+
}
|
|
4577
|
+
} else if (state.emulator?.platform) {
|
|
4578
|
+
event.platform = await state.emulator.platform({
|
|
4579
|
+
config: {},
|
|
4580
|
+
prerender: !!state.prerendering?.fallback
|
|
4581
|
+
});
|
|
4582
|
+
}
|
|
4583
|
+
const { cookies, new_cookies, get_cookie_header, set_internal } = get_cookies(
|
|
4584
|
+
request,
|
|
4585
|
+
url,
|
|
4586
|
+
trailing_slash ?? "never"
|
|
4587
|
+
);
|
|
4588
|
+
cookies_to_add = new_cookies;
|
|
4589
|
+
event.cookies = cookies;
|
|
4590
|
+
event.fetch = create_fetch({
|
|
4591
|
+
event,
|
|
4592
|
+
options: options2,
|
|
4593
|
+
manifest,
|
|
4594
|
+
state,
|
|
4595
|
+
get_cookie_header,
|
|
4596
|
+
set_internal
|
|
4597
|
+
});
|
|
4598
|
+
if (state.prerendering && !state.prerendering.fallback) disable_search(url);
|
|
4599
|
+
const response = await options2.hooks.handle({
|
|
4600
|
+
event,
|
|
4601
|
+
resolve: (event2, opts) => resolve2(event2, opts).then((response2) => {
|
|
4602
|
+
for (const key2 in headers2) {
|
|
4603
|
+
const value = headers2[key2];
|
|
4604
|
+
response2.headers.set(
|
|
4605
|
+
key2,
|
|
4606
|
+
/** @type {string} */
|
|
4607
|
+
value
|
|
4608
|
+
);
|
|
4609
|
+
}
|
|
4610
|
+
add_cookies_to_headers(response2.headers, Object.values(cookies_to_add));
|
|
4611
|
+
if (state.prerendering && event2.route.id !== null) {
|
|
4612
|
+
response2.headers.set("x-sveltekit-routeid", encodeURI(event2.route.id));
|
|
4613
|
+
}
|
|
4614
|
+
return response2;
|
|
4615
|
+
})
|
|
4616
|
+
});
|
|
4617
|
+
if (response.status === 200 && response.headers.has("etag")) {
|
|
4618
|
+
let if_none_match_value = request.headers.get("if-none-match");
|
|
4619
|
+
if (if_none_match_value?.startsWith('W/"')) {
|
|
4620
|
+
if_none_match_value = if_none_match_value.substring(2);
|
|
4621
|
+
}
|
|
4622
|
+
const etag2 = (
|
|
4623
|
+
/** @type {string} */
|
|
4624
|
+
response.headers.get("etag")
|
|
4625
|
+
);
|
|
4626
|
+
if (if_none_match_value === etag2) {
|
|
4627
|
+
const headers22 = new Headers({ etag: etag2 });
|
|
4628
|
+
for (const key2 of [
|
|
4629
|
+
"cache-control",
|
|
4630
|
+
"content-location",
|
|
4631
|
+
"date",
|
|
4632
|
+
"expires",
|
|
4633
|
+
"vary",
|
|
4634
|
+
"set-cookie"
|
|
4635
|
+
]) {
|
|
4636
|
+
const value = response.headers.get(key2);
|
|
4637
|
+
if (value) headers22.set(key2, value);
|
|
4638
|
+
}
|
|
4639
|
+
return new Response(void 0, {
|
|
4640
|
+
status: 304,
|
|
4641
|
+
headers: headers22
|
|
4642
|
+
});
|
|
4643
|
+
}
|
|
4644
|
+
}
|
|
4645
|
+
if (is_data_request && response.status >= 300 && response.status <= 308) {
|
|
4646
|
+
const location = response.headers.get("location");
|
|
4647
|
+
if (location) {
|
|
4648
|
+
return redirect_json_response(new Redirect(
|
|
4649
|
+
/** @type {any} */
|
|
4650
|
+
response.status,
|
|
4651
|
+
location
|
|
4652
|
+
));
|
|
4653
|
+
}
|
|
4654
|
+
}
|
|
4655
|
+
return response;
|
|
4656
|
+
} catch (e) {
|
|
4657
|
+
if (e instanceof Redirect) {
|
|
4658
|
+
const response = is_data_request ? redirect_json_response(e) : route?.page && is_action_json_request(event) ? action_json_redirect(e) : redirect_response(e.status, e.location);
|
|
4659
|
+
add_cookies_to_headers(response.headers, Object.values(cookies_to_add));
|
|
4660
|
+
return response;
|
|
4661
|
+
}
|
|
4662
|
+
return await handle_fatal_error(event, options2, e);
|
|
4663
|
+
}
|
|
4664
|
+
async function resolve2(event2, opts) {
|
|
4665
|
+
try {
|
|
4666
|
+
if (opts) {
|
|
4667
|
+
resolve_opts = {
|
|
4668
|
+
transformPageChunk: opts.transformPageChunk || default_transform,
|
|
4669
|
+
filterSerializedResponseHeaders: opts.filterSerializedResponseHeaders || default_filter,
|
|
4670
|
+
preload: opts.preload || default_preload
|
|
4671
|
+
};
|
|
4672
|
+
}
|
|
4673
|
+
if (options2.hash_routing || state.prerendering?.fallback) {
|
|
4674
|
+
return await render_response({
|
|
4675
|
+
event: event2,
|
|
4676
|
+
options: options2,
|
|
4677
|
+
manifest,
|
|
4678
|
+
state,
|
|
4679
|
+
page_config: { ssr: false, csr: true },
|
|
4680
|
+
status: 200,
|
|
4681
|
+
error: null,
|
|
4682
|
+
branch: [],
|
|
4683
|
+
fetched: [],
|
|
4684
|
+
resolve_opts
|
|
4685
|
+
});
|
|
4686
|
+
}
|
|
4687
|
+
if (route) {
|
|
4688
|
+
const method = (
|
|
4689
|
+
/** @type {import('types').HttpMethod} */
|
|
4690
|
+
event2.request.method
|
|
4691
|
+
);
|
|
4692
|
+
let response;
|
|
4693
|
+
if (is_data_request) {
|
|
4694
|
+
response = await render_data(
|
|
4695
|
+
event2,
|
|
4696
|
+
route,
|
|
4697
|
+
options2,
|
|
4698
|
+
manifest,
|
|
4699
|
+
state,
|
|
4700
|
+
invalidated_data_nodes,
|
|
4701
|
+
trailing_slash ?? "never"
|
|
4702
|
+
);
|
|
4703
|
+
} else if (route.endpoint && (!route.page || is_endpoint_request(event2))) {
|
|
4704
|
+
response = await render_endpoint(event2, await route.endpoint(), state);
|
|
4705
|
+
} else if (route.page) {
|
|
4706
|
+
if (page_methods.has(method)) {
|
|
4707
|
+
response = await render_page(event2, route.page, options2, manifest, state, resolve_opts);
|
|
4708
|
+
} else {
|
|
4709
|
+
const allowed_methods2 = new Set(allowed_page_methods);
|
|
4710
|
+
const node = await manifest._.nodes[route.page.leaf]();
|
|
4711
|
+
if (node?.server?.actions) {
|
|
4712
|
+
allowed_methods2.add("POST");
|
|
4713
|
+
}
|
|
4714
|
+
if (method === "OPTIONS") {
|
|
4715
|
+
response = new Response(null, {
|
|
4716
|
+
status: 204,
|
|
4717
|
+
headers: {
|
|
4718
|
+
allow: Array.from(allowed_methods2.values()).join(", ")
|
|
4719
|
+
}
|
|
4720
|
+
});
|
|
4721
|
+
} else {
|
|
4722
|
+
const mod = [...allowed_methods2].reduce(
|
|
4723
|
+
(acc, curr) => {
|
|
4724
|
+
acc[curr] = true;
|
|
4725
|
+
return acc;
|
|
4726
|
+
},
|
|
4727
|
+
/** @type {Record<string, any>} */
|
|
4728
|
+
{}
|
|
4729
|
+
);
|
|
4730
|
+
response = method_not_allowed(mod, method);
|
|
4731
|
+
}
|
|
4732
|
+
}
|
|
4733
|
+
} else {
|
|
4734
|
+
throw new Error("This should never happen");
|
|
4735
|
+
}
|
|
4736
|
+
if (request.method === "GET" && route.page && route.endpoint) {
|
|
4737
|
+
const vary = response.headers.get("vary")?.split(",")?.map((v) => v.trim().toLowerCase());
|
|
4738
|
+
if (!(vary?.includes("accept") || vary?.includes("*"))) {
|
|
4739
|
+
response = new Response(response.body, {
|
|
4740
|
+
status: response.status,
|
|
4741
|
+
statusText: response.statusText,
|
|
4742
|
+
headers: new Headers(response.headers)
|
|
4743
|
+
});
|
|
4744
|
+
response.headers.append("Vary", "Accept");
|
|
4745
|
+
}
|
|
4746
|
+
}
|
|
4747
|
+
return response;
|
|
4748
|
+
}
|
|
4749
|
+
if (state.error && event2.isSubRequest) {
|
|
4750
|
+
return await fetch(request, {
|
|
4751
|
+
headers: {
|
|
4752
|
+
"x-sveltekit-error": "true"
|
|
4753
|
+
}
|
|
4754
|
+
});
|
|
4755
|
+
}
|
|
4756
|
+
if (state.error) {
|
|
4757
|
+
return text("Internal Server Error", {
|
|
4758
|
+
status: 500
|
|
4759
|
+
});
|
|
4760
|
+
}
|
|
4761
|
+
if (state.depth === 0) {
|
|
4762
|
+
return await respond_with_error({
|
|
4763
|
+
event: event2,
|
|
4764
|
+
options: options2,
|
|
4765
|
+
manifest,
|
|
4766
|
+
state,
|
|
4767
|
+
status: 404,
|
|
4768
|
+
error: new SvelteKitError(404, "Not Found", `Not found: ${event2.url.pathname}`),
|
|
4769
|
+
resolve_opts
|
|
4770
|
+
});
|
|
4771
|
+
}
|
|
4772
|
+
if (state.prerendering) {
|
|
4773
|
+
return text("not found", { status: 404 });
|
|
4774
|
+
}
|
|
4775
|
+
return await fetch(request);
|
|
4776
|
+
} catch (e) {
|
|
4777
|
+
return await handle_fatal_error(event2, options2, e);
|
|
4778
|
+
} finally {
|
|
4779
|
+
event2.cookies.set = () => {
|
|
4780
|
+
throw new Error("Cannot use `cookies.set(...)` after the response has been generated");
|
|
4781
|
+
};
|
|
4782
|
+
event2.setHeaders = () => {
|
|
4783
|
+
throw new Error("Cannot use `setHeaders(...)` after the response has been generated");
|
|
4784
|
+
};
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4788
|
+
function filter_private_env(env, { public_prefix, private_prefix }) {
|
|
4789
|
+
return Object.fromEntries(
|
|
4790
|
+
Object.entries(env).filter(
|
|
4791
|
+
([k]) => k.startsWith(private_prefix) && (public_prefix === "" || !k.startsWith(public_prefix))
|
|
4792
|
+
)
|
|
4793
|
+
);
|
|
4794
|
+
}
|
|
4795
|
+
function filter_public_env(env, { public_prefix, private_prefix }) {
|
|
4796
|
+
return Object.fromEntries(
|
|
4797
|
+
Object.entries(env).filter(
|
|
4798
|
+
([k]) => k.startsWith(public_prefix) && (private_prefix === "" || !k.startsWith(private_prefix))
|
|
4799
|
+
)
|
|
4800
|
+
);
|
|
4801
|
+
}
|
|
4802
|
+
let init_promise;
|
|
4803
|
+
class Server {
|
|
4804
|
+
/** @type {import('types').SSROptions} */
|
|
4805
|
+
#options;
|
|
4806
|
+
/** @type {import('@sveltejs/kit').SSRManifest} */
|
|
4807
|
+
#manifest;
|
|
4808
|
+
/** @param {import('@sveltejs/kit').SSRManifest} manifest */
|
|
4809
|
+
constructor(manifest) {
|
|
4810
|
+
this.#options = options;
|
|
4811
|
+
this.#manifest = manifest;
|
|
4812
|
+
}
|
|
4813
|
+
/**
|
|
4814
|
+
* @param {{
|
|
4815
|
+
* env: Record<string, string>;
|
|
4816
|
+
* read?: (file: string) => ReadableStream;
|
|
4817
|
+
* }} opts
|
|
4818
|
+
*/
|
|
4819
|
+
async init({ env, read }) {
|
|
4820
|
+
const prefixes = {
|
|
4821
|
+
public_prefix: this.#options.env_public_prefix,
|
|
4822
|
+
private_prefix: this.#options.env_private_prefix
|
|
4823
|
+
};
|
|
4824
|
+
filter_private_env(env, prefixes);
|
|
4825
|
+
const public_env2 = filter_public_env(env, prefixes);
|
|
4826
|
+
set_public_env(
|
|
4827
|
+
public_env2
|
|
4828
|
+
);
|
|
4829
|
+
set_safe_public_env(public_env2);
|
|
4830
|
+
if (read) {
|
|
4831
|
+
set_read_implementation(read);
|
|
4832
|
+
}
|
|
4833
|
+
await (init_promise ??= (async () => {
|
|
4834
|
+
try {
|
|
4835
|
+
const module = await get_hooks();
|
|
4836
|
+
this.#options.hooks = {
|
|
4837
|
+
handle: module.handle || (({ event, resolve: resolve2 }) => resolve2(event)),
|
|
4838
|
+
handleError: module.handleError || (({ error }) => console.error(error)),
|
|
4839
|
+
handleFetch: module.handleFetch || (({ request, fetch: fetch2 }) => fetch2(request)),
|
|
4840
|
+
reroute: module.reroute || (() => {
|
|
4841
|
+
}),
|
|
4842
|
+
transport: module.transport || {}
|
|
4843
|
+
};
|
|
4844
|
+
if (module.init) {
|
|
4845
|
+
await module.init();
|
|
4846
|
+
}
|
|
4847
|
+
} catch (error) {
|
|
4848
|
+
{
|
|
4849
|
+
throw error;
|
|
4850
|
+
}
|
|
4851
|
+
}
|
|
4852
|
+
})());
|
|
4853
|
+
}
|
|
4854
|
+
/**
|
|
4855
|
+
* @param {Request} request
|
|
4856
|
+
* @param {import('types').RequestOptions} options
|
|
4857
|
+
*/
|
|
4858
|
+
async respond(request, options2) {
|
|
4859
|
+
return respond(request, this.#options, this.#manifest, {
|
|
4860
|
+
...options2,
|
|
4861
|
+
error: false,
|
|
4862
|
+
depth: 0
|
|
4863
|
+
});
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
4866
|
+
|
|
4867
|
+
export { Server };
|
|
4868
|
+
//# sourceMappingURL=index.js.map
|