@deepkit/http 1.0.1-alpha.100

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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/.gitkeep +0 -0
  4. package/dist/cjs/index.d.ts +14 -0
  5. package/dist/cjs/index.js +31 -0
  6. package/dist/cjs/index.js.map +1 -0
  7. package/dist/cjs/src/controllers.d.ts +13 -0
  8. package/dist/cjs/src/controllers.js +17 -0
  9. package/dist/cjs/src/controllers.js.map +1 -0
  10. package/dist/cjs/src/decorator.d.ts +241 -0
  11. package/dist/cjs/src/decorator.js +422 -0
  12. package/dist/cjs/src/decorator.js.map +1 -0
  13. package/dist/cjs/src/filter.d.ts +49 -0
  14. package/dist/cjs/src/filter.js +215 -0
  15. package/dist/cjs/src/filter.js.map +1 -0
  16. package/dist/cjs/src/http-app.d.ts +8 -0
  17. package/dist/cjs/src/http-app.js +16 -0
  18. package/dist/cjs/src/http-app.js.map +1 -0
  19. package/dist/cjs/src/http.d.ts +278 -0
  20. package/dist/cjs/src/http.js +878 -0
  21. package/dist/cjs/src/http.js.map +1 -0
  22. package/dist/cjs/src/kernel.d.ts +16 -0
  23. package/dist/cjs/src/kernel.js +79 -0
  24. package/dist/cjs/src/kernel.js.map +1 -0
  25. package/dist/cjs/src/logger.d.ts +7 -0
  26. package/dist/cjs/src/logger.js +34 -0
  27. package/dist/cjs/src/logger.js.map +1 -0
  28. package/dist/cjs/src/middleware.d.ts +61 -0
  29. package/dist/cjs/src/middleware.js +95 -0
  30. package/dist/cjs/src/middleware.js.map +1 -0
  31. package/dist/cjs/src/model.d.ts +165 -0
  32. package/dist/cjs/src/model.js +398 -0
  33. package/dist/cjs/src/model.js.map +1 -0
  34. package/dist/cjs/src/module.config.d.ts +84 -0
  35. package/dist/cjs/src/module.config.js +14 -0
  36. package/dist/cjs/src/module.config.js.map +1 -0
  37. package/dist/cjs/src/module.d.ts +14 -0
  38. package/dist/cjs/src/module.js +124 -0
  39. package/dist/cjs/src/module.js.map +1 -0
  40. package/dist/cjs/src/request-parser.d.ts +36 -0
  41. package/dist/cjs/src/request-parser.js +305 -0
  42. package/dist/cjs/src/request-parser.js.map +1 -0
  43. package/dist/cjs/src/router.d.ts +230 -0
  44. package/dist/cjs/src/router.js +617 -0
  45. package/dist/cjs/src/router.js.map +1 -0
  46. package/dist/cjs/src/static-serving.d.ts +32 -0
  47. package/dist/cjs/src/static-serving.js +157 -0
  48. package/dist/cjs/src/static-serving.js.map +1 -0
  49. package/dist/cjs/src/utils.d.ts +1 -0
  50. package/dist/cjs/src/utils.js +13 -0
  51. package/dist/cjs/src/utils.js.map +1 -0
  52. package/dist/cjs/tsconfig.tsbuildinfo +1 -0
  53. package/dist/esm/index.d.ts +14 -0
  54. package/dist/esm/index.js +15 -0
  55. package/dist/esm/index.js.map +1 -0
  56. package/dist/esm/package.json +1 -0
  57. package/dist/esm/src/controllers.d.ts +13 -0
  58. package/dist/esm/src/controllers.js +13 -0
  59. package/dist/esm/src/controllers.js.map +1 -0
  60. package/dist/esm/src/decorator.d.ts +241 -0
  61. package/dist/esm/src/decorator.js +414 -0
  62. package/dist/esm/src/decorator.js.map +1 -0
  63. package/dist/esm/src/filter.d.ts +49 -0
  64. package/dist/esm/src/filter.js +209 -0
  65. package/dist/esm/src/filter.js.map +1 -0
  66. package/dist/esm/src/http-app.d.ts +8 -0
  67. package/dist/esm/src/http-app.js +12 -0
  68. package/dist/esm/src/http-app.js.map +1 -0
  69. package/dist/esm/src/http.d.ts +278 -0
  70. package/dist/esm/src/http.js +841 -0
  71. package/dist/esm/src/http.js.map +1 -0
  72. package/dist/esm/src/kernel.d.ts +16 -0
  73. package/dist/esm/src/kernel.js +75 -0
  74. package/dist/esm/src/kernel.js.map +1 -0
  75. package/dist/esm/src/logger.d.ts +7 -0
  76. package/dist/esm/src/logger.js +30 -0
  77. package/dist/esm/src/logger.js.map +1 -0
  78. package/dist/esm/src/middleware.d.ts +61 -0
  79. package/dist/esm/src/middleware.js +90 -0
  80. package/dist/esm/src/middleware.js.map +1 -0
  81. package/dist/esm/src/model.d.ts +165 -0
  82. package/dist/esm/src/model.js +363 -0
  83. package/dist/esm/src/model.js.map +1 -0
  84. package/dist/esm/src/module.config.d.ts +84 -0
  85. package/dist/esm/src/module.config.js +10 -0
  86. package/dist/esm/src/module.config.js.map +1 -0
  87. package/dist/esm/src/module.d.ts +14 -0
  88. package/dist/esm/src/module.js +120 -0
  89. package/dist/esm/src/module.js.map +1 -0
  90. package/dist/esm/src/request-parser.d.ts +36 -0
  91. package/dist/esm/src/request-parser.js +295 -0
  92. package/dist/esm/src/request-parser.js.map +1 -0
  93. package/dist/esm/src/router.d.ts +230 -0
  94. package/dist/esm/src/router.js +605 -0
  95. package/dist/esm/src/router.js.map +1 -0
  96. package/dist/esm/src/static-serving.d.ts +32 -0
  97. package/dist/esm/src/static-serving.js +149 -0
  98. package/dist/esm/src/static-serving.js.map +1 -0
  99. package/dist/esm/src/utils.d.ts +1 -0
  100. package/dist/esm/src/utils.js +9 -0
  101. package/dist/esm/src/utils.js.map +1 -0
  102. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  103. package/index.ts +14 -0
  104. package/package.json +67 -0
  105. package/src/controllers.ts +11 -0
  106. package/src/decorator.ts +411 -0
  107. package/src/filter.ts +224 -0
  108. package/src/http-app.ts +11 -0
  109. package/src/http.ts +828 -0
  110. package/src/kernel.ts +79 -0
  111. package/src/logger.ts +20 -0
  112. package/src/middleware.ts +116 -0
  113. package/src/model.ts +392 -0
  114. package/src/module.config.ts +95 -0
  115. package/src/module.ts +116 -0
  116. package/src/request-parser.ts +346 -0
  117. package/src/router.ts +747 -0
  118. package/src/static-serving.ts +153 -0
  119. package/src/utils.ts +5 -0
  120. package/tsconfig.esm.json +36 -0
  121. package/tsconfig.json +53 -0
