TypeScript transformer that compiles pure TypeScript types into runtime validators, JSON serializers, protobuf codecs and random generators.
DZakh/sury
TypeScript and ReScript schema library that validates, parses, and encodes data from one declaration, with JSON, form data, and Protobuf wires.
- Stars
- 494
- Forks
- 15
- Open issues
- 18
- Last commit
- 2 days ago
What is it?
Sury is a schema library for TypeScript and ReScript. You declare a data model once, and the same schema is used to parse untrusted input into typed values, encode typed values back into a wire format, and infer TypeScript types from the declaration. Schemas can be chained so that a wire such as a base64url string or a JSON text is treated as a pipeline stage between the raw input and the model.
The library ships built-in wires for JSON, JSON strings, form data, environment variables, URL search params, base64, Uint8Array, Protobuf, File and Blob. Protobuf schemas need no .proto file or code generation, and can produce one for other consumers. Schemas also implement Standard Schema and Standard JSON Schema, and JSON Schema can be converted in both directions.
The project generates specialized JavaScript functions for each schema at runtime, which is how it aims for speed. Operations that run on a schema include parse, encode, constructor checks, equality and comparison, and each comes in sync, Promise-based and Result-returning variants.
Key features
- 01Parses and encodes data from a single schema declaration, with inferred TypeScript types.
- 02Built-in wires for JSON strings, form data, env vars, Protobuf, base64 and File/Blob.
- 03Works with Standard Schema, so it plugs into tRPC, Hono and other supporting libraries.
- 04Converts to and from JSON Schema, and generates .proto definitions from Protobuf schemas.
- 05Reports every validation issue with its path, and throws on values that JSON.stringify would silently corrupt.
Use cases
- Validating API request and response bodies in a TypeScript backend or client.
- Parsing and building multipart form submissions with typed fields and files.
- Reading environment variables into typed configuration with defaults and validation.
- Encoding and decoding Protobuf messages without maintaining generated code.
Quick start
- 1
Install the package from npm
npm install sury - 2
Import the library in your TypeScript code and declare a schema
Things to know
- Several wire formats such as S.request, S.response, S.capnp, S.rkyv and S.toon are listed as coming next and are not yet available.
- JSON Schema import passes about 93% of the official draft-07 test suite, so some schemas may not convert fully.
Topics
FAQ
- What is sury?
- TypeScript and ReScript schema library that validates, parses, and encodes data from one declaration, with JSON, form data, and Protobuf wires. Sury is a schema library for TypeScript and ReScript. You declare a data model once, and the same schema is used to parse untrusted input into typed values, encode typed values back into a wire format, and infer TypeScript types from the declaration. Schemas can be chained so that a wire such as a base64url string or a JSON text is treated as a pipeline stage between the raw input and the model.
- Is sury free to use? What license does it have?
- sury is open source under the MIT license. Check the license terms before using it in commercial products.
- Is sury still maintained?
- Actively maintained. The last commit to sury was on Nov 5, 2026.
- What can I use sury for?
- Validating API request and response bodies in a TypeScript backend or client. Parsing and building multipart form submissions with typed fields and files. Reading environment variables into typed configuration with defaults and validation. Encoding and decoding Protobuf messages without maintaining generated code.
- How do I install sury?
- Install the package from npm: npm install sury Import the library in your TypeScript code and declare a schema
- Where can I get sury?
- The source code and installation instructions are on GitHub: https://github.com/DZakh/sury
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Python data validation library that uses type hints to parse and validate data, with a Rust-based core.
A standardized JSON schema framework and server for describing AI agent capabilities, skills, domains and metadata so agents can be validated and discovered.
A fast Python serialization and validation library that encodes and decodes JSON, MessagePack, YAML, and TOML using standard type annotations.
A web-based JSON viewer and editor component with tree, code, text, and preview modes, usable inside your own web app.
Generates strongly-typed models and serializers in many languages from JSON, JSON Schema, TypeScript, and GraphQL queries.