いい感じに

This commit is contained in:
syuilo
2017-03-03 10:31:59 +09:00
parent e0c44abd4a
commit 73ac13a274

View File

@@ -47,9 +47,9 @@
* undefined も null も区別しないとしたら、触れていないフィールドまでリセットされることになってしまいます。 * undefined も null も区別しないとしたら、触れていないフィールドまでリセットされることになってしまいます。
* ですので、undefined と null は区別しています。 * ですので、undefined と null は区別しています。
* *
* 値が空であってほしくない場合は .require() を、 * 明示的に null を許可しない限り、null はエラーになります。
* 値を必ず指定しなければならない場合(値を「無し」に指定することは許可)は .notUndefined() を、 * null を許可する場合は nullable をプリフィックスします:
* 値の指定をしなくてもいいけど、する場合は「無し」は許可しない場合は .notNull() を使えます。 * const [val, err] = it(x).must.be.a.nullable.string().required().qed();
*/ */
import * as mongo from 'mongodb'; import * as mongo from 'mongodb';
@@ -104,35 +104,15 @@ class QueryCore implements Query {
} }
/** /**
* このインスタンスの値が空のときにエラーにします * このインスタンスの値が指定されていない(=undefined)ときにエラーにします
*/ */
required() { required() {
if (this.error === null && this.isEmpty) {
this.error = new Error('required');
}
return this;
}
/**
* このインスタンスの値が設定されていない(=undefined)場合エラーにします
*/
notUndefined() {
if (this.error === null && this.isUndefined) { if (this.error === null && this.isUndefined) {
this.error = new Error('required'); this.error = new Error('required');
} }
return this; return this;
} }
/**
* このインスタンスの値が null のときにエラーにします
*/
notNull() {
if (this.error === null && this.isNull) {
this.error = new Error('required');
}
return this;
}
/** /**
* このインスタンスの値が設定されていない(=undefined)ときにデフォルトで設定する値を設定します * このインスタンスの値が設定されていない(=undefined)ときにデフォルトで設定する値を設定します
*/ */