UNPKG

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