@sveltejs/kit 1.0.0-next.48 → 1.0.0-next.480

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.
Files changed (117) hide show
  1. package/README.md +12 -9
  2. package/package.json +93 -64
  3. package/scripts/special-types/$env+dynamic+private.md +10 -0
  4. package/scripts/special-types/$env+dynamic+public.md +8 -0
  5. package/scripts/special-types/$env+static+private.md +19 -0
  6. package/scripts/special-types/$env+static+public.md +7 -0
  7. package/scripts/special-types/$lib.md +1 -0
  8. package/src/cli.js +112 -0
  9. package/src/constants.js +7 -0
  10. package/src/core/adapt/builder.js +207 -0
  11. package/src/core/adapt/index.js +31 -0
  12. package/src/core/config/default-error.html +56 -0
  13. package/src/core/config/index.js +110 -0
  14. package/src/core/config/options.js +504 -0
  15. package/src/core/config/types.d.ts +1 -0
  16. package/src/core/env.js +121 -0
  17. package/src/core/generate_manifest/index.js +92 -0
  18. package/src/core/prerender/crawl.js +194 -0
  19. package/src/core/prerender/prerender.js +431 -0
  20. package/src/core/prerender/queue.js +80 -0
  21. package/src/core/sync/create_manifest_data/index.js +472 -0
  22. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  23. package/src/core/sync/sync.js +59 -0
  24. package/src/core/sync/utils.js +33 -0
  25. package/src/core/sync/write_ambient.js +53 -0
  26. package/src/core/sync/write_client_manifest.js +106 -0
  27. package/src/core/sync/write_matchers.js +25 -0
  28. package/src/core/sync/write_root.js +91 -0
  29. package/src/core/sync/write_tsconfig.js +195 -0
  30. package/src/core/sync/write_types/index.js +673 -0
  31. package/src/core/utils.js +70 -0
  32. package/src/exports/hooks/index.js +1 -0
  33. package/src/exports/hooks/sequence.js +44 -0
  34. package/src/exports/index.js +45 -0
  35. package/src/exports/node/index.js +163 -0
  36. package/src/exports/node/polyfills.js +41 -0
  37. package/src/exports/vite/build/build_server.js +372 -0
  38. package/src/exports/vite/build/build_service_worker.js +90 -0
  39. package/src/exports/vite/build/utils.js +162 -0
  40. package/src/exports/vite/dev/index.js +576 -0
  41. package/src/exports/vite/index.js +597 -0
  42. package/src/exports/vite/preview/index.js +189 -0
  43. package/src/exports/vite/types.d.ts +3 -0
  44. package/src/exports/vite/utils.js +438 -0
  45. package/src/runtime/app/env.js +1 -0
  46. package/src/runtime/app/environment.js +11 -0
  47. package/src/runtime/app/forms.js +108 -0
  48. package/src/runtime/app/navigation.js +23 -0
  49. package/src/runtime/app/paths.js +1 -0
  50. package/src/runtime/app/stores.js +102 -0
  51. package/src/runtime/client/ambient.d.ts +26 -0
  52. package/src/runtime/client/client.js +1569 -0
  53. package/src/runtime/client/fetcher.js +107 -0
  54. package/src/runtime/client/parse.js +60 -0
  55. package/src/runtime/client/singletons.js +21 -0
  56. package/src/runtime/client/start.js +37 -0
  57. package/src/runtime/client/types.d.ts +85 -0
  58. package/src/runtime/client/utils.js +159 -0
  59. package/src/runtime/components/error.svelte +16 -0
  60. package/{assets → src/runtime}/components/layout.svelte +0 -0
  61. package/src/runtime/control.js +98 -0
  62. package/src/runtime/env/dynamic/private.js +1 -0
  63. package/src/runtime/env/dynamic/public.js +1 -0
  64. package/src/runtime/env-private.js +6 -0
  65. package/src/runtime/env-public.js +6 -0
  66. package/src/runtime/env.js +6 -0
  67. package/src/runtime/hash.js +16 -0
  68. package/src/runtime/paths.js +11 -0
  69. package/src/runtime/server/cookie.js +77 -0
  70. package/src/runtime/server/data/index.js +136 -0
  71. package/src/runtime/server/endpoint.js +66 -0
  72. package/src/runtime/server/index.js +343 -0
  73. package/src/runtime/server/page/actions.js +243 -0
  74. package/src/runtime/server/page/crypto.js +239 -0
  75. package/src/runtime/server/page/csp.js +249 -0
  76. package/src/runtime/server/page/fetch.js +286 -0
  77. package/src/runtime/server/page/index.js +304 -0
  78. package/src/runtime/server/page/load_data.js +124 -0
  79. package/src/runtime/server/page/render.js +346 -0
  80. package/src/runtime/server/page/respond_with_error.js +92 -0
  81. package/src/runtime/server/page/serialize_data.js +87 -0
  82. package/src/runtime/server/page/types.d.ts +35 -0
  83. package/src/runtime/server/utils.js +178 -0
  84. package/src/utils/array.js +9 -0
  85. package/src/utils/error.js +22 -0
  86. package/src/utils/escape.js +46 -0
  87. package/src/utils/filesystem.js +137 -0
  88. package/src/utils/functions.js +16 -0
  89. package/src/utils/http.js +55 -0
  90. package/src/utils/misc.js +1 -0
  91. package/src/utils/routing.js +117 -0
  92. package/src/utils/url.js +142 -0
  93. package/svelte-kit.js +1 -1
  94. package/types/ambient.d.ts +426 -0
  95. package/types/index.d.ts +410 -0
  96. package/types/internal.d.ts +384 -0
  97. package/types/private.d.ts +210 -0
  98. package/CHANGELOG.md +0 -469
  99. package/assets/components/error.svelte +0 -13
  100. package/assets/runtime/app/env.js +0 -5
  101. package/assets/runtime/app/navigation.js +0 -44
  102. package/assets/runtime/app/paths.js +0 -1
  103. package/assets/runtime/app/stores.js +0 -93
  104. package/assets/runtime/chunks/utils.js +0 -22
  105. package/assets/runtime/internal/singletons.js +0 -23
  106. package/assets/runtime/internal/start.js +0 -773
  107. package/assets/runtime/paths.js +0 -12
  108. package/dist/chunks/index.js +0 -3517
  109. package/dist/chunks/index2.js +0 -587
  110. package/dist/chunks/index3.js +0 -246
  111. package/dist/chunks/index4.js +0 -530
  112. package/dist/chunks/index5.js +0 -763
  113. package/dist/chunks/index6.js +0 -322
  114. package/dist/chunks/standard.js +0 -99
  115. package/dist/chunks/utils.js +0 -83
  116. package/dist/cli.js +0 -553
  117. package/dist/ssr.js +0 -2581
