@demiurgejs/core 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/adapter/index.d.ts +20 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/browser/file-router.d.ts +30 -0
- package/dist/browser/file-router.d.ts.map +1 -0
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/chunks/index-BnX9Qxbm.js +44 -0
- package/dist/chunks/index-BnX9Qxbm.js.map +1 -0
- package/dist/chunks/ssr-O3d7Q73U.js +273 -0
- package/dist/chunks/ssr-O3d7Q73U.js.map +1 -0
- package/dist/chunks/streaming-27pwhjGC.js +343 -0
- package/dist/chunks/streaming-27pwhjGC.js.map +1 -0
- package/dist/chunks/testing-BBnJ5WUR.js +2871 -0
- package/dist/chunks/testing-BBnJ5WUR.js.map +1 -0
- package/dist/data/cache.d.ts +95 -0
- package/dist/data/cache.d.ts.map +1 -0
- package/dist/data/idempotency.d.ts +24 -0
- package/dist/data/idempotency.d.ts.map +1 -0
- package/dist/data/index.d.ts +5 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/testing.d.ts +7 -0
- package/dist/data/testing.d.ts.map +1 -0
- package/dist/data/testing.js +134 -0
- package/dist/data/testing.js.map +1 -0
- package/dist/document/hydration.d.ts +13 -0
- package/dist/document/hydration.d.ts.map +1 -0
- package/dist/document/index.d.ts +13 -0
- package/dist/document/index.d.ts.map +1 -0
- package/dist/document/links.d.ts +17 -0
- package/dist/document/links.d.ts.map +1 -0
- package/dist/document/metadata.d.ts +62 -0
- package/dist/document/metadata.d.ts.map +1 -0
- package/dist/document/render.d.ts +28 -0
- package/dist/document/render.d.ts.map +1 -0
- package/dist/document/scripts.d.ts +24 -0
- package/dist/document/scripts.d.ts.map +1 -0
- package/dist/document/seo.d.ts +42 -0
- package/dist/document/seo.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1318 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/testing.d.ts +3 -0
- package/dist/internal/testing.d.ts.map +1 -0
- package/dist/internal/testing.js +22 -0
- package/dist/internal/testing.js.map +1 -0
- package/dist/node/http.d.ts +28 -0
- package/dist/node/http.d.ts.map +1 -0
- package/dist/node/index.d.ts +45 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +385 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/static.d.ts +9 -0
- package/dist/node/static.d.ts.map +1 -0
- package/dist/node/streaming.d.ts +5 -0
- package/dist/node/streaming.d.ts.map +1 -0
- package/dist/package-name.d.ts +2 -0
- package/dist/package-name.d.ts.map +1 -0
- package/dist/platform/analytics.d.ts +20 -0
- package/dist/platform/analytics.d.ts.map +1 -0
- package/dist/platform/fonts.d.ts +35 -0
- package/dist/platform/fonts.d.ts.map +1 -0
- package/dist/platform/images.d.ts +49 -0
- package/dist/platform/images.d.ts.map +1 -0
- package/dist/platform/index.d.ts +9 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/observability.d.ts +60 -0
- package/dist/platform/observability.d.ts.map +1 -0
- package/dist/route/action.d.ts +33 -0
- package/dist/route/action.d.ts.map +1 -0
- package/dist/route/http-error.d.ts +24 -0
- package/dist/route/http-error.d.ts.map +1 -0
- package/dist/route/index.d.ts +10 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/page.d.ts +5 -0
- package/dist/route/page.d.ts.map +1 -0
- package/dist/route/response.d.ts +100 -0
- package/dist/route/response.d.ts.map +1 -0
- package/dist/route/types.d.ts +186 -0
- package/dist/route/types.d.ts.map +1 -0
- package/dist/route/webhook.d.ts +25 -0
- package/dist/route/webhook.d.ts.map +1 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/manifest.d.ts +117 -0
- package/dist/router/manifest.d.ts.map +1 -0
- package/dist/router/navigation-data.d.ts +9 -0
- package/dist/router/navigation-data.d.ts.map +1 -0
- package/dist/routing/generate.d.ts +14 -0
- package/dist/routing/generate.d.ts.map +1 -0
- package/dist/routing/index.d.ts +3 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/types.d.ts +38 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/security/audit.d.ts +16 -0
- package/dist/security/audit.d.ts.map +1 -0
- package/dist/security/cors.d.ts +7 -0
- package/dist/security/cors.d.ts.map +1 -0
- package/dist/security/csrf.d.ts +15 -0
- package/dist/security/csrf.d.ts.map +1 -0
- package/dist/security/env.d.ts +69 -0
- package/dist/security/env.d.ts.map +1 -0
- package/dist/security/index.d.ts +17 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/policy.d.ts +18 -0
- package/dist/security/policy.d.ts.map +1 -0
- package/dist/security/rate-limit.d.ts +6 -0
- package/dist/security/rate-limit.d.ts.map +1 -0
- package/dist/security/report.d.ts +13 -0
- package/dist/security/report.d.ts.map +1 -0
- package/dist/security/request.d.ts +11 -0
- package/dist/security/request.d.ts.map +1 -0
- package/dist/security/types.d.ts +137 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security/upload.d.ts +23 -0
- package/dist/security/upload.d.ts.map +1 -0
- package/dist/security/websocket.d.ts +13 -0
- package/dist/security/websocket.d.ts.map +1 -0
- package/dist/server/errors.d.ts +13 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/failure-site.d.ts +2 -0
- package/dist/server/failure-site.d.ts.map +1 -0
- package/dist/server/fallbacks.d.ts +10 -0
- package/dist/server/fallbacks.d.ts.map +1 -0
- package/dist/server/index.d.ts +14 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/negotiate.d.ts +3 -0
- package/dist/server/negotiate.d.ts.map +1 -0
- package/dist/server/not-found.d.ts +11 -0
- package/dist/server/not-found.d.ts.map +1 -0
- package/dist/server/problem.d.ts +18 -0
- package/dist/server/problem.d.ts.map +1 -0
- package/dist/server/render-tree.d.ts +4 -0
- package/dist/server/render-tree.d.ts.map +1 -0
- package/dist/server/request-handler.d.ts +40 -0
- package/dist/server/request-handler.d.ts.map +1 -0
- package/dist/server/request-metadata.d.ts +7 -0
- package/dist/server/request-metadata.d.ts.map +1 -0
- package/dist/server/ssr.d.ts +17 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/static/index.d.ts +23 -0
- package/dist/static/index.d.ts.map +1 -0
- package/dist/static/index.js +256 -0
- package/dist/static/index.js.map +1 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +580 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/plugin.d.ts +37 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/package.json +90 -4
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import { existsSync as A } from "node:fs";
|
|
2
|
+
import { mkdir as L, writeFile as U, readdir as C, readFile as G } from "node:fs/promises";
|
|
3
|
+
import { dirname as W, resolve as f, relative as y, sep as $, join as B } from "node:path";
|
|
4
|
+
import { parseAst as Y } from "vite";
|
|
5
|
+
import { b as q, d as K } from "../chunks/ssr-O3d7Q73U.js";
|
|
6
|
+
import { r as z, f as Q, h as X, c as Z } from "../chunks/testing-BBnJ5WUR.js";
|
|
7
|
+
import "react";
|
|
8
|
+
import "react-dom/server";
|
|
9
|
+
import "react/jsx-runtime";
|
|
10
|
+
import { t as S, U as N, w as x, b as F, c as tt } from "../chunks/streaming-27pwhjGC.js";
|
|
11
|
+
const m = "@demiurgejs/core";
|
|
12
|
+
async function et(t) {
|
|
13
|
+
const n = (await rt(t.routesDir)).map((o) => nt(t.routesDir, o)).filter((o) => !!o).sort((o, a) => o.pattern.localeCompare(a.pattern)), r = ot(n);
|
|
14
|
+
return await L(W(t.outputFile), { recursive: !0 }), await U(t.outputFile, r), {
|
|
15
|
+
routes: n,
|
|
16
|
+
source: r
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function rt(t) {
|
|
20
|
+
return (await C(t, {
|
|
21
|
+
recursive: !0,
|
|
22
|
+
withFileTypes: !0
|
|
23
|
+
})).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => f(n.parentPath, n.name));
|
|
24
|
+
}
|
|
25
|
+
function nt(t, e) {
|
|
26
|
+
const r = y(t, e).split($).join("/").replace(/\.tsx?$/, "").split("/");
|
|
27
|
+
if (r.at(-1)?.startsWith("@"))
|
|
28
|
+
return null;
|
|
29
|
+
const a = r.flatMap((s) => O(s) ? [] : s === "index" ? [] : s.startsWith("[...") && s.endsWith("]") ? [s] : s.startsWith("[") && s.endsWith("]") ? [s] : [s]);
|
|
30
|
+
return {
|
|
31
|
+
pathVars: r.flatMap((s) => O(s) ? [] : s.startsWith("[...") && s.endsWith("]") ? [s.slice(4, -1)] : s.startsWith("[") && s.endsWith("]") ? [s.slice(1, -1)] : []),
|
|
32
|
+
pattern: `/${a.join("/")}`.replace(/\/$/, "") || "/"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function O(t) {
|
|
36
|
+
return t.startsWith("(") && t.endsWith(")");
|
|
37
|
+
}
|
|
38
|
+
function ot(t) {
|
|
39
|
+
return `// Generated by Demiurge. Do not edit by hand.
|
|
40
|
+
import "${m}";
|
|
41
|
+
import type { PathValue } from "${m}";
|
|
42
|
+
|
|
43
|
+
declare module "${m}" {
|
|
44
|
+
interface RoutePathVars {
|
|
45
|
+
${t.map(st).join(`
|
|
46
|
+
`)}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface RouteConcretePaths {
|
|
50
|
+
${t.map(at).join(`
|
|
51
|
+
`)}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {};
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
function st(t) {
|
|
59
|
+
if (t.pathVars.length === 0)
|
|
60
|
+
return ` ${JSON.stringify(t.pattern)}: {};`;
|
|
61
|
+
const e = t.pathVars.map((n) => `${n}: PathValue`).join("; ");
|
|
62
|
+
return ` ${JSON.stringify(t.pattern)}: { ${e} };`;
|
|
63
|
+
}
|
|
64
|
+
function at(t) {
|
|
65
|
+
return ` ${JSON.stringify(t.pattern)}: ${it(t.pattern)};`;
|
|
66
|
+
}
|
|
67
|
+
function it(t) {
|
|
68
|
+
return t.includes("[") ? `\`${t.split(/(\[\.\.\.[^\]]+\]|\[[^\]]+\])/g).filter(Boolean).map((n) => n.startsWith("[") ? "${PathValue}" : ut(n)).join("")}\`` : JSON.stringify(t);
|
|
69
|
+
}
|
|
70
|
+
function ut(t) {
|
|
71
|
+
return t.replace(/[`$\\]/g, "\\$&");
|
|
72
|
+
}
|
|
73
|
+
const g = "virtual:demiurge/client-entry", E = `\0${g}`, V = "virtual:demiurge/server-entry", P = `\0${V}`, I = ".demiurge/route-manifest.d.ts";
|
|
74
|
+
function Yt(t = {}) {
|
|
75
|
+
let e = process.cwd(), n = !1;
|
|
76
|
+
return {
|
|
77
|
+
enforce: "post",
|
|
78
|
+
name: "demiurge",
|
|
79
|
+
config(r) {
|
|
80
|
+
return gt(r);
|
|
81
|
+
},
|
|
82
|
+
configResolved(r) {
|
|
83
|
+
e = r.root, n = r.command === "build";
|
|
84
|
+
},
|
|
85
|
+
resolveId(r) {
|
|
86
|
+
return r === g ? E : r === V ? P : null;
|
|
87
|
+
},
|
|
88
|
+
load(r) {
|
|
89
|
+
return r === E ? Rt(e, t) : r === P ? $t(e, t) : null;
|
|
90
|
+
},
|
|
91
|
+
transform: {
|
|
92
|
+
order: "post",
|
|
93
|
+
handler(r, o, a) {
|
|
94
|
+
if (a?.ssr || !ft(e, t, o))
|
|
95
|
+
return null;
|
|
96
|
+
const i = ct(r);
|
|
97
|
+
return i === r ? null : { code: i, map: null };
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
generateBundle(r, o) {
|
|
101
|
+
const a = Object.values(o).find(
|
|
102
|
+
(u) => u.type === "chunk" && u.isEntry && u.facadeModuleId === E
|
|
103
|
+
);
|
|
104
|
+
if (!a)
|
|
105
|
+
return;
|
|
106
|
+
const i = Object.values(o).filter(
|
|
107
|
+
(u) => u.type === "asset" && u.fileName.endsWith(".css")
|
|
108
|
+
).map((u) => `/${u.fileName}`), s = `/${a.fileName}`;
|
|
109
|
+
this.emitFile({
|
|
110
|
+
fileName: "index.html",
|
|
111
|
+
source: vt({
|
|
112
|
+
entrySrc: s,
|
|
113
|
+
lang: t.document?.lang,
|
|
114
|
+
styles: i,
|
|
115
|
+
title: t.document?.title
|
|
116
|
+
}),
|
|
117
|
+
type: "asset"
|
|
118
|
+
}), this.emitFile({
|
|
119
|
+
fileName: "demiurge-manifest.json",
|
|
120
|
+
source: JSON.stringify({ clientEntry: s, styles: i }, null, 2),
|
|
121
|
+
type: "asset"
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
async buildStart() {
|
|
125
|
+
n && await Ft(e, t), t.typedRoutes && await R(e, t);
|
|
126
|
+
},
|
|
127
|
+
configureServer(r) {
|
|
128
|
+
if (t.typedRoutes) {
|
|
129
|
+
const o = f(
|
|
130
|
+
r.config.root,
|
|
131
|
+
t.routesDir ?? "src/routes"
|
|
132
|
+
);
|
|
133
|
+
R(r.config.root, t), r.watcher.add(o), r.watcher.on("add", (a) => {
|
|
134
|
+
D(o, a) && R(r.config.root, t);
|
|
135
|
+
}), r.watcher.on("change", (a) => {
|
|
136
|
+
D(o, a) && R(r.config.root, t);
|
|
137
|
+
}), r.watcher.on("unlink", (a) => {
|
|
138
|
+
D(o, a) && R(r.config.root, t);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return r.middlewares.use(async (o, a, i) => {
|
|
142
|
+
try {
|
|
143
|
+
let s;
|
|
144
|
+
try {
|
|
145
|
+
s = S(o, {
|
|
146
|
+
// Vite performs its own configured host allowlist check before
|
|
147
|
+
// Demiurge's middleware runs. Production Node listeners require
|
|
148
|
+
// an explicit application allowlist instead.
|
|
149
|
+
allowedHosts: [o.headers.host ?? "localhost"]
|
|
150
|
+
});
|
|
151
|
+
} catch (l) {
|
|
152
|
+
if (l instanceof N) {
|
|
153
|
+
x(a);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
throw l;
|
|
157
|
+
}
|
|
158
|
+
const u = f(
|
|
159
|
+
r.config.root,
|
|
160
|
+
t.routesDir ?? "src/routes"
|
|
161
|
+
), c = await v(r, o, u), p = await Tt(
|
|
162
|
+
c,
|
|
163
|
+
s,
|
|
164
|
+
St(r, t)
|
|
165
|
+
);
|
|
166
|
+
if (p === "next") {
|
|
167
|
+
i();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
await F(a, p);
|
|
171
|
+
} catch (s) {
|
|
172
|
+
i(s);
|
|
173
|
+
}
|
|
174
|
+
}), () => {
|
|
175
|
+
r.middlewares.use(async (o, a, i) => {
|
|
176
|
+
try {
|
|
177
|
+
let s;
|
|
178
|
+
try {
|
|
179
|
+
s = S(o, {
|
|
180
|
+
allowedHosts: [o.headers.host ?? "localhost"]
|
|
181
|
+
});
|
|
182
|
+
} catch (p) {
|
|
183
|
+
if (p instanceof N) {
|
|
184
|
+
x(a);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
throw p;
|
|
188
|
+
}
|
|
189
|
+
const u = f(
|
|
190
|
+
r.config.root,
|
|
191
|
+
t.routesDir ?? "src/routes"
|
|
192
|
+
), c = await v(r, o, u);
|
|
193
|
+
xt(c, u), await F(
|
|
194
|
+
a,
|
|
195
|
+
await z(
|
|
196
|
+
c,
|
|
197
|
+
s,
|
|
198
|
+
Nt(r, t)
|
|
199
|
+
)
|
|
200
|
+
);
|
|
201
|
+
} catch (s) {
|
|
202
|
+
i(s);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function ct(t) {
|
|
210
|
+
const e = Y(t), n = [], r = lt(e), o = [];
|
|
211
|
+
w(e, (s) => {
|
|
212
|
+
if (s.type === "ImportDeclaration" && pt(s)) {
|
|
213
|
+
o.push(s);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (s.type !== "CallExpression" || !dt(s.callee))
|
|
217
|
+
return;
|
|
218
|
+
const u = h(s.arguments)[0];
|
|
219
|
+
if (u?.type === "ObjectExpression")
|
|
220
|
+
for (const c of h(u.properties))
|
|
221
|
+
c.type === "Property" && b(c.key) === "data" && n.push({ end: c.end, start: c.start });
|
|
222
|
+
});
|
|
223
|
+
const a = [...n, ...r];
|
|
224
|
+
if (a.length === 0)
|
|
225
|
+
return t;
|
|
226
|
+
const i = [...a];
|
|
227
|
+
for (const s of o) {
|
|
228
|
+
const u = h(s.specifiers).map((l) => d(l.local)).filter((l) => l?.type === "Identifier").map((l) => String(l.name)), c = mt(t, [
|
|
229
|
+
...a,
|
|
230
|
+
{ end: s.end, start: s.start }
|
|
231
|
+
]), p = u.find(
|
|
232
|
+
(l) => new RegExp(`\\b${yt(l)}\\b`).test(c)
|
|
233
|
+
);
|
|
234
|
+
if (p)
|
|
235
|
+
throw new Error(
|
|
236
|
+
`Server-only import ${JSON.stringify(p)} is used by client route code. Move that use into page data, a document contribution, or a client-safe module.`
|
|
237
|
+
);
|
|
238
|
+
i.push({ end: s.end, start: s.start });
|
|
239
|
+
}
|
|
240
|
+
return ht(
|
|
241
|
+
t,
|
|
242
|
+
i,
|
|
243
|
+
(s) => n.includes(s) ? "data: undefined" : r.includes(s) ? "undefined" : ""
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
const M = /* @__PURE__ */ new Set(["links", "metadata", "scripts"]);
|
|
247
|
+
function lt(t) {
|
|
248
|
+
const e = /* @__PURE__ */ new Set();
|
|
249
|
+
for (const r of h(t.body)) {
|
|
250
|
+
if (r.type !== "ExportNamedDeclaration") continue;
|
|
251
|
+
const o = d(r.declaration);
|
|
252
|
+
if (o?.type === "VariableDeclaration")
|
|
253
|
+
for (const a of h(o.declarations)) {
|
|
254
|
+
const i = d(a.id);
|
|
255
|
+
i?.type === "Identifier" && M.has(String(i.name)) && e.add(String(i.name));
|
|
256
|
+
}
|
|
257
|
+
for (const a of h(r.specifiers)) {
|
|
258
|
+
const i = b(a.exported), s = b(a.local);
|
|
259
|
+
i && s && M.has(i) && e.add(s);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const n = [];
|
|
263
|
+
return w(t, (r) => {
|
|
264
|
+
if (r.type !== "VariableDeclarator") return;
|
|
265
|
+
const o = d(r.id), a = d(r.init);
|
|
266
|
+
o?.type === "Identifier" && e.has(String(o.name)) && a && n.push({ end: a.end, start: a.start });
|
|
267
|
+
}), n;
|
|
268
|
+
}
|
|
269
|
+
function ft(t, e, n) {
|
|
270
|
+
const r = n.split("?", 1)[0] ?? n, o = f(t, e.routesDir ?? "src/routes"), a = y(o, r);
|
|
271
|
+
return a !== "" && a !== ".." && !a.startsWith(`..${$}`);
|
|
272
|
+
}
|
|
273
|
+
function w(t, e) {
|
|
274
|
+
if (!t || typeof t != "object") return;
|
|
275
|
+
if (Array.isArray(t)) {
|
|
276
|
+
for (const r of t) w(r, e);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const n = t;
|
|
280
|
+
if (typeof n.type == "string") {
|
|
281
|
+
e(n);
|
|
282
|
+
for (const [r, o] of Object.entries(n))
|
|
283
|
+
(/* @__PURE__ */ new Set(["end", "loc", "start", "type"])).has(r) || w(o, e);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function d(t) {
|
|
287
|
+
return t && typeof t == "object" && "type" in t ? t : void 0;
|
|
288
|
+
}
|
|
289
|
+
function h(t) {
|
|
290
|
+
return Array.isArray(t) ? t.map(d).filter((e) => !!e) : [];
|
|
291
|
+
}
|
|
292
|
+
function dt(t) {
|
|
293
|
+
const e = d(t);
|
|
294
|
+
return e?.type === "Identifier" ? e.name === "page" : e?.type === "MemberExpression" && b(e.property) === "page";
|
|
295
|
+
}
|
|
296
|
+
function b(t) {
|
|
297
|
+
const e = d(t);
|
|
298
|
+
return e?.type === "Identifier" || e?.type === "Literal" ? String(e.name ?? e.value) : void 0;
|
|
299
|
+
}
|
|
300
|
+
function pt(t) {
|
|
301
|
+
const e = d(t.source)?.value;
|
|
302
|
+
return typeof e == "string" && /(?:^|[/.-])server(?:[/.-]|$)/.test(e);
|
|
303
|
+
}
|
|
304
|
+
function mt(t, e) {
|
|
305
|
+
const n = [...t];
|
|
306
|
+
for (const { end: r, start: o } of e)
|
|
307
|
+
n.fill(" ", o, r);
|
|
308
|
+
return n.join("");
|
|
309
|
+
}
|
|
310
|
+
function ht(t, e, n) {
|
|
311
|
+
return [...e].sort((r, o) => o.start - r.start).reduce(
|
|
312
|
+
(r, o) => `${r.slice(0, o.start)}${n(o)}${r.slice(o.end)}`,
|
|
313
|
+
t
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
function yt(t) {
|
|
317
|
+
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
318
|
+
}
|
|
319
|
+
function gt(t) {
|
|
320
|
+
return {
|
|
321
|
+
appType: "custom",
|
|
322
|
+
build: {
|
|
323
|
+
rollupOptions: {
|
|
324
|
+
input: t.build?.rollupOptions?.input ?? g
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function Rt(t, e = {}) {
|
|
330
|
+
const n = e.routesDir ?? "src/routes", r = Dt(t, e);
|
|
331
|
+
return `import { hydrateFileRouter } from "${m}";
|
|
332
|
+
${r}
|
|
333
|
+
|
|
334
|
+
${k(n, {
|
|
335
|
+
exportRoutes: !1,
|
|
336
|
+
includeServerOnly: !1
|
|
337
|
+
})}
|
|
338
|
+
|
|
339
|
+
void hydrateFileRouter({ routes });
|
|
340
|
+
`;
|
|
341
|
+
}
|
|
342
|
+
function $t(t, e = {}) {
|
|
343
|
+
const n = e.routesDir ?? "src/routes";
|
|
344
|
+
return `import { createRequestHandler } from "${m}";
|
|
345
|
+
|
|
346
|
+
${k(n, {
|
|
347
|
+
exportRoutes: !0,
|
|
348
|
+
includeServerOnly: !0
|
|
349
|
+
})}
|
|
350
|
+
|
|
351
|
+
export function createHandler(options = {}) {
|
|
352
|
+
const { clientEntry, lang, styles, title, ...handlerOptions } = options;
|
|
353
|
+
|
|
354
|
+
return createRequestHandler({
|
|
355
|
+
...handlerOptions,
|
|
356
|
+
routes,
|
|
357
|
+
ssr: {
|
|
358
|
+
clientEntry,
|
|
359
|
+
lang: lang ?? ${JSON.stringify(e.document?.lang)},
|
|
360
|
+
styles,
|
|
361
|
+
title: title ?? ${JSON.stringify(e.document?.title)},
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
`;
|
|
366
|
+
}
|
|
367
|
+
function k(t, {
|
|
368
|
+
exportRoutes: e,
|
|
369
|
+
includeServerOnly: n
|
|
370
|
+
}) {
|
|
371
|
+
const r = bt(t, n), o = Et(t);
|
|
372
|
+
return `const routeModules = import.meta.glob(${JSON.stringify(r)});
|
|
373
|
+
const routePrefix = ${JSON.stringify(o)};
|
|
374
|
+
${e ? "export " : ""}const routes = Object.fromEntries(
|
|
375
|
+
Object.entries(routeModules).map(([file, load]) => [
|
|
376
|
+
\`./routes/\${file.slice(routePrefix.length)}\`,
|
|
377
|
+
load,
|
|
378
|
+
]),
|
|
379
|
+
);`;
|
|
380
|
+
}
|
|
381
|
+
const wt = ["@middleware.ts", "@policy.ts"];
|
|
382
|
+
function bt(t, e) {
|
|
383
|
+
const n = `/${t.replace(/^\/|\/$/g, "")}`, r = [`${n}/**/*.{ts,tsx}`];
|
|
384
|
+
return e || r.push(
|
|
385
|
+
...wt.flatMap((o) => [
|
|
386
|
+
`!${n}/${o}`,
|
|
387
|
+
`!${n}/**/${o}`
|
|
388
|
+
])
|
|
389
|
+
), r;
|
|
390
|
+
}
|
|
391
|
+
function Et(t) {
|
|
392
|
+
return `/${t.replace(/^\/|\/$/g, "")}/`;
|
|
393
|
+
}
|
|
394
|
+
function Dt(t, e) {
|
|
395
|
+
if (e.styles === !1)
|
|
396
|
+
return "";
|
|
397
|
+
const n = e.styles ?? "src/styles.css", r = f(t, n);
|
|
398
|
+
return A(r) ? `import ${JSON.stringify(`/${n.replace(/^\/+/, "")}`)};` : "";
|
|
399
|
+
}
|
|
400
|
+
function St(t, e) {
|
|
401
|
+
return {
|
|
402
|
+
dev: !0,
|
|
403
|
+
ssr: H(e),
|
|
404
|
+
transformDocument: (n) => t.transformIndexHtml("/", n),
|
|
405
|
+
renderPage: async (n, r) => {
|
|
406
|
+
if (n.render.mode === "streaming")
|
|
407
|
+
return await tt(n, {
|
|
408
|
+
...r,
|
|
409
|
+
clientEntry: `/${g}`,
|
|
410
|
+
transformDocument: (a) => t.transformIndexHtml("/", a)
|
|
411
|
+
});
|
|
412
|
+
const o = await t.transformIndexHtml(
|
|
413
|
+
"/",
|
|
414
|
+
K(n, {
|
|
415
|
+
...r,
|
|
416
|
+
clientEntry: `/${g}`
|
|
417
|
+
})
|
|
418
|
+
);
|
|
419
|
+
return new Response(o, {
|
|
420
|
+
headers: { "content-type": "text/html; charset=utf-8" }
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const _ = Symbol.for("demiurge.devManifest");
|
|
426
|
+
async function v(t, e, n) {
|
|
427
|
+
const r = e, o = r[_];
|
|
428
|
+
if (o)
|
|
429
|
+
return o;
|
|
430
|
+
const a = Z(
|
|
431
|
+
await jt(t, n)
|
|
432
|
+
);
|
|
433
|
+
return r[_] = a, a;
|
|
434
|
+
}
|
|
435
|
+
function H(t) {
|
|
436
|
+
return {
|
|
437
|
+
clientEntry: `/${g}`,
|
|
438
|
+
lang: t.document?.lang,
|
|
439
|
+
title: t.document?.title
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function Nt(t, e) {
|
|
443
|
+
return {
|
|
444
|
+
...H(e),
|
|
445
|
+
dev: !0,
|
|
446
|
+
transformDocument: (n) => t.transformIndexHtml("/", n)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
const j = /* @__PURE__ */ new Set();
|
|
450
|
+
function xt(t, e) {
|
|
451
|
+
j.has(e) || t.fallbacks.notFound.some(
|
|
452
|
+
(n) => n.fileSegments.length === 0
|
|
453
|
+
) || (j.add(e), console.warn(_t(B(e, "@not-found.tsx"))));
|
|
454
|
+
}
|
|
455
|
+
async function Ft(t, e = {}) {
|
|
456
|
+
const n = e.routesDir ?? "src/routes", r = f(t, n);
|
|
457
|
+
if (!A(r))
|
|
458
|
+
return;
|
|
459
|
+
const o = await J(r);
|
|
460
|
+
if (o.map(
|
|
461
|
+
(s) => y(r, s).split($).join("/")
|
|
462
|
+
).some((s) => /^@not-found\.tsx?$/.test(s)))
|
|
463
|
+
return;
|
|
464
|
+
const i = await Ot(o);
|
|
465
|
+
if (i)
|
|
466
|
+
throw new Error(
|
|
467
|
+
Mt(
|
|
468
|
+
n,
|
|
469
|
+
y(r, i).split($).join("/")
|
|
470
|
+
)
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
async function Ot(t) {
|
|
474
|
+
for (const e of t)
|
|
475
|
+
if (!y(W(e), e).startsWith("@") && It(await G(e, "utf8")))
|
|
476
|
+
return e;
|
|
477
|
+
}
|
|
478
|
+
const Pt = m.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), T = new RegExp(
|
|
479
|
+
`import\\s*\\{([^}]*)\\}\\s*from\\s*["']${Pt}["']`,
|
|
480
|
+
"g"
|
|
481
|
+
);
|
|
482
|
+
function It(t) {
|
|
483
|
+
const e = [...t.matchAll(T)].flatMap(
|
|
484
|
+
(r) => r[1].split(",").flatMap((o) => {
|
|
485
|
+
const [a, i] = o.trim().split(/\s+as\s+/);
|
|
486
|
+
return a.replace(/^type\s+/, "") === "page" ? [i ?? a] : [];
|
|
487
|
+
})
|
|
488
|
+
);
|
|
489
|
+
if (e.length === 0)
|
|
490
|
+
return !1;
|
|
491
|
+
const n = t.replace(T, "");
|
|
492
|
+
return e.some((r) => new RegExp(`\\b${r}\\s*\\(`).test(n));
|
|
493
|
+
}
|
|
494
|
+
function Mt(t, e) {
|
|
495
|
+
return `Demiurge will not build an app with page routes and no ${t}/@not-found.tsx.
|
|
496
|
+
|
|
497
|
+
"${e}" 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.
|
|
498
|
+
|
|
499
|
+
Create ${t}/@not-found.tsx:
|
|
500
|
+
|
|
501
|
+
export default function NotFound({ pathname }: { pathname: string }) {
|
|
502
|
+
return <h1>Nothing at {pathname}</h1>;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
It renders inside the layouts above the requested path. Opt out with "export const layout = false".`;
|
|
506
|
+
}
|
|
507
|
+
function _t(t) {
|
|
508
|
+
return `Demiurge is serving its built-in 404 because ${t} does not exist.
|
|
509
|
+
|
|
510
|
+
Create it before building for production:
|
|
511
|
+
|
|
512
|
+
export default function NotFound({ pathname }: { pathname: string }) {
|
|
513
|
+
return <h1>Nothing at {pathname}</h1>;
|
|
514
|
+
}
|
|
515
|
+
`;
|
|
516
|
+
}
|
|
517
|
+
function vt({
|
|
518
|
+
entrySrc: t,
|
|
519
|
+
lang: e,
|
|
520
|
+
links: n,
|
|
521
|
+
metadata: r,
|
|
522
|
+
nonce: o,
|
|
523
|
+
scripts: a,
|
|
524
|
+
styles: i,
|
|
525
|
+
title: s
|
|
526
|
+
}) {
|
|
527
|
+
return q({
|
|
528
|
+
entrySrc: t,
|
|
529
|
+
lang: e,
|
|
530
|
+
links: n,
|
|
531
|
+
metadata: r,
|
|
532
|
+
nonce: o,
|
|
533
|
+
scripts: a,
|
|
534
|
+
styles: i,
|
|
535
|
+
title: s
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
async function R(t, e) {
|
|
539
|
+
const n = f(t, e.routesDir ?? "src/routes"), r = f(
|
|
540
|
+
t,
|
|
541
|
+
typeof e.typedRoutes == "object" ? e.typedRoutes.outputFile ?? I : I
|
|
542
|
+
);
|
|
543
|
+
await et({ outputFile: r, routesDir: n });
|
|
544
|
+
}
|
|
545
|
+
function D(t, e) {
|
|
546
|
+
return e.startsWith(t) && /\.tsx?$/.test(e);
|
|
547
|
+
}
|
|
548
|
+
async function jt(t, e) {
|
|
549
|
+
const n = await J(e), r = {};
|
|
550
|
+
for (const o of n) {
|
|
551
|
+
const a = At(e, o);
|
|
552
|
+
r[a] = async () => await t.ssrLoadModule(o);
|
|
553
|
+
}
|
|
554
|
+
return r;
|
|
555
|
+
}
|
|
556
|
+
async function Tt(t, e, n = {}) {
|
|
557
|
+
const r = new URL(e.url);
|
|
558
|
+
return Q(t.routes, r.pathname) ? await X(t, e, n) : "next";
|
|
559
|
+
}
|
|
560
|
+
async function J(t) {
|
|
561
|
+
return (await C(t, {
|
|
562
|
+
recursive: !0,
|
|
563
|
+
withFileTypes: !0
|
|
564
|
+
})).filter((n) => n.isFile() && /\.tsx?$/.test(n.name)).map((n) => f(n.parentPath, n.name));
|
|
565
|
+
}
|
|
566
|
+
function At(t, e) {
|
|
567
|
+
return `./routes/${y(t, e).split($).join("/")}`;
|
|
568
|
+
}
|
|
569
|
+
export {
|
|
570
|
+
Yt as demiurge,
|
|
571
|
+
Ft as unstable_assertRootNotFoundRoute,
|
|
572
|
+
Rt as unstable_createClientEntrySource,
|
|
573
|
+
jt as unstable_createDevRouteImporters,
|
|
574
|
+
vt as unstable_createDocumentHtml,
|
|
575
|
+
$t as unstable_createServerEntrySource,
|
|
576
|
+
It as unstable_declaresPageRoute,
|
|
577
|
+
Tt as unstable_handleDevRequest,
|
|
578
|
+
ct as unstable_stripClientPageData
|
|
579
|
+
};
|
|
580
|
+
//# sourceMappingURL=index.js.map
|