create-donghanh 0.2.1 → 0.3.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/dist/index.js CHANGED
@@ -95,7 +95,11 @@ async function main() {
95
95
  console.log(" Next steps:");
96
96
  console.log(` cd ${target}`);
97
97
  console.log(" bun install");
98
- console.log(" bun run db:init # initialize D1 database");
98
+ if (template === "minimal") {
99
+ console.log(" bun run db:init # initialize D1 database");
100
+ } else {
101
+ console.log(" bun run db:push # push schema to D1");
102
+ }
99
103
  console.log(" bun run dev # start dev server");
100
104
  console.log();
101
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-donghanh",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Scaffold a donghanh project — conversational UI with JSX",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,7 +16,7 @@ function BoardDetail({ data }: OperationProps<Data>) {
16
16
  cards: col.cards.map(c => c.title),
17
17
  }))} />
18
18
  {columns.map(col => (
19
- <Action key={col.id} operation="add-card" label={`Add card to ${col.name}`} variables={{ boardId: board.id, columnId: col.id }} />
19
+ <Action operation="add-card" label={`Add card to ${col.name}`} variables={{ boardId: board.id, columnId: col.id }} />
20
20
  ))}
21
21
  <Action operation="add-member" label="Add member" variables={{ boardId: board.id }} />
22
22
  </Brief>
@@ -19,7 +19,7 @@ function ListBoards({ data }: OperationProps<Data>) {
19
19
  You have {data.boards.length} board(s).
20
20
  <Display data={data.boards.map(b => `${b.name} (${b.card_count} cards, ${b.member_count} members)`)} />
21
21
  {data.boards.map(b => (
22
- <Action key={b.id} operation="board-detail" label={`View ${b.name}`} variables={{ boardId: b.id }} />
22
+ <Action operation="board-detail" label={`View ${b.name}`} variables={{ boardId: b.id }} />
23
23
  ))}
24
24
  <Action operation="create-board" label="Create new board" />
25
25
  </Brief>
@@ -17,6 +17,9 @@
17
17
  "hono": "^4.7.0"
18
18
  },
19
19
  "devDependencies": {
20
+ "@cloudflare/workers-types": "^4.0.0",
21
+ "@types/node": "^22.0.0",
22
+ "better-sqlite3": "^11.0.0",
20
23
  "drizzle-kit": "^0.31.0",
21
24
  "wrangler": "^4.0.0",
22
25
  "typescript": "^5.8.0"
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2017",
4
4
  "lib": ["esnext"],
5
+ "types": ["@cloudflare/workers-types", "node"],
5
6
  "skipLibCheck": true,
6
7
  "strict": true,
7
8
  "noEmit": true,
@@ -10,5 +11,6 @@
10
11
  "jsx": "react-jsx",
11
12
  "jsxImportSource": "@donghanh/core"
12
13
  },
13
- "include": ["**/*.ts", "**/*.tsx"]
14
+ "include": ["**/*.ts", "**/*.tsx"],
15
+ "exclude": ["node_modules"]
14
16
  }
