1 |
|
2 |
|
3 |
|
4 | import http = require("http");
|
5 | import http2 = require("http2");
|
6 | import fastify = require("fastify");
|
7 | import { FastifyRequest, FastifyReply } from "fastify";
|
8 | import Bookshelf = require("bookshelf");
|
9 |
|
10 | export type FastifyInstance = fastify.FastifyInstance<
|
11 | HttpServer,
|
12 | HttpRequest,
|
13 | HttpResponse
|
14 | >;
|
15 | export type HttpServer = http.Server | http2.Http2Server;
|
16 | export type HttpRequest = http.IncomingMessage | http2.Http2ServerRequest;
|
17 | export type HttpResponse = http.ServerResponse | http2.Http2ServerResponse;
|
18 |
|
19 | export type Middleware = (
|
20 | request?: FastifyRequest<any>,
|
21 | reply?: FastifyReply<any>
|
22 | ) => Promise<any>;
|
23 |
|
24 | export interface IController {
|
25 | path: string;
|
26 | handler: PluginHandler;
|
27 | }
|
28 |
|
29 | export type PluginHandler = fastify.Plugin<
|
30 | HttpServer,
|
31 | HttpRequest,
|
32 | HttpResponse,
|
33 | any
|
34 | >;
|
35 |
|
36 | export interface IPlugin {
|
37 | handler: PluginHandler;
|
38 | options?: any;
|
39 | }
|
40 |
|
41 | export interface IModule {
|
42 | name: string;
|
43 | controllers: IController[];
|
44 | repositories: IRepository[];
|
45 | middlewares?: Middleware[];
|
46 | plugins?: IPlugin[];
|
47 | }
|
48 |
|
49 | export interface BootstrapOptions {
|
50 | modules: IModule[];
|
51 | }
|
52 |
|
53 | export interface IExtendedModel extends Partial<Bookshelf.Model<any>> {
|
54 | findAll: Middleware;
|
55 | findById: Middleware;
|
56 | upsert: Middleware;
|
57 | remove: Middleware;
|
58 | recover: Middleware;
|
59 | forge(props?: any, options?: any): any;
|
60 | watch(options: any): any;
|
61 | watchAll(options: any): any;
|
62 | }
|
63 |
|
64 | export interface IRepository {
|
65 | name: string;
|
66 | path: string;
|
67 | model: IExtendedModel;
|
68 | controller: IController;
|
69 | websocket: boolean;
|
70 | makeCrud(name: string, options: any): void;
|
71 | makeReactive(name: string): void;
|
72 | }
|