@demiurgejs/core 0.2.0-beta.4 → 0.2.0-beta.5

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 (116) hide show
  1. package/README.md +23 -0
  2. package/bin/demiurge.mjs +17 -1
  3. package/dist/adapter/index.d.ts +1 -1
  4. package/dist/adapter/index.d.ts.map +1 -1
  5. package/dist/browser/file-router.d.ts +1 -1
  6. package/dist/chunks/{document-shell-CpJnFtSC.js → document-shell-9GPwtcTt.js} +2 -2
  7. package/dist/chunks/{document-shell-CpJnFtSC.js.map → document-shell-9GPwtcTt.js.map} +1 -1
  8. package/dist/chunks/{image-codec-BmzWnH6W.js → image-codec-Dh1POFhE.js} +2 -2
  9. package/dist/chunks/{image-codec-BmzWnH6W.js.map → image-codec-Dh1POFhE.js.map} +1 -1
  10. package/dist/chunks/{images-BQ80950B.js → images-CG7ZzayG.js} +2 -2
  11. package/dist/chunks/{images-BQ80950B.js.map → images-CG7ZzayG.js.map} +1 -1
  12. package/dist/chunks/{index-BVk9zWbe.js → index-0MNiR_wo.js} +4 -3
  13. package/dist/chunks/{index-BVk9zWbe.js.map → index-0MNiR_wo.js.map} +1 -1
  14. package/dist/chunks/plugin-BZauDxRY.js +2310 -0
  15. package/dist/chunks/plugin-BZauDxRY.js.map +1 -0
  16. package/dist/chunks/streaming-GYIsVTQH.js +560 -0
  17. package/dist/chunks/streaming-GYIsVTQH.js.map +1 -0
  18. package/dist/chunks/testing-CUwGj2ie.js +4751 -0
  19. package/dist/chunks/testing-CUwGj2ie.js.map +1 -0
  20. package/dist/chunks/{vite-DO70kZA6.js → vite-QoqrGl6f.js} +43 -43
  21. package/dist/chunks/vite-QoqrGl6f.js.map +1 -0
  22. package/dist/cli.d.ts +4 -2
  23. package/dist/cli.d.ts.map +1 -1
  24. package/dist/cli.js +224 -98
  25. package/dist/cli.js.map +1 -1
  26. package/dist/config/index.js +2 -2
  27. package/dist/config/types.d.ts +11 -1
  28. package/dist/config/types.d.ts.map +1 -1
  29. package/dist/edge/index.js +3 -3
  30. package/dist/index.d.ts +3 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +161 -139
  33. package/dist/index.js.map +1 -1
  34. package/dist/inspect/command.d.ts +28 -0
  35. package/dist/inspect/command.d.ts.map +1 -0
  36. package/dist/inspect/index.d.ts +9 -0
  37. package/dist/inspect/index.d.ts.map +1 -0
  38. package/dist/inspect/redact.d.ts +35 -0
  39. package/dist/inspect/redact.d.ts.map +1 -0
  40. package/dist/inspect/report.d.ts +24 -0
  41. package/dist/inspect/report.d.ts.map +1 -0
  42. package/dist/inspect/types.d.ts +102 -0
  43. package/dist/inspect/types.d.ts.map +1 -0
  44. package/dist/internal/testing.js +12 -12
  45. package/dist/node/http.d.ts +5 -0
  46. package/dist/node/http.d.ts.map +1 -1
  47. package/dist/node/index.d.ts +1 -1
  48. package/dist/node/index.d.ts.map +1 -1
  49. package/dist/node/index.js +26 -24
  50. package/dist/node/index.js.map +1 -1
  51. package/dist/route/index.d.ts +1 -0
  52. package/dist/route/index.d.ts.map +1 -1
  53. package/dist/route/mutation.d.ts.map +1 -1
  54. package/dist/route/serialization.d.ts +24 -0
  55. package/dist/route/serialization.d.ts.map +1 -0
  56. package/dist/route/webhook.d.ts +6 -1
  57. package/dist/route/webhook.d.ts.map +1 -1
  58. package/dist/router/manifest.d.ts.map +1 -1
  59. package/dist/security/audit.d.ts +2 -1
  60. package/dist/security/audit.d.ts.map +1 -1
  61. package/dist/security/authorization.d.ts +36 -0
  62. package/dist/security/authorization.d.ts.map +1 -0
  63. package/dist/security/csrf.d.ts.map +1 -1
  64. package/dist/security/env-startup.d.ts +0 -2
  65. package/dist/security/env-startup.d.ts.map +1 -1
  66. package/dist/security/env.d.ts +27 -8
  67. package/dist/security/env.d.ts.map +1 -1
  68. package/dist/security/exceptions.d.ts +29 -0
  69. package/dist/security/exceptions.d.ts.map +1 -0
  70. package/dist/security/finding-codes.d.ts +56 -0
  71. package/dist/security/finding-codes.d.ts.map +1 -0
  72. package/dist/security/index.d.ts +5 -2
  73. package/dist/security/index.d.ts.map +1 -1
  74. package/dist/security/policy.d.ts +2 -5
  75. package/dist/security/policy.d.ts.map +1 -1
  76. package/dist/security/report.d.ts +2 -1
  77. package/dist/security/report.d.ts.map +1 -1
  78. package/dist/security/request.d.ts +1 -0
  79. package/dist/security/request.d.ts.map +1 -1
  80. package/dist/security/types.d.ts +138 -5
  81. package/dist/security/types.d.ts.map +1 -1
  82. package/dist/security/upload.d.ts +3 -3
  83. package/dist/security/upload.d.ts.map +1 -1
  84. package/dist/security/verification.d.ts.map +1 -1
  85. package/dist/server/request-handler.d.ts +3 -2
  86. package/dist/server/request-handler.d.ts.map +1 -1
  87. package/dist/server-only/browser.d.ts +2 -0
  88. package/dist/server-only/browser.d.ts.map +1 -0
  89. package/dist/server-only/browser.js +4 -0
  90. package/dist/server-only/browser.js.map +1 -0
  91. package/dist/server-only/index.d.ts +2 -0
  92. package/dist/server-only/index.d.ts.map +1 -0
  93. package/dist/server-only/index.js +2 -0
  94. package/dist/server-only/index.js.map +1 -0
  95. package/dist/static/index.js +4 -4
  96. package/dist/vite/index.d.ts +9 -4
  97. package/dist/vite/index.d.ts.map +1 -1
  98. package/dist/vite/index.js +28 -21
  99. package/dist/vite/plugin.d.ts +18 -2
  100. package/dist/vite/plugin.d.ts.map +1 -1
  101. package/dist/vite/policy-verification.d.ts +33 -2
  102. package/dist/vite/policy-verification.d.ts.map +1 -1
  103. package/dist/vite/route-audit.d.ts +14 -2
  104. package/dist/vite/route-audit.d.ts.map +1 -1
  105. package/dist/vite/server-only-boundary.d.ts +8 -0
  106. package/dist/vite/server-only-boundary.d.ts.map +1 -0
  107. package/package.json +6 -1
  108. package/dist/chunks/env-startup-DOBYWlZD.js +0 -257
  109. package/dist/chunks/env-startup-DOBYWlZD.js.map +0 -1
  110. package/dist/chunks/plugin-BQgMiHxa.js +0 -1827
  111. package/dist/chunks/plugin-BQgMiHxa.js.map +0 -1
  112. package/dist/chunks/streaming-BEbPN7Uk.js +0 -469
  113. package/dist/chunks/streaming-BEbPN7Uk.js.map +0 -1
  114. package/dist/chunks/testing-DueXbMo4.js +0 -4167
  115. package/dist/chunks/testing-DueXbMo4.js.map +0 -1
  116. package/dist/chunks/vite-DO70kZA6.js.map +0 -1
