MCPcopy Index your code
hub / github.com/decs/typeschema

github.com/decs/typeschema @v0.13.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.13.1 ↗ · + Follow
64 symbols 444 edges 137 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

TypeSchema

TypeSchema

Universal adapter for schema validation

https://typeschema.com

License Bundle size npm downloads GitHub stars

Quickstart   •   Coverage   •   API   •   GitHub   •   npm

When fetching data from an external source, it's important to verify its integrity. This happens when processing user inputs, calling third-party APIs, loading configuration files, and so on. And the thing is: Typescript doesn't come with runtime validation. Any type assertions are removed at compile-time.

As a result, developers turn to third-party validation libraries. But that landscape is fragmented, lacking a single best option. Each offers different trade-offs on developer experience, bundle size, and community support.

TypeSchema enables writing code that works with any validation library out-of-the-box. It provides a universal adapter for interacting with any validation schema, decoupling from implementation specifics and increasing compatibility.

import {validate} from '@typeschema/main';

import {z} from 'zod';
import {string} from 'valibot';

const zodSchema = z.string();
await validate(zodSchema, '123');
//    ^? {success: true, data: '123'}

const valibotSchema = string();
await validate(valibotSchema, 123);
//    ^? {success: false, issues: [...]}

Quickstart

We value flexibility, which is why there are multiple ways of using TypeSchema: 1. Using an adapter directly (e.g. @typeschema/valibot): Best pick for end developers, when the validation library is known ahead of time. This is particularly useful for supporting more validation libraries on tRPC. 2. Handpicking adapters with @typeschema/main: Recommended for library maintainers. Any validation library can be used, but adapters have to be explicitly installed. This allows end developers to trade-off between coverage and bundle size. 3. Batteries included with @typeschema/all: Easiest to use. All adapters are automatically installed, including future ones. This is a drop-in replacement for the deprecated @decs/typeschema.

Coverage

Project Popularity Infer InferIn Validation Serialization Adapter
zod GitHub stars @typeschema/zod
yup GitHub stars @typeschema/yup
joi GitHub stars 🧐 🧐 🧐 @typeschema/joi
ajv GitHub stars 🧐 🧐 @typeschema/json
superstruct GitHub stars 🧐 🧐 @typeschema/superstruct
io-ts GitHub stars 🧐 @typeschema/io-ts
valibot GitHub stars @typeschema/valibot
typebox GitHub stars 🧐 @typeschema/typebox
typia GitHub stars 🧐 @typeschema/function
ow GitHub stars 🧐 @typeschema/ow
effect GitHub stars 🧐 @typeschema/effect
arktype GitHub stars 🧐 @typeschema/arktype
deepkit GitHub stars 🧐 🧐 🧐 @typeschema/deepkit
runtypes GitHub stars 🧐 @typeschema/runtypes

API

Inference

  • Infer<TSchema>: Extracts the output type of a schema
  • InferIn<TSchema>: Extracts the input type of a schema

Validation

  • wrap(schema): Returns the wrapped schema with access to its operations
  • validate(schema, data): Returns the validated data or a list of validation issues
  • assert(schema, data): Returns the validated data or throws an AggregateError

Serialization

  • toJSONSchema(schema): Converts the schema into the equivalent JSON schema

Acknowledgements

Extension points exported contracts — how you extend this code

AdapterResolver (Interface)
(no doc)
packages/joi/src/resolver.ts
AdapterResolver (Interface)
(no doc)
packages/function/src/resolver.ts
AdapterResolver (Interface)
(no doc)
packages/io-ts/src/resolver.ts
AdapterResolver (Interface)
(no doc)
packages/runtypes/src/resolver.ts
AdapterResolver (Interface)
(no doc)
packages/yup/src/resolver.ts
AdapterResolver (Interface)
(no doc)
packages/ow/src/resolver.ts
Resolver (Interface)
(no doc)
packages/core/src/resolver.ts
AdapterResolver (Interface)
(no doc)
packages/superstruct/src/resolver.ts

Core symbols most depended-on inside this repo

memoize
called by 29
packages/core/src/utils.ts
createWrap
called by 16
packages/core/src/wrap.ts
createValidate
called by 16
packages/core/src/validation.ts
createAssert
called by 16
packages/core/src/validation.ts
unsupportedAdapter
called by 10
packages/core/src/utils.ts
notJSON
called by 10
packages/main/src/selector.ts
createToJSONSchema
called by 6
packages/core/src/serialization.ts
getAddAction
called by 4
turbo/generators/config.ts

Shape

Function 48
Interface 16

Languages

TypeScript100%

Modules by API surface

turbo/generators/config.ts5 symbols
packages/core/src/utils.ts4 symbols
packages/main/src/selector.ts3 symbols
www/components/Hero.tsx2 symbols
packages/main/src/__tests__/function.test.ts2 symbols
packages/function/src/__tests__/function.test.ts2 symbols
packages/core/src/validation.ts2 symbols
packages/all/src/__tests__/function.test.ts2 symbols
www/theme.config.tsx1 symbols
packages/zod/src/validation.ts1 symbols
packages/zod/src/serialization.ts1 symbols
packages/zod/src/resolver.ts1 symbols

For agents

$ claude mcp add typeschema \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page