vinojs 0.1.0 → 0.1.1
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/dist/client.mjs +1 -1
- package/dist/{compile-Lxl_tdxL.mjs → compile-glNMkyyx.mjs} +3 -47
- package/dist/compile-glNMkyyx.mjs.map +1 -0
- package/dist/{definePage-Ba4r-TFh.mjs → definePage--9Pz7rHs.mjs} +29 -7
- package/dist/definePage--9Pz7rHs.mjs.map +1 -0
- package/dist/defineServerFn-H-bz7xBX.mjs +47 -0
- package/dist/defineServerFn-H-bz7xBX.mjs.map +1 -0
- package/dist/factory-AHIdhfy4.d.mts +143 -0
- package/dist/factory-AHIdhfy4.d.mts.map +1 -0
- package/dist/factory.d.mts +2 -0
- package/dist/factory.mjs +35 -0
- package/dist/factory.mjs.map +1 -0
- package/dist/vino.d.mts +4 -103
- package/dist/vino.d.mts.map +1 -1
- package/dist/vino.mjs +5 -3
- package/dist/vino.mjs.map +1 -1
- package/dist/vite.mjs +3 -2
- package/dist/vite.mjs.map +1 -1
- package/package.json +5 -1
- package/dist/compile-Lxl_tdxL.mjs.map +0 -1
- package/dist/definePage-Ba4r-TFh.mjs.map +0 -1
- package/examples/basic/dist/client/.assetsignore +0 -2
- package/examples/basic/dist/client/about.html +0 -1
- package/examples/basic/dist/client/admin.html +0 -1
- package/examples/basic/dist/client/assets/Counter-BvqMZKON.js +0 -1
- package/examples/basic/dist/client/assets/_slug_-CYpOSbrn.js +0 -1
- package/examples/basic/dist/client/assets/about-BZXRzUyv.js +0 -1
- package/examples/basic/dist/client/assets/admin-DRE7uh2s.js +0 -1
- package/examples/basic/dist/client/assets/client-B6nFkut5.js +0 -1
- package/examples/basic/dist/client/assets/client-pages-Bc6cNZAm.js +0 -2
- package/examples/basic/dist/client/assets/components-DX9r6vHn.js +0 -1
- package/examples/basic/dist/client/assets/components-DsWJ6F73.js +0 -2
- package/examples/basic/dist/client/assets/counter-DBpvln_F.js +0 -1
- package/examples/basic/dist/client/assets/dom-B5sHIJ1E.js +0 -1
- package/examples/basic/dist/client/assets/honoto-9UtdLp4J.js +0 -33
- package/examples/basic/dist/client/assets/honoto-client-DEh86_WZ.css +0 -1
- package/examples/basic/dist/client/assets/honoto-client.js +0 -2
- package/examples/basic/dist/client/assets/hooks-Cz6AT21d.js +0 -1
- package/examples/basic/dist/client/assets/jsx-dev-runtime-92VDsVyo.js +0 -1
- package/examples/basic/dist/client/counter.html +0 -1
- package/examples/basic/dist/client/index.html +0 -1
- package/examples/basic/dist/client/jobs.html +0 -1
- package/examples/basic/dist/ssr/.vite/manifest.json +0 -140
- package/examples/basic/dist/ssr/assets/_slug_-CY3-kffX.js +0 -46
- package/examples/basic/dist/ssr/assets/about-CTDjNhkO.js +0 -15
- package/examples/basic/dist/ssr/assets/admin-DvS-UGJx.js +0 -26
- package/examples/basic/dist/ssr/assets/constants-UoriGYcX-CUecBFMT.js +0 -6
- package/examples/basic/dist/ssr/assets/counter-DfIbc9Sp.js +0 -30
- package/examples/basic/dist/ssr/assets/honoto-CA313cVy.js +0 -2129
- package/examples/basic/dist/ssr/assets/jobs-D9hh-UO9.js +0 -42
- package/examples/basic/dist/ssr/assets/jsx-CgYLQazd.js +0 -1080
- package/examples/basic/dist/ssr/assets/jsx-dev-runtime-BlUda7H8.js +0 -742
- package/examples/basic/dist/ssr/assets/jsx-renderer-CzZcZPnS.js +0 -65
- package/examples/basic/dist/ssr/assets/layout-DYvLwr2u.js +0 -53
- package/examples/basic/dist/ssr/assets/pages-DB6jeyrt.js +0 -53
- package/examples/basic/dist/ssr/assets/rolldown-runtime-D7D4PA-g.js +0 -13
- package/examples/basic/dist/ssr/assets/ssr-hooks-CBQr0cdH.js +0 -7
- package/examples/basic/dist/ssr/index.js +0 -22
- package/examples/basic/dist/ssr/wrangler.json +0 -1
- package/examples/full/dist/client/.assetsignore +0 -2
- package/examples/full/dist/client/assets/BookmarkButton-py0xGxgl.js +0 -1
- package/examples/full/dist/client/assets/_slug_-DZUFsE9O.js +0 -1
- package/examples/full/dist/client/assets/auth-client-D2Wtuobe.js +0 -1
- package/examples/full/dist/client/assets/bun-sqlite-dialect-C7ftEUSI-CsHdUKBY.js +0 -1
- package/examples/full/dist/client/assets/client-B6nFkut5.js +0 -1
- package/examples/full/dist/client/assets/client-pages-fshKs747.js +0 -2
- package/examples/full/dist/client/assets/components-DX9r6vHn.js +0 -1
- package/examples/full/dist/client/assets/components-S_-rWrKi.js +0 -2
- package/examples/full/dist/client/assets/d1-sqlite-dialect-BZmaVTp8-FPCaMZqX.js +0 -1
- package/examples/full/dist/client/assets/default-query-compiler-CUdqIu1h.js +0 -1
- package/examples/full/dist/client/assets/dist-BoGTNvkC.js +0 -1
- package/examples/full/dist/client/assets/dom-DCd3wYW7.js +0 -1
- package/examples/full/dist/client/assets/factory-Bgf4EtLx.js +0 -8
- package/examples/full/dist/client/assets/honoto-client-BSvNAnxN.css +0 -1
- package/examples/full/dist/client/assets/honoto-client.js +0 -2
- package/examples/full/dist/client/assets/hooks-Cz6AT21d.js +0 -1
- package/examples/full/dist/client/assets/jsx-dev-runtime-92VDsVyo.js +0 -1
- package/examples/full/dist/client/assets/kysely-adapter-BHhasAnc.js +0 -1
- package/examples/full/dist/client/assets/kysely-migration-tables-DFfmKhq--U5ujlMwE.js +0 -1
- package/examples/full/dist/client/assets/node-sqlite-dialect-DJDXH5Ot.js +0 -1
- package/examples/full/dist/client/assets/pages-CUQx6Eus.js +0 -1
- package/examples/full/dist/client/assets/saved-jIi74ncJ.js +0 -1
- package/examples/full/dist/client/assets/session-B-accyM3.js +0 -611
- package/examples/full/dist/client/assets/sign-in-BelI3gSs.js +0 -1
- package/examples/full/dist/client/assets/sign-up-pR94lfdu.js +0 -1
- package/examples/full/dist/client/index.html +0 -1
- package/examples/full/dist/client/saved.html +0 -1
- package/examples/full/dist/client/sign-in.html +0 -1
- package/examples/full/dist/client/sign-up.html +0 -1
- package/examples/full/dist/ssr/.dev.vars +0 -1
- package/examples/full/dist/ssr/.vite/manifest.json +0 -219
- package/examples/full/dist/ssr/assets/BookmarkButton-KS7z5_vi.js +0 -298
- package/examples/full/dist/ssr/assets/_slug_-rRStRaAN.js +0 -89
- package/examples/full/dist/ssr/assets/auth-DSFZ4iak.js +0 -31434
- package/examples/full/dist/ssr/assets/auth-client-BFSBVoML.js +0 -894
- package/examples/full/dist/ssr/assets/bun-sqlite-dialect-C7ftEUSI-BeXpIqKl.js +0 -162
- package/examples/full/dist/ssr/assets/compiled-query-DmoyCh28.js +0 -8410
- package/examples/full/dist/ssr/assets/d1-sqlite-dialect-BZmaVTp8-CjJdvL94.js +0 -114
- package/examples/full/dist/ssr/assets/default-query-compiler-D7xOzCCJ.js +0 -1727
- package/examples/full/dist/ssr/assets/dist-LmmDoNdk.js +0 -6832
- package/examples/full/dist/ssr/assets/dist-kFDN1l4Z.js +0 -342
- package/examples/full/dist/ssr/assets/factory-AD6s9SIW.js +0 -2079
- package/examples/full/dist/ssr/assets/jsx-renderer-mMLf5XLN.js +0 -1926
- package/examples/full/dist/ssr/assets/kysely-adapter-BCLenpM8.js +0 -2
- package/examples/full/dist/ssr/assets/kysely-migration-tables-DFfmKhq--BtVr6hRe.js +0 -17
- package/examples/full/dist/ssr/assets/layout-mVA7qP4j.js +0 -44
- package/examples/full/dist/ssr/assets/node-sqlite-dialect-D-wtYAD7.js +0 -162
- package/examples/full/dist/ssr/assets/pages-Do5kR_Ia.js +0 -147
- package/examples/full/dist/ssr/assets/saved-Dr4pP6B5.js +0 -111
- package/examples/full/dist/ssr/assets/session-BvIpX7tr.js +0 -13
- package/examples/full/dist/ssr/assets/sign-in-22pzTnJE.js +0 -115
- package/examples/full/dist/ssr/assets/sign-up-CN4j8Qg1.js +0 -117
- package/examples/full/dist/ssr/assets/sqlite-adapter-DVlms5wO.js +0 -79
- package/examples/full/dist/ssr/index.js +0 -97
- package/examples/full/dist/ssr/wrangler.json +0 -1
package/dist/client.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as PAGE_SLOT_ID, l as PAYLOAD_SCRIPT_ID, o as NAV_HEADER, t as COMPONENT_TAG } from "./constants-BVT2bJEd.mjs";
|
|
2
|
-
import { s as resolvePageRender } from "./definePage
|
|
2
|
+
import { s as resolvePageRender } from "./definePage--9Pz7rHs.mjs";
|
|
3
3
|
//#region src/client/create-client.ts
|
|
4
4
|
const islands = /* @__PURE__ */ new Map();
|
|
5
5
|
let pageRoot = null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as readPageDefinition } from "./definePage
|
|
1
|
+
import { o as readPageDefinition } from "./definePage--9Pz7rHs.mjs";
|
|
2
2
|
//#region src/vino/config.ts
|
|
3
3
|
function loadMergedConfig(page, pageMod) {
|
|
4
4
|
const merged = { ...page.config };
|
|
@@ -12,50 +12,6 @@ async function loadMergedData(_page, c, pageMod) {
|
|
|
12
12
|
return await fn(c);
|
|
13
13
|
}
|
|
14
14
|
//#endregion
|
|
15
|
-
//#region src/vino/defineServerFn.ts
|
|
16
|
-
const SERVER_FN_KIND = "vino:server-fn";
|
|
17
|
-
function isServerFn(value) {
|
|
18
|
-
return typeof value === "function" && value.kind === "vino:server-fn";
|
|
19
|
-
}
|
|
20
|
-
function readServerFn(value) {
|
|
21
|
-
return isServerFn(value) ? value : void 0;
|
|
22
|
-
}
|
|
23
|
-
/** Call-site of `defineServerFn(...)`, not `function defineServerFn(`. */
|
|
24
|
-
const DEFINE_SERVER_FN_CALL = /(?<!function\s)(?<![$\w])defineServerFn\s*(?:<[^>]*>\s*)?\(/g;
|
|
25
|
-
/** True when source *calls* `defineServerFn(...)`. */
|
|
26
|
-
function usesDefineServerFn(code) {
|
|
27
|
-
DEFINE_SERVER_FN_CALL.lastIndex = 0;
|
|
28
|
-
return DEFINE_SERVER_FN_CALL.test(code);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Mark a function as server-only.
|
|
32
|
-
*
|
|
33
|
-
* Pass the result to `definePage({ data })` (or `defineServerPage`) as a
|
|
34
|
-
* loader. The same function can later be imported and invoked
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* // [slug].server.ts
|
|
38
|
-
* export default defineServerFn(c => {
|
|
39
|
-
* const slug = c.req.param("slug") ?? ""
|
|
40
|
-
* return { slug }
|
|
41
|
-
* })
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* // [slug].tsx
|
|
45
|
-
* import data from "./[slug].server"
|
|
46
|
-
* export default definePage({ data, render: ({ data }) => <h1>{data.slug}</h1> })
|
|
47
|
-
*/
|
|
48
|
-
function defineServerFn(fn) {
|
|
49
|
-
function serverFn(c) {
|
|
50
|
-
return fn(c);
|
|
51
|
-
}
|
|
52
|
-
Object.defineProperty(serverFn, "kind", {
|
|
53
|
-
value: SERVER_FN_KIND,
|
|
54
|
-
enumerable: true
|
|
55
|
-
});
|
|
56
|
-
return serverFn;
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
15
|
//#region src/vino/compile.ts
|
|
60
16
|
const GROUP_RE = /^\([^)]+\)$/;
|
|
61
17
|
const CATCH_ALL_RE = /^\[\.\.\.(.+)\]$/;
|
|
@@ -150,6 +106,6 @@ function compareRoutes(a, b) {
|
|
|
150
106
|
return b.pattern.length - a.pattern.length;
|
|
151
107
|
}
|
|
152
108
|
//#endregion
|
|
153
|
-
export { pathDepth as a,
|
|
109
|
+
export { pathDepth as a, loadMergedData as c, pathCovers as i, compareRoutes as n, urlToHtmlFile as o, compileFilePath as r, loadMergedConfig as s, applyParams as t };
|
|
154
110
|
|
|
155
|
-
//# sourceMappingURL=compile-
|
|
111
|
+
//# sourceMappingURL=compile-glNMkyyx.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-glNMkyyx.mjs","names":[],"sources":["../src/vino/config.ts","../src/vino/compile.ts"],"sourcesContent":["import { readPageDefinition } from \"./definePage.ts\";\nimport type { DataLoader, ManifestPage, PageConfig, PageModule } from \"./types.ts\";\n\nexport function loadMergedConfig(page: ManifestPage, pageMod?: PageModule): PageConfig {\n const merged: PageConfig = { ...page.config };\n const inline = readPageDefinition(pageMod?.default)?.config;\n if (inline) Object.assign(merged, inline);\n return merged;\n}\n\nexport async function loadMergedData(\n _page: ManifestPage,\n c: Parameters<DataLoader>[0],\n pageMod?: PageModule,\n): Promise<unknown> {\n const fn = readPageDefinition(pageMod?.default)?.data;\n if (!fn) return undefined;\n return await fn(c);\n}\n","export interface CompiledRoute {\n /** Filesystem-derived path using `:param` (no Hono regex). `/`, `/about`, `/blog/:slug`. */\n path: string;\n /** Hono route pattern (`:slug{.+}` for catch-all). */\n pattern: string;\n isCatchAll: boolean;\n isStatic: boolean;\n paramNames: string[];\n}\n\nconst GROUP_RE = /^\\([^)]+\\)$/;\nconst CATCH_ALL_RE = /^\\[\\.\\.\\.(.+)\\]$/;\nconst PARAM_RE = /^\\[([^\\]]+)\\]$/;\n\nfunction toPosix(relativePath: string): string {\n return relativePath.replaceAll(\"\\\\\", \"/\").replace(/^\\.\\//, \"\");\n}\n\nfunction stripExt(posixPath: string): string {\n return posixPath.replace(/\\.(tsx|ts|jsx|js|mjs)$/, \"\");\n}\n\n/**\n * Compile a pages-dir-relative file path to a Hono route.\n * `(group)` dirs are omitted, `[param]` becomes `:param`, `[...slug]` becomes `:slug{.+}`,\n * trailing `index` is dropped.\n */\nexport function compileFilePath(relativePath: string): CompiledRoute {\n const posix = toPosix(relativePath);\n const withoutExt = stripExt(posix);\n\n const rawSegs = withoutExt.split(\"/\").filter(Boolean);\n const segs = rawSegs.filter((seg) => !GROUP_RE.test(seg));\n if (segs.at(-1) === \"index\") segs.pop();\n\n const out: string[] = [];\n const paramNames: string[] = [];\n let isCatchAll = false;\n\n for (const seg of segs) {\n const catchAll = CATCH_ALL_RE.exec(seg);\n if (catchAll) {\n paramNames.push(catchAll[1]);\n out.push(`:${catchAll[1]}{.+}`);\n isCatchAll = true;\n continue;\n }\n const param = PARAM_RE.exec(seg);\n if (param && !param[1].startsWith(\"...\")) {\n paramNames.push(param[1]);\n out.push(`:${param[1]}`);\n continue;\n }\n out.push(seg);\n }\n\n const pattern = out.length === 0 ? \"/\" : `/${out.join(\"/\")}`;\n const path = pattern.replaceAll(\"{.+}\", \"\");\n const isStatic = paramNames.length === 0 && !isCatchAll;\n\n return { path, pattern, isCatchAll, isStatic, paramNames };\n}\n\nexport function pathSegments(path: string): string[] {\n return path.split(\"/\").filter(Boolean);\n}\n\nexport function pathDepth(path: string): number {\n return pathSegments(path).length;\n}\n\n/**\n * True if `parent` is `/` or a prefix of `child`.\n * A `:param` segment in `parent` matches any child segment; a static parent\n * segment does not match a param child segment.\n */\nexport function pathCovers(parent: string, child: string): boolean {\n if (parent === \"/\" || parent === \"\") return true;\n const a = pathSegments(parent);\n const b = pathSegments(child);\n if (a.length > b.length) return false;\n return a.every((seg, i) => {\n const other = b[i];\n if (seg === other) return true;\n if (seg.startsWith(\":\")) return true;\n return false;\n });\n}\n\nexport function applyParams(path: string, params: Record<string, string>): string {\n let url = path;\n for (const [key, value] of Object.entries(params)) {\n url = url.replace(`:${key}`, value);\n }\n if (!url.startsWith(\"/\")) url = `/${url}`;\n return url;\n}\n\nexport function urlToHtmlFile(url: string): string {\n const clean = url.split(\"?\")[0].split(\"#\")[0];\n if (clean === \"/\") return \"index.html\";\n const trimmed = clean.replace(/^\\//, \"\").replace(/\\/$/, \"\");\n if (clean.endsWith(\"/\")) return `${trimmed}/index.html`;\n return `${trimmed}.html`;\n}\n\nexport function routeRank(pattern: string): number {\n if (pattern.includes(\"{.+}\")) return 2;\n if (pattern.includes(\":\")) return 1;\n return 0;\n}\n\nexport function compareRoutes(a: { pattern: string }, b: { pattern: string }): number {\n const d = routeRank(a.pattern) - routeRank(b.pattern);\n if (d !== 0) return d;\n return b.pattern.length - a.pattern.length;\n}\n"],"mappings":";;AAGA,SAAgB,iBAAiB,MAAoB,SAAkC;CACrF,MAAM,SAAqB,EAAE,GAAG,KAAK,OAAO;CAC5C,MA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,MAAM,GAAG,OAAO;CACrC,IAAI,QAAQ,SAAS,GAAG,GAAG,OAAO;CAClC,OAAO;AACT;AAEA,SAAgB,cAAc,GAAwB,GAAgC;CACpF,MAAM,IAAI,UAAU,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO;CACpD,IAAI,MAAM,GAAG,OAAO;CACpB,OAAO,EAAE,QAAQ,SAAS,EAAE,QAAQ;AACtC"}
|
|
@@ -39,13 +39,35 @@ function pageDefinition(page, kind, fnName) {
|
|
|
39
39
|
config: page.config
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Declare a page that SSRs with `hono/jsx`, then hydrates `#vino-page` with `hono/jsx/dom`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* export default definePage(() => {
|
|
47
|
+
* const [n, setN] = useState(0)
|
|
48
|
+
* return <button onClick={() => setN(n + 1)}>{n}</button>
|
|
49
|
+
* })
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* export default definePage({
|
|
53
|
+
* config: { prerender: 'full', clientRouting: true },
|
|
54
|
+
* data: async (c) => ({ title: 'Hello' }),
|
|
55
|
+
* render: ({ data }) => <h1>{data.title}</h1>,
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* import data from './[slug].server'
|
|
60
|
+
* export default definePage({ data, render: ({ data }) => <h1>{data.title}</h1> })
|
|
61
|
+
*/
|
|
62
|
+
const definePage = ((page) => pageDefinition(page, PAGE_KIND, "definePage"));
|
|
63
|
+
/**
|
|
64
|
+
* Declare a page that SSRs only. The output is never hydrated.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* export default defineServerPage(() => <h1>About</h1>)
|
|
68
|
+
*/
|
|
69
|
+
const defineServerPage = ((page) => pageDefinition(page, SERVER_PAGE_KIND, "defineServerPage"));
|
|
48
70
|
//#endregion
|
|
49
71
|
export { isServerPageDefinition as a, usesDefinePage as c, isPageDefinition as i, defineServerPage as n, readPageDefinition as o, isClientPageDefinition as r, resolvePageRender as s, definePage as t };
|
|
50
72
|
|
|
51
|
-
//# sourceMappingURL=definePage
|
|
73
|
+
//# sourceMappingURL=definePage--9Pz7rHs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definePage--9Pz7rHs.mjs","names":[],"sources":["../src/vino/definePage.ts"],"sourcesContent":["import type { Env } from \"hono\";\nimport type { ServerFn } from \"./defineServerFn.ts\";\nimport type { DataLoader, PageConfig, PageProps, VinoHtml } from \"./types.ts\";\n\nexport const PAGE_KIND = \"vino:page\" as const;\nexport const SERVER_PAGE_KIND = \"vino:server-page\" as const;\n\nexport type PageRender<Data = unknown> = (props: PageProps<Data>) => VinoHtml;\n\nexport type PageDataFn<E extends Env = Env> = DataLoader<E> | ServerFn<unknown, E>;\n\nexport interface DefinePageOptions<Data = unknown, E extends Env = Env> {\n /** JSX page component. Alias: `page`. */\n render?: PageRender<Data>;\n page?: PageRender<Data>;\n /** Loader or `defineServerFn(...)` */\n data?: DataLoader<E> | ServerFn<Data, E>;\n config?: PageConfig;\n}\n\n/** Options object that infers `data` return type into `render` / `page`. */\nexport type InferDefinePageOptions<\n D extends (...args: never[]) => unknown,\n Data = Awaited<ReturnType<D>>,\n> = {\n data?: D;\n config?: PageConfig;\n} & (\n | { render: PageRender<Data>; page?: PageRender<Data> }\n | { page: PageRender<Data>; render?: PageRender<Data> }\n);\n\n/**\n * `definePage` / `defineServerPage` call signature, with `Env` fixed so `data(c)`\n * is typed without blocking inference of the loader return type.\n */\nexport interface DefinePageFn<E extends Env = Env> {\n <Data = unknown>(page: PageRender<Data>): PageDefinition<Data>;\n <D extends PageDataFn<E>>(\n options: InferDefinePageOptions<D>,\n ): PageDefinition<Awaited<ReturnType<D>>>;\n <Data = unknown>(options: DefinePageOptions<Data, E>): PageDefinition<Data>;\n}\n\nexport interface PageDefinition<Data = unknown> {\n readonly kind: typeof PAGE_KIND | typeof SERVER_PAGE_KIND;\n readonly client: boolean;\n readonly render: PageRender<Data>;\n readonly data?: DataLoader | ServerFn<Data>;\n readonly config?: PageConfig;\n}\n\nexport function isPageDefinition(value: unknown): value is PageDefinition {\n if (value === null || (typeof value !== \"object\" && typeof value !== \"function\")) return false;\n const candidate = value as PageDefinition;\n return (\n (candidate.kind === PAGE_KIND || candidate.kind === SERVER_PAGE_KIND) &&\n typeof candidate.render === \"function\"\n );\n}\n\nexport function isClientPageDefinition(value: unknown): value is PageDefinition {\n return isPageDefinition(value) && value.kind === PAGE_KIND;\n}\n\nexport function isServerPageDefinition(value: unknown): value is PageDefinition {\n return isPageDefinition(value) && value.kind === SERVER_PAGE_KIND;\n}\n\nexport function readPageDefinition(value: unknown): PageDefinition | undefined {\n return isPageDefinition(value) ? value : undefined;\n}\n\nexport function resolvePageRender(value: unknown): PageRender | undefined {\n if (isPageDefinition(value)) return value.render;\n if (typeof value === \"function\") return value as PageRender;\n return undefined;\n}\n\n/** True when source calls `definePage(...)` (hydratable pages). */\nexport function usesDefinePage(code: string): boolean {\n return /(?:^|[^\\w$])definePage\\s*(?:<[^>]*>\\s*)?\\(/.test(code);\n}\n\nfunction pageDefinition<Data>(\n page: PageRender<Data> | DefinePageOptions<Data>,\n kind: typeof PAGE_KIND | typeof SERVER_PAGE_KIND,\n fnName: string,\n): PageDefinition<Data> {\n if (typeof page === \"function\") {\n return { kind, client: kind === PAGE_KIND, render: page };\n }\n const render = page.render ?? page.page;\n if (typeof render !== \"function\") {\n throw new TypeError(`[vino] ${fnName}() requires a JSX function or { render }`);\n }\n return {\n kind,\n client: kind === PAGE_KIND,\n render,\n data: page.data,\n config: page.config,\n };\n}\n\n/**\n * Declare a page that SSRs with `hono/jsx`, then hydrates `#vino-page` with `hono/jsx/dom`.\n *\n * @example\n * export default definePage(() => {\n * const [n, setN] = useState(0)\n * return <button onClick={() => setN(n + 1)}>{n}</button>\n * })\n *\n * @example\n * export default definePage({\n * config: { prerender: 'full', clientRouting: true },\n * data: async (c) => ({ title: 'Hello' }),\n * render: ({ data }) => <h1>{data.title}</h1>,\n * })\n *\n * @example\n * import data from './[slug].server'\n * export default definePage({ data, render: ({ data }) => <h1>{data.title}</h1> })\n */\nexport const definePage = ((page: PageRender | DefinePageOptions) => pageDefinition(page, PAGE_KIND, \"definePage\")) as DefinePageFn;\n\n/**\n * Declare a page that SSRs only. The output is never hydrated.\n *\n * @example\n * export default defineServerPage(() => <h1>About</h1>)\n */\nexport const defineServerPage = ((page: PageRender | DefinePageOptions) => pageDefinition(page, SERVER_PAGE_KIND, \"defineServerPage\")) as DefinePageFn;\n"],"mappings":";AAIA,MAAa,YAAY;AACzB,MAAa,mBAAmB;AA+ChC,SAAgB,iBAAiB,OAAyC;CACxE,IAAI,UAAU,QAAS,OAAO,UAAU,YAAY,OAAO,UAAU,YAAa,OAAO;CACzF,MAAM,YAAY;CAClB,QACG,UAAU,SAAA,eAAsB,UAAU,SAAA,uBAC3C,OAAO,UAAU,WAAW;AAEhC;AAEA,SAAgB,uBAAuB,OAAyC;CAC9E,OAAO,iBAAiB,KAAK,KAAK,MAAM,SAAA;AAC1C;AAEA,SAAgB,uBAAuB,OAAyC;CAC9E,OAAO,iBAAiB,KAAK,KAAK,MAAM,SAAA;AAC1C;AAEA,SAAgB,mBAAmB,OAA4C;CAC7E,OAAO,iBAAiB,KAAK,IAAI,QAAQ,KAAA;AAC3C;AAEA,SAAgB,kBAAkB,OAAwC;CACxE,IAAI,iBAAiB,KAAK,GAAG,OAAO,MAAM;CAC1C,IAAI,OAAO,UAAU,YAAY,OAAO;AAE1C;;AAGA,SAAgB,eAAe,MAAuB;CACpD,OAAO,6CAA6C,KAAK,IAAI;AAC/D;AAEA,SAAS,eACP,MACA,MACA,QACsB;CACtB,IAAI,OAAO,SAAS,YAClB,OAAO;EAAE;EAAM,QAAQ,SAAS;EAAW,QAAQ;CAAK;CAE1D,MAAM,SAAS,KAAK,UAAU,KAAK;CACnC,IAAI,OAAO,WAAW,YACpB,MAAM,IAAI,UAAU,UAAU,OAAO,yCAAyC;CAEhF,OAAO;EACL;EACA,QAAQ,SAAS;EACjB;EACA,MAAM,KAAK;EACX,QAAQ,KAAK;CACf;AACF;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,eAAe,SAAyC,eAAe,MAAM,WAAW,YAAY;;;;;;;AAQjH,MAAa,qBAAqB,SAAyC,eAAe,MAAM,kBAAkB,kBAAkB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/vino/defineServerFn.ts
|
|
2
|
+
const SERVER_FN_KIND = "vino:server-fn";
|
|
3
|
+
function isServerFn(value) {
|
|
4
|
+
return typeof value === "function" && value.kind === "vino:server-fn";
|
|
5
|
+
}
|
|
6
|
+
function readServerFn(value) {
|
|
7
|
+
return isServerFn(value) ? value : void 0;
|
|
8
|
+
}
|
|
9
|
+
/** Call-site of `defineServerFn(...)`, not `function defineServerFn(`. */
|
|
10
|
+
const DEFINE_SERVER_FN_CALL = /(?<!function\s)(?<![$\w])defineServerFn\s*(?:<[^>]*>\s*)?\(/g;
|
|
11
|
+
/** True when source *calls* `defineServerFn(...)`. */
|
|
12
|
+
function usesDefineServerFn(code) {
|
|
13
|
+
DEFINE_SERVER_FN_CALL.lastIndex = 0;
|
|
14
|
+
return DEFINE_SERVER_FN_CALL.test(code);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Mark a function as server-only.
|
|
18
|
+
*
|
|
19
|
+
* Pass the result to `definePage({ data })` (or `defineServerPage`) as a
|
|
20
|
+
* loader. The same function can later be imported and invoked
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // [slug].server.ts
|
|
24
|
+
* export default defineServerFn(c => {
|
|
25
|
+
* const slug = c.req.param("slug") ?? ""
|
|
26
|
+
* return { slug }
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // [slug].tsx
|
|
31
|
+
* import data from "./[slug].server"
|
|
32
|
+
* export default definePage({ data, render: ({ data }) => <h1>{data.slug}</h1> })
|
|
33
|
+
*/
|
|
34
|
+
function defineServerFn(fn) {
|
|
35
|
+
function serverFn(c) {
|
|
36
|
+
return fn(c);
|
|
37
|
+
}
|
|
38
|
+
Object.defineProperty(serverFn, "kind", {
|
|
39
|
+
value: SERVER_FN_KIND,
|
|
40
|
+
enumerable: true
|
|
41
|
+
});
|
|
42
|
+
return serverFn;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { readServerFn as a, isServerFn as i, SERVER_FN_KIND as n, usesDefineServerFn as o, defineServerFn as r, DEFINE_SERVER_FN_CALL as t };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=defineServerFn-H-bz7xBX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineServerFn-H-bz7xBX.mjs","names":[],"sources":["../src/vino/defineServerFn.ts"],"sourcesContent":["import type { Context, Env } from \"hono\";\n\nexport const SERVER_FN_KIND = \"vino:server-fn\" as const;\n\nexport type ServerFnHandler<T = unknown, E extends Env = Env> = (\n c: Context<E, string>,\n) => T | Promise<T>;\n\n/**\n * A server-only function. Callable as a `definePage({ data })` loader\n */\nexport type ServerFn<T = unknown, E extends Env = Env> = ServerFnHandler<T, E> & {\n readonly kind: typeof SERVER_FN_KIND;\n};\n\n/**\n * `defineServerFn` call signature, with `Env` fixed so `fn(c)` is typed without\n * blocking inference of the return type.\n */\nexport type DefineServerFnFn<E extends Env = Env> = <T>(fn: ServerFnHandler<T, E>) => ServerFn<T, E>;\n\nexport function isServerFn(value: unknown): value is ServerFn {\n return typeof value === \"function\" && (value as ServerFn).kind === SERVER_FN_KIND;\n}\n\nexport function readServerFn(value: unknown): ServerFn | undefined {\n return isServerFn(value) ? value : undefined;\n}\n\n/** Call-site of `defineServerFn(...)`, not `function defineServerFn(`. */\nexport const DEFINE_SERVER_FN_CALL =\n /(?<!function\\s)(?<![$\\w])defineServerFn\\s*(?:<[^>]*>\\s*)?\\(/g;\n\n/** True when source *calls* `defineServerFn(...)`. */\nexport function usesDefineServerFn(code: string): boolean {\n DEFINE_SERVER_FN_CALL.lastIndex = 0;\n return DEFINE_SERVER_FN_CALL.test(code);\n}\n\n/**\n * Mark a function as server-only.\n *\n * Pass the result to `definePage({ data })` (or `defineServerPage`) as a\n * loader. The same function can later be imported and invoked\n *\n * @example\n * // [slug].server.ts\n * export default defineServerFn(c => {\n * const slug = c.req.param(\"slug\") ?? \"\"\n * return { slug }\n * })\n *\n * @example\n * // [slug].tsx\n * import data from \"./[slug].server\"\n * export default definePage({ data, render: ({ data }) => <h1>{data.slug}</h1> })\n */\nexport function defineServerFn<T, E extends Env = Env>(fn: ServerFnHandler<T, E>): ServerFn<T, E> {\n function serverFn(c: Context<E, string>) {\n return fn(c);\n }\n Object.defineProperty(serverFn, \"kind\", {\n value: SERVER_FN_KIND,\n enumerable: true,\n });\n return serverFn as ServerFn<T, E>;\n}\n"],"mappings":";AAEA,MAAa,iBAAiB;AAmB9B,SAAgB,WAAW,OAAmC;CAC5D,OAAO,OAAO,UAAU,cAAe,MAAmB,SAAA;AAC5D;AAEA,SAAgB,aAAa,OAAsC;CACjE,OAAO,WAAW,KAAK,IAAI,QAAQ,KAAA;AACrC;;AAGA,MAAa,wBACX;;AAGF,SAAgB,mBAAmB,MAAuB;CACxD,sBAAsB,YAAY;CAClC,OAAO,sBAAsB,KAAK,IAAI;AACxC;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,eAAuC,IAA2C;CAChG,SAAS,SAAS,GAAuB;EACvC,OAAO,GAAG,CAAC;CACb;CACA,OAAO,eAAe,UAAU,QAAQ;EACtC,OAAO;EACP,YAAY;CACd,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { a as PageConfig, c as VinoHtml, n as DataLoader, o as PageProps } from "./types-CQITdkpF.mjs";
|
|
2
|
+
import { Context, Env } from "hono";
|
|
3
|
+
//#region src/vino/defineServerFn.d.ts
|
|
4
|
+
declare const SERVER_FN_KIND: "vino:server-fn";
|
|
5
|
+
type ServerFnHandler<T = unknown, E extends Env = Env> = (c: Context<E, string>) => T | Promise<T>;
|
|
6
|
+
/**
|
|
7
|
+
* A server-only function. Callable as a `definePage({ data })` loader
|
|
8
|
+
*/
|
|
9
|
+
type ServerFn<T = unknown, E extends Env = Env> = ServerFnHandler<T, E> & {
|
|
10
|
+
readonly kind: typeof SERVER_FN_KIND;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* `defineServerFn` call signature, with `Env` fixed so `fn(c)` is typed without
|
|
14
|
+
* blocking inference of the return type.
|
|
15
|
+
*/
|
|
16
|
+
type DefineServerFnFn<E extends Env = Env> = <T>(fn: ServerFnHandler<T, E>) => ServerFn<T, E>;
|
|
17
|
+
declare function isServerFn(value: unknown): value is ServerFn;
|
|
18
|
+
declare function readServerFn(value: unknown): ServerFn | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Mark a function as server-only.
|
|
21
|
+
*
|
|
22
|
+
* Pass the result to `definePage({ data })` (or `defineServerPage`) as a
|
|
23
|
+
* loader. The same function can later be imported and invoked
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // [slug].server.ts
|
|
27
|
+
* export default defineServerFn(c => {
|
|
28
|
+
* const slug = c.req.param("slug") ?? ""
|
|
29
|
+
* return { slug }
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // [slug].tsx
|
|
34
|
+
* import data from "./[slug].server"
|
|
35
|
+
* export default definePage({ data, render: ({ data }) => <h1>{data.slug}</h1> })
|
|
36
|
+
*/
|
|
37
|
+
declare function defineServerFn<T, E extends Env = Env>(fn: ServerFnHandler<T, E>): ServerFn<T, E>;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/vino/definePage.d.ts
|
|
40
|
+
declare const PAGE_KIND: "vino:page";
|
|
41
|
+
declare const SERVER_PAGE_KIND: "vino:server-page";
|
|
42
|
+
type PageRender<Data = unknown> = (props: PageProps<Data>) => VinoHtml;
|
|
43
|
+
type PageDataFn<E extends Env = Env> = DataLoader<E> | ServerFn<unknown, E>;
|
|
44
|
+
interface DefinePageOptions<Data = unknown, E extends Env = Env> {
|
|
45
|
+
/** JSX page component. Alias: `page`. */
|
|
46
|
+
render?: PageRender<Data>;
|
|
47
|
+
page?: PageRender<Data>;
|
|
48
|
+
/** Loader or `defineServerFn(...)` */
|
|
49
|
+
data?: DataLoader<E> | ServerFn<Data, E>;
|
|
50
|
+
config?: PageConfig;
|
|
51
|
+
}
|
|
52
|
+
/** Options object that infers `data` return type into `render` / `page`. */
|
|
53
|
+
type InferDefinePageOptions<D extends (...args: never[]) => unknown, Data = Awaited<ReturnType<D>>> = {
|
|
54
|
+
data?: D;
|
|
55
|
+
config?: PageConfig;
|
|
56
|
+
} & ({
|
|
57
|
+
render: PageRender<Data>;
|
|
58
|
+
page?: PageRender<Data>;
|
|
59
|
+
} | {
|
|
60
|
+
page: PageRender<Data>;
|
|
61
|
+
render?: PageRender<Data>;
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* `definePage` / `defineServerPage` call signature, with `Env` fixed so `data(c)`
|
|
65
|
+
* is typed without blocking inference of the loader return type.
|
|
66
|
+
*/
|
|
67
|
+
interface DefinePageFn<E extends Env = Env> {
|
|
68
|
+
<Data = unknown>(page: PageRender<Data>): PageDefinition<Data>;
|
|
69
|
+
<D extends PageDataFn<E>>(options: InferDefinePageOptions<D>): PageDefinition<Awaited<ReturnType<D>>>;
|
|
70
|
+
<Data = unknown>(options: DefinePageOptions<Data, E>): PageDefinition<Data>;
|
|
71
|
+
}
|
|
72
|
+
interface PageDefinition<Data = unknown> {
|
|
73
|
+
readonly kind: typeof PAGE_KIND | typeof SERVER_PAGE_KIND;
|
|
74
|
+
readonly client: boolean;
|
|
75
|
+
readonly render: PageRender<Data>;
|
|
76
|
+
readonly data?: DataLoader | ServerFn<Data>;
|
|
77
|
+
readonly config?: PageConfig;
|
|
78
|
+
}
|
|
79
|
+
declare function isPageDefinition(value: unknown): value is PageDefinition;
|
|
80
|
+
declare function isClientPageDefinition(value: unknown): value is PageDefinition;
|
|
81
|
+
declare function isServerPageDefinition(value: unknown): value is PageDefinition;
|
|
82
|
+
declare function resolvePageRender(value: unknown): PageRender | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Declare a page that SSRs with `hono/jsx`, then hydrates `#vino-page` with `hono/jsx/dom`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* export default definePage(() => {
|
|
88
|
+
* const [n, setN] = useState(0)
|
|
89
|
+
* return <button onClick={() => setN(n + 1)}>{n}</button>
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* export default definePage({
|
|
94
|
+
* config: { prerender: 'full', clientRouting: true },
|
|
95
|
+
* data: async (c) => ({ title: 'Hello' }),
|
|
96
|
+
* render: ({ data }) => <h1>{data.title}</h1>,
|
|
97
|
+
* })
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* import data from './[slug].server'
|
|
101
|
+
* export default definePage({ data, render: ({ data }) => <h1>{data.title}</h1> })
|
|
102
|
+
*/
|
|
103
|
+
declare const definePage: DefinePageFn;
|
|
104
|
+
/**
|
|
105
|
+
* Declare a page that SSRs only. The output is never hydrated.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* export default defineServerPage(() => <h1>About</h1>)
|
|
109
|
+
*/
|
|
110
|
+
declare const defineServerPage: DefinePageFn;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/vino/factory.d.ts
|
|
113
|
+
declare class Factory<E extends Env = Env> {
|
|
114
|
+
/** Same as `definePage`, with `c` typed as `Context<E>`. */
|
|
115
|
+
definePage: DefinePageFn<E>;
|
|
116
|
+
/** Same as `defineServerPage`, with `c` typed as `Context<E>`. */
|
|
117
|
+
defineServerPage: DefinePageFn<E>;
|
|
118
|
+
/** Same as `defineServerFn`, with `c` typed as `Context<E>`. */
|
|
119
|
+
defineServerFn: DefineServerFnFn<E>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a factory that binds `Env` onto page and server-fn helpers.
|
|
123
|
+
*
|
|
124
|
+
* Pair with `createVino<Env>()` (or `new Hono<Env>()`) so the app and pages
|
|
125
|
+
* share one `Env` type.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* // src/factory.ts
|
|
129
|
+
* import { createFactory } from "vinojs/factory"
|
|
130
|
+
* export const factory = createFactory<Env>()
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* // src/pages/index.tsx
|
|
134
|
+
* import { factory } from "../factory"
|
|
135
|
+
* export default factory.definePage({
|
|
136
|
+
* data: (c) => ({ title: c.env.TITLE }),
|
|
137
|
+
* render: ({ data }) => <h1>{data.title}</h1>,
|
|
138
|
+
* })
|
|
139
|
+
*/
|
|
140
|
+
declare const createFactory: <E extends Env = Env>() => Factory<E>;
|
|
141
|
+
//#endregion
|
|
142
|
+
export { ServerFnHandler as _, InferDefinePageOptions as a, readServerFn as b, PageRender as c, isClientPageDefinition as d, isPageDefinition as f, ServerFn as g, DefineServerFnFn as h, DefinePageOptions as i, definePage as l, resolvePageRender as m, createFactory as n, PageDataFn as o, isServerPageDefinition as p, DefinePageFn as r, PageDefinition as s, Factory as t, defineServerPage as u, defineServerFn as v, isServerFn as y };
|
|
143
|
+
//# sourceMappingURL=factory-AHIdhfy4.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-AHIdhfy4.d.mts","names":[],"sources":["../src/vino/defineServerFn.ts","../src/vino/definePage.ts","../src/vino/factory.ts"],"mappings":";;;cAEa;KAED,gBAAgB,aAAa,UAAU,MAAM,QACvD,GAAG,QAAQ,eACR,IAAI,QAAQ;;;;KAKL,SAAS,aAAa,UAAU,MAA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;cAsBtB,gBAAiB,UAAU,MAAM,UAAQ,QAAQ"}
|
package/dist/factory.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { n as defineServerPage, t as definePage } from "./definePage--9Pz7rHs.mjs";
|
|
2
|
+
import { r as defineServerFn } from "./defineServerFn-H-bz7xBX.mjs";
|
|
3
|
+
//#region src/vino/factory.ts
|
|
4
|
+
var Factory = class {
|
|
5
|
+
/** Same as `definePage`, with `c` typed as `Context<E>`. */
|
|
6
|
+
definePage = definePage;
|
|
7
|
+
/** Same as `defineServerPage`, with `c` typed as `Context<E>`. */
|
|
8
|
+
defineServerPage = defineServerPage;
|
|
9
|
+
/** Same as `defineServerFn`, with `c` typed as `Context<E>`. */
|
|
10
|
+
defineServerFn = defineServerFn;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Create a factory that binds `Env` onto page and server-fn helpers.
|
|
14
|
+
*
|
|
15
|
+
* Pair with `createVino<Env>()` (or `new Hono<Env>()`) so the app and pages
|
|
16
|
+
* share one `Env` type.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // src/factory.ts
|
|
20
|
+
* import { createFactory } from "vinojs/factory"
|
|
21
|
+
* export const factory = createFactory<Env>()
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // src/pages/index.tsx
|
|
25
|
+
* import { factory } from "../factory"
|
|
26
|
+
* export default factory.definePage({
|
|
27
|
+
* data: (c) => ({ title: c.env.TITLE }),
|
|
28
|
+
* render: ({ data }) => <h1>{data.title}</h1>,
|
|
29
|
+
* })
|
|
30
|
+
*/
|
|
31
|
+
const createFactory = () => new Factory();
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Factory, createFactory };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=factory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.mjs","names":["definePageImpl","defineServerPageImpl","defineServerFnImpl"],"sources":["../src/vino/factory.ts"],"sourcesContent":["/**\n * Factory helper for Vino, analogous to `hono/factory`.\n *\n * Bind `Env` once so `definePage` / `defineServerPage` / `defineServerFn` type\n * `c` without blocking inference of loader return data.\n */\n\nimport type { Env } from \"hono\";\nimport {\n definePage as definePageImpl,\n defineServerPage as defineServerPageImpl,\n type DefinePageFn,\n} from \"./definePage.ts\";\nimport { defineServerFn as defineServerFnImpl, type DefineServerFnFn } from \"./defineServerFn.ts\";\nimport type { PageConfig } from \"./types.ts\";\n\ninterface FactoryOptions {\n pageConfig?: PageConfig;\n}\n\nexport class Factory<E extends Env = Env> {\n /** Same as `definePage`, with `c` typed as `Context<E>`. */\n definePage: DefinePageFn<E> = definePageImpl as unknown as DefinePageFn<E>;\n\n /** Same as `defineServerPage`, with `c` typed as `Context<E>`. */\n defineServerPage: DefinePageFn<E> = defineServerPageImpl as unknown as DefinePageFn<E>;\n\n /** Same as `defineServerFn`, with `c` typed as `Context<E>`. */\n defineServerFn: DefineServerFnFn<E> = defineServerFnImpl;\n}\n\n/**\n * Create a factory that binds `Env` onto page and server-fn helpers.\n *\n * Pair with `createVino<Env>()` (or `new Hono<Env>()`) so the app and pages\n * share one `Env` type.\n *\n * @example\n * // src/factory.ts\n * import { createFactory } from \"vinojs/factory\"\n * export const factory = createFactory<Env>()\n *\n * @example\n * // src/pages/index.tsx\n * import { factory } from \"../factory\"\n * export default factory.definePage({\n * data: (c) => ({ title: c.env.TITLE }),\n * render: ({ data }) => <h1>{data.title}</h1>,\n * })\n */\nexport const createFactory = <E extends Env = Env>(): Factory<E> => new Factory<E>();\n// export const createFactory = <E extends Env = Env>(options?: FactoryOptions): Factory<E> => new Factory<E>(options);\n"],"mappings":";;;AAoBA,IAAa,UAAb,MAA0C;;CAExC,aAA8BA;;CAG9B,mBAAoCC;;CAGpC,iBAAsCC;AACxC;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,sBAAuD,IAAI,QAAW"}
|
package/dist/vino.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { a as PageConfig,
|
|
1
|
+
import { a as PageConfig, d as VinoViteOptions, i as ManifestPage, l as VinoManifest, o as PageProps, r as LayoutProps, s as RenderMode, t as CreateVinoOptions, u as VinoPayload } from "./types-CQITdkpF.mjs";
|
|
2
2
|
import { wrapComponent, wrapModule } from "./component-wrap.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { _ as ServerFnHandler, a as InferDefinePageOptions, b as readServerFn, c as PageRender, d as isClientPageDefinition, f as isPageDefinition, g as ServerFn, h as DefineServerFnFn, i as DefinePageOptions, l as definePage, m as resolvePageRender, n as createFactory, o as PageDataFn, p as isServerPageDefinition, r as DefinePageFn, s as PageDefinition, t as Factory, u as defineServerPage, v as defineServerFn, y as isServerFn } from "./factory-AHIdhfy4.mjs";
|
|
4
|
+
import { Env, Hono, Schema } from "hono";
|
|
4
5
|
import { BlankSchema } from "hono/types";
|
|
5
6
|
//#region src/vino/createVino.d.ts
|
|
6
7
|
/**
|
|
@@ -15,106 +16,6 @@ declare function mountVino<E extends Env, S extends Schema, BasePath extends str
|
|
|
15
16
|
*/
|
|
16
17
|
declare function createVino<E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = "/">(options?: CreateVinoOptions): Hono<E, S, BasePath>;
|
|
17
18
|
//#endregion
|
|
18
|
-
//#region src/vino/defineServerFn.d.ts
|
|
19
|
-
declare const SERVER_FN_KIND: "vino:server-fn";
|
|
20
|
-
type ServerFnHandler<T = unknown, E extends Env = Env> = (c: Context<E, string>) => T | Promise<T>;
|
|
21
|
-
/**
|
|
22
|
-
* A server-only function. Callable as a `definePage({ data })` loader
|
|
23
|
-
*/
|
|
24
|
-
type ServerFn<T = unknown, E extends Env = Env> = ServerFnHandler<T, E> & {
|
|
25
|
-
readonly kind: typeof SERVER_FN_KIND;
|
|
26
|
-
};
|
|
27
|
-
declare function isServerFn(value: unknown): value is ServerFn;
|
|
28
|
-
declare function readServerFn(value: unknown): ServerFn | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Mark a function as server-only.
|
|
31
|
-
*
|
|
32
|
-
* Pass the result to `definePage({ data })` (or `defineServerPage`) as a
|
|
33
|
-
* loader. The same function can later be imported and invoked
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* // [slug].server.ts
|
|
37
|
-
* export default defineServerFn(c => {
|
|
38
|
-
* const slug = c.req.param("slug") ?? ""
|
|
39
|
-
* return { slug }
|
|
40
|
-
* })
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* // [slug].tsx
|
|
44
|
-
* import data from "./[slug].server"
|
|
45
|
-
* export default definePage({ data, render: ({ data }) => <h1>{data.slug}</h1> })
|
|
46
|
-
*/
|
|
47
|
-
declare function defineServerFn<T, E extends Env = Env>(fn: ServerFnHandler<T, E>): ServerFn<T, E>;
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/vino/definePage.d.ts
|
|
50
|
-
declare const PAGE_KIND: "vino:page";
|
|
51
|
-
declare const SERVER_PAGE_KIND: "vino:server-page";
|
|
52
|
-
type PageRender<Data = unknown> = (props: PageProps<Data>) => VinoHtml;
|
|
53
|
-
interface DefinePageOptions<Data = unknown> {
|
|
54
|
-
/** JSX page component. Alias: `page`. */
|
|
55
|
-
render?: PageRender<Data>;
|
|
56
|
-
page?: PageRender<Data>;
|
|
57
|
-
/** Loader or `defineServerFn(...)` (including a default import from `*.server.ts`). */
|
|
58
|
-
data?: DataLoader | ServerFn<Data>;
|
|
59
|
-
config?: PageConfig;
|
|
60
|
-
}
|
|
61
|
-
interface PageDefinition<Data = unknown> {
|
|
62
|
-
readonly kind: typeof PAGE_KIND | typeof SERVER_PAGE_KIND;
|
|
63
|
-
readonly client: boolean;
|
|
64
|
-
readonly render: PageRender<Data>;
|
|
65
|
-
readonly data?: DataLoader | ServerFn<Data>;
|
|
66
|
-
readonly config?: PageConfig;
|
|
67
|
-
}
|
|
68
|
-
declare function isPageDefinition(value: unknown): value is PageDefinition;
|
|
69
|
-
declare function isClientPageDefinition(value: unknown): value is PageDefinition;
|
|
70
|
-
declare function isServerPageDefinition(value: unknown): value is PageDefinition;
|
|
71
|
-
declare function resolvePageRender(value: unknown): PageRender | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* Declare a page that SSRs with `hono/jsx`, then hydrates `#vino-page` with `hono/jsx/dom`.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* export default definePage(() => {
|
|
77
|
-
* const [n, setN] = useState(0)
|
|
78
|
-
* return <button onClick={() => setN(n + 1)}>{n}</button>
|
|
79
|
-
* })
|
|
80
|
-
*/
|
|
81
|
-
declare function definePage<Data = unknown>(page: PageRender<Data>): PageDefinition<Data>;
|
|
82
|
-
/**
|
|
83
|
-
* Declare a hydratable page as `{ render, data?, config? }`.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* export default definePage({
|
|
87
|
-
* config: { prerender: 'full', clientRouting: true },
|
|
88
|
-
* data: async (c) => ({ title: 'Hello' }),
|
|
89
|
-
* render: ({ data }) => <h1>{data.title}</h1>,
|
|
90
|
-
* })
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* import data from './[slug].server'
|
|
94
|
-
* export default definePage({ data, render: ({ data }) => <h1>{data.title}</h1> })
|
|
95
|
-
*/
|
|
96
|
-
declare function definePage<D extends DataLoader | ServerFn>(options: {
|
|
97
|
-
render: PageRender<Awaited<ReturnType<D>>>;
|
|
98
|
-
page?: PageRender<Awaited<ReturnType<D>>>;
|
|
99
|
-
data?: D;
|
|
100
|
-
config?: PageConfig;
|
|
101
|
-
}): PageDefinition<Awaited<ReturnType<D>>>;
|
|
102
|
-
declare function definePage<Data = unknown>(options: DefinePageOptions<Data>): PageDefinition<Data>;
|
|
103
|
-
/**
|
|
104
|
-
* Declare a page that SSRs only. The output is never hydrated.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* export default defineServerPage(() => <h1>About</h1>)
|
|
108
|
-
*/
|
|
109
|
-
declare function defineServerPage<Data = unknown>(page: PageRender<Data>): PageDefinition<Data>;
|
|
110
|
-
declare function defineServerPage<D extends DataLoader | ServerFn>(options: {
|
|
111
|
-
render: PageRender<Awaited<ReturnType<D>>>;
|
|
112
|
-
page?: PageRender<Awaited<ReturnType<D>>>;
|
|
113
|
-
data?: D;
|
|
114
|
-
config?: PageConfig;
|
|
115
|
-
}): PageDefinition<Awaited<ReturnType<D>>>;
|
|
116
|
-
declare function defineServerPage<Data = unknown>(options: DefinePageOptions<Data>): PageDefinition<Data>;
|
|
117
|
-
//#endregion
|
|
118
19
|
//#region src/vino/compile.d.ts
|
|
119
20
|
interface CompiledRoute {
|
|
120
21
|
/** Filesystem-derived path using `:param` (no Hono regex). `/`, `/about`, `/blog/:slug`. */
|
|
@@ -140,5 +41,5 @@ declare const COMPONENT_TAG = "vino-component";
|
|
|
140
41
|
declare const NAV_HEADER = "X-Vino-Nav";
|
|
141
42
|
declare const SHELL_HEADER = "X-Vino-Shell";
|
|
142
43
|
//#endregion
|
|
143
|
-
export { COMPONENT_TAG, type CreateVinoOptions, type DefinePageOptions, type LayoutProps, type ManifestPage, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, type PageConfig, type PageDefinition, type PageProps, type PageRender, type RenderMode, SHELL_HEADER, type ServerFn, type ServerFnHandler, type VinoManifest, type VinoPayload, type VinoViteOptions, applyParams, compileFilePath, createVino, definePage, defineServerFn, defineServerPage, isClientPageDefinition, isPageDefinition, isServerFn, isServerPageDefinition, mountVino, readServerFn, resolvePageRender, wrapComponent, wrapModule };
|
|
44
|
+
export { COMPONENT_TAG, type CreateVinoOptions, type DefinePageFn, type DefinePageOptions, type DefineServerFnFn, Factory, type InferDefinePageOptions, type LayoutProps, type ManifestPage, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, type PageConfig, type PageDataFn, type PageDefinition, type PageProps, type PageRender, type RenderMode, SHELL_HEADER, type ServerFn, type ServerFnHandler, type VinoManifest, type VinoPayload, type VinoViteOptions, applyParams, compileFilePath, createFactory, createVino, definePage, defineServerFn, defineServerPage, isClientPageDefinition, isPageDefinition, isServerFn, isServerPageDefinition, mountVino, readServerFn, resolvePageRender, wrapComponent, wrapModule };
|
|
144
45
|
//# sourceMappingURL=vino.d.mts.map
|
package/dist/vino.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vino.d.mts","names":[],"sources":["../src/vino/createVino.ts","../src/vino/
|
|
1
|
+
{"version":3,"file":"vino.d.mts","names":[],"sources":["../src/vino/createVino.ts","../src/vino/compile.ts","../src/vino/constants.ts"],"mappings":";;;;;;;;;;iBAgGgB,UAAU,UAAU,KAAK,UAAU,QAAQ,yBAAyB,KAAK,KAAK,GAAG,GAAG,WAAW,UAAS,oBAAyB,KAAK,GAAG,GAAG;;;;;;iBAc5I,WAAW,UAAU,MAAM,KAAK,UAAU,SAAS,aAAa,+BAA+B,UAAS,oBAAyB,KAAK,GAAG,GAAG;;;UC9G3I;;EAEf;;EAEA;EACA;EACA;EACA;;;;;;;iBAoBc,gBAAgB,uBAAuB;iBA8DvC,YAAY,cAAc,QAAQ;;;cCzFrC;cACA;cACA;cAKA;cACA"}
|
package/dist/vino.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { c as PAGE_SLOT_ID, l as PAYLOAD_SCRIPT_ID, o as NAV_HEADER, t as COMPONENT_TAG, u as SHELL_HEADER } from "./constants-BVT2bJEd.mjs";
|
|
2
|
-
import { a as isServerPageDefinition, i as isPageDefinition, n as defineServerPage, r as isClientPageDefinition, s as resolvePageRender, t as definePage } from "./definePage
|
|
3
|
-
import {
|
|
2
|
+
import { a as isServerPageDefinition, i as isPageDefinition, n as defineServerPage, r as isClientPageDefinition, s as resolvePageRender, t as definePage } from "./definePage--9Pz7rHs.mjs";
|
|
3
|
+
import { c as loadMergedData, r as compileFilePath, s as loadMergedConfig, t as applyParams } from "./compile-glNMkyyx.mjs";
|
|
4
|
+
import { a as readServerFn, i as isServerFn, r as defineServerFn } from "./defineServerFn-H-bz7xBX.mjs";
|
|
5
|
+
import { Factory, createFactory } from "./factory.mjs";
|
|
4
6
|
import { wrapComponent, wrapModule } from "./component-wrap.mjs";
|
|
5
7
|
import { Hono } from "hono";
|
|
6
8
|
import { jsxDEV } from "hono/jsx/jsx-dev-runtime";
|
|
@@ -192,6 +194,6 @@ function createVino(options = {}) {
|
|
|
192
194
|
return mountVino(new Hono(), options);
|
|
193
195
|
}
|
|
194
196
|
//#endregion
|
|
195
|
-
export { COMPONENT_TAG, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, SHELL_HEADER, applyParams, compileFilePath, createVino, definePage, defineServerFn, defineServerPage, isClientPageDefinition, isPageDefinition, isServerFn, isServerPageDefinition, mountVino, readServerFn, resolvePageRender, wrapComponent, wrapModule };
|
|
197
|
+
export { COMPONENT_TAG, Factory, NAV_HEADER, PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID, SHELL_HEADER, applyParams, compileFilePath, createFactory, createVino, definePage, defineServerFn, defineServerPage, isClientPageDefinition, isPageDefinition, isServerFn, isServerPageDefinition, mountVino, readServerFn, resolvePageRender, wrapComponent, wrapModule };
|
|
196
198
|
|
|
197
199
|
//# sourceMappingURL=vino.mjs.map
|
package/dist/vino.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vino.mjs","names":["jsx","jsx","assetsIsDev","manifest","virtualManifest"],"sources":["../src/vino/render.ts","../src/vino/createVino.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { Context } from \"hono\";\nimport type { Child } from \"hono/jsx\";\nimport { jsxDEV as jsx } from \"hono/jsx/jsx-dev-runtime\";\nimport { jsxRenderer } from \"hono/jsx-renderer\";\nimport { PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID } from \"./constants.ts\";\nimport type { ManifestPage, PageConfig, PageModule, RenderMode, VinoPayload } from \"./types.ts\";\n\nfunction DefaultLayout(props: { children?: Child }) {\n return jsx(\"html\", {\n children: [\n jsx(\"head\", {\n children: [\n jsx(\"meta\", { charset: \"utf-8\" }),\n jsx(\"meta\", { name: \"viewport\", content: \"width=device-width, initial-scale=1\" }),\n ],\n }),\n jsx(\"body\", { children: props.children }),\n ],\n });\n}\n\nexport function isHonoApp(value: unknown): value is Hono {\n return value instanceof Hono;\n}\n\nfunction payloadScript(payload: VinoPayload): string {\n const json = JSON.stringify(payload).replaceAll(\"<\", \"\\\\u003c\");\n return `<script id=\"${PAYLOAD_SCRIPT_ID}\" type=\"application/json\">${json}</script>`;\n}\n\nexport function injectDocument(\n html: string,\n payload: VinoPayload,\n isDev: boolean,\n scriptSrc: string,\n): string {\n const vite = isDev ? `<script type=\"module\" src=\"/@vite/client\"></script>` : \"\";\n const client = `<script type=\"module\" src=\"${scriptSrc}\"></script>`;\n const inject = `${vite}${payloadScript(payload)}${client}`;\n if (html.includes(\"</body>\")) return html.replace(\"</body>\", `${inject}</body>`);\n if (html.includes(\"</html>\")) return html.replace(\"</html>\", `${inject}</html>`);\n return `<!DOCTYPE html>${html}${inject}`;\n}\n\nasync function ensureJsxRenderer(c: Context): Promise<void> {\n await jsxRenderer(undefined, { docType: true })(c, async () => {});\n}\n\nfunction needsPageSlot(page: ManifestPage, config: PageConfig, mode: RenderMode): boolean {\n if (mode === \"shell\" || mode === \"content\") return true;\n if (page.isClientPage) return true;\n if (config.clientRouting === true) return true;\n if (config.prerender === \"partial\") return true;\n return false;\n}\n\nfunction emptySlot(): Child {\n return jsx(\"div\", { id: PAGE_SLOT_ID });\n}\n\nfunction wrapSlot(children: Child): Child {\n return jsx(\"div\", { id: PAGE_SLOT_ID, children });\n}\n\nfunction buildPayload(options: {\n page: ManifestPage;\n params: Record<string, string>;\n data: unknown;\n config: PageConfig;\n mode: RenderMode;\n requestPath?: string;\n title?: string;\n}): VinoPayload {\n const { page, params, data, config, mode, requestPath, title } = options;\n const path = requestPath ?? (page.path === \"\" ? \"/\" : page.path);\n return {\n path,\n params,\n data,\n clientRouting: config.clientRouting === true,\n clientPage: page.isClientPage ? page.path : null,\n partial: mode === \"shell\",\n title,\n };\n}\n\nexport async function renderPageHtml(options: {\n c: Context;\n page: ManifestPage;\n pageMod: PageModule;\n pageNode?: Child | null;\n data: unknown;\n params: Record<string, string>;\n config: PageConfig;\n isDev: boolean;\n clientScriptSrc: string;\n mode?: RenderMode;\n title?: string;\n}): Promise<{ html: string; payload: VinoPayload }> {\n const {\n c,\n page,\n pageNode = null,\n data,\n params,\n config,\n isDev,\n clientScriptSrc,\n mode = \"full\",\n title,\n } = options;\n\n const payload = buildPayload({\n page,\n params,\n data,\n config,\n mode,\n requestPath: c.req.path,\n title,\n });\n\n if (mode === \"content\") {\n if (pageNode == null) throw new Error(\"content render requires pageNode\");\n const node = wrapSlot(pageNode);\n await ensureJsxRenderer(c);\n const rendered = await c.render(node as never);\n let html = await rendered.text();\n html = html.replace(/^<!DOCTYPE html>/i, \"\");\n html = `${html}${payloadScript(payload)}`;\n return { html, payload };\n }\n\n let node: Child = mode === \"shell\" ? emptySlot() : (pageNode as Child);\n if (mode !== \"shell\" && needsPageSlot(page, config, mode)) {\n node = wrapSlot(node);\n }\n\n const layouts = await Promise.all(page.loadLayouts.map((load) => load()));\n for (const layout of [...layouts].reverse()) {\n const Layout = layout.default;\n node = jsx(Layout, { data, params, children: node });\n }\n if (layouts.length === 0) {\n node = jsx(DefaultLayout, { children: node });\n }\n\n await ensureJsxRenderer(c);\n const rendered = await c.render(node as never);\n let html = await rendered.text();\n\n html = injectDocument(html, payload, isDev, clientScriptSrc);\n if (!html.startsWith(\"<!\")) html = `<!DOCTYPE html>${html}`;\n return { html, payload };\n}\n","import { Hono } from \"hono\";\nimport type { Context, Env, Schema } from \"hono\";\nimport type { BlankSchema } from \"hono/types\";\nimport { jsxDEV as jsx } from \"hono/jsx/jsx-dev-runtime\";\nimport { manifest as virtualManifest } from \"virtual:vino/manifest\";\nimport { isDev as assetsIsDev, clientScriptSrc } from \"virtual:vino/assets\";\nimport { NAV_HEADER, SHELL_HEADER } from \"./constants.ts\";\nimport { loadMergedConfig, loadMergedData } from \"./config.ts\";\nimport { resolvePageRender } from \"./definePage.ts\";\nimport { isHonoApp, renderPageHtml } from \"./render.ts\";\nimport type { CreateVinoOptions, ManifestPage, PageModule, RenderMode } from \"./types.ts\";\n\ntype AppContext = Context;\n\nfunction requestParams(c: AppContext): Record<string, string> {\n try {\n return c.req.param();\n } catch {\n return {};\n }\n}\n\nfunction pageFromModule(pageMod: PageModule, data: unknown, params: Record<string, string>) {\n const Page = resolvePageRender(pageMod.default);\n if (Page) return jsx(Page, { data, params });\n return pageMod.default as never;\n}\n\nfunction resolveRenderMode(c: AppContext): RenderMode {\n if (c.req.header(SHELL_HEADER)) return \"shell\";\n if (c.req.header(NAV_HEADER)) return \"content\";\n return \"full\";\n}\n\nasync function handlePage(c: AppContext, page: ManifestPage): Promise<Response> {\n const pageMod = await page.loadPage();\n if (isHonoApp(pageMod.default)) {\n return pageMod.default.fetch(c.req.raw, c.env, c.executionCtx);\n }\n\n const method = c.req.method;\n const named = pageMod[method];\n const hasPage = Boolean(resolvePageRender(pageMod.default));\n const mode = resolveRenderMode(c);\n\n if (typeof named === \"function\" && (method !== \"GET\" || !hasPage)) {\n const result: unknown = await (named as (ctx: AppContext) => unknown)(c);\n if (result instanceof Response) return result;\n if (method === \"GET\" || method === \"HEAD\") {\n const config = loadMergedConfig(page, pageMod);\n const params = requestParams(c);\n const data = mode === \"shell\" ? undefined : await loadMergedData(page, c, pageMod);\n const { html } = await renderPageHtml({\n c,\n page,\n pageMod,\n pageNode: mode === \"shell\" ? null : (result as never),\n data,\n params,\n config,\n isDev: assetsIsDev,\n clientScriptSrc,\n mode,\n });\n return c.html(html);\n }\n return c.json(result as never);\n }\n\n if (method !== \"GET\" && method !== \"HEAD\") {\n return c.text(\"Method Not Allowed\", 405);\n }\n\n const config = loadMergedConfig(page, pageMod);\n const params = requestParams(c);\n const data = mode === \"shell\" ? undefined : await loadMergedData(page, c, pageMod);\n const pageNode = mode === \"shell\" ? null : pageFromModule(pageMod, data, params);\n const { html } = await renderPageHtml({\n c,\n page,\n pageMod,\n pageNode: pageNode,\n data,\n params,\n config,\n isDev: assetsIsDev,\n clientScriptSrc,\n mode,\n });\n return c.html(html);\n}\n\n/**\n * Mount filesystem pages from the Vite-generated manifest onto a user-owned Hono app.\n * Extra API routes should be registered on `app` before calling this.\n */\nexport function mountVino<E extends Env, S extends Schema, BasePath extends string>(app: Hono<E, S, BasePath>, options: CreateVinoOptions = {}): Hono<E, S, BasePath> {\n const manifest = options.manifest ?? virtualManifest;\n for (const page of manifest.pages) {\n app.get(page.pattern, (c) => handlePage(c as AppContext, page));\n }\n\n return app;\n}\n\n/**\n * Create a new Vino app. Returns a Hono app with the Vino pages mounted.\n * @param options - The options for the Vino app.\n * @returns A Hono app with the Vino pages mounted.\n */\nexport function createVino<E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = \"/\">(options: CreateVinoOptions = {}): Hono<E, S, BasePath> {\n const app = new Hono<E, S, BasePath>();\n return mountVino(app, options);\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAS,cAAc,OAA6B;CAClD,OAAOA,OAAI,QAAQ,EACjB,UAAU,CACRA,OAAI,QAAQ,EACV,UAAU,CACRA,OAAI,QAAQ,EAAE,SAAS,QAAQ,CAAC,GAChCA,OAAI,QAAQ;EAAE,MAAM;EAAY,SAAS;CAAsC,CAAC,CAClF,EACF,CAAC,GACDA,OAAI,QAAQ,EAAE,UAAU,MAAM,SAAS,CAAC,CAC1C,EACF,CAAC;AACH;AAEA,SAAgB,UAAU,OAA+B;CACvD,OAAO,iBAAiB;AAC1B;AAEA,SAAS,cAAc,SAA8B;CACnD,MAAM,OAAO,KAAK,UAAU,OAAO,CAAC,CAAC,WAAW,KAAK,SAAS;CAC9D,OAAO,eAAe,kBAAkB,4BAA4B,KAAK;AAC3E;AAEA,SAAgB,eACd,MACA,SACA,OACA,WACQ;CAC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,MAAM,EAAE,SAAS,MAAM,eAAe;EACpC;EACA;EACA;EACU,UALK,SAAS,UAAU,OAAO,eAAe,SAAS,MAAM,MAAM;EAM7E;EACA;EACA;EACOA;EACP;EACA;CACF,CAAC;CACD,OAAO,EAAE,KAAK,IAAI;AACpB;;;;;AAMA,SAAgB,UAAoE,KAA2B,UAA6B,CAAC,GAAyB;CACpK,MAAMC,aAAW,QAAQ,YAAYC;CACrC,KAAK,MAAM,QAAQD,WAAS,OAC1B,IAAI,IAAI,KAAK,UAAU,MAAM,WAAW,GAAiB,IAAI,CAAC;CAGhE,OAAO;AACT;;;;;;AAOA,SAAgB,WAA+F,UAA6B,CAAC,GAAyB;CAEpK,OAAO,UAAU,IADD,KACG,GAAG,OAAO;AAC/B"}
|
|
1
|
+
{"version":3,"file":"vino.mjs","names":["jsx","jsx","assetsIsDev","manifest","virtualManifest"],"sources":["../src/vino/render.ts","../src/vino/createVino.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { Context } from \"hono\";\nimport type { Child } from \"hono/jsx\";\nimport { jsxDEV as jsx } from \"hono/jsx/jsx-dev-runtime\";\nimport { jsxRenderer } from \"hono/jsx-renderer\";\nimport { PAGE_SLOT_ID, PAYLOAD_SCRIPT_ID } from \"./constants.ts\";\nimport type { ManifestPage, PageConfig, PageModule, RenderMode, VinoPayload } from \"./types.ts\";\n\nfunction DefaultLayout(props: { children?: Child }) {\n return jsx(\"html\", {\n children: [\n jsx(\"head\", {\n children: [\n jsx(\"meta\", { charset: \"utf-8\" }),\n jsx(\"meta\", { name: \"viewport\", content: \"width=device-width, initial-scale=1\" }),\n ],\n }),\n jsx(\"body\", { children: props.children }),\n ],\n });\n}\n\nexport function isHonoApp(value: unknown): value is Hono {\n return value instanceof Hono;\n}\n\nfunction payloadScript(payload: VinoPayload): string {\n const json = JSON.stringify(payload).replaceAll(\"<\", \"\\\\u003c\");\n return `<script id=\"${PAYLOAD_SCRIPT_ID}\" type=\"application/json\">${json}</script>`;\n}\n\nexport function injectDocument(\n html: string,\n payload: VinoPayload,\n isDev: boolean,\n scriptSrc: string,\n): string {\n const vite = isDev ? `<script type=\"module\" src=\"/@vite/client\"></script>` : \"\";\n const client = `<script type=\"module\" src=\"${scriptSrc}\"></script>`;\n const inject = `${vite}${payloadScript(payload)}${client}`;\n if (html.includes(\"</body>\")) return html.replace(\"</body>\", `${inject}</body>`);\n if (html.includes(\"</html>\")) return html.replace(\"</html>\", `${inject}</html>`);\n return `<!DOCTYPE html>${html}${inject}`;\n}\n\nasync function ensureJsxRenderer(c: Context): Promise<void> {\n await jsxRenderer(undefined, { docType: true })(c, async () => {});\n}\n\nfunction needsPageSlot(page: ManifestPage, config: PageConfig, mode: RenderMode): boolean {\n if (mode === \"shell\" || mode === \"content\") return true;\n if (page.isClientPage) return true;\n if (config.clientRouting === true) return true;\n if (config.prerender === \"partial\") return true;\n return false;\n}\n\nfunction emptySlot(): Child {\n return jsx(\"div\", { id: PAGE_SLOT_ID });\n}\n\nfunction wrapSlot(children: Child): Child {\n return jsx(\"div\", { id: PAGE_SLOT_ID, children });\n}\n\nfunction buildPayload(options: {\n page: ManifestPage;\n params: Record<string, string>;\n data: unknown;\n config: PageConfig;\n mode: RenderMode;\n requestPath?: string;\n title?: string;\n}): VinoPayload {\n const { page, params, data, config, mode, requestPath, title } = options;\n const path = requestPath ?? (page.path === \"\" ? \"/\" : page.path);\n return {\n path,\n params,\n data,\n clientRouting: config.clientRouting === true,\n clientPage: page.isClientPage ? page.path : null,\n partial: mode === \"shell\",\n title,\n };\n}\n\nexport async function renderPageHtml(options: {\n c: Context;\n page: ManifestPage;\n pageMod: PageModule;\n pageNode?: Child | null;\n data: unknown;\n params: Record<string, string>;\n config: PageConfig;\n isDev: boolean;\n clientScriptSrc: string;\n mode?: RenderMode;\n title?: string;\n}): Promise<{ html: string; payload: VinoPayload }> {\n const {\n c,\n page,\n pageNode = null,\n data,\n params,\n config,\n isDev,\n clientScriptSrc,\n mode = \"full\",\n title,\n } = options;\n\n const payload = buildPayload({\n page,\n params,\n data,\n config,\n mode,\n requestPath: c.req.path,\n title,\n });\n\n if (mode === \"content\") {\n if (pageNode == null) throw new Error(\"content render requires pageNode\");\n const node = wrapSlot(pageNode);\n await ensureJsxRenderer(c);\n const rendered = await c.render(node as never);\n let html = await rendered.text();\n html = html.replace(/^<!DOCTYPE html>/i, \"\");\n html = `${html}${payloadScript(payload)}`;\n return { html, payload };\n }\n\n let node: Child = mode === \"shell\" ? emptySlot() : (pageNode as Child);\n if (mode !== \"shell\" && needsPageSlot(page, config, mode)) {\n node = wrapSlot(node);\n }\n\n const layouts = await Promise.all(page.loadLayouts.map((load) => load()));\n for (const layout of [...layouts].reverse()) {\n const Layout = layout.default;\n node = jsx(Layout, { data, params, children: node });\n }\n if (layouts.length === 0) {\n node = jsx(DefaultLayout, { children: node });\n }\n\n await ensureJsxRenderer(c);\n const rendered = await c.render(node as never);\n let html = await rendered.text();\n\n html = injectDocument(html, payload, isDev, clientScriptSrc);\n if (!html.startsWith(\"<!\")) html = `<!DOCTYPE html>${html}`;\n return { html, payload };\n}\n","import { Hono } from \"hono\";\nimport type { Context, Env, Schema } from \"hono\";\nimport type { BlankSchema } from \"hono/types\";\nimport { jsxDEV as jsx } from \"hono/jsx/jsx-dev-runtime\";\nimport { manifest as virtualManifest } from \"virtual:vino/manifest\";\nimport { isDev as assetsIsDev, clientScriptSrc } from \"virtual:vino/assets\";\nimport { NAV_HEADER, SHELL_HEADER } from \"./constants.ts\";\nimport { loadMergedConfig, loadMergedData } from \"./config.ts\";\nimport { resolvePageRender } from \"./definePage.ts\";\nimport { isHonoApp, renderPageHtml } from \"./render.ts\";\nimport type { CreateVinoOptions, ManifestPage, PageModule, RenderMode } from \"./types.ts\";\n\ntype AppContext = Context;\n\nfunction requestParams(c: AppContext): Record<string, string> {\n try {\n return c.req.param();\n } catch {\n return {};\n }\n}\n\nfunction pageFromModule(pageMod: PageModule, data: unknown, params: Record<string, string>) {\n const Page = resolvePageRender(pageMod.default);\n if (Page) return jsx(Page, { data, params });\n return pageMod.default as never;\n}\n\nfunction resolveRenderMode(c: AppContext): RenderMode {\n if (c.req.header(SHELL_HEADER)) return \"shell\";\n if (c.req.header(NAV_HEADER)) return \"content\";\n return \"full\";\n}\n\nasync function handlePage(c: AppContext, page: ManifestPage): Promise<Response> {\n const pageMod = await page.loadPage();\n if (isHonoApp(pageMod.default)) {\n return pageMod.default.fetch(c.req.raw, c.env, c.executionCtx);\n }\n\n const method = c.req.method;\n const named = pageMod[method];\n const hasPage = Boolean(resolvePageRender(pageMod.default));\n const mode = resolveRenderMode(c);\n\n if (typeof named === \"function\" && (method !== \"GET\" || !hasPage)) {\n const result: unknown = await (named as (ctx: AppContext) => unknown)(c);\n if (result instanceof Response) return result;\n if (method === \"GET\" || method === \"HEAD\") {\n const config = loadMergedConfig(page, pageMod);\n const params = requestParams(c);\n const data = mode === \"shell\" ? undefined : await loadMergedData(page, c, pageMod);\n const { html } = await renderPageHtml({\n c,\n page,\n pageMod,\n pageNode: mode === \"shell\" ? null : (result as never),\n data,\n params,\n config,\n isDev: assetsIsDev,\n clientScriptSrc,\n mode,\n });\n return c.html(html);\n }\n return c.json(result as never);\n }\n\n if (method !== \"GET\" && method !== \"HEAD\") {\n return c.text(\"Method Not Allowed\", 405);\n }\n\n const config = loadMergedConfig(page, pageMod);\n const params = requestParams(c);\n const data = mode === \"shell\" ? undefined : await loadMergedData(page, c, pageMod);\n const pageNode = mode === \"shell\" ? null : pageFromModule(pageMod, data, params);\n const { html } = await renderPageHtml({\n c,\n page,\n pageMod,\n pageNode: pageNode,\n data,\n params,\n config,\n isDev: assetsIsDev,\n clientScriptSrc,\n mode,\n });\n return c.html(html);\n}\n\n/**\n * Mount filesystem pages from the Vite-generated manifest onto a user-owned Hono app.\n * Extra API routes should be registered on `app` before calling this.\n */\nexport function mountVino<E extends Env, S extends Schema, BasePath extends string>(app: Hono<E, S, BasePath>, options: CreateVinoOptions = {}): Hono<E, S, BasePath> {\n const manifest = options.manifest ?? virtualManifest;\n for (const page of manifest.pages) {\n app.get(page.pattern, (c) => handlePage(c as AppContext, page));\n }\n\n return app;\n}\n\n/**\n * Create a new Vino app. Returns a Hono app with the Vino pages mounted.\n * @param options - The options for the Vino app.\n * @returns A Hono app with the Vino pages mounted.\n */\nexport function createVino<E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = \"/\">(options: CreateVinoOptions = {}): Hono<E, S, BasePath> {\n const app = new Hono<E, S, BasePath>();\n return mountVino(app, options);\n}\n"],"mappings":";;;;;;;;;;;;AAQA,SAAS,cAAc,OAA6B;CAClD,OAAOA,OAAI,QAAQ,EACjB,UAAU,CACRA,OAAI,QAAQ,EACV,UAAU,CACRA,OAAI,QAAQ,EAAE,SAAS,QAAQ,CAAC,GAChCA,OAAI,QAAQ;EAAE,MAAM;EAAY,SAAS;CAAsC,CAAC,CAClF,EACF,CAAC,GACDA,OAAI,QAAQ,EAAE,UAAU,MAAM,SAAS,CAAC,CAC1C,EACF,CAAC;AACH;AAEA,SAAgB,UAAU,OAA+B;CACvD,OAAO,iBAAiB;AAC1B;AAEA,SAAS,cAAc,SAA8B;CACnD,MAAM,OAAO,KAAK,UAAU,OAAO,CAAC,CAAC,WAAW,KAAK,SAAS;CAC9D,OAAO,eAAe,kBAAkB,4BAA4B,KAAK;AAC3E;AAEA,SAAgB,eACd,MACA,SACA,OACA,WACQ;CACR,MAAM,OAAO,QAAQ,yDAAwD;CAC7E,MAAM,SAAS,8BAA8B,UAAU;CACvD,MAAM,SAAS,GAAG,OAAO,cAAc,OAAO,IAAI;CAClD,IAAI,KAAK,SAAS,SAAS,GAAG,OAAO,KAAK,QAAQ,WAAW,GAAG,OAAO,QAAQ;CAC/E,IAAI,KAAK,SAAS,SAAS,GAAG,OAAO,KAAK,QAAQ,WAAW,GAAG,OAAO,QAAQ;CAC/E,OAAO,kBAAkB,OAAO;AAClC;AAEA,eAAe,kBAAkB,GAA2B;CAC1D,MAAM,YAAY,KAAA,GAAW,EAAE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