@demiurgejs/core 0.2.0-beta.3 → 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 (237) hide show
  1. package/README.md +36 -11
  2. package/bin/demiurge.mjs +47 -13
  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 +388 -5
  6. package/dist/browser/file-router.d.ts.map +1 -1
  7. package/dist/browser/focus.d.ts +20 -0
  8. package/dist/browser/focus.d.ts.map +1 -0
  9. package/dist/browser/index.d.ts +7 -1
  10. package/dist/browser/index.d.ts.map +1 -1
  11. package/dist/browser/mutation-action.d.ts +81 -0
  12. package/dist/browser/mutation-action.d.ts.map +1 -0
  13. package/dist/chunks/document-shell-9GPwtcTt.js +36 -0
  14. package/dist/chunks/document-shell-9GPwtcTt.js.map +1 -0
  15. package/dist/chunks/{image-codec-Di53WpcH.js → image-codec-Dh1POFhE.js} +2 -2
  16. package/dist/chunks/{image-codec-Di53WpcH.js.map → image-codec-Dh1POFhE.js.map} +1 -1
  17. package/dist/chunks/{images-Edar3eU1.js → images-CG7ZzayG.js} +99 -91
  18. package/dist/chunks/images-CG7ZzayG.js.map +1 -0
  19. package/dist/chunks/index-0MNiR_wo.js +833 -0
  20. package/dist/chunks/index-0MNiR_wo.js.map +1 -0
  21. package/dist/chunks/manifest-vO6c0G0W.js +19 -0
  22. package/dist/chunks/manifest-vO6c0G0W.js.map +1 -0
  23. package/dist/chunks/plugin-BZauDxRY.js +2310 -0
  24. package/dist/chunks/plugin-BZauDxRY.js.map +1 -0
  25. package/dist/chunks/session-store-ChModVcq.js +92 -0
  26. package/dist/chunks/session-store-ChModVcq.js.map +1 -0
  27. package/dist/chunks/static-files-ehaD1kE7.js +51 -0
  28. package/dist/chunks/static-files-ehaD1kE7.js.map +1 -0
  29. package/dist/chunks/streaming-GYIsVTQH.js +560 -0
  30. package/dist/chunks/streaming-GYIsVTQH.js.map +1 -0
  31. package/dist/chunks/testing-CUwGj2ie.js +4751 -0
  32. package/dist/chunks/testing-CUwGj2ie.js.map +1 -0
  33. package/dist/chunks/vite-QoqrGl6f.js +259 -0
  34. package/dist/chunks/vite-QoqrGl6f.js.map +1 -0
  35. package/dist/cli.d.ts +19 -25
  36. package/dist/cli.d.ts.map +1 -1
  37. package/dist/cli.js +289 -128
  38. package/dist/cli.js.map +1 -1
  39. package/dist/config/define.d.ts +3 -0
  40. package/dist/config/define.d.ts.map +1 -0
  41. package/dist/config/index.d.ts +7 -0
  42. package/dist/config/index.d.ts.map +1 -0
  43. package/dist/config/index.js +78 -0
  44. package/dist/config/index.js.map +1 -0
  45. package/dist/config/load.d.ts +12 -0
  46. package/dist/config/load.d.ts.map +1 -0
  47. package/dist/config/types.d.ts +74 -0
  48. package/dist/config/types.d.ts.map +1 -0
  49. package/dist/config/validate.d.ts +9 -0
  50. package/dist/config/validate.d.ts.map +1 -0
  51. package/dist/config/vite.d.ts +12 -0
  52. package/dist/config/vite.d.ts.map +1 -0
  53. package/dist/data/cache.d.ts +2 -0
  54. package/dist/data/cache.d.ts.map +1 -1
  55. package/dist/data/idempotency.d.ts.map +1 -1
  56. package/dist/deployment/testing.d.ts +25 -0
  57. package/dist/deployment/testing.d.ts.map +1 -0
  58. package/dist/deployment/testing.js +171 -0
  59. package/dist/deployment/testing.js.map +1 -0
  60. package/dist/document/hydration.d.ts +9 -0
  61. package/dist/document/hydration.d.ts.map +1 -1
  62. package/dist/document/index.d.ts +4 -2
  63. package/dist/document/index.d.ts.map +1 -1
  64. package/dist/document/metadata.d.ts +8 -0
  65. package/dist/document/metadata.d.ts.map +1 -1
  66. package/dist/document/navigation.d.ts +28 -0
  67. package/dist/document/navigation.d.ts.map +1 -0
  68. package/dist/document/render.d.ts +3 -1
  69. package/dist/document/render.d.ts.map +1 -1
  70. package/dist/document/seo.d.ts.map +1 -1
  71. package/dist/edge/assets.d.ts.map +1 -1
  72. package/dist/edge/index.js +55 -73
  73. package/dist/edge/index.js.map +1 -1
  74. package/dist/index.d.ts +12 -10
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +1883 -692
  77. package/dist/index.js.map +1 -1
  78. package/dist/inspect/command.d.ts +28 -0
  79. package/dist/inspect/command.d.ts.map +1 -0
  80. package/dist/inspect/index.d.ts +9 -0
  81. package/dist/inspect/index.d.ts.map +1 -0
  82. package/dist/inspect/redact.d.ts +35 -0
  83. package/dist/inspect/redact.d.ts.map +1 -0
  84. package/dist/inspect/report.d.ts +24 -0
  85. package/dist/inspect/report.d.ts.map +1 -0
  86. package/dist/inspect/types.d.ts +102 -0
  87. package/dist/inspect/types.d.ts.map +1 -0
  88. package/dist/internal/testing.js +5 -5
  89. package/dist/kv/index.d.ts +2 -0
  90. package/dist/kv/index.d.ts.map +1 -1
  91. package/dist/kv/index.js +170 -73
  92. package/dist/kv/index.js.map +1 -1
  93. package/dist/kv/session-store.d.ts +20 -0
  94. package/dist/kv/session-store.d.ts.map +1 -0
  95. package/dist/manifest.d.ts +10 -0
  96. package/dist/manifest.d.ts.map +1 -0
  97. package/dist/node/http.d.ts +5 -0
  98. package/dist/node/http.d.ts.map +1 -1
  99. package/dist/node/image.d.ts.map +1 -1
  100. package/dist/node/index.d.ts +4 -1
  101. package/dist/node/index.d.ts.map +1 -1
  102. package/dist/node/index.js +257 -182
  103. package/dist/node/index.js.map +1 -1
  104. package/dist/node/serve.d.ts +47 -0
  105. package/dist/node/serve.d.ts.map +1 -0
  106. package/dist/node/static.d.ts.map +1 -1
  107. package/dist/platform/fonts.d.ts.map +1 -1
  108. package/dist/platform/image-url.d.ts.map +1 -1
  109. package/dist/platform/url.d.ts +19 -0
  110. package/dist/platform/url.d.ts.map +1 -0
  111. package/dist/platform/web-vitals.d.ts.map +1 -1
  112. package/dist/redis/index.d.ts +2 -0
  113. package/dist/redis/index.d.ts.map +1 -1
  114. package/dist/redis/index.js +186 -69
  115. package/dist/redis/index.js.map +1 -1
  116. package/dist/redis/session-store.d.ts +9 -0
  117. package/dist/redis/session-store.d.ts.map +1 -0
  118. package/dist/route/index.d.ts +3 -2
  119. package/dist/route/index.d.ts.map +1 -1
  120. package/dist/route/mutation.d.ts +97 -0
  121. package/dist/route/mutation.d.ts.map +1 -0
  122. package/dist/route/serialization.d.ts +24 -0
  123. package/dist/route/serialization.d.ts.map +1 -0
  124. package/dist/route/types.d.ts +6 -1
  125. package/dist/route/types.d.ts.map +1 -1
  126. package/dist/route/webhook.d.ts +6 -1
  127. package/dist/route/webhook.d.ts.map +1 -1
  128. package/dist/router/manifest.d.ts +8 -0
  129. package/dist/router/manifest.d.ts.map +1 -1
  130. package/dist/router/navigation-data.d.ts +9 -1
  131. package/dist/router/navigation-data.d.ts.map +1 -1
  132. package/dist/routing/generate.d.ts +3 -0
  133. package/dist/routing/generate.d.ts.map +1 -1
  134. package/dist/routing/index.d.ts +3 -1
  135. package/dist/routing/index.d.ts.map +1 -1
  136. package/dist/routing/locale.d.ts +43 -0
  137. package/dist/routing/locale.d.ts.map +1 -0
  138. package/dist/routing/types.d.ts +12 -0
  139. package/dist/routing/types.d.ts.map +1 -1
  140. package/dist/security/audit.d.ts +2 -1
  141. package/dist/security/audit.d.ts.map +1 -1
  142. package/dist/security/authorization.d.ts +36 -0
  143. package/dist/security/authorization.d.ts.map +1 -0
  144. package/dist/security/cookie-session.d.ts +43 -0
  145. package/dist/security/cookie-session.d.ts.map +1 -0
  146. package/dist/security/csrf.d.ts +1 -1
  147. package/dist/security/csrf.d.ts.map +1 -1
  148. package/dist/security/env-startup.d.ts +13 -0
  149. package/dist/security/env-startup.d.ts.map +1 -0
  150. package/dist/security/env.d.ts +49 -11
  151. package/dist/security/env.d.ts.map +1 -1
  152. package/dist/security/exceptions.d.ts +29 -0
  153. package/dist/security/exceptions.d.ts.map +1 -0
  154. package/dist/security/finding-codes.d.ts +56 -0
  155. package/dist/security/finding-codes.d.ts.map +1 -0
  156. package/dist/security/index.d.ts +14 -3
  157. package/dist/security/index.d.ts.map +1 -1
  158. package/dist/security/policy.d.ts +2 -5
  159. package/dist/security/policy.d.ts.map +1 -1
  160. package/dist/security/report.d.ts +2 -1
  161. package/dist/security/report.d.ts.map +1 -1
  162. package/dist/security/request.d.ts +1 -0
  163. package/dist/security/request.d.ts.map +1 -1
  164. package/dist/security/session-manager.d.ts +32 -0
  165. package/dist/security/session-manager.d.ts.map +1 -0
  166. package/dist/security/session-store.d.ts +51 -0
  167. package/dist/security/session-store.d.ts.map +1 -0
  168. package/dist/security/testing.d.ts +10 -0
  169. package/dist/security/testing.d.ts.map +1 -0
  170. package/dist/security/testing.js +145 -0
  171. package/dist/security/testing.js.map +1 -0
  172. package/dist/security/types.d.ts +139 -5
  173. package/dist/security/types.d.ts.map +1 -1
  174. package/dist/security/upload.d.ts +3 -3
  175. package/dist/security/upload.d.ts.map +1 -1
  176. package/dist/security/verification.d.ts.map +1 -1
  177. package/dist/server/document-shell.d.ts.map +1 -1
  178. package/dist/server/errors.d.ts +1 -0
  179. package/dist/server/errors.d.ts.map +1 -1
  180. package/dist/server/index.d.ts +1 -0
  181. package/dist/server/index.d.ts.map +1 -1
  182. package/dist/server/not-found.d.ts +1 -0
  183. package/dist/server/not-found.d.ts.map +1 -1
  184. package/dist/server/render-tree.d.ts.map +1 -1
  185. package/dist/server/request-handler.d.ts +7 -2
  186. package/dist/server/request-handler.d.ts.map +1 -1
  187. package/dist/server/request-metadata.d.ts +1 -0
  188. package/dist/server/request-metadata.d.ts.map +1 -1
  189. package/dist/server/ssr.d.ts +2 -0
  190. package/dist/server/ssr.d.ts.map +1 -1
  191. package/dist/server-only/browser.d.ts +2 -0
  192. package/dist/server-only/browser.d.ts.map +1 -0
  193. package/dist/server-only/browser.js +4 -0
  194. package/dist/server-only/browser.js.map +1 -0
  195. package/dist/server-only/index.d.ts +2 -0
  196. package/dist/server-only/index.d.ts.map +1 -0
  197. package/dist/server-only/index.js +2 -0
  198. package/dist/server-only/index.js.map +1 -0
  199. package/dist/static/index.d.ts +2 -0
  200. package/dist/static/index.d.ts.map +1 -1
  201. package/dist/static/index.js +380 -363
  202. package/dist/static/index.js.map +1 -1
  203. package/dist/static/preview.d.ts.map +1 -1
  204. package/dist/static/vercel.d.ts +11 -2
  205. package/dist/static/vercel.d.ts.map +1 -1
  206. package/dist/static-files.d.ts +12 -0
  207. package/dist/static-files.d.ts.map +1 -1
  208. package/dist/type-guards.d.ts +19 -0
  209. package/dist/type-guards.d.ts.map +1 -0
  210. package/dist/vite/env-boundary.d.ts +14 -0
  211. package/dist/vite/env-boundary.d.ts.map +1 -0
  212. package/dist/vite/index.d.ts +13 -6
  213. package/dist/vite/index.d.ts.map +1 -1
  214. package/dist/vite/index.js +29 -1560
  215. package/dist/vite/index.js.map +1 -1
  216. package/dist/vite/plugin.d.ts +24 -3
  217. package/dist/vite/plugin.d.ts.map +1 -1
  218. package/dist/vite/policy-verification.d.ts +33 -2
  219. package/dist/vite/policy-verification.d.ts.map +1 -1
  220. package/dist/vite/route-audit.d.ts +14 -2
  221. package/dist/vite/route-audit.d.ts.map +1 -1
  222. package/dist/vite/server-only-boundary.d.ts +8 -0
  223. package/dist/vite/server-only-boundary.d.ts.map +1 -0
  224. package/package.json +24 -6
  225. package/dist/chunks/document-shell-WoM8yZlR.js +0 -35
  226. package/dist/chunks/document-shell-WoM8yZlR.js.map +0 -1
  227. package/dist/chunks/images-Edar3eU1.js.map +0 -1
  228. package/dist/chunks/request-metadata-DaIYq4Ea.js +0 -677
  229. package/dist/chunks/request-metadata-DaIYq4Ea.js.map +0 -1
  230. package/dist/chunks/static-files-DUjHw-4H.js +0 -11
  231. package/dist/chunks/static-files-DUjHw-4H.js.map +0 -1
  232. package/dist/chunks/streaming-D0fGAuiO.js +0 -469
  233. package/dist/chunks/streaming-D0fGAuiO.js.map +0 -1
  234. package/dist/chunks/testing-CRflAw4X.js +0 -3475
  235. package/dist/chunks/testing-CRflAw4X.js.map +0 -1
  236. package/dist/route/action.d.ts +0 -33
  237. package/dist/route/action.d.ts.map +0 -1
