forked from jquense/yup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazy.js
36 lines (31 loc) · 996 Bytes
/
Lazy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import isSchema from './util/isSchema';
class Lazy {
constructor(mapFn) {
this._resolve = (value, options) => {
let schema = mapFn(value, options);
if (!isSchema(schema))
throw new TypeError('lazy() functions must return a valid schema');
return schema.resolve(options);
};
}
resolve(options) {
return this._resolve(options.value, options);
}
cast(value, options) {
return this._resolve(value, options).cast(value, options);
}
validate(value, options) {
return this._resolve(value, options).validate(value, options);
}
validateSync(value, options) {
return this._resolve(value, options).validateSync(value, options);
}
validateAt(path, value, options) {
return this._resolve(value, options).validateAt(path, value, options);
}
validateSyncAt(path, value, options) {
return this._resolve(value, options).validateSyncAt(path, value, options);
}
}
Lazy.prototype.__isYupSchema__ = true;
export default Lazy;