@deepkit/http 1.0.1-alpha.16 → 1.0.1-alpha.160
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.
- package/CHANGELOG.md +236 -0
- package/dist/cjs/index.d.ts +14 -10
- package/dist/cjs/index.js +19 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/src/controllers.d.ts +10 -3
- package/dist/cjs/src/controllers.js +7 -3
- package/dist/cjs/src/controllers.js.map +1 -1
- package/dist/cjs/src/decorator.d.ts +144 -70
- package/dist/cjs/src/decorator.js +277 -102
- package/dist/cjs/src/decorator.js.map +1 -1
- package/dist/cjs/src/filter.d.ts +49 -0
- package/dist/cjs/src/filter.js +215 -0
- package/dist/cjs/src/filter.js.map +1 -0
- package/dist/cjs/src/http-app.d.ts +8 -0
- package/dist/cjs/src/http-app.js +16 -0
- package/dist/cjs/src/http-app.js.map +1 -0
- package/dist/cjs/src/http.d.ts +131 -32
- package/dist/cjs/src/http.js +523 -122
- package/dist/cjs/src/http.js.map +1 -1
- package/dist/cjs/src/kernel.d.ts +50 -9
- package/dist/cjs/src/kernel.js +109 -98
- package/dist/cjs/src/kernel.js.map +1 -1
- package/dist/cjs/src/logger.d.ts +3 -3
- package/dist/cjs/src/logger.js +9 -12
- package/dist/cjs/src/logger.js.map +1 -1
- package/dist/cjs/src/middleware.d.ts +61 -0
- package/dist/cjs/src/middleware.js +95 -0
- package/dist/cjs/src/middleware.js.map +1 -0
- package/dist/cjs/src/model.d.ts +270 -4
- package/dist/cjs/src/model.js +401 -3
- package/dist/cjs/src/model.js.map +1 -1
- package/dist/cjs/src/module.config.d.ts +149 -4
- package/dist/cjs/src/module.config.js +11 -6
- package/dist/cjs/src/module.config.js.map +1 -1
- package/dist/cjs/src/module.d.ts +14 -32
- package/dist/cjs/src/module.js +122 -7
- package/dist/cjs/src/module.js.map +1 -1
- package/dist/cjs/src/request-parser.d.ts +37 -0
- package/dist/cjs/src/request-parser.js +382 -0
- package/dist/cjs/src/request-parser.js.map +1 -0
- package/dist/cjs/src/router.d.ts +174 -75
- package/dist/cjs/src/router.js +469 -288
- package/dist/cjs/src/router.js.map +1 -1
- package/dist/cjs/src/static-serving.d.ts +32 -4
- package/dist/cjs/src/static-serving.js +115 -71
- package/dist/cjs/src/static-serving.js.map +1 -1
- package/dist/cjs/src/utils.js +2 -2
- package/dist/cjs/src/utils.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -2916
- package/dist/esm/index.d.ts +14 -10
- package/dist/esm/index.js +14 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/controllers.d.ts +10 -3
- package/dist/esm/src/controllers.js +7 -3
- package/dist/esm/src/controllers.js.map +1 -1
- package/dist/esm/src/decorator.d.ts +144 -70
- package/dist/esm/src/decorator.js +272 -99
- package/dist/esm/src/decorator.js.map +1 -1
- package/dist/esm/src/filter.d.ts +49 -0
- package/dist/esm/src/filter.js +209 -0
- package/dist/esm/src/filter.js.map +1 -0
- package/dist/esm/src/http-app.d.ts +8 -0
- package/dist/esm/src/http-app.js +12 -0
- package/dist/esm/src/http-app.js.map +1 -0
- package/dist/esm/src/http.d.ts +131 -32
- package/dist/esm/src/http.js +504 -121
- package/dist/esm/src/http.js.map +1 -1
- package/dist/esm/src/kernel.d.ts +50 -9
- package/dist/esm/src/kernel.js +110 -100
- package/dist/esm/src/kernel.js.map +1 -1
- package/dist/esm/src/logger.d.ts +3 -3
- package/dist/esm/src/logger.js +7 -11
- package/dist/esm/src/logger.js.map +1 -1
- package/dist/esm/src/middleware.d.ts +61 -0
- package/dist/esm/src/middleware.js +90 -0
- package/dist/esm/src/middleware.js.map +1 -0
- package/dist/esm/src/model.d.ts +270 -4
- package/dist/esm/src/model.js +357 -1
- package/dist/esm/src/model.js.map +1 -1
- package/dist/esm/src/module.config.d.ts +149 -4
- package/dist/esm/src/module.config.js +9 -5
- package/dist/esm/src/module.config.js.map +1 -1
- package/dist/esm/src/module.d.ts +14 -32
- package/dist/esm/src/module.js +121 -7
- package/dist/esm/src/module.js.map +1 -1
- package/dist/esm/src/request-parser.d.ts +37 -0
- package/dist/esm/src/request-parser.js +372 -0
- package/dist/esm/src/request-parser.js.map +1 -0
- package/dist/esm/src/router.d.ts +174 -75
- package/dist/esm/src/router.js +463 -285
- package/dist/esm/src/router.js.map +1 -1
- package/dist/esm/src/static-serving.d.ts +32 -4
- package/dist/esm/src/static-serving.js +107 -65
- package/dist/esm/src/static-serving.js.map +1 -1
- package/dist/esm/src/utils.js +1 -0
- package/dist/esm/src/utils.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -2916
- package/index.ts +14 -10
- package/package.json +30 -19
- package/src/controllers.ts +4 -3
- package/src/decorator.ts +242 -104
- package/src/filter.ts +224 -0
- package/src/http-app.ts +11 -0
- package/src/http.ts +501 -100
- package/src/kernel.ts +128 -80
- package/src/logger.ts +4 -6
- package/src/middleware.ts +116 -0
- package/src/model.ts +516 -5
- package/src/module.config.ts +168 -5
- package/src/module.ts +120 -7
- package/src/request-parser.ts +430 -0
- package/src/router.ts +546 -317
- package/src/static-serving.ts +120 -50
- package/src/utils.ts +0 -2
- package/tsconfig.esm.json +7 -7
- package/tsconfig.json +18 -11
- package/tsconfig.spec.json +8 -0
- package/dist/cjs/tests/router.spec.d.ts +0 -1
- package/dist/cjs/tests/router.spec.js +0 -481
- package/dist/cjs/tests/router.spec.js.map +0 -1
- package/dist/esm/tests/router.spec.d.ts +0 -1
- package/dist/esm/tests/router.spec.js +0 -479
- package/dist/esm/tests/router.spec.js.map +0 -1
- package/tests/router.spec.ts +0 -347
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRouteFilter = exports.HttpRouterFilterResolver = exports.HttpRouteFilterModel = exports.__ΩHttpRouteFilterRoute = void 0;
|
|
4
|
+
/*@ts-ignore*/
|
|
5
|
+
const { __ΩClassType } = require('@deepkit/core');
|
|
6
|
+
const app_1 = require("@deepkit/app");
|
|
7
|
+
const router_js_1 = require("./router.js");
|
|
8
|
+
const __ΩHttpRouteFilterRoute = ['path', 'pathRegExp', "GET", "HEAD", "POST", "PATCH", "PUT", "DELETE", "OPTIONS", "TRACE", 'httpMethod', 'category', 'group', 'HttpRouteFilterRoute', 'P&4!8A4"8P.#.$.%.&.\'.(.).*J4+8&4,8&4-8Mw.y'];
|
|
9
|
+
exports.__ΩHttpRouteFilterRoute = __ΩHttpRouteFilterRoute;
|
|
10
|
+
class HttpRouteFilterModel {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.controllers = [];
|
|
13
|
+
this.excludeControllers = [];
|
|
14
|
+
this.routes = [];
|
|
15
|
+
this.excludeRoutes = [];
|
|
16
|
+
this.routeNames = [];
|
|
17
|
+
this.excludeRouteNames = [];
|
|
18
|
+
this.modules = [];
|
|
19
|
+
this.excludeModules = [];
|
|
20
|
+
this.moduleClasses = [];
|
|
21
|
+
this.excludeModuleClasses = [];
|
|
22
|
+
}
|
|
23
|
+
reset() {
|
|
24
|
+
this.controllers = [];
|
|
25
|
+
this.excludeControllers = [];
|
|
26
|
+
this.routes = [];
|
|
27
|
+
this.excludeRoutes = [];
|
|
28
|
+
this.routeNames = [];
|
|
29
|
+
this.excludeRouteNames = [];
|
|
30
|
+
this.modules = [];
|
|
31
|
+
this.moduleClasses = [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.HttpRouteFilterModel = HttpRouteFilterModel;
|
|
35
|
+
HttpRouteFilterModel.__type = [() => __ΩClassType, 'controllers', function () { return []; }, () => __ΩClassType, 'excludeControllers', function () { return []; }, () => __ΩHttpRouteFilterRoute, 'routes', function () { return []; }, () => __ΩHttpRouteFilterRoute, 'excludeRoutes', function () { return []; }, 'routeNames', function () { return []; }, 'excludeRouteNames', function () { return []; }, () => app_1.AppModule, 'modules', function () { return []; }, () => app_1.AppModule, 'excludeModules', function () { return []; }, () => __ΩClassType, () => app_1.AppModule, 'moduleClasses', function () { return []; }, () => __ΩClassType, () => app_1.AppModule, 'excludeModuleClasses', function () { return []; }, 'reset', 'HttpRouteFilterModel', 'n!F3">#n$F3%>&n\'F3(>)n*F3+>,&F3->.&F3/>0P"71F32>3P"74F35>6P"78o7"F39>:P"7<o;"F3=>>P"0?5w@'];
|
|
36
|
+
function match(routeConfig, route) {
|
|
37
|
+
if (route.httpMethod && routeConfig.httpMethods.includes(route.httpMethod))
|
|
38
|
+
return true;
|
|
39
|
+
if (route.category && route.category !== routeConfig.category)
|
|
40
|
+
return true;
|
|
41
|
+
if (route.group && routeConfig.groups.includes(route.group))
|
|
42
|
+
return true;
|
|
43
|
+
if (route.path || route.pathRegExp) {
|
|
44
|
+
if (!route.pathRegExp && route.path)
|
|
45
|
+
route.pathRegExp = new RegExp('^' + route.path.replace(/\*/g, '.*') + '$');
|
|
46
|
+
if (route.pathRegExp && route.pathRegExp.test(routeConfig.getFullPath()))
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
match.__type = [() => router_js_1.RouteConfig, 'routeConfig', () => __ΩHttpRouteFilterRoute, 'route', 'match', 'PP7!2"n#2$)/%'];
|
|
52
|
+
class HttpRouterFilterResolver {
|
|
53
|
+
constructor(router) {
|
|
54
|
+
this.router = router;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolves
|
|
58
|
+
*/
|
|
59
|
+
resolve(filter) {
|
|
60
|
+
const result = [];
|
|
61
|
+
outer: for (const routeConfig of this.router.getRoutes()) {
|
|
62
|
+
if (filter.controllers.length && routeConfig.action.type === 'controller' && !filter.controllers.includes(routeConfig.action.controller))
|
|
63
|
+
continue;
|
|
64
|
+
if (filter.excludeControllers.length && routeConfig.action.type === 'controller' && filter.excludeControllers.includes(routeConfig.action.controller))
|
|
65
|
+
continue;
|
|
66
|
+
if (filter.modules.length) {
|
|
67
|
+
if (!routeConfig.module)
|
|
68
|
+
continue;
|
|
69
|
+
let found = false;
|
|
70
|
+
for (const module of filter.modules) {
|
|
71
|
+
//modules get cloned everywhere, but id is sticky. So we compare that.
|
|
72
|
+
if (routeConfig.module.id === module.id) {
|
|
73
|
+
found = true;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!found)
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (filter.excludeModules.length) {
|
|
81
|
+
if (!routeConfig.module)
|
|
82
|
+
continue;
|
|
83
|
+
for (const module of filter.excludeModules) {
|
|
84
|
+
//modules get cloned everywhere, but id is sticky. So we compare that.
|
|
85
|
+
if (routeConfig.module.id === module.id)
|
|
86
|
+
continue outer;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (filter.moduleClasses.length) {
|
|
90
|
+
if (!routeConfig.module)
|
|
91
|
+
continue;
|
|
92
|
+
let found = false;
|
|
93
|
+
for (const module of filter.moduleClasses) {
|
|
94
|
+
if (routeConfig.module instanceof module) {
|
|
95
|
+
found = true;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!found)
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (filter.excludeModuleClasses.length) {
|
|
103
|
+
if (!routeConfig.module)
|
|
104
|
+
continue;
|
|
105
|
+
for (const module of filter.excludeModuleClasses) {
|
|
106
|
+
if (routeConfig.module instanceof module)
|
|
107
|
+
continue outer;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (filter.routeNames.length) {
|
|
111
|
+
let found = false;
|
|
112
|
+
for (const name of filter.routeNames) {
|
|
113
|
+
if (name.includes('*')) {
|
|
114
|
+
const regex = new RegExp('^' + name.replace(/\*/g, '.*') + '$');
|
|
115
|
+
if (regex.test(routeConfig.name)) {
|
|
116
|
+
found = true;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (name === routeConfig.name) {
|
|
121
|
+
found = true;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (!found)
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (filter.excludeRouteNames.length) {
|
|
129
|
+
for (const name of filter.excludeRouteNames) {
|
|
130
|
+
if (name.includes('*')) {
|
|
131
|
+
const regex = new RegExp('^' + name.replace(/\*/g, '.*') + '$');
|
|
132
|
+
if (regex.test(routeConfig.name))
|
|
133
|
+
continue outer;
|
|
134
|
+
}
|
|
135
|
+
else if (name == routeConfig.name) {
|
|
136
|
+
continue outer;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (filter.routes.length) {
|
|
141
|
+
let found = false;
|
|
142
|
+
for (const route of filter.routes) {
|
|
143
|
+
if (match(routeConfig, route)) {
|
|
144
|
+
found = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!found)
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
for (const route of filter.excludeRoutes) {
|
|
151
|
+
if (match(routeConfig, route))
|
|
152
|
+
continue outer;
|
|
153
|
+
}
|
|
154
|
+
result.push(routeConfig);
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.HttpRouterFilterResolver = HttpRouterFilterResolver;
|
|
160
|
+
HttpRouterFilterResolver.__type = [() => router_js_1.HttpRouter, 'router', 'constructor', () => HttpRouteFilterModel, 'filter', () => router_js_1.RouteConfig, 'resolve', 'HttpRouterFilterResolver', 'PP7!2"<"0#PP7$2%P7&F0\'5w('];
|
|
161
|
+
/**
|
|
162
|
+
* A class to describe a filter for routes.
|
|
163
|
+
*/
|
|
164
|
+
class HttpRouteFilter {
|
|
165
|
+
constructor() {
|
|
166
|
+
this.model = new HttpRouteFilterModel();
|
|
167
|
+
}
|
|
168
|
+
reset() {
|
|
169
|
+
this.model.reset();
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
forControllers(...controllers) {
|
|
173
|
+
this.model.controllers.push(...controllers);
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
excludeControllers(...controllers) {
|
|
177
|
+
this.model.excludeControllers.push(...controllers);
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
forRoutes(...routes) {
|
|
181
|
+
this.model.routes.push(...routes);
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
excludeRoutes(...routes) {
|
|
185
|
+
this.model.excludeRoutes.push(...routes);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
forRouteNames(...names) {
|
|
189
|
+
this.model.routeNames.push(...names);
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
excludeRouteNames(...names) {
|
|
193
|
+
this.model.excludeRouteNames.push(...names);
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
forModules(...modules) {
|
|
197
|
+
this.model.modules.push(...modules);
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
excludeModules(...modules) {
|
|
201
|
+
this.model.excludeModules.push(...modules);
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
forModuleClasses(...moduleClasses) {
|
|
205
|
+
this.model.moduleClasses.push(...moduleClasses);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
excludeModuleClasses(...moduleClasses) {
|
|
209
|
+
this.model.excludeModuleClasses.push(...moduleClasses);
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.HttpRouteFilter = HttpRouteFilter;
|
|
214
|
+
HttpRouteFilter.__type = ['model', function () { return new HttpRouteFilterModel(); }, 'reset', () => __ΩClassType, 'controllers', 'forControllers', () => __ΩClassType, 'excludeControllers', () => __ΩHttpRouteFilterRoute, 'routes', 'forRoutes', () => __ΩHttpRouteFilterRoute, 'excludeRoutes', 'names', 'forRouteNames', 'excludeRouteNames', () => app_1.AppModule, 'modules', 'forModules', () => app_1.AppModule, 'excludeModules', () => __ΩClassType, () => app_1.AppModule, 'moduleClasses', 'forModuleClasses', () => __ΩClassType, () => app_1.AppModule, 'excludeModuleClasses', 'HttpRouteFilter', '!3!>"P!0#Pn$@2%!0&Pn\'@2%!0(Pn)@2*!0+Pn,@2*!0-P&@2.!0/P&@2.!00PP"71@22!03PP"74@22!05PP"77o6"@28!09PP"7;o:"@28!0<5w='];
|
|
215
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/filter.ts"],"names":[],"mappings":";;;;iCAA0B,eAAe;AACzC,sCAAyC;AACzC,2CAAsD;;;AAUtD,MAAa,oBAAoB;IAAjC;QACI,gBAAW,GAAgB,EAAE,CAAC;QAC9B,uBAAkB,GAAgB,EAAE,CAAC;QAErC,WAAM,GAA2B,EAAE,CAAC;QACpC,kBAAa,GAA2B,EAAE,CAAC;QAE3C,eAAU,GAAa,EAAE,CAAC;QAC1B,sBAAiB,GAAa,EAAE,CAAC;QAEjC,YAAO,GAAqB,EAAE,CAAC;QAC/B,mBAAc,GAAqB,EAAE,CAAC;QAEtC,kBAAa,GAAgC,EAAE,CAAC;QAChD,yBAAoB,GAAgC,EAAE,CAAC;KAe1D;IAbG,KAAK;QACD,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QAExB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;QAE5B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC5B,CAAC;;AA5BL,oDA6BC;uFA5B8B,EAAE,oEACK,EAAE,mEAEH,EAAE,0EACK,EAA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AAC;IAChB,CAAC;IAED,oBAAoB,CAAC,GAAG,aAA0C;QAC9D,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IAChB,CAAC;;AAxDL,0CAyDC;wDAxDkB,IAAI,oBAAoB,EAAE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { App, RootModuleDefinition } from '@deepkit/app';
|
|
2
|
+
import { HttpRouterRegistry } from './router.js';
|
|
3
|
+
/**
|
|
4
|
+
* Same as App, but with easily accessible router to make the most common use case easier.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpApp<T extends RootModuleDefinition> extends App<T> {
|
|
7
|
+
get router(): HttpRouterRegistry;
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpApp = void 0;
|
|
4
|
+
const app_1 = require("@deepkit/app");
|
|
5
|
+
const router_js_1 = require("./router.js");
|
|
6
|
+
/**
|
|
7
|
+
* Same as App, but with easily accessible router to make the most common use case easier.
|
|
8
|
+
*/
|
|
9
|
+
class HttpApp extends app_1.App {
|
|
10
|
+
get router() {
|
|
11
|
+
return super.get(router_js_1.HttpRouterRegistry);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.HttpApp = HttpApp;
|
|
15
|
+
HttpApp.__type = ['T', () => app_1.App, 'HttpApp', 'b!Pe"!7"!5e!!6"w#'];
|
|
16
|
+
//# sourceMappingURL=http-app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-app.js","sourceRoot":"","sources":["../../../src/http-app.ts"],"names":[],"mappings":";;;AAAA,sCAAyD;AACzD,2CAAiD;AAEjD;;GAEG;AACH,MAAa,OAAwC,SAAQ,SAAM;IAC/D,IAAI,MAAM;QACN,OAAO,KAAK,CAAC,GAAG,CAAC,8BAAkB,CAAC,CAAC;IACzC,CAAC;;AAHL,0BAIC"}
|
package/dist/cjs/src/http.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClassType, CustomError } from '@deepkit/core';
|
|
2
|
+
import { OutgoingHttpHeaders, ServerResponse } from 'http';
|
|
3
|
+
import { HttpRequest, HttpRequestPositionedParameters, HttpResponse } from './model.js';
|
|
2
4
|
import { InjectorContext } from '@deepkit/injector';
|
|
3
|
-
import {
|
|
4
|
-
import { RouteConfig, RouteParameterResolverForInjector
|
|
5
|
+
import { LoggerInterface } from '@deepkit/logger';
|
|
6
|
+
import { HttpRouter, RouteConfig, RouteParameterResolverForInjector } from './router.js';
|
|
5
7
|
import { WorkflowEvent } from '@deepkit/workflow';
|
|
8
|
+
import type { ElementStruct } from '@deepkit/template';
|
|
9
|
+
import { Stopwatch } from '@deepkit/stopwatch';
|
|
10
|
+
import { Type } from '@deepkit/type';
|
|
11
|
+
import stream from 'stream';
|
|
12
|
+
export declare function isElementStruct(v: any): v is ElementStruct;
|
|
6
13
|
export declare class Redirect {
|
|
7
14
|
statusCode: number;
|
|
8
15
|
routeName?: string;
|
|
@@ -16,27 +23,55 @@ export declare class Redirect {
|
|
|
16
23
|
}, statusCode?: number): Redirect;
|
|
17
24
|
static toUrl(url: string, statusCode?: number): Redirect;
|
|
18
25
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
export declare class HttpError<T extends number> extends CustomError {
|
|
27
|
+
message: string;
|
|
28
|
+
httpCode: T;
|
|
29
|
+
constructor(message: string, httpCode: T);
|
|
22
30
|
}
|
|
23
|
-
export declare function
|
|
24
|
-
declare const
|
|
25
|
-
export declare class HttpNotFoundError extends HttpNotFoundError_base {
|
|
26
|
-
}
|
|
27
|
-
declare const HttpBadRequestError_base: HttpError<400>;
|
|
31
|
+
export declare function createHttpError<T extends number>(code: T, defaultMessage?: string): ClassType<HttpError<T>>;
|
|
32
|
+
declare const HttpBadRequestError_base: ClassType<HttpError<400>>;
|
|
28
33
|
export declare class HttpBadRequestError extends HttpBadRequestError_base {
|
|
29
34
|
}
|
|
30
|
-
declare const
|
|
35
|
+
declare const HttpUnauthorizedError_base: ClassType<HttpError<401>>;
|
|
36
|
+
export declare class HttpUnauthorizedError extends HttpUnauthorizedError_base {
|
|
37
|
+
}
|
|
38
|
+
declare const HttpAccessDeniedError_base: ClassType<HttpError<403>>;
|
|
31
39
|
export declare class HttpAccessDeniedError extends HttpAccessDeniedError_base {
|
|
32
40
|
}
|
|
41
|
+
declare const HttpNotFoundError_base: ClassType<HttpError<404>>;
|
|
42
|
+
export declare class HttpNotFoundError extends HttpNotFoundError_base {
|
|
43
|
+
}
|
|
44
|
+
declare const HttpMethodNotAllowedError_base: ClassType<HttpError<405>>;
|
|
45
|
+
export declare class HttpMethodNotAllowedError extends HttpMethodNotAllowedError_base {
|
|
46
|
+
}
|
|
47
|
+
declare const HttpNotAcceptableError_base: ClassType<HttpError<406>>;
|
|
48
|
+
export declare class HttpNotAcceptableError extends HttpNotAcceptableError_base {
|
|
49
|
+
}
|
|
50
|
+
declare const HttpTimeoutError_base: ClassType<HttpError<408>>;
|
|
51
|
+
export declare class HttpTimeoutError extends HttpTimeoutError_base {
|
|
52
|
+
}
|
|
53
|
+
declare const HttpConflictError_base: ClassType<HttpError<409>>;
|
|
54
|
+
export declare class HttpConflictError extends HttpConflictError_base {
|
|
55
|
+
}
|
|
56
|
+
declare const HttpGoneError_base: ClassType<HttpError<410>>;
|
|
57
|
+
export declare class HttpGoneError extends HttpGoneError_base {
|
|
58
|
+
}
|
|
59
|
+
declare const HttpTooManyRequestsError_base: ClassType<HttpError<429>>;
|
|
60
|
+
export declare class HttpTooManyRequestsError extends HttpTooManyRequestsError_base {
|
|
61
|
+
}
|
|
62
|
+
declare const HttpInternalServerError_base: ClassType<HttpError<500>>;
|
|
63
|
+
export declare class HttpInternalServerError extends HttpInternalServerError_base {
|
|
64
|
+
}
|
|
65
|
+
declare const HttpNotImplementedError_base: ClassType<HttpError<501>>;
|
|
66
|
+
export declare class HttpNotImplementedError extends HttpNotImplementedError_base {
|
|
67
|
+
}
|
|
33
68
|
export declare class HttpWorkflowEvent {
|
|
34
69
|
injectorContext: InjectorContext;
|
|
35
70
|
request: HttpRequest;
|
|
36
71
|
response: HttpResponse;
|
|
37
|
-
|
|
72
|
+
propagationStopped: boolean;
|
|
38
73
|
stopPropagation(): void;
|
|
39
|
-
|
|
74
|
+
isPropagationStopped(): boolean;
|
|
40
75
|
nextState?: any;
|
|
41
76
|
nextStateEvent?: any;
|
|
42
77
|
clearNext(): void;
|
|
@@ -44,6 +79,9 @@ export declare class HttpWorkflowEvent {
|
|
|
44
79
|
* @see WorkflowNextEvent.next
|
|
45
80
|
*/
|
|
46
81
|
next(nextState: string, event?: any): void;
|
|
82
|
+
/**
|
|
83
|
+
* Whether already a next workflow state has been scheduled.
|
|
84
|
+
*/
|
|
47
85
|
hasNext(): boolean;
|
|
48
86
|
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse);
|
|
49
87
|
get url(): string;
|
|
@@ -62,6 +100,7 @@ export declare class HttpWorkflowEventWithRoute extends HttpWorkflowEvent {
|
|
|
62
100
|
route: RouteConfig;
|
|
63
101
|
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig);
|
|
64
102
|
send(response: any): void;
|
|
103
|
+
accessDenied(error?: Error): void;
|
|
65
104
|
}
|
|
66
105
|
export declare class HttpRouteEvent extends HttpWorkflowEvent {
|
|
67
106
|
injectorContext: InjectorContext;
|
|
@@ -81,31 +120,32 @@ export declare class HttpAuthEvent extends HttpWorkflowEventWithRoute {
|
|
|
81
120
|
parameterResolver: RouteParameterResolverForInjector;
|
|
82
121
|
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig, parameterResolver: RouteParameterResolverForInjector);
|
|
83
122
|
success(): void;
|
|
84
|
-
accessDenied(): void;
|
|
85
123
|
}
|
|
86
124
|
export declare class HttpAccessDeniedEvent extends HttpWorkflowEvent {
|
|
87
125
|
injectorContext: InjectorContext;
|
|
88
126
|
request: HttpRequest;
|
|
89
127
|
response: HttpResponse;
|
|
90
128
|
route: RouteConfig;
|
|
91
|
-
|
|
129
|
+
error?: Error | undefined;
|
|
130
|
+
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig, error?: Error | undefined);
|
|
92
131
|
}
|
|
93
|
-
export declare class HttpResolveParametersEvent extends
|
|
132
|
+
export declare class HttpResolveParametersEvent extends HttpWorkflowEventWithRoute {
|
|
94
133
|
injectorContext: InjectorContext;
|
|
95
134
|
request: HttpRequest;
|
|
96
135
|
response: HttpResponse;
|
|
97
136
|
parameterResolver: RouteParameterResolverForInjector;
|
|
98
137
|
route: RouteConfig;
|
|
99
|
-
parameters:
|
|
138
|
+
parameters: HttpRequestPositionedParameters;
|
|
100
139
|
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, parameterResolver: RouteParameterResolverForInjector, route: RouteConfig);
|
|
140
|
+
accessDenied(): void;
|
|
101
141
|
}
|
|
102
|
-
export declare class HttpControllerEvent extends
|
|
142
|
+
export declare class HttpControllerEvent extends HttpWorkflowEventWithRoute {
|
|
103
143
|
injectorContext: InjectorContext;
|
|
104
144
|
request: HttpRequest;
|
|
105
145
|
response: HttpResponse;
|
|
106
|
-
parameters:
|
|
146
|
+
parameters: HttpRequestPositionedParameters;
|
|
107
147
|
route: RouteConfig;
|
|
108
|
-
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, parameters:
|
|
148
|
+
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, parameters: HttpRequestPositionedParameters | undefined, route: RouteConfig);
|
|
109
149
|
}
|
|
110
150
|
export declare class HttpResponseEvent extends WorkflowEvent {
|
|
111
151
|
injectorContext: InjectorContext;
|
|
@@ -113,14 +153,22 @@ export declare class HttpResponseEvent extends WorkflowEvent {
|
|
|
113
153
|
response: HttpResponse;
|
|
114
154
|
result: any;
|
|
115
155
|
route?: RouteConfig | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* The time it took to call the controller action in milliseconds.
|
|
158
|
+
*/
|
|
159
|
+
controllerActionTime: number;
|
|
116
160
|
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, result: any, route?: RouteConfig | undefined);
|
|
117
161
|
}
|
|
118
|
-
export declare class HttpControllerErrorEvent extends
|
|
162
|
+
export declare class HttpControllerErrorEvent extends HttpWorkflowEventWithRoute {
|
|
119
163
|
injectorContext: InjectorContext;
|
|
120
164
|
request: HttpRequest;
|
|
121
165
|
response: HttpResponse;
|
|
122
166
|
route: RouteConfig;
|
|
123
167
|
error: Error;
|
|
168
|
+
/**
|
|
169
|
+
* The time it took to call the controller action in milliseconds.
|
|
170
|
+
*/
|
|
171
|
+
controllerActionTime: number;
|
|
124
172
|
constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig, error: Error);
|
|
125
173
|
}
|
|
126
174
|
export declare const httpWorkflow: import("@deepkit/workflow").WorkflowDefinition<{
|
|
@@ -148,22 +196,67 @@ export declare const httpWorkflow: import("@deepkit/workflow").WorkflowDefinitio
|
|
|
148
196
|
parametersFailed: typeof HttpControllerErrorEvent;
|
|
149
197
|
response: typeof HttpResponseEvent;
|
|
150
198
|
}>;
|
|
151
|
-
export declare class
|
|
199
|
+
export declare class BaseResponse {
|
|
200
|
+
_statusCode?: number | undefined;
|
|
201
|
+
_headers: OutgoingHttpHeaders;
|
|
202
|
+
autoSerializing: boolean;
|
|
203
|
+
constructor(_statusCode?: number | undefined, _headers?: OutgoingHttpHeaders);
|
|
204
|
+
status(code: number): this;
|
|
205
|
+
/**
|
|
206
|
+
* Per default a JSONResponse is serialized using the return type specified at the route.
|
|
207
|
+
* This disables that behaviour so that JSON.stringify is run on the result directly.
|
|
208
|
+
*/
|
|
209
|
+
disableAutoSerializing(): this;
|
|
210
|
+
header(name: string, value: string | number): this;
|
|
211
|
+
headers(headers: OutgoingHttpHeaders): this;
|
|
212
|
+
contentType(type: string): this;
|
|
213
|
+
}
|
|
214
|
+
export declare class Response extends BaseResponse {
|
|
215
|
+
content: string | Uint8Array;
|
|
216
|
+
constructor(content: string | Uint8Array, contentType: string, statusCode?: number);
|
|
217
|
+
}
|
|
218
|
+
export declare class HtmlResponse extends BaseResponse {
|
|
152
219
|
html: string;
|
|
153
|
-
statusCode?: number
|
|
154
|
-
constructor(html: string, statusCode?: number | undefined);
|
|
220
|
+
constructor(html: string, statusCode?: number);
|
|
155
221
|
}
|
|
156
|
-
export declare class JSONResponse {
|
|
222
|
+
export declare class JSONResponse extends BaseResponse {
|
|
157
223
|
json: any;
|
|
158
|
-
statusCode?: number
|
|
159
|
-
|
|
224
|
+
constructor(json: any, statusCode?: number);
|
|
225
|
+
}
|
|
226
|
+
export type SupportedHttpResult = undefined | null | number | string | Response | JSONResponse | HtmlResponse | HttpResponse | ServerResponse | stream.Readable | Redirect | Uint8Array | Error;
|
|
227
|
+
export interface HttpResultFormatterContext {
|
|
228
|
+
request: HttpRequest;
|
|
229
|
+
response: HttpResponse;
|
|
230
|
+
route?: RouteConfig;
|
|
231
|
+
}
|
|
232
|
+
export declare class HttpResultFormatter {
|
|
233
|
+
protected router: HttpRouter;
|
|
234
|
+
protected jsonContentType: string;
|
|
235
|
+
protected htmlContentType: string;
|
|
236
|
+
constructor(router: HttpRouter);
|
|
237
|
+
protected setContentTypeIfNotSetAlready(response: HttpResponse, contentType: string): void;
|
|
238
|
+
handleError(error: Error, context: HttpResultFormatterContext): void;
|
|
239
|
+
handleUndefined(result: undefined | null, context: HttpResultFormatterContext): void;
|
|
240
|
+
handleRedirect(result: Redirect, context: HttpResultFormatterContext): void;
|
|
241
|
+
handleUnknown(result: any, context: HttpResultFormatterContext): void;
|
|
242
|
+
handleHtmlResponse(result: HtmlResponse, context: HttpResultFormatterContext): void;
|
|
243
|
+
handleGenericResponse(result: Response, context: HttpResultFormatterContext): void;
|
|
244
|
+
handleJSONResponse(result: JSONResponse, context: HttpResultFormatterContext): void;
|
|
245
|
+
handleTypeEntity<T>(classType: ClassType<T>, instance: T, context: HttpResultFormatterContext, route?: RouteConfig): void;
|
|
246
|
+
handleType<T>(type: Type, instance: T, context: HttpResultFormatterContext, route?: RouteConfig): void;
|
|
247
|
+
handleStream(stream: stream.Readable, context: HttpResultFormatterContext): void;
|
|
248
|
+
handleBinary(result: Uint8Array, context: HttpResultFormatterContext): void;
|
|
249
|
+
handleResponse(context: HttpResultFormatterContext): void;
|
|
250
|
+
handle(result: SupportedHttpResult, context: HttpResultFormatterContext): void;
|
|
160
251
|
}
|
|
161
252
|
export declare class HttpListener {
|
|
162
|
-
protected router:
|
|
163
|
-
protected logger:
|
|
164
|
-
|
|
253
|
+
protected router: HttpRouter;
|
|
254
|
+
protected logger: LoggerInterface;
|
|
255
|
+
protected resultFormatter: HttpResultFormatter;
|
|
256
|
+
protected stopwatch?: Stopwatch | undefined;
|
|
257
|
+
constructor(router: HttpRouter, logger: LoggerInterface, resultFormatter: HttpResultFormatter, stopwatch?: Stopwatch | undefined);
|
|
165
258
|
onRequest(event: typeof httpWorkflow.onRequest.event): void;
|
|
166
|
-
onRoute(event: typeof httpWorkflow.onRoute.event): void
|
|
259
|
+
onRoute(event: typeof httpWorkflow.onRoute.event): Promise<void>;
|
|
167
260
|
onRouteForward(event: typeof httpWorkflow.onRoute.event): void;
|
|
168
261
|
routeNotFound(event: typeof httpWorkflow.onRouteNotFound.event): Promise<void>;
|
|
169
262
|
onAuth(event: typeof httpWorkflow.onAuth.event): void;
|
|
@@ -172,6 +265,12 @@ export declare class HttpListener {
|
|
|
172
265
|
onController(event: typeof httpWorkflow.onController.event): Promise<void>;
|
|
173
266
|
onParametersFailed(event: typeof httpWorkflow.onParametersFailed.event): void;
|
|
174
267
|
onControllerError(event: typeof httpWorkflow.onControllerError.event): void;
|
|
268
|
+
/**
|
|
269
|
+
* This happens before the result is sent.
|
|
270
|
+
*/
|
|
271
|
+
onResultSerialization(event: typeof httpWorkflow.onResponse.event): Promise<void>;
|
|
175
272
|
onResponse(event: typeof httpWorkflow.onResponse.event): Promise<void>;
|
|
176
273
|
}
|
|
177
274
|
export {};
|
|
275
|
+
export declare type __ΩSupportedHttpResult = any[];
|
|
276
|
+
export declare type __ΩHttpResultFormatterContext = any[];
|