Skip to content

Commit

Permalink
feat: add reschema back to the monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
fakenickels committed Jan 16, 2024
1 parent 3864e68 commit fa82583
Show file tree
Hide file tree
Showing 40 changed files with 4,960 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"error": false
},
"suffix": ".bs.js",
"bs-dependencies": ["@rescriptbr/reform"]
"bs-dependencies": ["@rescriptbr/reform", "@rescriptbr/reschema"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"workspaces": [
"packages/reform",
"packages/website",
"packages/reschema",
"packages/demo"
],
"husky": {
Expand All @@ -58,7 +59,7 @@
"demo:build": "yarn workspace demo build"
},
"dependencies": {
"@rolandpeelen/rewatch": "^0.0.11",
"@rolandpeelen/rewatch": "0.0.12-0c3740d.0",
"rescript": "^10.1.4"
}
}
14 changes: 7 additions & 7 deletions packages/reform/src/ReForm.res
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ module Make = (Config: Config) => {
None
},
)
| SetFieldsState(fieldsState) => Update({...state, fieldsState: fieldsState})
| SetFieldsState(fieldsState) => Update({...state, fieldsState})
| ValidateField(field) =>
SideEffects(
self => {
Expand Down Expand Up @@ -425,7 +425,7 @@ module Make = (Config: Config) => {
}

let interface: api = {
state: state,
state,
formState: state.formState,
fieldsState: state.fieldsState,
values: state.values,
Expand All @@ -437,9 +437,9 @@ module Make = (Config: Config) => {
setValues: fn => send(SetValues(fn)),
setFieldValue: (field, value, ~shouldValidate=true, ()) =>
shouldValidate ? send(FieldChangeValue(field, value)) : send(SetFieldValue(field, value)),
getFieldState: getFieldState,
getFieldError: getFieldError,
getNestedFieldError: getNestedFieldError,
getFieldState,
getFieldError,
getNestedFieldError,
handleChange: (field, value) => send(FieldChangeValue(field, value)),
handleChangeWithCallback: (field, updateFn) =>
send(FieldChangeValueWithCallback(field, updateFn)),
Expand All @@ -450,8 +450,8 @@ module Make = (Config: Config) => {
arrayRemoveByIndex: (field, index) => send(FieldArrayRemove(field, index)),
validateField: field => send(ValidateField(field)),
validateForm: () => send(ValidateForm(false)),
validateFields: validateFields,
raiseSubmitFailed: raiseSubmitFailed,
validateFields,
raiseSubmitFailed,
}

interface
Expand Down
15 changes: 15 additions & 0 deletions packages/reschema/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: 14

- run: npm i
- run: npm run rescript:build
39 changes: 39 additions & 0 deletions packages/reschema/.github/workflows/create-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create version

on:
workflow_dispatch:
inputs:
versionType:
description: Version type
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
- premajor
- preminor
- prepatch
- prerelease


jobs:
create-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.ADMIN_SSH_KEY }}
- uses: actions/setup-node@v1
with:
node-version: 15
- run: |
git config user.name rescriptbr-admin
git config user.email [email protected]
- name: Generate new version ${{ github.event.inputs.versionType }}
run: npm version ${{ github.event.inputs.versionType }}

- name: Push the tags
run: git push origin master --tags
29 changes: 29 additions & 0 deletions packages/reschema/.github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: publish package on npm

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm i
- run: npm run rescript:build

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.ADMIN_NPM_TOKEN}}
4 changes: 4 additions & 0 deletions packages/reschema/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
*.bs.js
.merlin
node_modules
5 changes: 5 additions & 0 deletions packages/reschema/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lib
*.bs.js
__tests__
.merlin
demo/
1 change: 1 addition & 0 deletions packages/reschema/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15.0.1
89 changes: 89 additions & 0 deletions packages/reschema/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.0.3](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.3) (2021-01-07)


### Bug Fixes

