@veloxts/validation 0.6.91 → 0.6.93
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/CHANGELOG.md +16 -0
- package/GUIDE.md +36 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @veloxts/validation
|
|
2
2
|
|
|
3
|
+
## 0.6.93
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat(router): add Resource API with phantom types for context-dependent outputs
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @veloxts/core@0.6.93
|
|
10
|
+
|
|
11
|
+
## 0.6.92
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- feat(storage): add provider factories, lifecycle hooks, and presigned uploads
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @veloxts/core@0.6.92
|
|
18
|
+
|
|
3
19
|
## 0.6.91
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/GUIDE.md
CHANGED
|
@@ -183,6 +183,42 @@ export const userProcedures = procedures('users', {
|
|
|
183
183
|
});
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
+
## Resource API with Zod Schemas
|
|
187
|
+
|
|
188
|
+
For context-dependent outputs, use `resourceSchema()` with Zod field schemas:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { resourceSchema, resource } from '@veloxts/router';
|
|
192
|
+
import { z } from '@veloxts/validation';
|
|
193
|
+
|
|
194
|
+
// Define field visibility with Zod schemas
|
|
195
|
+
const UserSchema = resourceSchema()
|
|
196
|
+
.public('id', z.string().uuid())
|
|
197
|
+
.public('name', z.string())
|
|
198
|
+
.authenticated('email', z.string().email())
|
|
199
|
+
.admin('internalNotes', z.string().nullable())
|
|
200
|
+
.build();
|
|
201
|
+
|
|
202
|
+
// Returns different fields based on access level
|
|
203
|
+
const publicUser = resource(user, UserSchema).forAnonymous();
|
|
204
|
+
// Type: { id: string; name: string }
|
|
205
|
+
|
|
206
|
+
const authUser = resource(user, UserSchema).forAuthenticated();
|
|
207
|
+
// Type: { id: string; name: string; email: string }
|
|
208
|
+
|
|
209
|
+
const adminUser = resource(user, UserSchema).forAdmin();
|
|
210
|
+
// Type: { id: string; name: string; email: string; internalNotes: string | null }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### When to Use Each Approach
|
|
214
|
+
|
|
215
|
+
| Scenario | Approach |
|
|
216
|
+
|----------|----------|
|
|
217
|
+
| Same output for all users | `.output(zodSchema)` |
|
|
218
|
+
| Different fields per role | `resourceSchema()` + `resource()` |
|
|
219
|
+
| Input validation | `.input(zodSchema)` |
|
|
220
|
+
| Complex transforms | `.output()` with Zod transforms |
|
|
221
|
+
|
|
186
222
|
## Error Handling
|
|
187
223
|
|
|
188
224
|
Validation errors include field-level details:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veloxts/validation",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.93",
|
|
4
4
|
"description": "Zod integration and validation middleware for VeloxTS framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"zod": "3.25.76",
|
|
26
|
-
"@veloxts/core": "0.6.
|
|
26
|
+
"@veloxts/core": "0.6.93"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@vitest/coverage-v8": "4.0.18",
|