@fierst/c7t 0.0.0-stage → 1.0.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/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/README.md +62 -2
- package/bin/c7t.d.mts +1 -0
- package/bin/c7t.mjs +107 -0
- package/bin/create.d.mts +9 -0
- package/bin/create.mjs +344 -0
- package/dist/adapters/bun.d.mts +40 -0
- package/dist/adapters/bun.mjs +114 -0
- package/dist/adapters/cloudflare.d.mts +29 -0
- package/dist/adapters/cloudflare.mjs +28 -0
- package/dist/adapters/node.d.mts +31 -0
- package/dist/adapters/node.mjs +139 -0
- package/dist/adapters/static.d.mts +34 -0
- package/dist/adapters/static.mjs +53 -0
- package/dist/adapters/vercel.d.mts +40 -0
- package/dist/adapters/vercel.mjs +79 -0
- package/dist/client.d.mts +78 -0
- package/dist/client.mjs +181 -0
- package/dist/head-CUiNFY7Q.mjs +142 -0
- package/dist/index.d.mts +77 -0
- package/dist/index.mjs +25 -0
- package/dist/multipart-CwqTb3AQ.mjs +72 -0
- package/dist/protocol-B6QOAMGj.d.mts +115 -0
- package/dist/protocol-CZANZJ5x.mjs +126 -0
- package/dist/router-19ZZ3woS.d.mts +148 -0
- package/dist/router-B50LekA_.mjs +680 -0
- package/dist/router.d.mts +2 -0
- package/dist/router.mjs +1 -0
- package/dist/search-params-C03mU47i.mjs +79 -0
- package/dist/server.d.mts +146 -0
- package/dist/server.mjs +850 -0
- package/dist/ssg-DFBgqaob.d.mts +40 -0
- package/dist/ssg.d.mts +2 -0
- package/dist/ssg.mjs +179 -0
- package/dist/vite.d.mts +95 -0
- package/dist/vite.mjs +920 -0
- package/docs/README.md +26 -0
- package/docs/guides/01-getting-started.md +164 -0
- package/docs/guides/02-data-fetching-and-mutations.md +258 -0
- package/docs/guides/03-streaming-and-workflows.md +198 -0
- package/docs/guides/04-routing-layouts-and-state.md +236 -0
- package/docs/guides/05-auth-sessions-and-security.md +179 -0
- package/docs/guides/06-ssg-and-deployment.md +247 -0
- package/docs/guides/07-databases-and-drizzle.md +200 -0
- package/docs/reference.md +112 -0
- package/llms.txt +1627 -0
- package/package.json +121 -4
- package/template/gitignore +11 -0
- package/template/package.json +22 -0
- package/template/src/routes/404.tsx +16 -0
- package/template/src/routes/about.tsx +22 -0
- package/template/src/routes/index.tsx +41 -0
- package/template/src/routes/layout.tsx +14 -0
- package/template/src/styles.css +39 -0
- package/template/tsconfig.json +18 -0
- package/template/vite.config.ts +16 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { extname, join, normalize, resolve } from "node:path";
|
|
2
|
+
import { existsSync, statSync } from "node:fs";
|
|
3
|
+
// src/adapters/bun.ts
|
|
4
|
+
const MIME_TYPES = {
|
|
5
|
+
".html": "text/html; charset=utf-8",
|
|
6
|
+
".js": "text/javascript; charset=utf-8",
|
|
7
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
8
|
+
".css": "text/css; charset=utf-8",
|
|
9
|
+
".json": "application/json; charset=utf-8",
|
|
10
|
+
".xml": "application/xml; charset=utf-8",
|
|
11
|
+
".txt": "text/plain; charset=utf-8",
|
|
12
|
+
".svg": "image/svg+xml",
|
|
13
|
+
".png": "image/png",
|
|
14
|
+
".jpg": "image/jpeg",
|
|
15
|
+
".jpeg": "image/jpeg",
|
|
16
|
+
".webp": "image/webp",
|
|
17
|
+
".gif": "image/gif",
|
|
18
|
+
".ico": "image/x-icon",
|
|
19
|
+
".woff": "font/woff",
|
|
20
|
+
".woff2": "font/woff2",
|
|
21
|
+
".wasm": "application/wasm"
|
|
22
|
+
};
|
|
23
|
+
function resolveStaticFile(absClientRoot, pathname) {
|
|
24
|
+
let decoded;
|
|
25
|
+
try {
|
|
26
|
+
decoded = decodeURIComponent(pathname);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const safeRel = normalize(decoded).replace(/^(\.\.(\/|\\|$))+/, "").replace(/^[/\\]+/, "");
|
|
31
|
+
const candidate = resolve(absClientRoot, safeRel);
|
|
32
|
+
if (!candidate.startsWith(absClientRoot)) return null;
|
|
33
|
+
if (existsSync(candidate)) {
|
|
34
|
+
const st = statSync(candidate);
|
|
35
|
+
if (st.isFile()) return candidate;
|
|
36
|
+
if (st.isDirectory()) {
|
|
37
|
+
const idx = join(candidate, "index.html");
|
|
38
|
+
if (existsSync(idx) && statSync(idx).isFile()) return idx;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const htmlFallback = `${candidate}.html`;
|
|
42
|
+
if (existsSync(htmlFallback) && statSync(htmlFallback).isFile()) return htmlFallback;
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Declarative adapter preset for `c7t({ adapter: bunAdapter() })` in `vite.config.ts`.
|
|
47
|
+
*/
|
|
48
|
+
function bunAdapter(options = {}) {
|
|
49
|
+
return {
|
|
50
|
+
name: "bun",
|
|
51
|
+
options
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a Web-Standard `fetch` handler for `Bun.serve()` that serves static `dist/client` assets
|
|
56
|
+
* and prerendered SSG pages via `Bun.file()` (falling back to standard `fs.readFile` in non-Bun tests)
|
|
57
|
+
* before delegating dynamic SSR & NDJSON streaming RPCs to `app.fetch(request)`.
|
|
58
|
+
*/
|
|
59
|
+
function createBunFetchHandler(app, options = {}) {
|
|
60
|
+
const absClientDir = resolve(process.cwd(), options.clientDir ?? "dist/client");
|
|
61
|
+
const hasClientDir = existsSync(absClientDir);
|
|
62
|
+
const bunRuntime = globalThis.Bun;
|
|
63
|
+
return async (req) => {
|
|
64
|
+
const method = req.method || "GET";
|
|
65
|
+
if (hasClientDir && (method === "GET" || method === "HEAD")) {
|
|
66
|
+
const url = new URL(req.url);
|
|
67
|
+
if (!url.pathname.startsWith("/_c7t/")) {
|
|
68
|
+
const staticFile = resolveStaticFile(absClientDir, url.pathname);
|
|
69
|
+
if (staticFile) {
|
|
70
|
+
const ext = extname(staticFile).toLowerCase();
|
|
71
|
+
const headers = {
|
|
72
|
+
"Content-Type": MIME_TYPES[ext] ?? "application/octet-stream",
|
|
73
|
+
"Cache-Control": url.pathname.startsWith("/assets/") ? "public, max-age=31536000, immutable" : "public, max-age=0, must-revalidate"
|
|
74
|
+
};
|
|
75
|
+
if (method === "HEAD") return new Response(null, {
|
|
76
|
+
status: 200,
|
|
77
|
+
headers
|
|
78
|
+
});
|
|
79
|
+
if (bunRuntime?.file) return new Response(bunRuntime.file(staticFile), {
|
|
80
|
+
status: 200,
|
|
81
|
+
headers
|
|
82
|
+
});
|
|
83
|
+
const { readFile } = await import("node:fs/promises");
|
|
84
|
+
const bytes = await readFile(staticFile);
|
|
85
|
+
return new Response(bytes, {
|
|
86
|
+
status: 200,
|
|
87
|
+
headers
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return app.fetch(req);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Start a native `Bun.serve()` HTTP server for a `c7t` Hono application.
|
|
97
|
+
*/
|
|
98
|
+
function serveBun(app, options = {}) {
|
|
99
|
+
const bunRuntime = globalThis.Bun;
|
|
100
|
+
if (!bunRuntime?.serve) throw new Error(`[c7t Bun] \`serveBun()\` requires the Bun runtime (\`bun dist/server/start.bun.mjs\`).`);
|
|
101
|
+
const port = options.port ?? (Number(process.env.PORT) || 3e3);
|
|
102
|
+
const hostname = options.hostname ?? "0.0.0.0";
|
|
103
|
+
const server = bunRuntime.serve({
|
|
104
|
+
port,
|
|
105
|
+
hostname,
|
|
106
|
+
fetch: createBunFetchHandler(app, options)
|
|
107
|
+
});
|
|
108
|
+
options.onListen?.({
|
|
109
|
+
port: server.port,
|
|
110
|
+
hostname: server.hostname
|
|
111
|
+
});
|
|
112
|
+
return server;
|
|
113
|
+
}
|
|
114
|
+
export { bunAdapter, createBunFetchHandler, serveBun as default, serveBun };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface CloudflareExecutionContext {
|
|
2
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
3
|
+
passThroughOnException(): void;
|
|
4
|
+
}
|
|
5
|
+
export interface CloudflareAssetsBinding {
|
|
6
|
+
fetch(request: Request | URL | string): Promise<Response>;
|
|
7
|
+
}
|
|
8
|
+
export interface CloudflareAdapterOptions {
|
|
9
|
+
/** Name of the Workers Static Assets binding on `env` (default: `'ASSETS'`) */
|
|
10
|
+
assetsBinding?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Declarative adapter preset for `c7t({ adapter: cloudflarePreset() })` (or `adapter: 'cloudflare'`) in `vite.config.ts`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function cloudflarePreset(options?: CloudflareAdapterOptions): {
|
|
16
|
+
name: "cloudflare";
|
|
17
|
+
options: CloudflareAdapterOptions;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Wrap a `c7t` Hono application into a standard Cloudflare Workers module handler (`export default cloudflareAdapter(app)`).
|
|
21
|
+
* Automatically serves prerendered SSG pages, `__c7t.json` receipt sidecars, and hashed bundles via `env.ASSETS`
|
|
22
|
+
* when available before falling through to dynamic edge SSR and `/_c7t/rpc/*` streaming!
|
|
23
|
+
*/
|
|
24
|
+
export declare function cloudflareAdapter<TEnv extends Record<string, any> = Record<string, any>>(app: {
|
|
25
|
+
fetch(request: Request, env?: TEnv, executionCtx?: CloudflareExecutionContext): Response | Promise<Response>;
|
|
26
|
+
}, options?: CloudflareAdapterOptions): {
|
|
27
|
+
fetch(request: Request, env: TEnv, ctx: CloudflareExecutionContext): Promise<Response>;
|
|
28
|
+
};
|
|
29
|
+
export { cloudflareAdapter as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/adapters/cloudflare.ts
|
|
2
|
+
/**
|
|
3
|
+
* Declarative adapter preset for `c7t({ adapter: cloudflarePreset() })` (or `adapter: 'cloudflare'`) in `vite.config.ts`.
|
|
4
|
+
*/
|
|
5
|
+
function cloudflarePreset(options = {}) {
|
|
6
|
+
return {
|
|
7
|
+
name: "cloudflare",
|
|
8
|
+
options
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Wrap a `c7t` Hono application into a standard Cloudflare Workers module handler (`export default cloudflareAdapter(app)`).
|
|
13
|
+
* Automatically serves prerendered SSG pages, `__c7t.json` receipt sidecars, and hashed bundles via `env.ASSETS`
|
|
14
|
+
* when available before falling through to dynamic edge SSR and `/_c7t/rpc/*` streaming!
|
|
15
|
+
*/
|
|
16
|
+
function cloudflareAdapter(app, options = {}) {
|
|
17
|
+
const assetsKey = options.assetsBinding ?? "ASSETS";
|
|
18
|
+
return { async fetch(request, env, ctx) {
|
|
19
|
+
const url = new URL(request.url);
|
|
20
|
+
const assets = env?.[assetsKey];
|
|
21
|
+
if (assets && typeof assets.fetch === "function" && (request.method === "GET" || request.method === "HEAD") && !url.pathname.startsWith("/_c7t/")) {
|
|
22
|
+
const assetRes = await assets.fetch(request);
|
|
23
|
+
if (assetRes.status !== 404) return assetRes;
|
|
24
|
+
}
|
|
25
|
+
return app.fetch(request, env, ctx);
|
|
26
|
+
} };
|
|
27
|
+
}
|
|
28
|
+
export { cloudflareAdapter, cloudflareAdapter as default, cloudflarePreset };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Server } from "node:http";
|
|
2
|
+
export interface NodeAdapterOptions {
|
|
3
|
+
/** Port to listen on (default: `Number(process.env.PORT) || 3000`) */
|
|
4
|
+
port?: number;
|
|
5
|
+
/** Hostname to bind (default: `'0.0.0.0'`) */
|
|
6
|
+
hostname?: string;
|
|
7
|
+
/** Directory containing built static client assets & prerendered SSG files (default: `'dist/client'`) */
|
|
8
|
+
clientDir?: string;
|
|
9
|
+
/** Callback fired once the server starts listening */
|
|
10
|
+
onListen?: (info: {
|
|
11
|
+
port: number;
|
|
12
|
+
hostname: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Declarative adapter preset for `c7t({ adapter: nodeAdapter() })` in `vite.config.ts`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function nodeAdapter(options?: NodeAdapterOptions): {
|
|
19
|
+
name: "node";
|
|
20
|
+
options: NodeAdapterOptions;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Create a production Node.js `http.Server` serving static `dist/client` assets (including prerendered
|
|
24
|
+
* SSG `.html` & `__c7t.json` sidecars with optimal `Cache-Control`) and streaming Hono SSR / NDJSON RPCs.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createNodeHandler(app: {
|
|
27
|
+
fetch(req: Request): Response | Promise<Response>;
|
|
28
|
+
}, options?: Pick<NodeAdapterOptions, "clientDir">): (nodeReq: any, nodeRes: any) => Promise<void>;
|
|
29
|
+
export declare function serveNode(app: {
|
|
30
|
+
fetch(req: Request): Response | Promise<Response>;
|
|
31
|
+
}, options?: NodeAdapterOptions): Server;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { extname, join, normalize, resolve } from "node:path";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
4
|
+
// src/adapters/node.ts
|
|
5
|
+
const MIME_TYPES = {
|
|
6
|
+
".html": "text/html; charset=utf-8",
|
|
7
|
+
".js": "text/javascript; charset=utf-8",
|
|
8
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
9
|
+
".css": "text/css; charset=utf-8",
|
|
10
|
+
".json": "application/json; charset=utf-8",
|
|
11
|
+
".xml": "application/xml; charset=utf-8",
|
|
12
|
+
".txt": "text/plain; charset=utf-8",
|
|
13
|
+
".svg": "image/svg+xml",
|
|
14
|
+
".png": "image/png",
|
|
15
|
+
".jpg": "image/jpeg",
|
|
16
|
+
".jpeg": "image/jpeg",
|
|
17
|
+
".webp": "image/webp",
|
|
18
|
+
".gif": "image/gif",
|
|
19
|
+
".ico": "image/x-icon",
|
|
20
|
+
".woff": "font/woff",
|
|
21
|
+
".woff2": "font/woff2",
|
|
22
|
+
".wasm": "application/wasm"
|
|
23
|
+
};
|
|
24
|
+
function resolveStaticFile(absClientRoot, pathname) {
|
|
25
|
+
let decoded;
|
|
26
|
+
try {
|
|
27
|
+
decoded = decodeURIComponent(pathname);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const safeRel = normalize(decoded).replace(/^(\.\.(\/|\\|$))+/, "").replace(/^[/\\]+/, "");
|
|
32
|
+
const candidate = resolve(absClientRoot, safeRel);
|
|
33
|
+
if (!candidate.startsWith(absClientRoot)) return null;
|
|
34
|
+
if (existsSync(candidate)) {
|
|
35
|
+
const st = statSync(candidate);
|
|
36
|
+
if (st.isFile()) return candidate;
|
|
37
|
+
if (st.isDirectory()) {
|
|
38
|
+
const idx = join(candidate, "index.html");
|
|
39
|
+
if (existsSync(idx) && statSync(idx).isFile()) return idx;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const htmlFallback = `${candidate}.html`;
|
|
43
|
+
if (existsSync(htmlFallback) && statSync(htmlFallback).isFile()) return htmlFallback;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Declarative adapter preset for `c7t({ adapter: nodeAdapter() })` in `vite.config.ts`.
|
|
48
|
+
*/
|
|
49
|
+
function nodeAdapter(options = {}) {
|
|
50
|
+
return {
|
|
51
|
+
name: "node",
|
|
52
|
+
options
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a production Node.js `http.Server` serving static `dist/client` assets (including prerendered
|
|
57
|
+
* SSG `.html` & `__c7t.json` sidecars with optimal `Cache-Control`) and streaming Hono SSR / NDJSON RPCs.
|
|
58
|
+
*/
|
|
59
|
+
function createNodeHandler(app, options = {}) {
|
|
60
|
+
const absClientDir = resolve(process.cwd(), options.clientDir ?? "dist/client");
|
|
61
|
+
const hasClientDir = existsSync(absClientDir);
|
|
62
|
+
return async (nodeReq, nodeRes) => {
|
|
63
|
+
const method = nodeReq.method || "GET";
|
|
64
|
+
const rawUrl = nodeReq.url || "/";
|
|
65
|
+
const qIdx = rawUrl.indexOf("?");
|
|
66
|
+
const pathname = qIdx === -1 ? rawUrl : rawUrl.slice(0, qIdx);
|
|
67
|
+
if (hasClientDir && (method === "GET" || method === "HEAD") && !pathname.startsWith("/_c7t/")) {
|
|
68
|
+
const staticFile = resolveStaticFile(absClientDir, pathname);
|
|
69
|
+
if (staticFile) {
|
|
70
|
+
const ext = extname(staticFile).toLowerCase();
|
|
71
|
+
const mime = MIME_TYPES[ext] ?? "application/octet-stream";
|
|
72
|
+
const isImmutableAsset = pathname.startsWith("/assets/");
|
|
73
|
+
nodeRes.statusCode = 200;
|
|
74
|
+
nodeRes.setHeader("Content-Type", mime);
|
|
75
|
+
nodeRes.setHeader("Cache-Control", isImmutableAsset ? "public, max-age=31536000, immutable" : "public, max-age=0, must-revalidate");
|
|
76
|
+
if (method === "HEAD") {
|
|
77
|
+
nodeRes.end();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
createReadStream(staticFile).pipe(nodeRes);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const fullUrl = `${nodeReq.socket?.encrypted ? "https" : "http"}://${nodeReq.headers.host || "localhost"}${rawUrl}`;
|
|
85
|
+
const hasBody = method !== "GET" && method !== "HEAD";
|
|
86
|
+
const abortController = new AbortController();
|
|
87
|
+
nodeRes.on("close", () => {
|
|
88
|
+
if (!nodeRes.writableEnded) abortController.abort();
|
|
89
|
+
});
|
|
90
|
+
const headers = new Headers();
|
|
91
|
+
for (const [k, v] of Object.entries(nodeReq.headers)) if (typeof v === "string") headers.set(k, v);
|
|
92
|
+
else if (Array.isArray(v)) headers.set(k, v.join(", "));
|
|
93
|
+
const webReq = new Request(fullUrl, {
|
|
94
|
+
method,
|
|
95
|
+
headers,
|
|
96
|
+
body: hasBody ? nodeReq : void 0,
|
|
97
|
+
signal: abortController.signal,
|
|
98
|
+
...hasBody ? { duplex: "half" } : {}
|
|
99
|
+
});
|
|
100
|
+
const webRes = await app.fetch(webReq);
|
|
101
|
+
nodeRes.statusCode = webRes.status;
|
|
102
|
+
webRes.headers.forEach((v, k) => {
|
|
103
|
+
if (k.toLowerCase() === "set-cookie") return;
|
|
104
|
+
nodeRes.setHeader(k, v);
|
|
105
|
+
});
|
|
106
|
+
const setCookies = typeof webRes.headers.getSetCookie === "function" ? webRes.headers.getSetCookie() : [];
|
|
107
|
+
if (setCookies.length > 0) nodeRes.setHeader("Set-Cookie", setCookies);
|
|
108
|
+
if (!webRes.body) {
|
|
109
|
+
nodeRes.end();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const reader = webRes.body.getReader();
|
|
113
|
+
nodeRes.on("close", () => {
|
|
114
|
+
if (!nodeRes.writableEnded) reader.cancel().catch(() => {});
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
while (true) {
|
|
118
|
+
const { done, value } = await reader.read();
|
|
119
|
+
if (done) break;
|
|
120
|
+
nodeRes.write(value);
|
|
121
|
+
}
|
|
122
|
+
} finally {
|
|
123
|
+
if (!nodeRes.writableEnded) nodeRes.end();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function serveNode(app, options = {}) {
|
|
128
|
+
const port = options.port ?? (Number(process.env.PORT) || 3e3);
|
|
129
|
+
const hostname = options.hostname ?? "0.0.0.0";
|
|
130
|
+
const server = createServer(createNodeHandler(app, options));
|
|
131
|
+
server.listen(port, hostname, () => {
|
|
132
|
+
options.onListen?.({
|
|
133
|
+
port,
|
|
134
|
+
hostname
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return server;
|
|
138
|
+
}
|
|
139
|
+
export { createNodeHandler, nodeAdapter, serveNode };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { i as PrerenderResult, n as PrerenderOptions } from "../ssg-DFBgqaob.mjs";
|
|
2
|
+
export interface StaticAdapterOptions {
|
|
3
|
+
/** Output directory for static files (default: `'dist/client'`) */
|
|
4
|
+
outDir?: string;
|
|
5
|
+
/** Filename for static 404 fallback page when a custom 404 route exists, or `false` to skip (default: `'404.html'`) */
|
|
6
|
+
fallback?: string | false;
|
|
7
|
+
/** Additional seed paths to crawl/prerender (default: `['/']`) */
|
|
8
|
+
entries?: readonly string[];
|
|
9
|
+
/** Crawl internal `<a href="/...">` links in rendered HTML (default: `true`) */
|
|
10
|
+
crawl?: boolean;
|
|
11
|
+
/** Action when a crawled internal link returns HTTP 404 (default: `'error'`) */
|
|
12
|
+
onBrokenLink?: "error" | "warn" | "ignore";
|
|
13
|
+
/** Synthetic origin used for build-time Request URLs (default: `'http://prerender.local'`) */
|
|
14
|
+
origin?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface StaticBuildResult extends PrerenderResult {
|
|
17
|
+
/** Path to emitted 404 fallback file (e.g. `'404.html'`), or `null` if none was emitted */
|
|
18
|
+
readonly fallbackFile: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface C7tAdapterConfig {
|
|
21
|
+
readonly name: "node" | "cloudflare" | "vercel" | "bun" | "static";
|
|
22
|
+
readonly options?: Record<string, any>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Declarative adapter preset for `c7t({ adapter: staticAdapter() })` in `vite.config.ts`.
|
|
26
|
+
* Prerenders all routes (`mode: 'all'`), emits `__c7t.json` receipt sidecars, and writes `404.html`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function staticAdapter(options?: StaticAdapterOptions): C7tAdapterConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Build a 100% static site (`index.html` + `__c7t.json` sidecars + static `GET` endpoints + `404.html`)
|
|
31
|
+
* ready for Cloudflare Pages, GitHub Pages, Netlify, S3, or any static CDN.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildStaticSite(params: Pick<PrerenderOptions, "app" | "routes"> & StaticAdapterOptions): Promise<StaticBuildResult>;
|
|
34
|
+
export { staticAdapter as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { prerenderApp } from "../ssg.mjs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
// src/adapters/static.ts
|
|
5
|
+
/**
|
|
6
|
+
* Declarative adapter preset for `c7t({ adapter: staticAdapter() })` in `vite.config.ts`.
|
|
7
|
+
* Prerenders all routes (`mode: 'all'`), emits `__c7t.json` receipt sidecars, and writes `404.html`.
|
|
8
|
+
*/
|
|
9
|
+
function staticAdapter(options = {}) {
|
|
10
|
+
return {
|
|
11
|
+
name: "static",
|
|
12
|
+
options
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build a 100% static site (`index.html` + `__c7t.json` sidecars + static `GET` endpoints + `404.html`)
|
|
17
|
+
* ready for Cloudflare Pages, GitHub Pages, Netlify, S3, or any static CDN.
|
|
18
|
+
*/
|
|
19
|
+
async function buildStaticSite(params) {
|
|
20
|
+
const outDir = params.outDir ?? "dist/client";
|
|
21
|
+
const fallback = params.fallback ?? "404.html";
|
|
22
|
+
const origin = (params.origin ?? "http://prerender.local").replace(/\/$/, "");
|
|
23
|
+
const result = await prerenderApp({
|
|
24
|
+
app: params.app,
|
|
25
|
+
routes: params.routes,
|
|
26
|
+
outDir,
|
|
27
|
+
mode: "all",
|
|
28
|
+
crawl: params.crawl ?? true,
|
|
29
|
+
entries: params.entries ?? ["/"],
|
|
30
|
+
onBrokenLink: params.onBrokenLink ?? "error",
|
|
31
|
+
origin
|
|
32
|
+
});
|
|
33
|
+
let fallbackFile = null;
|
|
34
|
+
if (fallback) {
|
|
35
|
+
const res = await params.app.request(`${origin}/__c7t_static_404_probe__`, {
|
|
36
|
+
method: "GET",
|
|
37
|
+
headers: { "X-C7T-Prerender": "1" }
|
|
38
|
+
});
|
|
39
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
40
|
+
if (res.status === 404 && contentType.includes("text/html")) {
|
|
41
|
+
const html = await res.text();
|
|
42
|
+
const target = join(outDir, fallback.replace(/^[/\\]+/, ""));
|
|
43
|
+
await mkdir(dirname(target), { recursive: true });
|
|
44
|
+
await writeFile(target, html, "utf-8");
|
|
45
|
+
fallbackFile = fallback;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...result,
|
|
50
|
+
fallbackFile
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { buildStaticSite, staticAdapter as default, staticAdapter };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface VercelAdapterOptions {
|
|
2
|
+
/** Project root directory (default: `process.cwd()`) */
|
|
3
|
+
rootDir?: string;
|
|
4
|
+
/** Built client + SSG assets directory relative to `rootDir` (default: `'dist/client'`) */
|
|
5
|
+
clientDir?: string;
|
|
6
|
+
/** Built SSR server directory relative to `rootDir` (default: `'dist/server'`) */
|
|
7
|
+
serverDir?: string;
|
|
8
|
+
/** Server entry filename inside `serverDir` (default: `'entry.mjs'`) */
|
|
9
|
+
serverEntry?: string;
|
|
10
|
+
/** Vercel Build Output directory relative to `rootDir` (default: `'.vercel/output'`) */
|
|
11
|
+
outDir?: string;
|
|
12
|
+
/** Vercel Node.js function runtime identifier (default: `'nodejs22.x'`) */
|
|
13
|
+
runtime?: string;
|
|
14
|
+
/** Optional Vercel function deployment regions (e.g. `['iad1']`) */
|
|
15
|
+
regions?: readonly string[];
|
|
16
|
+
/** Optional maximum execution duration in seconds */
|
|
17
|
+
maxDuration?: number;
|
|
18
|
+
/** Optional function memory size in MB */
|
|
19
|
+
memory?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface VercelBuildResult {
|
|
22
|
+
readonly outDir: string;
|
|
23
|
+
readonly staticDir: string;
|
|
24
|
+
readonly functionDir: string;
|
|
25
|
+
readonly configPath: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Declarative adapter preset for `c7t({ adapter: vercelAdapter() })` in `vite.config.ts`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function vercelAdapter(options?: VercelAdapterOptions): {
|
|
31
|
+
name: "vercel";
|
|
32
|
+
options: VercelAdapterOptions;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Emit a complete Vercel Build Output API v3 directory (`.vercel/output`) serving static assets
|
|
36
|
+
* and prerendered SSG pages/sidecars from Vercel's edge CDN and routing dynamic SSR + NDJSON RPCs
|
|
37
|
+
* to a Web-Standard serverless function (`functions/index.func`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildVercelOutput(options?: VercelAdapterOptions): Promise<VercelBuildResult>;
|
|
40
|
+
export { vercelAdapter as default };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { cp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { basename, join, resolve } from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
// src/adapters/vercel.ts
|
|
5
|
+
/**
|
|
6
|
+
* Declarative adapter preset for `c7t({ adapter: vercelAdapter() })` in `vite.config.ts`.
|
|
7
|
+
*/
|
|
8
|
+
function vercelAdapter(options = {}) {
|
|
9
|
+
return {
|
|
10
|
+
name: "vercel",
|
|
11
|
+
options
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Emit a complete Vercel Build Output API v3 directory (`.vercel/output`) serving static assets
|
|
16
|
+
* and prerendered SSG pages/sidecars from Vercel's edge CDN and routing dynamic SSR + NDJSON RPCs
|
|
17
|
+
* to a Web-Standard serverless function (`functions/index.func`).
|
|
18
|
+
*/
|
|
19
|
+
async function buildVercelOutput(options = {}) {
|
|
20
|
+
const rootDir = resolve(options.rootDir ?? process.cwd());
|
|
21
|
+
const absClientDir = resolve(rootDir, options.clientDir ?? "dist/client");
|
|
22
|
+
const absServerDir = resolve(rootDir, options.serverDir ?? "dist/server");
|
|
23
|
+
const serverEntry = options.serverEntry ?? "entry.mjs";
|
|
24
|
+
const absOutDir = resolve(rootDir, options.outDir ?? ".vercel/output");
|
|
25
|
+
const staticDir = join(absOutDir, "static");
|
|
26
|
+
const functionDir = join(absOutDir, "functions", "index.func");
|
|
27
|
+
const bundledServerDir = join(functionDir, "_server");
|
|
28
|
+
const configPath = join(absOutDir, "config.json");
|
|
29
|
+
await rm(absOutDir, {
|
|
30
|
+
recursive: true,
|
|
31
|
+
force: true
|
|
32
|
+
});
|
|
33
|
+
await mkdir(staticDir, { recursive: true });
|
|
34
|
+
await mkdir(bundledServerDir, { recursive: true });
|
|
35
|
+
if (existsSync(absClientDir)) await cp(absClientDir, staticDir, {
|
|
36
|
+
recursive: true,
|
|
37
|
+
filter: (src) => {
|
|
38
|
+
const name = basename(src);
|
|
39
|
+
return name !== "c7t-manifest.json" && name !== "blokd-manifest.json";
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (!existsSync(join(absServerDir, serverEntry))) throw new Error(`[c7t Vercel] Missing compiled server entry at "${join(absServerDir, serverEntry)}". Run the SSR build first.`);
|
|
43
|
+
await cp(absServerDir, bundledServerDir, { recursive: true });
|
|
44
|
+
await writeFile(join(functionDir, "package.json"), JSON.stringify({ type: "module" }, null, 2) + "\n", "utf-8");
|
|
45
|
+
const handlerSource = `import app from "./_server/${serverEntry.replace(/\\/g, "/").replace(/^\/+/, "")}";\nexport default {\n fetch(request) {\n return app.fetch(request);\n },\n};\n`;
|
|
46
|
+
await writeFile(join(functionDir, "index.mjs"), handlerSource, "utf-8");
|
|
47
|
+
const vcConfig = {
|
|
48
|
+
runtime: options.runtime ?? "nodejs22.x",
|
|
49
|
+
handler: "index.mjs",
|
|
50
|
+
launcherType: "Nodejs",
|
|
51
|
+
shouldAddHelpers: false
|
|
52
|
+
};
|
|
53
|
+
if (options.regions && options.regions.length > 0) vcConfig.regions = [...options.regions];
|
|
54
|
+
if (options.maxDuration !== void 0) vcConfig.maxDuration = options.maxDuration;
|
|
55
|
+
if (options.memory !== void 0) vcConfig.memory = options.memory;
|
|
56
|
+
await writeFile(join(functionDir, ".vc-config.json"), JSON.stringify(vcConfig, null, 2) + "\n", "utf-8");
|
|
57
|
+
await writeFile(configPath, JSON.stringify({
|
|
58
|
+
version: 3,
|
|
59
|
+
routes: [
|
|
60
|
+
{
|
|
61
|
+
src: "^/assets/(.*)$",
|
|
62
|
+
headers: { "cache-control": "public, max-age=31536000, immutable" },
|
|
63
|
+
continue: true
|
|
64
|
+
},
|
|
65
|
+
{ handle: "filesystem" },
|
|
66
|
+
{
|
|
67
|
+
src: "/(.*)",
|
|
68
|
+
dest: "/index"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}, null, 2) + "\n", "utf-8");
|
|
72
|
+
return {
|
|
73
|
+
outDir: absOutDir,
|
|
74
|
+
staticDir,
|
|
75
|
+
functionDir,
|
|
76
|
+
configPath
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export { buildVercelOutput, vercelAdapter as default, vercelAdapter };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { a as ServerCall } from "./protocol-B6QOAMGj.mjs";
|
|
2
|
+
import { o as CompiledRoute } from "./router-19ZZ3woS.mjs";
|
|
3
|
+
import { ComponentFn } from "@fierst/blokd";
|
|
4
|
+
import "@fierst/blokd/ssr";
|
|
5
|
+
interface EncodedReceiptStore {
|
|
6
|
+
/** Shared value pool referenced by `{ "$ref": index }` pointers */
|
|
7
|
+
p: EncodedValue[];
|
|
8
|
+
/** Receipt table keyed by island receipt ID (`r0`, `r1`, ...) */
|
|
9
|
+
r: Record<string, EncodedReceiptEntry>;
|
|
10
|
+
}
|
|
11
|
+
interface EncodedReceiptEntry {
|
|
12
|
+
s: EncodedStep[];
|
|
13
|
+
y?: number;
|
|
14
|
+
}
|
|
15
|
+
type EncodedStep = {
|
|
16
|
+
i: string;
|
|
17
|
+
v: EncodedValue;
|
|
18
|
+
} | {
|
|
19
|
+
i: string;
|
|
20
|
+
e: EncodedValue;
|
|
21
|
+
};
|
|
22
|
+
type EncodedValue = null | boolean | number | string | {
|
|
23
|
+
$undef: 1;
|
|
24
|
+
} | {
|
|
25
|
+
$date: string;
|
|
26
|
+
} | {
|
|
27
|
+
$query: string;
|
|
28
|
+
} | {
|
|
29
|
+
$ref: number;
|
|
30
|
+
} | EncodedValue[] | {
|
|
31
|
+
[key: string]: EncodedValue;
|
|
32
|
+
};
|
|
33
|
+
/** Install the global 0-tick receipt resolver into `@fierst/blokd` on the client. */
|
|
34
|
+
export declare function installReceiptResolver(getStore?: () => EncodedReceiptStore | undefined): () => void;
|
|
35
|
+
export interface C7tClientConfig {
|
|
36
|
+
/** Base endpoint prefix for RPC calls (default: '/_c7t/rpc') */
|
|
37
|
+
rpcBase?: string;
|
|
38
|
+
/** Custom fetch implementation (useful in tests or custom edge environments) */
|
|
39
|
+
fetch?: typeof globalThis.fetch;
|
|
40
|
+
}
|
|
41
|
+
export declare function configureClient(config: C7tClientConfig): void;
|
|
42
|
+
/**
|
|
43
|
+
* Create a lightweight client RPC stub for a `server(...)` or `*.server.ts` function.
|
|
44
|
+
* Supports both `yield* stub(...args)` (0-tick SSR receipt revival + live fallback)
|
|
45
|
+
* and `await stub(...args)` (live HTTP POST RPC).
|
|
46
|
+
*/
|
|
47
|
+
export declare function createRpcStub<TArgs extends unknown[], TReturn>(fnId: string): (...args: TArgs) => ServerCall<TReturn>;
|
|
48
|
+
/**
|
|
49
|
+
* Create a lightweight client streaming stub for an `async function*` server workflow.
|
|
50
|
+
* Consumed via `for await (const chunk of streamStub(...args))`:
|
|
51
|
+
* - Streams `application/x-ndjson` frames over standard `fetch()`.
|
|
52
|
+
* - Automatically schedules compiled DOM slot patches on the calling component after each chunk!
|
|
53
|
+
* - Aborts the HTTP stream automatically on component unmount OR `break`/`return` out of `for await`,
|
|
54
|
+
* triggering Hono's `onAbort` -> server `gen.return()` -> backend `finally` cleanup!
|
|
55
|
+
*/
|
|
56
|
+
export declare function createStreamStub<TArgs extends unknown[], TYield, TReturn = void>(fnId: string): (...args: TArgs) => AsyncGenerator<TYield, TReturn, void>;
|
|
57
|
+
export interface InstallC7tOptions {
|
|
58
|
+
runtimeUrl?: string;
|
|
59
|
+
routes?: readonly CompiledRoute[];
|
|
60
|
+
errorComponent?: ComponentFn<{
|
|
61
|
+
error: unknown;
|
|
62
|
+
reset: () => void;
|
|
63
|
+
}>;
|
|
64
|
+
rootElement?: Element;
|
|
65
|
+
initialUrl?: string;
|
|
66
|
+
transitions?: boolean;
|
|
67
|
+
receiptStore?: () => EncodedReceiptStore | undefined;
|
|
68
|
+
rpcBase?: string;
|
|
69
|
+
fetch?: typeof globalThis.fetch;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Bootstrap c7t on the client:
|
|
73
|
+
* 1. Installs 0-tick `$ref` State Receipt decoding into `@fierst/blokd`.
|
|
74
|
+
* 2. Installs event-delegated Lazy Revival (`installRevival`).
|
|
75
|
+
* 3. Optionally installs persistent nested `<c7t-outlet>` client routing.
|
|
76
|
+
*/
|
|
77
|
+
export declare function installC7t(options?: InstallC7tOptions): () => void;
|
|
78
|
+
export type { EncodedReceiptStore };
|