@@ -0,0 +1,83 @@
1
+ import { Database } from "bun:sqlite";
2
+ import { describe, expect, test } from "bun:test";
3
+ import { createExecutor } from "./executor";
4
+
5
+ function createTestDb(): D1Database {
6
+ const sqlite = new Database(":memory:");
7
+ sqlite.exec(`
8
+ CREATE TABLE items (
9
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
10
+ name TEXT NOT NULL,
11
+ created_at TEXT DEFAULT (datetime('now'))
12
+ )
13
+ `);
14
+ // Wrap bun:sqlite to match D1Database.prepare() interface
15
+ return {
16
+ prepare(query: string) {
17
+ const stmt = sqlite.prepare(query);
18
+ return {
19
+ bind(...params: unknown[]) {
20
+ return {
21
+ async run() {
22
+ stmt.run(...(params as any[]));
23
+ return { success: true, meta: {} };
24
+ },
25
+ async all() {
26
+ return { results: stmt.all(...(params as any[])), success: true };
27
+ },
28
+ async first() {
29
+ return stmt.get(...(params as any[])) ?? null;
30
+ },
31
+ };
32
+ },
33
+ async run() {
34
+ stmt.run();
35
+ return { success: true, meta: {} };
36
+ },
37
+ async all() {
38
+ return { results: stmt.all(), success: true };
39
+ },
40
+ async first() {
41
+ return stmt.get() ?? null;
42
+ },
43
+ } as any;
44
+ },
45
+ } as any;
46
+ }
47
+
48
+ const ctx = { userId: "test", request: new Request("http://localhost") };
49
+
50
+ describe("executor", () => {
51
+ test("list-items returns empty array", async () => {
52
+ const executor = createExecutor(createTestDb());
53
+ const result = (await executor("list-items", {}, ctx)) as any;
54
+ expect(result.items).toEqual([]);
55
+ });
56
+
57
+ test("add-item creates an item", async () => {
58
+ const executor = createExecutor(createTestDb());
59
+ const result = (await executor(
60
+ "add-item",
61
+ { name: "Buy milk" },
62
+ ctx,
63
+ )) as any;
64
+ expect(result.items).toHaveLength(1);
65
+ expect(result.items[0].name).toBe("Buy milk");
66
+ });
67
+
68
+ test("add-item then list-items", async () => {
69
+ const db = createTestDb();
70
+ const executor = createExecutor(db);
71
+ await executor("add-item", { name: "Item 1" }, ctx);
72
+ await executor("add-item", { name: "Item 2" }, ctx);
73
+ const result = (await executor("list-items", {}, ctx)) as any;
74
+ expect(result.items).toHaveLength(2);
75
+ });
76
+
77
+ test("unknown operation throws", () => {
78
+ const executor = createExecutor(createTestDb());
79
+ expect(executor("unknown", {}, ctx)).rejects.toThrow(
80
+ "Unknown operation: unknown",
81
+ );
82
+ });
83
+ });
@@ -5,14 +5,18 @@
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "wrangler dev",
8
- "deploy": "wrangler deploy"
8
+ "deploy": "wrangler deploy",
9
+ "db:init": "wrangler d1 execute my-donghanh-app-db --local --file=schema.sql",
10
+ "test": "bun test"
9
11
  },
10
12
  "dependencies": {
11
- "@donghanh/core": "^0.1.0",
12
- "@donghanh/hono": "^0.1.0",
13
+ "@donghanh/core": "^0.1.1",
14
+ "@donghanh/hono": "^0.1.1",
13
15
  "hono": "^4.7.0"
14
16
  },
15
17
  "devDependencies": {
18
+ "@cloudflare/workers-types": "^4.0.0",
19
+ "@types/bun": "^1.0.0",
16
20
  "wrangler": "^4.0.0",
17
21
  "typescript": "^5.8.0"
18
22
  }
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2017",
4
4
  "lib": ["esnext"],
5
+ "types": ["@cloudflare/workers-types", "bun-types"],
5
6
  "skipLibCheck": true,
6
7
  "strict": true,
7
8
  "noEmit": true,
@@ -10,5 +11,6 @@
10
11
  "jsx": "react-jsx",
11
12
  "jsxImportSource": "@donghanh/core"
12
13
  },
13
- "include": ["**/*.ts", "**/*.tsx"]
14
+ "include": ["**/*.ts", "**/*.tsx"],
15
+ "exclude": ["node_modules"]
14
16
  }
@@ -1,28 +1,33 @@
1
- import { Hono } from "hono";
1
+ import { App, buildRegistry } from "@donghanh/core";
2
2
  import { gptRoutes } from "@donghanh/hono";
3
- import { buildRegistry, App } from "@donghanh/core";
4
- import { operations } from "./operations";
3
+ import { Hono } from "hono";
5
4
  import { createExecutor } from "./executor";
5
+ import { operations } from "./operations";
6
6
 
7
7
  type Env = { Bindings: { DB: D1Database } };
8
8
 
9
- const app = new Hono<Env>();
10
-
11
9
  const appNode = App({ operations });
12
10
  const registry = buildRegistry(appNode);
13
11
 
14
- app.route("/api", gptRoutes({
15
- registry,
16
- executor: (opId, vars, ctx) => createExecutor((ctx as any).db)(opId, vars, ctx),
17
- authenticate: async (request) => ({ userId: "anonymous" }),
18
- }));
12
+ const app = new Hono<Env>();
13
+
14
+ // Store DB reference for the executor
15
+ let _db: D1Database;
19
16
 
20
- // Inject D1 binding into executor context
21
- app.use("/api/*", async (c, next) => {
22
- (c as any).db = c.env.DB;
17
+ app.use("/*", async (c, next) => {
18
+ _db = c.env.DB;
23
19
  await next();
24
20
  });
25
21
 
22
+ app.route(
23
+ "/api",
24
+ gptRoutes({
25
+ registry,
26
+ executor: (opId, vars, ctx) => createExecutor(_db)(opId, vars, ctx),
27
+ authenticate: async () => ({ userId: "anonymous" }),
28
+ }),
29
+ );
30
+
26
31
  app.get("/", (c) => c.text("donghanh app running. Try GET /api/operations"));
27
32
 
28
33
  export default app;