Skip to content

Instantly share code, notes, and snippets.

View buildmotion's full-sized avatar

Matt Vaughn buildmotion

View GitHub Profile
import dCompareResult = require('typescript-dotnet-commonjs/System/CompareResult');
import CompareResult = dCompareResult.CompareResult;
import dCompare = require('typescript-dotnet-commonjs/System/Compare');
import Compare = dCompare;
import {CompositeRule} from './index';
import {RuleResult} from './RuleResult';
import {Primitive} from './index';
import {IsNotNullOrUndefined} from './index';
import {Min} from './index';
import dCompareResult = require('typescript-dotnet-commonjs/System/CompareResult');
import CompareResult = dCompareResult.CompareResult;
import dCompare = require('typescript-dotnet-commonjs/System/Compare');
import Compare = dCompare;
import {CompositeRule} from './index';
import {RuleResult} from './RuleResult';
import {Primitive} from './index';
import {IsNotNullOrUndefined} from './index';
import {Range} from './index';
import {RulePolicy} from './RulePolicy';
import {RuleResult} from './RuleResult';
export class CompositeRule extends RulePolicy {
hasErrors: boolean = false;
results: Array<RuleResult> = new Array<RuleResult>();
rules: Array<RulePolicy> = new Array<RulePolicy>();
constructor(name: string, message: string, isDisplayable: boolean) {
super(name, message, isDisplayable);
export class IsTrue extends SimpleRule {
target: boolean;
constructor(name: string, message: string, target: boolean, isDisplayable: boolean = true) {
super(name, message, isDisplayable);
this.target = target;
}
render() {
this.isValid = true;
import {RulePolicy} from './RulePolicy';
/**
* Use this class as a base [extends] class for simple rules. A simple contains
* a single rule and target to evaluate.
*
* If you require a rule that will contain more than one rule, you should
* use extend the [CompositeRule] class.
*/
export class SimpleRule extends RulePolicy {
import {RulePolicy} from './index';
import {CompositeRule} from './index';
export class RuleResult {
isValid: boolean = false;
rulePolicy: RulePolicy;
message: string;
target: any;
constructor(rulePolicy: RulePolicy, target: any);
export class RulePolicy implements IRuleComponent {
isValid: boolean = true;
message: string;
name: string;
priority: number;
result: RuleResult;
isDisplayable: boolean;
renderType: RenderType = RenderType.EvaluateAllRules;
severity: Severity = Severity.Exception;
source: string;
// Load the error/rule violations into the ServiceContext so that the information bubbles up to the caller of the service;
this.validationContext.results.forEach( (e) => {
if(!e.isValid && e.rulePolicy.isDisplayable) {
let serviceMessage = new ServiceMessage(e.rulePolicy.name, e.rulePolicy.message, MessageType.Error);
this.serviceContext.addMessage(serviceMessage);
}
} );
import { CompositeRule } from './CompositeRule';
import { IsNotNullOrUndefined } from './IsNotNullOrUndefined';
import { IsTrue } from './IsTrue';
/**
* Use this rule to determine if the string value matches the specified
* regular expression.
*/
export class StringIsRegExMatch extends CompositeRule {
/**
import { CompositeRule, StringIsNotNullEmptyRange, StringIsRegExMatch } from '@buildmotion/rules-engine';
import { RuleConstants } from './rule-constants';
/**
* Use to validate the format of an email address. Expects:
*
* 1. string is not null or undefined
* 2. string length is within specified value
* 3. string value matches RegEx
*