UNPKG

js-contracts

Version:
56 lines (55 loc) 2.74 kB
import 'reflect-metadata'; import { ContractCondition, ContractPredicate, ContractSettings } from './types'; export default abstract class Contract { /** * Set Contract settings * @param settings - contract settings object */ static setSettings(settings: ContractSettings): void; /** * Represents values as they were at the start of a method or property. * @param value - value of type T */ static OldValue<T>(value: T): T; /** * Represents values as they were at the start of a method or property. * @param path - path to the value */ static OldValueByPath<T>(path: string): T; /** * Represents the return value of a method or property. */ static ContractResult(): {}; /** * Checks for a condition; if the condition is false, follows the escalation policy set for the analyzer. * @param condition - The conditional expression to test * @param message - The message to post if the assumption fails. */ static Assert(condition: ContractCondition, message?: string): (...args: any[]) => void; /** * Determines whether an element within a collection of elements exists within a function. * @param collection<T> - Collection of type T * @param predicate<T> - Predicate condition with return type T * @param message - The message to post if the assumption fails. */ static Exists<T>(collection: T[], predicate: ContractPredicate<T>, message?: string): void; /** * Determines whether all the elements in a collection exist within a function. * @param collection<T> - Collection of type T * @param predicate<T> - Predicate condition with return type T * @param message - The message to post if the assumption fails. */ static ForAll<T>(collection: T[], predicate: ContractPredicate<T>, message?: string): void; /** * Specifies a precondition contract for the enclosing method or property, and displays a message if the condition for the contract fails. * @param condition - The conditional expression to test * @param message - The message to post if the assumption fails. */ static Requires(condition: ContractCondition, message?: string): (target: Object, key: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor; /** * Specifies a postcondition contract for the enclosing method or property. * @param condition - The conditional expression to test * @param message - The message to post if the assumption fails. */ static Ensures<T extends Error>(condition: ContractCondition, message?: string): (target: Object, key: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor; }