@wabot-dev/framework 0.5.4 → 0.5.6
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/dist/src/addon/auth/api-key/@apiKeyGuard.js +1 -1
- package/dist/src/addon/auth/jwt/@jwtGuard.js +1 -1
- package/dist/src/core/validation/core/validateModel.js +2 -2
- package/dist/src/feature/rest-controller/RestRequest.js +0 -10
- package/dist/src/feature/rest-controller/runRestControllers.js +16 -10
- package/dist/src/index.d.ts +1 -2
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
|
7
7
|
import '../../../feature/express/ExpressProvider.js';
|
|
8
8
|
import 'express';
|
|
9
9
|
import 'path';
|
|
10
|
-
import '
|
|
10
|
+
import 'http';
|
|
11
11
|
import { ApiKeyGuardMiddleware } from './ApiKeyGuardMiddleware.js';
|
|
12
12
|
|
|
13
13
|
function apiKeyGuard() {
|
|
@@ -7,7 +7,7 @@ import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
|
7
7
|
import '../../../feature/express/ExpressProvider.js';
|
|
8
8
|
import 'express';
|
|
9
9
|
import 'path';
|
|
10
|
-
import '
|
|
10
|
+
import 'http';
|
|
11
11
|
import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
|
|
12
12
|
|
|
13
13
|
function jwtGuard() {
|
|
@@ -33,7 +33,7 @@ function validateModel(value, info) {
|
|
|
33
33
|
propertyErrors = [];
|
|
34
34
|
propertiesErrors[propertyName] = propertyErrors;
|
|
35
35
|
}
|
|
36
|
-
propertyErrors.push(propertyValidatorResult.error
|
|
36
|
+
propertyErrors.push(propertyValidatorResult.error);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
currentPropValue = propertyValidatorResult.value;
|
|
@@ -56,7 +56,7 @@ function validateModel(value, info) {
|
|
|
56
56
|
propertyErrors = [];
|
|
57
57
|
propertiesErrors[propertyName] = propertyErrors;
|
|
58
58
|
}
|
|
59
|
-
propertyErrors.push(propertyValidatorResult.error
|
|
59
|
+
propertyErrors.push(propertyValidatorResult.error);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import '../../core/injection/index.js';
|
|
3
|
-
import '../../core/validation/metadata/ValidationMetadataStore.js';
|
|
4
|
-
import { isRecord } from '../../core/validation/validators/is-record/@isRecord.js';
|
|
5
|
-
|
|
6
1
|
class RestRequest {
|
|
7
|
-
headers;
|
|
8
2
|
}
|
|
9
|
-
__decorate([
|
|
10
|
-
isRecord('string', 'string'),
|
|
11
|
-
__metadata("design:type", Object)
|
|
12
|
-
], RestRequest.prototype, "headers", void 0);
|
|
13
3
|
|
|
14
4
|
export { RestRequest };
|
|
@@ -10,6 +10,7 @@ import path__default from 'path';
|
|
|
10
10
|
import { EXPRESS_REQ, EXPRESS_RES } from './injection-tokens.js';
|
|
11
11
|
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
12
12
|
import { RestRequest } from './RestRequest.js';
|
|
13
|
+
import { IncomingMessage } from 'http';
|
|
13
14
|
|
|
14
15
|
function buildRequest(req) {
|
|
15
16
|
return Object.assign({}, req.body, req.query, req.params);
|
|
@@ -51,18 +52,23 @@ function runRestControllers(controllers) {
|
|
|
51
52
|
}
|
|
52
53
|
if (endPoint.paramsTypes.length === 1) {
|
|
53
54
|
const paramType = endPoint.paramsTypes[0];
|
|
54
|
-
if (
|
|
55
|
-
|
|
55
|
+
if (paramType === IncomingMessage) {
|
|
56
|
+
endPointArgs.push(req);
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
else {
|
|
59
|
+
if (typeof paramType !== 'function') {
|
|
60
|
+
throw new Error(`invalid rest controller endpoint parameter type`);
|
|
61
|
+
}
|
|
62
|
+
const paramInfo = validationMetadataStore.getModelValidatorsInfo(paramType);
|
|
63
|
+
const validableReq = paramInfo.modelHierarchy.includes(RestRequest)
|
|
64
|
+
? req
|
|
65
|
+
: buildRequest(req);
|
|
66
|
+
const { value, error } = validateModel(validableReq, paramInfo);
|
|
67
|
+
if (error) {
|
|
68
|
+
throw new CustomError({ httpCode: 400, message: error.description, info: error });
|
|
69
|
+
}
|
|
70
|
+
endPointArgs.push(value);
|
|
64
71
|
}
|
|
65
|
-
endPointArgs.push(value);
|
|
66
72
|
}
|
|
67
73
|
const response = await controllerInstance[endPoint.functionName].apply(controllerInstance, endPointArgs);
|
|
68
74
|
res.status(200).json(response ?? null);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -219,7 +219,7 @@ interface IValidationError {
|
|
|
219
219
|
}
|
|
220
220
|
interface IModelValidationError extends IValidationError {
|
|
221
221
|
properties: {
|
|
222
|
-
[key: string]:
|
|
222
|
+
[key: string]: IValidationError[];
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
interface IArrayValidationError extends IValidationError {
|
|
@@ -1221,7 +1221,6 @@ declare const EXPRESS_REQ = "EXPRESS_REQ";
|
|
|
1221
1221
|
declare const EXPRESS_RES = "EXPRESS_RES";
|
|
1222
1222
|
|
|
1223
1223
|
declare class RestRequest {
|
|
1224
|
-
headers?: Record<string, string>;
|
|
1225
1224
|
}
|
|
1226
1225
|
|
|
1227
1226
|
declare class SocketServerConfig {
|