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

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 (232) hide show
  1. package/README.md +13 -11
  2. package/bin/demiurge.mjs +30 -12
  3. package/dist/adapter/testing.js.map +1 -1
  4. package/dist/browser/file-router.d.ts +388 -5
  5. package/dist/browser/file-router.d.ts.map +1 -1
  6. package/dist/browser/focus.d.ts +20 -0
  7. package/dist/browser/focus.d.ts.map +1 -0
  8. package/dist/browser/index.d.ts +7 -1
  9. package/dist/browser/index.d.ts.map +1 -1
  10. package/dist/browser/mutation-action.d.ts +81 -0
  11. package/dist/browser/mutation-action.d.ts.map +1 -0
  12. package/dist/chunks/document-shell-CpJnFtSC.js +36 -0
  13. package/dist/chunks/document-shell-CpJnFtSC.js.map +1 -0
  14. package/dist/chunks/env-startup-DOBYWlZD.js +257 -0
  15. package/dist/chunks/env-startup-DOBYWlZD.js.map +1 -0
  16. package/dist/chunks/{image-codec-BGTx_t5K.js → image-codec-BmzWnH6W.js} +2 -2
  17. package/dist/chunks/{image-codec-BGTx_t5K.js.map → image-codec-BmzWnH6W.js.map} +1 -1
  18. package/dist/chunks/{images-B9MqcjSA.js → images-BQ80950B.js} +99 -91
  19. package/dist/chunks/images-BQ80950B.js.map +1 -0
  20. package/dist/chunks/index-BVk9zWbe.js +832 -0
  21. package/dist/chunks/index-BVk9zWbe.js.map +1 -0
  22. package/dist/chunks/manifest-vO6c0G0W.js +19 -0
  23. package/dist/chunks/manifest-vO6c0G0W.js.map +1 -0
  24. package/dist/chunks/plugin-BQgMiHxa.js +1827 -0
  25. package/dist/chunks/plugin-BQgMiHxa.js.map +1 -0
  26. package/dist/chunks/session-store-ChModVcq.js +92 -0
  27. package/dist/chunks/session-store-ChModVcq.js.map +1 -0
  28. package/dist/chunks/static-files-ehaD1kE7.js +51 -0
  29. package/dist/chunks/static-files-ehaD1kE7.js.map +1 -0
  30. package/dist/chunks/{streaming-BQ1bykDo.js → streaming-BEbPN7Uk.js} +163 -163
  31. package/dist/chunks/streaming-BEbPN7Uk.js.map +1 -0
  32. package/dist/chunks/testing-DueXbMo4.js +4167 -0
  33. package/dist/chunks/testing-DueXbMo4.js.map +1 -0
  34. package/dist/chunks/vite-DO70kZA6.js +259 -0
  35. package/dist/chunks/vite-DO70kZA6.js.map +1 -0
  36. package/dist/cli.d.ts +17 -25
  37. package/dist/cli.d.ts.map +1 -1
  38. package/dist/cli.js +159 -124
  39. package/dist/cli.js.map +1 -1
  40. package/dist/config/define.d.ts +3 -0
  41. package/dist/config/define.d.ts.map +1 -0
  42. package/dist/config/index.d.ts +7 -0
  43. package/dist/config/index.d.ts.map +1 -0
  44. package/dist/config/index.js +78 -0
  45. package/dist/config/index.js.map +1 -0
  46. package/dist/config/load.d.ts +12 -0
  47. package/dist/config/load.d.ts.map +1 -0
  48. package/dist/config/types.d.ts +64 -0
  49. package/dist/config/types.d.ts.map +1 -0
  50. package/dist/config/validate.d.ts +9 -0
  51. package/dist/config/validate.d.ts.map +1 -0
  52. package/dist/config/vite.d.ts +12 -0
  53. package/dist/config/vite.d.ts.map +1 -0
  54. package/dist/data/cache.d.ts +10 -0
  55. package/dist/data/cache.d.ts.map +1 -1
  56. package/dist/data/idempotency.d.ts.map +1 -1
  57. package/dist/data/index.d.ts +3 -1
  58. package/dist/data/index.d.ts.map +1 -1
  59. package/dist/data/testing.d.ts.map +1 -1
  60. package/dist/data/testing.js +94 -72
  61. package/dist/data/testing.js.map +1 -1
  62. package/dist/data/tiered.d.ts +7 -0
  63. package/dist/data/tiered.d.ts.map +1 -0
  64. package/dist/deployment/testing.d.ts +25 -0
  65. package/dist/deployment/testing.d.ts.map +1 -0
  66. package/dist/deployment/testing.js +171 -0
  67. package/dist/deployment/testing.js.map +1 -0
  68. package/dist/document/deferred-scripts.d.ts.map +1 -1
  69. package/dist/document/hydration.d.ts +9 -0
  70. package/dist/document/hydration.d.ts.map +1 -1
  71. package/dist/document/index.d.ts +5 -2
  72. package/dist/document/index.d.ts.map +1 -1
  73. package/dist/document/metadata.d.ts +8 -0
  74. package/dist/document/metadata.d.ts.map +1 -1
  75. package/dist/document/navigation.d.ts +28 -0
  76. package/dist/document/navigation.d.ts.map +1 -0
  77. package/dist/document/render.d.ts +3 -1
  78. package/dist/document/render.d.ts.map +1 -1
  79. package/dist/document/seo.d.ts.map +1 -1
  80. package/dist/document/trusted-types.d.ts +10 -0
  81. package/dist/document/trusted-types.d.ts.map +1 -0
  82. package/dist/edge/assets.d.ts.map +1 -1
  83. package/dist/edge/index.js +55 -73
  84. package/dist/edge/index.js.map +1 -1
  85. package/dist/index.d.ts +15 -13
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +2078 -573
  88. package/dist/index.js.map +1 -1
  89. package/dist/internal/testing.js +11 -11
  90. package/dist/kv/index.d.ts +4 -0
  91. package/dist/kv/index.d.ts.map +1 -1
  92. package/dist/kv/index.js +180 -60
  93. package/dist/kv/index.js.map +1 -1
  94. package/dist/kv/rate-limit-store.d.ts +8 -0
  95. package/dist/kv/rate-limit-store.d.ts.map +1 -0
  96. package/dist/kv/session-store.d.ts +20 -0
  97. package/dist/kv/session-store.d.ts.map +1 -0
  98. package/dist/kv/store.d.ts.map +1 -1
  99. package/dist/manifest.d.ts +10 -0
  100. package/dist/manifest.d.ts.map +1 -0
  101. package/dist/node/http.d.ts.map +1 -1
  102. package/dist/node/image.d.ts.map +1 -1
  103. package/dist/node/index.d.ts +3 -0
  104. package/dist/node/index.d.ts.map +1 -1
  105. package/dist/node/index.js +251 -178
  106. package/dist/node/index.js.map +1 -1
  107. package/dist/node/serve.d.ts +47 -0
  108. package/dist/node/serve.d.ts.map +1 -0
  109. package/dist/node/static.d.ts.map +1 -1
  110. package/dist/node/streaming.d.ts.map +1 -1
  111. package/dist/platform/fonts.d.ts.map +1 -1
  112. package/dist/platform/image-url.d.ts.map +1 -1
  113. package/dist/platform/images.d.ts.map +1 -1
  114. package/dist/platform/index.d.ts +5 -1
  115. package/dist/platform/index.d.ts.map +1 -1
  116. package/dist/platform/observability.d.ts +2 -1
  117. package/dist/platform/observability.d.ts.map +1 -1
  118. package/dist/platform/url.d.ts +19 -0
  119. package/dist/platform/url.d.ts.map +1 -0
  120. package/dist/platform/web-vitals-client.d.ts +32 -0
  121. package/dist/platform/web-vitals-client.d.ts.map +1 -0
  122. package/dist/platform/web-vitals.d.ts +78 -0
  123. package/dist/platform/web-vitals.d.ts.map +1 -0
  124. package/dist/redis/index.d.ts +4 -0
  125. package/dist/redis/index.d.ts.map +1 -1
  126. package/dist/redis/index.js +209 -54
  127. package/dist/redis/index.js.map +1 -1
  128. package/dist/redis/rate-limit-store.d.ts +8 -0
  129. package/dist/redis/rate-limit-store.d.ts.map +1 -0
  130. package/dist/redis/session-store.d.ts +9 -0
  131. package/dist/redis/session-store.d.ts.map +1 -0
  132. package/dist/redis/store.d.ts.map +1 -1
  133. package/dist/route/index.d.ts +2 -2
  134. package/dist/route/index.d.ts.map +1 -1
  135. package/dist/route/middleware.d.ts.map +1 -1
  136. package/dist/route/mutation.d.ts +97 -0
  137. package/dist/route/mutation.d.ts.map +1 -0
  138. package/dist/route/response.d.ts.map +1 -1
  139. package/dist/route/types.d.ts +6 -1
  140. package/dist/route/types.d.ts.map +1 -1
  141. package/dist/router/index.d.ts +1 -1
  142. package/dist/router/index.d.ts.map +1 -1
  143. package/dist/router/manifest.d.ts +9 -0
  144. package/dist/router/manifest.d.ts.map +1 -1
  145. package/dist/router/navigation-data.d.ts +9 -1
  146. package/dist/router/navigation-data.d.ts.map +1 -1
  147. package/dist/routing/generate.d.ts +3 -0
  148. package/dist/routing/generate.d.ts.map +1 -1
  149. package/dist/routing/index.d.ts +3 -1
  150. package/dist/routing/index.d.ts.map +1 -1
  151. package/dist/routing/locale.d.ts +43 -0
  152. package/dist/routing/locale.d.ts.map +1 -0
  153. package/dist/routing/types.d.ts +12 -0
  154. package/dist/routing/types.d.ts.map +1 -1
  155. package/dist/security/cookie-session.d.ts +43 -0
  156. package/dist/security/cookie-session.d.ts.map +1 -0
  157. package/dist/security/cookies.d.ts +26 -0
  158. package/dist/security/cookies.d.ts.map +1 -0
  159. package/dist/security/csrf.d.ts +1 -1
  160. package/dist/security/csrf.d.ts.map +1 -1
  161. package/dist/security/env-startup.d.ts +15 -0
  162. package/dist/security/env-startup.d.ts.map +1 -0
  163. package/dist/security/env.d.ts +25 -6
  164. package/dist/security/env.d.ts.map +1 -1
  165. package/dist/security/fetch-metadata.d.ts +29 -0
  166. package/dist/security/fetch-metadata.d.ts.map +1 -0
  167. package/dist/security/index.d.ts +14 -2
  168. package/dist/security/index.d.ts.map +1 -1
  169. package/dist/security/policy.d.ts.map +1 -1
  170. package/dist/security/rate-limit.d.ts +6 -3
  171. package/dist/security/rate-limit.d.ts.map +1 -1
  172. package/dist/security/report.d.ts.map +1 -1
  173. package/dist/security/request.d.ts.map +1 -1
  174. package/dist/security/session-manager.d.ts +32 -0
  175. package/dist/security/session-manager.d.ts.map +1 -0
  176. package/dist/security/session-store.d.ts +51 -0
  177. package/dist/security/session-store.d.ts.map +1 -0
  178. package/dist/security/testing.d.ts +10 -0
  179. package/dist/security/testing.d.ts.map +1 -0
  180. package/dist/security/testing.js +145 -0
  181. package/dist/security/testing.js.map +1 -0
  182. package/dist/security/types.d.ts +73 -3
  183. package/dist/security/types.d.ts.map +1 -1
  184. package/dist/server/document-shell.d.ts.map +1 -1
  185. package/dist/server/errors.d.ts +1 -0
  186. package/dist/server/errors.d.ts.map +1 -1
  187. package/dist/server/index.d.ts +2 -1
  188. package/dist/server/index.d.ts.map +1 -1
  189. package/dist/server/not-found.d.ts +1 -0
  190. package/dist/server/not-found.d.ts.map +1 -1
  191. package/dist/server/render-tree.d.ts.map +1 -1
  192. package/dist/server/request-handler.d.ts +10 -2
  193. package/dist/server/request-handler.d.ts.map +1 -1
  194. package/dist/server/request-metadata.d.ts +1 -0
  195. package/dist/server/request-metadata.d.ts.map +1 -1
  196. package/dist/server/ssr.d.ts +2 -0
  197. package/dist/server/ssr.d.ts.map +1 -1
  198. package/dist/static/index.d.ts +2 -0
  199. package/dist/static/index.d.ts.map +1 -1
  200. package/dist/static/index.js +380 -363
  201. package/dist/static/index.js.map +1 -1
  202. package/dist/static/preview.d.ts.map +1 -1
  203. package/dist/static/vercel.d.ts +11 -2
  204. package/dist/static/vercel.d.ts.map +1 -1
  205. package/dist/static-files.d.ts +12 -0
  206. package/dist/static-files.d.ts.map +1 -1
  207. package/dist/type-guards.d.ts +19 -0
  208. package/dist/type-guards.d.ts.map +1 -0
  209. package/dist/vite/env-boundary.d.ts +14 -0
  210. package/dist/vite/env-boundary.d.ts.map +1 -0
  211. package/dist/vite/index.d.ts +8 -3
  212. package/dist/vite/index.d.ts.map +1 -1
  213. package/dist/vite/index.js +22 -1196
  214. package/dist/vite/index.js.map +1 -1
  215. package/dist/vite/plugin.d.ts +8 -1
  216. package/dist/vite/plugin.d.ts.map +1 -1
  217. package/dist/vite/policy-verification.d.ts.map +1 -1
  218. package/dist/vite/route-audit.d.ts +50 -0
  219. package/dist/vite/route-audit.d.ts.map +1 -0
  220. package/package.json +19 -6
  221. package/dist/chunks/document-shell-D1xo6cEA.js +0 -35
  222. package/dist/chunks/document-shell-D1xo6cEA.js.map +0 -1
  223. package/dist/chunks/images-B9MqcjSA.js.map +0 -1
  224. package/dist/chunks/request-metadata-D5NrT8ks.js +0 -642
  225. package/dist/chunks/request-metadata-D5NrT8ks.js.map +0 -1
  226. package/dist/chunks/static-files-DUjHw-4H.js +0 -11
  227. package/dist/chunks/static-files-DUjHw-4H.js.map +0 -1
  228. package/dist/chunks/streaming-BQ1bykDo.js.map +0 -1
  229. package/dist/chunks/testing-B_iMFYz_.js +0 -3321
  230. package/dist/chunks/testing-B_iMFYz_.js.map +0 -1
  231. package/dist/route/action.d.ts +0 -33
  232. package/dist/route/action.d.ts.map +0 -1
