@kozojs/cli 0.1.4
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 +213 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1210 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# @kozojs/cli
|
|
2
|
+
|
|
3
|
+
๐ฅ **CLI to scaffold new Kozo Framework projects** - The next-gen TypeScript Backend Framework with **Zod Native Integration**
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Using npx
|
|
9
|
+
npx @kozojs/cli my-app
|
|
10
|
+
|
|
11
|
+
# Or install globally
|
|
12
|
+
npm install -g @kozojs/cli
|
|
13
|
+
kozo my-app
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- ๐ **Interactive Setup** - Choose database, template, and more
|
|
19
|
+
- ๐ฆ **Zero Config** - Works out of the box
|
|
20
|
+
- ๐ฅ **Hono-powered** - Fastest HTTP framework
|
|
21
|
+
- ๐ก๏ธ **Type-safe** - Full TypeScript inference with Zod
|
|
22
|
+
- โก **High Performance** - Ajv validation + fast-json-stringify serialization
|
|
23
|
+
- ๐ **OpenAPI Auto-gen** - Swagger docs out of the box
|
|
24
|
+
- ๐๏ธ **Drizzle ORM** - Best-in-class database toolkit
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Create a new project
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx @kozojs/cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or with a project name:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx @kozojs/cli my-awesome-api
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Interactive prompts
|
|
41
|
+
|
|
42
|
+
The CLI will ask you:
|
|
43
|
+
|
|
44
|
+
1. **Project name** - Name of your new project
|
|
45
|
+
2. **Template** - Choose from available templates:
|
|
46
|
+
- **Complete Server** - Full production-ready app (Auth, CRUD, Stats, Pagination)
|
|
47
|
+
- **Starter** - Minimal setup with database integration
|
|
48
|
+
- **SaaS** - Auth + Stripe + Email (coming soon)
|
|
49
|
+
- **E-commerce** - Products + Orders (coming soon)
|
|
50
|
+
3. **Database** - PostgreSQL, MySQL, or SQLite (skipped for Complete template)
|
|
51
|
+
4. **Package source** - npm registry or local workspace
|
|
52
|
+
5. **Install dependencies** - Auto-run `pnpm install`
|
|
53
|
+
|
|
54
|
+
## Project Structure
|
|
55
|
+
|
|
56
|
+
### Starter Template (with Database)
|
|
57
|
+
```
|
|
58
|
+
my-app/
|
|
59
|
+
โโโ src/
|
|
60
|
+
โ โโโ db/
|
|
61
|
+
โ โ โโโ schema.ts # Drizzle schema
|
|
62
|
+
โ โ โโโ index.ts # Database client
|
|
63
|
+
โ โโโ services/
|
|
64
|
+
โ โ โโโ index.ts # Service definitions
|
|
65
|
+
โ โโโ index.ts # Entry point with Zod native API
|
|
66
|
+
โโโ drizzle.config.ts
|
|
67
|
+
โโโ package.json
|
|
68
|
+
โโโ tsconfig.json
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Complete Server Template
|
|
72
|
+
```
|
|
73
|
+
my-app/
|
|
74
|
+
โโโ src/
|
|
75
|
+
โ โโโ data/
|
|
76
|
+
โ โ โโโ store.ts # In-memory data store
|
|
77
|
+
โ โโโ routes/
|
|
78
|
+
โ โ โโโ auth/
|
|
79
|
+
โ โ โ โโโ index.ts # Auth routes (login, me)
|
|
80
|
+
โ โ โโโ users/
|
|
81
|
+
โ โ โ โโโ index.ts # User CRUD routes
|
|
82
|
+
โ โ โโโ posts/
|
|
83
|
+
โ โ โ โโโ index.ts # Post routes
|
|
84
|
+
โ โ โโโ health.ts # Health check
|
|
85
|
+
โ โ โโโ stats.ts # Statistics
|
|
86
|
+
โ โโโ schemas/
|
|
87
|
+
โ โ โโโ user.ts # User schemas
|
|
88
|
+
โ โ โโโ post.ts # Post schemas
|
|
89
|
+
โ โ โโโ common.ts # Common schemas
|
|
90
|
+
โ โโโ utils/
|
|
91
|
+
โ โ โโโ helpers.ts # Helper functions
|
|
92
|
+
โ โโโ index.ts # Entry point
|
|
93
|
+
โโโ package.json
|
|
94
|
+
โโโ tsconfig.json
|
|
95
|
+
โโโ README.md
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## ๐ Complete Server Template
|
|
99
|
+
|
|
100
|
+
The **Complete Server** template generates a **production-ready** Kozo application with:
|
|
101
|
+
|
|
102
|
+
### Features
|
|
103
|
+
- โ
**Authentication** - Login endpoint with mock JWT
|
|
104
|
+
- โ
**User Management** - Full CRUD (Create, Read, Update, Delete)
|
|
105
|
+
- โ
**Posts System** - With authors, tags, and filtering
|
|
106
|
+
- โ
**Pagination** - Query-based pagination for lists
|
|
107
|
+
- โ
**Statistics** - System stats endpoint (users, posts, performance)
|
|
108
|
+
- โ
**Health Check** - Fast-path health endpoint
|
|
109
|
+
- โ
**In-Memory Store** - Ready-to-run without database setup
|
|
110
|
+
|
|
111
|
+
### API Endpoints
|
|
112
|
+
- `POST /auth/login` - Authenticate user
|
|
113
|
+
- `GET /auth/me` - Get current user
|
|
114
|
+
- `GET /users?page=1&limit=10` - List users (paginated)
|
|
115
|
+
- `GET /users/:id` - Get user by ID
|
|
116
|
+
- `POST /users` - Create new user
|
|
117
|
+
- `PUT /users/:id` - Update user
|
|
118
|
+
- `DELETE /users/:id` - Delete user
|
|
119
|
+
- `GET /posts?published=true&tag=framework` - List posts (filtered)
|
|
120
|
+
- `GET /posts/:id` - Get post with author
|
|
121
|
+
- `POST /posts` - Create new post
|
|
122
|
+
- `GET /stats` - System statistics
|
|
123
|
+
- `GET /health` - Health check
|
|
124
|
+
|
|
125
|
+
### Performance Optimized
|
|
126
|
+
- Pre-compiled Zod schemas (no runtime overhead)
|
|
127
|
+
- Optimized handler closures
|
|
128
|
+
- Fast-path routes for simple endpoints
|
|
129
|
+
- Minimal context allocation
|
|
130
|
+
|
|
131
|
+
### Perfect For
|
|
132
|
+
- Learning Kozo framework features
|
|
133
|
+
- Prototyping and demos
|
|
134
|
+
- Benchmarking and performance testing
|
|
135
|
+
- Starting point for production apps
|
|
136
|
+
|
|
137
|
+
## โจ New Zod Native API
|
|
138
|
+
|
|
139
|
+
Kozo now features a **brand new API** with automatic TypeScript inference:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { createKozo } from '@kozojs/core';
|
|
143
|
+
import { z } from 'zod';
|
|
144
|
+
|
|
145
|
+
const app = createKozo({
|
|
146
|
+
port: 3000,
|
|
147
|
+
openapi: {
|
|
148
|
+
info: { title: 'My API', version: '1.0.0' }
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Define schemas (compile-time only!)
|
|
153
|
+
const UserSchema = z.object({
|
|
154
|
+
id: z.string(),
|
|
155
|
+
name: z.string(),
|
|
156
|
+
email: z.string()
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const CreateUserSchema = z.object({
|
|
160
|
+
name: z.string().min(2),
|
|
161
|
+
email: z.string().email()
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Routes with automatic type inference
|
|
165
|
+
app.get('/users', {
|
|
166
|
+
response: z.array(UserSchema)
|
|
167
|
+
}, (c) => {
|
|
168
|
+
// TypeScript SA che il return รจ UserSchema[]
|
|
169
|
+
return users;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
app.post('/users', {
|
|
173
|
+
body: CreateUserSchema,
|
|
174
|
+
response: UserSchema
|
|
175
|
+
}, (c) => {
|
|
176
|
+
// TypeScript SA che c.body ha name: string, email: string
|
|
177
|
+
const newUser = {
|
|
178
|
+
id: Date.now().toString(),
|
|
179
|
+
name: c.body.name, // โ
Type-checked
|
|
180
|
+
email: c.body.email // โ
Type-checked
|
|
181
|
+
};
|
|
182
|
+
return newUser;
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
app.get('/users/:id', {
|
|
186
|
+
params: z.object({ id: z.string() }),
|
|
187
|
+
response: UserSchema
|
|
188
|
+
}, (c) => {
|
|
189
|
+
// TypeScript SA che c.params.id รจ string
|
|
190
|
+
const user = users.find(u => u.id === c.params.id);
|
|
191
|
+
return user;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
console.log('๐ Server: http://localhost:3000');
|
|
195
|
+
console.log('๐ API Docs: http://localhost:3000/swagger');
|
|
196
|
+
app.listen();
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Performance Benefits
|
|
200
|
+
|
|
201
|
+
- **Validation**: Ajv compiled (5x faster than Zod runtime)
|
|
202
|
+
- **Serialization**: fast-json-stringify (2x faster than JSON.stringify)
|
|
203
|
+
- **Type Safety**: Complete TypeScript inference
|
|
204
|
+
- **Zero Overhead**: No runtime Zod parsing
|
|
205
|
+
|
|
206
|
+
## Requirements
|
|
207
|
+
|
|
208
|
+
- Node.js >= 18.0.0
|
|
209
|
+
- pnpm (recommended) or npm
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
MIT
|
package/lib/index.d.ts
ADDED