@gravito/mass 1.0.0-alpha.2 → 1.0.0-alpha.6

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 CHANGED
@@ -1,23 +1,23 @@
1
1
  # @gravito/mass
2
2
 
3
- TypeBox-based validation for Gravito - High-performance schema validation with full TypeScript support.
3
+ TypeBox-based validation for Gravito. High-performance schema validation with full TypeScript support.
4
4
 
5
- ## 特色
5
+ ## Features
6
6
 
7
- - **高效能驗證**: 基於 TypeBox,比 Zod 更快的執行速度
8
- - **完整 TypeScript 支援**: 自動推導型別,無需手動定義
9
- - **Hono 整合**: 完美整合 Hono 的驗證中間件
10
- - **多種資料來源**: 支援 JSON、Query、Param、Form 驗證
7
+ - **Fast validation**: TypeBox-powered validators with strong runtime performance
8
+ - **Full TypeScript support**: Type inference without manual typings
9
+ - **Hono integration**: Works seamlessly with Hono validation middleware
10
+ - **Multiple sources**: Validate JSON, query, params, and form data
11
11
 
12
- ## 安裝
12
+ ## Installation
13
13
 
14
14
  ```bash
15
15
  bun add @gravito/mass
16
16
  ```
17
17
 
18
- ## 基本使用
18
+ ## Quick Start
19
19
 
20
- ### JSON 驗證
20
+ ### JSON validation
21
21
 
22
22
  ```typescript
23
23
  import { Hono } from 'hono'
@@ -37,7 +37,7 @@ app.post('/login',
37
37
  )
38
38
  ```
39
39
 
40
- ### Query 參數驗證
40
+ ### Query validation
41
41
 
42
42
  ```typescript
43
43
  app.get('/search',
@@ -52,7 +52,7 @@ app.get('/search',
52
52
  )
53
53
  ```
54
54
 
55
- ### Route 參數驗證
55
+ ### Route param validation
56
56
 
57
57
  ```typescript
58
58
  app.get('/users/:id',
@@ -66,40 +66,33 @@ app.get('/users/:id',
66
66
  )
67
67
  ```
68
68
 
69
- ## Schema 建構器
69
+ ## Schema Builder
70
70
 
71
- `Schema` 物件提供所有 TypeBox 的建構器:
71
+ `Schema` exposes TypeBox constructors:
72
72
 
73
73
  ```typescript
74
74
  import { Schema } from '@gravito/mass'
75
75
 
76
- // 基本型別
77
76
  Schema.String()
78
77
  Schema.Number()
79
78
  Schema.Boolean()
80
79
  Schema.Array(Schema.String())
81
80
 
82
- // 物件
83
81
  Schema.Object({
84
82
  name: Schema.String(),
85
83
  age: Schema.Number()
86
84
  })
87
85
 
88
- // 選填欄位
89
86
  Schema.Optional(Schema.String())
90
-
91
- // 預設值
92
87
  Schema.String({ default: 'hello' })
93
-
94
- // 驗證規則
95
88
  Schema.String({ minLength: 2, maxLength: 100 })
96
89
  Schema.Number({ minimum: 0, maximum: 100 })
97
90
  Schema.String({ format: 'email' })
98
91
  ```
99
92
 
100
- ## Hono Client 整合
93
+ ## Hono Client Integration
101
94
 
102
- 使用 `app.route()` 方法串接路由模組,可以獲得完整的型別推導:
95
+ When you compose routes with `app.route()`, you get full type inference for the client:
103
96
 
104
97
  ```typescript
105
98
  // app.ts
@@ -113,8 +106,6 @@ export default app
113
106
  export type AppRoutes = typeof routes
114
107
  ```
115
108
 
116
- 前端使用時可以獲得完整的型別提示:
117
-
118
109
  ```typescript
119
110
  // client.ts
120
111
  import { hc } from 'hono/client'
@@ -124,22 +115,16 @@ export const createClient = (baseUrl: string) => {
124
115
  return hc<AppRoutes>(baseUrl)
125
116
  }
126
117
 
127
- // 使用時有完整的型別提示
128
118
  const client = createClient('http://localhost:3000')
129
119
  const result = await client.api.users.login.$post({
130
120
  json: { username: 'user', password: 'pass' }
131
121
  })
132
122
  ```