@@ -1,54 +1,54 @@
1
- import { readFile as O, mkdir as T, mkdtemp as k, cp as D, writeFile as b, rm as A, rename as nt } from "node:fs/promises";
2
- import { resolve as h, relative as w, sep as S, extname as it, dirname as C, join as y } from "node:path";
3
- import { d as ot, S as P } from "../chunks/request-metadata-D5NrT8ks.js";
4
- import { v as st, a as at, b as ct, d as ut, h as lt, r as ft, m as dt, e as _, f as ht } from "../chunks/testing-B_iMFYz_.js";
1
+ import { readFile as A, mkdir as x, mkdtemp as G, cp as K, writeFile as L, rm as C, rename as ut } from "node:fs/promises";
2
+ import { resolve as h, relative as E, sep as O, extname as lt, dirname as M, join as $ } from "node:path";
3
+ import { d as ft, S as j } from "../chunks/index-BVk9zWbe.js";
4
+ import { i as H, v as dt, a as ht, b as D, l as Z, d as pt, c as mt, h as wt, r as yt, e as gt, f as St, g as Et, m as vt, j as Y, k as $t } from "../chunks/testing-DueXbMo4.js";
5
5
  import "react-dom/server";
6
+ import { c as Ot, D as Rt, C as Q, I as Tt, R as At } from "../chunks/static-files-ehaD1kE7.js";
6
7
  import "react";
7
8
  import "react/jsx-runtime";
