Commit c1deeeb
committed
feat(validation): universal validateSchema for TypeBox + Zod
Adds `validateSchema` / `parseSchema` at `@socketsecurity/lib/validation/validate-schema` — a single structurally-dispatched entry point that accepts TypeBox schemas, Zod v3/v4 schemas, or any `safeParse`-shaped duck type, and returns a tagged `{ ok, value | errors }` result with normalized `{ path, message }` issues across all validator backends. Type inference flows through: Zod users get `z.infer<…>`, TypeBox users get `Static<…>`, no casts.
Migrates the bundled external from `zod` to `@sinclair/typebox` since TypeBox is the only backend whose runtime we eagerly need (`Value.Check` / `Value.Errors`); Zod is detected purely via `.safeParse`, so it stays a pinned devDep used by tests that verify the Zod path. `ipc.ts`'s stub schema switches from `z.object(...)` to `Type.Object(...)` + `parseSchema` to prove the new path end-to-end.
Drops `./zod` subpath export + `src/zod.ts` + `src/external/zod.*` + `test/unit/zod.test.mts` (the wrapper has no consumers now that validation goes through the universal helper). TypeBox is bundled as `dist/external/@sinclair/typebox.js` (+ `/value.js` subpath) so consumers of `@socketsecurity/lib` do not need to install `@sinclair/typebox` themselves.1 parent 94c67b5 commit c1deeeb
15 files changed
Lines changed: 474 additions & 163 deletions
File tree
- docs
- scripts/build-externals
- src
- external
- @sinclair
- typebox
- validation
- test/unit
- validation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| |||
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
666 | 670 | | |
667 | 671 | | |
668 | 672 | | |
| |||
671 | 675 | | |
672 | 676 | | |
673 | 677 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
| |||
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
| 723 | + | |
723 | 724 | | |
724 | 725 | | |
725 | 726 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | 52 | | |
55 | 53 | | |
56 | 54 | | |
| |||
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
89 | 100 | | |
90 | 101 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
This file was deleted.
This file was deleted.
0 commit comments