UNPKG

2.08 kBPlain TextView Raw
1import http from 'http'
2import express, { Express } from 'express'
3import {
4 Application as FeathersApplication,
5 Params as FeathersParams,
6 HookContext,
7 ServiceMethods,
8 ServiceInterface,
9 RouteLookup
10} from '@feathersjs/feathers'
11
12interface ExpressUseHandler<T, Services> {
13 <L extends keyof Services & string>(
14 path: L,
15 ...middlewareOrService: (
16 | Express
17 | express.RequestHandler
18 | express.RequestHandler[]
19 | (keyof any extends keyof Services ? ServiceInterface : Services[L])
20 )[]
21 ): T
22 (path: string | RegExp, ...expressHandlers: express.RequestHandler[]): T
23 (...expressHandlers: express.RequestHandler[]): T
24 (handler: Express | express.ErrorRequestHandler): T
25}
26
27export interface ExpressOverrides<Services> {
28 listen(port: number, hostname: string, backlog: number, callback?: () => void): Promise<http.Server>
29 listen(port: number, hostname: string, callback?: () => void): Promise<http.Server>
30 listen(port: number | string | any, callback?: () => void): Promise<http.Server>
31 listen(callback?: () => void): Promise<http.Server>
32 use: ExpressUseHandler<this, Services>
33 server?: http.Server
34}
35
36export type Application<Services = any, Settings = any> = Omit<Express, 'listen' | 'use' | 'get' | 'set'> &
37 FeathersApplication<Services, Settings> &
38 ExpressOverrides<Services>
39
40declare module '@feathersjs/feathers/lib/declarations' {
41 interface ServiceOptions {
42 express?: {
43 before?: express.RequestHandler[]
44 after?: express.RequestHandler[]
45 composed?: express.RequestHandler
46 }
47 }
48}
49
50declare module 'express-serve-static-core' {
51 interface Request {
52 feathers: Partial<FeathersParams> & { [key: string]: any }
53 lookup?: RouteLookup
54 }
55
56 interface Response {
57 data?: any
58 hook?: HookContext
59 }
60
61 interface IRouterMatcher<T> {
62 // eslint-disable-next-line
63 <P extends Params = ParamsDictionary, ResBody = any, ReqBody = any>(
64 path: PathParams,
65 ...handlers: (RequestHandler<P, ResBody, ReqBody> | Partial<ServiceMethods> | Application)[]
66 ): T
67 }
68}