import type { Transaction } from './connections'; import { type Cascade, type DeferMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums'; import { type AssignOptions, type Collection, type EntityFactory, type EntityIdentifier, type EntityLoaderOptions, type EntityRepository, Reference, type ScalarReference } from './entity'; import type { MikroORM } from './MikroORM'; import type { SerializationContext, SerializeOptions } from './serialization'; import type { EntitySchema, MetadataStorage } from './metadata'; import type { Type, types } from './types'; import type { Platform } from './platforms'; import type { Configuration, RawQueryFragment } from './utils'; import type { EntityManager } from './EntityManager'; import type { EmbeddedPrefixMode } from './decorators/Embedded'; import type { EventSubscriber } from './events'; import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers'; export type Constructor = new (...args: any[]) => T; export type Dictionary = { [k: string]: T; }; export type EntityKey = string & { [K in keyof T]-?: CleanKeys extends never ? never : K; }[keyof T]; export type EntityValue = T[EntityKey]; export type EntityDataValue = EntityData[EntityKey]; export type FilterKey = keyof FilterQuery; export type AsyncFunction = (args: T) => Promise; export type Compute = { [K in keyof T]: T[K]; } & {}; type InternalKeys = 'EntityRepositoryType' | 'PrimaryKeyProp' | 'OptionalProps' | 'EagerProps' | 'HiddenProps' | '__selectedType' | '__loadedType'; export type CleanKeys = (T[K] & {}) extends Function ? never : K extends symbol | InternalKeys ? never : B extends true ? (T[K] & {}) extends Scalar ? never : K : K; export type FunctionKeys = T[K] extends Function ? K : never; export type Cast = T extends R ? T : R; export type IsUnknown = T extends unknown ? unknown extends T ? true : never : never; export type IsAny = 0 extends (1 & T) ? true : false; export type IsNever = [T] extends [never] ? True : False; export type MaybePromise = T | Promise; export type NoInfer = [T][T extends any ? 0 : never]; export type DeepPartial = T & { [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial[] : T[P] extends Readonly[] ? Readonly>[] : DeepPartial; }; export declare const EntityRepositoryType: unique symbol; export declare const PrimaryKeyProp: unique symbol; export declare const OptionalProps: unique symbol; export declare const EagerProps: unique symbol; export declare const HiddenProps: unique symbol; export declare const Config: unique symbol; export type Opt = T & Opt.Brand; export declare namespace Opt { const __optional: unique symbol; interface Brand { [__optional]?: 1; } } export type RequiredNullable = (T & RequiredNullable.Brand) | null; export declare namespace RequiredNullable { const __requiredNullable: unique symbol; interface Brand { [__requiredNullable]?: 1; } } export type Hidden = T & Hidden.Brand; export declare namespace Hidden { const __hidden: unique symbol; interface Brand { [__hidden]?: 1; } } export type DefineConfig = T & DefineConfig.Brand; export declare namespace DefineConfig { const __config: unique symbol; interface Brand { [__config]?: 1; } } export type CleanTypeConfig = Compute>>; export interface TypeConfig { forceObject?: boolean; } export type UnwrapPrimary = T extends Scalar ? T : T extends Reference ? Primary : Primary; type PrimaryPropToType = { [Index in keyof Keys]: UnwrapPrimary; }; type ReadonlyPrimary = T extends any[] ? Readonly : T; export type Primary = IsAny extends true ? any : T extends { [PrimaryKeyProp]?: infer PK; } ? PK extends undefined ? Omit : PK extends keyof T ? ReadonlyPrimary> : PK extends (keyof T)[] ? ReadonlyPrimary> : PK : T extends { _id?: infer PK; } ? ReadonlyPrimary | string : T extends { id?: infer PK; } ? ReadonlyPrimary : T extends { uuid?: infer PK; } ? ReadonlyPrimary : T; /** @internal */ export type PrimaryProperty = T extends { [PrimaryKeyProp]?: infer PK; } ? (PK extends keyof T ? PK : (PK extends any[] ? PK[number] : never)) : T extends { _id?: any; } ? (T extends { id?: any; } ? 'id' | '_id' : '_id') : T extends { id?: any; } ? 'id' : T extends { uuid?: any; } ? 'uuid' : never; export type IPrimaryKeyValue = number | string | bigint | Date | { toHexString(): string; }; export type IPrimaryKey = T; export type Scalar = boolean | number | string | bigint | symbol | Date | RegExp | Uint8Array | { toHexString(): string; }; export type ExpandScalar = null | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T); export type OperatorMap = { $and?: ExpandQuery[]; $or?: ExpandQuery[]; $eq?: ExpandScalar | readonly ExpandScalar[]; $ne?: ExpandScalar; $in?: readonly ExpandScalar[]; $nin?: readonly ExpandScalar[]; $not?: ExpandQuery; $none?: ExpandQuery; $some?: ExpandQuery; $every?: ExpandQuery; $gt?: ExpandScalar; $gte?: ExpandScalar; $lt?: ExpandScalar; $lte?: ExpandScalar; $like?: string; $re?: string; $ilike?: string; $fulltext?: string; $overlap?: readonly string[] | string | object; $contains?: readonly string[] | string | object; $contained?: readonly string[] | string | object; $exists?: boolean; $hasKey?: string; $hasKeys?: readonly string[]; $hasSomeKeys?: readonly string[]; }; export type FilterItemValue = T | ExpandScalar | Primary; export type FilterValue = OperatorMap> | FilterItemValue | FilterItemValue[] | null; export type FilterObject = { -readonly [K in EntityKey]?: ExpandQuery> | FilterValue> | null; }; export type ExpandObject = T extends object ? T extends Scalar ? never : FilterObject : never; export type ExpandQuery = T extends object ? T extends Scalar ? never : FilterQuery : FilterValue; export type EntityProps = { -readonly [K in EntityKey]?: T[K]; }; export type ObjectQuery = OperatorMap & FilterObject; export type FilterQuery = ObjectQuery | NonNullable>> | NonNullable & OperatorMap> | FilterQuery[]; export type QBFilterQuery = ObjectQuery | Dictionary; export interface IWrappedEntity { isInitialized(): boolean; isTouched(): boolean; isManaged(): boolean; populated(populated?: boolean): void; populate(populate: readonly AutoPath[] | false, options?: EntityLoaderOptions): Promise>; init(options?: FindOneOptions): Promise | null>; toReference(): Ref & LoadedReference>>; toObject(): EntityDTO; toObject(ignoreFields: never[]): EntityDTO; toObject>(ignoreFields: Ignored[]): Omit, Ignored>; toJSON(...args: any[]): EntityDTO; toPOJO(): EntityDTO; serialize = FromEntityType, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions): EntityDTO>; setSerializationContext(options: LoadHint): void; assign = FromEntityType, Convert extends boolean = false, Data extends EntityData | Partial> = EntityData | Partial>>(data: Data & IsSubset, Data>, options?: AssignOptions): MergeSelected; getSchema(): string | undefined; setSchema(schema?: string): void; } export interface IWrappedEntityInternal extends IWrappedEntity { hasPrimaryKey(): boolean; getPrimaryKey(convertCustomTypes?: boolean): Primary | null; getPrimaryKeys(convertCustomTypes?: boolean): Primary[] | null; setPrimaryKey(val: Primary): void; getSerializedPrimaryKey(): string & keyof Entity; __meta: EntityMetadata; __data: Dictionary; __em?: EntityManager; __platform: Platform; __config: Configuration; __factory: EntityFactory; __hydrator: IHydrator; __initialized: boolean; __touched: boolean; __originalEntityData?: EntityData; __loadedProperties: Set; __identifier?: EntityIdentifier | EntityIdentifier[]; __managed: boolean; __processing: boolean; __schema?: string; __populated: boolean; __onLoadFired: boolean; __reference?: Ref; __pk?: Primary; __primaryKeys: Primary[]; __serializationContext: { root?: SerializationContext; populate?: PopulateOptions[]; fields?: Set; exclude?: string[]; }; } export type AnyEntity = Partial; export type EntityClass = Function & { prototype: T; }; export type EntityClassGroup = { entity: EntityClass; schema: EntityMetadata | EntitySchema; }; export type EntityName = string | EntityClass | EntitySchema | { name: string; }; export type GetRepository = Entity[typeof EntityRepositoryType] extends EntityRepository | undefined ? NonNullable : Fallback; export type EntityDataPropValue = T | Primary; type ExpandEntityProp = T extends Record ? { [K in keyof T as CleanKeys]?: EntityDataProp, C> | EntityDataPropValue> | null; } | EntityDataPropValue> : T; type ExpandRequiredEntityProp = T extends Record ? ExpandRequiredEntityPropObject | EntityDataPropValue> : T; type ExpandRequiredEntityPropObject = { [K in keyof T as RequiredKeys]: RequiredEntityDataProp, T, C> | EntityDataPropValue>; } & { [K in keyof T as OptionalKeys]?: RequiredEntityDataProp, T, C> | EntityDataPropValue> | null | undefined; }; type NonArrayObject = object & { [Symbol.iterator]?: never; }; export type EntityDataProp = T extends Date ? string | Date : T extends Scalar ? T : T extends { __runtime?: infer Runtime; __raw?: infer Raw; } ? (C extends true ? Raw : Runtime) : T extends Reference ? EntityDataNested : T extends ScalarReference ? EntityDataProp : T extends Collection ? U | U[] | EntityDataNested | EntityDataNested[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | EntityDataNested | EntityDataNested[] : U[] | EntityDataNested[] : EntityDataNested; export type RequiredEntityDataProp = T extends Date ? string | Date : Exclude extends RequiredNullable.Brand ? T | null : T extends Scalar ? T : T extends { __runtime?: infer Runtime; __raw?: infer Raw; } ? (C extends true ? Raw : Runtime) : T extends Reference ? RequiredEntityDataNested : T extends ScalarReference ? RequiredEntityDataProp : T extends Collection ? U | U[] | RequiredEntityDataNested | RequiredEntityDataNested[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | RequiredEntityDataNested | RequiredEntityDataNested[] : U[] | RequiredEntityDataNested[] : RequiredEntityDataNested; export type EntityDataNested = T extends undefined ? never : T extends any[] ? Readonly : EntityData | ExpandEntityProp; type EntityDataItem = C extends false ? T | EntityDataProp | null : EntityDataProp | null; export type RequiredEntityDataNested = T extends any[] ? Readonly : RequiredEntityData | ExpandRequiredEntityProp; type ExplicitlyOptionalProps = (T extends { [OptionalProps]?: infer K; } ? K : never) | ({ [K in keyof T]: T[K] extends Opt ? K : never; }[keyof T] & {}); type NullableKeys = { [K in keyof T]: V extends T[K] ? K : never; }[keyof T]; type RequiredNullableKeys = { [K in keyof T]: Exclude extends RequiredNullable.Brand ? K : never; }[keyof T]; type ProbablyOptionalProps = PrimaryProperty | ExplicitlyOptionalProps | Exclude>, RequiredNullableKeys>; type IsOptional = T[K] extends Collection ? true : ExtractType extends I ? true : K extends ProbablyOptionalProps ? true : false; type RequiredKeys = IsOptional extends false ? CleanKeys : never; type OptionalKeys = IsOptional extends false ? never : CleanKeys; export type EntityData = { [K in EntityKey]?: EntityDataItem; }; export type RequiredEntityData = { [K in keyof T as RequiredKeys]: T[K] | RequiredEntityDataProp | Primary; } & { [K in keyof T as OptionalKeys]?: T[K] | RequiredEntityDataProp | Primary | null; }; export type EntityDictionary = EntityData & Record; type ExtractEagerProps = T extends { [EagerProps]?: infer PK; } ? PK : never; type Relation = { [P in keyof T as T[P] extends unknown[] | Record ? P : never]?: T[P]; }; /** Identity type that can be used to get around issues with cycles in bidirectional relations. It will disable reflect-metadata inference. */ export type Rel = T; /** Alias for `ScalarReference` (see {@apilink Ref}). */ export type ScalarRef = ScalarReference; /** Alias for `Reference & { id: number }` (see {@apilink Ref}). */ export type EntityRef = true extends IsUnknown> ? Reference : IsAny extends true ? Reference : ({ [K in PrimaryProperty & keyof T]: T[K]; } & Reference); /** * Ref type represents a `Reference` instance, and adds the primary keys to its prototype automatically, so you can do * `ref.id` instead of `ref.unwrap().id`. It resolves to either `ScalarRef` or `EntityRef`, based on the type argument. */ export type Ref = T extends any ? IsAny extends true ? Reference : T extends Scalar ? ScalarReference : EntityRef : never; type ExtractHiddenProps = (T extends { [HiddenProps]?: infer K; } ? K : never) | ({ [K in keyof T]: T[K] extends Hidden ? K : never; }[keyof T] & {}); type ExcludeHidden = K extends ExtractHiddenProps ? never : K; type ExtractConfig = T extends { [Config]?: infer K; } ? (K & TypeConfig) : TypeConfig; type PreferExplicitConfig = IsNever; type PrimaryOrObject = PreferExplicitConfig>['forceObject'] extends true ? { [K in PrimaryProperty & keyof U]: U[K]; } : Primary; export type EntityDTOProp = T extends Scalar ? T : T extends { __serialized?: infer U; } ? (IsUnknown extends false ? U : T) : T extends LoadedReference ? EntityDTO : T extends Reference ? PrimaryOrObject : T extends ScalarReference ? U : T extends LoadedCollection ? EntityDTO[] : T extends Collection ? PrimaryOrObject[] : T extends readonly (infer U)[] ? (T extends readonly any[] ? T : U[]) : T extends Relation ? EntityDTO : T; type DTOProbablyOptionalProps = NonNullable>; type DTOIsOptional = T[K] extends LoadedCollection ? false : K extends PrimaryProperty ? false : K extends DTOProbablyOptionalProps ? true : false; type DTORequiredKeys = DTOIsOptional extends false ? ExcludeHidden & CleanKeys : never; type DTOOptionalKeys = DTOIsOptional extends false ? never : ExcludeHidden & CleanKeys; export type EntityDTO = { [K in keyof T as DTORequiredKeys]: EntityDTOProp | AddOptional; } & { [K in keyof T as DTOOptionalKeys]?: EntityDTOProp | AddOptional; }; type PropertyName = IsUnknown extends false ? keyof T : string; type TableName = { name: string; schema?: string; toString: () => string; }; export type FormulaTable = { alias: string; name: string; schema?: string; qualifiedName: string; toString: () => string; }; export type IndexCallback = (table: TableName, columns: Record, string>, indexName: string) => string | RawQueryFragment; export type FormulaCallback = (table: FormulaTable, columns: Record, string>) => string; export type CheckCallback = (columns: Record, string>) => string; export type GeneratedColumnCallback = (columns: Record) => string; export interface CheckConstraint { name?: string; property?: string; expression: string | CheckCallback; } export type AnyString = string & {}; export interface EntityProperty { name: EntityKey; entity: () => EntityName; type: keyof typeof types | AnyString; runtimeType: 'number' | 'string' | 'boolean' | 'bigint' | 'Buffer' | 'Date' | 'object' | 'any' | AnyString; targetMeta?: EntityMetadata; columnTypes: string[]; generated?: string | GeneratedColumnCallback; customType?: Type; customTypes: (Type | undefined)[]; hasConvertToJSValueSQL: boolean; hasConvertToDatabaseValueSQL: boolean; autoincrement?: boolean; returning?: boolean; primary?: boolean; serializedPrimaryKey: boolean; groups?: string[]; lazy?: boolean; array?: boolean; length?: number; precision?: number; scale?: number; kind: ReferenceKind; ref?: boolean; fieldNames: string[]; fieldNameRaw?: string; default?: string | number | boolean | null; defaultRaw?: string; formula?: FormulaCallback; filters?: FilterOptions; prefix?: string | boolean; prefixMode?: EmbeddedPrefixMode; embedded?: [EntityKey, EntityKey]; embeddedPath?: string[]; embeddable: EntityClass; embeddedProps: Dictionary; discriminatorColumn?: string; object?: boolean; index?: boolean | string; unique?: boolean | string; nullable?: boolean; inherited?: boolean; renamedFrom?: string; stiFieldNames?: string[]; stiFieldNameMap?: Dictionary; unsigned?: boolean; mapToPk?: boolean; persist?: boolean; hydrate?: boolean; trackChanges?: boolean; hidden?: boolean; enum?: boolean; items?: (number | string)[]; nativeEnumName?: string; version?: boolean; concurrencyCheck?: boolean; eager?: boolean; setter?: boolean; getter?: boolean; getterName?: keyof Owner; accessor?: EntityKey; cascade: Cascade[]; orphanRemoval?: boolean; onCreate?: (entity: Owner, em: EntityManager) => any; onUpdate?: (entity: Owner, em: EntityManager) => any; deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString; updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString; strategy?: LoadStrategy; owner: boolean; inversedBy: EntityKey; mappedBy: EntityKey; where?: FilterQuery; orderBy?: QueryOrderMap | QueryOrderMap[]; customOrder?: string[] | number[] | boolean[]; fixedOrder?: boolean; fixedOrderColumn?: string; pivotTable: string; pivotEntity: string; joinColumns: string[]; ownColumns: string[]; inverseJoinColumns: string[]; referencedColumnNames: string[]; referencedTableName: string; referencedPKs: EntityKey[]; serializer?: (value: any, options?: SerializeOptions) => any; serializedName?: string; comment?: string; /** mysql only */ extra?: string; userDefined?: boolean; optional?: boolean; ignoreSchemaChanges?: ('type' | 'extra' | 'default')[]; deferMode?: DeferMode; createForeignKeyConstraint: boolean; foreignKeyName?: string; } export declare class EntityMetadata { private static counter; readonly _id: number; readonly propertyOrder: Map; constructor(meta?: Partial); addProperty(prop: Partial>, sync?: boolean): void; removeProperty(name: string, sync?: boolean): void; getPrimaryProps(flatten?: boolean): EntityProperty[]; getPrimaryProp(): EntityProperty; createColumnMappingObject(): Record, string>; get tableName(): string; set tableName(name: string); sync(initIndexes?: boolean): void; private initIndexes; /** @internal */ clone(): this; } export interface SimpleColumnMeta { name: string; type: string; } export interface EntityMetadata { name?: string; className: string; tableName: string; schema?: string; pivotTable?: boolean; virtual?: boolean; expression?: string | ((em: any, where: ObjectQuery, options: FindOptions) => MaybePromise); discriminatorColumn?: EntityKey | AnyString; discriminatorValue?: number | string; discriminatorMap?: Dictionary; embeddable: boolean; constructorParams: EntityKey[]; forceConstructor: boolean; toJsonParams: string[]; extends: string; collection: string; path: string; primaryKeys: EntityKey[]; simplePK: boolean; compositePK: boolean; versionProperty: EntityKey; concurrencyCheckKeys: Set>; serializedPrimaryKey: EntityKey; properties: { [K in EntityKey]: EntityProperty; }; props: EntityProperty[]; relations: EntityProperty[]; bidirectionalRelations: EntityProperty[]; referencingProperties: { meta: EntityMetadata; prop: EntityProperty; }[]; comparableProps: EntityProperty[]; trackingProps: EntityProperty[]; hydrateProps: EntityProperty[]; uniqueProps: EntityProperty[]; getterProps: EntityProperty[]; indexes: { properties?: EntityKey | EntityKey[]; name?: string; type?: string; options?: Dictionary; expression?: string | IndexCallback; }[]; uniques: { properties?: EntityKey | EntityKey[]; name?: string; options?: Dictionary; expression?: string | IndexCallback; deferMode?: DeferMode | `${DeferMode}`; }[]; checks: CheckConstraint[]; repositoryClass?: string; repository: () => EntityClass>; hooks: { [K in EventType]?: (keyof T | EventSubscriber[EventType])[]; }; prototype: T; class: EntityClass; abstract: boolean; useCache: boolean; filters: Dictionary; comment?: string; selfReferencing?: boolean; hasUniqueProps?: boolean; readonly?: boolean; polymorphs?: EntityMetadata[]; root: EntityMetadata; definedProperties: Dictionary; hasTriggers?: boolean; /** @internal can be used for computed numeric cache keys */ readonly _id: number; } export interface CreateSchemaOptions { wrap?: boolean; schema?: string; } export interface ClearDatabaseOptions { schema?: string; truncate?: boolean; } export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions { clear?: boolean; create?: boolean; forceCheck?: boolean; } export interface DropSchemaOptions { wrap?: boolean; dropMigrationsTable?: boolean; dropForeignKeys?: boolean; dropDb?: boolean; schema?: string; } export interface UpdateSchemaOptions { wrap?: boolean; safe?: boolean; dropDb?: boolean; dropTables?: boolean; schema?: string; fromSchema?: DatabaseSchema; } export interface RefreshDatabaseOptions extends CreateSchemaOptions { ensureIndexes?: boolean; dropDb?: boolean; } export interface ISchemaGenerator { createSchema(options?: CreateSchemaOptions): Promise; ensureDatabase(options?: EnsureDatabaseOptions): Promise; getCreateSchemaSQL(options?: CreateSchemaOptions): Promise; dropSchema(options?: DropSchemaOptions): Promise; getDropSchemaSQL(options?: Omit): Promise; updateSchema(options?: UpdateSchemaOptions): Promise; getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise; getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{ up: string; down: string; }>; createDatabase(name?: string): Promise; dropDatabase(name?: string): Promise; execute(sql: string, options?: { wrap?: boolean; }): Promise; ensureIndexes(): Promise; refreshDatabase(options?: RefreshDatabaseOptions): Promise; clearDatabase(options?: ClearDatabaseOptions): Promise; } export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => { path: string; name: string; } | undefined; export interface GenerateOptions { path?: string; save?: boolean; schema?: string; takeTables?: (RegExp | string)[]; skipTables?: (RegExp | string)[]; skipColumns?: Dictionary<(RegExp | string)[]>; forceUndefined?: boolean; undefinedDefaults?: boolean; bidirectionalRelations?: boolean; identifiedReferences?: boolean; entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema'; inferEntityType?: boolean; enumMode?: 'ts-enum' | 'union-type' | 'dictionary'; esmImport?: boolean; scalarTypeInDecorator?: boolean; scalarPropertiesForRelations?: 'always' | 'never' | 'smart'; fileName?: (className: string) => string; onImport?: ImportsResolver; extraImports?: (basePath: string, originFileName: string) => string[] | undefined; onlyPurePivotTables?: boolean; outputPurePivotTables?: boolean; readOnlyPivotTables?: boolean; customBaseEntityName?: string; useCoreBaseEntity?: boolean; coreImportsPrefix?: string; onInitialMetadata?: MetadataProcessor; onProcessedMetadata?: MetadataProcessor; /** @deprecated use `entityDefinition: 'entitySchema'` instead */ entitySchema?: boolean; } export interface IEntityGenerator { generate(options?: GenerateOptions): Promise; } export type UmzugMigration = { name: string; path?: string; }; export type MigrateOptions = { from?: string | number; to?: string | number; migrations?: string[]; transaction?: Transaction; }; export type MigrationResult = { fileName: string; code: string; diff: MigrationDiff; }; export type MigrationRow = { name: string; executed_at: Date; }; /** * @internal */ export interface IMigratorStorage { executed(): Promise; logMigration(params: Dictionary): Promise; unlogMigration(params: Dictionary): Promise; getExecutedMigrations(): Promise; ensureTable?(): Promise; setMasterMigration(trx: Transaction): void; unsetMasterMigration(): void; getMigrationName(name: string): string; getTableName?(): { schemaName?: string; tableName: string; }; } export interface IMigrator { /** * Checks current schema for changes, generates new migration if there are any. */ createMigration(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise; /** * Checks current schema for changes. */ checkMigrationNeeded(): Promise; /** * Creates initial migration. This generates the schema based on metadata, and checks whether all the tables * are already present. If yes, it will also automatically log the migration as executed. * Initial migration can be created only if the schema is already aligned with the metadata, or when no schema * is present - in such case regular migration would have the same effect. */ createInitialMigration(path?: string): Promise; /** * Returns list of already executed migrations. */ getExecutedMigrations(): Promise; /** * Returns list of pending (not yet executed) migrations found in the migration directory. */ getPendingMigrations(): Promise; /** * Executes specified migrations. Without parameter it will migrate up to the latest version. */ up(options?: string | string[] | MigrateOptions): Promise; /** * Executes down migrations to the given point. Without parameter it will migrate one version down. */ down(options?: string | string[] | MigrateOptions): Promise; /** * Registers event handler. */ on(event: MigratorEvent, listener: (event: UmzugMigration) => MaybePromise): IMigrator; /** * Removes event handler. */ off(event: MigratorEvent, listener: (event: UmzugMigration) => MaybePromise): IMigrator; /** * @internal */ getStorage(): IMigratorStorage; } export type MigratorEvent = 'migrating' | 'migrated' | 'reverting' | 'reverted'; export interface MigrationDiff { up: string[]; down: string[]; } export interface IMigrationGenerator { /** * Generates the full contents of migration file. Uses `generateMigrationFile` to get the file contents. */ generate(diff: MigrationDiff, path?: string, name?: string): Promise<[string, string]>; /** * Creates single migration statement. By default adds `this.addSql(sql);` to the code. */ createStatement(sql: string, padLeft: number): string; /** * Returns the file contents of given migration. */ generateMigrationFile(className: string, diff: MigrationDiff): MaybePromise; } export interface Migration { up(): Promise | void; down(): Promise | void; } export interface MigrationObject { name: string; class: Constructor; } export type FilterDef = { name: string; cond: Dictionary | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions | FindOneOptions, entityName?: EntityName) => Dictionary | Promise); default?: boolean; entity?: string[]; args?: boolean; strict?: boolean; }; export type Populate = readonly AutoPath[] | false; export type PopulateOptions = { field: EntityKey; strategy?: LoadStrategy; all?: boolean; filter?: boolean; joinType?: 'inner join' | 'left join'; children?: PopulateOptions[]; /** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */ dataOnly?: boolean; }; type Loadable = Collection | Reference | Ref | readonly T[]; type ExtractType = T extends Loadable ? U : T; type ExtractStringKeys = { [K in keyof T]-?: CleanKeys; }[keyof T] & {}; type StringKeys = T extends Collection ? ExtractStringKeys> | E : T extends Reference ? ExtractStringKeys> | E : T extends object ? ExtractStringKeys> | E : never; type GetStringKey, E extends string> = K extends keyof T ? ExtractType : (K extends E ? keyof T : never); type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; type CollectionKeys = T extends object ? { [K in keyof T]-?: T[K] extends Collection ? IsAny extends true ? never : K & string : never; }[keyof T] & {} : never; export type AutoPath = P extends boolean ? P : [D] extends [never] ? never : P extends any ? P extends string ? (P & `${string}.` extends never ? P : P & `${string}.`) extends infer Q ? Q extends `${infer A}.${infer B}` ? A extends StringKeys ? `${A}.${AutoPath>, B, E, Prev[D]>}` : never : Q extends StringKeys ? (NonNullable> extends unknown ? Exclude : never) | (StringKeys>, E> extends never ? never : `${Q & string}.`) : StringKeys | `${CollectionKeys}:ref` : never : never : never; export type UnboxArray = T extends any[] ? ArrayElement : T; export type ArrayElement = ArrayType extends (infer ElementType)[] ? ElementType : never; export type ExpandProperty = T extends Reference ? NonNullable : T extends Collection ? NonNullable : T extends (infer U)[] ? NonNullable : NonNullable; type LoadedLoadable = T extends Collection ? LoadedCollection : T extends Reference ? T & LoadedReference : T extends ScalarReference ? LoadedScalarReference : T extends Scalar | any[] ? T : E; type IsTrue = IsNever extends true ? false : T extends boolean ? T extends true ? true : false : false; type StringLiteral = T extends string ? string extends T ? never : T : never; type Prefix = K extends `${infer S}.${string}` ? S : (K extends '*' ? keyof T : K); type IsPrefixedExclude = K extends E ? never : K; export type IsPrefixed = IsNever extends false ? IsPrefixedExclude : K extends symbol ? never : IsTrue extends true ? (T[K] & {} extends Loadable ? K : never) : IsNever> extends true ? never : K extends Prefix ? K : K extends PrimaryProperty ? K : never; type Suffix = Hint extends `${infer Pref}.${infer Suf}` ? (Pref extends Key ? Suf : never) : Hint extends All ? Hint : never; export type IsSubset = keyof U extends keyof T ? {} : Dictionary extends U ? {} : { [K in keyof U as K extends keyof T ? never : CleanKeys]: never; }; declare const __selectedType: unique symbol; declare const __loadedType: unique symbol; type AnyStringToNever = string extends T ? never : T; export type MergeSelected = T extends Loaded ? IsNever> extends true ? Loaded | AnyStringToNever> : Loaded, AnyStringToNever, AnyStringToNever>> : T; type MergeFields = P1 | P2 extends '*' ? '*' : F1 | F2; type MergeExcludes = F extends E ? never : Exclude; export type MergeLoaded = T extends Loaded ? string extends FF ? Loaded | E> : string extends P ? Loaded> : Loaded, MergeFields, P, PP>, MergeExcludes, P, PP>, (R extends true ? never : EE) | E>> : Loaded; export type AddOptional = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never; type LoadedProp = LoadedLoadable, L, F, E>>; export type AddEager = ExtractEagerProps & string; export type ExpandHint = L | AddEager; export type Selected = { [K in keyof T as IsPrefixed>]: LoadedProp, Suffix, Suffix> | AddOptional; } & { [K in keyof T as FunctionKeys]: T[K]; } & { [__selectedType]?: T; }; type LoadedEntityType = { [__loadedType]?: T; } | { [__selectedType]?: T; }; export type EntityType = T | LoadedEntityType; export type FromEntityType = T extends LoadedEntityType ? U : T; type LoadedInternal = [ F ] extends ['*'] ? IsNever extends true ? T & { [K in keyof T as IsPrefixed>]: LoadedProp, Suffix, Suffix, Suffix> | AddOptional; } : { [K in keyof T as IsPrefixed, E>]: LoadedProp, Suffix, Suffix, Suffix> | AddOptional; } : Selected; /** * Represents entity with its loaded relations (`populate` hint) and selected properties (`fields` hint). */ export type Loaded = LoadedInternal & { [__loadedType]?: T; }; export interface LoadedReference extends Reference> { $: NonNullable; get(): NonNullable; } export interface LoadedScalarReference extends ScalarReference { $: T; get(): T; } export interface LoadedCollection extends Collection { $: Collection; get(): Collection; getItems(check?: boolean): T[]; } export type New = Loaded; export interface Highlighter { highlight(text: string): string; } export interface IMetadataStorage { getAll(): Dictionary; get(entity: string, init?: boolean, validate?: boolean): EntityMetadata; find(entity: string): EntityMetadata | undefined; has(entity: string): boolean; set(entity: string, meta: EntityMetadata): EntityMetadata; reset(entity: string): void; } export interface IHydrator { /** * Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances, * mapping FKs to entity instances, as well as merging those entities. */ hydrate(entity: T, meta: EntityMetadata, data: EntityData, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void; /** * Hydrates primary keys only */ hydrateReference(entity: T, meta: EntityMetadata, data: EntityData, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void; isRunning(): boolean; } export interface HydratorConstructor { new (metadata: MetadataStorage, platform: Platform, config: Configuration): IHydrator; } export interface ISeedManager { seed(...classNames: Constructor[]): Promise; /** @internal */ seedString(...classNames: string[]): Promise; createSeeder(className: string): Promise; } export interface Seeder { run(em: EntityManager, context?: T): void | Promise; } export type ConnectionType = 'read' | 'write'; export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise; /** * The type of context that the user intends to inject. */ export type ContextProvider = MaybePromise | ((type: T) => MaybePromise | { getEntityManager(): EntityManager; }>); export {};