Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V9.2.0 #104

Merged
merged 8 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules
.merlin
.bsb.lock
packages/tests/src/core/**/*_test.bs.mjs
packages/tests/src/core/**/*_test.res.mjs
lib
coverage
dist
Expand Down
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ LoginSchema.parse({ email: "", password: "" });
LoginSchema.parse({ email: "jane@example.com", password: "12345678" });
```

ArkType

```ts
import { type } from "arktype@2.0.4";

const loginSchema = type({
email: "string.email",
password: "string > 7",
});

loginSchema({ email: "", password: "" });

loginSchema({ email: "jane@example.com", password: "12345678" });
```

https://bundlejs.com/?q=arktype%402.0.4&treeshake=%5B*%5D&text=%22const+loginSchema+%3D+type%28%7B%5Cn++email%3A+%5C%22string.email%5C%22%2C%5Cn++password%3A+%5C%22string+%3E+7%5C%22%2C%5Cn%7D%29%3B%5Cn%5CnloginSchema%28%7B+email%3A+%5C%22%5C%22%2C+password%3A+%5C%22%5C%22+%7D%29%3B%5Cn%5CnloginSchema%28%7B+email%3A+%5C%22jane%40example.com%5C%22%2C+password%3A+%5C%2212345678%5C%22+%7D%29%3B%22

## License

By contributing your code to the rescript-schema GitHub repository, you agree to license your contribution under the MIT license.
11 changes: 8 additions & 3 deletions IDEAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ let trimContract: S.contract<string => string> = S.contract(s => {

## v9.1

- Add s.strict s.strip to ppx
- Add S.test
- [x] Update object type validation
- [ ] Support standard schema
- [ ] Make rescript an optional peer dependency

## v10

- Rename S.to to S.reshape
- Change S.classify to something like S.input/S.output
- Add refinement info to the tagged type
- Add S.string->S.coerce(S.int) to coerce string to int and other types
- Add S.codegen
- Add schema input to the error ??? What about build errors?
- Remove Literal.parse in favor of S.literal and make it create Object/Tuple schema instead of Literal(Object)
- S.transform(s => {
Expand All @@ -39,7 +45,6 @@ let trimContract: S.contract<string => string> = S.contract(s => {

## v???

- Add S.string->S.coerce(S.int) to coerce string to int and other types
- Rename S.inline to S.toRescriptCode + Codegen type + Codegen schema using type
- Make `error.reason` tree-shakeable
- S.toJSON/S.castToJson ???
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ 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](https://moltar.github.io/typescript-runtime-type-benchmarks/))
- Small JS footprint & tree-shakable API ([Comparison with Zod and Valibot](#comparison))
- Describe transformations in a schema without a performance loss
- Implements the [Standard Schema](https://standardschema.dev/) spec
- Declarative transformations in a schema without a performance loss
- Reverse schema and convert values to the initial format (serializing)
- Detailed and easy to understand error messages
- Support for asynchronous transformations
- Immutable API with 100+ different operation combinations
- Easy to create _recursive_ schema
- Opt-in strict mode for object schema to prevent unknown fields with ability to change it for the whole project
- Opt-in ReScript PPX to generate schema from type definition
- Opt-in ReScript Schema codegen from type definition (ppx)

Also, it has declarative API allowing you to use **rescript-schema** as a building block for other tools, such as:
Also, you can use **rescript-schema** as a building block for your tools. And there are many existing ones:

- [rescript-rest](https://github.com/DZakh/rescript-rest) - RPC-like client, contract, and server implementation for a pure REST API
- [rescript-envsafe](https://github.com/DZakh/rescript-envsafe) - Makes sure you don't accidentally deploy apps with missing or invalid environment variables
- [rescript-json-schema](https://github.com/DZakh/rescript-json-schema) - Typesafe JSON schema for ReScript
- [rescript-stripe](https://github.com/enviodev/rescript-stripe) - Describe and manage Stripe billing in a declarative way with code
- Internal form library at [Carla](https://www.carla.se/)
- [tRPC](https://trpc.io/), [TanStack Form](https://tanstack.com/form), [TanStack Router](https://tanstack.com/router), [Hono](https://hono.dev/) and 15+ more using [Standard Schema](https://standardschema.dev/) spec

## Documentation

Expand All @@ -36,7 +39,7 @@ Also, it has declarative API allowing you to use **rescript-schema** as a buildi
- [For PPX users](/packages/rescript-schema-ppx/README.md)
- [For library maintainers](/docs/integration-guide.md)

## Content
## Resources

- Building and consuming REST API in ReScript with rescript-rest and Fastify ([YouTube](https://youtu.be/37FY6a-zY20?si=72zT8Gecs5vmDPlD))
- ReScript Schema V9 Changes Overview ([Dev.to](https://dev.to/dzakh/rescript-schema-v9-zod-like-library-to-the-next-level-1dn6))
Expand All @@ -51,12 +54,12 @@ Besides the individual bundle size, the overall size of the library is also sign

At the same time **rescript-schema** 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 `eval`.

| | rescript-schema@9.0.0 | Zod@3.24.1 | Valibot@0.42.1 |
| ---------------------------------------- | --------------------- | --------------- | -------------- |
| **Total size** (minified + gzipped) | 11 kB | 14.8 kB | 10.5 kB |
| **Example size** (minified + gzipped) | 4.45 kB | 13.5 kB | 1.22 kB |
| **Parse with the same schema** | 100,070 ops/ms | 1,277 ops/ms | 3,881 ops/ms |
| **Create schema & parse once** | 179 ops/ms | 112 ops/ms | 2,521 ops/ms |
| **Eval-free** | ❌ | ✅ | ✅ |
| **Codegen-free** (Doesn't need compiler) | ✅ | ✅ | ✅ |
| **Ecosystem** | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️⭐️ |
| | rescript-schema@9.1.0 | Zod@3.24.1 | Valibot@0.42.1 | ArkType@2.0.4 |
| ---------------------------------------- | --------------------- | --------------- | -------------- | ------------- |
| **Total size** (minified + gzipped) | 11 kB | 14.8 kB | 10.5 kB | 40.8 kB |
| **Example size** (minified + gzipped) | 4.45 kB | 13.5 kB | 1.22 kB | 40.7 kB |
| **Parse with the same schema** | 93,491 ops/ms | 1,191 ops/ms | 3,540 ops/ms | 84,772 ops/ms |
| **Create schema & parse once** | 166 ops/ms | 93 ops/ms | 2,302 ops/ms | 13 ops/ms |
| **Eval-free** | ❌ | ✅ | ✅ | ❓ |
| **Codegen-free** (Doesn't need compiler) | ✅ | ✅ | ✅ | ✅ |
| **Ecosystem** | ⭐️⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️⭐️ | ⭐️⭐️ |
14 changes: 12 additions & 2 deletions docs/js-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- [Built-in operations](#built-in-operations)
- [`compile`](#compile)
- [`reverse`](#reverse)
- [`standard`](#standard)
- [`name`](#name)
- [`setName`](#setname)
- [Error handling](#error-handling)
Expand All @@ -52,10 +53,10 @@
## Install

```sh
npm install rescript-schema rescript@11
npm install rescript-schema
```

> 🧠 Even though `rescript` is a peer dependency, you don't need to use the compiler. It's only needed for a few lightweight runtime helpers.
> 🧠 You don't need to install [ReScript](https://rescript-lang.org/) compiler for the library to work.

## Basic usage

Expand Down Expand Up @@ -828,6 +829,15 @@ S.parseOrThrow(123, reversed);

Reverses the schema. This gets especially magical for schemas with transformations 🪄

### **`standard`**

```ts
S.standard(S.string);
// Returns StandardSchemaV1<string>
```

Converts ReScript Schema into [Standard Schema](https://standardschema.dev/). You can use it to integrate with 20+ other libraries. Checkout the [Standard Schema](https://standardschema.dev/) to learn more. 👀

### **`name`**

```ts
Expand Down
4 changes: 2 additions & 2 deletions docs/rescript-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Compiled parser code

