Skip to content

Commit 1dd71fa

Browse files
committed
update changelog
1 parent ab63cda commit 1dd71fa

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

CHANGELOG.md

+57
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
1+
<a name="1.11.0"></a>
2+
# 1.11.0 (2021-05-11)
3+
4+
## Async custom validator supports
5+
6+
```js
7+
const schema = {
8+
// Turn on async mode for this schema
9+
$$async: true,
10+
name: {
11+
type: "string",
12+
min: 4,
13+
max: 25,
14+
custom: async (v) => {
15+
await new Promise(resolve => setTimeout(resolve, 1000));
16+
return v.toUpperCase();
17+
}
18+
},
19+
20+
username: {
21+
type: "custom",
22+
custom: async (v) => {
23+
// E.g. checking in the DB that whether is unique.
24+
await new Promise(resolve => setTimeout(resolve, 1000));
25+
return v.trim();
26+
}
27+
},
28+
}
29+
```
30+
31+
The compiled `check` function has an `async` property to detect this mode. If `true` it returns a `Promise`.
32+
```js
33+
const check = v.compile(schema);
34+
console.log("Is async?", check.async);
35+
```
36+
37+
## Meta-information for custom validators
38+
You can pass any extra meta information for the custom validators which is available via `context.meta`.
39+
```js
40+
const schema = {
41+
name: { type: "string", custom: (value, errors, schema, name, parent, context) => {
42+
// Access to the meta
43+
return context.meta.a;
44+
} },
45+
};
46+
const check = v.compile(schema);
47+
48+
const res = check(obj, {
49+
// Passes meta information
50+
meta: { a: "from-meta" }
51+
});
52+
```
53+
54+
## Changes
55+
- support default and optional in tuples and arrays [#226](https://github.com/icebob/fastest-validator/pull/226)
56+
- fix that `this` points to the Validator instance in custom functions [#231](https://github.com/icebob/fastest-validator/pull/231)
57+
-
158
<a name="1.10.1"></a>
259
# 1.10.1 (2021-03-22)
360

0 commit comments

Comments
 (0)