UNPKG

1.66 kBPlain TextView Raw
1/// <reference types="node" />
2/// <reference types="pino" />
3
4import http = require("http");
5import http2 = require("http2");
6import fastify = require("fastify");
7import { FastifyRequest, FastifyReply } from "fastify";
8import Bookshelf = require("bookshelf");
9
10export type FastifyInstance = fastify.FastifyInstance<
11 HttpServer,
12 HttpRequest,
13 HttpResponse
14>;
15export type HttpServer = http.Server | http2.Http2Server;
16export type HttpRequest = http.IncomingMessage | http2.Http2ServerRequest;
17export type HttpResponse = http.ServerResponse | http2.Http2ServerResponse;
18
19export type Middleware = (
20 request?: FastifyRequest<any>,
21 reply?: FastifyReply<any>
22) => Promise<any>;
23
24export interface IController {
25 path: string;
26 handler: PluginHandler;
27}
28
29export type PluginHandler = fastify.Plugin<
30 HttpServer,
31 HttpRequest,
32 HttpResponse,
33 any
34>;
35
36export interface IPlugin {
37 handler: PluginHandler;
38 options?: any;
39}
40
41export interface IModule {
42 name: string;
43 controllers: IController[];
44 repositories: IRepository[];
45 middlewares?: Middleware[];
46 plugins?: IPlugin[];
47}
48
49export interface BootstrapOptions {
50 modules: IModule[];
51}
52
53export 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
64export 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}