@sveltejs/kit 1.0.0-next.46 → 1.0.0-next.460

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 (115) hide show
  1. package/README.md +12 -9
  2. package/package.json +93 -65
  3. package/scripts/special-types/$env+dynamic+private.md +8 -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 +105 -0
  14. package/src/core/config/options.js +498 -0
  15. package/src/core/config/types.d.ts +1 -0
  16. package/src/core/env.js +112 -0
  17. package/src/core/generate_manifest/index.js +78 -0
  18. package/src/core/prerender/crawl.js +194 -0
  19. package/src/core/prerender/prerender.js +425 -0
  20. package/src/core/prerender/queue.js +80 -0
  21. package/src/core/sync/create_manifest_data/index.js +452 -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 +94 -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 +595 -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 +145 -0
  36. package/src/exports/node/polyfills.js +40 -0
  37. package/src/exports/vite/build/build_server.js +349 -0
  38. package/src/exports/vite/build/build_service_worker.js +90 -0
  39. package/src/exports/vite/build/utils.js +160 -0
  40. package/src/exports/vite/dev/index.js +543 -0
  41. package/src/exports/vite/index.js +595 -0
  42. package/src/exports/vite/preview/index.js +186 -0
  43. package/src/exports/vite/types.d.ts +3 -0
  44. package/src/exports/vite/utils.js +345 -0
  45. package/src/runtime/app/env.js +1 -0
  46. package/src/runtime/app/environment.js +11 -0
  47. package/src/runtime/app/navigation.js +22 -0
  48. package/src/runtime/app/paths.js +1 -0
  49. package/src/runtime/app/stores.js +102 -0
  50. package/src/runtime/client/ambient.d.ts +24 -0
  51. package/src/runtime/client/client.js +1387 -0
  52. package/src/runtime/client/fetcher.js +60 -0
  53. package/src/runtime/client/parse.js +60 -0
  54. package/src/runtime/client/singletons.js +21 -0
  55. package/src/runtime/client/start.js +45 -0
  56. package/src/runtime/client/types.d.ts +88 -0
  57. package/src/runtime/client/utils.js +140 -0
  58. package/src/runtime/components/error.svelte +16 -0
  59. package/{assets → src/runtime}/components/layout.svelte +0 -0
  60. package/src/runtime/control.js +33 -0
  61. package/src/runtime/env/dynamic/private.js +1 -0
  62. package/src/runtime/env/dynamic/public.js +1 -0
  63. package/src/runtime/env-private.js +6 -0
  64. package/src/runtime/env-public.js +6 -0
  65. package/src/runtime/env.js +6 -0
  66. package/src/runtime/hash.js +16 -0
  67. package/src/runtime/paths.js +11 -0
  68. package/src/runtime/server/data/index.js +146 -0
  69. package/src/runtime/server/endpoint.js +63 -0
  70. package/src/runtime/server/index.js +339 -0
  71. package/src/runtime/server/page/cookie.js +25 -0
  72. package/src/runtime/server/page/crypto.js +239 -0
  73. package/src/runtime/server/page/csp.js +249 -0
  74. package/src/runtime/server/page/fetch.js +269 -0
  75. package/src/runtime/server/page/index.js +404 -0
  76. package/src/runtime/server/page/load_data.js +124 -0
  77. package/src/runtime/server/page/render.js +358 -0
  78. package/src/runtime/server/page/respond_with_error.js +92 -0
  79. package/src/runtime/server/page/serialize_data.js +58 -0
  80. package/src/runtime/server/page/types.d.ts +44 -0
  81. package/src/runtime/server/utils.js +209 -0
  82. package/src/utils/array.js +9 -0
  83. package/src/utils/error.js +22 -0
  84. package/src/utils/escape.js +46 -0
  85. package/src/utils/filesystem.js +108 -0
  86. package/src/utils/functions.js +16 -0
  87. package/src/utils/http.js +55 -0
  88. package/src/utils/misc.js +1 -0
  89. package/src/utils/routing.js +137 -0
  90. package/src/utils/url.js +142 -0
  91. package/svelte-kit.js +1 -1
  92. package/types/ambient.d.ts +332 -0
  93. package/types/index.d.ts +343 -0
  94. package/types/internal.d.ts +383 -0
  95. package/types/private.d.ts +213 -0
  96. package/CHANGELOG.md +0 -456
  97. package/assets/components/error.svelte +0 -13
  98. package/assets/runtime/app/env.js +0 -5
  99. package/assets/runtime/app/navigation.js +0 -44
  100. package/assets/runtime/app/paths.js +0 -1
  101. package/assets/runtime/app/stores.js +0 -93
  102. package/assets/runtime/chunks/utils.js +0 -22
  103. package/assets/runtime/internal/singletons.js +0 -23
  104. package/assets/runtime/internal/start.js +0 -771
  105. package/assets/runtime/paths.js +0 -12
  106. package/dist/chunks/index.js +0 -3522
  107. package/dist/chunks/index2.js +0 -587
  108. package/dist/chunks/index3.js +0 -246
  109. package/dist/chunks/index4.js +0 -539
  110. package/dist/chunks/index5.js +0 -763
  111. package/dist/chunks/index6.js +0 -322
  112. package/dist/chunks/standard.js +0 -99
  113. package/dist/chunks/utils.js +0 -83
  114. package/dist/cli.js +0 -546
  115. 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,269 @@
