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.

32 lines (31 loc) 1.84 kB
import type { AnyEntity, EntityMetadata, EntityName, PopulateOptions } from '../typings.js'; /** * Helper that allows to keep track of where we are currently at when serializing complex entity graph with cycles. * Before we process a property, we call `visit` that checks if it is not a cycle path (but allows to pass cycles that * are defined in populate hint). If not, we proceed and call `leave` afterwards. */ export declare class SerializationContext<T extends object> { #private; readonly path: [EntityName, string][]; readonly visited: Set<AnyEntity>; constructor(populate?: PopulateOptions<T>[], fields?: Set<string>, exclude?: readonly string[]); /** * Returns true when there is a cycle detected. */ visit(entityName: EntityName, prop: string): boolean; /** Removes the last entry from the visit path after processing a property. */ leave(entityName: EntityName, prop: string): void; /** Cleans up the serialization context by removing root references from all tracked entities. */ close(): void; /** * When initializing new context, we need to propagate it to the whole entity graph recursively. */ static propagate(root: SerializationContext<any>, entity: AnyEntity, isVisible: (meta: EntityMetadata, prop: string) => boolean): void; /** Checks whether a property is explicitly listed in the populate hints for the current path. */ isMarkedAsPopulated(entityName: EntityName, prop: string): boolean; /** Checks whether a property is excluded from serialization via the exclude list. */ isExcluded(entityName: EntityName, prop: string): boolean; /** Checks whether a property is included in the partial fields selection for the current path. */ isPartiallyLoaded(entityName: EntityName, prop: string): boolean; private register; }