UNPKG

4.48 kBTypeScriptView Raw
1import { HttpVerb } from "./http-verb";
2export interface LynxRouteBody {
3 name: string;
4 schema: any;
5}
6export interface LynxRouteMetadata {
7 type: HttpVerb;
8 path: string;
9 method: any;
10 body?: LynxRouteBody;
11 isAPI: boolean;
12 isMultipartForm: boolean;
13 verifiers: {
14 fun: Function;
15 isAsync: boolean;
16 }[];
17 isDisabledOn?: Function;
18 name?: string;
19}
20export interface LynxControllerMetadata {
21 controllerPath: string;
22 routes: LynxRouteMetadata[];
23}
24/**
25 * Decorator to set the base route of a controller.
26 * @param path the route path for the controller.
27 */
28export declare function Route(path: string): (target: any) => void;
29/**
30 * Set the decorated method to a GET endpoint with the specified path.
31 * @param path the endpoint path
32 */
33export declare function GET(path: string): (target: any, method: any, _: any) => void;
34/**
35 * Set the decorated method to a POST endpoint with the specified path.
36 * @param path the endpoint path
37 */
38export declare function POST(path: string): (target: any, method: any, _: any) => void;
39/**
40 * Set the decorated method to a PUT endpoint with the specified path.
41 * @param path the endpoint path
42 */
43export declare function PUT(path: string): (target: any, method: any, _: any) => void;
44/**
45 * Set the decorated method to a DELETE endpoint with the specified path.
46 * @param path the endpoint path
47 */
48export declare function DELETE(path: string): (target: any, method: any, _: any) => void;
49/**
50 * Set the decorated method to a PATH endpoint with the specified path.
51 * @param path the endpoint path
52 */
53export declare function PATCH(path: string): (target: any, method: any, _: any) => void;
54/**
55 * Add to the decorated method a body to be injected. The body will be validated
56 * using the specified schema.
57 * @param name the name of the argument in the method to map the body
58 * @param schema a JOI schema to validate the body object
59 */
60export declare function Body(name: string, schema: any): (target: any, _: any, __: any) => void;
61/**
62 * Set the decorated method to an API endpoints.
63 * In this way, the returned value of the method will be encapsulated in a
64 * standard API envelope and serialized to JSON using the Lynx serialization system.
65 */
66export declare function API(): (target: any, _: any, __: any) => void;
67/**
68 * Set the decorated method to accept MultipartForm requested.
69 */
70export declare function MultipartForm(): (target: any, _: any, __: any) => void;
71/**
72 * Add to the decorated method a route name, in order to easely generate redirect
73 * or, more general, the execution of the `route` method.
74 * @param name the name of the route
75 */
76export declare function Name(name: string): (_: any, __: any, ___: any) => void;
77/**
78 * Add to the decorated method a verification function that will be executed
79 * BEFORE the route. The function must NOT be an async function, and it shell
80 * return a boolean value. If true is returned, the method is then executed.
81 * This method is fundamental to implement authorization to a single endpoint.
82 * NOTE: this is the sync version of the AsyncVerify decorator.
83 * @param func the verification function to be executed. It must NOT be an async function, and return a boolean value.
84 */
85export declare function Verify(func: Function): (target: any, _: any, __: any) => void;
86/**
87 * Add to the decorated method a verification function that will be executed
88 * BEFORE the route. The function must NOT be an async function, and it shell
89 * return a boolean value. If true is returned, the method is then executed.
90 * This method is fundamental to implement authorization to a single endpoint.
91 * NOTE: this is the async version of the Verify decorator.
92 * @param func the verification function to be executed. It MUST BE an async function, and return a boolean value.
93 */
94export declare function AsyncVerify(func: Function): (target: any, _: any, __: any) => void;
95/**
96 * Add to the decorated method a "disabled" function, that is verified at startup
97 * time. If the function return a truly value, the decorated method is not registered
98 * as an endpoint.
99 * @param func the disabling function to be executed. It shall return a boolean value.
100 */
101export declare function IsDisabledOn(func: Function): (target: any, _: any, __: any) => void;
102/**
103 * Add to the decorated class a path to be executed as middleware.
104 * @param path the endpoint path
105 */
106export declare function Middleware(path: string): (target: any) => void;