create-thexjs-app 0.1.4 → 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 (2) hide show
  1. package/README.md +78 -148
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <p align="center">
8
8
 
9
9
  <strong>The ultra-fast, full-stack React framework built natively for Bun.</strong>
10
- Static sites, SSR, file-based API routes, and server functions — running in a single process.
10
+ Static sites, SSR, file-based API routes, and server functions, running in a single process.
11
11
 
12
12
  </p>
13
13
 
@@ -56,7 +56,7 @@ cd my-app
56
56
  bun run dev
57
57
  ```
58
58
 
59
- When prompted for a template, press Enter to accept **default** (recommended) — a single home page to start from.
59
+ When prompted for a template, press Enter to accept **default** (recommended), a single home page to start from.
60
60
 
61
61
  Your app will be running at `http://localhost:3000`.
62
62
 
@@ -173,11 +173,12 @@ export async function loader({ params }: LoaderArgs) {
173
173
  return { title: post.title, content: post.content };
174
174
  }
175
175
 
176
- export default function BlogPost({ loaderData }: RouteProps<typeof loader>) {
176
+ export default function BlogPost({ loaderData }: RouteProps) {
177
+ const { title, content } = loaderData as { title: string; content: string };
177
178
  return (
178
179
  <article>
179
- <h1 className="text-3xl font-bold">{loaderData.title}</h1>
180
- <div>{loaderData.content}</div>
180
+ <h1 className="text-3xl font-bold">{title}</h1>
181
+ <div>{content}</div>
181
182
  </article>
182
183
  );
183
184
  }
@@ -221,7 +222,7 @@ export default function NotFound() {
221
222
 
222
223
  ## Pages & Loaders
223
224
 
224
- x supports two page modes — static prerendering and server-side rendering — both powered by loaders.
225
+ x supports two page modes: static prerendering and server-side rendering, both powered by loaders.
225
226
 
226
227
  ### Page modes
227
228
 
@@ -261,12 +262,13 @@ export async function loader({ request }: LoaderArgs) {
261
262
  return { products };
262
263
  }
263
264
 
264
- export default function Products({ loaderData }: RouteProps<typeof loader>) {
265
+ export default function Products({ loaderData }: RouteProps) {
266
+ const { products } = loaderData as { products: Array<{ id: string; name: string; price: number }> };
265
267
  return (
266
268
  <div>
267
269
  <h1 className="text-3xl font-bold">Products</h1>
268
270
  <ul className="mt-6 space-y-4">
269
- {loaderData.products.map((p: any) => (
271
+ {products.map((p) => (
270
272
  <li key={p.id} className="rounded-xl border border-border bg-card p-4">
271
273
  <h2 className="font-semibold">{p.name}</h2>
272
274
  <p className="text-sm text-muted-foreground">{p.price}</p>
@@ -289,12 +291,12 @@ export async function loader({ params }: LoaderArgs) {
289
291
  const product = await db.query(
290
292
  "SELECT * FROM products WHERE id = ?", [params.id]
291
293
  );
292
- if (!product) throw new Response(null, { status: 404 });
294
+ if (!product) return new Response(null, { status: 404 });
293
295
  return { product };
294
296
  }
295
297
 
296
- export default function ProductDetail({ loaderData }: RouteProps<typeof loader>) {
297
- const { product } = loaderData;
298
+ export default function ProductDetail({ loaderData }: RouteProps) {
299
+ const { product } = loaderData as { product: { name: string; description: string; price: number } };
298
300
  return (
299
301
  <div>
300
302
  <h1 className="text-3xl font-bold">{product.name}</h1>
@@ -307,15 +309,14 @@ export default function ProductDetail({ loaderData }: RouteProps<typeof loader>)
307
309
 
308
310
  ### RouteProps type
309
311
 
310
- The `RouteProps` type provides typed access to `loaderData`, `params`, and `request`. Pass your loader function as the type parameter for full type safety.
312
+ `RouteProps` is a plain non-generic type with `params` (a `Record<string, string>` of dynamic segments) and `loaderData` (the loader's return value). Cast loader data to its shape for inline types.
311
313
 
312
314
  ```tsx
313
315
  import type { RouteProps } from "@thexjs/core";
314
316
 
315
- export default function Page({ loaderData, params, request }: RouteProps<typeof loader>) {
316
- // loaderData has the return type of loader()
317
- // params has the dynamic segment types
318
- // request is the standard Request object
317
+ export default function ProductDetail({ loaderData }: RouteProps) {
318
+ const { product } = loaderData as { product: { name: string; price: number } };
319
+ return <h1>{product.name}</h1>;
319
320
  }
320
321
  ```
321
322
 
@@ -409,43 +410,37 @@ Build REST endpoints alongside your frontend pages. API routes live in `src/api/
409
410
 
410
411
  Like pages, API routes use the file system. A file at `src/api/hello.ts` becomes `/api/hello`.
411
412
 
412
- ```tsx
413
- import type { ApiHandler } from "@thexjs/core";
414
-
415
- export const GET: ApiHandler = ({ request }) => {
413
+ ```ts
414
+ export function GET(req: Request) {
416
415
  return Response.json({ message: "Hello from x!" });
417
- };
416
+ }
418
417
  ```
419
418
 
420
419
  ### Request & response
421
420
 
422
- Each exported HTTP method receives the request and returns a standard `Response` object. Dynamic segments work the same as pages: `api/users/[id].ts` → `/api/users/:id`.
421
+ Each exported HTTP method is a plain `export async function GET(req: Request)` that receives the standard fetch `Request` and returns a `Response`. Dynamic segments work the same as pages: `api/users/[id].ts` → `/api/users/:id`.
423
422
 
424
423
  ```tsx
425
- import type { ApiHandler } from "@thexjs/core";
426
-
427
- export const GET: ApiHandler = async ({ request }) => {
428
- const users = await db.query("SELECT * FROM users");
424
+ export async function GET(req: Request) {
425
+ const users = await db.query("SELECT * FROM users").all();
429
426
  return Response.json(users);
430
- };
427
+ }
431
428
 
432
- export const POST: ApiHandler = async ({ request }) => {
433
- const body = await request.json();
429
+ export async function POST(req: Request) {
430
+ const body = await req.json();
434
431
  const result = await db.query(
435
432
  "INSERT INTO users (name, email) VALUES (?, ?) RETURNING *",
436
433
  [body.name, body.email]
437
434
  );
438
435
  return Response.json(result, { status: 201 });
439
- };
436
+ }
440
437
  ```
441
438
 
442
439
  ### POST endpoint example
443
440
 
444
441
  ```tsx
445
- import type { ApiHandler } from "@thexjs/core";
446
-
447
- export const POST: ApiHandler = async ({ request }) => {
448
- const form = await request.formData();
442
+ export async function POST(req: Request) {
443
+ const form = await req.formData();
449
444
  const email = form.get("email");
450
445
  const message = form.get("message");
451
446
 
@@ -458,12 +453,12 @@ export const POST: ApiHandler = async ({ request }) => {
458
453
 
459
454
  await sendEmail({ email, message });
460
455
  return Response.json({ success: true });
461
- };
456
+ }
462
457
  ```
463
458
 
464
459
  ### API route tree
465
460
 
466
- API routes support the same file-tree conventions as pages — nested folders, dynamic segments, and index files.
461
+ API routes support the same file-tree conventions as pages: nested folders, dynamic segments, and index files.
467
462
 
468
463
  ```
469
464
  src/api/
@@ -549,7 +544,7 @@ export default function GreetForm() {
549
544
 
550
545
  ### Server functions from loaders
551
546
 
552
- You can also import and call server functions directly in loaders — no HTTP needed since they share the same process.
547
+ You can also import and call server functions directly in loaders; no HTTP needed since they share the same process.
553
548
 
554
549
  ```tsx
555
550
  import type { RouteProps, LoaderArgs } from "@thexjs/core";
@@ -560,7 +555,7 @@ export async function loader({ request }: LoaderArgs) {
560
555
  return { data };
561
556
  }
562
557
 
563
- export default function Dashboard({ loaderData }: RouteProps<typeof loader>) {
558
+ export default function Dashboard({ loaderData }: RouteProps) {
564
559
  return <div>...</div>;
565
560
  }
566
561
  ```
@@ -620,22 +615,25 @@ import type { RouteProps, LoaderArgs } from "@thexjs/core";
620
615
  import { scanContent, renderMarkdown } from "@thexjs/core";
621
616
 
622
617
  export async function loader({ params }: LoaderArgs) {
623
- const posts = await scanContent("posts");
618
+ const posts = scanContent("posts");
624
619
  const post = posts.find((p) => p.slug === params.slug);
625
- if (!post) throw new Response(null, { status: 404 });
626
- const html = await renderMarkdown(post.body);
620
+ if (!post) return new Response(null, { status: 404 });
621
+ const html = renderMarkdown(post.body);
627
622
  return { post: { ...post, html } };
628
623
  }
629
624
 
630
- export default function BlogPost({ loaderData }: RouteProps<typeof loader>) {
625
+ export default function BlogPost({ loaderData }: RouteProps) {
626
+ const { post } = loaderData as {
627
+ post: { frontmatter: Record<string, unknown>; html: string; date: string; author: string; tags?: string[] };
628
+ };
631
629
  return (
632
630
  <article className="prose max-w-none">
633
- <h1 className="text-4xl font-bold">{loaderData.post.title}</h1>
631
+ <h1 className="text-4xl font-bold">{String(post.frontmatter.title)}</h1>
634
632
  <p className="text-sm text-muted-foreground">
635
- {loaderData.post.date} &mdash; {loaderData.post.author}
633
+ {post.date} &mdash; {post.author}
636
634
  </p>
637
635
  <div className="mt-6 flex gap-2">
638
- {loaderData.post.tags?.map((tag: string) => (
636
+ {post.tags?.map((tag) => (
639
637
  <span key={tag} className="rounded-full bg-primary/10 px-3 py-1 text-xs text-primary">
640
638
  {tag}
641
639
  </span>
@@ -643,7 +641,7 @@ export default function BlogPost({ loaderData }: RouteProps<typeof loader>) {
643
641
  </div>
644
642
  <div
645
643
  className="mt-8 leading-relaxed"
646
- dangerouslySetInnerHTML={{ __html: loaderData.post.html }}
644
+ dangerouslySetInnerHTML={{ __html: post.html }}
647
645
  />
648
646
  </article>
649
647
  );
@@ -652,11 +650,11 @@ export default function BlogPost({ loaderData }: RouteProps<typeof loader>) {
652
650
 
653
651
  ### scanContent API
654
652
 
655
- `scanContent(directory)` scans a subdirectory of your content folder and returns an array of content entries. Each entry includes `slug`, `frontmatter`, and `content`.
653
+ `scanContent(directory)` scans a subdirectory of your content folder (synchronously) and returns an array of content entries. Each entry includes `filePath`, `routePath`, `slug`, `frontmatter`, and `body`.
656
654
 
657
655
  ### renderMarkdown API
658
656
 
659
- `renderMarkdown(markdownString)` converts markdown to an HTML string. It supports syntax highlighting via Shiki and handles all standard markdown features.
657
+ `renderMarkdown(markdownString)` converts Markdown to an HTML string. It's a lightweight, dependency-free renderer (headings, paragraphs, lists, links, inline code, code blocks, bold/italic, blockquotes) that HTML-escapes content by default.
660
658
 
661
659
  ---
662
660
 
@@ -690,7 +688,7 @@ import type { MiddlewareContext, MiddlewareNext } from "@thexjs/core";
690
688
 
691
689
  export async function middleware(ctx: MiddlewareContext, next: MiddlewareNext) {
692
690
  console.log(`[${ctx.request.method}] ${ctx.request.url}`);
693
- return next(ctx);
691
+ return next();
694
692
  }
695
693
  ```
696
694
 
@@ -700,7 +698,7 @@ export async function middleware(ctx: MiddlewareContext, next: MiddlewareNext) {
700
698
  import type { MiddlewareContext, MiddlewareNext } from "@thexjs/core";
701
699
 
702
700
  export async function middleware(ctx: MiddlewareContext, next: MiddlewareNext) {
703
- const session = ctx.request.cookies.get("session");
701
+ const session = ctx.request.headers.get("cookie");
704
702
 
705
703
  if (!session) {
706
704
  return new Response(null, {
@@ -717,14 +715,13 @@ export async function middleware(ctx: MiddlewareContext, next: MiddlewareNext) {
717
715
  });
718
716
  }
719
717
 
720
- ctx.params.user = user;
721
- return next(ctx);
718
+ return next();
722
719
  }
723
720
  ```
724
721
 
725
722
  ### MiddlewareNext
726
723
 
727
- Call `next(ctx)` to pass control to the next middleware or the route handler. You can modify `ctx.params` to enrich the request context for downstream handlers.
724
+ Call `next()` (no arguments) to pass control to the next middleware or the route handler. Any mutations to `ctx.params` you make before the call flow through to downstream handlers. Middleware applies to page routes only, not API routes.
728
725
 
729
726
  ### Redirect patterns
730
727
 
@@ -755,44 +752,23 @@ x provides built-in SQLite and PostgreSQL integrations. Connect to a database, r
755
752
  Use `connectSQLite` to connect to a local SQLite database file. SQLite requires zero configuration and is perfect for development and single-server deployments.
756
753
 
757
754
  ```ts
758
- import { connectSQLite, runSQLiteMigrations } from "@thexjs/core";
759
-
760
- const db = connectSQLite("data/app.db");
761
-
762
- await runSQLiteMigrations(db, [
763
- {
764
- version: 1,
765
- sql: `
766
- CREATE TABLE IF NOT EXISTS users (
767
- id INTEGER PRIMARY KEY AUTOINCREMENT,
768
- name TEXT NOT NULL,
769
- email TEXT UNIQUE NOT NULL,
770
- created_at TEXT DEFAULT (datetime('now'))
771
- )
772
- `,
773
- },
774
- {
775
- version: 2,
776
- sql: `
777
- CREATE TABLE IF NOT EXISTS posts (
778
- id INTEGER PRIMARY KEY AUTOINCREMENT,
779
- user_id INTEGER REFERENCES users(id),
780
- title TEXT NOT NULL,
781
- body TEXT,
782
- created_at TEXT DEFAULT (datetime('now'))
783
- )
784
- `,
785
- },
786
- ]);
755
+ import { connectSQLite, runSQLiteMigrations } from "@thexjs/core/data";
756
+
757
+ const db = connectSQLite({ path: "data/app.db" });
758
+
759
+ // Points at a directory of .sql files (e.g. data/migrations/001_create_users.sql)
760
+ await runSQLiteMigrations(db, "data/migrations");
787
761
 
788
762
  export { db };
789
763
  ```
790
764
 
765
+ `runSQLiteMigrations` runs each `.sql` file in the directory in sorted order, tracking them in a `_x_migrations` table so each runs only once. It returns `{ applied, skipped }`.
766
+
791
767
  ### Querying SQLite
792
768
 
793
769
  The database object supports prepared statements with `query` and `execute` methods.
794
770
 
795
- ```tsx
771
+ ```ts
796
772
  import type { RouteProps, LoaderArgs } from "@thexjs/core";
797
773
  import { db } from "../lib/db";
798
774
 
@@ -803,12 +779,13 @@ export async function loader({}: LoaderArgs) {
803
779
  return { users };
804
780
  }
805
781
 
806
- export default function Users({ loaderData }: RouteProps<typeof loader>) {
782
+ export default function Users({ loaderData }: RouteProps) {
783
+ const { users } = loaderData as { users: Array<{ id: string; name: string; email: string }> };
807
784
  return (
808
785
  <div>
809
786
  <h1 className="text-3xl font-bold">Users</h1>
810
787
  <ul className="mt-6 space-y-3">
811
- {loaderData.users.map((u: any) => (
788
+ {users.map((u) => (
812
789
  <li key={u.id} className="rounded-xl border border-border bg-card p-4">
813
790
  <p className="font-semibold">{u.name}</p>
814
791
  <p className="text-sm text-muted-foreground">{u.email}</p>
@@ -825,90 +802,43 @@ export default function Users({ loaderData }: RouteProps<typeof loader>) {
825
802
  For production deployments, use `connectPostgres` with a connection string. PostgreSQL provides concurrent access, connection pooling, and is suitable for multi-server deployments.
826
803
 
827
804
  ```ts
828
- import { connectPostgres, runPostgresMigrations } from "@thexjs/core";
805
+ import { connectPostgres, runPostgresMigrations } from "@thexjs/core/data";
829
806
 
830
807
  const db = connectPostgres({
831
- connectionString: process.env.DATABASE_URL,
808
+ url: process.env.DATABASE_URL,
832
809
  max: 20, // connection pool size
833
810
  });
834
811
 
835
- await runPostgresMigrations(db, [
836
- {
837
- version: 1,
838
- sql: `
839
- CREATE TABLE IF NOT EXISTS users (
840
- id SERIAL PRIMARY KEY,
841
- name VARCHAR(255) NOT NULL,
842
- email VARCHAR(255) UNIQUE NOT NULL,
843
- created_at TIMESTAMPTZ DEFAULT NOW()
844
- )
845
- `,
846
- },
847
- ]);
812
+ await runPostgresMigrations(db, "data/migrations");
848
813
 
849
814
  export { db };
850
815
  ```
851
816
 
852
817
  ### Migration API
853
818
 
854
- Both `runSQLiteMigrations` and `runPostgresMigrations` take an array of migration objects. Each migration has a `version` number (incrementing) and `sql` string. Migrations are tracked and only run once.
819
+ Both `runSQLiteMigrations` and `runPostgresMigrations` take a database connection and a **directory of `.sql` files**. The files run in sorted order and are tracked in a `_x_migrations` table, so each runs only once. They return `{ applied, skipped }`.
855
820
 
856
821
  ---
857
822
 
858
823
  ## Build & Deploy
859
824
 
860
- x produces optimized production builds with static HTML export, a server entry point, and content collection rendering — all in a single command.
861
-
862
- ### Build command
825
+ x produces optimized production builds with static HTML export, a server entry point, and content collection rendering, all in a single command.
863
826
 
864
- Run `x build` to produce a production build. The build output goes to a `.x/` directory.
865
-
866
- ```bash
867
- x build
868
- [x] resolving routes...
869
- [x] found 12 routes
870
- [x] building static pages...
871
- [x] building server bundle...
872
- [x] rendering content collections...
873
- [x] build complete in 1.2s
874
- ```
875
-
876
- ### Output structure
877
-
878
- The `.x/` directory contains everything needed to deploy — static files, server bundle, and assets.
827
+ Build with `x build --outDir <dir>` (default `.x`). Output:
879
828
 
880
829
  ```
881
830
  .x/
882
- client/ # Client-side assets
883
- assets/
884
- *.js # Bundled JS
885
- *.css # Extracted CSS
886
- server/ # Server entry point
887
- index.js # Bun server bundle
888
- static/ # Prerendered HTML pages
831
+ client/ # Prerendered static HTML + assets (deployable as a static site)
889
832
  index.html
890
833
  about/index.html
891
- blog/
892
- hello-world/index.html
893
- x.json # Build manifest
834
+ styles.css
835
+ public/ # your public/ assets copied alongside
836
+ _islands/ # per-page island hydration bundles
837
+ server/
838
+ index.ts # Bun server entry for server-mode pages + API routes
894
839
  ```
895
840
 
896
- ### Static page export
897
-
898
- Pages with `mode = "static"` are exported as HTML files in `.x/static/`. Each page is fully rendered at build time, including its loader output.
899
-
900
- ### Server entry
901
-
902
- Server-rendered pages are bundled into `.x/server/index.js`. This file contains all server routes, API handlers, server functions, and middleware.
903
-
904
- ### Production server
905
-
906
- Use `x start` to run the production server. It serves static files from `.x/static/` and handles dynamic routes via the server bundle.
907
-
908
- ```bash
909
- x start
910
- [x] production server running at http://localhost:3000
911
- ```
841
+ Static pages are exported as HTML under `client/`. Server-rendered pages and API routes are covered by `server/index.ts`, run with `x start`. `x build --adapter vercel` emits a `.vercel/output` tree instead for Vercel.
912
842
 
913
843
  ### Docker deployment
914
844
 
@@ -972,9 +902,9 @@ export default defineConfig({
972
902
  |--------------|----------|---------------|------------------------------------|
973
903
  | `pagesDir` | `string` | `"src/pages"` | File-based page routes |
974
904
  | `layoutsDir` | `string` | `"src/layouts"` | Root layout directory |
975
- | `apiDir` | `string` | `"src/api"` | File-based API routes |
976
- | `actionsDir` | `string` | `"src/actions"` | Server functions |
977
- | `contentDir` | `string` | `"content"` | Markdown content collections |
905
+ | `apiDir` | `string` | *(none)* | File-based API routes |
906
+ | `actionsDir` | `string` | *(auto-detected)* | Server functions |
907
+ | `contentDir` | `string` | *(auto-detected)* | Markdown content collections |
978
908
  | `port` | `number` | `3000` | Dev server port |
979
909
  | `routesDir` | `string` | `undefined` | Legacy routes directory |
980
910
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-thexjs-app",
3
- "version": "0.1.4",
3
+ "version": "1.0.0",
4
4
  "description": "Scaffold a new x framework app (npm create thexjs-app@latest).",
5
5
  "keywords": [
6
6
  "react",