2021-06-19 09:55:58 +00:00
|
|
|
/**
|
|
|
|
* 错误响应
|
|
|
|
*/
|
2021-07-23 13:34:47 +00:00
|
|
|
interface ExpressResponseError extends Record<string,unknown>{
|
2021-06-19 09:55:58 +00:00
|
|
|
error:string
|
|
|
|
}
|
|
|
|
|
2021-07-23 13:34:47 +00:00
|
|
|
/**
|
|
|
|
* 成功响应
|
|
|
|
*/
|
|
|
|
interface ExpressResponseSuccess extends Record<string,unknown>{
|
|
|
|
message:string
|
|
|
|
}
|
|
|
|
|
2021-06-19 09:55:58 +00:00
|
|
|
/**
|
|
|
|
* 响应列表
|
|
|
|
*/
|
|
|
|
interface ExpressResponseList<T=Record<string,unknown>> extends Record<string,unknown>{
|
|
|
|
list:T[]
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ExpressResponseDetail<T=Record<string,unknown>> extends Record<string,unknown>{
|
|
|
|
detail:T
|
|
|
|
}
|
|
|
|
|
2021-07-23 13:34:47 +00:00
|
|
|
type SSEPayload = Record<string|number,SSEPayload>|string|number
|
|
|
|
|
2021-06-19 09:55:58 +00:00
|
|
|
declare namespace Express {
|
|
|
|
export interface Response {
|
2021-07-23 13:34:47 +00:00
|
|
|
error(error:string,statusCode:number,errObj?:Record<string,unknown>):ExpressResponseError
|
|
|
|
list<T=Record<string,unknown>>(list:T,resObj?:Record<string,unknown>):ExpressResponseList<T>
|
|
|
|
detail<T=Record<string,unknown>>(detail:T,resObj?:Record<string,unknown>):ExpressResponseDetail<T>
|
|
|
|
success(message:string,resObj?:Record<string,unknown>):ExpressResponseSuccess
|
|
|
|
|
|
|
|
enable_sse():this
|
|
|
|
|
|
|
|
sse(data:SSEPayload,event:string):this
|
2021-06-19 09:55:58 +00:00
|
|
|
}
|
|
|
|
}
|