Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ sury Public
forked from DZakh/sury

🧬 The fastest schema with next-gen DX

License

Notifications You must be signed in to change notification settings

mediremi/sury

 
 

Repository files navigation

CI codecov npm

Sury (aka ReScript Schema) 🧬

The fastest schema with next-gen DX.

Highlights:

  • Works with plain JavaScript, TypeScript, and ReScript. You don't need to use any compiler.
  • The fastest parsing and validation library in the entire JavaScript ecosystem (benchmark)
  • Small JS footprint & tree-shakable API (Comparison with Zod and Valibot)
  • Implements the Standard Schema spec
  • Built-in JSON Schema support
  • Detailed and easy to understand error messages
  • Declarative transformations with automatic serialization support
  • Immutable API with 100+ different operations
  • Flexible global config
  • Opt-in ReScript codegen from type definitions (ppx)

Also, you can use Sury as a building block for your own tools or use existing ones:

Documentation

⚠️ Be aware that Sury uses new Function for parsing. The approach is battle tested and has no known security issues. It's also used by TypeBox, Zod@4 and ArkType. Although, some environments like Cloudflare Workers will not allow it.

Resources

  • Welcome Sury - The fastest schema with next-gen DX (Dev.to)
  • ReScript Schema unique features (Dev.to)
  • Building and consuming REST API in ReScript with rescript-rest and Fastify (YouTube)

Comparison

Instead of relying on a few large functions with many methods, Sury follows Valibot's approach, where API design and source code is based on many small and independent functions, each with just a single task. This modular design has several advantages.

For example, this allows a bundler to use the import statements to remove code that is not needed. This way, only the code that is actually used gets into your production build. This can reduce the bundle size by up to 2 times compared to Zod.

Besides the individual bundle size, the overall size of the library is also significantly smaller.

At the same time Sury is the fastest composable validation library in the entire JavaScript ecosystem. This is achieved because of the JIT approach when an ultra optimized validator is created using new Function.

[email protected] [email protected] [email protected] [email protected] [email protected]
Total size (min + gzip) 14.1 kB 25.9 kB 31.4 kB 12.6 kB 45.9 kB
Benchmark size (min + gzip) 4.27 kB 13.5 kB 22.8 kB 1.23 kB 45.8 kB
Parse with the same schema 94,828 ops/ms 8,437 ops/ms 99,640 ops/ms (No transforms) 1,721 ops/ms 67,552 ops/ms
Create schema & parse once 166 ops/ms 6 ops/ms 111 ops/ms (No transforms) 287 ops/ms 11 ops/ms
JSON Schema S.toJSONSchema z.toJSONSchema 👑 @valibot/to-json-schema T.toJsonSchema
Standard Schema
Eval-free ⭕ opt-out ⭕ opt-in ⭕ opt-out
Codegen-free (Doesn't need compiler)
Infered TS Type S.Schema<{foo: string}, {foo: string}> z.ZodObject<{foo: z.ZodString}, {}> TObject<{foo: TString}> v.ObjectSchema<{readonly foo: v.StringSchema<undefined>}, undefined> Type<{foo: string}, {}>
Ecosystem ⭐️⭐️ ⭐️⭐️⭐️⭐️⭐️ ⭐️⭐️⭐️⭐️⭐️ ⭐️⭐️⭐️ ⭐️⭐️

About

🧬 The fastest schema with next-gen DX

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • ReScript 67.8%
  • JavaScript 25.2%
  • TypeScript 5.6%
  • OCaml 1.4%
  • Shell 0.0%
  • Batchfile 0.0%