1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Middleware = exports.IsDisabledOn = exports.AsyncVerify = exports.Verify = exports.Name = exports.MultipartForm = exports.API = exports.Body = exports.PATCH = exports.DELETE = exports.PUT = exports.POST = exports.GET = exports.Route = void 0;
|
4 | var http_verb_1 = require("./http-verb");
|
5 | var routes = [];
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function Route(path) {
|
11 | return function (target) {
|
12 | target.controllerPath = path;
|
13 | target.routes = routes;
|
14 | routes = [];
|
15 | };
|
16 | }
|
17 | exports.Route = Route;
|
18 | function setTarget(_, type, path, method) {
|
19 | routes.push({
|
20 | type: type,
|
21 | path: path,
|
22 | method: method,
|
23 | body: undefined,
|
24 | isAPI: false,
|
25 | isMultipartForm: false,
|
26 | verifiers: [],
|
27 | isDisabledOn: undefined
|
28 | });
|
29 | }
|
30 | function setBody(_, name, schema) {
|
31 | if (!routes)
|
32 | return;
|
33 | routes[routes.length - 1].body = {
|
34 | name: name,
|
35 | schema: schema
|
36 | };
|
37 | }
|
38 | function setApi(_) {
|
39 | if (!routes)
|
40 | return;
|
41 | routes[routes.length - 1].isAPI = true;
|
42 | }
|
43 | function setMultipartForm(_) {
|
44 | if (!routes)
|
45 | return;
|
46 | routes[routes.length - 1].isMultipartForm = true;
|
47 | }
|
48 | function setName(name) {
|
49 | if (!routes)
|
50 | return;
|
51 | routes[routes.length - 1].name = name;
|
52 | }
|
53 | function setVerify(_, func) {
|
54 | if (!routes)
|
55 | return;
|
56 | routes[routes.length - 1].verifiers.push({ fun: func, isAsync: false });
|
57 | }
|
58 | function setAsyncVerify(_, func) {
|
59 | if (!routes)
|
60 | return;
|
61 | routes[routes.length - 1].verifiers.push({ fun: func, isAsync: true });
|
62 | }
|
63 | function setIsDisabledOn(_, func) {
|
64 | if (!routes)
|
65 | return;
|
66 | routes[routes.length - 1].isDisabledOn = func;
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | function GET(path) {
|
73 | return function (target, method, _) {
|
74 | setTarget(target, http_verb_1.HttpVerb.GET, path, method);
|
75 | };
|
76 | }
|
77 | exports.GET = GET;
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | function POST(path) {
|
83 | return function (target, method, _) {
|
84 | setTarget(target, http_verb_1.HttpVerb.POST, path, method);
|
85 | };
|
86 | }
|
87 | exports.POST = POST;
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | function PUT(path) {
|
93 | return function (target, method, _) {
|
94 | setTarget(target, http_verb_1.HttpVerb.PUT, path, method);
|
95 | };
|
96 | }
|
97 | exports.PUT = PUT;
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | function DELETE(path) {
|
103 | return function (target, method, _) {
|
104 | setTarget(target, http_verb_1.HttpVerb.DELETE, path, method);
|
105 | };
|
106 | }
|
107 | exports.DELETE = DELETE;
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | function PATCH(path) {
|
113 | return function (target, method, _) {
|
114 | setTarget(target, http_verb_1.HttpVerb.PATCH, path, method);
|
115 | };
|
116 | }
|
117 | exports.PATCH = PATCH;
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | function Body(name, schema) {
|
125 | return function (target, _, __) {
|
126 | setBody(target, name, schema);
|
127 | };
|
128 | }
|
129 | exports.Body = Body;
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | function API() {
|
136 | return function (target, _, __) {
|
137 | setApi(target);
|
138 | };
|
139 | }
|
140 | exports.API = API;
|
141 |
|
142 |
|
143 |
|
144 | function MultipartForm() {
|
145 | return function (target, _, __) {
|
146 | setMultipartForm(target);
|
147 | };
|
148 | }
|
149 | exports.MultipartForm = MultipartForm;
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | function Name(name) {
|
156 | return function (_, __, ___) {
|
157 | setName(name);
|
158 | };
|
159 | }
|
160 | exports.Name = Name;
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | function Verify(func) {
|
170 | return function (target, _, __) {
|
171 | setVerify(target, func);
|
172 | };
|
173 | }
|
174 | exports.Verify = Verify;
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 | function AsyncVerify(func) {
|
184 | return function (target, _, __) {
|
185 | setAsyncVerify(target, func);
|
186 | };
|
187 | }
|
188 | exports.AsyncVerify = AsyncVerify;
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | function IsDisabledOn(func) {
|
196 | return function (target, _, __) {
|
197 | setIsDisabledOn(target, func);
|
198 | };
|
199 | }
|
200 | exports.IsDisabledOn = IsDisabledOn;
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | function Middleware(path) {
|
206 | return function (target) {
|
207 | target.middlewarePath = path;
|
208 | };
|
209 | }
|
210 | exports.Middleware = Middleware;
|