@veloxts/validation 0.6.25 → 0.6.27
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 +499 -0
- package/GUIDE.md +216 -0
- package/package.json +6 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
# @veloxts/validation
|
|
2
|
+
|
|
3
|
+
## 0.6.27
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- chore: add GUIDE, LICENSE and CHANGELOG.md to npm files
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @veloxts/core@0.6.27
|
|
10
|
+
|
|
11
|
+
## 0.6.26
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- docs(mcp): add README and GUIDE, docs(web): simplify README and create concise GUIDE
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @veloxts/core@0.6.26
|
|
18
|
+
|
|
19
|
+
## 0.6.25
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- docs(create): add guide for React Server Components setup
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
- @veloxts/core@0.6.25
|
|
26
|
+
|
|
27
|
+
## 0.6.24
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- clarify installation paths and package contents
|
|
32
|
+
- Updated dependencies
|
|
33
|
+
- @veloxts/core@0.6.24
|
|
34
|
+
|
|
35
|
+
## 0.6.23
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- add defineContract for improved type inference DX
|
|
40
|
+
- Updated dependencies
|
|
41
|
+
- @veloxts/core@0.6.23
|
|
42
|
+
|
|
43
|
+
## 0.6.22
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- support {method, path} route entry format
|
|
48
|
+
- Updated dependencies
|
|
49
|
+
- @veloxts/core@0.6.22
|
|
50
|
+
|
|
51
|
+
## 0.6.21
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- separate schemas from procedures for browser-safe import
|
|
56
|
+
- Updated dependencies
|
|
57
|
+
- @veloxts/core@0.6.21
|
|
58
|
+
|
|
59
|
+
## 0.6.20
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- add Fastify ecosystem stubs and debuglog to util
|
|
64
|
+
- Updated dependencies
|
|
65
|
+
- @veloxts/core@0.6.20
|
|
66
|
+
|
|
67
|
+
## 0.6.19
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- restore dotenv stub for browser compatibility
|
|
72
|
+
- Updated dependencies
|
|
73
|
+
- @veloxts/core@0.6.19
|
|
74
|
+
|
|
75
|
+
## 0.6.18
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- add node:fs/promises stub and fix esbuild plugin
|
|
80
|
+
- Updated dependencies
|
|
81
|
+
- @veloxts/core@0.6.18
|
|
82
|
+
|
|
83
|
+
## 0.6.17
|
|
84
|
+
|
|
85
|
+
### Patch Changes
|
|
86
|
+
|
|
87
|
+
- remove optimizeDeps.exclude to fix CJS/ESM interop
|
|
88
|
+
- Updated dependencies
|
|
89
|
+
- @veloxts/core@0.6.17
|
|
90
|
+
|
|
91
|
+
## 0.6.16
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- add stubs for Fastify ecosystem packages
|
|
96
|
+
- Updated dependencies
|
|
97
|
+
- @veloxts/core@0.6.16
|
|
98
|
+
|
|
99
|
+
## 0.6.15
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- implement three-layer Node.js stubbing for Vite
|
|
104
|
+
- Updated dependencies
|
|
105
|
+
- @veloxts/core@0.6.15
|
|
106
|
+
|
|
107
|
+
## 0.6.14
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- stub dotenv as virtual module instead of process shims
|
|
112
|
+
- Updated dependencies
|
|
113
|
+
- @veloxts/core@0.6.14
|
|
114
|
+
|
|
115
|
+
## 0.6.13
|
|
116
|
+
|
|
117
|
+
### Patch Changes
|
|
118
|
+
|
|
119
|
+
- add process.argv stub for dotenv browser compatibility
|
|
120
|
+
- Updated dependencies
|
|
121
|
+
- @veloxts/core@0.6.13
|
|
122
|
+
|
|
123
|
+
## 0.6.12
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- Fixes the "process is not defined" error from dotenv
|
|
128
|
+
- Updated dependencies
|
|
129
|
+
- @veloxts/core@0.6.12
|
|
130
|
+
|
|
131
|
+
## 0.6.11
|
|
132
|
+
|
|
133
|
+
### Patch Changes
|
|
134
|
+
|
|
135
|
+
- add Vite plugin for Node.js module stubs
|
|
136
|
+
- Updated dependencies
|
|
137
|
+
- @veloxts/core@0.6.11
|
|
138
|
+
|
|
139
|
+
## 0.6.10
|
|
140
|
+
|
|
141
|
+
### Patch Changes
|
|
142
|
+
|
|
143
|
+
- use import() type syntax for AppRouter
|
|
144
|
+
- Updated dependencies
|
|
145
|
+
- @veloxts/core@0.6.10
|
|
146
|
+
|
|
147
|
+
## 0.6.9
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- isolate auth procedures from database imports
|
|
152
|
+
- Updated dependencies
|
|
153
|
+
- @veloxts/core@0.6.9
|
|
154
|
+
|
|
155
|
+
## 0.6.8
|
|
156
|
+
|
|
157
|
+
### Patch Changes
|
|
158
|
+
|
|
159
|
+
- prevent dotenv from leaking into browser bundle
|
|
160
|
+
- Updated dependencies
|
|
161
|
+
- @veloxts/core@0.6.8
|
|
162
|
+
|
|
163
|
+
## 0.6.7
|
|
164
|
+
|
|
165
|
+
### Patch Changes
|
|
166
|
+
|
|
167
|
+
- better-sqlite3 versions mismatch fix
|
|
168
|
+
- Updated dependencies
|
|
169
|
+
- @veloxts/core@0.6.7
|
|
170
|
+
|
|
171
|
+
## 0.6.6
|
|
172
|
+
|
|
173
|
+
### Patch Changes
|
|
174
|
+
|
|
175
|
+
- ensure the web app never imports server-side code paths
|
|
176
|
+
- Updated dependencies
|
|
177
|
+
- @veloxts/core@0.6.6
|
|
178
|
+
|
|
179
|
+
## 0.6.5
|
|
180
|
+
|
|
181
|
+
### Patch Changes
|
|
182
|
+
|
|
183
|
+
- move @prisma/client-runtime-utils to root package.json
|
|
184
|
+
- Updated dependencies
|
|
185
|
+
- @veloxts/core@0.6.5
|
|
186
|
+
|
|
187
|
+
## 0.6.4
|
|
188
|
+
|
|
189
|
+
### Patch Changes
|
|
190
|
+
|
|
191
|
+
- add @prisma/client-runtime-utils dependency
|
|
192
|
+
- Updated dependencies
|
|
193
|
+
- @veloxts/core@0.6.4
|
|
194
|
+
|
|
195
|
+
## 0.6.3
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- Add workspaces field to root package.json template + Fix Prisma ESM/CJS import for Node.js v24
|
|
200
|
+
- Updated dependencies
|
|
201
|
+
- @veloxts/core@0.6.3
|
|
202
|
+
|
|
203
|
+
## 0.6.2
|
|
204
|
+
|
|
205
|
+
### Patch Changes
|
|
206
|
+
|
|
207
|
+
- add server actions, removed some deprecated and other chore
|
|
208
|
+
- Updated dependencies
|
|
209
|
+
- @veloxts/core@0.6.2
|
|
210
|
+
|
|
211
|
+
## 0.6.1
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- route groups for file-based routing; add dynamic route support with [param] segments
|
|
216
|
+
- Updated dependencies
|
|
217
|
+
- @veloxts/core@0.6.1
|
|
218
|
+
|
|
219
|
+
## 0.6.0
|
|
220
|
+
|
|
221
|
+
### Minor Changes
|
|
222
|
+
|
|
223
|
+
- RSC streaming, dynamic routes, Vinxi integration
|
|
224
|
+
|
|
225
|
+
### Patch Changes
|
|
226
|
+
|
|
227
|
+
- Updated dependencies
|
|
228
|
+
- @veloxts/core@0.6.0
|
|
229
|
+
|
|
230
|
+
## 0.5.0
|
|
231
|
+
|
|
232
|
+
### Minor Changes
|
|
233
|
+
|
|
234
|
+
- Auto-register procedures + inject Prisma models feature
|
|
235
|
+
|
|
236
|
+
### Patch Changes
|
|
237
|
+
|
|
238
|
+
- Updated dependencies
|
|
239
|
+
- @veloxts/core@0.5.0
|
|
240
|
+
|
|
241
|
+
## 0.4.21
|
|
242
|
+
|
|
243
|
+
### Patch Changes
|
|
244
|
+
|
|
245
|
+
- format Prisma default values correctly by type
|
|
246
|
+
- Updated dependencies
|
|
247
|
+
- @veloxts/core@0.4.21
|
|
248
|
+
|
|
249
|
+
## 0.4.20
|
|
250
|
+
|
|
251
|
+
### Patch Changes
|
|
252
|
+
|
|
253
|
+
- import consolidation: update import paths for `@veloxts/velox`
|
|
254
|
+
- Updated dependencies
|
|
255
|
+
- @veloxts/core@0.4.20
|
|
256
|
+
|
|
257
|
+
## 0.4.19
|
|
258
|
+
|
|
259
|
+
### Patch Changes
|
|
260
|
+
|
|
261
|
+
- update default dev server port to 3030
|
|
262
|
+
- Updated dependencies
|
|
263
|
+
- @veloxts/core@0.4.19
|
|
264
|
+
|
|
265
|
+
## 0.4.18
|
|
266
|
+
|
|
267
|
+
### Patch Changes
|
|
268
|
+
|
|
269
|
+
- introduce interactive field menu and templates for resource generation
|
|
270
|
+
- Updated dependencies
|
|
271
|
+
- @veloxts/core@0.4.18
|
|
272
|
+
|
|
273
|
+
## 0.4.17
|
|
274
|
+
|
|
275
|
+
### Patch Changes
|
|
276
|
+
|
|
277
|
+
- add interactive field prompts for resource generation
|
|
278
|
+
- Updated dependencies
|
|
279
|
+
- @veloxts/core@0.4.17
|
|
280
|
+
|
|
281
|
+
## 0.4.16
|
|
282
|
+
|
|
283
|
+
### Patch Changes
|
|
284
|
+
|
|
285
|
+
- fixed velox procedures list
|
|
286
|
+
- Updated dependencies
|
|
287
|
+
- @veloxts/core@0.4.16
|
|
288
|
+
|
|
289
|
+
## 0.4.15
|
|
290
|
+
|
|
291
|
+
### Patch Changes
|
|
292
|
+
|
|
293
|
+
- chore lint fixes
|
|
294
|
+
- Updated dependencies
|
|
295
|
+
- @veloxts/core@0.4.15
|
|
296
|
+
|
|
297
|
+
## 0.4.14
|
|
298
|
+
|
|
299
|
+
### Patch Changes
|
|
300
|
+
|
|
301
|
+
- fixed proxy-type inferance and update proxy hooks for optional input handling
|
|
302
|
+
- Updated dependencies
|
|
303
|
+
- @veloxts/core@0.4.14
|
|
304
|
+
|
|
305
|
+
## 0.4.13
|
|
306
|
+
|
|
307
|
+
### Patch Changes
|
|
308
|
+
|
|
309
|
+
- add debug mode to dev server
|
|
310
|
+
- Updated dependencies
|
|
311
|
+
- @veloxts/core@0.4.13
|
|
312
|
+
|
|
313
|
+
## 0.4.12
|
|
314
|
+
|
|
315
|
+
### Patch Changes
|
|
316
|
+
|
|
317
|
+
- preserve type info in trpc template AppRouter export
|
|
318
|
+
- Updated dependencies
|
|
319
|
+
- @veloxts/core@0.4.12
|
|
320
|
+
|
|
321
|
+
## 0.4.11
|
|
322
|
+
|
|
323
|
+
### Patch Changes
|
|
324
|
+
|
|
325
|
+
- fixed api.health.check.useQuery is not a function issue
|
|
326
|
+
- Updated dependencies
|
|
327
|
+
- @veloxts/core@0.4.11
|
|
328
|
+
|
|
329
|
+
## 0.4.10
|
|
330
|
+
|
|
331
|
+
### Patch Changes
|
|
332
|
+
|
|
333
|
+
- fixed ReferenceError: styles is not defined in rpc template
|
|
334
|
+
- Updated dependencies
|
|
335
|
+
- @veloxts/core@0.4.10
|
|
336
|
+
|
|
337
|
+
## 0.4.7
|
|
338
|
+
|
|
339
|
+
### Patch Changes
|
|
340
|
+
|
|
341
|
+
- Add dynamic headers and routes config to client
|
|
342
|
+
- Updated dependencies
|
|
343
|
+
- @veloxts/core@0.4.7
|
|
344
|
+
|
|
345
|
+
## 0.4.6
|
|
346
|
+
|
|
347
|
+
### Patch Changes
|
|
348
|
+
|
|
349
|
+
- Fix broken npm packages - republish with correct dependencies
|
|
350
|
+
- Updated dependencies
|
|
351
|
+
- @veloxts/core@0.4.6
|
|
352
|
+
|
|
353
|
+
## 0.4.5
|
|
354
|
+
|
|
355
|
+
### Patch Changes
|
|
356
|
+
|
|
357
|
+
- b06631b: CI CD npm Trusted Publishing setup
|
|
358
|
+
- Updated dependencies [b06631b]
|
|
359
|
+
- @veloxts/core@0.4.5
|
|
360
|
+
|
|
361
|
+
## 0.4.4
|
|
362
|
+
|
|
363
|
+
### Patch Changes
|
|
364
|
+
|
|
365
|
+
- 05ae1a5: Update to boilerplate, work in progress
|
|
366
|
+
- 9961b52: full-stack React frontend implementation
|
|
367
|
+
- Updated dependencies [05ae1a5]
|
|
368
|
+
- Updated dependencies [9961b52]
|
|
369
|
+
- @veloxts/core@0.4.4
|
|
370
|
+
|
|
371
|
+
## 0.4.3
|
|
372
|
+
|
|
373
|
+
### Patch Changes
|
|
374
|
+
|
|
375
|
+
- ef8d5d0: Dynamically load VeloxTS version from `package.json` in shared template configuration
|
|
376
|
+
- Updated dependencies [ef8d5d0]
|
|
377
|
+
- @veloxts/core@0.4.3
|
|
378
|
+
|
|
379
|
+
## 0.4.2
|
|
380
|
+
|
|
381
|
+
### Patch Changes
|
|
382
|
+
|
|
383
|
+
- 5b4f02c: Updated documentations
|
|
384
|
+
- 0d8d775: Updated guides and readme files
|
|
385
|
+
- Updated dependencies [5b4f02c]
|
|
386
|
+
- Updated dependencies [0d8d775]
|
|
387
|
+
- @veloxts/core@0.4.2
|
|
388
|
+
|
|
389
|
+
## 0.4.1
|
|
390
|
+
|
|
391
|
+
### Patch Changes
|
|
392
|
+
|
|
393
|
+
- 0eea918: Completed CLI generators
|
|
394
|
+
- Updated dependencies [0eea918]
|
|
395
|
+
- @veloxts/core@0.4.1
|
|
396
|
+
|
|
397
|
+
## 0.4.0
|
|
398
|
+
|
|
399
|
+
### Minor Changes
|
|
400
|
+
|
|
401
|
+
- b478fee: Performance Benchmarks | 34k req/s, <1ms p50 latency, 75MB memory, 530ms startup
|
|
402
|
+
|
|
403
|
+
### Patch Changes
|
|
404
|
+
|
|
405
|
+
- Updated dependencies [b478fee]
|
|
406
|
+
- @veloxts/core@0.4.0
|
|
407
|
+
|
|
408
|
+
## 0.3.6
|
|
409
|
+
|
|
410
|
+
### Patch Changes
|
|
411
|
+
|
|
412
|
+
- 929f2ab: Interactive CLI setup
|
|
413
|
+
- Updated dependencies [929f2ab]
|
|
414
|
+
- @veloxts/core@0.3.6
|
|
415
|
+
|
|
416
|
+
## 0.3.5
|
|
417
|
+
|
|
418
|
+
### Patch Changes
|
|
419
|
+
|
|
420
|
+
- 658e83f: @veloxts/auth, Full REST Support, Better error messages, Type tests with tsd
|
|
421
|
+
- Updated dependencies [658e83f]
|
|
422
|
+
- @veloxts/core@0.3.5
|
|
423
|
+
|
|
424
|
+
## 0.3.4
|
|
425
|
+
|
|
426
|
+
### Patch Changes
|
|
427
|
+
|
|
428
|
+
- 65ef3e7: DI container and Auth Guards
|
|
429
|
+
- Updated dependencies [65ef3e7]
|
|
430
|
+
- @veloxts/core@0.3.4
|
|
431
|
+
|
|
432
|
+
## 0.3.3
|
|
433
|
+
|
|
434
|
+
### Patch Changes
|
|
435
|
+
|
|
436
|
+
- 4ee103b: Full REST support PUT, PATCH and DELETE
|
|
437
|
+
- Updated dependencies [4ee103b]
|
|
438
|
+
- @veloxts/core@0.3.3
|
|
439
|
+
|
|
440
|
+
## 0.3.2
|
|
441
|
+
|
|
442
|
+
### Patch Changes
|
|
443
|
+
|
|
444
|
+
- abf270e: Dynamically set core `VELOX_VERSION` from package.json
|
|
445
|
+
- Updated dependencies [abf270e]
|
|
446
|
+
- @veloxts/core@0.3.2
|
|
447
|
+
|
|
448
|
+
## 0.3.1
|
|
449
|
+
|
|
450
|
+
### Patch Changes
|
|
451
|
+
|
|
452
|
+
- cb9806e: Fixed the value for VELOXTS_VERSION in create app template
|
|
453
|
+
- Updated dependencies [cb9806e]
|
|
454
|
+
- @veloxts/core@0.3.1
|
|
455
|
+
|
|
456
|
+
## 0.3.0
|
|
457
|
+
|
|
458
|
+
### Minor Changes
|
|
459
|
+
|
|
460
|
+
- 1adce10: Introduced an umbrella package for server side packages: @veloxts/velox
|
|
461
|
+
|
|
462
|
+
### Patch Changes
|
|
463
|
+
|
|
464
|
+
- Updated dependencies [1adce10]
|
|
465
|
+
- @veloxts/core@0.3.0
|
|
466
|
+
|
|
467
|
+
## 0.2.2
|
|
468
|
+
|
|
469
|
+
### Patch Changes
|
|
470
|
+
|
|
471
|
+
- Version bump to sync with create-velox-app native module fix
|
|
472
|
+
- Updated dependencies
|
|
473
|
+
- @veloxts/core@0.2.2
|
|
474
|
+
|
|
475
|
+
## 0.2.0
|
|
476
|
+
|
|
477
|
+
### Minor Changes
|
|
478
|
+
|
|
479
|
+
- 9404976: fix Prisma client generation. README adjustments
|
|
480
|
+
|
|
481
|
+
### Patch Changes
|
|
482
|
+
|
|
483
|
+
- Updated dependencies [9404976]
|
|
484
|
+
- @veloxts/core@0.2.0
|
|
485
|
+
|
|
486
|
+
## 0.1.1
|
|
487
|
+
|
|
488
|
+
### Patch Changes
|
|
489
|
+
|
|
490
|
+
- Fix Prisma client generation in scaffolder
|
|
491
|
+
|
|
492
|
+
- Added automatic Prisma client generation after dependency installation in create-velox-app
|
|
493
|
+
- Fixed database template to validate DATABASE_URL environment variable
|
|
494
|
+
- Added alpha release warning to all package READMEs
|
|
495
|
+
- Fixed TypeScript type for registerTRPCPlugin to accept FastifyInstance
|
|
496
|
+
- Updated playground app to use Prisma 7.x custom output path
|
|
497
|
+
|
|
498
|
+
- Updated dependencies
|
|
499
|
+
- @veloxts/core@0.1.1
|
package/GUIDE.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# @veloxts/validation
|
|
2
|
+
|
|
3
|
+
Type-safe validation using Zod schemas for VeloxTS Framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @veloxts/validation
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { z, parse } from '@veloxts/validation';
|
|
15
|
+
|
|
16
|
+
const UserSchema = z.object({
|
|
17
|
+
id: z.string().uuid(),
|
|
18
|
+
name: z.string().min(1),
|
|
19
|
+
email: z.string().email(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const user = parse(UserSchema, untrustedData);
|
|
23
|
+
// user is validated and typed
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Validation Functions
|
|
27
|
+
|
|
28
|
+
### parse()
|
|
29
|
+
|
|
30
|
+
Parse and validate data, throwing `ValidationError` if invalid:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { parse, ValidationError } from '@veloxts/validation';
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const user = parse(UserSchema, data);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof ValidationError) {
|
|
39
|
+
console.log(error.fields); // Field-specific errors
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### safeParse()
|
|
45
|
+
|
|
46
|
+
Validate without throwing, returns result object:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { safeParse } from '@veloxts/validation';
|
|
50
|
+
|
|
51
|
+
const result = safeParse(UserSchema, data);
|
|
52
|
+
|
|
53
|
+
if (result.success) {
|
|
54
|
+
console.log(result.data);
|
|
55
|
+
} else {
|
|
56
|
+
console.log(result.error.issues);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Common Schemas
|
|
61
|
+
|
|
62
|
+
Pre-built schemas for common use cases:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import {
|
|
66
|
+
uuidSchema,
|
|
67
|
+
emailSchema,
|
|
68
|
+
urlSchema,
|
|
69
|
+
nonEmptyStringSchema,
|
|
70
|
+
datetimeSchema,
|
|
71
|
+
idParamSchema,
|
|
72
|
+
} from '@veloxts/validation';
|
|
73
|
+
|
|
74
|
+
const id = parse(uuidSchema, '123e4567-...');
|
|
75
|
+
const email = parse(emailSchema, 'user@example.com');
|
|
76
|
+
const url = parse(urlSchema, 'https://example.com');
|
|
77
|
+
const name = parse(nonEmptyStringSchema, ' Alice '); // "Alice"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Pagination
|
|
81
|
+
|
|
82
|
+
Built-in pagination support:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import {
|
|
86
|
+
paginationInputSchema,
|
|
87
|
+
createPaginatedResponseSchema,
|
|
88
|
+
calculatePaginationMeta,
|
|
89
|
+
} from '@veloxts/validation';
|
|
90
|
+
|
|
91
|
+
const input = parse(paginationInputSchema, {
|
|
92
|
+
page: 1,
|
|
93
|
+
limit: 20, // Default: 10, max: 100
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const UserListSchema = createPaginatedResponseSchema(UserSchema);
|
|
97
|
+
|
|
98
|
+
const meta = calculatePaginationMeta({
|
|
99
|
+
page: 1,
|
|
100
|
+
limit: 10,
|
|
101
|
+
total: 95,
|
|
102
|
+
});
|
|
103
|
+
// { page: 1, limit: 10, total: 95, totalPages: 10, hasNext: true, hasPrev: false }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Schema Utilities
|
|
107
|
+
|
|
108
|
+
Manipulate schemas:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { pickFields, omitFields, makePartial, partialExcept } from '@veloxts/validation';
|
|
112
|
+
|
|
113
|
+
const UserSchema = z.object({
|
|
114
|
+
id: z.string().uuid(),
|
|
115
|
+
name: z.string(),
|
|
116
|
+
email: z.string().email(),
|
|
117
|
+
password: z.string(),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const PublicUserSchema = pickFields(UserSchema, ['id', 'name', 'email']);
|
|
121
|
+
const SafeUserSchema = omitFields(UserSchema, ['password']);
|
|
122
|
+
const PartialUserSchema = makePartial(UserSchema);
|
|
123
|
+
const UpdateSchema = partialExcept(UserSchema, ['id']);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## String Coercion
|
|
127
|
+
|
|
128
|
+
Parse string inputs to other types:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import {
|
|
132
|
+
numberStringSchema,
|
|
133
|
+
integerStringSchema,
|
|
134
|
+
booleanStringSchema,
|
|
135
|
+
} from '@veloxts/validation';
|
|
136
|
+
|
|
137
|
+
const age = parse(numberStringSchema, '25'); // 25 (number)
|
|
138
|
+
const count = parse(integerStringSchema, '42'); // 42 (number)
|
|
139
|
+
const enabled = parse(booleanStringSchema, 'true'); // true (boolean)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Type Inference
|
|
143
|
+
|
|
144
|
+
Extract TypeScript types from schemas:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { InferInput, InferOutput } from '@veloxts/validation';
|
|
148
|
+
|
|
149
|
+
const UserSchema = z.object({
|
|
150
|
+
email: z.string().email(),
|
|
151
|
+
age: z.number().transform((n) => n + 1),
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
type UserInput = InferInput<typeof UserSchema>;
|
|
155
|
+
// { email: string; age: number }
|
|
156
|
+
|
|
157
|
+
type UserOutput = InferOutput<typeof UserSchema>;
|
|
158
|
+
// { email: string; age: number } (after transform)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Using with Procedures
|
|
162
|
+
|
|
163
|
+
Validation integrates seamlessly with VeloxTS procedures:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { procedure, defineProcedures } from '@veloxts/router';
|
|
167
|
+
import { z, emailSchema, nonEmptyStringSchema } from '@veloxts/validation';
|
|
168
|
+
|
|
169
|
+
const CreateUserInput = z.object({
|
|
170
|
+
name: nonEmptyStringSchema,
|
|
171
|
+
email: emailSchema,
|
|
172
|
+
age: z.number().int().min(18).optional(),
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
export const userProcedures = defineProcedures('users', {
|
|
176
|
+
createUser: procedure()
|
|
177
|
+
.input(CreateUserInput)
|
|
178
|
+
.output(UserSchema)
|
|
179
|
+
.mutation(async ({ input, ctx }) => {
|
|
180
|
+
// input is validated and typed
|
|
181
|
+
return ctx.db.user.create({ data: input });
|
|
182
|
+
}),
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Error Handling
|
|
187
|
+
|
|
188
|
+
Validation errors include field-level details:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { ValidationError, parse } from '@veloxts/validation';
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
parse(UserSchema, invalidData);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof ValidationError) {
|
|
197
|
+
console.log(error.statusCode); // 400
|
|
198
|
+
console.log(error.fields);
|
|
199
|
+
// {
|
|
200
|
+
// name: "String must contain at least 2 character(s)",
|
|
201
|
+
// email: "Invalid email"
|
|
202
|
+
// }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Learn More
|
|
208
|
+
|
|
209
|
+
- [@veloxts/core](https://www.npmjs.com/package/@veloxts/core) - Error classes
|
|
210
|
+
- [@veloxts/router](https://www.npmjs.com/package/@veloxts/router) - Procedure definitions
|
|
211
|
+
- [@veloxts/client](https://www.npmjs.com/package/@veloxts/client) - Type-safe client
|
|
212
|
+
- [VeloxTS Framework](https://www.npmjs.com/package/@veloxts/velox) - Complete framework
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veloxts/validation",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.27",
|
|
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.27"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@vitest/coverage-v8": "4.0.16",
|
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist",
|
|
43
|
-
"README.md"
|
|
43
|
+
"README.md",
|
|
44
|
+
"GUIDE.md",
|
|
45
|
+
"LICENSE",
|
|
46
|
+
"CHANGELOG.md"
|
|
44
47
|
],
|
|
45
48
|
"keywords": [
|
|
46
49
|
"velox",
|