@nanokajs/core 0.1.2 → 0.1.3
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/README.md +53 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,11 +21,44 @@ Phase 1 (MVP). Experimental. Expect breaking changes until v1.0.
|
|
|
21
21
|
|
|
22
22
|
## Install
|
|
23
23
|
|
|
24
|
+
Nanoka assumes a Hono + Cloudflare Workers project. The standard starting point is `pnpm create hono@latest` (Cloudflare Workers template), which scaffolds `wrangler` and `hono` but **not** TypeScript, `@cloudflare/workers-types`, or `drizzle-kit`. From a fresh scaffold, add Nanoka and the missing pieces:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add @nanokajs/core drizzle-orm zod@^3.23.0
|
|
28
|
+
pnpm add -D typescript drizzle-kit @cloudflare/workers-types
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then add a `types` entry to `tsconfig.json` so `D1Database`, `Request`, `ExecutionContext`, and `crypto` resolve as ambient globals (no per-file imports needed):
|
|
32
|
+
|
|
33
|
+
```jsonc
|
|
34
|
+
{
|
|
35
|
+
"compilerOptions": {
|
|
36
|
+
// ... existing options from create-hono ...
|
|
37
|
+
"types": ["@cloudflare/workers-types"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Without `types`, you would have to `import { D1Database, Request, ... } from '@cloudflare/workers-types'` in every file — which works for types but is misleading because the package has no runtime exports, and importing `Request` shadows the global `Request` constructor.
|
|
43
|
+
|
|
44
|
+
After this, the [Minimal example](#minimal-example-model--1-route) below works as written.
|
|
45
|
+
|
|
46
|
+
> **Zod 4 is not yet supported.** Zod 4 reorders the `ZodType` generics, which collapses Nanoka's field type inference (`RowType`, `CreateInput`) to `never`. Pin `zod@^3.23.0` until Phase 2 ships Zod 4 support. Without the pin, `pnpm add zod` will install the latest 4.x and `User.create({...})` will fail to type-check.
|
|
47
|
+
|
|
48
|
+
`drizzle-kit` is required at install time (not a peer dep) because `npx drizzle-kit generate` is the supported migration step — see Quickstart step 3.
|
|
49
|
+
|
|
50
|
+
### Adding to a project that wasn't scaffolded by create-hono
|
|
51
|
+
|
|
52
|
+
If you're integrating into an existing TypeScript project (no `create hono`), `hono` itself is also a peer dep — add it to the runtime install:
|
|
53
|
+
|
|
24
54
|
```bash
|
|
25
|
-
pnpm add @nanokajs/core hono drizzle-orm zod
|
|
55
|
+
pnpm add @nanokajs/core hono drizzle-orm zod@^3.23.0
|
|
56
|
+
pnpm add -D typescript drizzle-kit @cloudflare/workers-types
|
|
26
57
|
```
|
|
27
58
|
|
|
28
|
-
|
|
59
|
+
The tsconfig `types` entry above still applies if you're targeting Cloudflare Workers.
|
|
60
|
+
|
|
61
|
+
Peer dependency ranges: `hono ^4.0.0`, `drizzle-orm ^0.45.0`, `zod ^3.23.0`, `@cloudflare/workers-types ^4.20240925.0`.
|
|
29
62
|
|
|
30
63
|
## Quickstart
|
|
31
64
|
|
|
@@ -69,8 +102,21 @@ Peer dependencies: `hono ^4.0.0`, `drizzle-orm ^0.45.0`, `zod ^3.23.0`, `@cloudf
|
|
|
69
102
|
|
|
70
103
|
✓ Creates `drizzle/schema.ts` from your models.
|
|
71
104
|
|
|
72
|
-
3. **
|
|
105
|
+
3. **Generate SQL migrations and apply them**
|
|
106
|
+
|
|
107
|
+
Create `drizzle.config.ts` in your project root (this is read by `drizzle-kit`, not by Nanoka):
|
|
108
|
+
```ts
|
|
109
|
+
import { defineConfig } from 'drizzle-kit'
|
|
110
|
+
|
|
111
|
+
export default defineConfig({
|
|
112
|
+
schema: './drizzle/schema.ts',
|
|
113
|
+
out: './drizzle/migrations',
|
|
114
|
+
dialect: 'sqlite',
|
|
115
|
+
driver: 'd1-http',
|
|
116
|
+
})
|
|
117
|
+
```
|
|
73
118
|
|
|
119
|
+
Then:
|
|
74
120
|
```bash
|
|
75
121
|
npx drizzle-kit generate
|
|
76
122
|
npx wrangler d1 migrations apply <DATABASE> --local
|
|
@@ -78,12 +124,14 @@ Peer dependencies: `hono ^4.0.0`, `drizzle-orm ^0.45.0`, `zod ^3.23.0`, `@cloudf
|
|
|
78
124
|
|
|
79
125
|
✓ SQL migrations generated from Drizzle schema. Ready to deploy.
|
|
80
126
|
|
|
127
|
+
The `nanoka.config.ts` (step 2) and `drizzle.config.ts` (step 3) are deliberately separate: Nanoka generates Drizzle schema code, then `drizzle-kit` diffs and emits SQL. Nanoka does not generate SQL or apply migrations — see [How it fits with drizzle-kit and wrangler](#how-it-fits-with-drizzle-kit-and-wrangler) below.
|
|
128
|
+
|
|
81
129
|
### Minimal example (model + 1 route)
|
|
82
130
|
|
|
83
131
|
`src/index.ts`:
|
|
84
132
|
```ts
|
|
85
133
|
import { d1Adapter, nanoka } from '@nanokajs/core'
|
|
86
|
-
import { userFields, userTableName } from './
|
|
134
|
+
import { userFields, userTableName } from './models/user'
|
|
87
135
|
|
|
88
136
|
export interface Env {
|
|
89
137
|
DB: D1Database
|
|
@@ -335,6 +383,7 @@ Nanoka Phase 1 is intentionally minimal. These features are Phase 2 or later:
|
|
|
335
383
|
|
|
336
384
|
- **Relations** (`hasMany()`, `belongsTo()`, lazy loading) — Phase 2. Use raw Drizzle for joins.
|
|
337
385
|
- **Field accessor API** (`User.schema({ pick: f => [f.name, f.email] })`, `User.where(f => eq(f.email, x))`) — Phase 2. Phase 1 uses string arrays and object-form `where`. When Phase 2 lands, the `f` object will be `as const`, with zero runtime cost.
|
|
386
|
+
- **Zod 4 support** — Phase 2. Zod 4 changed `ZodType<Output, Def, Input>` (v3) to `ZodType<Output, Input, Internals>` (v4); Nanoka's field type derivation depends on the v3 generic order, so installing Zod 4 collapses `InferFieldType` to `never`. Pin `zod@^3.23.0` for now.
|
|
338
387
|
- **OpenAPI generation** — Phase 2 or 3.
|
|
339
388
|
- **Turso / libSQL adapters** — Phase 2. Nanoka is designed adapter-first; additional adapters will follow.
|
|
340
389
|
- **CLI scaffolder** (`create-nanoka-app`) — Phase 3.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nanokajs/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Thin wrapper over Hono + Drizzle + Zod for Cloudflare Workers + D1. 80% automatic, 20% explicit.",
|
|
6
6
|
"author": "Eiichiro Iriguchi <eiichiro_iriguchi@a-1ro.dev>",
|