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.

119 lines (118 loc) 5.25 kB
import { inspect } from 'node:util'; import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings'; import { Reference } from './Reference'; export declare class ArrayCollection<T extends object, O extends object> { readonly owner: O; protected readonly items: Set<T>; protected initialized: boolean; protected dirty: boolean; protected partial: boolean; protected snapshot: T[] | undefined; protected _count?: number; private _property?; constructor(owner: O, items?: T[]); loadCount(): Promise<number>; getItems(): T[]; toArray<TT extends T>(): EntityDTO<TT>[]; toJSON(): EntityDTO<T>[]; getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[]; add(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void; /** * @internal */ addWithoutPropagation(entity: T): void; set(items: Iterable<T | Reference<T>>): void; private compare; /** * @internal */ hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void; /** * Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity, * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()` * is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`, * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed. */ remove(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void; /** * Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity, * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()` * is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`, * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed. */ removeAll(): void; /** * @internal */ removeWithoutPropagation(entity: T): void; contains(item: T | Reference<T>, check?: boolean): boolean; /** * Extracts a slice of the collection items starting at position start to end (exclusive) of the collection. * If end is null it returns all elements from start to the end of the collection. */ slice(start?: number, end?: number): T[]; /** * Tests for the existence of an element that satisfies the given predicate. */ exists(cb: (item: T) => boolean): boolean; /** * Returns the first element of this collection that satisfies the predicate. */ find(cb: (item: T, index: number) => boolean): T | undefined; /** * Extracts a subset of the collection items. */ filter(cb: (item: T, index: number) => boolean): T[]; /** * Maps the collection items based on your provided mapper function. */ map<R>(mapper: (item: T, index: number) => R): R[]; /** * Maps the collection items based on your provided mapper function to a single object. */ reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R; /** * Maps the collection items to a dictionary, indexed by the key you specify. * If there are more items with the same key, only the first one will be present. */ indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>; /** * Maps the collection items to a dictionary, indexed by the key you specify. * If there are more items with the same key, only the first one will be present. */ indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>; count(): number; isInitialized(fully?: boolean): boolean; isDirty(): boolean; isPartial(): boolean; isEmpty(): boolean; setDirty(dirty?: boolean): void; get length(): number; [Symbol.iterator](): IterableIterator<T>; /** * @internal */ takeSnapshot(forcePropagate?: boolean): void; /** * @internal */ getSnapshot(): T[] | undefined; /** * @internal */ get property(): EntityProperty; /** * @internal */ set property(prop: EntityProperty); protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void; protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void; protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void; protected shouldPropagateToCollection(collection: ArrayCollection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean; protected incrementCount(value: number): void; /** @ignore */ [inspect.custom](depth?: number): string; } export interface ArrayCollection<T, O> { [k: number]: T; }