import { RowObject } from '../core/sql'; import { RelationKeyOf } from './data-types'; declare const ENTITY_TAG: unique symbol; declare type ENTITY_TAG = typeof ENTITY_TAG; export declare type EntityData = Omit<{ [P in keyof T]: NonNullable extends Entity ? EntityData> : NonNullable extends EntityArray ? EntityData[] : T[P]; }, ENTITY_TAG>; /** * 实体类基类,仅为了typescript区分类型 * 不一定非得从此继承 */ export declare class Entity { /** * 实体类标记 */ [ENTITY_TAG]: true; static create(this: EntityConstructor, data: EntityData): EntityInstance; static create(this: EntityConstructor, data: EntityData[]): EntityInstance[]; } export interface EntityConstructor { new (...args: any): T; } /** * 用于做实体主键类型 * 用户可自行使用 合并声明扩展 */ export interface EntityKey { } /** * 主键的类型 */ export declare type EntityKeyType = EntityKey[keyof EntityKey] extends never ? number : Exclude; declare type EntityArray = T[]; /** * 主键字段字面量类型 */ export declare type EntityKeyName = keyof EntityKey extends never ? 'id' : keyof EntityKey; export declare type EntityInstance = T & { [P in RelationKeyOf]: T[P] extends EntityArray ? EntityInstance>[] : T[P] extends Entity ? EntityInstance> : T[P]; } & { constructor: EntityConstructor>; }; export declare type ToEntity = T & { [ENTITY_TAG]: true; }; export declare type EntityTypeOf> = C extends EntityConstructor ? T : never; export {};