import { BackReferenceOptionsResolved, DatabaseFieldOptions, IndexOptions, ReferenceOptions, ReflectionKind, ReflectionVisibility, Type, TypeClass, TypeFunction, TypeMethod, TypeMethodSignature, TypeObjectLiteral, TypeParameter, TypeProperty, TypePropertySignature, TypeTemplateLiteral } from './type.js'; import { AbstractClassType, ClassType } from '@deepkit/core'; import { Packed } from './processor.js'; import type { ValidateFunction } from '../validator.js'; import { SerializedTypes } from '../type-serialization.js'; /** * Receives the runtime type of template argument or runtime symbols like * class references, functions, or packed types. * * Use * * ```typescript * function f(type?: ReceiveType): Type { * return resolveReceiveType(type); * } * ``` */ export type ReceiveType = Packed | ClassType | Type; export declare function resolveReceiveType(type?: Packed | Type | Function | ClassType | AbstractClassType | ReflectionClass): Type; export declare function reflect(o: any, ...args: any[]): Type; export declare function reflectOrUndefined(o: any, ...args: any[]): Type | undefined; export declare function valuesOf(args?: any[], p?: ReceiveType): (string | number | symbol | Type)[]; export declare function propertiesOf(args?: any[], p?: ReceiveType): (string | number | symbol | Type)[]; export declare function getNominalId(args?: any[], p?: ReceiveType): number | undefined; export declare function typeOf(args?: any[], p?: ReceiveType): Type; export declare function removeTypeName(type: T): T; export declare function removeNominal(type: T): T; export declare function getProperty(type: TypeObjectLiteral | TypeClass, memberName: number | string | symbol): TypeProperty | TypePropertySignature | undefined; export declare function toSignature(type: TypeProperty | TypeMethod | TypePropertySignature | TypeMethodSignature): TypePropertySignature | TypeMethodSignature; export declare function hasCircularReference(type: Type): any; export declare function visit(type: Type, visitor: (type: Type, path: string) => false | void, onCircular?: () => void): void; /** * @reflection never */ export declare class ReflectionParameter { readonly parameter: TypeParameter; readonly reflectionFunction: ReflectionMethod | ReflectionFunction; type: Type; constructor(parameter: TypeParameter, reflectionFunction: ReflectionMethod | ReflectionFunction); getType(): Type; getName(): string; get name(): string; isOptional(): boolean; hasDefault(): boolean; isValueRequired(): boolean; getDefaultValue(): any; hasDefaultFunctionExpression(): boolean; applyDecorator(t: TData): void; getVisibility(): ReflectionVisibility | undefined; isPublic(): boolean; isProtected(): boolean; isPrivate(): boolean; isReadonly(): boolean; /** * True if the parameter becomes a property in the class. * This is the case for parameters in constructors with visibility or readonly. * * ```typescript * class User { * constructor(public name: string) {} * } */ isProperty(): boolean; } /** * @reflection never */ export declare class ReflectionFunction { readonly type: TypeMethod | TypeMethodSignature | TypeFunction; parameters: ReflectionParameter[]; description: string; constructor(type: TypeMethod | TypeMethodSignature | TypeFunction); static from(fn: Function): ReflectionFunction; getParameterNames(): (string)[]; hasParameter(name: string | number | symbol): boolean; getParameterOrUndefined(name: string | number | symbol): ReflectionParameter | undefined; getParameter(name: string | number | symbol): ReflectionParameter; getParameterType(name: string | number | symbol): Type | undefined; getParameters(): ReflectionParameter[]; getReturnType(): Type; getName(): number | string | symbol; getDescription(): string; get name(): string; } /** * @reflection never */ export declare class ReflectionMethod extends ReflectionFunction { type: TypeMethod | TypeMethodSignature; reflectionClass: ReflectionClass; /** * Whether this method acts as validator. */ validator: boolean; constructor(type: TypeMethod | TypeMethodSignature, reflectionClass: ReflectionClass); setType(method: TypeMethod | TypeMethodSignature): void; applyDecorator(data: TData): void; clone(reflectionClass?: ReflectionClass, method?: TypeMethod | TypeMethodSignature): ReflectionMethod; isOptional(): boolean; } export declare function resolveForeignReflectionClass(property: ReflectionProperty): ReflectionClass; /** * Resolved the class/object ReflectionClass of the given TypeClass|TypeObjectLiteral */ export declare function resolveClassType(type: Type): ReflectionClass; /** * @reflection never */ export declare class ReflectionProperty { property: TypeProperty | TypePropertySignature; reflectionClass: ReflectionClass; jsonType?: Type; serializer?: SerializerFn; deserializer?: SerializerFn; data: { [name: string]: any; }; /** * The type of the property, not the property itself. * * Note: If the property is optional via `property?: T`, this information * is not available here. It's on `property`. * Use `isOptional()` instead, which handles this case plus the case * where optionality is given via union of T and undefined. */ type: Type; symbol: symbol; protected cachedResolvedReflectionClass?: ReflectionClass; constructor(property: TypeProperty | TypePropertySignature, reflectionClass: ReflectionClass); setType(type: Type): void; isPrimaryKey(): boolean; isEmbedded(): boolean; /** * Returns the sub type if available (for arrays for example). * * @throws Error if the property type does not support sub types. */ getSubType(): Type; /** * If undefined, it's not an embedded class. */ getEmbedded(): { prefix?: string; } | undefined; isBackReference(): boolean; isDatabaseSkipped(database: string): boolean; isDatabaseMigrationSkipped(database: string): boolean; getBackReference(): BackReferenceOptionsResolved; isAutoIncrement(): boolean; isReference(): boolean; isArray(): boolean; isDate(): boolean; isNumber(): boolean; getForeignKeyName(): string; getReference(): ReferenceOptions | undefined; getGroups(): string[]; isInGroup(...group: string[]): boolean; getExcluded(): string[]; isSerializerExcluded(name: string): boolean; getData(): { [name: string]: any; }; /** * Returns the ReflectionClass of the reference class/object literal. * * @throws Error if the property is not from type TypeClass or TypeObjectLiteral */ getResolvedReflectionClass(): ReflectionClass; /** * If undefined the property is not an index. * A unique property is defined as index with IndexOptions.unique=true. */ getIndex(): IndexOptions | undefined; /** * Returns database specific options, if defined * * ```typescript * interface User { * logins: number & DatabaseField<{type: 'integer(8)'}>; * * //of for a specific db engine * logins: number & Sqlite<{type: 'integer(8)'}>; * } * * ``` */ getDatabase(name: string): T | undefined; clone(reflectionClass?: ReflectionClass, property?: TypeProperty | TypePropertySignature): ReflectionProperty; applyDecorator(data: TData): void; getName(): number | string | symbol; getNameAsString(): string; get name(): string; getKind(): ReflectionKind; getType(): Type; getDescription(): string; /** * Whether a value is required from serialization point of view. * If this property has for example a default value (set via constructor or manually via t.default), * then the value is not required to instantiate the property value. */ isValueRequired(): boolean; /** * Returns true when `undefined` or a missing value is allowed at the class itself. * This is now only true when `optional` is set, but also when type is `any`. */ isActualOptional(): boolean; /** * If the property is actual optional or is an union with undefined in it. */ isOptional(): boolean; setOptional(v: boolean): void; isNullable(): boolean; isReadonly(): boolean; isAbstract(): boolean; hasDefault(): boolean; getDefaultValue(): any; hasDefaultFunctionExpression(): boolean; getDefaultValueFunction(): (() => any) | undefined; getVisibility(): ReflectionVisibility | undefined; isPublic(): boolean; isProtected(): boolean; isPrivate(): boolean; } export declare const reflectionClassSymbol: unique symbol; export interface SerializerFn { (value: any, property: ReflectionProperty): any; } export declare class TData { validator: boolean; validators: ValidateFunction[]; type?: Packed | Type | ClassType; data: { [name: string]: any; }; serializer?: SerializerFn; deserializer?: SerializerFn; } export declare class EntityData { name?: string; collectionName?: string; databaseSchemaName?: string; disableConstructor: boolean; data: { [name: string]: any; }; indexes: { names: string[]; options: IndexOptions; }[]; singleTableInheritance?: true; } /** * @reflection never */ export declare class ReflectionClass { readonly type: TypeClass | TypeObjectLiteral; readonly parent?: ReflectionClass | undefined; /** * The description, extracted from the class JSDoc @description. */ description: string; /** * A place where arbitrary data is stored, usually set via decorator t.data. */ data: { [name: string]: any; }; /** * The unique entity name. * * ```typescript * @entity.name('user') * class User { * * } * ``` */ name?: string; databaseSchemaName?: string; disableConstructor: boolean; /** * The collection name, used in database context (also known as table name). * * Usually, if this is not set, `name` will be used. * * ```typescript * @entity.collection('users').name('user') * class User { * * } * ``` */ collectionName?: string; /** * True when @entity.singleTableInheritance was set. */ singleTableInheritance: boolean; /** * Contains all indexed, multi-field using entity.index and all indexes from properties. * * ```typescript * @entity * .collection('users') * .name('user') * .index(['username', 'email']) * .index(['email', 'region'], {unique: true}) * class User { * username: string; * email: string; * } * ``` */ indexes: { names: string[]; options: IndexOptions; }[]; protected propertyNames: string[]; protected methodNames: string[]; protected properties: ReflectionProperty[]; protected methods: ReflectionMethod[]; /** * References and back references. */ protected references: ReflectionProperty[]; protected primaries: ReflectionProperty[]; protected autoIncrements: ReflectionProperty[]; /** * If a custom validator method was set via @t.validator, then this is the method name. */ validationMethod?: string | symbol | number | TypeTemplateLiteral; /** * A class using @t.singleTableInheritance registers itself in this array in its super class. */ subClasses: ReflectionClass[]; constructor(type: TypeClass | TypeObjectLiteral, parent?: ReflectionClass | undefined); clone(): ReflectionClass; toString(): string; getPropertiesDeclaredInConstructor(): ReflectionProperty[]; clearJitContainer(): void; getJitContainer(): any; getClassType(): ClassType; getClassName(): string; createDefaultObject(): object; getName(): string; getDescription(): string; getCollectionName(): string; hasProperty(name: string | symbol | number): boolean; hasMethod(name: string | symbol | number): boolean; getPrimary(): ReflectionProperty; getAutoIncrement(): ReflectionProperty | undefined; isSchemaOf(classType: ClassType): boolean; hasPrimary(): boolean; getPrimaries(): ReflectionProperty[]; /** * Returns the ReflectionClass object from parent/super class, if available. */ getSuperReflectionClass(): ReflectionClass | undefined; removeProperty(name: string | number | symbol): void; registerProperty(property: ReflectionProperty): void; addProperty(prop: { name: number | string | symbol; optional?: true; readonly?: true; description?: string; visibility?: ReflectionVisibility; type: Type; }): ReflectionProperty; registerMethod(method: ReflectionMethod): void; add(member: Type): void; assignedSingleTableInheritanceSubClassesByIdentifier?: { [id: string]: ReflectionClass; }; getAssignedSingleTableInheritanceSubClassesByIdentifier(): { [id: string]: ReflectionClass; } | undefined; hasSingleTableInheritanceSubClasses(): boolean; getSingleTableInheritanceDiscriminantName(): string; applyDecorator(data: EntityData): void; static from(classTypeIn?: ReceiveType | AbstractClassType | TypeClass | TypeObjectLiteral | ReflectionClass, args?: any[]): ReflectionClass; getIndexSignatures(): void; getPropertyNames(): (string | number | symbol)[]; getProperties(): ReflectionProperty[]; getPropertiesInGroup(...group: string[]): ReflectionProperty[]; getMethodNames(): (string | number | symbol)[]; getMethods(): ReflectionMethod[]; /** * Returns references and back references. */ getReferences(): ReflectionProperty[]; getConstructorOrUndefined(): ReflectionMethod | undefined; getPropertyOrUndefined(name: string | number | symbol | TypeTemplateLiteral): ReflectionProperty | undefined; getProperty(name: string | number | symbol): ReflectionProperty; getMethodParameters(name: string | number | symbol): ReflectionParameter[]; getMethodOrUndefined(name: string | number | symbol | TypeTemplateLiteral): ReflectionMethod | undefined; getMethod(name: string | number | symbol): ReflectionMethod; hasCircularReference(): boolean; serializeType(): SerializedTypes; /** * All references have a counter-part. This methods finds it and errors if not possible. * * If the given reference is a owning reference it finds the correct backReference, * which can be found by checking all reference options.mappedBy. * * If the given reference is a back reference it finds the owning reference, * which can be found by using its options.mappedBy. * * Alternatively we simply check for resolvedClassType to be given `classType`, and if only one * found, we return it. When more than one found, we throw an error saying the user he * should make its relation mapping not ambiguous. */ findReverseReference(toClassType: ClassType, fromReference: ReflectionProperty): ReflectionProperty; extractPrimaryKey(item: object): Partial; } export declare type __ΩReceiveType = any[]; export declare type __ΩSerializerFn = any[];