import { Schema, ObjectSchema } from "joi"; import * as joi from "joi"; export declare const WORKING_SCHEMA_KEY = "tsdv:working-schema"; export declare const SCHEMA_KEY = "tsdv:schema"; export declare let Joi: typeof joi; export declare function registerJoi(customJoi: typeof joi): void; export declare class ConstraintDefinitionError extends Error { message: string; name: string; constructor(message: string); } export declare class ValidationSchemaNotFound extends ConstraintDefinitionError { name: string; constructor(propertyKey: string | Symbol); } export declare type WorkingSchema = { [index: string]: Schema; }; export interface AnyClass { new (...args: any[]): any; } export declare type StringKey = Extract; export declare type StringOrSymbolKey = Extract; export declare type Nullable = { [K in keyof T]: T[K] | null; }; /** * If a given type extends the desired type, return the given type. Otherwise, return the desired type. * So, you can do stuff like this: * * ```typescript * interface Foo { * bar: null; * baz: number; * boz: string; * biz: string | null; * } * * const bars1: AllowUnions[] = [ * 'sdf', // Type 'string' is not assignable to type 'number'. * null, // Type 'null' is not assignable to type 'number'. * 123 * ]; * * const bars2: AllowUnions[] = [ * 'sdf', * null, // Type 'null' is not assignable to type 'string'. * 123 // Type 'number' is not assignable to type 'string'. * ]; * * const bars3: AllowUnions[] = [ * 'sdf', * null, * 123 // Type 'number' is not assignable to type 'string | null'. * ]; * ``` * * Notice that you pass the TOriginal type parameter, which is identical to the TType type parameter. This is because * the "extends" condition will narrow the type of TType to just TDesired. So, "string | null" will be narrowed to * "string", but we actually want to return the original "string | null". * * By returning the TDesired when there's no match, we get nice error messages that state what the desired type was. */ export declare type AllowUnions = TType extends TDesired ? TOriginal : TDesired; export declare type MapAllowUnions = { [K in TKey]: AllowUnions; }; export declare type TypedPropertyDecorator = , TKey extends StringOrSymbolKey>(target: TClass, propertyKey: TKey) => void; export declare function getWorkingSchema(target: TClass): WorkingSchema; export declare function getMergedWorkingSchemas(target: object): WorkingSchema; export declare function getJoiSchema(clz: AnyClass): ObjectSchema; export declare function getPropertySchema>(target: TClass, propertyKey: TKey): Schema; export declare function updateSchema>(target: TClass, propertyKey: TKey, schema: Schema): void; export declare function getAndUpdateSchema>(target: TClass, propertyKey: TKey, updateFunction: (schema: Schema) => Schema): void; export declare function constraintDecorator(updateFunction: (schema: Schema) => Schema): TypedPropertyDecorator; export declare function constraintDecoratorWithPeers(peers: StringOrSymbolKey[], updateFunction: (schema: Schema) => Schema): TypedPropertyDecorator; export declare function typeConstraintDecorator(typeSchema: (Joi: typeof joi) => Schema): , TKey extends Extract>(target: TClass, propertyKey: TKey) => void; export declare function verifyPeers(target: TClass, peers: StringOrSymbolKey[]): void;