@demiurgejs/core 0.0.0 → 0.1.0

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 (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -2
  3. package/dist/adapter/index.d.ts +20 -0
  4. package/dist/adapter/index.d.ts.map +1 -0
  5. package/dist/browser/file-router.d.ts +30 -0
  6. package/dist/browser/file-router.d.ts.map +1 -0
  7. package/dist/browser/index.d.ts +3 -0
  8. package/dist/browser/index.d.ts.map +1 -0
  9. package/dist/chunks/index-BnX9Qxbm.js +44 -0
  10. package/dist/chunks/index-BnX9Qxbm.js.map +1 -0
  11. package/dist/chunks/ssr-O3d7Q73U.js +273 -0
  12. package/dist/chunks/ssr-O3d7Q73U.js.map +1 -0
  13. package/dist/chunks/streaming-27pwhjGC.js +343 -0
  14. package/dist/chunks/streaming-27pwhjGC.js.map +1 -0
  15. package/dist/chunks/testing-BBnJ5WUR.js +2871 -0
  16. package/dist/chunks/testing-BBnJ5WUR.js.map +1 -0
  17. package/dist/data/cache.d.ts +95 -0
  18. package/dist/data/cache.d.ts.map +1 -0
  19. package/dist/data/idempotency.d.ts +24 -0
  20. package/dist/data/idempotency.d.ts.map +1 -0
  21. package/dist/data/index.d.ts +5 -0
  22. package/dist/data/index.d.ts.map +1 -0
  23. package/dist/data/testing.d.ts +7 -0
  24. package/dist/data/testing.d.ts.map +1 -0
  25. package/dist/data/testing.js +134 -0
  26. package/dist/data/testing.js.map +1 -0
  27. package/dist/document/hydration.d.ts +13 -0
  28. package/dist/document/hydration.d.ts.map +1 -0
  29. package/dist/document/index.d.ts +13 -0
  30. package/dist/document/index.d.ts.map +1 -0
  31. package/dist/document/links.d.ts +17 -0
  32. package/dist/document/links.d.ts.map +1 -0
  33. package/dist/document/metadata.d.ts +62 -0
  34. package/dist/document/metadata.d.ts.map +1 -0
  35. package/dist/document/render.d.ts +28 -0
  36. package/dist/document/render.d.ts.map +1 -0
  37. package/dist/document/scripts.d.ts +24 -0
  38. package/dist/document/scripts.d.ts.map +1 -0
  39. package/dist/document/seo.d.ts +42 -0
  40. package/dist/document/seo.d.ts.map +1 -0
  41. package/dist/index.d.ts +23 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +1318 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/internal/testing.d.ts +3 -0
  46. package/dist/internal/testing.d.ts.map +1 -0
  47. package/dist/internal/testing.js +22 -0
  48. package/dist/internal/testing.js.map +1 -0
  49. package/dist/node/http.d.ts +28 -0
  50. package/dist/node/http.d.ts.map +1 -0
  51. package/dist/node/index.d.ts +45 -0
  52. package/dist/node/index.d.ts.map +1 -0
  53. package/dist/node/index.js +385 -0
  54. package/dist/node/index.js.map +1 -0
  55. package/dist/node/static.d.ts +9 -0
  56. package/dist/node/static.d.ts.map +1 -0
  57. package/dist/node/streaming.d.ts +5 -0
  58. package/dist/node/streaming.d.ts.map +1 -0
  59. package/dist/package-name.d.ts +2 -0
  60. package/dist/package-name.d.ts.map +1 -0
  61. package/dist/platform/analytics.d.ts +20 -0
  62. package/dist/platform/analytics.d.ts.map +1 -0
  63. package/dist/platform/fonts.d.ts +35 -0
  64. package/dist/platform/fonts.d.ts.map +1 -0
  65. package/dist/platform/images.d.ts +49 -0
  66. package/dist/platform/images.d.ts.map +1 -0
  67. package/dist/platform/index.d.ts +9 -0
  68. package/dist/platform/index.d.ts.map +1 -0
  69. package/dist/platform/observability.d.ts +60 -0
  70. package/dist/platform/observability.d.ts.map +1 -0
  71. package/dist/route/action.d.ts +33 -0
  72. package/dist/route/action.d.ts.map +1 -0
  73. package/dist/route/http-error.d.ts +24 -0
  74. package/dist/route/http-error.d.ts.map +1 -0
  75. package/dist/route/index.d.ts +10 -0
  76. package/dist/route/index.d.ts.map +1 -0
  77. package/dist/route/page.d.ts +5 -0
  78. package/dist/route/page.d.ts.map +1 -0
  79. package/dist/route/response.d.ts +100 -0
  80. package/dist/route/response.d.ts.map +1 -0
  81. package/dist/route/types.d.ts +186 -0
  82. package/dist/route/types.d.ts.map +1 -0
  83. package/dist/route/webhook.d.ts +25 -0
  84. package/dist/route/webhook.d.ts.map +1 -0
  85. package/dist/router/index.d.ts +5 -0
  86. package/dist/router/index.d.ts.map +1 -0
  87. package/dist/router/manifest.d.ts +117 -0
  88. package/dist/router/manifest.d.ts.map +1 -0
  89. package/dist/router/navigation-data.d.ts +9 -0
  90. package/dist/router/navigation-data.d.ts.map +1 -0
  91. package/dist/routing/generate.d.ts +14 -0
  92. package/dist/routing/generate.d.ts.map +1 -0
  93. package/dist/routing/index.d.ts +3 -0
  94. package/dist/routing/index.d.ts.map +1 -0
  95. package/dist/routing/types.d.ts +38 -0
  96. package/dist/routing/types.d.ts.map +1 -0
  97. package/dist/security/audit.d.ts +16 -0
  98. package/dist/security/audit.d.ts.map +1 -0
  99. package/dist/security/cors.d.ts +7 -0
  100. package/dist/security/cors.d.ts.map +1 -0
  101. package/dist/security/csrf.d.ts +15 -0
  102. package/dist/security/csrf.d.ts.map +1 -0
  103. package/dist/security/env.d.ts +69 -0
  104. package/dist/security/env.d.ts.map +1 -0
  105. package/dist/security/index.d.ts +17 -0
  106. package/dist/security/index.d.ts.map +1 -0
  107. package/dist/security/policy.d.ts +18 -0
  108. package/dist/security/policy.d.ts.map +1 -0
  109. package/dist/security/rate-limit.d.ts +6 -0
  110. package/dist/security/rate-limit.d.ts.map +1 -0
  111. package/dist/security/report.d.ts +13 -0
  112. package/dist/security/report.d.ts.map +1 -0
  113. package/dist/security/request.d.ts +11 -0
  114. package/dist/security/request.d.ts.map +1 -0
  115. package/dist/security/types.d.ts +137 -0
  116. package/dist/security/types.d.ts.map +1 -0
  117. package/dist/security/upload.d.ts +23 -0
  118. package/dist/security/upload.d.ts.map +1 -0
  119. package/dist/security/websocket.d.ts +13 -0
  120. package/dist/security/websocket.d.ts.map +1 -0
  121. package/dist/server/errors.d.ts +13 -0
  122. package/dist/server/errors.d.ts.map +1 -0
  123. package/dist/server/failure-site.d.ts +2 -0
  124. package/dist/server/failure-site.d.ts.map +1 -0
  125. package/dist/server/fallbacks.d.ts +10 -0
  126. package/dist/server/fallbacks.d.ts.map +1 -0
  127. package/dist/server/index.d.ts +14 -0
  128. package/dist/server/index.d.ts.map +1 -0
  129. package/dist/server/negotiate.d.ts +3 -0
  130. package/dist/server/negotiate.d.ts.map +1 -0
  131. package/dist/server/not-found.d.ts +11 -0
  132. package/dist/server/not-found.d.ts.map +1 -0
  133. package/dist/server/problem.d.ts +18 -0
  134. package/dist/server/problem.d.ts.map +1 -0
  135. package/dist/server/render-tree.d.ts +4 -0
  136. package/dist/server/render-tree.d.ts.map +1 -0
  137. package/dist/server/request-handler.d.ts +40 -0
  138. package/dist/server/request-handler.d.ts.map +1 -0
  139. package/dist/server/request-metadata.d.ts +7 -0
  140. package/dist/server/request-metadata.d.ts.map +1 -0
  141. package/dist/server/ssr.d.ts +17 -0
  142. package/dist/server/ssr.d.ts.map +1 -0
  143. package/dist/static/index.d.ts +23 -0
  144. package/dist/static/index.d.ts.map +1 -0
  145. package/dist/static/index.js +256 -0
  146. package/dist/static/index.js.map +1 -0
  147. package/dist/vite/index.d.ts +4 -0
  148. package/dist/vite/index.d.ts.map +1 -0
  149. package/dist/vite/index.js +580 -0
  150. package/dist/vite/index.js.map +1 -0
  151. package/dist/vite/plugin.d.ts +37 -0
  152. package/dist/vite/plugin.d.ts.map +1 -0
  153. package/package.json +90 -4
@@ -0,0 +1,2871 @@
1
+ import { g as mt, h as ht, b as Le, r as pt } from "./ssr-O3d7Q73U.js";
2
+ import { createElement as ee } from "react";
3
+ import { renderToString as He } from "react-dom/server";
4
+ import { jsxs as N, jsx as $ } from "react/jsx-runtime";
5
+ function as(e) {
6
+ return e;
7
+ }
8
+ function cs(e, t = {}) {
9
+ return {
10
+ ...t,
11
+ href: e,
12
+ kind: "link",
13
+ rel: "preconnect"
14
+ };
15
+ }
16
+ function us(e, t) {
17
+ return {
18
+ ...t,
19
+ href: e,
20
+ kind: "link",
21
+ rel: "preload"
22
+ };
23
+ }
24
+ function ls(e) {
25
+ return {
26
+ href: e,
27
+ kind: "link",
28
+ rel: "modulepreload"
29
+ };
30
+ }
31
+ async function gt(e, t) {
32
+ const r = [];
33
+ for (const n of e) {
34
+ if (!n)
35
+ continue;
36
+ const s = typeof n == "function" ? await n(t) : n;
37
+ r.push(...s);
38
+ }
39
+ return wt(r).sort(yt);
40
+ }
41
+ function wt(e) {
42
+ const t = /* @__PURE__ */ new Map();
43
+ for (const r of e)
44
+ t.set(pe(r), {
45
+ ...t.get(pe(r)),
46
+ ...r
47
+ });
48
+ return [...t.values()];
49
+ }
50
+ function pe(e) {
51
+ return [
52
+ e.rel,
53
+ e.href,
54
+ e.as ?? "",
55
+ e.type ?? "",
56
+ e.crossOrigin ?? ""
57
+ ].join("\0");
58
+ }
59
+ function yt(e, t) {
60
+ return ge(e.rel) - ge(t.rel) || e.href.localeCompare(t.href);
61
+ }
62
+ function ge(e) {
63
+ return e === "preconnect" ? 0 : e === "preload" ? 1 : e === "modulepreload" ? 2 : 3;
64
+ }
65
+ function fs(e) {
66
+ return e;
67
+ }
68
+ function ds(e) {
69
+ return {
70
+ ...e,
71
+ kind: "meta"
72
+ };
73
+ }
74
+ function ms(e) {
75
+ return {
76
+ ...e,
77
+ kind: "link"
78
+ };
79
+ }
80
+ function hs(e) {
81
+ return {
82
+ kind: "structured-data",
83
+ value: e
84
+ };
85
+ }
86
+ function b(...e) {
87
+ const t = {
88
+ custom: [],
89
+ structuredData: []
90
+ };
91
+ for (const o of e)
92
+ o && St(t, o);
93
+ const r = Rt(t), n = t.description, s = bt(t.openGraph, r, n);
94
+ return {
95
+ canonical: t.canonical,
96
+ charset: "utf-8",
97
+ custom: t.custom,
98
+ description: n,
99
+ openGraph: s,
100
+ robots: t.robots,
101
+ structuredData: t.structuredData,
102
+ title: r,
103
+ viewport: "width=device-width, initial-scale=1"
104
+ };
105
+ }
106
+ function St(e, t) {
107
+ Et(e, t.title), t.description !== void 0 && (e.description = t.description), t.canonical !== void 0 && (e.canonical = t.canonical), t.robots && (e.robots = {
108
+ ...e.robots ?? {},
109
+ ...t.robots
110
+ }), t.openGraph && (e.openGraph = {
111
+ ...e.openGraph ?? {},
112
+ ...t.openGraph
113
+ }), t.custom && e.custom.push(...t.custom), t.structuredData && e.structuredData.push(...t.structuredData);
114
+ }
115
+ function Et(e, t) {
116
+ if (t !== void 0) {
117
+ if (typeof t == "string") {
118
+ e.title = t;
119
+ return;
120
+ }
121
+ t.default !== void 0 && (e.titleDefault = t.default), t.format && (e.titleFormat = t.format);
122
+ }
123
+ }
124
+ function Rt(e) {
125
+ return e.title === void 0 ? e.titleDefault : e.titleFormat ? e.titleFormat(e.title) : e.title;
126
+ }
127
+ function bt(e, t, r) {
128
+ if (!(!e && !t && !r))
129
+ return {
130
+ ...t ? { title: t } : {},
131
+ ...r ? { description: r } : {},
132
+ ...e ?? {}
133
+ };
134
+ }
135
+ const Tt = /* @__PURE__ */ new Set([
136
+ "afterInteractive",
137
+ "beforeInteractive",
138
+ "module"
139
+ ]);
140
+ function ps(e) {
141
+ return e;
142
+ }
143
+ function gs(e) {
144
+ const t = e.strategy ?? "afterInteractive";
145
+ if (!Tt.has(t))
146
+ throw new Error(
147
+ `Unsupported script strategy ${JSON.stringify(t)}. Demiurge 0.1 supports "beforeInteractive", "module", and "afterInteractive"; deferred, visibility-triggered, and worker loading require a future client script runtime.`
148
+ );
149
+ if (t === "module" && e.type && e.type !== "module")
150
+ throw new Error(
151
+ 'The "module" script strategy cannot be combined with type="text/javascript".'
152
+ );
153
+ return {
154
+ ...e,
155
+ kind: "script",
156
+ strategy: t
157
+ };
158
+ }
159
+ async function vt(e, t) {
160
+ const r = [];
161
+ for (const n of e) {
162
+ if (!n)
163
+ continue;
164
+ const s = typeof n == "function" ? await n(t) : n;
165
+ r.push(...s);
166
+ }
167
+ return xt(r).sort(kt);
168
+ }
169
+ function xt(e) {
170
+ const t = /* @__PURE__ */ new Map();
171
+ for (const r of e)
172
+ t.set(we(r), {
173
+ ...t.get(we(r)),
174
+ ...r
175
+ });
176
+ return [...t.values()];
177
+ }
178
+ function we(e) {
179
+ return [
180
+ e.src,
181
+ e.type ?? "",
182
+ e.integrity ?? "",
183
+ e.strategy
184
+ ].join("\0");
185
+ }
186
+ function kt(e, t) {
187
+ return ye(e.strategy) - ye(t.strategy) || e.src.localeCompare(t.src);
188
+ }
189
+ function ye(e) {
190
+ return e === "beforeInteractive" ? 0 : e === "module" ? 1 : 2;
191
+ }
192
+ function Pt(e) {
193
+ if (typeof e == "string")
194
+ return e;
195
+ const t = Ct(Nt(
196
+ e.to,
197
+ "path" in e ? e.path : void 0
198
+ )), r = e.search === void 0 ? t.search : At(e.search), n = e.hash === void 0 ? t.hash : e.hash ? e.hash.startsWith("#") ? e.hash : `#${e.hash}` : "";
199
+ return `${t.pathname}${r}${n}`;
200
+ }
201
+ function Ct(e) {
202
+ const t = e.indexOf("#"), r = t === -1 ? e : e.slice(0, t), n = r.indexOf("?");
203
+ return {
204
+ hash: t === -1 ? "" : e.slice(t),
205
+ pathname: n === -1 ? r : r.slice(0, n),
206
+ search: n === -1 ? "" : r.slice(n)
207
+ };
208
+ }
209
+ function At(e) {
210
+ if (!e)
211
+ return "";
212
+ if (typeof e == "string")
213
+ return e.startsWith("?") ? e : `?${e}`;
214
+ const r = (e instanceof URLSearchParams ? e : Dt(e)).toString();
215
+ return r ? `?${r}` : "";
216
+ }
217
+ function Dt(e) {
218
+ const t = new URLSearchParams();
219
+ for (const [r, n] of Object.entries(e)) {
220
+ const s = Array.isArray(n) ? n : [n];
221
+ for (const o of s)
222
+ o != null && t.append(r, String(o));
223
+ }
224
+ return t;
225
+ }
226
+ function Nt(e, t) {
227
+ return t ? e.replace(
228
+ /\[(\.\.\.)?([a-zA-Z_$][a-zA-Z0-9_$]*)\]/g,
229
+ (r, n, s) => {
230
+ const o = t[s];
231
+ if (o === void 0)
232
+ throw new Error(`Missing path value for "${s}" in route "${e}".`);
233
+ return n ? String(o).split("/").filter(Boolean).map((i) => encodeURIComponent(i)).join("/") : encodeURIComponent(String(o));
234
+ }
235
+ ) : e;
236
+ }
237
+ function ws(e, t) {
238
+ return {
239
+ cors: t?.cors,
240
+ kind: "json",
241
+ security: t?.security,
242
+ timing: S(t?.timing),
243
+ value: e,
244
+ init: T(t)
245
+ };
246
+ }
247
+ function ys(e, t) {
248
+ return {
249
+ cors: t?.cors,
250
+ init: T(t),
251
+ kind: "jsonl",
252
+ lines: e,
253
+ security: t?.security,
254
+ timing: S(t?.timing)
255
+ };
256
+ }
257
+ function Ss(e, t) {
258
+ return {
259
+ cors: t?.cors,
260
+ kind: "text",
261
+ security: t?.security,
262
+ timing: S(t?.timing),
263
+ value: e,
264
+ init: T(t)
265
+ };
266
+ }
267
+ function Es(e, t) {
268
+ return {
269
+ cors: t?.cors,
270
+ kind: "html",
271
+ security: t?.security,
272
+ timing: S(t?.timing),
273
+ value: e,
274
+ init: T(t)
275
+ };
276
+ }
277
+ function Rs(e, t) {
278
+ const r = typeof t == "number" ? void 0 : t;
279
+ return {
280
+ cors: r?.cors,
281
+ kind: "redirect",
282
+ security: r?.security,
283
+ timing: S(r?.timing),
284
+ to: zt(e) ? Pt(e) : e,
285
+ init: typeof t == "number" ? { status: t } : T(t)
286
+ };
287
+ }
288
+ function bs(e, t) {
289
+ return {
290
+ cors: t?.cors,
291
+ kind: "not-found",
292
+ security: t?.security,
293
+ timing: S(t?.timing),
294
+ body: e,
295
+ init: T(t)
296
+ };
297
+ }
298
+ function Ts(e, t) {
299
+ return {
300
+ cors: t?.cors,
301
+ kind: "response",
302
+ response: e,
303
+ security: t?.security,
304
+ timing: S(t?.timing)
305
+ };
306
+ }
307
+ function vs(e, t) {
308
+ return {
309
+ body: e,
310
+ cors: t?.cors,
311
+ init: T(t),
312
+ kind: "stream",
313
+ security: t?.security,
314
+ timing: S(t?.timing)
315
+ };
316
+ }
317
+ function xs(e, t) {
318
+ return {
319
+ cors: t?.cors,
320
+ events: e,
321
+ init: T(t),
322
+ kind: "sse",
323
+ security: t?.security,
324
+ timing: S(t?.timing)
325
+ };
326
+ }
327
+ function ks(...e) {
328
+ return e;
329
+ }
330
+ async function $t(e, t) {
331
+ switch (e.kind) {
332
+ case "json":
333
+ return new Response(JSON.stringify(await w(e.value, t)), {
334
+ ...e.init,
335
+ headers: V(
336
+ e.init?.headers,
337
+ "content-type",
338
+ "application/json; charset=utf-8"
339
+ )
340
+ });
341
+ case "jsonl":
342
+ return new Response(
343
+ Ot(await w(e.lines, t)),
344
+ {
345
+ ...e.init,
346
+ headers: j(e.init?.headers, {
347
+ "cache-control": "no-cache",
348
+ "content-type": "application/x-ndjson; charset=utf-8",
349
+ "x-accel-buffering": "no"
350
+ })
351
+ }
352
+ );
353
+ case "text":
354
+ return new Response(await w(e.value, t), {
355
+ ...e.init,
356
+ headers: V(
357
+ e.init?.headers,
358
+ "content-type",
359
+ "text/plain; charset=utf-8"
360
+ )
361
+ });
362
+ case "html":
363
+ return new Response(await w(e.value, t), {
364
+ ...e.init,
365
+ headers: V(
366
+ e.init?.headers,
367
+ "content-type",
368
+ "text/html; charset=utf-8"
369
+ )
370
+ });
371
+ case "redirect": {
372
+ const r = new Headers(e.init?.headers);
373
+ return r.set("location", String(await w(e.to, t))), new Response(null, {
374
+ ...e.init,
375
+ headers: r,
376
+ status: e.init?.status ?? 302
377
+ });
378
+ }
379
+ case "not-found":
380
+ return new Response(
381
+ e.body ? await w(e.body, t) : null,
382
+ {
383
+ ...e.init,
384
+ status: e.init?.status ?? 404
385
+ }
386
+ );
387
+ case "response":
388
+ return await w(e.response, t);
389
+ case "stream":
390
+ return new Response(
391
+ Lt(await w(e.body, t)),
392
+ {
393
+ ...e.init,
394
+ headers: j(e.init?.headers, {
395
+ "content-type": "application/octet-stream",
396
+ "x-accel-buffering": "no"
397
+ })
398
+ }
399
+ );
400
+ case "sse":
401
+ return new Response(
402
+ It(await w(e.events, t)),
403
+ {
404
+ ...e.init,
405
+ headers: j(e.init?.headers, {
406
+ "cache-control": "no-cache",
407
+ "content-type": "text/event-stream; charset=utf-8",
408
+ "x-accel-buffering": "no"
409
+ })
410
+ }
411
+ );
412
+ }
413
+ }
414
+ async function w(e, t) {
415
+ return typeof e != "function" ? e : await e(
416
+ t
417
+ );
418
+ }
419
+ function V(e, t, r) {
420
+ return j(e, { [t]: r });
421
+ }
422
+ function j(e, t) {
423
+ const r = new Headers(e);
424
+ for (const [n, s] of Object.entries(t))
425
+ r.has(n) || r.set(n, s);
426
+ return r;
427
+ }
428
+ function It(e) {
429
+ const t = new TextEncoder(), r = oe(e);
430
+ return new ReadableStream({
431
+ async pull(n) {
432
+ const s = await r.next();
433
+ if (s.done) {
434
+ n.close();
435
+ return;
436
+ }
437
+ n.enqueue(t.encode(Mt(s.value)));
438
+ },
439
+ async cancel() {
440
+ await r.return?.();
441
+ }
442
+ });
443
+ }
444
+ function Ot(e) {
445
+ const t = new TextEncoder(), r = oe(e);
446
+ return new ReadableStream({
447
+ async pull(n) {
448
+ const s = await r.next();
449
+ if (s.done) {
450
+ n.close();
451
+ return;
452
+ }
453
+ n.enqueue(t.encode(`${JSON.stringify(s.value)}
454
+ `));
455
+ },
456
+ async cancel() {
457
+ await r.return?.();
458
+ }
459
+ });
460
+ }
461
+ function Lt(e) {
462
+ const t = new TextEncoder(), r = oe(e);
463
+ return new ReadableStream({
464
+ async pull(n) {
465
+ const s = await r.next();
466
+ if (s.done) {
467
+ n.close();
468
+ return;
469
+ }
470
+ n.enqueue(Ht(s.value, t));
471
+ },
472
+ async cancel() {
473
+ await r.return?.();
474
+ }
475
+ });
476
+ }
477
+ function Ht(e, t) {
478
+ return typeof e == "string" ? t.encode(e) : e;
479
+ }
480
+ function oe(e) {
481
+ if (e instanceof ReadableStream) {
482
+ const t = e.getReader();
483
+ return {
484
+ async next() {
485
+ return await t.read();
486
+ },
487
+ async return() {
488
+ return t.releaseLock(), { done: !0, value: void 0 };
489
+ }
490
+ };
491
+ }
492
+ return Symbol.asyncIterator in e ? e[Symbol.asyncIterator]() : Ut(e[Symbol.iterator]());
493
+ }
494
+ function Ut(e) {
495
+ return {
496
+ async next() {
497
+ return e.next();
498
+ },
499
+ async return() {
500
+ return e.return?.(), { done: !0, value: void 0 };
501
+ }
502
+ };
503
+ }
504
+ function Mt(e) {
505
+ if (typeof e == "string")
506
+ return jt(e);
507
+ const t = [];
508
+ if (e.comment !== void 0 && t.push(...C("", e.comment)), e.id !== void 0 && t.push(...C("id", e.id)), e.event !== void 0 && t.push(...C("event", e.event)), e.retry !== void 0) {
509
+ if (!Number.isInteger(e.retry) || e.retry < 0)
510
+ throw new Error("SSE retry must be a non-negative integer.");
511
+ t.push(`retry: ${e.retry}`);
512
+ }
513
+ return e.data !== void 0 && t.push(...C("data", Ft(e.data))), `${t.join(`
514
+ `)}
515
+
516
+ `;
517
+ }
518
+ function jt(e) {
519
+ return `${C("data", e).join(`
520
+ `)}
521
+
522
+ `;
523
+ }
524
+ function C(e, t) {
525
+ return t.split(/\r\n|\r|\n/).map(
526
+ (r) => e ? `${e}: ${r}` : `: ${r}`
527
+ );
528
+ }
529
+ function Ft(e) {
530
+ return typeof e == "string" ? e : JSON.stringify(e);
531
+ }
532
+ function zt(e) {
533
+ return typeof e == "object" && e !== null && !(e instanceof URL) && "to" in e;
534
+ }
535
+ function T(e) {
536
+ if (!e)
537
+ return;
538
+ const {
539
+ cors: t,
540
+ security: r,
541
+ timing: n,
542
+ ...s
543
+ } = e;
544
+ return s;
545
+ }
546
+ function qt(e, t) {
547
+ if (!t?.length)
548
+ return e;
549
+ const r = new Headers(e.headers), n = Wt(t), s = r.get("server-timing");
550
+ return r.set(
551
+ "server-timing",
552
+ s ? `${s}, ${n}` : n
553
+ ), new Response(e.body, {
554
+ headers: r,
555
+ status: e.status,
556
+ statusText: e.statusText
557
+ });
558
+ }
559
+ function Wt(e) {
560
+ return e.map(Bt).join(", ");
561
+ }
562
+ function S(e) {
563
+ if (e)
564
+ return Array.isArray(e) ? e : [e];
565
+ }
566
+ function Bt(e) {
567
+ if (!Gt(e.name))
568
+ throw new Error(
569
+ `Server-Timing metric name "${e.name}" is not a valid token.`
570
+ );
571
+ const t = [e.name];
572
+ if (e.duration !== void 0) {
573
+ if (!Number.isFinite(e.duration) || e.duration < 0)
574
+ throw new Error("Server-Timing metric duration must be a non-negative finite number.");
575
+ t.push(`dur=${_t(e.duration)}`);
576
+ }
577
+ return e.description !== void 0 && t.push(`desc="${Vt(e.description)}"`), t.join(";");
578
+ }
579
+ function Gt(e) {
580
+ return /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(e);
581
+ }
582
+ function _t(e) {
583
+ return Number.isInteger(e), String(e);
584
+ }
585
+ function Vt(e) {
586
+ return e.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
587
+ }
588
+ const Kt = [
589
+ 400,
590
+ 401,
591
+ 402,
592
+ 403,
593
+ 404,
594
+ 405,
595
+ 406,
596
+ 407,
597
+ 408,
598
+ 409,
599
+ 410,
600
+ 411,
601
+ 412,
602
+ 413,
603
+ 414,
604
+ 415,
605
+ 416,
606
+ 417,
607
+ 418,
608
+ 421,
609
+ 422,
610
+ 423,
611
+ 424,
612
+ 425,
613
+ 426,
614
+ 428,
615
+ 429,
616
+ 431,
617
+ 451,
618
+ 500,
619
+ 501,
620
+ 502,
621
+ 503,
622
+ 504,
623
+ 505,
624
+ 506,
625
+ 507,
626
+ 508,
627
+ 510,
628
+ 511
629
+ ], Jt = {
630
+ 400: "Bad Request",
631
+ 401: "Unauthorized",
632
+ 402: "Payment Required",
633
+ 403: "Forbidden",
634
+ 404: "Not Found",
635
+ 405: "Method Not Allowed",
636
+ 406: "Not Acceptable",
637
+ 407: "Proxy Authentication Required",
638
+ 408: "Request Timeout",
639
+ 409: "Conflict",
640
+ 410: "Gone",
641
+ 411: "Length Required",
642
+ 412: "Precondition Failed",
643
+ 413: "Content Too Large",
644
+ 414: "URI Too Long",
645
+ 415: "Unsupported Media Type",
646
+ 416: "Range Not Satisfiable",
647
+ 417: "Expectation Failed",
648
+ 418: "I'm a Teapot",
649
+ 421: "Misdirected Request",
650
+ 422: "Unprocessable Content",
651
+ 423: "Locked",
652
+ 424: "Failed Dependency",
653
+ 425: "Too Early",
654
+ 426: "Upgrade Required",
655
+ 428: "Precondition Required",
656
+ 429: "Too Many Requests",
657
+ 431: "Request Header Fields Too Large",
658
+ 451: "Unavailable For Legal Reasons",
659
+ 500: "Internal Server Error",
660
+ 501: "Not Implemented",
661
+ 502: "Bad Gateway",
662
+ 503: "Service Unavailable",
663
+ 504: "Gateway Timeout",
664
+ 505: "HTTP Version Not Supported",
665
+ 506: "Variant Also Negotiates",
666
+ 507: "Insufficient Storage",
667
+ 508: "Loop Detected",
668
+ 510: "Not Extended",
669
+ 511: "Network Authentication Required"
670
+ }, Yt = new Set(Kt);
671
+ class Ue extends Error {
672
+ detail;
673
+ extensions;
674
+ headers;
675
+ status;
676
+ title;
677
+ type;
678
+ constructor(t, r = {}, n = {}) {
679
+ Zt(t);
680
+ const s = typeof r == "string" ? { detail: r } : r, {
681
+ detail: o,
682
+ title: i = Jt[t],
683
+ type: a = "about:blank",
684
+ ...c
685
+ } = s;
686
+ super(o ?? i, { cause: n.cause }), this.name = "HttpError", this.detail = o, this.extensions = Object.freeze({ ...c }), this.headers = new Headers(n.headers), this.status = t, this.title = i, this.type = a;
687
+ }
688
+ }
689
+ function Ps(e, t, r) {
690
+ return new Ue(e, t, r);
691
+ }
692
+ function ie(e) {
693
+ return e instanceof Ue;
694
+ }
695
+ function Zt(e) {
696
+ if (!Yt.has(e))
697
+ throw new RangeError(
698
+ `HTTP error status must be a standard 4xx or 5xx status; received ${JSON.stringify(e)}.`
699
+ );
700
+ }
701
+ const Se = ["build", "private", "public"], Qt = {
702
+ app: "demiurge-memory",
703
+ environment: "local",
704
+ schemaVersion: 1
705
+ }, Xt = 1e4, er = 3e4;
706
+ function Cs(e) {
707
+ return (...t) => ({
708
+ fn: () => e.fn(...t),
709
+ key: e.key(...t),
710
+ scope: e.scope,
711
+ staleWhileRevalidate: e.staleWhileRevalidate,
712
+ tags: e.tags?.(...t),
713
+ ttl: e.ttl
714
+ });
715
+ }
716
+ function As(e) {
717
+ return { id: e };
718
+ }
719
+ function Ds(e) {
720
+ return e;
721
+ }
722
+ function Me(e) {
723
+ const t = e.now ?? Date.now, r = sr(e.refreshLeaseTtl), n = je(e.namespace), s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
724
+ return {
725
+ async get(i) {
726
+ const a = i.scope ?? "request";
727
+ if (a === "none")
728
+ return await i.fn();
729
+ const c = Re(i.key);
730
+ if (a === "request")
731
+ return await nr(s, c, i, t);
732
+ const u = be(n, a, c), l = (i.tags ?? []).map(
733
+ (g) => Te(n, a, te(g))
734
+ ), d = await e.store.get(u);
735
+ if (d && (d.expiresAt === null || d.expiresAt > t()))
736
+ return d.value;
737
+ if (d && or(d, t())) {
738
+ const g = ir(e.store), h = globalThis.crypto.randomUUID();
739
+ if (await g.acquireRefreshLease(
740
+ u,
741
+ h,
742
+ t() + r
743
+ )) {
744
+ const v = ar({
745
+ key: u,
746
+ now: t,
747
+ onBackgroundError: e.onBackgroundError,
748
+ refreshStore: g,
749
+ request: i,
750
+ tags: l,
751
+ token: h
752
+ });
753
+ e.waitUntil?.(v);
754
+ }
755
+ return d.value;
756
+ }
757
+ d && await e.store.delete(u);
758
+ const m = o.get(u);
759
+ if (m)
760
+ return await m.promise;
761
+ const f = { invalidated: !1 }, k = Promise.resolve().then(i.fn).then(async (g) => (f.invalidated || await e.store.set(u, {
762
+ expiresAt: Fe(t(), i.ttl),
763
+ staleUntil: ze(
764
+ t(),
765
+ i.ttl,
766
+ i.staleWhileRevalidate
767
+ ),
768
+ tags: l,
769
+ value: g
770
+ }), g)), H = {
771
+ promise: k,
772
+ state: f,
773
+ tags: l
774
+ };
775
+ o.set(u, H);
776
+ try {
777
+ return await k;
778
+ } finally {
779
+ o.get(u) === H && o.delete(u);
780
+ }
781
+ },
782
+ async invalidateKey(i) {
783
+ const a = Re(i), c = s.delete(a);
784
+ let u = !1;
785
+ const l = await Promise.all(
786
+ Se.map((d) => {
787
+ const m = be(n, d, a), f = o.get(m);
788
+ return f && (f.state.invalidated = !0, u = !0), e.store.delete(m);
789
+ })
790
+ );
791
+ return c || u || l.some(Boolean);
792
+ },
793
+ async invalidateTags(i) {
794
+ const a = i.map(te), c = cr(
795
+ s,
796
+ new Set(a)
797
+ ), u = new Set(
798
+ Se.flatMap(
799
+ (m) => a.map((f) => Te(n, m, f))
800
+ )
801
+ );
802
+ let l = 0;
803
+ for (const m of o.values())
804
+ !m.state.invalidated && m.tags.some((f) => u.has(f)) && (m.state.invalidated = !0, l += 1);
805
+ const d = await e.store.invalidateTags([...u]);
806
+ return c + l + d;
807
+ }
808
+ };
809
+ }
810
+ function ae(e = {}) {
811
+ const t = e.now ?? Date.now;
812
+ return Me({
813
+ namespace: Qt,
814
+ now: t,
815
+ onBackgroundError: e.onBackgroundError,
816
+ refreshLeaseTtl: e.refreshLeaseTtl,
817
+ store: tr({
818
+ maximumEntries: e.maximumEntries,
819
+ now: t
820
+ }),
821
+ waitUntil: e.waitUntil
822
+ });
823
+ }
824
+ function tr(e = {}) {
825
+ const t = e.entries ?? /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), n = e.maximumEntries ?? Xt, s = e.now ?? Date.now;
826
+ if (!Number.isSafeInteger(n) || n <= 0)
827
+ throw new Error(
828
+ "Demiurge memory cache maximumEntries must be a positive integer."
829
+ );
830
+ K(t, r, s()), rr(t, n);
831
+ let o = J(t);
832
+ return {
833
+ acquireRefreshLease(i, a, c) {
834
+ const u = s(), l = r.get(i);
835
+ return l && l.expiresAt > u ? !1 : (r.set(i, { expiresAt: c, token: a }), !0);
836
+ },
837
+ delete(i) {
838
+ return r.delete(i), t.delete(i);
839
+ },
840
+ get(i) {
841
+ return s() >= o && (K(t, r, s()), o = J(t)), t.get(i);
842
+ },
843
+ invalidateTags(i) {
844
+ const a = new Set(i);
845
+ let c = 0;
846
+ for (const [u, l] of t)
847
+ l.tags.some((d) => a.has(d)) && (t.delete(u), r.delete(u), c += 1);
848
+ return c;
849
+ },
850
+ publishRefresh(i, a, c) {
851
+ const u = r.get(i);
852
+ return !u || u.token !== a || u.expiresAt <= s() ? !1 : (Ee(
853
+ t,
854
+ r,
855
+ n,
856
+ i,
857
+ c
858
+ ), r.delete(i), c.staleUntil !== null && (o = Math.min(o, c.staleUntil)), !0);
859
+ },
860
+ releaseRefreshLease(i, a) {
861
+ r.get(i)?.token === a && r.delete(i);
862
+ },
863
+ set(i, a) {
864
+ const c = s();
865
+ c >= o && (K(t, r, c), o = J(t)), r.delete(i), Ee(
866
+ t,
867
+ r,
868
+ n,
869
+ i,
870
+ a
871
+ ), a.staleUntil !== null && (o = Math.min(o, a.staleUntil));
872
+ }
873
+ };
874
+ }
875
+ function K(e, t, r) {
876
+ for (const [n, s] of e)
877
+ s.staleUntil !== null && s.staleUntil <= r && (e.delete(n), t.delete(n));
878
+ }
879
+ function Ee(e, t, r, n, s) {
880
+ if (!e.has(n) && e.size >= r)
881
+ for (; e.size >= r; ) {
882
+ const o = e.keys().next().value;
883
+ if (o === void 0)
884
+ break;
885
+ e.delete(o), t.delete(o);
886
+ }
887
+ e.set(n, s);
888
+ }
889
+ function rr(e, t) {
890
+ for (; e.size > t; ) {
891
+ const r = e.keys().next().value;
892
+ if (r === void 0)
893
+ return;
894
+ e.delete(r);
895
+ }
896
+ }
897
+ function J(e) {
898
+ let t = Number.POSITIVE_INFINITY;
899
+ for (const r of e.values())
900
+ r.staleUntil !== null && (t = Math.min(t, r.staleUntil));
901
+ return t;
902
+ }
903
+ function je(e) {
904
+ const t = Y("app", e.app), r = Y(
905
+ "environment",
906
+ e.environment
907
+ );
908
+ if (typeof e.schemaVersion == "number" && (!Number.isInteger(e.schemaVersion) || e.schemaVersion < 0))
909
+ throw new Error(
910
+ "Demiurge cache namespace schemaVersion must be a non-negative integer or string."
911
+ );
912
+ const n = Y(
913
+ "schemaVersion",
914
+ String(e.schemaVersion)
915
+ );
916
+ return `${t}:${r}:${n}`;
917
+ }
918
+ function Ns(e) {
919
+ return {
920
+ async key(t) {
921
+ return {
922
+ deleted: await e.invalidateKey(t) ? 1 : 0,
923
+ kind: "key"
924
+ };
925
+ },
926
+ async keys(t) {
927
+ let r = 0;
928
+ for (const n of t)
929
+ await e.invalidateKey(n) && (r += 1);
930
+ return {
931
+ deleted: r,
932
+ kind: "key"
933
+ };
934
+ },
935
+ async tag(t) {
936
+ return {
937
+ deleted: await e.invalidateTags([t]),
938
+ kind: "tag"
939
+ };
940
+ },
941
+ async tags(t) {
942
+ return {
943
+ deleted: await e.invalidateTags(t),
944
+ kind: "tag"
945
+ };
946
+ }
947
+ };
948
+ }
949
+ function I(e) {
950
+ if (e === void 0)
951
+ return Number.POSITIVE_INFINITY;
952
+ if (typeof e == "number") {
953
+ if (!Number.isInteger(e) || e < 0)
954
+ throw new Error("Demiurge cache duration must be a non-negative integer.");
955
+ return e;
956
+ }
957
+ const t = /^(\d+)(ms|s|m|h)$/.exec(e);
958
+ if (!t)
959
+ throw new Error("Demiurge cache duration must use an ms/s/m/h suffix.");
960
+ const r = Number(t[1]), n = t[2];
961
+ return n === "h" ? r * 36e5 : n === "m" ? r * 6e4 : n === "s" ? r * 1e3 : r;
962
+ }
963
+ function Re(e) {
964
+ return re(e, /* @__PURE__ */ new Set());
965
+ }
966
+ function te(e) {
967
+ return e.id;
968
+ }
969
+ async function nr(e, t, r, n) {
970
+ const s = e.get(t);
971
+ if (s && s.expiresAt > n())
972
+ return await s.value;
973
+ const o = Promise.resolve().then(r.fn), i = {
974
+ expiresAt: n() + I(r.ttl),
975
+ tags: (r.tags ?? []).map(te),
976
+ value: o
977
+ };
978
+ e.set(t, i);
979
+ try {
980
+ return await o;
981
+ } catch (a) {
982
+ throw e.get(t) === i && e.delete(t), a;
983
+ }
984
+ }
985
+ function be(e, t, r) {
986
+ return `${e}:${t}:key:${r}`;
987
+ }
988
+ function Te(e, t, r) {
989
+ return `${e}:${t}:tag:${r}`;
990
+ }
991
+ function Fe(e, t) {
992
+ const r = I(t);
993
+ return Number.isFinite(r) ? e + r : null;
994
+ }
995
+ function ze(e, t, r) {
996
+ const n = I(t);
997
+ if (!Number.isFinite(n)) {
998
+ if (r !== void 0)
999
+ throw new Error(
1000
+ "Demiurge staleWhileRevalidate requires a finite cache ttl."
1001
+ );
1002
+ return null;
1003
+ }
1004
+ return e + n + I(r ?? 0);
1005
+ }
1006
+ function sr(e) {
1007
+ const t = I(e ?? er);
1008
+ if (!Number.isFinite(t) || t <= 0)
1009
+ throw new Error(
1010
+ "Demiurge cache refreshLeaseTtl must be a positive finite duration."
1011
+ );
1012
+ return t;
1013
+ }
1014
+ function or(e, t) {
1015
+ return e.expiresAt !== null && e.expiresAt <= t && (e.staleUntil === null || e.staleUntil > t);
1016
+ }
1017
+ function ir(e) {
1018
+ if (!e.acquireRefreshLease || !e.publishRefresh || !e.releaseRefreshLease)
1019
+ throw new Error(
1020
+ "Demiurge staleWhileRevalidate requires a cache store with acquireRefreshLease, publishRefresh, and releaseRefreshLease coordination methods."
1021
+ );
1022
+ return e;
1023
+ }
1024
+ async function ar(e) {
1025
+ try {
1026
+ const t = await e.request.fn(), r = e.now();
1027
+ await e.refreshStore.publishRefresh(e.key, e.token, {
1028
+ expiresAt: Fe(r, e.request.ttl),
1029
+ staleUntil: ze(
1030
+ r,
1031
+ e.request.ttl,
1032
+ e.request.staleWhileRevalidate
1033
+ ),
1034
+ tags: e.tags,
1035
+ value: t
1036
+ });
1037
+ } catch (t) {
1038
+ e.onBackgroundError ? e.onBackgroundError(t) : console.error("Demiurge stale cache refresh failed.", t);
1039
+ } finally {
1040
+ await e.refreshStore.releaseRefreshLease(e.key, e.token);
1041
+ }
1042
+ }
1043
+ function Y(e, t) {
1044
+ const r = [...t].some((n) => {
1045
+ const s = n.charCodeAt(0);
1046
+ return s <= 31 || s === 127;
1047
+ });
1048
+ if (!t || t.trim() !== t || t.includes(":") || r)
1049
+ throw new Error(
1050
+ `Demiurge cache namespace ${e} must be non-empty and cannot contain whitespace padding, colons, or control characters.`
1051
+ );
1052
+ return t;
1053
+ }
1054
+ function cr(e, t) {
1055
+ let r = 0;
1056
+ for (const [n, s] of e)
1057
+ s.tags.some((o) => t.has(o)) && (e.delete(n), r += 1);
1058
+ return r;
1059
+ }
1060
+ function re(e, t) {
1061
+ if (e === null || typeof e == "boolean" || typeof e == "string")
1062
+ return JSON.stringify(e);
1063
+ if (typeof e == "number") {
1064
+ if (!Number.isFinite(e) || Object.is(e, -0))
1065
+ throw new Error(
1066
+ "Demiurge cache keys require finite numbers and do not accept negative zero."
1067
+ );
1068
+ return JSON.stringify(e);
1069
+ }
1070
+ if (typeof e != "object")
1071
+ throw new Error(
1072
+ `Demiurge cache keys do not accept values of type ${typeof e}.`
1073
+ );
1074
+ if (t.has(e))
1075
+ throw new Error("Demiurge cache keys cannot contain circular references.");
1076
+ if (t.add(e), Array.isArray(e)) {
1077
+ const i = Reflect.ownKeys(e), a = [
1078
+ ...Array.from({ length: e.length }, (u, l) => String(l)),
1079
+ "length"
1080
+ ];
1081
+ if (i.length !== a.length || i.some((u, l) => u !== a[l]) || a.slice(0, -1).some((u) => {
1082
+ const l = Object.getOwnPropertyDescriptor(e, u);
1083
+ return !l?.enumerable || !("value" in l);
1084
+ }))
1085
+ throw t.delete(e), new Error(
1086
+ "Demiurge cache key arrays must be dense and cannot contain accessors or custom properties."
1087
+ );
1088
+ const c = `[${e.map((u) => re(u, t)).join(",")}]`;
1089
+ return t.delete(e), c;
1090
+ }
1091
+ const r = Object.getPrototypeOf(e);
1092
+ if (r !== Object.prototype && r !== null)
1093
+ throw new Error(
1094
+ "Demiurge cache keys accept only primitives, arrays, and plain objects."
1095
+ );
1096
+ const n = Reflect.ownKeys(e);
1097
+ if (n.some((i) => typeof i == "symbol") || n.some((i) => {
1098
+ const a = Object.getOwnPropertyDescriptor(e, i);
1099
+ return !a?.enumerable || !("value" in a);
1100
+ }))
1101
+ throw new Error(
1102
+ "Demiurge cache key objects require enumerable string data properties."
1103
+ );
1104
+ const s = e, o = `{${Object.keys(s).sort().map(
1105
+ (i) => `${JSON.stringify(i)}:${re(s[i], t)}`
1106
+ ).join(",")}}`;
1107
+ return t.delete(e), o;
1108
+ }
1109
+ function ur(e) {
1110
+ const t = {
1111
+ fallbacks: {
1112
+ error: [],
1113
+ loading: [],
1114
+ notFound: []
1115
+ },
1116
+ routes: [],
1117
+ layouts: [],
1118
+ middlewares: [],
1119
+ policies: []
1120
+ };
1121
+ for (const [r, n] of Object.entries(e)) {
1122
+ const s = r.replace(/^\/src\/routes\//, "").replace(/^\.\/routes\//, "").replace(/\.tsx?$/, "").split("/"), o = s.at(-1);
1123
+ if (o === "@layout") {
1124
+ t.layouts.push({
1125
+ file: r,
1126
+ fileSegments: s.slice(0, -1),
1127
+ segments: R(s.slice(0, -1)),
1128
+ load: n
1129
+ });
1130
+ continue;
1131
+ }
1132
+ if (o === "@policy") {
1133
+ t.policies.push({
1134
+ file: r,
1135
+ fileSegments: s.slice(0, -1),
1136
+ segments: R(s.slice(0, -1)),
1137
+ load: n
1138
+ });
1139
+ continue;
1140
+ }
1141
+ if (o === "@middleware") {
1142
+ t.middlewares.push({
1143
+ file: r,
1144
+ fileSegments: s.slice(0, -1),
1145
+ segments: R(s.slice(0, -1)),
1146
+ load: n
1147
+ });
1148
+ continue;
1149
+ }
1150
+ if (o === "@loading") {
1151
+ t.fallbacks.loading.push({
1152
+ file: r,
1153
+ fileSegments: s.slice(0, -1),
1154
+ segments: R(s.slice(0, -1)),
1155
+ load: n
1156
+ });
1157
+ continue;
1158
+ }
1159
+ if (o === "@error") {
1160
+ t.fallbacks.error.push({
1161
+ file: r,
1162
+ fileSegments: s.slice(0, -1),
1163
+ segments: R(s.slice(0, -1)),
1164
+ load: n
1165
+ });
1166
+ continue;
1167
+ }
1168
+ if (o === "@not-found") {
1169
+ t.fallbacks.notFound.push({
1170
+ file: r,
1171
+ fileSegments: s.slice(0, -1),
1172
+ segments: R(s.slice(0, -1)),
1173
+ load: n
1174
+ });
1175
+ continue;
1176
+ }
1177
+ t.routes.push({
1178
+ file: r,
1179
+ fileSegments: s,
1180
+ segments: R(s),
1181
+ score: kr(s),
1182
+ load: n
1183
+ });
1184
+ }
1185
+ return lr(t.routes), t.routes.sort(mr), t.layouts.sort(
1186
+ (r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
1187
+ ), t.policies.sort(
1188
+ (r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
1189
+ ), t.middlewares.sort(
1190
+ (r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
1191
+ ), t.fallbacks.loading.sort(
1192
+ (r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
1193
+ ), t.fallbacks.error.sort(
1194
+ (r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
1195
+ ), t.fallbacks.notFound.sort(
1196
+ (r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
1197
+ ), t;
1198
+ }
1199
+ function lr(e) {
1200
+ const t = /* @__PURE__ */ new Map();
1201
+ for (const r of e) {
1202
+ const n = r.segments.findIndex(
1203
+ (i) => i.startsWith("*")
1204
+ );
1205
+ if (n !== -1 && n !== r.segments.length - 1)
1206
+ throw new Error(
1207
+ `Catchall route segment in "${r.file}" must be the final URL segment.`
1208
+ );
1209
+ const s = r.segments.map(fr).join("/"), o = t.get(s);
1210
+ if (o)
1211
+ throw new Error(
1212
+ `Ambiguous routes "${o.file}" and "${r.file}" have the same runtime shape and both match "${dr(r.segments)}".`
1213
+ );
1214
+ t.set(s, r);
1215
+ }
1216
+ }
1217
+ function fr(e) {
1218
+ return e.startsWith("*") ? "*" : e.startsWith(":") ? ":" : `=${e}`;
1219
+ }
1220
+ function dr(e) {
1221
+ return e.length === 0 ? "/" : `/${e.map((t) => t.startsWith(":") || t.startsWith("*") ? "example" : t).join("/")}`;
1222
+ }
1223
+ function mr(e, t) {
1224
+ const r = Math.max(e.segments.length, t.segments.length);
1225
+ for (let n = 0; n < r; n += 1) {
1226
+ const s = ve(t.segments[n]) - ve(e.segments[n]);
1227
+ if (s !== 0)
1228
+ return s;
1229
+ }
1230
+ return e.file.localeCompare(t.file);
1231
+ }
1232
+ function ve(e) {
1233
+ return e === void 0 ? 4 : e.startsWith("*") ? 1 : e.startsWith(":") ? 2 : 3;
1234
+ }
1235
+ async function qe(e, t, r = new Request(`http://demiurge.local${t}`), n, s = ae(), o = {}) {
1236
+ const i = o.documentContributions ?? !0, a = L(e.routes, t);
1237
+ if (!a)
1238
+ return {
1239
+ ...await ne(e, t, {
1240
+ documentContributions: i
1241
+ }),
1242
+ status: "not-found"
1243
+ };
1244
+ const c = e.layouts.filter(
1245
+ (f) => B(f.fileSegments, a.route.fileSegments)
1246
+ ), u = await a.route.load();
1247
+ if (!u.GET || u.GET.kind !== "page")
1248
+ return {
1249
+ ...await ne(e, t, {
1250
+ fallback: ce(
1251
+ e.fallbacks.notFound,
1252
+ a.route
1253
+ ),
1254
+ documentContributions: i,
1255
+ layouts: c
1256
+ }),
1257
+ status: "not-found"
1258
+ };
1259
+ const l = u.GET.layout === !1 ? [] : await Promise.all(c.map((f) => f.load())), d = new URL(r.url), m = {
1260
+ cache: s,
1261
+ path: a.path,
1262
+ pathname: t,
1263
+ request: r,
1264
+ search: d.searchParams,
1265
+ url: d
1266
+ };
1267
+ return {
1268
+ status: "ready",
1269
+ match: {
1270
+ data: u.GET.data && !n?.hasData ? await u.GET.data(m) : n?.data,
1271
+ error: await We(e, a.route),
1272
+ links: i ? await gt(
1273
+ [
1274
+ ...l.map((f) => f.links),
1275
+ u.links
1276
+ ],
1277
+ m
1278
+ ) : [],
1279
+ page: u.GET.view,
1280
+ layouts: l.map(
1281
+ (f) => f.default
1282
+ ),
1283
+ metadata: i ? b(
1284
+ ...l.map((f) => f.metadata),
1285
+ u.metadata
1286
+ ) : b(),
1287
+ path: a.path,
1288
+ pathname: t,
1289
+ render: u.GET.render,
1290
+ scripts: i ? await vt(
1291
+ [
1292
+ ...l.map((f) => f.scripts),
1293
+ u.scripts
1294
+ ],
1295
+ m
1296
+ ) : []
1297
+ }
1298
+ };
1299
+ }
1300
+ async function $s(e) {
1301
+ const t = ae(), r = [];
1302
+ for (const n of e.routes) {
1303
+ const s = await n.load();
1304
+ if (!s.GET || s.GET.kind !== "page")
1305
+ continue;
1306
+ if (s.GET.render.mode !== "static")
1307
+ throw new Error(
1308
+ `Page route "${n.file}" uses render mode "${s.GET.render.mode}" and cannot be emitted as static output. Set render: { mode: "static" } or deploy a runtime adapter.`
1309
+ );
1310
+ const o = Er(n.segments);
1311
+ if (br(n.segments).length === 0) {
1312
+ r.push({
1313
+ file: n.file,
1314
+ path: {},
1315
+ pattern: o,
1316
+ pathname: o
1317
+ });
1318
+ continue;
1319
+ }
1320
+ if (!s.paths)
1321
+ throw new Error(
1322
+ `Dynamic static route "${n.file}" must export paths for "${o}".`
1323
+ );
1324
+ const a = await s.paths({ cache: t });
1325
+ for (const c of a) {
1326
+ const u = Tr(n, o, c);
1327
+ r.push({
1328
+ file: n.file,
1329
+ path: u,
1330
+ pattern: o,
1331
+ pathname: xr(n.segments, u)
1332
+ });
1333
+ }
1334
+ }
1335
+ return r;
1336
+ }
1337
+ async function Is(e, t) {
1338
+ const r = L(e.routes, t);
1339
+ if (r)
1340
+ return await yr(
1341
+ ce(e.fallbacks.loading, r.route)
1342
+ );
1343
+ }
1344
+ async function hr(e, t) {
1345
+ let r;
1346
+ try {
1347
+ r = L(e.routes, t);
1348
+ } catch (n) {
1349
+ if (!(n instanceof fe)) throw n;
1350
+ return await le(
1351
+ e.fallbacks.error.find(
1352
+ (s) => s.fileSegments.length === 0
1353
+ )
1354
+ );
1355
+ }
1356
+ return r ? await We(e, r.route) : await pr(e, t);
1357
+ }
1358
+ async function We(e, t) {
1359
+ return await le(
1360
+ ce(e.fallbacks.error, t)
1361
+ );
1362
+ }
1363
+ async function pr(e, t) {
1364
+ return await le(
1365
+ Be(e.fallbacks.error, t)
1366
+ );
1367
+ }
1368
+ async function ne(e, t, r = {}) {
1369
+ const s = await (r.fallback ?? Be(e.fallbacks.notFound, t))?.load(), o = s?.default, i = r.documentContributions ?? !0;
1370
+ if (s?.layout === !1)
1371
+ return {
1372
+ layouts: [],
1373
+ metadata: i ? b(s.metadata) : b(),
1374
+ notFound: o,
1375
+ pathname: t
1376
+ };
1377
+ const a = r.layouts ?? gr(e, t);
1378
+ try {
1379
+ const c = await Promise.all(
1380
+ a.map((u) => u.load())
1381
+ );
1382
+ return {
1383
+ layouts: c.map(
1384
+ (u) => u.default
1385
+ ),
1386
+ metadata: i ? b(
1387
+ ...c.map((u) => u.metadata),
1388
+ s?.metadata
1389
+ ) : b(),
1390
+ notFound: o,
1391
+ pathname: t
1392
+ };
1393
+ } catch (c) {
1394
+ return r.onLayoutError?.(c), {
1395
+ layouts: [],
1396
+ metadata: i ? b(s?.metadata) : b(),
1397
+ notFound: o,
1398
+ pathname: t
1399
+ };
1400
+ }
1401
+ }
1402
+ function gr(e, t) {
1403
+ const r = _(t);
1404
+ return e.layouts.filter(
1405
+ (n) => !n.fileSegments.some(G) && ue(n.segments, r)
1406
+ );
1407
+ }
1408
+ function wr(e, t) {
1409
+ const r = _(t);
1410
+ return e.policies.filter(
1411
+ (n) => !n.fileSegments.some(G) && ue(n.segments, r)
1412
+ );
1413
+ }
1414
+ function ce(e, t) {
1415
+ for (let r = e.length - 1; r >= 0; r -= 1) {
1416
+ const n = e[r];
1417
+ if (B(n.fileSegments, t.fileSegments))
1418
+ return n;
1419
+ }
1420
+ }
1421
+ function Be(e, t) {
1422
+ const r = _(t);
1423
+ for (let n = e.length - 1; n >= 0; n -= 1) {
1424
+ const s = e[n];
1425
+ if (!s.fileSegments.some(G) && ue(s.segments, r))
1426
+ return s;
1427
+ }
1428
+ }
1429
+ function ue(e, t) {
1430
+ return e.every((r, n) => r.startsWith("*") ? t.length > n : r.startsWith(":") ? !!t[n] : t[n] === r);
1431
+ }
1432
+ async function yr(e) {
1433
+ return e ? (await e.load()).default : void 0;
1434
+ }
1435
+ async function le(e) {
1436
+ return e ? (await e.load()).default : void 0;
1437
+ }
1438
+ function L(e, t) {
1439
+ const r = _(t);
1440
+ for (const n of e) {
1441
+ const s = Sr(n.segments, r);
1442
+ if (s)
1443
+ return { route: n, path: s };
1444
+ }
1445
+ return null;
1446
+ }
1447
+ const Os = qe, Ls = L;
1448
+ function Sr(e, t) {
1449
+ const r = {};
1450
+ for (let n = 0; n < e.length; n += 1) {
1451
+ const s = e[n], o = t[n];
1452
+ if (s?.startsWith("*"))
1453
+ return r[s.slice(1)] = t.slice(n).join("/"), r;
1454
+ if (!o)
1455
+ return null;
1456
+ if (s.startsWith(":")) {
1457
+ r[s.slice(1)] = o;
1458
+ continue;
1459
+ }
1460
+ if (s !== o)
1461
+ return null;
1462
+ }
1463
+ return e.length === t.length ? r : null;
1464
+ }
1465
+ function Hs(e, t) {
1466
+ return e.every(
1467
+ (r, n) => t[n] === r
1468
+ );
1469
+ }
1470
+ function B(e, t) {
1471
+ return e.every(
1472
+ (r, n) => t[n] === r
1473
+ );
1474
+ }
1475
+ function R(e) {
1476
+ return e.flatMap((t) => G(t) ? [] : t === "index" ? [] : t.startsWith("[...") && t.endsWith("]") ? [`*${t.slice(4, -1)}`] : t.startsWith("[") && t.endsWith("]") ? [`:${t.slice(1, -1)}`] : [t]);
1477
+ }
1478
+ function G(e) {
1479
+ return e.startsWith("(") && e.endsWith(")");
1480
+ }
1481
+ function Er(e) {
1482
+ return e.length === 0 ? "/" : `/${e.map(Rr).join("/")}`;
1483
+ }
1484
+ function Rr(e) {
1485
+ return e.startsWith("*") ? `[...${e.slice(1)}]` : e.startsWith(":") ? `[${e.slice(1)}]` : e;
1486
+ }
1487
+ function br(e) {
1488
+ return e.flatMap((t) => t.startsWith(":") || t.startsWith("*") ? [t.slice(1)] : []);
1489
+ }
1490
+ function Tr(e, t, r) {
1491
+ const n = {};
1492
+ for (const s of e.segments) {
1493
+ if (!s.startsWith(":") && !s.startsWith("*"))
1494
+ continue;
1495
+ const o = s.slice(1), i = r[o];
1496
+ if (i === void 0)
1497
+ throw new Error(
1498
+ `Static paths for "${e.file}" must include "${o}" for "${t}".`
1499
+ );
1500
+ if (!vr(i))
1501
+ throw new Error(
1502
+ `Static path "${o}" for "${e.file}" must be a string, number, or boolean.`
1503
+ );
1504
+ n[o] = String(i);
1505
+ }
1506
+ return n;
1507
+ }
1508
+ function vr(e) {
1509
+ return typeof e == "string" || typeof e == "number" || typeof e == "boolean";
1510
+ }
1511
+ function xr(e, t) {
1512
+ return `/${e.map((n) => n.startsWith("*") ? t[n.slice(1)].split("/").filter(Boolean).map(encodeURIComponent).join("/") : n.startsWith(":") ? encodeURIComponent(t[n.slice(1)]) : encodeURIComponent(n)).filter(Boolean).join("/")}`;
1513
+ }
1514
+ function kr(e) {
1515
+ return R(e).reduce((t, r) => r.startsWith("*") ? t : r.startsWith(":") ? t + 1 : t + 2, 0);
1516
+ }
1517
+ function _(e) {
1518
+ return e.replace(/^\/|\/$/g, "").split("/").filter(Boolean).map((t) => {
1519
+ try {
1520
+ return decodeURIComponent(t);
1521
+ } catch (r) {
1522
+ throw new fe(e, { cause: r });
1523
+ }
1524
+ });
1525
+ }
1526
+ class fe extends URIError {
1527
+ pathname;
1528
+ constructor(t, r) {
1529
+ super(
1530
+ `Malformed percent encoding in URL pathname ${JSON.stringify(t)}.`,
1531
+ r
1532
+ ), this.name = "MalformedPathnameError", this.pathname = t;
1533
+ }
1534
+ }
1535
+ const x = "x-demiurge-navigation", Pr = "data", Cr = "data", Z = "error", xe = "not-found";
1536
+ function Ge(e) {
1537
+ return e.headers.get(x) === Pr;
1538
+ }
1539
+ function Ar(e) {
1540
+ return Response.json(
1541
+ { data: e, hasData: !0 },
1542
+ {
1543
+ headers: {
1544
+ "cache-control": "no-store",
1545
+ [x]: Cr,
1546
+ vary: x
1547
+ }
1548
+ }
1549
+ );
1550
+ }
1551
+ function U(e, t) {
1552
+ return e.headers.set("cache-control", "no-store"), e.headers.set(x, t), e.headers.append("vary", x), e;
1553
+ }
1554
+ function ke({ pathname: e }) {
1555
+ return /* @__PURE__ */ N("main", { children: [
1556
+ /* @__PURE__ */ $("h1", { children: "404" }),
1557
+ /* @__PURE__ */ N("p", { children: [
1558
+ "No route matched ",
1559
+ e,
1560
+ "."
1561
+ ] })
1562
+ ] });
1563
+ }
1564
+ function Pe({ status: e }) {
1565
+ return /* @__PURE__ */ N("main", { children: [
1566
+ /* @__PURE__ */ $("h1", { children: e }),
1567
+ /* @__PURE__ */ $("p", { children: "Something went wrong." })
1568
+ ] });
1569
+ }
1570
+ function Dr({ error: e, pathname: t, status: r }) {
1571
+ const { message: n, name: s, stack: o } = _e(e);
1572
+ return /* @__PURE__ */ N("main", { children: [
1573
+ /* @__PURE__ */ N("h1", { children: [
1574
+ r,
1575
+ " ",
1576
+ s,
1577
+ " at ",
1578
+ t
1579
+ ] }),
1580
+ /* @__PURE__ */ $("p", { children: n }),
1581
+ o ? /* @__PURE__ */ $("pre", { children: o }) : null
1582
+ ] });
1583
+ }
1584
+ function _e(e) {
1585
+ return e instanceof Error ? {
1586
+ message: e.message,
1587
+ name: e.name,
1588
+ stack: e.stack
1589
+ } : {
1590
+ message: typeof e == "string" ? e : String(e),
1591
+ name: "Error",
1592
+ stack: void 0
1593
+ };
1594
+ }
1595
+ const O = "{nonce}", Ve = {
1596
+ baseUri: ["'self'"],
1597
+ connectSrc: ["'self'"],
1598
+ defaultSrc: ["'self'"],
1599
+ fontSrc: ["'self'"],
1600
+ formAction: ["'self'"],
1601
+ frameAncestors: ["'none'"],
1602
+ imgSrc: ["'self'", "data:", "blob:"],
1603
+ objectSrc: ["'none'"],
1604
+ scriptSrc: [`'nonce-${O}'`, "'strict-dynamic'"],
1605
+ styleSrc: ["'self'", `'nonce-${O}'`],
1606
+ upgradeInsecureRequests: !0
1607
+ }, Nr = {
1608
+ ...Ve,
1609
+ scriptSrc: ["'self'"],
1610
+ styleSrc: ["'self'"]
1611
+ }, Ce = {
1612
+ contentTypeOptions: "nosniff",
1613
+ crossOriginOpenerPolicy: "same-origin",
1614
+ crossOriginResourcePolicy: "same-origin",
1615
+ permissionsPolicy: "camera=(), microphone=(), geolocation=(), payment=()",
1616
+ referrerPolicy: "strict-origin-when-cross-origin",
1617
+ strictTransportSecurity: {
1618
+ includeSubDomains: !1,
1619
+ maxAge: 31536e3,
1620
+ preload: !1
1621
+ }
1622
+ }, $r = {
1623
+ contentTypeOptions: "nosniff",
1624
+ crossOriginResourcePolicy: "same-origin",
1625
+ referrerPolicy: "strict-origin-when-cross-origin"
1626
+ }, P = {
1627
+ api(e = {}) {
1628
+ return A(
1629
+ {
1630
+ headers: $r
1631
+ },
1632
+ e
1633
+ );
1634
+ },
1635
+ preset(e, t = {}) {
1636
+ return e === "api" ? P.api(t) : e === "cross-origin-isolated" ? P.crossOriginIsolated(t) : e === "static" ? P.static(t) : P.strict(t);
1637
+ },
1638
+ static(e = {}) {
1639
+ return A(
1640
+ {
1641
+ csp: Nr,
1642
+ headers: Ce
1643
+ },
1644
+ e
1645
+ );
1646
+ },
1647
+ strict(e = {}) {
1648
+ return A(
1649
+ {
1650
+ csp: Ve,
1651
+ headers: Ce
1652
+ },
1653
+ e
1654
+ );
1655
+ },
1656
+ crossOriginIsolated(e = {}) {
1657
+ return A(
1658
+ P.strict({
1659
+ headers: {
1660
+ crossOriginEmbedderPolicy: "require-corp",
1661
+ crossOriginOpenerPolicy: "same-origin"
1662
+ }
1663
+ }),
1664
+ e
1665
+ );
1666
+ }
1667
+ };
1668
+ function Us(e) {
1669
+ return e;
1670
+ }
1671
+ function Ms(e) {
1672
+ return e;
1673
+ }
1674
+ function Ir(...e) {
1675
+ return e.reduce((t, r) => r ? A(t, r) : t, {});
1676
+ }
1677
+ function Ke(...e) {
1678
+ return e.reduce((t, r) => r ? {
1679
+ document: Ir(t.document, r.document),
1680
+ security: Or(t.security, r.security)
1681
+ } : t, {});
1682
+ }
1683
+ function Or(...e) {
1684
+ return e.reduce((t, r) => r ? {
1685
+ csrf: r.csrf ?? t.csrf,
1686
+ rateLimit: r.rateLimit ?? t.rateLimit,
1687
+ request: Qe(t.request, r.request)
1688
+ } : t, {});
1689
+ }
1690
+ async function js(e, t = "sha256") {
1691
+ const r = await globalThis.crypto.subtle.digest(
1692
+ Jr(t),
1693
+ new TextEncoder().encode(e)
1694
+ );
1695
+ return `'${t}-${Yr(new Uint8Array(r))}'`;
1696
+ }
1697
+ function Je(e, t = {}) {
1698
+ Gr(e);
1699
+ const r = new Headers(), n = e.csp !== !1 && e.csp ? qr(e.csp, t) : void 0, s = Fr(e.trustedTypes), o = e.trustedTypes ? e.trustedTypes.mode === "report-only" : !1;
1700
+ return y(
1701
+ r,
1702
+ "content-security-policy",
1703
+ q(n, o ? void 0 : s)
1704
+ ), y(
1705
+ r,
1706
+ "content-security-policy-report-only",
1707
+ o ? q(s, Xe(e.csp)) : void 0
1708
+ ), jr(r, e.headers, t), r;
1709
+ }
1710
+ function Ye(e) {
1711
+ return !e || !e.csp ? !1 : de(e.csp).some(
1712
+ ([, t]) => Array.isArray(t) && t.some((r) => r.includes(O))
1713
+ );
1714
+ }
1715
+ function Ze() {
1716
+ const e = new Uint8Array(16);
1717
+ return globalThis.crypto.getRandomValues(e), btoa(String.fromCharCode(...e));
1718
+ }
1719
+ function A(e, t) {
1720
+ return {
1721
+ csp: Hr(e.csp, t.csp),
1722
+ headers: Lr(e.headers, t.headers),
1723
+ trustedTypes: t.trustedTypes ?? e.trustedTypes
1724
+ };
1725
+ }
1726
+ function Lr(e, t) {
1727
+ const r = Qe(e, t);
1728
+ return !r || t?.reportingEndpoints === !1 || e?.reportingEndpoints && t?.reportingEndpoints && (r.reportingEndpoints = {
1729
+ ...e.reportingEndpoints,
1730
+ ...t.reportingEndpoints
1731
+ }), r;
1732
+ }
1733
+ function Qe(e, t) {
1734
+ return t ? {
1735
+ ...e ?? {},
1736
+ ...t
1737
+ } : e;
1738
+ }
1739
+ function Hr(e, t) {
1740
+ if (t === !1)
1741
+ return !1;
1742
+ if (!t)
1743
+ return e;
1744
+ if (!e)
1745
+ return t;
1746
+ const r = {
1747
+ ...e,
1748
+ ...t
1749
+ };
1750
+ for (const [n, s] of de(t)) {
1751
+ const o = e[n];
1752
+ n !== "reportUri" && Array.isArray(o) && Array.isArray(s) && Mr(r, n, Ur([...o, ...s]));
1753
+ }
1754
+ return e.reportUri && t.reportUri && (r.reportUri = [.../* @__PURE__ */ new Set([...e.reportUri, ...t.reportUri])]), r;
1755
+ }
1756
+ function Ur(e) {
1757
+ return [...new Set(e)];
1758
+ }
1759
+ function Mr(e, t, r) {
1760
+ t === "reportTo" || t === "reportUri" || t === "upgradeInsecureRequests" || (e[t] = r);
1761
+ }
1762
+ function jr(e, t, r) {
1763
+ t && (y(e, "referrer-policy", t.referrerPolicy), y(e, "x-content-type-options", t.contentTypeOptions), y(e, "cross-origin-opener-policy", t.crossOriginOpenerPolicy), y(e, "cross-origin-embedder-policy", t.crossOriginEmbedderPolicy), y(e, "cross-origin-resource-policy", t.crossOriginResourcePolicy), y(e, "permissions-policy", t.permissionsPolicy), y(
1764
+ e,
1765
+ "reporting-endpoints",
1766
+ Wr(t.reportingEndpoints)
1767
+ ), t.strictTransportSecurity && (!r.request || new URL(r.request.url).protocol === "https:") && e.set(
1768
+ "strict-transport-security",
1769
+ zr(t.strictTransportSecurity)
1770
+ ));
1771
+ }
1772
+ function Fr(e) {
1773
+ if (!e)
1774
+ return;
1775
+ const t = [];
1776
+ return e.requireFor?.includes("script") && t.push("require-trusted-types-for 'script'"), e.policies.length > 0 && t.push(`trusted-types ${e.policies.join(" ")}`), q(...t);
1777
+ }
1778
+ function q(...e) {
1779
+ const t = e.filter((r) => r);
1780
+ return t.length > 0 ? t.join("; ") : void 0;
1781
+ }
1782
+ function y(e, t, r) {
1783
+ r && e.set(t, r);
1784
+ }
1785
+ function zr(e) {
1786
+ const t = [`max-age=${e.maxAge}`];
1787
+ return e.includeSubDomains && t.push("includeSubDomains"), e.preload && t.push("preload"), t.join("; ");
1788
+ }
1789
+ function qr(e, t) {
1790
+ const r = [];
1791
+ for (const [s, o] of de(e)) {
1792
+ if (s === "reportTo" || s === "reportUri" || o === !1 || o === void 0)
1793
+ continue;
1794
+ const i = Kr(s);
1795
+ if (o === !0) {
1796
+ r.push(i);
1797
+ continue;
1798
+ }
1799
+ r.push(`${i} ${Vr(o, t).join(" ")}`);
1800
+ }
1801
+ const n = Xe(e);
1802
+ return n && r.push(n), r.join("; ");
1803
+ }
1804
+ function Xe(e) {
1805
+ if (!e)
1806
+ return;
1807
+ const t = [];
1808
+ return e.reportUri?.length && t.push(`report-uri ${e.reportUri.join(" ")}`), e.reportTo && t.push(`report-to ${e.reportTo}`), q(...t);
1809
+ }
1810
+ function Wr(e) {
1811
+ if (e)
1812
+ return Object.entries(e).sort(([t], [r]) => t.localeCompare(r)).map(([t, r]) => `${t}="${Br(r)}"`).join(", ");
1813
+ }
1814
+ function Br(e) {
1815
+ return e.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
1816
+ }
1817
+ function Gr(e) {
1818
+ const t = e.headers?.reportingEndpoints;
1819
+ if (t) {
1820
+ const n = Object.entries(t);
1821
+ if (n.length === 0)
1822
+ throw new Error("Demiurge Reporting-Endpoints requires at least one endpoint.");
1823
+ for (const [s, o] of n)
1824
+ Ae(s), De(o, `Reporting-Endpoints member ${JSON.stringify(s)}`);
1825
+ }
1826
+ const r = e.csp || void 0;
1827
+ if (r?.reportTo && (Ae(r.reportTo), !t || !(r.reportTo in t)))
1828
+ throw new Error(
1829
+ `Demiurge CSP report-to group ${JSON.stringify(r.reportTo)} is not defined in headers.reportingEndpoints.`
1830
+ );
1831
+ for (const n of r?.reportUri ?? [])
1832
+ De(n, "CSP report-uri target");
1833
+ }
1834
+ function Ae(e) {
1835
+ if (!/^(?:[a-z]|\*)[a-z0-9_.*-]*$/.test(e))
1836
+ throw new Error(
1837
+ `Invalid reporting endpoint name ${JSON.stringify(e)}. Use a lowercase Structured Field key.`
1838
+ );
1839
+ }
1840
+ function De(e, t) {
1841
+ if (!_r(e) || /[\s,;"\\]/.test(e) || !e.startsWith("/") && !e.startsWith("https://"))
1842
+ throw new Error(`${t} must be a same-origin path or an HTTPS URL.`);
1843
+ if (e.startsWith("//"))
1844
+ throw new Error(`${t} must not be a scheme-relative URL.`);
1845
+ let r;
1846
+ try {
1847
+ r = new URL(e, "https://demiurge.invalid");
1848
+ } catch {
1849
+ throw new Error(`${t} must be a valid URI reference.`);
1850
+ }
1851
+ if (r.username || r.password || r.hash)
1852
+ throw new Error(`${t} must not contain credentials or a fragment.`);
1853
+ }
1854
+ function _r(e) {
1855
+ return /^[\x20-\x7e]+$/.test(e);
1856
+ }
1857
+ function de(e) {
1858
+ return Object.entries(e);
1859
+ }
1860
+ function Vr(e, t) {
1861
+ return e.map((r) => {
1862
+ if (!r.includes(O))
1863
+ return r;
1864
+ if (!t.nonce)
1865
+ throw new Error("Demiurge security policy requires a CSP nonce.");
1866
+ return r.replaceAll(O, t.nonce);
1867
+ });
1868
+ }
1869
+ function Kr(e) {
1870
+ return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
1871
+ }
1872
+ function Jr(e) {
1873
+ return e === "sha384" ? "SHA-384" : e === "sha512" ? "SHA-512" : "SHA-256";
1874
+ }
1875
+ function Yr(e) {
1876
+ let t = "";
1877
+ for (const r of e)
1878
+ t += String.fromCharCode(r);
1879
+ return typeof btoa == "function" ? btoa(t) : Buffer.from(t, "binary").toString("base64");
1880
+ }
1881
+ function et(e, t, r = {}) {
1882
+ Qr(e);
1883
+ const n = t.request.headers.get("origin"), s = new Headers();
1884
+ if (e.origins !== "*" && tt(s, "Origin"), !n)
1885
+ return s;
1886
+ const o = Xr(e, n);
1887
+ if (!o)
1888
+ return s;
1889
+ if (s.set("access-control-allow-origin", o), e.credentials && s.set("access-control-allow-credentials", "true"), e.exposeHeaders?.length && s.set("access-control-expose-headers", e.exposeHeaders.join(", ")), r.preflight) {
1890
+ s.set("access-control-allow-methods", r.methods.join(", "));
1891
+ const i = t.request.headers.get(
1892
+ "access-control-request-headers"
1893
+ ), a = e.headers?.join(", ") ?? i;
1894
+ a && s.set("access-control-allow-headers", a), e.maxAge !== void 0 && s.set("access-control-max-age", String(e.maxAge));
1895
+ }
1896
+ return s;
1897
+ }
1898
+ function F(e, t, r) {
1899
+ if (!t)
1900
+ return e;
1901
+ const n = new Headers(e.headers);
1902
+ return en(n, et(t, { request: r })), new Response(e.body, {
1903
+ headers: n,
1904
+ status: e.status,
1905
+ statusText: e.statusText
1906
+ });
1907
+ }
1908
+ function Zr(e, t) {
1909
+ const r = t.headers.get("access-control-request-method"), n = tn(r);
1910
+ if (!n)
1911
+ return null;
1912
+ const s = rt(e, n);
1913
+ if (!s?.cors)
1914
+ return null;
1915
+ const o = s.cors.methods ?? rn(e);
1916
+ return o.includes(n) ? new Response(null, {
1917
+ headers: et(
1918
+ s.cors,
1919
+ { request: t },
1920
+ {
1921
+ methods: o,
1922
+ preflight: !0
1923
+ }
1924
+ ),
1925
+ status: 204
1926
+ }) : null;
1927
+ }
1928
+ function Qr(e) {
1929
+ if (e.credentials && e.origins === "*")
1930
+ throw new Error(
1931
+ "Demiurge CORS policy cannot use wildcard origins with credentials."
1932
+ );
1933
+ if (e.credentials && (e.headers?.includes("*") || e.exposeHeaders?.includes("*")))
1934
+ throw new Error(
1935
+ "Demiurge credentialed CORS policy must list allowed and exposed headers explicitly."
1936
+ );
1937
+ if (e.maxAge !== void 0 && (!Number.isSafeInteger(e.maxAge) || e.maxAge < 0))
1938
+ throw new Error(
1939
+ "Demiurge CORS maxAge must be a non-negative integer number of seconds."
1940
+ );
1941
+ }
1942
+ function Xr(e, t) {
1943
+ return e.origins === "*" ? "*" : e.origins.includes(t) ? t : null;
1944
+ }
1945
+ function en(e, t) {
1946
+ t.forEach((r, n) => {
1947
+ if (n === "vary" && e.has("vary")) {
1948
+ for (const s of r.split(","))
1949
+ tt(e, s.trim());
1950
+ return;
1951
+ }
1952
+ e.set(n, r);
1953
+ });
1954
+ }
1955
+ function tt(e, t) {
1956
+ if (!t)
1957
+ return;
1958
+ const r = e.get("vary")?.split(",").map((n) => n.trim()).filter(Boolean) ?? [];
1959
+ r.some((n) => n.toLowerCase() === t.toLowerCase()) || e.set("vary", [...r, t].join(", "));
1960
+ }
1961
+ function tn(e) {
1962
+ if (!e)
1963
+ return null;
1964
+ const t = e.toUpperCase();
1965
+ return nn(t) ? t : null;
1966
+ }
1967
+ function rt(e, t) {
1968
+ return t === "HEAD" ? e.HEAD ?? Ne(e.GET) : Ne(e[t]);
1969
+ }
1970
+ function Ne(e) {
1971
+ return e?.kind === "page" ? void 0 : e;
1972
+ }
1973
+ function rn(e) {
1974
+ return [
1975
+ "GET",
1976
+ "POST",
1977
+ "PUT",
1978
+ "PATCH",
1979
+ "DELETE",
1980
+ "OPTIONS",
1981
+ "HEAD"
1982
+ ].filter((t) => rt(e, t));
1983
+ }
1984
+ function nn(e) {
1985
+ return e === "GET" || e === "POST" || e === "PUT" || e === "PATCH" || e === "DELETE" || e === "OPTIONS" || e === "HEAD";
1986
+ }
1987
+ const sn = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]), on = /^[!#$%&'*+\-.^_`|~A-Za-z0-9]+$/;
1988
+ function an() {
1989
+ const e = new Uint8Array(32);
1990
+ return globalThis.crypto.getRandomValues(e), btoa(String.fromCharCode(...e)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
1991
+ }
1992
+ function cn(e, t = {}) {
1993
+ const r = t.cookie ?? "csrf-token";
1994
+ if (!on.test(r))
1995
+ throw new Error("Demiurge CSRF cookie name is invalid.");
1996
+ if (!e)
1997
+ throw new Error("Demiurge CSRF token must not be empty.");
1998
+ const n = [
1999
+ `${r}=${encodeURIComponent(e)}`,
2000
+ "Path=/",
2001
+ "SameSite=Lax"
2002
+ ];
2003
+ return (t.secure ?? !0) && n.push("Secure"), n.join("; ");
2004
+ }
2005
+ function Fs(e = {}) {
2006
+ const t = an();
2007
+ return {
2008
+ cookie: cn(t, e),
2009
+ token: t
2010
+ };
2011
+ }
2012
+ function un(e, t) {
2013
+ if (!sn.has(t.method.toUpperCase()) || e === !1)
2014
+ return null;
2015
+ const r = t.headers.get("cookie");
2016
+ if (e === void 0 && !r?.trim())
2017
+ return null;
2018
+ const n = fn(e ?? !0), o = ln(r).get(n.cookie), i = t.headers.get(n.header);
2019
+ return !o || !i || !mn(o, i) ? new Response("Invalid CSRF token.", {
2020
+ status: 403
2021
+ }) : null;
2022
+ }
2023
+ function ln(e) {
2024
+ const t = /* @__PURE__ */ new Map();
2025
+ if (!e)
2026
+ return t;
2027
+ for (const r of e.split(";")) {
2028
+ const n = r.indexOf("=");
2029
+ if (n === -1)
2030
+ continue;
2031
+ const s = r.slice(0, n).trim(), o = r.slice(n + 1).trim();
2032
+ s && t.set(s, dn(o));
2033
+ }
2034
+ return t;
2035
+ }
2036
+ function fn(e) {
2037
+ return e === !0 ? {
2038
+ cookie: "csrf-token",
2039
+ header: "x-csrf-token"
2040
+ } : {
2041
+ cookie: e.cookie ?? "csrf-token",
2042
+ header: e.header ?? "x-csrf-token"
2043
+ };
2044
+ }
2045
+ function dn(e) {
2046
+ try {
2047
+ return decodeURIComponent(e);
2048
+ } catch {
2049
+ return e;
2050
+ }
2051
+ }
2052
+ function mn(e, t) {
2053
+ let r = e.length ^ t.length;
2054
+ const n = Math.max(e.length, t.length);
2055
+ for (let s = 0; s < n; s += 1)
2056
+ r |= e.charCodeAt(s) ^ t.charCodeAt(s);
2057
+ return r === 0;
2058
+ }
2059
+ const hn = {
2060
+ h: 3600 * 1e3,
2061
+ m: 60 * 1e3,
2062
+ s: 1e3
2063
+ }, pn = 1e4;
2064
+ function nt(e = {}) {
2065
+ const t = e.maximumEntries ?? pn;
2066
+ if (!Number.isSafeInteger(t) || t <= 0)
2067
+ throw new Error(
2068
+ "Demiurge rate limit maximumEntries must be a positive integer."
2069
+ );
2070
+ const r = /* @__PURE__ */ new Map();
2071
+ let n = Number.POSITIVE_INFINITY;
2072
+ return {
2073
+ increment(s, o, i) {
2074
+ i >= n && (gn(r, i), n = wn(r));
2075
+ const a = r.get(s);
2076
+ if (!a || a.resetAt <= i) {
2077
+ const c = {
2078
+ count: 1,
2079
+ resetAt: i + o
2080
+ };
2081
+ return !a && r.size >= t && yn(r), r.set(s, c), n = Math.min(n, c.resetAt), c;
2082
+ }
2083
+ return a.count += 1, a;
2084
+ }
2085
+ };
2086
+ }
2087
+ function gn(e, t) {
2088
+ for (const [r, n] of e)
2089
+ n.resetAt <= t && e.delete(r);
2090
+ }
2091
+ function wn(e) {
2092
+ let t = Number.POSITIVE_INFINITY;
2093
+ for (const r of e.values())
2094
+ t = Math.min(t, r.resetAt);
2095
+ return t;
2096
+ }
2097
+ function yn(e) {
2098
+ const t = e.keys().next().value;
2099
+ t !== void 0 && e.delete(t);
2100
+ }
2101
+ function Sn(e, t, r, n = Date.now()) {
2102
+ if (!e)
2103
+ return null;
2104
+ En(e);
2105
+ const s = st(e.window), o = Rn(e, t), i = r.increment(o, s, n), a = Math.max(0, e.limit - i.count), c = new Headers({
2106
+ "retry-after": String(Math.ceil(Math.max(0, i.resetAt - n) / 1e3)),
2107
+ "x-ratelimit-limit": String(e.limit),
2108
+ "x-ratelimit-remaining": String(a),
2109
+ "x-ratelimit-reset": String(Math.ceil(i.resetAt / 1e3))
2110
+ });
2111
+ return i.count > e.limit ? new Response("Rate limit exceeded.", {
2112
+ headers: c,
2113
+ status: 429
2114
+ }) : null;
2115
+ }
2116
+ function st(e) {
2117
+ if (typeof e == "number") {
2118
+ if (!Number.isSafeInteger(e) || e <= 0)
2119
+ throw new Error("Demiurge rate limit window must be a positive integer.");
2120
+ return e;
2121
+ }
2122
+ const t = /^(\d+)(s|m|h)$/i.exec(e.trim());
2123
+ if (!t)
2124
+ throw new Error("Demiurge rate limit window must use an s/m/h suffix.");
2125
+ const r = Number(t[1]), n = t[2].toLowerCase(), s = r * hn[n];
2126
+ if (!Number.isSafeInteger(s))
2127
+ throw new Error("Demiurge rate limit window is too large.");
2128
+ return s;
2129
+ }
2130
+ function En(e) {
2131
+ if (!Number.isSafeInteger(e.limit) || e.limit <= 0)
2132
+ throw new Error("Demiurge rate limit limit must be a positive integer.");
2133
+ st(e.window);
2134
+ }
2135
+ function Rn(e, t) {
2136
+ return `${bn(e.key)}:${Tn(e.key, t)}`;
2137
+ }
2138
+ function bn(e) {
2139
+ return typeof e == "string" ? e : `header:${e.header.toLowerCase()}`;
2140
+ }
2141
+ function Tn(e, t) {
2142
+ return e === "ip" ? vn(t) : t.headers.get(e.header) ?? "missing";
2143
+ }
2144
+ function vn(e) {
2145
+ return mt(e)?.clientIp ?? "unknown";
2146
+ }
2147
+ const xn = {
2148
+ b: 1,
2149
+ gb: 1024 ** 3,
2150
+ kb: 1024,
2151
+ mb: 1024 ** 2
2152
+ };
2153
+ function kn(e, t, r) {
2154
+ const n = Cn(e, r);
2155
+ if (n)
2156
+ return n;
2157
+ if (e?.maxBodySize === void 0)
2158
+ return null;
2159
+ const s = t.headers.get("content-length");
2160
+ if (!s)
2161
+ return null;
2162
+ const o = An(s);
2163
+ if (o === null)
2164
+ return new Response("Invalid Content-Length.", {
2165
+ status: 400
2166
+ });
2167
+ const i = ot(e.maxBodySize);
2168
+ return o > i ? new Response("Request body too large.", {
2169
+ status: 413
2170
+ }) : null;
2171
+ }
2172
+ class D extends Error {
2173
+ constructor() {
2174
+ super("Demiurge request body exceeded maxBodySize while being read."), this.name = "RequestBodyTooLargeError";
2175
+ }
2176
+ }
2177
+ function Pn(e, t) {
2178
+ if (e?.maxBodySize === void 0 || t.body === null)
2179
+ return t;
2180
+ const r = ot(e.maxBodySize), n = t.body.getReader();
2181
+ let s = 0;
2182
+ const o = new ReadableStream({
2183
+ async pull(a) {
2184
+ const c = await n.read();
2185
+ if (c.done) {
2186
+ a.close();
2187
+ return;
2188
+ }
2189
+ if (s += c.value.byteLength, s > r) {
2190
+ const u = new D();
2191
+ a.error(u);
2192
+ try {
2193
+ await n.cancel(u);
2194
+ } catch {
2195
+ }
2196
+ return;
2197
+ }
2198
+ a.enqueue(c.value);
2199
+ },
2200
+ async cancel(a) {
2201
+ try {
2202
+ await n.cancel(a);
2203
+ } catch {
2204
+ }
2205
+ }
2206
+ }), i = new Request(t, {
2207
+ body: o,
2208
+ duplex: "half"
2209
+ });
2210
+ return ht(t, i), i;
2211
+ }
2212
+ function M() {
2213
+ return new Response("Request body too large.", { status: 413 });
2214
+ }
2215
+ function Cn(e, t) {
2216
+ return !e?.allowedMethods || Dn(e.allowedMethods, t) ? null : new Response(null, {
2217
+ headers: {
2218
+ allow: Nn(e.allowedMethods)
2219
+ },
2220
+ status: 405
2221
+ });
2222
+ }
2223
+ function ot(e) {
2224
+ if (typeof e == "number") {
2225
+ if (!Number.isSafeInteger(e) || e < 0)
2226
+ throw new Error("Demiurge request maxBodySize must be a non-negative integer.");
2227
+ return e;
2228
+ }
2229
+ const t = /^(\d+)(b|kb|mb|gb)$/i.exec(e.trim());
2230
+ if (!t)
2231
+ throw new Error(
2232
+ "Demiurge request maxBodySize must use bytes or a b/kb/mb/gb suffix."
2233
+ );
2234
+ const r = Number(t[1]), n = t[2].toLowerCase(), s = r * xn[n];
2235
+ if (!Number.isSafeInteger(s))
2236
+ throw new Error("Demiurge request maxBodySize is too large.");
2237
+ return s;
2238
+ }
2239
+ function An(e) {
2240
+ if (!/^\d+$/.test(e))
2241
+ return null;
2242
+ const t = Number(e);
2243
+ return Number.isSafeInteger(t) ? t : null;
2244
+ }
2245
+ function Dn(e, t) {
2246
+ return e.includes(t) || t === "HEAD" && e.includes("GET");
2247
+ }
2248
+ function Nn(e) {
2249
+ const t = [...e];
2250
+ return t.includes("GET") && !t.includes("HEAD") && t.push("HEAD"), t.join(", ");
2251
+ }
2252
+ const $n = ["text/html", "application/xhtml+xml"];
2253
+ function it(e) {
2254
+ return In(e.headers.get("accept"));
2255
+ }
2256
+ function In(e) {
2257
+ return e ? On(e).some(
2258
+ (t) => t.quality > 0 && $n.includes(t.type)
2259
+ ) : !1;
2260
+ }
2261
+ function On(e) {
2262
+ return e.split(",").flatMap((t) => {
2263
+ const [r, ...n] = t.split(";"), s = r.trim().toLowerCase();
2264
+ return s ? [
2265
+ {
2266
+ quality: Ln(n),
2267
+ type: s
2268
+ }
2269
+ ] : [];
2270
+ });
2271
+ }
2272
+ function Ln(e) {
2273
+ for (const t of e) {
2274
+ const [r, n] = t.split("=");
2275
+ if (r?.trim().toLowerCase() !== "q")
2276
+ continue;
2277
+ const s = Number.parseFloat(n ?? "");
2278
+ return Number.isNaN(s) ? 1 : s;
2279
+ }
2280
+ return 1;
2281
+ }
2282
+ const Hn = "application/problem+json";
2283
+ function Un({
2284
+ detail: e,
2285
+ instance: t,
2286
+ status: r,
2287
+ title: n,
2288
+ type: s = "about:blank",
2289
+ ...o
2290
+ }) {
2291
+ return {
2292
+ type: s,
2293
+ title: n,
2294
+ status: r,
2295
+ ...e === void 0 ? {} : { detail: e },
2296
+ ...t === void 0 ? {} : { instance: t },
2297
+ ...o
2298
+ };
2299
+ }
2300
+ function W(e, t) {
2301
+ const r = new Headers(t?.headers);
2302
+ return r.set("content-type", `${Hn}; charset=utf-8`), new Response(JSON.stringify(Un(e)), {
2303
+ ...t,
2304
+ headers: r,
2305
+ status: e.status
2306
+ });
2307
+ }
2308
+ const Mn = "Internal Server Error";
2309
+ function at(e) {
2310
+ return e === !0 && process.env.NODE_ENV !== "production";
2311
+ }
2312
+ async function z(e, t, r, n, s = {}) {
2313
+ s.onError?.(r, n);
2314
+ const o = new URL(t.url);
2315
+ return n === "page" || n === "middleware" && it(t) ? await Fn(e, o, r, s) : jn(o, r, s);
2316
+ }
2317
+ function jn(e, t, r = {}) {
2318
+ if (ie(t))
2319
+ return W(
2320
+ {
2321
+ ...t.extensions,
2322
+ detail: t.detail,
2323
+ instance: `${e.pathname}${e.search}`,
2324
+ status: t.status,
2325
+ title: t.title,
2326
+ type: t.type
2327
+ },
2328
+ { headers: t.headers }
2329
+ );
2330
+ const { message: n } = _e(t);
2331
+ return W({
2332
+ // `detail` carries the thrown message, so it is dev only for the same
2333
+ // reason the stack is.
2334
+ ...at(r.dev) ? { detail: n } : {},
2335
+ instance: `${e.pathname}${e.search}`,
2336
+ status: 500,
2337
+ title: "Internal Server Error"
2338
+ });
2339
+ }
2340
+ async function Fn(e, t, r, n) {
2341
+ const s = ct(r);
2342
+ try {
2343
+ const o = await qn(
2344
+ e,
2345
+ t.pathname,
2346
+ r,
2347
+ n
2348
+ ), i = ie(r) ? new Headers(r.headers) : new Headers();
2349
+ return i.set("content-type", "text/html; charset=utf-8"), new Response(await n.transformDocument?.(o) ?? o, {
2350
+ headers: i,
2351
+ status: s
2352
+ });
2353
+ } catch (o) {
2354
+ return n.onError?.(o, "page"), zn();
2355
+ }
2356
+ }
2357
+ function zn() {
2358
+ return new Response(Mn, {
2359
+ headers: { "content-type": "text/plain; charset=utf-8" },
2360
+ status: 500
2361
+ });
2362
+ }
2363
+ async function qn(e, t, r, n) {
2364
+ const s = await Wn(e, t, n), o = He(
2365
+ ee(s, { error: r, pathname: t, status: ct(r) })
2366
+ );
2367
+ return Le({
2368
+ body: { data: void 0, html: o, navigation: n.navigation },
2369
+ entrySrc: n.clientEntry,
2370
+ lang: n.lang,
2371
+ nonce: n.nonce,
2372
+ styles: n.styles,
2373
+ title: n.title
2374
+ });
2375
+ }
2376
+ function ct(e) {
2377
+ return ie(e) ? e.status : 500;
2378
+ }
2379
+ async function Wn(e, t, r) {
2380
+ if (at(r.dev))
2381
+ return Dr;
2382
+ try {
2383
+ return await hr(e, t) ?? Pe;
2384
+ } catch {
2385
+ return Pe;
2386
+ }
2387
+ }
2388
+ function Bn(e) {
2389
+ return W({
2390
+ instance: `${e.pathname}${e.search}`,
2391
+ status: 404,
2392
+ title: "Not Found"
2393
+ });
2394
+ }
2395
+ async function se(e, t, r = {}) {
2396
+ const n = new URL(t.url);
2397
+ if (!it(t))
2398
+ return Bn(n);
2399
+ const s = await ne(e, n.pathname, {
2400
+ onLayoutError: (u) => r.onError?.(u, "page")
2401
+ }), o = await Gn(e, n.pathname), i = r.nonce ?? (Ye(o) ? Ze() : void 0), a = _n(s, { ...r, nonce: i }), c = Je(o ?? {}, {
2402
+ nonce: i,
2403
+ request: t
2404
+ });
2405
+ return c.set("content-type", "text/html; charset=utf-8"), new Response(
2406
+ await r.transformDocument?.(a) ?? a,
2407
+ {
2408
+ headers: c,
2409
+ status: 404
2410
+ }
2411
+ );
2412
+ }
2413
+ async function Gn(e, t) {
2414
+ const r = await Promise.all(
2415
+ wr(e, t).map((n) => n.load())
2416
+ );
2417
+ return Ke(...r.map((n) => n.policy)).document;
2418
+ }
2419
+ function _n(e, t = {}) {
2420
+ const r = e.notFound ?? ke;
2421
+ try {
2422
+ return Q(e, r, e.layouts, t);
2423
+ } catch (n) {
2424
+ t.onError?.(n, "page");
2425
+ }
2426
+ try {
2427
+ return Q(e, r, [], t);
2428
+ } catch (n) {
2429
+ t.onError?.(n, "page");
2430
+ }
2431
+ return Q(e, ke, [], t);
2432
+ }
2433
+ function Q(e, t, r, n) {
2434
+ const s = r.reduceRight(
2435
+ (o, i) => ee(i, {
2436
+ children: o,
2437
+ path: {},
2438
+ pathname: e.pathname
2439
+ }),
2440
+ ee(t, { pathname: e.pathname })
2441
+ );
2442
+ return Le({
2443
+ body: {
2444
+ data: void 0,
2445
+ fallback: "not-found",
2446
+ html: He(s),
2447
+ navigation: n.navigation
2448
+ },
2449
+ entrySrc: n.clientEntry,
2450
+ lang: n.lang,
2451
+ metadata: e.metadata,
2452
+ nonce: n.nonce,
2453
+ styles: n.styles,
2454
+ title: n.title
2455
+ });
2456
+ }
2457
+ const ut = [
2458
+ "GET",
2459
+ "POST",
2460
+ "PUT",
2461
+ "PATCH",
2462
+ "DELETE",
2463
+ "OPTIONS",
2464
+ "HEAD"
2465
+ ], lt = nt();
2466
+ function zs(e) {
2467
+ const t = ur(e.routes), r = e.rateLimitStore ?? nt();
2468
+ return e.cacheStore && je(e.cacheStore.namespace), async function(s) {
2469
+ return await Vn(t, s, {
2470
+ cacheStore: e.cacheStore,
2471
+ onError: e.onError,
2472
+ rateLimitStore: r,
2473
+ renderPage: e.renderPage,
2474
+ ssr: e.ssr
2475
+ });
2476
+ };
2477
+ }
2478
+ async function Vn(e, t, r = {
2479
+ rateLimitStore: lt
2480
+ }) {
2481
+ const n = new URL(t.url), s = Yn(n, r), o = Ge(t);
2482
+ let i;
2483
+ try {
2484
+ i = L(e.routes, n.pathname);
2485
+ } catch (a) {
2486
+ if (!(a instanceof fe))
2487
+ throw a;
2488
+ const c = W({
2489
+ instance: `${n.pathname}${n.search}`,
2490
+ status: 400,
2491
+ title: "Bad Request"
2492
+ });
2493
+ return o ? U(c, Z) : c;
2494
+ }
2495
+ if (!i)
2496
+ try {
2497
+ const a = await se(
2498
+ e,
2499
+ t,
2500
+ s
2501
+ );
2502
+ return o ? U(a, xe) : a;
2503
+ } catch (a) {
2504
+ return s.onError(a, "page"), new Response("Not Found", {
2505
+ headers: { "content-type": "text/plain; charset=utf-8" },
2506
+ status: 404
2507
+ });
2508
+ }
2509
+ try {
2510
+ const a = await Kn(
2511
+ e,
2512
+ t,
2513
+ n,
2514
+ i,
2515
+ r,
2516
+ s
2517
+ );
2518
+ return o && !a.headers.has(x) ? U(
2519
+ a,
2520
+ a.status === 404 ? xe : Z
2521
+ ) : a;
2522
+ } catch (a) {
2523
+ const c = await z(
2524
+ e,
2525
+ t,
2526
+ a,
2527
+ "middleware",
2528
+ s
2529
+ );
2530
+ return o ? U(c, Z) : c;
2531
+ }
2532
+ }
2533
+ async function Kn(e, t, r, n, s, o) {
2534
+ const i = await n.route.load();
2535
+ if (t.method.toUpperCase() === "OPTIONS") {
2536
+ const h = Zr(i, t);
2537
+ if (h)
2538
+ return h;
2539
+ }
2540
+ const a = es(t.method);
2541
+ if (!a)
2542
+ return Oe(i);
2543
+ const c = ts(i, a);
2544
+ if (!c)
2545
+ return Oe(i);
2546
+ const u = await Qn(
2547
+ e,
2548
+ n.route,
2549
+ i,
2550
+ c
2551
+ ), l = u.security, d = un(l?.csrf, t);
2552
+ if (d)
2553
+ return F(d, X(c), t);
2554
+ const m = Sn(
2555
+ l?.rateLimit,
2556
+ t,
2557
+ s.rateLimitStore ?? lt
2558
+ );
2559
+ if (m)
2560
+ return F(
2561
+ m,
2562
+ X(c),
2563
+ t
2564
+ );
2565
+ const f = kn(
2566
+ l?.request,
2567
+ t,
2568
+ a
2569
+ );
2570
+ if (f)
2571
+ return F(
2572
+ f,
2573
+ X(c),
2574
+ t
2575
+ );
2576
+ if (t = Pn(l?.request, t), c.kind === "page") {
2577
+ const h = {
2578
+ path: n.path,
2579
+ pathname: r.pathname,
2580
+ request: t,
2581
+ search: r.searchParams,
2582
+ url: r
2583
+ }, me = await $e(
2584
+ e,
2585
+ n.route
2586
+ ), v = Ye(u.document) ? Ze() : void 0;
2587
+ let E;
2588
+ try {
2589
+ E = await Ie(me, h, async () => {
2590
+ try {
2591
+ const p = await qe(
2592
+ e,
2593
+ r.pathname,
2594
+ t,
2595
+ void 0,
2596
+ Jn(s.cacheStore)
2597
+ );
2598
+ if (p.status !== "ready")
2599
+ return await se(e, t, {
2600
+ ...o,
2601
+ nonce: v
2602
+ });
2603
+ if (Ge(t))
2604
+ return Ar(p.match.data);
2605
+ if (p.match.render.mode === "streaming" && !s.renderPage)
2606
+ throw new Error(
2607
+ "Streaming page routes require an adapter renderer. Pass renderNodePageResponse from @demiurgejs/core/node as createRequestHandler({ renderPage })."
2608
+ );
2609
+ return await (s.renderPage ?? pt)(p.match, {
2610
+ ...s.ssr,
2611
+ nonce: v,
2612
+ onStreamError: (dt) => {
2613
+ s.onError?.(dt, {
2614
+ pathname: r.pathname,
2615
+ site: "page"
2616
+ });
2617
+ },
2618
+ signal: t.signal
2619
+ });
2620
+ } catch (p) {
2621
+ return p instanceof D ? M() : await z(e, t, p, "page", {
2622
+ ...o,
2623
+ nonce: v
2624
+ });
2625
+ }
2626
+ });
2627
+ } catch (p) {
2628
+ if (!(p instanceof D))
2629
+ throw p;
2630
+ E = M();
2631
+ }
2632
+ const ft = Je(u.document ?? {}, {
2633
+ nonce: v,
2634
+ request: t
2635
+ });
2636
+ for (const [p, he] of ft)
2637
+ E.headers.set(p, he);
2638
+ return v && E.headers.set("cache-control", "private, no-store"), a === "HEAD" ? (await E.body?.cancel(), new Response(null, {
2639
+ headers: E.headers,
2640
+ status: E.status
2641
+ })) : E;
2642
+ }
2643
+ const k = {
2644
+ path: n.path,
2645
+ pathname: r.pathname,
2646
+ request: t,
2647
+ search: r.searchParams,
2648
+ url: r
2649
+ }, H = await $e(
2650
+ e,
2651
+ n.route
2652
+ );
2653
+ let g;
2654
+ try {
2655
+ g = await Ie(H, k, async () => {
2656
+ try {
2657
+ return c.kind === "not-found" && c.body === void 0 ? Zn(
2658
+ await se(e, t, o),
2659
+ c.init
2660
+ ) : await $t(c, k);
2661
+ } catch (h) {
2662
+ return h instanceof D ? M() : await z(
2663
+ e,
2664
+ t,
2665
+ h,
2666
+ "route",
2667
+ o
2668
+ );
2669
+ }
2670
+ });
2671
+ } catch (h) {
2672
+ if (!(h instanceof D))
2673
+ throw h;
2674
+ g = M();
2675
+ }
2676
+ try {
2677
+ return Xn(g, c, t, a);
2678
+ } catch (h) {
2679
+ return await z(
2680
+ e,
2681
+ t,
2682
+ h,
2683
+ "route",
2684
+ o
2685
+ );
2686
+ }
2687
+ }
2688
+ function Jn(e) {
2689
+ return e ? Me(e) : ae();
2690
+ }
2691
+ function Yn(e, t) {
2692
+ return {
2693
+ ...t.ssr,
2694
+ dev: t.dev,
2695
+ onError: (r, n) => {
2696
+ t.onError?.(r, { pathname: e.pathname, site: n });
2697
+ },
2698
+ transformDocument: t.transformDocument
2699
+ };
2700
+ }
2701
+ function Zn(e, t) {
2702
+ if (!t)
2703
+ return e;
2704
+ const r = new Headers(e.headers), n = new Headers(t.headers);
2705
+ for (const [s, o] of n)
2706
+ s !== "set-cookie" && r.set(s, o);
2707
+ for (const s of n.getSetCookie())
2708
+ r.append("set-cookie", s);
2709
+ return new Response(e.body, {
2710
+ headers: r,
2711
+ status: t.status ?? e.status,
2712
+ statusText: t.statusText ?? e.statusText
2713
+ });
2714
+ }
2715
+ async function Qn(e, t, r, n) {
2716
+ const s = await Promise.all(
2717
+ e.policies.filter(
2718
+ (o) => B(o.fileSegments, t.fileSegments)
2719
+ ).map((o) => o.load())
2720
+ );
2721
+ return Ke(
2722
+ ...s.map((o) => o.policy),
2723
+ r.policy,
2724
+ {
2725
+ security: n.kind === "page" ? void 0 : n.security
2726
+ }
2727
+ );
2728
+ }
2729
+ async function $e(e, t) {
2730
+ return (await Promise.all(
2731
+ e.middlewares.filter(
2732
+ (n) => B(n.fileSegments, t.fileSegments)
2733
+ ).map((n) => n.load())
2734
+ )).flatMap(
2735
+ (n) => n.middleware ? [n.middleware] : []
2736
+ );
2737
+ }
2738
+ async function Ie(e, t, r) {
2739
+ let n = -1;
2740
+ async function s(o) {
2741
+ if (o <= n)
2742
+ throw new Error("Demiurge route middleware next() called multiple times.");
2743
+ n = o;
2744
+ const i = e[o];
2745
+ return i ? await i(t, () => s(o + 1)) : await r();
2746
+ }
2747
+ return await s(0);
2748
+ }
2749
+ function Xn(e, t, r, n) {
2750
+ const s = qt(
2751
+ F(e, t.cors, r),
2752
+ t.timing
2753
+ );
2754
+ return n === "HEAD" ? new Response(null, {
2755
+ headers: s.headers,
2756
+ status: s.status,
2757
+ statusText: s.statusText
2758
+ }) : s;
2759
+ }
2760
+ function X(e) {
2761
+ return e.kind === "page" ? void 0 : e.cors;
2762
+ }
2763
+ function es(e) {
2764
+ const t = e.toUpperCase();
2765
+ return ut.includes(t) ? t : null;
2766
+ }
2767
+ function ts(e, t) {
2768
+ return t === "HEAD" ? e.HEAD ?? e.GET : e[t];
2769
+ }
2770
+ function Oe(e) {
2771
+ return new Response(null, {
2772
+ headers: {
2773
+ allow: rs(e).join(", ")
2774
+ },
2775
+ status: 405
2776
+ });
2777
+ }
2778
+ function rs(e) {
2779
+ const t = ut.filter((r) => e[r]);
2780
+ return e.GET && !t.includes("HEAD") && t.push("HEAD"), t;
2781
+ }
2782
+ export {
2783
+ ms as $,
2784
+ Ue as A,
2785
+ ke as B,
2786
+ Me as C,
2787
+ et as D,
2788
+ cn as E,
2789
+ an as F,
2790
+ Ns as G,
2791
+ Kt as H,
2792
+ ae as I,
2793
+ tr as J,
2794
+ zs as K,
2795
+ as as L,
2796
+ fs as M,
2797
+ x as N,
2798
+ Ms as O,
2799
+ ps as P,
2800
+ Us as Q,
2801
+ D as R,
2802
+ Ds as S,
2803
+ Cn as T,
2804
+ un as U,
2805
+ Sn as V,
2806
+ kn as W,
2807
+ Es as X,
2808
+ Fs as Y,
2809
+ ws as Z,
2810
+ ys as _,
2811
+ $s as a,
2812
+ Ke as a0,
2813
+ Or as a1,
2814
+ Ir as a2,
2815
+ ds as a3,
2816
+ ls as a4,
2817
+ bs as a5,
2818
+ ln as a6,
2819
+ st as a7,
2820
+ cs as a8,
2821
+ us as a9,
2822
+ Cs as aa,
2823
+ Rs as ab,
2824
+ gt as ac,
2825
+ b as ad,
2826
+ vt as ae,
2827
+ P as af,
2828
+ je as ag,
2829
+ te as ah,
2830
+ ks as ai,
2831
+ xs as aj,
2832
+ vs as ak,
2833
+ hs as al,
2834
+ As as am,
2835
+ Ss as an,
2836
+ En as ao,
2837
+ Ls as ap,
2838
+ B as aq,
2839
+ Hs as ar,
2840
+ Os as as,
2841
+ Sr as at,
2842
+ kr as au,
2843
+ _ as av,
2844
+ R as aw,
2845
+ nt as b,
2846
+ ur as c,
2847
+ js as d,
2848
+ Ts as e,
2849
+ L as f,
2850
+ Pt as g,
2851
+ Vn as h,
2852
+ qe as i,
2853
+ hr as j,
2854
+ Pr as k,
2855
+ Is as l,
2856
+ Cr as m,
2857
+ xe as n,
2858
+ Z as o,
2859
+ I as p,
2860
+ Ps as q,
2861
+ se as r,
2862
+ Re as s,
2863
+ $t as t,
2864
+ ie as u,
2865
+ gs as v,
2866
+ Je as w,
2867
+ Qr as x,
2868
+ Pn as y,
2869
+ ot as z
2870
+ };
2871
+ //# sourceMappingURL=testing-BBnJ5WUR.js.map