8
- import { C as U, I as pt, R as mt } from "../chunks/static-files-DUjHw-4H.js";
9
- import { t as wt, n as gt, r as yt } from "../chunks/image-codec-BGTx_t5K.js";
10
- import { e as V, g as St, p as Et, h as $t } from "../chunks/images-B9MqcjSA.js";
11
- import { createServer as vt } from "node:http";
12
- import { normalizeRoutes as Ot, getTransformedRoutes as Rt } from "@vercel/routing-utils";
13
- async function Tt(t) {
14
- const e = h(t.outDir), r = t.policy ?? {}, n = r.optimizerPath ?? V, o = new Set(
9
+ import { t as Ft, n as Nt, r as Pt } from "../chunks/image-codec-BmzWnH6W.js";
10
+ import { e as X, g as bt, p as xt, h as Ct } from "../chunks/images-BQ80950B.js";
11
+ import { createServer as Ht } from "node:http";
12
+ import { pathToRegexp as It } from "path-to-regexp";
13
+ async function Jt(t) {
14
+ const e = h(t.outDir), r = t.policy ?? {}, n = r.optimizerPath ?? X, o = new Set(
15
15
  t.documents.flatMap(
16
- (a) => St(a, n)
16
+ (s) => bt(s, n)
17
17
  )
18
- ), s = [], c = /* @__PURE__ */ new Map();
19
- for (const a of [...o].sort()) {
20
- const i = Et(a, n);
21
- if (!i)
18
+ ), i = [], c = /* @__PURE__ */ new Map();
19
+ for (const s of [...o].sort()) {
20
+ const a = xt(s, n);
21
+ if (!a)
22
22
  throw new Error(
23
- `Static output references image variant ${JSON.stringify(a)}, which does not describe a transform the build can emit.`
23
+ `Static output references image variant ${JSON.stringify(s)}, which does not describe a transform the build can emit.`
24
24
  );
25
- if (!$t(i.src, r))
25
+ if (!Ct(a.src, r))
26
26
  throw new Error(
27
- `Image source ${JSON.stringify(i.src)} is not allowed by the image policy.`
27
+ `Image source ${JSON.stringify(a.src)} is not allowed by the image policy.`
28
28
  );
29
- const u = Ft(e, i.src);
30
- let f = c.get(u);
31
- f || (f = await Nt(u, i.src), c.set(u, f));
32
- const E = await wt(f, {
33
- format: gt(i, null),
34
- quality: i.quality,
35
- width: i.width
29
+ const u = jt(e, a.src);
30
+ let d = c.get(u);
31
+ d || (d = await Mt(u, a.src), c.set(u, d));
32
+ const p = await Ft(d, {
33
+ format: Nt(a, null),
34
+ quality: a.quality,
35
+ width: a.width
36
36
  });
37
- s.push({ body: E.body, file: a.slice(1) });
37
+ i.push({ body: p.body, file: s.slice(1) });
38
38
  }
39
- return s;
39
+ return i;
40
40
  }
41
- function At(t, e = {}) {
42
- const r = e.optimizerPath ?? V, n = new RegExp(`${r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\?`);
41
+ function Lt(t, e = {}) {
42
+ const r = e.optimizerPath ?? X, n = new RegExp(`${r.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\?`);
43
43
  for (const o of t)
44
44
  if (n.test(o))
45
45
  throw new Error(
46
46
  'Static output references the request-time image optimizer, which a static build cannot serve. Set loader: "static" in the image policy, or deploy a runtime adapter.'
47
47
  );
48
48
  }
49
- async function Nt(t, e) {
49
+ async function Mt(t, e) {
50
50
  try {
51
- return new Uint8Array(await O(t));
51
+ return new Uint8Array(await A(t));
52
52
  } catch (r) {
53
53
  throw new Error(
54
54
  `Demiurge could not read the source image ${JSON.stringify(e)} from the build output.`,
@@ -56,7 +56,7 @@ async function Nt(t, e) {
56
56
  );
57
57
  }
58
58
  }
59
- function Ft(t, e) {
59
+ function jt(t, e) {
60
60
  let r;
61
61
  try {
62
62
  r = decodeURIComponent(e);
@@ -64,156 +64,141 @@ function Ft(t, e) {
64
64
  throw new Error(`Image source is not valid UTF-8: ${JSON.stringify(e)}.`);
65
65
  }
66
66
  const n = h(t, `.${r}`);
67
- if (w(t, n).split(S).includes(".."))
67
+ if (E(t, n).split(O).includes(".."))
68
68
  throw new Error(
69
69
  `Image source escaped the build output directory: ${JSON.stringify(e)}.`
70
70
  );
71
71
  return n;
72
72
  }
73
- const xt = "demiurge-static-manifest.json", bt = {
74
- ".avif": "image/avif",
75
- ".css": "text/css; charset=utf-8",
76
- ".gif": "image/gif",
77
- ".html": "text/html; charset=utf-8",
78
- ".ico": "image/x-icon",
79
- ".jpeg": "image/jpeg",
80
- ".jpg": "image/jpeg",
81
- ".js": "text/javascript; charset=utf-8",
82
- ".json": "application/json; charset=utf-8",
83
- ".mjs": "text/javascript; charset=utf-8",
84
- ".png": "image/png",
85
- ".svg": "image/svg+xml",
86
- ".txt": "text/plain; charset=utf-8",
87
- ".webmanifest": "application/manifest+json",
88
- ".webp": "image/webp",
89
- ".woff": "font/woff",
90
- ".woff2": "font/woff2"
91
- };
92
- async function Ne(t) {
93
- const e = h(t.outDir), r = Pt(
94
- await O(h(e, xt), "utf8")
73
+ const Dt = "demiurge-static-manifest.json";
74
+ async function Me(t) {
75
+ const e = h(t.outDir), r = Ut(
76
+ await A(h(e, Dt), "utf8")
95
77
  ), n = new Map(
96
78
  r.entries.map((a) => [a.pathname, a])
97
79
  ), o = new Map(
98
80
  r.entries.map((a) => [a.file, a])
99
- ), s = r.fileHeaderRules.map((a) => ({
81
+ ), i = r.fileHeaderRules.map((a) => ({
100
82
  ...a,
101
83
  expression: new RegExp(a.pattern)
102
- })), c = vt(async (a, i) => {
84
+ })), c = Ht((a, u) => {
85
+ s(a, u);
86
+ });
87
+ async function s(a, u) {
103
88
  try {
104
89
  if (a.method !== "GET" && a.method !== "HEAD") {
105
- i.writeHead(405, { allow: "GET, HEAD" }), i.end();
90
+ u.writeHead(405, { allow: "GET, HEAD" }), u.end();
106
91
  return;
107
92
  }
108
- const u = new URL(a.url ?? "/", "http://demiurge.local");
109
- let f;
93
+ const d = new URL(a.url ?? "/", "http://demiurge.local");
94
+ let p;
110
95
  try {
111
- f = decodeURIComponent(u.pathname);
96
+ p = decodeURIComponent(d.pathname);
112
97
  } catch {
113
- i.writeHead(400, {
98
+ u.writeHead(400, {
114
99
  "content-type": "text/plain; charset=utf-8"
115
- }), i.end("The request path is not valid UTF-8.");
100
+ }), u.end("The request path is not valid UTF-8.");
116
101
  return;
117
102
  }
118
- const E = f.replace(/\/$/, "") || "/", $ = n.get(E);
119
- if ($) {
120
- await F(e, $, a.method, i);
103
+ const y = p.replace(/\/$/, "") || "/", m = n.get(y);
104
+ if (m) {
105
+ await I(e, m, a.method, u);
121
106
  return;
122
107
  }
123
- const p = Ct(e, f);
124
- if (p)
108
+ const g = Wt(e, p);
109
+ if (g)
125
110
  try {
126
- const m = w(e, p).split(S).join("/"), l = o.get(m);
127
- if (l) {
128
- await F(e, l, a.method, i);
111
+ const w = E(e, g).split(O).join("/"), F = o.get(w);
112
+ if (F) {
113
+ await I(e, F, a.method, u);
129
114
  return;
130
115
  }
131
- const d = await O(p), v = bt[it(p).toLowerCase()];
132
- v && i.setHeader("content-type", v);
133
- const tt = f.split("/").at(-1) ?? "", et = s.find(({ expression: rt }) => rt.test(tt));
134
- z(i, et?.headers ?? {}), i.writeHead(200), i.end(a.method === "HEAD" ? void 0 : d);
116
+ const N = await A(g), v = Ot(lt(g));
117
+ v !== Rt && u.setHeader("content-type", v);
118
+ const T = p.split("/").at(-1) ?? "", P = i.find(({ expression: l }) => l.test(T));
119
+ tt(u, P?.headers ?? {}), u.writeHead(200), u.end(a.method === "HEAD" ? void 0 : N);
135
120
  return;
136
- } catch (m) {
137
- if (!Ht(m)) throw m;
121
+ } catch (w) {
122
+ if (!Vt(w)) throw w;
138
123
  }
139
- const g = n.get("*");
140
- if (!g) {
141
- i.writeHead(404), i.end();
124
+ const R = n.get("*");
125
+ if (!R) {
126
+ u.writeHead(404), u.end();
142
127
  return;
143
128
  }
144
- await F(e, g, a.method, i);
129
+ await I(e, R, a.method, u);
145
130
  } catch {
146
- i.writeHead(500, {
131
+ u.writeHead(500, {
147
132
  "content-type": "text/plain; charset=utf-8"
148
- }), i.end("Demiurge could not serve the static output.");
133
+ }), u.end("Demiurge could not serve the static output.");
149
134
  }
150
- });
151
- return await new Promise((a, i) => {
152
- const u = (f) => i(f);
153
- c.once("error", u), c.listen(
135
+ }
136
+ return await new Promise((a, u) => {
137
+ const d = (p) => u(p);
138
+ c.once("error", d), c.listen(
154
139
  t.port ?? 4173,
155
140
  t.host ?? "localhost",
156
141
  () => {
157
- c.off("error", u), a();
142
+ c.off("error", d), a();
158
143
  }
159
144
  );
160
145
  }), c;
161
146
  }
162
- async function F(t, e, r, n) {
163
- const o = q(t, e.file), s = await O(o);
164
- z(n, e.headers), n.writeHead(e.status), n.end(r === "HEAD" ? void 0 : s);
147
+ async function I(t, e, r, n) {
148
+ const o = et(t, e.file), i = await A(o);
149
+ tt(n, e.headers), n.writeHead(e.status), n.end(r === "HEAD" ? void 0 : i);
165
150
  }
166
- function z(t, e) {
151
+ function tt(t, e) {
167
152
  for (const [r, n] of Object.entries(e))
168
153
  t.setHeader(r, n);
169
154
  }
170
- function Ct(t, e) {
155
+ function Wt(t, e) {
171
156
  if (!e.endsWith("/"))
172
- return B(t, `.${e}`);
157
+ return rt(t, `.${e}`);
173
158
  }
174
- function q(t, e) {
175
- const r = B(t, e);
159
+ function et(t, e) {
160
+ const r = rt(t, e);
176
161
  if (!r)
177
162
  throw new Error(`Static preview file is outside the output directory: ${JSON.stringify(e)}.`);
178
163
  return r;
179
164
  }
180
- function B(t, e) {
165
+ function rt(t, e) {
181
166
  if (!e || e.startsWith("/") || e.startsWith("\\") || e.split(/[\\/]/).includes(".."))
182
167
  return;
183
- const r = h(t, e), n = w(t, r);
184
- return n !== ".." && !n.startsWith(`..${S}`) ? r : void 0;
168
+ const r = h(t, e), n = E(t, r);
169
+ return n !== ".." && !n.startsWith(`..${O}`) ? r : void 0;
185
170
  }
186
- function Pt(t) {
171
+ function Ut(t) {
187
172
  let e;
188
173
  try {
189
174
  e = JSON.parse(t);
190
175
  } catch {
191
176
  throw new Error("The static output manifest is not valid JSON.");
192
177
  }
193
- if (!N(e) || e.adapter !== "static" || e.version !== 1)
178
+ if (!H(e) || e.adapter !== "static" || e.version !== 1)
194
179
  throw new Error("The static output manifest has an unsupported format.");
195
180
  if (!Array.isArray(e.entries) || !Array.isArray(e.fileHeaderRules))
196
181
  throw new Error("The static output manifest does not contain header rules and entries.");
197
- const r = e.entries.map(It), n = e.fileHeaderRules.map(jt), o = /* @__PURE__ */ new Set();
198
- for (const s of r) {
199
- if (o.has(s.pathname))
200
- throw new Error(`The static output manifest repeats pathname ${JSON.stringify(s.pathname)}.`);
201
- o.add(s.pathname);
182
+ const r = e.entries.map(kt), n = e.fileHeaderRules.map(_t), o = /* @__PURE__ */ new Set();
183
+ for (const i of r) {
184
+ if (o.has(i.pathname))
185
+ throw new Error(`The static output manifest repeats pathname ${JSON.stringify(i.pathname)}.`);
186
+ o.add(i.pathname);
202
187
  }
203
188
  return { adapter: "static", entries: r, fileHeaderRules: n, version: 1 };
204
189
  }
205
- function It(t) {
206
- if (!N(t) || typeof t.file != "string" || typeof t.pathname != "string" || t.status !== 200 && t.status !== 404 || !G(t.headers))
190
+ function kt(t) {
191
+ if (!H(t) || typeof t.file != "string" || typeof t.pathname != "string" || t.status !== 200 && t.status !== 404 || !nt(t.headers))
207
192
  throw new Error("The static output manifest contains an invalid entry.");
208
- return q("/demiurge-manifest-root", t.file), {
193
+ return et("/demiurge-manifest-root", t.file), {
209
194
  file: t.file,
210
195
  headers: t.headers,
211
196
  pathname: t.pathname,
212
197
  status: t.status
213
198
  };
214
199
  }
215
- function jt(t) {
216
- if (!N(t) || typeof t.pattern != "string" || !G(t.headers))
200
+ function _t(t) {
201
+ if (!H(t) || typeof t.pattern != "string" || !nt(t.headers))
217
202
  throw new Error("The static output manifest contains an invalid file header rule.");
218
203
  try {
219
204
  new RegExp(t.pattern);
@@ -222,19 +207,16 @@ function jt(t) {
222
207
  }
223
208
  return { headers: t.headers, pattern: t.pattern };
224
209
  }
225
- function N(t) {
226
- return !!t && typeof t == "object" && !Array.isArray(t);
227
- }
228
- function G(t) {
229
- return N(t) && Object.values(t).every(
210
+ function nt(t) {
211
+ return H(t) && Object.values(t).every(
230
212
  (e) => typeof e == "string"
231
213
  );
232
214
  }
233
- function Ht(t) {
215
+ function Vt(t) {
234
216
  return t instanceof Error && "code" in t && (t.code === "EISDIR" || t.code === "ENOENT");
235
217
  }
236
- const Jt = "demiurge-manifest.json", Mt = "demiurge-static-manifest.json";
237
- function Fe(t = {}) {
218
+ const qt = "demiurge-manifest.json", zt = "demiurge-static-manifest.json";
219
+ function je(t = {}) {
238
220
  return {
239
221
  adapter: "vercel",
240
222
  cache: t.cache?.map((e) => ({
@@ -244,110 +226,105 @@ function Fe(t = {}) {
244
226
  cors: t.cors
245
227
  };
246
228
  }
247
- async function xe(t) {
248
- Vt(t.deployment);
229
+ async function De(t) {
230
+ te(t.deployment);
249
231
  const e = h(t.projectRoot), r = h(t.outDir), n = h(e, ".vercel/output");
250
- if (zt(r, n))
232
+ if (ee(r, n))
251
233
  throw new Error(
252
234
  "The static output directory must not overlap the Vercel output directory."
253
235
  );
254
- const o = C(n);
255
- await T(o, { recursive: !0 });
256
- const s = await k(y(o, "output-demiurge-"));
236
+ const o = M(n);
237
+ await x(o, { recursive: !0 });
238
+ const i = await G($(o, "output-demiurge-"));
257
239
  try {
258
- const c = y(s, "static");
259
- await D(r, c, {
260
- filter: (a) => {
261
- const i = w(r, a).split(S).join("/");
262
- return i !== Jt && i !== Mt;
240
+ const c = $(i, "static");
241
+ await K(r, c, {
242
+ filter: (s) => {
243
+ const a = E(r, s).split(O).join("/");
244
+ return a !== qt && a !== zt;
263
245
  },
264
246
  recursive: !0
265
- }), await b(
266
- y(s, "config.json"),
267
- `${JSON.stringify(Lt(
247
+ }), await L(
248
+ $(i, "config.json"),
249
+ `${JSON.stringify(Bt(
268
250
  t.manifest,
269
251
  t.deployment
270
252
  ), null, 2)}
271
253
  `
272
- ), await A(n, { force: !0, recursive: !0 }), await nt(s, n);
254
+ ), await C(n, { force: !0, recursive: !0 }), await ut(i, n);
273
255
  } catch (c) {
274
- throw await A(s, { force: !0, recursive: !0 }), c;
256
+ throw await C(i, { force: !0, recursive: !0 }), c;
275
257
  }
276
258
  return n;
277
259
  }
278
- function Lt(t, e) {
279
- const r = t.entries.find((i) => i.pathname === "*");
260
+ function Bt(t, e) {
261
+ const r = t.entries.find((s) => s.pathname === "*");
280
262
  if (!r)
281
263
  throw new Error("Vercel output requires a static fallback entry.");
282
- const n = _t(e.cache), s = [
264
+ const n = Yt(e.cache), i = [
283
265
  {
284
266
  continue: !0,
285
- headers: { "access-control-allow-origin": Ut(e.cors, t.origin) },
267
+ headers: { "access-control-allow-origin": Xt(e.cors, t.origin) },
286
268
  src: "^/.*$"
287
269
  }
288
270
  ];
289
- for (const i of t.entries) {
290
- if (i.pathname === "*") continue;
291
- const u = `/${i.file}`;
292
- u !== i.pathname && s.push({
271
+ for (const s of t.entries) {
272
+ if (s.pathname === "*") continue;
273
+ const a = `/${s.file}`;
274
+ a !== s.pathname && i.push({
293
275
  continue: !0,
294
- dest: i.pathname,
295
- src: R(u)
276
+ dest: s.pathname,
277
+ src: b(a)
296
278
  });
297
279
  }
298
- for (const i of t.entries) {
299
- const u = I(i.headers);
300
- if (Object.keys(u).length === 0) continue;
301
- const f = i.pathname === "*" ? `/${i.file}` : i.pathname;
302
- s.push({
280
+ for (const s of t.entries) {
281
+ const a = W(s.headers);
282
+ if (Object.keys(a).length === 0) continue;
283
+ const u = s.pathname === "*" ? `/${s.file}` : s.pathname;
284
+ i.push({
303
285
  continue: !0,
304
- headers: u,
305
- src: R(f)
286
+ headers: a,
287
+ src: b(u)
306
288
  });
307
289
  }
308
- s.push(...n);
309
- for (const i of t.entries) {
310
- if (i.pathname === "*") {
311
- s.push({
312
- dest: `/${i.file}`,
313
- src: R(`/${i.file}`),
290
+ i.push(...n);
291
+ for (const s of t.entries) {
292
+ if (s.pathname === "*") {
293
+ i.push({
294
+ dest: `/${s.file}`,
295
+ src: b(`/${s.file}`),
314
296
  status: 404
315
297
  });
316
298
  continue;
317
299
  }
318
- s.push({
319
- dest: i.pathname === "/" ? `/${i.file}` : i.pathname,
320
- src: R(i.pathname)
300
+ i.push({
301
+ dest: s.pathname === "/" ? `/${s.file}` : s.pathname,
302
+ src: b(s.pathname)
321
303
  });
322
304
  }
323
- s.push({ handle: "hit" });
324
- for (const i of [...t.fileHeaderRules].reverse())
325
- s.push({
305
+ i.push({ handle: "hit" });
306
+ for (const s of [...t.fileHeaderRules].reverse())
307
+ i.push({
326
308
  continue: !0,
327
- headers: { ...i.headers },
328
- src: kt(i.pattern)
309
+ headers: { ...s.headers },
310
+ src: Kt(s.pattern)
329
311
  });
330
- s.push(...n.map((i) => ({ ...i }))), s.push({ handle: "error" });
331
- const c = I(r.headers);
332
- Object.keys(c).length > 0 && s.push({
333
- continue: !0,
312
+ i.push(...n.map((s) => ({ ...s }))), i.push({ handle: "error" });
313
+ const c = W(r.headers);
314
+ return i.push(...n.map((s) => ({ ...s }))), i.push({
315
+ dest: `/${r.file}`,
334
316
  headers: c,
335
- src: "^/.*$"
336
- }), s.push(...n.map((i) => ({ ...i }))), s.push({ dest: `/${r.file}`, src: "^/.*$", status: 404 });
337
- const a = Ot(s);
338
- if (a.error || !a.routes)
339
- throw new Error(
340
- `Vercel rejected the generated routes: ${a.error?.message ?? "The route list is empty."}`
341
- );
342
- return {
317
+ src: "^/.*$",
318
+ status: 404
319
+ }), Qt(i), {
343
320
  overrides: Object.fromEntries(
344
- t.entries.map((i) => [i.file, Wt(i)])
321
+ t.entries.map((s) => [s.file, Gt(s)])
345
322
  ),
346
- routes: a.routes,
323
+ routes: i,
347
324
  version: 3
348
325
  };
349
326
  }
350
- function Wt(t) {
327
+ function Gt(t) {
351
328
  const e = {}, r = t.headers["content-type"];
352
329
  if (r && (e.contentType = r), t.pathname !== "*") {
353
330
  const n = t.file === "index.html" ? "/" : `/${t.file}`;
@@ -355,39 +332,53 @@ function Wt(t) {
355
332
  }
356
333
  return e;
357
334
  }
358
- function R(t) {
335
+ function b(t) {
359
336
  const e = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
360
337
  return t === "/" ? "^/$" : `^${e}/?$`;
361
338
  }
362
- function I(t) {
339
+ function W(t) {
363
340
  return Object.fromEntries(
364
341
  Object.entries(t).filter(([e]) => e.toLowerCase() !== "content-type")
365
342
  );
366
343
  }
367
- function kt(t) {
368
- return t === ".*" ? "^/.*$" : t === U.source ? "^/(?:.*/)?[^/]*-[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9]+$" : `^/${Dt(t)}$`;
344
+ function Kt(t) {
345
+ return t === ".*" ? "^/.*$" : t === Q.source ? "^/(?:.*/)?[^/]*-[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9]+$" : `^/${Zt(t)}$`;
369
346
  }
370
- function Dt(t) {
347
+ function Zt(t) {
371
348
  const e = t.startsWith("^"), r = t.endsWith("$") && !t.endsWith("\\$"), n = t.slice(
372
349
  e ? 1 : 0,
373
350
  r ? -1 : void 0
374
351
  );
375
352
  return `${e ? "(?:.*/)?" : "(?:.*/)?[^/]*"}(?:${n})${r ? "" : "[^/]*"}`;
376
353
  }
377
- function _t(t) {
378
- const e = t.map((n) => ({
379
- headers: [{ key: "cache-control", value: n.value }],
380
- source: n.source
381
- })), r = Rt({ headers: e });
382
- if (r.error || !r.routes)
354
+ function Yt(t) {
355
+ try {
356
+ return t.map((e) => ({
357
+ continue: !0,
358
+ headers: { "cache-control": e.value },
359
+ src: It(e.source, [], {
360
+ delimiter: "/",
361
+ strict: !0
362
+ }).source.replaceAll("\\/", "/")
363
+ }));
364
+ } catch {
383
365
  throw new Error(
384
- `A Vercel static header rule is not valid: ${r.error?.message ?? "The route list is empty."}`
366
+ "A Vercel static header rule is not valid."
385
367
  );
386
- return r.routes;
368
+ }
369
+ }
370
+ function Qt(t) {
371
+ for (const e of t)
372
+ if (!("handle" in e))
373
+ try {
374
+ new RegExp(e.src);
375
+ } catch {
376
+ throw new Error("A generated Vercel route is not valid.");
377
+ }
387
378
  }
388
- function Ut(t, e) {
379
+ function Xt(t, e) {
389
380
  if (t) {
390
- if (st(t), t.origins === "*")
381
+ if (dt(t), t.origins === "*")
391
382
  return "*";
392
383
  if (t.origins.length === 1)
393
384
  return t.origins[0];
@@ -401,40 +392,40 @@ function Ut(t, e) {
401
392
  );
402
393
  return e;
403
394
  }
404
- function Vt(t) {
395
+ function te(t) {
405
396
  if (t.adapter !== "vercel" || !Array.isArray(t.cache))
406
397
  throw new Error("The Vercel static adapter configuration is not valid.");
407
398
  for (const e of t.cache)
408
399
  if (!e || typeof e != "object" || typeof e.source != "string" || !e.source || typeof e.value != "string" || !e.value)
409
400
  throw new Error("A Vercel static header rule is not valid.");
410
401
  }
411
- function zt(t, e) {
412
- const r = w(t, e), n = w(e, t);
413
- return j(r) || j(n);
402
+ function ee(t, e) {
403
+ const r = E(t, e), n = E(e, t);
404
+ return U(r) || U(n);
414
405
  }
415
- function j(t) {
416
- return !t || t !== ".." && !t.startsWith(`..${S}`) && !t.startsWith("/");
406
+ function U(t) {
407
+ return !t || t !== ".." && !t.startsWith(`..${O}`) && !t.startsWith("/");
417
408
  }
418
- const K = "demiurge-static-manifest.json", qt = ot({
409
+ const ot = "demiurge-static-manifest.json", k = ft({
419
410
  name: "static",
420
411
  capabilities: {
421
412
  staticOutput: !0
422
413
  }
423
- }), Bt = 8;
424
- async function Gt(t) {
414
+ }), re = 8;
415
+ async function ne(t) {
425
416
  const e = Object.entries(t), r = new Array(e.length);
426
417
  let n = 0;
427
418
  const o = Array.from(
428
- { length: Math.min(Bt, e.length) },
419
+ { length: Math.min(re, e.length) },
429
420
  async () => {
430
421
  for (; n < e.length; ) {
431
- const s = n++, [c, a] = e[s];
422
+ const i = n++, [c, s] = e[i];
432
423
  try {
433
- r[s] = [c, await a()];
434
- } catch (i) {
424
+ r[i] = [c, await s()];
425
+ } catch (a) {
435
426
  throw new Error(
436
427
  `Demiurge could not load route module ${JSON.stringify(c)}.`,
437
- { cause: i }
428
+ { cause: a }
438
429
  );
439
430
  }
440
431
  }
@@ -442,109 +433,135 @@ async function Gt(t) {
442
433
  );
443
434
  return await Promise.all(o), Object.fromEntries(r);
444
435
  }
445
- async function be(t) {
446
- const e = await Gt(t.routes), r = at(e, {
447
- adapter: qt
448
- }), n = Xt(t.origin), o = h(t.outDir), s = await te(r), c = await ct(r, {
436
+ async function We(t) {
437
+ const e = await ne(t.routes), r = ht(e, {
438
+ adapter: k
439
+ }), n = ce(t.origin), o = h(t.outDir), i = await le(r), c = await D(r, {
440
+ includePages: !1,
449
441
  includeResources: !0
450
- });
451
- Yt(
442
+ }), s = t.locales ? oe(n, t.locales) : [void 0], a = (await Promise.all(
443
+ s.map((l) => D(r, { locale: l }))
444
+ )).flatMap((l, f) => l.map((S) => ({
445
+ ...S,
446
+ locale: s[f]
447
+ }))), u = [...c, ...a];
448
+ ue(
452
449
  r,
453
- c.filter((l) => s.get(l.file) === "document").length
450
+ a.length
454
451
  );
455
- const a = ne(
456
- c.map((l) => ({
457
- kind: s.get(l.file) ?? "resource",
458
- pathname: l.pathname
459
- }))
460
- ), i = ut(), u = [], f = { ...t.ssr, navigation: "document" };
461
- for (const l of a) {
462
- const d = J(n, l.pathname, l.kind), v = await lt(r, d, {
452
+ const d = he(
453
+ u.flatMap((l) => {
454
+ const f = i.get(l.file) ?? "resource";
455
+ if (f !== "document" || !t.locales || !l.locale)
456
+ return [{ kind: f, pathname: l.pathname }];
457
+ const S = new URL(
458
+ Z(l.pathname, l.locale, t.locales, n),
459
+ n
460
+ );
461
+ return [{ kind: f, pathname: `${S.pathname}${S.search}` }];
462
+ })
463
+ ), p = pt(), y = [], m = { ...t.ssr, navigation: "document" }, g = t.locales ? mt({
464
+ adapter: k,
465
+ locales: t.locales,
466
+ onError: t.onError,
467
+ routeModules: e,
468
+ routes: t.routes,
469
+ ssr: m
470
+ }) : void 0;
471
+ for (const l of d) {
472
+ const f = V(n, l.pathname, l.kind), S = g ? await g(f) : await wt(r, f, {
463
473
  onError: t.onError,
464
- rateLimitStore: i,
465
- ssr: f
474
+ rateLimitStore: p,
475
+ ssr: m
466
476
  });
467
- u.push(
468
- l.kind === "document" ? await M(l, v, 200) : await se(l, v)
477
+ y.push(
478
+ l.kind === "document" ? await q(l, S, 200) : await we(l, S)
469
479
  );
470
480
  }
471
- const E = await ft(
481
+ const R = V(n, "/404", "document"), w = t.locales ? yt(R, gt(t.locales)).locale : void 0, F = await St(
472
482
  r,
473
- J(n, "/404", "document"),
483
+ R,
474
484
  {
475
- ...f,
476
- onError: (l, d) => t.onError?.(l, { pathname: "/404", site: d })
485
+ ...m,
486
+ dir: w ? Et(w, t.locales) : m.dir,
487
+ lang: w ?? m.lang,
488
+ locale: w ?? m.locale,
489
+ onError: (l, f) => t.onError?.(l, { pathname: "/404", site: f })
477
490
  }
478
491
  );
479
- u.push(
480
- await M(
492
+ y.push(
493
+ await q(
481
494
  {
482
495
  file: "404.html",
483
496
  pathname: "*"
484
497
  },
485
- E,
498
+ F,
486
499
  404
487
500
  )
488
501
  );
489
- const $ = u.map((l) => l.body);
490
- At($, t.images);
491
- const p = await Tt({
492
- documents: $,
502
+ const N = y.map((l) => l.body);
503
+ Lt(N, t.images);
504
+ const v = await Jt({
505
+ documents: N,
493
506
  outDir: o,
494
507
  policy: t.images
495
- }), g = await yt({
508
+ }), T = await Pt({
496
509
  fonts: t.fonts,
497
510
  root: t.root ?? process.cwd()
498
511
  });
499
- u.sort((l, d) => l.file.localeCompare(d.file)), p.sort((l, d) => l.file.localeCompare(d.file)), g.sort((l, d) => l.file.localeCompare(d.file));
500
- const m = {
512
+ y.sort((l, f) => l.file.localeCompare(f.file)), v.sort((l, f) => l.file.localeCompare(f.file)), T.sort((l, f) => l.file.localeCompare(f.file));
513
+ const P = {
501
514
  adapter: "static",
502
- entries: u.map(({ body: l, ...d }) => d),
503
- fileHeaderRules: await Kt(
515
+ entries: y.map(({ body: l, ...f }) => f),
516
+ fileHeaderRules: await ie(
504
517
  r,
505
518
  t.staticFileHeaders ?? []
506
519
  ),
507
- fontFiles: g.map((l) => l.file),
508
- imageFiles: p.map((l) => l.file),
520
+ fontFiles: T.map((l) => l.file),
521
+ imageFiles: v.map((l) => l.file),
509
522
  origin: n,
510
523
  version: 1
511
524
  };
512
- return await he(o, u, [...p, ...g], m), m;
525
+ return await Oe(o, y, [...v, ...T], P), P;
526
+ }
527
+ function oe(t, e) {
528
+ const r = new URL(t);
529
+ return e.supportedLocales.flatMap((n) => new URL(Z("/", n, e, t), t).origin === r.origin ? [n] : []);
513
530
  }
514
- async function Kt(t, e) {
515
- const r = await Zt(t), n = H(r);
531
+ async function ie(t, e) {
532
+ const r = await ae(t), n = _(r);
516
533
  return [
517
- ...e.map((o) => (Qt(o.pattern), {
518
- headers: H(
519
- dt(r, { headers: o.headers })
534
+ ...e.map((o) => (se(o.pattern), {
535
+ headers: _(
536
+ vt(r, { headers: o.headers })
520
537
  ),
521
538
  pattern: o.pattern
522
539
  })),
523
540
  {
524
541
  headers: {
525
542
  ...n,
526
- "cache-control": pt
543
+ "cache-control": Tt
527
544
  },
528
- pattern: U.source
545
+ pattern: Q.source
529
546
  },
530
547
  {
531
548
  headers: {
532
549
  ...n,
533
- "cache-control": mt
550
+ "cache-control": At
534
551
  },
535
552
  pattern: ".*"
536
553
  }
537
554
  ];
538
555
  }
539
- async function Zt(t) {
556
+ async function ae(t) {
540
557
  return { headers: (await t.policies.find(
541
558
  (n) => n.fileSegments.length === 0
542
559
  )?.load())?.policy?.document?.headers };
543
560
  }
544
- function H(t) {
545
- return Object.fromEntries(ht(t, {}).entries());
561
+ function _(t) {
562
+ return Object.fromEntries($t(t, {}).entries());
546
563
  }
547
- function Qt(t) {
564
+ function se(t) {
548
565
  try {
549
566
  new RegExp(t);
550
567
  } catch {
@@ -553,7 +570,7 @@ function Qt(t) {
553
570
  );
554
571
  }
555
572
  }
556
- function Xt(t) {
573
+ function ce(t) {
557
574
  let e;
558
575
  try {
559
576
  e = new URL(t ?? "http://demiurge.local");
@@ -568,7 +585,7 @@ function Xt(t) {
568
585
  );
569
586
  return e.origin;
570
587
  }
571
- function Yt(t, e) {
588
+ function ue(t, e) {
572
589
  if (e === 0)
573
590
  throw new Error("Static output requires at least one page route.");
574
591
  if (!t.fallbacks.notFound.some(
@@ -578,10 +595,10 @@ function Yt(t, e) {
578
595
  "Static output requires a root @not-found.tsx so 404.html is app-owned."
579
596
  );
580
597
  }
581
- async function te(t) {
598
+ async function le(t) {
582
599
  const e = /* @__PURE__ */ new Map();
583
600
  for (const r of t.routes) {
584
- const n = await r.load(), o = ee(n);
601
+ const n = await r.load(), o = fe(n);
585
602
  if (o.length > 0)
586
603
  throw new Error(
587
604
  `Static route ${JSON.stringify(r.file)} exports unsupported methods ${o.join(", ")}. Deploy a runtime adapter for request-time methods.`
@@ -594,14 +611,14 @@ async function te(t) {
594
611
  e.set(r.file, "document");
595
612
  continue;
596
613
  }
597
- re(r.file, n.GET), e.set(r.file, "resource");
614
+ de(r.file, n.GET), e.set(r.file, "resource");
598
615
  }
599
616
  return e;
600
617
  }
601
- function ee(t) {
618
+ function fe(t) {
602
619
  return ["POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"].filter((e) => t[e] !== void 0);
603
620
  }
604
- function re(t, e) {
621
+ function de(t, e) {
605
622
  if ((e.kind === "text" || e.kind === "html" || e.kind === "json") && typeof e.value != "function")
606
623
  return;
607
624
  const r = "value" in e && typeof e.value == "function" ? `uses a request-dependent ${e.kind} value` : `uses the ${e.kind} response helper`;
@@ -609,23 +626,23 @@ function re(t, e) {
609
626
  `Static route ${JSON.stringify(t)} ${r} and cannot produce a fixed output file. Use a fixed text, html, or json value, or deploy a runtime adapter.`
610
627
  );
611
628
  }
612
- function ne(t) {
629
+ function he(t) {
613
630
  const e = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
614
631
  return t.map(({ kind: n, pathname: o }) => {
615
632
  if (r.has(o))
616
633
  throw new Error(`Static output collected duplicate pathname ${JSON.stringify(o)}.`);
617
634
  r.add(o);
618
- const s = n === "document" ? Z(o) : ie(o), c = s.toLocaleLowerCase("en-US"), a = [...e.entries()].find(
619
- ([i]) => i === c || i.startsWith(`${c}/`) || c.startsWith(`${i}/`)
635
+ const i = n === "document" ? it(o) : pe(o), c = i.toLocaleLowerCase("en-US"), s = [...e.entries()].find(
636
+ ([a]) => a === c || a.startsWith(`${c}/`) || c.startsWith(`${a}/`)
620
637
  );
621
- if (a)
638
+ if (s)
622
639
  throw new Error(
623
- `Static paths ${JSON.stringify(a[1])} and ${JSON.stringify(o)} map to the same portable output file or to a file and directory conflict.`
640
+ `Static paths ${JSON.stringify(s[1])} and ${JSON.stringify(o)} map to the same portable output file or to a file and directory conflict.`
624
641
  );
625
- return e.set(c, o), { file: s, kind: n, pathname: o };
642
+ return e.set(c, o), { file: i, kind: n, pathname: o };
626
643
  });
627
644
  }
628
- function Z(t) {
645
+ function it(t) {
629
646
  if (!t.startsWith("/") || t.includes("?") || t.includes("#"))
630
647
  throw new Error(`Static output received invalid pathname ${JSON.stringify(t)}.`);
631
648
  return t === "/" ? "index.html" : [...t.split("/").slice(1).map((r) => {
@@ -635,27 +652,27 @@ function Z(t) {
635
652
  } catch {
636
653
  throw new Error(`Static output pathname is not valid UTF-8: ${JSON.stringify(t)}.`);
637
654
  }
638
- return oe(n, t), n;
655
+ return me(n, t), n;
639
656
  }), "index.html"].join("/");
640
657
  }
641
- function ie(t) {
658
+ function pe(t) {
642
659
  if (t === "/")
643
660
  throw new Error("A static resource route cannot own the root pathname.");
644
- return Z(t).slice(0, -11);
661
+ return it(t).slice(0, -11);
645
662
  }
646
- function oe(t, e) {
663
+ function me(t, e) {
647
664
  const r = /[<>:"|?*]/.test(t) || [...t].some((n) => n.charCodeAt(0) <= 31) || /[. ]$/.test(t) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(t);
648
665
  if (!t || t === "." || t === ".." || t.includes("/") || t.includes("\\") || r)
649
666
  throw new Error(
650
667
  `Static pathname ${JSON.stringify(e)} contains a segment that is unsafe or not portable as a file name: ${JSON.stringify(t)}.`
651
668
  );
652
669
  }
653
- function J(t, e, r) {
670
+ function V(t, e, r) {
654
671
  return new Request(`${t}${e}`, {
655
672
  headers: { accept: r === "document" ? "text/html" : "*/*" }
656
673
  });
657
674
  }
658
- async function M(t, e, r) {
675
+ async function q(t, e, r) {
659
676
  if (e.status !== r)
660
677
  throw new Error(
661
678
  `Static output for ${JSON.stringify(t.pathname)} returned status ${e.status}; expected ${r}.`
@@ -669,19 +686,19 @@ async function M(t, e, r) {
669
686
  throw new Error(
670
687
  `Static output for ${JSON.stringify(t.pathname)} attempted to set a cookie. Build artifacts cannot contain per-user response state.`
671
688
  );
672
- const o = await ae(
689
+ const o = await ye(
673
690
  await e.text(),
674
691
  e.headers
675
692
  );
676
- return await ue(t.pathname, o, e.headers), {
693
+ return await Se(t.pathname, o, e.headers), {
677
694
  file: t.file,
678
- headers: X(e.headers),
695
+ headers: st(e.headers),
679
696
  body: o,
680
697
  pathname: t.pathname,
681
698
  status: r
682
699
  };
683
700
  }
684
- async function se(t, e) {
701
+ async function we(t, e) {
685
702
  if (e.status !== 200)
686
703
  throw new Error(
687
704
  `Static output for ${JSON.stringify(t.pathname)} returned status ${e.status}; expected 200.`
@@ -692,48 +709,48 @@ async function se(t, e) {
692
709
  );
693
710
  return {
694
711
  file: t.file,
695
- headers: X(e.headers),
712
+ headers: st(e.headers),
696
713
  body: await e.text(),
697
714
  pathname: t.pathname,
698
715
  status: 200
699
716
  };
700
717
  }
701
- async function ae(t, e) {
718
+ async function ye(t, e) {
702
719
  const r = new RegExp(
703
- `(?:^|\\s)${P}(?:\\s|$)`
704
- ), n = Q(t, "script").filter((s) => r.test(s.attributes));
720
+ `(?:^|\\s)${j}(?:\\s|$)`
721
+ ), n = at(t, "script").filter((i) => r.test(i.attributes));
705
722
  if (n.length === 0)
706
723
  return t;
707
724
  const o = await Promise.all(
708
- n.map((s) => _(s.content))
725
+ n.map((i) => Y(i.content))
709
726
  );
710
- for (const s of [
727
+ for (const i of [
711
728
  "content-security-policy",
712
729
  "content-security-policy-report-only"
713
730
  ]) {
714
- const c = e.get(s);
715
- c && e.set(s, ce(c, o));
731
+ const c = e.get(i);
732
+ c && e.set(i, ge(c, o));
716
733
  }
717
734
  return t.replace(
718
- new RegExp(`\\s${P}(?=\\s|>)`, "g"),
735
+ new RegExp(`\\s${j}(?=\\s|>)`, "g"),
719
736
  ""
720
737
  );
721
738
  }
722
- function ce(t, e) {
723
- const r = t.split(";").map((i) => i.trim()).filter(Boolean), n = r.findIndex(
724
- (i) => i.split(/\s+/, 1)[0]?.toLowerCase() === "script-src"
739
+ function ge(t, e) {
740
+ const r = t.split(";").map((a) => a.trim()).filter(Boolean), n = r.findIndex(
741
+ (a) => a.split(/\s+/, 1)[0]?.toLowerCase() === "script-src"
725
742
  ), o = r.find(
726
- (i) => i.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
727
- ), s = n === -1 ? o : r[n];
728
- if (!s)
743
+ (a) => a.split(/\s+/, 1)[0]?.toLowerCase() === "default-src"
744
+ ), i = n === -1 ? o : r[n];
745
+ if (!i)
729
746
  return t;
730
- const c = s.split(/\s+/).slice(1).filter((i) => i !== "'none'"), a = [
747
+ const c = i.split(/\s+/).slice(1).filter((a) => a !== "'none'"), s = [
731
748
  "script-src",
732
749
  .../* @__PURE__ */ new Set([...c, ...e])
733
750
  ].join(" ");
734
- return n === -1 ? r.push(a) : r[n] = a, r.join("; ");
751
+ return n === -1 ? r.push(s) : r[n] = s, r.join("; ");
735
752
  }
736
- async function ue(t, e, r) {
753
+ async function Se(t, e, r) {
737
754
  const n = r.get("content-security-policy");
738
755
  if (!n)
739
756
  return;
@@ -741,35 +758,35 @@ async function ue(t, e, r) {
741
758
  throw new Error(
742
759
  `Static output for ${JSON.stringify(t)} uses a nonce-backed CSP. Use security.static() with stable hashes or a runtime adapter that injects a fresh nonce.`
743
760
  );
744
- const o = le(n);
745
- await L(
761
+ const o = Ee(n);
762
+ await z(
746
763
  t,
747
764
  e,
748
765
  "script",
749
- x(o, "script-src", "default-src")
750
- ), await L(
766
+ J(o, "script-src", "default-src")
767
+ ), await z(
751
768
  t,
752
769
  e,
753
770
  "style",
754
- x(
771
+ J(
755
772
  o,
756
773
  "style-src-elem",
757
774
  "style-src",
758
775
  "default-src"
759
776
  )
760
777
  );
761
- const s = x(
778
+ const i = J(
762
779
  o,
763
780
  "style-src-attr",
764
781
  "style-src",
765
782
  "default-src"
766
783
  );
767
- if (s && /\sstyle\s*=/i.test(e) && !s.includes("'unsafe-inline'"))
784
+ if (i && /\sstyle\s*=/i.test(e) && !i.includes("'unsafe-inline'"))
768
785
  throw new Error(
769
786
  `Static output for ${JSON.stringify(t)} contains an inline style attribute that its CSP does not allow. Move the style into a stylesheet or explicitly allow inline styles.`
770
787
  );
771
788
  }
772
- function le(t) {
789
+ function Ee(t) {
773
790
  const e = /* @__PURE__ */ new Map();
774
791
  for (const r of t.split(";")) {
775
792
  const [n, ...o] = r.trim().split(/\s+/);
@@ -777,20 +794,20 @@ function le(t) {
777
794
  }
778
795
  return e;
779
796
  }
780
- function x(t, ...e) {
797
+ function J(t, ...e) {
781
798
  for (const r of e) {
782
799
  const n = t.get(r);
783
800
  if (n)
784
801
  return n;
785
802
  }
786
803
  }
787
- async function L(t, e, r, n) {
804
+ async function z(t, e, r, n) {
788
805
  if (!(!n || n.includes("'unsafe-inline'")))
789
- for (const o of Q(e, r)) {
806
+ for (const o of at(e, r)) {
790
807
  if (r === "script") {
791
- const c = fe(o.attributes, "src");
808
+ const c = ve(o.attributes, "src");
792
809
  if (c) {
793
- if (!de(n, c))
810
+ if (!$e(n, c))
794
811
  throw new Error(
795
812
  `Static output for ${JSON.stringify(t)} contains script ${JSON.stringify(c)} that the effective script-src directive does not allow. Add its origin to security.needs.script or the route CSP policy.`
796
813
  );
@@ -799,19 +816,19 @@ async function L(t, e, r, n) {
799
816
  }
800
817
  if (!o.content)
801
818
  continue;
802
- const s = await _(o.content);
803
- if (!n.includes(s))
819
+ const i = await Y(o.content);
820
+ if (!n.includes(i))
804
821
  throw new Error(
805
- `Static output for ${JSON.stringify(t)} contains an inline ${r} without the required CSP hash ${s}.`
822
+ `Static output for ${JSON.stringify(t)} contains an inline ${r} without the required CSP hash ${i}.`
806
823
  );
807
824
  }
808
825
  }
809
- function fe(t, e) {
826
+ function ve(t, e) {
810
827
  return t.match(
811
828
  new RegExp(`(?:^|\\s)${e}\\s*=\\s*["']([^"']+)["']`, "i")
812
829
  )?.[1]?.replaceAll("&amp;", "&");
813
830
  }
814
- function de(t, e) {
831
+ function $e(t, e) {
815
832
  if (!t)
816
833
  return !0;
817
834
  if (t.includes("'none'") || t.includes("'strict-dynamic'") && t.some(
@@ -835,91 +852,91 @@ function de(t, e) {
835
852
  } catch {
836
853
  return !1;
837
854
  }
838
- const s = o.hostname.startsWith("*.") ? r.hostname.endsWith(o.hostname.slice(1)) && r.hostname !== o.hostname.slice(2) : r.hostname === o.hostname, c = o.pathname === "/" || o.pathname.endsWith("/") ? r.pathname.startsWith(o.pathname) : r.pathname === o.pathname;
839
- return r.protocol === o.protocol && s && r.port === o.port && c;
855
+ const i = o.hostname.startsWith("*.") ? r.hostname.endsWith(o.hostname.slice(1)) && r.hostname !== o.hostname.slice(2) : r.hostname === o.hostname, c = o.pathname === "/" || o.pathname.endsWith("/") ? r.pathname.startsWith(o.pathname) : r.pathname === o.pathname;
856
+ return r.protocol === o.protocol && i && r.port === o.port && c;
840
857
  });
841
858
  }
842
- function Q(t, e) {
843
- const r = t.toLowerCase(), n = [], o = `<${e}`, s = `</${e}`;
859
+ function at(t, e) {
860
+ const r = t.toLowerCase(), n = [], o = `<${e}`, i = `</${e}`;
844
861
  let c = 0;
845
862
  for (; c < t.length; ) {
846
- const a = r.indexOf(o, c);
847
- if (a === -1)
863
+ const s = r.indexOf(o, c);
864
+ if (s === -1)
848
865
  break;
849
- const i = r.indexOf(">", a + o.length), u = i === -1 ? -1 : r.indexOf(s, i + 1), f = u === -1 ? -1 : r.indexOf(">", u + s.length);
850
- if (i === -1 || u === -1 || f === -1)
866
+ const a = r.indexOf(">", s + o.length), u = a === -1 ? -1 : r.indexOf(i, a + 1), d = u === -1 ? -1 : r.indexOf(">", u + i.length);
867
+ if (a === -1 || u === -1 || d === -1)
851
868
  throw new Error(`Static output contains an unclosed <${e}> element.`);
852
869
  n.push({
853
- attributes: t.slice(a + o.length, i),
854
- content: t.slice(i + 1, u)
855
- }), c = f + 1;
870
+ attributes: t.slice(s + o.length, a),
871
+ content: t.slice(a + 1, u)
872
+ }), c = d + 1;
856
873
  }
857
874
  return n;
858
875
  }
859
- function X(t) {
876
+ function st(t) {
860
877
  return Object.fromEntries(
861
878
  [...t.entries()].sort(([e], [r]) => e.localeCompare(r))
862
879
  );
863
880
  }
864
- async function he(t, e, r, n) {
865
- const o = C(t);
866
- await T(o, { recursive: !0 });
867
- const s = await k(y(o, ".demiurge-static-"));
881
+ async function Oe(t, e, r, n) {
882
+ const o = M(t);
883
+ await x(o, { recursive: !0 });
884
+ const i = await G($(o, ".demiurge-static-"));
868
885
  try {
869
- for (const i of [...e, ...r]) {
870
- const u = W(s, i.file);
871
- await T(C(u), { recursive: !0 }), await b(u, i.body);
886
+ for (const a of [...e, ...r]) {
887
+ const u = B(i, a.file);
888
+ await x(M(u), { recursive: !0 }), await L(u, a.body);
872
889
  }
873
- await b(
874
- y(s, K),
890
+ await L(
891
+ $(i, ot),
875
892
  `${JSON.stringify(n, null, 2)}
876
893
  `
877
894
  );
878
- const c = await pe(t);
879
- await T(t, { recursive: !0 }), await D(s, t, { recursive: !0, force: !0 });
880
- const a = new Set(
881
- [...e, ...r].map((i) => i.file)
895
+ const c = await Re(t);
896
+ await x(t, { recursive: !0 }), await K(i, t, { recursive: !0, force: !0 });
897
+ const s = new Set(
898
+ [...e, ...r].map((a) => a.file)
882
899
  );
883
- for (const i of c)
884
- a.has(i) || await A(W(t, i), { force: !0 });
900
+ for (const a of c)
901
+ s.has(a) || await C(B(t, a), { force: !0 });
885
902
  } finally {
886
- await A(s, { force: !0, recursive: !0 });
903
+ await C(i, { force: !0, recursive: !0 });
887
904
  }
888
905
  }
889
- async function pe(t) {
906
+ async function Re(t) {
890
907
  try {
891
- const e = await O(y(t, K), "utf8"), r = JSON.parse(e);
908
+ const e = await A($(t, ot), "utf8"), r = JSON.parse(e);
892
909
  if (r.adapter !== "static" || r.version !== 1 || !Array.isArray(r.entries))
893
910
  return [];
894
911
  const n = Array.isArray(r.fontFiles) ? r.fontFiles : [], o = Array.isArray(r.imageFiles) ? r.imageFiles : [];
895
912
  return [
896
- ...r.entries.map((s) => s.file),
913
+ ...r.entries.map((i) => i.file),
897
914
  ...n,
898
915
  ...o
899
916
  ].flatMap(
900
- (s) => typeof s == "string" && Y(s) ? [s] : []
917
+ (i) => typeof i == "string" && ct(i) ? [i] : []
901
918
  );
902
919
  } catch {
903
920
  return [];
904
921
  }
905
922
  }
906
- function W(t, e) {
907
- if (!Y(e))
923
+ function B(t, e) {
924
+ if (!ct(e))
908
925
  throw new Error(`Static output file must stay inside the output directory: ${JSON.stringify(e)}.`);
909
926
  const r = h(t), n = h(r, e);
910
- if (w(r, n).split(S).includes(".."))
927
+ if (E(r, n).split(O).includes(".."))
911
928
  throw new Error(`Static output file escaped the output directory: ${JSON.stringify(e)}.`);
912
929
  return n;
913
930
  }
914
- function Y(t) {
931
+ function ct(t) {
915
932
  return !!t && !t.startsWith("/") && !t.startsWith("\\") && !t.split(/[\\/]/).includes("..");
916
933
  }
917
934
  export {
918
- Ne as createStaticPreviewServer,
919
- Lt as createVercelOutputConfig,
920
- be as generateStaticOutput,
921
- xe as generateVercelStaticOutput,
922
- qt as staticAdapter,
923
- Fe as vercelStatic
935
+ Me as createStaticPreviewServer,
936
+ Bt as createVercelOutputConfig,
937
+ We as generateStaticOutput,
938
+ De as generateVercelStaticOutput,
939
+ k as staticAdapter,
940
+ je as vercelStatic
924
941
  };
925
942
  //# sourceMappingURL=index.js.map