@mini2/core 1.4.10-beta.9 → 1.4.11
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/app.d.ts +4 -7
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +16 -17
- package/dist/app.js.map +1 -1
- package/dist/container.d.ts +2 -15
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +2 -38
- package/dist/container.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -10
- package/dist/index.js.map +1 -1
- package/dist/interfaces/app.interface.d.ts +1 -6
- package/dist/interfaces/app.interface.d.ts.map +1 -1
- package/dist/interfaces/authenticated.interface.d.ts.map +1 -0
- package/dist/interfaces/authenticated.interface.js.map +1 -0
- package/dist/interfaces/queue.interface.d.ts +6 -0
- package/dist/interfaces/queue.interface.d.ts.map +1 -0
- package/dist/{notations/controller/rest.types.js → interfaces/queue.interface.js} +1 -1
- package/dist/interfaces/queue.interface.js.map +1 -0
- package/dist/interfaces/repository.interface.d.ts +9 -0
- package/dist/interfaces/repository.interface.d.ts.map +1 -0
- package/dist/interfaces/repository.interface.js +3 -0
- package/dist/interfaces/repository.interface.js.map +1 -0
- package/dist/jest.config.d.ts.map +1 -1
- package/dist/jest.config.js +0 -1
- package/dist/jest.config.js.map +1 -1
- package/dist/middlewares/authenticated.middleware.d.ts.map +1 -0
- package/dist/{notations/controller/middlewares → middlewares}/authenticated.middleware.js +3 -8
- package/dist/middlewares/authenticated.middleware.js.map +1 -0
- package/dist/middlewares/authorized.middleware.d.ts +12 -0
- package/dist/middlewares/authorized.middleware.d.ts.map +1 -0
- package/dist/{notations/controller/middlewares → middlewares}/authorized.middleware.js +6 -1
- package/dist/middlewares/authorized.middleware.js.map +1 -0
- package/dist/{notations/controller/middlewares → middlewares}/validation.middleware.d.ts +3 -1
- package/dist/middlewares/validation.middleware.d.ts.map +1 -0
- package/dist/{notations/controller/middlewares → middlewares}/validation.middleware.js +25 -15
- package/dist/middlewares/validation.middleware.js.map +1 -0
- package/dist/{notations/controller/index.d.ts → rest.d.ts} +41 -3
- package/dist/rest.d.ts.map +1 -0
- package/dist/{notations/controller/index.js → rest.js} +12 -7
- package/dist/rest.js.map +1 -0
- package/dist/swagger.d.ts.map +1 -1
- package/dist/swagger.js +4 -5
- package/dist/swagger.js.map +1 -1
- package/package.json +1 -3
- package/dist/loader.d.ts +0 -12
- package/dist/loader.d.ts.map +0 -1
- package/dist/loader.js +0 -72
- package/dist/loader.js.map +0 -1
- package/dist/notations/controller/index.d.ts.map +0 -1
- package/dist/notations/controller/index.js.map +0 -1
- package/dist/notations/controller/interfaces/authenticated.interface.d.ts.map +0 -1
- package/dist/notations/controller/interfaces/authenticated.interface.js.map +0 -1
- package/dist/notations/controller/middlewares/authenticated.middleware.d.ts.map +0 -1
- package/dist/notations/controller/middlewares/authenticated.middleware.js.map +0 -1
- package/dist/notations/controller/middlewares/authorized.middleware.d.ts +0 -7
- package/dist/notations/controller/middlewares/authorized.middleware.d.ts.map +0 -1
- package/dist/notations/controller/middlewares/authorized.middleware.js.map +0 -1
- package/dist/notations/controller/middlewares/validation.middleware.d.ts.map +0 -1
- package/dist/notations/controller/middlewares/validation.middleware.js.map +0 -1
- package/dist/notations/controller/rest.types.d.ts +0 -42
- package/dist/notations/controller/rest.types.d.ts.map +0 -1
- package/dist/notations/controller/rest.types.js.map +0 -1
- package/dist/notations/index.d.ts +0 -3
- package/dist/notations/index.d.ts.map +0 -1
- package/dist/notations/index.js +0 -19
- package/dist/notations/index.js.map +0 -1
- /package/dist/{notations/controller/interfaces → interfaces}/authenticated.interface.d.ts +0 -0
- /package/dist/{notations/controller/interfaces → interfaces}/authenticated.interface.js +0 -0
- /package/dist/{notations/controller/middlewares → middlewares}/authenticated.middleware.d.ts +0 -0
package/dist/app.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import express, { Express } from 'express';
|
|
2
|
-
import { Server } from 'http';
|
|
3
2
|
import { IApp } from './interfaces/app.interface';
|
|
4
3
|
import { IConfig } from './interfaces/config.interface';
|
|
5
|
-
import { IController } from './
|
|
4
|
+
import { IController } from './rest';
|
|
6
5
|
import { Container } from 'inversify';
|
|
7
|
-
import { LoadInjectablesOptions } from './loader';
|
|
8
6
|
declare class App implements IApp {
|
|
7
|
+
private controllers;
|
|
9
8
|
app: Express;
|
|
10
9
|
container: Container;
|
|
11
|
-
controllers: IController[];
|
|
12
|
-
|
|
13
|
-
constructor();
|
|
14
|
-
init(config: IConfig, loadInjectablesOptions?: LoadInjectablesOptions): Promise<void>;
|
|
10
|
+
constructor(controllers: IController[]);
|
|
11
|
+
init(config: IConfig): Promise<void>;
|
|
15
12
|
getApp(): express.Express;
|
|
16
13
|
afterInit(standartErrorHandler?: boolean): Promise<void>;
|
|
17
14
|
}
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAmC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAmC,MAAM,SAAS,CAAC;AAG5E,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAY,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,SAAS,EAA2B,MAAM,WAAW,CAAC;AAM/D,cACM,GAAI,YAAW,IAAI;IAIyB,OAAO,CAAC,WAAW;IAHpE,GAAG,EAAE,OAAO,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;gBAEoC,WAAW,EAAE,WAAW,EAAE;IAM7E,IAAI,CAAC,MAAM,EAAE,OAAO;IAyB1B,MAAM;IAMA,SAAS,CAAC,oBAAoB,GAAC,OAAc;CAuBnD;AAED,eAAe,GAAG,CAAC"}
|
package/dist/app.js
CHANGED
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
16
|
};
|
|
@@ -15,30 +18,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
18
|
const express_1 = __importDefault(require("express"));
|
|
16
19
|
const cors_1 = __importDefault(require("cors"));
|
|
17
20
|
const morgan_1 = __importDefault(require("morgan"));
|
|
18
|
-
const
|
|
21
|
+
const rest_1 = require("./rest");
|
|
19
22
|
const inversify_1 = require("inversify");
|
|
20
23
|
const swagger_1 = require("./swagger");
|
|
21
24
|
const types_1 = require("./types");
|
|
22
|
-
const container_1 = require("./container");
|
|
25
|
+
const container_1 = __importDefault(require("./container"));
|
|
23
26
|
const http_expection_1 = __importDefault(require("./expections/http.expection"));
|
|
24
|
-
const loader_1 = require("./loader");
|
|
25
27
|
let App = class App {
|
|
26
|
-
constructor() {
|
|
28
|
+
constructor(controllers) {
|
|
29
|
+
this.controllers = controllers;
|
|
27
30
|
this.app = (0, express_1.default)();
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
31
|
+
this.container = container_1.default;
|
|
32
|
+
console.log(this.controllers);
|
|
30
33
|
}
|
|
31
|
-
async init(config
|
|
32
|
-
if (loadInjectablesOptions?.autoload) {
|
|
33
|
-
(0, loader_1.loadInjectables)(loadInjectablesOptions);
|
|
34
|
-
(0, container_1.bindDiscovered)();
|
|
35
|
-
}
|
|
36
|
-
this.controllers = container_1.container.getAll(types_1.MINI_TYPES.IController);
|
|
34
|
+
async init(config) {
|
|
37
35
|
this.app.use(express_1.default.json());
|
|
38
36
|
this.app.use(express_1.default.urlencoded({ extended: true }));
|
|
39
37
|
this.app.use((0, cors_1.default)());
|
|
40
38
|
this.app.use((0, morgan_1.default)('dev'));
|
|
41
|
-
this.
|
|
39
|
+
this.app.listen(config.port, () => {
|
|
42
40
|
console.log(`Server is running on port ${config.port}`);
|
|
43
41
|
});
|
|
44
42
|
const swaggerIntegration = new swagger_1.SwaggerIntegration({
|
|
@@ -56,7 +54,7 @@ let App = class App {
|
|
|
56
54
|
});
|
|
57
55
|
swaggerIntegration.generateSwaggerSpec(this.controllers);
|
|
58
56
|
swaggerIntegration.setupSwagger(this.app);
|
|
59
|
-
(0,
|
|
57
|
+
(0, rest_1.buildApp)(this.app, this.controllers);
|
|
60
58
|
}
|
|
61
59
|
getApp() {
|
|
62
60
|
return this.app;
|
|
@@ -68,10 +66,10 @@ let App = class App {
|
|
|
68
66
|
res.status(error.code).json(error.messageJson);
|
|
69
67
|
}
|
|
70
68
|
else {
|
|
71
|
-
console.error(
|
|
69
|
+
console.error("Unexpected error:", error);
|
|
72
70
|
res.status(500).json({
|
|
73
71
|
errorId: 1,
|
|
74
|
-
message:
|
|
72
|
+
message: "Some error happen",
|
|
75
73
|
});
|
|
76
74
|
}
|
|
77
75
|
});
|
|
@@ -80,7 +78,8 @@ let App = class App {
|
|
|
80
78
|
};
|
|
81
79
|
App = __decorate([
|
|
82
80
|
(0, inversify_1.injectable)(),
|
|
83
|
-
|
|
81
|
+
__param(0, (0, inversify_1.multiInject)(types_1.MINI_TYPES.IController)),
|
|
82
|
+
__metadata("design:paramtypes", [Array])
|
|
84
83
|
], App);
|
|
85
84
|
exports.default = App;
|
|
86
85
|
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAA4E;AAC5E,gDAAwB;AACxB,oDAA4B;AAG5B,iCAA+C;AAC/C,yCAA+D;AAC/D,uCAA+C;AAC/C,mCAAqC;AACrC,4DAAoC;AACpC,iFAAwD;AAExD,IACM,GAAG,GADT,MACM,GAAG;IAIR,YAAyD,WAA0B;QAA1B,gBAAW,GAAX,WAAW,CAAe;QAClF,IAAI,CAAC,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,mBAAS,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAe;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAA,gBAAM,EAAC,KAAK,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACjC,OAAO,CAAC,GAAG,CAAC,6BAA6B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QACH,MAAM,kBAAkB,GAAG,IAAI,4BAAkB,CAAC;YACjD,KAAK,EAAE,MAAM,CAAC,eAAe;YAC7B,WAAW,EAAE,yBAAy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AAW,CAAC,CAAA;;GAJ3C,GAAG,CAgER;AAED,kBAAe,GAAG,CAAC"}
|
package/dist/container.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import type { ServiceIdentifier } from 'inversify';
|
|
2
1
|
import { Container } from 'inversify';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type DiscoveredBinding = {
|
|
6
|
-
token: ServiceIdentifier<any>;
|
|
7
|
-
target: new (...args: any[]) => any;
|
|
8
|
-
scope: Scope;
|
|
9
|
-
};
|
|
10
|
-
export declare function AutoBind(token: DiscoveredBinding['token'], opts?: {
|
|
11
|
-
scope?: Scope;
|
|
12
|
-
}): (target: any) => void;
|
|
13
|
-
export declare const bindDiscovered: () => {
|
|
14
|
-
count: number;
|
|
15
|
-
};
|
|
16
|
-
export {};
|
|
2
|
+
declare const container: Container;
|
|
3
|
+
export default container;
|
|
17
4
|
//# sourceMappingURL=container.d.ts.map
|
package/dist/container.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,QAAA,MAAM,SAAS,WAAkB,CAAC;AAGlC,eAAe,SAAS,CAAC"}
|
package/dist/container.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bindDiscovered = exports.container = void 0;
|
|
4
|
-
exports.AutoBind = AutoBind;
|
|
5
3
|
const inversify_1 = require("inversify");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
autobind: true,
|
|
9
|
-
});
|
|
10
|
-
const DISCOVERY_KEY = Symbol.for('DI_DISCOVERY_REGISTRY');
|
|
11
|
-
// Global registry: import edilen her dosyada tek bir listeye yazabilelim
|
|
12
|
-
function getRegistry() {
|
|
13
|
-
const g = globalThis;
|
|
14
|
-
if (!g[DISCOVERY_KEY])
|
|
15
|
-
g[DISCOVERY_KEY] = [];
|
|
16
|
-
return g[DISCOVERY_KEY];
|
|
17
|
-
}
|
|
18
|
-
function AutoBind(token, opts) {
|
|
19
|
-
const scope = opts?.scope ?? 'Singleton';
|
|
20
|
-
return function (target) {
|
|
21
|
-
const reg = getRegistry();
|
|
22
|
-
reg.push({ token, target, scope });
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const bindDiscovered = () => {
|
|
26
|
-
const reg = getRegistry();
|
|
27
|
-
for (const b of reg) {
|
|
28
|
-
// aynı token birden fazla kez gelirse tekrar bind etmeyelim
|
|
29
|
-
if (exports.container.isBound(b.token))
|
|
30
|
-
continue;
|
|
31
|
-
const binding = exports.container.bind(b.token).to(b.target);
|
|
32
|
-
if (b.scope === 'Singleton')
|
|
33
|
-
binding.inSingletonScope();
|
|
34
|
-
if (b.scope === 'Transient')
|
|
35
|
-
binding.inTransientScope();
|
|
36
|
-
if (b.scope === 'Request')
|
|
37
|
-
binding.inRequestScope();
|
|
38
|
-
}
|
|
39
|
-
return { count: reg.length };
|
|
40
|
-
};
|
|
41
|
-
exports.bindDiscovered = bindDiscovered;
|
|
4
|
+
const container = new inversify_1.Container();
|
|
5
|
+
exports.default = container;
|
|
42
6
|
//# sourceMappingURL=container.js.map
|
package/dist/container.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../container.ts"],"names":[],"mappings":";;AAAA,yCAAsC;AAEtC,MAAM,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;AAGlC,kBAAe,SAAS,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import App from './app';
|
|
2
|
-
import
|
|
2
|
+
import container from './container';
|
|
3
3
|
import { IApp } from './interfaces/app.interface';
|
|
4
4
|
import { MINI_TYPES } from './types';
|
|
5
5
|
export * from 'inversify';
|
|
6
6
|
export { container };
|
|
7
|
-
export { AutoBind };
|
|
8
7
|
export { IApp };
|
|
9
8
|
export { App };
|
|
10
9
|
export { MINI_TYPES };
|
|
11
10
|
export * from './interfaces/app.interface';
|
|
12
|
-
export * from './
|
|
11
|
+
export * from './interfaces/authenticated.interface';
|
|
13
12
|
export * from './interfaces/config.interface';
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
13
|
+
export * from './interfaces/queue.interface';
|
|
14
|
+
export * from './interfaces/repository.interface';
|
|
15
|
+
export * from './middlewares/authenticated.middleware';
|
|
16
|
+
export * from './middlewares/authorized.middleware';
|
|
17
|
+
export * from './middlewares/validation.middleware';
|
|
17
18
|
export * from './utils/array-unify';
|
|
18
19
|
export * from './utils/math';
|
|
19
20
|
export * from './expections/http.expection';
|
|
20
21
|
export { default as HttpException } from './expections/http.expection';
|
|
21
22
|
export * from './types';
|
|
22
23
|
export * from './response-builder';
|
|
23
|
-
export * from './
|
|
24
|
+
export * from './rest';
|
|
24
25
|
export * from './swagger';
|
|
25
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIrC,cAAe,WAAW,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,OAAO,EAAE,GAAG,EAAE,CAAC;AACf,OAAO,EAAE,UAAU,EAAE,CAAC;AAGtB,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAGlD,cAAc,wCAAwC,CAAC;AACvD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AAGpD,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAG7B,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAGvE,cAAc,SAAS,CAAC;AAGxB,cAAc,oBAAoB,CAAC;AAGnC,cAAc,QAAQ,CAAC;AAGvB,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.HttpException = exports.MINI_TYPES = exports.App = exports.
|
|
20
|
+
exports.HttpException = exports.MINI_TYPES = exports.App = exports.container = void 0;
|
|
21
21
|
const app_1 = __importDefault(require("./app"));
|
|
22
22
|
exports.App = app_1.default;
|
|
23
|
-
const container_1 = require("./container");
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(exports, "AutoBind", { enumerable: true, get: function () { return container_1.AutoBind; } });
|
|
23
|
+
const container_1 = __importDefault(require("./container"));
|
|
24
|
+
exports.container = container_1.default;
|
|
26
25
|
const types_1 = require("./types");
|
|
27
26
|
Object.defineProperty(exports, "MINI_TYPES", { enumerable: true, get: function () { return types_1.MINI_TYPES; } });
|
|
28
27
|
// Main Application class
|
|
@@ -30,12 +29,14 @@ Object.defineProperty(exports, "MINI_TYPES", { enumerable: true, get: function (
|
|
|
30
29
|
__exportStar(require("inversify"), exports);
|
|
31
30
|
// Interfaces
|
|
32
31
|
__exportStar(require("./interfaces/app.interface"), exports);
|
|
33
|
-
__exportStar(require("./
|
|
32
|
+
__exportStar(require("./interfaces/authenticated.interface"), exports);
|
|
34
33
|
__exportStar(require("./interfaces/config.interface"), exports);
|
|
34
|
+
__exportStar(require("./interfaces/queue.interface"), exports);
|
|
35
|
+
__exportStar(require("./interfaces/repository.interface"), exports);
|
|
35
36
|
// Middlewares
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./
|
|
38
|
-
__exportStar(require("./
|
|
37
|
+
__exportStar(require("./middlewares/authenticated.middleware"), exports);
|
|
38
|
+
__exportStar(require("./middlewares/authorized.middleware"), exports);
|
|
39
|
+
__exportStar(require("./middlewares/validation.middleware"), exports);
|
|
39
40
|
// Utils
|
|
40
41
|
__exportStar(require("./utils/array-unify"), exports);
|
|
41
42
|
__exportStar(require("./utils/math"), exports);
|
|
@@ -48,8 +49,8 @@ __exportStar(require("./types"), exports);
|
|
|
48
49
|
// Response builder
|
|
49
50
|
__exportStar(require("./response-builder"), exports);
|
|
50
51
|
// REST utilities
|
|
51
|
-
__exportStar(require("./
|
|
52
|
+
__exportStar(require("./rest"), exports);
|
|
52
53
|
// Swagger integration
|
|
53
54
|
__exportStar(require("./swagger"), exports);
|
|
54
|
-
container_1.
|
|
55
|
+
container_1.default.bind(types_1.MINI_TYPES.IApp).to(app_1.default).inSingletonScope();
|
|
55
56
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AAUf,cAVF,aAAG,CAUE;AATZ,4DAAoC;AAO3B,oBAPF,mBAAS,CAOE;AALlB,mCAAqC;AAQ5B,2FARA,kBAAU,OAQA;AAPnB,yBAAyB;AAEzB,mCAAmC;AACnC,4CAA2B;AAM3B,aAAa;AACb,6DAA2C;AAC3C,uEAAqD;AACrD,gEAA8C;AAC9C,+DAA6C;AAC7C,oEAAkD;AAElD,cAAc;AACd,yEAAuD;AACvD,sEAAoD;AACpD,sEAAoD;AAEpD,QAAQ;AACR,sDAAoC;AACpC,+CAA6B;AAE7B,aAAa;AACb,8DAA4C;AAC5C,8DAAuE;AAA9D,gIAAA,OAAO,OAAiB;AAEjC,QAAQ;AACR,0CAAwB;AAExB,mBAAmB;AACnB,qDAAmC;AAEnC,iBAAiB;AACjB,yCAAuB;AAEvB,sBAAsB;AACtB,4CAA0B;AAE1B,mBAAS,CAAC,IAAI,CAAO,kBAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,aAAG,CAAC,CAAC,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { IController } from '../notations';
|
|
2
1
|
import { IConfig } from './config.interface';
|
|
3
2
|
import { Express } from 'express';
|
|
4
|
-
import { Server } from 'http';
|
|
5
|
-
import { LoadInjectablesOptions } from '../loader';
|
|
6
3
|
export interface IApp {
|
|
7
|
-
|
|
8
|
-
controllers: IController[];
|
|
9
|
-
init(config: IConfig, loadInjectablesOptions?: LoadInjectablesOptions): Promise<void>;
|
|
4
|
+
init(config: IConfig): Promise<void>;
|
|
10
5
|
afterInit(standartErrorHandler?: boolean): Promise<void>;
|
|
11
6
|
getApp(): Express;
|
|
12
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.interface.d.ts","sourceRoot":"","sources":["../../interfaces/app.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"app.interface.d.ts","sourceRoot":"","sources":["../../interfaces/app.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,MAAM,WAAW,IAAI;IACpB,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,SAAS,CAAC,oBAAoB,CAAC,EAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,IAAG,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticated.interface.d.ts","sourceRoot":"","sources":["../../interfaces/authenticated.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,WAAW,qBAAsB,SAAQ,OAAO;IACrD,aAAa,EAAE,OAAO,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticated.interface.js","sourceRoot":"","sources":["../../interfaces/authenticated.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.interface.d.ts","sourceRoot":"","sources":["../../interfaces/queue.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACnB,UAAU,EAAC,GAAG,CAAC;IACf,EAAE,EAAC,CAAC,SAAS,EAAC,MAAM,EAAE,KAAK,EAAC,GAAG,KAAK,IAAI,CAAC;IACzC,IAAI,EAAC,CAAC,SAAS,EAAC,MAAM,EAAE,KAAK,EAAC,GAAG,KAAK,IAAI,CAAC;CAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.interface.js","sourceRoot":"","sources":["../../interfaces/queue.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface IRepository<IdentifierType, ModelType> {
|
|
2
|
+
findAll(): Promise<ModelType[]>;
|
|
3
|
+
findById(id: IdentifierType): Promise<ModelType | null>;
|
|
4
|
+
create(item: ModelType): Promise<ModelType>;
|
|
5
|
+
update(id: IdentifierType, item: Partial<ModelType>): Promise<ModelType>;
|
|
6
|
+
delete(id: IdentifierType): Promise<void>;
|
|
7
|
+
findPaginated(query: Partial<ModelType>, page: number, limit: number): Promise<ModelType[]>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=repository.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.interface.d.ts","sourceRoot":"","sources":["../../interfaces/repository.interface.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,WAAW,CAAC,cAAc,EAAE,SAAS;IACrD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5C,MAAM,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACzE,MAAM,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,aAAa,CACZ,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,EACzB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.interface.js","sourceRoot":"","sources":["../../interfaces/repository.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.config.d.ts","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"jest.config.d.ts","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,QAAA,MAAM,MAAM,EAAE,MAiBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/jest.config.js
CHANGED
package/dist/jest.config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";;AAEA,MAAM,MAAM,GAAW;
|
|
1
|
+
{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";;AAEA,MAAM,MAAM,GAAW;IACrB,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,MAAM;IACvB,KAAK,EAAE,CAAC,qBAAqB,CAAC;IAC9B,oBAAoB,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC;IACjD,SAAS,EAAE;QACT,aAAa,EAAE;YACb,SAAS;YACT;gBACE,QAAQ,EAAE,oBAAoB;gBAC9B,WAAW,EAAE,IAAI;gBACjB,eAAe,EAAE,KAAK;aACvB;SACF;KACF;IACD,kBAAkB,EAAE,CAAC,yBAAyB,CAAC;IAC/C,WAAW,EAAE,KAAK;CACnB,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticated.middleware.d.ts","sourceRoot":"","sources":["../../middlewares/authenticated.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,qBAAqB,EAC1B,MAAM,QAAQ,EACd,MAAM,YAAY,SAuBnB,CAAC"}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.authenticatedMiddleware = void 0;
|
|
4
|
-
const http_expection_1 = require("
|
|
4
|
+
const http_expection_1 = require("../expections/http.expection");
|
|
5
5
|
/** Header tabanlı auth kontrolü (throw’lu):
|
|
6
6
|
* - x-authenticated: "true" | "1" | "yes" → zorunlu
|
|
7
7
|
* - x-user-id: (opsiyonel)
|
|
8
8
|
* - x-user-permissions: "admin,editor" (opsiyonel, virgülle ayrılmış)
|
|
9
9
|
*/
|
|
10
10
|
const authenticatedMiddleware = (req, _res, next) => {
|
|
11
|
-
const isAuthHeader = String(req.headers['x-authenticated'] ?? '')
|
|
12
|
-
|
|
13
|
-
.toLowerCase();
|
|
14
|
-
const isAuthenticated = isAuthHeader === 'true' ||
|
|
15
|
-
isAuthHeader === '1' ||
|
|
16
|
-
isAuthHeader === 'yes' ||
|
|
17
|
-
isAuthHeader === 'y';
|
|
11
|
+
const isAuthHeader = String(req.headers['x-authenticated'] ?? '').trim().toLowerCase();
|
|
12
|
+
const isAuthenticated = isAuthHeader === 'true' || isAuthHeader === '1' || isAuthHeader === 'yes' || isAuthHeader === 'y';
|
|
18
13
|
if (!isAuthenticated) {
|
|
19
14
|
// 401 → throw (global error handler bunu 401’e map etmeli)
|
|
20
15
|
throw new http_expection_1.UnauthorizedException({ message: 'Unauthorized' });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticated.middleware.js","sourceRoot":"","sources":["../../middlewares/authenticated.middleware.ts"],"names":[],"mappings":";;;AACA,iEAAqE;AAGrE;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,CACrC,GAA0B,EAC1B,IAAc,EACd,IAAkB,EAClB,EAAE;IACF,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACvF,MAAM,eAAe,GACnB,YAAY,KAAK,MAAM,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,KAAK,KAAK,IAAI,YAAY,KAAK,GAAG,CAAC;IAEpG,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,2DAA2D;QAC3D,MAAM,IAAI,sCAAqB,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,MAAM,GAAI,GAAG,CAAC,OAAO,CAAC,WAAW,CAAY,IAAI,SAAS,CAAC;IACjE,MAAM,WAAW,GAAI,GAAG,CAAC,OAAO,CAAC,oBAAoB,CAAY,IAAI,EAAE,CAAC;IACxE,MAAM,WAAW,GAAG,WAAW;SAC5B,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnB,qCAAqC;IACrC,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC;IACxB,GAAW,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAEhD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AA1BW,QAAA,uBAAuB,2BA0BlC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
/** Header tabanlı yetkilendirme (throw’lu):
|
|
3
|
+
* - required: gerekli permission listesi
|
|
4
|
+
* - Mevcut izinler önce req.user.permissions’tan,
|
|
5
|
+
* yoksa x-user-permissions header’ından alınır.
|
|
6
|
+
*/
|
|
7
|
+
export declare const authorizedMiddleware: (required: string[]) => (req: Request & {
|
|
8
|
+
user?: {
|
|
9
|
+
permissions?: string[];
|
|
10
|
+
};
|
|
11
|
+
}, _res: Response, next: NextFunction) => void;
|
|
12
|
+
//# sourceMappingURL=authorized.middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorized.middleware.d.ts","sourceRoot":"","sources":["../../middlewares/authorized.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,MAAM,EAAE,MAEnD,KAAK,OAAO,GAAG;IAAE,IAAI,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAE,EACpD,MAAM,QAAQ,EACd,MAAM,YAAY,SAkBrB,CAAC"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.authorizedMiddleware = void 0;
|
|
4
|
-
const http_expection_1 = require("
|
|
4
|
+
const http_expection_1 = require("../expections/http.expection");
|
|
5
|
+
/** Header tabanlı yetkilendirme (throw’lu):
|
|
6
|
+
* - required: gerekli permission listesi
|
|
7
|
+
* - Mevcut izinler önce req.user.permissions’tan,
|
|
8
|
+
* yoksa x-user-permissions header’ından alınır.
|
|
9
|
+
*/
|
|
5
10
|
const authorizedMiddleware = (required) => {
|
|
6
11
|
return (req, _res, next) => {
|
|
7
12
|
const fromReq = req.user?.permissions ?? [];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorized.middleware.js","sourceRoot":"","sources":["../../middlewares/authorized.middleware.ts"],"names":[],"mappings":";;;AACA,iEAAkE;AAElE;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,CAAC,QAAkB,EAAE,EAAE;IACzD,OAAO,CACL,GAAoD,EACpD,IAAc,EACd,IAAkB,EAClB,EAAE;QACF,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC;QAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC;aAC/D,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACpB,MAAM,CAAC,OAAO,CAAC,CAAC;QAEnB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAS,CAAC,GAAG,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;QAC7D,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAE/E,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,2DAA2D;YAC3D,MAAM,IAAI,mCAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,oBAAoB,wBAsB/B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RequestHandler } from 'express';
|
|
2
2
|
import { TransformOptions } from 'class-transformer';
|
|
3
3
|
import { ValidatorOptions } from 'class-validator';
|
|
4
|
+
import HttpException from '../expections/http.expection';
|
|
4
5
|
export type IValidation = {
|
|
5
6
|
body?: any;
|
|
6
7
|
params?: any;
|
|
@@ -9,6 +10,7 @@ export type IValidation = {
|
|
|
9
10
|
logging?: boolean;
|
|
10
11
|
transformOptions?: TransformOptions;
|
|
11
12
|
validatorOptions?: ValidatorOptions;
|
|
13
|
+
customHttpError?: HttpException;
|
|
12
14
|
};
|
|
13
|
-
export default function validationMiddleware(ValidationClass: new (...args: any[]) => any, type: keyof IValidation, logging?: boolean, transformOptions?: TransformOptions, validatorOptions?: ValidatorOptions): RequestHandler;
|
|
15
|
+
export default function validationMiddleware(ValidationClass: new (...args: any[]) => any, type: keyof IValidation, logging?: boolean, transformOptions?: TransformOptions, validatorOptions?: ValidatorOptions, customHttpError?: HttpException): RequestHandler;
|
|
14
16
|
//# sourceMappingURL=validation.middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.middleware.d.ts","sourceRoot":"","sources":["../../middlewares/validation.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmC,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAmB,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAY,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,aAAa,MAAM,8BAA8B,CAAC;AACzD,MAAM,MAAM,WAAW,GAAG;IACzB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,eAAe,CAAC,EAAC,aAAa,CAAC;CAC/B,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC3C,eAAe,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC5C,IAAI,EAAE,MAAM,WAAW,EACvB,OAAO,CAAC,EAAE,OAAO,EACjB,gBAAgB,CAAC,EAAE,gBAAgB,EACnC,gBAAgB,CAAC,EAAE,gBAAgB,EACnC,eAAe,CAAC,EAAC,aAAa,GAC5B,cAAc,CAsFhB"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = validationMiddleware;
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
5
|
const class_validator_1 = require("class-validator");
|
|
6
|
-
function validationMiddleware(ValidationClass, type, logging, transformOptions, validatorOptions) {
|
|
6
|
+
function validationMiddleware(ValidationClass, type, logging, transformOptions, validatorOptions, customHttpError) {
|
|
7
7
|
const handler = async (req, res, next) => {
|
|
8
8
|
try {
|
|
9
9
|
const source = type === 'body'
|
|
@@ -36,14 +36,19 @@ function validationMiddleware(ValidationClass, type, logging, transformOptions,
|
|
|
36
36
|
...validatorOptions,
|
|
37
37
|
});
|
|
38
38
|
if (errors.length > 0) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
if (customHttpError) {
|
|
40
|
+
res.status(customHttpError.code).json(customHttpError.messageJson);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
res.status(400).json({
|
|
44
|
+
ok: false,
|
|
45
|
+
message: 'Validation error',
|
|
46
|
+
errors: errors.map((e) => ({
|
|
47
|
+
property: e.property,
|
|
48
|
+
constraints: e.constraints,
|
|
49
|
+
})),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
47
52
|
return; // <-- explicit return
|
|
48
53
|
}
|
|
49
54
|
Object.defineProperty(req, type, {
|
|
@@ -60,14 +65,19 @@ function validationMiddleware(ValidationClass, type, logging, transformOptions,
|
|
|
60
65
|
return; // <-- explicit return
|
|
61
66
|
}
|
|
62
67
|
catch (err) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
if (customHttpError) {
|
|
69
|
+
res.status(customHttpError.code).json(customHttpError.messageJson);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
res.status(400).json({
|
|
73
|
+
ok: false,
|
|
74
|
+
message: 'Validation middleware failed',
|
|
75
|
+
error: err?.message ?? String(err),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
68
78
|
return; // <-- explicit return
|
|
69
79
|
}
|
|
70
80
|
};
|
|
71
|
-
return handler;
|
|
81
|
+
return handler;
|
|
72
82
|
}
|
|
73
83
|
//# sourceMappingURL=validation.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.middleware.js","sourceRoot":"","sources":["../../middlewares/validation.middleware.ts"],"names":[],"mappings":";;AAcA,uCA6FC;AA1GD,yDAAsE;AACtE,qDAA6D;AAY7D,SAAwB,oBAAoB,CAC3C,eAA4C,EAC5C,IAAuB,EACvB,OAAiB,EACjB,gBAAmC,EACnC,gBAAmC,EACnC,eAA8B;IAE9B,MAAM,OAAO,GAAmB,KAAK,EACpC,GAAY,EACZ,GAAa,EACb,IAAkB,EACF,EAAE;QAClB,IAAI,CAAC;YACJ,MAAM,MAAM,GACX,IAAI,KAAK,MAAM;gBACd,CAAC,CAAC,GAAG,CAAC,IAAI;gBACV,CAAC,CAAC,IAAI,KAAK,OAAO;oBAClB,CAAC,CAAC,GAAG,CAAC,KAAK;oBACX,CAAC,CAAC,IAAI,KAAK,SAAS;wBACpB,CAAC,CAAC,GAAG,CAAC,OAAO;wBACb,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;YAEf,IAAI,OAAO,EAAE,CAAC;gBACb,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;gBAC/C,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC;YAED,oBAAoB;YACpB,MAAM,QAAQ,GAAG,IAAA,mCAAe,EAAC,eAAe,EAAE,MAAM,EAAE;gBACzD,wBAAwB,EAAE,IAAI;gBAC9B,mBAAmB,EAAE,IAAI;gBACzB,GAAG,gBAAgB;aACnB,CAAC,CAAC;YAEH,IAAI,OAAO,EAAE,CAAC;gBACb,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAA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