UNPKG

lakutata

Version:

An IoC-based universal application framework.

65 lines (56 loc) 1.67 kB
import './TypeDef.internal.30.js'; import { EntitySchema } from './TypeDef.internal.41.js'; /** * Represents some Type of the Object. */ type ObjectType<T> = { new (): T; } | Function; /** * Entity target. */ type EntityTarget<Entity> = ObjectType<Entity> | EntitySchema<Entity> | string | { type: Entity; name: string; }; /** * Interface of the simple literal object with any string keys. */ interface ObjectLiteral { [key: string]: any; } /** * List of T-s passed as an array or object map. * * Example usage: entities as an array of imported using import * as syntax. */ type MixedList<T> = T[] | { [key: string]: T; }; /** * Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties. */ type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? { [K in keyof T]?: DeepPartial<T[K]>; } : T); /** * Pick only the keys that match the Type `U` */ type PickKeysByType<T, U> = string & keyof { [P in keyof T as T[P] extends U ? P : never]: T[P]; }; /** * Wrapper type for relation type definitions in entities. * Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property. * * Usage example: * @Entity() * export default class User { * * @OneToOne(() => Profile, profile => profile.user) * profile: Relation<Profile>; * * } */ type Relation<T> = T; export type { DeepPartial, EntityTarget, MixedList, ObjectLiteral, ObjectType, PickKeysByType, Relation };