@@ -0,0 +1,2310 @@
1
+ import { existsSync as ye } from "node:fs";
2
+ import { mkdir as Et, writeFile as xt, readdir as He, readFile as Ke } from "node:fs/promises";
3
+ import { dirname as M, resolve as O, relative as I, sep as A, basename as he, join as Ge } from "node:path";
4
+ import Ot from "magic-string";
5
+ import { parseAst as K, transformWithEsbuild as Pt } from "vite";
6
+ import { e as Dt, f as Nt } from "./index-0MNiR_wo.js";
7
+ import { v as kt, n as Mt, o as jt, p as It, i as k, q as Ct, s as be, u as At, D as Tt, w as Z, x as Ft, y as we, z as _t, A as ie, t as Lt, B as Vt, C as Ye, M as Wt, E as Bt, F as ee, G as Se, H as zt, I as Jt, J as Ut, K as Xe, f as qt, g as Ht, h as Kt, L as Gt, N as Yt } from "./testing-CUwGj2ie.js";
8
+ import "react";
9
+ import "react-dom/server";
10
+ import "react/jsx-runtime";
11
+ import { c as Xt, t as $e, U as Re, w as Ee, b as U, d as Zt, e as Qt } from "./streaming-GYIsVTQH.js";
12
+ import { p as en } from "./images-CG7ZzayG.js";
13
+ const F = "@demiurgejs/core";
14
+ async function tn(e) {
15
+ const t = await rn(e.routesDir), n = t.map((i) => sn(e, i)).filter((i) => !!i), r = t.map((i) => on(e, i, n)).filter((i) => !!i).sort((i, s) => i.pattern.localeCompare(s.pattern));
16
+ nn(r, e.localeNamespaces ?? []);
17
+ const o = cn(r, n, e.locales);
18
+ return await Et(M(e.outputFile), { recursive: !0 }), await xt(e.outputFile, o), {
19
+ routes: r,
20
+ source: o
21
+ };
22
+ }
23
+ function nn(e, t) {
24
+ const n = new Set(t.map((r) => r.toLowerCase()));
25
+ for (const r of e) {
26
+ const [o] = r.pattern.slice(1).split("/");
27
+ if (o && !o.startsWith("[") && n.has(o.toLowerCase()))
28
+ throw new Error(
29
+ `Route "${r.pattern}" conflicts with the locale URL namespace "${o}". Move the route or change the locale label.`
30
+ );
31
+ }
32
+ }
33
+ async function rn(e) {
34
+ return (await He(e, {
35
+ recursive: !0,
36
+ withFileTypes: !0
37
+ })).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => O(n.parentPath, n.name));
38
+ }
39
+ function on(e, t, n) {
40
+ const o = I(e.routesDir, t).split(A).join("/").replace(/\.tsx?$/, "").split("/");
41
+ if (o.at(-1)?.startsWith("@"))
42
+ return null;
43
+ const s = o.flatMap((c) => xe(c) ? [] : c === "index" ? [] : c.startsWith("[...") && c.endsWith("]") ? [c] : c.startsWith("[") && c.endsWith("]") ? [c] : [c]), a = o.flatMap((c) => xe(c) ? [] : c.startsWith("[...") && c.endsWith("]") ? [c.slice(4, -1)] : c.startsWith("[") && c.endsWith("]") ? [c.slice(1, -1)] : []);
44
+ return {
45
+ contextMiddleware: n.filter((c) => an(c.fileSegments, o)).map((c) => n.indexOf(c)),
46
+ fileSegments: o,
47
+ importPath: Ze(e.outputFile, t),
48
+ pathVars: a,
49
+ pattern: `/${s.join("/")}`.replace(/\/$/, "") || "/"
50
+ };
51
+ }
52
+ function sn(e, t) {
53
+ const r = I(e.routesDir, t).split(A).join("/").replace(/\.tsx?$/, "").split("/");
54
+ return r.at(-1) !== "@middleware" ? null : {
55
+ file: t,
56
+ fileSegments: r.slice(0, -1),
57
+ importPath: Ze(e.outputFile, t)
58
+ };
59
+ }
60
+ function Ze(e, t) {
61
+ let n = I(M(e), t).split(A).join("/").replace(/\.tsx?$/, "");
62
+ return n.startsWith(".") || (n = `./${n}`), n;
63
+ }
64
+ function an(e, t) {
65
+ return e.every(
66
+ (n, r) => t[r] === n
67
+ );
68
+ }
69
+ function xe(e) {
70
+ return e.startsWith("(") && e.endsWith(")");
71
+ }
72
+ function cn(e, t, n = []) {
73
+ return `// Generated by Demiurge. Do not edit by hand.
74
+ import "${F}";
75
+ import type { MiddlewareContextOf, MutationMethodsOf, PathValue } from "${F}";
76
+ ${t.map(un).join(`
77
+ `)}
78
+
79
+ ${t.map((r, o) => ln(o)).join(`
80
+ `)}
81
+
82
+ declare module "${F}" {
83
+ interface RouteLocales {
84
+ ${n.map((r) => ` ${JSON.stringify(r)}: true;`).join(`
85
+ `)}
86
+ }
87
+
88
+ interface RoutePathVars {
89
+ ${e.map(fn).join(`
90
+ `)}
91
+ }
92
+
93
+ interface RouteConcretePaths {
94
+ ${e.map(dn).join(`
95
+ `)}
96
+ }
97
+
98
+ interface RouteRequestContexts {
99
+ ${e.map(pn).join(`
100
+ `)}
101
+ }
102
+
103
+ interface RouteMutationMethods {
104
+ ${e.map(mn).join(`
105
+ `)}
106
+ }
107
+ }
108
+
109
+ export {};
110
+ `;
111
+ }
112
+ function un(e, t) {
113
+ return `type __DemiurgeMiddleware${t} = typeof import(${JSON.stringify(e.importPath)}) extends { middleware?: infer T } ? T : never;`;
114
+ }
115
+ function ln(e) {
116
+ return `type __DemiurgeMiddlewareContext${e} = MiddlewareContextOf<__DemiurgeMiddleware${e}>;`;
117
+ }
118
+ function fn(e) {
119
+ if (e.pathVars.length === 0)
120
+ return ` ${JSON.stringify(e.pattern)}: {};`;
121
+ const t = e.pathVars.map((n) => `${n}: PathValue`).join("; ");
122
+ return ` ${JSON.stringify(e.pattern)}: { ${t} };`;
123
+ }
124
+ function dn(e) {
125
+ return ` ${JSON.stringify(e.pattern)}: ${yn(e.pattern)};`;
126
+ }
127
+ function pn(e) {
128
+ const t = e.contextMiddleware.map((r) => `__DemiurgeMiddlewareContext${r}`), n = t.length > 0 ? t.join(" & ") : "Record<never, never>";
129
+ return ` ${JSON.stringify(e.pattern)}: ${n};`;
130
+ }
131
+ function mn(e) {
132
+ return ` ${JSON.stringify(e.pattern)}: MutationMethodsOf<typeof import(${JSON.stringify(e.importPath)})>;`;
133
+ }
134
+ function yn(e) {
135
+ return e.includes("[") ? `\`${e.split(/(\[\.\.\.[^\]]+\]|\[[^\]]+\])/g).filter(Boolean).map((n) => n.startsWith("[") ? "${PathValue}" : hn(n)).join("")}\`` : JSON.stringify(e);
136
+ }
137
+ function hn(e) {
138
+ return e.replace(/[`$\\]/g, "\\$&");
139
+ }
140
+ function gn(e) {
141
+ const t = /* @__PURE__ */ new Map();
142
+ for (const [n, r] of Object.entries(e ?? {}))
143
+ r.client || t.set(n, { sensitive: r.sensitive });
144
+ return t;
145
+ }
146
+ function vn(e, t) {
147
+ const n = new Set(t), r = /* @__PURE__ */ new Set();
148
+ return n.size ? [...n].some((o) => e.includes(o)) ? (et(K(e), n, r), [...r].sort()) : [] : [];
149
+ }
150
+ function Qe(e, t, n) {
151
+ if (e === t) return [e];
152
+ const r = /* @__PURE__ */ new Set([e]), o = [[e]];
153
+ for (; o.length; ) {
154
+ const i = o.shift();
155
+ for (const s of n(i[i.length - 1]))
156
+ if (!r.has(s)) {
157
+ if (s === t) return [...i, s];
158
+ r.add(s), o.push([...i, s]);
159
+ }
160
+ }
161
+ }
162
+ function bn(e) {
163
+ return [
164
+ "Demiurge stopped the build. Client code reads an environment variable that stays on the server.",
165
+ "",
166
+ ...e.flatMap(wn)
167
+ ].join(`
168
+ `);
169
+ }
170
+ function wn(e) {
171
+ return [
172
+ ` variable: ${e.key}`,
173
+ ` module: ${e.module}`,
174
+ ` import path: ${e.importPath.join(" -> ")}`,
175
+ e.code === "client-secret" ? " A secret variable never reaches the browser. Read the value on the server, then send the result through route data." : " Declare the variable with client: true to put the value in the browser bundle.",
176
+ ""
177
+ ];
178
+ }
179
+ function et(e, t, n) {
180
+ if (e.type !== "ImportDeclaration" && !(e.type === "ExportNamedDeclaration" && !e.declaration) && e.type !== "ExportAllDeclaration") {
181
+ if (e.type === "Identifier") {
182
+ ce(e.name, t, n);
183
+ return;
184
+ }
185
+ if (e.type === "MemberExpression") {
186
+ W(e.object, t, n), Oe(e.property, !!e.computed, t, n);
187
+ return;
188
+ }
189
+ if (e.type === "Property" || e.type === "PropertyDefinition") {
190
+ (e.computed || Sn(e)) && Oe(e.key, !!e.computed, t, n), W(e.value, t, n);
191
+ return;
192
+ }
193
+ $n(e, t, n);
194
+ }
195
+ }
196
+ function Sn(e) {
197
+ const t = ge(e.value);
198
+ return t?.type === "Identifier" || t?.type === "ObjectPattern" || t?.type === "ArrayPattern" || t?.type === "AssignmentPattern";
199
+ }
200
+ function Oe(e, t, n, r) {
201
+ const o = ge(e);
202
+ if (o) {
203
+ if (o.type === "Literal") {
204
+ ce(o.value, n, r);
205
+ return;
206
+ }
207
+ if (!t) {
208
+ o.type === "Identifier" && ce(o.name, n, r);
209
+ return;
210
+ }
211
+ W(o, n, r);
212
+ }
213
+ }
214
+ function ce(e, t, n) {
215
+ typeof e == "string" && t.has(e) && n.add(e);
216
+ }
217
+ function $n(e, t, n) {
218
+ for (const [r, o] of Object.entries(e))
219
+ r === "end" || r === "loc" || r === "start" || r === "type" || W(o, t, n);
220
+ }
221
+ function W(e, t, n) {
222
+ if (!e || typeof e != "object") return;
223
+ if (Array.isArray(e)) {
224
+ for (const o of e) W(o, t, n);
225
+ return;
226
+ }
227
+ const r = ge(e);
228
+ if (r) {
229
+ et(r, t, n);
230
+ return;
231
+ }
232
+ for (const o of Object.values(e))
233
+ W(o, t, n);
234
+ }
235
+ function ge(e) {
236
+ return e && typeof e == "object" && "type" in e && typeof e.type == "string" ? e : void 0;
237
+ }
238
+ const Rn = /* @__PURE__ */ new Set([
239
+ "@demiurgejs/core/server-only",
240
+ "server-only"
241
+ ]);
242
+ function En(e) {
243
+ return e.includes("server-only") ? Dn(K(e)) : !1;
244
+ }
245
+ function xn(e) {
246
+ return [
247
+ "Demiurge stopped the build. A browser bundle reaches a module marked server-only.",
248
+ "",
249
+ ...e.flatMap(Pn)
250
+ ].join(`
251
+ `);
252
+ }
253
+ function On(e) {
254
+ return `Demiurge stopped the development server. The browser requested ${e}, and this module is marked server-only.
255
+
256
+ Keep this module out of client code. Move the server logic to a module that no client module imports.`;
257
+ }
258
+ function Pn(e) {
259
+ return [
260
+ ` module: ${e.module}`,
261
+ ` import path: ${e.importPath.join(" -> ")}`,
262
+ " Keep this module out of client code. Move the server logic to a module that no client module imports.",
263
+ ""
264
+ ];
265
+ }
266
+ function Dn(e) {
267
+ let t = !1;
268
+ return ue(e, (n) => {
269
+ t || (n.type === "ImportDeclaration" || n.type === "ExportNamedDeclaration" || n.type === "ExportAllDeclaration" || n.type === "ImportExpression") && Nn(n.source) && (t = !0);
270
+ }), t;
271
+ }
272
+ function Nn(e) {
273
+ const t = kn(e);
274
+ return t?.type === "Literal" && typeof t.value == "string" && Rn.has(t.value);
275
+ }
276
+ function ue(e, t) {
277
+ if (!e || typeof e != "object") return;
278
+ if (Array.isArray(e)) {
279
+ for (const r of e) ue(r, t);
280
+ return;
281
+ }
282
+ const n = e;
283
+ if (typeof n.type == "string") {
284
+ t(n);
285
+ for (const [r, o] of Object.entries(n))
286
+ (/* @__PURE__ */ new Set(["end", "loc", "start", "type"])).has(r) || ue(o, t);
287
+ }
288
+ }
289
+ function kn(e) {
290
+ return e && typeof e == "object" && "type" in e ? e : void 0;
291
+ }
292
+ const tt = [
293
+ "GET",
294
+ "POST",
295
+ "PUT",
296
+ "PATCH",
297
+ "DELETE",
298
+ "OPTIONS",
299
+ "HEAD"
300
+ ], Mn = /* @__PURE__ */ new Set([
301
+ "mutation",
302
+ "html",
303
+ "json",
304
+ "jsonl",
305
+ "notFound",
306
+ "redirect",
307
+ "response",
308
+ "sse",
309
+ "stream",
310
+ "text"
311
+ ]);
312
+ async function jn(e) {
313
+ const t = await Ke(e, "utf8"), n = await nt(t, e), r = he(e).startsWith("@");
314
+ return {
315
+ accessState: n.accessState,
316
+ declaresDocumentPolicy: n.declaresDocumentPolicy,
317
+ documentCspState: n.documentCspState,
318
+ // An attached file owns no address, so it never declares a route.
319
+ declaresRoute: !r && n.declaredMethods.size > 0,
320
+ declaresPageRoute: !r && ot(t),
321
+ file: e,
322
+ findings: ft(n, e),
323
+ methods: r ? [] : tt.filter((o) => n.declaredMethods.has(o))
324
+ };
325
+ }
326
+ async function No(e, t) {
327
+ return ft(
328
+ await nt(e, t),
329
+ t
330
+ );
331
+ }
332
+ async function nt(e, t) {
333
+ const n = t.endsWith(".tsx") ? "tsx" : "ts", r = await Pt(e, t, {
334
+ format: "esm",
335
+ loader: n,
336
+ target: "esnext"
337
+ });
338
+ return Wn(r.code);
339
+ }
340
+ function In(e, t) {
341
+ const n = t.filter((o) => rt(o.file)), r = [];
342
+ for (const o of t) {
343
+ if (!o.declaresPageRoute && !Tn(o.file))
344
+ continue;
345
+ const i = _n(
346
+ e,
347
+ M(o.file),
348
+ n
349
+ );
350
+ Ln(
351
+ i,
352
+ o.documentCspState
353
+ ) === "absent" && r.push({
354
+ code: "document-policy-missing",
355
+ file: o.file,
356
+ message: Fn(e, i),
357
+ severity: "error"
358
+ });
359
+ }
360
+ return r;
361
+ }
362
+ function Cn(e, t) {
363
+ const n = t.filter(
364
+ (o) => rt(o.file)
365
+ ), r = [];
366
+ for (const o of t)
367
+ !o.declaresRoute || An(
368
+ e,
369
+ M(o.file),
370
+ o.accessState,
371
+ n
372
+ ) !== "absent" || r.push({
373
+ code: "access-declaration-missing",
374
+ file: o.file,
375
+ message: "This route inherits no access declaration, so the request pipeline denies each request. Add access: { public: true } for a public route, or access: { authorize } to this route or an ancestor @policy.ts file.",
376
+ severity: "error"
377
+ });
378
+ return r;
379
+ }
380
+ function An(e, t, n, r) {
381
+ const o = r.filter(
382
+ (s) => te(M(s.file), t) && te(e, M(s.file))
383
+ );
384
+ let i = n;
385
+ for (const s of o)
386
+ s.accessState !== "absent" && (i = s.accessState);
387
+ return i;
388
+ }
389
+ function Tn(e) {
390
+ return /^@(?:not-found|error)\.tsx?$/.test(he(e));
391
+ }
392
+ function Fn(e, t) {
393
+ const n = "To accept a document without a Content-Security-Policy, declare csp with a value of false and a reason.", r = t.at(-1);
394
+ return r ? `This route inherits no document policy. ${r.file} does not declare one. Add document: security.strict() to ${r.file}. ${n}` : `This route inherits no document policy. No @policy.ts file exists above it. Create ${Ge(e, "@policy.ts")} with document: security.strict(). ${n}`;
395
+ }
396
+ function _n(e, t, n) {
397
+ return n.filter(
398
+ (r) => te(M(r.file), t) && te(e, M(r.file))
399
+ ).sort(
400
+ (r, o) => M(r.file).length - M(o.file).length || r.file.localeCompare(o.file)
401
+ );
402
+ }
403
+ function Ln(e, t) {
404
+ let n = "absent";
405
+ for (const r of e)
406
+ n = Pe(n, r.documentCspState);
407
+ return Pe(n, t);
408
+ }
409
+ function Pe(e, t) {
410
+ return t === "absent" ? e : t;
411
+ }
412
+ function rt(e) {
413
+ return /^@policy\.tsx?$/.test(he(e));
414
+ }
415
+ function te(e, t) {
416
+ const n = I(e, t);
417
+ return n === "" || n !== ".." && !n.startsWith(`..${A}`) && !n.startsWith(A);
418
+ }
419
+ const Vn = F.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), De = new RegExp(
420
+ `import\\s*\\{([^}]*)\\}\\s*from\\s*["']${Vn}["']`,
421
+ "g"
422
+ );
423
+ function ot(e) {
424
+ const t = [...e.matchAll(De)].flatMap(
425
+ (r) => r[1].split(",").flatMap((o) => {
426
+ const [i, s] = o.trim().split(/\s+as\s+/);
427
+ return i.replace(/^type\s+/, "") === "page" ? [s ?? i] : [];
428
+ })
429
+ );
430
+ if (t.length === 0)
431
+ return !1;
432
+ const n = e.replace(De, "");
433
+ return t.some((r) => new RegExp(`\\b${r}\\s*\\(`).test(n));
434
+ }
435
+ function Wn(e) {
436
+ const t = K(e), n = Gn(t), r = Yn(t), o = zn(t), i = Jn(t), s = {}, a = /* @__PURE__ */ new Set();
437
+ let c = "absent", u = !1, l = "absent", d;
438
+ for (const [f, b] of i) {
439
+ const R = o.get(b);
440
+ if (f === "policy") {
441
+ c = R ? it(R, n, r) : "unknown", l = R ? st(R, n, r) : "unknown", u = l !== "absent", R && (d = lt(R, n, r));
442
+ continue;
443
+ }
444
+ if (!Xn(f) || (a.add(f), !R)) continue;
445
+ const h = Un(R, n, r);
446
+ h && (s[f] = h);
447
+ }
448
+ return {
449
+ accessState: c,
450
+ capabilities: s,
451
+ declaredMethods: a,
452
+ declaresDocumentPolicy: u,
453
+ documentCspState: l,
454
+ policy: d
455
+ };
456
+ }
457
+ function it(e, t, n) {
458
+ if (e.type === "Identifier") {
459
+ if (e.name === "undefined") return "absent";
460
+ const r = n.get(String(e.name));
461
+ return r === void 0 && !n.has(String(e.name)) || !k(r) ? "unknown" : Object.prototype.hasOwnProperty.call(r, "access") ? "declared" : "absent";
462
+ }
463
+ if (e.type === "CallExpression") {
464
+ const r = j(e.callee);
465
+ if (r && t.get(r) === "defineRoutePolicy") {
466
+ const o = m(e.arguments)[0];
467
+ return o ? it(o, t, n) : "unknown";
468
+ }
469
+ return "unknown";
470
+ }
471
+ if (e.type !== "ObjectExpression") return "unknown";
472
+ for (const r of m(e.properties)) {
473
+ if (r.type === "SpreadElement") return "unknown";
474
+ if (r.type !== "Property") continue;
475
+ if (r.computed) return "unknown";
476
+ if (D(r.key) !== "access") continue;
477
+ const o = y(r.value);
478
+ return o?.type === "Identifier" && o.name === "undefined" ? "absent" : "declared";
479
+ }
480
+ return "absent";
481
+ }
482
+ function st(e, t, n) {
483
+ if (e.type === "Identifier") {
484
+ if (e.name === "undefined") return "absent";
485
+ const r = n.get(String(e.name));
486
+ return r === void 0 && !n.has(String(e.name)) ? "unknown" : ut(r);
487
+ }
488
+ if (e.type === "CallExpression") {
489
+ const r = j(e.callee);
490
+ if (r && t.get(r) === "defineRoutePolicy") {
491
+ const i = m(e.arguments)[0];
492
+ return i ? st(i, t, n) : "unknown";
493
+ }
494
+ const o = y(e.callee);
495
+ if (o?.type === "MemberExpression") {
496
+ const i = j(o.object), s = D(o.property);
497
+ if (i && t.get(i) === "security" && s)
498
+ return at(s, m(e.arguments)[0], n);
499
+ }
500
+ return "unknown";
501
+ }
502
+ if (e.type !== "ObjectExpression") return "unknown";
503
+ for (const r of m(e.properties)) {
504
+ if (r.type === "SpreadElement") return "unknown";
505
+ if (r.type === "Property") {
506
+ if (r.computed) return "unknown";
507
+ if (D(r.key) === "document")
508
+ return Bn(
509
+ y(r.value),
510
+ t,
511
+ n
512
+ );
513
+ }
514
+ }
515
+ return "absent";
516
+ }
517
+ function Bn(e, t, n) {
518
+ if (!e) return "unknown";
519
+ if (e.type === "UnaryExpression" && e.operator === "void")
520
+ return "absent";
521
+ if (e.type === "Identifier") {
522
+ if (e.name === "undefined") return "absent";
523
+ const r = n.get(String(e.name));
524
+ return r === void 0 && !n.has(String(e.name)) ? "unknown" : ut(r);
525
+ }
526
+ if (e.type === "CallExpression") {
527
+ const r = y(e.callee);
528
+ if (r?.type !== "MemberExpression") return "unknown";
529
+ const o = j(r.object), i = D(r.property);
530
+ return !o || t.get(o) !== "security" || !i ? "unknown" : at(i, m(e.arguments)[0], n);
531
+ }
532
+ if (e.type !== "ObjectExpression") return "unknown";
533
+ for (const r of m(e.properties)) {
534
+ if (r.type === "SpreadElement" || r.computed) return "unknown";
535
+ if (r.type !== "Property" || D(r.key) !== "csp") continue;
536
+ const o = y(r.value);
537
+ if (!o) return "unknown";
538
+ if (o.type === "Literal")
539
+ return o.value === !1 ? "false" : o.value === void 0 || o.value === null ? "absent" : "present";
540
+ if (o.type === "Identifier") {
541
+ const i = P(o, n);
542
+ return i === g ? "unknown" : ne(i);
543
+ }
544
+ if (o.type === "ObjectExpression") {
545
+ const i = P(o, n);
546
+ return i === g ? "unknown" : ne(i);
547
+ }
548
+ return o.type === "ArrayExpression" ? "present" : "unknown";
549
+ }
550
+ return "absent";
551
+ }
552
+ function at(e, t, n) {
553
+ const r = e === "api" ? "absent" : e === "strict" || e === "static" || e === "crossOriginIsolated" ? "present" : "unknown";
554
+ if (!t) return r;
555
+ if (t.type === "Identifier") {
556
+ const o = P(t, n);
557
+ return o === g ? "unknown" : Ne(r, ct(o));
558
+ }
559
+ if (t.type !== "ObjectExpression") return "unknown";
560
+ for (const o of m(t.properties)) {
561
+ if (o.type === "SpreadElement" || o.computed) return "unknown";
562
+ if (o.type !== "Property" || D(o.key) !== "csp") continue;
563
+ const i = P(y(o.value), n);
564
+ return i === g ? "unknown" : Ne(r, ne(i));
565
+ }
566
+ return r;
567
+ }
568
+ function ct(e) {
569
+ return k(e) ? Object.prototype.hasOwnProperty.call(e, "csp") ? ne(e.csp) : "absent" : e === void 0 ? "absent" : "unknown";
570
+ }
571
+ function ne(e) {
572
+ return e === !1 ? "false" : Ft(e) ? e.value === !1 ? "false" : "unknown" : e == null ? "absent" : k(e) || Array.isArray(e) ? "present" : "unknown";
573
+ }
574
+ function Ne(e, t) {
575
+ return t === "absent" ? e : t;
576
+ }
577
+ function ut(e) {
578
+ return e === void 0 ? "absent" : k(e) ? Object.prototype.hasOwnProperty.call(e, "document") ? ct(e.document) : "absent" : "unknown";
579
+ }
580
+ function zn(e) {
581
+ const t = /* @__PURE__ */ new Map();
582
+ for (const n of m(e.body)) {
583
+ const r = n.type === "ExportNamedDeclaration" ? y(n.declaration) : n;
584
+ if (r?.type === "VariableDeclaration")
585
+ for (const o of m(r.declarations)) {
586
+ const i = j(o.id), s = y(o.init);
587
+ i && s && t.set(i, s);
588
+ }
589
+ }
590
+ return t;
591
+ }
592
+ function Jn(e) {
593
+ const t = /* @__PURE__ */ new Map();
594
+ for (const n of m(e.body)) {
595
+ if (n.type !== "ExportNamedDeclaration") continue;
596
+ const r = y(n.declaration);
597
+ if (r?.type === "VariableDeclaration")
598
+ for (const o of m(r.declarations)) {
599
+ const i = j(o.id);
600
+ i && t.set(i, i);
601
+ }
602
+ for (const o of m(n.specifiers)) {
603
+ const i = D(o.exported), s = D(o.local);
604
+ i && s && t.set(i, s);
605
+ }
606
+ }
607
+ return t;
608
+ }
609
+ function Un(e, t, n) {
610
+ if (e.type !== "CallExpression") return;
611
+ const r = j(e.callee), o = r ? t.get(r) : void 0;
612
+ if (!o || !Mn.has(o)) return;
613
+ const i = m(e.arguments), s = o === "mutation" ? i[0] : i[1];
614
+ if (!s) return {};
615
+ const a = ke(s, "cors", n), c = ke(
616
+ s,
617
+ "security",
618
+ n
619
+ );
620
+ return {
621
+ cors: k(a) ? a : void 0,
622
+ security: k(c) ? c : void 0
623
+ };
624
+ }
625
+ function ke(e, t, n) {
626
+ if (e.type === "Identifier") {
627
+ const o = n.get(String(e.name));
628
+ return k(o) ? o[t] : g;
629
+ }
630
+ if (e.type !== "ObjectExpression") return g;
631
+ let r;
632
+ for (const o of m(e.properties)) {
633
+ if (o.type !== "Property" || o.computed) return g;
634
+ D(o.key) === t && (r = P(y(o.value), n));
635
+ }
636
+ return r;
637
+ }
638
+ function lt(e, t, n) {
639
+ if (e.type === "CallExpression") {
640
+ const o = j(e.callee);
641
+ if (o && t.get(o) === "defineRoutePolicy") {
642
+ const i = m(e.arguments)[0];
643
+ return i ? lt(i, t, n) : void 0;
644
+ }
645
+ }
646
+ if (e.type !== "ObjectExpression") {
647
+ const o = P(e, n);
648
+ return k(o) ? o : void 0;
649
+ }
650
+ const r = {};
651
+ for (const o of m(e.properties)) {
652
+ if (o.type !== "Property" || o.computed) return;
653
+ const i = D(o.key), s = y(o.value);
654
+ if (!i || !s) return;
655
+ if (i === "document") {
656
+ const c = qn(s, t, n);
657
+ if (!c) return;
658
+ r.document = c;
659
+ continue;
660
+ }
661
+ const a = P(s, n);
662
+ if (a === g) return;
663
+ r[i] = a;
664
+ }
665
+ return r;
666
+ }
667
+ function qn(e, t, n) {
668
+ if (e.type !== "CallExpression") {
669
+ const a = P(e, n);
670
+ return k(a) ? a : void 0;
671
+ }
672
+ const r = y(e.callee);
673
+ if (r?.type !== "MemberExpression") return;
674
+ const o = j(r.object), i = D(r.property);
675
+ if (!o || t.get(o) !== "security" || !i)
676
+ return;
677
+ const s = P(m(e.arguments)[0], n);
678
+ if (s !== g && !(s !== void 0 && !k(s))) {
679
+ if (i === "api")
680
+ return Z.api(s);
681
+ if (i === "crossOriginIsolated")
682
+ return Z.crossOriginIsolated(s);
683
+ if (i === "static")
684
+ return Z.static(s);
685
+ if (i === "strict")
686
+ return Z.strict(s);
687
+ }
688
+ }
689
+ function ft(e, t) {
690
+ const n = [], r = new Set(e.declaredMethods);
691
+ r.has("GET") && r.add("HEAD"), r.add("OPTIONS");
692
+ for (const [o, i] of Object.entries(
693
+ e.capabilities
694
+ )) {
695
+ if (i.cors) {
696
+ try {
697
+ kt(i.cors);
698
+ } catch (s) {
699
+ n.push(_(
700
+ "cors-invalid",
701
+ t,
702
+ le(s, "The CORS policy is invalid."),
703
+ o
704
+ ));
705
+ }
706
+ for (const s of i.cors.methods ?? [])
707
+ r.has(s) || n.push(_(
708
+ "cors-method-unavailable",
709
+ t,
710
+ `CORS method ${s} is not available from this route.`,
711
+ o
712
+ ));
713
+ }
714
+ Ie(i.security, t, o, n), Me(
715
+ void 0,
716
+ i.security,
717
+ t,
718
+ o,
719
+ n
720
+ );
721
+ }
722
+ if (Ie(e.policy?.security, t, void 0, n), Me(
723
+ e.policy?.document,
724
+ e.policy?.security,
725
+ t,
726
+ void 0,
727
+ n
728
+ ), e.policy?.document)
729
+ try {
730
+ Mt(Hn(e.policy.document), {
731
+ nonce: "build-verification-nonce"
732
+ });
733
+ } catch (o) {
734
+ n.push(_(
735
+ "security-header-render-failed",
736
+ t,
737
+ le(o, "The security headers are invalid.")
738
+ ));
739
+ }
740
+ return n;
741
+ }
742
+ function Hn(e) {
743
+ const t = e.headers?.reportingEndpoints, n = !!(t && Object.keys(t).length), r = It(e.csp), o = r ? r.reportTo : void 0;
744
+ return n || !o ? e : {
745
+ ...e,
746
+ csp: { ...r, reportTo: void 0 },
747
+ headers: t ? { ...e.headers, reportingEndpoints: void 0 } : e.headers
748
+ };
749
+ }
750
+ function Me(e, t, n, r, o) {
751
+ e && je(e.csp) && o.push(_(
752
+ "security-exception-reason-missing",
753
+ n,
754
+ "This document policy accepts no Content-Security-Policy and states no reason. Declare csp with a value of false and a reason.",
755
+ r
756
+ )), t && je(t.csrf) && o.push(_(
757
+ "security-exception-reason-missing",
758
+ n,
759
+ "This route runs no CSRF check and states no reason. Declare csrf with a value of false and a reason.",
760
+ r
761
+ )), Kn(t, n, r, o);
762
+ }
763
+ function je(e) {
764
+ return e === !1 ? !0 : k(e) && "value" in e && typeof e.reason != "string";
765
+ }
766
+ function Kn(e, t, n, r) {
767
+ const o = e?.request?.maxBodySize;
768
+ if (o === void 0 || Ct(o))
769
+ return;
770
+ let i, s;
771
+ try {
772
+ i = be(At(o)), s = be(Tt);
773
+ } catch {
774
+ return;
775
+ }
776
+ i <= s || r.push(_(
777
+ "security-exception-reason-missing",
778
+ t,
779
+ `This route raises the request body limit to ${String(o)} and states no reason. Declare maxBodySize with a limit value and a reason.`,
780
+ n
781
+ ));
782
+ }
783
+ function Ie(e, t, n, r) {
784
+ if (e?.rateLimit)
785
+ try {
786
+ jt(e.rateLimit);
787
+ } catch (o) {
788
+ r.push(_(
789
+ "rate-limit-invalid",
790
+ t,
791
+ le(o, "The rate limit policy is invalid."),
792
+ n
793
+ ));
794
+ }
795
+ }
796
+ function _(e, t, n, r) {
797
+ return { code: e, exportName: r, file: t, message: n, severity: "error" };
798
+ }
799
+ function Gn(e) {
800
+ const t = /* @__PURE__ */ new Map();
801
+ for (const n of m(e.body))
802
+ if (!(n.type !== "ImportDeclaration" || y(n.source)?.value !== "@demiurgejs/core"))
803
+ for (const r of m(n.specifiers)) {
804
+ if (r.type !== "ImportSpecifier") continue;
805
+ const o = j(r.local), i = D(r.imported);
806
+ o && i && t.set(o, i);
807
+ }
808
+ return t;
809
+ }
810
+ function Yn(e) {
811
+ const t = /* @__PURE__ */ new Map();
812
+ for (const n of m(e.body)) {
813
+ const r = n.type === "ExportNamedDeclaration" ? y(n.declaration) : n;
814
+ if (r?.type === "VariableDeclaration")
815
+ for (const o of m(r.declarations)) {
816
+ const i = j(o.id), s = y(o.init);
817
+ if (!i || !s) continue;
818
+ const a = P(s, t);
819
+ a !== g && t.set(i, a);
820
+ }
821
+ }
822
+ return t;
823
+ }
824
+ const g = Symbol("unresolved");
825
+ function P(e, t) {
826
+ if (e) {
827
+ if (e.type === "Literal") return e.value;
828
+ if (e.type === "Identifier")
829
+ return e.name === "undefined" ? void 0 : t.has(String(e.name)) ? t.get(String(e.name)) : g;
830
+ if (e.type === "TemplateLiteral")
831
+ return m(e.expressions).length ? g : m(e.quasis).map((n) => y(n.value)?.cooked ?? "").join("");
832
+ if (e.type === "UnaryExpression") {
833
+ const n = P(y(e.argument), t);
834
+ return typeof n != "number" ? g : e.operator === "-" ? -n : e.operator === "+" ? n : g;
835
+ }
836
+ if (e.type === "ArrayExpression") {
837
+ const n = [];
838
+ for (const r of m(e.elements)) {
839
+ const o = P(r, t);
840
+ if (o === g) return g;
841
+ n.push(o);
842
+ }
843
+ return n;
844
+ }
845
+ if (e.type === "ObjectExpression") {
846
+ const n = {};
847
+ for (const r of m(e.properties)) {
848
+ if (r.type !== "Property" || r.computed) return g;
849
+ const o = D(r.key), i = P(y(r.value), t);
850
+ if (!o || i === g) return g;
851
+ n[o] = i;
852
+ }
853
+ return n;
854
+ }
855
+ return g;
856
+ }
857
+ }
858
+ function Xn(e) {
859
+ return tt.includes(e);
860
+ }
861
+ function le(e, t) {
862
+ return e instanceof Error ? e.message : t;
863
+ }
864
+ function y(e) {
865
+ return e && typeof e == "object" && "type" in e ? e : void 0;
866
+ }
867
+ function m(e) {
868
+ return Array.isArray(e) ? e.map(y).filter((t) => !!t) : [];
869
+ }
870
+ function j(e) {
871
+ const t = y(e);
872
+ return t?.type === "Identifier" ? String(t.name) : void 0;
873
+ }
874
+ function D(e) {
875
+ const t = y(e);
876
+ return t?.type === "Identifier" || t?.type === "Literal" ? String(t.name ?? t.value) : void 0;
877
+ }
878
+ const Zn = "[redacted]", dt = /* @__PURE__ */ new Set([
879
+ "cookie",
880
+ "cookies",
881
+ "setcookie",
882
+ "setcookies"
883
+ ]), pt = /* @__PURE__ */ new Set([
884
+ "session",
885
+ "sessiondata",
886
+ "sessionrecord",
887
+ "sessions"
888
+ ]), Qn = /* @__PURE__ */ new Set(["value"]), er = /* @__PURE__ */ new Set(["data", "id"]);
889
+ function tr(e, t = {}) {
890
+ const n = nr(e, t), r = rr(n);
891
+ return JSON.stringify(r, void 0, t.space ?? 2);
892
+ }
893
+ function nr(e, t = {}) {
894
+ const n = [], r = {
895
+ inCookie: !1,
896
+ inSession: !1,
897
+ secretEnvKeys: new Set(t.secretEnvKeys ?? [])
898
+ }, o = fe(e, "", r, n);
899
+ return n.sort((i, s) => i.path.localeCompare(s.path)), { redactions: n, value: o };
900
+ }
901
+ function rr(e) {
902
+ return !yt(e.value) || !Array.isArray(e.value.redactions) ? e.value : { ...e.value, redactions: e.redactions };
903
+ }
904
+ function fe(e, t, n, r) {
905
+ if (Array.isArray(e))
906
+ return e.map(
907
+ (s, a) => fe(s, `${t}[${a}]`, n, r)
908
+ );
909
+ if (!yt(e)) return e;
910
+ const o = sr(e) ? { ...n, inSession: !0 } : n, i = {};
911
+ for (const [s, a] of Object.entries(e)) {
912
+ const c = t ? `${t}.${s}` : s, u = or(s, a, o);
913
+ if (u) {
914
+ r.push({ name: s, path: c, reason: u }), i[s] = Zn;
915
+ continue;
916
+ }
917
+ i[s] = fe(a, c, ir(s, o), r);
918
+ }
919
+ return i;
920
+ }
921
+ function or(e, t, n) {
922
+ if (n.secretEnvKeys.has(e)) return "environment-secret";
923
+ const r = mt(e);
924
+ if (n.inCookie && Qn.has(r))
925
+ return "cookie-value";
926
+ if (n.inSession && er.has(r))
927
+ return "session-record";
928
+ if (typeof t == "string") {
929
+ if (dt.has(r)) return "cookie-value";
930
+ if (pt.has(r)) return "session-record";
931
+ }
932
+ }
933
+ function ir(e, t) {
934
+ const n = mt(e);
935
+ return dt.has(n) ? { ...t, inCookie: !0 } : pt.has(n) ? { ...t, inSession: !0 } : t;
936
+ }
937
+ function mt(e) {
938
+ return e.toLowerCase().replaceAll("-", "").replaceAll("_", "");
939
+ }
940
+ function yt(e) {
941
+ if (!k(e)) return !1;
942
+ const t = Object.getPrototypeOf(e);
943
+ return t === Object.prototype || t === null;
944
+ }
945
+ function sr(e) {
946
+ return typeof e.id == "string" && typeof e.createdAt == "number" && typeof e.expiresAt == "number" && typeof e.version == "number" && "data" in e;
947
+ }
948
+ const ar = 1, ht = "/_demiurge/audit", gt = [
949
+ "GET",
950
+ "POST",
951
+ "PUT",
952
+ "PATCH",
953
+ "DELETE",
954
+ "OPTIONS",
955
+ "HEAD"
956
+ ], cr = {
957
+ audit: "request",
958
+ cacheReads: "request",
959
+ metadata: "request",
960
+ policy: "static",
961
+ route: "static",
962
+ scripts: "request"
963
+ };
964
+ function ur(e) {
965
+ return new URL(e.url).pathname === ht;
966
+ }
967
+ async function lr(e, t) {
968
+ const n = new URL(t.url), r = await fr(
969
+ e,
970
+ n.searchParams.get("path") || "/",
971
+ t
972
+ ), o = n.searchParams.get("format") === "json";
973
+ return new Response(
974
+ o ? tr(r) : yr(r),
975
+ {
976
+ headers: {
977
+ "cache-control": "no-store",
978
+ // The panel is a side channel. It declares its own policy, so the
979
+ // policy of the application stays unchanged. The panel runs no script.
980
+ "content-security-policy": "default-src 'none'; base-uri 'none'; form-action 'self'; style-src 'unsafe-inline'",
981
+ "content-type": o ? "application/json; charset=utf-8" : "text/html; charset=utf-8",
982
+ "x-robots-tag": "noindex"
983
+ }
984
+ }
985
+ );
986
+ }
987
+ async function fr(e, t, n) {
988
+ const r = new URL(n.url).origin, o = new URL(t, r), i = o.pathname, s = new Request(o, { headers: n.headers }), a = dr(e, i);
989
+ if (!a) {
990
+ const h = await we(
991
+ e,
992
+ { fileSegments: [] },
993
+ {},
994
+ void 0
995
+ );
996
+ return Ce({
997
+ cacheReads: [],
998
+ kind: "unmatched",
999
+ method: "GET",
1000
+ pathname: i,
1001
+ policy: h,
1002
+ request: s,
1003
+ scripts: []
1004
+ });
1005
+ }
1006
+ const c = await a.route.load(), u = pr(c), l = c[u], d = await we(
1007
+ e,
1008
+ a.route,
1009
+ c,
1010
+ l
1011
+ ), f = [], b = l?.kind === "page" ? await _t(
1012
+ e,
1013
+ i,
1014
+ s,
1015
+ void 0,
1016
+ mr(f)
1017
+ ) : void 0, R = b?.status === "ready" ? b.match : void 0;
1018
+ return Ce({
1019
+ cacheReads: f,
1020
+ cors: l && l.kind !== "page" ? l.cors : void 0,
1021
+ kind: l?.kind === "page" ? "page" : "resource",
1022
+ metadata: R?.metadata,
1023
+ method: u,
1024
+ pathname: i,
1025
+ policy: d,
1026
+ request: s,
1027
+ route: {
1028
+ file: a.route.file,
1029
+ groups: a.route.fileSegments.filter(Vt),
1030
+ layouts: e.layouts.filter((h) => ie(h.fileSegments, a.route.fileSegments)).map((h) => h.file),
1031
+ methods: gt.filter((h) => c[h]),
1032
+ middlewares: e.middlewares.filter((h) => ie(h.fileSegments, a.route.fileSegments)).map((h) => h.file),
1033
+ params: a.path,
1034
+ pattern: Lt(a.route.segments),
1035
+ policies: e.policies.filter((h) => ie(h.fileSegments, a.route.fileSegments)).map((h) => h.file),
1036
+ render: R?.render.mode
1037
+ },
1038
+ scripts: R?.scripts ?? []
1039
+ });
1040
+ }
1041
+ function Ce(e) {
1042
+ const t = e.kind === "page", n = t && Bt(e.policy.document) ? ee() : void 0, r = e.scripts.map((s) => ({
1043
+ ...s,
1044
+ nonce: s.nonce ?? n
1045
+ })), o = {
1046
+ headers: { nonce: n, request: e.request },
1047
+ policy: e.policy.document ?? {},
1048
+ scriptDependencies: !0
1049
+ };
1050
+ return {
1051
+ audit: Se({
1052
+ document: t ? { ...o, scripts: r } : void 0,
1053
+ route: {
1054
+ // A path that matches no route file has no access declaration to
1055
+ // report, so the audit says nothing about its authorization.
1056
+ access: e.kind === "unmatched" ? void 0 : e.policy.access,
1057
+ cors: e.cors,
1058
+ method: e.method,
1059
+ security: e.policy.security
1060
+ }
1061
+ }),
1062
+ // A nonce makes a document unique for each response. The request handler
1063
+ // therefore replaces the cache directives of the application.
1064
+ cacheControl: n ? "private, no-store" : void 0,
1065
+ cacheReads: e.cacheReads,
1066
+ kind: e.kind,
1067
+ metadata: e.metadata,
1068
+ method: e.method,
1069
+ nonce: n,
1070
+ pathname: e.pathname,
1071
+ policy: e.policy,
1072
+ resolutions: cr,
1073
+ route: e.route,
1074
+ scripts: r.map((s) => ({
1075
+ // One audit for each script gives the status of that script alone. The
1076
+ // panel reads the same code path that the complete audit reads.
1077
+ findings: Se({
1078
+ document: { ...o, scripts: [s] }
1079
+ }).findings,
1080
+ integrity: s.integrity,
1081
+ nonce: s.nonce,
1082
+ purpose: s.purpose,
1083
+ src: s.src,
1084
+ strategy: s.strategy
1085
+ })),
1086
+ version: ar
1087
+ };
1088
+ }
1089
+ function dr(e, t) {
1090
+ try {
1091
+ return Ye(e.routes, t);
1092
+ } catch (n) {
1093
+ if (n instanceof Wt)
1094
+ return null;
1095
+ throw n;
1096
+ }
1097
+ }
1098
+ function pr(e) {
1099
+ return gt.find((t) => e[t]) ?? "GET";
1100
+ }
1101
+ function mr(e) {
1102
+ const t = zt();
1103
+ return {
1104
+ get: async (n) => (e.push({
1105
+ key: Ut(n.key),
1106
+ scope: n.scope ?? "request",
1107
+ staleWhileRevalidate: Ae(n.staleWhileRevalidate),
1108
+ tags: (n.tags ?? []).map(Jt),
1109
+ ttl: Ae(n.ttl)
1110
+ }), await t.get(n)),
1111
+ invalidateKey: t.invalidateKey,
1112
+ invalidateTags: t.invalidateTags
1113
+ };
1114
+ }
1115
+ function Ae(e) {
1116
+ return e === void 0 ? void 0 : String(e);
1117
+ }
1118
+ function yr(e) {
1119
+ return `<!doctype html>
1120
+ <html lang="en">
1121
+ <head>
1122
+ <meta charset="utf-8" />
1123
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
1124
+ <title>Demiurge route audit</title>
1125
+ <style>${hr}</style>
1126
+ </head>
1127
+ <body>
1128
+ <h1>Demiurge route audit</h1>
1129
+ <form method="get" action="${ht}">
1130
+ <label for="path">Path</label>
1131
+ <input id="path" name="path" value="${p(e.pathname)}" />
1132
+ <button type="submit">Audit</button>
1133
+ </form>
1134
+ ${gr(e)}
1135
+ ${vr(e.audit.findings)}
1136
+ ${br(e.audit.headers)}
1137
+ ${wr(e)}
1138
+ ${Sr(e.metadata)}
1139
+ ${$r(e.scripts)}
1140
+ ${Rr(e)}
1141
+ <p class="footer">
1142
+ The development server serves this panel. A production build and a static
1143
+ export do not contain it.
1144
+ </p>
1145
+ </body>
1146
+ </html>
1147
+ `;
1148
+ }
1149
+ const hr = `
1150
+ :root { color-scheme: light dark; }
1151
+ body {
1152
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1153
+ line-height: 1.5;
1154
+ margin: 0 auto;
1155
+ max-width: 60rem;
1156
+ padding: 2rem 1rem;
1157
+ }
1158
+ h1 { font-size: 1.25rem; }
1159
+ h2 { font-size: 1rem; margin-bottom: 0.25rem; }
1160
+ form { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
1161
+ input { flex: 1; padding: 0.25rem 0.5rem; }
1162
+ section { border-top: 1px solid currentColor; padding: 0.75rem 0; }
1163
+ table { border-collapse: collapse; width: 100%; }
1164
+ td, th { padding: 0.25rem 0.5rem 0.25rem 0; text-align: left; vertical-align: top; }
1165
+ th { white-space: nowrap; width: 12rem; }
1166
+ ul { margin: 0; padding-left: 1.25rem; }
1167
+ .empty { opacity: 0.7; }
1168
+ .error { font-weight: 700; }
1169
+ .footer { opacity: 0.7; }
1170
+ `;
1171
+ function gr(e) {
1172
+ if (!e.route)
1173
+ return N(
1174
+ "Route",
1175
+ `<p class="empty">No route matches ${p(e.pathname)}.</p>`
1176
+ );
1177
+ const t = e.route;
1178
+ return N(
1179
+ "Route",
1180
+ V([
1181
+ ["Pathname", p(e.pathname)],
1182
+ ["Pattern", p(t.pattern)],
1183
+ ["File", p(t.file)],
1184
+ ["Kind", p(e.kind)],
1185
+ ["Method", p(e.method)],
1186
+ ["Methods", p(t.methods.join(", "))],
1187
+ ["Render mode", t.render ? p(t.render) : C()],
1188
+ ["Path values", Er(t.params)],
1189
+ ["Route groups", L(t.groups)],
1190
+ ["Layouts", L(t.layouts)],
1191
+ ["Policies", L(t.policies)],
1192
+ ["Middleware", L(t.middlewares)]
1193
+ ])
1194
+ );
1195
+ }
1196
+ function vr(e) {
1197
+ return e.length === 0 ? N("Findings", '<p class="empty">No findings.</p>') : N(
1198
+ "Findings",
1199
+ `<ul>${e.map(vt).join("")}</ul>`
1200
+ );
1201
+ }
1202
+ function vt(e) {
1203
+ return `<li${e.severity === "error" ? ' class="error"' : ""}>${p(e.severity)}: ${p(e.message)} <code>${p(e.code)}</code></li>`;
1204
+ }
1205
+ function br(e) {
1206
+ const t = Object.keys(e).sort();
1207
+ return t.length === 0 ? N(
1208
+ "Response headers",
1209
+ '<p class="empty">The response carries no document header.</p>'
1210
+ ) : N(
1211
+ "Response headers",
1212
+ V(t.map((n) => [n, p(e[n])]))
1213
+ );
1214
+ }
1215
+ function wr(e) {
1216
+ const t = {
1217
+ cors: e.audit.route?.cors,
1218
+ document: e.policy.document,
1219
+ security: e.policy.security
1220
+ };
1221
+ return N(
1222
+ "Effective policy",
1223
+ `<pre>${p(JSON.stringify(t, null, 2))}</pre>`
1224
+ );
1225
+ }
1226
+ function Sr(e) {
1227
+ return e ? N(
1228
+ "Metadata",
1229
+ `<pre>${p(JSON.stringify(e, null, 2))}</pre>`
1230
+ ) : N("Metadata", '<p class="empty">No document metadata.</p>');
1231
+ }
1232
+ function $r(e) {
1233
+ return e.length === 0 ? N("Scripts", '<p class="empty">No contributed scripts.</p>') : N(
1234
+ "Scripts",
1235
+ e.map(
1236
+ (t) => V([
1237
+ ["Source", p(t.src)],
1238
+ ["Strategy", p(t.strategy)],
1239
+ ["Purpose", t.purpose ? p(t.purpose) : C()],
1240
+ ["Integrity", t.integrity ? p(t.integrity) : C()],
1241
+ ["Nonce", t.nonce ? "applied" : C()],
1242
+ [
1243
+ "Policy status",
1244
+ t.findings.length === 0 ? "allowed" : `<ul>${t.findings.map(vt).join("")}</ul>`
1245
+ ]
1246
+ ])
1247
+ ).join("")
1248
+ );
1249
+ }
1250
+ function Rr(e) {
1251
+ const t = [
1252
+ [
1253
+ "Response cache-control",
1254
+ e.cacheControl ? p(e.cacheControl) : C()
1255
+ ],
1256
+ ["Nonce", e.nonce ? "required" : C()]
1257
+ ];
1258
+ return e.cacheReads.length === 0 ? N(
1259
+ "Cache behavior",
1260
+ `${V(t)}<p class="empty">The request read no cache entry.</p>`
1261
+ ) : N(
1262
+ "Cache behavior",
1263
+ `${V(t)}${e.cacheReads.map(
1264
+ (n) => V([
1265
+ ["Key", p(n.key)],
1266
+ ["Scope", p(n.scope)],
1267
+ ["Time to live", n.ttl ? p(n.ttl) : C()],
1268
+ [
1269
+ "Stale while revalidate",
1270
+ n.staleWhileRevalidate ? p(n.staleWhileRevalidate) : C()
1271
+ ],
1272
+ ["Tags", L(n.tags)]
1273
+ ])
1274
+ ).join("")}`
1275
+ );
1276
+ }
1277
+ function N(e, t) {
1278
+ return ` <section>
1279
+ <h2>${p(e)}</h2>
1280
+ ${t}
1281
+ </section>`;
1282
+ }
1283
+ function V(e) {
1284
+ return `<table><tbody>${e.map(
1285
+ ([t, n]) => `<tr><th scope="row">${p(t)}</th><td>${n}</td></tr>`
1286
+ ).join("")}</tbody></table>`;
1287
+ }
1288
+ function L(e) {
1289
+ return e.length === 0 ? C() : `<ul>${e.map((t) => `<li>${p(t)}</li>`).join("")}</ul>`;
1290
+ }
1291
+ function Er(e) {
1292
+ return L(
1293
+ Object.entries(e).map(([t, n]) => `${t} = ${String(n)}`)
1294
+ );
1295
+ }
1296
+ function C() {
1297
+ return '<span class="empty">none</span>';
1298
+ }
1299
+ function p(e) {
1300
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
1301
+ }
1302
+ const re = "virtual:demiurge/client-entry", de = `/@id/${re}`, se = `\0${re}`, bt = "virtual:demiurge/server-entry", Te = `\0${bt}`, Fe = ".demiurge/route-manifest.d.ts";
1303
+ function ko(e = {}) {
1304
+ e.locales && (e = { ...e, locales: qt(e.locales) });
1305
+ let t = process.cwd(), n = !1;
1306
+ const r = gn(e.env), o = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), s = `demiurge-${ee()}`;
1307
+ return {
1308
+ api: {
1309
+ demiurge: !0,
1310
+ fonts: e.fonts,
1311
+ images: e.images,
1312
+ staticDeployment: e.static?.deployment,
1313
+ staticFileHeaders: e.static?.headers
1314
+ },
1315
+ enforce: "post",
1316
+ name: "demiurge",
1317
+ config(a, c) {
1318
+ return Ar(a, c, s);
1319
+ },
1320
+ configResolved(a) {
1321
+ t = a.root, n = a.command === "build", n || zr(e);
1322
+ },
1323
+ resolveId(a) {
1324
+ return a === re ? se : a === bt ? Te : null;
1325
+ },
1326
+ load(a) {
1327
+ return a === se ? Wr(t, e) : a === Te ? Br(t, e) : null;
1328
+ },
1329
+ transform: {
1330
+ order: "post",
1331
+ handler(a, c, u) {
1332
+ if (u?.ssr || _r(i, n, t, a, c), n && !u?.ssr && Tr(o, r, a, c), !kr(t, e, c))
1333
+ return null;
1334
+ if (u?.ssr)
1335
+ return n ? null : xr(a, c);
1336
+ const l = Or(a);
1337
+ return l === a ? null : { code: l, map: null };
1338
+ }
1339
+ },
1340
+ generateBundle(a, c) {
1341
+ const u = Object.values(c).find(
1342
+ (f) => f.type === "chunk" && f.isEntry && f.facadeModuleId === se
1343
+ );
1344
+ if (!u)
1345
+ return;
1346
+ const l = Object.values(c).filter(
1347
+ (f) => f.type === "asset" && f.fileName.endsWith(".css")
1348
+ ).map((f) => `/${f.fileName}`), d = `/${u.fileName}`;
1349
+ this.emitFile({
1350
+ fileName: "index.html",
1351
+ source: ao({
1352
+ entrySrc: d,
1353
+ lang: e.document?.lang,
1354
+ styles: l,
1355
+ title: e.document?.title
1356
+ }),
1357
+ type: "asset"
1358
+ }), this.emitFile({
1359
+ fileName: "demiurge-manifest.json",
1360
+ source: JSON.stringify({ clientEntry: d, styles: l }, null, 2),
1361
+ type: "asset"
1362
+ });
1363
+ },
1364
+ buildEnd() {
1365
+ const a = Fr({
1366
+ moduleIds: [...this.getModuleIds()],
1367
+ moduleInfo: (u) => this.getModuleInfo(u),
1368
+ references: o,
1369
+ root: t,
1370
+ serverEnvKeys: r
1371
+ });
1372
+ a.length && this.error(bn(a));
1373
+ const c = Lr({
1374
+ markers: i,
1375
+ moduleIds: [...this.getModuleIds()],
1376
+ moduleInfo: (u) => this.getModuleInfo(u),
1377
+ root: t
1378
+ });
1379
+ c.length && this.error(xn(c));
1380
+ },
1381
+ async buildStart() {
1382
+ if (o.clear(), i.clear(), n) {
1383
+ await ro(t, e);
1384
+ const a = await qe(t, e), c = a.filter(
1385
+ (u) => u.severity === "error"
1386
+ );
1387
+ for (const u of a)
1388
+ u.severity !== "error" && this.warn(me(u));
1389
+ if (c.length)
1390
+ throw new Error(yo(c));
1391
+ }
1392
+ e.typedRoutes && await Ue(t, e);
1393
+ },
1394
+ configureServer(a) {
1395
+ const c = async () => {
1396
+ const w = await qe(a.config.root, e);
1397
+ for (const S of w)
1398
+ a.config.logger.warn(me(S));
1399
+ };
1400
+ let u, l = Promise.resolve();
1401
+ const d = () => {
1402
+ l = l.then(c).catch(() => {
1403
+ });
1404
+ }, f = () => {
1405
+ u && clearTimeout(u), u = setTimeout(() => {
1406
+ u = void 0, d();
1407
+ }, fo), u.unref?.();
1408
+ };
1409
+ if (a.httpServer?.once("close", () => {
1410
+ u && (clearTimeout(u), u = void 0);
1411
+ }), d(), e.typedRoutes) {
1412
+ const w = O(
1413
+ a.config.root,
1414
+ e.routesDir ?? "src/routes"
1415
+ ), S = () => {
1416
+ Ue(a.config.root, e).catch(
1417
+ ($) => {
1418
+ a.config.logger.error(
1419
+ $ instanceof Error ? $.message : String($)
1420
+ );
1421
+ }
1422
+ );
1423
+ };
1424
+ S(), a.watcher.add(w), a.watcher.on("add", ($) => {
1425
+ Q(w, $) && (S(), f());
1426
+ }), a.watcher.on("change", ($) => {
1427
+ Q(w, $) && (S(), f());
1428
+ }), a.watcher.on("unlink", ($) => {
1429
+ Q(w, $) && (S(), f());
1430
+ });
1431
+ } else {
1432
+ const w = O(
1433
+ a.config.root,
1434
+ e.routesDir ?? "src/routes"
1435
+ );
1436
+ a.watcher.add(w);
1437
+ for (const S of ["add", "change", "unlink"])
1438
+ a.watcher.on(S, ($) => {
1439
+ Q(w, $) && f();
1440
+ });
1441
+ }
1442
+ const b = Kr(e), R = Gr(a, e), h = Xt({
1443
+ fonts: e.fonts,
1444
+ root: a.config.root
1445
+ });
1446
+ return a.middlewares.use(async (w, S, $) => {
1447
+ try {
1448
+ let x;
1449
+ try {
1450
+ x = $e(w, {
1451
+ // Vite performs its own configured host allowlist check before
1452
+ // Demiurge's middleware runs. Production Node listeners require
1453
+ // an explicit application allowlist instead.
1454
+ allowedHosts: [w.headers.host ?? "localhost"]
1455
+ });
1456
+ } catch (X) {
1457
+ if (X instanceof Re) {
1458
+ Ee(S);
1459
+ return;
1460
+ }
1461
+ throw X;
1462
+ }
1463
+ if (b && ur(x)) {
1464
+ const X = await ae(
1465
+ a,
1466
+ w,
1467
+ O(a.config.root, e.routesDir ?? "src/routes")
1468
+ );
1469
+ await U(
1470
+ S,
1471
+ await lr(X, x)
1472
+ );
1473
+ return;
1474
+ }
1475
+ const B = await h(x);
1476
+ if (B) {
1477
+ await U(S, B);
1478
+ return;
1479
+ }
1480
+ const z = await R(x);
1481
+ if (z) {
1482
+ await U(S, z);
1483
+ return;
1484
+ }
1485
+ const G = O(
1486
+ a.config.root,
1487
+ e.routesDir ?? "src/routes"
1488
+ ), Y = await ae(a, w, G), J = Le(
1489
+ a,
1490
+ s
1491
+ ), oe = await uo(
1492
+ Y,
1493
+ x,
1494
+ Yr(e, J.transform)
1495
+ );
1496
+ if (oe === "next") {
1497
+ $();
1498
+ return;
1499
+ }
1500
+ We(oe, J.nonce), await U(S, oe);
1501
+ } catch (x) {
1502
+ $(x);
1503
+ }
1504
+ }), () => {
1505
+ a.middlewares.use(async (w, S, $) => {
1506
+ try {
1507
+ let x;
1508
+ try {
1509
+ x = $e(w, {
1510
+ allowedHosts: [w.headers.host ?? "localhost"]
1511
+ });
1512
+ } catch (J) {
1513
+ if (J instanceof Re) {
1514
+ Ee(S);
1515
+ return;
1516
+ }
1517
+ throw J;
1518
+ }
1519
+ const B = O(
1520
+ a.config.root,
1521
+ e.routesDir ?? "src/routes"
1522
+ ), z = await ae(a, w, B);
1523
+ no(z, B);
1524
+ const G = Le(
1525
+ a,
1526
+ s
1527
+ ), Y = await Ht(
1528
+ z,
1529
+ x,
1530
+ to(e, G.transform)
1531
+ );
1532
+ We(
1533
+ Y,
1534
+ G.nonce
1535
+ ), await U(S, Y);
1536
+ } catch (x) {
1537
+ $(x);
1538
+ }
1539
+ });
1540
+ };
1541
+ }
1542
+ };
1543
+ }
1544
+ function xr(e, t) {
1545
+ if (!e.includes("import.meta"))
1546
+ return null;
1547
+ const n = K(e), r = E(n.body).find(
1548
+ (u) => u.type === "ImportDeclaration" && E(u.specifiers).some(
1549
+ (l) => v(l.local)?.type === "Identifier" && v(l.local)?.name === "meta"
1550
+ )
1551
+ ), o = r && E(r.specifiers).find(
1552
+ (u) => v(u.local)?.type === "Identifier" && v(u.local)?.name === "meta"
1553
+ ), i = o && v(o.local);
1554
+ if (!r || !o || !i)
1555
+ return null;
1556
+ let s = "__demiurge_imported_meta__";
1557
+ for (; new RegExp(`\\b${s}\\b`).test(e); )
1558
+ s += "_";
1559
+ const a = new Ot(e), c = v(o.imported);
1560
+ return a.overwrite(
1561
+ i.start,
1562
+ i.end,
1563
+ c?.start === i.start ? `meta as ${s}` : s
1564
+ ), a.appendLeft(r.end, `
1565
+ const meta = ${s};`), {
1566
+ code: a.toString(),
1567
+ map: a.generateMap({
1568
+ hires: "boundary",
1569
+ includeContent: !0,
1570
+ source: t
1571
+ })
1572
+ };
1573
+ }
1574
+ function Or(e) {
1575
+ const t = K(e), n = [], r = Nr(t), o = Pr(t), i = Dr(t), s = [];
1576
+ q(t, (u) => {
1577
+ if (u.type === "ImportDeclaration" && jr(u)) {
1578
+ s.push(u);
1579
+ return;
1580
+ }
1581
+ if (u.type !== "CallExpression" || !Mr(u.callee))
1582
+ return;
1583
+ const l = E(u.arguments)[0];
1584
+ if (l?.type === "ObjectExpression")
1585
+ for (const d of E(l.properties))
1586
+ d.type === "Property" && T(d.key) === "data" && n.push({ end: d.end, start: d.start });
1587
+ });
1588
+ const a = [
1589
+ ...n,
1590
+ ...r,
1591
+ ...o,
1592
+ ...i
1593
+ ];
1594
+ if (a.length === 0)
1595
+ return e;
1596
+ const c = [...a];
1597
+ for (const u of s) {
1598
+ const l = E(u.specifiers).map((b) => v(b.local)).filter((b) => b?.type === "Identifier").map((b) => String(b.name)), d = Ir(e, [
1599
+ ...a,
1600
+ { end: u.end, start: u.start }
1601
+ ]), f = l.find(
1602
+ (b) => new RegExp(`\\b${wt(b)}\\b`).test(d)
1603
+ );
1604
+ if (f)
1605
+ throw new Error(
1606
+ `Server-only import ${JSON.stringify(f)} is used by client route code. Move that use into page data, a document contribution, or a client-safe module.`
1607
+ );
1608
+ c.push({ end: u.end, start: u.start });
1609
+ }
1610
+ return Cr(e, c, (u) => n.includes(u) ? "data: undefined" : r.includes(u) || o.includes(u) ? "undefined" : i.find((l) => l === u)?.replacement ?? "");
1611
+ }
1612
+ const pe = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
1613
+ function Pr(e) {
1614
+ const t = [], n = /* @__PURE__ */ new Set();
1615
+ for (const r of E(e.body)) {
1616
+ if (r.type !== "ExportNamedDeclaration") continue;
1617
+ const o = v(r.declaration);
1618
+ if (o?.type === "VariableDeclaration")
1619
+ for (const i of E(o.declarations)) {
1620
+ const s = v(i.id);
1621
+ s?.type === "Identifier" && pe.has(String(s.name)) && n.add(String(s.name));
1622
+ }
1623
+ for (const i of E(r.specifiers)) {
1624
+ const s = T(i.exported), a = T(i.local);
1625
+ s && a && pe.has(s) && n.add(a);
1626
+ }
1627
+ }
1628
+ return q(e, (r) => {
1629
+ if (r.type !== "VariableDeclarator") return;
1630
+ const o = v(r.id), i = v(r.init);
1631
+ o?.type === "Identifier" && n.has(String(o.name)) && i && t.push({ end: i.end, start: i.start });
1632
+ }), t;
1633
+ }
1634
+ function Dr(e) {
1635
+ const t = [];
1636
+ for (const n of E(e.body)) {
1637
+ if (n.type !== "ExportNamedDeclaration") continue;
1638
+ const r = v(n.source)?.value;
1639
+ if (typeof r != "string") continue;
1640
+ const o = [], i = [];
1641
+ for (const c of E(n.specifiers)) {
1642
+ const u = T(c.exported), l = T(c.local);
1643
+ !u || !l || (pe.has(u) ? i.push(u) : o.push(l === u ? l : `${l} as ${u}`));
1644
+ }
1645
+ if (i.length === 0) continue;
1646
+ const s = o.length > 0 ? `export { ${o.join(", ")} } from ${JSON.stringify(r)};
1647
+ ` : "", a = i.map((c) => `export const ${c} = undefined;`).join(`
1648
+ `);
1649
+ t.push({
1650
+ end: n.end,
1651
+ replacement: `${s}${a}`,
1652
+ start: n.start
1653
+ });
1654
+ }
1655
+ return t;
1656
+ }
1657
+ const _e = /* @__PURE__ */ new Set(["links", "metadata", "scripts"]);
1658
+ function Nr(e) {
1659
+ const t = /* @__PURE__ */ new Set();
1660
+ for (const r of E(e.body)) {
1661
+ if (r.type !== "ExportNamedDeclaration") continue;
1662
+ const o = v(r.declaration);
1663
+ if (o?.type === "VariableDeclaration")
1664
+ for (const i of E(o.declarations)) {
1665
+ const s = v(i.id);
1666
+ s?.type === "Identifier" && _e.has(String(s.name)) && t.add(String(s.name));
1667
+ }
1668
+ for (const i of E(r.specifiers)) {
1669
+ const s = T(i.exported), a = T(i.local);
1670
+ s && a && _e.has(s) && t.add(a);
1671
+ }
1672
+ }
1673
+ const n = [];
1674
+ return q(e, (r) => {
1675
+ if (r.type !== "VariableDeclarator") return;
1676
+ const o = v(r.id), i = v(r.init);
1677
+ o?.type === "Identifier" && t.has(String(o.name)) && i && n.push({ end: i.end, start: i.start });
1678
+ }), n;
1679
+ }
1680
+ function kr(e, t, n) {
1681
+ const r = n.split("?", 1)[0] ?? n, o = O(e, t.routesDir ?? "src/routes"), i = I(o, r);
1682
+ return i !== "" && i !== ".." && !i.startsWith(`..${A}`);
1683
+ }
1684
+ function q(e, t) {
1685
+ if (!e || typeof e != "object") return;
1686
+ if (Array.isArray(e)) {
1687
+ for (const r of e) q(r, t);
1688
+ return;
1689
+ }
1690
+ const n = e;
1691
+ if (typeof n.type == "string") {
1692
+ t(n);
1693
+ for (const [r, o] of Object.entries(n))
1694
+ (/* @__PURE__ */ new Set(["end", "loc", "start", "type"])).has(r) || q(o, t);
1695
+ }
1696
+ }
1697
+ function v(e) {
1698
+ return e && typeof e == "object" && "type" in e ? e : void 0;
1699
+ }
1700
+ function E(e) {
1701
+ return Array.isArray(e) ? e.map(v).filter((t) => !!t) : [];
1702
+ }
1703
+ function Mr(e) {
1704
+ const t = v(e);
1705
+ return t?.type === "Identifier" ? t.name === "page" : t?.type === "MemberExpression" && T(t.property) === "page";
1706
+ }
1707
+ function T(e) {
1708
+ const t = v(e);
1709
+ return t?.type === "Identifier" || t?.type === "Literal" ? String(t.name ?? t.value) : void 0;
1710
+ }
1711
+ function jr(e) {
1712
+ const t = v(e.source)?.value;
1713
+ return typeof t == "string" && /(?:^|[/.-])server(?:[/.-]|$)/.test(t);
1714
+ }
1715
+ function Ir(e, t) {
1716
+ const n = [...e];
1717
+ for (const { end: r, start: o } of t)
1718
+ n.fill(" ", o, r);
1719
+ return n.join("");
1720
+ }
1721
+ function Cr(e, t, n) {
1722
+ return [...t].sort((r, o) => o.start - r.start).reduce(
1723
+ (r, o) => `${r.slice(0, o.start)}${n(o)}${r.slice(o.end)}`,
1724
+ e
1725
+ );
1726
+ }
1727
+ function wt(e) {
1728
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1729
+ }
1730
+ function Ar(e, t, n) {
1731
+ return {
1732
+ appType: "custom",
1733
+ build: {
1734
+ assetsInlineLimit: e.build?.assetsInlineLimit ?? 0,
1735
+ ...t.isSsrBuild && e.build?.target === void 0 && e.ssr?.target !== "webworker" ? { target: "node22.13" } : {},
1736
+ rollupOptions: {
1737
+ input: e.build?.rollupOptions?.input ?? re
1738
+ }
1739
+ },
1740
+ ...t.command === "serve" ? {
1741
+ html: { cspNonce: n },
1742
+ ssr: { external: [F] }
1743
+ } : {}
1744
+ };
1745
+ }
1746
+ function Tr(e, t, n, r) {
1747
+ if (!t.size || r.includes("/node_modules/") || r.startsWith("\0")) return;
1748
+ const o = vn(n, t.keys());
1749
+ o.length && e.set(r, o);
1750
+ }
1751
+ function Fr(e) {
1752
+ const { moduleIds: t, moduleInfo: n, references: r, root: o, serverEnvKeys: i } = e;
1753
+ if (!r.size) return [];
1754
+ const s = t.filter((u) => n(u)?.isEntry), a = (u) => {
1755
+ const l = n(u);
1756
+ return l ? [...l.importedIds, ...l.dynamicallyImportedIds] : [];
1757
+ }, c = [];
1758
+ for (const u of [...r.keys()].sort()) {
1759
+ const d = s.map((f) => Qe(f, u, a)).filter((f) => !!f).sort((f, b) => f.length - b.length)[0];
1760
+ if (d)
1761
+ for (const f of r.get(u) ?? [])
1762
+ c.push({
1763
+ code: i.get(f)?.sensitive ? "client-secret" : "client-server-only",
1764
+ importPath: d.map((b) => H(o, b)),
1765
+ key: f,
1766
+ module: H(o, u)
1767
+ });
1768
+ }
1769
+ return c;
1770
+ }
1771
+ function H(e, t) {
1772
+ const n = t.startsWith("\0") ? t.slice(1) : t;
1773
+ return n.startsWith(e) && I(e, n) || n;
1774
+ }
1775
+ function _r(e, t, n, r, o) {
1776
+ if (!(o.includes("/node_modules/") || o.startsWith("\0")) && En(r)) {
1777
+ if (t) {
1778
+ e.add(o);
1779
+ return;
1780
+ }
1781
+ throw new Error(On(H(n, o)));
1782
+ }
1783
+ }
1784
+ function Lr(e) {
1785
+ const { markers: t, moduleIds: n, moduleInfo: r, root: o } = e;
1786
+ if (!t.size) return [];
1787
+ const i = n.filter((c) => r(c)?.isEntry), s = (c) => {
1788
+ const u = r(c);
1789
+ return u ? [...u.importedIds, ...u.dynamicallyImportedIds] : [];
1790
+ }, a = [];
1791
+ for (const c of [...t].sort()) {
1792
+ const l = i.map((d) => Qe(d, c, s)).filter((d) => !!d).sort((d, f) => d.length - f.length)[0];
1793
+ l && a.push({
1794
+ importPath: l.map((d) => H(o, d)),
1795
+ module: H(o, c)
1796
+ });
1797
+ }
1798
+ return a;
1799
+ }
1800
+ function Vr(e = {}, t = process.env) {
1801
+ const n = Object.entries(e.env ?? {}).filter(([, a]) => a.client);
1802
+ if (!n.length) return "";
1803
+ const r = n.filter(
1804
+ ([a, c]) => !c.optional && !t[a]
1805
+ );
1806
+ if (r.length)
1807
+ throw new Error(
1808
+ [
1809
+ "Demiurge stopped the build. The environment of the build does not have a required client variable.",
1810
+ ...r.map(([a]) => ` variable: ${a}`),
1811
+ " The build inlines the value of a client variable. Give the value to the build."
1812
+ ].join(`
1813
+ `)
1814
+ );
1815
+ const o = n.filter(([a]) => t[a] !== void 0).flatMap(([a, c]) => {
1816
+ const u = t[a];
1817
+ try {
1818
+ return c.parse(a, u), [];
1819
+ } catch (l) {
1820
+ return [{
1821
+ key: a,
1822
+ message: l instanceof Error ? l.message : `Environment variable ${a} is invalid.`
1823
+ }];
1824
+ }
1825
+ });
1826
+ if (o.length)
1827
+ throw new Error(
1828
+ [
1829
+ "Demiurge stopped the build. The environment of the build has an invalid client variable.",
1830
+ ...o.map(({ key: a, message: c }) => ` variable: ${a}
1831
+ ${c}`)
1832
+ ].join(`
1833
+ `)
1834
+ );
1835
+ const i = Xe(Object.fromEntries(n)), s = Object.fromEntries(
1836
+ n.map(([a]) => [a, t[a]]).filter(([, a]) => a !== void 0)
1837
+ );
1838
+ return `
1839
+ // The build put these values in the browser bundle. The schema declares each
1840
+ // one as a client variable.
1841
+ unstable_startEnvironment(${JSON.stringify(i)}, { source: ${JSON.stringify(s)} });
1842
+ `;
1843
+ }
1844
+ function Wr(e, t = {}, n = process.env) {
1845
+ const r = t.routesDir ?? "src/routes", o = Hr(e, t), i = Vr(t, n);
1846
+ return `import { hydrateFileRouter${i ? ", unstable_startEnvironment" : ""} } from "${F}";
1847
+ ${o}
1848
+ ${i}
1849
+ ${St(r, {
1850
+ exportRoutes: !1,
1851
+ includeServerOnly: !1
1852
+ })}
1853
+
1854
+ void hydrateFileRouter({ routes${t.locales ? `, locales: ${JSON.stringify(t.locales)}` : ""} });
1855
+ `;
1856
+ }
1857
+ function Br(e, t = {}) {
1858
+ const n = t.routesDir ?? "src/routes", r = !!(t.env && Object.keys(t.env).length), o = r ? ", unstable_startEnvironment" : "", i = r ? `
1859
+ // The framework validates the declared environment before the server accepts
1860
+ // traffic. A required variable that is absent or invalid stops the start. A
1861
+ // deferred variable validates on its first server access.
1862
+ export const env = unstable_startEnvironment(${JSON.stringify(Xe(t.env ?? {}))}).values;
1863
+ ` : "";
1864
+ return `import { createRequestHandler${o} } from "${F}";
1865
+ ${i}
1866
+ ${St(n, {
1867
+ exportRoutes: !0,
1868
+ includeServerOnly: !0,
1869
+ eagerModules: !0
1870
+ })}
1871
+
1872
+ export function createHandler(options = {}) {
1873
+ const { clientEntry, lang, locales, styles, title, ...handlerOptions } = options;
1874
+
1875
+ return createRequestHandler({
1876
+ ...handlerOptions,
1877
+ routes,
1878
+ routeModules,
1879
+ locales: locales ?? ${JSON.stringify(t.locales)},
1880
+ ssr: {
1881
+ clientEntry,
1882
+ lang: lang ?? ${JSON.stringify(t.document?.lang)},
1883
+ styles,
1884
+ title: title ?? ${JSON.stringify(t.document?.title)},
1885
+ },
1886
+ });
1887
+ }
1888
+ `;
1889
+ }
1890
+ function zr(e) {
1891
+ !e.env || !Object.keys(e.env).length || Yt(e.env);
1892
+ }
1893
+ function St(e, {
1894
+ exportRoutes: t,
1895
+ eagerModules: n = !1,
1896
+ includeServerOnly: r
1897
+ }) {
1898
+ const o = Ur(e, r), i = qr(e);
1899
+ return n ? `const eagerRouteModules = import.meta.glob(${JSON.stringify(o)}, { eager: true });
1900
+ const routePrefix = ${JSON.stringify(i)};
1901
+ export const routeModules = Object.fromEntries(
1902
+ Object.entries(eagerRouteModules).map(([file, module]) => [
1903
+ \`./routes/\${file.slice(routePrefix.length)}\`,
1904
+ module,
1905
+ ]),
1906
+ );
1907
+ ${t ? "export " : ""}const routes = Object.fromEntries(
1908
+ Object.entries(routeModules).map(([file, module]) => [
1909
+ file,
1910
+ async () => module,
1911
+ ]),
1912
+ );` : `const routeModules = import.meta.glob(${JSON.stringify(o)});
1913
+ const routePrefix = ${JSON.stringify(i)};
1914
+ ${t ? "export " : ""}const routes = Object.fromEntries(
1915
+ Object.entries(routeModules).map(([file, load]) => [
1916
+ \`./routes/\${file.slice(routePrefix.length)}\`,
1917
+ load,
1918
+ ]),
1919
+ );`;
1920
+ }
1921
+ const Jr = ["@middleware.ts", "@policy.ts"];
1922
+ function Ur(e, t) {
1923
+ const n = `/${e.replace(/^\/|\/$/g, "")}`, r = [`${n}/**/*.{ts,tsx}`];
1924
+ return t || r.push(
1925
+ ...Jr.flatMap((o) => [
1926
+ `!${n}/${o}`,
1927
+ `!${n}/**/${o}`
1928
+ ])
1929
+ ), r;
1930
+ }
1931
+ function qr(e) {
1932
+ return `/${e.replace(/^\/|\/$/g, "")}/`;
1933
+ }
1934
+ function Hr(e, t) {
1935
+ if (t.styles === !1)
1936
+ return "";
1937
+ const n = t.styles ?? "src/styles.css", r = O(e, n);
1938
+ return ye(r) ? `import ${JSON.stringify(`/${n.replace(/^\/+/, "")}`)};` : "";
1939
+ }
1940
+ function Kr(e) {
1941
+ return e.devtools !== !1 && process.env.NODE_ENV !== "production";
1942
+ }
1943
+ function Gr(e, t) {
1944
+ const n = e.config.publicDir, r = t.images?.optimizerPath ?? "/_demiurge/image";
1945
+ return n ? Zt({
1946
+ policy: t.images,
1947
+ resolveVariant: (o) => en(o, r),
1948
+ root: n
1949
+ }) : async () => null;
1950
+ }
1951
+ function Yr(e, t) {
1952
+ return {
1953
+ dev: !0,
1954
+ ssr: Rt(e),
1955
+ transformDocument: t,
1956
+ renderPage: async (n, r) => {
1957
+ if (n.render.mode === "streaming")
1958
+ return await Qt(n, {
1959
+ ...r,
1960
+ clientEntry: de,
1961
+ transformDocument: t
1962
+ });
1963
+ const o = await t(
1964
+ Nt(n, {
1965
+ ...r,
1966
+ clientEntry: de
1967
+ })
1968
+ );
1969
+ return new Response(o, {
1970
+ headers: { "content-type": "text/html; charset=utf-8" }
1971
+ });
1972
+ }
1973
+ };
1974
+ }
1975
+ function Le(e, t) {
1976
+ const n = ee(), r = ee();
1977
+ return {
1978
+ nonce: n,
1979
+ transform: async (o) => {
1980
+ const i = Xr(o, r), s = await e.transformIndexHtml("/", i);
1981
+ return Ve(
1982
+ Ve(s, r),
1983
+ t,
1984
+ n
1985
+ );
1986
+ }
1987
+ };
1988
+ }
1989
+ function Xr(e, t) {
1990
+ const n = e.toLowerCase();
1991
+ let r = 0, o = "";
1992
+ for (; r < e.length; ) {
1993
+ const i = e.indexOf("<", r);
1994
+ if (i === -1)
1995
+ return o + e.slice(r);
1996
+ if (o += e.slice(r, i), n.startsWith("<!--", i)) {
1997
+ const u = n.indexOf("-->", i + 4), l = u === -1 ? e.length : u + 3;
1998
+ o += e.slice(i, l), r = l;
1999
+ continue;
2000
+ }
2001
+ const s = n.slice(i).match(/^<\s*(script|style|link)\b/)?.[1];
2002
+ if (!s) {
2003
+ o += "<", r = i + 1;
2004
+ continue;
2005
+ }
2006
+ const a = Zr(e, i);
2007
+ if (a === -1)
2008
+ return o + e.slice(i);
2009
+ const c = e.slice(i, a + 1);
2010
+ if (o += /(?:^|\s)nonce(?:\s|=|>)/i.test(c) ? c : Qr(c, t), r = a + 1, s === "script" || s === "style") {
2011
+ const u = n.indexOf(`</${s}`, r);
2012
+ if (u === -1)
2013
+ return o + e.slice(r);
2014
+ o += e.slice(r, u), r = u;
2015
+ }
2016
+ }
2017
+ return o;
2018
+ }
2019
+ function Zr(e, t) {
2020
+ let n;
2021
+ for (let r = t + 1; r < e.length; r++) {
2022
+ const o = e[r];
2023
+ if (n) {
2024
+ o === n && (n = void 0);
2025
+ continue;
2026
+ }
2027
+ if (o === '"' || o === "'")
2028
+ n = o;
2029
+ else if (o === ">")
2030
+ return r;
2031
+ }
2032
+ return -1;
2033
+ }
2034
+ function Qr(e, t) {
2035
+ const n = /\/\s*>$/.test(e) ? e.lastIndexOf("/") : e.length - 1;
2036
+ return `${e.slice(0, n)} nonce="${t}"${e.slice(n)}`;
2037
+ }
2038
+ function Ve(e, t, n) {
2039
+ const r = new RegExp(
2040
+ `(\\snonce\\s*=\\s*)(["'])${wt(t)}\\2`,
2041
+ "g"
2042
+ );
2043
+ return e.replace(
2044
+ r,
2045
+ n ? `$1"${n}"` : ""
2046
+ );
2047
+ }
2048
+ function We(e, t) {
2049
+ const n = e.headers.get("content-type"), r = e.headers.get("content-security-policy");
2050
+ if (!n?.toLowerCase().startsWith("text/html") || !r)
2051
+ return;
2052
+ const o = `'nonce-${t}'`, i = Be(
2053
+ r,
2054
+ ["script-src-elem", "script-src"],
2055
+ "script-src",
2056
+ o
2057
+ ), s = eo(
2058
+ i,
2059
+ ["style-src-elem", "style-src"]
2060
+ ) ? i : Be(
2061
+ i,
2062
+ ["style-src-elem", "style-src"],
2063
+ "style-src",
2064
+ o
2065
+ );
2066
+ e.headers.set("content-security-policy", s), e.headers.set("cache-control", "private, no-store");
2067
+ }
2068
+ function Be(e, t, n, r) {
2069
+ const o = e.split(";").map((l) => l.trim()), i = $t(o, t), s = o.find(
2070
+ (l) => l.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
2071
+ );
2072
+ if (i === -1 && !s) return e;
2073
+ const [a, ...c] = (i === -1 ? s : o[i]).split(/\s+/), u = [
2074
+ i === -1 ? n : a,
2075
+ .../* @__PURE__ */ new Set([
2076
+ ...c.filter((l) => l !== "'none'"),
2077
+ r
2078
+ ])
2079
+ ].join(" ");
2080
+ return i === -1 ? o.push(u) : o[i] = u, o.join("; ");
2081
+ }
2082
+ function eo(e, t) {
2083
+ const n = e.split(";").map((s) => s.trim()), r = $t(n, t), i = (r === -1 ? n.find(
2084
+ (s) => s.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
2085
+ ) : n[r])?.split(/\s+/).slice(1) ?? [];
2086
+ return i.includes("'unsafe-inline'") && !i.some((s) => /^'(?:nonce-|sha(?:256|384|512)-)/i.test(s));
2087
+ }
2088
+ function $t(e, t) {
2089
+ for (const n of t) {
2090
+ const r = e.findIndex(
2091
+ (o) => o.split(/\s+/, 1)[0]?.toLowerCase() === n
2092
+ );
2093
+ if (r !== -1) return r;
2094
+ }
2095
+ return -1;
2096
+ }
2097
+ const ze = Symbol.for("demiurge.devManifest");
2098
+ async function ae(e, t, n) {
2099
+ const r = t, o = r[ze];
2100
+ if (o)
2101
+ return o;
2102
+ const i = Gt(
2103
+ await co(e, n)
2104
+ );
2105
+ return r[ze] = i, i;
2106
+ }
2107
+ function Rt(e) {
2108
+ return {
2109
+ clientEntry: de,
2110
+ lang: e.document?.lang,
2111
+ title: e.document?.title
2112
+ };
2113
+ }
2114
+ function to(e, t) {
2115
+ return {
2116
+ ...Rt(e),
2117
+ dev: !0,
2118
+ transformDocument: t
2119
+ };
2120
+ }
2121
+ const Je = /* @__PURE__ */ new Set();
2122
+ function no(e, t) {
2123
+ Je.has(t) || e.fallbacks.notFound.some(
2124
+ (n) => n.fileSegments.length === 0
2125
+ ) || (Je.add(t), console.warn(so(Ge(t, "@not-found.tsx"))));
2126
+ }
2127
+ async function ro(e, t = {}) {
2128
+ const n = t.routesDir ?? "src/routes", r = O(e, n);
2129
+ if (!ye(r))
2130
+ return;
2131
+ const o = await ve(r);
2132
+ if (o.map(
2133
+ (a) => I(r, a).split(A).join("/")
2134
+ ).some((a) => /^@not-found\.tsx?$/.test(a)))
2135
+ return;
2136
+ const s = await oo(o);
2137
+ if (s)
2138
+ throw new Error(
2139
+ io(
2140
+ n,
2141
+ I(r, s).split(A).join("/")
2142
+ )
2143
+ );
2144
+ }
2145
+ async function oo(e) {
2146
+ for (const t of e)
2147
+ if (!I(M(t), t).startsWith("@") && ot(await Ke(t, "utf8")))
2148
+ return t;
2149
+ }
2150
+ function io(e, t) {
2151
+ return `Demiurge will not build an app with page routes and no ${e}/@not-found.tsx.
2152
+
2153
+ "${t}" declares a page, so a browser can reach a path this app does not serve. Decide what that looks like rather than shipping the framework built-in.
2154
+
2155
+ Create ${e}/@not-found.tsx:
2156
+
2157
+ export default function NotFound({ pathname }: { pathname: string }) {
2158
+ return <h1>Nothing at {pathname}</h1>;
2159
+ }
2160
+
2161
+ It renders inside the layouts above the requested path. Opt out with "export const layout = false".`;
2162
+ }
2163
+ function so(e) {
2164
+ return `Demiurge is serving its built-in 404 because ${e} does not exist.
2165
+
2166
+ Create it before building for production:
2167
+
2168
+ export default function NotFound({ pathname }: { pathname: string }) {
2169
+ return <h1>Nothing at {pathname}</h1>;
2170
+ }
2171
+ `;
2172
+ }
2173
+ function ao({
2174
+ entrySrc: e,
2175
+ lang: t,
2176
+ links: n,
2177
+ metadata: r,
2178
+ nonce: o,
2179
+ scripts: i,
2180
+ styles: s,
2181
+ title: a
2182
+ }) {
2183
+ return Dt({
2184
+ entrySrc: e,
2185
+ lang: t,
2186
+ links: n,
2187
+ metadata: r,
2188
+ nonce: o,
2189
+ scripts: i,
2190
+ styles: s,
2191
+ title: a
2192
+ });
2193
+ }
2194
+ async function Ue(e, t) {
2195
+ const n = O(e, t.routesDir ?? "src/routes"), r = O(
2196
+ e,
2197
+ typeof t.typedRoutes == "object" ? t.typedRoutes.outputFile ?? Fe : Fe
2198
+ );
2199
+ await tn({
2200
+ outputFile: r,
2201
+ routesDir: n,
2202
+ locales: t.locales?.supportedLocales,
2203
+ localeNamespaces: [
2204
+ ...Object.values(t.locales?.path?.labels ?? {}),
2205
+ ...Object.keys(t.locales?.aliases ?? {}),
2206
+ ...t.locales?.path?.reserved ?? []
2207
+ ]
2208
+ });
2209
+ }
2210
+ function Q(e, t) {
2211
+ return t.startsWith(e) && /\.tsx?$/.test(t);
2212
+ }
2213
+ async function co(e, t) {
2214
+ const n = await ve(t), r = {};
2215
+ for (const o of n) {
2216
+ const i = ho(t, o);
2217
+ r[i] = async () => await e.ssrLoadModule(o);
2218
+ }
2219
+ return r;
2220
+ }
2221
+ async function uo(e, t, n = {}) {
2222
+ const r = new URL(t.url);
2223
+ return Ye(e.routes, r.pathname) ? await Kt(e, t, n) : "next";
2224
+ }
2225
+ async function ve(e) {
2226
+ return (await He(e, {
2227
+ recursive: !0,
2228
+ withFileTypes: !0
2229
+ })).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => O(n.parentPath, n.name));
2230
+ }
2231
+ const lo = 8, fo = 50;
2232
+ async function po(e, t, n) {
2233
+ const r = new Array(e.length);
2234
+ let o = 0;
2235
+ const i = Array.from(
2236
+ { length: Math.min(t, e.length) },
2237
+ async () => {
2238
+ for (; o < e.length; ) {
2239
+ const s = o++;
2240
+ r[s] = await n(e[s]);
2241
+ }
2242
+ }
2243
+ );
2244
+ return await Promise.all(i), r;
2245
+ }
2246
+ async function mo(e, t = {}) {
2247
+ const n = O(e, t.routesDir ?? "src/routes");
2248
+ if (!ye(n))
2249
+ return { findings: [], inspections: [], routesDir: n };
2250
+ const r = await po(
2251
+ await ve(n),
2252
+ lo,
2253
+ jn
2254
+ ), o = [
2255
+ ...r.flatMap((i) => i.findings),
2256
+ ...In(n, r),
2257
+ ...Cn(n, r)
2258
+ ];
2259
+ return o.sort(
2260
+ (i, s) => i.file.localeCompare(s.file) || (i.exportName ?? "").localeCompare(s.exportName ?? "") || i.code.localeCompare(s.code)
2261
+ ), { findings: o, inspections: r, routesDir: n };
2262
+ }
2263
+ async function qe(e, t = {}) {
2264
+ return (await mo(e, t)).findings;
2265
+ }
2266
+ function yo(e) {
2267
+ return [
2268
+ "Demiurge found invalid static route policy:",
2269
+ ...e.map(me)
2270
+ ].join(`
2271
+ `);
2272
+ }
2273
+ function me(e) {
2274
+ return `${e.exportName ? `${e.file} export ${e.exportName}` : e.file}: [${e.code}] ${e.message}`;
2275
+ }
2276
+ function ho(e, t) {
2277
+ return `./routes/${I(e, t).split(A).join("/")}`;
2278
+ }
2279
+ export {
2280
+ No as A,
2281
+ tr as B,
2282
+ ht as R,
2283
+ ar as a,
2284
+ ro as b,
2285
+ Cn as c,
2286
+ Wr as d,
2287
+ Vr as e,
2288
+ co as f,
2289
+ ao as g,
2290
+ fr as h,
2291
+ Br as i,
2292
+ ot as j,
2293
+ ko as k,
2294
+ Qe as l,
2295
+ vn as m,
2296
+ gn as n,
2297
+ bn as o,
2298
+ xn as p,
2299
+ On as q,
2300
+ yo as r,
2301
+ uo as s,
2302
+ En as t,
2303
+ jn as u,
2304
+ mo as v,
2305
+ Kr as w,
2306
+ yr as x,
2307
+ Or as y,
2308
+ qe as z
2309
+ };
2310
+ //# sourceMappingURL=plugin-BZauDxRY.js.map