import { EntityOptions as BaseEntityOptions } from 'typeorm/decorator/options/EntityOptions' ; import { createCustomPropertyDecorator , saveClassMetadata , saveModule , } from '@midwayjs/decorator' ; import { getMetadataArgsStorage } from 'typeorm' ; import { ViewEntityOptions as BaseViewEntityOptions } from 'typeorm/decorator/options/ViewEntityOptions' ; import { ENTITY_MODEL_KEY , EVENT_SUBSCRIBER_KEY , ORM_MODEL_KEY } from './index' ; export interface EntityOptions extends BaseEntityOptions { connectionName ? : string ; } export interface ViewEntityOptions extends BaseViewEntityOptions { connectionName ? : string ; } param options export function EntityModel ( options ? ) ; param name param options export function EntityModel ( name ? , options ? ) ; param nameOrOptions param maybeOptions export function EntityModel ( nameOrOptions ? , maybeOptions ? ) { const options = ( typeof nameOrOptions === 'object' ? ( nameOrOptions as EntityOptions ) : maybeOptions ) || ( { } as any ) ; const name = typeof nameOrOptions === 'string' ? nameOrOptions : options . name ; const connectionName = options ?. connectionName || 'ALL' ; return function ( target ) { if ( typeof target === 'function' ) { saveModule ( ENTITY_MODEL_KEY , target ) ; saveClassMetadata ( ENTITY_MODEL_KEY , { connectionName } , target ) ; } else { saveModule ( ENTITY_MODEL_KEY , ( target as any ) . constructor ) ; saveClassMetadata ( ENTITY_MODEL_KEY , { connectionName } , ( target as any ) . constructor ) ; } getMetadataArgsStorage ( ) . tables . push ( { target : target , name : name , type : 'regular' , orderBy : options . orderBy ? options . orderBy : undefined , engine : options . engine ? options . engine : undefined , database : options . database ? options . database : undefined , schema : options . schema ? options . schema : undefined , synchronize : options . synchronize , withoutRowid : options . withoutRowid , } ) ; } ; } param options export function EntityView ( options ? ) ; param name param options export function EntityView ( name ? , options ? ) ; param nameOrOptions param maybeOptions export function EntityView ( nameOrOptions ? , maybeOptions ? ) { const options = ( typeof nameOrOptions === 'object' ? ( nameOrOptions as ViewEntityOptions ) : maybeOptions ) || { } ; const name = typeof nameOrOptions === 'string' ? nameOrOptions : options . name ; const connectionName = options ?. connectionName || 'ALL' ; return function ( target ) { if ( typeof target === 'function' ) { saveModule ( ENTITY_MODEL_KEY , target ) ; saveClassMetadata ( ENTITY_MODEL_KEY , { connectionName } , target ) ; } else { saveModule ( ENTITY_MODEL_KEY , ( target as any ) . constructor ) ; saveClassMetadata ( ENTITY_MODEL_KEY , { connectionName } , ( target as any ) . constructor ) ; } getMetadataArgsStorage ( ) . tables . push ( { target : target , name : name , type : 'view' , database : options . database ? options . database : undefined , schema : options . schema ? options . schema : undefined , expression : options . expression ? options . expression : undefined , materialized : options . materialized ? options . materialized : undefined , synchronize : options . synchronize , } ) ; } ; } export function InjectEntityModel ( modelKey ? , connectionName = 'default' ) { return createCustomPropertyDecorator ( ORM_MODEL_KEY , { modelKey , connectionName , } ) ; } /**
 * EventSubscriber - typeorm
 * implements EntitySubscriberInterface
 */ export function EventSubscriberModel ( options = { } ) { return function ( target ) { saveModule ( EVENT_SUBSCRIBER_KEY , target ) ; saveClassMetadata ( EVENT_SUBSCRIBER_KEY , options , target ) ; } ; }