resting-squirrel-controller 2.6.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,380 +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
- 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: [
204
- ...((controllerOptions === null || controllerOptions === void 0 ? void 0 : controllerOptions.errors) || []),
205
- ...((options === null || options === void 0 ? void 0 : options.errors) || []),
206
- ], props: Object.assign(Object.assign({}, controllerOptions === null || controllerOptions === void 0 ? void 0 : controllerOptions.props), options === null || options === void 0 ? void 0 : options.props) });
207
- const { args, params, response, optionalParams, omitParams, omitResponse } = options, restOptions = __rest(options, ["args", "params", "response", "optionalParams", "omitParams", "omitResponse"]);
208
- return Object.assign(Object.assign({}, restOptions), { args: args
209
- ? args instanceof Array
210
- ? args
211
- : args.toArray()
212
- : undefined, params: this._getParamsArray(params, optionalParams, omitParams), response: response instanceof resting_squirrel_1.Response.Base
213
- ? response
214
- : this._getResponseArray(response, omitResponse) });
215
- }
216
- isDeprecated(propertyKey) {
217
- const t = this;
218
- if (!t.__deprecated__) {
219
- return false;
220
- }
221
- return t.__deprecated__.includes(propertyKey);
222
- }
223
- getRoute(route) {
224
- let resource = this.getResource();
225
- if (!resource) {
226
- return route;
227
- }
228
- if (resource.indexOf('/') !== 0) {
229
- resource = `/${resource}`;
230
- }
231
- if (route.indexOf('/') !== 0) {
232
- route = `/${route}`;
233
- }
234
- return `${resource}${route}`;
235
- }
236
- _getParamsArray(params, optional = [], omit = []) {
237
- if (!params) {
238
- return undefined;
239
- }
240
- if (params.prototype instanceof resting_squirrel_dto_1.RequestDto) {
241
- return params.toArray(optional, omit);
242
- }
243
- return resting_squirrel_dto_1.default.toParams(params, optional, omit);
244
- }
245
- _getResponseArray(response, omit = []) {
246
- if (response === null) {
247
- return null;
248
- }
249
- if (!response) {
250
- return undefined;
251
- }
252
- if (response.prototype instanceof resting_squirrel_dto_1.ResponseDto) {
253
- return response.toArray();
254
- }
255
- return resting_squirrel_dto_1.default.toResponse(response, omit);
256
- }
257
- }
258
- exports.default = Controller;
259
- // #region Decorators
260
- /**
261
- * Sets the version to the `Controller` class. All endpoints will have this version.
262
- */
263
- Controller.version = version_1.default;
264
- /**
265
- * @alias version
266
- */
267
- Controller.v = Controller.version;
268
- Controller.controllerOptions = controller_options_1.default;
269
- Controller.resource = resource_1.default;
270
- Controller.Endpoint = E;
271
- /**
272
- * Marks the endpoint on the method as deprecated.
273
- * @deprecated
274
- */
275
- Controller.deprecated = deprecated_1.default;
276
- // #region Methods
277
- /**
278
- * The endpoint is executed with `PUT` method.
279
- * @deprecated
280
- */
281
- Controller.put = methods_1.put;
282
- /**
283
- * The endpoint is executed with `GET` method.
284
- * @deprecated
285
- */
286
- Controller.get = methods_1.get;
287
- /**
288
- * The endpoint is executed with `POST` method.
289
- * @deprecated
290
- */
291
- Controller.post = methods_1.post;
292
- /**
293
- * The endpoint is executed with `DELETE` method.
294
- * @deprecated
295
- */
296
- Controller.delete = methods_1.del;
297
- // #endregion
298
- // #region Options
299
- /**
300
- * Defines options to the endpoint.
301
- * @deprecated
302
- */
303
- Controller.options = options_1.default;
304
- /**
305
- * Define specific option to the endpoint.
306
- * @deprecated
307
- */
308
- Controller.option = (option, value) => Controller.options({ [option]: value });
309
- /**
310
- * Sets the `auth` option of the endpoint.
311
- * @deprecated
312
- */
313
- Controller.auth = (auth) => Controller.options({ auth });
314
- /**
315
- * Sets the `params` option to the endpoint using DTO classes.
316
- * @deprecated
317
- */
318
- Controller.params = (params, optionalParams = [], omit = []) => Controller.options({ params, optionalParams, omitParams: omit });
319
- /**
320
- * Sets the `response` option to the endpoint using DTO classes.
321
- * @deprecated
322
- */
323
- Controller.response = (response, omit = []) => Controller.options({ response, omitResponse: omit });
324
- /**
325
- * Sets the `params` and `response` options to the endpoint using DTO classes.
326
- * @deprecated
327
- */
328
- Controller.dto = (dto, optionalParams = [], omitParams = [], omitResponse = []) => Controller.options({ params: dto, response: dto, optionalParams, omitParams, omitResponse });
329
- /**
330
- * Sets the `errors` option to the endpoint.
331
- * @deprecated
332
- */
333
- Controller.errors = (errors) => Controller.options({ errors });
334
- /**
335
- * Sets the `description` option to the endpoint.
336
- * @deprecated
337
- */
338
- Controller.description = (description) => Controller.options({ description });
339
- /**
340
- * Sets the `hideDocs` option to `true` to the endpoint.
341
- * @deprecated
342
- */
343
- // tslint:disable-next-line: member-ordering
344
- Controller.hideDocs = Controller.option('hideDocs', true);
345
- /**
346
- * Sets the `args` option to the endpoint.
347
- * @deprecated
348
- */
349
- Controller.args = (args) => Controller.options({ args });
350
- /**
351
- * Sets the `requireApiKey` option to the endpoint.
352
- * @deprecated
353
- */
354
- Controller.requireApiKey = (requireApiKey) => Controller.options({ requireApiKey });
355
- /**
356
- * Sets the `excludedApiKey` option to the endpoint.
357
- * @deprecated
358
- */
359
- Controller.excludedApiKeys = (excludedApiKeys) => Controller.options({ excludedApiKeys });
360
- /**
361
- * Sets the `timeout` option to the endpoint.
362
- * @deprecated
363
- */
364
- Controller.timeout = (timeout) => Controller.options({ timeout });
365
- /**
366
- * Sets the `props` option to the endpoint.
367
- * @deprecated
368
- */
369
- Controller.props = (props) => Controller.options({ props });
370
- /**
371
- * Sets the endpoint as empty. It returns 204 status code.
372
- * @deprecated
373
- */
374
- // tslint:disable-next-line: member-ordering
375
- Controller.emptyResponse = Controller.response(null);
376
- // #endregion
377
- // #endregion
378
- // tslint:disable-next-line: member-ordering
379
- Controller._controllers = [];
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 = [];
380
374
  //# sourceMappingURL=controller.js.map