import type { ServiceOptions as BaseServiceOptions, ServiceRunContext } from "./service.ts" import { Service } from "./service.ts" export type ServiceAbstractConstructor< ServiceOptions extends BaseServiceOptions, Context extends ServiceRunContext, Left, Right, > = (abstract new (options: ServiceOptions) => Service) & { is(target: unknown): target is Service } export const createServiceAbstractClass = ( serviceName: ServiceName, ) => { return < ServiceOptions extends BaseServiceOptions, Context extends ServiceRunContext, Left, Right, >(): ServiceAbstractConstructor => { abstract class AbstractService extends Service { constructor(options: ServiceOptions) { super(options) this.logger.setDefaultName(serviceName) } static is(target: unknown): target is Service { if (target instanceof AbstractService) { return true } return false } } return AbstractService } } export type SimpleServiceAbstractConstructor< Context extends ServiceRunContext, Left, Right, > = ServiceAbstractConstructor export const createSimpleServiceAbstractClass = ( serviceName: ServiceName, ) => { return (): SimpleServiceAbstractConstructor< Context, Left, Right > => { return createServiceAbstractClass(serviceName)() } }