* **regex:** export ([3a880d0](https://github.com/Astrocoders/reform/commit/3a880d045de867b33b983b29b05ba29c64f0879e))





## [2.0.2](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.2) (2021-01-07)


### Features

* **regexp:** better email regexp ([03e105b](https://github.com/Astrocoders/reform/commit/03e105bce60e842945641b83d5a45a645e39196a))





## [2.0.2-alpha.0](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.2-alpha.0) (2020-08-31)


### Features

* **reschema:** add true_ and false_ validators ([b05d3d6](https://github.com/Astrocoders/reform/commit/b05d3d60564cd2a412935efe2e924a2156f19575))
* **reschema:** make errors straight strings ([72f7da4](https://github.com/Astrocoders/reform/commit/72f7da4133cf68492f8357b750814e0b4ab95807))





## [2.0.1-alpha.0](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.1-alpha.0) (2020-07-30)


### Bug Fixes

* **optimisations:** minor optimizations ([24ce4ca](https://github.com/Astrocoders/reform/commit/24ce4cace3eefbbab656e8349f3a3eab22d67922))


### Features

* **meta:** meta field ([78ec9aa](https://github.com/Astrocoders/reform/commit/78ec9aa68f0f07246e2e3863dd6efd95b7b60c88))





# [2.0.0-alpha.0](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.0-alpha.0) (2020-07-30)


### Bug Fixes

* **setup:** setup for monorepo watcher ([c4dd831](https://github.com/Astrocoders/reform/commit/c4dd8315574a1d74e90b930cb10c1b01a9ef4d38))


### Features

* **monorepo:** setup BS monorepo ([f702b09](https://github.com/Astrocoders/reform/commit/f702b0934f772c77ccd6e0eb01d98bdb5fc46c1e))
* **nested-errors,custom-errors:** add nested errors for field array ([8dcf20a](https://github.com/Astrocoders/reform/commit/8dcf20aa5e20bd383a2836c16ae64b8cbe38c5ca))
* **reschema:** use inline records for validators ([bdefa25](https://github.com/Astrocoders/reform/commit/bdefa25041429264f733bbdf8eb2ee7bc96884a5))
* **reschema:** validator helpers ([a4e404c](https://github.com/Astrocoders/reform/commit/a4e404c77637c3b7e13a702186f21d68c6b1419f))
* **validators:** easier composition ([43c9bb8](https://github.com/Astrocoders/reform/commit/43c9bb8c8bacc7497d91ac43d948bcf69a5a0edf))





## [1.3.1](https://github.com/Astrocoders/reform/compare/[email protected]@1.3.1) (2020-06-23)

**Note:** Version bump only for package reschema





# [1.3.0](https://github.com/Astrocoders/reform/compare/[email protected]@1.3.0) (2019-11-22)


### Features

* **reschema:** add method validateFields ([4b712a3](https://github.com/Astrocoders/reform/commit/4b712a3))
21 changes: 21 additions & 0 deletions packages/reschema/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions packages/reschema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<p align="center">
<img src="./assets/cover.svg" />
<br />
</p>
<p align="center">
<a href="#what-is-this-">What is this?</a> •
<a href="#features-">Features</a> •
<a href="#installation-">Installation</a> •
<a href="#documentation-">Documentation</a> •
<a target="_blank" href="https://reform-demo.rescriptbrasil.org">Live demo (with ReForm)</a>
</p>
<br/>

## What is this? 💡
ReSchema is a schema builder for ReScript. We created ReSchema to be deadly simple, leveraging ReScript's powerful typesytem.
Schemas created with ReSchema are nothing more than constructors built-in in the language itself with a small size footprint.

## Features ⚡
- Schema validation using GADT's
- Built-in validators
- Type-safe validation
- I18n support
- Regex support
- Custom validations

## Installation 📦

```sh
yarn add @rescriptbr/reschema
```
and then, add `ReSchema` as a dependency in your `bsconfig.json`
```js
{
...
"bs-dependencies": [
"@rescriptbr/reschema"
],
}
```

## Documentation 🔎
- [Getting Started](./docs/1-getting-started.md)
- [API Reference](./docs/2-api-reference.md)
25 changes: 25 additions & 0 deletions packages/reschema/__tests__/Jest.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
type testable<'a>
type jestFn

@val @scope("jest") external fn0: (unit => 'a) => jestFn = "fn"
@val @scope("jest") external fn1: ('a => 'b) => jestFn = "fn"
@val @scope("jest") external fn2: (('a, 'b) => 'c, 'a, 'b) => 'c = "fn"

@val external describe: (string, (. unit) => unit) => unit = "describe"
@val external it: (string, (. unit) => unit) => unit = "it"
@val external test: (string, (. unit) => unit) => unit = "test"

@val external expect: 'value => testable<'value> = "expect"
@val external expectFn: jestFn => testable<'value> = "expect"
@val external expectArray: array<'value> => testable<'value> = "expect"

@send external toBe: (testable<'value>, 'value) => unit = "toBe"
@send external toEqual: (testable<'value>, 'value) => testable<'value> = "toEqual"
@send external toStrictEqual: (testable<'value>, 'value) => testable<'value> = "toStrictEqual"
@send external toContain: (testable<'value>, 'value) => testable<'value> = "toContain"
@send external toHaveBeenCalled: (testable<'value>, unit) => testable<'value> = "toHaveBeenCalled"
@send
external toHaveBeenCalledTimes: (testable<'value>, int) => testable<'value> =
"toHaveBeenCalledTimes"

@get external not: testable<'value> => testable<'value> = "not"
Loading

0 comments on commit fa82583

Please sign in to comment.