@@ -0,0 +1,249 @@
1
+ import { escape_html_attr } from '../../../utils/escape.js';
2
+ import { sha256, base64 } from './crypto.js';
3
+
4
+ const array = new Uint8Array(16);
5
+
6
+ function generate_nonce() {
7
+ crypto.getRandomValues(array);
8
+ return base64(array);
9
+ }
10
+
11
+ const quoted = new Set([
12
+ 'self',
13
+ 'unsafe-eval',
14
+ 'unsafe-hashes',
15
+ 'unsafe-inline',
16
+ 'none',
17
+ 'strict-dynamic',
18
+ 'report-sample'
19
+ ]);
20
+
21
+ const crypto_pattern = /^(nonce|sha\d\d\d)-/;
22
+
23
+ // CSP and CSP Report Only are extremely similar with a few caveats
24
+ // the easiest/DRYest way to express this is with some private encapsulation
25
+ class BaseProvider {
26
+ /** @type {boolean} */
27
+ #use_hashes;
28
+
29
+ /** @type {boolean} */
30
+ #script_needs_csp;
31
+
32
+ /** @type {boolean} */
33
+ #style_needs_csp;
34
+
35
+ /** @type {import('types').CspDirectives} */
36
+ #directives;
37
+
38
+ /** @type {import('types').Csp.Source[]} */
39
+ #script_src;
40
+
41
+ /** @type {import('types').Csp.Source[]} */
42
+ #style_src;
43
+
44
+ /** @type {string} */
45
+ #nonce;
46
+
47
+ /**
48
+ * @param {boolean} use_hashes
49
+ * @param {import('types').CspDirectives} directives
50
+ * @param {string} nonce
51
+ * @param {boolean} dev
52
+ */
53
+ constructor(use_hashes, directives, nonce, dev) {
54
+ this.#use_hashes = use_hashes;
55
+ this.#directives = dev ? { ...directives } : directives; // clone in dev so we can safely mutate
56
+
57
+ const d = this.#directives;
58
+
59
+ if (dev) {
60
+ // remove strict-dynamic in dev...
61
+ // TODO reinstate this if we can figure out how to make strict-dynamic work
62
+ // if (d['default-src']) {
63
+ // d['default-src'] = d['default-src'].filter((name) => name !== 'strict-dynamic');
64
+ // if (d['default-src'].length === 0) delete d['default-src'];
65
+ // }
66
+
67
+ // if (d['script-src']) {
68
+ // d['script-src'] = d['script-src'].filter((name) => name !== 'strict-dynamic');
69
+ // if (d['script-src'].length === 0) delete d['script-src'];
70
+ // }
71
+
72
+ const effective_style_src = d['style-src'] || d['default-src'];
73
+
74
+ // ...and add unsafe-inline so we can inject <style> elements
75
+ if (effective_style_src && !effective_style_src.includes('unsafe-inline')) {
76
+ d['style-src'] = [...effective_style_src, 'unsafe-inline'];
77
+ }
78
+ }
79
+
80
+ this.#script_src = [];
81
+ this.#style_src = [];
82
+
83
+ const effective_script_src = d['script-src'] || d['default-src'];
84
+ const effective_style_src = d['style-src'] || d['default-src'];
85
+
86
+ this.#script_needs_csp =
87
+ !!effective_script_src &&
88
+ effective_script_src.filter((value) => value !== 'unsafe-inline').length > 0;
89
+
90
+ this.#style_needs_csp =
91
+ !dev &&
92
+ !!effective_style_src &&
93
+ effective_style_src.filter((value) => value !== 'unsafe-inline').length > 0;
94
+
95
+ this.script_needs_nonce = this.#script_needs_csp && !this.#use_hashes;
96
+ this.style_needs_nonce = this.#style_needs_csp && !this.#use_hashes;
97
+ this.#nonce = nonce;
98
+ }
99
+
100
+ /** @param {string} content */
101
+ add_script(content) {
102
+ if (this.#script_needs_csp) {
103
+ if (this.#use_hashes) {
104
+ this.#script_src.push(`sha256-${sha256(content)}`);
105
+ } else if (this.#script_src.length === 0) {
106
+ this.#script_src.push(`nonce-${this.#nonce}`);
107
+ }
108
+ }
109
+ }
110
+
111
+ /** @param {string} content */
112
+ add_style(content) {
113
+ if (this.#style_needs_csp) {
114
+ if (this.#use_hashes) {
115
+ this.#style_src.push(`sha256-${sha256(content)}`);
116
+ } else if (this.#style_src.length === 0) {
117
+ this.#style_src.push(`nonce-${this.#nonce}`);
118
+ }
119
+ }
120
+ }
121
+
122
+ /**
123
+ * @param {boolean} [is_meta]
124
+ */
125
+ get_header(is_meta = false) {
126
+ const header = [];
127
+
128
+ // due to browser inconsistencies, we can't append sources to default-src
129
+ // (specifically, Firefox appears to not ignore nonce-{nonce} directives
130
+ // on default-src), so we ensure that script-src and style-src exist
131
+
132
+ const directives = { ...this.#directives };
133
+
134
+ if (this.#style_src.length > 0) {
135
+ directives['style-src'] = [
136
+ ...(directives['style-src'] || directives['default-src'] || []),
137
+ ...this.#style_src
138
+ ];
139
+ }
140
+
141
+ if (this.#script_src.length > 0) {
142
+ directives['script-src'] = [
143
+ ...(directives['script-src'] || directives['default-src'] || []),
144
+ ...this.#script_src
145
+ ];
146
+ }
147
+
148
+ for (const key in directives) {
149
+ if (is_meta && (key === 'frame-ancestors' || key === 'report-uri' || key === 'sandbox')) {
150
+ // these values cannot be used with a <meta> tag
151
+ // TODO warn?
152
+ continue;
153
+ }
154
+
155
+ // @ts-expect-error gimme a break typescript, `key` is obviously a member of internal_directives
156
+ const value = /** @type {string[] | true} */ (directives[key]);
157
+
158
+ if (!value) continue;
159
+
160
+ const directive = [key];
161
+ if (Array.isArray(value)) {
162
+ value.forEach((value) => {
163
+ if (quoted.has(value) || crypto_pattern.test(value)) {
164
+ directive.push(`'${value}'`);
165
+ } else {
166
+ directive.push(value);
167
+ }
168
+ });
169
+ }
170
+
171
+ header.push(directive.join(' '));
172
+ }
173
+
174
+ return header.join('; ');
175
+ }
176
+ }
177
+
178
+ class CspProvider extends BaseProvider {
179
+ get_meta() {
180
+ const content = escape_html_attr(this.get_header(true));
181
+ return `<meta http-equiv="content-security-policy" content=${content}>`;
182
+ }
183
+ }
184
+
185
+ class CspReportOnlyProvider extends BaseProvider {
186
+ /**
187
+ * @param {boolean} use_hashes
188
+ * @param {import('types').CspDirectives} directives
189
+ * @param {string} nonce
190
+ * @param {boolean} dev
191
+ */
192
+ constructor(use_hashes, directives, nonce, dev) {
193
+ super(use_hashes, directives, nonce, dev);
194
+
195
+ if (Object.values(directives).filter((v) => !!v).length > 0) {
196
+ // If we're generating content-security-policy-report-only,
197
+ // if there are any directives, we need a report-uri or report-to (or both)
198
+ // else it's just an expensive noop.
199
+ const has_report_to = directives['report-to']?.length ?? 0 > 0;
200
+ const has_report_uri = directives['report-uri']?.length ?? 0 > 0;
201
+ if (!has_report_to && !has_report_uri) {
202
+ throw Error(
203
+ '`content-security-policy-report-only` must be specified with either the `report-to` or `report-uri` directives, or both'
204
+ );
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ export class Csp {
211
+ /** @readonly */
212
+ nonce = generate_nonce();
213
+
214
+ /** @type {CspProvider} */
215
+ csp_provider;
216
+
217
+ /** @type {CspReportOnlyProvider} */
218
+ report_only_provider;
219
+
220
+ /**
221
+ * @param {import('./types').CspConfig} config
222
+ * @param {import('./types').CspOpts} opts
223
+ */
224
+ constructor({ mode, directives, reportOnly }, { prerender, dev }) {
225
+ const use_hashes = mode === 'hash' || (mode === 'auto' && prerender);
226
+ this.csp_provider = new CspProvider(use_hashes, directives, this.nonce, dev);
227
+ this.report_only_provider = new CspReportOnlyProvider(use_hashes, reportOnly, this.nonce, dev);
228
+ }
229
+
230
+ get script_needs_nonce() {
231
+ return this.csp_provider.script_needs_nonce || this.report_only_provider.script_needs_nonce;
232
+ }
233
+
234
+ get style_needs_nonce() {
235
+ return this.csp_provider.style_needs_nonce || this.report_only_provider.style_needs_nonce;
236
+ }
237
+
238
+ /** @param {string} content */
239
+ add_script(content) {
240
+ this.csp_provider.add_script(content);
241
+ this.report_only_provider.add_script(content);
242
+ }
243
+
244
+ /** @param {string} content */
245
+ add_style(content) {
246
+ this.csp_provider.add_style(content);
247
+ this.report_only_provider.add_style(content);
248
+ }
249
+ }
@@ -0,0 +1,286 @@
1
+ import * as cookie from 'cookie';
2
+ import * as set_cookie_parser from 'set-cookie-parser';
3
+ import { respond } from '../index.js';
4
+ import { domain_matches, path_matches } from '../cookie.js';
5
+
6
+ /**
7
+ * @param {{
8
+ * event: import('types').RequestEvent;
9
+ * options: import('types').SSROptions;
10
+ * state: import('types').SSRState;
11
+ * route: import('types').SSRRoute | import('types').SSRErrorPage;
12
+ * prerender_default?: import('types').PrerenderOption;
13
+ * resolve_opts: import('types').RequiredResolveOptions;
14
+ * }} opts
15
+ */
16
+ export function create_fetch({ event, options, state, route, prerender_default, resolve_opts }) {
17
+ /** @type {import('./types').Fetched[]} */
18
+ const fetched = [];
19
+
20
+ const initial_cookies = cookie.parse(event.request.headers.get('cookie') || '');
21
+
22
+ /** @type {import('set-cookie-parser').Cookie[]} */
23
+ const set_cookies = [];
24
+
25
+ /**
26
+ * @param {URL} url
27
+ * @param {string | null} header
28
+ */
29
+ function get_cookie_header(url, header) {
30
+ /** @type {Record<string, string>} */
31
+ const new_cookies = {};
32
+
33
+ for (const cookie of set_cookies) {
34
+ if (!domain_matches(url.hostname, cookie.domain)) continue;
35
+ if (!path_matches(url.pathname, cookie.path)) continue;
36
+
37
+ new_cookies[cookie.name] = cookie.value;
38
+ }
39
+
40
+ // cookies from explicit `cookie` header take precedence over cookies previously set
41
+ // during this load with `set-cookie`, which take precedence over the cookies
42
+ // sent by the user agent
43
+ const combined_cookies = {
44
+ ...initial_cookies,
45
+ ...new_cookies,
46
+ ...cookie.parse(header ?? '')
47
+ };
48
+
49
+ return Object.entries(combined_cookies)
50
+ .map(([name, value]) => `${name}=${value}`)
51
+ .join('; ');
52
+ }
53
+
54
+ /** @type {typeof fetch} */
55
+ const fetcher = async (info, init) => {
56
+ const request = normalize_fetch_input(info, init, event.url);
57
+
58
+ const request_body = init?.body;
59
+
60
+ /** @type {import('types').PrerenderDependency} */
61
+ let dependency;
62
+
63
+ const response = await options.hooks.handleFetch({
64
+ event,
65
+ request,
66
+ fetch: async (info, init) => {
67
+ const request = normalize_fetch_input(info, init, event.url);
68
+
69
+ const url = new URL(request.url);
70
+
71
+ if (url.origin !== event.url.origin) {
72
+ // allow cookie passthrough for "same-origin"
73
+ // if SvelteKit is serving my.domain.com:
74
+ // - domain.com WILL NOT receive cookies
75
+ // - my.domain.com WILL receive cookies
76
+ // - api.domain.dom WILL NOT receive cookies
77
+ // - sub.my.domain.com WILL receive cookies
78
+ // ports do not affect the resolution
79
+ // leading dot prevents mydomain.com matching domain.com
80
+ if (
81
+ `.${url.hostname}`.endsWith(`.${event.url.hostname}`) &&
82
+ request.credentials !== 'omit'
83
+ ) {
84
+ const cookie = get_cookie_header(url, request.headers.get('cookie'));
85
+ if (cookie) request.headers.set('cookie', cookie);
86
+ }
87
+
88
+ let response = await fetch(request);
89
+
90
+ if (request.mode === 'no-cors') {
91
+ response = new Response('', {
92
+ status: response.status,
93
+ statusText: response.statusText,
94
+ headers: response.headers
95
+ });
96
+ } else {
97
+ if (url.origin !== event.url.origin) {
98
+ const acao = response.headers.get('access-control-allow-origin');
99
+ if (!acao || (acao !== event.url.origin && acao !== '*')) {
100
+ throw new Error(
101
+ `CORS error: ${
102
+ acao ? 'Incorrect' : 'No'
103
+ } 'Access-Control-Allow-Origin' header is present on the requested resource`
104
+ );
105
+ }
106
+ }
107
+ }
108
+
109
+ return response;
110
+ }
111
+
112
+ /** @type {Response} */
113
+ let response;
114
+
115
+ // handle fetch requests for static assets. e.g. prebaked data, etc.
116
+ // we need to support everything the browser's fetch supports
117
+ const prefix = options.paths.assets || options.paths.base;
118
+ const decoded = decodeURIComponent(url.pathname);
119
+ const filename = (
120
+ decoded.startsWith(prefix) ? decoded.slice(prefix.length) : decoded
121
+ ).slice(1);
122
+ const filename_html = `${filename}/index.html`; // path may also match path/index.html
123
+
124
+ const is_asset = options.manifest.assets.has(filename);
125
+ const is_asset_html = options.manifest.assets.has(filename_html);
126
+
127
+ if (is_asset || is_asset_html) {
128
+ const file = is_asset ? filename : filename_html;
129
+
130
+ if (options.read) {
131
+ const type = is_asset
132
+ ? options.manifest.mimeTypes[filename.slice(filename.lastIndexOf('.'))]
133
+ : 'text/html';
134
+
135
+ return new Response(options.read(file), {
136
+ headers: type ? { 'content-type': type } : {}
137
+ });
138
+ }
139
+
140
+ return await fetch(request);
141
+ }
142
+
143
+ if (request.credentials !== 'omit') {
144
+ const cookie = get_cookie_header(url, request.headers.get('cookie'));
145
+ if (cookie) {
146
+ request.headers.set('cookie', cookie);
147
+ }
148
+
149
+ const authorization = event.request.headers.get('authorization');
150
+ if (authorization && !request.headers.has('authorization')) {
151
+ request.headers.set('authorization', authorization);
152
+ }
153
+ }
154
+
155
+ if (request_body && typeof request_body !== 'string') {
156
+ // TODO is this still necessary? we just bail out below
157
+ // per https://developer.mozilla.org/en-US/docs/Web/API/Request/Request, this can be a
158
+ // Blob, BufferSource, FormData, URLSearchParams, USVString, or ReadableStream object.
159
+ // non-string bodies are irksome to deal with, but luckily aren't particularly useful
160
+ // in this context anyway, so we take the easy route and ban them
161
+ throw new Error('Request body must be a string');
162
+ }
163
+
164
+ response = await respond(request, options, {
165
+ prerender_default,
166
+ ...state,
167
+ initiator: route
168
+ });
169
+
170
+ if (state.prerendering) {
171
+ dependency = { response, body: null };
172
+ state.prerendering.dependencies.set(url.pathname, dependency);
173
+ }
174
+
175
+ return response;
176
+ }
177
+ });
178
+
179
+ const set_cookie = response.headers.get('set-cookie');
180
+ if (set_cookie) {
181
+ set_cookies.push(
182
+ ...set_cookie_parser
183
+ .splitCookiesString(set_cookie)
184
+ .map((str) => set_cookie_parser.parseString(str))
185
+ );
186
+ }
187
+
188
+ const proxy = new Proxy(response, {
189
+ get(response, key, _receiver) {
190
+ async function text() {
191
+ const body = await response.text();
192
+
193
+ if (!body || typeof body === 'string') {
194
+ const status_number = Number(response.status);
195
+ if (isNaN(status_number)) {
196
+ throw new Error(
197
+ `response.status is not a number. value: "${
198
+ response.status
199
+ }" type: ${typeof response.status}`
200
+ );
201
+ }
202
+
203
+ fetched.push({
204
+ url: request.url.startsWith(event.url.origin)
205
+ ? request.url.slice(event.url.origin.length)
206
+ : request.url,
207
+ method: request.method,
208
+ request_body: /** @type {string | undefined} */ (request_body),
209
+ response_body: body,
210
+ response: response
211
+ });
212
+
213
+ // ensure that excluded headers can't be read
214
+ const get = response.headers.get;
215
+ response.headers.get = (key) => {
216
+ const lower = key.toLowerCase();
217
+ const value = get.call(response.headers, lower);
218
+ if (value && !lower.startsWith('x-sveltekit-')) {
219
+ const included = resolve_opts.filterSerializedResponseHeaders(lower, value);
220
+ if (!included) {
221
+ throw new Error(
222
+ `Failed to get response header "${lower}" — it must be included by the \`filterSerializedResponseHeaders\` option: https://kit.svelte.dev/docs/hooks#handle`
223
+ );
224
+ }
225
+ }
226
+
227
+ return value;
228
+ };
229
+ }
230
+
231
+ if (dependency) {
232
+ dependency.body = body;
233
+ }
234
+
235
+ return body;
236
+ }
237
+
238
+ if (key === 'arrayBuffer') {
239
+ return async () => {
240
+ const buffer = await response.arrayBuffer();
241
+
242
+ if (dependency) {
243
+ dependency.body = new Uint8Array(buffer);
244
+ }
245
+
246
+ // TODO should buffer be inlined into the page (albeit base64'd)?
247
+ // any conditions in which it shouldn't be?
248
+
249
+ return buffer;
250
+ };
251
+ }
252
+
253
+ if (key === 'text') {
254
+ return text;
255
+ }
256
+
257
+ if (key === 'json') {
258
+ return async () => {
259
+ return JSON.parse(await text());
260
+ };
261
+ }
262
+
263
+ // TODO arrayBuffer?
264
+
265
+ return Reflect.get(response, key, response);
266
+ }
267
+ });
268
+
269
+ return proxy;
270
+ };
271
+
272
+ return { fetcher, fetched, cookies: set_cookies };
273
+ }
274
+
275
+ /**
276
+ * @param {RequestInfo | URL} info
277
+ * @param {RequestInit | undefined} init
278
+ * @param {URL} url
279
+ */
280
+ function normalize_fetch_input(info, init, url) {
281
+ if (info instanceof Request) {
282
+ return info;
283
+ }
284
+
285
+ return new Request(typeof info === 'string' ? new URL(info, url) : info, init);
286
+ }