Skip to content

Commit

Permalink
Rename to rescript-schema
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Nov 23, 2023
1 parent 0817540 commit 1d28c51
Show file tree
Hide file tree
Showing 131 changed files with 4,100 additions and 4,104 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ocaml.sandbox": {
"kind": "opam",
"switch": "struct"
"switch": "rescript-schema"
}
}
18 changes: 9 additions & 9 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ In progress

### How to use

Add `@struct` in front of a type defenition.
Add `@schema` in front of a type defenition.

```rescript
@struct
@schema
type rating =
| @as("G") GeneralAudiences
| @as("PG") ParentalGuidanceSuggested
| @as("PG13") ParentalStronglyCautioned
| @as("R") Restricted
@struct
@schema
type film = {
@as("Id")
id: float,
@as("Title")
title: string,
@as("Tags")
tags: @struct(S.array(S.string)->S.default(() => [])) array<string>,
tags: @schema(S.array(S.string)->S.default(() => [])) array<string>,
@as("Rating")
rating: rating,
@as("Age")
deprecatedAgeRestriction: @struct(S.int->S.option->S.deprecate("Use rating instead")) option<int>,
deprecatedAgeRestriction: @schema(S.int->S.option->S.deprecate("Use rating instead")) option<int>,
}
```

This will automatically create `filmStruct` of type `S.t<film>`:
This will automatically create `filmSchema` of type `S.t<film>`:

```rescript
let ratingStruct = S.union([
let ratingSchema = S.union([
S.literal(GeneralAudiences),
S.literal(ParentalGuidanceSuggested),
S.literal(ParentalStronglyCautioned),
S.literal(Restricted),
])
let filmStruct = S.object(s => {
let filmSchema = S.object(s => {
id: s.field("Id", S.float),
title: s.field("Title", S.string),
tags: s.field("Tags", S.array(S.string)->S.default(() => [])),
rating: s.field("Rating", ratingStruct),
rating: s.field("Rating", ratingSchema),
deprecatedAgeRestriction: s.field("Age", S.int->S.option->S.deprecate("Use rating instead")),
})
```
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Before you start working on a contribution, create an issue describing what you
The following steps will get you setup to contribute changes to this repo:

1. Fork this repo.
2. Clone your forked repo: `git clone [email protected]:{your_username}/rescript-struct.git`
2. Clone your forked repo: `git clone [email protected]:{your_username}/rescript-schema.git`
3. Install [pnpm](https://pnpm.io/) if not available `npm i -g [email protected]`
4. Run `pnpm i` to install dependencies.
5. Start playing with the code!
Expand All @@ -25,7 +25,7 @@ Make sure running the below commands in `packages/ppx/src`.
1. Create a sandbox with opam

```
opam switch create struct 4.12.1
opam switch create rescript-schema 4.12.1
```

2. Install dependencies
Expand Down Expand Up @@ -55,4 +55,4 @@ npm run test -- --watch

## License

By contributing your code to the rescript-struct GitHub repository, you agree to license your contribution under the MIT license.
By contributing your code to the rescript-schema GitHub repository, you agree to license your contribution under the MIT license.
1 change: 1 addition & 0 deletions IDEAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let trimContract: S.contract<string => string> = S.contract(s => {
- Make `error.reason` tree-shakeable
- Update `Literal` `tagged` to include `text`, `value` and `kind`. So it's more convinient and smaller bundle-size
- Turn `String.email` -> `email`, `String.min` -> `stringMin` for tree-shaking
- Rename `InvalidJsonStruct` error, since after `rescript-struct`->`rescript-schema` it became misleading

## v???

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[![CI](https://github.com/DZakh/rescript-struct/actions/workflows/ci.yml/badge.svg)](https://github.com/DZakh/rescript-struct/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/DZakh/rescript-struct/branch/main/graph/badge.svg?token=40G6YKKD6J)](https://codecov.io/gh/DZakh/rescript-struct)
[![npm](https://img.shields.io/npm/dm/rescript-struct)](https://www.npmjs.com/package/rescript-struct)
[![CI](https://github.com/DZakh/rescript-schema/actions/workflows/ci.yml/badge.svg)](https://github.com/DZakh/rescript-schema/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/DZakh/rescript-schema/branch/main/graph/badge.svg?token=40G6YKKD6J)](https://codecov.io/gh/DZakh/rescript-schema)
[![npm](https://img.shields.io/npm/dm/rescript-schema)](https://www.npmjs.com/package/rescript-schema)

# ReScript Struct
# ReScript Schema

The fastest composable parser/serializer for ReScript (and TypeScript)

> ⚠️ Be aware that **rescript-struct** uses `eval`. It's usually fine but might not work in some environments like Cloudflare Workers or third-party scripts used on pages with the [script-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) header.
> ⚠️ Be aware that **rescript-schema** uses `eval`. It's usually fine but might not work in some environments like Cloudflare Workers or third-party scripts used on pages with the [script-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) header.
Highlights:

Expand All @@ -15,14 +15,14 @@ Highlights:
- Works with any Js value, not only `Js.Json.t`
- Support for asynchronous transformations
- Immutable API with both result and exception-based operations
- Easy to create _recursive_ structs
- Easy to create _recursive_ schema
- Detailed error messages
- Strict mode for object structs to prevent excessive fields and many more built-in helpers
- Opt-in strict mode for object schema to prevent excessive fields and many more built-in helpers
- Works with plain JavaScript/TypeScript too! You don't need to use ReScript
- The **fastest** composable 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](./docs/js-usage.md#comparison))

Also, it has declarative API allowing you to use **rescript-struct** as a building block for other tools, such as:
Also, it has declarative API allowing you to use **rescript-schema** as a building block for other tools, such as:

- [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
Expand Down
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rescript-struct",
"name": "rescript-schema",
"namespace": true,
"suffix": ".bs.mjs",
"package-specs": {
Expand Down
4 changes: 2 additions & 2 deletions docs/integration-guide.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[⬅ Back to highlights](../README.md)

# ReScript Struct for library maintainers
# ReScript Schema for library maintainers

If you're a library maintainer, you can use **rescript-struct** to get information about described structures. The most common use case is building type-safe schemas e.g for REST APIs, databases, and forms.
If you're a library maintainer, you can use **rescript-schema** as a building block for your tools. The most common use case is a type-safe schema for REST APIs, databases, forms, etc.

Documentation for this feature is work in progress, for now, you can use `S.resi` file as a reference and the [rescript-json-schema](https://github.com/DZakh/rescript-json-schema)'s source code.
Loading

0 comments on commit 1d28c51

Please sign in to comment.