import { ClassType, TypeAnnotation } from './core/index.js'; import { Type, TypeClass, TypeObjectLiteral } from './reflection/type.js'; import type { ValidatorError } from './validator.js'; export type ValidatorMeta = TypeAnnotation<'validator', [ Name, Args ]>; export type ValidateFunction = (value: any, type: Type, options: any) => ValidatorError | void; export type Validate[2] = unknown> = ValidatorMeta<'function', [ T, Options ]>; export type Pattern = ValidatorMeta<'pattern', [T]>; export type Alpha = ValidatorMeta<'alpha'>; export type Alphanumeric = ValidatorMeta<'alphanumeric'>; export type Ascii = ValidatorMeta<'ascii'>; export type Decimal = ValidatorMeta<'decimal', [ MinDigits, MaxDigits ]>; export type MultipleOf = ValidatorMeta<'multipleOf', [Num]>; export type MinLength = ValidatorMeta<'minLength', [Length]>; export type MaxLength = ValidatorMeta<'maxLength', [Length]>; export type Includes = ValidatorMeta<'includes', [T]>; export type Excludes = ValidatorMeta<'excludes', [T]>; export type Minimum = ValidatorMeta<'minimum', [T]>; export type Maximum = ValidatorMeta<'maximum', [T]>; /** Includes 0. Use PositiveNoZero to exclude 0. */ export type Positive = ValidatorMeta<'positive', unknown & [true]>; /** * Includes 0. Use NegativeNoZero to exclude 0. */ export type Negative = ValidatorMeta<'negative', [true]>; export type PositiveNoZero = ValidatorMeta<'positive', [false]>; export type NegativeNoZero = ValidatorMeta<'negative', [false]>; export type ExclusiveMinimum = ValidatorMeta<'exclusiveMinimum', [T]>; export type ExclusiveMaximum = ValidatorMeta<'exclusiveMaximum', [T]>; export type BeforeDate = ValidatorMeta<'beforeDate', [T]>; export type AfterDate = ValidatorMeta<'afterDate', [T]>; export type BeforeNow = ValidatorMeta<'beforeNow'>; export type AfterNow = ValidatorMeta<'afterNow'>; export declare const EMAIL_REGEX: RegExp; export type Email = string & Pattern; /** * Integer */ export type integer = number; /** * Integer 8 bit. * Min value -127, max value 128 */ export type int8 = number; /** * Unsigned integer 8 bit. * Min value 0, max value 255 */ export type uint8 = number; /** * Integer 16 bit. * Min value -32768, max value 32767 */ export type int16 = number; /** * Unsigned integer 16 bit. * Min value 0, max value 65535 */ export type uint16 = number; /** * Integer 8 bit. * Min value -2147483648, max value 2147483647 */ export type int32 = number; /** * Unsigned integer 32 bit. * Min value 0, max value 4294967295 */ export type uint32 = number; /** * Float (same as number, but different semantic for databases). */ export type float = number; /** * Float 32 bit. */ export type float32 = number; /** * Float 64 bit. */ export type float64 = number; export type Annotations = any; export declare class AnnotationDefinition { readonly id: string; symbol: symbol; constructor(id: string); register(annotations: Annotations, data: T): void; reset(annotations: Annotations): void; registerType(type: TType, data: T): TType; replace(annotations: Annotations, annotation: T[]): void; replaceType(type: Type, annotation: T[]): void; getAnnotations(type: Type): T[]; getFirst(type: Type): T | undefined; hasAnnotations(type: Type): boolean; } export type AnnotationType> = T extends AnnotationDefinition ? K : never; export type ReferenceActions = 'RESTRICT' | 'NO ACTION' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT'; export interface ReferenceOptions { /** * Default is CASCADE. */ onDelete?: ReferenceActions; /** * Default is CASCADE. */ onUpdate?: ReferenceActions; } /** * Assigns one or multiple groups to a type. * * @example * ```typescript * interface User { * username: string; * password: string & Group<'credentials'>; * } * ``` */ export type Group = TypeAnnotation<'group', Name>; /** * Excludes the type from serialization of all kind. * * @example * ```typescript * interface User { * username: string; * password: string & Excluded; * } * ``` */ export type Excluded = TypeAnnotation<'excluded', Name>; /** * Assigns arbitrary data to a type that can be read in runtime. * * @example * ```typescript * interface User { * username: string; * password: string & Data<'role', 'admin'>; * } * ``` */ export type Data = TypeAnnotation<'data', [Name, Value]>; /** * Resets an already set decorator to undefined. * * The required Name is the name of the type decorator (its first tuple entry). * * ```typescript * type Password = string & MinLength<6> & Excluded; * * interface UserCreationPayload { * password: Password & ResetAnnotation<'excluded'> * } * ``` */ export type ResetAnnotation = TypeAnnotation<'reset', Name>; /** * note: if this is adjusted, make sure to adjust ReflectionClass, entityAnnotation, and type serializer accordingly. */ export interface EntityOptions { name?: string; description?: string; } /** * Type to decorate an interface/object literal with entity information. * * ```typescript * interface User extends Entity<{name: 'user'}> { * id: number & Identifier; * username: string; * } * ``` */ export type Entity = {} & TypeAnnotation<'entity', T>; /** * Marks a property as the identifier of its object: the value that uniquely * identifies an instance, e.g. when it is the target of a `Reference`. * ```typescript * class User { * id: number & Identifier = 0; * } * ``` */ export type Identifier = TypeAnnotation<'identifier'>; type TypeKeyOf = T[keyof T]; export type IdentifierFields = any extends T ? any : { [P in keyof T]: Required extends Required ? T[P] : never; }; export type IdentifierType = any extends T ? any : TypeKeyOf>; export type ReferenceFields = { [P in keyof T]: Required extends Required | Required ? T[P] : never; }; /** * Same as `bigint` but serializes to unsigned binary with unlimited size (instead of 8 bytes in most databases). * Negative values will be converted to positive (abs(x)). * * ```typescript * class Entity { * id: BinaryBigInt = 0n; * } * ``` */ export type BinaryBigInt = bigint & TypeAnnotation<'binaryBigInt'>; /** * Same as `bigint` but serializes to signed binary with unlimited size (instead of 8 bytes in most databases). * The binary has an additional leading sign byte and is represented as an uint: 255 for negative, 0 for zero, or 1 for positive. * * ```typescript * class Entity { * id: SignedBinaryBigInt = 0n; * } * ``` */ export type SignedBinaryBigInt = bigint & TypeAnnotation<'signedBinaryBigInt'>; export interface BackReferenceOptions { /** * Necessary for normalised many-to-many relations. This defines the class of the pivot table/collection. */ via?: ClassType | {}; /** * A reference/backReference can define which reference on the other side * reference back. This is necessary when there are multiple outgoing references * to the same entity. */ mappedBy?: string; } export type Reference = TypeAnnotation<'reference', Options>; export type BackReference = TypeAnnotation<'backReference', Options>; /** * Options for the Inline annotation. * Controls which serializers should serialize the reference as a nested object. */ export interface InlineOptions { /** * List of serializer names where inline serialization is active. * If specified, only these serializers will output nested objects. * Example: { only: ['json'] } - only JSON serializer outputs nested, BSON outputs FK. */ only?: string[]; /** * List of serializer names where inline serialization is disabled. * These serializers will output FK even with & Inline. * Example: { except: ['bson'] } - BSON outputs FK, others output nested. */ except?: string[]; } /** * Marks a Reference field to be serialized as a nested object instead of just the foreign key. * * By default, `& Reference` fields serialize as FK only (just the identifier). * Adding `& Inline` changes this to serialize the full nested object. * * @example * ```typescript * class Post { * // Serializes as FK: { author: 2 } * author: User & Reference; * * // Serializes as nested: { editor: { id: 3, name: "Bob" } } * // Throws if not loaded via joinWith() * editor: User & Reference & Inline; * * // Nested only for JSON serializer, FK for BSON * reviewer: User & Reference & Inline<{ only: ['json'] }>; * } * ``` * * Note: MongoDB database serialization always outputs FK regardless of Inline. */ export type Inline = TypeAnnotation<'inline', Options>; export type EmbeddedMeta = TypeAnnotation<'embedded', Options>; export type Embedded = T & EmbeddedMeta; export type MapName = TypeAnnotation<'mapName', [ Alias, ForSerializer ]>; export interface EmbeddedOptions { prefix?: string; } export declare const embeddedAnnotation: AnnotationDefinition; export declare function hasEmbedded(type: Type): boolean; export declare enum BinaryBigIntType { unsigned = 0, signed = 1 } export declare const binaryBigIntAnnotation: AnnotationDefinition; export declare const groupAnnotation: AnnotationDefinition; export declare const excludedAnnotation: { isExcluded(type: Type, name: string): boolean; symbol: symbol; readonly id: string; register(annotations: Annotations, data: string): void; reset(annotations: Annotations): void; registerType(type: TType, data: string): TType; replace(annotations: Annotations, annotation: string[]): void; replaceType(type: Type, annotation: string[]): void; getAnnotations(type: Type): string[]; getFirst(type: Type): string | undefined; hasAnnotations(type: Type): boolean; }; export declare const dataAnnotation: { set(type: T, key: string, value: any): T; get(type: Type, key: string): any; symbol: symbol; readonly id: string; register(annotations: Annotations, data: { [name: string]: any; }): void; reset(annotations: Annotations): void; registerType(type: TType, data: { [name: string]: any; }): TType; replace(annotations: Annotations, annotation: { [name: string]: any; }[]): void; replaceType(type: Type, annotation: { [name: string]: any; }[]): void; getAnnotations(type: Type): { [name: string]: any; }[]; getFirst(type: Type): { [name: string]: any; } | undefined; hasAnnotations(type: Type): boolean; }; /** * All raw data from `TypeAnnotation` types. */ export declare const typeAnnotation: { /** * Returns the parsed Type to JS objects, e.g. `{name: string}` => `{name: 'xy'}` */ getOption(type: Type, name: string): any; /** * Returns the Type object of the annotation which can be parsed with `typeToObject`. */ getType(type: Type, name: string): Type | undefined; symbol: symbol; readonly id: string; register(annotations: Annotations, data: { name: string; options: Type; }): void; reset(annotations: Annotations): void; registerType(type: TType, data: { name: string; options: Type; }): TType; replace(annotations: Annotations, annotation: { name: string; options: Type; }[]): void; replaceType(type: Type, annotation: { name: string; options: Type; }[]): void; getAnnotations(type: Type): { name: string; options: Type; }[]; getFirst(type: Type): { name: string; options: Type; } | undefined; hasAnnotations(type: Type): boolean; }; export declare const referenceAnnotation: AnnotationDefinition; export declare const inlineAnnotation: AnnotationDefinition; export declare const entityAnnotation: { set(type: Type, name: K, value: EntityOptions[K]): void; get(type: Type): EntityOptions; symbol: symbol; readonly id: string; register(annotations: Annotations, data: EntityOptions): void; reset(annotations: Annotations): void; registerType(type: TType, data: EntityOptions): TType; replace(annotations: Annotations, annotation: EntityOptions[]): void; replaceType(type: Type, annotation: EntityOptions[]): void; getAnnotations(type: Type): EntityOptions[]; getFirst(type: Type): EntityOptions | undefined; hasAnnotations(type: Type): boolean; }; export declare const mapNameAnnotation: AnnotationDefinition<{ name: string; serializer?: string; }>; export declare const identifierAnnotation: { isIdentifier(type: Type): boolean; symbol: symbol; readonly id: string; register(annotations: Annotations, data: true): void; reset(annotations: Annotations): void; registerType(type: TType, data: true): TType; replace(annotations: Annotations, annotation: true[]): void; replaceType(type: Type, annotation: true[]): void; getAnnotations(type: Type): true[]; getFirst(type: Type): true | undefined; hasAnnotations(type: Type): boolean; }; export interface BackReferenceOptionsResolved { /** * Necessary for normalised many-to-many relations. This defines the class of the pivot table/collection. */ via?: TypeClass | TypeObjectLiteral; /** * A reference/backReference can define which reference on the other side * reference back. This is necessary when there are multiple outgoing references * to the same entity. */ mappedBy?: string; } export declare const backReferenceAnnotation: AnnotationDefinition; export declare function isIdentifierType(type: Type): boolean; export declare function isBinaryBigIntType(type: Type): boolean; export declare function isReferenceType(type: Type): boolean; export declare function getReferenceType(type: Type): ReferenceOptions | undefined; export declare function isBackReferenceType(type: Type): boolean; export declare function getBackReferenceType(type: Type): BackReferenceOptionsResolved; export declare const defaultAnnotation: AnnotationDefinition; export declare const validationAnnotation: AnnotationDefinition<{ name: string; args: Type[]; }>; export {}; export declare type __ΩValidatorMeta = any[]; export declare type __ΩValidateFunction = any[]; export declare type __ΩValidate = any[]; export declare type __ΩPattern = any[]; export declare type __ΩAlpha = any[]; export declare type __ΩAlphanumeric = any[]; export declare type __ΩAscii = any[]; export declare type __ΩDecimal = any[]; export declare type __ΩMultipleOf = any[]; export declare type __ΩMinLength = any[]; export declare type __ΩMaxLength = any[]; export declare type __ΩIncludes = any[]; export declare type __ΩExcludes = any[]; export declare type __ΩMinimum = any[]; export declare type __ΩMaximum = any[]; export declare type __ΩPositive = any[]; export declare type __ΩNegative = any[]; export declare type __ΩPositiveNoZero = any[]; export declare type __ΩNegativeNoZero = any[]; export declare type __ΩExclusiveMinimum = any[]; export declare type __ΩExclusiveMaximum = any[]; export declare type __ΩBeforeDate = any[]; export declare type __ΩAfterDate = any[]; export declare type __ΩBeforeNow = any[]; export declare type __ΩAfterNow = any[]; export declare type __ΩEmail = any[]; export declare type __Ωinteger = any[]; export declare type __Ωint8 = any[]; export declare type __Ωuint8 = any[]; export declare type __Ωint16 = any[]; export declare type __Ωuint16 = any[]; export declare type __Ωint32 = any[]; export declare type __Ωuint32 = any[]; export declare type __Ωfloat = any[]; export declare type __Ωfloat32 = any[]; export declare type __Ωfloat64 = any[]; export declare type __ΩAnnotations = any[]; export declare type __ΩAnnotationType = any[]; export declare type __ΩReferenceActions = any[]; export declare type __ΩReferenceOptions = any[]; export declare type __ΩGroup = any[]; export declare type __ΩExcluded = any[]; export declare type __ΩData = any[]; export declare type __ΩResetAnnotation = any[]; export declare type __ΩEntityOptions = any[]; export declare type __ΩEntity = any[]; export declare type __ΩIdentifier = any[]; export declare type __ΩIdentifierFields = any[]; export declare type __ΩIdentifierType = any[]; export declare type __ΩReferenceFields = any[]; export declare type __ΩBinaryBigInt = any[]; export declare type __ΩSignedBinaryBigInt = any[]; export declare type __ΩBackReferenceOptions = any[]; export declare type __ΩReference = any[]; export declare type __ΩBackReference = any[]; export declare type __ΩInlineOptions = any[]; export declare type __ΩInline = any[]; export declare type __ΩEmbeddedMeta = any[]; export declare type __ΩEmbedded = any[]; export declare type __ΩMapName = any[]; export declare type __ΩEmbeddedOptions = any[]; export declare type __ΩBinaryBigIntType = any[]; export declare type __ΩBackReferenceOptionsResolved = any[];