@mindflight/mindbrain-personal-studio 0.6.1
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/.env.example +50 -0
- package/README.md +134 -0
- package/bin/mindbrain-studio.mjs +20 -0
- package/build/client/_app/immutable/assets/2.BXRKVU9n.css +1 -0
- package/build/client/_app/immutable/assets/2.BXRKVU9n.css.br +0 -0
- package/build/client/_app/immutable/assets/2.BXRKVU9n.css.gz +0 -0
- package/build/client/_app/immutable/chunks/-OSExkSk.js +2 -0
- package/build/client/_app/immutable/chunks/-OSExkSk.js.br +0 -0
- package/build/client/_app/immutable/chunks/-OSExkSk.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BIHI7g3E.js +1 -0
- package/build/client/_app/immutable/chunks/BIHI7g3E.js.br +2 -0
- package/build/client/_app/immutable/chunks/BIHI7g3E.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BJB7pSge.js +1 -0
- package/build/client/_app/immutable/chunks/BJB7pSge.js.br +0 -0
- package/build/client/_app/immutable/chunks/BJB7pSge.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BNUkRZqg.js +1 -0
- package/build/client/_app/immutable/chunks/BNUkRZqg.js.br +0 -0
- package/build/client/_app/immutable/chunks/BNUkRZqg.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BP2JbIUZ.js +1 -0
- package/build/client/_app/immutable/chunks/BP2JbIUZ.js.br +0 -0
- package/build/client/_app/immutable/chunks/BP2JbIUZ.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BVrgUHq-.js +1 -0
- package/build/client/_app/immutable/chunks/BVrgUHq-.js.br +0 -0
- package/build/client/_app/immutable/chunks/BVrgUHq-.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js +1 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js.br +0 -0
- package/build/client/_app/immutable/chunks/BmeSanva.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BnkCgNCx.js +1 -0
- package/build/client/_app/immutable/chunks/BnkCgNCx.js.br +0 -0
- package/build/client/_app/immutable/chunks/BnkCgNCx.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C5KYKPa8.js +311 -0
- package/build/client/_app/immutable/chunks/C5KYKPa8.js.br +0 -0
- package/build/client/_app/immutable/chunks/C5KYKPa8.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CBDzfqXr.js +1 -0
- package/build/client/_app/immutable/chunks/CBDzfqXr.js.br +0 -0
- package/build/client/_app/immutable/chunks/CBDzfqXr.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Cp9dXlPT.js +1 -0
- package/build/client/_app/immutable/chunks/Cp9dXlPT.js.br +0 -0
- package/build/client/_app/immutable/chunks/Cp9dXlPT.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D0daF8Eh.js +2 -0
- package/build/client/_app/immutable/chunks/D0daF8Eh.js.br +0 -0
- package/build/client/_app/immutable/chunks/D0daF8Eh.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D4SoBmS0.js +1 -0
- package/build/client/_app/immutable/chunks/D4SoBmS0.js.br +0 -0
- package/build/client/_app/immutable/chunks/D4SoBmS0.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DpVrWha3.js +1 -0
- package/build/client/_app/immutable/chunks/DpVrWha3.js.br +0 -0
- package/build/client/_app/immutable/chunks/DpVrWha3.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DyXQogav.js +1 -0
- package/build/client/_app/immutable/chunks/DyXQogav.js.br +0 -0
- package/build/client/_app/immutable/chunks/DyXQogav.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Gs0cNFYG.js +1 -0
- package/build/client/_app/immutable/chunks/Gs0cNFYG.js.br +0 -0
- package/build/client/_app/immutable/chunks/Gs0cNFYG.js.gz +0 -0
- package/build/client/_app/immutable/chunks/NXeHtWpC.js +1 -0
- package/build/client/_app/immutable/chunks/NXeHtWpC.js.br +0 -0
- package/build/client/_app/immutable/chunks/NXeHtWpC.js.gz +0 -0
- package/build/client/_app/immutable/chunks/i0D5dc1Y.js +1 -0
- package/build/client/_app/immutable/chunks/i0D5dc1Y.js.br +0 -0
- package/build/client/_app/immutable/chunks/i0D5dc1Y.js.gz +0 -0
- package/build/client/_app/immutable/chunks/nnWk1BBo.js +1 -0
- package/build/client/_app/immutable/chunks/nnWk1BBo.js.br +0 -0
- package/build/client/_app/immutable/chunks/nnWk1BBo.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js +2 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js.br +0 -0
- package/build/client/_app/immutable/entry/app.CVz6aYsT.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js +1 -0
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js.br +2 -0
- package/build/client/_app/immutable/entry/start.Bt5tVOz8.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.C2sXq0eH.js +1 -0
- package/build/client/_app/immutable/nodes/0.C2sXq0eH.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.C2sXq0eH.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js +1 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.BBtxY46Q.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.D0pSa9ko.js +9 -0
- package/build/client/_app/immutable/nodes/2.D0pSa9ko.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.D0pSa9ko.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/robots.txt +3 -0
- package/build/client/robots.txt.br +0 -0
- package/build/client/robots.txt.gz +0 -0
- package/build/env.js +70 -0
- package/build/env.js.map +1 -0
- package/build/handler.js +26 -0
- package/build/handler.js.map +1 -0
- package/build/index.js +149 -0
- package/build/index.js.map +1 -0
- package/build/server/chunks/chunks/edgeLinkModes.js-CfRqrZtd.js +50 -0
- package/build/server/chunks/chunks/edgeLinkModes.js-CfRqrZtd.js.map +1 -0
- package/build/server/chunks/chunks/environment.js-Bf8x1V_n.js +16 -0
- package/build/server/chunks/chunks/environment.js-Bf8x1V_n.js.map +1 -0
- package/build/server/chunks/chunks/exports.js-DFR3riS9.js +217 -0
- package/build/server/chunks/chunks/exports.js-DFR3riS9.js.map +1 -0
- package/build/server/chunks/chunks/false.js-CRHihH2U.js +4 -0
- package/build/server/chunks/chunks/false.js-CRHihH2U.js.map +1 -0
- package/build/server/chunks/chunks/graphRepository.js-D2DARfVY.js +280 -0
- package/build/server/chunks/chunks/graphRepository.js-D2DARfVY.js.map +1 -0
- package/build/server/chunks/chunks/internal.js-D8EA_he2.js +119 -0
- package/build/server/chunks/chunks/internal.js-D8EA_he2.js.map +1 -0
- package/build/server/chunks/chunks/mindbrainClient.js-BFAJqRSL.js +108 -0
- package/build/server/chunks/chunks/mindbrainClient.js-BFAJqRSL.js.map +1 -0
- package/build/server/chunks/chunks/ontologyInspect.js-Dm3l7KgF.js +13 -0
- package/build/server/chunks/chunks/ontologyInspect.js-Dm3l7KgF.js.map +1 -0
- package/build/server/chunks/chunks/render-context.js-CTu5Wkzp.js +475 -0
- package/build/server/chunks/chunks/render-context.js-CTu5Wkzp.js.map +1 -0
- package/build/server/chunks/chunks/renderer.js-DsOhU1UZ.js +1243 -0
- package/build/server/chunks/chunks/renderer.js-DsOhU1UZ.js.map +1 -0
- package/build/server/chunks/chunks/root.js-DCnlE3XY.js +2815 -0
- package/build/server/chunks/chunks/root.js-DCnlE3XY.js.map +1 -0
- package/build/server/chunks/chunks/shared-server.js-DaWdgxVh.js +11 -0
- package/build/server/chunks/chunks/shared-server.js-DaWdgxVh.js.map +1 -0
- package/build/server/chunks/chunks/shared.js-DuDDTJVi.js +1338 -0
- package/build/server/chunks/chunks/shared.js-DuDDTJVi.js.map +1 -0
- package/build/server/chunks/chunks/utils.js-DGYJFmnf.js +39 -0
- package/build/server/chunks/chunks/utils.js-DGYJFmnf.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/brain/_...path_/_server.ts.js-MgPpKBks.js +82 -0
- package/build/server/chunks/entries/endpoints/api/brain/_...path_/_server.ts.js-MgPpKBks.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/brain/health/_server.ts.js-DnJQNmWV.js +19 -0
- package/build/server/chunks/entries/endpoints/api/brain/health/_server.ts.js-DnJQNmWV.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/_server.ts.js-Bxo7qHVz.js +37 -0
- package/build/server/chunks/entries/endpoints/api/graph/_server.ts.js-Bxo7qHVz.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/count/_server.ts.js-BajaLnqp.js +37 -0
- package/build/server/chunks/entries/endpoints/api/graph/count/_server.ts.js-BajaLnqp.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/ontologies/_server.ts.js-BFq2mbbX.js +146 -0
- package/build/server/chunks/entries/endpoints/api/graph/ontologies/_server.ts.js-BFq2mbbX.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/graph/schema-registry/_server.ts.js-Dyfsc-VA.js +154 -0
- package/build/server/chunks/entries/endpoints/api/graph/schema-registry/_server.ts.js-Dyfsc-VA.js.map +1 -0
- package/build/server/chunks/entries/endpoints/api/projections/catalog/_server.ts.js-Ds1RymA0.js +351 -0
- package/build/server/chunks/entries/endpoints/api/projections/catalog/_server.ts.js-Ds1RymA0.js.map +1 -0
- package/build/server/chunks/entries/fallbacks/error.svelte.js-B7V4yZjo.js +51 -0
- package/build/server/chunks/entries/fallbacks/error.svelte.js-B7V4yZjo.js.map +1 -0
- package/build/server/chunks/entries/pages/_layout.svelte.js-CoC9BAeH.js +15 -0
- package/build/server/chunks/entries/pages/_layout.svelte.js-CoC9BAeH.js.map +1 -0
- package/build/server/chunks/entries/pages/_page.svelte.js-DMEbD3K6.js +891 -0
- package/build/server/chunks/entries/pages/_page.svelte.js-DMEbD3K6.js.map +1 -0
- package/build/server/chunks/handler-BjXBCd1c.js +1698 -0
- package/build/server/chunks/handler-BjXBCd1c.js.map +1 -0
- package/build/server/chunks/index.js-BJYcV8V7.js +4183 -0
- package/build/server/chunks/index.js-BJYcV8V7.js.map +1 -0
- package/build/server/chunks/manifest.js-Ddaot0P4.js +91 -0
- package/build/server/chunks/manifest.js-Ddaot0P4.js.map +1 -0
- package/build/server/chunks/nodes/0.js-87v83UX9.js +9 -0
- package/build/server/chunks/nodes/0.js-87v83UX9.js.map +1 -0
- package/build/server/chunks/nodes/1.js-BRigw_9J.js +9 -0
- package/build/server/chunks/nodes/1.js-BRigw_9J.js.map +1 -0
- package/build/server/chunks/nodes/2.js-D9-B_qyX.js +9 -0
- package/build/server/chunks/nodes/2.js-D9-B_qyX.js.map +1 -0
- package/build/shims.js +33 -0
- package/build/shims.js.map +1 -0
- package/fixtures/minimal-graph.sqlite +0 -0
- package/package.json +81 -0
- package/scripts/backend-sqlite.mjs +190 -0
- package/scripts/build-serenity-v6-concept-review-pack.mjs +493 -0
- package/scripts/build-serenity-v6-review-pack.mjs +479 -0
- package/scripts/create-serenity-production-v6.mjs +627 -0
- package/scripts/dev-sqlite.mjs +86 -0
- package/scripts/export-serenity-v6-backup.mjs +178 -0
- package/scripts/import-serenity-v6-user-decisions.mjs +543 -0
- package/scripts/lib/sqlite-runtime.mjs +197 -0
- package/scripts/materialize-serenity-v6-snapshots.mjs +675 -0
- package/scripts/publish-npm.mjs +134 -0
- package/scripts/seed-immeuble-projections.mjs +169 -0
- package/scripts/studio-sqlite.mjs +74 -0
|
@@ -0,0 +1,1338 @@
|
|
|
1
|
+
import { t as text_decoder, b as base64_decode } from './utils.js-DGYJFmnf.js';
|
|
2
|
+
import { D as DevalueError, i as is_primitive, g as get_type, a as is_plain_object, e as enumerable_symbols, s as stringify_key, b as stringify_string, v as valid_array_indices } from './render-context.js-CTu5Wkzp.js';
|
|
3
|
+
|
|
4
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
5
|
+
|
|
6
|
+
class HttpError {
|
|
7
|
+
/**
|
|
8
|
+
* @param {number} status
|
|
9
|
+
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
|
|
10
|
+
*/
|
|
11
|
+
constructor(status, body) {
|
|
12
|
+
this.status = status;
|
|
13
|
+
if (typeof body === 'string') {
|
|
14
|
+
this.body = { message: body };
|
|
15
|
+
} else if (body) {
|
|
16
|
+
this.body = body;
|
|
17
|
+
} else {
|
|
18
|
+
this.body = { message: `Error: ${status}` };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toString() {
|
|
23
|
+
return JSON.stringify(this.body);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class Redirect {
|
|
28
|
+
/**
|
|
29
|
+
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
|
|
30
|
+
* @param {string} location
|
|
31
|
+
*/
|
|
32
|
+
constructor(status, location) {
|
|
33
|
+
this.status = status;
|
|
34
|
+
this.location = location;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* An error that was thrown from within the SvelteKit runtime that is not fatal and doesn't result in a 500, such as a 404.
|
|
40
|
+
* `SvelteKitError` goes through `handleError`.
|
|
41
|
+
* @extends Error
|
|
42
|
+
*/
|
|
43
|
+
class SvelteKitError extends Error {
|
|
44
|
+
/**
|
|
45
|
+
* @param {number} status
|
|
46
|
+
* @param {string} text
|
|
47
|
+
* @param {string} message
|
|
48
|
+
*/
|
|
49
|
+
constructor(status, text, message) {
|
|
50
|
+
super(message);
|
|
51
|
+
this.status = status;
|
|
52
|
+
this.text = text;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @template [T=undefined]
|
|
58
|
+
*/
|
|
59
|
+
class ActionFailure {
|
|
60
|
+
/**
|
|
61
|
+
* @param {number} status
|
|
62
|
+
* @param {T} data
|
|
63
|
+
*/
|
|
64
|
+
constructor(status, data) {
|
|
65
|
+
this.status = status;
|
|
66
|
+
this.data = data;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const text_encoder = new TextEncoder();
|
|
71
|
+
new TextDecoder();
|
|
72
|
+
|
|
73
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// TODO 3.0: remove these types as they are not used anymore (we can't remove them yet because that would be a breaking change)
|
|
77
|
+
/**
|
|
78
|
+
* @template {number} TNumber
|
|
79
|
+
* @template {any[]} [TArray=[]]
|
|
80
|
+
* @typedef {TNumber extends TArray['length'] ? TArray[number] : LessThan<TNumber, [...TArray, TArray['length']]>} LessThan
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @template {number} TStart
|
|
85
|
+
* @template {number} TEnd
|
|
86
|
+
* @typedef {Exclude<TEnd | LessThan<TEnd>, LessThan<TStart>>} NumericRange
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
// Keep the status codes as `number` because restricting to certain numbers makes it unnecessarily hard to use compared to the benefits
|
|
90
|
+
// (we have runtime errors already to check for invalid codes). Also see https://github.com/sveltejs/kit/issues/11780
|
|
91
|
+
|
|
92
|
+
// we have to repeat the JSDoc because the display for function overloads is broken
|
|
93
|
+
// see https://github.com/microsoft/TypeScript/issues/55056
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Throws an error with a HTTP status code and an optional message.
|
|
97
|
+
* When called during request handling, this will cause SvelteKit to
|
|
98
|
+
* return an error response without invoking `handleError`.
|
|
99
|
+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
100
|
+
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
101
|
+
* @param {App.Error} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
102
|
+
* @overload
|
|
103
|
+
* @param {number} status
|
|
104
|
+
* @param {App.Error} body
|
|
105
|
+
* @return {never}
|
|
106
|
+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
107
|
+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Throws an error with a HTTP status code and an optional message.
|
|
111
|
+
* When called during request handling, this will cause SvelteKit to
|
|
112
|
+
* return an error response without invoking `handleError`.
|
|
113
|
+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
114
|
+
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
115
|
+
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} [body] An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
116
|
+
* @overload
|
|
117
|
+
* @param {number} status
|
|
118
|
+
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} [body]
|
|
119
|
+
* @return {never}
|
|
120
|
+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
121
|
+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* Throws an error with a HTTP status code and an optional message.
|
|
125
|
+
* When called during request handling, this will cause SvelteKit to
|
|
126
|
+
* return an error response without invoking `handleError`.
|
|
127
|
+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
128
|
+
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
129
|
+
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
130
|
+
* @return {never}
|
|
131
|
+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
132
|
+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
133
|
+
*/
|
|
134
|
+
function error(status, body) {
|
|
135
|
+
if ((isNaN(status) || status < 400 || status > 599)) {
|
|
136
|
+
throw new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
throw new HttpError(status, body);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Checks whether this is a redirect thrown by {@link redirect}.
|
|
144
|
+
* @param {unknown} e The object to check.
|
|
145
|
+
* @return {e is Redirect}
|
|
146
|
+
*/
|
|
147
|
+
function isRedirect(e) {
|
|
148
|
+
return e instanceof Redirect;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Create a JSON `Response` object from the supplied data.
|
|
153
|
+
* @param {any} data The value that will be serialized as JSON.
|
|
154
|
+
* @param {ResponseInit} [init] Options such as `status` and `headers` that will be added to the response. `Content-Type: application/json` and `Content-Length` headers will be added automatically.
|
|
155
|
+
*/
|
|
156
|
+
function json(data, init) {
|
|
157
|
+
// TODO deprecate this in favour of `Response.json` when it's
|
|
158
|
+
// more widely supported
|
|
159
|
+
const body = JSON.stringify(data);
|
|
160
|
+
|
|
161
|
+
// we can't just do `text(JSON.stringify(data), init)` because
|
|
162
|
+
// it will set a default `content-type` header. duplicated code
|
|
163
|
+
// means less duplicated work
|
|
164
|
+
const headers = new Headers(init?.headers);
|
|
165
|
+
if (!headers.has('content-length')) {
|
|
166
|
+
headers.set('content-length', text_encoder.encode(body).byteLength.toString());
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!headers.has('content-type')) {
|
|
170
|
+
headers.set('content-type', 'application/json');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return new Response(body, {
|
|
174
|
+
...init,
|
|
175
|
+
headers
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create a `Response` object from the supplied body.
|
|
181
|
+
* @param {string} body The value that will be used as-is.
|
|
182
|
+
* @param {ResponseInit} [init] Options such as `status` and `headers` that will be added to the response. A `Content-Length` header will be added automatically.
|
|
183
|
+
*/
|
|
184
|
+
function text(body, init) {
|
|
185
|
+
const headers = new Headers(init?.headers);
|
|
186
|
+
if (!headers.has('content-length')) {
|
|
187
|
+
const encoded = text_encoder.encode(body);
|
|
188
|
+
headers.set('content-length', encoded.byteLength.toString());
|
|
189
|
+
return new Response(encoded, {
|
|
190
|
+
...init,
|
|
191
|
+
headers
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return new Response(body, {
|
|
196
|
+
...init,
|
|
197
|
+
headers
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// eslint-disable-next-line n/prefer-global/process
|
|
202
|
+
const IN_WEBCONTAINER = !!globalThis.process?.versions?.webcontainer;
|
|
203
|
+
|
|
204
|
+
/** @import { RequestEvent } from '@sveltejs/kit' */
|
|
205
|
+
/** @import { RequestStore } from 'types' */
|
|
206
|
+
/** @import { AsyncLocalStorage } from 'node:async_hooks' */
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
/** @type {RequestStore | null} */
|
|
210
|
+
let sync_store = null;
|
|
211
|
+
|
|
212
|
+
/** @type {AsyncLocalStorage<RequestStore | null> | null} */
|
|
213
|
+
let als;
|
|
214
|
+
|
|
215
|
+
import('node:async_hooks')
|
|
216
|
+
.then((hooks) => (als = new hooks.AsyncLocalStorage()))
|
|
217
|
+
.catch(() => {
|
|
218
|
+
// can't use AsyncLocalStorage, but can still call getRequestEvent synchronously.
|
|
219
|
+
// this isn't behind `supports` because it's basically just StackBlitz (i.e.
|
|
220
|
+
// in-browser usage) that doesn't support it AFAICT
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @template T
|
|
225
|
+
* @param {RequestStore | null} store
|
|
226
|
+
* @param {() => T} fn
|
|
227
|
+
*/
|
|
228
|
+
function with_request_store(store, fn) {
|
|
229
|
+
try {
|
|
230
|
+
sync_store = store;
|
|
231
|
+
return als ? als.run(store, fn) : fn();
|
|
232
|
+
} finally {
|
|
233
|
+
// Since AsyncLocalStorage is not working in webcontainers, we don't reset `sync_store`
|
|
234
|
+
// and handle only one request at a time in `src/runtime/server/index.js`.
|
|
235
|
+
if (!IN_WEBCONTAINER) {
|
|
236
|
+
sync_store = null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @template {{ tracing: { enabled: boolean, root: import('@opentelemetry/api').Span, current: import('@opentelemetry/api').Span } }} T
|
|
243
|
+
* @param {T} event_like
|
|
244
|
+
* @param {import('@opentelemetry/api').Span} current
|
|
245
|
+
* @returns {T}
|
|
246
|
+
*/
|
|
247
|
+
function merge_tracing(event_like, current) {
|
|
248
|
+
return {
|
|
249
|
+
...event_like,
|
|
250
|
+
tracing: {
|
|
251
|
+
...event_like.tracing,
|
|
252
|
+
current
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const SVELTE_KIT_ASSETS = "/_svelte_kit_assets";
|
|
258
|
+
const ENDPOINT_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
259
|
+
const PAGE_METHODS = ["GET", "POST", "HEAD"];
|
|
260
|
+
function encode64(arraybuffer) {
|
|
261
|
+
const dv = new DataView(arraybuffer);
|
|
262
|
+
let binaryString = "";
|
|
263
|
+
for (let i = 0; i < arraybuffer.byteLength; i++) {
|
|
264
|
+
binaryString += String.fromCharCode(dv.getUint8(i));
|
|
265
|
+
}
|
|
266
|
+
return binaryToAscii(binaryString);
|
|
267
|
+
}
|
|
268
|
+
function decode64(string) {
|
|
269
|
+
const binaryString = asciiToBinary(string);
|
|
270
|
+
const arraybuffer = new ArrayBuffer(binaryString.length);
|
|
271
|
+
const dv = new DataView(arraybuffer);
|
|
272
|
+
for (let i = 0; i < arraybuffer.byteLength; i++) {
|
|
273
|
+
dv.setUint8(i, binaryString.charCodeAt(i));
|
|
274
|
+
}
|
|
275
|
+
return arraybuffer;
|
|
276
|
+
}
|
|
277
|
+
const KEY_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
278
|
+
function asciiToBinary(data) {
|
|
279
|
+
if (data.length % 4 === 0) {
|
|
280
|
+
data = data.replace(/==?$/, "");
|
|
281
|
+
}
|
|
282
|
+
let output = "";
|
|
283
|
+
let buffer = 0;
|
|
284
|
+
let accumulatedBits = 0;
|
|
285
|
+
for (let i = 0; i < data.length; i++) {
|
|
286
|
+
buffer <<= 6;
|
|
287
|
+
buffer |= KEY_STRING.indexOf(data[i]);
|
|
288
|
+
accumulatedBits += 6;
|
|
289
|
+
if (accumulatedBits === 24) {
|
|
290
|
+
output += String.fromCharCode((buffer & 16711680) >> 16);
|
|
291
|
+
output += String.fromCharCode((buffer & 65280) >> 8);
|
|
292
|
+
output += String.fromCharCode(buffer & 255);
|
|
293
|
+
buffer = accumulatedBits = 0;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (accumulatedBits === 12) {
|
|
297
|
+
buffer >>= 4;
|
|
298
|
+
output += String.fromCharCode(buffer);
|
|
299
|
+
} else if (accumulatedBits === 18) {
|
|
300
|
+
buffer >>= 2;
|
|
301
|
+
output += String.fromCharCode((buffer & 65280) >> 8);
|
|
302
|
+
output += String.fromCharCode(buffer & 255);
|
|
303
|
+
}
|
|
304
|
+
return output;
|
|
305
|
+
}
|
|
306
|
+
function binaryToAscii(str) {
|
|
307
|
+
let out = "";
|
|
308
|
+
for (let i = 0; i < str.length; i += 3) {
|
|
309
|
+
const groupsOfSix = [void 0, void 0, void 0, void 0];
|
|
310
|
+
groupsOfSix[0] = str.charCodeAt(i) >> 2;
|
|
311
|
+
groupsOfSix[1] = (str.charCodeAt(i) & 3) << 4;
|
|
312
|
+
if (str.length > i + 1) {
|
|
313
|
+
groupsOfSix[1] |= str.charCodeAt(i + 1) >> 4;
|
|
314
|
+
groupsOfSix[2] = (str.charCodeAt(i + 1) & 15) << 2;
|
|
315
|
+
}
|
|
316
|
+
if (str.length > i + 2) {
|
|
317
|
+
groupsOfSix[2] |= str.charCodeAt(i + 2) >> 6;
|
|
318
|
+
groupsOfSix[3] = str.charCodeAt(i + 2) & 63;
|
|
319
|
+
}
|
|
320
|
+
for (let j = 0; j < groupsOfSix.length; j++) {
|
|
321
|
+
if (typeof groupsOfSix[j] === "undefined") {
|
|
322
|
+
out += "=";
|
|
323
|
+
} else {
|
|
324
|
+
out += KEY_STRING[groupsOfSix[j]];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
const UNDEFINED = -1;
|
|
331
|
+
const HOLE = -2;
|
|
332
|
+
const NAN = -3;
|
|
333
|
+
const POSITIVE_INFINITY = -4;
|
|
334
|
+
const NEGATIVE_INFINITY = -5;
|
|
335
|
+
const NEGATIVE_ZERO = -6;
|
|
336
|
+
const SPARSE = -7;
|
|
337
|
+
function parse(serialized, revivers) {
|
|
338
|
+
return unflatten(JSON.parse(serialized), revivers);
|
|
339
|
+
}
|
|
340
|
+
function unflatten(parsed, revivers) {
|
|
341
|
+
if (typeof parsed === "number") return hydrate(parsed, true);
|
|
342
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
343
|
+
throw new Error("Invalid input");
|
|
344
|
+
}
|
|
345
|
+
const values = (
|
|
346
|
+
/** @type {any[]} */
|
|
347
|
+
parsed
|
|
348
|
+
);
|
|
349
|
+
const hydrated = Array(values.length);
|
|
350
|
+
let hydrating = null;
|
|
351
|
+
function hydrate(index, standalone = false) {
|
|
352
|
+
if (index === UNDEFINED) return void 0;
|
|
353
|
+
if (index === NAN) return NaN;
|
|
354
|
+
if (index === POSITIVE_INFINITY) return Infinity;
|
|
355
|
+
if (index === NEGATIVE_INFINITY) return -Infinity;
|
|
356
|
+
if (index === NEGATIVE_ZERO) return -0;
|
|
357
|
+
if (standalone || typeof index !== "number") {
|
|
358
|
+
throw new Error(`Invalid input`);
|
|
359
|
+
}
|
|
360
|
+
if (index in hydrated) return hydrated[index];
|
|
361
|
+
const value = values[index];
|
|
362
|
+
if (!value || typeof value !== "object") {
|
|
363
|
+
hydrated[index] = value;
|
|
364
|
+
} else if (Array.isArray(value)) {
|
|
365
|
+
if (typeof value[0] === "string") {
|
|
366
|
+
const type = value[0];
|
|
367
|
+
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
|
|
368
|
+
if (reviver) {
|
|
369
|
+
let i = value[1];
|
|
370
|
+
if (typeof i !== "number") {
|
|
371
|
+
i = values.push(value[1]) - 1;
|
|
372
|
+
}
|
|
373
|
+
hydrating ??= /* @__PURE__ */ new Set();
|
|
374
|
+
if (hydrating.has(i)) {
|
|
375
|
+
throw new Error("Invalid circular reference");
|
|
376
|
+
}
|
|
377
|
+
hydrating.add(i);
|
|
378
|
+
hydrated[index] = reviver(hydrate(i));
|
|
379
|
+
hydrating.delete(i);
|
|
380
|
+
return hydrated[index];
|
|
381
|
+
}
|
|
382
|
+
switch (type) {
|
|
383
|
+
case "Date":
|
|
384
|
+
hydrated[index] = new Date(value[1]);
|
|
385
|
+
break;
|
|
386
|
+
case "Set":
|
|
387
|
+
const set = /* @__PURE__ */ new Set();
|
|
388
|
+
hydrated[index] = set;
|
|
389
|
+
for (let i = 1; i < value.length; i += 1) {
|
|
390
|
+
set.add(hydrate(value[i]));
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
case "Map":
|
|
394
|
+
const map = /* @__PURE__ */ new Map();
|
|
395
|
+
hydrated[index] = map;
|
|
396
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
397
|
+
map.set(hydrate(value[i]), hydrate(value[i + 1]));
|
|
398
|
+
}
|
|
399
|
+
break;
|
|
400
|
+
case "RegExp":
|
|
401
|
+
hydrated[index] = new RegExp(value[1], value[2]);
|
|
402
|
+
break;
|
|
403
|
+
case "Object":
|
|
404
|
+
const object = Object(value[1]);
|
|
405
|
+
if (Object.hasOwn(object, "__proto__")) {
|
|
406
|
+
throw new Error("Cannot parse an object with a `__proto__` property");
|
|
407
|
+
}
|
|
408
|
+
hydrated[index] = object;
|
|
409
|
+
break;
|
|
410
|
+
case "BigInt":
|
|
411
|
+
hydrated[index] = BigInt(value[1]);
|
|
412
|
+
break;
|
|
413
|
+
case "null":
|
|
414
|
+
const obj = /* @__PURE__ */ Object.create(null);
|
|
415
|
+
hydrated[index] = obj;
|
|
416
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
417
|
+
if (value[i] === "__proto__") {
|
|
418
|
+
throw new Error("Cannot parse an object with a `__proto__` property");
|
|
419
|
+
}
|
|
420
|
+
obj[value[i]] = hydrate(value[i + 1]);
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
case "Int8Array":
|
|
424
|
+
case "Uint8Array":
|
|
425
|
+
case "Uint8ClampedArray":
|
|
426
|
+
case "Int16Array":
|
|
427
|
+
case "Uint16Array":
|
|
428
|
+
case "Int32Array":
|
|
429
|
+
case "Uint32Array":
|
|
430
|
+
case "Float32Array":
|
|
431
|
+
case "Float64Array":
|
|
432
|
+
case "BigInt64Array":
|
|
433
|
+
case "BigUint64Array": {
|
|
434
|
+
if (values[value[1]][0] !== "ArrayBuffer") {
|
|
435
|
+
throw new Error("Invalid data");
|
|
436
|
+
}
|
|
437
|
+
const TypedArrayConstructor = globalThis[type];
|
|
438
|
+
const buffer = hydrate(value[1]);
|
|
439
|
+
const typedArray = new TypedArrayConstructor(buffer);
|
|
440
|
+
hydrated[index] = value[2] !== void 0 ? typedArray.subarray(value[2], value[3]) : typedArray;
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
case "ArrayBuffer": {
|
|
444
|
+
const base64 = value[1];
|
|
445
|
+
if (typeof base64 !== "string") {
|
|
446
|
+
throw new Error("Invalid ArrayBuffer encoding");
|
|
447
|
+
}
|
|
448
|
+
const arraybuffer = decode64(base64);
|
|
449
|
+
hydrated[index] = arraybuffer;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
case "Temporal.Duration":
|
|
453
|
+
case "Temporal.Instant":
|
|
454
|
+
case "Temporal.PlainDate":
|
|
455
|
+
case "Temporal.PlainTime":
|
|
456
|
+
case "Temporal.PlainDateTime":
|
|
457
|
+
case "Temporal.PlainMonthDay":
|
|
458
|
+
case "Temporal.PlainYearMonth":
|
|
459
|
+
case "Temporal.ZonedDateTime": {
|
|
460
|
+
const temporalName = type.slice(9);
|
|
461
|
+
hydrated[index] = Temporal[temporalName].from(value[1]);
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
case "URL": {
|
|
465
|
+
const url = new URL(value[1]);
|
|
466
|
+
hydrated[index] = url;
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
case "URLSearchParams": {
|
|
470
|
+
const url = new URLSearchParams(value[1]);
|
|
471
|
+
hydrated[index] = url;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
default:
|
|
475
|
+
throw new Error(`Unknown type ${type}`);
|
|
476
|
+
}
|
|
477
|
+
} else if (value[0] === SPARSE) {
|
|
478
|
+
const len = value[1];
|
|
479
|
+
if (!Number.isInteger(len) || len < 0) {
|
|
480
|
+
throw new Error("Invalid input");
|
|
481
|
+
}
|
|
482
|
+
const array = new Array(len);
|
|
483
|
+
hydrated[index] = array;
|
|
484
|
+
for (let i = 2; i < value.length; i += 2) {
|
|
485
|
+
const idx = value[i];
|
|
486
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= len) {
|
|
487
|
+
throw new Error("Invalid input");
|
|
488
|
+
}
|
|
489
|
+
array[idx] = hydrate(value[i + 1]);
|
|
490
|
+
}
|
|
491
|
+
} else {
|
|
492
|
+
const array = new Array(value.length);
|
|
493
|
+
hydrated[index] = array;
|
|
494
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
495
|
+
const n = value[i];
|
|
496
|
+
if (n === HOLE) continue;
|
|
497
|
+
array[i] = hydrate(n);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
} else {
|
|
501
|
+
const object = {};
|
|
502
|
+
hydrated[index] = object;
|
|
503
|
+
for (const key of Object.keys(value)) {
|
|
504
|
+
if (key === "__proto__") {
|
|
505
|
+
throw new Error("Cannot parse an object with a `__proto__` property");
|
|
506
|
+
}
|
|
507
|
+
const n = value[key];
|
|
508
|
+
object[key] = hydrate(n);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return hydrated[index];
|
|
512
|
+
}
|
|
513
|
+
return hydrate(0);
|
|
514
|
+
}
|
|
515
|
+
function stringify$1(value, reducers) {
|
|
516
|
+
const stringified = [];
|
|
517
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
518
|
+
const custom = [];
|
|
519
|
+
if (reducers) {
|
|
520
|
+
for (const key of Object.getOwnPropertyNames(reducers)) {
|
|
521
|
+
custom.push({ key, fn: reducers[key] });
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
const keys = [];
|
|
525
|
+
let p = 0;
|
|
526
|
+
function flatten(thing) {
|
|
527
|
+
if (thing === void 0) return UNDEFINED;
|
|
528
|
+
if (Number.isNaN(thing)) return NAN;
|
|
529
|
+
if (thing === Infinity) return POSITIVE_INFINITY;
|
|
530
|
+
if (thing === -Infinity) return NEGATIVE_INFINITY;
|
|
531
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;
|
|
532
|
+
if (indexes.has(thing)) return indexes.get(thing);
|
|
533
|
+
const index2 = p++;
|
|
534
|
+
indexes.set(thing, index2);
|
|
535
|
+
for (const { key, fn } of custom) {
|
|
536
|
+
const value2 = fn(thing);
|
|
537
|
+
if (value2) {
|
|
538
|
+
stringified[index2] = `["${key}",${flatten(value2)}]`;
|
|
539
|
+
return index2;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (typeof thing === "function") {
|
|
543
|
+
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
544
|
+
}
|
|
545
|
+
let str = "";
|
|
546
|
+
if (is_primitive(thing)) {
|
|
547
|
+
str = stringify_primitive(thing);
|
|
548
|
+
} else {
|
|
549
|
+
const type = get_type(thing);
|
|
550
|
+
switch (type) {
|
|
551
|
+
case "Number":
|
|
552
|
+
case "String":
|
|
553
|
+
case "Boolean":
|
|
554
|
+
str = `["Object",${stringify_primitive(thing)}]`;
|
|
555
|
+
break;
|
|
556
|
+
case "BigInt":
|
|
557
|
+
str = `["BigInt",${thing}]`;
|
|
558
|
+
break;
|
|
559
|
+
case "Date":
|
|
560
|
+
const valid = !isNaN(thing.getDate());
|
|
561
|
+
str = `["Date","${valid ? thing.toISOString() : ""}"]`;
|
|
562
|
+
break;
|
|
563
|
+
case "URL":
|
|
564
|
+
str = `["URL",${stringify_string(thing.toString())}]`;
|
|
565
|
+
break;
|
|
566
|
+
case "URLSearchParams":
|
|
567
|
+
str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
|
|
568
|
+
break;
|
|
569
|
+
case "RegExp":
|
|
570
|
+
const { source, flags } = thing;
|
|
571
|
+
str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
|
|
572
|
+
break;
|
|
573
|
+
case "Array": {
|
|
574
|
+
let mostly_dense = false;
|
|
575
|
+
str = "[";
|
|
576
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
577
|
+
if (i > 0) str += ",";
|
|
578
|
+
if (Object.hasOwn(thing, i)) {
|
|
579
|
+
keys.push(`[${i}]`);
|
|
580
|
+
str += flatten(thing[i]);
|
|
581
|
+
keys.pop();
|
|
582
|
+
} else if (mostly_dense) {
|
|
583
|
+
str += HOLE;
|
|
584
|
+
} else {
|
|
585
|
+
const populated_keys = valid_array_indices(
|
|
586
|
+
/** @type {any[]} */
|
|
587
|
+
thing
|
|
588
|
+
);
|
|
589
|
+
const population = populated_keys.length;
|
|
590
|
+
const d = String(thing.length).length;
|
|
591
|
+
const hole_cost = (thing.length - population) * 3;
|
|
592
|
+
const sparse_cost = 4 + d + population * (d + 1);
|
|
593
|
+
if (hole_cost > sparse_cost) {
|
|
594
|
+
str = "[" + SPARSE + "," + thing.length;
|
|
595
|
+
for (let j = 0; j < populated_keys.length; j++) {
|
|
596
|
+
const key = populated_keys[j];
|
|
597
|
+
keys.push(`[${key}]`);
|
|
598
|
+
str += "," + key + "," + flatten(thing[key]);
|
|
599
|
+
keys.pop();
|
|
600
|
+
}
|
|
601
|
+
break;
|
|
602
|
+
} else {
|
|
603
|
+
mostly_dense = true;
|
|
604
|
+
str += HOLE;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
str += "]";
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
case "Set":
|
|
612
|
+
str = '["Set"';
|
|
613
|
+
for (const value2 of thing) {
|
|
614
|
+
str += `,${flatten(value2)}`;
|
|
615
|
+
}
|
|
616
|
+
str += "]";
|
|
617
|
+
break;
|
|
618
|
+
case "Map":
|
|
619
|
+
str = '["Map"';
|
|
620
|
+
for (const [key, value2] of thing) {
|
|
621
|
+
keys.push(
|
|
622
|
+
`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`
|
|
623
|
+
);
|
|
624
|
+
str += `,${flatten(key)},${flatten(value2)}`;
|
|
625
|
+
keys.pop();
|
|
626
|
+
}
|
|
627
|
+
str += "]";
|
|
628
|
+
break;
|
|
629
|
+
case "Int8Array":
|
|
630
|
+
case "Uint8Array":
|
|
631
|
+
case "Uint8ClampedArray":
|
|
632
|
+
case "Int16Array":
|
|
633
|
+
case "Uint16Array":
|
|
634
|
+
case "Int32Array":
|
|
635
|
+
case "Uint32Array":
|
|
636
|
+
case "Float32Array":
|
|
637
|
+
case "Float64Array":
|
|
638
|
+
case "BigInt64Array":
|
|
639
|
+
case "BigUint64Array": {
|
|
640
|
+
const typedArray = thing;
|
|
641
|
+
str = '["' + type + '",' + flatten(typedArray.buffer);
|
|
642
|
+
const a = thing.byteOffset;
|
|
643
|
+
const b = a + thing.byteLength;
|
|
644
|
+
if (a > 0 || b !== typedArray.buffer.byteLength) {
|
|
645
|
+
const m = +/(\d+)/.exec(type)[1] / 8;
|
|
646
|
+
str += `,${a / m},${b / m}`;
|
|
647
|
+
}
|
|
648
|
+
str += "]";
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
case "ArrayBuffer": {
|
|
652
|
+
const arraybuffer = thing;
|
|
653
|
+
const base64 = encode64(arraybuffer);
|
|
654
|
+
str = `["ArrayBuffer","${base64}"]`;
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
case "Temporal.Duration":
|
|
658
|
+
case "Temporal.Instant":
|
|
659
|
+
case "Temporal.PlainDate":
|
|
660
|
+
case "Temporal.PlainTime":
|
|
661
|
+
case "Temporal.PlainDateTime":
|
|
662
|
+
case "Temporal.PlainMonthDay":
|
|
663
|
+
case "Temporal.PlainYearMonth":
|
|
664
|
+
case "Temporal.ZonedDateTime":
|
|
665
|
+
str = `["${type}",${stringify_string(thing.toString())}]`;
|
|
666
|
+
break;
|
|
667
|
+
default:
|
|
668
|
+
if (!is_plain_object(thing)) {
|
|
669
|
+
throw new DevalueError(
|
|
670
|
+
`Cannot stringify arbitrary non-POJOs`,
|
|
671
|
+
keys,
|
|
672
|
+
thing,
|
|
673
|
+
value
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
677
|
+
throw new DevalueError(
|
|
678
|
+
`Cannot stringify POJOs with symbolic keys`,
|
|
679
|
+
keys,
|
|
680
|
+
thing,
|
|
681
|
+
value
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
if (Object.getPrototypeOf(thing) === null) {
|
|
685
|
+
str = '["null"';
|
|
686
|
+
for (const key of Object.keys(thing)) {
|
|
687
|
+
if (key === "__proto__") {
|
|
688
|
+
throw new DevalueError(
|
|
689
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
690
|
+
keys,
|
|
691
|
+
thing,
|
|
692
|
+
value
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
keys.push(stringify_key(key));
|
|
696
|
+
str += `,${stringify_string(key)},${flatten(thing[key])}`;
|
|
697
|
+
keys.pop();
|
|
698
|
+
}
|
|
699
|
+
str += "]";
|
|
700
|
+
} else {
|
|
701
|
+
str = "{";
|
|
702
|
+
let started = false;
|
|
703
|
+
for (const key of Object.keys(thing)) {
|
|
704
|
+
if (key === "__proto__") {
|
|
705
|
+
throw new DevalueError(
|
|
706
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
707
|
+
keys,
|
|
708
|
+
thing,
|
|
709
|
+
value
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
if (started) str += ",";
|
|
713
|
+
started = true;
|
|
714
|
+
keys.push(stringify_key(key));
|
|
715
|
+
str += `${stringify_string(key)}:${flatten(thing[key])}`;
|
|
716
|
+
keys.pop();
|
|
717
|
+
}
|
|
718
|
+
str += "}";
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
stringified[index2] = str;
|
|
723
|
+
return index2;
|
|
724
|
+
}
|
|
725
|
+
const index = flatten(value);
|
|
726
|
+
if (index < 0) return `${index}`;
|
|
727
|
+
return `[${stringified.join(",")}]`;
|
|
728
|
+
}
|
|
729
|
+
function stringify_primitive(thing) {
|
|
730
|
+
const type = typeof thing;
|
|
731
|
+
if (type === "string") return stringify_string(thing);
|
|
732
|
+
if (thing instanceof String) return stringify_string(thing.toString());
|
|
733
|
+
if (thing === void 0) return UNDEFINED.toString();
|
|
734
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO.toString();
|
|
735
|
+
if (type === "bigint") return `["BigInt","${thing}"]`;
|
|
736
|
+
return String(thing);
|
|
737
|
+
}
|
|
738
|
+
function set_nested_value(object, path_string, value) {
|
|
739
|
+
if (path_string.startsWith("n:")) {
|
|
740
|
+
path_string = path_string.slice(2);
|
|
741
|
+
value = value === "" ? void 0 : parseFloat(value);
|
|
742
|
+
} else if (path_string.startsWith("b:")) {
|
|
743
|
+
path_string = path_string.slice(2);
|
|
744
|
+
value = value === "on";
|
|
745
|
+
}
|
|
746
|
+
deep_set(object, split_path(path_string), value);
|
|
747
|
+
}
|
|
748
|
+
function convert_formdata(data) {
|
|
749
|
+
const result = {};
|
|
750
|
+
for (let key of data.keys()) {
|
|
751
|
+
const is_array = key.endsWith("[]");
|
|
752
|
+
let values = data.getAll(key);
|
|
753
|
+
if (is_array) key = key.slice(0, -2);
|
|
754
|
+
if (values.length > 1 && !is_array) {
|
|
755
|
+
throw new Error(`Form cannot contain duplicated keys — "${key}" has ${values.length} values`);
|
|
756
|
+
}
|
|
757
|
+
values = values.filter(
|
|
758
|
+
(entry) => typeof entry === "string" || entry.name !== "" || entry.size > 0
|
|
759
|
+
);
|
|
760
|
+
if (key.startsWith("n:")) {
|
|
761
|
+
key = key.slice(2);
|
|
762
|
+
values = values.map((v) => v === "" ? void 0 : parseFloat(
|
|
763
|
+
/** @type {string} */
|
|
764
|
+
v
|
|
765
|
+
));
|
|
766
|
+
} else if (key.startsWith("b:")) {
|
|
767
|
+
key = key.slice(2);
|
|
768
|
+
values = values.map((v) => v === "on");
|
|
769
|
+
}
|
|
770
|
+
set_nested_value(result, key, is_array ? values : values[0]);
|
|
771
|
+
}
|
|
772
|
+
return result;
|
|
773
|
+
}
|
|
774
|
+
const BINARY_FORM_CONTENT_TYPE = "application/x-sveltekit-formdata";
|
|
775
|
+
const BINARY_FORM_VERSION = 0;
|
|
776
|
+
const HEADER_BYTES = 1 + 4 + 2;
|
|
777
|
+
async function deserialize_binary_form(request) {
|
|
778
|
+
if (request.headers.get("content-type") !== BINARY_FORM_CONTENT_TYPE) {
|
|
779
|
+
const form_data = await request.formData();
|
|
780
|
+
return { data: convert_formdata(form_data), meta: {}, form_data };
|
|
781
|
+
}
|
|
782
|
+
if (!request.body) {
|
|
783
|
+
throw deserialize_error("no body");
|
|
784
|
+
}
|
|
785
|
+
const content_length = parseInt(request.headers.get("content-length") ?? "");
|
|
786
|
+
if (Number.isNaN(content_length)) {
|
|
787
|
+
throw deserialize_error("invalid Content-Length header");
|
|
788
|
+
}
|
|
789
|
+
const reader = request.body.getReader();
|
|
790
|
+
const chunks = [];
|
|
791
|
+
function get_chunk(index) {
|
|
792
|
+
if (index in chunks) return chunks[index];
|
|
793
|
+
let i = chunks.length;
|
|
794
|
+
while (i <= index) {
|
|
795
|
+
chunks[i] = reader.read().then((chunk) => chunk.value);
|
|
796
|
+
i++;
|
|
797
|
+
}
|
|
798
|
+
return chunks[index];
|
|
799
|
+
}
|
|
800
|
+
async function get_buffer(offset, length) {
|
|
801
|
+
let start_chunk;
|
|
802
|
+
let chunk_start = 0;
|
|
803
|
+
let chunk_index;
|
|
804
|
+
for (chunk_index = 0; ; chunk_index++) {
|
|
805
|
+
const chunk = await get_chunk(chunk_index);
|
|
806
|
+
if (!chunk) return null;
|
|
807
|
+
const chunk_end = chunk_start + chunk.byteLength;
|
|
808
|
+
if (offset >= chunk_start && offset < chunk_end) {
|
|
809
|
+
start_chunk = chunk;
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
chunk_start = chunk_end;
|
|
813
|
+
}
|
|
814
|
+
if (offset + length <= chunk_start + start_chunk.byteLength) {
|
|
815
|
+
return start_chunk.subarray(offset - chunk_start, offset + length - chunk_start);
|
|
816
|
+
}
|
|
817
|
+
const chunks2 = [start_chunk.subarray(offset - chunk_start)];
|
|
818
|
+
let cursor = start_chunk.byteLength - offset + chunk_start;
|
|
819
|
+
while (cursor < length) {
|
|
820
|
+
chunk_index++;
|
|
821
|
+
let chunk = await get_chunk(chunk_index);
|
|
822
|
+
if (!chunk) return null;
|
|
823
|
+
if (chunk.byteLength > length - cursor) {
|
|
824
|
+
chunk = chunk.subarray(0, length - cursor);
|
|
825
|
+
}
|
|
826
|
+
chunks2.push(chunk);
|
|
827
|
+
cursor += chunk.byteLength;
|
|
828
|
+
}
|
|
829
|
+
const buffer = new Uint8Array(length);
|
|
830
|
+
cursor = 0;
|
|
831
|
+
for (const chunk of chunks2) {
|
|
832
|
+
buffer.set(chunk, cursor);
|
|
833
|
+
cursor += chunk.byteLength;
|
|
834
|
+
}
|
|
835
|
+
return buffer;
|
|
836
|
+
}
|
|
837
|
+
const header = await get_buffer(0, HEADER_BYTES);
|
|
838
|
+
if (!header) throw deserialize_error("too short");
|
|
839
|
+
if (header[0] !== BINARY_FORM_VERSION) {
|
|
840
|
+
throw deserialize_error(`got version ${header[0]}, expected version ${BINARY_FORM_VERSION}`);
|
|
841
|
+
}
|
|
842
|
+
const header_view = new DataView(header.buffer, header.byteOffset, header.byteLength);
|
|
843
|
+
const data_length = header_view.getUint32(1, true);
|
|
844
|
+
if (HEADER_BYTES + data_length > content_length) {
|
|
845
|
+
throw deserialize_error("data overflow");
|
|
846
|
+
}
|
|
847
|
+
const file_offsets_length = header_view.getUint16(5, true);
|
|
848
|
+
if (HEADER_BYTES + data_length + file_offsets_length > content_length) {
|
|
849
|
+
throw deserialize_error("file offset table overflow");
|
|
850
|
+
}
|
|
851
|
+
const data_buffer = await get_buffer(HEADER_BYTES, data_length);
|
|
852
|
+
if (!data_buffer) throw deserialize_error("data too short");
|
|
853
|
+
let file_offsets;
|
|
854
|
+
let files_start_offset;
|
|
855
|
+
if (file_offsets_length > 0) {
|
|
856
|
+
const file_offsets_buffer = await get_buffer(HEADER_BYTES + data_length, file_offsets_length);
|
|
857
|
+
if (!file_offsets_buffer) throw deserialize_error("file offset table too short");
|
|
858
|
+
const parsed_offsets = JSON.parse(text_decoder.decode(file_offsets_buffer));
|
|
859
|
+
if (!Array.isArray(parsed_offsets) || parsed_offsets.some((n) => typeof n !== "number" || !Number.isInteger(n) || n < 0)) {
|
|
860
|
+
throw deserialize_error("invalid file offset table");
|
|
861
|
+
}
|
|
862
|
+
file_offsets = /** @type {Array<number>} */
|
|
863
|
+
parsed_offsets;
|
|
864
|
+
files_start_offset = HEADER_BYTES + data_length + file_offsets_length;
|
|
865
|
+
}
|
|
866
|
+
const file_spans = [];
|
|
867
|
+
const [data, meta] = parse(text_decoder.decode(data_buffer), {
|
|
868
|
+
File: ([name, type, size, last_modified, index]) => {
|
|
869
|
+
if (typeof name !== "string" || typeof type !== "string" || typeof size !== "number" || typeof last_modified !== "number" || typeof index !== "number") {
|
|
870
|
+
throw deserialize_error("invalid file metadata");
|
|
871
|
+
}
|
|
872
|
+
let offset = file_offsets[index];
|
|
873
|
+
if (offset === void 0) {
|
|
874
|
+
throw deserialize_error("duplicate file offset table index");
|
|
875
|
+
}
|
|
876
|
+
file_offsets[index] = void 0;
|
|
877
|
+
offset += files_start_offset;
|
|
878
|
+
if (offset + size > content_length) {
|
|
879
|
+
throw deserialize_error("file data overflow");
|
|
880
|
+
}
|
|
881
|
+
file_spans.push({ offset, size });
|
|
882
|
+
return new Proxy(new LazyFile(name, type, size, last_modified, get_chunk, offset), {
|
|
883
|
+
getPrototypeOf() {
|
|
884
|
+
return File.prototype;
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
file_spans.sort((a, b) => a.offset - b.offset || a.size - b.size);
|
|
890
|
+
for (let i = 1; i < file_spans.length; i++) {
|
|
891
|
+
const previous = file_spans[i - 1];
|
|
892
|
+
const current = file_spans[i];
|
|
893
|
+
const previous_end = previous.offset + previous.size;
|
|
894
|
+
if (previous_end < current.offset) {
|
|
895
|
+
throw deserialize_error("gaps in file data");
|
|
896
|
+
}
|
|
897
|
+
if (previous_end > current.offset) {
|
|
898
|
+
throw deserialize_error("overlapping file data");
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
void (async () => {
|
|
902
|
+
let has_more = true;
|
|
903
|
+
while (has_more) {
|
|
904
|
+
const chunk = await get_chunk(chunks.length);
|
|
905
|
+
has_more = !!chunk;
|
|
906
|
+
}
|
|
907
|
+
})();
|
|
908
|
+
return { data, meta, form_data: null };
|
|
909
|
+
}
|
|
910
|
+
function deserialize_error(message) {
|
|
911
|
+
return new SvelteKitError(400, "Bad Request", `Could not deserialize binary form: ${message}`);
|
|
912
|
+
}
|
|
913
|
+
class LazyFile {
|
|
914
|
+
/** @type {(index: number) => Promise<Uint8Array<ArrayBuffer> | undefined>} */
|
|
915
|
+
#get_chunk;
|
|
916
|
+
/** @type {number} */
|
|
917
|
+
#offset;
|
|
918
|
+
/**
|
|
919
|
+
* @param {string} name
|
|
920
|
+
* @param {string} type
|
|
921
|
+
* @param {number} size
|
|
922
|
+
* @param {number} last_modified
|
|
923
|
+
* @param {(index: number) => Promise<Uint8Array<ArrayBuffer> | undefined>} get_chunk
|
|
924
|
+
* @param {number} offset
|
|
925
|
+
*/
|
|
926
|
+
constructor(name, type, size, last_modified, get_chunk, offset) {
|
|
927
|
+
this.name = name;
|
|
928
|
+
this.type = type;
|
|
929
|
+
this.size = size;
|
|
930
|
+
this.lastModified = last_modified;
|
|
931
|
+
this.webkitRelativePath = "";
|
|
932
|
+
this.#get_chunk = get_chunk;
|
|
933
|
+
this.#offset = offset;
|
|
934
|
+
this.arrayBuffer = this.arrayBuffer.bind(this);
|
|
935
|
+
this.bytes = this.bytes.bind(this);
|
|
936
|
+
this.slice = this.slice.bind(this);
|
|
937
|
+
this.stream = this.stream.bind(this);
|
|
938
|
+
this.text = this.text.bind(this);
|
|
939
|
+
}
|
|
940
|
+
/** @type {ArrayBuffer | undefined} */
|
|
941
|
+
#buffer;
|
|
942
|
+
async arrayBuffer() {
|
|
943
|
+
this.#buffer ??= await new Response(this.stream()).arrayBuffer();
|
|
944
|
+
return this.#buffer;
|
|
945
|
+
}
|
|
946
|
+
async bytes() {
|
|
947
|
+
return new Uint8Array(await this.arrayBuffer());
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* @param {number=} start
|
|
951
|
+
* @param {number=} end
|
|
952
|
+
* @param {string=} contentType
|
|
953
|
+
*/
|
|
954
|
+
slice(start = 0, end = this.size, contentType = this.type) {
|
|
955
|
+
if (start < 0) {
|
|
956
|
+
start = Math.max(this.size + start, 0);
|
|
957
|
+
} else {
|
|
958
|
+
start = Math.min(start, this.size);
|
|
959
|
+
}
|
|
960
|
+
if (end < 0) {
|
|
961
|
+
end = Math.max(this.size + end, 0);
|
|
962
|
+
} else {
|
|
963
|
+
end = Math.min(end, this.size);
|
|
964
|
+
}
|
|
965
|
+
const size = Math.max(end - start, 0);
|
|
966
|
+
const file = new LazyFile(
|
|
967
|
+
this.name,
|
|
968
|
+
contentType,
|
|
969
|
+
size,
|
|
970
|
+
this.lastModified,
|
|
971
|
+
this.#get_chunk,
|
|
972
|
+
this.#offset + start
|
|
973
|
+
);
|
|
974
|
+
return file;
|
|
975
|
+
}
|
|
976
|
+
stream() {
|
|
977
|
+
let cursor = 0;
|
|
978
|
+
let chunk_index = 0;
|
|
979
|
+
return new ReadableStream({
|
|
980
|
+
start: async (controller) => {
|
|
981
|
+
let chunk_start = 0;
|
|
982
|
+
let start_chunk;
|
|
983
|
+
for (chunk_index = 0; ; chunk_index++) {
|
|
984
|
+
const chunk = await this.#get_chunk(chunk_index);
|
|
985
|
+
if (!chunk) return null;
|
|
986
|
+
const chunk_end = chunk_start + chunk.byteLength;
|
|
987
|
+
if (this.#offset >= chunk_start && this.#offset < chunk_end) {
|
|
988
|
+
start_chunk = chunk;
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
chunk_start = chunk_end;
|
|
992
|
+
}
|
|
993
|
+
if (this.#offset + this.size <= chunk_start + start_chunk.byteLength) {
|
|
994
|
+
controller.enqueue(
|
|
995
|
+
start_chunk.subarray(this.#offset - chunk_start, this.#offset + this.size - chunk_start)
|
|
996
|
+
);
|
|
997
|
+
controller.close();
|
|
998
|
+
} else {
|
|
999
|
+
controller.enqueue(start_chunk.subarray(this.#offset - chunk_start));
|
|
1000
|
+
cursor = start_chunk.byteLength - this.#offset + chunk_start;
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
pull: async (controller) => {
|
|
1004
|
+
chunk_index++;
|
|
1005
|
+
let chunk = await this.#get_chunk(chunk_index);
|
|
1006
|
+
if (!chunk) {
|
|
1007
|
+
controller.error("incomplete file data");
|
|
1008
|
+
controller.close();
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (chunk.byteLength > this.size - cursor) {
|
|
1012
|
+
chunk = chunk.subarray(0, this.size - cursor);
|
|
1013
|
+
}
|
|
1014
|
+
controller.enqueue(chunk);
|
|
1015
|
+
cursor += chunk.byteLength;
|
|
1016
|
+
if (cursor >= this.size) {
|
|
1017
|
+
controller.close();
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
async text() {
|
|
1023
|
+
return text_decoder.decode(await this.arrayBuffer());
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
const path_regex = /^[a-zA-Z_$]\w*(\.[a-zA-Z_$]\w*|\[\d+\])*$/;
|
|
1027
|
+
function split_path(path) {
|
|
1028
|
+
if (!path_regex.test(path)) {
|
|
1029
|
+
throw new Error(`Invalid path ${path}`);
|
|
1030
|
+
}
|
|
1031
|
+
return path.split(/\.|\[|\]/).filter(Boolean);
|
|
1032
|
+
}
|
|
1033
|
+
function check_prototype_pollution(key) {
|
|
1034
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
1035
|
+
throw new Error(
|
|
1036
|
+
`Invalid key "${key}"`
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function deep_set(object, keys, value) {
|
|
1041
|
+
let current = object;
|
|
1042
|
+
for (let i = 0; i < keys.length - 1; i += 1) {
|
|
1043
|
+
const key = keys[i];
|
|
1044
|
+
check_prototype_pollution(key);
|
|
1045
|
+
const is_array = /^\d+$/.test(keys[i + 1]);
|
|
1046
|
+
const exists = Object.hasOwn(current, key);
|
|
1047
|
+
const inner = current[key];
|
|
1048
|
+
if (exists && is_array !== Array.isArray(inner)) {
|
|
1049
|
+
throw new Error(`Invalid array key ${keys[i + 1]}`);
|
|
1050
|
+
}
|
|
1051
|
+
if (!exists) {
|
|
1052
|
+
current[key] = is_array ? [] : {};
|
|
1053
|
+
}
|
|
1054
|
+
current = current[key];
|
|
1055
|
+
}
|
|
1056
|
+
const final_key = keys[keys.length - 1];
|
|
1057
|
+
check_prototype_pollution(final_key);
|
|
1058
|
+
current[final_key] = value;
|
|
1059
|
+
}
|
|
1060
|
+
function negotiate(accept, types) {
|
|
1061
|
+
const parts = [];
|
|
1062
|
+
accept.split(",").forEach((str, i) => {
|
|
1063
|
+
const match = /([^/ \t]+)\/([^; \t]+)[ \t]*(?:;[ \t]*q=([0-9.]+))?/.exec(str);
|
|
1064
|
+
if (match) {
|
|
1065
|
+
const [, type, subtype, q = "1"] = match;
|
|
1066
|
+
parts.push({ type, subtype, q: +q, i });
|
|
1067
|
+
}
|
|
1068
|
+
});
|
|
1069
|
+
parts.sort((a, b) => {
|
|
1070
|
+
if (a.q !== b.q) {
|
|
1071
|
+
return b.q - a.q;
|
|
1072
|
+
}
|
|
1073
|
+
if (a.subtype === "*" !== (b.subtype === "*")) {
|
|
1074
|
+
return a.subtype === "*" ? 1 : -1;
|
|
1075
|
+
}
|
|
1076
|
+
if (a.type === "*" !== (b.type === "*")) {
|
|
1077
|
+
return a.type === "*" ? 1 : -1;
|
|
1078
|
+
}
|
|
1079
|
+
return a.i - b.i;
|
|
1080
|
+
});
|
|
1081
|
+
let accepted;
|
|
1082
|
+
let min_priority = Infinity;
|
|
1083
|
+
for (const mimetype of types) {
|
|
1084
|
+
const [type, subtype] = mimetype.split("/");
|
|
1085
|
+
const priority = parts.findIndex(
|
|
1086
|
+
(part) => (part.type === type || part.type === "*") && (part.subtype === subtype || part.subtype === "*")
|
|
1087
|
+
);
|
|
1088
|
+
if (priority !== -1 && priority < min_priority) {
|
|
1089
|
+
accepted = mimetype;
|
|
1090
|
+
min_priority = priority;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return accepted;
|
|
1094
|
+
}
|
|
1095
|
+
function is_content_type(request, ...types) {
|
|
1096
|
+
const type = request.headers.get("content-type")?.split(";", 1)[0].trim() ?? "";
|
|
1097
|
+
return types.includes(type.toLowerCase());
|
|
1098
|
+
}
|
|
1099
|
+
function is_form_content_type(request) {
|
|
1100
|
+
return is_content_type(
|
|
1101
|
+
request,
|
|
1102
|
+
"application/x-www-form-urlencoded",
|
|
1103
|
+
"multipart/form-data",
|
|
1104
|
+
"text/plain",
|
|
1105
|
+
BINARY_FORM_CONTENT_TYPE
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
function coalesce_to_error(err) {
|
|
1109
|
+
return err instanceof Error || err && /** @type {any} */
|
|
1110
|
+
err.name && /** @type {any} */
|
|
1111
|
+
err.message ? (
|
|
1112
|
+
/** @type {Error} */
|
|
1113
|
+
err
|
|
1114
|
+
) : new Error(JSON.stringify(err));
|
|
1115
|
+
}
|
|
1116
|
+
function normalize_error(error) {
|
|
1117
|
+
return (
|
|
1118
|
+
/** @type {import('../exports/internal/index.js').Redirect | HttpError | SvelteKitError | Error} */
|
|
1119
|
+
error
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
function get_status(error) {
|
|
1123
|
+
return error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
1124
|
+
}
|
|
1125
|
+
function get_message(error) {
|
|
1126
|
+
return error instanceof SvelteKitError ? error.text : "Internal Error";
|
|
1127
|
+
}
|
|
1128
|
+
const escape_html_attr_dict = {
|
|
1129
|
+
"&": "&",
|
|
1130
|
+
'"': """
|
|
1131
|
+
// Svelte also escapes < because the escape function could be called inside a `noscript` there
|
|
1132
|
+
// https://github.com/sveltejs/svelte/security/advisories/GHSA-8266-84wp-wv5c
|
|
1133
|
+
// However, that doesn't apply in SvelteKit
|
|
1134
|
+
};
|
|
1135
|
+
const escape_html_dict = {
|
|
1136
|
+
"&": "&",
|
|
1137
|
+
"<": "<"
|
|
1138
|
+
};
|
|
1139
|
+
const surrogates = (
|
|
1140
|
+
// high surrogate without paired low surrogate
|
|
1141
|
+
"[\\ud800-\\udbff](?![\\udc00-\\udfff])|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\udc00-\\udfff]"
|
|
1142
|
+
);
|
|
1143
|
+
const escape_html_attr_regex = new RegExp(
|
|
1144
|
+
`[${Object.keys(escape_html_attr_dict).join("")}]|` + surrogates,
|
|
1145
|
+
"g"
|
|
1146
|
+
);
|
|
1147
|
+
const escape_html_regex = new RegExp(
|
|
1148
|
+
`[${Object.keys(escape_html_dict).join("")}]|` + surrogates,
|
|
1149
|
+
"g"
|
|
1150
|
+
);
|
|
1151
|
+
function escape_html(str, is_attr) {
|
|
1152
|
+
const dict = is_attr ? escape_html_attr_dict : escape_html_dict;
|
|
1153
|
+
const escaped_str = str.replace(is_attr ? escape_html_attr_regex : escape_html_regex, (match) => {
|
|
1154
|
+
if (match.length === 2) {
|
|
1155
|
+
return match;
|
|
1156
|
+
}
|
|
1157
|
+
return dict[match] ?? `&#${match.charCodeAt(0)};`;
|
|
1158
|
+
});
|
|
1159
|
+
return escaped_str;
|
|
1160
|
+
}
|
|
1161
|
+
function method_not_allowed(mod, method) {
|
|
1162
|
+
return text(`${method} method not allowed`, {
|
|
1163
|
+
status: 405,
|
|
1164
|
+
headers: {
|
|
1165
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
1166
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
1167
|
+
allow: allowed_methods(mod).join(", ")
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
function allowed_methods(mod) {
|
|
1172
|
+
const allowed = ENDPOINT_METHODS.filter((method) => method in mod);
|
|
1173
|
+
if ("GET" in mod && !("HEAD" in mod)) {
|
|
1174
|
+
allowed.push("HEAD");
|
|
1175
|
+
}
|
|
1176
|
+
return allowed;
|
|
1177
|
+
}
|
|
1178
|
+
function get_global_name(options) {
|
|
1179
|
+
return `__sveltekit_${options.version_hash}`;
|
|
1180
|
+
}
|
|
1181
|
+
function static_error_page(options, status, message) {
|
|
1182
|
+
let page = options.templates.error({ status, message: escape_html(message) });
|
|
1183
|
+
return text(page, {
|
|
1184
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
1185
|
+
status
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
async function handle_fatal_error(event, state, options, error) {
|
|
1189
|
+
error = error instanceof HttpError ? error : coalesce_to_error(error);
|
|
1190
|
+
const status = get_status(error);
|
|
1191
|
+
const body = await handle_error_and_jsonify(event, state, options, error);
|
|
1192
|
+
const type = negotiate(event.request.headers.get("accept") || "text/html", [
|
|
1193
|
+
"application/json",
|
|
1194
|
+
"text/html"
|
|
1195
|
+
]);
|
|
1196
|
+
if (event.isDataRequest || type === "application/json") {
|
|
1197
|
+
return json(body, {
|
|
1198
|
+
status
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
return static_error_page(options, status, body.message);
|
|
1202
|
+
}
|
|
1203
|
+
async function handle_error_and_jsonify(event, state, options, error) {
|
|
1204
|
+
if (error instanceof HttpError) {
|
|
1205
|
+
return { message: "Unknown Error", ...error.body };
|
|
1206
|
+
}
|
|
1207
|
+
const status = get_status(error);
|
|
1208
|
+
const message = get_message(error);
|
|
1209
|
+
return await with_request_store(
|
|
1210
|
+
{ event, state },
|
|
1211
|
+
() => options.hooks.handleError({ error, event, status, message })
|
|
1212
|
+
) ?? { message };
|
|
1213
|
+
}
|
|
1214
|
+
function redirect_response(status, location) {
|
|
1215
|
+
const response = new Response(void 0, {
|
|
1216
|
+
status,
|
|
1217
|
+
headers: { location }
|
|
1218
|
+
});
|
|
1219
|
+
return response;
|
|
1220
|
+
}
|
|
1221
|
+
function clarify_devalue_error(event, error) {
|
|
1222
|
+
if (error.path) {
|
|
1223
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not serializable: ${error.message} (${error.path}). If you need to serialize/deserialize custom types, use transport hooks: https://svelte.dev/docs/kit/hooks#Universal-hooks-transport.`;
|
|
1224
|
+
}
|
|
1225
|
+
if (error.path === "") {
|
|
1226
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not a plain object`;
|
|
1227
|
+
}
|
|
1228
|
+
return error.message;
|
|
1229
|
+
}
|
|
1230
|
+
function serialize_uses(node) {
|
|
1231
|
+
const uses = {};
|
|
1232
|
+
if (node.uses && node.uses.dependencies.size > 0) {
|
|
1233
|
+
uses.dependencies = Array.from(node.uses.dependencies);
|
|
1234
|
+
}
|
|
1235
|
+
if (node.uses && node.uses.search_params.size > 0) {
|
|
1236
|
+
uses.search_params = Array.from(node.uses.search_params);
|
|
1237
|
+
}
|
|
1238
|
+
if (node.uses && node.uses.params.size > 0) {
|
|
1239
|
+
uses.params = Array.from(node.uses.params);
|
|
1240
|
+
}
|
|
1241
|
+
if (node.uses?.parent) uses.parent = 1;
|
|
1242
|
+
if (node.uses?.route) uses.route = 1;
|
|
1243
|
+
if (node.uses?.url) uses.url = 1;
|
|
1244
|
+
return uses;
|
|
1245
|
+
}
|
|
1246
|
+
function has_prerendered_path(manifest, pathname) {
|
|
1247
|
+
return manifest._.prerendered_routes.has(pathname) || pathname.at(-1) === "/" && manifest._.prerendered_routes.has(pathname.slice(0, -1));
|
|
1248
|
+
}
|
|
1249
|
+
function format_server_error(status, error, event) {
|
|
1250
|
+
const formatted_text = `
|
|
1251
|
+
\x1B[1;31m[${status}] ${event.request.method} ${event.url.pathname}\x1B[0m`;
|
|
1252
|
+
if (status === 404) {
|
|
1253
|
+
return formatted_text;
|
|
1254
|
+
}
|
|
1255
|
+
return `${formatted_text}
|
|
1256
|
+
${error.stack}`;
|
|
1257
|
+
}
|
|
1258
|
+
function get_node_type(node_id) {
|
|
1259
|
+
const parts = node_id?.split("/");
|
|
1260
|
+
const filename = parts?.at(-1);
|
|
1261
|
+
if (!filename) return "unknown";
|
|
1262
|
+
const dot_parts = filename.split(".");
|
|
1263
|
+
return dot_parts.slice(0, -1).join(".");
|
|
1264
|
+
}
|
|
1265
|
+
const INVALIDATED_PARAM = "x-sveltekit-invalidated";
|
|
1266
|
+
const TRAILING_SLASH_PARAM = "x-sveltekit-trailing-slash";
|
|
1267
|
+
function stringify(data, transport) {
|
|
1268
|
+
const encoders = Object.fromEntries(Object.entries(transport).map(([k, v]) => [k, v.encode]));
|
|
1269
|
+
return stringify$1(data, encoders);
|
|
1270
|
+
}
|
|
1271
|
+
const remote_object = "__skrao";
|
|
1272
|
+
const remote_map = "__skram";
|
|
1273
|
+
const remote_set = "__skras";
|
|
1274
|
+
function create_remote_arg_revivers(transport) {
|
|
1275
|
+
const remote_fns_revivers = {
|
|
1276
|
+
/** @type {(value: unknown) => unknown} */
|
|
1277
|
+
[remote_object]: (value) => value,
|
|
1278
|
+
/** @type {(value: unknown) => Map<unknown, unknown>} */
|
|
1279
|
+
[remote_map]: (value) => {
|
|
1280
|
+
if (!Array.isArray(value)) {
|
|
1281
|
+
throw new Error("Invalid data for Map reviver");
|
|
1282
|
+
}
|
|
1283
|
+
const map = /* @__PURE__ */ new Map();
|
|
1284
|
+
for (const item of value) {
|
|
1285
|
+
if (!Array.isArray(item) || item.length !== 2 || typeof item[0] !== "string" || typeof item[1] !== "string") {
|
|
1286
|
+
throw new Error("Invalid data for Map reviver");
|
|
1287
|
+
}
|
|
1288
|
+
const [key, val] = item;
|
|
1289
|
+
map.set(parse$1(key), parse$1(val));
|
|
1290
|
+
}
|
|
1291
|
+
return map;
|
|
1292
|
+
},
|
|
1293
|
+
/** @type {(value: unknown) => Set<unknown>} */
|
|
1294
|
+
[remote_set]: (value) => {
|
|
1295
|
+
if (!Array.isArray(value)) {
|
|
1296
|
+
throw new Error("Invalid data for Set reviver");
|
|
1297
|
+
}
|
|
1298
|
+
const set = /* @__PURE__ */ new Set();
|
|
1299
|
+
for (const item of value) {
|
|
1300
|
+
if (typeof item !== "string") {
|
|
1301
|
+
throw new Error("Invalid data for Set reviver");
|
|
1302
|
+
}
|
|
1303
|
+
set.add(parse$1(item));
|
|
1304
|
+
}
|
|
1305
|
+
return set;
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
const user_revivers = Object.fromEntries(
|
|
1309
|
+
Object.entries(transport).map(([k, v]) => [k, v.decode])
|
|
1310
|
+
);
|
|
1311
|
+
const all_revivers = { ...user_revivers, ...remote_fns_revivers };
|
|
1312
|
+
const parse$1 = (data) => parse(data, all_revivers);
|
|
1313
|
+
return all_revivers;
|
|
1314
|
+
}
|
|
1315
|
+
function parse_remote_arg(string, transport) {
|
|
1316
|
+
if (!string) return void 0;
|
|
1317
|
+
const json_string = text_decoder.decode(
|
|
1318
|
+
// no need to add back `=` characters, atob can handle it
|
|
1319
|
+
base64_decode(string.replaceAll("-", "+").replaceAll("_", "/"))
|
|
1320
|
+
);
|
|
1321
|
+
return parse(json_string, create_remote_arg_revivers(transport));
|
|
1322
|
+
}
|
|
1323
|
+
function create_remote_key(id, payload) {
|
|
1324
|
+
return id + "/" + payload;
|
|
1325
|
+
}
|
|
1326
|
+
function split_remote_key(key) {
|
|
1327
|
+
const i = key.lastIndexOf("/");
|
|
1328
|
+
if (i === -1) {
|
|
1329
|
+
throw new Error(`Invalid remote key: ${key}`);
|
|
1330
|
+
}
|
|
1331
|
+
return {
|
|
1332
|
+
id: key.slice(0, i),
|
|
1333
|
+
payload: key.slice(i + 1)
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
export { ActionFailure as A, split_remote_key as B, isRedirect as C, SVELTE_KIT_ASSETS as D, ENDPOINT_METHODS as E, HttpError as H, INVALIDATED_PARAM as I, PAGE_METHODS as P, Redirect as R, SvelteKitError as S, TRAILING_SLASH_PARAM as T, handle_fatal_error as a, method_not_allowed as b, create_remote_key as c, clarify_devalue_error as d, handle_error_and_jsonify as e, format_server_error as f, get_global_name as g, has_prerendered_path as h, is_form_content_type as i, json as j, get_status as k, normalize_error as l, merge_tracing as m, negotiate as n, static_error_page as o, error as p, parse_remote_arg as q, redirect_response as r, serialize_uses as s, text as t, stringify as u, deserialize_binary_form as v, with_request_store as w, get_node_type as x, stringify$1 as y, escape_html as z };
|
|
1338
|
+
//# sourceMappingURL=shared.js-DuDDTJVi.js.map
|