resting-squirrel-controller 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,374 +1,374 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- const path = require("path");
24
- const resting_squirrel_1 = require("resting-squirrel");
25
- const resting_squirrel_dto_1 = require("resting-squirrel-dto");
26
- const controller_options_1 = require("./decorators/controller-options");
27
- const deprecated_1 = require("./decorators/deprecated");
28
- const methods_1 = require("./decorators/methods");
29
- const options_1 = require("./decorators/options");
30
- const resource_1 = require("./decorators/resource");
31
- const version_1 = require("./decorators/version");
32
- const utils_1 = require("./utils");
33
- class E {
34
- }
35
- /**
36
- * The endpoint is executed with `PUT` method.
37
- */
38
- E.put = methods_1.put;
39
- /**
40
- * The endpoint is executed with `GET` method.
41
- */
42
- E.get = methods_1.get;
43
- /**
44
- * The endpoint is executed with `POST` method.
45
- */
46
- E.post = methods_1.post;
47
- /**
48
- * The endpoint is executed with `DELETE` method.
49
- */
50
- E.delete = methods_1.del;
51
- /**
52
- * The endpoint is executed with `HEAD` method.
53
- */
54
- E.head = methods_1.head;
55
- /**
56
- * Defines options to the endpoint.
57
- */
58
- E.options = options_1.default;
59
- /**
60
- * Define specific option to the endpoint.
61
- */
62
- E.option = (option, value) => E.options({ [option]: value });
63
- /**
64
- * Sets the `auth` option of the endpoint.
65
- */
66
- E.auth = (auth) => E.options({ auth });
67
- /**
68
- * Sets the `params` option to the endpoint using DTO classes.
69
- */
70
- E.params = (params, optionalParams = [], omit = []) => E.options({ params, optionalParams, omitParams: omit });
71
- /**
72
- * Sets the `response` option to the endpoint using DTO classes.
73
- */
74
- E.response = (response, omit = []) => E.options({ response, omitResponse: omit });
75
- /**
76
- * Sets the `params` and `response` options to the endpoint using DTO classes.
77
- */
78
- E.dto = (dto, optionalParams = [], omitParams = [], omitResponse = []) => E.options({ params: dto, response: dto, optionalParams, omitParams, omitResponse });
79
- /**
80
- * Sets the `errors` option to the endpoint.
81
- */
82
- E.errors = (errors) => E.options({ errors });
83
- /**
84
- * Sets the `description` option to the endpoint.
85
- */
86
- E.description = (description) => E.options({ description });
87
- /**
88
- * Sets the `hideDocs` option to `true` to the endpoint.
89
- */
90
- // tslint:disable-next-line: member-ordering
91
- E.hideDocs = E.option('hideDocs', true);
92
- /**
93
- * Sets the `args` option to the endpoint.
94
- */
95
- E.args = (args) => E.options({ args });
96
- /**
97
- * Sets the `requireApiKey` option to the endpoint.
98
- */
99
- E.requireApiKey = (requireApiKey) => E.options({ requireApiKey });
100
- /**
101
- * Sets the `excludedApiKey` option to the endpoint.
102
- */
103
- E.excludedApiKeys = (excludedApiKeys) => E.options({ excludedApiKeys });
104
- /**
105
- * Sets the `timeout` option to the endpoint.
106
- */
107
- E.timeout = (timeout) => E.options({ timeout });
108
- /**
109
- * Sets the `props` option to the endpoint.
110
- */
111
- E.props = (props) => E.options({ props });
112
- /**
113
- * Sets the endpoint as empty. It returns 204 status code.
114
- */
115
- // tslint:disable-next-line: member-ordering
116
- E.emptyResponse = E.response(null);
117
- /**
118
- * Sets the endpoint as deprecated.
119
- */
120
- // tslint:disable-next-line: member-ordering
121
- E.deprecated = deprecated_1.default;
122
- // tslint:disable-next-line: member-ordering
123
- E.redirect = E.options({ redirect: true });
124
- // tslint:disable-next-line: max-classes-per-file
125
- class Controller {
126
- constructor(app) {
127
- this._app = app;
128
- }
129
- // #endregion
130
- // #endregion
131
- /**
132
- * Registers all found controllers in the directory to the application.
133
- *
134
- * @param app The instance of the application.
135
- * @param directory Path to the directory where the controllers are located.
136
- */
137
- static registerDirectory(app, directory) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- const files = yield utils_1.fs.readdir(directory);
140
- for (const file of files) {
141
- const filename = path.resolve(directory, file);
142
- if ((yield utils_1.fs.stat(filename)).isDirectory()) {
143
- yield this.registerDirectory(app, filename);
144
- continue;
145
- }
146
- try {
147
- const M = (0, utils_1.requireModule)(filename);
148
- if (M && M.prototype && M.prototype instanceof this) {
149
- M.register(app);
150
- }
151
- }
152
- catch (e) {
153
- if (file.indexOf('.js.map') >= 0 || file.indexOf('.d.ts') >= 0) {
154
- continue;
155
- }
156
- console.error(file, e);
157
- }
158
- }
159
- });
160
- }
161
- static register(app) {
162
- new this(app).register();
163
- }
164
- register() {
165
- const version = this.getVersion();
166
- for (const endpoint of this.getEndpoints()) {
167
- let e;
168
- if (version !== undefined) {
169
- e = this._app.registerRoute(endpoint.method, version, this.getRoute(endpoint.route), this.getOptions(endpoint.propertyKey), endpoint.callback);
170
- }
171
- else {
172
- e = this._app.registerRoute(endpoint.method, this.getRoute(endpoint.route), this.getOptions(endpoint.propertyKey), endpoint.callback);
173
- }
174
- if (this.isDeprecated(endpoint.propertyKey)) {
175
- e.deprecate();
176
- }
177
- }
178
- }
179
- beforeExecution(req, res) {
180
- return __awaiter(this, void 0, void 0, function* () { });
181
- }
182
- getEndpoints() {
183
- return this.__endpoints__ || [];
184
- }
185
- getVersion() {
186
- return this.constructor.__version__;
187
- }
188
- getResource() {
189
- return this.constructor.__resource__;
190
- }
191
- getOptions(propertyKey) {
192
- const t = this;
193
- const controllerOptions = this.constructor.__options__;
194
- if (!t.__options__) {
195
- return {};
196
- }
197
- if (!t.__options__[propertyKey]) {
198
- return {};
199
- }
200
- let options = t.__options__[propertyKey];
201
- options = Object.assign(Object.assign(Object.assign({}, controllerOptions), options), { errors: [
202
- ...((controllerOptions === null || controllerOptions === void 0 ? void 0 : controllerOptions.errors) || []),
203
- ...((options === null || options === void 0 ? void 0 : options.errors) || []),
204
- ], props: Object.assign(Object.assign({}, controllerOptions === null || controllerOptions === void 0 ? void 0 : controllerOptions.props), options === null || options === void 0 ? void 0 : options.props) });
205
- const { args, params, response, optionalParams, omitParams, omitResponse } = options, restOptions = __rest(options, ["args", "params", "response", "optionalParams", "omitParams", "omitResponse"]);
206
- return Object.assign(Object.assign({}, restOptions), { args: args
207
- ? args instanceof Array
208
- ? args
209
- : args.toArray()
210
- : undefined, params: this._getParamsArray(params, optionalParams, omitParams), response: response instanceof resting_squirrel_1.Response.Base
211
- ? response
212
- : this._getResponseArray(response, omitResponse) });
213
- }
214
- isDeprecated(propertyKey) {
215
- const t = this;
216
- if (!t.__deprecated__) {
217
- return false;
218
- }
219
- return t.__deprecated__.includes(propertyKey);
220
- }
221
- getRoute(route) {
222
- let resource = this.getResource();
223
- if (!resource) {
224
- return route;
225
- }
226
- if (resource.indexOf('/') !== 0) {
227
- resource = `/${resource}`;
228
- }
229
- if (route.indexOf('/') !== 0) {
230
- route = `/${route}`;
231
- }
232
- return `${resource}${route}`;
233
- }
234
- _getParamsArray(params, optional = [], omit = []) {
235
- if (!params) {
236
- return undefined;
237
- }
238
- if (params.prototype instanceof resting_squirrel_dto_1.RequestDto) {
239
- return params.toArray(optional, omit);
240
- }
241
- return resting_squirrel_dto_1.default.toParams(params, optional, omit);
242
- }
243
- _getResponseArray(response, omit = []) {
244
- if (response === null) {
245
- return null;
246
- }
247
- if (!response) {
248
- return undefined;
249
- }
250
- if (response.prototype instanceof resting_squirrel_dto_1.ResponseDto) {
251
- return response.toArray();
252
- }
253
- return resting_squirrel_dto_1.default.toResponse(response, omit);
254
- }
255
- }
256
- exports.default = Controller;
257
- // #region Decorators
258
- /**
259
- * Sets the version to the `Controller` class. All endpoints will have this version.
260
- */
261
- Controller.version = version_1.default;
262
- /**
263
- * @alias version
264
- */
265
- Controller.v = Controller.version;
266
- Controller.controllerOptions = controller_options_1.default;
267
- Controller.resource = resource_1.default;
268
- Controller.Endpoint = E;
269
- /**
270
- * Marks the endpoint on the method as deprecated.
271
- * @deprecated
272
- */
273
- Controller.deprecated = deprecated_1.default;
274
- // #region Methods
275
- /**
276
- * The endpoint is executed with `PUT` method.
277
- * @deprecated
278
- */
279
- Controller.put = methods_1.put;
280
- /**
281
- * The endpoint is executed with `GET` method.
282
- * @deprecated
283
- */
284
- Controller.get = methods_1.get;
285
- /**
286
- * The endpoint is executed with `POST` method.
287
- * @deprecated
288
- */
289
- Controller.post = methods_1.post;
290
- /**
291
- * The endpoint is executed with `DELETE` method.
292
- * @deprecated
293
- */
294
- Controller.delete = methods_1.del;
295
- // #endregion
296
- // #region Options
297
- /**
298
- * Defines options to the endpoint.
299
- * @deprecated
300
- */
301
- Controller.options = options_1.default;
302
- /**
303
- * Define specific option to the endpoint.
304
- * @deprecated
305
- */
306
- Controller.option = (option, value) => Controller.options({ [option]: value });
307
- /**
308
- * Sets the `auth` option of the endpoint.
309
- * @deprecated
310
- */
311
- Controller.auth = (auth) => Controller.options({ auth });
312
- /**
313
- * Sets the `params` option to the endpoint using DTO classes.
314
- * @deprecated
315
- */
316
- Controller.params = (params, optionalParams = [], omit = []) => Controller.options({ params, optionalParams, omitParams: omit });
317
- /**
318
- * Sets the `response` option to the endpoint using DTO classes.
319
- * @deprecated
320
- */
321
- Controller.response = (response, omit = []) => Controller.options({ response, omitResponse: omit });
322
- /**
323
- * Sets the `params` and `response` options to the endpoint using DTO classes.
324
- * @deprecated
325
- */
326
- Controller.dto = (dto, optionalParams = [], omitParams = [], omitResponse = []) => Controller.options({ params: dto, response: dto, optionalParams, omitParams, omitResponse });
327
- /**
328
- * Sets the `errors` option to the endpoint.
329
- * @deprecated
330
- */
331
- Controller.errors = (errors) => Controller.options({ errors });
332
- /**
333
- * Sets the `description` option to the endpoint.
334
- * @deprecated
335
- */
336
- Controller.description = (description) => Controller.options({ description });
337
- /**
338
- * Sets the `hideDocs` option to `true` to the endpoint.
339
- * @deprecated
340
- */
341
- // tslint:disable-next-line: member-ordering
342
- Controller.hideDocs = Controller.option('hideDocs', true);
343
- /**
344
- * Sets the `args` option to the endpoint.
345
- * @deprecated
346
- */
347
- Controller.args = (args) => Controller.options({ args });
348
- /**
349
- * Sets the `requireApiKey` option to the endpoint.
350
- * @deprecated
351
- */
352
- Controller.requireApiKey = (requireApiKey) => Controller.options({ requireApiKey });
353
- /**
354
- * Sets the `excludedApiKey` option to the endpoint.
355
- * @deprecated
356
- */
357
- Controller.excludedApiKeys = (excludedApiKeys) => Controller.options({ excludedApiKeys });
358
- /**
359
- * Sets the `timeout` option to the endpoint.
360
- * @deprecated
361
- */
362
- Controller.timeout = (timeout) => Controller.options({ timeout });
363
- /**
364
- * Sets the `props` option to the endpoint.
365
- * @deprecated
366
- */
367
- Controller.props = (props) => Controller.options({ props });
368
- /**
369
- * Sets the endpoint as empty. It returns 204 status code.
370
- * @deprecated
371
- */
372
- // tslint:disable-next-line: member-ordering
373
- Controller.emptyResponse = Controller.response(null);
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ const path = require("path");
24
+ const resting_squirrel_1 = require("resting-squirrel");
25
+ const resting_squirrel_dto_1 = require("resting-squirrel-dto");
26
+ const controller_options_1 = require("./decorators/controller-options");
27
+ const deprecated_1 = require("./decorators/deprecated");
28
+ const methods_1 = require("./decorators/methods");
29
+ const options_1 = require("./decorators/options");
30
+ const resource_1 = require("./decorators/resource");
31
+ const version_1 = require("./decorators/version");
32
+ const utils_1 = require("./utils");
33
+ class E {
34
+ }
35
+ /**
36
+ * The endpoint is executed with `PUT` method.
37
+ */
38
+ E.put = methods_1.put;
39
+ /**
40
+ * The endpoint is executed with `GET` method.
41
+ */
42
+ E.get = methods_1.get;
43
+ /**
44
+ * The endpoint is executed with `POST` method.
45
+ */
46
+ E.post = methods_1.post;
47
+ /**
48
+ * The endpoint is executed with `DELETE` method.
49
+ */
50
+ E.delete = methods_1.del;
51
+ /**
52
+ * The endpoint is executed with `HEAD` method.
53
+ */
54
+ E.head = methods_1.head;
55
+ /**
56
+ * Defines options to the endpoint.
57
+ */
58
+ E.options = options_1.default;
59
+ /**
60
+ * Define specific option to the endpoint.
61
+ */
62
+ E.option = (option, value) => E.options({ [option]: value });
63
+ /**
64
+ * Sets the `auth` option of the endpoint.
65
+ */
66
+ E.auth = (auth) => E.options({ auth });
67
+ /**
68
+ * Sets the `params` option to the endpoint using DTO classes.
69
+ */
70
+ E.params = (params, optionalParams = [], omit = []) => E.options({ params, optionalParams, omitParams: omit });
71
+ /**
72
+ * Sets the `response` option to the endpoint using DTO classes.
73
+ */
74
+ E.response = (response, omit = []) => E.options({ response, omitResponse: omit });
75
+ /**
76
+ * Sets the `params` and `response` options to the endpoint using DTO classes.
77
+ */
78
+ E.dto = (dto, optionalParams = [], omitParams = [], omitResponse = []) => E.options({ params: dto, response: dto, optionalParams, omitParams, omitResponse });
79
+ /**
80
+ * Sets the `errors` option to the endpoint.
81
+ */
82
+ E.errors = (errors) => E.options({ errors });
83
+ /**
84
+ * Sets the `description` option to the endpoint.
85
+ */
86
+ E.description = (description) => E.options({ description });
87
+ /**
88
+ * Sets the `hideDocs` option to `true` to the endpoint.
89
+ */
90
+ // tslint:disable-next-line: member-ordering
91
+ E.hideDocs = E.option('hideDocs', true);
92
+ /**
93
+ * Sets the `args` option to the endpoint.
94
+ */
95
+ E.args = (args) => E.options({ args });
96
+ /**
97
+ * Sets the `requireApiKey` option to the endpoint.
98
+ */
99
+ E.requireApiKey = (requireApiKey) => E.options({ requireApiKey });
100
+ /**
101
+ * Sets the `excludedApiKey` option to the endpoint.
102
+ */
103
+ E.excludedApiKeys = (excludedApiKeys) => E.options({ excludedApiKeys });
104
+ /**
105
+ * Sets the `timeout` option to the endpoint.
106
+ */
107
+ E.timeout = (timeout) => E.options({ timeout });
108
+ /**
109
+ * Sets the `props` option to the endpoint.
110
+ */
111
+ E.props = (props) => E.options({ props });
112
+ /**
113
+ * Sets the endpoint as empty. It returns 204 status code.
114
+ */
115
+ // tslint:disable-next-line: member-ordering
116
+ E.emptyResponse = E.response(null);
117
+ /**
118
+ * Sets the endpoint as deprecated.
119
+ */
120
+ // tslint:disable-next-line: member-ordering
121
+ E.deprecated = deprecated_1.default;
122
+ // tslint:disable-next-line: member-ordering
123
+ E.redirect = E.options({ redirect: true });
124
+ // tslint:disable-next-line: max-classes-per-file
125
+ class Controller {
126
+ constructor(app) {
127
+ this._app = app;
128
+ Controller._controllers.push(this);
129
+ }
130
+ /**
131
+ * Registers all found controllers in the directory to the application.
132
+ *
133
+ * @param app The instance of the application.
134
+ * @param directory Path to the directory where the controllers are located.
135
+ */
136
+ static registerDirectory(app, directory) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ const files = yield utils_1.fs.readdir(directory);
139
+ for (const file of files) {
140
+ const filename = path.resolve(directory, file);
141
+ if ((yield utils_1.fs.stat(filename)).isDirectory()) {
142
+ yield this.registerDirectory(app, filename);
143
+ continue;
144
+ }
145
+ try {
146
+ const M = (0, utils_1.requireModule)(filename);
147
+ if (M && M.prototype && M.prototype instanceof this) {
148
+ M.register(app);
149
+ }
150
+ }
151
+ catch (e) {
152
+ if (file.indexOf('.js.map') >= 0 || file.indexOf('.d.ts') >= 0) {
153
+ continue;
154
+ }
155
+ console.error(file, e);
156
+ }
157
+ }
158
+ });
159
+ }
160
+ static register(app) {
161
+ new this(app).register();
162
+ }
163
+ static getControllers() {
164
+ return this._controllers;
165
+ }
166
+ register() {
167
+ const version = this.getVersion();
168
+ for (const endpoint of this.getEndpoints()) {
169
+ let e;
170
+ if (version !== undefined) {
171
+ e = this._app.registerRoute(endpoint.method, version, this.getRoute(endpoint.route), this.getOptions(endpoint.propertyKey), endpoint.callback);
172
+ }
173
+ else {
174
+ e = this._app.registerRoute(endpoint.method, this.getRoute(endpoint.route), this.getOptions(endpoint.propertyKey), endpoint.callback);
175
+ }
176
+ if (this.isDeprecated(endpoint.propertyKey)) {
177
+ e.deprecate();
178
+ }
179
+ }
180
+ }
181
+ beforeExecution(req, res) {
182
+ return __awaiter(this, void 0, void 0, function* () { });
183
+ }
184
+ getEndpoints() {
185
+ return this.__endpoints__ || [];
186
+ }
187
+ getVersion() {
188
+ return this.constructor.__version__;
189
+ }
190
+ getResource() {
191
+ return this.constructor.__resource__;
192
+ }
193
+ getOptions(propertyKey) {
194
+ const t = this;
195
+ const controllerOptions = this.constructor.__options__;
196
+ if (!t.__options__) {
197
+ return {};
198
+ }
199
+ if (!t.__options__[propertyKey]) {
200
+ return {};
201
+ }
202
+ let options = t.__options__[propertyKey];
203
+ options = Object.assign(Object.assign(Object.assign({}, controllerOptions), options), { errors: [...((controllerOptions === null || controllerOptions === void 0 ? void 0 : controllerOptions.errors) || []), ...((options === null || options === void 0 ? void 0 : options.errors) || [])], props: Object.assign(Object.assign({}, controllerOptions === null || controllerOptions === void 0 ? void 0 : controllerOptions.props), options === null || options === void 0 ? void 0 : options.props) });
204
+ const { args, params, response, optionalParams, omitParams, omitResponse } = options, restOptions = __rest(options, ["args", "params", "response", "optionalParams", "omitParams", "omitResponse"]);
205
+ return Object.assign(Object.assign({}, restOptions), { args: args ? (args instanceof Array ? args : args.toArray()) : undefined, params: this._getParamsArray(params, optionalParams, omitParams), response: response instanceof resting_squirrel_1.Response.Base ? response : this._getResponseArray(response, omitResponse) });
206
+ }
207
+ isDeprecated(propertyKey) {
208
+ const t = this;
209
+ if (!t.__deprecated__) {
210
+ return false;
211
+ }
212
+ return t.__deprecated__.includes(propertyKey);
213
+ }
214
+ getRoute(route) {
215
+ let resource = this.getResource();
216
+ if (!resource) {
217
+ return route;
218
+ }
219
+ if (resource.indexOf('/') !== 0) {
220
+ resource = `/${resource}`;
221
+ }
222
+ if (route.indexOf('/') !== 0) {
223
+ route = `/${route}`;
224
+ }
225
+ if (route.lastIndexOf('/') === route.length - 1) {
226
+ route = route.substring(0, route.length - 1);
227
+ }
228
+ return `${resource}${route}`;
229
+ }
230
+ _getParamsArray(params, optional = [], omit = []) {
231
+ if (!params) {
232
+ return undefined;
233
+ }
234
+ if (params.prototype instanceof resting_squirrel_dto_1.RequestDto) {
235
+ return params.toArray(optional, omit);
236
+ }
237
+ return resting_squirrel_dto_1.default.toParams(params, optional, omit);
238
+ }
239
+ _getResponseArray(response, omit = []) {
240
+ if (response === null) {
241
+ return null;
242
+ }
243
+ if (!response) {
244
+ return undefined;
245
+ }
246
+ if (response.prototype instanceof resting_squirrel_dto_1.ResponseDto) {
247
+ return response.toArray();
248
+ }
249
+ return resting_squirrel_dto_1.default.toResponse(response, omit);
250
+ }
251
+ }
252
+ exports.default = Controller;
253
+ // #region Decorators
254
+ /**
255
+ * Sets the version to the `Controller` class. All endpoints will have this version.
256
+ */
257
+ Controller.version = version_1.default;
258
+ /**
259
+ * @alias version
260
+ */
261
+ Controller.v = Controller.version;
262
+ Controller.controllerOptions = controller_options_1.default;
263
+ Controller.resource = resource_1.default;
264
+ Controller.Endpoint = E;
265
+ /**
266
+ * Marks the endpoint on the method as deprecated.
267
+ * @deprecated
268
+ */
269
+ Controller.deprecated = deprecated_1.default;
270
+ // #region Methods
271
+ /**
272
+ * The endpoint is executed with `PUT` method.
273
+ * @deprecated
274
+ */
275
+ Controller.put = methods_1.put;
276
+ /**
277
+ * The endpoint is executed with `GET` method.
278
+ * @deprecated
279
+ */
280
+ Controller.get = methods_1.get;
281
+ /**
282
+ * The endpoint is executed with `POST` method.
283
+ * @deprecated
284
+ */
285
+ Controller.post = methods_1.post;
286
+ /**
287
+ * The endpoint is executed with `DELETE` method.
288
+ * @deprecated
289
+ */
290
+ Controller.delete = methods_1.del;
291
+ // #endregion
292
+ // #region Options
293
+ /**
294
+ * Defines options to the endpoint.
295
+ * @deprecated
296
+ */
297
+ Controller.options = options_1.default;
298
+ /**
299
+ * Define specific option to the endpoint.
300
+ * @deprecated
301
+ */
302
+ Controller.option = (option, value) => Controller.options({ [option]: value });
303
+ /**
304
+ * Sets the `auth` option of the endpoint.
305
+ * @deprecated
306
+ */
307
+ Controller.auth = (auth) => Controller.options({ auth });
308
+ /**
309
+ * Sets the `params` option to the endpoint using DTO classes.
310
+ * @deprecated
311
+ */
312
+ Controller.params = (params, optionalParams = [], omit = []) => Controller.options({ params, optionalParams, omitParams: omit });
313
+ /**
314
+ * Sets the `response` option to the endpoint using DTO classes.
315
+ * @deprecated
316
+ */
317
+ Controller.response = (response, omit = []) => Controller.options({ response, omitResponse: omit });
318
+ /**
319
+ * Sets the `params` and `response` options to the endpoint using DTO classes.
320
+ * @deprecated
321
+ */
322
+ Controller.dto = (dto, optionalParams = [], omitParams = [], omitResponse = []) => Controller.options({ params: dto, response: dto, optionalParams, omitParams, omitResponse });
323
+ /**
324
+ * Sets the `errors` option to the endpoint.
325
+ * @deprecated
326
+ */
327
+ Controller.errors = (errors) => Controller.options({ errors });
328
+ /**
329
+ * Sets the `description` option to the endpoint.
330
+ * @deprecated
331
+ */
332
+ Controller.description = (description) => Controller.options({ description });
333
+ /**
334
+ * Sets the `hideDocs` option to `true` to the endpoint.
335
+ * @deprecated
336
+ */
337
+ // tslint:disable-next-line: member-ordering
338
+ Controller.hideDocs = Controller.option('hideDocs', true);
339
+ /**
340
+ * Sets the `args` option to the endpoint.
341
+ * @deprecated
342
+ */
343
+ Controller.args = (args) => Controller.options({ args });
344
+ /**
345
+ * Sets the `requireApiKey` option to the endpoint.
346
+ * @deprecated
347
+ */
348
+ Controller.requireApiKey = (requireApiKey) => Controller.options({ requireApiKey });
349
+ /**
350
+ * Sets the `excludedApiKey` option to the endpoint.
351
+ * @deprecated
352
+ */
353
+ Controller.excludedApiKeys = (excludedApiKeys) => Controller.options({ excludedApiKeys });
354
+ /**
355
+ * Sets the `timeout` option to the endpoint.
356
+ * @deprecated
357
+ */
358
+ Controller.timeout = (timeout) => Controller.options({ timeout });
359
+ /**
360
+ * Sets the `props` option to the endpoint.
361
+ * @deprecated
362
+ */
363
+ Controller.props = (props) => Controller.options({ props });
364
+ /**
365
+ * Sets the endpoint as empty. It returns 204 status code.
366
+ * @deprecated
367
+ */
368
+ // tslint:disable-next-line: member-ordering
369
+ Controller.emptyResponse = Controller.response(null);
370
+ // #endregion
371
+ // #endregion
372
+ // tslint:disable-next-line: member-ordering
373
+ Controller._controllers = [];
374
374
  //# sourceMappingURL=controller.js.map