UNPKG

@type-ddd/patterns

Version:

This package provide utils file and interfaces to assistant build a complex application with domain driving design

79 lines (78 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NotSpecification = exports.AndNotSpecification = exports.OrNotSpecification = exports.OrSpecification = exports.AndSpecification = exports.Specification = void 0; class Specification { and(other) { return new AndSpecification(this, other); } or(other) { return new OrSpecification(this, other); } orNot(other) { return new OrNotSpecification(this, other); } andNot(other) { return new AndNotSpecification(this, other); } not() { return new NotSpecification(this); } } exports.Specification = Specification; class AndSpecification extends Specification { constructor(one, other) { super(); this.one = one; this.other = other; } isSatisfiedBy(target) { return (this.one.isSatisfiedBy(target) && this.other.isSatisfiedBy(target)); } } exports.AndSpecification = AndSpecification; class OrSpecification extends Specification { constructor(one, other) { super(); this.one = one; this.other = other; } isSatisfiedBy(target) { return (this.one.isSatisfiedBy(target) || this.other.isSatisfiedBy(target)); } } exports.OrSpecification = OrSpecification; class OrNotSpecification extends Specification { constructor(one, other) { super(); this.one = one; this.other = other; } isSatisfiedBy(target) { return ((this.one.isSatisfiedBy(target) || this.other.isSatisfiedBy(target)) !== true); } } exports.OrNotSpecification = OrNotSpecification; class AndNotSpecification extends Specification { constructor(one, other) { super(); this.one = one; this.other = other; } isSatisfiedBy(target) { return ((this.one.isSatisfiedBy(target) && this.other.isSatisfiedBy(target)) !== true); } } exports.AndNotSpecification = AndNotSpecification; class NotSpecification extends Specification { constructor(other) { super(); this.other = other; } isSatisfiedBy(target) { return !this.other.isSatisfiedBy(target); } } exports.NotSpecification = NotSpecification; exports.default = Specification;