rescriptbr / reschema Goto Github PK
View Code? Open in Web Editor NEW✅ Schema validation made easy for ReScript
License: MIT License
✅ Schema validation made easy for ReScript
License: MIT License
@mununk reported on ReForm (rescriptbr/reform#244):
I encounter a weird unexpected validation pass about the nested field array. Here is my example:
module ProfileFormFields = %lenses(
type t = {
nickname: string,
age: int,
}
)
module FormFields = %lenses(
type state = {
name: string,
email: string,
profiles: array<ProfileFormFields.t>,
}
)
module Form = ReForm.Make(FormFields)
...
schema([
custom(({profiles}) => {
let errors: array<ReSchema.childFieldError> = // <-- 1
profiles
->Array.mapWithIndex((index, profile) =>
if profile.nickname == "" || profile.age <= 0 {
let error: ReSchema.childFieldError = {
error: "Invalid profile",
index,
name: "???",
}
Some(error)
} else {
None
}
)
->Array.keepMap(x => x)
switch errors {
| [] => Valid
| _ => NestedErrors(errors) // <- 2. return NestedErrors!
}
}, Profiles)
])
...
Field(Profiles)->form.getNestedFieldError(index)->Js.log // errors are all None??
The length of errors in comment:1 is not 0, so it means that this predicate function returns NestedErrors(errors). But none of the indexes in the nested field has an error. So, the submission proceeded even though the nested fields are not satisfied in the custom schema.
I guess that validate function (https://github.com/rescriptbr/reschema/blob/master/src/ReSchema.res#L287:L292) in ReSchema should check the NestedErrors there. Or anything I missed for the nested fields validation?
Error: Cannot find module 'project_folder/node_modules/@rescriptbr/reschema/src/ReSchemaRegExp' imported from project_folder/node_modules/@rescriptbr/reschema/src/ReSchema.mjs
when I starting the investigation the bug I find this file with module.exports.email = email
in js file, when use the "suffix": ".bs.js",
no has error, but when you use "suffix": ".mjs",
using ES6 module has error because no has option import email regex with module.exports
reschema
to @rescriptbr/reschema
).This is not a breaking change
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.