@@ -1,95 +1,79 @@
1
- import { createServer as C } from "node:http";
2
- import { d as O } from "../chunks/request-metadata-DaIYq4Ea.js";
3
- import { v, t as A, U as M, w as H, a as L, b as k } from "../chunks/streaming-D0fGAuiO.js";
4
- import { c as Oe, d as ve, r as Ae, e as Me, f as He } from "../chunks/streaming-D0fGAuiO.js";
1
+ import { createServer as H } from "node:http";
2
+ import { d as C } from "../chunks/index-0MNiR_wo.js";
3
+ import { r as I, v as L, t as x, U as A, w as F, a as M, b as k } from "../chunks/streaming-GYIsVTQH.js";
4
+ import { C as _e, c as je, d as Be, e as ze, f as qe } from "../chunks/streaming-GYIsVTQH.js";
5
5
  import { constants as S } from "node:fs";
6
- import { realpath as T, open as F, lstat as j } from "node:fs/promises";
7
- import { resolve as x, sep as w, extname as P, relative as W, join as $ } from "node:path";
8
- import { Readable as N } from "node:stream";
9
- import { I as _, R as D, i as U } from "../chunks/static-files-DUjHw-4H.js";
10
- const z = {
11
- ".avif": "image/avif",
12
- ".css": "text/css; charset=utf-8",
13
- ".gif": "image/gif",
14
- ".html": "text/html; charset=utf-8",
15
- ".ico": "image/x-icon",
16
- ".jpeg": "image/jpeg",
17
- ".jpg": "image/jpeg",
18
- ".js": "text/javascript; charset=utf-8",
19
- ".json": "application/json; charset=utf-8",
20
- ".mjs": "text/javascript; charset=utf-8",
21
- ".png": "image/png",
22
- ".svg": "image/svg+xml",
23
- ".txt": "text/plain; charset=utf-8",
24
- ".webmanifest": "application/manifest+json",
25
- ".webp": "image/webp",
26
- ".woff": "font/woff",
27
- ".woff2": "font/woff2"
28
- }, G = /* @__PURE__ */ new Set(["demiurge-manifest.json", "index.html"]);
29
- function V(e) {
30
- const t = x(e.root), n = T(t), r = te(e.prefix), o = e.exclude ?? re, i = e.immutable ?? ne;
31
- return async function(s) {
32
- if (s.method !== "GET" && s.method !== "HEAD")
6
+ import { realpath as T, open as W, lstat as D, readFile as $ } from "node:fs/promises";
7
+ import { resolve as P, sep as y, extname as U, relative as _, join as O } from "node:path";
8
+ import { Readable as E } from "node:stream";
9
+ import { I as j, R as B, i as z, c as q } from "../chunks/static-files-ehaD1kE7.js";
10
+ import { fileURLToPath as G } from "node:url";
11
+ import { p as V } from "../chunks/manifest-vO6c0G0W.js";
12
+ const Y = /* @__PURE__ */ new Set(["demiurge-manifest.json", "index.html"]);
13
+ function J(e) {
14
+ const t = P(e.root), n = T(t), r = ae(e.prefix), o = e.exclude ?? se, a = e.immutable ?? ie;
15
+ return async function(c) {
16
+ if (c.method !== "GET" && c.method !== "HEAD")
33
17
  return null;
34
- const m = K(
18
+ const m = ee(
35
19
  t,
36
20
  r,
37
- new URL(s.url).pathname
21
+ new URL(c.url).pathname
38
22
  );
39
- if (!m || o(oe(t, m)))
23
+ if (!m || o(ce(t, m)))
40
24
  return null;
41
- const g = await X(t, await Q(n), m);
25
+ const g = await ne(t, await te(n), m);
42
26
  if (!g)
43
27
  return null;
44
- const { file: h, stats: a } = g, l = q(a.size, a.mtimeMs), f = a.mtime.toUTCString(), c = new Headers({
28
+ const { file: h, stats: i } = g, s = K(i.size, i.mtimeMs), f = i.mtime.toUTCString(), l = new Headers({
45
29
  "accept-ranges": "bytes",
46
- "cache-control": i(ie(m)) ? _ : D,
47
- "content-length": String(a.size),
48
- "content-type": ae(m),
30
+ "cache-control": a(le(m)) ? j : B,
31
+ "content-length": String(i.size),
32
+ "content-type": ue(m),
49
33
  "cross-origin-resource-policy": "same-origin",
50
- etag: l,
34
+ etag: s,
51
35
  "last-modified": f,
52
36
  "x-content-type-options": "nosniff"
53
37
  });
54
- if (B(s, l, a.mtimeMs))
55
- return await h.close(), c.delete("content-length"), c.delete("content-type"), new Response(null, { headers: c, status: 304 });
56
- const d = J(s, a.mtimeMs) ? Y(s.headers.get("range"), a.size) : null;
57
- if (d === "unsatisfiable")
58
- return await h.close(), c.delete("content-length"), c.delete("content-type"), c.set("content-range", `bytes */${a.size}`), new Response(null, { headers: c, status: 416 });
59
- if (d) {
60
- const p = d.end - d.start + 1;
61
- return c.set("content-length", String(p)), c.set("content-range", `bytes ${d.start}-${d.end}/${a.size}`), s.method === "HEAD" ? (await h.close(), new Response(null, { headers: c, status: 206 })) : new Response(
62
- N.toWeb(
63
- h.createReadStream({ end: d.end, start: d.start })
38
+ if (Q(c, s, i.mtimeMs))
39
+ return await h.close(), l.delete("content-length"), l.delete("content-type"), new Response(null, { headers: l, status: 304 });
40
+ const u = Z(c, i.mtimeMs) ? X(c.headers.get("range"), i.size) : null;
41
+ if (u === "unsatisfiable")
42
+ return await h.close(), l.delete("content-length"), l.delete("content-type"), l.set("content-range", `bytes */${i.size}`), new Response(null, { headers: l, status: 416 });
43
+ if (u) {
44
+ const w = u.end - u.start + 1;
45
+ return l.set("content-length", String(w)), l.set("content-range", `bytes ${u.start}-${u.end}/${i.size}`), c.method === "HEAD" ? (await h.close(), new Response(null, { headers: l, status: 206 })) : new Response(
46
+ E.toWeb(
47
+ h.createReadStream({ end: u.end, start: u.start })
64
48
  ),
65
- { headers: c, status: 206 }
49
+ { headers: l, status: 206 }
66
50
  );
67
51
  }
68
- return s.method === "HEAD" ? (await h.close(), new Response(null, { headers: c })) : new Response(
69
- N.toWeb(h.createReadStream()),
70
- { headers: c }
52
+ return c.method === "HEAD" ? (await h.close(), new Response(null, { headers: l })) : new Response(
53
+ E.toWeb(h.createReadStream()),
54
+ { headers: l }
71
55
  );
72
56
  };
73
57
  }
74
- function q(e, t) {
58
+ function K(e, t) {
75
59
  return `W/"${e.toString(16)}-${Math.trunc(t).toString(16)}"`;
76
60
  }
77
- function B(e, t, n) {
61
+ function Q(e, t, n) {
78
62
  const r = e.headers.get("if-none-match");
79
63
  if (r !== null)
80
64
  return r.trim() === "*" || r.split(",").some(
81
- (u) => E(u) === E(t)
65
+ (d) => N(d) === N(t)
82
66
  );
83
67
  const o = e.headers.get("if-modified-since");
84
68
  if (o === null)
85
69
  return !1;
86
- const i = Date.parse(o);
87
- return Number.isFinite(i) && Math.floor(n / 1e3) * 1e3 <= i;
70
+ const a = Date.parse(o);
71
+ return Number.isFinite(a) && Math.floor(n / 1e3) * 1e3 <= a;
88
72
  }
89
- function E(e) {
73
+ function N(e) {
90
74
  return e.trim().replace(/^W\//i, "");
91
75
  }
92
- function Y(e, t) {
76
+ function X(e, t) {
93
77
  if (e === null)
94
78
  return null;
95
79
  const n = /^bytes=(\d*)-(\d*)$/.exec(e.trim());
@@ -98,13 +82,13 @@ function Y(e, t) {
98
82
  if (t === 0)
99
83
  return "unsatisfiable";
100
84
  if (!n[1]) {
101
- const i = Number(n[2]);
102
- return !Number.isSafeInteger(i) || i <= 0 ? null : { start: Math.max(0, t - i), end: t - 1 };
85
+ const a = Number(n[2]);
86
+ return !Number.isSafeInteger(a) || a <= 0 ? null : { start: Math.max(0, t - a), end: t - 1 };
103
87
  }
104
88
  const r = Number(n[1]), o = n[2] ? Number(n[2]) : t - 1;
105
89
  return !Number.isSafeInteger(r) || !Number.isSafeInteger(o) ? null : r >= t ? "unsatisfiable" : n[2] && o < r ? null : { start: r, end: Math.min(o, t - 1) };
106
90
  }
107
- function J(e, t) {
91
+ function Z(e, t) {
108
92
  const n = e.headers.get("if-range");
109
93
  if (n === null)
110
94
  return !0;
@@ -113,7 +97,7 @@ function J(e, t) {
113
97
  const r = Date.parse(n);
114
98
  return Number.isFinite(r) && Math.floor(t / 1e3) * 1e3 <= r;
115
99
  }
116
- function K(e, t, n) {
100
+ function ee(e, t, n) {
117
101
  let r;
118
102
  try {
119
103
  r = decodeURIComponent(n);
@@ -129,18 +113,18 @@ function K(e, t, n) {
129
113
  }
130
114
  if (r.endsWith("/"))
131
115
  return null;
132
- const o = x(e, `.${r}`);
133
- return o.startsWith(`${e}${w}`) ? o : null;
116
+ const o = P(e, `.${r}`);
117
+ return o.startsWith(`${e}${y}`) ? o : null;
134
118
  }
135
- async function Q(e) {
119
+ async function te(e) {
136
120
  try {
137
121
  return await e;
138
122
  } catch {
139
123
  return null;
140
124
  }
141
125
  }
142
- async function X(e, t, n) {
143
- if (!t || !await Z(e, n))
126
+ async function ne(e, t, n) {
127
+ if (!t || !await re(e, n))
144
128
  return null;
145
129
  let r;
146
130
  try {
@@ -148,104 +132,169 @@ async function X(e, t, n) {
148
132
  } catch {
149
133
  return null;
150
134
  }
151
- if (!ee(t, r))
135
+ if (!oe(t, r))
152
136
  return null;
153
137
  const o = typeof S.O_NOFOLLOW == "number" ? S.O_NOFOLLOW : 0;
154
- let i;
138
+ let a;
155
139
  try {
156
- i = await F(n, S.O_RDONLY | o);
140
+ a = await W(n, S.O_RDONLY | o);
157
141
  } catch {
158
142
  return null;
159
143
  }
160
144
  try {
161
- const u = await i.stat();
162
- return u.isFile() ? { file: i, stats: u } : (await i.close(), null);
145
+ const d = await a.stat();
146
+ return d.isFile() ? { file: a, stats: d } : (await a.close(), null);
163
147
  } catch {
164
- return await i.close(), null;
148
+ return await a.close(), null;
165
149
  }
166
150
  }
167
- async function Z(e, t) {
168
- const n = W(e, t).split(w);
151
+ async function re(e, t) {
152
+ const n = _(e, t).split(y);
169
153
  let r = e;
170
154
  try {
171
155
  for (const o of n)
172
- if (r = $(r, o), (await j(r)).isSymbolicLink())
156
+ if (r = O(r, o), (await D(r)).isSymbolicLink())
173
157
  return !1;
174
158
  } catch {
175
159
  return !1;
176
160
  }
177
161
  return !0;
178
162
  }
179
- function ee(e, t) {
180
- return t.startsWith(`${e}${w}`);
163
+ function oe(e, t) {
164
+ return t.startsWith(`${e}${y}`);
181
165
  }
182
- function te(e) {
166
+ function ae(e) {
183
167
  return !e || e === "/" ? "" : `/${e.replace(/^\/|\/$/g, "")}/`;
184
168
  }
185
- function ne(e) {
186
- return U(e);
169
+ function ie(e) {
170
+ return z(e);
187
171
  }
188
- function re(e) {
189
- return G.has(e);
172
+ function se(e) {
173
+ return Y.has(e);
190
174
  }
191
- function oe(e, t) {
192
- return t.slice(e.length + 1).split(w).join("/");
175
+ function ce(e, t) {
176
+ return t.slice(e.length + 1).split(y).join("/");
193
177
  }
194
- function ie(e) {
195
- return e.slice(e.lastIndexOf(w) + 1);
178
+ function le(e) {
179
+ return e.slice(e.lastIndexOf(y) + 1);
196
180
  }
197
- function ae(e) {
198
- return z[P(e).toLowerCase()] ?? "application/octet-stream";
181
+ function ue(e) {
182
+ return q(U(e));
183
+ }
184
+ const de = "dist/client", fe = "/.well-known/ready";
185
+ async function We(e) {
186
+ const t = e.env ?? process.env, n = G(
187
+ new URL(e.clientDir ?? de, e.base)
188
+ ), r = V(
189
+ await $(O(n, "demiurge-manifest.json"), "utf8")
190
+ ), o = e.host ?? t.HOST ?? "127.0.0.1", a = me(t.PORT, e.port), d = he(
191
+ e.allowedHosts,
192
+ t.ALLOWED_HOSTS,
193
+ o
194
+ ), c = e.name ?? "Demiurge Node server", m = e.readyPath === !1 ? void 0 : e.readyPath ?? fe, g = [], h = {
195
+ page: {
196
+ clientEntry: r.clientEntry,
197
+ renderPage: I,
198
+ styles: r.styles
199
+ },
200
+ root: n,
201
+ waitUntil(u) {
202
+ g.push(u);
203
+ }
204
+ }, i = await e.createHandler(h), s = Se({
205
+ allowedHosts: d,
206
+ handler: i,
207
+ onError: e.onError,
208
+ readyPath: m,
209
+ shutdown: e.shutdown,
210
+ static: ge(e.static, h),
211
+ timeouts: e.timeouts,
212
+ trustProxy: e.trustProxy
213
+ });
214
+ h.waitUntil = (u) => {
215
+ s.waitUntil(u);
216
+ };
217
+ for (const u of g)
218
+ s.waitUntil(u);
219
+ await new Promise((u, w) => {
220
+ s.once("error", w), s.listen(a, o, () => {
221
+ s.off("error", w), u();
222
+ });
223
+ });
224
+ const f = s.address(), l = typeof f == "object" && f ? f.port : a;
225
+ return e.onListen ? e.onListen({ host: o, port: l, server: s }) : console.log(`${c} listening on http://${o}:${l}`), s;
226
+ }
227
+ function me(e, t) {
228
+ const n = e ?? String(t ?? 4173), r = Number(n);
229
+ if (!Number.isSafeInteger(r) || r < 0 || r > 65535)
230
+ throw new Error("Demiurge Node PORT must be an integer from 0 through 65535.");
231
+ return r;
232
+ }
233
+ function he(e, t, n) {
234
+ return e || (t ? t.split(",").map((r) => r.trim()).filter(Boolean) : n === "localhost" ? [n] : [n, "localhost"]);
235
+ }
236
+ function ge(e, t) {
237
+ if (!e)
238
+ return { root: t.root };
239
+ if (typeof e != "function")
240
+ return e;
241
+ const n = e(t);
242
+ if (n instanceof Promise)
243
+ throw new TypeError(
244
+ "The `static` option must be a StaticFileHandlerOptions object or a factory `(context) => StaticFileHandler | StaticFileHandlerOptions`. It looks like a StaticFileHandler was passed directly. Wrap it: `static: () => yourHandler`."
245
+ );
246
+ return n;
199
247
  }
200
- const Te = O({
248
+ const De = C({
201
249
  name: "node",
202
250
  capabilities: {
203
251
  backgroundLifetime: !0,
204
252
  crossOriginIsolationHeaders: !0,
205
253
  nonceInjection: !0,
254
+ requestTimeoutEnforcement: !0,
206
255
  streaming: !0
207
256
  }
208
- }), se = {
257
+ }), we = {
209
258
  headersTimeout: 66e3,
210
259
  keepAliveTimeout: 65e3,
211
260
  requestTimeout: 3e5
212
- }, ce = 3e4;
213
- function le(e) {
214
- v(e);
215
- const t = ge(e.static), n = e.onError ?? b;
216
- return function(i, u) {
217
- const s = ue(i, u);
218
- r(i, u, s.signal).catch((m) => {
219
- s.signal.aborted || (n(m, i), he(u));
220
- }).finally(s.cleanup);
261
+ }, ye = 3e4;
262
+ function pe(e) {
263
+ L(e);
264
+ const t = Pe(e.static), n = e.onError ?? p;
265
+ return function(a, d) {
266
+ const c = be(a, d);
267
+ r(a, d, c.signal).catch((m) => {
268
+ c.signal.aborted || (n(m, a), Oe(d));
269
+ }).finally(c.cleanup);
221
270
  };
222
- async function r(o, i, u) {
223
- let s;
271
+ async function r(o, a, d) {
272
+ let c;
224
273
  try {
225
- s = A(o, {
274
+ c = x(o, {
226
275
  allowedHosts: e.allowedHosts,
227
- signal: u,
276
+ signal: d,
228
277
  trustProxy: e.trustProxy
229
278
  });
230
279
  } catch (g) {
231
- if (g instanceof M) {
232
- H(i);
280
+ if (g instanceof A) {
281
+ F(a);
233
282
  return;
234
283
  }
235
- if (g instanceof L) {
236
- fe(i);
284
+ if (g instanceof M) {
285
+ Re(a);
237
286
  return;
238
287
  }
239
288
  throw g;
240
289
  }
241
- const m = await t?.(s);
290
+ const m = await t?.(c);
242
291
  await k(
243
- i,
244
- m ?? await e.handler(s)
292
+ a,
293
+ m ?? await e.handler(c)
245
294
  );
246
295
  }
247
296
  }
248
- function ue(e, t) {
297
+ function be(e, t) {
249
298
  const n = new AbortController(), r = () => {
250
299
  n.signal.aborted || n.abort(new DOMException("Client disconnected.", "AbortError"));
251
300
  }, o = () => {
@@ -258,16 +307,38 @@ function ue(e, t) {
258
307
  signal: n.signal
259
308
  };
260
309
  }
261
- function fe(e) {
310
+ function Re(e) {
262
311
  e.statusCode = 421, e.setHeader("content-type", "text/plain; charset=utf-8"), e.end("Misdirected Request");
263
312
  }
264
- function xe(e) {
265
- const t = de(e.timeouts), n = C(le(e));
266
- return n.keepAliveTimeout = t.keepAliveTimeout, n.headersTimeout = t.headersTimeout, n.requestTimeout = t.requestTimeout, me(n, e.shutdown);
313
+ function Se(e) {
314
+ const t = Ne(e.timeouts), n = Ee(e.readyPath), r = n ? async (a) => {
315
+ if (new URL(a.url).pathname !== n)
316
+ return e.handler(a);
317
+ const d = o.isReady();
318
+ return new Response(d ? "ready" : "draining", {
319
+ headers: {
320
+ "cache-control": "no-store",
321
+ "content-type": "text/plain; charset=utf-8"
322
+ },
323
+ status: d ? 200 : 503
324
+ });
325
+ } : e.handler, o = H(
326
+ pe({ ...e, handler: r })
327
+ );
328
+ return o.keepAliveTimeout = t.keepAliveTimeout, o.headersTimeout = t.headersTimeout, o.requestTimeout = t.requestTimeout, Te(o, e.shutdown);
329
+ }
330
+ function Ee(e) {
331
+ if (e !== void 0) {
332
+ if (!e.startsWith("/") || e.includes("?"))
333
+ throw new Error(
334
+ "Demiurge Node readyPath must be an absolute path without a query string."
335
+ );
336
+ return e;
337
+ }
267
338
  }
268
- function de(e) {
339
+ function Ne(e) {
269
340
  const t = {
270
- ...se,
341
+ ...we,
271
342
  ...e
272
343
  };
273
344
  for (const [n, r] of Object.entries(t))
@@ -281,87 +352,87 @@ function de(e) {
281
352
  );
282
353
  return t;
283
354
  }
284
- function me(e, t) {
285
- const n = t?.gracePeriod ?? ce;
355
+ function Te(e, t) {
356
+ const n = t?.gracePeriod ?? ye;
286
357
  if (!Number.isSafeInteger(n) || n < 0)
287
358
  throw new Error(
288
359
  "Demiurge Node shutdown gracePeriod must be a non-negative integer in milliseconds."
289
360
  );
290
- let r = !1, o, i;
291
- const u = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set();
292
- e.on("connection", (a) => {
293
- s.set(a, 0), a.once("close", () => s.delete(a));
294
- }), e.on("request", (a, l) => {
295
- const f = l.socket;
361
+ let r = !1, o, a;
362
+ const d = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set();
363
+ e.on("connection", (i) => {
364
+ c.set(i, 0), i.once("close", () => c.delete(i));
365
+ }), e.on("request", (i, s) => {
366
+ const f = s.socket;
296
367
  if (!f)
297
368
  return;
298
- s.set(f, (s.get(f) ?? 0) + 1);
299
- let c = !1;
300
- const d = () => {
301
- if (c)
369
+ c.set(f, (c.get(f) ?? 0) + 1);
370
+ let l = !1;
371
+ const u = () => {
372
+ if (l)
302
373
  return;
303
- c = !0;
304
- const p = Math.max(0, (s.get(f) ?? 1) - 1);
305
- s.set(f, p), r && p === 0 && f.destroy();
374
+ l = !0;
375
+ const w = Math.max(0, (c.get(f) ?? 1) - 1);
376
+ c.set(f, w), r && w === 0 && f.destroy();
306
377
  };
307
- l.once("finish", d), l.once("close", d);
308
- }), e.isReady = () => e.listening && !r, e.waitUntil = (a) => {
309
- const l = Promise.resolve(a).catch((f) => {
378
+ s.once("finish", u), s.once("close", u);
379
+ }), e.isReady = () => e.listening && !r, e.waitUntil = (i) => {
380
+ const s = Promise.resolve(i).catch((f) => {
310
381
  try {
311
- (t?.onBackgroundError ?? b)(f);
312
- } catch (c) {
313
- b(c);
382
+ (t?.onBackgroundError ?? p)(f);
383
+ } catch (l) {
384
+ p(l);
314
385
  }
315
386
  }).then(() => {
316
387
  }).finally(() => {
317
- m.delete(l), i?.();
388
+ m.delete(s), a?.();
318
389
  });
319
- m.add(l);
320
- }, e.shutdown = () => o || (r = !0, t?.onStateChange?.("draining"), o = new Promise((a, l) => {
321
- let f, c = !1, d = !1, p = !1;
322
- const I = setTimeout(() => {
323
- c = !0, e.closeAllConnections(), y();
390
+ m.add(s);
391
+ }, e.shutdown = () => o || (r = !0, t?.onStateChange?.("draining"), o = new Promise((i, s) => {
392
+ let f, l = !1, u = !1, w = !1;
393
+ const v = setTimeout(() => {
394
+ l = !0, e.closeAllConnections(), b();
324
395
  }, n);
325
396
  e.close((R) => {
326
- R && R.code !== "ERR_SERVER_NOT_RUNNING" && (f = R), d = !0, y();
397
+ R && R.code !== "ERR_SERVER_NOT_RUNNING" && (f = R), u = !0, b();
327
398
  }), e.closeIdleConnections(), h(), setImmediate(() => {
328
399
  e.closeIdleConnections(), h();
329
- }), i = y;
330
- function y() {
331
- if (!(p || !d || !c && m.size > 0)) {
332
- if (p = !0, i = void 0, clearTimeout(I), g(), t?.onStateChange?.("stopped"), f) {
333
- l(f);
400
+ }), a = b;
401
+ function b() {
402
+ if (!(w || !u || !l && m.size > 0)) {
403
+ if (w = !0, a = void 0, clearTimeout(v), g(), t?.onStateChange?.("stopped"), f) {
404
+ s(f);
334
405
  return;
335
406
  }
336
- a();
407
+ i();
337
408
  }
338
409
  }
339
410
  }), o), e.on("listening", () => t?.onStateChange?.("ready"));
340
- for (const a of new Set(t?.signals ?? [])) {
341
- const l = () => {
342
- e.shutdown().catch(b);
411
+ for (const i of new Set(t?.signals ?? [])) {
412
+ const s = () => {
413
+ e.shutdown().catch(p);
343
414
  };
344
- u.set(a, l), process.once(a, l);
415
+ d.set(i, s), process.once(i, s);
345
416
  }
346
417
  return e.once("close", g), e;
347
418
  function g() {
348
- for (const [a, l] of u)
349
- process.off(a, l);
350
- u.clear();
419
+ for (const [i, s] of d)
420
+ process.off(i, s);
421
+ d.clear();
351
422
  }
352
423
  function h() {
353
- for (const [a, l] of s)
354
- l === 0 && a.destroy();
424
+ for (const [i, s] of c)
425
+ s === 0 && i.destroy();
355
426
  }
356
427
  }
357
- function ge(e) {
428
+ function Pe(e) {
358
429
  if (e)
359
- return typeof e == "function" ? e : V(e);
430
+ return typeof e == "function" ? e : J(e);
360
431
  }
361
- function b(e) {
432
+ function p(e) {
362
433
  console.error(e);
363
434
  }
364
- function he(e) {
435
+ function Oe(e) {
365
436
  if (e.headersSent) {
366
437
  e.destroy();
367
438
  return;
@@ -369,20 +440,24 @@ function he(e) {
369
440
  e.statusCode = 500, e.setHeader("content-type", "text/plain; charset=utf-8"), e.end("Internal Server Error");
370
441
  }
371
442
  export {
372
- M as UnsupportedMethodError,
373
- L as UntrustedHostError,
374
- Oe as createFontAssetHandler,
375
- ve as createImageOptimizer,
376
- le as createNodeRequestListener,
377
- xe as createNodeServer,
378
- V as createStaticFileHandler,
379
- se as defaultNodeServerTimeouts,
380
- Te as nodeAdapter,
381
- Ae as renderNodePageResponse,
382
- Me as renderStreamingPageResponse,
383
- He as toHeaders,
384
- A as toWebRequest,
385
- v as validateNodeOriginPolicy,
443
+ _e as ConsumedRequestBodyError,
444
+ A as UnsupportedMethodError,
445
+ M as UntrustedHostError,
446
+ je as createFontAssetHandler,
447
+ Be as createImageOptimizer,
448
+ pe as createNodeRequestListener,
449
+ Se as createNodeServer,
450
+ J as createStaticFileHandler,
451
+ de as defaultNodeBuildClientDir,
452
+ fe as defaultNodeBuildReadyPath,
453
+ we as defaultNodeServerTimeouts,
454
+ De as nodeAdapter,
455
+ I as renderNodePageResponse,
456
+ ze as renderStreamingPageResponse,
457
+ We as serveNodeBuild,
458
+ qe as toHeaders,
459
+ x as toWebRequest,
460
+ L as validateNodeOriginPolicy,
386
461
  k as writeWebResponse
387
462
  };
388
463
  //# sourceMappingURL=index.js.map