@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.
Files changed (57) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +21 -0
  3. package/README.md +62 -2
  4. package/bin/c7t.d.mts +1 -0
  5. package/bin/c7t.mjs +107 -0
  6. package/bin/create.d.mts +9 -0
  7. package/bin/create.mjs +344 -0
  8. package/dist/adapters/bun.d.mts +40 -0
  9. package/dist/adapters/bun.mjs +114 -0
  10. package/dist/adapters/cloudflare.d.mts +29 -0
  11. package/dist/adapters/cloudflare.mjs +28 -0
  12. package/dist/adapters/node.d.mts +31 -0
  13. package/dist/adapters/node.mjs +139 -0
  14. package/dist/adapters/static.d.mts +34 -0
  15. package/dist/adapters/static.mjs +53 -0
  16. package/dist/adapters/vercel.d.mts +40 -0
  17. package/dist/adapters/vercel.mjs +79 -0
  18. package/dist/client.d.mts +78 -0
  19. package/dist/client.mjs +181 -0
  20. package/dist/head-CUiNFY7Q.mjs +142 -0
  21. package/dist/index.d.mts +77 -0
  22. package/dist/index.mjs +25 -0
  23. package/dist/multipart-CwqTb3AQ.mjs +72 -0
  24. package/dist/protocol-B6QOAMGj.d.mts +115 -0
  25. package/dist/protocol-CZANZJ5x.mjs +126 -0
  26. package/dist/router-19ZZ3woS.d.mts +148 -0
  27. package/dist/router-B50LekA_.mjs +680 -0
  28. package/dist/router.d.mts +2 -0
  29. package/dist/router.mjs +1 -0
  30. package/dist/search-params-C03mU47i.mjs +79 -0
  31. package/dist/server.d.mts +146 -0
  32. package/dist/server.mjs +850 -0
  33. package/dist/ssg-DFBgqaob.d.mts +40 -0
  34. package/dist/ssg.d.mts +2 -0
  35. package/dist/ssg.mjs +179 -0
  36. package/dist/vite.d.mts +95 -0
  37. package/dist/vite.mjs +920 -0
  38. package/docs/README.md +26 -0
  39. package/docs/guides/01-getting-started.md +164 -0
  40. package/docs/guides/02-data-fetching-and-mutations.md +258 -0
  41. package/docs/guides/03-streaming-and-workflows.md +198 -0
  42. package/docs/guides/04-routing-layouts-and-state.md +236 -0
  43. package/docs/guides/05-auth-sessions-and-security.md +179 -0
  44. package/docs/guides/06-ssg-and-deployment.md +247 -0
  45. package/docs/guides/07-databases-and-drizzle.md +200 -0
  46. package/docs/reference.md +112 -0
  47. package/llms.txt +1627 -0
  48. package/package.json +121 -4
  49. package/template/gitignore +11 -0
  50. package/template/package.json +22 -0
  51. package/template/src/routes/404.tsx +16 -0
  52. package/template/src/routes/about.tsx +22 -0
  53. package/template/src/routes/index.tsx +41 -0
  54. package/template/src/routes/layout.tsx +14 -0
  55. package/template/src/styles.css +39 -0
  56. package/template/tsconfig.json +18 -0
  57. package/template/vite.config.ts +16 -0