@@ -0,0 +1,422 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.http = exports.__ΩHttpDecorator = exports.httpAction = exports.HttpActionDecorator = exports.httpClass = exports.HttpControllerDecorator = exports.HttpAction = exports.HttpActionParameter = exports.HttpController = void 0;
4
+ /*@ts-ignore*/
5
+ const { __ΩClassType } = require('@deepkit/core');
6
+ /*@ts-ignore*/
7
+ const { __ΩSerializationOptions } = require('@deepkit/type');
8
+ /*@ts-ignore*/
9
+ const { __ΩRouteParameterResolver } = require('./router.js');
10
+ /*@ts-ignore*/
11
+ const { __ΩReceiveType } = require('@deepkit/type');
12
+ /*@ts-ignore*/
13
+ const { __ΩHttpMiddleware } = require('./middleware.js');
14
+ /*@ts-ignore*/
15
+ const { __ΩHttpMiddlewareFn } = require('./middleware.js');
16
+ /*@ts-ignore*/
17
+ const { __ΩExtractApiDataType } = require('@deepkit/type');
18
+ /*@ts-ignore*/
19
+ const { __ΩExtractClass } = require('@deepkit/type');
20
+ /*@ts-ignore*/
21
+ const { __ΩPropertyDecoratorFn } = require('@deepkit/type');
22
+ /*@ts-ignore*/
23
+ const { __ΩDecoratorAndFetchSignature } = require('@deepkit/type');
24
+ /*@ts-ignore*/
25
+ const { __ΩDualDecorator } = require('@deepkit/type');
26
+ /*@ts-ignore*/
27
+ const { __ΩUnionToIntersection } = require('@deepkit/type');
28
+ function __assignType(fn, args) {
29
+ fn.__type = args;
30
+ return fn;
31
+ }
32
+ const __ΩPick = ['T', 'K', 'l+e#!e"!fRb!b"Pde""N#!'];
33
+ const __ΩExclude = ['T', 'U', 'l6!Re$!RPe#!e$"qk#%QRb!b"Pde"!p)'];
34
+ const __ΩOmit = ['T', 'K', () => __ΩPick, () => __ΩExclude, 'b!b"e!!e!!ge!"o$#o##'];
35
+ /*
36
+ * Deepkit Framework
37
+ * Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
38
+ *
39
+ * This program is free software: you can redistribute it and/or modify
40
+ * it under the terms of the MIT License.
41
+ *
42
+ * You should have received a copy of the MIT License along with this program.
43
+ */
44
+ const core_1 = require("@deepkit/core");
45
+ const type_1 = require("@deepkit/type");
46
+ const middleware_js_1 = require("./middleware.js");
47
+ const __ΩHttpActionMiddleware = [() => middleware_js_1.HttpMiddlewareConfig, '', () => __ΩClassType, () => __ΩHttpMiddleware, () => __ΩHttpMiddlewareFn, 'PPP7!/"n$o#"n%J'];
48
+ function isMiddlewareClassTypeOrFn(v) {
49
+ return (0, core_1.isClass)(v) || !(0, type_1.isDecoratorContext)(middleware_js_1.httpMiddleware, v);
50
+ }
51
+ isMiddlewareClassTypeOrFn.__type = [() => __ΩHttpActionMiddleware, 'v', 'isMiddlewareClassTypeOrFn', 'Pn!2"!/#'];
52
+ class HttpController {
53
+ constructor() {
54
+ this.baseUrl = '';
55
+ this.actions = (Set.Ω = [[() => HttpAction, 'P7!']], new Set());
56
+ this.groups = [];
57
+ this.middlewares = [];
58
+ this.resolverForToken = new Map();
59
+ this.resolverForParameterName = new Map();
60
+ this.actionsProcessed = (Set.Ω = [[() => HttpAction, 'P7!']], new Set());
61
+ }
62
+ getUrl(action) {
63
+ return (0, core_1.urlJoin)('/', this.baseUrl, action.path);
64
+ }
65
+ addAction(action) {
66
+ this.actions.add(action);
67
+ }
68
+ getActions() {
69
+ for (const action of this.actions) {
70
+ if (!this.actionsProcessed.has(action)) {
71
+ action.groups = [
72
+ ...this.groups,
73
+ ...action.groups.filter(__assignType((g) => !this.groups.includes(g), ['g', '', 'P"2!"/"'])),
74
+ ];
75
+ this.actionsProcessed.add(action);
76
+ }
77
+ }
78
+ return this.actions;
79
+ }
80
+ removeAction(methodName) {
81
+ const action = this.getAction(methodName);
82
+ this.actions.delete(action);
83
+ this.actionsProcessed.delete(action);
84
+ }
85
+ getAction(methodName) {
86
+ for (const a of this.getActions()) {
87
+ if (a.methodName === methodName)
88
+ return a;
89
+ }
90
+ throw new Error(`No action with methodName ${methodName} found`);
91
+ }
92
+ }
93
+ exports.HttpController = HttpController;
94
+ HttpController.__type = ['baseUrl', function () { return ''; }, 'groups', function () { return []; }, () => middleware_js_1.HttpMiddlewareConfig, '', 'middlewares', function () { return []; }, () => __ΩClassType, 'resolverForToken', function () { return new Map(); }, () => __ΩClassType, 'resolverForParameterName', function () { return new Map(); }, () => HttpAction, 'action', 'getUrl', () => HttpAction, 'addAction', () => HttpAction, 'getActions', 'methodName', 'removeAction', () => HttpAction, 'getAction', '&3!>"&F3#>$PP7%/&F3\'>("n)E3*>+&n,E3->.PP7/20&01PP7220"03PP74D05P&26$07P&26P78095'];
95
+ class HttpActionParameter {
96
+ constructor() {
97
+ this.name = '';
98
+ this.optional = false;
99
+ }
100
+ }
101
+ exports.HttpActionParameter = HttpActionParameter;
102
+ HttpActionParameter.__type = ['name', function () { return ''; }, "body", "query", "queries", 'type', 'typePath', 'optional', function () { return false; }, '&3!>"P.#.$.%J3&8&3\'8)3(>)5'];
103
+ class HttpAction {
104
+ constructor() {
105
+ this.name = '';
106
+ this.description = '';
107
+ this.category = '';
108
+ this.path = '';
109
+ this.httpMethods = [];
110
+ this.methodName = '';
111
+ this.groups = [];
112
+ this.middlewares = [];
113
+ this.resolverForToken = new Map();
114
+ this.resolverForParameterName = new Map();
115
+ /**
116
+ * An arbitrary data container the user can use to store app specific settings/values.
117
+ */
118
+ this.data = (Map.Ω = [['"'], ['"']], new Map());
119
+ this.responses = [];
120
+ }
121
+ }
122
+ exports.HttpAction = HttpAction;
123
+ HttpAction.__type = ['name', function () { return ''; }, 'description', function () { return ''; }, 'category', function () { return ''; }, 'path', function () { return ''; }, 'httpMethods', function () { return []; }, 'methodName', function () { return ''; }, 'groups', function () { return []; }, () => type_1.Serializer, 'serializer', () => middleware_js_1.HttpMiddlewareConfig, '', 'middlewares', function () { return []; }, () => __ΩSerializationOptions, 'serializationOptions', () => __ΩClassType, 'resolverForToken', function () { return new Map(); }, () => __ΩClassType, 'resolverForParameterName', function () { return new Map(); }, 'statusCode', 'type', 'responses', function () { return []; }, '&3!>"&3#>$&3%>&&3\'>(&F3)>*&3+>,&F3->.P7/308PP71/2F33>4n5368"n7E38>9&n:E3;><P\'4=&4#"4>8MF3?>@5'];
124
+ class HttpControllerDecorator {
125
+ constructor() {
126
+ this.t = new HttpController;
127
+ }
128
+ controller(baseUrl = '') {
129
+ this.t.baseUrl = baseUrl;
130
+ }
131
+ group(...group) {
132
+ this.t.groups.push(...group);
133
+ }
134
+ middleware(...middlewares) {
135
+ this.t.middlewares.push(...middlewares.map(__assignType(v => isMiddlewareClassTypeOrFn(v) ? middleware_js_1.httpMiddleware.for(v) : v, ['v', '', 'P"2!"/"'])));
136
+ }
137
+ /**
138
+ * Adds a parameter resolver for parameters based on the class type. Use .resolveParameterByName() for name-based resolving.
139
+ *
140
+ * ```typescript
141
+ *
142
+ * class UserResolver {
143
+ * resolve(context: RouteParameterResolverContext): any | Promise<any> {
144
+ * return new User();
145
+ * }
146
+ * }
147
+ *
148
+ * @http.resolveParameter(User, UserResolver)
149
+ * class MyController {
150
+ *
151
+ * @http.GET()
152
+ * myAction(user: User) {
153
+ * }
154
+ * }
155
+ *
156
+ * new App({providers: [UserResolver]}).run();
157
+ * ```
158
+ */
159
+ resolveParameter(classType, resolver) {
160
+ this.t.resolverForToken.set(classType, resolver);
161
+ }
162
+ /**
163
+ * Adds a parameter resolver for parameters based on its name. Use .resolveParameter() for class-based resolving.
164
+ *
165
+ * ```typescript
166
+ *
167
+ * class UserResolver {
168
+ * resolve(context: RouteParameterResolverContext): any | Promise<any> {
169
+ * return new User();
170
+ * }
171
+ * }
172
+ *
173
+ * @http.resolveParameterByName('user', UserResolver)
174
+ * class MyController {
175
+ *
176
+ * @http.GET()
177
+ * myAction(user: User) {
178
+ * }
179
+ * }
180
+ *
181
+ * new App({providers: [UserResolver]}).run();
182
+ * ```
183
+ */
184
+ resolveParameterByName(name, resolver) {
185
+ this.t.resolverForParameterName.set(name, resolver);
186
+ }
187
+ setAction(action) {
188
+ this.t.addAction(action);
189
+ }
190
+ }
191
+ exports.HttpControllerDecorator = HttpControllerDecorator;
192
+ HttpControllerDecorator.__type = ['baseUrl', () => "", 'controller', 'group', () => __ΩHttpActionMiddleware, 'middlewares', 'middleware', () => __ΩClassType, 'classType', () => __ΩClassType, () => __ΩRouteParameterResolver, 'resolver', 'resolveParameter', 'name', () => __ΩClassType, () => __ΩRouteParameterResolver, 'resolveParameterByName', () => HttpAction, 'action', 'setAction', 'P&2!>""0#P&@2$"0$Pn%@2&"0\'PPn(&"J2)n+o*"2,"0-P&2.n0o/"2,"01PP7223"045'];
193
+ exports.httpClass = (0, type_1.createClassDecoratorContext)(HttpControllerDecorator);
194
+ class HttpActionDecorator {
195
+ constructor() {
196
+ this.t = new HttpAction;
197
+ }
198
+ onDecorator(target, property, parameterIndexOrDescriptor) {
199
+ if (!property)
200
+ return;
201
+ if (target === Object)
202
+ return;
203
+ this.t.methodName = property;
204
+ exports.httpClass.setAction(this.t)(target);
205
+ }
206
+ name(name) {
207
+ this.t.name = name;
208
+ }
209
+ description(description) {
210
+ this.t.description = description;
211
+ }
212
+ serialization(options) {
213
+ this.t.serializationOptions = options;
214
+ }
215
+ serializer(serializer) {
216
+ this.t.serializer = serializer;
217
+ }
218
+ middleware(...middlewares) {
219
+ this.t.middlewares.push(...middlewares.map(__assignType(v => isMiddlewareClassTypeOrFn(v) ? middleware_js_1.httpMiddleware.for(v) : v, ['v', '', 'P"2!"/"'])));
220
+ }
221
+ /**
222
+ * Allows to change the HttpAction object and composite multiple properties into one function.
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const authGroup = Symbol('authGroup');
227
+ *
228
+ * function authGroup(group: 'admin' | 'user') {
229
+ * return (action: HttpAction) => {
230
+ * action.data.set(authGroup, group);
231
+ * };
232
+ * }
233
+ *
234
+ * class My Controller {
235
+ * @http.GET('/assets').use(authGroup('admin'))
236
+ * assets() {}
237
+ * }
238
+ * ```
239
+ */
240
+ use(use) {
241
+ use(this.t);
242
+ }
243
+ /**
244
+ * Arbitrary value container that can be read in RouterParameterResolver and all
245
+ * HTTP workflow events (like authentication).
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * class My Controller {
250
+ * @http.GET('/assets').data('authGroup', 'admin')
251
+ * assets() {}
252
+ * }
253
+ * ```
254
+ */
255
+ data(name, value) {
256
+ this.t.data.set(name, value);
257
+ }
258
+ category(category) {
259
+ this.t.category = category;
260
+ }
261
+ group(...group) {
262
+ this.t.groups.push(...group);
263
+ }
264
+ GET(path = '') {
265
+ this.t.httpMethods.push('GET');
266
+ if (path)
267
+ this.t.path = path;
268
+ }
269
+ HEAD(path = '') {
270
+ this.t.httpMethods.push('HEAD');
271
+ if (path)
272
+ this.t.path = path;
273
+ }
274
+ POST(path = '') {
275
+ this.t.httpMethods.push('POST');
276
+ if (path)
277
+ this.t.path = path;
278
+ }
279
+ PUT(path = '') {
280
+ this.t.httpMethods.push('PUT');
281
+ if (path)
282
+ this.t.path = path;
283
+ }
284
+ DELETE(path = '') {
285
+ this.t.httpMethods.push('DELETE');
286
+ if (path)
287
+ this.t.path = path;
288
+ }
289
+ OPTIONS(path = '') {
290
+ this.t.httpMethods.push('OPTIONS');
291
+ if (path)
292
+ this.t.path = path;
293
+ }
294
+ TRACE(path = '') {
295
+ this.t.httpMethods.push('TRACE');
296
+ if (path)
297
+ this.t.path = path;
298
+ }
299
+ PATCH(path = '') {
300
+ this.t.httpMethods.push('PATCH');
301
+ if (path)
302
+ this.t.path = path;
303
+ }
304
+ ANY(path = '') {
305
+ this.t.httpMethods = [];
306
+ if (path)
307
+ this.t.path = path;
308
+ }
309
+ /**
310
+ * Adds additional information about what HTTP status codes are available in this route.
311
+ * You can add additionally a description and a response body type.
312
+ *
313
+ * The type is used for serialization for responses with the given statusCode.
314
+ *
315
+ * This information is available in Deepkit API console.
316
+ *
317
+ * ```typescript
318
+ *
319
+ * http.GET().response<boolean>(200, 'All ok')
320
+ *
321
+ * interface User {
322
+ * username: string;
323
+ * }
324
+ * http.GET().response<User>(200, 'User object')
325
+ *
326
+ * interface HttpErrorMessage {
327
+ * error: string;
328
+ * }
329
+ * http.GET().response<HttpErrorMessage>(500, 'Error')
330
+ * ```
331
+ */
332
+ response(statusCode, description, type) {
333
+ var _a;
334
+ if (description === void 0) { description = ''; }
335
+ if (type === void 0) { type = (_a = this.
336
+ /**
337
+ * Adds additional information about what HTTP status codes are available in this route.
338
+ * You can add additionally a description and a response body type.
339
+ *
340
+ * The type is used for serialization for responses with the given statusCode.
341
+ *
342
+ * This information is available in Deepkit API console.
343
+ *
344
+ * ```typescript
345
+ *
346
+ * http.GET().response<boolean>(200, 'All ok')
347
+ *
348
+ * interface User {
349
+ * username: string;
350
+ * }
351
+ * http.GET().response<User>(200, 'User object')
352
+ *
353
+ * interface HttpErrorMessage {
354
+ * error: string;
355
+ * }
356
+ * http.GET().response<HttpErrorMessage>(500, 'Error')
357
+ * ```
358
+ */
359
+ response.Ω) === null || _a === void 0 ? void 0 : _a[0]; }
360
+ this.response.Ω = undefined;
361
+ this.t.responses.push({ statusCode, description, type: type ? (0, type_1.resolveReceiveType)(type) : undefined });
362
+ }
363
+ /**
364
+ * Adds a parameter resolver for parameters based on the class type. Use .resolveParameterByName() for name-based resolving.
365
+ *
366
+ * ```typescript
367
+ *
368
+ * class UserResolver {
369
+ * resolve(context: RouteParameterResolverContext): any | Promise<any> {
370
+ * return new User();
371
+ * }
372
+ * }
373
+ *
374
+ * class MyController {
375
+ * @http.GET()
376
+ * @http.resolveParameter(User, UserResolver)
377
+ * myAction(user: User) {
378
+ * }
379
+ * }
380
+ *
381
+ * new App({providers: [UserResolver]}).run();
382
+ * ```
383
+ */
384
+ resolveParameter(classType, resolver) {
385
+ this.t.resolverForToken.set(classType, resolver);
386
+ }
387
+ /**
388
+ * Adds a parameter resolver for parameters based on its name. Use .resolveParameter() for class-based resolving.
389
+ *
390
+ * ```typescript
391
+ *
392
+ * class UserResolver {
393
+ * resolve(context: RouteParameterResolverContext): any | Promise<any> {
394
+ * return new User();
395
+ * }
396
+ * }
397
+ *
398
+ * class MyController {
399
+ * @http.GET()
400
+ * @http.resolveParameterByName('user', UserResolver)
401
+ * myAction(user: User) {
402
+ * }
403
+ * }
404
+ *
405
+ * new App({providers: [UserResolver]}).run();
406
+ * ```
407
+ */
408
+ resolveParameterByName(name, resolver) {
409
+ this.t.resolverForParameterName.set(name, resolver);
410
+ }
411
+ }
412
+ exports.HttpActionDecorator = HttpActionDecorator;
413
+ HttpActionDecorator.__type = [() => __ΩClassType, 'target', 'property', 'parameterIndexOrDescriptor', 'onDecorator', 'name', 'description', () => __ΩSerializationOptions, 'options', 'serialization', () => type_1.Serializer, 'serializer', () => __ΩHttpActionMiddleware, 'middlewares', 'middleware', () => HttpAction, 'action', '', 'use', 'value', 'data', 'category', 'group', 'path', () => "", 'GET', () => "", 'HEAD', () => "", 'POST', () => "", 'PUT', () => "", 'DELETE', () => "", 'OPTIONS', () => "", 'TRACE', () => "", 'PATCH', () => "", 'ANY', 'statusCode', () => "", () => __ΩReceiveType, 'type', 'response', () => __ΩClassType, 'classType', () => __ΩClassType, () => __ΩRouteParameterResolver, 'resolver', 'resolveParameter', () => __ΩClassType, () => __ΩRouteParameterResolver, 'resolveParameterByName', 'Pn!2"P&-J2#"2$8"0%P&2&"0&P&2\'"0\'Pn(2)"0*PP7+2,"0,Pn-@2."0/PPP7021$/223"03P&2&"24"05P&26"06P&@27"07P&28>9"0:P&28>;"0<P&28>="0>P&28>?"0@P&28>A"0BP&28>C"0DP&28>E"0FP&28>G"0HP&28>I"0JP\'2K&2\'>L"oM"2N8"0OPPnP&"J2QnSoR"2T"0UP&2&nWoV"2T"0X5'];
414
+ const __ΩHttpActionFluidDecorator = ['T', 'D', "response", 'statusCode', 'description', () => __ΩReceiveType, 'type', () => __ΩHttpActionFluidDecorator, '', 'args', () => __ΩHttpActionFluidDecorator, () => __ΩHttpActionFluidDecorator, () => __ΩExtractApiDataType, '_data', 'l\u00A1P\'2$&2%8"o&"2\'8Pe)"e)!e)"o(#K/)RPe#!@2*Pe+"e+!e+"o+#K/)RPe*"e*!e*"o,#Pe+!o-"4.MKRPde(!e%!fPh"!@2*"/)qkC[QRPe#!.#qk#tQRPde#!p\u008DRb!b"Pde"!gN\u0099!'];
415
+ const __ΩHttpActionPropertyDecoratorResult = [() => __ΩHttpActionFluidDecorator, () => __ΩExtractClass, () => HttpActionDecorator, () => __ΩPropertyDecoratorFn, () => __ΩDecoratorAndFetchSignature, () => HttpActionDecorator, () => __ΩPropertyDecoratorFn, 'Pi#o""n$o!#i&n\'o%#K'];
416
+ exports.httpAction = (0, type_1.createPropertyDecoratorContext)(HttpActionDecorator);
417
+ const __ΩHttpMerge = ['U', "response", 'statusCode', 'description', () => __ΩReceiveType, 'type', () => __ΩPropertyDecoratorFn, '', 'a', () => __ΩDualDecorator, () => __ΩPropertyDecoratorFn, 'l\u00A3P\'2#&2$8"o%"2&8Pn\'e)!K/(RPe\'!@2)Pn+e&!e/!K/(RPe\'!@2)e%!/(RPe#!n*qk<PQRPde#"p]R!RPdde(!e%!fPh"!@2)h""/(qkiqQRPe#!."qk#sQRPde#!p\u008FRb!Pde"!gN\u009B!'];
418
+ const __ΩMergedHttp = ['T', () => __ΩHttpMerge, () => __ΩOmit, () => __ΩUnionToIntersection, "_fetch", "t", 'b!e!!\'fo$"P.%.&Jo##o""'];
419
+ const __ΩHttpDecorator = [() => __ΩPropertyDecoratorFn, () => __ΩHttpActionFluidDecorator, () => HttpActionDecorator, () => __ΩPropertyDecoratorFn, 'Pn!P7#n$o"#K'];
420
+ exports.__ΩHttpDecorator = __ΩHttpDecorator;
421
+ exports.http = (0, type_1.mergeDecorator)(exports.httpClass, exports.httpAction);
422
+ //# sourceMappingURL=decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../src/decorator.ts"],"names":[],"mappings":";;;;iCAU4C,eAAe;;4CAkBpD,eAAe;;8CACiB,aAAa;;mCAD7C,eAAe;;sCAEiE,iBAAiB;;wCAAjB,iBAAiB;;0CAFjG,eAAe;;oCAAf,eAAe;;2CAAf,eAAe;;kDAAf,eAAe;;qCA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AC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sBAAsB,CAAC,IAAY,EAAE,QAA2C;QAC5E,IAAI,CAAC,CAAC,CAAC,wBAAwB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;;AArML,kDAsMC;;;;AAUY,QAAA,UAAU,GAAsC,IAAA,qCAA8B,EAAC,mBAAmB,CAAC,CAAC;;;;;AAQpG,QAAA,IAAI,GAAsD,IAAA,qBAAc,EAAC,iBAAS,EAAE,kBAAU,CAA6D,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { ClassType } from '@deepkit/core';
2
+ import { AppModule } from '@deepkit/app';
3
+ import { RouteConfig, HttpRouter } from './router.js';
4
+ export interface HttpRouteFilterRoute {
5
+ path?: string;
6
+ pathRegExp?: RegExp;
7
+ httpMethod?: 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' | 'OPTIONS' | 'TRACE';
8
+ category?: string;
9
+ group?: string;
10
+ }
11
+ export declare class HttpRouteFilterModel {
12
+ controllers: ClassType[];
13
+ excludeControllers: ClassType[];
14
+ routes: HttpRouteFilterRoute[];
15
+ excludeRoutes: HttpRouteFilterRoute[];
16
+ routeNames: string[];
17
+ excludeRouteNames: string[];
18
+ modules: AppModule<any>[];
19
+ excludeModules: AppModule<any>[];
20
+ moduleClasses: ClassType<AppModule<any>>[];
21
+ excludeModuleClasses: ClassType<AppModule<any>>[];
22
+ reset(): void;
23
+ }
24
+ export declare class HttpRouterFilterResolver {
25
+ protected router: HttpRouter;
26
+ constructor(router: HttpRouter);
27
+ /**
28
+ * Resolves
29
+ */
30
+ resolve(filter: HttpRouteFilterModel): RouteConfig[];
31
+ }
32
+ /**
33
+ * A class to describe a filter for routes.
34
+ */
35
+ export declare class HttpRouteFilter {
36
+ model: HttpRouteFilterModel;
37
+ reset(): this;
38
+ forControllers(...controllers: ClassType[]): this;
39
+ excludeControllers(...controllers: ClassType[]): this;
40
+ forRoutes(...routes: HttpRouteFilterRoute[]): this;
41
+ excludeRoutes(...routes: HttpRouteFilterRoute[]): this;
42
+ forRouteNames(...names: string[]): this;
43
+ excludeRouteNames(...names: string[]): this;
44
+ forModules(...modules: AppModule<any>[]): this;
45
+ excludeModules(...modules: AppModule<any>[]): this;
46
+ forModuleClasses(...moduleClasses: ClassType<AppModule<any>>[]): this;
47
+ excludeModuleClasses(...moduleClasses: ClassType<AppModule<any>>[]): this;
48
+ }
49
+ export declare type __ΩHttpRouteFilterRoute = any[];