Skip to content

Commit

Permalink
v9.0.0 🚀 - Reverse & Compile
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Dec 15, 2024
1 parent 65d1140 commit 0726d29
Show file tree
Hide file tree
Showing 9 changed files with 480 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ jobs:
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22.6.0
cache: "pnpm"
- run: pnpm install

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ lib
coverage
dist
packages/artifacts
.tsimp
5 changes: 0 additions & 5 deletions IDEAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ let trimContract: S.contract<string => string> = S.contract(s => {

- Use internal transform for trim

## v9

- Update documentation:
- Add Enums section to js docs

### Done

- Removed deprecated APIs, check S.resi diff, S.d.ts and RescriptSchema.gen.ts
Expand Down
258 changes: 183 additions & 75 deletions docs/js-usage.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/rescript-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,9 @@ This is literally the same as convert operations applied to the reversed schema.

For some cases you might want to simply assert the input value is valid. For this there's `S.assertOrThrow` operation:

| Operation | Interface | Description |
| --------------- | --------------------------- | ------------------------------------- |
| S.assertOrThrow | `('any, S.t<'value>) => ()` | Asserts that the input value is valid |
| Operation | Interface | Description |
| --------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| S.assertOrThrow | `('any, S.t<'value>) => ()` | Asserts that the input value is valid. Since the operation doesn't return a value, it's 2-3 times faster than `parseOrThrow` depending on the schema |

All operations either return the output value or raise an exception which you can catch with `try/catch` block:

Expand All @@ -1330,13 +1330,13 @@ try true->S.parseOrThrow(schema) catch {
If you want to have the most possible performance, or the built-in operations doesn't cover your specific use case, you can use `compile` to create fine-tuned operation functions.

```rescript
let fn = S.compile(
let operation = S.compile(
S.string,
~input=Any,
~output=Assert,
~mode=Async,
)
await fn("Hello world!")
await operation("Hello world!")
// ()
```

Expand All @@ -1356,7 +1356,7 @@ You can configure compiled function `output` with the following options:
- `Unknown` - returns `unknown`
- `Assert` - returns `unit`
- `Json` - validates that the schema is JSON compatible and returns `Js.Json.t`
- `JsonString` - validates that the schema is JSON compatible and transforms output to JSON string
- `JsonString` - validates that the schema is JSON compatible and converts output to JSON string

You can configure compiled function `mode` with the following options:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
],
"nodeArguments": [
"--no-warnings",
"--loader=ts-node/esm"
"--import=tsimp"
]
},
"devDependencies": {
Expand All @@ -81,7 +81,7 @@
"rescript-stdlib-vendorer": "1.1.0",
"rescript-schema": "link:",
"ts-expect": "1.3.0",
"ts-node": "10.9.1",
"tsimp": "2.0.12",
"typescript": "4.9.3",
"valibot": "0.42.1",
"zod": "3.24.1"
Expand Down
Loading

0 comments on commit 0726d29

Please sign in to comment.