@@ -0,0 +1,126 @@
1
+ import { STEP } from "@fierst/blokd";
2
+ // src/protocol.ts
3
+ function isStandardSchema(val) {
4
+ return Boolean(val && (typeof val === "object" || typeof val === "function") && "~standard" in val && typeof val["~standard"]?.validate === "function");
5
+ }
6
+ async function validateSchema(schema, input) {
7
+ const result = await schema["~standard"].validate(input);
8
+ if (result.issues) throw new ValidationError(result.issues);
9
+ return result.value;
10
+ }
11
+ var RedirectSignal = class extends Error {
12
+ __c7tControlFlow = true;
13
+ location;
14
+ status;
15
+ constructor(location, status = 302) {
16
+ super(`Redirect to ${location}`);
17
+ this.name = "RedirectSignal";
18
+ this.location = location;
19
+ this.status = status;
20
+ }
21
+ };
22
+ function redirect(location, status = 302) {
23
+ return new RedirectSignal(location, status);
24
+ }
25
+ var HttpStatusError = class extends Error {
26
+ __c7tControlFlow;
27
+ status;
28
+ data;
29
+ constructor(status, message, data, isControlFlow = false) {
30
+ super(message ?? `HTTP ${status}`);
31
+ this.name = "HttpStatusError";
32
+ this.status = status;
33
+ this.data = data;
34
+ this.__c7tControlFlow = isControlFlow;
35
+ }
36
+ };
37
+ function httpError(status, message, data) {
38
+ return new HttpStatusError(status, message, data, false);
39
+ }
40
+ function notFound(message = "Not Found") {
41
+ return new HttpStatusError(404, message, void 0, true);
42
+ }
43
+ function unauthorized(message = "Unauthorized") {
44
+ return new HttpStatusError(401, message, void 0, false);
45
+ }
46
+ function forbidden(message = "Forbidden") {
47
+ return new HttpStatusError(403, message, void 0, false);
48
+ }
49
+ function formatIssuePath(path) {
50
+ if (!path || path.length === 0) return "_root";
51
+ return path.map((seg) => seg !== null && typeof seg === "object" && "key" in seg ? String(seg.key) : String(seg)).join(".");
52
+ }
53
+ var ValidationError = class extends Error {
54
+ status = 400;
55
+ issues;
56
+ #fields;
57
+ constructor(issues, message) {
58
+ super(message ?? issues.map((i) => i.message).join("; ") ?? "Validation failed");
59
+ this.name = "ValidationError";
60
+ this.issues = issues;
61
+ }
62
+ /**
63
+ * Flat map of field dot-paths to their first validation message
64
+ * (e.g. `{ title: "Title must be at least 2 characters" }`, or `_root` for top-level issues).
65
+ */
66
+ get fields() {
67
+ if (!this.#fields) {
68
+ const map = {};
69
+ for (const issue of this.issues) {
70
+ const key = formatIssuePath(issue.path);
71
+ if (!(key in map)) map[key] = issue.message;
72
+ }
73
+ this.#fields = map;
74
+ }
75
+ return this.#fields;
76
+ }
77
+ };
78
+ const CALL_META = Symbol.for("c7t.callMeta");
79
+ function createServerCall(id, args, execute) {
80
+ let inflight = null;
81
+ const toPromise = () => {
82
+ if (!inflight) inflight = Promise.resolve().then(() => execute());
83
+ return inflight;
84
+ };
85
+ const meta = {
86
+ id,
87
+ args,
88
+ execute
89
+ };
90
+ return {
91
+ [CALL_META]: meta,
92
+ *[Symbol.iterator]() {
93
+ return yield { [STEP]: {
94
+ id,
95
+ args,
96
+ run: (sig) => execute(sig)
97
+ } };
98
+ },
99
+ async *[Symbol.asyncIterator]() {
100
+ return yield { [STEP]: {
101
+ id,
102
+ args,
103
+ run: (sig) => execute(sig)
104
+ } };
105
+ },
106
+ then(onfulfilled, onrejected) {
107
+ return toPromise().then(onfulfilled, onrejected);
108
+ },
109
+ catch(onrejected) {
110
+ return toPromise().catch(onrejected);
111
+ },
112
+ finally(onfinally) {
113
+ return toPromise().finally(onfinally);
114
+ }
115
+ };
116
+ }
117
+ /**
118
+ * Execute multiple `ServerCall` steps concurrently (`Promise.all` on SSR / live navigation)
119
+ * while recording a single deterministic tuple receipt that revives in 0 ticks on the client.
120
+ */
121
+ function all(calls) {
122
+ return createServerCall(`$all(${calls.map((c) => c[CALL_META].id).join(",")})`, calls.map((c) => c[CALL_META].args), async (signal) => {
123
+ return await Promise.all(calls.map((c) => c[CALL_META].execute(signal)));
124
+ });
125
+ }
126
+ export { createServerCall as a, isStandardSchema as c, unauthorized as d, validateSchema as f, all as i, notFound as l, RedirectSignal as n, forbidden as o, ValidationError as r, httpError as s, HttpStatusError as t, redirect as u };
@@ -0,0 +1,148 @@
1
+ import { ComponentFn, View } from "@fierst/blokd";
2
+ type ExtractSegmentParam<Seg extends string> = Seg extends `[...${infer Rest}]` ? { [K in Rest]: string; } : Seg extends `[${infer Param}]` ? { [K in Param]: string; } : Seg extends `:${infer ColonParam}` ? { [K in ColonParam]: string; } : {};
3
+ type Simplify<T> = { [K in keyof T]: T[K]; } & {};
4
+ type ExtractRouteParams<Path extends string> = Path extends `${infer Head}/${infer Tail}` ? Simplify<ExtractSegmentParam<Head> & ExtractRouteParams<Tail>> : Simplify<ExtractSegmentParam<Path>>;
5
+ interface RouteProps<Path extends string = string> {
6
+ params: ExtractRouteParams<Path>;
7
+ search: URLSearchParams;
8
+ pathname: string;
9
+ children?: View;
10
+ }
11
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
12
+ type ApiRouteHandler = (c: any) => Response | Promise<Response>;
13
+ /**
14
+ * Client-side JavaScript mode for a route, layout subtree, or entire application:
15
+ * - `'auto'` (default): Emits **0 `<script>` tags (0 KB JS)** when zero interactive islands render on the page,
16
+ * and automatically loads lazy island revival + nested client routing when 1+ islands render.
17
+ * - `'islands'`: Astro-style MPA mode — emits **0 KB JS** when zero islands render, and loads ONLY the lightweight
18
+ * island + State Receipt loader (no SPA router) when 1+ islands render.
19
+ * - `true`: Always include the client SPA router + lazy revival bootstrap.
20
+ * - `false`: Strict 0-JS lock — omit all island markers and `<script>` tags on this route.
21
+ */
22
+ type CsrMode = boolean | "auto" | "islands";
23
+ interface BuildRoutesOptions {
24
+ /** Default `prerender` flag inherited by routes that don't specify `prerender` (default: `false`) */
25
+ prerender?: boolean;
26
+ /** Default `csr` mode inherited by routes that don't specify `csr` (default: `'auto'`) */
27
+ csr?: CsrMode;
28
+ }
29
+ interface RouteModuleEntry {
30
+ /** Route file path relative to routes root (e.g. 'layout.tsx', 'index.tsx', 'projects/[id].tsx', 'api/stripe.ts') */
31
+ readonly file: string;
32
+ readonly component?: ComponentFn<any>;
33
+ readonly load?: () => Promise<any>;
34
+ /** Static prerendering (`true`, `false` to opt out of global prerendering, or async param generator `() => [{ id: 'alpha' }]`) */
35
+ readonly prerender?: boolean | (() => any[] | Promise<any[]>);
36
+ /** Client rendering mode (`'auto'`, `'islands'`, `true`, or `false`) */
37
+ readonly csr?: CsrMode;
38
+ /** File-system HTTP verb handlers (`export async function GET(c)`, `POST(c)`, etc.) */
39
+ readonly handlers?: Partial<Record<HttpMethod, ApiRouteHandler>>;
40
+ }
41
+ interface CompiledApiRoute {
42
+ readonly id: string;
43
+ readonly honoPath: string;
44
+ readonly score: number;
45
+ readonly prerender?: boolean;
46
+ readonly handlers: Partial<Record<HttpMethod, ApiRouteHandler>>;
47
+ }
48
+ interface CompiledRoute {
49
+ readonly id: string;
50
+ readonly pattern: string;
51
+ readonly regex: RegExp;
52
+ readonly paramNames: readonly string[];
53
+ readonly score: number;
54
+ readonly layouts: readonly LayoutEntry[];
55
+ readonly page: ComponentFn<any>;
56
+ readonly pageLoad?: () => Promise<any>;
57
+ readonly prerender: boolean;
58
+ readonly csr: CsrMode;
59
+ }
60
+ interface LayoutEntry {
61
+ readonly id: string;
62
+ readonly prefix: string;
63
+ readonly component: ComponentFn<any>;
64
+ readonly load?: () => Promise<any>;
65
+ readonly prerender?: boolean;
66
+ readonly csr?: CsrMode;
67
+ }
68
+ interface MatchedSegment {
69
+ readonly kind: "layout" | "page";
70
+ readonly id: string;
71
+ readonly instanceKey: string;
72
+ readonly component: ComponentFn<any>;
73
+ }
74
+ interface NestedRouteMatch {
75
+ readonly route: CompiledRoute;
76
+ readonly pathname: string;
77
+ readonly search: URLSearchParams;
78
+ readonly params: Record<string, string>;
79
+ readonly stack: readonly MatchedSegment[];
80
+ readonly prerender: boolean;
81
+ readonly csr: CsrMode;
82
+ }
83
+ interface C7tRouteInfo {
84
+ pathname: string;
85
+ search: URLSearchParams;
86
+ params: Record<string, string>;
87
+ }
88
+ declare const c7tRouteContext: import("@fierst/blokd").Context<C7tRouteInfo>;
89
+ declare function useRoute(): C7tRouteInfo;
90
+ interface SpecialRoutes {
91
+ readonly notFound?: ComponentFn<{
92
+ pathname: string;
93
+ }>;
94
+ readonly error?: ComponentFn<{
95
+ error: unknown;
96
+ reset: () => void;
97
+ }>;
98
+ readonly rootLayout?: ComponentFn<any>;
99
+ }
100
+ /**
101
+ * Extract convention-based root `404.tsx` (`_404.tsx`), `error.tsx` (`_error.tsx`), and `layout.tsx`
102
+ * components from route module entries.
103
+ */
104
+ declare function extractSpecialRoutes(entries: readonly RouteModuleEntry[]): SpecialRoutes;
105
+ /**
106
+ * Compile a list of route module entries (`layout.tsx`, `(group)/layout.tsx`, `index.tsx`, `projects/[id].tsx`, `[...all].tsx`)
107
+ * into a specificity-ordered nested route table.
108
+ */
109
+ declare function buildRoutes(entries: readonly RouteModuleEntry[], defaults?: BuildRoutesOptions): CompiledRoute[];
110
+ /**
111
+ * Compile file-system HTTP endpoint entries (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS`)
112
+ * into specificity-ordered Hono route definitions.
113
+ */
114
+ declare function buildApiRoutes(entries: readonly RouteModuleEntry[]): CompiledApiRoute[];
115
+ declare function matchNestedRoutes(routes: readonly CompiledRoute[], urlStr: string): NestedRouteMatch | null;
116
+ declare function Outlet(props: {
117
+ depth: number;
118
+ children?: View;
119
+ }): View;
120
+ /** Build the nested SSR or client VDOM tree from `depth` downward. */
121
+ declare function buildMatchedRouteView(match: NestedRouteMatch, startDepth?: number, errorComponent?: ComponentFn<{
122
+ error: unknown;
123
+ reset: () => void;
124
+ }>): View;
125
+ declare function navigate(to: string, opts?: {
126
+ replace?: boolean;
127
+ transition?: boolean;
128
+ }): Promise<void>;
129
+ interface ClientRouterOptions {
130
+ routes: readonly CompiledRoute[];
131
+ errorComponent?: ComponentFn<{
132
+ error: unknown;
133
+ reset: () => void;
134
+ }>;
135
+ rootElement?: Element;
136
+ initialUrl?: string;
137
+ transitions?: boolean;
138
+ wakeIsland?: (island: Element) => Promise<boolean>;
139
+ fetch?: typeof globalThis.fetch;
140
+ onNavigate?: () => void;
141
+ }
142
+ /**
143
+ * Install client-side nested layout navigation with hover preloading and SSG `__c7t.json` sidecar support.
144
+ * Keeps unchanged parent layouts (`RootLayout`) mounted with local `let` & `Context` state intact,
145
+ * while tearing down outgoing child route generators (`finally` + `AbortSignal`) and mounting the new leaf.
146
+ */
147
+ declare function installClientRouter(options: ClientRouterOptions): () => void;
148
+ export { matchNestedRoutes as C, installClientRouter as S, useRoute as T, buildApiRoutes as _, CompiledApiRoute as a, c7tRouteContext as b, ExtractRouteParams as c, MatchedSegment as d, NestedRouteMatch as f, SpecialRoutes as g, RouteProps as h, ClientRouterOptions as i, HttpMethod as l, RouteModuleEntry as m, BuildRoutesOptions as n, CompiledRoute as o, Outlet as p, C7tRouteInfo as r, CsrMode as s, ApiRouteHandler as t, LayoutEntry as u, buildMatchedRouteView as v, navigate as w, extractSpecialRoutes as x, buildRoutes as y };