@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,79 @@
|
|
|
1
|
+
import { u as useRoute } from "./router-B50LekA_.mjs";
|
|
2
|
+
import { signal } from "@fierst/blokd";
|
|
3
|
+
// src/search-params.ts
|
|
4
|
+
const activeParamListeners = /* @__PURE__ */ new Set();
|
|
5
|
+
let popstateInstalled = false;
|
|
6
|
+
/** @internal Notify active `searchParam` signals when `navigate()` updates the URL. */
|
|
7
|
+
function _notifySearchParamsChanged() {
|
|
8
|
+
for (const listener of activeParamListeners) listener();
|
|
9
|
+
}
|
|
10
|
+
function coerceValue(raw, defaultValue, parse) {
|
|
11
|
+
if (raw === null) return defaultValue;
|
|
12
|
+
if (parse) return parse(raw);
|
|
13
|
+
if (typeof defaultValue === "number") {
|
|
14
|
+
const n = Number(raw);
|
|
15
|
+
return Number.isFinite(n) ? n : defaultValue;
|
|
16
|
+
}
|
|
17
|
+
if (typeof defaultValue === "boolean") return raw === "true" || raw === "1";
|
|
18
|
+
return raw;
|
|
19
|
+
}
|
|
20
|
+
function defaultSerialize(value) {
|
|
21
|
+
return String(value);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a reactive `Signal<T>` synchronized with a URL query parameter (`?key=...`).
|
|
25
|
+
*
|
|
26
|
+
* Works directly with Blokd two-way bindings (`<input bind:value={q} />`, `<input type="checkbox" bind:checked={done} />`)!
|
|
27
|
+
* - **During SSR:** Reads initial value from the request URL search params.
|
|
28
|
+
* - **On Client:** Updates reactive DOM slots immediately and syncs `window.location.search`
|
|
29
|
+
* cleanly (removing the parameter when equal to `defaultValue`).
|
|
30
|
+
*/
|
|
31
|
+
function searchParam(key, defaultValue, options = {}) {
|
|
32
|
+
const route = useRoute();
|
|
33
|
+
const getRawParam = () => {
|
|
34
|
+
if (typeof window !== "undefined" && window.location.protocol !== "about:") return new URLSearchParams(window.location.search).get(key);
|
|
35
|
+
return route.search.get(key);
|
|
36
|
+
};
|
|
37
|
+
const inner = signal(coerceValue(getRawParam(), defaultValue, options.parse));
|
|
38
|
+
if (typeof window !== "undefined") {
|
|
39
|
+
if (!popstateInstalled) {
|
|
40
|
+
popstateInstalled = true;
|
|
41
|
+
window.addEventListener("popstate", () => _notifySearchParamsChanged());
|
|
42
|
+
}
|
|
43
|
+
const syncFromUrl = () => {
|
|
44
|
+
const next = coerceValue(getRawParam(), defaultValue, options.parse);
|
|
45
|
+
inner.set(next);
|
|
46
|
+
};
|
|
47
|
+
activeParamListeners.add(syncFromUrl);
|
|
48
|
+
}
|
|
49
|
+
function writeUrl(next) {
|
|
50
|
+
if (typeof window === "undefined" || window.location.protocol === "about:") return;
|
|
51
|
+
try {
|
|
52
|
+
const url = new URL(window.location.href);
|
|
53
|
+
if (Object.is(next, defaultValue) || next === "") url.searchParams.delete(key);
|
|
54
|
+
else {
|
|
55
|
+
const serialized = (options.serialize ?? defaultSerialize)(next);
|
|
56
|
+
url.searchParams.set(key, serialized);
|
|
57
|
+
}
|
|
58
|
+
const nextHref = url.pathname + url.search + url.hash;
|
|
59
|
+
if (nextHref !== window.location.pathname + window.location.search + window.location.hash) {
|
|
60
|
+
if (options.history === "push") window.history.pushState(null, "", nextHref);
|
|
61
|
+
else window.history.replaceState(null, "", nextHref);
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
}
|
|
65
|
+
function read() {
|
|
66
|
+
return inner();
|
|
67
|
+
}
|
|
68
|
+
read.peek = () => inner.peek();
|
|
69
|
+
read.set = (next) => {
|
|
70
|
+
inner.set(next);
|
|
71
|
+
writeUrl(next);
|
|
72
|
+
};
|
|
73
|
+
read.update = (fn) => {
|
|
74
|
+
const next = fn(inner.peek());
|
|
75
|
+
read.set(next);
|
|
76
|
+
};
|
|
77
|
+
return read;
|
|
78
|
+
}
|
|
79
|
+
export { searchParam as n, _notifySearchParamsChanged as t };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { o as StandardSchemaV1 } from "./protocol-B6QOAMGj.mjs";
|
|
2
|
+
import { m as RouteModuleEntry, n as BuildRoutesOptions, o as CompiledRoute, s as CsrMode } from "./router-19ZZ3woS.mjs";
|
|
3
|
+
import { ComponentFn } from "@fierst/blokd";
|
|
4
|
+
import { Context, Hono, MiddlewareHandler } from "hono";
|
|
5
|
+
import { DocumentOptions, RevivalManifest } from "@fierst/blokd/ssr";
|
|
6
|
+
import { CookieOptions } from "hono/utils/cookie";
|
|
7
|
+
interface DefineDbOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Instance caching strategy:
|
|
10
|
+
* - `'auto'` (default): caches per unique request `env` object (`WeakMap`) when request bindings exist
|
|
11
|
+
* (e.g. Cloudflare Workers `env.DB` D1 or `env.HYPERDRIVE`), and reuses a module singleton when running
|
|
12
|
+
* against `process.env` (Node.js, Bun, Vercel).
|
|
13
|
+
* - `'singleton'`: always reuse a single client instance across the process.
|
|
14
|
+
* - `'request'`: create/memoize at most one client instance per active HTTP/SSR request.
|
|
15
|
+
*/
|
|
16
|
+
scope?: "auto" | "singleton" | "request";
|
|
17
|
+
}
|
|
18
|
+
type DbInstance<TDb extends object> = TDb & {
|
|
19
|
+
/** Underlying initialized database client (useful for `instanceof` checks or raw driver APIs). */
|
|
20
|
+
readonly $client: TDb;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Create a lazy, request-aware database proxy that works identically across Node.js/Bun connection pools
|
|
24
|
+
* (`process.env.DATABASE_URL`) and Cloudflare Workers per-request bindings (`req.env.DB` D1 / Hyperdrive).
|
|
25
|
+
*
|
|
26
|
+
* Works with Drizzle, Kysely, `node:sqlite`, `Bun.sql`, LibSQL/Turso, Neon, or any database client.
|
|
27
|
+
*/
|
|
28
|
+
export declare function defineDb<TDb extends object>(factory: (env: Record<string, any>) => TDb, options?: DefineDbOptions): DbInstance<TDb>;
|
|
29
|
+
interface SessionConfig {
|
|
30
|
+
/** Cookie name (default: `'c7t_session'`) */
|
|
31
|
+
name?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Signing secret (at least 16 chars recommended) or `[currentSecret, ...olderSecrets]`
|
|
34
|
+
* for zero-downtime secret rotation.
|
|
35
|
+
*/
|
|
36
|
+
secret: string | readonly string[];
|
|
37
|
+
/** Session lifetime in seconds (default: 7 days = 604800) */
|
|
38
|
+
maxAge?: number;
|
|
39
|
+
/** Cookie path (default: `'/'`) */
|
|
40
|
+
path?: string;
|
|
41
|
+
/** HTTP-only flag (default: `true`) */
|
|
42
|
+
httpOnly?: boolean;
|
|
43
|
+
/** SameSite policy (default: `'Lax'`) */
|
|
44
|
+
sameSite?: "Lax" | "Strict" | "None";
|
|
45
|
+
/** Secure flag (defaults to `true` on `https://` requests, `false` on `http://localhost`) */
|
|
46
|
+
secure?: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface SessionManager<TData extends Record<string, any>> {
|
|
49
|
+
/** Read and cryptographically verify the current request's session cookie (`null` if absent or tampered). */
|
|
50
|
+
get(): Promise<TData | null>;
|
|
51
|
+
/** Sign `data` with HMAC-SHA256 and attach `Set-Cookie` to the active response. */
|
|
52
|
+
set(data: TData): Promise<void>;
|
|
53
|
+
/** Clear the session cookie on the active response. */
|
|
54
|
+
clear(): void;
|
|
55
|
+
/** Low-level token signer (useful in tests or custom bearer tokens). */
|
|
56
|
+
sign(data: TData): Promise<string>;
|
|
57
|
+
/** Low-level token verifier (returns `null` if tampered or expired). */
|
|
58
|
+
verify(token: string): Promise<TData | null>;
|
|
59
|
+
}
|
|
60
|
+
export interface RequestContext {
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
}
|
|
63
|
+
export interface C7tRequest extends RequestContext {
|
|
64
|
+
/** Underlying Hono Context (`c`) */
|
|
65
|
+
readonly c: Context;
|
|
66
|
+
/** Web-Standard Request (`c.req.raw`) */
|
|
67
|
+
readonly raw: Request;
|
|
68
|
+
/** Request URL string */
|
|
69
|
+
readonly url: string;
|
|
70
|
+
/** HTTP method */
|
|
71
|
+
readonly method: string;
|
|
72
|
+
/** Request Headers */
|
|
73
|
+
readonly headers: Headers;
|
|
74
|
+
/** Platform bindings (e.g. Cloudflare Workers `c.env`) */
|
|
75
|
+
readonly env: Record<string, unknown>;
|
|
76
|
+
/** AbortSignal tied to client disconnect / stream cancellation */
|
|
77
|
+
readonly signal: AbortSignal;
|
|
78
|
+
}
|
|
79
|
+
export declare function runWithRequestContext<R>(c: Context, fn: () => R, signal?: AbortSignal, onHeadUpdate?: () => void): R;
|
|
80
|
+
/**
|
|
81
|
+
* Ambient typed request proxy backed by `AsyncLocalStorage`.
|
|
82
|
+
* Exposes `req.url`, `req.headers`, `req.method`, `req.env`, `req.c`, and any
|
|
83
|
+
* middleware variables set via `c.set('user', ...)` directly as `req.user`!
|
|
84
|
+
*/
|
|
85
|
+
export declare const req: C7tRequest;
|
|
86
|
+
export declare const cookies: {
|
|
87
|
+
get(name: string): string | undefined;
|
|
88
|
+
set(name: string, value: string, options?: CookieOptions): void;
|
|
89
|
+
delete(name: string, options?: CookieOptions): void;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Create a Web-Crypto (`HMAC-SHA256`) signed cookie session manager backed automatically
|
|
93
|
+
* by `c7t`'s request-scoped `cookies` store. Supports zero-downtime key rotation via `secret: [current, old]`.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createSession<TData extends Record<string, any> = Record<string, any>>(config: SessionConfig): SessionManager<TData>;
|
|
96
|
+
export interface RegisteredRpcEntry {
|
|
97
|
+
readonly id: string;
|
|
98
|
+
readonly isStream: boolean;
|
|
99
|
+
readonly schema?: StandardSchemaV1;
|
|
100
|
+
readonly handler: (...args: any[]) => any;
|
|
101
|
+
}
|
|
102
|
+
export declare function getRegisteredRpc(id: string): RegisteredRpcEntry | undefined;
|
|
103
|
+
export declare function clearRegisteredRpcs(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Register a server function or `async function*` stream under a canonical ID
|
|
106
|
+
* (invoked automatically by `@fierst/c7t/vite` on server builds, or manually in tests).
|
|
107
|
+
*/
|
|
108
|
+
export declare function registerServerFn(id: string, schemaOrFn: StandardSchemaV1 | ((...args: any[]) => any), maybeFn?: (...args: any[]) => any): (...args: any[]) => any;
|
|
109
|
+
export interface CreateServerOptions {
|
|
110
|
+
/** Route module entries (`src/routes/**`) or precompiled routes */
|
|
111
|
+
routes?: readonly RouteModuleEntry[] | readonly CompiledRoute[];
|
|
112
|
+
/** Global middleware executed on BOTH SSR page requests and `/_c7t/rpc/:id` calls */
|
|
113
|
+
middleware?: MiddlewareHandler | readonly MiddlewareHandler[];
|
|
114
|
+
/** Direct escape hatch to register custom Hono webhooks, REST routes, or WebSockets */
|
|
115
|
+
configure?: (app: Hono<any>) => void;
|
|
116
|
+
/** Custom 404 component when no route matches (auto-populated from `src/routes/404.tsx` if present) */
|
|
117
|
+
notFoundComponent?: ComponentFn<{
|
|
118
|
+
pathname: string;
|
|
119
|
+
}>;
|
|
120
|
+
/** Root error boundary fallback component (auto-populated from `src/routes/error.tsx` if present) */
|
|
121
|
+
errorComponent?: ComponentFn<{
|
|
122
|
+
error: unknown;
|
|
123
|
+
reset: () => void;
|
|
124
|
+
}>;
|
|
125
|
+
/** Stylesheet URLs injected as `<link rel="stylesheet">` in `<head>` for zero-FOUC SSR/SSG */
|
|
126
|
+
styles?: readonly string[];
|
|
127
|
+
/** Default `prerender` flag inherited by routes that don't specify `prerender` (default: `false`) */
|
|
128
|
+
prerender?: boolean;
|
|
129
|
+
/** Default `csr` mode inherited by routes that don't specify `csr` (default: `'auto'`) */
|
|
130
|
+
csr?: CsrMode;
|
|
131
|
+
/** Base RPC endpoint prefix (default: '/_c7t/rpc') */
|
|
132
|
+
rpcBase?: string;
|
|
133
|
+
/** Render mode: `'stream'` (default, fast TTFB) or `'string'` (buffered) */
|
|
134
|
+
ssrMode?: "stream" | "string";
|
|
135
|
+
/** Document shell options (title, head, manifest, importmap, CSP nonce, clientBootstrap) */
|
|
136
|
+
document?: Omit<DocumentOptions, "receipts"> & {
|
|
137
|
+
/** Client entry script URL to load `installC7t` (optional override) */
|
|
138
|
+
clientEntryUrl?: string;
|
|
139
|
+
};
|
|
140
|
+
/** Production asset manifest */
|
|
141
|
+
manifest?: RevivalManifest;
|
|
142
|
+
}
|
|
143
|
+
/** @internal Auto-populated by `@fierst/c7t/vite` from `virtual:c7t/routes` when `routes` is omitted in `createServer()`. */
|
|
144
|
+
export declare function _setDefaultRoutes(routes: readonly RouteModuleEntry[] | readonly CompiledRoute[] | null, clientRevivalUrl?: string | null, prodManifest?: RevivalManifest | null, prodStyles?: readonly string[] | null, routeDefaults?: BuildRoutesOptions | null, islandsRevivalUrl?: string | null): void;
|
|
145
|
+
export declare function createServer(options?: CreateServerOptions): Hono<any>;
|
|
146
|
+
export type { DbInstance, DefineDbOptions, SessionConfig, SessionManager };
|