import { Adaptor , AdaptorConfig , Environment , getParams , Injector } from "../core/mod.ts" ; import ApplicationEventsMark from "./application_events_mark.ts" ; import ApplicationEvents from "../application_events.ts" ; import { Reflect } from "../../third_party/Reflect.ts" ; import { APPLICATION_EVENTS_MARK_KEY } from "./metadata_keys.ts" ; import { Constructor , Log } from "../util/mod.ts" ; import { DEFAULT_ADAPTOR_CONFIG } from "../constant.ts" ; import { useServer } from "./use_server.ts" ; export type AddAdaptorApplicationEventMark = ApplicationEventsMark < Adaptor > ; export function AddAdaptor ( adaptorConstructor , configure = DEFAULT_ADAPTOR_CONFIG ) { const adaptor = useServer ( ) . addAdaptorWithConfigure ( adaptorConstructor , configure ) ; return ( target , propertyKey , descriptor ) => { const defaultTarget = function ( ) { Log . error ( "no target found." ) ; } ; const mark = { type : ApplicationEvents . onAddAdaptor , meta : adaptor , target : < Function > ( descriptor . value ?? defaultTarget ) } ; Reflect . defineMetadata ( APPLICATION_EVENTS_MARK_KEY , mark , descriptor . value ) ; } ; }