```javascript
(i) => {
if (!i || i.constructor !== Object) {
if (typeof i !== "object" || !i) {
e[7](i);
}
let v0 = i["Id"],
Expand Down Expand Up @@ -1508,7 +1508,7 @@ let schema = S.object(s => s.field("abc", S.int))->S.removeTypeValidation

{
"abc": 123,
}->S.parseOrThrow(schema) // This doesn't have `if (!i || i.constructor !== Object) {` check. But field types are still validated.
}->S.parseOrThrow(schema) // This doesn't have `if (typeof i !== "object" || !i) {` check. But field types are still validated.
// 123
```

Expand Down
25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "rescript-schema",
"version": "9.1.0",
"version": "9.2.0",
"private": true,
"description": "🧬 The fastest parser in the entire JavaScript ecosystem with a focus on small bundle size and top-notch DX",
"keywords": [
"ReScript",
Expand Down Expand Up @@ -35,21 +36,21 @@
"files": [
"dist",
"src/S_Core.res",
"src/S_Core.bs.js",
"src/S_Core.bs.mjs",
"src/S_Core.res.js",
"src/S_Core.res.mjs",
"src/S.res",
"src/S.resi",
"src/S.bs.js",
"src/S.bs.mjs",
"src/S.res.js",
"src/S.res.mjs",
"src/S.d.ts",
"RescriptSchema.gen.d.ts",
"rescript.json"
],
"scripts": {
"benchmark": "node ./packages/tests/src/benchmark/Benchmark.bs.mjs",
"benchmark": "node ./packages/tests/src/benchmark/Benchmark.res.mjs",
"benchmark:comparison": "node ./packages/tests/src/benchmark/comparison.js",
"coverage": "c8 --reporter=lcov npm test",
"build": "node ./packages/prepack/src/Prepack.bs.mjs",
"build": "node ./packages/prepack/src/Prepack.res.mjs",
"ppx:install": "node ./packages/rescript-schema-ppx/install.cjs",
"res": "rescript -w",
"res:build": "rescript build",
Expand All @@ -63,7 +64,7 @@
"mjs": true
},
"files": [
"packages/tests/src/**/*_test.bs.mjs",
"packages/tests/src/**/*_test.res.mjs",
"packages/tests/src/**/*_test.ts"
],
"nodeArguments": [
Expand All @@ -84,10 +85,16 @@
"tsimp": "2.0.12",
"typescript": "4.9.3",
"valibot": "0.42.1",
"zod": "3.24.1"
"zod": "3.24.1",
"arktype": "2.0.4"
},
"peerDependencies": {
"rescript": "11.x"
},
"peerDependenciesMeta": {
"rescript": {
"optional": true
}
},
"packageManager": "pnpm@9.0.5"
}
2 changes: 2 additions & 0 deletions packages/prepack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"dependencies": {
"@rescript/core": "1.3.0",
"@rollup/plugin-replace": "5.0.2",
"@rollup/plugin-node-resolve": "16.0.0",
"@rollup/plugin-commonjs": "28.0.2",
"execa": "7.1.1",
"rescript": "11.1.0",
"rescript-nodejs": "16.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/prepack/rescript.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prepack",
"suffix": ".bs.mjs",
"suffix": ".res.mjs",
"package-specs": {
"module": "esmodule",
"in-source": true
Expand Down
Loading