0
0
This commit is contained in:
syuilo 2017-03-04 01:29:16 +09:00
parent 3a58cff9b2
commit ed46d61fd4

View File

@ -57,22 +57,12 @@ import hasDuplicates from '../common/has-duplicates';
type Validator<T> = (value: T) => boolean | Error; type Validator<T> = (value: T) => boolean | Error;
interface Query { /**
/** *
* qedはQ.E.D.'QueryEnD' */
*/ abstract class Query {
qed: () => [any, Error]; protected value: any;
protected error: Error;
required: () => Query;
default: (value: any) => Query;
validate: (validator: Validator<any>) => Query;
}
class QueryCore implements Query {
value: any;
error: Error;
constructor(value: any, nullable: boolean = false) { constructor(value: any, nullable: boolean = false) {
if (value === null && !nullable) { if (value === null && !nullable) {
@ -84,22 +74,22 @@ class QueryCore implements Query {
} }
} }
get isUndefined() { protected get isUndefined() {
return this.value === undefined; return this.value === undefined;
} }
get isNull() { protected get isNull() {
return this.value === null; return this.value === null;
} }
get isEmpty() { protected get isEmpty() {
return this.isUndefined || this.isNull; return this.isUndefined || this.isNull;
} }
/** /**
* *
*/ */
get shouldSkip() { protected get shouldSkip() {
return this.error !== null || this.isEmpty; return this.error !== null || this.isEmpty;
} }
@ -125,6 +115,7 @@ class QueryCore implements Query {
/** /**
* *
* *qedはQ.E.D.'QueryEnD'
*/ */
qed(): [any, Error] { qed(): [any, Error] {
return [this.value, this.error]; return [this.value, this.error];
@ -147,7 +138,7 @@ class QueryCore implements Query {
} }
} }
class BooleanQuery extends QueryCore { class BooleanQuery extends Query {
value: boolean; value: boolean;
error: Error; error: Error;
@ -182,7 +173,7 @@ class BooleanQuery extends QueryCore {
} }
} }
class NumberQuery extends QueryCore { class NumberQuery extends Query {
value: number; value: number;
error: Error; error: Error;
@ -254,7 +245,7 @@ class NumberQuery extends QueryCore {
} }
} }
class StringQuery extends QueryCore { class StringQuery extends Query {
value: string; value: string;
error: Error; error: Error;
@ -332,7 +323,7 @@ class StringQuery extends QueryCore {
} }
} }
class ArrayQuery extends QueryCore { class ArrayQuery extends Query {
value: any[]; value: any[];
error: Error; error: Error;
@ -403,7 +394,7 @@ class ArrayQuery extends QueryCore {
} }
} }
class IdQuery extends QueryCore { class IdQuery extends Query {
value: mongo.ObjectID; value: mongo.ObjectID;
error: Error; error: Error;
@ -438,7 +429,7 @@ class IdQuery extends QueryCore {
} }
} }
class ObjectQuery extends QueryCore { class ObjectQuery extends Query {
value: any; value: any;
error: Error; error: Error;