1
+ import * as cookie from 'cookie';
2
+ import * as set_cookie_parser from 'set-cookie-parser';
3
+ import { respond } from '../index.js';
4
+ import { is_root_relative, resolve } from '../../../utils/url.js';
5
+ import { domain_matches, path_matches } from './cookie.js';
6
+
7
+ /**
8
+ * @param {{
9
+ * event: import('types').RequestEvent;
10
+ * options: import('types').SSROptions;
11
+ * state: import('types').SSRState;
12
+ * route: import('types').SSRRoute | import('types').SSRErrorPage;
13
+ * prerender_default?: import('types').PrerenderOption;
14
+ * }} opts
15
+ */
16
+ export function create_fetch({ event, options, state, route, prerender_default }) {
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 cookies = [];
24
+
25
+ /** @type {typeof fetch} */
26
+ const fetcher = async (resource, opts = {}) => {
27
+ /** @type {string} */
28
+ let requested;
29
+
30
+ if (typeof resource === 'string' || resource instanceof URL) {
31
+ requested = resource.toString();
32
+ } else {
33
+ requested = resource.url;
34
+
35
+ opts = {
36
+ method: resource.method,
37
+ headers: resource.headers,
38
+ body: resource.body,
39
+ mode: resource.mode,
40
+ credentials: resource.credentials,
41
+ cache: resource.cache,
42
+ redirect: resource.redirect,
43
+ referrer: resource.referrer,
44
+ integrity: resource.integrity,
45
+ ...opts
46
+ };
47
+ }
48
+
49
+ opts.headers = new Headers(opts.headers);
50
+
51
+ // merge headers from request
52
+ for (const [key, value] of event.request.headers) {
53
+ if (
54
+ key !== 'authorization' &&
55
+ key !== 'connection' &&
56
+ key !== 'content-length' &&
57
+ key !== 'cookie' &&
58
+ key !== 'host' &&
59
+ key !== 'if-none-match' &&
60
+ !opts.headers.has(key)
61
+ ) {
62
+ opts.headers.set(key, value);
63
+ }
64
+ }
65
+
66
+ const resolved = resolve(event.url.pathname, requested.split('?')[0]);
67
+
68
+ /** @type {Response} */
69
+ let response;
70
+
71
+ /** @type {import('types').PrerenderDependency} */
72
+ let dependency;
73
+
74
+ // handle fetch requests for static assets. e.g. prebaked data, etc.
75
+ // we need to support everything the browser's fetch supports
76
+ const prefix = options.paths.assets || options.paths.base;
77
+ const filename = decodeURIComponent(
78
+ resolved.startsWith(prefix) ? resolved.slice(prefix.length) : resolved
79
+ ).slice(1);
80
+ const filename_html = `${filename}/index.html`; // path may also match path/index.html
81
+
82
+ const is_asset = options.manifest.assets.has(filename);
83
+ const is_asset_html = options.manifest.assets.has(filename_html);
84
+
85
+ if (is_asset || is_asset_html) {
86
+ const file = is_asset ? filename : filename_html;
87
+
88
+ if (options.read) {
89
+ const type = is_asset
90
+ ? options.manifest.mimeTypes[filename.slice(filename.lastIndexOf('.'))]
91
+ : 'text/html';
92
+
93
+ response = new Response(options.read(file), {
94
+ headers: type ? { 'content-type': type } : {}
95
+ });
96
+ } else {
97
+ response = await fetch(`${event.url.origin}/${file}`, /** @type {RequestInit} */ (opts));
98
+ }
99
+ } else if (is_root_relative(resolved)) {
100
+ if (opts.credentials !== 'omit') {
101
+ const authorization = event.request.headers.get('authorization');
102
+
103
+ // combine cookies from the initiating request with any that were
104
+ // added via set-cookie
105
+ const combined_cookies = { ...initial_cookies };
106
+
107
+ for (const cookie of cookies) {
108
+ if (!domain_matches(event.url.hostname, cookie.domain)) continue;
109
+ if (!path_matches(resolved, cookie.path)) continue;
110
+
111
+ combined_cookies[cookie.name] = cookie.value;
112
+ }
113
+
114
+ const cookie = Object.entries(combined_cookies)
115
+ .map(([name, value]) => `${name}=${value}`)
116
+ .join('; ');
117
+
118
+ if (cookie) {
119
+ opts.headers.set('cookie', cookie);
120
+ }
121
+
122
+ if (authorization && !opts.headers.has('authorization')) {
123
+ opts.headers.set('authorization', authorization);
124
+ }
125
+ }
126
+
127
+ if (opts.body && typeof opts.body !== 'string') {
128
+ // per https://developer.mozilla.org/en-US/docs/Web/API/Request/Request, this can be a
129
+ // Blob, BufferSource, FormData, URLSearchParams, USVString, or ReadableStream object.
130
+ // non-string bodies are irksome to deal with, but luckily aren't particularly useful
131
+ // in this context anyway, so we take the easy route and ban them
132
+ throw new Error('Request body must be a string');
133
+ }
134
+
135
+ response = await respond(
136
+ new Request(new URL(requested, event.url).href, { ...opts }),
137
+ options,
138
+ {
139
+ prerender_default,
140
+ ...state,
141
+ initiator: route
142
+ }
143
+ );
144
+
145
+ if (state.prerendering) {
146
+ dependency = { response, body: null };
147
+ state.prerendering.dependencies.set(resolved, dependency);
148
+ }
149
+ } else {
150
+ // external
151
+ if (resolved.startsWith('//')) {
152
+ requested = event.url.protocol + requested;
153
+ }
154
+
155
+ // external fetch
156
+ // allow cookie passthrough for "same-origin"
157
+ // if SvelteKit is serving my.domain.com:
158
+ // - domain.com WILL NOT receive cookies
159
+ // - my.domain.com WILL receive cookies
160
+ // - api.domain.dom WILL NOT receive cookies
161
+ // - sub.my.domain.com WILL receive cookies
162
+ // ports do not affect the resolution
163
+ // leading dot prevents mydomain.com matching domain.com
164
+ if (
165
+ `.${new URL(requested).hostname}`.endsWith(`.${event.url.hostname}`) &&
166
+ opts.credentials !== 'omit'
167
+ ) {
168
+ const cookie = event.request.headers.get('cookie');
169
+ if (cookie) opts.headers.set('cookie', cookie);
170
+ }
171
+
172
+ // we need to delete the connection header, as explained here:
173
+ // https://github.com/nodejs/undici/issues/1470#issuecomment-1140798467
174
+ // TODO this may be a case for being selective about which headers we let through
175
+ opts.headers.delete('connection');
176
+
177
+ const external_request = new Request(requested, /** @type {RequestInit} */ (opts));
178
+ response = await options.hooks.externalFetch.call(null, external_request);
179
+ }
180
+
181
+ const set_cookie = response.headers.get('set-cookie');
182
+ if (set_cookie) {
183
+ cookies.push(
184
+ ...set_cookie_parser
185
+ .splitCookiesString(set_cookie)
186
+ .map((str) => set_cookie_parser.parseString(str))
187
+ );
188
+ }
189
+
190
+ const proxy = new Proxy(response, {
191
+ get(response, key, _receiver) {
192
+ async function text() {
193
+ const body = await response.text();
194
+
195
+ // TODO just pass `response.headers`, for processing inside `serialize_data`
196
+ /** @type {import('types').ResponseHeaders} */
197
+ const headers = {};
198
+ for (const [key, value] of response.headers) {
199
+ // TODO skip others besides set-cookie and etag?
200
+ if (key !== 'set-cookie' && key !== 'etag') {
201
+ headers[key] = value;
202
+ }
203
+ }
204
+
205
+ if (!opts.body || typeof opts.body === 'string') {
206
+ const status_number = Number(response.status);
207
+ if (isNaN(status_number)) {
208
+ throw new Error(
209
+ `response.status is not a number. value: "${
210
+ response.status
211
+ }" type: ${typeof response.status}`
212
+ );
213
+ }
214
+
215
+ fetched.push({
216
+ url: requested,
217
+ body: opts.body,
218
+ response: {
219
+ status: status_number,
220
+ statusText: response.statusText,
221
+ headers,
222
+ body
223
+ }
224
+ });
225
+ }
226
+
227
+ if (dependency) {
228
+ dependency.body = body;
229
+ }
230
+
231
+ return body;
232
+ }
233
+
234
+ if (key === 'arrayBuffer') {
235
+ return async () => {
236
+ const buffer = await response.arrayBuffer();
237
+
238
+ if (dependency) {
239
+ dependency.body = new Uint8Array(buffer);
240
+ }
241
+
242
+ // TODO should buffer be inlined into the page (albeit base64'd)?
243
+ // any conditions in which it shouldn't be?
244
+
245
+ return buffer;
246
+ };
247
+ }
248
+
249
+ if (key === 'text') {
250
+ return text;
251
+ }
252
+
253
+ if (key === 'json') {
254
+ return async () => {
255
+ return JSON.parse(await text());
256
+ };
257
+ }
258
+
259
+ // TODO arrayBuffer?
260
+
261
+ return Reflect.get(response, key, response);
262
+ }
263
+ });
264
+
265
+ return proxy;
266
+ };
267
+
268
+ return { fetcher, fetched, cookies };
269
+ }