UNPKG

@mikro-orm/core

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

93 lines (92 loc) • 7.69 kB
import type { AnyEntity, Constructor, Dictionary, EntityMetadata, EntityName, EntityProperty, IPrimaryKey } from './typings.js'; /** Base error class for ORM validation errors such as invalid entity state or incorrect usage. */ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Error { readonly entity?: T | undefined; constructor(message: string, entity?: T | undefined); /** * Gets instance of entity that caused this error. */ getEntity(): AnyEntity | undefined; static fromWrongPropertyType(entity: AnyEntity, property: string, expectedType: string, givenType: string, givenValue: string): ValidationError; static fromWrongRepositoryType(entityName: string, repoType: string, method: string): ValidationError; static fromMergeWithoutPK(meta: EntityMetadata): ValidationError; static transactionRequired(): ValidationError; static entityNotManaged(entity: AnyEntity): ValidationError; static notEntity(owner: AnyEntity, prop: EntityProperty, data: any): ValidationError; static notDiscoveredEntity(data: any, meta?: EntityMetadata, action?: string): ValidationError; static invalidPropertyName(entityName: EntityName, invalid: string): ValidationError; static invalidCollectionValues(entityName: string, propName: string, invalid: unknown): ValidationError; static invalidEnumArrayItems(entityName: string, invalid: unknown): ValidationError; static invalidType(type: Constructor<any>, value: any, mode: string): ValidationError; static propertyRequired(entity: AnyEntity, property: EntityProperty): ValidationError; static cannotModifyInverseCollection(owner: AnyEntity, property: EntityProperty): ValidationError; static cannotModifyReadonlyCollection(owner: AnyEntity, property: EntityProperty): ValidationError; static cannotRemoveFromCollectionWithoutOrphanRemoval(owner: AnyEntity, property: EntityProperty): ValidationError; static invalidCompositeIdentifier(meta: EntityMetadata): ValidationError; static cannotCommit(): ValidationError; static cannotUseGlobalContext(): ValidationError; static cannotUseOperatorsInsideEmbeddables(entityName: EntityName, propName: string, payload: unknown): ValidationError; static cannotUseGroupOperatorsInsideScalars(entityName: EntityName, propName: string, payload: unknown): ValidationError; static invalidEmbeddableQuery(entityName: EntityName, propName: string, embeddableType: string): ValidationError; static invalidQueryCondition(cond: unknown): ValidationError; } /** Error thrown when cursor-based pagination encounters missing or invalid cursor values. */ export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> { static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError; static missingValue(entityName: string, prop: string): ValidationError; } /** Error thrown when an optimistic lock conflict is detected during entity persistence. */ export declare class OptimisticLockError<T extends AnyEntity = AnyEntity> extends ValidationError<T> { static notVersioned(meta: EntityMetadata): OptimisticLockError; static lockFailed(entityOrName: AnyEntity | string): OptimisticLockError; static lockFailedVersionMismatch(entity: AnyEntity, expectedLockVersion: number | Date, actualLockVersion: number | Date): OptimisticLockError; } /** Error thrown when entity metadata is invalid, incomplete, or inconsistent. */ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends ValidationError<T> { static fromMissingPrimaryKey(meta: EntityMetadata): MetadataError; static fromWrongReference(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy', owner?: EntityProperty): MetadataError; static fromWrongForeignKey(meta: EntityMetadata, prop: EntityProperty, key: string): MetadataError; static fromWrongTypeDefinition(meta: EntityMetadata, prop: EntityProperty): MetadataError; static fromWrongOwnership(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy'): MetadataError; static fromWrongReferenceKind(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError; static fromInversideSidePrimary(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError; static unknownIndexProperty(meta: EntityMetadata, prop: string, type: string): MetadataError; static multipleVersionFields(meta: EntityMetadata, fields: string[]): MetadataError; static invalidVersionFieldType(meta: EntityMetadata): MetadataError; static fromUnknownEntity(entityName: string, source: string): MetadataError; static noEntityDiscovered(): MetadataError; static onlyAbstractEntitiesDiscovered(): MetadataError; static duplicateEntityDiscovered(paths: string[]): MetadataError; static duplicateFieldName(entityName: EntityName, names: [string, string][]): MetadataError; static multipleDecorators(entityName: string, propertyName: string): MetadataError; static missingMetadata(entity: string): MetadataError; static invalidPrimaryKey(meta: EntityMetadata, prop: EntityProperty, requiredName: string): MetadataError; static invalidManyToManyWithPivotEntity(meta1: EntityMetadata, prop1: EntityProperty, meta2: EntityMetadata, prop2: EntityProperty): MetadataError; static targetIsAbstract(meta: EntityMetadata, prop: EntityProperty): MetadataError; static nonPersistentCompositeProp(meta: EntityMetadata, prop: EntityProperty): MetadataError; static propertyTargetsEntityType(meta: EntityMetadata, prop: EntityProperty, target: EntityMetadata): MetadataError; static fromMissingOption(meta: EntityMetadata, prop: EntityProperty, option: string): MetadataError; static targetKeyOnManyToMany(meta: EntityMetadata, prop: EntityProperty): MetadataError; static targetKeyNotUnique(meta: EntityMetadata, prop: EntityProperty, target?: EntityMetadata): MetadataError; static targetKeyNotFound(meta: EntityMetadata, prop: EntityProperty, target?: EntityMetadata): MetadataError; static incompatiblePolymorphicTargets(meta: EntityMetadata, prop: EntityProperty, target1: EntityMetadata, target2: EntityMetadata, reason: string): MetadataError; static dangerousPropertyName(meta: EntityMetadata, prop: EntityProperty): MetadataError; static viewEntityWithoutExpression(meta: EntityMetadata): MetadataError; static mixedInheritanceStrategies(root: EntityMetadata, child: EntityMetadata): MetadataError; static tptNotSupportedByDriver(meta: EntityMetadata): MetadataError; /** Thrown when database triggers are defined on an entity using a driver that does not support them. */ static triggersNotSupportedByDriver(meta: EntityMetadata): MetadataError; private static fromMessage; } /** Error thrown when an entity lookup fails to find the expected result. */ export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends ValidationError<T> { static findOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError; static findExactlyOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError; static failedToLoadProperty(name: string, propName: string, where: unknown): NotFoundError; } /** Error thrown when a transaction propagation requirement is not satisfied. */ export declare class TransactionStateError extends ValidationError { static requiredTransactionNotFound(propagation: string): TransactionStateError; static transactionNotAllowed(propagation: string): TransactionStateError; static invalidPropagation(propagation: string): TransactionStateError; }