UNPKG

@darlean/valueobjects

Version:

Library for DDD-like value objects that can be validated, serialized and represented in other programming languages as native objects with native naming.

84 lines (83 loc) 5.84 kB
/// <reference types="node" /> import { CanonicalLike, ICanonical, ICanonicalSource } from '@darlean/canonical'; import 'reflect-metadata'; import { Class, IFromCanonicalOptions, IValueOptions, Value, valueobject } from './base'; import { NoInfer } from './utils'; export declare abstract class PrimitiveValue<TPrimitive> extends Value implements ICanonicalSource { protected _value: TPrimitive; private _canonical?; static from<T extends PrimitiveValue<TPrimitive>, TPrimitive = T extends PrimitiveValue<infer X> ? X : never>(this: Class<T>, value: NoInfer<TPrimitive>): T; static fromCanonical<T extends PrimitiveValue<TPrimitive>, TPrimitive = T extends PrimitiveValue<infer X> ? X : never>(this: Class<T>, value: CanonicalLike, options?: IFromCanonicalOptions): T; static required<T>(this: Class<T>): T; static optional<T>(this: Class<T>): T | undefined; constructor(options: IValueOptions); _peekCanonicalRepresentation(): ICanonical<this>; get value(): TPrimitive; get _logicalTypes(): string[]; equals(other: unknown): boolean; protected abstract _fromCanonical(canonical: ICanonical): TPrimitive; protected abstract _toCanonical(value: TPrimitive, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): TPrimitive | void; } export declare class StringValue extends PrimitiveValue<string> { protected _fromCanonical(canonical: ICanonical): string; protected _toCanonical(value: string, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): string | void; } export declare const stringvalue: typeof valueobject; export declare const stringvalidation: (validator: (value: string) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void; export declare class IntValue extends PrimitiveValue<number> { protected _fromCanonical(canonical: ICanonical): number; protected _toCanonical(value: number, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): number | void; } export declare const intvalue: typeof valueobject; export declare const intvalidation: (validator: (value: number) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void; export declare class FloatValue extends PrimitiveValue<number> { protected _fromCanonical(canonical: ICanonical): number; protected _toCanonical(value: number, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): number | void; } export declare const floatvalue: typeof valueobject; export declare const floatvalidation: (validator: (value: number) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void; export declare class NoneValue extends PrimitiveValue<undefined> { protected _fromCanonical(canonical: ICanonical): undefined; protected _toCanonical(_value: undefined, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): undefined | void; } export declare const nonevalue: typeof valueobject; export declare const nonevalidation: (validator: (value: undefined) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void; export declare class BoolValue extends PrimitiveValue<boolean> { protected _fromCanonical(canonical: ICanonical): boolean; protected _toCanonical(value: boolean, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): boolean | void; } export declare const boolvalue: typeof valueobject; export declare const boolvalidation: (validator: (value: boolean) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void; export declare class DurationValue extends FloatValue { } export declare class MomentValue extends PrimitiveValue<Date> { protected _fromCanonical(canonical: ICanonical): Date; protected _toCanonical(value: Date, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): Date | void; get ms(): number; static fromMilliseconds<T extends Class<MomentValue>>(this: T, ms: number): MomentValue; addDuration(duration: DurationValue): this; subtractDuration(duration: DurationValue): this; } export declare const momentvalue: typeof valueobject; export declare const momentvalidation: (validator: (value: Date) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void; export declare class BinaryValue extends PrimitiveValue<Buffer> { protected _fromCanonical(canonical: ICanonical): Buffer; protected _toCanonical(value: Buffer, logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): Buffer | void; } export declare const binaryvalue: typeof valueobject; export declare const binaryvalidation: (validator: (value: Buffer) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void; export declare class CanonicalValue extends PrimitiveValue<ICanonical> { protected _fromCanonical(canonical: ICanonical): ICanonical; protected _toCanonical(value: ICanonical, _logicalTypes: string[]): ICanonical<this>; protected _validate(v: unknown, fail: (msg: string) => void): ICanonical | void; } export declare const canonicalvalue: typeof valueobject; export declare const canonicalvalidation: (validator: (value: ICanonical<ICanonicalSource>) => string | boolean | void, description?: string | undefined) => (constructor: Function) => void;