node-universe
Version:
基于 Nodejs 环境的一款微服务框架,原理来自于宇宙中的恒星,行星,卫星等系统。
66 lines (65 loc) • 2.56 kB
TypeScript
import Service from '../../lib/star/service';
import { ActionHandler, ActionHookAfter, ActionHookBefore, ActionHookError, ActionParams, ActionSchema } from '../context';
import { ServiceEventHandler, ServiceEventLegacyHandler } from '../context/event';
export interface ServiceSettingSchema {
$noVersionPrefix?: boolean;
$noServiceNamePrefix?: boolean;
$dependencyTimeout?: number;
$shutdownTimeout?: number;
$secureSettings?: string[];
[name: string]: any;
}
export interface ServiceDependency {
name: string;
version?: string | number;
}
export type ServiceActionsSchema<S = ServiceSettingSchema> = {
[key: string]: ActionSchema | ActionHandler | boolean;
} & ThisType<Service<S>>;
export type ServiceMethods = {
[key: string]: (...args: any[]) => any;
} & ThisType<Service>;
export interface ServiceHooksBefore {
[key: string]: string | ActionHookBefore | (string | ActionHookBefore)[];
}
export interface ServiceHooksAfter {
[key: string]: string | ActionHookAfter | (string | ActionHookAfter)[];
}
export interface ServiceHooksError {
[key: string]: string | ActionHookError | (string | ActionHookError)[];
}
export interface ServiceHooks {
before?: ServiceHooksBefore;
after?: ServiceHooksAfter;
error?: ServiceHooksError;
}
export interface ServiceEvent {
name?: string;
group?: string;
params?: ActionParams;
context?: boolean;
debounce?: number;
throttle?: number;
handler?: ServiceEventHandler | ServiceEventLegacyHandler;
}
export type ServiceEvents<S = ServiceSettingSchema> = {
[key: string]: ServiceEventHandler | ServiceEventLegacyHandler | ServiceEvent;
} & ThisType<Service<S>>;
export type ServiceSyncLifecycleHandler<S = ServiceSettingSchema> = (this: Service<S>) => void;
export type ServiceAsyncLifecycleHandler<S = ServiceSettingSchema> = (this: Service<S>) => void | Promise<void>;
export interface ServiceSchema<S = ServiceSettingSchema> {
name: string;
version?: string | number;
settings?: S;
dependencies?: string | ServiceDependency | (string | ServiceDependency)[];
metadata?: any;
actions?: ServiceActionsSchema;
mixins?: Partial<ServiceSchema>[];
methods?: ServiceMethods;
hooks?: ServiceHooks;
events?: ServiceEvents;
created?: ServiceSyncLifecycleHandler<S> | ServiceSyncLifecycleHandler<S>[];
started?: ServiceAsyncLifecycleHandler<S> | ServiceAsyncLifecycleHandler<S>[];
stopped?: ServiceAsyncLifecycleHandler<S> | ServiceAsyncLifecycleHandler<S>[];
[name: string]: any;
}