133
123
 
134
- ## 效能優勢
124
+ ## Performance Notes
135
125
 
136
- TypeBox 相較於 Zod 的優勢:
137
-
138
- - **編譯時驗證**: TypeBox 在編譯時生成驗證器,執行時效能更高
139
- - **更小的 bundle**: 產生的程式碼更小
140
- - **更好的型別推導**: 與 TypeScript 深度整合
126
+ TypeBox generates validators at build-time for faster runtime performance, smaller bundles, and strong TypeScript inference.
141
127
 
142
128
  ## License
143
129
 
144
130
  MIT
145
-
@@ -0,0 +1,29 @@
1
+ # @gravito/mass
2
+
3
+ > Gravito 的 TypeBox 驗證模組,提供高效能且完整的 TypeScript 支援。
4
+
5
+ ## 安裝
6
+
7
+ ```bash
8
+ bun add @gravito/mass
9
+ ```
10
+
11
+ ## 快速開始
12
+
13
+ ```typescript
14
+ import { Hono } from 'hono'
15
+ import { Schema, validate } from '@gravito/mass'
16
+
17
+ const app = new Hono()
18
+
19
+ app.post('/login',
20
+ validate('json', Schema.Object({
21
+ username: Schema.String(),
22
+ password: Schema.String()
23
+ })),
24
+ (c) => {
25
+ const { username } = c.req.valid('json')
26
+ return c.json({ success: true, message: `Welcome ${username}` })
27
+ }
28
+ )
29
+ ```
@@ -7,9 +7,11 @@ export type ValidationSource = 'json' | 'query' | 'param' | 'form';
7
7
  /**
8
8
  * Create a validation middleware.
9
9
  *
10
+ * Validates the request data against the provided TypeBox schema.
11
+ *
10
12
  * @param source - Validation source (json, query, param, form)
11
13
  * @param schema - TypeBox Schema
12
- * @returns Hono middleware
14
+ * @returns Hono middleware handler that validates the request.
13
15
  */
14
16
  export declare function validate<T extends TSchema, S extends ValidationSource, E extends Env = any, P extends string = any>(source: S, schema: T): MiddlewareHandler<E, P, {
15
17
  in: {
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAElD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;AAElE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,gBAAgB,EAC1B,CAAC,SAAS,GAAG,GAAG,GAAG,EACnB,CAAC,SAAS,MAAM,GAAG,GAAG,EAEtB,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,GACR,iBAAiB,CAClB,CAAC,EACD,CAAC,EACD;IACE,EAAE,EAAE;SAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;KAAE,CAAA;IAC3B,GAAG,EAAE;SAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;KAAE,CAAA;CAC7B,CACF,CAEA"}
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAElD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;AAElE;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CACtB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,gBAAgB,EAC1B,CAAC,SAAS,GAAG,GAAG,GAAG,EACnB,CAAC,SAAS,MAAM,GAAG,GAAG,EAEtB,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,GACR,iBAAiB,CAClB,CAAC,EACD,CAAC,EACD;IACE,EAAE,EAAE;SAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;KAAE,CAAA;IAC3B,GAAG,EAAE;SAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;KAAE,CAAA;CAC7B,CACF,CAEA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/mass",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "TypeBox-based validation for Gravito - High-performance schema validation with full TypeScript support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,10 +28,11 @@
28
28
  "@sinclair/typebox": "^0.34.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "hono": "^4.0.0"
31
+ "gravito-core": "1.0.0-beta.5"
32
32
  },
33
33
  "devDependencies": {
34
34
  "bun-types": "^1.1.0",
35
+ "hono": "^4.0.0",
35
36
  "typescript": "^5.0.0"
36
37
  },
37
38
  "author": "Carl Lee <carllee0520@gmail.com>",
@@ -46,7 +47,6 @@
46
47
  "validation",
47
48
  "typebox",
48
49
  "schema",
49
- "hono",
50
50
  "middleware",
51
51
  "typescript"
52
52
  ],