speexjs 0.2.3 → 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/README.md +32 -60
- package/dist/cli/index.js +300 -91
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1048 -285
- package/dist/index.js.map +1 -1
- package/dist/rpc/index.d.ts +1 -1
- package/dist/schema/index.d.ts +36 -30
- package/dist/schema/index.js +12 -229
- package/dist/schema/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +1 -0
- package/dist/server/auth/index.js +18 -12
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/database/index.d.ts +22 -2
- package/dist/server/database/index.js +993 -30
- package/dist/server/database/index.js.map +1 -1
- package/dist/server/http/index.js +19 -2
- package/dist/server/http/index.js.map +1 -1
- package/dist/server/index.d.ts +4 -3
- package/dist/server/index.js +1028 -48
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware/index.js +53 -33
- package/dist/server/middleware/index.js.map +1 -1
- package/dist/server/router/index.js +8 -6
- package/dist/server/router/index.js.map +1 -1
- package/dist/{types-CXH8hPei.d.ts → types-aW38f63o.d.ts} +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -12,11 +12,7 @@ npm install speexjs
|
|
|
12
12
|
import { speexjs } from 'speexjs/server'
|
|
13
13
|
|
|
14
14
|
const app = speexjs()
|
|
15
|
-
|
|
16
|
-
app.get('/', async ({ response }) => {
|
|
17
|
-
return response.html('<h1>SpeexJS 🚀</h1>')
|
|
18
|
-
})
|
|
19
|
-
|
|
15
|
+
app.get('/', ({ response }) => response.html('<h1>SpeexJS 🚀</h1>'))
|
|
20
16
|
app.listen(3000)
|
|
21
17
|
```
|
|
22
18
|
|
|
@@ -24,107 +20,83 @@ app.listen(3000)
|
|
|
24
20
|
npx speexjs serve
|
|
25
21
|
```
|
|
26
22
|
|
|
27
|
-
##
|
|
23
|
+
## Features
|
|
28
24
|
|
|
29
|
-
| Category |
|
|
30
|
-
|
|
31
|
-
| **Server** | Router, Middleware (10 built-in), Controller, DI Container
|
|
32
|
-
| **Database** | Query Builder, Migrations, Pagination
|
|
33
|
-
| **Auth** | Session Guard, Token Guard, Gate Authorization
|
|
34
|
-
| **Validation** | 25+ schema types,
|
|
35
|
-
| **Client** | Signals, VDOM, JSX, SSR — no React
|
|
25
|
+
| Category | Description |
|
|
26
|
+
|----------|-------------|
|
|
27
|
+
| **Server** | Router, Middleware (10 built-in), Controller, DI Container |
|
|
28
|
+
| **Database** | Query Builder, Migrations, Pagination — MySQL/SQLite/PG |
|
|
29
|
+
| **Auth** | Session Guard, Token Guard, Gate Authorization |
|
|
30
|
+
| **Validation** | 25+ schema types — string, number, objects, arrays, and more |
|
|
31
|
+
| **Client** | Signals, VDOM, JSX, SSR — no React required |
|
|
36
32
|
| **RPC** | Type-safe server-client communication |
|
|
37
33
|
| **CLI** | `speexjs init`, `serve`, `make:*`, `list-routes` |
|
|
38
|
-
| **Zero Dep** | 100% native Node.js
|
|
34
|
+
| **Zero Dep** | 100% native Node.js |
|
|
39
35
|
|
|
40
36
|
## Examples
|
|
41
37
|
|
|
42
38
|
### Routing
|
|
43
39
|
|
|
44
40
|
```typescript
|
|
45
|
-
import { speexjs
|
|
41
|
+
import { speexjs } from 'speexjs/server'
|
|
46
42
|
|
|
47
43
|
const app = speexjs()
|
|
48
44
|
|
|
49
|
-
// Route groups with middleware
|
|
50
45
|
app.group('/api', (router) => {
|
|
51
46
|
router.get('/users', [UserController, 'index'])
|
|
52
47
|
router.post('/users', [UserController, 'store'])
|
|
53
48
|
}).middleware(['auth', 'throttle'])
|
|
54
49
|
|
|
55
|
-
// Resource routes
|
|
56
50
|
app.router.resource('/posts', PostController)
|
|
57
|
-
// GET /posts, POST /posts, GET /posts/:id, PUT /posts/:id, DELETE /posts/:id
|
|
58
51
|
```
|
|
59
52
|
|
|
60
53
|
### Validation
|
|
61
54
|
|
|
62
55
|
```typescript
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
const UserSchema = s.object({
|
|
66
|
-
name: s.string().min(3).max(100),
|
|
67
|
-
email: s.string().email(),
|
|
68
|
-
age: s.number().min(17).max(120).optional(),
|
|
69
|
-
phone: s.phone(), // Nomor Indonesia
|
|
70
|
-
nik: s.nik().optional(), // NIK 16 digit
|
|
71
|
-
})
|
|
56
|
+
import { schema } from 'speexjs/schema'
|
|
72
57
|
|
|
73
|
-
|
|
58
|
+
const UserSchema = schema.object({
|
|
59
|
+
name: schema.string().min(3).max(100),
|
|
60
|
+
email: schema.string().email(),
|
|
61
|
+
age: schema.number().min(17).optional(),
|
|
62
|
+
})
|
|
74
63
|
```
|
|
75
64
|
|
|
76
65
|
### Database
|
|
77
66
|
|
|
78
67
|
```typescript
|
|
79
|
-
import {
|
|
68
|
+
import { db } from 'speexjs/server/database'
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
await db.connect()
|
|
70
|
+
await db.connect({ driver: 'mysql', database: 'myapp' })
|
|
83
71
|
|
|
84
72
|
const users = await db.table('users')
|
|
85
73
|
.select('id', 'name', 'email')
|
|
86
74
|
.where('age', '>', 18)
|
|
87
|
-
.orderByDesc('created_at')
|
|
88
75
|
.paginate(10, 1)
|
|
89
76
|
```
|
|
90
77
|
|
|
91
78
|
### Auth
|
|
92
79
|
|
|
93
80
|
```typescript
|
|
94
|
-
import {
|
|
95
|
-
|
|
96
|
-
const auth = new AuthManager()
|
|
97
|
-
auth.guard('session', new SessionGuard({ table: 'users' }))
|
|
81
|
+
import { auth } from 'speexjs/server/auth'
|
|
98
82
|
|
|
99
83
|
app.post('/login', async ({ request, response }) => {
|
|
100
84
|
const { email, password } = await request.json()
|
|
101
|
-
const ok = await auth.
|
|
102
|
-
if (!ok) return response.json({ error: 'Login
|
|
103
|
-
return response.json({ message: 'Login
|
|
85
|
+
const ok = await auth.attempt({ email, password })
|
|
86
|
+
if (!ok) return response.json({ error: 'Login failed' }, 401)
|
|
87
|
+
return response.json({ message: 'Login successful' })
|
|
104
88
|
})
|
|
105
89
|
```
|
|
106
90
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
speexjs init my-app # Buat project baru
|
|
111
|
-
speexjs serve # Jalankan dev server
|
|
112
|
-
speexjs make:controller User # Generate controller
|
|
113
|
-
speexjs make:middleware Auth # Generate middleware
|
|
114
|
-
speexjs list-routes # Lihat semua route
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Architecture
|
|
118
|
-
|
|
119
|
-
```
|
|
120
|
-
speexjs/
|
|
121
|
-
├── server/ (HTTP, Router, Middleware, Auth, Database, Cache, Storage, Events)
|
|
122
|
-
├── client/ (Signals, VDOM, SSR, JSX)
|
|
123
|
-
├── schema/ (25+ validation types)
|
|
124
|
-
├── rpc/ (Type-safe RPC)
|
|
125
|
-
└── cli/ (speexjs init, serve, make:*)
|
|
126
|
-
```
|
|
91
|
+
## CLI
|
|
127
92
|
|
|
128
|
-
|
|
93
|
+
| Command | Description |
|
|
94
|
+
|---------|-------------|
|
|
95
|
+
| `speexjs init` | Create a new project |
|
|
96
|
+
| `speexjs serve` | Start development server |
|
|
97
|
+
| `speexjs make:controller User` | Generate a controller |
|
|
98
|
+
| `speexjs make:middleware Auth` | Generate a middleware |
|
|
99
|
+
| `speexjs make:schema User` | Generate a schema |
|
|
100
|
+
| `speexjs list-routes` | Display all registered routes |
|
|
129
101
|
|
|
130
102
|
MIT
|