@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,358 @@
1
+ import { devalue } from 'devalue';
2
+ import { readable, writable } from 'svelte/store';
3
+ import * as cookie from 'cookie';
4
+ import { hash } from '../../hash.js';
5
+ import { serialize_data } from './serialize_data.js';
6
+ import { s } from '../../../utils/misc.js';
7
+ import { Csp } from './csp.js';
8
+ import { serialize_error } from '../utils.js';
9
+ import { HttpError } from '../../control.js';
10
+
11
+ // TODO rename this function/module
12
+
13
+ const updated = {
14
+ ...readable(false),
15
+ check: () => false
16
+ };
17
+
18
+ /**
19
+ * Creates the HTML response.
20
+ * @param {{
21
+ * branch: Array<import('./types').Loaded>;
22
+ * fetched: Array<import('./types').Fetched>;
23
+ * cookies: import('set-cookie-parser').Cookie[];
24
+ * options: import('types').SSROptions;
25
+ * state: import('types').SSRState;
26
+ * page_config: { ssr: boolean; csr: boolean };
27
+ * status: number;
28
+ * error: HttpError | Error | null;
29
+ * event: import('types').RequestEvent;
30
+ * resolve_opts: import('types').RequiredResolveOptions;
31
+ * validation_errors: Record<string, string> | undefined;
32
+ * }} opts
33
+ */
34
+ export async function render_response({
35
+ branch,
36
+ fetched,
37
+ cookies,
38
+ options,
39
+ state,
40
+ page_config,
41
+ status,
42
+ error = null,
43
+ event,
44
+ resolve_opts,
45
+ validation_errors
46
+ }) {
47
+ if (state.prerendering) {
48
+ if (options.csp.mode === 'nonce') {
49
+ throw new Error('Cannot use prerendering if config.kit.csp.mode === "nonce"');
50
+ }
51
+
52
+ if (options.app_template_contains_nonce) {
53
+ throw new Error('Cannot use prerendering if page template contains %sveltekit.nonce%');
54
+ }
55
+ }
56
+
57
+ const { entry } = options.manifest._;
58
+
59
+ const stylesheets = new Set(entry.stylesheets);
60
+ const modulepreloads = new Set(entry.imports);
61
+
62
+ /** @type {Set<string>} */
63
+ const link_header_preloads = new Set();
64
+
65
+ /** @type {Map<string, string>} */
66
+ // TODO if we add a client entry point one day, we will need to include inline_styles with the entry, otherwise stylesheets will be linked even if they are below inlineStyleThreshold
67
+ const inline_styles = new Map();
68
+
69
+ let rendered;
70
+
71
+ const stack = error instanceof HttpError ? undefined : error?.stack;
72
+
73
+ if (error && options.dev && !(error instanceof HttpError)) {
74
+ error.stack = options.get_stack(error);
75
+ }
76
+
77
+ if (page_config.ssr) {
78
+ /** @type {Record<string, any>} */
79
+ const props = {
80
+ stores: {
81
+ page: writable(null),
82
+ navigating: writable(null),
83
+ updated
84
+ },
85
+ components: await Promise.all(branch.map(({ node }) => node.component()))
86
+ };
87
+
88
+ let data = {};
89
+
90
+ // props_n (instead of props[n]) makes it easy to avoid
91
+ // unnecessary updates for layout components
92
+ for (let i = 0; i < branch.length; i += 1) {
93
+ data = { ...data, ...branch[i].data };
94
+ props[`data_${i}`] = data;
95
+ }
96
+
97
+ props.page = {
98
+ error,
99
+ params: /** @type {Record<string, any>} */ (event.params),
100
+ routeId: event.routeId,
101
+ status,
102
+ url: event.url,
103
+ data
104
+ };
105
+
106
+ if (validation_errors) {
107
+ props.errors = validation_errors;
108
+ }
109
+
110
+ // TODO remove this for 1.0
111
+ /**
112
+ * @param {string} property
113
+ * @param {string} replacement
114
+ */
115
+ const print_error = (property, replacement) => {
116
+ Object.defineProperty(props.page, property, {
117
+ get: () => {
118
+ throw new Error(`$page.${property} has been replaced by $page.url.${replacement}`);
119
+ }
120
+ });
121
+ };
122
+
123
+ print_error('origin', 'origin');
124
+ print_error('path', 'pathname');
125
+ print_error('query', 'searchParams');
126
+
127
+ rendered = options.root.render(props);
128
+
129
+ for (const { node } of branch) {
130
+ if (node.imports) {
131
+ node.imports.forEach((url) => modulepreloads.add(url));
132
+ }
133
+
134
+ if (node.stylesheets) {
135
+ node.stylesheets.forEach((url) => stylesheets.add(url));
136
+ }
137
+
138
+ if (node.inline_styles) {
139
+ Object.entries(await node.inline_styles()).forEach(([k, v]) => inline_styles.set(k, v));
140
+ }
141
+ }
142
+ } else {
143
+ rendered = { head: '', html: '', css: { code: '', map: null } };
144
+ }
145
+
146
+ let { head, html: body } = rendered;
147
+
148
+ const csp = new Csp(options.csp, {
149
+ dev: options.dev,
150
+ prerender: !!state.prerendering
151
+ });
152
+
153
+ const target = hash(body);
154
+
155
+ /**
156
+ * The prefix to use for static assets. Replaces `%sveltekit.assets%` in the template
157
+ * @type {string}
158
+ */
159
+ let assets;
160
+
161
+ if (options.paths.assets) {
162
+ // if an asset path is specified, use it
163
+ assets = options.paths.assets;
164
+ } else if (state.prerendering?.fallback) {
165
+ // if we're creating a fallback page, asset paths need to be root-relative
166
+ assets = options.paths.base;
167
+ } else {
168
+ // otherwise we want asset paths to be relative to the page, so that they
169
+ // will work in odd contexts like IPFS, the internet archive, and so on
170
+ const segments = event.url.pathname.slice(options.paths.base.length).split('/').slice(2);
171
+ assets = segments.length > 0 ? segments.map(() => '..').join('/') : '.';
172
+ }
173
+
174
+ /** @param {string} path */
175
+ const prefixed = (path) => (path.startsWith('/') ? path : `${assets}/${path}`);
176
+
177
+ const serialized = { data: '', errors: 'null' };
178
+
179
+ try {
180
+ serialized.data = devalue(branch.map(({ server_data }) => server_data));
181
+ } catch (e) {
182
+ // If we're here, the data could not be serialized with devalue
183
+ // TODO if we wanted to get super fancy we could track down the origin of the `load`
184
+ // function, but it would mean passing more stuff around than we currently do
185
+ const error = /** @type {any} */ (e);
186
+ const match = /\[(\d+)\]\.data\.(.+)/.exec(error.path);
187
+ if (match) throw new Error(`${error.message} (data.${match[2]})`);
188
+ throw error;
189
+ }
190
+
191
+ if (validation_errors) {
192
+ try {
193
+ serialized.errors = devalue(validation_errors);
194
+ } catch (e) {
195
+ // If we're here, the data could not be serialized with devalue
196
+ const error = /** @type {any} */ (e);
197
+ if (error.path) throw new Error(`${error.message} (errors.${error.path})`);
198
+ throw error;
199
+ }
200
+ }
201
+
202
+ // prettier-ignore
203
+ const init_app = `
204
+ import { start } from ${s(prefixed(entry.file))};
205
+
206
+ start({
207
+ env: ${s(options.public_env)},
208
+ hydrate: ${page_config.ssr ? `{
209
+ status: ${status},
210
+ error: ${error && serialize_error(error, e => e.stack)},
211
+ node_ids: [${branch.map(({ node }) => node.index).join(', ')}],
212
+ params: ${devalue(event.params)},
213
+ routeId: ${s(event.routeId)},
214
+ data: ${serialized.data},
215
+ errors: ${serialized.errors}
216
+ }` : 'null'},
217
+ paths: ${s(options.paths)},
218
+ target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
219
+ trailing_slash: ${s(options.trailing_slash)}
220
+ });
221
+ `;
222
+
223
+ // we use an anonymous function instead of an arrow function to support
224
+ // older browsers (https://github.com/sveltejs/kit/pull/5417)
225
+ const init_service_worker = `
226
+ if ('serviceWorker' in navigator) {
227
+ addEventListener('load', function () {
228
+ navigator.serviceWorker.register('${options.service_worker}');
229
+ });
230
+ }
231
+ `;
232
+
233
+ if (inline_styles.size > 0) {
234
+ const content = Array.from(inline_styles.values()).join('\n');
235
+
236
+ const attributes = [];
237
+ if (options.dev) attributes.push(' data-sveltekit');
238
+ if (csp.style_needs_nonce) attributes.push(` nonce="${csp.nonce}"`);
239
+
240
+ csp.add_style(content);
241
+
242
+ head += `\n\t<style${attributes.join('')}>${content}</style>`;
243
+ }
244
+
245
+ for (const dep of stylesheets) {
246
+ const path = prefixed(dep);
247
+ const attributes = [];
248
+
249
+ if (csp.style_needs_nonce) {
250
+ attributes.push(`nonce="${csp.nonce}"`);
251
+ }
252
+
253
+ if (inline_styles.has(dep)) {
254
+ // don't load stylesheets that are already inlined
255
+ // include them in disabled state so that Vite can detect them and doesn't try to add them
256
+ attributes.push('disabled', 'media="(max-width: 0)"');
257
+ } else {
258
+ const preload_atts = ['rel="preload"', 'as="style"'].concat(attributes);
259
+ link_header_preloads.add(`<${encodeURI(path)}>; ${preload_atts.join(';')}; nopush`);
260
+ }
261
+
262
+ attributes.unshift('rel="stylesheet"');
263
+ head += `\n\t<link href="${path}" ${attributes.join(' ')}>`;
264
+ }
265
+
266
+ if (page_config.csr) {
267
+ for (const dep of modulepreloads) {
268
+ const path = prefixed(dep);
269
+ link_header_preloads.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
270
+ if (state.prerendering) {
271
+ head += `\n\t<link rel="modulepreload" href="${path}">`;
272
+ }
273
+ }
274
+
275
+ const attributes = ['type="module"', `data-sveltekit-hydrate="${target}"`];
276
+
277
+ csp.add_script(init_app);
278
+
279
+ if (csp.script_needs_nonce) {
280
+ attributes.push(`nonce="${csp.nonce}"`);
281
+ }
282
+
283
+ body += `\n\t\t<script ${attributes.join(' ')}>${init_app}</script>`;
284
+ }
285
+
286
+ if (page_config.ssr && page_config.csr) {
287
+ body += `\n\t${fetched.map(serialize_data).join('\n\t')}`;
288
+ }
289
+
290
+ if (options.service_worker) {
291
+ // always include service worker unless it's turned off explicitly
292
+ csp.add_script(init_service_worker);
293
+
294
+ head += `
295
+ <script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ''}>${init_service_worker}</script>`;
296
+ }
297
+
298
+ if (state.prerendering) {
299
+ // TODO read headers set with setHeaders and convert into http-equiv where possible
300
+ const http_equiv = [];
301
+
302
+ const csp_headers = csp.csp_provider.get_meta();
303
+ if (csp_headers) {
304
+ http_equiv.push(csp_headers);
305
+ }
306
+
307
+ if (state.prerendering.cache) {
308
+ http_equiv.push(`<meta http-equiv="cache-control" content="${state.prerendering.cache}">`);
309
+ }
310
+
311
+ if (http_equiv.length > 0) {
312
+ head = http_equiv.join('\n') + head;
313
+ }
314
+ }
315
+
316
+ // TODO flush chunks as early as we can
317
+ const html =
318
+ (await resolve_opts.transformPageChunk({
319
+ html: options.app_template({ head, body, assets, nonce: /** @type {string} */ (csp.nonce) }),
320
+ done: true
321
+ })) || '';
322
+
323
+ const headers = new Headers({
324
+ 'content-type': 'text/html',
325
+ etag: `"${hash(html)}"`
326
+ });
327
+
328
+ if (!state.prerendering) {
329
+ const csp_header = csp.csp_provider.get_header();
330
+ if (csp_header) {
331
+ headers.set('content-security-policy', csp_header);
332
+ }
333
+ const report_only_header = csp.report_only_provider.get_header();
334
+ if (report_only_header) {
335
+ headers.set('content-security-policy-report-only', report_only_header);
336
+ }
337
+
338
+ for (const new_cookie of cookies) {
339
+ const { name, value, ...options } = new_cookie;
340
+ // @ts-expect-error
341
+ headers.append('set-cookie', cookie.serialize(name, value, options));
342
+ }
343
+
344
+ if (link_header_preloads.size) {
345
+ headers.set('link', Array.from(link_header_preloads).join(', '));
346
+ }
347
+ }
348
+
349
+ if (error && options.dev && !(error instanceof HttpError)) {
350
+ // reset stack, otherwise it may be 'fixed' a second time
351
+ error.stack = stack;
352
+ }
353
+
354
+ return new Response(html, {
355
+ status,
356
+ headers
357
+ });
358
+ }
@@ -0,0 +1,92 @@
1
+ import { render_response } from './render.js';
2
+ import { load_data, load_server_data } from './load_data.js';
3
+ import { coalesce_to_error } from '../../../utils/error.js';
4
+ import { GENERIC_ERROR, get_option, static_error_page } from '../utils.js';
5
+ import { create_fetch } from './fetch.js';
6
+
7
+ /**
8
+ * @typedef {import('./types.js').Loaded} Loaded
9
+ * @typedef {import('types').SSROptions} SSROptions
10
+ * @typedef {import('types').SSRState} SSRState
11
+ */
12
+
13
+ /**
14
+ * @param {{
15
+ * event: import('types').RequestEvent;
16
+ * options: SSROptions;
17
+ * state: SSRState;
18
+ * status: number;
19
+ * error: Error;
20
+ * resolve_opts: import('types').RequiredResolveOptions;
21
+ * }} opts
22
+ */
23
+ export async function respond_with_error({ event, options, state, status, error, resolve_opts }) {
24
+ const { fetcher, fetched, cookies } = create_fetch({
25
+ event,
26
+ options,
27
+ state,
28
+ route: GENERIC_ERROR
29
+ });
30
+
31
+ try {
32
+ const branch = [];
33
+ const default_layout = await options.manifest._.nodes[0](); // 0 is always the root layout
34
+ const ssr = get_option([default_layout], 'ssr') ?? true;
35
+
36
+ if (ssr) {
37
+ const server_data_promise = load_server_data({
38
+ event,
39
+ state,
40
+ node: default_layout,
41
+ parent: async () => ({})
42
+ });
43
+
44
+ const server_data = await server_data_promise;
45
+
46
+ const data = await load_data({
47
+ event,
48
+ fetcher,
49
+ node: default_layout,
50
+ parent: async () => ({}),
51
+ server_data_promise,
52
+ state
53
+ });
54
+
55
+ branch.push(
56
+ {
57
+ node: default_layout,
58
+ server_data,
59
+ data
60
+ },
61
+ {
62
+ node: await options.manifest._.nodes[1](), // 1 is always the root error
63
+ data: null,
64
+ server_data: null
65
+ }
66
+ );
67
+ }
68
+
69
+ return await render_response({
70
+ options,
71
+ state,
72
+ page_config: {
73
+ ssr,
74
+ csr: get_option([default_layout], 'csr') ?? true
75
+ },
76
+ status,
77
+ error,
78
+ branch,
79
+ fetched,
80
+ cookies,
81
+ event,
82
+ resolve_opts,
83
+ validation_errors: undefined
84
+ });
85
+ } catch (err) {
86
+ const error = coalesce_to_error(err);
87
+
88
+ options.handle_error(error, event);
89
+
90
+ return static_error_page(options, 500, error.message);
91
+ }
92
+ }
@@ -0,0 +1,58 @@
1
+ import { escape_html_attr } from '../../../utils/escape.js';
2
+ import { hash } from '../../hash.js';
3
+
4
+ /**
5
+ * Inside a script element, only `</script` and `<!--` hold special meaning to the HTML parser.
6
+ *
7
+ * The first closes the script element, so everything after is treated as raw HTML.
8
+ * The second disables further parsing until `-->`, so the script element might be unexpectedly
9
+ * kept open until until an unrelated HTML comment in the page.
10
+ *
11
+ * U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are escaped for the sake of pre-2018
12
+ * browsers.
13
+ *
14
+ * @see tests for unsafe parsing examples.
15
+ * @see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
16
+ * @see https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions
17
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-state
18
+ * @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-double-escaped-state
19
+ * @see https://github.com/tc39/proposal-json-superset
20
+ * @type {Record<string, string>}
21
+ */
22
+ const replacements = {
23
+ '<': '\\u003C',
24
+ '\u2028': '\\u2028',
25
+ '\u2029': '\\u2029'
26
+ };
27
+
28
+ const pattern = new RegExp(`[${Object.keys(replacements).join('')}]`, 'g');
29
+
30
+ /**
31
+ * Generates a raw HTML string containing a safe script element carrying data and associated attributes.
32
+ *
33
+ * It escapes all the special characters needed to guarantee the element is unbroken, but care must
34
+ * be taken to ensure it is inserted in the document at an acceptable position for a script element,
35
+ * and that the resulting string isn't further modified.
36
+ *
37
+ * @param {import('./types.js').Fetched} fetched
38
+ * @returns {string} The raw HTML of a script element carrying the JSON payload.
39
+ * @example const html = serialize_data('/data.json', null, { foo: 'bar' });
40
+ */
41
+ export function serialize_data(fetched) {
42
+ const safe_payload = JSON.stringify(fetched.response).replace(
43
+ pattern,
44
+ (match) => replacements[match]
45
+ );
46
+
47
+ const attrs = [
48
+ 'type="application/json"',
49
+ 'data-sveltekit-fetched',
50
+ `data-url=${escape_html_attr(fetched.url)}`
51
+ ];
52
+
53
+ if (fetched.body) {
54
+ attrs.push(`data-hash=${escape_html_attr(hash(fetched.body))}`);
55
+ }
56
+
57
+ return `<script ${attrs.join(' ')}>${safe_payload}</script>`;
58
+ }
@@ -0,0 +1,44 @@
1
+ import { ResponseHeaders, SSRNode, CspDirectives } from 'types';
2
+ import { HttpError } from '../../control.js';
3
+
4
+ export interface Fetched {
5
+ url: string;
6
+ body?: string | null;
7
+ response: {
8
+ status: number;
9
+ statusText: string;
10
+ headers: ResponseHeaders;
11
+ body: string;
12
+ };
13
+ }
14
+
15
+ export interface FetchState {
16
+ fetched: Fetched[];
17
+ cookies: string[];
18
+ new_cookies: string[];
19
+ }
20
+
21
+ export type Loaded = {
22
+ node: SSRNode;
23
+ data: Record<string, any> | null;
24
+ server_data: any;
25
+ };
26
+
27
+ type CspMode = 'hash' | 'nonce' | 'auto';
28
+
29
+ export interface CspConfig {
30
+ mode: CspMode;
31
+ directives: CspDirectives;
32
+ reportOnly: CspDirectives;
33
+ }
34
+
35
+ export interface CspOpts {
36
+ dev: boolean;
37
+ prerender: boolean;
38
+ }
39
+
40
+ export interface SerializedHttpError extends Pick<HttpError, 'message' | 'status'> {
41
+ name: 'HttpError';
42
+ stack: '';
43
+ __is_http_error: true;
44
+ }