@sharangyawali/sg-app 1.0.10
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/README.md +24 -0
- package/cls/cls.service.d.ts +8 -0
- package/cls/cls.service.js +33 -0
- package/cls/index.d.ts +1 -0
- package/cls/index.js +17 -0
- package/common/constants/index.d.ts +1 -0
- package/common/constants/index.js +17 -0
- package/common/constants/providers.constants.d.ts +1 -0
- package/common/constants/providers.constants.js +4 -0
- package/common/decorators/component.decorators.d.ts +2 -0
- package/common/decorators/component.decorators.js +14 -0
- package/common/decorators/controller.decorator.d.ts +2 -0
- package/common/decorators/controller.decorator.js +18 -0
- package/common/decorators/filters.decorator.d.ts +2 -0
- package/common/decorators/filters.decorator.js +19 -0
- package/common/decorators/guards.decorator.d.ts +4 -0
- package/common/decorators/guards.decorator.js +25 -0
- package/common/decorators/index.d.ts +10 -0
- package/common/decorators/index.js +26 -0
- package/common/decorators/inject.decorators.d.ts +3 -0
- package/common/decorators/inject.decorators.js +13 -0
- package/common/decorators/interceptors.decorator.d.ts +4 -0
- package/common/decorators/interceptors.decorator.js +25 -0
- package/common/decorators/middlewares.decorator.d.ts +3 -0
- package/common/decorators/middlewares.decorator.js +19 -0
- package/common/decorators/module.decorator.d.ts +2 -0
- package/common/decorators/module.decorator.js +25 -0
- package/common/decorators/parameter-validator.decorator.d.ts +7 -0
- package/common/decorators/parameter-validator.decorator.js +25 -0
- package/common/decorators/route-mapping.decorator.d.ts +5 -0
- package/common/decorators/route-mapping.decorator.js +32 -0
- package/common/enum/index.d.ts +3 -0
- package/common/enum/index.js +19 -0
- package/common/enum/request-method.enum.d.ts +11 -0
- package/common/enum/request-method.enum.js +15 -0
- package/common/enum/request-parameters.enum.d.ts +9 -0
- package/common/enum/request-parameters.enum.js +13 -0
- package/common/enum/scope.enum.d.ts +5 -0
- package/common/enum/scope.enum.js +9 -0
- package/common/http/http-context.d.ts +13 -0
- package/common/http/http-context.js +27 -0
- package/common/http/http-exception.d.ts +7 -0
- package/common/http/http-exception.js +17 -0
- package/common/http/index.d.ts +2 -0
- package/common/http/index.js +18 -0
- package/common/index.d.ts +5 -0
- package/common/index.js +21 -0
- package/common/interface/controller-method-paramenters.interface.d.ts +6 -0
- package/common/interface/controller-method-paramenters.interface.js +2 -0
- package/common/interface/controller-methods.interface.d.ts +6 -0
- package/common/interface/controller-methods.interface.js +2 -0
- package/common/interface/cors.interface.d.ts +14 -0
- package/common/interface/cors.interface.js +2 -0
- package/common/interface/features/index.d.ts +4 -0
- package/common/interface/features/index.js +20 -0
- package/common/interface/features/sg-filter.interface.d.ts +4 -0
- package/common/interface/features/sg-filter.interface.js +2 -0
- package/common/interface/features/sg-guard.interface.d.ts +4 -0
- package/common/interface/features/sg-guard.interface.js +2 -0
- package/common/interface/features/sg-interceptor.interface.d.ts +4 -0
- package/common/interface/features/sg-interceptor.interface.js +2 -0
- package/common/interface/features/sg-middleware.interface.d.ts +4 -0
- package/common/interface/features/sg-middleware.interface.js +2 -0
- package/common/interface/global-middleware-options.interface.d.ts +5 -0
- package/common/interface/global-middleware-options.interface.js +2 -0
- package/common/interface/global-prefix-options.interface.d.ts +4 -0
- package/common/interface/global-prefix-options.interface.js +2 -0
- package/common/interface/index.d.ts +15 -0
- package/common/interface/index.js +31 -0
- package/common/interface/injectable-options.interface.d.ts +5 -0
- package/common/interface/injectable-options.interface.js +2 -0
- package/common/interface/injection-token.interface.d.ts +6 -0
- package/common/interface/injection-token.interface.js +2 -0
- package/common/interface/module-options.interface.d.ts +6 -0
- package/common/interface/module-options.interface.js +2 -0
- package/common/interface/provider.interface.d.ts +28 -0
- package/common/interface/provider.interface.js +2 -0
- package/common/interface/route-info.interface.d.ts +5 -0
- package/common/interface/route-info.interface.js +2 -0
- package/common/interface/sg-application.interface.d.ts +8 -0
- package/common/interface/sg-application.interface.js +2 -0
- package/common/interface/sg-factory.interface.d.ts +8 -0
- package/common/interface/sg-factory.interface.js +2 -0
- package/common/interface/sg-interceptor.interface.d.ts +3 -0
- package/common/interface/sg-interceptor.interface.js +2 -0
- package/common/interface/static-route.interface.d.ts +20 -0
- package/common/interface/static-route.interface.js +2 -0
- package/common/interface/type.interface.d.ts +3 -0
- package/common/interface/type.interface.js +2 -0
- package/config/config-service.d.ts +3 -0
- package/config/config-service.js +11 -0
- package/config/index.d.ts +1 -0
- package/config/index.js +17 -0
- package/di-container.d.ts +19 -0
- package/di-container.js +113 -0
- package/index.d.ts +9 -0
- package/index.js +25 -0
- package/logger/index.d.ts +1 -0
- package/logger/index.js +17 -0
- package/logger/logger-service.d.ts +9 -0
- package/logger/logger-service.js +44 -0
- package/package.json +24 -0
- package/routes-config.d.ts +24 -0
- package/routes-config.js +224 -0
- package/set-meta-data.d.ts +1 -0
- package/set-meta-data.js +35 -0
- package/sg-application.d.ts +12 -0
- package/sg-application.js +37 -0
- package/sg-factory.d.ts +7 -0
- package/sg-factory.js +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# ⚡ SG-APP
|
|
2
|
+
|
|
3
|
+
A lightweight, opinionated framework built on top of **Express**, inspired by NestJS, designed for **Clean Architecture**, **modularity**, and **developer productivity** — without hiding Express.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ✨ Features
|
|
8
|
+
|
|
9
|
+
- 🚀 Built on **Express**
|
|
10
|
+
- 🧱 Clean Architecture out of the box
|
|
11
|
+
- 🧩 Module-based structure
|
|
12
|
+
- 🪄 Decorator-based API (RestController, UseGuard, UseInterceptor, etc.)
|
|
13
|
+
- 🔌 Dependency Injection
|
|
14
|
+
- 🧵 Request-scoped context via CLS
|
|
15
|
+
- 📝 Centralized logging & configuration
|
|
16
|
+
- 🛠 Compatible with plain Express middleware
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 📥 Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @sharangyawali/sg-app
|
|
24
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CLSService = void 0;
|
|
7
|
+
const async_hooks_1 = require("async_hooks");
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
class CLSService {
|
|
10
|
+
asyncLocalStorage;
|
|
11
|
+
constructor() {
|
|
12
|
+
this.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
13
|
+
}
|
|
14
|
+
run(req, fn) {
|
|
15
|
+
const requestId = crypto_1.default.randomUUID();
|
|
16
|
+
return this.asyncLocalStorage.run({ requestId, request: req }, fn);
|
|
17
|
+
}
|
|
18
|
+
set(key, value) {
|
|
19
|
+
const store = this.asyncLocalStorage.getStore();
|
|
20
|
+
if (!store) {
|
|
21
|
+
throw new Error("CLS context not initialized");
|
|
22
|
+
}
|
|
23
|
+
store[key] = value;
|
|
24
|
+
}
|
|
25
|
+
get(key) {
|
|
26
|
+
const store = this.asyncLocalStorage.getStore();
|
|
27
|
+
if (!store) {
|
|
28
|
+
throw new Error("CLS context not initialized");
|
|
29
|
+
}
|
|
30
|
+
return store[key];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.CLSService = CLSService;
|
package/cls/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./cls.service";
|
package/cls/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cls.service"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers.constants";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./providers.constants"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const REQUEST = "request";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Component = Component;
|
|
4
|
+
const di_container_1 = require("../../di-container");
|
|
5
|
+
const enum_1 = require("../enum");
|
|
6
|
+
function Component(options) {
|
|
7
|
+
return function (target) {
|
|
8
|
+
di_container_1.container.register({
|
|
9
|
+
token: options && options.token ? options.token : target,
|
|
10
|
+
useClass: target,
|
|
11
|
+
scope: options && options.scope ? options.scope : enum_1.Scope.SINGLETON
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.controllers = void 0;
|
|
4
|
+
exports.RestController = RestController;
|
|
5
|
+
const di_container_1 = require("../../di-container");
|
|
6
|
+
const enum_1 = require("../enum");
|
|
7
|
+
exports.controllers = [];
|
|
8
|
+
function RestController(prefix = "/") {
|
|
9
|
+
return function (target) {
|
|
10
|
+
target.prototype.prefix = prefix[0] !== "/" ? "/" + prefix : prefix;
|
|
11
|
+
exports.controllers.push(target);
|
|
12
|
+
di_container_1.container.register({
|
|
13
|
+
token: target,
|
|
14
|
+
useClass: target,
|
|
15
|
+
scope: enum_1.Scope.SINGLETON
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filters = void 0;
|
|
4
|
+
exports.Catch = Catch;
|
|
5
|
+
const di_container_1 = require("../../di-container");
|
|
6
|
+
const enum_1 = require("../enum");
|
|
7
|
+
exports.filters = [];
|
|
8
|
+
function Catch() {
|
|
9
|
+
return function (target) {
|
|
10
|
+
if (typeof target.prototype.catch !== "function")
|
|
11
|
+
throw new Error(`${target.name} does not implements catch method`);
|
|
12
|
+
exports.filters.push(target);
|
|
13
|
+
di_container_1.container.register({
|
|
14
|
+
token: target,
|
|
15
|
+
useClass: target,
|
|
16
|
+
scope: enum_1.Scope.SINGLETON
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalGuards = void 0;
|
|
4
|
+
exports.UseGuard = UseGuard;
|
|
5
|
+
exports.GlobalGuard = GlobalGuard;
|
|
6
|
+
const di_container_1 = require("../../di-container");
|
|
7
|
+
const enum_1 = require("../enum");
|
|
8
|
+
exports.globalGuards = [];
|
|
9
|
+
function UseGuard(...guardClasses) {
|
|
10
|
+
return function (target, propertyKey) {
|
|
11
|
+
target[propertyKey].guards = guardClasses;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function GlobalGuard() {
|
|
15
|
+
return function (target) {
|
|
16
|
+
if (typeof target.prototype.canAccess !== "function")
|
|
17
|
+
throw new Error(`${target.name} does not implements canActivate method`);
|
|
18
|
+
exports.globalGuards.push(target);
|
|
19
|
+
di_container_1.container.register({
|
|
20
|
+
token: target,
|
|
21
|
+
useClass: target,
|
|
22
|
+
scope: enum_1.Scope.SINGLETON
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./controller.decorator";
|
|
2
|
+
export * from "./filters.decorator";
|
|
3
|
+
export * from "./guards.decorator";
|
|
4
|
+
export * from "./interceptors.decorator";
|
|
5
|
+
export * from "./middlewares.decorator";
|
|
6
|
+
export * from "./parameter-validator.decorator";
|
|
7
|
+
export * from "./route-mapping.decorator";
|
|
8
|
+
export * from "./module.decorator";
|
|
9
|
+
export * from "./component.decorators";
|
|
10
|
+
export * from "./inject.decorators";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./controller.decorator"), exports);
|
|
18
|
+
__exportStar(require("./filters.decorator"), exports);
|
|
19
|
+
__exportStar(require("./guards.decorator"), exports);
|
|
20
|
+
__exportStar(require("./interceptors.decorator"), exports);
|
|
21
|
+
__exportStar(require("./middlewares.decorator"), exports);
|
|
22
|
+
__exportStar(require("./parameter-validator.decorator"), exports);
|
|
23
|
+
__exportStar(require("./route-mapping.decorator"), exports);
|
|
24
|
+
__exportStar(require("./module.decorator"), exports);
|
|
25
|
+
__exportStar(require("./component.decorators"), exports);
|
|
26
|
+
__exportStar(require("./inject.decorators"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Inject = Inject;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
function Inject(token) {
|
|
6
|
+
return (target, _, index) => {
|
|
7
|
+
if (typeof index === "number") {
|
|
8
|
+
const existing = Reflect.getMetadata("custom:inject_tokens", target) || {};
|
|
9
|
+
existing[index] = token;
|
|
10
|
+
Reflect.defineMetadata("custom:inject_tokens", existing, target);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalInterceptors = void 0;
|
|
4
|
+
exports.UseInterceptor = UseInterceptor;
|
|
5
|
+
exports.GlobalInterceptors = GlobalInterceptors;
|
|
6
|
+
const di_container_1 = require("../../di-container");
|
|
7
|
+
const enum_1 = require("../enum");
|
|
8
|
+
exports.globalInterceptors = [];
|
|
9
|
+
function UseInterceptor(...interceptorClasses) {
|
|
10
|
+
return function (target, propertyKey) {
|
|
11
|
+
target[propertyKey].interceptors = interceptorClasses;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function GlobalInterceptors() {
|
|
15
|
+
return function (target) {
|
|
16
|
+
if (typeof target.prototype.intercept !== "function")
|
|
17
|
+
throw new Error(`${target.name} does not implements intercept method`);
|
|
18
|
+
exports.globalInterceptors.push(target);
|
|
19
|
+
di_container_1.container.register({
|
|
20
|
+
token: target,
|
|
21
|
+
useClass: target,
|
|
22
|
+
scope: enum_1.Scope.SINGLETON
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.middlewares = void 0;
|
|
4
|
+
exports.Middleware = Middleware;
|
|
5
|
+
const di_container_1 = require("../../di-container");
|
|
6
|
+
const scope_enum_1 = require("../enum/scope.enum");
|
|
7
|
+
exports.middlewares = [];
|
|
8
|
+
function Middleware(options) {
|
|
9
|
+
return function (target) {
|
|
10
|
+
if (typeof target.prototype.use !== "function")
|
|
11
|
+
throw new Error(`${target.name} does not implements use method`);
|
|
12
|
+
exports.middlewares.push({ target, options });
|
|
13
|
+
di_container_1.container.register({
|
|
14
|
+
token: target,
|
|
15
|
+
useClass: target,
|
|
16
|
+
scope: scope_enum_1.Scope.SINGLETON
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = Module;
|
|
4
|
+
const di_container_1 = require("../../di-container");
|
|
5
|
+
const enum_1 = require("../enum");
|
|
6
|
+
function Module(options) {
|
|
7
|
+
return function (target) {
|
|
8
|
+
if (options.providers) {
|
|
9
|
+
options.providers.forEach((p) => {
|
|
10
|
+
if (Object.keys(p).length > 0) {
|
|
11
|
+
const provider = p;
|
|
12
|
+
if (provider.useClass || provider.useValue || provider.useFactory)
|
|
13
|
+
di_container_1.container.register({
|
|
14
|
+
scope: provider.scope || enum_1.Scope.SINGLETON,
|
|
15
|
+
token: provider.token,
|
|
16
|
+
useValue: provider.useValue,
|
|
17
|
+
useClass: provider.useClass,
|
|
18
|
+
useFactory: provider.useFactory,
|
|
19
|
+
inject: provider.inject
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const Query: (dtoClass: any) => ParameterDecorator;
|
|
2
|
+
export declare const Body: (dtoClass: any) => ParameterDecorator;
|
|
3
|
+
export declare const Params: (dtoClass: any) => ParameterDecorator;
|
|
4
|
+
export declare const UploadedFile: () => ParameterDecorator;
|
|
5
|
+
export declare const UploadedFiles: () => ParameterDecorator;
|
|
6
|
+
export declare const Req: () => ParameterDecorator;
|
|
7
|
+
export declare const Res: () => ParameterDecorator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Res = exports.Req = exports.UploadedFiles = exports.UploadedFile = exports.Params = exports.Body = exports.Query = void 0;
|
|
4
|
+
const enum_1 = require("../enum");
|
|
5
|
+
function Validator(data, dtoClass) {
|
|
6
|
+
return function (target, propertyKey, index) {
|
|
7
|
+
const parameters = target[propertyKey].parameters || [];
|
|
8
|
+
parameters.push({ index, dtoClass, paramType: data });
|
|
9
|
+
target[propertyKey].parameters = parameters;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
const Query = (dtoClass) => Validator(enum_1.RequestParameters.QUERY, dtoClass);
|
|
13
|
+
exports.Query = Query;
|
|
14
|
+
const Body = (dtoClass) => Validator(enum_1.RequestParameters.BODY, dtoClass);
|
|
15
|
+
exports.Body = Body;
|
|
16
|
+
const Params = (dtoClass) => Validator(enum_1.RequestParameters.PARAMS, dtoClass);
|
|
17
|
+
exports.Params = Params;
|
|
18
|
+
const UploadedFile = () => Validator(enum_1.RequestParameters.FILE, null);
|
|
19
|
+
exports.UploadedFile = UploadedFile;
|
|
20
|
+
const UploadedFiles = () => Validator(enum_1.RequestParameters.FILES, null);
|
|
21
|
+
exports.UploadedFiles = UploadedFiles;
|
|
22
|
+
const Req = () => Validator(enum_1.RequestParameters.REQUEST, null);
|
|
23
|
+
exports.Req = Req;
|
|
24
|
+
const Res = () => Validator(enum_1.RequestParameters.RESPONSE, null);
|
|
25
|
+
exports.Res = Res;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const Get: (path?: string) => MethodDecorator;
|
|
2
|
+
export declare const Post: (path?: string) => MethodDecorator;
|
|
3
|
+
export declare const Put: (path?: string) => MethodDecorator;
|
|
4
|
+
export declare const Patch: (path?: string) => MethodDecorator;
|
|
5
|
+
export declare const Delete: (path?: string) => MethodDecorator;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = void 0;
|
|
4
|
+
function RequestMapping(method, path) {
|
|
5
|
+
return function (target, propertyKey) {
|
|
6
|
+
const methods = target.methods || [];
|
|
7
|
+
const index = methods.findIndex((m) => m.handler === propertyKey);
|
|
8
|
+
if (index > -1)
|
|
9
|
+
methods[index] = {
|
|
10
|
+
...methods[index],
|
|
11
|
+
method: method,
|
|
12
|
+
path: path && path.length > 0 && path[0] !== "/" ? "/" + path : path
|
|
13
|
+
};
|
|
14
|
+
else
|
|
15
|
+
methods.push({
|
|
16
|
+
handler: propertyKey,
|
|
17
|
+
method,
|
|
18
|
+
path: path && path.length > 0 && path[0] !== "/" ? "/" + path : path
|
|
19
|
+
});
|
|
20
|
+
target.methods = methods;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const Get = (path) => RequestMapping("get", path);
|
|
24
|
+
exports.Get = Get;
|
|
25
|
+
const Post = (path) => RequestMapping("post", path);
|
|
26
|
+
exports.Post = Post;
|
|
27
|
+
const Put = (path) => RequestMapping("put", path);
|
|
28
|
+
exports.Put = Put;
|
|
29
|
+
const Patch = (path) => RequestMapping("patch", path);
|
|
30
|
+
exports.Patch = Patch;
|
|
31
|
+
const Delete = (path) => RequestMapping("delete", path);
|
|
32
|
+
exports.Delete = Delete;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./request-method.enum"), exports);
|
|
18
|
+
__exportStar(require("./request-parameters.enum"), exports);
|
|
19
|
+
__exportStar(require("./scope.enum"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestMethodEnum = void 0;
|
|
4
|
+
var RequestMethodEnum;
|
|
5
|
+
(function (RequestMethodEnum) {
|
|
6
|
+
RequestMethodEnum["POST"] = "post";
|
|
7
|
+
RequestMethodEnum["GET"] = "get";
|
|
8
|
+
RequestMethodEnum["DELETE"] = "delete";
|
|
9
|
+
RequestMethodEnum["PUT"] = "put";
|
|
10
|
+
RequestMethodEnum["PATCH"] = "patch";
|
|
11
|
+
RequestMethodEnum["ALL"] = "all";
|
|
12
|
+
RequestMethodEnum["OPTIONS"] = "options";
|
|
13
|
+
RequestMethodEnum["HEAD"] = "head";
|
|
14
|
+
RequestMethodEnum["SEARCH"] = "search";
|
|
15
|
+
})(RequestMethodEnum || (exports.RequestMethodEnum = RequestMethodEnum = {}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestParameters = void 0;
|
|
4
|
+
var RequestParameters;
|
|
5
|
+
(function (RequestParameters) {
|
|
6
|
+
RequestParameters["QUERY"] = "query";
|
|
7
|
+
RequestParameters["BODY"] = "body";
|
|
8
|
+
RequestParameters["PARAMS"] = "params";
|
|
9
|
+
RequestParameters["FILE"] = "file";
|
|
10
|
+
RequestParameters["FILES"] = "files";
|
|
11
|
+
RequestParameters["REQUEST"] = "req";
|
|
12
|
+
RequestParameters["RESPONSE"] = "res";
|
|
13
|
+
})(RequestParameters || (exports.RequestParameters = RequestParameters = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Scope = void 0;
|
|
4
|
+
var Scope;
|
|
5
|
+
(function (Scope) {
|
|
6
|
+
Scope["SINGLETON"] = "singleton";
|
|
7
|
+
Scope["TRANSIENT"] = "transient";
|
|
8
|
+
Scope["REQUEST"] = "request";
|
|
9
|
+
})(Scope || (exports.Scope = Scope = {}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
import { ControllerMethods } from "../interface";
|
|
3
|
+
export declare class HttpContext {
|
|
4
|
+
private readonly request;
|
|
5
|
+
private readonly response;
|
|
6
|
+
private readonly methodMeta;
|
|
7
|
+
private readonly req;
|
|
8
|
+
private readonly res;
|
|
9
|
+
constructor(request: Request, response: Response, methodMeta: ControllerMethods);
|
|
10
|
+
getRequest(): Request;
|
|
11
|
+
getResponse(): Response;
|
|
12
|
+
getMetaData<T>(key: string): T;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpContext = void 0;
|
|
4
|
+
class HttpContext {
|
|
5
|
+
request;
|
|
6
|
+
response;
|
|
7
|
+
methodMeta;
|
|
8
|
+
req;
|
|
9
|
+
res;
|
|
10
|
+
constructor(request, response, methodMeta) {
|
|
11
|
+
this.request = request;
|
|
12
|
+
this.response = response;
|
|
13
|
+
this.methodMeta = methodMeta;
|
|
14
|
+
this.req = request;
|
|
15
|
+
this.res = response;
|
|
16
|
+
}
|
|
17
|
+
getRequest() {
|
|
18
|
+
return this.req;
|
|
19
|
+
}
|
|
20
|
+
getResponse() {
|
|
21
|
+
return this.res;
|
|
22
|
+
}
|
|
23
|
+
getMetaData(key) {
|
|
24
|
+
return this.methodMeta[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.HttpContext = HttpContext;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpException = void 0;
|
|
4
|
+
class HttpException extends Error {
|
|
5
|
+
msg;
|
|
6
|
+
status;
|
|
7
|
+
message;
|
|
8
|
+
statusCode;
|
|
9
|
+
constructor(msg = "Internal Server Error", status = 500) {
|
|
10
|
+
super(msg);
|
|
11
|
+
this.msg = msg;
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.message = msg;
|
|
14
|
+
this.statusCode = status;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.HttpException = HttpException;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./http-context"), exports);
|
|
18
|
+
__exportStar(require("./http-exception"), exports);
|