Skip to content

Commit fa82583

Browse files
committed
feat: add reschema back to the monorepo
1 parent 3864e68 commit fa82583

40 files changed

+4960
-28
lines changed

bsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"error": false
1717
},
1818
"suffix": ".bs.js",
19-
"bs-dependencies": ["@rescriptbr/reform"]
19+
"bs-dependencies": ["@rescriptbr/reform", "@rescriptbr/reschema"]
2020
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"workspaces": [
3838
"packages/reform",
3939
"packages/website",
40+
"packages/reschema",
4041
"packages/demo"
4142
],
4243
"husky": {
@@ -58,7 +59,7 @@
5859
"demo:build": "yarn workspace demo build"
5960
},
6061
"dependencies": {
61-
"@rolandpeelen/rewatch": "^0.0.11",
62+
"@rolandpeelen/rewatch": "0.0.12-0c3740d.0",
6263
"rescript": "^10.1.4"
6364
}
6465
}

packages/reform/src/ReForm.res

+7-7
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ module Make = (Config: Config) => {
207207
None
208208
},
209209
)
210-
| SetFieldsState(fieldsState) => Update({...state, fieldsState: fieldsState})
210+
| SetFieldsState(fieldsState) => Update({...state, fieldsState})
211211
| ValidateField(field) =>
212212
SideEffects(
213213
self => {
@@ -425,7 +425,7 @@ module Make = (Config: Config) => {
425425
}
426426

427427
let interface: api = {
428-
state: state,
428+
state,
429429
formState: state.formState,
430430
fieldsState: state.fieldsState,
431431
values: state.values,
@@ -437,9 +437,9 @@ module Make = (Config: Config) => {
437437
setValues: fn => send(SetValues(fn)),
438438
setFieldValue: (field, value, ~shouldValidate=true, ()) =>
439439
shouldValidate ? send(FieldChangeValue(field, value)) : send(SetFieldValue(field, value)),
440-
getFieldState: getFieldState,
441-
getFieldError: getFieldError,
442-
getNestedFieldError: getNestedFieldError,
440+
getFieldState,
441+
getFieldError,
442+
getNestedFieldError,
443443
handleChange: (field, value) => send(FieldChangeValue(field, value)),
444444
handleChangeWithCallback: (field, updateFn) =>
445445
send(FieldChangeValueWithCallback(field, updateFn)),
@@ -450,8 +450,8 @@ module Make = (Config: Config) => {
450450
arrayRemoveByIndex: (field, index) => send(FieldArrayRemove(field, index)),
451451
validateField: field => send(ValidateField(field)),
452452
validateForm: () => send(ValidateForm(false)),
453-
validateFields: validateFields,
454-
raiseSubmitFailed: raiseSubmitFailed,
453+
validateFields,
454+
raiseSubmitFailed,
455455
}
456456

457457
interface
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: build
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-node@v2-beta
11+
with:
12+
node-version: 14
13+
14+
- run: npm i
15+
- run: npm run rescript:build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Create version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
versionType:
7+
description: Version type
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
- premajor
16+
- preminor
17+
- prepatch
18+
- prerelease
19+
20+
21+
jobs:
22+
create-version:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
with:
27+
ssh-key: ${{ secrets.ADMIN_SSH_KEY }}
28+
- uses: actions/setup-node@v1
29+
with:
30+
node-version: 15
31+
- run: |
32+
git config user.name rescriptbr-admin
33+
git config user.email [email protected]
34+
35+
- name: Generate new version ${{ github.event.inputs.versionType }}
36+
run: npm version ${{ github.event.inputs.versionType }}
37+
38+
- name: Push the tags
39+
run: git push origin master --tags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: publish package on npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 14
15+
- run: npm i
16+
- run: npm run rescript:build
17+
18+
publish-npm:
19+
needs: build
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: actions/setup-node@v2
24+
with:
25+
node-version: 14
26+
registry-url: https://registry.npmjs.org/
27+
- run: npm publish --access=public
28+
env:
29+
NODE_AUTH_TOKEN: ${{secrets.ADMIN_NPM_TOKEN}}

packages/reschema/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib/
2+
*.bs.js
3+
.merlin
4+
node_modules

packages/reschema/.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib
2+
*.bs.js
3+
__tests__
4+
.merlin
5+
demo/

packages/reschema/.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
15.0.1

packages/reschema/CHANGELOG.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
## [2.0.3](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.3) (2021-01-07)
7+
8+
9+
### Bug Fixes
10+
11+
* **regex:** export ([3a880d0](https://github.com/Astrocoders/reform/commit/3a880d045de867b33b983b29b05ba29c64f0879e))
12+
13+
14+
15+
16+
17+
## [2.0.2](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.2) (2021-01-07)
18+
19+
20+
### Features
21+
22+
* **regexp:** better email regexp ([03e105b](https://github.com/Astrocoders/reform/commit/03e105bce60e842945641b83d5a45a645e39196a))
23+
24+
25+
26+
27+
28+
## [2.0.2-alpha.0](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.2-alpha.0) (2020-08-31)
29+
30+
31+
### Features
32+
33+
* **reschema:** add true_ and false_ validators ([b05d3d6](https://github.com/Astrocoders/reform/commit/b05d3d60564cd2a412935efe2e924a2156f19575))
34+
* **reschema:** make errors straight strings ([72f7da4](https://github.com/Astrocoders/reform/commit/72f7da4133cf68492f8357b750814e0b4ab95807))
35+
36+
37+
38+
39+
40+
## [2.0.1-alpha.0](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.1-alpha.0) (2020-07-30)
41+
42+
43+
### Bug Fixes
44+
45+
* **optimisations:** minor optimizations ([24ce4ca](https://github.com/Astrocoders/reform/commit/24ce4cace3eefbbab656e8349f3a3eab22d67922))
46+
47+
48+
### Features
49+
50+
* **meta:** meta field ([78ec9aa](https://github.com/Astrocoders/reform/commit/78ec9aa68f0f07246e2e3863dd6efd95b7b60c88))
51+
52+
53+
54+
55+
56+
# [2.0.0-alpha.0](https://github.com/Astrocoders/reform/compare/[email protected]@2.0.0-alpha.0) (2020-07-30)
57+
58+
59+
### Bug Fixes
60+
61+
* **setup:** setup for monorepo watcher ([c4dd831](https://github.com/Astrocoders/reform/commit/c4dd8315574a1d74e90b930cb10c1b01a9ef4d38))
62+
63+
64+
### Features
65+
66+
* **monorepo:** setup BS monorepo ([f702b09](https://github.com/Astrocoders/reform/commit/f702b0934f772c77ccd6e0eb01d98bdb5fc46c1e))
67+
* **nested-errors,custom-errors:** add nested errors for field array ([8dcf20a](https://github.com/Astrocoders/reform/commit/8dcf20aa5e20bd383a2836c16ae64b8cbe38c5ca))
68+
* **reschema:** use inline records for validators ([bdefa25](https://github.com/Astrocoders/reform/commit/bdefa25041429264f733bbdf8eb2ee7bc96884a5))
69+
* **reschema:** validator helpers ([a4e404c](https://github.com/Astrocoders/reform/commit/a4e404c77637c3b7e13a702186f21d68c6b1419f))
70+
* **validators:** easier composition ([43c9bb8](https://github.com/Astrocoders/reform/commit/43c9bb8c8bacc7497d91ac43d948bcf69a5a0edf))
71+
72+
73+
74+
75+
76+
## [1.3.1](https://github.com/Astrocoders/reform/compare/[email protected]@1.3.1) (2020-06-23)
77+
78+
**Note:** Version bump only for package reschema
79+
80+
81+
82+
83+
84+
# [1.3.0](https://github.com/Astrocoders/reform/compare/[email protected]@1.3.0) (2019-11-22)
85+
86+
87+
### Features
88+
89+
* **reschema:** add method validateFields ([4b712a3](https://github.com/Astrocoders/reform/commit/4b712a3))

packages/reschema/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/reschema/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<p align="center">
2+
<img src="./assets/cover.svg" />
3+
<br />
4+
</p>
5+
<p align="center">
6+
<a href="#what-is-this-">What is this?</a> •
7+
<a href="#features-">Features</a> •
8+
<a href="#installation-">Installation</a> •
9+
<a href="#documentation-">Documentation</a> •
10+
<a target="_blank" href="https://reform-demo.rescriptbrasil.org">Live demo (with ReForm)</a>
11+
</p>
12+
<br/>
13+
14+
## What is this? 💡
15+
ReSchema is a schema builder for ReScript. We created ReSchema to be deadly simple, leveraging ReScript's powerful typesytem.
16+
Schemas created with ReSchema are nothing more than constructors built-in in the language itself with a small size footprint.
17+
18+
## Features ⚡
19+
- Schema validation using GADT's
20+
- Built-in validators
21+
- Type-safe validation
22+
- I18n support
23+
- Regex support
24+
- Custom validations
25+
26+
## Installation 📦
27+
28+
```sh
29+
yarn add @rescriptbr/reschema
30+
```
31+
and then, add `ReSchema` as a dependency in your `bsconfig.json`
32+
```js
33+
{
34+
...
35+
"bs-dependencies": [
36+
"@rescriptbr/reschema"
37+
],
38+
}
39+
```
40+
41+
## Documentation 🔎
42+
- [Getting Started](./docs/1-getting-started.md)
43+
- [API Reference](./docs/2-api-reference.md)

packages/reschema/__tests__/Jest.res

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
type testable<'a>
2+
type jestFn
3+
4+
@val @scope("jest") external fn0: (unit => 'a) => jestFn = "fn"
5+
@val @scope("jest") external fn1: ('a => 'b) => jestFn = "fn"
6+
@val @scope("jest") external fn2: (('a, 'b) => 'c, 'a, 'b) => 'c = "fn"
7+
8+
@val external describe: (string, (. unit) => unit) => unit = "describe"
9+
@val external it: (string, (. unit) => unit) => unit = "it"
10+
@val external test: (string, (. unit) => unit) => unit = "test"
11+
12+
@val external expect: 'value => testable<'value> = "expect"
13+
@val external expectFn: jestFn => testable<'value> = "expect"
14+
@val external expectArray: array<'value> => testable<'value> = "expect"
15+
16+
@send external toBe: (testable<'value>, 'value) => unit = "toBe"
17+
@send external toEqual: (testable<'value>, 'value) => testable<'value> = "toEqual"
18+
@send external toStrictEqual: (testable<'value>, 'value) => testable<'value> = "toStrictEqual"
19+
@send external toContain: (testable<'value>, 'value) => testable<'value> = "toContain"
20+
@send external toHaveBeenCalled: (testable<'value>, unit) => testable<'value> = "toHaveBeenCalled"
21+
@send
22+
external toHaveBeenCalledTimes: (testable<'value>, int) => testable<'value> =
23+
"toHaveBeenCalledTimes"
24+
25+
@get external not: testable<'value> => testable<'value> = "not"

0 commit comments

Comments
 (0)